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