file2alias.c 33 KB

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