17 #if KERNEL_ELFCLASS == ELFCLASS32
19 #define BITS_PER_LONG 32
22 #define BITS_PER_LONG 64
35 typedef unsigned char __u8;
40 #include "../../include/linux/mod_devicetable.h"
49 #define ___cat(a,b) a ## b
50 #define __cat(a,b) ___cat(a,b)
58 #include <mach-o/getsect.h>
60 #define INIT_SECTION(name) do { \
61 unsigned long name ## _len; \
62 char *__cat(pstart_,name) = getsectdata("__TEXT", \
63 #name, &__cat(name,_len)); \
64 char *__cat(pstop_,name) = __cat(pstart_,name) + \
66 __cat(__start_,name) = (void *)__cat(pstart_,name); \
67 __cat(__stop_,name) = (void *)__cat(pstop_,name); \
69 #define SECTION(name) __attribute__((section("__TEXT, " #name)))
73 #define INIT_SECTION(name)
74 #define SECTION(name) __attribute__((section(#name)))
78 extern struct devtable *__start___devtable[], *__stop___devtable[];
81 #if __GNUC__ == 3 && __GNUC_MINOR__ < 3
82 # define __used __attribute__((__unused__))
84 # define __used __attribute__((__used__))
88 #define ADD_TO_DEVTABLE(device_id, type, function) \
89 static struct devtable __cat(devtable,__LINE__) = { \
90 device_id + 0*sizeof((function)((const char *)NULL, \
93 sizeof(type), (function) }; \
94 static struct devtable *SECTION(__devtable) __used \
95 __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
97 #define ADD(str, sep, cond, field) \
101 sprintf(str + strlen(str), \
102 sizeof(field) == 1 ? "%02X" : \
103 sizeof(field) == 2 ? "%04X" : \
104 sizeof(field) == 4 ? "%08X" : "", \
107 sprintf(str + strlen(str), "*"); \
111 static inline void add_wildcard(
char *
str)
115 if (str[len - 1] !=
'*')
133 if (size % id_size || size < id_size) {
136 fatal(
"%s: sizeof(struct %s_device_id)=%lu is not a modulo "
137 "of the size of section __mod_%s_device_table=%lu.\n"
138 "Fix definition of struct %s_device_id "
139 "in mod_devicetable.h\n",
140 modname, device_id, id_size, device_id, size, device_id);
143 for (i = 0; i <
id_size; i++ ) {
144 if (*(
uint8_t*)(symval+size-id_size+i)) {
145 fprintf(stderr,
"%s: struct %s_device_id is %lu bytes. "
146 "The last of %lu is:\n",
147 modname, device_id, id_size, size / id_size);
150 *(
uint8_t*)(symval+size-id_size+i) );
152 fatal(
"%s: struct %s_device_id is not terminated "
153 "with a NULL entry!\n", modname, device_id);
161 unsigned int bcdDevice_initial,
int bcdDevice_initial_digits,
162 unsigned char range_lo,
unsigned char range_hi,
173 if (bcdDevice_initial_digits)
175 bcdDevice_initial_digits, bcdDevice_initial);
176 if (range_lo == range_hi)
178 else if (range_lo > 0 || range_hi < max) {
179 if (range_lo > 0x9 || range_hi < 0xA)
186 range_lo < 0x9 ?
"[%X-9" :
"[%X",
189 range_hi > 0xA ?
"a-%X]" :
"%X]",
193 if (bcdDevice_initial_digits < (
sizeof(id->
bcdDevice_lo) * 2 - 1))
219 "MODULE_ALIAS(\"%s\");\n", alias);
224 static unsigned int incbcd(
unsigned int *bcd,
229 unsigned int init = *bcd,
i,
j;
230 unsigned long long c, dec = 0;
239 for (i=0 ; i < chars ; i++) {
240 c = (*bcd >> (i << 2)) & 0xf;
242 for (j=0 ; j <
i ; j++)
252 for (i=0 ; i < chars ; i++) {
253 for (c=1,j=0 ; j <
i ; j++)
256 *bcd += c << (i << 2);
263 unsigned int devlo, devhi;
264 unsigned char chi, clo,
max;
278 for (ndigits = 0 ; ndigits <
sizeof(
id->bcdDevice_lo) * 2 ; ndigits++) {
279 clo = (devlo >> (ndigits << 2)) & 0xf;
280 chi = ((devhi > 0x9999 ? 0x9999 : devhi) >> (ndigits << 2)) & 0xf;
281 if (clo > max || chi > max) {
295 for (ndigits =
sizeof(id->
bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) {
303 if (devlo == devhi || !ndigits) {
304 do_usb_entry(
id, devlo, ndigits, clo, chi, max, mod);
310 incbcd(&devlo, 1, max,
312 ndigits, clo, max, max, mod);
316 incbcd(&devhi, -1, max,
318 ndigits, 0x0, chi, max, mod);
322 static void do_usb_table(
void *symval,
unsigned long size,
328 device_id_check(mod->
name,
"usb", size, id_size, symval);
333 for (i = 0; i <
size; i += id_size)
334 do_usb_entry_multi(symval + i, mod);
338 static int do_hid_entry(
const char *
filename,
357 static int do_ieee1394_entry(
const char *
filename,
366 strcpy(alias,
"ieee1394:");
382 static int do_pci_entry(
const char *
filename,
387 baseclass_mask, subclass_mask, interface_mask;
402 baseclass = (
id->class) >> 16;
403 baseclass_mask = (
id->class_mask) >> 16;
404 subclass = (
id->class) >> 8;
405 subclass_mask = (
id->class_mask) >> 8;
406 interface = id->
class;
407 interface_mask =
id->class_mask;
409 if ((baseclass_mask != 0 && baseclass_mask != 0xFF)
410 || (subclass_mask != 0 && subclass_mask != 0xFF)
411 || (interface_mask != 0 && interface_mask != 0xFF)) {
412 warn(
"Can't handle masks in %s:%04X\n",
417 ADD(alias,
"bc", baseclass_mask == 0xFF, baseclass);
418 ADD(alias,
"sc", subclass_mask == 0xFF, subclass);
419 ADD(alias,
"i", interface_mask == 0xFF, interface);
426 static int do_ccw_entry(
const char *filename,
450 static int do_ap_entry(
const char *filename,
459 static int do_css_entry(
const char *filename,
468 static int do_serio_entry(
const char *filename,
488 static int do_acpi_entry(
const char *filename,
497 static void do_pnp_device_entry(
void *symval,
unsigned long size,
501 const unsigned int count = (size / id_size)-1;
505 device_id_check(mod->
name,
"pnp", size, id_size, symval);
507 for (i = 0; i <
count; i++) {
508 const char *
id = (
char *)devs[i].
id;
509 char acpi_id[
sizeof(devs[0].
id)];
513 "MODULE_ALIAS(\"pnp:d%s*\");\n",
id);
516 for (j = 0; j <
sizeof(acpi_id); j++)
519 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
524 static void do_pnp_card_entries(
void *symval,
unsigned long size,
528 const unsigned int count = (size / id_size)-1;
532 device_id_check(mod->
name,
"pnp", size, id_size, symval);
534 for (i = 0; i <
count; i++) {
539 const char *
id = (
char *)card->
devs[j].id;
547 for (i2 = 0; i2 < i && !dup; i2++) {
551 const char *
id2 = (
char *)card2->
devs[j2].id;
565 char acpi_id[
sizeof(card->
devs[0].id)];
569 "MODULE_ALIAS(\"pnp:d%s*\");\n",
id);
572 for (k = 0; k <
sizeof(acpi_id); k++)
575 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
582 static int do_pcmcia_entry(
const char *filename,
594 for (i=0; i<4; i++) {
595 id->prod_id_hash[
i] =
TO_NATIVE(id->prod_id_hash[i]);
619 static int do_of_entry (
const char *filename,
struct of_device_id *of,
char *alias)
623 len =
sprintf (alias,
"of:N%sT%s",
629 of->
type[0] ?
"*" :
"",
633 for (tmp = alias; tmp && *
tmp; tmp++)
642 static int do_vio_entry(
const char *filename,
struct vio_device_id *vio,
651 for (tmp = alias; tmp && *
tmp; tmp++)
660 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
662 static void do_input(
char *alias,
667 for (i = min; i <
max; i++)
673 static int do_input_entry(
const char *filename,
struct input_device_id *
id,
688 do_input(alias, id->
keybit,
716 static int do_eisa_entry(
const char *filename,
struct eisa_device_id *eisa,
728 static int do_parisc_entry(
const char *filename,
struct parisc_device_id *
id,
748 static int do_sdio_entry(
const char *filename,
765 static int do_ssb_entry(
const char *filename,
782 static int do_bcma_entry(
const char *filename,
801 static int do_virtio_entry(
const char *filename,
struct virtio_device_id *
id,
826 char guid_name[((
sizeof(
id->guid) + 1)) * 2];
828 for (i = 0; i < (
sizeof(
id->guid) * 2); i += 2)
829 sprintf(&guid_name[i],
"%02x", id->guid[i/2]);
839 static int do_i2c_entry(
const char *filename,
struct i2c_device_id *
id,
849 static int do_spi_entry(
const char *filename,
struct spi_device_id *
id,
858 static const struct dmifield {
877 static void dmi_ascii_filter(
char *
d,
const char *
s)
881 if (*s >
' ' && *s < 127 && *s !=
':')
888 static int do_dmi_entry(
const char *filename,
struct dmi_system_id *
id,
895 for (i = 0; i <
ARRAY_SIZE(dmi_fields); i++) {
896 for (j = 0; j < 4; j++) {
898 id->
matches[j].slot == dmi_fields[i].field) {
901 dmi_ascii_filter(alias +
strlen(alias),
913 static int do_platform_entry(
const char *filename,
921 static int do_mdio_entry(
const char *filename,
928 for (i = 0; i < 32; i++) {
931 else if ((id->
phy_id >> (31-i)) & 1)
945 static int do_zorro_entry(
const char *filename,
struct zorro_device_id *
id,
956 static int do_isapnp_entry(
const char *filename,
959 sprintf(alias,
"pnp:d%c%c%c%x%x%x%x*",
960 'A' + ((id->
vendor >> 2) & 0x3f) - 1,
961 'A' + (((id->
vendor & 3) << 3) | ((id->
vendor >> 13) & 7)) - 1,
962 'A' + ((id->
vendor >> 8) & 0x1f) - 1,
970 static int do_ipack_entry(
const char *filename,
990 static void append_nibble_mask(
char **
outp,
991 unsigned int nibble,
unsigned int mask)
1002 p +=
sprintf(p,
"%X", nibble);
1013 for (i = 0; i < 0x10; i++)
1014 if ((i & mask) == nibble)
1032 static int do_amba_entry(
const char *filename,
1033 struct amba_id *
id,
char *alias)
1039 fatal(
"%s: Masked-off bit(s) of AMBA device ID are non-zero: "
1040 "id=0x%08X, mask=0x%08X. Please fix this driver.\n",
1041 filename, id->
id, id->
mask);
1043 p +=
sprintf(alias,
"amba:d");
1044 for (digit = 0; digit < 8; digit++)
1045 append_nibble_mask(&p,
1046 (id->
id >> (4 * (7 - digit))) & 0xf,
1047 (id->
mask >> (4 * (7 - digit))) & 0xf);
1059 static int do_x86cpu_entry(
const char *filename,
struct x86_cpu_id *
id,
1067 strcpy(alias,
"x86cpu:");
1071 strcat(alias,
":feature:*");
1081 if (namelen !=
strlen(symbol))
1084 return memcmp(name, symbol, namelen) == 0;
1087 static void do_table(
void *symval,
unsigned long size,
1088 unsigned long id_size,
1095 int (*do_entry)(
const char *,
void *
entry,
char *
alias) =
function;
1097 device_id_check(mod->
name, device_id, size, id_size, symval);
1101 for (i = 0; i <
size; i += id_size) {
1102 if (do_entry(mod->
name, symval+i, alias)) {
1104 "MODULE_ALIAS(\"%s\");\n", alias);
1113 Elf_Sym *sym,
const char *symname)
1121 if (!sym->st_shndx || get_secindex(info, sym) >= info->
num_sections)
1129 name =
strstr(symname,
"__mod_");
1132 name +=
strlen(
"__mod_");
1134 if (namelen <
strlen(
"_device_table"))
1136 if (
strcmp(name + namelen -
strlen(
"_device_table"),
"_device_table"))
1138 namelen -=
strlen(
"_device_table");
1142 zeros = calloc(1, sym->st_size);
1145 symval = (
void *)info->
hdr
1146 + info->
sechdrs[get_secindex(info, sym)].sh_offset
1151 if (sym_is(name, namelen,
"usb"))
1152 do_usb_table(symval, sym->st_size, mod);
1153 else if (sym_is(name, namelen,
"pnp"))
1154 do_pnp_device_entry(symval, sym->st_size, mod);
1155 else if (sym_is(name, namelen,
"pnp_card"))
1156 do_pnp_card_entries(symval, sym->st_size, mod);
1161 for (p = __start___devtable; p < __stop___devtable; p++) {
1162 if (sym_is(name, namelen, (*p)->device_id)) {
1163 do_table(symval, sym->st_size, (*p)->id_size,
1164 (*p)->device_id, (*p)->function, mod);
1175 buf_printf(buf,
"\n");