Rev 4358 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4358 | Rev 5080 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | * |
30 | * |
31 | **************************************************************************/ |
31 | **************************************************************************/ |
Line 32... | Line 32... | ||
32 | 32 | ||
33 | #include |
33 | #include |
34 | #include |
34 | #include |
35 | #include |
35 | //#include |
Line 36... | Line 36... | ||
36 | #include |
36 | #include |
Line 37... | Line 37... | ||
37 | 37 | ||
Line 48... | Line 48... | ||
48 | #include "util/u_dl.h" |
48 | #include "util/u_dl.h" |
49 | #include "util/u_debug.h" |
49 | #include "util/u_debug.h" |
Line 50... | Line 50... | ||
50 | 50 | ||
51 | #define DRIVER_MAP_GALLIUM_ONLY |
51 | #define DRIVER_MAP_GALLIUM_ONLY |
- | 52 | #include "pci_ids/pci_id_driver_map.h" |
|
- | 53 | #include |
|
- | 54 | ||
- | 55 | struct pci_device { |
|
- | 56 | uint16_t domain; |
|
- | 57 | uint8_t bus; |
|
- | 58 | uint8_t dev; |
|
- | 59 | uint8_t func; |
|
- | 60 | uint16_t vendor_id; |
|
- | 61 | uint16_t device_id; |
|
- | 62 | uint16_t subvendor_id; |
|
- | 63 | uint16_t subdevice_id; |
|
- | 64 | uint32_t device_class; |
|
- | 65 | uint8_t revision; |
|
Line 52... | Line 66... | ||
52 | #include "pci_ids/pci_id_driver_map.h" |
66 | }; |
53 | 67 | ||
54 | struct pipe_loader_drm_device { |
68 | struct pipe_loader_drm_device { |
55 | struct pipe_loader_device base; |
69 | struct pipe_loader_device base; |
Line 60... | Line 74... | ||
60 | #define pipe_loader_drm_device(dev) ((struct pipe_loader_drm_device *)dev) |
74 | #define pipe_loader_drm_device(dev) ((struct pipe_loader_drm_device *)dev) |
Line 61... | Line 75... | ||
61 | 75 | ||
62 | static boolean |
76 | static boolean |
63 | find_drm_pci_id(struct pipe_loader_drm_device *ddev) |
77 | find_drm_pci_id(struct pipe_loader_drm_device *ddev) |
64 | { |
78 | { |
65 | struct udev *udev = NULL; |
- | |
66 | struct udev_device *parent, *device = NULL; |
- | |
67 | struct stat stat; |
- | |
68 | const char *pci_id; |
- | |
69 | - | ||
70 | if (fstat(ddev->fd, &stat) < 0) |
- | |
71 | goto fail; |
- | |
72 | - | ||
73 | udev = udev_new(); |
- | |
74 | if (!udev) |
79 | struct pci_device device; |
Line -... | Line 80... | ||
- | 80 | ioctl_t io; |
|
75 | goto fail; |
81 | |
76 | 82 | io.handle = ddev->fd; |
|
- | 83 | io.io_code = SRV_GET_PCI_INFO; |
|
- | 84 | io.input = &device; |
|
77 | device = udev_device_new_from_devnum(udev, 'c', stat.st_rdev); |
85 | io.inp_size = sizeof(device); |
Line 78... | Line -... | ||
78 | if (!device) |
- | |
79 | goto fail; |
86 | io.output = NULL; |
80 | 87 | io.out_size = 0; |
|
Line 81... | Line -... | ||
81 | parent = udev_device_get_parent(device); |
- | |
82 | if (!parent) |
- | |
83 | goto fail; |
88 | |
84 | 89 | if (call_service(&io)!=0) |
|
85 | pci_id = udev_device_get_property_value(parent, "PCI_ID"); |
- | |
Line 86... | Line 90... | ||
86 | if (!pci_id || |
90 | return FALSE; |
87 | sscanf(pci_id, "%x:%x", &ddev->base.u.pci.vendor_id, |
- | |
88 | &ddev->base.u.pci.chip_id) != 2) |
- | |
89 | goto fail; |
- | |
90 | - | ||
91 | return TRUE; |
- | |
92 | - | ||
93 | fail: |
- | |
94 | if (device) |
- | |
95 | udev_device_unref(device); |
91 | |
Line 96... | Line 92... | ||
96 | if (udev) |
92 | ddev->base.u.pci.vendor_id = device.vendor_id; |
97 | udev_unref(udev); |
93 | ddev->base.u.pci.chip_id = device.device_id; |
98 | 94 | ||
Line 128... | Line 124... | ||
128 | return TRUE; |
124 | return TRUE; |
129 | } |
125 | } |
Line 130... | Line 126... | ||
130 | 126 | ||
Line 131... | Line -... | ||
131 | static struct pipe_loader_ops pipe_loader_drm_ops; |
- | |
132 | - | ||
133 | static void |
- | |
134 | pipe_loader_drm_x_auth(int fd) |
- | |
135 | { |
- | |
136 | #if HAVE_PIPE_LOADER_XCB |
- | |
137 | /* Try authenticate with the X server to give us access to devices that X |
- | |
138 | * is running on. */ |
- | |
139 | xcb_connection_t *xcb_conn; |
- | |
140 | const xcb_setup_t *xcb_setup; |
- | |
141 | xcb_screen_iterator_t s; |
- | |
142 | xcb_dri2_connect_cookie_t connect_cookie; |
- | |
143 | xcb_dri2_connect_reply_t *connect; |
- | |
144 | drm_magic_t magic; |
- | |
145 | xcb_dri2_authenticate_cookie_t authenticate_cookie; |
- | |
146 | xcb_dri2_authenticate_reply_t *authenticate; |
- | |
147 | - | ||
148 | xcb_conn = xcb_connect(NULL, NULL); |
- | |
149 | - | ||
150 | if(!xcb_conn) |
- | |
151 | return; |
- | |
152 | - | ||
153 | xcb_setup = xcb_get_setup(xcb_conn); |
- | |
154 | - | ||
155 | if (!xcb_setup) |
- | |
156 | goto disconnect; |
- | |
157 | - | ||
158 | s = xcb_setup_roots_iterator(xcb_setup); |
- | |
159 | connect_cookie = xcb_dri2_connect_unchecked(xcb_conn, s.data->root, |
- | |
160 | XCB_DRI2_DRIVER_TYPE_DRI); |
- | |
161 | connect = xcb_dri2_connect_reply(xcb_conn, connect_cookie, NULL); |
- | |
162 | - | ||
163 | if (!connect || connect->driver_name_length |
- | |
164 | + connect->device_name_length == 0) { |
- | |
165 | - | ||
166 | goto disconnect; |
- | |
167 | } |
- | |
168 | - | ||
169 | if (drmGetMagic(fd, &magic)) |
- | |
170 | goto disconnect; |
- | |
171 | - | ||
172 | authenticate_cookie = xcb_dri2_authenticate_unchecked(xcb_conn, |
- | |
173 | s.data->root, |
- | |
174 | magic); |
- | |
175 | authenticate = xcb_dri2_authenticate_reply(xcb_conn, |
- | |
176 | authenticate_cookie, |
- | |
177 | NULL); |
- | |
178 | FREE(authenticate); |
- | |
179 | - | ||
180 | disconnect: |
- | |
181 | xcb_disconnect(xcb_conn); |
- | |
182 | - | ||
Line 183... | Line 127... | ||
183 | #endif |
127 | static struct pipe_loader_ops pipe_loader_drm_ops; |
184 | } |
128 | |
185 | 129 | ||
186 | boolean |
130 | boolean |
Line 187... | Line 131... | ||
187 | pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd) |
131 | pipe_loader_drm_probe_fd(struct pipe_loader_device **dev, int fd) |
188 | { |
132 | { |
189 | struct pipe_loader_drm_device *ddev = CALLOC_STRUCT(pipe_loader_drm_device); |
133 | struct pipe_loader_drm_device *ddev = CALLOC_STRUCT(pipe_loader_drm_device); |
Line 190... | Line -... | ||
190 | - | ||
191 | ddev->base.type = PIPE_LOADER_DEVICE_PCI; |
- | |
192 | ddev->base.ops = &pipe_loader_drm_ops; |
134 | |
193 | ddev->fd = fd; |
135 | ddev->base.type = PIPE_LOADER_DEVICE_PCI; |
Line 194... | Line 136... | ||
194 | 136 | ddev->base.ops = &pipe_loader_drm_ops; |
|
195 | pipe_loader_drm_x_auth(fd); |
137 | ddev->fd = fd; |
Line 206... | Line 148... | ||
206 | fail: |
148 | fail: |
207 | FREE(ddev); |
149 | FREE(ddev); |
208 | return FALSE; |
150 | return FALSE; |
209 | } |
151 | } |
Line 210... | Line -... | ||
210 | - | ||
211 | static int |
- | |
212 | open_drm_minor(int minor) |
- | |
213 | { |
- | |
214 | char path[PATH_MAX]; |
- | |
215 | snprintf(path, sizeof(path), DRM_DEV_NAME, DRM_DIR_NAME, minor); |
- | |
216 | return open(path, O_RDWR, 0); |
- | |
Line 217... | Line 152... | ||
217 | } |
152 | |
218 | 153 | ||
219 | int |
154 | int |
220 | pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev) |
155 | pipe_loader_drm_probe(struct pipe_loader_device **devs, int ndev) |
Line 221... | Line 156... | ||
221 | { |
156 | { |
222 | int i, j, fd; |
157 | int i, j, fd; |
223 | 158 | ||
224 | for (i = 0, j = 0; i < DRM_MAX_MINOR; i++) { |
159 | for (i = 0, j = 0; i < 1; i++) { |
Line 225... | Line 160... | ||
225 | fd = open_drm_minor(i); |
160 | fd = get_service("DISPLAY"); |
226 | if (fd < 0) |
161 | if (fd == 0) |
Line 227... | Line 162... | ||
227 | continue; |
162 | continue; |
228 | 163 | ||
Line 229... | Line 164... | ||
229 | if (j >= ndev || !pipe_loader_drm_probe_fd(&devs[j], fd)) |
164 | if (j >= ndev || !pipe_loader_drm_probe_fd(&devs[j], fd)) |
Line 238... | Line 173... | ||
238 | static void |
173 | static void |
239 | pipe_loader_drm_release(struct pipe_loader_device **dev) |
174 | pipe_loader_drm_release(struct pipe_loader_device **dev) |
240 | { |
175 | { |
241 | struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(*dev); |
176 | struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(*dev); |
Line 242... | Line -... | ||
242 | - | ||
243 | if (ddev->lib) |
- | |
244 | util_dl_close(ddev->lib); |
- | |
245 | - | ||
246 | close(ddev->fd); |
177 | |
247 | FREE(ddev); |
178 | FREE(ddev); |
248 | *dev = NULL; |
179 | *dev = NULL; |
Line 249... | Line 180... | ||
249 | } |
180 | } |