]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - arch/i386/kernel/dmi_scan.c
Merge branch 'upstream-fixes'
[linux-2.6-omap-h63xx.git] / arch / i386 / kernel / dmi_scan.c
index ecdaae26275535b2065348ec778d0790a038780f..6a93d75db4313a5b3355c0b2896917b13f0c32f8 100644 (file)
@@ -4,27 +4,30 @@
 #include <linux/module.h>
 #include <linux/dmi.h>
 #include <linux/bootmem.h>
-
-
-struct dmi_header {
-       u8 type;
-       u8 length;
-       u16 handle;
-};
-
+#include <linux/slab.h>
 
 static char * __init dmi_string(struct dmi_header *dm, u8 s)
 {
        u8 *bp = ((u8 *) dm) + dm->length;
+       char *str = "";
 
-       if (!s)
-               return "";
-       s--;
-       while (s > 0 && *bp) {
-               bp += strlen(bp) + 1;
+       if (s) {
                s--;
-       }
-       return bp;
+               while (s > 0 && *bp) {
+                       bp += strlen(bp) + 1;
+                       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");
+               }
+       }
+
+       return str;
 }
 
 /*
@@ -37,7 +40,7 @@ static int __init dmi_table(u32 base, int len, int num,
        u8 *buf, *data;
        int i = 0;
                
-       buf = bt_ioremap(base, len);
+       buf = dmi_ioremap(base, len);
        if (buf == NULL)
                return -1;
 
@@ -62,7 +65,7 @@ static int __init dmi_table(u32 base, int len, int num,
                data += 2;
                i++;
        }
-       bt_iounmap(buf, len);
+       dmi_iounmap(buf, len);
        return 0;
 }
 
@@ -78,25 +81,75 @@ static int __init dmi_checksum(u8 *buf)
 }
 
 static char *dmi_ident[DMI_STRING_MAX];
+static LIST_HEAD(dmi_devices);
 
 /*
  *     Save a DMI string
  */
 static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
 {
-       char *d = (char*)dm;
-       char *p = dmi_string(dm, d[string]);
+       char *p, *d = (char*) dm;
 
-       if (p == NULL || *p == 0)
-               return;
        if (dmi_ident[slot])
                return;
 
-       dmi_ident[slot] = alloc_bootmem(strlen(p) + 1);
-       if(dmi_ident[slot])
-               strcpy(dmi_ident[slot], p);
-       else
-               printk(KERN_ERR "dmi_save_ident: out of memory.\n");
+       p = dmi_string(dm, d[string]);
+       if (p == NULL)
+               return;
+
+       dmi_ident[slot] = p;
+}
+
+static void __init dmi_save_devices(struct dmi_header *dm)
+{
+       int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
+       struct dmi_device *dev;
+
+       for (i = 0; i < count; i++) {
+               char *d = ((char *) dm) + (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);
+       }
+}
+
+static void __init dmi_save_ipmi_device(struct dmi_header *dm)
+{
+       struct dmi_device *dev;
+       void * data;
+
+       data = dmi_alloc(dm->length);
+       if (data == NULL) {
+               printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
+               return;
+       }
+
+       memcpy(data, dm, dm->length);
+
+       dev = dmi_alloc(sizeof(*dev));
+       if (!dev) {
+               printk(KERN_ERR "dmi_save_ipmi_device: out of memory.\n");
+               return;
+       }
+
+       dev->type = DMI_DEV_TYPE_IPMI;
+       dev->name = "IPMI controller";
+       dev->device_data = data;
+
+       list_add(&dev->list, &dmi_devices);
 }
 
 /*
@@ -106,25 +159,28 @@ static void __init dmi_save_ident(struct dmi_header *dm, int slot, int string)
  */
 static void __init dmi_decode(struct dmi_header *dm)
 {
-       u8 *data __attribute__((__unused__)) = (u8 *)dm;
-       
        switch(dm->type) {
-       case  0:
+       case 0:         /* BIOS Information */
                dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
                dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
                dmi_save_ident(dm, DMI_BIOS_DATE, 8);
                break;
-       case 1:
+       case 1:         /* System Information */
                dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
                dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
                dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
                dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
                break;
-       case 2:
+       case 2:         /* Base Board Information */
                dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
                dmi_save_ident(dm, DMI_BOARD_NAME, 5);
                dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
                break;
+       case 10:        /* Onboard Devices Information */
+               dmi_save_devices(dm);
+               break;
+       case 38:        /* IPMI Device Information */
+               dmi_save_ipmi_device(dm);
        }
 }
 
@@ -165,7 +221,7 @@ void __init dmi_scan_machine(void)
                }
        }
 
-out:   printk(KERN_INFO "DMI not present.\n");
+out:   printk(KERN_INFO "DMI not present or invalid.\n");
 }
 
 
@@ -192,9 +248,9 @@ int dmi_check_system(struct dmi_system_id *list)
                        /* No match */
                        goto fail;
                }
+               count++;
                if (d->callback && d->callback(d))
                        break;
-               count++;
 fail:          d++;
        }
 
@@ -214,3 +270,32 @@ char *dmi_get_system_info(int field)
        return dmi_ident[field];
 }
 EXPORT_SYMBOL(dmi_get_system_info);
+
+/**
+ *     dmi_find_device - find onboard device by type/name
+ *     @type: device type or %DMI_DEV_TYPE_ANY to match all device types
+ *     @desc: device name string or %NULL to match all
+ *     @from: previous device found in search, or %NULL for new search.
+ *
+ *     Iterates through the list of known onboard devices. If a device is
+ *     found with a matching @vendor and @device, a pointer to its device
+ *     structure is returned.  Otherwise, %NULL is returned.
+ *     A new search is initiated by passing %NULL to 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)
+{
+       struct list_head *d, *head = from ? &from->list : &dmi_devices;
+
+       for(d = head->next; d != &dmi_devices; d = d->next) {
+               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)))
+                       return dev;
+       }
+
+       return NULL;
+}
+EXPORT_SYMBOL(dmi_find_device);