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