loader: Look for any version of currently linked libudev.so
[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(struct udev_list_entry *, udev_list_entry_get_next,
277 (struct udev_list_entry *));
278 UDEV_SYMBOL(const char *, udev_list_entry_get_name,
279 (struct udev_list_entry *));
280 UDEV_SYMBOL(struct udev_device *, udev_device_new_from_syspath,
281 (struct udev *, const char *));
282 UDEV_SYMBOL(const char *, udev_device_get_property_value,
283 (struct udev_device *, const char *));
284 UDEV_SYMBOL(const char *, udev_device_get_devnode,
285 (struct udev_device *));
286 UDEV_SYMBOL(struct udev_device *, udev_device_unref,
287 (struct udev_device *));
288
289 e = udev_enumerate_new(udev);
290 udev_enumerate_add_match_subsystem(e, "drm");
291 udev_enumerate_add_match_sysname(e, "render*");
292
293 udev_enumerate_scan_devices(e);
294 udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
295 path = udev_list_entry_get_name(entry);
296 device = udev_device_new_from_syspath(udev, path);
297 if (!device)
298 continue;
299 id_path_tag_tmp = udev_device_get_property_value(device, "ID_PATH_TAG");
300 if (id_path_tag_tmp) {
301 if ((!another_tag && !strcmp(id_path_tag, id_path_tag_tmp)) ||
302 (another_tag && strcmp(id_path_tag, id_path_tag_tmp))) {
303 found = 1;
304 break;
305 }
306 }
307 udev_device_unref(device);
308 }
309
310 if (found) {
311 path_res = strdup(udev_device_get_devnode(device));
312 udev_device_unref(device);
313 return path_res;
314 }
315 return NULL;
316 }
317
318 static char *
319 get_id_path_tag_from_fd(struct udev *udev, int fd)
320 {
321 struct udev_device *device;
322 const char *id_path_tag_tmp;
323 char *id_path_tag;
324 UDEV_SYMBOL(const char *, udev_device_get_property_value,
325 (struct udev_device *, const char *));
326 UDEV_SYMBOL(struct udev_device *, udev_device_unref,
327 (struct udev_device *));
328
329 device = udev_device_new_from_fd(udev, fd);
330 if (!device)
331 return NULL;
332
333 id_path_tag_tmp = udev_device_get_property_value(device, "ID_PATH_TAG");
334 if (!id_path_tag_tmp)
335 return NULL;
336
337 id_path_tag = strdup(id_path_tag_tmp);
338
339 udev_device_unref(device);
340 return id_path_tag;
341 }
342
343 #ifdef USE_DRICONF
344 const char __driConfigOptionsLoader[] =
345 DRI_CONF_BEGIN
346 DRI_CONF_SECTION_INITIALIZATION
347 DRI_CONF_DEVICE_ID_PATH_TAG()
348 DRI_CONF_SECTION_END
349 DRI_CONF_END;
350 #endif
351
352 int loader_get_user_preferred_fd(int default_fd, int *different_device)
353 {
354 struct udev *udev;
355 #ifdef USE_DRICONF
356 driOptionCache defaultInitOptions;
357 driOptionCache userInitOptions;
358 #endif
359 const char *dri_prime = getenv("DRI_PRIME");
360 char *prime = NULL;
361 int is_different_device = 0, fd = default_fd;
362 char *default_device_id_path_tag;
363 char *device_name = NULL;
364 char another_tag = 0;
365 UDEV_SYMBOL(struct udev *, udev_new, (void));
366 UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));
367
368 if (dri_prime)
369 prime = strdup(dri_prime);
370 #ifdef USE_DRICONF
371 else {
372 driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
373 driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader");
374 if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
375 prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
376 driDestroyOptionCache(&userInitOptions);
377 driDestroyOptionInfo(&defaultInitOptions);
378 }
379 #endif
380
381 if (prime == NULL) {
382 *different_device = 0;
383 return default_fd;
384 }
385
386 udev = udev_new();
387 if (!udev)
388 goto prime_clean;
389
390 default_device_id_path_tag = get_id_path_tag_from_fd(udev, default_fd);
391 if (!default_device_id_path_tag)
392 goto udev_clean;
393
394 is_different_device = 1;
395 /* two format are supported:
396 * "1": choose any other card than the card used by default.
397 * id_path_tag: (for example "pci-0000_02_00_0") choose the card
398 * with this id_path_tag.
399 */
400 if (!strcmp(prime,"1")) {
401 free(prime);
402 prime = strdup(default_device_id_path_tag);
403 /* request a card with a different card than the default card */
404 another_tag = 1;
405 } else if (!strcmp(default_device_id_path_tag, prime))
406 /* we are to get a new fd (render-node) of the same device */
407 is_different_device = 0;
408
409 device_name = get_render_node_from_id_path_tag(udev,
410 prime,
411 another_tag);
412 if (device_name == NULL) {
413 is_different_device = 0;
414 goto default_device_clean;
415 }
416
417 fd = loader_open_device(device_name);
418 if (fd >= 0) {
419 close(default_fd);
420 } else {
421 fd = default_fd;
422 is_different_device = 0;
423 }
424 free(device_name);
425
426 default_device_clean:
427 free(default_device_id_path_tag);
428 udev_clean:
429 udev_unref(udev);
430 prime_clean:
431 free(prime);
432
433 *different_device = is_different_device;
434 return fd;
435 }
436 #else
437 int loader_get_user_preferred_fd(int default_fd, int *different_device)
438 {
439 *different_device = 0;
440 return default_fd;
441 }
442 #endif
443
444 #if defined(HAVE_SYSFS)
445 static int
446 dev_node_from_fd(int fd, unsigned int *maj, unsigned int *min)
447 {
448 struct stat buf;
449
450 if (fstat(fd, &buf) < 0) {
451 log_(_LOADER_WARNING, "MESA-LOADER: failed to stat fd %d\n", fd);
452 return -1;
453 }
454
455 if (!S_ISCHR(buf.st_mode)) {
456 log_(_LOADER_WARNING, "MESA-LOADER: fd %d not a character device\n", fd);
457 return -1;
458 }
459
460 *maj = major(buf.st_rdev);
461 *min = minor(buf.st_rdev);
462
463 return 0;
464 }
465
466 static int
467 sysfs_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
468 {
469 unsigned int maj, min;
470 FILE *f;
471 char buf[0x40];
472
473 if (dev_node_from_fd(fd, &maj, &min) < 0) {
474 *chip_id = -1;
475 return 0;
476 }
477
478 snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/vendor", maj, min);
479 if (!(f = fopen(buf, "r"))) {
480 *chip_id = -1;
481 return 0;
482 }
483 if (fscanf(f, "%x", vendor_id) != 1) {
484 *chip_id = -1;
485 fclose(f);
486 return 0;
487 }
488 fclose(f);
489 snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/device/device", maj, min);
490 if (!(f = fopen(buf, "r"))) {
491 *chip_id = -1;
492 return 0;
493 }
494 if (fscanf(f, "%x", chip_id) != 1) {
495 *chip_id = -1;
496 fclose(f);
497 return 0;
498 }
499 fclose(f);
500 return 1;
501 }
502 #endif
503
504 #if !defined(__NOT_HAVE_DRM_H)
505 /* for i915 */
506 #include <i915_drm.h>
507 /* for radeon */
508 #include <radeon_drm.h>
509
510 static int
511 drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
512 {
513 drmVersionPtr version;
514
515 *chip_id = -1;
516
517 version = drmGetVersion(fd);
518 if (!version) {
519 log_(_LOADER_WARNING, "MESA-LOADER: invalid drm fd\n");
520 return 0;
521 }
522 if (!version->name) {
523 log_(_LOADER_WARNING, "MESA-LOADER: unable to determine the driver name\n");
524 drmFreeVersion(version);
525 return 0;
526 }
527
528 if (strcmp(version->name, "i915") == 0) {
529 struct drm_i915_getparam gp;
530 int ret;
531
532 *vendor_id = 0x8086;
533
534 memset(&gp, 0, sizeof(gp));
535 gp.param = I915_PARAM_CHIPSET_ID;
536 gp.value = chip_id;
537 ret = drmCommandWriteRead(fd, DRM_I915_GETPARAM, &gp, sizeof(gp));
538 if (ret) {
539 log_(_LOADER_WARNING, "MESA-LOADER: failed to get param for i915\n");
540 *chip_id = -1;
541 }
542 }
543 else if (strcmp(version->name, "radeon") == 0) {
544 struct drm_radeon_info info;
545 int ret;
546
547 *vendor_id = 0x1002;
548
549 memset(&info, 0, sizeof(info));
550 info.request = RADEON_INFO_DEVICE_ID;
551 info.value = (unsigned long) chip_id;
552 ret = drmCommandWriteRead(fd, DRM_RADEON_INFO, &info, sizeof(info));
553 if (ret) {
554 log_(_LOADER_WARNING, "MESA-LOADER: failed to get info for radeon\n");
555 *chip_id = -1;
556 }
557 }
558 else if (strcmp(version->name, "nouveau") == 0) {
559 *vendor_id = 0x10de;
560 /* not used */
561 *chip_id = 0;
562 }
563 else if (strcmp(version->name, "vmwgfx") == 0) {
564 *vendor_id = 0x15ad;
565 /* assume SVGA II */
566 *chip_id = 0x0405;
567 }
568
569 drmFreeVersion(version);
570
571 return (*chip_id >= 0);
572 }
573 #endif
574
575
576 int
577 loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
578 {
579 #if HAVE_LIBUDEV
580 if (libudev_get_pci_id_for_fd(fd, vendor_id, chip_id))
581 return 1;
582 #endif
583 #if HAVE_SYSFS
584 if (sysfs_get_pci_id_for_fd(fd, vendor_id, chip_id))
585 return 1;
586 #endif
587 #if !defined(__NOT_HAVE_DRM_H)
588 if (drm_get_pci_id_for_fd(fd, vendor_id, chip_id))
589 return 1;
590 #endif
591 return 0;
592 }
593
594
595 #ifdef HAVE_LIBUDEV
596 static char *
597 libudev_get_device_name_for_fd(int fd)
598 {
599 char *device_name = NULL;
600 struct udev *udev;
601 struct udev_device *device;
602 const char *const_device_name;
603 UDEV_SYMBOL(struct udev *, udev_new, (void));
604 UDEV_SYMBOL(const char *, udev_device_get_devnode,
605 (struct udev_device *));
606 UDEV_SYMBOL(struct udev_device *, udev_device_unref,
607 (struct udev_device *));
608 UDEV_SYMBOL(struct udev *, udev_unref, (struct udev *));
609
610 if (dlsym_failed)
611 return NULL;
612
613 udev = udev_new();
614 device = udev_device_new_from_fd(udev, fd);
615 if (device == NULL)
616 return NULL;
617
618 const_device_name = udev_device_get_devnode(device);
619 if (!const_device_name)
620 goto out;
621 device_name = strdup(const_device_name);
622
623 out:
624 udev_device_unref(device);
625 udev_unref(udev);
626 return device_name;
627 }
628 #endif
629
630
631 #if HAVE_SYSFS
632 static char *
633 sysfs_get_device_name_for_fd(int fd)
634 {
635 char *device_name = NULL;
636 unsigned int maj, min;
637 FILE *f;
638 char buf[0x40];
639 static const char match[9] = "\0DEVNAME=";
640 int expected = 1;
641
642 if (dev_node_from_fd(fd, &maj, &min) < 0)
643 return NULL;
644
645 snprintf(buf, sizeof(buf), "/sys/dev/char/%d:%d/uevent", maj, min);
646 if (!(f = fopen(buf, "r")))
647 return NULL;
648
649 while (expected < sizeof(match)) {
650 int c = getc(f);
651
652 if (c == EOF) {
653 fclose(f);
654 return NULL;
655 } else if (c == match[expected] )
656 expected++;
657 else
658 expected = 0;
659 }
660
661 strcpy(buf, "/dev/");
662 if (fgets(buf + 5, sizeof(buf) - 5, f))
663 device_name = strdup(buf);
664
665 fclose(f);
666 return device_name;
667 }
668 #endif
669
670
671 char *
672 loader_get_device_name_for_fd(int fd)
673 {
674 char *result = NULL;
675
676 #if HAVE_LIBUDEV
677 if ((result = libudev_get_device_name_for_fd(fd)))
678 return result;
679 #endif
680 #if HAVE_SYSFS
681 if ((result = sysfs_get_device_name_for_fd(fd)))
682 return result;
683 #endif
684 return result;
685 }
686
687 char *
688 loader_get_driver_for_fd(int fd, unsigned driver_types)
689 {
690 int vendor_id, chip_id, i, j;
691 char *driver = NULL;
692
693 if (!driver_types)
694 driver_types = _LOADER_GALLIUM | _LOADER_DRI;
695
696 if (!loader_get_pci_id_for_fd(fd, &vendor_id, &chip_id)) {
697
698 #ifndef __NOT_HAVE_DRM_H
699 /* fallback to drmGetVersion(): */
700 drmVersionPtr version = drmGetVersion(fd);
701
702 if (!version) {
703 log_(_LOADER_WARNING, "failed to get driver name for fd %d\n", fd);
704 return NULL;
705 }
706
707 driver = strndup(version->name, version->name_len);
708 log_(_LOADER_INFO, "using driver %s for %d\n", driver, fd);
709
710 drmFreeVersion(version);
711 #endif
712
713 return driver;
714 }
715
716 for (i = 0; driver_map[i].driver; i++) {
717 if (vendor_id != driver_map[i].vendor_id)
718 continue;
719
720 if (!(driver_types & driver_map[i].driver_types))
721 continue;
722
723 if (driver_map[i].predicate && !driver_map[i].predicate(fd))
724 continue;
725
726 if (driver_map[i].num_chips_ids == -1) {
727 driver = strdup(driver_map[i].driver);
728 goto out;
729 }
730
731 for (j = 0; j < driver_map[i].num_chips_ids; j++)
732 if (driver_map[i].chip_ids[j] == chip_id) {
733 driver = strdup(driver_map[i].driver);
734 goto out;
735 }
736 }
737
738 out:
739 log_(driver ? _LOADER_DEBUG : _LOADER_WARNING,
740 "pci id for fd %d: %04x:%04x, driver %s\n",
741 fd, vendor_id, chip_id, driver);
742 return driver;
743 }
744
745 void
746 loader_set_logger(void (*logger)(int level, const char *fmt, ...))
747 {
748 log_ = logger;
749 }