]>
git.ipfire.org Git - thirdparty/pciutils.git/blob - lib/init.c
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
60 #ifdef PCI_HAVE_PM_DARWIN_DEVICE
68 pci_malloc(struct pci_access
*a
, int size
)
70 void *x
= malloc(size
);
73 a
->error("Out of memory (allocation of %d bytes failed)", size
);
85 pci_strdup(struct pci_access
*a
, const char *s
)
87 int len
= strlen(s
) + 1;
88 char *t
= pci_malloc(a
, len
);
94 pci_generic_error(char *msg
, ...)
99 fputs("pcilib: ", stderr
);
100 vfprintf(stderr
, msg
, args
);
106 pci_generic_warn(char *msg
, ...)
111 fputs("pcilib: ", stderr
);
112 vfprintf(stderr
, msg
, args
);
117 pci_generic_debug(char *msg
, ...)
122 vfprintf(stdout
, msg
, args
);
127 pci_null_debug(char *msg UNUSED
, ...)
132 pci_lookup_method(char *name
)
136 for (i
=0; i
<PCI_ACCESS_MAX
; i
++)
137 if (pci_methods
[i
] && !strcmp(pci_methods
[i
]->name
, name
))
143 pci_get_method_name(int index
)
145 if (index
< 0 || index
>= PCI_ACCESS_MAX
)
147 else if (!pci_methods
[index
])
150 return pci_methods
[index
]->name
;
156 struct pci_access
*a
= malloc(sizeof(struct pci_access
));
159 memset(a
, 0, sizeof(*a
));
160 pci_set_name_list_path(a
, PCI_PATH_IDS_DIR
"/" PCI_IDS
, 0);
162 pci_define_param(a
, "net.domain", PCI_ID_DOMAIN
, "DNS domain used for resolving of ID's");
163 pci_define_param(a
, "net.cache_name", "~/.pciids-cache", "Name of the ID cache file");
164 a
->id_lookup_mode
= PCI_LOOKUP_CACHE
;
167 pci_define_param(a
, "hwdb.disable", "0", "Do not look up names in UDEV's HWDB if non-zero");
169 for (i
=0; i
<PCI_ACCESS_MAX
; i
++)
170 if (pci_methods
[i
] && pci_methods
[i
]->config
)
171 pci_methods
[i
]->config(a
);
176 pci_init_v34(struct pci_access
*a
)
179 a
->error
= pci_generic_error
;
181 a
->warning
= pci_generic_warn
;
183 a
->debug
= pci_generic_debug
;
185 a
->debug
= pci_null_debug
;
189 if (a
->method
>= PCI_ACCESS_MAX
|| !pci_methods
[a
->method
])
190 a
->error("This access method is not supported.");
191 a
->methods
= pci_methods
[a
->method
];
196 for (i
=0; i
<PCI_ACCESS_MAX
; i
++)
199 a
->debug("Trying method %d...", i
);
200 if (pci_methods
[i
]->detect(a
))
203 a
->methods
= pci_methods
[i
];
207 a
->debug("...No.\n");
210 a
->error("Cannot find any working access method.");
212 a
->debug("Decided to use %s\n", a
->methods
->name
);
216 STATIC_ALIAS(void pci_init(struct pci_access
*a
), pci_init_v34(a
));
217 SYMBOL_VERSION(pci_init_v34
, pci_init@@LIBPCI_3
.4
);
220 pci_cleanup(struct pci_access
*a
)
222 struct pci_dev
*d
, *e
;
224 for (d
=a
->devices
; d
; d
=e
)
230 a
->methods
->cleanup(a
);
231 pci_free_name_list(a
);
233 pci_set_name_list_path(a
, NULL
, 0);