Example #1
0
static INLINE void
get_bus_info( int fd,
              DWORD *vendorid,
              DWORD *deviceid,
              DWORD *subsysid,
              DWORD *revision )
{
    drm_unique_t u;

    u.unique_len = 0;
    u.unique = NULL;

    if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) { return; }
    u.unique = CALLOC(u.unique_len+1, 1);

    if (ioctl(fd, DRM_IOCTL_GET_UNIQUE, &u)) { return; }
    u.unique[u.unique_len] = '\0';

    DBG("DRM Device BusID: %s\n", u.unique);
    if (strncmp("pci:", u.unique, 4) == 0) {
        char fname[512]; /* this ought to be enough */
        int l = snprintf(fname, 512, "/sys/bus/pci/devices/%s/", u.unique+4);

        /* VendorId */
        snprintf(fname+l, 512-l, "vendor");
        *vendorid = read_file_dword(fname);
        /* DeviceId */
        snprintf(fname+l, 512-l, "device");
        *deviceid = read_file_dword(fname);
        /* SubSysId */
        snprintf(fname+l, 512-l, "subsystem_device");
        *subsysid = (read_file_dword(fname) << 16) & 0xFFFF0000;
        snprintf(fname+l, 512-l, "subsystem_vendor");
        *subsysid |= read_file_dword(fname) & 0x0000FFFF;
        /* Revision */
        {
            int cfgfd;

            snprintf(fname+l, 512-l, "config");
            cfgfd = open(fname, O_RDONLY);
            if (cfgfd >= 0) {
                *revision = read_config_dword(cfgfd, 0x8) & 0x000000FF;
                close(cfgfd);
            } else {
                DBG("Unable to get raw PCI information from `%s'\n", fname);
            }
        }
        DBG("PCI info: vendor=0x%04x, device=0x%04x, subsys=0x%08x, rev=%d\n",
            *vendorid, *deviceid, *subsysid, *revision);
    } else {
        DBG("Unsupported BusID type.\n");
    }

    FREE(u.unique);
}
Example #2
0
static int pci_config_read(struct pci_bus *bus, unsigned int devfn,
                       int where, int size, u32 * val)
{
   switch (size) {
  case 1:
    return read_config_byte(bus, devfn, where, val);
  case 2:
    return read_config_word(bus, devfn, where, val);
  default:
    return read_config_dword(bus, devfn, where, val);
  }
}