Add elf_core.c into the EXTRA_SOURCES for the static library
[mit.git] / tables.c
blobe3f005fde2a78d56b1a2c3d7f59477856bb73c13
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];
48 if (!i->pci_table)
49 continue;
51 make_shortname(shortname, i->pathname);
52 for (e = i->pci_table; e->vendor; e = (void *)e + i->pci_size)
53 output_pci_entry(e, shortname, out, i->conv);
57 /* We set driver_info to zero */
58 static void output_usb_entry(struct usb_device_id *usb, char *name, FILE *out,
59 int conv)
61 fprintf(out, "%-20s 0x%04x 0x%04x 0x%04x 0x%04x"
62 " 0x%04x 0x%02x 0x%02x"
63 " 0x%02x 0x%02x"
64 " 0x%02x 0x%02x"
65 " 0x0\n",
66 name,
67 END(usb->match_flags, conv),
68 END(usb->idVendor, conv),
69 END(usb->idProduct, conv),
70 END(usb->bcdDevice_lo, conv),
71 END(usb->bcdDevice_hi, conv),
72 END(usb->bDeviceClass, conv),
73 END(usb->bDeviceSubClass, conv),
74 END(usb->bDeviceProtocol, conv),
75 END(usb->bInterfaceClass, conv),
76 END(usb->bInterfaceSubClass, conv),
77 END(usb->bInterfaceProtocol, conv));
80 void output_usb_table(struct module *modules, FILE *out, char *dirname)
82 struct module *i;
84 fprintf(out, "# usb module ");
85 /* Requires all users to be on kernel 2.4.0 or later */
86 fprintf(out, "match_flags ");
87 fprintf(out, "idVendor idProduct bcdDevice_lo bcdDevice_hi"
88 " bDeviceClass bDeviceSubClass bDeviceProtocol"
89 " bInterfaceClass bInterfaceSubClass"
90 " bInterfaceProtocol driver_info\n");
92 for (i = modules; i; i = i->next) {
93 struct usb_device_id *e;
94 char shortname[strlen(i->pathname) + 1];
96 if (!i->usb_table)
97 continue;
99 make_shortname(shortname, i->pathname);
100 for (e = i->usb_table;
101 e->idVendor || e->bDeviceClass || e->bInterfaceClass;
102 e = (void *)e + i->usb_size)
103 output_usb_entry(e, shortname, out, i->conv);
107 static void output_ieee1394_entry(struct ieee1394_device_id *fw, char *name,
108 FILE *out, int conv)
110 fprintf(out, "%-20s 0x%08x 0x%06x 0x%06x 0x%06x 0x%06x\n",
111 name,
112 END(fw->match_flags, conv),
113 END(fw->vendor_id, conv),
114 END(fw->model_id, conv),
115 END(fw->specifier_id, conv),
116 END(fw->version, conv));
119 void output_ieee1394_table(struct module *modules, FILE *out, char *dirname)
121 struct module *i;
123 fprintf(out, "# ieee1394 module ");
124 fprintf(out, "match_flags vendor_id model_id specifier_id version\n");
126 for (i = modules; i; i = i->next) {
127 struct ieee1394_device_id *fw;
128 char shortname[strlen(i->pathname) + 1];
130 if (!i->ieee1394_table)
131 continue;
133 make_shortname(shortname, i->pathname);
134 for (fw = i->ieee1394_table; fw->match_flags;
135 fw = (void *) fw + i->ieee1394_size)
136 output_ieee1394_entry(fw, shortname, out, i->conv);
141 /* We set driver_data to zero */
142 static void output_ccw_entry(struct ccw_device_id *ccw, char *name, FILE *out,
143 int conv)
145 fprintf(out, "%-20s 0x%04x 0x%04x 0x%02x 0x%04x 0x%02x\n",
146 name, END(ccw->match_flags, conv),
147 END(ccw->cu_type, conv), END(ccw->cu_model, conv),
148 END(ccw->dev_type, conv), END(ccw->dev_model, conv));
151 void output_ccw_table(struct module *modules, FILE *out, char *dirname)
153 struct module *i;
155 fprintf(out, "# ccw module ");
156 fprintf(out, "match_flags cu_type cu_model dev_type dev_model\n");
158 for (i = modules; i; i = i->next) {
159 struct ccw_device_id *e;
160 char shortname[strlen(i->pathname) + 1];
162 if (!i->ccw_table)
163 continue;
165 make_shortname(shortname, i->pathname);
166 for (e = i->ccw_table;
167 e->cu_type || e->cu_model || e->dev_type || e->dev_model;
168 e = (void *) e + i->ccw_size)
169 output_ccw_entry(e, shortname, out, i->conv);
173 #define ISAPNP_VENDOR(a,b,c) (((((a)-'A'+1)&0x3f)<<2)|\
174 ((((b)-'A'+1)&0x18)>>3)|((((b)-'A'+1)&7)<<13)|\
175 ((((c)-'A'+1)&0x1f)<<8))
176 #define ISAPNP_DEVICE(x) ((((x)&0xf000)>>8)|\
177 (((x)&0x0f00)>>8)|\
178 (((x)&0x00f0)<<8)|\
179 (((x)&0x000f)<<8))
181 static void put_isapnp_id(FILE *out, const char *id)
183 unsigned short vendor, device;
185 vendor = ISAPNP_VENDOR(id[0], id[1], id[2]);
186 device = (unsigned short)strtol(&id[3], NULL, 16);
187 device = ISAPNP_DEVICE(device);
188 fprintf(out, " 0x%04x 0x%04x ", vendor, device);
191 void output_isapnp_table(struct module *modules, FILE *out, char *dirname)
193 struct module *i;
195 fprintf(out, "# isapnp module ");
196 fprintf(out, "cardvendor carddevice driver_data vendor function ...\n");
198 for (i = modules; i; i = i->next) {
199 char shortname[strlen(i->pathname) + 1];
201 if (i->pnp_table) {
202 struct pnp_device_id *id;
203 make_shortname(shortname, i->pathname);
204 for (id = i->pnp_table;
205 id->id[0];
206 id = (void *)id + i->pnp_size) {
207 fprintf(out, "%-20s", shortname);
208 fprintf(out, " 0xffff 0xffff ");
209 fprintf(out, " 0x00000000 "); /* driver_data */
210 put_isapnp_id(out, id->id);
211 fprintf(out, "\n");
214 if (i->pnp_card_table) {
215 void *id;
216 make_shortname(shortname, i->pathname);
217 for (id = i->pnp_card_table;
218 ((char *)id)[0];
219 id += i->pnp_card_size) {
220 int idx;
221 struct pnp_card_devid *devid
222 = id + i->pnp_card_offset;
224 fprintf(out, "%-20s", shortname);
225 put_isapnp_id(out, id);
226 fprintf(out, " 0x00000000 "); /* driver_data */
227 for (idx = 0; idx < 8; idx++) {
228 if (!devid->devid[idx][0])
229 break;
230 put_isapnp_id(out, devid->devid[idx]);
232 fprintf(out, "\n");
238 #define MATCH_bustype 1
239 #define MATCH_vendor 2
240 #define MATCH_product 4
241 #define MATCH_version 8
243 #define MATCH_evbit 0x010
244 #define MATCH_keybit 0x020
245 #define MATCH_relbit 0x040
246 #define MATCH_absbit 0x080
247 #define MATCH_mscbit 0x100
248 #define MATCH_ledbit 0x200
249 #define MATCH_sndbit 0x400
250 #define MATCH_ffbit 0x800
251 #define MATCH_swbit 0x1000
253 #define MATCH(x) (END(input->match_flags, conv) & MATCH_ ## x)
254 #define PRINT_SCALAR(n) fprintf(out, " 0x%lx", MATCH(n) ? END(input->n, conv) : 0l)
255 #define PRINT_ARRAY64(n) do { \
256 fprintf(out, " "); \
257 if (MATCH(n)) \
258 output_input_bits_64(out, input->n, sizeof(input->n), conv); \
259 else \
260 fprintf(out, "%d", 0); \
261 } while (0)
263 #define PRINT_ARRAY32(n) do { \
264 fprintf(out, " "); \
265 if (MATCH(n)) \
266 output_input_bits_32(out, input->n, sizeof(input->n), conv); \
267 else \
268 fprintf(out, "%d", 0); \
269 } while (0)
271 static void output_input_bits_32(FILE *out, unsigned int *bits, int size,
272 int conv)
274 int i, j;
276 size /= sizeof(*bits);
277 for (i = size - 1; i >= 0; i--)
278 if (END(bits[i], conv))
279 break;
280 if (i < 0)
281 i = 0;
282 fprintf(out, "%x", END(bits[i], conv));
283 for (j = i - 1; j >= 0; j--)
284 fprintf(out, ":%x", END(bits[j], conv));
287 static void output_input_bits_64(FILE *out, unsigned long long *bits, int size,
288 int conv)
290 int i, j;
292 size /= sizeof(*bits);
293 for (i = size - 1; i >= 0; i--)
294 if (END(bits[i], conv))
295 break;
296 if (i < 0)
297 i = 0;
298 fprintf(out, "%llx", END(bits[i], conv));
299 for (j = i - 1; j >= 0; j--)
300 fprintf(out, ":%llx", END(bits[j], conv));
303 /* Formats are too different to */
304 static int output_input_entry_32(struct input_device_id_32 *input,
305 char *name, FILE *out, int conv)
307 if (!input->match_flags && !input->driver_info)
308 return 1;
310 fprintf(out, "%-20s0x%x", name, END(input->match_flags, conv));
312 PRINT_SCALAR(bustype);
313 PRINT_SCALAR(vendor);
314 PRINT_SCALAR(product);
315 PRINT_SCALAR(version);
317 PRINT_ARRAY32(evbit);
318 PRINT_ARRAY32(keybit);
319 PRINT_ARRAY32(relbit);
320 PRINT_ARRAY32(absbit);
321 PRINT_ARRAY32(mscbit);
322 PRINT_ARRAY32(ledbit);
323 PRINT_ARRAY32(sndbit);
324 PRINT_ARRAY32(ffbit);
325 PRINT_ARRAY32(swbit);
327 fprintf(out, " 0x%x\n", END(input->driver_info, conv));
328 return 0;
331 static int output_input_entry_32_old(struct input_device_id_old_32 *input,
332 char *name, FILE *out, int conv)
334 if (!input->match_flags && !input->driver_info)
335 return 1;
337 fprintf(out, "%-20s0x%x", name, END(input->match_flags, conv));
339 PRINT_SCALAR(bustype);
340 PRINT_SCALAR(vendor);
341 PRINT_SCALAR(product);
342 PRINT_SCALAR(version);
344 PRINT_ARRAY32(evbit);
345 PRINT_ARRAY32(keybit);
346 PRINT_ARRAY32(relbit);
347 PRINT_ARRAY32(absbit);
348 PRINT_ARRAY32(mscbit);
349 PRINT_ARRAY32(ledbit);
350 PRINT_ARRAY32(sndbit);
351 PRINT_ARRAY32(ffbit);
353 fprintf(out, " 0x%x\n", END(input->driver_info, conv));
354 return 0;
357 static int output_input_entry_64(struct input_device_id_64 *input,
358 char *name, FILE *out, int conv)
360 if (!input->match_flags && !input->driver_info)
361 return 1;
363 fprintf(out, "%-20s0x%llx", name, END(input->match_flags, conv));
365 PRINT_SCALAR(bustype);
366 PRINT_SCALAR(vendor);
367 PRINT_SCALAR(product);
368 PRINT_SCALAR(version);
370 PRINT_ARRAY64(evbit);
371 PRINT_ARRAY64(keybit);
372 PRINT_ARRAY64(relbit);
373 PRINT_ARRAY64(absbit);
374 PRINT_ARRAY64(mscbit);
375 PRINT_ARRAY64(ledbit);
376 PRINT_ARRAY64(sndbit);
377 PRINT_ARRAY64(ffbit);
378 PRINT_ARRAY64(swbit);
380 fprintf(out, " 0x%llx\n", END(input->driver_info, conv));
381 return 0;
384 static int output_input_entry_64_old(struct input_device_id_old_64 *input,
385 char *name, FILE *out, int conv)
387 if (!input->match_flags && !input->driver_info)
388 return 1;
390 fprintf(out, "%-20s0x%llx", name, END(input->match_flags, conv));
392 PRINT_SCALAR(bustype);
393 PRINT_SCALAR(vendor);
394 PRINT_SCALAR(product);
395 PRINT_SCALAR(version);
397 PRINT_ARRAY64(evbit);
398 PRINT_ARRAY64(keybit);
399 PRINT_ARRAY64(relbit);
400 PRINT_ARRAY64(absbit);
401 PRINT_ARRAY64(mscbit);
402 PRINT_ARRAY64(ledbit);
403 PRINT_ARRAY64(sndbit);
404 PRINT_ARRAY64(ffbit);
406 fprintf(out, " 0x%llx\n", END(input->driver_info, conv));
407 return 0;
410 void output_input_table(struct module *modules, FILE *out, char *dirname)
412 struct module *i;
414 fprintf(out, "# module matchBits");
415 fprintf(out, " bustype vendor product version evBits keyBits relBits");
416 fprintf(out, " absBits mscBits ledBits sndBits ffBits [swBits] driver_info\n");
418 for (i = modules; i; i = i->next) {
419 void *p;
420 char shortname[strlen(i->pathname) + 1];
421 int done = 0;
423 if (!i->input_table)
424 continue;
426 make_shortname(shortname, i->pathname);
427 /* Guess what size it really is, based on size of
428 * whole table. Table changed in 2.6.14. This is a hack. */
429 if (i->input_size == sizeof(struct input_device_id_old_64)) {
430 if ((i->input_table_size % i->input_size) != 0) {
431 i->input_size
432 = sizeof(struct input_device_id_64);
434 } else {
435 if ((i->input_table_size % i->input_size) != 0) {
436 i->input_size
437 = sizeof(struct input_device_id_32);
441 for (p = i->input_table; !done; p += i->input_size) {
442 switch (i->input_size) {
443 case sizeof(struct input_device_id_old_64):
444 done = output_input_entry_64_old(p,
445 shortname,
446 out,
447 i->conv);
448 break;
449 case sizeof(struct input_device_id_64):
450 done = output_input_entry_64(p, shortname,
451 out, i->conv);
452 break;
453 case sizeof(struct input_device_id_old_32):
454 done = output_input_entry_32_old(p,
455 shortname,
456 out,
457 i->conv);
458 break;
459 case sizeof(struct input_device_id_32):
460 done = output_input_entry_32(p, shortname,
461 out, i->conv);
462 break;
468 static void output_serio_entry(struct serio_device_id *serio, char *name, FILE *out)
470 fprintf(out,
471 "%-20s 0x%02x 0x%02x 0x%02x 0x%02x\n",
472 name,
473 serio->type,
474 serio->extra,
475 serio->id,
476 serio->proto);
480 void output_serio_table(struct module *modules, FILE *out, char *dirname)
482 struct module *i;
484 fprintf(out, "# serio module type extra id proto\n");
486 for (i = modules; i; i = i->next) {
487 struct serio_device_id *e;
488 char shortname[strlen(i->pathname) + 1];
490 if (!i->serio_table)
491 continue;
493 make_shortname(shortname, i->pathname);
494 for (e = i->serio_table; e->type || e->proto; e = (void *)e + i->serio_size)
495 output_serio_entry(e, shortname, out);
500 static void
501 strip_whitespace (char *str, char chr)
503 int i;
504 if (!str)
505 return;
506 for (i = strlen (str); i >= 0; --i)
507 if (isspace (*str))
508 *str = chr;
511 /* We set driver_data to zero */
512 static void output_of_entry(struct of_device_id *dev, char *name, FILE *out)
514 char *ofname = NULL, *type = NULL, *compatible = NULL;
515 if (dev->name[0]) {
516 ofname = strdup (dev->name);
517 strip_whitespace (ofname, '_');
520 if (dev->type[0]) {
521 type = strdup (dev->type);
522 strip_whitespace (type, '_');
525 if (dev->compatible[0]) {
526 compatible = strdup (dev->compatible);
527 strip_whitespace (compatible, '_');
530 fprintf (out, "%-20s %-20s %-20s %s\n",
531 name, ofname ? ofname : "*", type ? type : "*",
532 compatible ? compatible : "*");
534 free(ofname);
535 free(type);
536 free(compatible);
539 void output_of_table(struct module *modules, FILE *out, char *dirname)
541 struct module *i;
543 fprintf (out, "# of module name type compatible\n");
544 for (i = modules; i; i = i->next) {
545 struct of_device_id *e;
546 char shortname[strlen(i->pathname) + 1];
548 if (!i->of_table)
549 continue;
551 make_shortname(shortname, i->pathname);
552 for (e = i->of_table; e->name[0]|e->type[0]|e->compatible[0];
553 e = (void *)e + i->of_size)
554 output_of_entry(e, shortname, out);