file2alias.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /* Simple code to turn various tables in an ELF file into alias definitions.
  2. * This deals with kernel datastructures where they should be
  3. * dealt with: in the kernel source.
  4. *
  5. * Copyright 2002-2003 Rusty Russell, IBM Corporation
  6. * 2003 Kai Germaschewski
  7. *
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. */
  12. #include "modpost.h"
  13. #include "devicetable-offsets.h"
  14. /* We use the ELF typedefs for kernel_ulong_t but bite the bullet and
  15. * use either stdint.h or inttypes.h for the rest. */
  16. #if KERNEL_ELFCLASS == ELFCLASS32
  17. typedef Elf32_Addr kernel_ulong_t;
  18. #define BITS_PER_LONG 32
  19. #else
  20. typedef Elf64_Addr kernel_ulong_t;
  21. #define BITS_PER_LONG 64
  22. #endif
  23. #ifdef __sun__
  24. #include <inttypes.h>
  25. #else
  26. #include <stdint.h>
  27. #endif
  28. #include <ctype.h>
  29. #include <stdbool.h>
  30. typedef uint32_t __u32;
  31. typedef uint16_t __u16;
  32. typedef unsigned char __u8;
  33. /* Big exception to the "don't include kernel headers into userspace, which
  34. * even potentially has different endianness and word sizes, since
  35. * we handle those differences explicitly below */
  36. #include "../../include/linux/mod_devicetable.h"
  37. /* This array collects all instances that use the generic do_table */
  38. struct devtable {
  39. const char *device_id; /* name of table, __mod_<name>_device_table. */
  40. unsigned long id_size;
  41. int (*do_entry)(const char *filename, void *symval, char *alias);
  42. };
  43. /* Define a variable f that holds the value of field f of struct devid
  44. * based at address m.
  45. */
  46. #define DEF_FIELD(m, devid, f) \
  47. typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
  48. /* Define a variable f that holds the address of field f of struct devid
  49. * based at address m. Due to the way typeof works, for a field of type
  50. * T[N] the variable has type T(*)[N], _not_ T*.
  51. */
  52. #define DEF_FIELD_ADDR(m, devid, f) \
  53. typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
  54. #define ADD(str, sep, cond, field) \
  55. do { \
  56. strcat(str, sep); \
  57. if (cond) \
  58. sprintf(str + strlen(str), \
  59. sizeof(field) == 1 ? "%02X" : \
  60. sizeof(field) == 2 ? "%04X" : \
  61. sizeof(field) == 4 ? "%08X" : "", \
  62. field); \
  63. else \
  64. sprintf(str + strlen(str), "*"); \
  65. } while(0)
  66. /* Always end in a wildcard, for future extension */
  67. static inline void add_wildcard(char *str)
  68. {
  69. int len = strlen(str);
  70. if (str[len - 1] != '*')
  71. strcat(str + len, "*");
  72. }
  73. /**
  74. * Check that sizeof(device_id type) are consistent with size of section
  75. * in .o file. If in-consistent then userspace and kernel does not agree
  76. * on actual size which is a bug.
  77. * Also verify that the final entry in the table is all zeros.
  78. * Ignore both checks if build host differ from target host and size differs.
  79. **/
  80. static void device_id_check(const char *modname, const char *device_id,
  81. unsigned long size, unsigned long id_size,
  82. void *symval)
  83. {
  84. int i;
  85. if (size % id_size || size < id_size) {
  86. fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
  87. "of the size of section __mod_%s_device_table=%lu.\n"
  88. "Fix definition of struct %s_device_id "
  89. "in mod_devicetable.h\n",
  90. modname, device_id, id_size, device_id, size, device_id);
  91. }
  92. /* Verify last one is a terminator */
  93. for (i = 0; i < id_size; i++ ) {
  94. if (*(uint8_t*)(symval+size-id_size+i)) {
  95. fprintf(stderr,"%s: struct %s_device_id is %lu bytes. "
  96. "The last of %lu is:\n",
  97. modname, device_id, id_size, size / id_size);
  98. for (i = 0; i < id_size; i++ )
  99. fprintf(stderr,"0x%02x ",
  100. *(uint8_t*)(symval+size-id_size+i) );
  101. fprintf(stderr,"\n");
  102. fatal("%s: struct %s_device_id is not terminated "
  103. "with a NULL entry!\n", modname, device_id);
  104. }
  105. }
  106. }
  107. /* USB is special because the bcdDevice can be matched against a numeric range */
  108. /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
  109. static void do_usb_entry(void *symval,
  110. unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
  111. unsigned char range_lo, unsigned char range_hi,
  112. unsigned char max, struct module *mod)
  113. {
  114. char alias[500];
  115. DEF_FIELD(symval, usb_device_id, match_flags);
  116. DEF_FIELD(symval, usb_device_id, idVendor);
  117. DEF_FIELD(symval, usb_device_id, idProduct);
  118. DEF_FIELD(symval, usb_device_id, bcdDevice_lo);
  119. DEF_FIELD(symval, usb_device_id, bDeviceClass);
  120. DEF_FIELD(symval, usb_device_id, bDeviceSubClass);
  121. DEF_FIELD(symval, usb_device_id, bDeviceProtocol);
  122. DEF_FIELD(symval, usb_device_id, bInterfaceClass);
  123. DEF_FIELD(symval, usb_device_id, bInterfaceSubClass);
  124. DEF_FIELD(symval, usb_device_id, bInterfaceProtocol);
  125. DEF_FIELD(symval, usb_device_id, bInterfaceNumber);
  126. strcpy(alias, "usb:");
  127. ADD(alias, "v", match_flags&USB_DEVICE_ID_MATCH_VENDOR,
  128. idVendor);
  129. ADD(alias, "p", match_flags&USB_DEVICE_ID_MATCH_PRODUCT,
  130. idProduct);
  131. strcat(alias, "d");
  132. if (bcdDevice_initial_digits)
  133. sprintf(alias + strlen(alias), "%0*X",
  134. bcdDevice_initial_digits, bcdDevice_initial);
  135. if (range_lo == range_hi)
  136. sprintf(alias + strlen(alias), "%X", range_lo);
  137. else if (range_lo > 0 || range_hi < max) {
  138. if (range_lo > 0x9 || range_hi < 0xA)
  139. sprintf(alias + strlen(alias),
  140. "[%X-%X]",
  141. range_lo,
  142. range_hi);
  143. else {
  144. sprintf(alias + strlen(alias),
  145. range_lo < 0x9 ? "[%X-9" : "[%X",
  146. range_lo);
  147. sprintf(alias + strlen(alias),
  148. range_hi > 0xA ? "A-%X]" : "%X]",
  149. range_hi);
  150. }
  151. }
  152. if (bcdDevice_initial_digits < (sizeof(bcdDevice_lo) * 2 - 1))
  153. strcat(alias, "*");
  154. ADD(alias, "dc", match_flags&USB_DEVICE_ID_MATCH_DEV_CLASS,
  155. bDeviceClass);
  156. ADD(alias, "dsc", match_flags&USB_DEVICE_ID_MATCH_DEV_SUBCLASS,
  157. bDeviceSubClass);
  158. ADD(alias, "dp", match_flags&USB_DEVICE_ID_MATCH_DEV_PROTOCOL,
  159. bDeviceProtocol);
  160. ADD(alias, "ic", match_flags&USB_DEVICE_ID_MATCH_INT_CLASS,
  161. bInterfaceClass);
  162. ADD(alias, "isc", match_flags&USB_DEVICE_ID_MATCH_INT_SUBCLASS,
  163. bInterfaceSubClass);
  164. ADD(alias, "ip", match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL,
  165. bInterfaceProtocol);
  166. ADD(alias, "in", match_flags&USB_DEVICE_ID_MATCH_INT_NUMBER,
  167. bInterfaceNumber);
  168. add_wildcard(alias);
  169. buf_printf(&mod->dev_table_buf,
  170. "MODULE_ALIAS(\"%s\");\n", alias);
  171. }
  172. /* Handles increment/decrement of BCD formatted integers */
  173. /* Returns the previous value, so it works like i++ or i-- */
  174. static unsigned int incbcd(unsigned int *bcd,
  175. int inc,
  176. unsigned char max,
  177. size_t chars)
  178. {
  179. unsigned int init = *bcd, i, j;
  180. unsigned long long c, dec = 0;
  181. /* If bcd is not in BCD format, just increment */
  182. if (max > 0x9) {
  183. *bcd += inc;
  184. return init;
  185. }
  186. /* Convert BCD to Decimal */
  187. for (i=0 ; i < chars ; i++) {
  188. c = (*bcd >> (i << 2)) & 0xf;
  189. c = c > 9 ? 9 : c; /* force to bcd just in case */
  190. for (j=0 ; j < i ; j++)
  191. c = c * 10;
  192. dec += c;
  193. }
  194. /* Do our increment/decrement */
  195. dec += inc;
  196. *bcd = 0;
  197. /* Convert back to BCD */
  198. for (i=0 ; i < chars ; i++) {
  199. for (c=1,j=0 ; j < i ; j++)
  200. c = c * 10;
  201. c = (dec / c) % 10;
  202. *bcd += c << (i << 2);
  203. }
  204. return init;
  205. }
  206. static void do_usb_entry_multi(void *symval, struct module *mod)
  207. {
  208. unsigned int devlo, devhi;
  209. unsigned char chi, clo, max;
  210. int ndigits;
  211. DEF_FIELD(symval, usb_device_id, match_flags);
  212. DEF_FIELD(symval, usb_device_id, idVendor);
  213. DEF_FIELD(symval, usb_device_id, idProduct);
  214. DEF_FIELD(symval, usb_device_id, bcdDevice_lo);
  215. DEF_FIELD(symval, usb_device_id, bcdDevice_hi);
  216. DEF_FIELD(symval, usb_device_id, bDeviceClass);
  217. DEF_FIELD(symval, usb_device_id, bInterfaceClass);
  218. devlo = match_flags & USB_DEVICE_ID_MATCH_DEV_LO ?
  219. bcdDevice_lo : 0x0U;
  220. devhi = match_flags & USB_DEVICE_ID_MATCH_DEV_HI ?
  221. bcdDevice_hi : ~0x0U;
  222. /* Figure out if this entry is in bcd or hex format */
  223. max = 0x9; /* Default to decimal format */
  224. for (ndigits = 0 ; ndigits < sizeof(bcdDevice_lo) * 2 ; ndigits++) {
  225. clo = (devlo >> (ndigits << 2)) & 0xf;
  226. chi = ((devhi > 0x9999 ? 0x9999 : devhi) >> (ndigits << 2)) & 0xf;
  227. if (clo > max || chi > max) {
  228. max = 0xf;
  229. break;
  230. }
  231. }
  232. /*
  233. * Some modules (visor) have empty slots as placeholder for
  234. * run-time specification that results in catch-all alias
  235. */
  236. if (!(idVendor | idProduct | bDeviceClass | bInterfaceClass))
  237. return;
  238. /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
  239. for (ndigits = sizeof(bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) {
  240. clo = devlo & 0xf;
  241. chi = devhi & 0xf;
  242. if (chi > max) /* If we are in bcd mode, truncate if necessary */
  243. chi = max;
  244. devlo >>= 4;
  245. devhi >>= 4;
  246. if (devlo == devhi || !ndigits) {
  247. do_usb_entry(symval, devlo, ndigits, clo, chi, max, mod);
  248. break;
  249. }
  250. if (clo > 0x0)
  251. do_usb_entry(symval,
  252. incbcd(&devlo, 1, max,
  253. sizeof(bcdDevice_lo) * 2),
  254. ndigits, clo, max, max, mod);
  255. if (chi < max)
  256. do_usb_entry(symval,
  257. incbcd(&devhi, -1, max,
  258. sizeof(bcdDevice_lo) * 2),
  259. ndigits, 0x0, chi, max, mod);
  260. }
  261. }
  262. static void do_usb_table(void *symval, unsigned long size,
  263. struct module *mod)
  264. {
  265. unsigned int i;
  266. const unsigned long id_size = SIZE_usb_device_id;
  267. device_id_check(mod->name, "usb", size, id_size, symval);
  268. /* Leave last one: it's the terminator. */
  269. size -= id_size;
  270. for (i = 0; i < size; i += id_size)
  271. do_usb_entry_multi(symval + i, mod);
  272. }
  273. /* Looks like: hid:bNvNpN */
  274. static int do_hid_entry(const char *filename,
  275. void *symval, char *alias)
  276. {
  277. DEF_FIELD(symval, hid_device_id, bus);
  278. DEF_FIELD(symval, hid_device_id, group);
  279. DEF_FIELD(symval, hid_device_id, vendor);
  280. DEF_FIELD(symval, hid_device_id, product);
  281. sprintf(alias, "hid:");
  282. ADD(alias, "b", bus != HID_BUS_ANY, bus);
  283. ADD(alias, "g", group != HID_GROUP_ANY, group);
  284. ADD(alias, "v", vendor != HID_ANY_ID, vendor);
  285. ADD(alias, "p", product != HID_ANY_ID, product);
  286. return 1;
  287. }
  288. /* Looks like: ieee1394:venNmoNspNverN */
  289. static int do_ieee1394_entry(const char *filename,
  290. void *symval, char *alias)
  291. {
  292. DEF_FIELD(symval, ieee1394_device_id, match_flags);
  293. DEF_FIELD(symval, ieee1394_device_id, vendor_id);
  294. DEF_FIELD(symval, ieee1394_device_id, model_id);
  295. DEF_FIELD(symval, ieee1394_device_id, specifier_id);
  296. DEF_FIELD(symval, ieee1394_device_id, version);
  297. strcpy(alias, "ieee1394:");
  298. ADD(alias, "ven", match_flags & IEEE1394_MATCH_VENDOR_ID,
  299. vendor_id);
  300. ADD(alias, "mo", match_flags & IEEE1394_MATCH_MODEL_ID,
  301. model_id);
  302. ADD(alias, "sp", match_flags & IEEE1394_MATCH_SPECIFIER_ID,
  303. specifier_id);
  304. ADD(alias, "ver", match_flags & IEEE1394_MATCH_VERSION,
  305. version);
  306. add_wildcard(alias);
  307. return 1;
  308. }
  309. /* Looks like: pci:vNdNsvNsdNbcNscNiN. */
  310. static int do_pci_entry(const char *filename,
  311. void *symval, char *alias)
  312. {
  313. /* Class field can be divided into these three. */
  314. unsigned char baseclass, subclass, interface,
  315. baseclass_mask, subclass_mask, interface_mask;
  316. DEF_FIELD(symval, pci_device_id, vendor);
  317. DEF_FIELD(symval, pci_device_id, device);
  318. DEF_FIELD(symval, pci_device_id, subvendor);
  319. DEF_FIELD(symval, pci_device_id, subdevice);
  320. DEF_FIELD(symval, pci_device_id, class);
  321. DEF_FIELD(symval, pci_device_id, class_mask);
  322. strcpy(alias, "pci:");
  323. ADD(alias, "v", vendor != PCI_ANY_ID, vendor);
  324. ADD(alias, "d", device != PCI_ANY_ID, device);
  325. ADD(alias, "sv", subvendor != PCI_ANY_ID, subvendor);
  326. ADD(alias, "sd", subdevice != PCI_ANY_ID, subdevice);
  327. baseclass = (class) >> 16;
  328. baseclass_mask = (class_mask) >> 16;
  329. subclass = (class) >> 8;
  330. subclass_mask = (class_mask) >> 8;
  331. interface = class;
  332. interface_mask = class_mask;
  333. if ((baseclass_mask != 0 && baseclass_mask != 0xFF)
  334. || (subclass_mask != 0 && subclass_mask != 0xFF)
  335. || (interface_mask != 0 && interface_mask != 0xFF)) {
  336. warn("Can't handle masks in %s:%04X\n",
  337. filename, class_mask);
  338. return 0;
  339. }
  340. ADD(alias, "bc", baseclass_mask == 0xFF, baseclass);
  341. ADD(alias, "sc", subclass_mask == 0xFF, subclass);
  342. ADD(alias, "i", interface_mask == 0xFF, interface);
  343. add_wildcard(alias);
  344. return 1;
  345. }
  346. /* looks like: "ccw:tNmNdtNdmN" */
  347. static int do_ccw_entry(const char *filename,
  348. void *symval, char *alias)
  349. {
  350. DEF_FIELD(symval, ccw_device_id, match_flags);
  351. DEF_FIELD(symval, ccw_device_id, cu_type);
  352. DEF_FIELD(symval, ccw_device_id, cu_model);
  353. DEF_FIELD(symval, ccw_device_id, dev_type);
  354. DEF_FIELD(symval, ccw_device_id, dev_model);
  355. strcpy(alias, "ccw:");
  356. ADD(alias, "t", match_flags&CCW_DEVICE_ID_MATCH_CU_TYPE,
  357. cu_type);
  358. ADD(alias, "m", match_flags&CCW_DEVICE_ID_MATCH_CU_MODEL,
  359. cu_model);
  360. ADD(alias, "dt", match_flags&CCW_DEVICE_ID_MATCH_DEVICE_TYPE,
  361. dev_type);
  362. ADD(alias, "dm", match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL,
  363. dev_model);
  364. add_wildcard(alias);
  365. return 1;
  366. }
  367. /* looks like: "ap:tN" */
  368. static int do_ap_entry(const char *filename,
  369. void *symval, char *alias)
  370. {
  371. DEF_FIELD(symval, ap_device_id, dev_type);
  372. sprintf(alias, "ap:t%02X*", dev_type);
  373. return 1;
  374. }
  375. /* looks like: "css:tN" */
  376. static int do_css_entry(const char *filename,
  377. void *symval, char *alias)
  378. {
  379. DEF_FIELD(symval, css_device_id, type);
  380. sprintf(alias, "css:t%01X", type);
  381. return 1;
  382. }
  383. /* Looks like: "serio:tyNprNidNexN" */
  384. static int do_serio_entry(const char *filename,
  385. void *symval, char *alias)
  386. {
  387. DEF_FIELD(symval, serio_device_id, type);
  388. DEF_FIELD(symval, serio_device_id, proto);
  389. DEF_FIELD(symval, serio_device_id, id);
  390. DEF_FIELD(symval, serio_device_id, extra);
  391. strcpy(alias, "serio:");
  392. ADD(alias, "ty", type != SERIO_ANY, type);
  393. ADD(alias, "pr", proto != SERIO_ANY, proto);
  394. ADD(alias, "id", id != SERIO_ANY, id);
  395. ADD(alias, "ex", extra != SERIO_ANY, extra);
  396. add_wildcard(alias);
  397. return 1;
  398. }
  399. /* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */
  400. static int do_acpi_entry(const char *filename,
  401. void *symval, char *alias)
  402. {
  403. DEF_FIELD_ADDR(symval, acpi_device_id, id);
  404. sprintf(alias, "acpi*:%s:*", *id);
  405. return 1;
  406. }
  407. /* looks like: "pnp:dD" */
  408. static void do_pnp_device_entry(void *symval, unsigned long size,
  409. struct module *mod)
  410. {
  411. const unsigned long id_size = SIZE_pnp_device_id;
  412. const unsigned int count = (size / id_size)-1;
  413. unsigned int i;
  414. device_id_check(mod->name, "pnp", size, id_size, symval);
  415. for (i = 0; i < count; i++) {
  416. DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
  417. char acpi_id[sizeof(*id)];
  418. int j;
  419. buf_printf(&mod->dev_table_buf,
  420. "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
  421. /* fix broken pnp bus lowercasing */
  422. for (j = 0; j < sizeof(acpi_id); j++)
  423. acpi_id[j] = toupper((*id)[j]);
  424. buf_printf(&mod->dev_table_buf,
  425. "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
  426. }
  427. }
  428. /* looks like: "pnp:dD" for every device of the card */
  429. static void do_pnp_card_entries(void *symval, unsigned long size,
  430. struct module *mod)
  431. {
  432. const unsigned long id_size = SIZE_pnp_card_device_id;
  433. const unsigned int count = (size / id_size)-1;
  434. unsigned int i;
  435. device_id_check(mod->name, "pnp", size, id_size, symval);
  436. for (i = 0; i < count; i++) {
  437. unsigned int j;
  438. DEF_FIELD_ADDR(symval + i*id_size, pnp_card_device_id, devs);
  439. for (j = 0; j < PNP_MAX_DEVICES; j++) {
  440. const char *id = (char *)(*devs)[j].id;
  441. int i2, j2;
  442. int dup = 0;
  443. if (!id[0])
  444. break;
  445. /* find duplicate, already added value */
  446. for (i2 = 0; i2 < i && !dup; i2++) {
  447. DEF_FIELD_ADDR(symval + i2*id_size, pnp_card_device_id, devs);
  448. for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
  449. const char *id2 = (char *)(*devs)[j2].id;
  450. if (!id2[0])
  451. break;
  452. if (!strcmp(id, id2)) {
  453. dup = 1;
  454. break;
  455. }
  456. }
  457. }
  458. /* add an individual alias for every device entry */
  459. if (!dup) {
  460. char acpi_id[PNP_ID_LEN];
  461. int k;
  462. buf_printf(&mod->dev_table_buf,
  463. "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
  464. /* fix broken pnp bus lowercasing */
  465. for (k = 0; k < sizeof(acpi_id); k++)
  466. acpi_id[k] = toupper(id[k]);
  467. buf_printf(&mod->dev_table_buf,
  468. "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
  469. }
  470. }
  471. }
  472. }
  473. /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
  474. static int do_pcmcia_entry(const char *filename,
  475. void *symval, char *alias)
  476. {
  477. unsigned int i;
  478. DEF_FIELD(symval, pcmcia_device_id, match_flags);
  479. DEF_FIELD(symval, pcmcia_device_id, manf_id);
  480. DEF_FIELD(symval, pcmcia_device_id, card_id);
  481. DEF_FIELD(symval, pcmcia_device_id, func_id);
  482. DEF_FIELD(symval, pcmcia_device_id, function);
  483. DEF_FIELD(symval, pcmcia_device_id, device_no);
  484. DEF_FIELD_ADDR(symval, pcmcia_device_id, prod_id_hash);
  485. for (i=0; i<4; i++) {
  486. (*prod_id_hash)[i] = TO_NATIVE((*prod_id_hash)[i]);
  487. }
  488. strcpy(alias, "pcmcia:");
  489. ADD(alias, "m", match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID,
  490. manf_id);
  491. ADD(alias, "c", match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID,
  492. card_id);
  493. ADD(alias, "f", match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID,
  494. func_id);
  495. ADD(alias, "fn", match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION,
  496. function);
  497. ADD(alias, "pfn", match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO,
  498. device_no);
  499. ADD(alias, "pa", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, (*prod_id_hash)[0]);
  500. ADD(alias, "pb", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, (*prod_id_hash)[1]);
  501. ADD(alias, "pc", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, (*prod_id_hash)[2]);
  502. ADD(alias, "pd", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, (*prod_id_hash)[3]);
  503. add_wildcard(alias);
  504. return 1;
  505. }
  506. static int do_of_entry (const char *filename, void *symval, char *alias)
  507. {
  508. int len;
  509. char *tmp;
  510. DEF_FIELD_ADDR(symval, of_device_id, name);
  511. DEF_FIELD_ADDR(symval, of_device_id, type);
  512. DEF_FIELD_ADDR(symval, of_device_id, compatible);
  513. len = sprintf (alias, "of:N%sT%s",
  514. (*name)[0] ? *name : "*",
  515. (*type)[0] ? *type : "*");
  516. if (compatible[0])
  517. sprintf (&alias[len], "%sC%s",
  518. (*type)[0] ? "*" : "",
  519. *compatible);
  520. /* Replace all whitespace with underscores */
  521. for (tmp = alias; tmp && *tmp; tmp++)
  522. if (isspace (*tmp))
  523. *tmp = '_';
  524. add_wildcard(alias);
  525. return 1;
  526. }
  527. static int do_vio_entry(const char *filename, void *symval,
  528. char *alias)
  529. {
  530. char *tmp;
  531. DEF_FIELD_ADDR(symval, vio_device_id, type);
  532. DEF_FIELD_ADDR(symval, vio_device_id, compat);
  533. sprintf(alias, "vio:T%sS%s", (*type)[0] ? *type : "*",
  534. (*compat)[0] ? *compat : "*");
  535. /* Replace all whitespace with underscores */
  536. for (tmp = alias; tmp && *tmp; tmp++)
  537. if (isspace (*tmp))
  538. *tmp = '_';
  539. add_wildcard(alias);
  540. return 1;
  541. }
  542. #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
  543. static void do_input(char *alias,
  544. kernel_ulong_t *arr, unsigned int min, unsigned int max)
  545. {
  546. unsigned int i;
  547. for (i = min / BITS_PER_LONG; i < max / BITS_PER_LONG + 1; i++)
  548. arr[i] = TO_NATIVE(arr[i]);
  549. for (i = min; i < max; i++)
  550. if (arr[i / BITS_PER_LONG] & (1L << (i%BITS_PER_LONG)))
  551. sprintf(alias + strlen(alias), "%X,*", i);
  552. }
  553. /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */
  554. static int do_input_entry(const char *filename, void *symval,
  555. char *alias)
  556. {
  557. DEF_FIELD(symval, input_device_id, flags);
  558. DEF_FIELD(symval, input_device_id, bustype);
  559. DEF_FIELD(symval, input_device_id, vendor);
  560. DEF_FIELD(symval, input_device_id, product);
  561. DEF_FIELD(symval, input_device_id, version);
  562. DEF_FIELD_ADDR(symval, input_device_id, evbit);
  563. DEF_FIELD_ADDR(symval, input_device_id, keybit);
  564. DEF_FIELD_ADDR(symval, input_device_id, relbit);
  565. DEF_FIELD_ADDR(symval, input_device_id, absbit);
  566. DEF_FIELD_ADDR(symval, input_device_id, mscbit);
  567. DEF_FIELD_ADDR(symval, input_device_id, ledbit);
  568. DEF_FIELD_ADDR(symval, input_device_id, sndbit);
  569. DEF_FIELD_ADDR(symval, input_device_id, ffbit);
  570. DEF_FIELD_ADDR(symval, input_device_id, swbit);
  571. sprintf(alias, "input:");
  572. ADD(alias, "b", flags & INPUT_DEVICE_ID_MATCH_BUS, bustype);
  573. ADD(alias, "v", flags & INPUT_DEVICE_ID_MATCH_VENDOR, vendor);
  574. ADD(alias, "p", flags & INPUT_DEVICE_ID_MATCH_PRODUCT, product);
  575. ADD(alias, "e", flags & INPUT_DEVICE_ID_MATCH_VERSION, version);
  576. sprintf(alias + strlen(alias), "-e*");
  577. if (flags & INPUT_DEVICE_ID_MATCH_EVBIT)
  578. do_input(alias, *evbit, 0, INPUT_DEVICE_ID_EV_MAX);
  579. sprintf(alias + strlen(alias), "k*");
  580. if (flags & INPUT_DEVICE_ID_MATCH_KEYBIT)
  581. do_input(alias, *keybit,
  582. INPUT_DEVICE_ID_KEY_MIN_INTERESTING,
  583. INPUT_DEVICE_ID_KEY_MAX);
  584. sprintf(alias + strlen(alias), "r*");
  585. if (flags & INPUT_DEVICE_ID_MATCH_RELBIT)
  586. do_input(alias, *relbit, 0, INPUT_DEVICE_ID_REL_MAX);
  587. sprintf(alias + strlen(alias), "a*");
  588. if (flags & INPUT_DEVICE_ID_MATCH_ABSBIT)
  589. do_input(alias, *absbit, 0, INPUT_DEVICE_ID_ABS_MAX);
  590. sprintf(alias + strlen(alias), "m*");
  591. if (flags & INPUT_DEVICE_ID_MATCH_MSCIT)
  592. do_input(alias, *mscbit, 0, INPUT_DEVICE_ID_MSC_MAX);
  593. sprintf(alias + strlen(alias), "l*");
  594. if (flags & INPUT_DEVICE_ID_MATCH_LEDBIT)
  595. do_input(alias, *ledbit, 0, INPUT_DEVICE_ID_LED_MAX);
  596. sprintf(alias + strlen(alias), "s*");
  597. if (flags & INPUT_DEVICE_ID_MATCH_SNDBIT)
  598. do_input(alias, *sndbit, 0, INPUT_DEVICE_ID_SND_MAX);
  599. sprintf(alias + strlen(alias), "f*");
  600. if (flags & INPUT_DEVICE_ID_MATCH_FFBIT)
  601. do_input(alias, *ffbit, 0, INPUT_DEVICE_ID_FF_MAX);
  602. sprintf(alias + strlen(alias), "w*");
  603. if (flags & INPUT_DEVICE_ID_MATCH_SWBIT)
  604. do_input(alias, *swbit, 0, INPUT_DEVICE_ID_SW_MAX);
  605. return 1;
  606. }
  607. static int do_eisa_entry(const char *filename, void *symval,
  608. char *alias)
  609. {
  610. DEF_FIELD_ADDR(symval, eisa_device_id, sig);
  611. if (sig[0])
  612. sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", *sig);
  613. else
  614. strcat(alias, "*");
  615. return 1;
  616. }
  617. /* Looks like: parisc:tNhvNrevNsvN */
  618. static int do_parisc_entry(const char *filename, void *symval,
  619. char *alias)
  620. {
  621. DEF_FIELD(symval, parisc_device_id, hw_type);
  622. DEF_FIELD(symval, parisc_device_id, hversion);
  623. DEF_FIELD(symval, parisc_device_id, hversion_rev);
  624. DEF_FIELD(symval, parisc_device_id, sversion);
  625. strcpy(alias, "parisc:");
  626. ADD(alias, "t", hw_type != PA_HWTYPE_ANY_ID, hw_type);
  627. ADD(alias, "hv", hversion != PA_HVERSION_ANY_ID, hversion);
  628. ADD(alias, "rev", hversion_rev != PA_HVERSION_REV_ANY_ID, hversion_rev);
  629. ADD(alias, "sv", sversion != PA_SVERSION_ANY_ID, sversion);
  630. add_wildcard(alias);
  631. return 1;
  632. }
  633. /* Looks like: sdio:cNvNdN. */
  634. static int do_sdio_entry(const char *filename,
  635. void *symval, char *alias)
  636. {
  637. DEF_FIELD(symval, sdio_device_id, class);
  638. DEF_FIELD(symval, sdio_device_id, vendor);
  639. DEF_FIELD(symval, sdio_device_id, device);
  640. strcpy(alias, "sdio:");
  641. ADD(alias, "c", class != (__u8)SDIO_ANY_ID, class);
  642. ADD(alias, "v", vendor != (__u16)SDIO_ANY_ID, vendor);
  643. ADD(alias, "d", device != (__u16)SDIO_ANY_ID, device);
  644. add_wildcard(alias);
  645. return 1;
  646. }
  647. /* Looks like: ssb:vNidNrevN. */
  648. static int do_ssb_entry(const char *filename,
  649. void *symval, char *alias)
  650. {
  651. DEF_FIELD(symval, ssb_device_id, vendor);
  652. DEF_FIELD(symval, ssb_device_id, coreid);
  653. DEF_FIELD(symval, ssb_device_id, revision);
  654. strcpy(alias, "ssb:");
  655. ADD(alias, "v", vendor != SSB_ANY_VENDOR, vendor);
  656. ADD(alias, "id", coreid != SSB_ANY_ID, coreid);
  657. ADD(alias, "rev", revision != SSB_ANY_REV, revision);
  658. add_wildcard(alias);
  659. return 1;
  660. }
  661. /* Looks like: bcma:mNidNrevNclN. */
  662. static int do_bcma_entry(const char *filename,
  663. void *symval, char *alias)
  664. {
  665. DEF_FIELD(symval, bcma_device_id, manuf);
  666. DEF_FIELD(symval, bcma_device_id, id);
  667. DEF_FIELD(symval, bcma_device_id, rev);
  668. DEF_FIELD(symval, bcma_device_id, class);
  669. strcpy(alias, "bcma:");
  670. ADD(alias, "m", manuf != BCMA_ANY_MANUF, manuf);
  671. ADD(alias, "id", id != BCMA_ANY_ID, id);
  672. ADD(alias, "rev", rev != BCMA_ANY_REV, rev);
  673. ADD(alias, "cl", class != BCMA_ANY_CLASS, class);
  674. add_wildcard(alias);
  675. return 1;
  676. }
  677. /* Looks like: virtio:dNvN */
  678. static int do_virtio_entry(const char *filename, void *symval,
  679. char *alias)
  680. {
  681. DEF_FIELD(symval, virtio_device_id, device);
  682. DEF_FIELD(symval, virtio_device_id, vendor);
  683. strcpy(alias, "virtio:");
  684. ADD(alias, "d", device != VIRTIO_DEV_ANY_ID, device);
  685. ADD(alias, "v", vendor != VIRTIO_DEV_ANY_ID, vendor);
  686. add_wildcard(alias);
  687. return 1;
  688. }
  689. /*
  690. * Looks like: vmbus:guid
  691. * Each byte of the guid will be represented by two hex characters
  692. * in the name.
  693. */
  694. static int do_vmbus_entry(const char *filename, void *symval,
  695. char *alias)
  696. {
  697. int i;
  698. DEF_FIELD_ADDR(symval, hv_vmbus_device_id, guid);
  699. char guid_name[(sizeof(*guid) + 1) * 2];
  700. for (i = 0; i < (sizeof(*guid) * 2); i += 2)
  701. sprintf(&guid_name[i], "%02x", TO_NATIVE((*guid)[i/2]));
  702. strcpy(alias, "vmbus:");
  703. strcat(alias, guid_name);
  704. return 1;
  705. }
  706. /* Looks like: i2c:S */
  707. static int do_i2c_entry(const char *filename, void *symval,
  708. char *alias)
  709. {
  710. DEF_FIELD_ADDR(symval, i2c_device_id, name);
  711. sprintf(alias, I2C_MODULE_PREFIX "%s", *name);
  712. return 1;
  713. }
  714. /* Looks like: spi:S */
  715. static int do_spi_entry(const char *filename, void *symval,
  716. char *alias)
  717. {
  718. DEF_FIELD_ADDR(symval, spi_device_id, name);
  719. sprintf(alias, SPI_MODULE_PREFIX "%s", *name);
  720. return 1;
  721. }
  722. static const struct dmifield {
  723. const char *prefix;
  724. int field;
  725. } dmi_fields[] = {
  726. { "bvn", DMI_BIOS_VENDOR },
  727. { "bvr", DMI_BIOS_VERSION },
  728. { "bd", DMI_BIOS_DATE },
  729. { "svn", DMI_SYS_VENDOR },
  730. { "pn", DMI_PRODUCT_NAME },
  731. { "pvr", DMI_PRODUCT_VERSION },
  732. { "rvn", DMI_BOARD_VENDOR },
  733. { "rn", DMI_BOARD_NAME },
  734. { "rvr", DMI_BOARD_VERSION },
  735. { "cvn", DMI_CHASSIS_VENDOR },
  736. { "ct", DMI_CHASSIS_TYPE },
  737. { "cvr", DMI_CHASSIS_VERSION },
  738. { NULL, DMI_NONE }
  739. };
  740. static void dmi_ascii_filter(char *d, const char *s)
  741. {
  742. /* Filter out characters we don't want to see in the modalias string */
  743. for (; *s; s++)
  744. if (*s > ' ' && *s < 127 && *s != ':')
  745. *(d++) = *s;
  746. *d = 0;
  747. }
  748. static int do_dmi_entry(const char *filename, void *symval,
  749. char *alias)
  750. {
  751. int i, j;
  752. DEF_FIELD_ADDR(symval, dmi_system_id, matches);
  753. sprintf(alias, "dmi*");
  754. for (i = 0; i < ARRAY_SIZE(dmi_fields); i++) {
  755. for (j = 0; j < 4; j++) {
  756. if ((*matches)[j].slot &&
  757. (*matches)[j].slot == dmi_fields[i].field) {
  758. sprintf(alias + strlen(alias), ":%s*",
  759. dmi_fields[i].prefix);
  760. dmi_ascii_filter(alias + strlen(alias),
  761. (*matches)[j].substr);
  762. strcat(alias, "*");
  763. }
  764. }
  765. }
  766. strcat(alias, ":");
  767. return 1;
  768. }
  769. static int do_platform_entry(const char *filename,
  770. void *symval, char *alias)
  771. {
  772. DEF_FIELD_ADDR(symval, platform_device_id, name);
  773. sprintf(alias, PLATFORM_MODULE_PREFIX "%s", *name);
  774. return 1;
  775. }
  776. static int do_mdio_entry(const char *filename,
  777. void *symval, char *alias)
  778. {
  779. int i;
  780. DEF_FIELD(symval, mdio_device_id, phy_id);
  781. DEF_FIELD(symval, mdio_device_id, phy_id_mask);
  782. alias += sprintf(alias, MDIO_MODULE_PREFIX);
  783. for (i = 0; i < 32; i++) {
  784. if (!((phy_id_mask >> (31-i)) & 1))
  785. *(alias++) = '?';
  786. else if ((phy_id >> (31-i)) & 1)
  787. *(alias++) = '1';
  788. else
  789. *(alias++) = '0';
  790. }
  791. /* Terminate the string */
  792. *alias = 0;
  793. return 1;
  794. }
  795. /* Looks like: zorro:iN. */
  796. static int do_zorro_entry(const char *filename, void *symval,
  797. char *alias)
  798. {
  799. DEF_FIELD(symval, zorro_device_id, id);
  800. strcpy(alias, "zorro:");
  801. ADD(alias, "i", id != ZORRO_WILDCARD, id);
  802. return 1;
  803. }
  804. /* looks like: "pnp:dD" */
  805. static int do_isapnp_entry(const char *filename,
  806. void *symval, char *alias)
  807. {
  808. DEF_FIELD(symval, isapnp_device_id, vendor);
  809. DEF_FIELD(symval, isapnp_device_id, function);
  810. sprintf(alias, "pnp:d%c%c%c%x%x%x%x*",
  811. 'A' + ((vendor >> 2) & 0x3f) - 1,
  812. 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
  813. 'A' + ((vendor >> 8) & 0x1f) - 1,
  814. (function >> 4) & 0x0f, function & 0x0f,
  815. (function >> 12) & 0x0f, (function >> 8) & 0x0f);
  816. return 1;
  817. }
  818. /*
  819. * Append a match expression for a single masked hex digit.
  820. * outp points to a pointer to the character at which to append.
  821. * *outp is updated on return to point just after the appended text,
  822. * to facilitate further appending.
  823. */
  824. static void append_nibble_mask(char **outp,
  825. unsigned int nibble, unsigned int mask)
  826. {
  827. char *p = *outp;
  828. unsigned int i;
  829. switch (mask) {
  830. case 0:
  831. *p++ = '?';
  832. break;
  833. case 0xf:
  834. p += sprintf(p, "%X", nibble);
  835. break;
  836. default:
  837. /*
  838. * Dumbly emit a match pattern for all possible matching
  839. * digits. This could be improved in some cases using ranges,
  840. * but it has the advantage of being trivially correct, and is
  841. * often optimal.
  842. */
  843. *p++ = '[';
  844. for (i = 0; i < 0x10; i++)
  845. if ((i & mask) == nibble)
  846. p += sprintf(p, "%X", i);
  847. *p++ = ']';
  848. }
  849. /* Ensure that the string remains NUL-terminated: */
  850. *p = '\0';
  851. /* Advance the caller's end-of-string pointer: */
  852. *outp = p;
  853. }
  854. /*
  855. * looks like: "amba:dN"
  856. *
  857. * N is exactly 8 digits, where each is an upper-case hex digit, or
  858. * a ? or [] pattern matching exactly one digit.
  859. */
  860. static int do_amba_entry(const char *filename,
  861. void *symval, char *alias)
  862. {
  863. unsigned int digit;
  864. char *p = alias;
  865. DEF_FIELD(symval, amba_id, id);
  866. DEF_FIELD(symval, amba_id, mask);
  867. if ((id & mask) != id)
  868. fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: "
  869. "id=0x%08X, mask=0x%08X. Please fix this driver.\n",
  870. filename, id, mask);
  871. p += sprintf(alias, "amba:d");
  872. for (digit = 0; digit < 8; digit++)
  873. append_nibble_mask(&p,
  874. (id >> (4 * (7 - digit))) & 0xf,
  875. (mask >> (4 * (7 - digit))) & 0xf);
  876. return 1;
  877. }
  878. /* LOOKS like x86cpu:vendor:VVVV:family:FFFF:model:MMMM:feature:*,FEAT,*
  879. * All fields are numbers. It would be nicer to use strings for vendor
  880. * and feature, but getting those out of the build system here is too
  881. * complicated.
  882. */
  883. static int do_x86cpu_entry(const char *filename, void *symval,
  884. char *alias)
  885. {
  886. DEF_FIELD(symval, x86_cpu_id, feature);
  887. DEF_FIELD(symval, x86_cpu_id, family);
  888. DEF_FIELD(symval, x86_cpu_id, model);
  889. DEF_FIELD(symval, x86_cpu_id, vendor);
  890. strcpy(alias, "x86cpu:");
  891. ADD(alias, "vendor:", vendor != X86_VENDOR_ANY, vendor);
  892. ADD(alias, ":family:", family != X86_FAMILY_ANY, family);
  893. ADD(alias, ":model:", model != X86_MODEL_ANY, model);
  894. strcat(alias, ":feature:*");
  895. if (feature != X86_FEATURE_ANY)
  896. sprintf(alias + strlen(alias), "%04X*", feature);
  897. return 1;
  898. }
  899. /* Does namelen bytes of name exactly match the symbol? */
  900. static bool sym_is(const char *name, unsigned namelen, const char *symbol)
  901. {
  902. if (namelen != strlen(symbol))
  903. return false;
  904. return memcmp(name, symbol, namelen) == 0;
  905. }
  906. static void do_table(void *symval, unsigned long size,
  907. unsigned long id_size,
  908. const char *device_id,
  909. int (*do_entry)(const char *filename, void *symval, char *alias),
  910. struct module *mod)
  911. {
  912. unsigned int i;
  913. char alias[500];
  914. device_id_check(mod->name, device_id, size, id_size, symval);
  915. /* Leave last one: it's the terminator. */
  916. size -= id_size;
  917. for (i = 0; i < size; i += id_size) {
  918. if (do_entry(mod->name, symval+i, alias)) {
  919. buf_printf(&mod->dev_table_buf,
  920. "MODULE_ALIAS(\"%s\");\n", alias);
  921. }
  922. }
  923. }
  924. static const struct devtable devtable[] = {
  925. {"hid", SIZE_hid_device_id, do_hid_entry},
  926. {"ieee1394", SIZE_ieee1394_device_id, do_ieee1394_entry},
  927. {"pci", SIZE_pci_device_id, do_pci_entry},
  928. {"ccw", SIZE_ccw_device_id, do_ccw_entry},
  929. {"ap", SIZE_ap_device_id, do_ap_entry},
  930. {"css", SIZE_css_device_id, do_css_entry},
  931. {"serio", SIZE_serio_device_id, do_serio_entry},
  932. {"acpi", SIZE_acpi_device_id, do_acpi_entry},
  933. {"pcmcia", SIZE_pcmcia_device_id, do_pcmcia_entry},
  934. {"vio", SIZE_vio_device_id, do_vio_entry},
  935. {"input", SIZE_input_device_id, do_input_entry},
  936. {"eisa", SIZE_eisa_device_id, do_eisa_entry},
  937. {"parisc", SIZE_parisc_device_id, do_parisc_entry},
  938. {"sdio", SIZE_sdio_device_id, do_sdio_entry},
  939. {"ssb", SIZE_ssb_device_id, do_ssb_entry},
  940. {"bcma", SIZE_bcma_device_id, do_bcma_entry},
  941. {"virtio", SIZE_virtio_device_id, do_virtio_entry},
  942. {"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry},
  943. {"i2c", SIZE_i2c_device_id, do_i2c_entry},
  944. {"spi", SIZE_spi_device_id, do_spi_entry},
  945. {"dmi", SIZE_dmi_system_id, do_dmi_entry},
  946. {"platform", SIZE_platform_device_id, do_platform_entry},
  947. {"mdio", SIZE_mdio_device_id, do_mdio_entry},
  948. {"zorro", SIZE_zorro_device_id, do_zorro_entry},
  949. {"isapnp", SIZE_isapnp_device_id, do_isapnp_entry},
  950. {"amba", SIZE_amba_id, do_amba_entry},
  951. {"x86cpu", SIZE_x86_cpu_id, do_x86cpu_entry},
  952. {"of", SIZE_of_device_id, do_of_entry},
  953. };
  954. /* Create MODULE_ALIAS() statements.
  955. * At this time, we cannot write the actual output C source yet,
  956. * so we write into the mod->dev_table_buf buffer. */
  957. void handle_moddevtable(struct module *mod, struct elf_info *info,
  958. Elf_Sym *sym, const char *symname)
  959. {
  960. void *symval;
  961. char *zeros = NULL;
  962. const char *name;
  963. unsigned int namelen;
  964. /* We're looking for a section relative symbol */
  965. if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections)
  966. return;
  967. /* We're looking for an object */
  968. if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
  969. return;
  970. /* All our symbols are of form <prefix>__mod_XXX_device_table. */
  971. name = strstr(symname, "__mod_");
  972. if (!name)
  973. return;
  974. name += strlen("__mod_");
  975. namelen = strlen(name);
  976. if (namelen < strlen("_device_table"))
  977. return;
  978. if (strcmp(name + namelen - strlen("_device_table"), "_device_table"))
  979. return;
  980. namelen -= strlen("_device_table");
  981. /* Handle all-NULL symbols allocated into .bss */
  982. if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) {
  983. zeros = calloc(1, sym->st_size);
  984. symval = zeros;
  985. } else {
  986. symval = (void *)info->hdr
  987. + info->sechdrs[get_secindex(info, sym)].sh_offset
  988. + sym->st_value;
  989. }
  990. /* First handle the "special" cases */
  991. if (sym_is(name, namelen, "usb"))
  992. do_usb_table(symval, sym->st_size, mod);
  993. else if (sym_is(name, namelen, "pnp"))
  994. do_pnp_device_entry(symval, sym->st_size, mod);
  995. else if (sym_is(name, namelen, "pnp_card"))
  996. do_pnp_card_entries(symval, sym->st_size, mod);
  997. else {
  998. int i;
  999. for (i = 0; i < ARRAY_SIZE(devtable); i++) {
  1000. const struct devtable *p = &devtable[i];
  1001. if (sym_is(name, namelen, p->device_id)) {
  1002. do_table(symval, sym->st_size, p->id_size,
  1003. p->device_id, p->do_entry, mod);
  1004. break;
  1005. }
  1006. }
  1007. }
  1008. free(zeros);
  1009. }
  1010. /* Now add out buffered information to the generated C source */
  1011. void add_moddevtable(struct buffer *buf, struct module *mod)
  1012. {
  1013. buf_printf(buf, "\n");
  1014. buf_write(buf, mod->dev_table_buf.p, mod->dev_table_buf.pos);
  1015. free(mod->dev_table_buf.p);
  1016. }