Magellan Linux

Annotation of /trunk/pciutils/patches/pcimodules-pciutils-2.1.11.patch

Parent Directory Parent Directory | Revision Log Revision Log


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