2 * Copyright © 2013 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 * This code is derived from src/egl/drivers/dri2/common.c which
25 * carries the following copyright:
27 * Copyright © 2011 Intel Corporation
29 * Permission is hereby granted, free of charge, to any person obtaining a
30 * copy of this software and associated documentation files (the "Software"),
31 * to deal in the Software without restriction, including without limitation
32 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
33 * and/or sell copies of the Software, and to permit persons to whom the
34 * Software is furnished to do so, subject to the following conditions:
36 * The above copyright notice and this permission notice (including the next
37 * paragraph) shall be included in all copies or substantial portions of the
40 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
41 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
42 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
43 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
44 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
45 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
46 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
47 * DEALINGS IN THE SOFTWARE.
50 * Kristian Høgsberg <krh@bitplanet.net>
51 * Benjamin Franzke <benjaminfranzke@googlemail.com>
57 #include <sys/types.h>
62 #include "glxclient.h"
67 #include <sys/types.h>
71 #include "dri_common.h"
72 #include "dri3_priv.h"
74 #define DRIVER_MAP_DRI3_ONLY
75 #include "pci_ids/pci_id_driver_map.h"
79 static struct udev_device
*
80 dri3_udev_device_new_from_fd(struct udev
*udev
, int fd
)
82 struct udev_device
*device
;
85 if (fstat(fd
, &buf
) < 0) {
86 ErrorMessageF("DRI3: failed to stat fd %d", fd
);
90 device
= udev_device_new_from_devnum(udev
, 'c', buf
.st_rdev
);
92 ErrorMessageF("DRI3: could not create udev device for fd %d", fd
);
100 dri3_get_driver_for_fd(int fd
)
103 struct udev_device
*device
, *parent
;
106 int vendor_id
, chip_id
, i
, j
;
109 device
= dri3_udev_device_new_from_fd(udev
, fd
);
113 parent
= udev_device_get_parent(device
);
114 if (parent
== NULL
) {
115 ErrorMessageF("DRI3: could not get parent device");
119 pci_id
= udev_device_get_property_value(parent
, "PCI_ID");
120 if (pci_id
== NULL
||
121 sscanf(pci_id
, "%x:%x", &vendor_id
, &chip_id
) != 2) {
122 ErrorMessageF("DRI3: malformed or no PCI ID");
126 for (i
= 0; driver_map
[i
].driver
; i
++) {
127 if (vendor_id
!= driver_map
[i
].vendor_id
)
129 if (driver_map
[i
].num_chips_ids
== -1) {
130 driver
= strdup(driver_map
[i
].driver
);
134 for (j
= 0; j
< driver_map
[i
].num_chips_ids
; j
++)
135 if (driver_map
[i
].chip_ids
[j
] == chip_id
) {
136 driver
= strdup(driver_map
[i
].driver
);
142 udev_device_unref(device
);