38f5b257400ad99193d03671ede6e2288663b78b
12 #define DRIVER_MAP_DRI2_ONLY
13 #include "pci_ids/pci_id_driver_map.h"
17 static struct udev_device
*
18 dri2_udev_device_new_from_fd(struct udev
*udev
, int fd
)
20 struct udev_device
*device
;
23 if (fstat(fd
, &buf
) < 0) {
24 _eglLog(_EGL_WARNING
, "EGL-DRI2: failed to stat fd %d", fd
);
28 device
= udev_device_new_from_devnum(udev
, 'c', buf
.st_rdev
);
31 "EGL-DRI2: could not create udev device for fd %d", fd
);
39 dri2_get_device_name_for_fd(int fd
)
42 struct udev_device
*device
;
43 const char *const_device_name
;
44 char *device_name
= NULL
;
47 device
= dri2_udev_device_new_from_fd(udev
, fd
);
51 const_device_name
= udev_device_get_devnode(device
);
52 if (!const_device_name
)
54 device_name
= strdup(const_device_name
);
57 udev_device_unref(device
);
64 dri2_get_driver_for_fd(int fd
)
67 struct udev_device
*device
, *parent
;
70 int vendor_id
, chip_id
, i
, j
;
73 device
= dri2_udev_device_new_from_fd(udev
, fd
);
77 parent
= udev_device_get_parent(device
);
79 _eglLog(_EGL_WARNING
, "DRI2: could not get parent device");
83 pci_id
= udev_device_get_property_value(parent
, "PCI_ID");
85 sscanf(pci_id
, "%x:%x", &vendor_id
, &chip_id
) != 2) {
86 _eglLog(_EGL_WARNING
, "EGL-DRI2: malformed or no PCI ID");
90 for (i
= 0; driver_map
[i
].driver
; i
++) {
91 if (vendor_id
!= driver_map
[i
].vendor_id
)
93 if (driver_map
[i
].num_chips_ids
== -1) {
94 driver
= strdup(driver_map
[i
].driver
);
95 _eglLog(_EGL_DEBUG
, "pci id for %d: %04x:%04x, driver %s",
96 fd
, vendor_id
, chip_id
, driver
);
100 for (j
= 0; j
< driver_map
[i
].num_chips_ids
; j
++)
101 if (driver_map
[i
].chip_ids
[j
] == chip_id
) {
102 driver
= strdup(driver_map
[i
].driver
);
103 _eglLog(_EGL_DEBUG
, "pci id for %d: %04x:%04x, driver %s",
104 fd
, vendor_id
, chip_id
, driver
);
110 udev_device_unref(device
);
116 #endif /* HAVE_LIBUDEV */