Magellan Linux

Contents of /trunk/pciutils/patches/pciutils-2.2.4-pcimodules.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations) (download)
Tue May 8 20:52:56 2007 UTC (17 years ago) by niro
File size: 11724 byte(s)
-import

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