~ubuntu-branches/ubuntu/precise/pciutils/precise

« back to all changes in this revision

Viewing changes to debian/patches/02-pcimodules.patch

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2010-06-26 14:17:57 UTC
  • mfrom: (2.1.18 sid)
  • Revision ID: james.westby@ubuntu.com-20100626141757-xsp7xqv15qotwels
Tags: 1:3.1.7-4
Update pci.ids with snapshot dated 2010-06-12

Show diffs side-by-side

added added

removed removed

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