2 * Copyright © 2011 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Kristian Høgsberg <krh@bitplanet.net>
26 * Benjamin Franzke <benjaminfranzke@googlemail.com>
34 #include "gbm_driint.h"
35 #define DRIVER_MAP_DRI2_ONLY
36 #include "pci_ids/pci_id_driver_map.h"
39 dri_fd_get_driver_name(int fd
)
42 struct udev_device
*device
, *parent
;
45 int vendor_id
, chip_id
, i
, j
;
48 device
= _gbm_udev_device_new_from_fd(udev
, fd
);
52 parent
= udev_device_get_parent(device
);
54 fprintf(stderr
, "gbm: could not get parent device");
58 pci_id
= udev_device_get_property_value(parent
, "PCI_ID");
60 sscanf(pci_id
, "%x:%x", &vendor_id
, &chip_id
) != 2) {
61 fprintf(stderr
, "gbm: malformed or no PCI ID");
65 for (i
= 0; driver_map
[i
].driver
; i
++) {
66 if (vendor_id
!= driver_map
[i
].vendor_id
)
68 if (driver_map
[i
].num_chips_ids
== -1) {
69 driver
= strdup(driver_map
[i
].driver
);
70 _gbm_log("pci id for %d: %04x:%04x, driver %s",
71 fd
, vendor_id
, chip_id
, driver
);
75 for (j
= 0; j
< driver_map
[i
].num_chips_ids
; j
++)
76 if (driver_map
[i
].chip_ids
[j
] == chip_id
) {
77 driver
= strdup(driver_map
[i
].driver
);
78 _gbm_log("pci id for %d: %04x:%04x, driver %s",
79 fd
, vendor_id
, chip_id
, driver
);
85 udev_device_unref(device
);