1 |
vapier 09/01/26 03:28:44 |
2 |
|
3 |
Modified: pcimodules-pciutils-3.0.0.patch |
4 |
Added: pcimodules.8 pcimodules.c |
5 |
Log: |
6 |
Split pcimodules files apart to share across versions. |
7 |
|
8 |
Revision Changes Path |
9 |
1.2 sys-apps/pciutils/files/pcimodules-pciutils-3.0.0.patch |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/pciutils/files/pcimodules-pciutils-3.0.0.patch?rev=1.2&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/pciutils/files/pcimodules-pciutils-3.0.0.patch?rev=1.2&content-type=text/plain |
13 |
diff : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/pciutils/files/pcimodules-pciutils-3.0.0.patch?r1=1.1&r2=1.2 |
14 |
|
15 |
Index: pcimodules-pciutils-3.0.0.patch |
16 |
=================================================================== |
17 |
RCS file: /var/cvsroot/gentoo-x86/sys-apps/pciutils/files/pcimodules-pciutils-3.0.0.patch,v |
18 |
retrieving revision 1.1 |
19 |
retrieving revision 1.2 |
20 |
diff -u -r1.1 -r1.2 |
21 |
--- pcimodules-pciutils-3.0.0.patch 13 Apr 2008 22:38:52 -0000 1.1 |
22 |
+++ pcimodules-pciutils-3.0.0.patch 26 Jan 2009 03:28:44 -0000 1.2 |
23 |
@@ -12,285 +12,3 @@ |
24 |
lspci.o: lspci.c pciutils.h $(PCIINC) |
25 |
setpci.o: setpci.c pciutils.h $(PCIINC) |
26 |
common.o: common.c pciutils.h $(PCIINC) |
27 |
---- pciutils-3.0.0/pcimodules.c |
28 |
-+++ pciutils-3.0.0/pcimodules.c |
29 |
-@@ -0,0 +1,184 @@ |
30 |
-+/* |
31 |
-+ * pcimodules: Load all kernel modules for PCI device currently |
32 |
-+ * plugged into any PCI slot. |
33 |
-+ * |
34 |
-+ * Copyright 2000 Yggdrasil Computing, Incorporated |
35 |
-+ * This file may be copied under the terms and conditions of version |
36 |
-+ * two of the GNU General Public License, as published by the Free |
37 |
-+ * Software Foundation (Cambridge, Massachusetts, USA). |
38 |
-+ * |
39 |
-+ * This file is based on pciutils/lib/example.c, which has the following |
40 |
-+ * authorship and copyright statement: |
41 |
-+ * |
42 |
-+ * Written by Martin Mares and put to public domain. You can do |
43 |
-+ * with it anything you want, but I don't give you any warranty. |
44 |
-+ */ |
45 |
-+ |
46 |
-+#include <stdlib.h> |
47 |
-+#include <stdio.h> |
48 |
-+#include <string.h> |
49 |
-+#include <unistd.h> |
50 |
-+#include <sys/utsname.h> |
51 |
-+#include <sys/param.h> |
52 |
-+#include <sys/types.h> |
53 |
-+ |
54 |
-+#define _GNU_SOURCE |
55 |
-+#include <getopt.h> |
56 |
-+ |
57 |
-+#include "pciutils.h" |
58 |
-+ |
59 |
-+#define MODDIR "/lib/modules" |
60 |
-+#define PCIMAP "modules.pcimap" |
61 |
-+ |
62 |
-+#define LINELENGTH 8000 |
63 |
-+ |
64 |
-+#define DEVICE_ANY 0xffffffff |
65 |
-+#define VENDOR_ANY 0xffffffff |
66 |
-+ |
67 |
-+#include "lib/pci.h" |
68 |
-+ |
69 |
-+struct pcimap_entry { |
70 |
-+ unsigned int vendor, subsys_vendor, dev, subsys_dev, class, class_mask; |
71 |
-+ char *module; |
72 |
-+ struct pcimap_entry *next; |
73 |
-+}; |
74 |
-+ |
75 |
-+static struct pcimap_entry *pcimap_list = NULL; |
76 |
-+ |
77 |
-+const char program_name[] = "pcimodules"; |
78 |
-+ |
79 |
-+#define OPT_STRING "hcm" |
80 |
-+static struct option long_options[] = { |
81 |
-+ {"class", required_argument, NULL, 'c'}, |
82 |
-+ {"classmask", required_argument, NULL, 'm'}, |
83 |
-+ {"help", no_argument, NULL, 'h'}, |
84 |
-+ { 0, 0, 0, 0} |
85 |
-+}; |
86 |
-+ |
87 |
-+static unsigned long desired_class; |
88 |
-+static unsigned long desired_classmask; /* Default is 0: accept all classes.*/ |
89 |
-+ |
90 |
-+static void |
91 |
-+read_pcimap(void) |
92 |
-+{ |
93 |
-+ struct utsname utsname; |
94 |
-+ char filename[MAXPATHLEN]; |
95 |
-+ FILE *pcimap_file; |
96 |
-+ char line[LINELENGTH]; |
97 |
-+ struct pcimap_entry *entry; |
98 |
-+ unsigned int driver_data; |
99 |
-+ char *prevmodule = ""; |
100 |
-+ char module[LINELENGTH]; |
101 |
-+ |
102 |
-+ if (uname(&utsname) < 0) { |
103 |
-+ perror("uname"); |
104 |
-+ exit(1); |
105 |
-+ } |
106 |
-+ sprintf(filename, "%s/%s/%s", MODDIR, utsname.release, PCIMAP); |
107 |
-+ if ((pcimap_file = fopen(filename, "r")) == NULL) { |
108 |
-+ perror(filename); |
109 |
-+ exit(1); |
110 |
-+ } |
111 |
-+ |
112 |
-+ while(fgets(line, LINELENGTH, pcimap_file) != NULL) { |
113 |
-+ if (line[0] == '#') |
114 |
-+ continue; |
115 |
-+ |
116 |
-+ entry = xmalloc(sizeof(struct pcimap_entry)); |
117 |
-+ |
118 |
-+ if (sscanf(line, "%s 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", |
119 |
-+ module, |
120 |
-+ &entry->vendor, &entry->dev, |
121 |
-+ &entry->subsys_vendor, &entry->subsys_dev, |
122 |
-+ &entry->class, &entry->class_mask, |
123 |
-+ &driver_data) != 8) { |
124 |
-+ fprintf (stderr, |
125 |
-+ "modules.pcimap unparsable line: %s.\n", line); |
126 |
-+ free(entry); |
127 |
-+ continue; |
128 |
-+ } |
129 |
-+ |
130 |
-+ /* Optimize memory allocation a bit, in case someday we |
131 |
-+ have Linux systems with ~100,000 modules. It also |
132 |
-+ allows us to just compare pointers to avoid trying |
133 |
-+ to load a module twice. */ |
134 |
-+ if (strcmp(module, prevmodule) != 0) { |
135 |
-+ prevmodule = xmalloc(strlen(module)+1); |
136 |
-+ strcpy(prevmodule, module); |
137 |
-+ } |
138 |
-+ entry->module = prevmodule; |
139 |
-+ entry->next = pcimap_list; |
140 |
-+ pcimap_list = entry; |
141 |
-+ } |
142 |
-+ fclose(pcimap_file); |
143 |
-+} |
144 |
-+ |
145 |
-+/* Return a filled in pci_access->dev tree, with the device classes |
146 |
-+ stored in dev->aux. |
147 |
-+*/ |
148 |
-+static void |
149 |
-+match_pci_modules(void) |
150 |
-+{ |
151 |
-+ struct pci_access *pacc; |
152 |
-+ struct pci_dev *dev; |
153 |
-+ unsigned int class, subsys_dev, subsys_vendor; |
154 |
-+ struct pcimap_entry *map; |
155 |
-+ const char *prevmodule = ""; |
156 |
-+ |
157 |
-+ pacc = pci_alloc(); /* Get the pci_access structure */ |
158 |
-+ /* Set all options you want -- here we stick with the defaults */ |
159 |
-+ pci_init(pacc); /* Initialize the PCI library */ |
160 |
-+ pci_scan_bus(pacc); /* We want to get the list of devices */ |
161 |
-+ for(dev=pacc->devices; dev; dev=dev->next) { |
162 |
-+ pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES); |
163 |
-+ class = (pci_read_word(dev, PCI_CLASS_DEVICE) << 8) |
164 |
-+ | pci_read_byte(dev, PCI_CLASS_PROG); |
165 |
-+ subsys_dev = pci_read_word(dev, PCI_SUBSYSTEM_ID); |
166 |
-+ subsys_vendor = pci_read_word(dev,PCI_SUBSYSTEM_VENDOR_ID); |
167 |
-+ for(map = pcimap_list; map != NULL; map = map->next) { |
168 |
-+ if (((map->class ^ class) & map->class_mask) == 0 && |
169 |
-+ ((desired_class ^ class) & desired_classmask)==0 && |
170 |
-+ (map->dev == DEVICE_ANY || |
171 |
-+ map->dev == dev->device_id) && |
172 |
-+ (map->vendor == VENDOR_ANY || |
173 |
-+ map->vendor == dev->vendor_id) && |
174 |
-+ (map->subsys_dev == DEVICE_ANY || |
175 |
-+ map->subsys_dev == subsys_dev) && |
176 |
-+ (map->subsys_vendor == VENDOR_ANY || |
177 |
-+ map->subsys_vendor == subsys_vendor) && |
178 |
-+ prevmodule != map->module) { |
179 |
-+ printf("%s\n", map->module); |
180 |
-+ prevmodule = map->module; |
181 |
-+ } |
182 |
-+ } |
183 |
-+ |
184 |
-+ } |
185 |
-+ pci_cleanup(pacc); |
186 |
-+} |
187 |
-+ |
188 |
-+int |
189 |
-+main (int argc, char **argv) |
190 |
-+{ |
191 |
-+ int opt_index = 0; |
192 |
-+ int opt; |
193 |
-+ |
194 |
-+ while ((opt = getopt_long(argc, argv, OPT_STRING, long_options, |
195 |
-+ &opt_index)) != -1) { |
196 |
-+ switch(opt) { |
197 |
-+ case 'c': |
198 |
-+ desired_class = strtol(optarg, NULL, 0); |
199 |
-+ break; |
200 |
-+ case 'm': |
201 |
-+ desired_classmask = strtol(optarg, NULL, 0); |
202 |
-+ break; |
203 |
-+ case 'h': |
204 |
-+ printf ("Usage: pcimodules [--help]\n" |
205 |
-+ " Lists kernel modules corresponding to PCI devices currently plugged" |
206 |
-+ " into the computer.\n"); |
207 |
-+ } |
208 |
-+ } |
209 |
-+ |
210 |
-+ read_pcimap(); |
211 |
-+ match_pci_modules(); |
212 |
-+ return 0; |
213 |
-+} |
214 |
---- pciutils-3.0.0/pcimodules.man |
215 |
-+++ pciutils-3.0.0/pcimodules.man |
216 |
-@@ -0,0 +1,92 @@ |
217 |
-+.TH pcimodules 8 "@TODAY@" "@VERSION@" "Linux PCI Utilities" |
218 |
-+.IX pcimodules |
219 |
-+.SH NAME |
220 |
-+pcimodules \- List kernel driver modules available for all currently plugged |
221 |
-+in PCI devices |
222 |
-+.SH SYNOPSIS |
223 |
-+.B pcimodules |
224 |
-+.RB [ --class class_id ] |
225 |
-+.RB [ --classmask mask ] |
226 |
-+.RB [ --help ] |
227 |
-+.SH DESCRIPTION |
228 |
-+.B pcimodules |
229 |
-+lists all driver modules for all currently plugged in PCI devices. |
230 |
-+.B pcimodules |
231 |
-+should be run at boot time, and whenever a PCI device is "hot plugged" |
232 |
-+into the system. This can be done by the following Bourne shell syntax: |
233 |
-+.IP |
234 |
-+ for module in $(pcimodules) ; do |
235 |
-+.IP |
236 |
-+ modprobe -s -k "$module" |
237 |
-+.IP |
238 |
-+ done |
239 |
-+.PP |
240 |
-+When a PCI device is removed from the system, the Linux kernel will |
241 |
-+decrement a usage count on PCI driver module. If this count drops |
242 |
-+to zero (i.e., there are no PCI drivers), then the |
243 |
-+.B modprobe -r |
244 |
-+process that is normally configured to run from cron every few minutes |
245 |
-+will eventually remove the unneeded module. |
246 |
-+.PP |
247 |
-+The --class and --classmask arguments can be used to limit the search |
248 |
-+to certain classes of PCI devices. This is useful, for example, to |
249 |
-+generate a list of ethernet card drivers to be loaded when the kernel |
250 |
-+has indicated that it is trying to resolve an unknown network interface. |
251 |
-+.PP |
252 |
-+Modules are listed in the order in which the PCI devices are physically |
253 |
-+arranged so that the computer owner can arrange things like having scsi |
254 |
-+device 0 be on a controller that is not alphabetically the first scsi |
255 |
-+controller. |
256 |
-+.SH OPTIONS |
257 |
-+.TP |
258 |
-+.B --class class --classmask mask |
259 |
-+.PP |
260 |
-+--class and --classmask limit the search to PCI |
261 |
-+cards in particular classes. These arguments are always used together. |
262 |
-+The arguments to --class and --classmask |
263 |
-+can be given as hexadecimal numbers by prefixing a leading "0x". |
264 |
-+Note that the classes used by pcimodules are in "Linux" format, |
265 |
-+meaning the class value that you see with lspci would be shifted |
266 |
-+left eight bits, with the new low eight bits programming interface ID. |
267 |
-+An examples of how to use class and classmask is provided below. |
268 |
-+.B --help, -h |
269 |
-+Print a help message and exit. |
270 |
-+.SH EXAMPLES |
271 |
-+.TP |
272 |
-+pcimodules |
273 |
-+lists all modules corresponding to currently plugged in PCI devices. |
274 |
-+.TP |
275 |
-+pcimodules --class 0x200000 --classmask 0xffff00 |
276 |
-+lists all modules corresponding to currently plugged in ethernet PCI devices. |
277 |
-+.SH FILES |
278 |
-+.TP |
279 |
-+.B /lib/modules/<kernel-version>/modules.pcimap |
280 |
-+This file is automatically generated by |
281 |
-+.B depmod, |
282 |
-+and used by |
283 |
-+.B pcimodules |
284 |
-+to determine which modules correspond to which PCI ID's. |
285 |
-+.TP |
286 |
-+.B /proc/bus/pci |
287 |
-+An interface to PCI bus configuration space provided by the post-2.1.82 Linux |
288 |
-+kernels. Contains per-bus subdirectories with per-card config space files and a |
289 |
-+.I devices |
290 |
-+file containing a list of all PCI devices. |
291 |
-+ |
292 |
-+.SH SEE ALSO |
293 |
-+.BR lspci (8) |
294 |
-+ |
295 |
-+.SH MAINTAINER |
296 |
-+The Linux PCI Utilities are maintained by Martin Mares <mj@××××.cz>. |
297 |
-+ |
298 |
-+.SH AUTHOR |
299 |
-+.B pcimodules |
300 |
-+was written by Adam J. Richter <adam@×××××××××.com>, based on public |
301 |
-+domain example code by Martin Mares <mj@××××.cz>. |
302 |
-+ |
303 |
-+.SH COPYRIGHT |
304 |
-+.B pcimodules |
305 |
-+is copyright 2000, Yggdrasil Computing, Incorporated, and may |
306 |
-+be copied under the terms and conditions of version 2 of the GNU |
307 |
-+General Public License as published by the Free Software Foundation |
308 |
-+(Cambrige, Massachusetts, United States of America). |
309 |
|
310 |
|
311 |
|
312 |
1.1 sys-apps/pciutils/files/pcimodules.8 |
313 |
|
314 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/pciutils/files/pcimodules.8?rev=1.1&view=markup |
315 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/pciutils/files/pcimodules.8?rev=1.1&content-type=text/plain |
316 |
|
317 |
Index: pcimodules.8 |
318 |
=================================================================== |
319 |
.TH pcimodules 8 "@TODAY@" "@VERSION@" "Linux PCI Utilities" |
320 |
.IX pcimodules |
321 |
.SH NAME |
322 |
pcimodules \- List kernel driver modules available for all currently plugged |
323 |
in PCI devices |
324 |
.SH SYNOPSIS |
325 |
.B pcimodules |
326 |
.RB [ --class class_id ] |
327 |
.RB [ --classmask mask ] |
328 |
.RB [ --help ] |
329 |
.SH DESCRIPTION |
330 |
.B pcimodules |
331 |
lists all driver modules for all currently plugged in PCI devices. |
332 |
.B pcimodules |
333 |
should be run at boot time, and whenever a PCI device is "hot plugged" |
334 |
into the system. This can be done by the following Bourne shell syntax: |
335 |
.IP |
336 |
for module in $(pcimodules) ; do |
337 |
.IP |
338 |
modprobe -s -k "$module" |
339 |
.IP |
340 |
done |
341 |
.PP |
342 |
When a PCI device is removed from the system, the Linux kernel will |
343 |
decrement a usage count on PCI driver module. If this count drops |
344 |
to zero (i.e., there are no PCI drivers), then the |
345 |
.B modprobe -r |
346 |
process that is normally configured to run from cron every few minutes |
347 |
will eventually remove the unneeded module. |
348 |
.PP |
349 |
The --class and --classmask arguments can be used to limit the search |
350 |
to certain classes of PCI devices. This is useful, for example, to |
351 |
generate a list of ethernet card drivers to be loaded when the kernel |
352 |
has indicated that it is trying to resolve an unknown network interface. |
353 |
.PP |
354 |
Modules are listed in the order in which the PCI devices are physically |
355 |
arranged so that the computer owner can arrange things like having scsi |
356 |
device 0 be on a controller that is not alphabetically the first scsi |
357 |
controller. |
358 |
.SH OPTIONS |
359 |
.TP |
360 |
.B --class class --classmask mask |
361 |
.PP |
362 |
--class and --classmask limit the search to PCI |
363 |
cards in particular classes. These arguments are always used together. |
364 |
The arguments to --class and --classmask |
365 |
can be given as hexadecimal numbers by prefixing a leading "0x". |
366 |
Note that the classes used by pcimodules are in "Linux" format, |
367 |
meaning the class value that you see with lspci would be shifted |
368 |
left eight bits, with the new low eight bits programming interface ID. |
369 |
An examples of how to use class and classmask is provided below. |
370 |
.B --help, -h |
371 |
Print a help message and exit. |
372 |
.SH EXAMPLES |
373 |
.TP |
374 |
pcimodules |
375 |
lists all modules corresponding to currently plugged in PCI devices. |
376 |
.TP |
377 |
pcimodules --class 0x200000 --classmask 0xffff00 |
378 |
lists all modules corresponding to currently plugged in ethernet PCI devices. |
379 |
.SH FILES |
380 |
.TP |
381 |
.B /lib/modules/<kernel-version>/modules.pcimap |
382 |
This file is automatically generated by |
383 |
.B depmod, |
384 |
and used by |
385 |
.B pcimodules |
386 |
to determine which modules correspond to which PCI ID's. |
387 |
.TP |
388 |
.B /proc/bus/pci |
389 |
An interface to PCI bus configuration space provided by the post-2.1.82 Linux |
390 |
kernels. Contains per-bus subdirectories with per-card config space files and a |
391 |
.I devices |
392 |
file containing a list of all PCI devices. |
393 |
|
394 |
.SH SEE ALSO |
395 |
.BR lspci (8) |
396 |
|
397 |
.SH MAINTAINER |
398 |
The Linux PCI Utilities are maintained by Martin Mares <mj@××××.cz>. |
399 |
|
400 |
.SH AUTHOR |
401 |
.B pcimodules |
402 |
was written by Adam J. Richter <adam@×××××××××.com>, based on public |
403 |
domain example code by Martin Mares <mj@××××.cz>. |
404 |
|
405 |
.SH COPYRIGHT |
406 |
.B pcimodules |
407 |
is copyright 2000, Yggdrasil Computing, Incorporated, and may |
408 |
be copied under the terms and conditions of version 2 of the GNU |
409 |
General Public License as published by the Free Software Foundation |
410 |
(Cambrige, Massachusetts, United States of America). |
411 |
|
412 |
|
413 |
|
414 |
1.1 sys-apps/pciutils/files/pcimodules.c |
415 |
|
416 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/pciutils/files/pcimodules.c?rev=1.1&view=markup |
417 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/pciutils/files/pcimodules.c?rev=1.1&content-type=text/plain |
418 |
|
419 |
Index: pcimodules.c |
420 |
=================================================================== |
421 |
/* |
422 |
* pcimodules: Load all kernel modules for PCI device currently |
423 |
* plugged into any PCI slot. |
424 |
* |
425 |
* Copyright 2000 Yggdrasil Computing, Incorporated |
426 |
* This file may be copied under the terms and conditions of version |
427 |
* two of the GNU General Public License, as published by the Free |
428 |
* Software Foundation (Cambridge, Massachusetts, USA). |
429 |
* |
430 |
* This file is based on pciutils/lib/example.c, which has the following |
431 |
* authorship and copyright statement: |
432 |
* |
433 |
* Written by Martin Mares and put to public domain. You can do |
434 |
* with it anything you want, but I don't give you any warranty. |
435 |
*/ |
436 |
|
437 |
#include <stdlib.h> |
438 |
#include <stdio.h> |
439 |
#include <string.h> |
440 |
#include <unistd.h> |
441 |
#include <sys/utsname.h> |
442 |
#include <sys/param.h> |
443 |
#include <sys/types.h> |
444 |
|
445 |
#define _GNU_SOURCE |
446 |
#include <getopt.h> |
447 |
|
448 |
#include "pciutils.h" |
449 |
|
450 |
#define MODDIR "/lib/modules" |
451 |
#define PCIMAP "modules.pcimap" |
452 |
|
453 |
#define LINELENGTH 8000 |
454 |
|
455 |
#define DEVICE_ANY 0xffffffff |
456 |
#define VENDOR_ANY 0xffffffff |
457 |
|
458 |
#include "lib/pci.h" |
459 |
|
460 |
struct pcimap_entry { |
461 |
unsigned int vendor, subsys_vendor, dev, subsys_dev, class, class_mask; |
462 |
char *module; |
463 |
struct pcimap_entry *next; |
464 |
}; |
465 |
|
466 |
static struct pcimap_entry *pcimap_list = NULL; |
467 |
|
468 |
const char program_name[] = "pcimodules"; |
469 |
|
470 |
#define OPT_STRING "hcm" |
471 |
static struct option long_options[] = { |
472 |
{"class", required_argument, NULL, 'c'}, |
473 |
{"classmask", required_argument, NULL, 'm'}, |
474 |
{"help", no_argument, NULL, 'h'}, |
475 |
{ 0, 0, 0, 0} |
476 |
}; |
477 |
|
478 |
static unsigned long desired_class; |
479 |
static unsigned long desired_classmask; /* Default is 0: accept all classes.*/ |
480 |
|
481 |
static void |
482 |
read_pcimap(void) |
483 |
{ |
484 |
struct utsname utsname; |
485 |
char filename[MAXPATHLEN]; |
486 |
FILE *pcimap_file; |
487 |
char line[LINELENGTH]; |
488 |
struct pcimap_entry *entry; |
489 |
unsigned int driver_data; |
490 |
char *prevmodule = ""; |
491 |
char module[LINELENGTH]; |
492 |
|
493 |
if (uname(&utsname) < 0) { |
494 |
perror("uname"); |
495 |
exit(1); |
496 |
} |
497 |
sprintf(filename, "%s/%s/%s", MODDIR, utsname.release, PCIMAP); |
498 |
if ((pcimap_file = fopen(filename, "r")) == NULL) { |
499 |
perror(filename); |
500 |
exit(1); |
501 |
} |
502 |
|
503 |
while(fgets(line, LINELENGTH, pcimap_file) != NULL) { |
504 |
if (line[0] == '#') |
505 |
continue; |
506 |
|
507 |
entry = xmalloc(sizeof(struct pcimap_entry)); |
508 |
|
509 |
if (sscanf(line, "%s 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", |
510 |
module, |
511 |
&entry->vendor, &entry->dev, |
512 |
&entry->subsys_vendor, &entry->subsys_dev, |
513 |
&entry->class, &entry->class_mask, |
514 |
&driver_data) != 8) { |
515 |
fprintf (stderr, |
516 |
"modules.pcimap unparsable line: %s.\n", line); |
517 |
free(entry); |
518 |
continue; |
519 |
} |
520 |
|
521 |
/* Optimize memory allocation a bit, in case someday we |
522 |
have Linux systems with ~100,000 modules. It also |
523 |
allows us to just compare pointers to avoid trying |
524 |
to load a module twice. */ |
525 |
if (strcmp(module, prevmodule) != 0) { |
526 |
prevmodule = xmalloc(strlen(module)+1); |
527 |
strcpy(prevmodule, module); |
528 |
} |
529 |
entry->module = prevmodule; |
530 |
entry->next = pcimap_list; |
531 |
pcimap_list = entry; |
532 |
} |
533 |
fclose(pcimap_file); |
534 |
} |
535 |
|
536 |
/* Return a filled in pci_access->dev tree, with the device classes |
537 |
stored in dev->aux. |
538 |
*/ |
539 |
static void |
540 |
match_pci_modules(void) |
541 |
{ |
542 |
struct pci_access *pacc; |
543 |
struct pci_dev *dev; |
544 |
unsigned int class, subsys_dev, subsys_vendor; |
545 |
struct pcimap_entry *map; |
546 |
const char *prevmodule = ""; |
547 |
|
548 |
pacc = pci_alloc(); /* Get the pci_access structure */ |
549 |
/* Set all options you want -- here we stick with the defaults */ |
550 |
pci_init(pacc); /* Initialize the PCI library */ |
551 |
pci_scan_bus(pacc); /* We want to get the list of devices */ |
552 |
for(dev=pacc->devices; dev; dev=dev->next) { |
553 |
pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES); |
554 |
class = (pci_read_word(dev, PCI_CLASS_DEVICE) << 8) |
555 |
| pci_read_byte(dev, PCI_CLASS_PROG); |
556 |
subsys_dev = pci_read_word(dev, PCI_SUBSYSTEM_ID); |
557 |
subsys_vendor = pci_read_word(dev,PCI_SUBSYSTEM_VENDOR_ID); |
558 |
for(map = pcimap_list; map != NULL; map = map->next) { |
559 |
if (((map->class ^ class) & map->class_mask) == 0 && |
560 |
((desired_class ^ class) & desired_classmask)==0 && |
561 |
(map->dev == DEVICE_ANY || |
562 |
map->dev == dev->device_id) && |
563 |
(map->vendor == VENDOR_ANY || |
564 |
map->vendor == dev->vendor_id) && |
565 |
(map->subsys_dev == DEVICE_ANY || |
566 |
map->subsys_dev == subsys_dev) && |
567 |
(map->subsys_vendor == VENDOR_ANY || |
568 |
map->subsys_vendor == subsys_vendor) && |
569 |
prevmodule != map->module) { |
570 |
printf("%s\n", map->module); |
571 |
prevmodule = map->module; |
572 |
} |
573 |
} |
574 |
|
575 |
} |
576 |
pci_cleanup(pacc); |
577 |
} |
578 |
|
579 |
int |
580 |
main (int argc, char **argv) |
581 |
{ |
582 |
int opt_index = 0; |
583 |
int opt; |
584 |
|
585 |
while ((opt = getopt_long(argc, argv, OPT_STRING, long_options, |
586 |
&opt_index)) != -1) { |
587 |
switch(opt) { |
588 |
case 'c': |
589 |
desired_class = strtol(optarg, NULL, 0); |
590 |
break; |
591 |
case 'm': |
592 |
desired_classmask = strtol(optarg, NULL, 0); |
593 |
break; |
594 |
case 'h': |
595 |
printf ("Usage: pcimodules [--help]\n" |
596 |
" Lists kernel modules corresponding to PCI devices currently plugged" |
597 |
" into the computer.\n"); |
598 |
} |
599 |
} |
600 |
|
601 |
read_pcimap(); |
602 |
match_pci_modules(); |
603 |
return 0; |
604 |
} |