]> err.no Git - linux-2.6/blobdiff - scripts/mod/file2alias.c
Merge branch 'powerpc-next' of master.kernel.org:/pub/scm/linux/kernel/git/galak...
[linux-2.6] / scripts / mod / file2alias.c
index 494435ca88fa704ef130ae4d9fd8e8d18456886f..769b69db89c13b6f6af68abbfe3167929d81d5e8 100644 (file)
@@ -51,21 +51,43 @@ do {                                                            \
                 sprintf(str + strlen(str), "*");                \
 } while(0)
 
+unsigned int cross_build = 0;
 /**
  * Check that sizeof(device_id type) are consistent with size of section
  * in .o file. If in-consistent then userspace and kernel does not agree
  * on actual size which is a bug.
+ * Also verify that the final entry in the table is all zeros.
+ * Ignore both checks if build host differ from target host and size differs.
  **/
-static void device_id_size_check(const char *modname, const char *device_id,
-                                unsigned long size, unsigned long id_size)
+static void device_id_check(const char *modname, const char *device_id,
+                           unsigned long size, unsigned long id_size,
+                           void *symval)
 {
+       int i;
+
        if (size % id_size || size < id_size) {
+               if (cross_build != 0)
+                       return;
                fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
                      "of the size of section __mod_%s_device_table=%lu.\n"
                      "Fix definition of struct %s_device_id "
                      "in mod_devicetable.h\n",
                      modname, device_id, id_size, device_id, size, device_id);
        }
+       /* Verify last one is a terminator */
+       for (i = 0; i < id_size; i++ ) {
+               if (*(uint8_t*)(symval+size-id_size+i)) {
+                       fprintf(stderr,"%s: struct %s_device_id is %lu bytes.  "
+                               "The last of %lu is:\n",
+                               modname, device_id, id_size, size / id_size);
+                       for (i = 0; i < id_size; i++ )
+                               fprintf(stderr,"0x%02x ",
+                                       *(uint8_t*)(symval+size-id_size+i) );
+                       fprintf(stderr,"\n");
+                       fatal("%s: struct %s_device_id is not terminated "
+                               "with a NULL entry!\n", modname, device_id);
+               }
+       }
 }
 
 /* USB is special because the bcdDevice can be matched against a numeric range */
@@ -137,7 +159,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
         * Some modules (visor) have empty slots as placeholder for
         * run-time specification that results in catch-all alias
         */
-       if (!(id->idVendor | id->bDeviceClass | id->bInterfaceClass))
+       if (!(id->idVendor | id->idProduct | id->bDeviceClass | id->bInterfaceClass))
                return;
 
        /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
