8da1858734ac11428e58b185a82dc94c2667efc4
[mesa.git] / src / loader / loader.c
1 /*
2 * Copyright (C) 2013 Rob Clark <robclark@freedesktop.org>
3 *
4 * This code is derived from the following files.
5 *
6 * * src/glx/dri3_common.c
7 * Copyright © 2013 Keith Packard
8 *
9 * * src/egl/drivers/dri2/common.c
10 * * src/gbm/backends/dri/driver_name.c
11 * Copyright © 2011 Intel Corporation
12 *
13 * Authors:
14 * Kristian Høgsberg <krh@bitplanet.net>
15 * Benjamin Franzke <benjaminfranzke@googlemail.com>
16 *
17 * * src/gallium/targets/egl-static/egl.c
18 * Copyright (C) 2010-2011 LunarG Inc.
19 *
20 * Authors:
21 * Chia-I Wu <olv@lunarg.com>
22 *
23 * * src/gallium/state_trackers/egl/drm/native_drm.c
24 * Copyright (C) 2010 Chia-I Wu <olv@0xlab.org>
25 *
26 * * src/egl/drivers/dri2/platform_android.c
27 *
28 * Copyright (C) 2010-2011 Chia-I Wu <olvaffe@gmail.com>
29 * Copyright (C) 2010-2011 LunarG Inc.
30 *
31 * Based on platform_x11, which has
32 *
33 * Copyright © 2011 Intel Corporation
34 *
35 * * src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
36 * Copyright 2011 Intel Corporation
37 * Copyright 2012 Francisco Jerez
38 * All Rights Reserved.
39 *
40 * Authors:
41 * Kristian Høgsberg <krh@bitplanet.net>
42 * Benjamin Franzke <benjaminfranzke@googlemail.com>
43 *
44 * Permission is hereby granted, free of charge, to any person obtaining a
45 * copy of this software and associated documentation files (the "Software"),
46 * to deal in the Software without restriction, including without limitation
47 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
48 * and/or sell copies of the Software, and to permit persons to whom the
49 * Software is furnished to do so, subject to the following conditions:
50 *
51 * The above copyright notice and this permission notice (including the next
52 * paragraph) shall be included in all copies or substantial portions of the
53 * Software.
54 *
55 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
58 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61 * SOFTWARE.
62 *
63 * Authors:
64 * Rob Clark <robclark@freedesktop.org>
65 */
66
67 #include <errno.h>
68 #include <fcntl.h>
69 #include <sys/stat.h>
70 #include <stdarg.h>
71 #include <stdio.h>
72 #include <string.h>
73 #ifdef HAVE_LIBUDEV
74 #include <assert.h>
75 #include <dlfcn.h>
76 #include <unistd.h>
77 #include <stdlib.h>
78 #ifdef USE_DRICONF
79 #include "xmlconfig.h"
80 #include "xmlpool.h"
81 #endif
82 #endif
83 #ifdef HAVE_SYSFS
84 #include <sys/types.h>
85 #endif
86 #include "loader.h"
87
88 #ifndef __NOT_HAVE_DRM_H
89 #include <xf86drm.h>
90 #endif
91
92 #define __IS_LOADER
93 #include "pci_id_driver_map.h"
94
95 static void default_logger(int level, const char *fmt, ...)
96 {
97 if (level <= _LOADER_WARNING) {
98 va_list args;
99 va_start(args, fmt);
100 vfprintf(stderr, fmt, args);
101 va_end(args);
102 }
103 }
104
105 static void (*log_)(int level, const char *fmt, ...) = default_logger;
106
107 int
108 loader_open_device(const char *device_name)
109 {
110 int fd;
111 #ifdef O_CLOEXEC
112 fd = open(device_name, O_RDWR | O_CLOEXEC);
113 if (fd == -1 && errno == EINVAL)
114 #endif
115 {
116 fd = open(device_name, O_RDWR);
117 if (fd != -1)
118 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
119 }
120 return fd;
121 }
122
123 #ifdef HAVE_LIBUDEV
124 #include <libudev.h>
125
126 static void *udev_handle = NULL;
127
128 static void *
129 udev_dlopen_handle(void)
130 {
131 char name[80];
132 unsigned flags = RTLD_NOLOAD | RTLD_LOCAL | RTLD_LAZY;
133 int version;
134
135 /* libudev.so.1 changed the return types of the two unref functions
136 * from voids to pointers. We don't use those return values, and the
137 * only ABI I've heard that cares about this kind of change (calling
138 * a function with a void * return that actually only returns void)
139 * might be ia64.
140 */
141
142 /* First try opening an already linked libudev, then try loading one */
143 do {
144 for (version = 1; version >= 0; version--) {
145 snprintf(name, sizeof(name), "libudev.so.%d", version);
146 udev_handle = dlopen(name, flags);
147 if (udev_handle)
148 return udev_handle;
149 }
150
151 if ((flags & RTLD_NOLOAD) == 0)
152 break;
153
154 flags &= ~RTLD_NOLOAD;
155 } while (1);
156
157 log_(_LOADER_WARNING,
158 "Couldn't dlopen libudev.so.1 or "
159 "libudev.so.0, driver detection may be broken.\n");
160 return NULL;
161 }
162
163 static int dlsym_failed = 0;
164
165 static void *
166 checked_dlsym(void *dlopen_handle, const char *name)
167 {
168 void *result = dlsym(dlopen_handle, name);
169 if (!result)
170 dlsym_failed = 1;
171 return result;
172 }
173
174 #define UDEV_SYMBOL(ret, name, args) \
175 ret (*name) args = checked_dlsym(udev_dlopen_handle(), #name);
176
177
178 static inline struct udev_device *
179 udev_device_new_from_fd(struct udev *udev, int fd)
180 {
181 struct udev_device *device;
182 struct stat buf;
183 UDEV_SYMBOL(struct udev_device *, udev_device_new_from_devnum,
184 (struct udev *udev, char type, dev_t devnum));
185
186 if (dlsym_failed)
187 return NULL;
188
189 if (fstat(fd, &buf) < 0) {
190 log_(_LOADER_WARNING, "MESA-LOADER: failed to stat fd %d\n", fd);
191 return NULL;
192 }
193
194 device = udev_device_new_from_devnum(udev, 'c', buf.st_rdev);
195 if (device == NULL) {
196 log_(_LOADER_WARNING,
197 "MESA-LOADER: could not create udev device for fd %d\n", fd);
198 return NULL;
199 }
200
201 return device;
202 }
203
204 static int
205 libudev_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
206 {
207 struct udev *udev = NULL;
208 struct udev_device *device = NULL, *parent;
209 const char *pci_id;
210 UDEV_SYMBOL(struct udev *, udev_new, (void));
211 UDEV_SYMBOL(struct udev_device *, udev_device_get_parent,
212 (struct udev_device *));
213 UDEV_SYMBOL(const char *, udev_device_get_property_value,
214 (struct udev_device *, const char *));
215 UDEV_SYMBOL(struct udev_device *, udev_device_unref,
216 (struct udev_device *));
217 UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));
218
219 *chip_id = -1;
220
221 if (dlsym_failed)
222 return 0;
223
224 udev = udev_new();
225 device = udev_device_new_from_fd(udev, fd);
226 if (!device)
227 goto out;
228
229 parent = udev_device_get_parent(device);
230 if (parent == NULL) {
231 log_(_LOADER_WARNING, "MESA-LOADER: could not get parent device\n");
232 goto out;
233 }
234
235 pci_id = udev_device_get_property_value(parent, "PCI_ID");
236 if (pci_id == NULL) {
237 log_(_LOADER_INFO, "MESA-LOADER: no PCI ID\n");
238 *chip_id = -1;
239 goto out;
240 } else if (sscanf(pci_id, "%x:%x", vendor_id, chip_id) != 2) {
241 log_(_LOADER_WARNING, "MESA-LOADER: malformed PCI ID\n");
242 *chip_id = -1;
243 goto out;
244 }
245
246 out:
247 if (device)
248 udev_device_unref(device);
249 if (udev)
250 udev_unref(udev);
251
252 return (*chip_id >= 0);
253 }
254
255 static char *
256 get_render_node_from_id_path_tag(struct udev *udev,
257 char *id_path_tag,
258 char another_tag)
259 {
260 struct udev_device *device;
261 struct udev_enumerate *e;
262 struct udev_list_entry *entry;
263 const char *path, *id_path_tag_tmp;
264 char *path_res;
265 char found = 0;
266 UDEV_SYMBOL(struct udev_enumerate *, udev_enumerate_new,
267 (struct udev *));
268 UDEV_SYMBOL(int, udev_enumerate_add_match_subsystem,
269 (struct udev_enumerate *, const char *));
270 UDEV_SYMBOL(int, udev_enumerate_add_match_sysname,
271 (struct udev_enumerate *, const char *));
272 UDEV_SYMBOL(int, udev_enumerate_scan_devices,
273 (struct udev_enumerate *));
274 UDEV_SYMBOL(struct udev_list_entry *, udev_enumerate_get_list_entry,
275 (struct udev_enumerate *));
276 UDEV_SYMBOL(void, udev_enumerate_unref,
277 (struct udev_enumerate *));
278 UDEV_SYMBOL(struct udev_list_entry *, udev_list_entry_get_next,
279 (struct udev_list_entry *));
280 UDEV_SYMBOL(const char *, udev_list_entry_get_name,
281 (struct udev_list_entry *));
282 UDEV_SYMBOL(struct udev_device *, udev_device_new_from_syspath,
283 (struct udev *, const char *));
284 UDEV_SYMBOL(const char *, udev_device_get_property_value,
285 (struct udev_device *, const char *));
286 UDEV_SYMBOL(const char *, udev_device_get_devnode,
287 (struct udev_device *));
288 UDEV_SYMBOL(struct udev_device *, udev_device_unref,
289 (struct udev_device *));
290
291 e = udev_enumerate_new(udev);
292 udev_enumerate_add_match_subsystem(e, "drm");
293 udev_enumerate_add_match_sysname(e, "render*");
294
295 udev_enumerate_scan_devices(e);
296 udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
297 path = udev_list_entry_get_name(entry);
298 device = udev_device_new_from_syspath(udev, path);
299 if (!device)
300 continue;
301 id_path_tag_tmp = udev_device_get_property_value(device, "ID_PATH_TAG");
302 if (id_path_tag_tmp) {
303 if ((!another_tag && !strcmp(id_path_tag, id_path_tag_tmp)) ||
304 (another_tag && strcmp(id_path_tag, id_path_tag_tmp))) {
305 found = 1;
306 break;
307 }
308 }
309 udev_device_unref(device);
310 }
311
312 udev_enumerate_unref(e);
313
314 if (found) {
315 path_res = strdup(udev_device_get_devnode(device));
316 udev_device_unref(device);
317 return path_res;
318 }
319 return NULL;
320 }
321
322 static char *
323 get_id_path_tag_from_fd(struct udev *udev, int fd)
324 {
325 struct udev_device *device;
326 const char *id_path_tag_tmp;
327 char *id_path_tag;
328 UDEV_SYMBOL(const char *, udev_device_get_property_value,
329 (struct udev_device *, const char *));
330 UDEV_SYMBOL(struct udev_device *, udev_device_unref,
331 (struct udev_device *));
332
333 device = udev_device_new_from_fd(udev, fd);
334 if (!device)
335 return NULL;
336
337 id_path_tag_tmp = udev_device_get_property_value(device, "ID_PATH_TAG");
338 if (!id_path_tag_tmp)
339 return NULL;
340
341 id_path_tag = strdup(id_path_tag_tmp);
342
343 udev_device_unref(device);
344 return id_path_tag;
345 }
346
347 #ifdef USE_DRICONF
348 const char __driConfigOptionsLoader[] =
349 DRI_CONF_BEGIN
350 DRI_CONF_SECTION_INITIALIZATION
351 DRI_CONF_DEVICE_ID_PATH_TAG()
352 DRI_CONF_SECTION_END
353 DRI_CONF_END;
354 #endif
355
356 int loader_get_user_preferred_fd(int default_fd, int *different_device)
357 {
358 struct udev *udev;
359 #ifdef USE_DRICONF
360 driOptionCache defaultInitOptions;
361 driOptionCache userInitOptions;
362 #endif
363 const char *dri_prime = getenv("DRI_PRIME");
364 char *prime = NULL;
365 int is_different_device = 0, fd = default_fd;
366 char *default_device_id_path_tag;
367 char *device_name = NULL;
368 char another_tag = 0;
369 UDEV_SYMBOL(struct udev *, udev_new, (void));
370 UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));
371
372 if (dri_prime)
373 prime = strdup(dri_prime);
374 #ifdef USE_DRICONF
375 else {
376 driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
377 driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader");
378 if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
379 prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
380 driDestroyOptionCache(&userInitOptions);
381 driDestroyOptionInfo(&defaultInitOptions);
382 }
383 #endif
384
385 if (prime == NULL) {
386 *different_device = 0;
387 return default_fd;
388 }
389
390 udev = udev_new();
391 if (!udev)
392 goto prime_clean;
393
394 default_device_id_path_tag = get_id_path_tag_from_fd(udev, default_fd);
395 if (!default_device_id_path_tag)
396 goto udev_clean;
397
398 is_different_device = 1;
399 /* two format are supported:
400 * "1": choose any other card than the card used by default.
401 * id_path_tag: (for example "pci-0000_02_00_0") choose the card
402 * with this id_path_tag.
403 */
404 if (!strcmp(prime,"1")) {
405 free(prime);
406 prime = strdup(default_device_id_path_tag);
407 /* request a card with a different card than the default card */
408 another_tag = 1;
409 } else if (!strcmp(default_device_id_path_tag, prime))
410 /* we are to get a new fd (render-node) of the same device */
411 is_different_device = 0;
412
413 device_name = get_render_node_from_id_path_tag(udev,
414 prime,
415 another_tag);
416 if (device_name == NULL) {
417 is_different_device = 0;
418 goto default_device_clean;
419 }
420
421 fd = loader_open_device(device_name);
422 if (fd >= 0) {
423 close(default_fd);
424 } else {
425 fd = default_fd;
426 is_different_device = 0;
427 }
428 free(device_name);
429
430 default_device_clean:
431 free(default_device_id_path_tag);
432 udev_clean:
433 udev_unref(udev);
434 prime_clean:
435 free(prime);
436
437 *different_device = is_different_device;
438 return fd;
439 }
440 #else
441 int loader_get_user_preferred_fd(int default_fd, int *different_device)
442 {
443 *different_device = 0;
444 return default_fd;
445 }
446 #endif
447
448 #if defined(HAVE_SYSFS)
449 static int
450 dev_node_from_fd(int fd, unsigned int *maj, unsigned int *min)
451 {
452 struct stat buf;
453
454 if (fstat(fd, &buf) < 0) {
455 log_(_LOADER_WARNING, "MESA-LOADER: failed to stat fd %d\n", fd);
456 return -1;
457 }
458
459 if (!S_ISCHR(buf.st_mode)) {
460 log_(_LOADER_WARNING, "MESA-LOADER: fd %d not a character device\n", fd);
461 return -1;
462 }
463
464 *maj = major(buf.st_rdev);
465 *min = minor(buf.st_rdev);
466
467 return 0;
468 }
469
470 static int
471 sysfs_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
472 {
473 unsigned int maj, min;
474 FILE *f;
475 char buf[0x40];
476
477 if (dev_node_from_fd(fd, &maj, &min) < 0) {
478 *chip_id = -1;
479 return 0;
480 }
481
482 snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/vendor", maj, min);
483 if (!(f = fopen(buf, "r"))) {
484 *chip_id = -1;
485 return 0;
486 }
487 if (fscanf(f, "%x", vendor_id) != 1) {
488 *chip_id = -1;
489 fclose(f);
490 return 0;
491 }
492 fclose(f);
493 snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/device", maj, min);
494 if (!(f = fopen(buf, "r"))) {
495 *chip_id = -1;
496 return 0;
497 }
498 if (fscanf(f, "%x", chip_id) != 1) {
499 *chip_id = -1;
500 fclose(f);
501 return 0;
502 }
503 fclose(f);
504 return 1;
505 }
506 #endif
507
508 #if !defined(__NOT_HAVE_DRM_H)
509 /* for i915 */
510 #include <i915_drm.h>
511 /* for radeon */
512 #include <radeon_drm.h>
513
514 static int
515 drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
516 {
517 drmVersionPtr version;
518
519 *chip_id = -1;
520
521 version = drmGetVersion(fd);
522 if (!version) {
523 log_(_LOADER_WARNING, "MESA-LOADER: invalid drm fd\n");
524 return 0;
525 }
526 if (!version->name) {
527 log_(_LOADER_WARNING, "MESA-LOADER: unable to determine the driver name\n");
528 drmFreeVersion(version);
529 return 0;
530 }
531
532 if (strcmp(version->name, "i915") == 0) {
533 struct drm_i915_getparam gp;
534 int ret;
535
536 *vendor_id = 0x8086;
537
538 memset(&gp, 0, sizeof(gp));
539 gp.param = I915_PARAM_CHIPSET_ID;
540 gp.value = chip_id;
541 ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
542 if (ret) {
543 log_(_LOADER_WARNING, "MESA-LOADER: failed to get param for i915\n");
544 *chip_id = -1;
545 }
546 }
547 else if (strcmp(version->name, "radeon") == 0) {
548 struct drm_radeon_info info;
549 int ret;
550
551 *vendor_id = 0x1002;
552
553 memset(&info, 0, sizeof(info));
554 info.request = RADEON_INFO_DEVICE_ID;
555 info.value = (unsigned long) chip_id;
556 ret = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
557 if (ret) {
558 log_(_LOADER_WARNING, "MESA-LOADER: failed to get info for radeon\n");
559 *chip_id = -1;
560 }
561 }
562 else if (strcmp(version->name, "nouveau") == 0) {
563 *vendor_id = 0x10de;
564 /* not used */
565 *chip_id = 0;
566 }
567 else if (strcmp(version->name, "vmwgfx") == 0) {
568 *vendor_id = 0x15ad;
569 /* assume SVGA II */
570 *chip_id = 0x0405;
571 }
572
573 drmFreeVersion(version);
574
575 return (*chip_id >= 0);
576 }
577 #endif
578
579
580 int
581 loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
582 {
583 #if HAVE_LIBUDEV
584 if (libudev_get_pci_id_for_fd(fd, vendor_id, chip_id))
585 return 1;
586 #endif
587 #if HAVE_SYSFS
588 if (sysfs_get_pci_id_for_fd(fd, vendor_id, chip_id))
589 return 1;
590 #endif
591 #if !defined(__NOT_HAVE_DRM_H)
592 if (drm_get_pci_id_for_fd(fd, vendor_id, chip_id))
593 return 1;
594 #endif
595 return 0;
596 }
597
598
599 #ifdef HAVE_LIBUDEV
600 static char *
601 libudev_get_device_name_for_fd(int fd)
602 {
603 char *device_name = NULL;
604 struct udev *udev;
605 struct udev_device *device;
606 const char *const_device_name;
607 UDEV_SYMBOL(struct udev *, udev_new, (void));
608 UDEV_SYMBOL(const char *, udev_device_get_devnode,
609 (struct udev_device *));
610 UDEV_SYMBOL(struct udev_device *, udev_device_unref,
611 (struct udev_device *));
612 UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));
613
614 if (dlsym_failed)
615 return NULL;
616
617 udev = udev_new();
618 device = udev_device_new_from_fd(udev, fd);
619 if (device == NULL)
620 return NULL;
621
622 const_device_name = udev_device_get_devnode(device);
623 if (!const_device_name)
624 goto out;
625 device_name = strdup(const_device_name);
626
627 out:
628 udev_device_unref(device);
629 udev_unref(udev);
630 return device_name;
631 }
632 #endif
633
634
635 #if HAVE_SYSFS
636 static char *
637 sysfs_get_device_name_for_fd(int fd)
638 {
639 char *device_name = NULL;
640 unsigned int maj, min;
641 FILE *f;
642 char buf[0x40];
643 static const char match[9] = "\0DEVNAME=";
644 int expected = 1;
645
646 if (dev_node_from_fd(fd, &maj, &min) < 0)
647 return NULL;
648
649 snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/uevent", maj, min);
650 if (!(f = fopen(buf, "r")))
651 return NULL;
652
653 while (expected < sizeof(match)) {
654 int c = getc(f);
655
656 if (c == EOF) {
657 fclose(f);
658 return NULL;
659 } else if (c == match[expected] )
660 expected++;
661 else
662 expected = 0;
663 }
664
665 strcpy(buf, "/dev/");
666 if (fgets(buf + 5, sizeof(buf) - 5, f))
667 device_name = strdup(buf);
668
669 fclose(f);
670 return device_name;
671 }
672 #endif
673
674
675 char *
676 loader_get_device_name_for_fd(int fd)
677 {
678 char *result = NULL;
679
680 #if HAVE_LIBUDEV
681 if ((result = libudev_get_device_name_for_fd(fd)))
682 return result;
683 #endif
684 #if HAVE_SYSFS
685 if ((result = sysfs_get_device_name_for_fd(fd)))
686 return result;
687 #endif
688 return result;
689 }
690
691 char *
692 loader_get_driver_for_fd(int fd, unsigned driver_types)
693 {
694 int vendor_id, chip_id, i, j;
695 char *driver = NULL;
696
697 if (!driver_types)
698 driver_types = _LOADER_GALLIUM | _LOADER_DRI;
699
700 if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
701
702 #ifndef __NOT_HAVE_DRM_H
703 /* fallback to drmGetVersion(): */
704 drmVersionPtr version = drmGetVersion(fd);
705
706 if (!version) {
707 log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
708 return NULL;
709 }
710
711 driver = strndup(version->name, version->name_len);
712 log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
713
714 drmFreeVersion(version);
715 #endif
716
717 return driver;
718 }
719
720 for (i = 0; driver_map[i].driver; i++) {
721 if (vendor_id != driver_map[i].vendor_id)
722 continue;
723
724 if (!(driver_types & driver_map[i].driver_types))
725 continue;
726
727 if (driver_map[i].predicate && !driver_map[i].predicate(fd))
728 continue;
729
730 if (driver_map[i].num_chips_ids == -1) {
731 driver = strdup(driver_map[i].driver);
732 goto out;
733 }
734
735 for (j = 0; j < driver_map[i].num_chips_ids; j++)
736 if (driver_map[i].chip_ids[j] == chip_id) {
737 driver = strdup(driver_map[i].driver);
738 goto out;
739 }
740 }
741
742 out:
743 log_(driver ? _LOADER_DEBUG : _LOADER_WARNING,
744 "pci id for fd %d: %04x:%04x, driver %s\n",
745 fd, vendor_id, chip_id, driver);
746 return driver;
747 }
748
749 void
750 loader_set_logger(void (*logger)(int level, const char *fmt, ...))
751 {
752 log_ = logger;
753 }