X-Git-Url: http://pilppa.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=drivers%2Ffirmware%2Fdmi_scan.c;h=c5e3ed7e903b3a14f405554f8c6163f2d62cb998;hb=dbfe54a9c9a9e31cdf71704e4e70d10d22a57264;hp=9008ed5ef4ce2e384b41c591cdc7c629a08af324;hpb=8f859016ea49cd8d7c743533bd1ab3db9a813ffa;p=linux-2.6-omap-h63xx.git diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c index 9008ed5ef4c..c5e3ed7e903 100644 --- a/drivers/firmware/dmi_scan.c +++ b/drivers/firmware/dmi_scan.c @@ -10,10 +10,9 @@ static char dmi_empty_string[] = " "; -static char * __init dmi_string(const struct dmi_header *dm, u8 s) +static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s) { const u8 *bp = ((u8 *) dm) + dm->length; - char *str = ""; if (s) { s--; @@ -28,14 +27,29 @@ static char * __init dmi_string(const struct dmi_header *dm, u8 s) if (!memcmp(bp, dmi_empty_string, cmp_len)) return dmi_empty_string; - str = dmi_alloc(len); - if (str != NULL) - strcpy(str, bp); - else - printk(KERN_ERR "dmi_string: cannot allocate %Zu bytes.\n", len); + 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; } @@ -43,18 +57,12 @@ static char * __init dmi_string(const 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)(const 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) @@ -75,7 +83,23 @@ 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; } @@ -157,10 +181,30 @@ static void __init dmi_save_type(const struct dmi_header *dm, int slot, int inde dmi_ident[slot] = s; } +static void __init dmi_save_one_device(int type, const char *name) +{ + 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; - struct dmi_device *dev; for (i = 0; i < count; i++) { const char *d = (char *)(dm + 1) + (i * 2); @@ -169,23 +213,10 @@ static void __init dmi_save_devices(const struct dmi_header *dm) 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 struct dmi_device empty_oem_string_dev = { - .name = dmi_empty_string, -}; - static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) { int i, count = *(u8 *)(dm + 1); @@ -194,10 +225,8 @@ static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) for (i = 1; i <= count; i++) { char *devname = dmi_string(dm, i); - if (!strcmp(devname, dmi_empty_string)) { - list_add(&empty_oem_string_dev.list, &dmi_devices); + if (devname == dmi_empty_string) continue; - } dev = dmi_alloc(sizeof(*dev)); if (!dev) { @@ -237,7 +266,18 @@ static void __init dmi_save_ipmi_device(const 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))); } /* @@ -282,6 +322,9 @@ static void __init dmi_decode(const 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); } } @@ -291,9 +334,9 @@ static int __init dmi_present(const char __iomem *p) 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]; /* @@ -305,7 +348,7 @@ static int __init dmi_present(const 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; @@ -491,10 +534,25 @@ int dmi_get_year(int field) } /** - * dmi_get_slot - return dmi_ident[slot] - * @slot: index into dmi_ident[] + * 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. */ -char *dmi_get_slot(int slot) +int dmi_walk(void (*decode)(const struct dmi_header *)) { - return(dmi_ident[slot]); + 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);