@@ -168,7 +190,7 @@ static void do_usb_table(void *symval, unsigned long size,
        unsigned int i;
        const unsigned long id_size = sizeof(struct usb_device_id);
 
-       device_id_size_check(mod->name, "usb", size, id_size);
+       device_id_check(mod->name, "usb", size, id_size, symval);
 
        /* Leave last one: it's the terminator. */
        size -= id_size;
@@ -306,19 +328,52 @@ static int do_pnp_entry(const char *filename,
        return 1;
 }
 
-/* looks like: "pnp:cCdD..." */
-static int do_pnp_card_entry(const char *filename,
-                       struct pnp_card_device_id *id, char *alias)
+/* looks like: "pnp:dD" for every device of the card */
+static void do_pnp_card_entries(void *symval, unsigned long size,
+                               struct module *mod)
 {
-       int i;
+       const unsigned long id_size = sizeof(struct pnp_card_device_id);
+       const unsigned int count = (size / id_size)-1;
+       const struct pnp_card_device_id *cards = symval;
+       unsigned int i;
 
-       sprintf(alias, "pnp:c%s", id->id);
-       for (i = 0; i < PNP_MAX_DEVICES; i++) {
-               if (! *id->devs[i].id)
-                       break;
-               sprintf(alias + strlen(alias), "d%s", id->devs[i].id);
+       device_id_check(mod->name, "pnp", size, id_size, symval);
+
+       for (i = 0; i < count; i++) {
+               unsigned int j;
+               const struct pnp_card_device_id *card = &cards[i];
+
+               for (j = 0; j < PNP_MAX_DEVICES; j++) {
+                       const char *id = (char *)card->devs[j].id;
+                       int i2, j2;
+                       int dup = 0;
+
+                       if (!id[0])
+                               break;
+
+                       /* find duplicate, already added value */
+                       for (i2 = 0; i2 < i && !dup; i2++) {
+                               const struct pnp_card_device_id *card2 = &cards[i2];
+
+                               for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
+                                       const char *id2 = (char *)card2->devs[j2].id;
+
+                                       if (!id2[0])
+                                               break;
+
+                                       if (!strcmp(id, id2)) {
+                                               dup = 1;
+                                               break;
+                                       }
+                               }
+                       }
+
+                       /* add an individual alias for every device entry */
+                       if (!dup)
+                               buf_printf(&mod->dev_table_buf,
+                                          "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
+               }
        }
-       return 1;
 }
 
 /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
@@ -507,6 +562,20 @@ static int do_ssb_entry(const char *filename,
        return 1;
 }
 
+/* Looks like: virtio:dNvN */
+static int do_virtio_entry(const char *filename, struct virtio_device_id *id,
+                          char *alias)
+{
+       id->device = TO_NATIVE(id->device);
+       id->vendor = TO_NATIVE(id->vendor);
+
+       strcpy(alias, "virtio:");
+       ADD(alias, "d", 1, id->device);
+       ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor);
+
+       return 1;
+}
+
 /* Ignore any prefix, eg. v850 prepends _ */
 static inline int sym_is(const char *symbol, const char *name)
 {
@@ -528,7 +597,7 @@ static void do_table(void *symval, unsigned long size,
        char alias[500];
        int (*do_entry)(const char *, void *entry, char *alias) = function;
 
-       device_id_size_check(mod->name, device_id, size, id_size);
+       device_id_check(mod->name, device_id, size, id_size, symval);
        /* Leave last one: it's the terminator. */
        size -= id_size;
 
@@ -550,14 +619,21 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
                        Elf_Sym *sym, const char *symname)
 {
        void *symval;
+       char *zeros = NULL;
 
        /* We're looking for a section relative symbol */
        if (!sym->st_shndx || sym->st_shndx >= info->hdr->e_shnum)
                return;
 
-       symval = (void *)info->hdr
-               + info->sechdrs[sym->st_shndx].sh_offset
-               + sym->st_value;
+       /* Handle all-NULL symbols allocated into .bss */
+       if (info->sechdrs[sym->st_shndx].sh_type & SHT_NOBITS) {
+               zeros = calloc(1, sym->st_size);
+               symval = zeros;
+       } else {
+               symval = (void *)info->hdr
+                       + info->sechdrs[sym->st_shndx].sh_offset
+                       + sym->st_value;
+       }
 
        if (sym_is(symname, "__mod_pci_device_table"))
                do_table(symval, sym->st_size,
@@ -591,9 +667,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
                         sizeof(struct pnp_device_id), "pnp",
                         do_pnp_entry, mod);
        else if (sym_is(symname, "__mod_pnp_card_device_table"))
-               do_table(symval, sym->st_size,
-                        sizeof(struct pnp_card_device_id), "pnp_card",
-                        do_pnp_card_entry, mod);
+               do_pnp_card_entries(symval, sym->st_size, mod);
        else if (sym_is(symname, "__mod_pcmcia_device_table"))
                do_table(symval, sym->st_size,
                         sizeof(struct pcmcia_device_id), "pcmcia",
@@ -626,6 +700,11 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
                do_table(symval, sym->st_size,
                         sizeof(struct ssb_device_id), "ssb",
                         do_ssb_entry, mod);
+       else if (sym_is(symname, "__mod_virtio_device_table"))
+               do_table(symval, sym->st_size,
+                        sizeof(struct virtio_device_id), "virtio",
+                        do_virtio_entry, mod);
+       free(zeros);
 }
 
 /* Now add out buffered information to the generated C source */