modprobe: add --resolve-alias option
[mit.git] / tables.c
blob2f44450bdb5530766ff1a37988b2bfe262a722b4
1 #include <string.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <ctype.h>
5 #include "depmod.h"
6 #include "tables.h"
7 #include "util.h"
9 /* Turn /lib/modules/2.5.49/kernel/foo.ko(.gz) => foo */
10 static void make_shortname(char *dest, const char *src)
12 char *ext;
13 const char *bname;
15 bname = my_basename(src);
16 strcpy(dest, bname);
17 ext = strchr(dest, '.');
18 if (ext)
19 *ext = '\0';
22 /* We set driver_data to zero */
23 static void output_pci_entry(struct pci_device_id *pci, char *name, FILE *out,
24 int conv)
26 fprintf(out,
27 "%-20s 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x 0x0\n",
28 name,
29 END(pci->vendor, conv),
30 END(pci->device, conv),
31 END(pci->subvendor, conv),
32 END(pci->subdevice, conv),
33 END(pci->class, conv),
34 END(pci->class_mask, conv));
37 void output_pci_table(struct module *modules, FILE *out, char *dirname)
39 struct module *i;
41 fprintf(out, "# pci module vendor device subvendor"
42 " subdevice class class_mask driver_data\n");
44 for (i = modules; i; i = i->next) {
45 struct pci_device_id *e;
46 char shortname[strlen(i->pathname) + 1];
47 struct module_tables *t = &i->tables;
49 if (!t->pci_table)
50 continue;
52 make_shortname(shortname, i->pathname);
53 for (e = t->pci_table; e->vendor; e = (void *)e + t->pci_size)
54 output_pci_entry(e, shortname, out, i->file->conv);
58 /* We set driver_info to zero */
59 static void output_usb_entry(struct usb_device_id *usb, char *name, FILE *out,
60 int conv)
62 fprintf(out, "%-20s 0x%04x 0x%04x 0x%04x 0x%04x"
63 " 0x%04x 0x%02x 0x%02x"
64 " 0x%02x 0x%02x"
65 " 0x%02x 0x%02x"
66 " 0x0\n",
67 name,
68 END(usb->match_flags, conv),
69 END(usb->idVendor, conv),
70 END(usb->idProduct, conv),
71 END(usb->bcdDevice_lo, conv),
72 END(usb->bcdDevice_hi, conv),
73 END(usb->bDeviceClass, conv),
74 END(usb->bDeviceSubClass, conv),
75 END(usb->bDeviceProtocol, conv),
76 END(usb->bInterfaceClass, conv),
77 END(usb->bInterfaceSubClass, conv),
78 END(usb->bInterfaceProtocol, conv));
81 void output_usb_table(struct module *modules, FILE *out, char *dirname)
83 struct module *i;
85 fprintf(out, "# usb module ");
86 /* Requires all users to be on kernel 2.4.0 or later */
87 fprintf(out, "match_flags ");
88 fprintf(out, "idVendor idProduct bcdDevice_lo bcdDevice_hi"
89 " bDeviceClass bDeviceSubClass bDeviceProtocol"
90 " bInterfaceClass bInterfaceSubClass"
91 " bInterfaceProtocol driver_info\n");
93 for (i = modules; i; i = i->next) {
94 struct usb_device_id *e;
95 char shortname[strlen(i->pathname) + 1];
96 struct module_tables *t = &i->tables;
98 if (!t->usb_table)
99 continue;
101 make_shortname(shortname, i->pathname);
102 for (e = t->usb_table;
103 e->idVendor || e->bDeviceClass || e->bInterfaceClass;
104 e = (void *)e + t->usb_size)
105 output_usb_entry(e, shortname, out, i->file->conv);
109 static void output_ieee1394_entry(struct ieee1394_device_id *fw, char *name,
110 FILE *out, int conv)
112 fprintf(out, "%-20s 0x%08x 0x%06x 0x%06x 0x%06x 0x%06x\n",
113 name,
114 END(fw->match_flags, conv),
115 END(fw->vendor_id, conv),
116 END(fw->model_id, conv),
117 END(fw->specifier_id, conv),
118 END(fw->version, conv));
121 void output_ieee1394_table(struct module *modules, FILE *out, char *dirname)
123 struct module *i;
125 fprintf(out, "# ieee1394 module ");
126 fprintf(out, "match_flags vendor_id model_id specifier_id version\n");
128 for (i = modules; i; i = i->next) {
129 struct ieee1394_device_id *fw;
130 char shortname[strlen(i->pathname) + 1];
131 struct module_tables *t = &i->tables;
133 if (!t->ieee1394_table)
134 continue;
136 make_shortname(shortname, i->pathname);
137 for (fw = t->ieee1394_table; fw->match_flags;
138 fw = (void *) fw + t->ieee1394_size)
139 output_ieee1394_entry(fw, shortname, out, i->file->conv);
144 /* We set driver_data to zero */
145 static void output_ccw_entry(struct ccw_device_id *ccw, char *name, FILE *out,
146 int conv)
148 fprintf(out, "%-20s 0x%04x 0x%04x 0x%02x 0x%04x 0x%02x\n",
149 name, END(ccw->match_flags, conv),
150 END(ccw->cu_type, conv), END(ccw->cu_model, conv),
151 END(ccw->dev_type, conv), END(ccw->dev_model, conv));
154 void output_ccw_table(struct module *modules, FILE *out, char *dirname)
156 struct module *i;
158 fprintf(out, "# ccw module ");
159 fprintf(out, "match_flags cu_type cu_model dev_type dev_model\n");
161 for (i = modules; i; i = i->next) {
162 struct ccw_device_id *e;
163 char shortname[strlen(i->pathname) + 1];
164 struct module_tables *t = &i->tables;
166 if (!t->ccw_table)
167 continue;
169 make_shortname(shortname, i->pathname);
170 for (e = t->ccw_table;
171 e->cu_type || e->cu_model || e->dev_type || e->dev_model;
172 e = (void *) e + t->ccw_size)
173 output_ccw_entry(e, shortname, out, i->file->conv);
177 #define ISAPNP_VENDOR(a,b,c) (((((a)-'A'+1)&0x3f)<<2)|\
178 ((((b)-'A'+1)&0x18)>>3)|((((b)-'A'+1)&7)<<13)|\
179 ((((c)-'A'+1)&0x1f)<<8))
180 #define ISAPNP_DEVICE(x) ((((x)&0xf000)>>8)|\
181 (((x)&0x0f00)>>8)|\
182 (((x)&0x00f0)<<8)|\
183 (((x)&0x000f)<<8))
185 static void put_isapnp_id(FILE *out, const char *id)
187 unsigned short vendor, device;
189 vendor = ISAPNP_VENDOR(id[0], id[1], id[2]);
190 device = (unsigned short)strtol(&id[3], NULL, 16);
191 device = ISAPNP_DEVICE(device);
192 fprintf(out, " 0x%04x 0x%04x ", vendor, device);
195 void output_isapnp_table(struct module *modules, FILE *out, char *dirname)
197 struct module *i;
199 fprintf(out, "# isapnp module ");
200 fprintf(out, "cardvendor carddevice driver_data vendor function ...\n");
202 for (i = modules; i; i = i->next) {
203 char shortname[strlen(i->pathname) + 1];
204 struct module_tables *t = &i->tables;
206 if (t->pnp_table) {
207 struct pnp_device_id *id;
208 make_shortname(shortname, i->pathname);
209 for (id = t->pnp_table;
210 id->id[0];
211 id = (void *)id + t->pnp_size) {
212 fprintf(out, "%-20s", shortname);
213 fprintf(out, " 0xffff 0xffff ");
214 fprintf(out, " 0x00000000 "); /* driver_data */
215 put_isapnp_id(out, id->id);
216 fprintf(out, "\n");
219 if (t->pnp_card_table) {
220 void *id;
221 make_shortname(shortname, i->pathname);
222 for (id = t->pnp_card_table;
223 ((char *)id)[0];
224 id += t->pnp_card_size) {
225 int idx;
226 struct pnp_card_devid *devid
227 = id + t->pnp_card_offset;
229 fprintf(out, "%-20s", shortname);
230 put_isapnp_id(out, id);
231 fprintf(out, " 0x00000000 "); /* driver_data */
232 for (idx = 0; idx < 8; idx++) {
233 if (!devid->devid[idx][0])
234 break;
235 put_isapnp_id(out, devid->devid[idx]);
237 fprintf(out, "\n");
243 #define MATCH_bustype 1
244 #define MATCH_vendor 2
245 #define MATCH_product 4
246 #define MATCH_version 8
248 #define MATCH_evbit 0x010
249 #define MATCH_keybit 0x020
250 #define MATCH_relbit 0x040
251 #define MATCH_absbit 0x080
252 #define MATCH_mscbit 0x100
253 #define MATCH_ledbit 0x200
254 #define MATCH_sndbit 0x400
255 #define MATCH_ffbit 0x800
256 #define MATCH_swbit 0x1000
258 #define MATCH(x) (END(input->match_flags, conv) & MATCH_ ## x)
259 #define PRINT_SCALAR(n) fprintf(out, " 0x%lx", MATCH(n) ? END(input->n, conv) : 0l)
260 #define PRINT_ARRAY64(n) do { \
261 fprintf(out, " "); \
262 if (MATCH(n)) \
263 output_input_bits_64(out, input->n, sizeof(input->n), conv); \
264 else \
265 fprintf(out, "%d", 0); \
266 } while (0)
268 #define PRINT_ARRAY32(n) do { \
269 fprintf(out, " "); \
270 if (MATCH(n)) \
271 output_input_bits_32(out, input->n, sizeof(input->n), conv); \
272 else \
273 fprintf(out, "%d", 0); \
274 } while (0)
276 static void output_input_bits_32(FILE *out, unsigned int *bits, int size,
277 int conv)
279 int i, j;
281 size /= sizeof(*bits);
282 for (i = size - 1; i >= 0; i--)
283 if (END(bits[i], conv))
284 break;
285 if (i < 0)
286 i = 0;
287 fprintf(out, "%x", END(bits[i], conv));
288 for (j = i - 1; j >= 0; j--)
289 fprintf(out, ":%x", END(bits[j], conv));
292 static void output_input_bits_64(FILE *out, unsigned long long *bits, int size,
293 int conv)
295 int i, j;
297 size /= sizeof(*bits);
298 for (i = size - 1; i >= 0; i--)
299 if (END(bits[i], conv))
300 break;
301 if (i < 0)
302 i = 0;
303 fprintf(out, "%llx", END(bits[i], conv));
304 for (j = i - 1; j >= 0; j--)
305 fprintf(out, ":%llx", END(bits[j], conv));
308 /* Formats are too different to */
309 static int output_input_entry_32(struct input_device_id_32 *input,
310 char *name, FILE *out, int conv)
312 if (!input->match_flags && !input->driver_info)
313 return 1;
315 fprintf(out, "%-20s0x%x", name, END(input->match_flags, conv));
317 PRINT_SCALAR(bustype);
318 PRINT_SCALAR(vendor);
319 PRINT_SCALAR(product);
320 PRINT_SCALAR(version);
322 PRINT_ARRAY32(evbit);
323 PRINT_ARRAY32(keybit);
324 PRINT_ARRAY32(relbit);
325 PRINT_ARRAY32(absbit);
326 PRINT_ARRAY32(mscbit);
327 PRINT_ARRAY32(ledbit);
328 PRINT_ARRAY32(sndbit);
329 PRINT_ARRAY32(ffbit);
330 PRINT_ARRAY32(swbit);
332 fprintf(out, " 0x%x\n", END(input->driver_info, conv));
333 return 0;
336 static int output_input_entry_32_old(struct input_device_id_old_32 *input,
337 char *name, FILE *out, int conv)
339 if (!input->match_flags && !input->driver_info)
340 return 1;
342 fprintf(out, "%-20s0x%x", name, END(input->match_flags, conv));
344 PRINT_SCALAR(bustype);
345 PRINT_SCALAR(vendor);
346 PRINT_SCALAR(product);
347 PRINT_SCALAR(version);
349 PRINT_ARRAY32(evbit);
350 PRINT_ARRAY32(keybit);
351 PRINT_ARRAY32(relbit);
352 PRINT_ARRAY32(absbit);
353 PRINT_ARRAY32(mscbit);
354 PRINT_ARRAY32(ledbit);
355 PRINT_ARRAY32(sndbit);
356 PRINT_ARRAY32(ffbit);
358 fprintf(out, " 0x%x\n", END(input->driver_info, conv));
359 return 0;
362 static int output_input_entry_64(struct input_device_id_64 *input,
363 char *name, FILE *out, int conv)
365 if (!input->match_flags && !input->driver_info)
366 return 1;
368 fprintf(out, "%-20s0x%llx", name, END(input->match_flags, conv));
370 PRINT_SCALAR(bustype);
371 PRINT_SCALAR(vendor);
372 PRINT_SCALAR(product);
373 PRINT_SCALAR(version);
375 PRINT_ARRAY64(evbit);
376 PRINT_ARRAY64(keybit);
377 PRINT_ARRAY64(relbit);
378 PRINT_ARRAY64(absbit);
379 PRINT_ARRAY64(mscbit);
380 PRINT_ARRAY64(ledbit);
381 PRINT_ARRAY64(sndbit);
382 PRINT_ARRAY64(ffbit);
383 PRINT_ARRAY64(swbit);
385 fprintf(out, " 0x%llx\n", END(input->driver_info, conv));
386 return 0;
389 static int output_input_entry_64_old(struct input_device_id_old_64 *input,
390 char *name, FILE *out, int conv)
392 if (!input->match_flags && !input->driver_info)
393 return 1;
395 fprintf(out, "%-20s0x%llx", name, END(input->match_flags, conv));
397 PRINT_SCALAR(bustype);
398 PRINT_SCALAR(vendor);
399 PRINT_SCALAR(product);
400 PRINT_SCALAR(version);
402 PRINT_ARRAY64(evbit);
403 PRINT_ARRAY64(keybit);
404 PRINT_ARRAY64(relbit);
405 PRINT_ARRAY64(absbit);
406 PRINT_ARRAY64(mscbit);
407 PRINT_ARRAY64(ledbit);
408 PRINT_ARRAY64(sndbit);
409 PRINT_ARRAY64(ffbit);
411 fprintf(out, " 0x%llx\n", END(input->driver_info, conv));
412 return 0;
415 void output_input_table(struct module *modules, FILE *out, char *dirname)
417 struct module *i;
419 fprintf(out, "# module matchBits");
420 fprintf(out, " bustype vendor product version evBits keyBits relBits");
421 fprintf(out, " absBits mscBits ledBits sndBits ffBits [swBits] driver_info\n");
423 for (i = modules; i; i = i->next) {
424 void *p;
425 char shortname[strlen(i->pathname) + 1];
426 int done = 0;
427 struct module_tables *t = &i->tables;
428 int conv = i->file->conv;
430 if (!t->input_table)
431 continue;
433 make_shortname(shortname, i->pathname);
434 /* Guess what size it really is, based on size of
435 * whole table. Table changed in 2.6.14. This is a hack. */
436 if (t->input_size == sizeof(struct input_device_id_old_64)) {
437 if ((t->input_table_size % t->input_size) != 0) {
438 t->input_size
439 = sizeof(struct input_device_id_64);
441 } else {
442 if ((t->input_table_size % t->input_size) != 0) {
443 t->input_size
444 = sizeof(struct input_device_id_32);
448 for (p = t->input_table; !done; p += t->input_size) {
449 switch (t->input_size) {
450 case sizeof(struct input_device_id_old_64):
451 done = output_input_entry_64_old(p,
452 shortname,
453 out, conv);
454 break;
455 case sizeof(struct input_device_id_64):
456 done = output_input_entry_64(p, shortname,
457 out, conv);
458 break;
459 case sizeof(struct input_device_id_old_32):
460 done = output_input_entry_32_old(p,
461 shortname,
462 out, conv);
463 break;
464 case sizeof(struct input_device_id_32):
465 done = output_input_entry_32(p, shortname,
466 out, conv);
467 break;
473 static void output_serio_entry(struct serio_device_id *serio, char *name, FILE *out)
475 fprintf(out,
476 "%-20s 0x%02x 0x%02x 0x%02x 0x%02x\n",
477 name,
478 serio->type,
479 serio->extra,
480 serio->id,
481 serio->proto);
485 void output_serio_table(struct module *modules, FILE *out, char *dirname)
487 struct module *i;
489 fprintf(out, "# serio module type extra id proto\n");
491 for (i = modules; i; i = i->next) {
492 struct serio_device_id *e;
493 char shortname[strlen(i->pathname) + 1];
494 struct module_tables *t = &i->tables;
496 if (!t->serio_table)
497 continue;
499 make_shortname(shortname, i->pathname);
500 for (e = t->serio_table; e->type || e->proto; e = (void *)e + t->serio_size)
501 output_serio_entry(e, shortname, out);
506 static void
507 strip_whitespace (char *str, char chr)
509 int i;
510 if (!str)
511 return;
512 for (i = strlen (str); i >= 0; --i)
513 if (isspace (*str))
514 *str = chr;
517 /* We set driver_data to zero */
518 static void output_of_entry(struct of_device_id *dev, char *name, FILE *out)
520 char *ofname = NULL, *type = NULL, *compatible = NULL;
521 if (dev->name[0]) {
522 ofname = strdup (dev->name);
523 strip_whitespace (ofname, '_');
526 if (dev->type[0]) {
527 type = strdup (dev->type);
528 strip_whitespace (type, '_');
531 if (dev->compatible[0]) {
532 compatible = strdup (dev->compatible);
533 strip_whitespace (compatible, '_');
536 fprintf (out, "%-20s %-20s %-20s %s\n",
537 name, ofname ? ofname : "*", type ? type : "*",
538 compatible ? compatible : "*");
540 free(ofname);
541 free(type);
542 free(compatible);
545 void output_of_table(struct module *modules, FILE *out, char *dirname)
547 struct module *i;
549 fprintf (out, "# of module name type compatible\n");
550 for (i = modules; i; i = i->next) {
551 struct of_device_id *e;
552 char shortname[strlen(i->pathname) + 1];
553 struct module_tables *t = &i->tables;
555 if (!t->of_table)
556 continue;
558 make_shortname(shortname, i->pathname);
559 for (e = t->of_table; e->name[0]|e->type[0]|e->compatible[0];
560 e = (void *)e + t->of_size)
561 output_of_entry(e, shortname, out);