Annotation of /trunk/pciutils/patches/pcimodules-pciutils-2.2.0.patch
Parent Directory | Revision Log
Revision 153 -
(hide annotations)
(download)
Tue May 8 20:52:56 2007 UTC (17 years, 4 months ago) by niro
File size: 10872 byte(s)
Tue May 8 20:52:56 2007 UTC (17 years, 4 months ago) by niro
File size: 10872 byte(s)
-import
1 | niro | 153 | --- pciutils-2.2.0/lspci.c |
2 | +++ pciutils-dsd/lspci.c | ||
3 | @@ -113,8 +113,10 @@ scan_device(struct pci_dev *p) | ||
4 | d->config = xmalloc(64); | ||
5 | d->present = xmalloc(64); | ||
6 | memset(d->present, 1, 64); | ||
7 | - if (!pci_read_block(p, 0, d->config, 64)) | ||
8 | - die("Unable to read the standard configuration space header"); | ||
9 | + if (!pci_read_block(p, 0, d->config, 64)) { | ||
10 | + fprintf(stderr, "Unable to read the standard configuration space header"); | ||
11 | + return NULL; | ||
12 | + } | ||
13 | if ((d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS) | ||
14 | { | ||
15 | /* For cardbus bridges, we need to fetch 64 bytes more to get the | ||
16 | --- pciutils-2.2.0/Makefile | ||
17 | +++ pciutils-dsd/Makefile | ||
18 | @@ -33,7 +33,7 @@ RELEASE= | ||
19 | |||
20 | export | ||
21 | |||
22 | -all: $(PCILIB) lspci setpci lspci.8 setpci.8 update-pciids update-pciids.8 pci.ids | ||
23 | +all: $(PCILIB) lspci setpci pcimodules lspci.8 setpci.8 update-pciids update-pciids.8 pcimodules.8 pci.ids | ||
24 | |||
25 | $(PCILIB): $(PCIINC) force | ||
26 | $(MAKE) -C lib all | ||
27 | @@ -43,9 +43,11 @@ force: | ||
28 | lib/config.h: | ||
29 | cd lib && ./configure $(IDSDIR) $(VERSION) $(HOST) $(RELEASE) | ||
30 | |||
31 | +pcimodules: pcimodules.o common.o $(PCILIB) | ||
32 | lspci: lspci.o common.o $(PCILIB) | ||
33 | setpci: setpci.o common.o $(PCILIB) | ||
34 | |||
35 | +pcimodules.o: pcimodules.c pciutils.h $(PCIINC) | ||
36 | lspci.o: lspci.c pciutils.h $(PCIINC) | ||
37 | setpci.o: setpci.c pciutils.h $(PCIINC) | ||
38 | common.o: common.c pciutils.h $(PCIINC) | ||
39 | @@ -66,15 +68,15 @@ distclean: clean | ||
40 | install: all | ||
41 | # -c is ignored on Linux, but required on FreeBSD | ||
42 | $(DIRINSTALL) -m 755 $(SBINDIR) $(IDSDIR) $(MANDIR)/man8 | ||
43 | - $(INSTALL) -c -m 755 -s lspci setpci $(SBINDIR) | ||
44 | + $(INSTALL) -c -m 755 -s lspci setpci pcimodules $(SBINDIR) | ||
45 | $(INSTALL) -c -m 755 update-pciids $(SBINDIR) | ||
46 | $(INSTALL) -c -m 644 pci.ids $(IDSDIR) | ||
47 | - $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(MANDIR)/man8 | ||
48 | + $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 pcimodules.8 $(MANDIR)/man8 | ||
49 | |||
50 | uninstall: all | ||
51 | - rm -f $(SBINDIR)/lspci $(SBINDIR)/setpci $(SBINDIR)/update-pciids | ||
52 | + rm -f $(SBINDIR)/lspci $(SBINDIR)/setpci $(SBINDIR)/update-pciids $(SBINDIR)/pcimodules | ||
53 | rm -f $(IDSDIR)/pci.ids | ||
54 | - rm -f $(MANDIR)/man8/lspci.8 $(MANDIR)/man8/setpci.8 $(MANDIR)/man8/update-pciids.8 | ||
55 | + rm -f $(MANDIR)/man8/lspci.8 $(MANDIR)/man8/setpci.8 $(MANDIR)/man8/update-pciids.8 $(MANDIR)/man8/pcimodules.8 | ||
56 | |||
57 | get-ids: | ||
58 | cp ~/tree/pciids/pci.ids pci.ids | ||
59 | --- pciutils-2.2.0/pcimodules.c | ||
60 | +++ pciutils-dsd/pcimodules.c | ||
61 | @@ -0,0 +1,183 @@ | ||
62 | +/* | ||
63 | + * pcimodules: Load all kernel modules for PCI device currently | ||
64 | + * plugged into any PCI slot. | ||
65 | + * | ||
66 | + * Copyright 2000 Yggdrasil Computing, Incorporated | ||
67 | + * This file may be copied under the terms and conditions of version | ||
68 | + * two of the GNU General Public License, as published by the Free | ||
69 | + * Software Foundation (Cambridge, Massachusetts, USA). | ||
70 | + * | ||
71 | + * This file is based on pciutils/lib/example.c, which has the following | ||
72 | + * authorship and copyright statement: | ||
73 | + * | ||
74 | + * Written by Martin Mares and put to public domain. You can do | ||
75 | + * with it anything you want, but I don't give you any warranty. | ||
76 | + */ | ||
77 | + | ||
78 | +#include <stdlib.h> | ||
79 | +#include <stdio.h> | ||
80 | +#include <malloc.h> | ||
81 | +#include <string.h> | ||
82 | +#include <unistd.h> | ||
83 | +#include <sys/utsname.h> | ||
84 | +#include <sys/param.h> | ||
85 | +#include <sys/types.h> | ||
86 | + | ||
87 | +#define _GNU_SOURCE | ||
88 | +#include <getopt.h> | ||
89 | + | ||
90 | +#include "pciutils.h" | ||
91 | + | ||
92 | +#define MODDIR "/lib/modules" | ||
93 | +#define PCIMAP "modules.pcimap" | ||
94 | + | ||
95 | +#define LINELENGTH 8000 | ||
96 | + | ||
97 | +#define DEVICE_ANY 0xffffffff | ||
98 | +#define VENDOR_ANY 0xffffffff | ||
99 | + | ||
100 | +#include "lib/pci.h" | ||
101 | + | ||
102 | +struct pcimap_entry { | ||
103 | + unsigned int vendor, subsys_vendor, dev, subsys_dev, class, class_mask; | ||
104 | + char *module; | ||
105 | + struct pcimap_entry *next; | ||
106 | +}; | ||
107 | + | ||
108 | +static struct pcimap_entry *pcimap_list = NULL; | ||
109 | + | ||
110 | +#define OPT_STRING "h" | ||
111 | +static struct option long_options[] = { | ||
112 | + {"class", required_argument, NULL, 'c'}, | ||
113 | + {"classmask", required_argument, NULL, 'm'}, | ||
114 | + {"help", no_argument, NULL, 'h'}, | ||
115 | + { 0, 0, 0, 0} | ||
116 | +}; | ||
117 | + | ||
118 | +static unsigned long desired_class; | ||
119 | +static unsigned long desired_classmask; /* Default is 0: accept all classes.*/ | ||
120 | + | ||
121 | +void | ||
122 | +read_pcimap(void) | ||
123 | +{ | ||
124 | + struct utsname utsname; | ||
125 | + char filename[MAXPATHLEN]; | ||
126 | + FILE *pcimap_file; | ||
127 | + char line[LINELENGTH]; | ||
128 | + struct pcimap_entry *entry; | ||
129 | + unsigned int driver_data; | ||
130 | + char *prevmodule = ""; | ||
131 | + char module[LINELENGTH]; | ||
132 | + | ||
133 | + if (uname(&utsname) < 0) { | ||
134 | + perror("uname"); | ||
135 | + exit(1); | ||
136 | + } | ||
137 | + sprintf(filename, "%s/%s/%s", MODDIR, utsname.release, PCIMAP); | ||
138 | + if ((pcimap_file = fopen(filename, "r")) == NULL) { | ||
139 | + perror(filename); | ||
140 | + exit(1); | ||
141 | + } | ||
142 | + | ||
143 | + while(fgets(line, LINELENGTH, pcimap_file) != NULL) { | ||
144 | + if (line[0] == '#') | ||
145 | + continue; | ||
146 | + | ||
147 | + entry = xmalloc(sizeof(struct pcimap_entry)); | ||
148 | + | ||
149 | + if (sscanf(line, "%s 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x", | ||
150 | + module, | ||
151 | + &entry->vendor, &entry->dev, | ||
152 | + &entry->subsys_vendor, &entry->subsys_dev, | ||
153 | + &entry->class, &entry->class_mask, | ||
154 | + &driver_data) != 8) { | ||
155 | + fprintf (stderr, | ||
156 | + "modules.pcimap unparsable line: %s.\n", line); | ||
157 | + free(entry); | ||
158 | + continue; | ||
159 | + } | ||
160 | + | ||
161 | + /* Optimize memory allocation a bit, in case someday we | ||
162 | + have Linux systems with ~100,000 modules. It also | ||
163 | + allows us to just compare pointers to avoid trying | ||
164 | + to load a module twice. */ | ||
165 | + if (strcmp(module, prevmodule) != 0) { | ||
166 | + prevmodule = xmalloc(strlen(module)+1); | ||
167 | + strcpy(prevmodule, module); | ||
168 | + } | ||
169 | + entry->module = prevmodule; | ||
170 | + entry->next = pcimap_list; | ||
171 | + pcimap_list = entry; | ||
172 | + } | ||
173 | + fclose(pcimap_file); | ||
174 | +} | ||
175 | + | ||
176 | +/* Return a filled in pci_access->dev tree, with the device classes | ||
177 | + stored in dev->aux. | ||
178 | +*/ | ||
179 | +static void | ||
180 | +match_pci_modules(void) | ||
181 | +{ | ||
182 | + struct pci_access *pacc; | ||
183 | + struct pci_dev *dev; | ||
184 | + unsigned int class, subsys_dev, subsys_vendor; | ||
185 | + struct pcimap_entry *map; | ||
186 | + const char *prevmodule = ""; | ||
187 | + | ||
188 | + pacc = pci_alloc(); /* Get the pci_access structure */ | ||
189 | + /* Set all options you want -- here we stick with the defaults */ | ||
190 | + pci_init(pacc); /* Initialize the PCI library */ | ||
191 | + pci_scan_bus(pacc); /* We want to get the list of devices */ | ||
192 | + for(dev=pacc->devices; dev; dev=dev->next) { | ||
193 | + pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES); | ||
194 | + class = (pci_read_word(dev, PCI_CLASS_DEVICE) << 8) | ||
195 | + | pci_read_byte(dev, PCI_CLASS_PROG); | ||
196 | + subsys_dev = pci_read_word(dev, PCI_SUBSYSTEM_ID); | ||
197 | + subsys_vendor = pci_read_word(dev,PCI_SUBSYSTEM_VENDOR_ID); | ||
198 | + for(map = pcimap_list; map != NULL; map = map->next) { | ||
199 | + if (((map->class ^ class) & map->class_mask) == 0 && | ||
200 | + ((desired_class ^ class) & desired_classmask)==0 && | ||
201 | + (map->dev == DEVICE_ANY || | ||
202 | + map->dev == dev->device_id) && | ||
203 | + (map->vendor == VENDOR_ANY || | ||
204 | + map->vendor == dev->vendor_id) && | ||
205 | + (map->subsys_dev == DEVICE_ANY || | ||
206 | + map->subsys_dev == subsys_dev) && | ||
207 | + (map->subsys_vendor == VENDOR_ANY || | ||
208 | + map->subsys_vendor == subsys_vendor) && | ||
209 | + prevmodule != map->module) { | ||
210 | + printf("%s\n", map->module); | ||
211 | + prevmodule = map->module; | ||
212 | + } | ||
213 | + } | ||
214 | + | ||
215 | + } | ||
216 | + pci_cleanup(pacc); | ||
217 | +} | ||
218 | + | ||
219 | +int | ||
220 | +main (int argc, char **argv) | ||
221 | +{ | ||
222 | + int opt_index = 0; | ||
223 | + int opt; | ||
224 | + | ||
225 | + while ((opt = getopt_long(argc, argv, OPT_STRING, long_options, | ||
226 | + &opt_index)) != -1) { | ||
227 | + switch(opt) { | ||
228 | + case 'c': | ||
229 | + desired_class = strtol(optarg, NULL, 0); | ||
230 | + break; | ||
231 | + case 'm': | ||
232 | + desired_classmask = strtol(optarg, NULL, 0); | ||
233 | + break; | ||
234 | + case 'h': | ||
235 | + printf ("Usage: pcimodules [--help]\n" | ||
236 | + " Lists kernel modules corresponding to PCI devices currently plugged" | ||
237 | + " into the computer.\n"); | ||
238 | + } | ||
239 | + } | ||
240 | + | ||
241 | + read_pcimap(); | ||
242 | + match_pci_modules(); | ||
243 | + return 0; | ||
244 | +} | ||
245 | --- pciutils-2.2.0/pcimodules.man | ||
246 | +++ pciutils-dsd/pcimodules.man | ||
247 | @@ -0,0 +1,92 @@ | ||
248 | +.TH pcimodules 8 "@TODAY@" "@VERSION@" "Linux PCI Utilities" | ||
249 | +.IX pcimodules | ||
250 | +.SH NAME | ||
251 | +pcimodules \- List kernel driver modules available for all currently plugged | ||
252 | +in PCI devices | ||
253 | +.SH SYNOPSIS | ||
254 | +.B pcimodules | ||
255 | +.RB [ --class class_id ] | ||
256 | +.RB [ --classmask mask ] | ||
257 | +.RB [ --help ] | ||
258 | +.SH DESCRIPTION | ||
259 | +.B pcimodules | ||
260 | +lists all driver modules for all currently plugged in PCI devices. | ||
261 | +.B pcimodules | ||
262 | +should be run at boot time, and whenever a PCI device is "hot plugged" | ||
263 | +into the system. This can be done by the following Bourne shell syntax: | ||
264 | +.IP | ||
265 | + for module in $(pcimodules) ; do | ||
266 | +.IP | ||
267 | + modprobe -s -k "$module" | ||
268 | +.IP | ||
269 | + done | ||
270 | +.PP | ||
271 | +When a PCI device is removed from the system, the Linux kernel will | ||
272 | +decrement a usage count on PCI driver module. If this count drops | ||
273 | +to zero (i.e., there are no PCI drivers), then the | ||
274 | +.B modprobe -r | ||
275 | +process that is normally configured to run from cron every few minutes | ||
276 | +will eventually remove the unneeded module. | ||
277 | +.PP | ||
278 | +The --class and --classmask arguments can be used to limit the search | ||
279 | +to certain classes of PCI devices. This is useful, for example, to | ||
280 | +generate a list of ethernet card drivers to be loaded when the kernel | ||
281 | +has indicated that it is trying to resolve an unknown network interface. | ||
282 | +.PP | ||
283 | +Modules are listed in the order in which the PCI devices are physically | ||
284 | +arranged so that the computer owner can arrange things like having scsi | ||
285 | +device 0 be on a controller that is not alphabetically the first scsi | ||
286 | +controller. | ||
287 | +.SH OPTIONS | ||
288 | +.TP | ||
289 | +.B --class class --classmask mask | ||
290 | +.PP | ||
291 | +--class and --classmask limit the search to PCI | ||
292 | +cards in particular classes. These arguments are always used together. | ||
293 | +The arguments to --class and --classmask | ||
294 | +can be given as hexadecimal numbers by prefixing a leading "0x". | ||
295 | +Note that the classes used by pcimodules are in "Linux" format, | ||
296 | +meaning the class value that you see with lspci would be shifted | ||
297 | +left eight bits, with the new low eight bits programming interface ID. | ||
298 | +An examples of how to use class and classmask is provided below. | ||
299 | +.B --help, -h | ||
300 | +Print a help message and exit. | ||
301 | +.SH EXAMPLES | ||
302 | +.TP | ||
303 | +pcimodules | ||
304 | +lists all modules corresponding to currently plugged in PCI devices. | ||
305 | +.TP | ||
306 | +pcimodules --class 0x200000 --classmask 0xffff00 | ||
307 | +lists all modules corresponding to currently plugged in ethernet PCI devices. | ||
308 | +.SH FILES | ||
309 | +.TP | ||
310 | +.B /lib/modules/<kernel-version>/modules.pcimap | ||
311 | +This file is automatically generated by | ||
312 | +.B depmod, | ||
313 | +and used by | ||
314 | +.B pcimodules | ||
315 | +to determine which modules correspond to which PCI ID's. | ||
316 | +.TP | ||
317 | +.B /proc/bus/pci | ||
318 | +An interface to PCI bus configuration space provided by the post-2.1.82 Linux | ||
319 | +kernels. Contains per-bus subdirectories with per-card config space files and a | ||
320 | +.I devices | ||
321 | +file containing a list of all PCI devices. | ||
322 | + | ||
323 | +.SH SEE ALSO | ||
324 | +.BR lspci (8) | ||
325 | + | ||
326 | +.SH MAINTAINER | ||
327 | +The Linux PCI Utilities are maintained by Martin Mares <mj@suse.cz>. | ||
328 | + | ||
329 | +.SH AUTHOR | ||
330 | +.B pcimodules | ||
331 | +was written by Adam J. Richter <adam@yggdrasil.com>, based on public | ||
332 | +domain example code by Martin Mares <mj@suse.cz>. | ||
333 | + | ||
334 | +.SH COPYRIGHT | ||
335 | +.B pcimodules | ||
336 | +is copyright 2000, Yggdrasil Computing, Incorporated, and may | ||
337 | +be copied under the terms and conditions of version 2 of the GNU | ||
338 | +General Public License as published by the Free Software Foundation | ||
339 | +(Cambrige, Massachusetts, United States of America). |