2 * The PCI Library -- Initialization and related things
4 * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
16 static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {
18 #ifdef PCI_HAVE_PM_LINUX_SYSFS
23 #ifdef PCI_HAVE_PM_LINUX_PROC
28 #ifdef PCI_HAVE_PM_INTEL_CONF
35 #ifdef PCI_HAVE_PM_FBSD_DEVICE
40 #ifdef PCI_HAVE_PM_AIX_DEVICE
45 #ifdef PCI_HAVE_PM_NBSD_LIBPCI
50 #ifdef PCI_HAVE_PM_OBSD_DEVICE
55 #ifdef PCI_HAVE_PM_DUMP
65 struct pci_access *a = malloc(sizeof(struct pci_access));
68 memset(a, 0, sizeof(*a));
69 pci_set_name_list_path(a, PCI_PATH_IDS_DIR "/" PCI_IDS, 0);
70 pci_set_net_domain(a, PCI_ID_DOMAIN, 0);
71 a->id_lookup_mode = PCI_LOOKUP_CACHE;
72 for(i=0; i<PCI_ACCESS_MAX; i++)
73 if (pci_methods[i] && pci_methods[i]->config)
74 pci_methods[i]->config(a);
79 pci_malloc(struct pci_access *a, int size)
81 void *x = malloc(size);
84 a->error("Out of memory (allocation of %d bytes failed)", size);
96 pci_generic_error(char *msg, ...)
101 fputs("pcilib: ", stderr);
102 vfprintf(stderr, msg, args);
108 pci_generic_warn(char *msg, ...)
113 fputs("pcilib: ", stderr);
114 vfprintf(stderr, msg, args);
119 pci_generic_debug(char *msg, ...)
124 vfprintf(stdout, msg, args);
129 pci_null_debug(char *msg UNUSED, ...)
134 pci_init(struct pci_access *a)
137 a->error = pci_generic_error;
139 a->warning = pci_generic_warn;
141 a->debug = pci_generic_debug;
143 a->debug = pci_null_debug;
147 if (a->method >= PCI_ACCESS_MAX || !pci_methods[a->method])
148 a->error("This access method is not supported.");
149 a->methods = pci_methods[a->method];
154 for(i=0; i<PCI_ACCESS_MAX; i++)
157 a->debug("Trying method %d...", i);
158 if (pci_methods[i]->detect(a))
161 a->methods = pci_methods[i];
165 a->debug("...No.\n");
168 a->error("Cannot find any working access method.");
170 a->debug("Decided to use %s\n", a->methods->name);
175 pci_cleanup(struct pci_access *a)
177 struct pci_dev *d, *e;
179 for(d=a->devices; d; d=e)
185 a->methods->cleanup(a);
186 pci_free_name_list(a);
187 pci_set_name_list_path(a, NULL, 0);
188 pci_set_net_domain(a, NULL, 0);
189 pci_set_id_cache(a, NULL, 0);