xf86drm: move platform details to drmParsePciDeviceInfo()

As with previous commit let's try to keep drmGetDevices clean of linux
specifics.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
main
Emil Velikov 2015-09-07 12:47:47 +01:00
parent 536e0deba3
commit ef5192e9c7
1 changed files with 15 additions and 21 deletions

View File

@ -2924,11 +2924,22 @@ static int drmGetNodeType(const char *name)
return -EINVAL; return -EINVAL;
} }
static int drmParsePciDeviceInfo(const unsigned char *config, static int drmParsePciDeviceInfo(const char *d_name,
drmPciDeviceInfoPtr device) drmPciDeviceInfoPtr device)
{ {
if (config == NULL) char path[PATH_MAX + 1];
return -EINVAL; unsigned char config[64];
int fd, ret;
snprintf(path, PATH_MAX, "/sys/class/drm/%s/device/config", d_name);
fd = open(path, O_RDONLY);
if (fd < 0)
return -errno;
ret = read(fd, config, sizeof(config));
close(fd);
if (ret < 0)
return -errno;
device->vendor_id = config[0] | (config[1] << 8); device->vendor_id = config[0] | (config[1] << 8);
device->device_id = config[2] | (config[3] << 8); device->device_id = config[2] | (config[3] << 8);
@ -2991,10 +3002,8 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
struct stat sbuf = {0}; struct stat sbuf = {0};
char node[PATH_MAX + 1] = ""; char node[PATH_MAX + 1] = "";
char path[PATH_MAX + 1] = ""; char path[PATH_MAX + 1] = "";
unsigned char config[64] = "";
int node_type, subsystem_type; int node_type, subsystem_type;
int maj, min; int maj, min;
int fd;
int ret, i = 0, j, node_count, device_count = 0; int ret, i = 0, j, node_count, device_count = 0;
int max_count = 16; int max_count = 16;
int *duplicated = NULL; int *duplicated = NULL;
@ -3063,32 +3072,17 @@ int drmGetDevices(drmDevicePtr devices[], int max_devices)
devs[i].available_nodes = 1 << node_type; devs[i].available_nodes = 1 << node_type;
if (devices != NULL) { if (devices != NULL) {
snprintf(path, PATH_MAX, "/sys/class/drm/%s/device/config",
dent->d_name);
fd = open(path, O_RDONLY);
if (fd < 0) {
ret = -errno;
goto free_locals;
}
ret = read(fd, config, 64);
if (ret < 0) {
ret = -errno;
close(fd);
goto free_locals;
}
pcidevice = calloc(1, sizeof(*pcidevice)); pcidevice = calloc(1, sizeof(*pcidevice));
if (pcidevice == NULL) { if (pcidevice == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto free_locals; goto free_locals;
} }
ret = drmParsePciDeviceInfo(config, pcidevice); ret = drmParsePciDeviceInfo(dent->d_name, pcidevice);
if (ret) if (ret)
goto free_locals; goto free_locals;
devs[i].deviceinfo.pci = pcidevice; devs[i].deviceinfo.pci = pcidevice;
close(fd);
} }
break; break;
default: default: