]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/firmware/dmi_scan.c
trivial: dmi_scan typo
[linux-2.6-omap-h63xx.git] / drivers / firmware / dmi_scan.c
index f7318b3b51f2a0860bf2f952896d60f746bd98a8..8daf4793ac32485824194af5e14f332c50fc6f26 100644 (file)
@@ -8,10 +8,21 @@
 #include <linux/slab.h>
 #include <asm/dmi.h>
 
-static char * __init dmi_string(struct dmi_header *dm, u8 s)
+/*
+ * DMI stands for "Desktop Management Interface".  It is part
+ * of and an antecedent to, SMBIOS, which stands for System
+ * Management BIOS.  See further: http://www.dmtf.org/standards
+ */
+static char dmi_empty_string[] = "        ";
+
+/*
+ * Catch too early calls to dmi_check_system():
+ */
+static int dmi_initialized;
+
+static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
 {
-       u8 *bp = ((u8 *) dm) + dm->length;
-       char *str = "";
+       const u8 *bp = ((u8 *) dm) + dm->length;
 
        if (s) {
                s--;
@@ -21,14 +32,34 @@ static char * __init dmi_string(struct dmi_header *dm, u8 s)
                }
 
                if (*bp != 0) {
-                       str = dmi_alloc(strlen(bp) + 1);
-                       if (str != NULL)
-                               strcpy(str, bp);
-                       else
-                               printk(KERN_ERR "dmi_string: out of memory.\n");
+                       size_t len = strlen(bp)+1;
+                       size_t cmp_len = len > 8 ? 8 : len;
+
+                       if (!memcmp(bp, dmi_empty_string, cmp_len))
+                               return dmi_empty_string;
+                       return bp;
                }
        }
 
+       return "";
+}
+
+static char * __init dmi_string(const struct dmi_header *dm, u8 s)
+{
+       const char *bp = dmi_string_nosave(dm, s);
+       char *str;
+       size_t len;
+
+       if (bp == dmi_empty_string)
+               return dmi_empty_string;
+
+       len = strlen(bp) + 1;
+       str = dmi_alloc(len);
+       if (str != NULL)
+               strcpy(str, bp);
+       else
+               printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len);
+
        return str;
 }
 
@@ -36,28 +67,23 @@ static char * __init dmi_string(struct dmi_header *dm, u8 s)
  *     We have to be cautious here. We have seen BIOSes with DMI pointers
  *     pointing to completely the wrong place for example
  */
-static int __init dmi_table(u32 base, int len, int num,
-                           void (*decode)(struct dmi_header *))
+static void dmi_table(u8 *buf, int len, int num,
+                     void (*decode)(const struct dmi_header *))
 {
-       u8 *buf, *data;
+       u8 *data = buf;
        int i = 0;
 
-       buf = dmi_ioremap(base, len);
-       if (buf == NULL)
-               return -1;
-
-       data = buf;
-
        /*
         *      Stop when we see all the items the table claimed to have
         *      OR we run off the end of the table (also happens)
         */
        while ((i < num) && (data - buf + sizeof(struct dmi_header)) <= len) {
-               struct dmi_header *dm = (struct dmi_header *)data;
+               const struct dmi_header *dm = (const struct dmi_header *)data;
+
                /*
-                *  We want to know the total length (formated area and strings)
-                *  before decoding to make sure we won't run off the table in
-                *  dmi_decode or dmi_string
+                *  We want to know the total length (formatted area and
+                *  strings) before decoding to make sure we won't run off the
+                *  table in dmi_decode or dmi_string
                 */
                data += dm->length;
                while ((data - buf < len - 1) && (data[0] || data[1]))
@@ -67,11 +93,27 @@ static int __init dmi_table(u32 base, int len, int num,
                data += 2;
                i++;
        }
-       dmi_iounmap(buf, len);
+}
+
+static u32 dmi_base;
+static u16 dmi_len;
+static u16 dmi_num;
+
+static int __init dmi_walk_early(void (*decode)(const struct dmi_header *))
+{
+       u8 *buf;
+
+       buf = dmi_ioremap(dmi_base, dmi_len);
+       if (buf == NULL)
+               return -1;
+
+       dmi_table(buf, dmi_len, dmi_num, decode);
+
+       dmi_iounmap(buf, dmi_len);
        return 0;
 }
 
-static int __init dmi_checksum(u8 *buf)
+static int __init dmi_checksum(const u8 *buf)
 {
        u8 sum = 0;
        int a;
@@ -89,9 +131,10 @@ int dmi_available;
 /*
  *     Save a DMI string
  */
-static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
+static void __init dmi_save_ident(const struct dmi_header *dm, int slot, int string)
 {
-       char *p, *d = (char*) dm;
+       const char *d = (const char*) dm;
+       char *p;
 
        if (dmi_ident[slot])
                return;
@@ -103,9 +146,9 @@ static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
        dmi_ident[slot] = p;
 }
 
-static void __init dmi_save_uuid(struct dmi_header *dm, int slot, int index)
+static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, int index)
 {
-       u8 *d = (u8*) dm + index;
+       const u8 *d = (u8*) dm + index;
        char *s;
        int is_ff = 1, is_00 = 1, i;
 
@@ -132,9 +175,9 @@ static void __init dmi_save_uuid(struct dmi_header *dm, int slot, int index)
         dmi_ident[slot] = s;
 }
 
-static void __init dmi_save_type(struct dmi_header *dm, int slot, int index)
+static void __init dmi_save_type(const struct dmi_header *dm, int slot, int index)
 {
-       u8 *d = (u8*) dm + index;
+       const u8 *d = (u8*) dm + index;
        char *s;
 
        if (dmi_ident[slot])
@@ -148,37 +191,53 @@ static void __init dmi_save_type(struct dmi_header *dm, int slot, int index)
        dmi_ident[slot] = s;
 }
 
-static void __init dmi_save_devices(struct dmi_header *dm)
+static void __init dmi_save_one_device(int type, const char *name)
 {
-       int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
        struct dmi_device *dev;
 
+       /* No duplicate device */
+       if (dmi_find_device(type, name, NULL))
+               return;
+
+       dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
+       if (!dev) {
+               printk(KERN_ERR "dmi_save_one_device: out of memory.\n");
+               return;
+       }
+
+       dev->type = type;
+       strcpy((char *)(dev + 1), name);
+       dev->name = (char *)(dev + 1);
+       dev->device_data = NULL;
+       list_add(&dev->list, &dmi_devices);
+}
+
+static void __init dmi_save_devices(const struct dmi_header *dm)
+{
+       int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
+
        for (i = 0; i < count; i++) {
-               char *d = (char *)(dm + 1) + (i * 2);
+               const char *d = (char *)(dm + 1) + (i * 2);
 
                /* Skip disabled device */
                if ((*d & 0x80) == 0)
                        continue;
 
-               dev = dmi_alloc(sizeof(*dev));
-               if (!dev) {
-                       printk(KERN_ERR "dmi_save_devices: out of memory.\n");
-                       break;
-               }
-
-               dev->type = *d++ & 0x7f;
-               dev->name = dmi_string(dm, *d);
-               dev->device_data = NULL;
-               list_add(&dev->list, &dmi_devices);
+               dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
        }
 }
 
-static void __init dmi_save_oem_strings_devices(struct dmi_header *dm)
+static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
 {
        int i, count = *(u8 *)(dm + 1);
        struct dmi_device *dev;
 
        for (i = 1; i <= count; i++) {
+               char *devname = dmi_string(dm, i);
+
+               if (devname == dmi_empty_string)
+                       continue;
+
                dev = dmi_alloc(sizeof(*dev));
                if (!dev) {
                        printk(KERN_ERR
@@ -187,14 +246,14 @@ static void __init dmi_save_oem_strings_devices(struct dmi_header *dm)
                }
 
                dev->type = DMI_DEV_TYPE_OEM_STRING;
-               dev->name = dmi_string(dm, i);
+               dev->name = devname;
                dev->device_data = NULL;
 
                list_add(&dev->list, &dmi_devices);
        }
 }
 
-static void __init dmi_save_ipmi_device(struct dmi_header *dm)
+static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
 {
        struct dmi_device *dev;
        void * data;
@@ -217,7 +276,18 @@ static void __init dmi_save_ipmi_device(struct dmi_header *dm)
        dev->name = "IPMI controller";
        dev->device_data = data;
 
-       list_add(&dev->list, &dmi_devices);
+       list_add_tail(&dev->list, &dmi_devices);
+}
+
+static void __init dmi_save_extended_devices(const struct dmi_header *dm)
+{
+       const u8 *d = (u8*) dm + 5;
+
+       /* Skip disabled device */
+       if ((*d & 0x80) == 0)
+               return;
+
+       dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d - 1)));
 }
 
 /*
@@ -225,7 +295,7 @@ static void __init dmi_save_ipmi_device(struct dmi_header *dm)
  *     and machine entries. For 2.5 we should pull the smbus controller info
  *     out of here.
  */
-static void __init dmi_decode(struct dmi_header *dm)
+static void __init dmi_decode(const struct dmi_header *dm)
 {
        switch(dm->type) {
        case 0:         /* BIOS Information */
@@ -262,17 +332,21 @@ static void __init dmi_decode(struct dmi_header *dm)
                break;
        case 38:        /* IPMI Device Information */
                dmi_save_ipmi_device(dm);
+               break;
+       case 41:        /* Onboard Devices Extended Information */
+               dmi_save_extended_devices(dm);
        }
 }
 
-static int __init dmi_present(char __iomem *p)
+static int __init dmi_present(const char __iomem *p)
 {
        u8 buf[15];
+
        memcpy_fromio(buf, p, 15);
        if ((memcmp(buf, "_DMI_", 5) == 0) && dmi_checksum(buf)) {
-               u16 num = (buf[13] << 8) | buf[12];
-               u16 len = (buf[7] << 8) | buf[6];
-               u32 base = (buf[11] << 24) | (buf[10] << 16) |
+               dmi_num = (buf[13] << 8) | buf[12];
+               dmi_len = (buf[7] << 8) | buf[6];
+               dmi_base = (buf[11] << 24) | (buf[10] << 16) |
                        (buf[9] << 8) | buf[8];
 
                /*
@@ -284,7 +358,7 @@ static int __init dmi_present(char __iomem *p)
                               buf[14] >> 4, buf[14] & 0xF);
                else
                        printk(KERN_INFO "DMI present.\n");
-               if (dmi_table(base,len, num, dmi_decode) == 0)
+               if (dmi_walk_early(dmi_decode) == 0)
                        return 0;
        }
        return 1;
@@ -297,7 +371,7 @@ void __init dmi_scan_machine(void)
 
        if (efi_enabled) {
                if (efi.smbios == EFI_INVALID_TABLE_ADDR)
-                       goto out;
+                       goto error;
 
                /* This is called as a core_initcall() because it isn't
                 * needed during early boot.  This also means we can
@@ -305,13 +379,13 @@ void __init dmi_scan_machine(void)
                 */
                p = dmi_ioremap(efi.smbios, 32);
                if (p == NULL)
-                       goto out;
+                       goto error;
 
                rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
                dmi_iounmap(p, 32);
                if (!rc) {
                        dmi_available = 1;
-                       return;
+                       goto out;
                }
        }
        else {
@@ -322,17 +396,22 @@ void __init dmi_scan_machine(void)
                 */
                p = dmi_ioremap(0xF0000, 0x10000);
                if (p == NULL)
-                       goto out;
+                       goto error;
 
                for (q = p; q < p + 0x10000; q += 16) {
                        rc = dmi_present(q);
                        if (!rc) {
                                dmi_available = 1;
-                               return;
+                               dmi_iounmap(p, 0x10000);
+                               goto out;
                        }
                }
+               dmi_iounmap(p, 0x10000);
        }
- out:  printk(KERN_INFO "DMI not present or invalid.\n");
+ error:
+       printk(KERN_INFO "DMI not present or invalid.\n");
+ out:
+       dmi_initialized = 1;
 }
 
 /**
@@ -348,10 +427,12 @@ void __init dmi_scan_machine(void)
  *     returns non zero or we hit the end. Callback function is called for
  *     each successful match. Returns the number of matches.
  */
-int dmi_check_system(struct dmi_system_id *list)
+int dmi_check_system(const struct dmi_system_id *list)
 {
        int i, count = 0;
-       struct dmi_system_id *d = list;
+       const struct dmi_system_id *d = list;
+
+       WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
 
        while (d->ident) {
                for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
@@ -380,7 +461,7 @@ EXPORT_SYMBOL(dmi_check_system);
  *     Returns one DMI data value, can be used to perform
  *     complex DMI data checks.
  */
-char *dmi_get_system_info(int field)
+const char *dmi_get_system_info(int field)
 {
        return dmi_ident[field];
 }
@@ -391,7 +472,7 @@ EXPORT_SYMBOL(dmi_get_system_info);
  *     dmi_name_in_vendors - Check if string is anywhere in the DMI vendor information.
  *     @str:   Case sensitive Name
  */
-int dmi_name_in_vendors(char *str)
+int dmi_name_in_vendors(const char *str)
 {
        static int fields[] = { DMI_BIOS_VENDOR, DMI_BIOS_VERSION, DMI_SYS_VENDOR,
                                DMI_PRODUCT_NAME, DMI_PRODUCT_VERSION, DMI_BOARD_VENDOR,
@@ -418,13 +499,15 @@ EXPORT_SYMBOL(dmi_name_in_vendors);
  *     A new search is initiated by passing %NULL as the @from argument.
  *     If @from is not %NULL, searches continue from next device.
  */
-struct dmi_device * dmi_find_device(int type, const char *name,
-                                   struct dmi_device *from)
+const struct dmi_device * dmi_find_device(int type, const char *name,
+                                   const struct dmi_device *from)
 {
-       struct list_head *d, *head = from ? &from->list : &dmi_devices;
+       const struct list_head *head = from ? &from->list : &dmi_devices;
+       struct list_head *d;
 
        for(d = head->next; d != &dmi_devices; d = d->next) {
-               struct dmi_device *dev = list_entry(d, struct dmi_device, list);
+               const struct dmi_device *dev =
+                       list_entry(d, struct dmi_device, list);
 
                if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
                    ((name == NULL) || (strcmp(dev->name, name) == 0)))
@@ -444,7 +527,7 @@ EXPORT_SYMBOL(dmi_find_device);
 int dmi_get_year(int field)
 {
        int year;
-       char *s = dmi_get_system_info(field);
+       const char *s = dmi_get_system_info(field);
 
        if (!s)
                return -1;
@@ -465,3 +548,26 @@ int dmi_get_year(int field)
        return year;
 }
 
+/**
+ *     dmi_walk - Walk the DMI table and get called back for every record
+ *     @decode: Callback function
+ *
+ *     Returns -1 when the DMI table can't be reached, 0 on success.
+ */
+int dmi_walk(void (*decode)(const struct dmi_header *))
+{
+       u8 *buf;
+
+       if (!dmi_available)
+               return -1;
+
+       buf = ioremap(dmi_base, dmi_len);
+       if (buf == NULL)
+               return -1;
+
+       dmi_table(buf, dmi_len, dmi_num, decode);
+
+       iounmap(buf);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(dmi_walk);