Advertisement
Guest User

file2alias.diff

a guest
Jun 19th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 14.23 KB | None | 0 0
  1. 30a31
  2. > #include <stdbool.h>
  3. 40a42,96
  4. > /* This array collects all instances that use the generic do_table */
  5. > struct devtable {
  6. >   const char *device_id; /* name of table, __mod_<name>_device_table. */
  7. >   unsigned long id_size;
  8. >   void *function;
  9. > };
  10. >
  11. > #define ___cat(a,b) a ## b
  12. > #define __cat(a,b) ___cat(a,b)
  13. >
  14. > /* we need some special handling for this host tool running eventually on
  15. >  * Darwin. The Mach-O section handling is a bit different than ELF section
  16. >  * handling. The differnces in detail are:
  17. >  *  a) we have segments which have sections
  18. >  *  b) we need a API call to get the respective section symbols */
  19. > #if defined(__MACH__)
  20. > #include <mach-o/getsect.h>
  21. >
  22. > #define INIT_SECTION(name)  do {                  \
  23. >       unsigned long name ## _len;             \
  24. >       char *__cat(pstart_,name) = getsectdata("__TEXT",   \
  25. >           #name, &__cat(name,_len));          \
  26. >       char *__cat(pstop_,name) = __cat(pstart_,name) +    \
  27. >           __cat(name, _len);              \
  28. >       __cat(__start_,name) = (void *)__cat(pstart_,name); \
  29. >       __cat(__stop_,name) = (void *)__cat(pstop_,name);   \
  30. >   } while (0)
  31. > #define SECTION(name)   __attribute__((section("__TEXT, " #name)))
  32. >
  33. > struct devtable **__start___devtable, **__stop___devtable;
  34. > #else
  35. > #define INIT_SECTION(name) /* no-op for ELF */
  36. > #define SECTION(name)   __attribute__((section(#name)))
  37. >
  38. > /* We construct a table of pointers in an ELF section (pointers generally
  39. >  * go unpadded by gcc).  ld creates boundary syms for us. */
  40. > extern struct devtable *__start___devtable[], *__stop___devtable[];
  41. > #endif /* __MACH__ */
  42. >
  43. > #if __GNUC__ == 3 && __GNUC_MINOR__ < 3
  44. > # define __used           __attribute__((__unused__))
  45. > #else
  46. > # define __used           __attribute__((__used__))
  47. > #endif
  48. >
  49. > /* Add a table entry.  We test function type matches while we're here. */
  50. > #define ADD_TO_DEVTABLE(device_id, type, function) \
  51. >   static struct devtable __cat(devtable,__LINE__) = { \
  52. >       device_id + 0*sizeof((function)((const char *)NULL, \
  53. >                       (type *)NULL,       \
  54. >                       (char *)NULL)),     \
  55. >       sizeof(type), (function) };             \
  56. >   static struct devtable *SECTION(__devtable) __used \
  57. >       __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
  58. >
  59. 291a348
  60. > ADD_TO_DEVTABLE("hid", struct hid_device_id, do_hid_entry);
  61. 315a373
  62. > ADD_TO_DEVTABLE("ieee1394", struct ieee1394_device_id, do_ieee1394_entry);
  63. 358a417
  64. > ADD_TO_DEVTABLE("pci", struct pci_device_id, do_pci_entry);
  65. 381a441
  66. > ADD_TO_DEVTABLE("ccw", struct ccw_device_id, do_ccw_entry);
  67. 389a450
  68. > ADD_TO_DEVTABLE("ap", struct ap_device_id, do_ap_entry);
  69. 397a459
  70. > ADD_TO_DEVTABLE("css", struct css_device_id, do_css_entry);
  71. 416a479
  72. > ADD_TO_DEVTABLE("serio", struct serio_device_id, do_serio_entry);
  73. 424a488
  74. > ADD_TO_DEVTABLE("acpi", struct acpi_device_id, do_acpi_entry);
  75. 547,548c611
  76. <
  77. <
  78. ---
  79. > ADD_TO_DEVTABLE("pcmcia", struct pcmcia_device_id, do_pcmcia_entry);
  80. 570a634
  81. > ADD_TO_DEVTABLE("of", struct of_device_id, do_of_entry);
  82. 587a652
  83. > ADD_TO_DEVTABLE("vio", struct vio_device_id, do_vio_entry);
  84. 642a708
  85. > ADD_TO_DEVTABLE("input", struct input_device_id, do_input_entry);
  86. 652a719
  87. > ADD_TO_DEVTABLE("eisa", struct eisa_device_id, do_eisa_entry);
  88. 671a739
  89. > ADD_TO_DEVTABLE("parisc", struct parisc_device_id, do_parisc_entry);
  90. 687a756
  91. > ADD_TO_DEVTABLE("sdio", struct sdio_device_id, do_sdio_entry);
  92. 703a773,792
  93. > ADD_TO_DEVTABLE("ssb", struct ssb_device_id, do_ssb_entry);
  94. >
  95. > /* Looks like: bcma:mNidNrevNclN. */
  96. > static int do_bcma_entry(const char *filename,
  97. >            struct bcma_device_id *id, char *alias)
  98. > {
  99. >   id->manuf = TO_NATIVE(id->manuf);
  100. >   id->id = TO_NATIVE(id->id);
  101. >   id->rev = TO_NATIVE(id->rev);
  102. >   id->class = TO_NATIVE(id->class);
  103. >
  104. >   strcpy(alias, "bcma:");
  105. >   ADD(alias, "m", id->manuf != BCMA_ANY_MANUF, id->manuf);
  106. >   ADD(alias, "id", id->id != BCMA_ANY_ID, id->id);
  107. >   ADD(alias, "rev", id->rev != BCMA_ANY_REV, id->rev);
  108. >   ADD(alias, "cl", id->class != BCMA_ANY_CLASS, id->class);
  109. >   add_wildcard(alias);
  110. >   return 1;
  111. > }
  112. > ADD_TO_DEVTABLE("bcma", struct bcma_device_id, do_bcma_entry);
  113. 718a808,830
  114. > ADD_TO_DEVTABLE("virtio", struct virtio_device_id, do_virtio_entry);
  115. >
  116. > /*
  117. >  * Looks like: vmbus:guid
  118. >  * Each byte of the guid will be represented by two hex characters
  119. >  * in the name.
  120. >  */
  121. >
  122. > static int do_vmbus_entry(const char *filename, struct hv_vmbus_device_id *id,
  123. >             char *alias)
  124. > {
  125. >   int i;
  126. >   char guid_name[((sizeof(id->guid) + 1)) * 2];
  127. >
  128. >   for (i = 0; i < (sizeof(id->guid) * 2); i += 2)
  129. >       sprintf(&guid_name[i], "%02x", id->guid[i/2]);
  130. >
  131. >   strcpy(alias, "vmbus:");
  132. >   strcat(alias, guid_name);
  133. >
  134. >   return 1;
  135. > }
  136. > ADD_TO_DEVTABLE("vmbus", struct hv_vmbus_device_id, do_vmbus_entry);
  137. 727a840
  138. > ADD_TO_DEVTABLE("i2c", struct i2c_device_id, do_i2c_entry);
  139. 736a850
  140. > ADD_TO_DEVTABLE("spi", struct spi_device_id, do_spi_entry);
  141. 790a905
  142. > ADD_TO_DEVTABLE("dmi", struct dmi_system_id, do_dmi_entry);
  143. 797a913
  144. > ADD_TO_DEVTABLE("platform", struct platform_device_id, do_platform_entry);
  145. 819a936
  146. > ADD_TO_DEVTABLE("mdio", struct mdio_device_id, do_mdio_entry);
  147. 829a947
  148. > ADD_TO_DEVTABLE("zorro", struct zorro_device_id, do_zorro_entry);
  149. 842a961
  150. > ADD_TO_DEVTABLE("isapnp", struct isapnp_device_id, do_isapnp_entry);
  151. 844,845c963,970
  152. < /* Ignore any prefix, eg. some architectures prepend _ */
  153. < static inline int sym_is(const char *symbol, const char *name)
  154. ---
  155. > /*
  156. >  * Append a match expression for a single masked hex digit.
  157. >  * outp points to a pointer to the character at which to append.
  158. >  *    *outp is updated on return to point just after the appended text,
  159. >  *    to facilitate further appending.
  160. >  */
  161. > static void append_nibble_mask(char **outp,
  162. >                  unsigned int nibble, unsigned int mask)
  163. 847c972,973
  164. <   const char *match;
  165. ---
  166. >   char *p = *outp;
  167. >   unsigned int i;
  168. 849,852c975,1063
  169. <   match = strstr(symbol, name);
  170. <   if (!match)
  171. <       return 0;
  172. <   return match[strlen(name)] == '\0';
  173. ---
  174. >   switch (mask) {
  175. >   case 0:
  176. >       *p++ = '?';
  177. >       break;
  178. >
  179. >   case 0xf:
  180. >       p += sprintf(p, "%X",  nibble);
  181. >       break;
  182. >
  183. >   default:
  184. >       /*
  185. >        * Dumbly emit a match pattern for all possible matching
  186. >        * digits.  This could be improved in some cases using ranges,
  187. >        * but it has the advantage of being trivially correct, and is
  188. >        * often optimal.
  189. >        */
  190. >       *p++ = '[';
  191. >       for (i = 0; i < 0x10; i++)
  192. >           if ((i & mask) == nibble)
  193. >               p += sprintf(p, "%X", i);
  194. >       *p++ = ']';
  195. >   }
  196. >
  197. >   /* Ensure that the string remains NUL-terminated: */
  198. >   *p = '\0';
  199. >
  200. >   /* Advance the caller's end-of-string pointer: */
  201. >   *outp = p;
  202. > }
  203. >
  204. > /*
  205. >  * looks like: "amba:dN"
  206. >  *
  207. >  * N is exactly 8 digits, where each is an upper-case hex digit, or
  208. >  *    a ? or [] pattern matching exactly one digit.
  209. >  */
  210. > static int do_amba_entry(const char *filename,
  211. >            struct amba_id *id, char *alias)
  212. > {
  213. >   unsigned int digit;
  214. >   char *p = alias;
  215. >
  216. >   if ((id->id & id->mask) != id->id)
  217. >       fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: "
  218. >             "id=0x%08X, mask=0x%08X.  Please fix this driver.\n",
  219. >             filename, id->id, id->mask);
  220. >
  221. >   p += sprintf(alias, "amba:d");
  222. >   for (digit = 0; digit < 8; digit++)
  223. >       append_nibble_mask(&p,
  224. >                  (id->id >> (4 * (7 - digit))) & 0xf,
  225. >                  (id->mask >> (4 * (7 - digit))) & 0xf);
  226. >
  227. >   return 1;
  228. > }
  229. > ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry);
  230. >
  231. > /* LOOKS like x86cpu:vendor:VVVV:family:FFFF:model:MMMM:feature:*,FEAT,*
  232. >  * All fields are numbers. It would be nicer to use strings for vendor
  233. >  * and feature, but getting those out of the build system here is too
  234. >  * complicated.
  235. >  */
  236. >
  237. > static int do_x86cpu_entry(const char *filename, struct x86_cpu_id *id,
  238. >              char *alias)
  239. > {
  240. >   id->feature = TO_NATIVE(id->feature);
  241. >   id->family = TO_NATIVE(id->family);
  242. >   id->model = TO_NATIVE(id->model);
  243. >   id->vendor = TO_NATIVE(id->vendor);
  244. >
  245. >   strcpy(alias, "x86cpu:");
  246. >   ADD(alias, "vendor:",  id->vendor != X86_VENDOR_ANY, id->vendor);
  247. >   ADD(alias, ":family:", id->family != X86_FAMILY_ANY, id->family);
  248. >   ADD(alias, ":model:",  id->model  != X86_MODEL_ANY,  id->model);
  249. >   strcat(alias, ":feature:*");
  250. >   if (id->feature != X86_FEATURE_ANY)
  251. >       sprintf(alias + strlen(alias), "%04X*", id->feature);
  252. >   return 1;
  253. > }
  254. > ADD_TO_DEVTABLE("x86cpu", struct x86_cpu_id, do_x86cpu_entry);
  255. >
  256. > /* Does namelen bytes of name exactly match the symbol? */
  257. > static bool sym_is(const char *name, unsigned namelen, const char *symbol)
  258. > {
  259. >   if (namelen != strlen(symbol))
  260. >       return false;
  261. >
  262. >   return memcmp(name, symbol, namelen) == 0;
  263. 884a1096,1097
  264. >   const char *name;
  265. >   unsigned int namelen;
  266. 887c1100,1113
  267. <   if (!sym->st_shndx || sym->st_shndx >= info->hdr->e_shnum)
  268. ---
  269. >   if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections)
  270. >       return;
  271. >
  272. >   /* We're looking for an object */
  273. >   if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT)
  274. >       return;
  275. >
  276. >   /* All our symbols are of form <prefix>__mod_XXX_device_table. */
  277. >   name = strstr(symname, "__mod_");
  278. >   if (!name)
  279. >       return;
  280. >   name += strlen("__mod_");
  281. >   namelen = strlen(name);
  282. >   if (namelen < strlen("_device_table"))
  283. 888a1115,1117
  284. >   if (strcmp(name + namelen - strlen("_device_table"), "_device_table"))
  285. >       return;
  286. >   namelen -= strlen("_device_table");
  287. 891c1120
  288. <   if (info->sechdrs[sym->st_shndx].sh_type & SHT_NOBITS) {
  289. ---
  290. >   if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) {
  291. 896c1125
  292. <           + info->sechdrs[sym->st_shndx].sh_offset
  293. ---
  294. >           + info->sechdrs[get_secindex(info, sym)].sh_offset
  295. 900,905c1129,1130
  296. <   if (sym_is(symname, "__mod_pci_device_table"))
  297. <       do_table(symval, sym->st_size,
  298. <            sizeof(struct pci_device_id), "pci",
  299. <            do_pci_entry, mod);
  300. <   else if (sym_is(symname, "__mod_usb_device_table"))
  301. <       /* special case to handle bcdDevice ranges */
  302. ---
  303. >   /* First handle the "special" cases */
  304. >   if (sym_is(name, namelen, "usb"))
  305. 907,935c1132
  306. <   else if (sym_is(symname, "__mod_hid_device_table"))
  307. <       do_table(symval, sym->st_size,
  308. <            sizeof(struct hid_device_id), "hid",
  309. <            do_hid_entry, mod);
  310. <   else if (sym_is(symname, "__mod_ieee1394_device_table"))
  311. <       do_table(symval, sym->st_size,
  312. <            sizeof(struct ieee1394_device_id), "ieee1394",
  313. <            do_ieee1394_entry, mod);
  314. <   else if (sym_is(symname, "__mod_ccw_device_table"))
  315. <       do_table(symval, sym->st_size,
  316. <            sizeof(struct ccw_device_id), "ccw",
  317. <            do_ccw_entry, mod);
  318. <   else if (sym_is(symname, "__mod_ap_device_table"))
  319. <       do_table(symval, sym->st_size,
  320. <            sizeof(struct ap_device_id), "ap",
  321. <            do_ap_entry, mod);
  322. <   else if (sym_is(symname, "__mod_css_device_table"))
  323. <       do_table(symval, sym->st_size,
  324. <            sizeof(struct css_device_id), "css",
  325. <            do_css_entry, mod);
  326. <   else if (sym_is(symname, "__mod_serio_device_table"))
  327. <       do_table(symval, sym->st_size,
  328. <            sizeof(struct serio_device_id), "serio",
  329. <            do_serio_entry, mod);
  330. <   else if (sym_is(symname, "__mod_acpi_device_table"))
  331. <       do_table(symval, sym->st_size,
  332. <            sizeof(struct acpi_device_id), "acpi",
  333. <            do_acpi_entry, mod);
  334. <   else if (sym_is(symname, "__mod_pnp_device_table"))
  335. ---
  336. >   else if (sym_is(name, namelen, "pnp"))
  337. 937c1134
  338. <   else if (sym_is(symname, "__mod_pnp_card_device_table"))
  339. ---
  340. >   else if (sym_is(name, namelen, "pnp_card"))
  341. 939,1002c1136,1147
  342. <   else if (sym_is(symname, "__mod_pcmcia_device_table"))
  343. <       do_table(symval, sym->st_size,
  344. <            sizeof(struct pcmcia_device_id), "pcmcia",
  345. <            do_pcmcia_entry, mod);
  346. <         else if (sym_is(symname, "__mod_of_device_table"))
  347. <       do_table(symval, sym->st_size,
  348. <            sizeof(struct of_device_id), "of",
  349. <            do_of_entry, mod);
  350. <         else if (sym_is(symname, "__mod_vio_device_table"))
  351. <       do_table(symval, sym->st_size,
  352. <            sizeof(struct vio_device_id), "vio",
  353. <            do_vio_entry, mod);
  354. <   else if (sym_is(symname, "__mod_input_device_table"))
  355. <       do_table(symval, sym->st_size,
  356. <            sizeof(struct input_device_id), "input",
  357. <            do_input_entry, mod);
  358. <   else if (sym_is(symname, "__mod_eisa_device_table"))
  359. <       do_table(symval, sym->st_size,
  360. <            sizeof(struct eisa_device_id), "eisa",
  361. <            do_eisa_entry, mod);
  362. <   else if (sym_is(symname, "__mod_parisc_device_table"))
  363. <       do_table(symval, sym->st_size,
  364. <            sizeof(struct parisc_device_id), "parisc",
  365. <            do_parisc_entry, mod);
  366. <   else if (sym_is(symname, "__mod_sdio_device_table"))
  367. <       do_table(symval, sym->st_size,
  368. <            sizeof(struct sdio_device_id), "sdio",
  369. <            do_sdio_entry, mod);
  370. <   else if (sym_is(symname, "__mod_ssb_device_table"))
  371. <       do_table(symval, sym->st_size,
  372. <            sizeof(struct ssb_device_id), "ssb",
  373. <            do_ssb_entry, mod);
  374. <   else if (sym_is(symname, "__mod_virtio_device_table"))
  375. <       do_table(symval, sym->st_size,
  376. <            sizeof(struct virtio_device_id), "virtio",
  377. <            do_virtio_entry, mod);
  378. <   else if (sym_is(symname, "__mod_i2c_device_table"))
  379. <       do_table(symval, sym->st_size,
  380. <            sizeof(struct i2c_device_id), "i2c",
  381. <            do_i2c_entry, mod);
  382. <   else if (sym_is(symname, "__mod_spi_device_table"))
  383. <       do_table(symval, sym->st_size,
  384. <            sizeof(struct spi_device_id), "spi",
  385. <            do_spi_entry, mod);
  386. <   else if (sym_is(symname, "__mod_dmi_device_table"))
  387. <       do_table(symval, sym->st_size,
  388. <            sizeof(struct dmi_system_id), "dmi",
  389. <            do_dmi_entry, mod);
  390. <   else if (sym_is(symname, "__mod_platform_device_table"))
  391. <       do_table(symval, sym->st_size,
  392. <            sizeof(struct platform_device_id), "platform",
  393. <            do_platform_entry, mod);
  394. <   else if (sym_is(symname, "__mod_mdio_device_table"))
  395. <       do_table(symval, sym->st_size,
  396. <            sizeof(struct mdio_device_id), "mdio",
  397. <            do_mdio_entry, mod);
  398. <   else if (sym_is(symname, "__mod_zorro_device_table"))
  399. <       do_table(symval, sym->st_size,
  400. <            sizeof(struct zorro_device_id), "zorro",
  401. <            do_zorro_entry, mod);
  402. <   else if (sym_is(symname, "__mod_isapnp_device_table"))
  403. <       do_table(symval, sym->st_size,
  404. <           sizeof(struct isapnp_device_id), "isa",
  405. <           do_isapnp_entry, mod);
  406. ---
  407. >   else {
  408. >       struct devtable **p;
  409. >       INIT_SECTION(__devtable);
  410. >
  411. >       for (p = __start___devtable; p < __stop___devtable; p++) {
  412. >           if (sym_is(name, namelen, (*p)->device_id)) {
  413. >               do_table(symval, sym->st_size, (*p)->id_size,
  414. >                    (*p)->device_id, (*p)->function, mod);
  415. >               break;
  416. >           }
  417. >       }
  418. >   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement