14f705ae3SBjorn Helgaas #include <linux/types.h> 24f705ae3SBjorn Helgaas #include <linux/string.h> 34f705ae3SBjorn Helgaas #include <linux/init.h> 44f705ae3SBjorn Helgaas #include <linux/module.h> 58881cdceSBjorn Helgaas #include <linux/ctype.h> 64f705ae3SBjorn Helgaas #include <linux/dmi.h> 74f705ae3SBjorn Helgaas #include <linux/efi.h> 84f705ae3SBjorn Helgaas #include <linux/bootmem.h> 9d114a333STony Luck #include <linux/random.h> 104f705ae3SBjorn Helgaas #include <asm/dmi.h> 110841c04dSLuck, Tony #include <asm/unaligned.h> 124f705ae3SBjorn Helgaas 13d7f96f97SIvan Khoronzhuk struct kobject *dmi_kobj; 14d7f96f97SIvan Khoronzhuk EXPORT_SYMBOL_GPL(dmi_kobj); 15d7f96f97SIvan Khoronzhuk 16cb5dd7c1SPaul Jackson /* 17cb5dd7c1SPaul Jackson * DMI stands for "Desktop Management Interface". It is part 18cb5dd7c1SPaul Jackson * of and an antecedent to, SMBIOS, which stands for System 19cb5dd7c1SPaul Jackson * Management BIOS. See further: http://www.dmtf.org/standards 20cb5dd7c1SPaul Jackson */ 21ffbbb96dSJean Delvare static const char dmi_empty_string[] = " "; 2279da4721SParag Warudkar 2395be58dfSIvan Khoronzhuk static u32 dmi_ver __initdata; 24552e19d8SIvan Khoronzhuk static u32 dmi_len; 25552e19d8SIvan Khoronzhuk static u16 dmi_num; 26d7f96f97SIvan Khoronzhuk static u8 smbios_entry_point[32]; 27d7f96f97SIvan Khoronzhuk static int smbios_entry_point_size; 28d7f96f97SIvan Khoronzhuk 299a22b6e7SIngo Molnar /* 309a22b6e7SIngo Molnar * Catch too early calls to dmi_check_system(): 319a22b6e7SIngo Molnar */ 329a22b6e7SIngo Molnar static int dmi_initialized; 339a22b6e7SIngo Molnar 34c90fe6bcSTejun Heo /* DMI system identification string used during boot */ 35c90fe6bcSTejun Heo static char dmi_ids_string[128] __initdata; 36c90fe6bcSTejun Heo 37dd6dad42SChen, Gong static struct dmi_memdev_info { 38dd6dad42SChen, Gong const char *device; 39dd6dad42SChen, Gong const char *bank; 40dd6dad42SChen, Gong u16 handle; 41dd6dad42SChen, Gong } *dmi_memdev; 42dd6dad42SChen, Gong static int dmi_memdev_nr; 43dd6dad42SChen, Gong 44f3069ae9SJean Delvare static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s) 454f705ae3SBjorn Helgaas { 461855256cSJeff Garzik const u8 *bp = ((u8 *) dm) + dm->length; 474f705ae3SBjorn Helgaas 484f705ae3SBjorn Helgaas if (s) { 494f705ae3SBjorn Helgaas s--; 504f705ae3SBjorn Helgaas while (s > 0 && *bp) { 514f705ae3SBjorn Helgaas bp += strlen(bp) + 1; 524f705ae3SBjorn Helgaas s--; 534f705ae3SBjorn Helgaas } 544f705ae3SBjorn Helgaas 554f705ae3SBjorn Helgaas if (*bp != 0) { 5679da4721SParag Warudkar size_t len = strlen(bp)+1; 5779da4721SParag Warudkar size_t cmp_len = len > 8 ? 8 : len; 5879da4721SParag Warudkar 5979da4721SParag Warudkar if (!memcmp(bp, dmi_empty_string, cmp_len)) 6079da4721SParag Warudkar return dmi_empty_string; 61f3069ae9SJean Delvare return bp; 62f3069ae9SJean Delvare } 63f3069ae9SJean Delvare } 64f3069ae9SJean Delvare 65f3069ae9SJean Delvare return ""; 66f3069ae9SJean Delvare } 67f3069ae9SJean Delvare 68ffbbb96dSJean Delvare static const char * __init dmi_string(const struct dmi_header *dm, u8 s) 69f3069ae9SJean Delvare { 70f3069ae9SJean Delvare const char *bp = dmi_string_nosave(dm, s); 71f3069ae9SJean Delvare char *str; 72f3069ae9SJean Delvare size_t len; 73f3069ae9SJean Delvare 74f3069ae9SJean Delvare if (bp == dmi_empty_string) 75f3069ae9SJean Delvare return dmi_empty_string; 76f3069ae9SJean Delvare 77f3069ae9SJean Delvare len = strlen(bp) + 1; 7879da4721SParag Warudkar str = dmi_alloc(len); 794f705ae3SBjorn Helgaas if (str != NULL) 804f705ae3SBjorn Helgaas strcpy(str, bp); 814f705ae3SBjorn Helgaas 824f705ae3SBjorn Helgaas return str; 834f705ae3SBjorn Helgaas } 844f705ae3SBjorn Helgaas 854f705ae3SBjorn Helgaas /* 864f705ae3SBjorn Helgaas * We have to be cautious here. We have seen BIOSes with DMI pointers 874f705ae3SBjorn Helgaas * pointing to completely the wrong place for example 884f705ae3SBjorn Helgaas */ 89eb4c5ea5SIvan Khoronzhuk static void dmi_decode_table(u8 *buf, 90e7a19c56SJean Delvare void (*decode)(const struct dmi_header *, void *), 91e7a19c56SJean Delvare void *private_data) 924f705ae3SBjorn Helgaas { 937fce084aSJean Delvare u8 *data = buf; 944f705ae3SBjorn Helgaas int i = 0; 954f705ae3SBjorn Helgaas 964f705ae3SBjorn Helgaas /* 97bfbaafaeSJean Delvare * Stop when we have seen all the items the table claimed to have 9817cd5bd5SJean Delvare * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS 9917cd5bd5SJean Delvare * >= 3.0 only) OR we run off the end of the table (should never 10017cd5bd5SJean Delvare * happen but sometimes does on bogus implementations.) 1014f705ae3SBjorn Helgaas */ 1029c65e12aSLinus Torvalds while ((!dmi_num || i < dmi_num) && 1039c65e12aSLinus Torvalds (data - buf + sizeof(struct dmi_header)) <= dmi_len) { 1041855256cSJeff Garzik const struct dmi_header *dm = (const struct dmi_header *)data; 1051855256cSJeff Garzik 1064f705ae3SBjorn Helgaas /* 1078638545cSAlan Cox * We want to know the total length (formatted area and 1088638545cSAlan Cox * strings) before decoding to make sure we won't run off the 1098638545cSAlan Cox * table in dmi_decode or dmi_string 1104f705ae3SBjorn Helgaas */ 1114f705ae3SBjorn Helgaas data += dm->length; 112552e19d8SIvan Khoronzhuk while ((data - buf < dmi_len - 1) && (data[0] || data[1])) 1134f705ae3SBjorn Helgaas data++; 114552e19d8SIvan Khoronzhuk if (data - buf < dmi_len - 1) 115e7a19c56SJean Delvare decode(dm, private_data); 116ce204e9aSIvan Khoronzhuk 1176e0ad59eSJean Delvare data += 2; 1186e0ad59eSJean Delvare i++; 1196e0ad59eSJean Delvare 120ce204e9aSIvan Khoronzhuk /* 121ce204e9aSIvan Khoronzhuk * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0] 12217cd5bd5SJean Delvare * For tables behind a 64-bit entry point, we have no item 12317cd5bd5SJean Delvare * count and no exact table length, so stop on end-of-table 12417cd5bd5SJean Delvare * marker. For tables behind a 32-bit entry point, we have 12517cd5bd5SJean Delvare * seen OEM structures behind the end-of-table marker on 12617cd5bd5SJean Delvare * some systems, so don't trust it. 127ce204e9aSIvan Khoronzhuk */ 12817cd5bd5SJean Delvare if (!dmi_num && dm->type == DMI_ENTRY_END_OF_TABLE) 129ce204e9aSIvan Khoronzhuk break; 1304f705ae3SBjorn Helgaas } 1316e0ad59eSJean Delvare 1326e0ad59eSJean Delvare /* Trim DMI table length if needed */ 1336e0ad59eSJean Delvare if (dmi_len > data - buf) 1346e0ad59eSJean Delvare dmi_len = data - buf; 1357fce084aSJean Delvare } 1367fce084aSJean Delvare 137fc430262SArd Biesheuvel static phys_addr_t dmi_base; 1387fce084aSJean Delvare 139e7a19c56SJean Delvare static int __init dmi_walk_early(void (*decode)(const struct dmi_header *, 140e7a19c56SJean Delvare void *)) 1417fce084aSJean Delvare { 1427fce084aSJean Delvare u8 *buf; 1436e0ad59eSJean Delvare u32 orig_dmi_len = dmi_len; 1447fce084aSJean Delvare 1456e0ad59eSJean Delvare buf = dmi_early_remap(dmi_base, orig_dmi_len); 1467fce084aSJean Delvare if (buf == NULL) 147c9268200SAndy Lutomirski return -ENOMEM; 1487fce084aSJean Delvare 149eb4c5ea5SIvan Khoronzhuk dmi_decode_table(buf, decode, NULL); 1507fce084aSJean Delvare 151d114a333STony Luck add_device_randomness(buf, dmi_len); 152d114a333STony Luck 1536e0ad59eSJean Delvare dmi_early_unmap(buf, orig_dmi_len); 1544f705ae3SBjorn Helgaas return 0; 1554f705ae3SBjorn Helgaas } 1564f705ae3SBjorn Helgaas 1579f9c9cbbSZhenzhong Duan static int __init dmi_checksum(const u8 *buf, u8 len) 1584f705ae3SBjorn Helgaas { 1594f705ae3SBjorn Helgaas u8 sum = 0; 1604f705ae3SBjorn Helgaas int a; 1614f705ae3SBjorn Helgaas 1629f9c9cbbSZhenzhong Duan for (a = 0; a < len; a++) 1634f705ae3SBjorn Helgaas sum += buf[a]; 1644f705ae3SBjorn Helgaas 1654f705ae3SBjorn Helgaas return sum == 0; 1664f705ae3SBjorn Helgaas } 1674f705ae3SBjorn Helgaas 168ffbbb96dSJean Delvare static const char *dmi_ident[DMI_STRING_MAX]; 1694f705ae3SBjorn Helgaas static LIST_HEAD(dmi_devices); 1704f5c791aSLennart Poettering int dmi_available; 1714f705ae3SBjorn Helgaas 1724f705ae3SBjorn Helgaas /* 1734f705ae3SBjorn Helgaas * Save a DMI string 1744f705ae3SBjorn Helgaas */ 17502d9c47fSJean Delvare static void __init dmi_save_ident(const struct dmi_header *dm, int slot, 17602d9c47fSJean Delvare int string) 1774f705ae3SBjorn Helgaas { 1781855256cSJeff Garzik const char *d = (const char *) dm; 179ffbbb96dSJean Delvare const char *p; 1804f705ae3SBjorn Helgaas 181*a814c359SJean Delvare if (dmi_ident[slot] || dm->length <= string) 1824f705ae3SBjorn Helgaas return; 1834f705ae3SBjorn Helgaas 1844f705ae3SBjorn Helgaas p = dmi_string(dm, d[string]); 1854f705ae3SBjorn Helgaas if (p == NULL) 1864f705ae3SBjorn Helgaas return; 1874f705ae3SBjorn Helgaas 1884f705ae3SBjorn Helgaas dmi_ident[slot] = p; 1894f705ae3SBjorn Helgaas } 1904f705ae3SBjorn Helgaas 19102d9c47fSJean Delvare static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, 19202d9c47fSJean Delvare int index) 1934f5c791aSLennart Poettering { 194*a814c359SJean Delvare const u8 *d; 1954f5c791aSLennart Poettering char *s; 1964f5c791aSLennart Poettering int is_ff = 1, is_00 = 1, i; 1974f5c791aSLennart Poettering 198*a814c359SJean Delvare if (dmi_ident[slot] || dm->length <= index + 16) 1994f5c791aSLennart Poettering return; 2004f5c791aSLennart Poettering 201*a814c359SJean Delvare d = (u8 *) dm + index; 2024f5c791aSLennart Poettering for (i = 0; i < 16 && (is_ff || is_00); i++) { 203f1d8e614SZhenzhong Duan if (d[i] != 0x00) 204f1d8e614SZhenzhong Duan is_00 = 0; 205f1d8e614SZhenzhong Duan if (d[i] != 0xFF) 206f1d8e614SZhenzhong Duan is_ff = 0; 2074f5c791aSLennart Poettering } 2084f5c791aSLennart Poettering 2094f5c791aSLennart Poettering if (is_ff || is_00) 2104f5c791aSLennart Poettering return; 2114f5c791aSLennart Poettering 2124f5c791aSLennart Poettering s = dmi_alloc(16*2+4+1); 2134f5c791aSLennart Poettering if (!s) 2144f5c791aSLennart Poettering return; 2154f5c791aSLennart Poettering 216f1d8e614SZhenzhong Duan /* 217f1d8e614SZhenzhong Duan * As of version 2.6 of the SMBIOS specification, the first 3 fields of 218f1d8e614SZhenzhong Duan * the UUID are supposed to be little-endian encoded. The specification 219f1d8e614SZhenzhong Duan * says that this is the defacto standard. 220f1d8e614SZhenzhong Duan */ 22195be58dfSIvan Khoronzhuk if (dmi_ver >= 0x020600) 222f1d8e614SZhenzhong Duan sprintf(s, "%pUL", d); 223f1d8e614SZhenzhong Duan else 224bc058f65SJoe Perches sprintf(s, "%pUB", d); 2254f5c791aSLennart Poettering 2264f5c791aSLennart Poettering dmi_ident[slot] = s; 2274f5c791aSLennart Poettering } 2284f5c791aSLennart Poettering 22902d9c47fSJean Delvare static void __init dmi_save_type(const struct dmi_header *dm, int slot, 23002d9c47fSJean Delvare int index) 2314f5c791aSLennart Poettering { 232*a814c359SJean Delvare const u8 *d; 2334f5c791aSLennart Poettering char *s; 2344f5c791aSLennart Poettering 235*a814c359SJean Delvare if (dmi_ident[slot] || dm->length <= index) 2364f5c791aSLennart Poettering return; 2374f5c791aSLennart Poettering 2384f5c791aSLennart Poettering s = dmi_alloc(4); 2394f5c791aSLennart Poettering if (!s) 2404f5c791aSLennart Poettering return; 2414f5c791aSLennart Poettering 242*a814c359SJean Delvare d = (u8 *) dm + index; 2434f5c791aSLennart Poettering sprintf(s, "%u", *d & 0x7F); 2444f5c791aSLennart Poettering dmi_ident[slot] = s; 2454f5c791aSLennart Poettering } 2464f5c791aSLennart Poettering 247f3069ae9SJean Delvare static void __init dmi_save_one_device(int type, const char *name) 248f3069ae9SJean Delvare { 249f3069ae9SJean Delvare struct dmi_device *dev; 250f3069ae9SJean Delvare 251f3069ae9SJean Delvare /* No duplicate device */ 252f3069ae9SJean Delvare if (dmi_find_device(type, name, NULL)) 253f3069ae9SJean Delvare return; 254f3069ae9SJean Delvare 255f3069ae9SJean Delvare dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1); 256ae797449SJean Delvare if (!dev) 257f3069ae9SJean Delvare return; 258f3069ae9SJean Delvare 259f3069ae9SJean Delvare dev->type = type; 260f3069ae9SJean Delvare strcpy((char *)(dev + 1), name); 261f3069ae9SJean Delvare dev->name = (char *)(dev + 1); 262f3069ae9SJean Delvare dev->device_data = NULL; 263f3069ae9SJean Delvare list_add(&dev->list, &dmi_devices); 264f3069ae9SJean Delvare } 265f3069ae9SJean Delvare 2661855256cSJeff Garzik static void __init dmi_save_devices(const struct dmi_header *dm) 2674f705ae3SBjorn Helgaas { 2684f705ae3SBjorn Helgaas int i, count = (dm->length - sizeof(struct dmi_header)) / 2; 2694f705ae3SBjorn Helgaas 2704f705ae3SBjorn Helgaas for (i = 0; i < count; i++) { 2711855256cSJeff Garzik const char *d = (char *)(dm + 1) + (i * 2); 2724f705ae3SBjorn Helgaas 2734f705ae3SBjorn Helgaas /* Skip disabled device */ 2744f705ae3SBjorn Helgaas if ((*d & 0x80) == 0) 2754f705ae3SBjorn Helgaas continue; 2764f705ae3SBjorn Helgaas 277f3069ae9SJean Delvare dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1))); 2782e0c1f6cSShem Multinymous } 2792e0c1f6cSShem Multinymous } 2802e0c1f6cSShem Multinymous 2811855256cSJeff Garzik static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) 2822e0c1f6cSShem Multinymous { 283*a814c359SJean Delvare int i, count; 2842e0c1f6cSShem Multinymous struct dmi_device *dev; 2852e0c1f6cSShem Multinymous 286*a814c359SJean Delvare if (dm->length < 0x05) 287*a814c359SJean Delvare return; 288*a814c359SJean Delvare 289*a814c359SJean Delvare count = *(u8 *)(dm + 1); 2902e0c1f6cSShem Multinymous for (i = 1; i <= count; i++) { 291ffbbb96dSJean Delvare const char *devname = dmi_string(dm, i); 29279da4721SParag Warudkar 29343fe105aSJean Delvare if (devname == dmi_empty_string) 29479da4721SParag Warudkar continue; 29579da4721SParag Warudkar 2962e0c1f6cSShem Multinymous dev = dmi_alloc(sizeof(*dev)); 297ae797449SJean Delvare if (!dev) 2982e0c1f6cSShem Multinymous break; 2992e0c1f6cSShem Multinymous 3002e0c1f6cSShem Multinymous dev->type = DMI_DEV_TYPE_OEM_STRING; 30179da4721SParag Warudkar dev->name = devname; 3022e0c1f6cSShem Multinymous dev->device_data = NULL; 3034f705ae3SBjorn Helgaas 3044f705ae3SBjorn Helgaas list_add(&dev->list, &dmi_devices); 3054f705ae3SBjorn Helgaas } 3064f705ae3SBjorn Helgaas } 3074f705ae3SBjorn Helgaas 3081855256cSJeff Garzik static void __init dmi_save_ipmi_device(const struct dmi_header *dm) 3094f705ae3SBjorn Helgaas { 3104f705ae3SBjorn Helgaas struct dmi_device *dev; 3114f705ae3SBjorn Helgaas void *data; 3124f705ae3SBjorn Helgaas 3134f705ae3SBjorn Helgaas data = dmi_alloc(dm->length); 314ae797449SJean Delvare if (data == NULL) 3154f705ae3SBjorn Helgaas return; 3164f705ae3SBjorn Helgaas 3174f705ae3SBjorn Helgaas memcpy(data, dm, dm->length); 3184f705ae3SBjorn Helgaas 3194f705ae3SBjorn Helgaas dev = dmi_alloc(sizeof(*dev)); 320ae797449SJean Delvare if (!dev) 3214f705ae3SBjorn Helgaas return; 3224f705ae3SBjorn Helgaas 3234f705ae3SBjorn Helgaas dev->type = DMI_DEV_TYPE_IPMI; 3244f705ae3SBjorn Helgaas dev->name = "IPMI controller"; 3254f705ae3SBjorn Helgaas dev->device_data = data; 3264f705ae3SBjorn Helgaas 327abd24df8SCarol Hebert list_add_tail(&dev->list, &dmi_devices); 3284f705ae3SBjorn Helgaas } 3294f705ae3SBjorn Helgaas 330e5b6c151SJordan Hargrave static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus, 331e5b6c151SJordan Hargrave int devfn, const char *name, int type) 332911e1c9bSNarendra K { 333e5b6c151SJordan Hargrave struct dmi_dev_onboard *dev; 334911e1c9bSNarendra K 335e5b6c151SJordan Hargrave /* Ignore invalid values */ 336e5b6c151SJordan Hargrave if (type == DMI_DEV_TYPE_DEV_SLOT && 337e5b6c151SJordan Hargrave segment == 0xFFFF && bus == 0xFF && devfn == 0xFF) 338911e1c9bSNarendra K return; 339ae797449SJean Delvare 340e5b6c151SJordan Hargrave dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1); 341e5b6c151SJordan Hargrave if (!dev) 342e5b6c151SJordan Hargrave return; 343911e1c9bSNarendra K 344e5b6c151SJordan Hargrave dev->instance = instance; 345e5b6c151SJordan Hargrave dev->segment = segment; 346e5b6c151SJordan Hargrave dev->bus = bus; 347e5b6c151SJordan Hargrave dev->devfn = devfn; 348911e1c9bSNarendra K 349e5b6c151SJordan Hargrave strcpy((char *)&dev[1], name); 350e5b6c151SJordan Hargrave dev->dev.type = type; 351e5b6c151SJordan Hargrave dev->dev.name = (char *)&dev[1]; 352e5b6c151SJordan Hargrave dev->dev.device_data = dev; 353e5b6c151SJordan Hargrave 354e5b6c151SJordan Hargrave list_add(&dev->dev.list, &dmi_devices); 355911e1c9bSNarendra K } 356911e1c9bSNarendra K 357b4bd7d59SWim Van Sebroeck static void __init dmi_save_extended_devices(const struct dmi_header *dm) 358b4bd7d59SWim Van Sebroeck { 35996e23943SJean Delvare const char *name; 36045b98257SJean Delvare const u8 *d = (u8 *)dm; 361b4bd7d59SWim Van Sebroeck 362*a814c359SJean Delvare if (dm->length < 0x0B) 363*a814c359SJean Delvare return; 364*a814c359SJean Delvare 365b4bd7d59SWim Van Sebroeck /* Skip disabled device */ 36645b98257SJean Delvare if ((d[0x5] & 0x80) == 0) 367b4bd7d59SWim Van Sebroeck return; 368b4bd7d59SWim Van Sebroeck 36945b98257SJean Delvare name = dmi_string_nosave(dm, d[0x4]); 370e5b6c151SJordan Hargrave dmi_save_dev_pciaddr(d[0x6], *(u16 *)(d + 0x7), d[0x9], d[0xA], name, 371e5b6c151SJordan Hargrave DMI_DEV_TYPE_DEV_ONBOARD); 37245b98257SJean Delvare dmi_save_one_device(d[0x5] & 0x7f, name); 373b4bd7d59SWim Van Sebroeck } 374b4bd7d59SWim Van Sebroeck 375e5b6c151SJordan Hargrave static void __init dmi_save_system_slot(const struct dmi_header *dm) 376e5b6c151SJordan Hargrave { 377e5b6c151SJordan Hargrave const u8 *d = (u8 *)dm; 378e5b6c151SJordan Hargrave 379e5b6c151SJordan Hargrave /* Need SMBIOS 2.6+ structure */ 380e5b6c151SJordan Hargrave if (dm->length < 0x11) 381e5b6c151SJordan Hargrave return; 382e5b6c151SJordan Hargrave dmi_save_dev_pciaddr(*(u16 *)(d + 0x9), *(u16 *)(d + 0xD), d[0xF], 383e5b6c151SJordan Hargrave d[0x10], dmi_string_nosave(dm, d[0x4]), 384e5b6c151SJordan Hargrave DMI_DEV_TYPE_DEV_SLOT); 385e5b6c151SJordan Hargrave } 386e5b6c151SJordan Hargrave 387dd6dad42SChen, Gong static void __init count_mem_devices(const struct dmi_header *dm, void *v) 388dd6dad42SChen, Gong { 389dd6dad42SChen, Gong if (dm->type != DMI_ENTRY_MEM_DEVICE) 390dd6dad42SChen, Gong return; 391dd6dad42SChen, Gong dmi_memdev_nr++; 392dd6dad42SChen, Gong } 393dd6dad42SChen, Gong 394dd6dad42SChen, Gong static void __init save_mem_devices(const struct dmi_header *dm, void *v) 395dd6dad42SChen, Gong { 396dd6dad42SChen, Gong const char *d = (const char *)dm; 397dd6dad42SChen, Gong static int nr; 398dd6dad42SChen, Gong 399*a814c359SJean Delvare if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x12) 400dd6dad42SChen, Gong return; 401dd6dad42SChen, Gong if (nr >= dmi_memdev_nr) { 402dd6dad42SChen, Gong pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n"); 403dd6dad42SChen, Gong return; 404dd6dad42SChen, Gong } 4050841c04dSLuck, Tony dmi_memdev[nr].handle = get_unaligned(&dm->handle); 406dd6dad42SChen, Gong dmi_memdev[nr].device = dmi_string(dm, d[0x10]); 407dd6dad42SChen, Gong dmi_memdev[nr].bank = dmi_string(dm, d[0x11]); 408dd6dad42SChen, Gong nr++; 409dd6dad42SChen, Gong } 410dd6dad42SChen, Gong 411dd6dad42SChen, Gong void __init dmi_memdev_walk(void) 412dd6dad42SChen, Gong { 413dd6dad42SChen, Gong if (!dmi_available) 414dd6dad42SChen, Gong return; 415dd6dad42SChen, Gong 416dd6dad42SChen, Gong if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) { 417dd6dad42SChen, Gong dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr); 418dd6dad42SChen, Gong if (dmi_memdev) 419dd6dad42SChen, Gong dmi_walk_early(save_mem_devices); 420dd6dad42SChen, Gong } 421dd6dad42SChen, Gong } 422dd6dad42SChen, Gong 4234f705ae3SBjorn Helgaas /* 4244f705ae3SBjorn Helgaas * Process a DMI table entry. Right now all we care about are the BIOS 4254f705ae3SBjorn Helgaas * and machine entries. For 2.5 we should pull the smbus controller info 4264f705ae3SBjorn Helgaas * out of here. 4274f705ae3SBjorn Helgaas */ 428e7a19c56SJean Delvare static void __init dmi_decode(const struct dmi_header *dm, void *dummy) 4294f705ae3SBjorn Helgaas { 4304f705ae3SBjorn Helgaas switch (dm->type) { 4314f705ae3SBjorn Helgaas case 0: /* BIOS Information */ 4324f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_VENDOR, 4); 4334f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_VERSION, 5); 4344f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_DATE, 8); 4354f705ae3SBjorn Helgaas break; 4364f705ae3SBjorn Helgaas case 1: /* System Information */ 4374f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_SYS_VENDOR, 4); 4384f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_NAME, 5); 4394f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6); 4404f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7); 4414f5c791aSLennart Poettering dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8); 442c61872c9SMika Westerberg dmi_save_ident(dm, DMI_PRODUCT_FAMILY, 26); 4434f705ae3SBjorn Helgaas break; 4444f705ae3SBjorn Helgaas case 2: /* Base Board Information */ 4454f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_VENDOR, 4); 4464f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_NAME, 5); 4474f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_VERSION, 6); 4484f5c791aSLennart Poettering dmi_save_ident(dm, DMI_BOARD_SERIAL, 7); 4494f5c791aSLennart Poettering dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8); 4504f5c791aSLennart Poettering break; 4514f5c791aSLennart Poettering case 3: /* Chassis Information */ 4524f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4); 4534f5c791aSLennart Poettering dmi_save_type(dm, DMI_CHASSIS_TYPE, 5); 4544f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6); 4554f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7); 4564f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8); 4574f705ae3SBjorn Helgaas break; 458e5b6c151SJordan Hargrave case 9: /* System Slots */ 459e5b6c151SJordan Hargrave dmi_save_system_slot(dm); 460e5b6c151SJordan Hargrave break; 4614f705ae3SBjorn Helgaas case 10: /* Onboard Devices Information */ 4624f705ae3SBjorn Helgaas dmi_save_devices(dm); 4634f705ae3SBjorn Helgaas break; 4642e0c1f6cSShem Multinymous case 11: /* OEM Strings */ 4652e0c1f6cSShem Multinymous dmi_save_oem_strings_devices(dm); 4662e0c1f6cSShem Multinymous break; 4674f705ae3SBjorn Helgaas case 38: /* IPMI Device Information */ 4684f705ae3SBjorn Helgaas dmi_save_ipmi_device(dm); 469b4bd7d59SWim Van Sebroeck break; 470b4bd7d59SWim Van Sebroeck case 41: /* Onboard Devices Extended Information */ 471b4bd7d59SWim Van Sebroeck dmi_save_extended_devices(dm); 4724f705ae3SBjorn Helgaas } 4734f705ae3SBjorn Helgaas } 4744f705ae3SBjorn Helgaas 475c90fe6bcSTejun Heo static int __init print_filtered(char *buf, size_t len, const char *info) 4768881cdceSBjorn Helgaas { 477c90fe6bcSTejun Heo int c = 0; 4788881cdceSBjorn Helgaas const char *p; 4798881cdceSBjorn Helgaas 4808881cdceSBjorn Helgaas if (!info) 481c90fe6bcSTejun Heo return c; 4828881cdceSBjorn Helgaas 4838881cdceSBjorn Helgaas for (p = info; *p; p++) 4848881cdceSBjorn Helgaas if (isprint(*p)) 485c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "%c", *p); 4868881cdceSBjorn Helgaas else 487c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff); 488c90fe6bcSTejun Heo return c; 4898881cdceSBjorn Helgaas } 4908881cdceSBjorn Helgaas 491c90fe6bcSTejun Heo static void __init dmi_format_ids(char *buf, size_t len) 4928881cdceSBjorn Helgaas { 493c90fe6bcSTejun Heo int c = 0; 49484e383b3SNaga Chumbalkar const char *board; /* Board Name is optional */ 49584e383b3SNaga Chumbalkar 496c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 497c90fe6bcSTejun Heo dmi_get_system_info(DMI_SYS_VENDOR)); 498c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, " "); 499c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 500c90fe6bcSTejun Heo dmi_get_system_info(DMI_PRODUCT_NAME)); 501c90fe6bcSTejun Heo 50284e383b3SNaga Chumbalkar board = dmi_get_system_info(DMI_BOARD_NAME); 50384e383b3SNaga Chumbalkar if (board) { 504c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "/"); 505c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, board); 50684e383b3SNaga Chumbalkar } 507c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, ", BIOS "); 508c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 509c90fe6bcSTejun Heo dmi_get_system_info(DMI_BIOS_VERSION)); 510c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, " "); 511c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 512c90fe6bcSTejun Heo dmi_get_system_info(DMI_BIOS_DATE)); 5138881cdceSBjorn Helgaas } 5148881cdceSBjorn Helgaas 515d39de28cSBen Hutchings /* 516d39de28cSBen Hutchings * Check for DMI/SMBIOS headers in the system firmware image. Any 517d39de28cSBen Hutchings * SMBIOS header must start 16 bytes before the DMI header, so take a 518d39de28cSBen Hutchings * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset 519d39de28cSBen Hutchings * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS 520d39de28cSBen Hutchings * takes precedence) and return 0. Otherwise return 1. 521d39de28cSBen Hutchings */ 52279bae42dSBen Hutchings static int __init dmi_present(const u8 *buf) 5234f705ae3SBjorn Helgaas { 52495be58dfSIvan Khoronzhuk u32 smbios_ver; 5251855256cSJeff Garzik 52679bae42dSBen Hutchings if (memcmp(buf, "_SM_", 4) == 0 && 52779bae42dSBen Hutchings buf[5] < 32 && dmi_checksum(buf, buf[5])) { 528fc430262SArd Biesheuvel smbios_ver = get_unaligned_be16(buf + 6); 529d7f96f97SIvan Khoronzhuk smbios_entry_point_size = buf[5]; 530d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, smbios_entry_point_size); 53179bae42dSBen Hutchings 53279bae42dSBen Hutchings /* Some BIOS report weird SMBIOS version, fix that up */ 53379bae42dSBen Hutchings switch (smbios_ver) { 53479bae42dSBen Hutchings case 0x021F: 53579bae42dSBen Hutchings case 0x0221: 53679bae42dSBen Hutchings pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 53779bae42dSBen Hutchings smbios_ver & 0xFF, 3); 53879bae42dSBen Hutchings smbios_ver = 0x0203; 53979bae42dSBen Hutchings break; 54079bae42dSBen Hutchings case 0x0233: 54179bae42dSBen Hutchings pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6); 54279bae42dSBen Hutchings smbios_ver = 0x0206; 54379bae42dSBen Hutchings break; 54479bae42dSBen Hutchings } 54579bae42dSBen Hutchings } else { 54679bae42dSBen Hutchings smbios_ver = 0; 54779bae42dSBen Hutchings } 54879bae42dSBen Hutchings 54979bae42dSBen Hutchings buf += 16; 55079bae42dSBen Hutchings 55179bae42dSBen Hutchings if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) { 5525c1ac56bSJean Delvare if (smbios_ver) 5535c1ac56bSJean Delvare dmi_ver = smbios_ver; 5545c1ac56bSJean Delvare else 5555c1ac56bSJean Delvare dmi_ver = (buf[14] & 0xF0) << 4 | (buf[14] & 0x0F); 556ff4319dcSAndrea Arcangeli dmi_ver <<= 8; 557fc430262SArd Biesheuvel dmi_num = get_unaligned_le16(buf + 12); 558fc430262SArd Biesheuvel dmi_len = get_unaligned_le16(buf + 6); 559fc430262SArd Biesheuvel dmi_base = get_unaligned_le32(buf + 8); 5604f705ae3SBjorn Helgaas 5618881cdceSBjorn Helgaas if (dmi_walk_early(dmi_decode) == 0) { 56279bae42dSBen Hutchings if (smbios_ver) { 563c2493045SJean Delvare pr_info("SMBIOS %d.%d present.\n", 564ff4319dcSAndrea Arcangeli dmi_ver >> 16, (dmi_ver >> 8) & 0xFF); 56579bae42dSBen Hutchings } else { 566d7f96f97SIvan Khoronzhuk smbios_entry_point_size = 15; 567d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, 568d7f96f97SIvan Khoronzhuk smbios_entry_point_size); 5699f9c9cbbSZhenzhong Duan pr_info("Legacy DMI %d.%d present.\n", 570ff4319dcSAndrea Arcangeli dmi_ver >> 16, (dmi_ver >> 8) & 0xFF); 5719f9c9cbbSZhenzhong Duan } 572c90fe6bcSTejun Heo dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); 573d4af49f8SKefeng Wang pr_info("DMI: %s\n", dmi_ids_string); 5744f705ae3SBjorn Helgaas return 0; 5754f705ae3SBjorn Helgaas } 5768881cdceSBjorn Helgaas } 5774f705ae3SBjorn Helgaas 578a40e7cf8SBen Hutchings return 1; 5799f9c9cbbSZhenzhong Duan } 5809f9c9cbbSZhenzhong Duan 581fc430262SArd Biesheuvel /* 582fc430262SArd Biesheuvel * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy 583fc430262SArd Biesheuvel * 32-bit entry point, there is no embedded DMI header (_DMI_) in here. 584fc430262SArd Biesheuvel */ 585fc430262SArd Biesheuvel static int __init dmi_smbios3_present(const u8 *buf) 586fc430262SArd Biesheuvel { 587fc430262SArd Biesheuvel if (memcmp(buf, "_SM3_", 5) == 0 && 588fc430262SArd Biesheuvel buf[6] < 32 && dmi_checksum(buf, buf[6])) { 589d1d8704cSJean Delvare dmi_ver = get_unaligned_be32(buf + 6) & 0xFFFFFF; 590bfbaafaeSJean Delvare dmi_num = 0; /* No longer specified */ 591fc430262SArd Biesheuvel dmi_len = get_unaligned_le32(buf + 12); 592fc430262SArd Biesheuvel dmi_base = get_unaligned_le64(buf + 16); 593d7f96f97SIvan Khoronzhuk smbios_entry_point_size = buf[6]; 594d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, smbios_entry_point_size); 595fc430262SArd Biesheuvel 596fc430262SArd Biesheuvel if (dmi_walk_early(dmi_decode) == 0) { 59795be58dfSIvan Khoronzhuk pr_info("SMBIOS %d.%d.%d present.\n", 59895be58dfSIvan Khoronzhuk dmi_ver >> 16, (dmi_ver >> 8) & 0xFF, 59995be58dfSIvan Khoronzhuk dmi_ver & 0xFF); 600fc430262SArd Biesheuvel dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); 601d4af49f8SKefeng Wang pr_info("DMI: %s\n", dmi_ids_string); 602fc430262SArd Biesheuvel return 0; 603fc430262SArd Biesheuvel } 604fc430262SArd Biesheuvel } 605fc430262SArd Biesheuvel return 1; 606fc430262SArd Biesheuvel } 607fc430262SArd Biesheuvel 6084f705ae3SBjorn Helgaas void __init dmi_scan_machine(void) 6094f705ae3SBjorn Helgaas { 6104f705ae3SBjorn Helgaas char __iomem *p, *q; 61179bae42dSBen Hutchings char buf[32]; 6124f705ae3SBjorn Helgaas 61383e68189SMatt Fleming if (efi_enabled(EFI_CONFIG_TABLES)) { 614fc430262SArd Biesheuvel /* 615fc430262SArd Biesheuvel * According to the DMTF SMBIOS reference spec v3.0.0, it is 616fc430262SArd Biesheuvel * allowed to define both the 64-bit entry point (smbios3) and 617fc430262SArd Biesheuvel * the 32-bit entry point (smbios), in which case they should 618fc430262SArd Biesheuvel * either both point to the same SMBIOS structure table, or the 619fc430262SArd Biesheuvel * table pointed to by the 64-bit entry point should contain a 620fc430262SArd Biesheuvel * superset of the table contents pointed to by the 32-bit entry 621fc430262SArd Biesheuvel * point (section 5.2) 622fc430262SArd Biesheuvel * This implies that the 64-bit entry point should have 623fc430262SArd Biesheuvel * precedence if it is defined and supported by the OS. If we 624fc430262SArd Biesheuvel * have the 64-bit entry point, but fail to decode it, fall 625fc430262SArd Biesheuvel * back to the legacy one (if available) 626fc430262SArd Biesheuvel */ 627fc430262SArd Biesheuvel if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) { 628fc430262SArd Biesheuvel p = dmi_early_remap(efi.smbios3, 32); 629fc430262SArd Biesheuvel if (p == NULL) 630fc430262SArd Biesheuvel goto error; 631fc430262SArd Biesheuvel memcpy_fromio(buf, p, 32); 632fc430262SArd Biesheuvel dmi_early_unmap(p, 32); 633fc430262SArd Biesheuvel 634fc430262SArd Biesheuvel if (!dmi_smbios3_present(buf)) { 635fc430262SArd Biesheuvel dmi_available = 1; 636fc430262SArd Biesheuvel goto out; 637fc430262SArd Biesheuvel } 638fc430262SArd Biesheuvel } 6394f705ae3SBjorn Helgaas if (efi.smbios == EFI_INVALID_TABLE_ADDR) 6409a22b6e7SIngo Molnar goto error; 6414f705ae3SBjorn Helgaas 6424f705ae3SBjorn Helgaas /* This is called as a core_initcall() because it isn't 6434f705ae3SBjorn Helgaas * needed during early boot. This also means we can 6444f705ae3SBjorn Helgaas * iounmap the space when we're done with it. 6454f705ae3SBjorn Helgaas */ 646cf074402SArd Biesheuvel p = dmi_early_remap(efi.smbios, 32); 6474f705ae3SBjorn Helgaas if (p == NULL) 6489a22b6e7SIngo Molnar goto error; 64979bae42dSBen Hutchings memcpy_fromio(buf, p, 32); 650cf074402SArd Biesheuvel dmi_early_unmap(p, 32); 65179bae42dSBen Hutchings 65279bae42dSBen Hutchings if (!dmi_present(buf)) { 6534f5c791aSLennart Poettering dmi_available = 1; 6549a22b6e7SIngo Molnar goto out; 6554f705ae3SBjorn Helgaas } 656cf074402SArd Biesheuvel } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) { 657cf074402SArd Biesheuvel p = dmi_early_remap(0xF0000, 0x10000); 6584f705ae3SBjorn Helgaas if (p == NULL) 6599a22b6e7SIngo Molnar goto error; 6604f705ae3SBjorn Helgaas 661d39de28cSBen Hutchings /* 662c9aba143SJean Delvare * Same logic as above, look for a 64-bit entry point 663c9aba143SJean Delvare * first, and if not found, fall back to 32-bit entry point. 664c9aba143SJean Delvare */ 665c9aba143SJean Delvare memcpy_fromio(buf, p, 16); 666c9aba143SJean Delvare for (q = p + 16; q < p + 0x10000; q += 16) { 667c9aba143SJean Delvare memcpy_fromio(buf + 16, q, 16); 668c9aba143SJean Delvare if (!dmi_smbios3_present(buf)) { 669c9aba143SJean Delvare dmi_available = 1; 670c9aba143SJean Delvare dmi_early_unmap(p, 0x10000); 671c9aba143SJean Delvare goto out; 672c9aba143SJean Delvare } 673c9aba143SJean Delvare memcpy(buf, buf + 16, 16); 674c9aba143SJean Delvare } 675c9aba143SJean Delvare 676c9aba143SJean Delvare /* 677d39de28cSBen Hutchings * Iterate over all possible DMI header addresses q. 678d39de28cSBen Hutchings * Maintain the 32 bytes around q in buf. On the 679d39de28cSBen Hutchings * first iteration, substitute zero for the 680d39de28cSBen Hutchings * out-of-range bytes so there is no chance of falsely 681d39de28cSBen Hutchings * detecting an SMBIOS header. 682d39de28cSBen Hutchings */ 68379bae42dSBen Hutchings memset(buf, 0, 16); 6844f705ae3SBjorn Helgaas for (q = p; q < p + 0x10000; q += 16) { 68579bae42dSBen Hutchings memcpy_fromio(buf + 16, q, 16); 686c9aba143SJean Delvare if (!dmi_present(buf)) { 6874f5c791aSLennart Poettering dmi_available = 1; 688cf074402SArd Biesheuvel dmi_early_unmap(p, 0x10000); 6899a22b6e7SIngo Molnar goto out; 6904f705ae3SBjorn Helgaas } 69179bae42dSBen Hutchings memcpy(buf, buf + 16, 16); 6924f705ae3SBjorn Helgaas } 693cf074402SArd Biesheuvel dmi_early_unmap(p, 0x10000); 6944f5c791aSLennart Poettering } 6959a22b6e7SIngo Molnar error: 69602d9c47fSJean Delvare pr_info("DMI not present or invalid.\n"); 6979a22b6e7SIngo Molnar out: 6989a22b6e7SIngo Molnar dmi_initialized = 1; 6994f705ae3SBjorn Helgaas } 7004f705ae3SBjorn Helgaas 701d7f96f97SIvan Khoronzhuk static ssize_t raw_table_read(struct file *file, struct kobject *kobj, 702d7f96f97SIvan Khoronzhuk struct bin_attribute *attr, char *buf, 703d7f96f97SIvan Khoronzhuk loff_t pos, size_t count) 704d7f96f97SIvan Khoronzhuk { 705d7f96f97SIvan Khoronzhuk memcpy(buf, attr->private + pos, count); 706d7f96f97SIvan Khoronzhuk return count; 707d7f96f97SIvan Khoronzhuk } 708d7f96f97SIvan Khoronzhuk 709d7f96f97SIvan Khoronzhuk static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0); 710d7f96f97SIvan Khoronzhuk static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0); 711d7f96f97SIvan Khoronzhuk 712d7f96f97SIvan Khoronzhuk static int __init dmi_init(void) 713d7f96f97SIvan Khoronzhuk { 714d7f96f97SIvan Khoronzhuk struct kobject *tables_kobj; 715d7f96f97SIvan Khoronzhuk u8 *dmi_table; 716d7f96f97SIvan Khoronzhuk int ret = -ENOMEM; 717d7f96f97SIvan Khoronzhuk 718d7f96f97SIvan Khoronzhuk if (!dmi_available) { 719d7f96f97SIvan Khoronzhuk ret = -ENODATA; 720d7f96f97SIvan Khoronzhuk goto err; 721d7f96f97SIvan Khoronzhuk } 722d7f96f97SIvan Khoronzhuk 723d7f96f97SIvan Khoronzhuk /* 724d7f96f97SIvan Khoronzhuk * Set up dmi directory at /sys/firmware/dmi. This entry should stay 725d7f96f97SIvan Khoronzhuk * even after farther error, as it can be used by other modules like 726d7f96f97SIvan Khoronzhuk * dmi-sysfs. 727d7f96f97SIvan Khoronzhuk */ 728d7f96f97SIvan Khoronzhuk dmi_kobj = kobject_create_and_add("dmi", firmware_kobj); 729d7f96f97SIvan Khoronzhuk if (!dmi_kobj) 730d7f96f97SIvan Khoronzhuk goto err; 731d7f96f97SIvan Khoronzhuk 732d7f96f97SIvan Khoronzhuk tables_kobj = kobject_create_and_add("tables", dmi_kobj); 733d7f96f97SIvan Khoronzhuk if (!tables_kobj) 734d7f96f97SIvan Khoronzhuk goto err; 735d7f96f97SIvan Khoronzhuk 736d7f96f97SIvan Khoronzhuk dmi_table = dmi_remap(dmi_base, dmi_len); 737d7f96f97SIvan Khoronzhuk if (!dmi_table) 738d7f96f97SIvan Khoronzhuk goto err_tables; 739d7f96f97SIvan Khoronzhuk 740d7f96f97SIvan Khoronzhuk bin_attr_smbios_entry_point.size = smbios_entry_point_size; 741d7f96f97SIvan Khoronzhuk bin_attr_smbios_entry_point.private = smbios_entry_point; 742d7f96f97SIvan Khoronzhuk ret = sysfs_create_bin_file(tables_kobj, &bin_attr_smbios_entry_point); 743d7f96f97SIvan Khoronzhuk if (ret) 744d7f96f97SIvan Khoronzhuk goto err_unmap; 745d7f96f97SIvan Khoronzhuk 746d7f96f97SIvan Khoronzhuk bin_attr_DMI.size = dmi_len; 747d7f96f97SIvan Khoronzhuk bin_attr_DMI.private = dmi_table; 748d7f96f97SIvan Khoronzhuk ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI); 749d7f96f97SIvan Khoronzhuk if (!ret) 750d7f96f97SIvan Khoronzhuk return 0; 751d7f96f97SIvan Khoronzhuk 752d7f96f97SIvan Khoronzhuk sysfs_remove_bin_file(tables_kobj, 753d7f96f97SIvan Khoronzhuk &bin_attr_smbios_entry_point); 754d7f96f97SIvan Khoronzhuk err_unmap: 755d7f96f97SIvan Khoronzhuk dmi_unmap(dmi_table); 756d7f96f97SIvan Khoronzhuk err_tables: 757d7f96f97SIvan Khoronzhuk kobject_del(tables_kobj); 758d7f96f97SIvan Khoronzhuk kobject_put(tables_kobj); 759d7f96f97SIvan Khoronzhuk err: 760d7f96f97SIvan Khoronzhuk pr_err("dmi: Firmware registration failed.\n"); 761d7f96f97SIvan Khoronzhuk 762d7f96f97SIvan Khoronzhuk return ret; 763d7f96f97SIvan Khoronzhuk } 764d7f96f97SIvan Khoronzhuk subsys_initcall(dmi_init); 765d7f96f97SIvan Khoronzhuk 7664f705ae3SBjorn Helgaas /** 76798e5e1bfSTejun Heo * dmi_set_dump_stack_arch_desc - set arch description for dump_stack() 76898e5e1bfSTejun Heo * 76998e5e1bfSTejun Heo * Invoke dump_stack_set_arch_desc() with DMI system information so that 77098e5e1bfSTejun Heo * DMI identifiers are printed out on task dumps. Arch boot code should 77198e5e1bfSTejun Heo * call this function after dmi_scan_machine() if it wants to print out DMI 77298e5e1bfSTejun Heo * identifiers on task dumps. 77398e5e1bfSTejun Heo */ 77498e5e1bfSTejun Heo void __init dmi_set_dump_stack_arch_desc(void) 77598e5e1bfSTejun Heo { 77698e5e1bfSTejun Heo dump_stack_set_arch_desc("%s", dmi_ids_string); 77798e5e1bfSTejun Heo } 77898e5e1bfSTejun Heo 77998e5e1bfSTejun Heo /** 780d7b1956fSRafael J. Wysocki * dmi_matches - check if dmi_system_id structure matches system DMI data 781d7b1956fSRafael J. Wysocki * @dmi: pointer to the dmi_system_id structure to check 782d7b1956fSRafael J. Wysocki */ 783d7b1956fSRafael J. Wysocki static bool dmi_matches(const struct dmi_system_id *dmi) 784d7b1956fSRafael J. Wysocki { 785d7b1956fSRafael J. Wysocki int i; 786d7b1956fSRafael J. Wysocki 787d7b1956fSRafael J. Wysocki WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n"); 788d7b1956fSRafael J. Wysocki 789d7b1956fSRafael J. Wysocki for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) { 790d7b1956fSRafael J. Wysocki int s = dmi->matches[i].slot; 791d7b1956fSRafael J. Wysocki if (s == DMI_NONE) 79275757507SDmitry Torokhov break; 7935017b285SJani Nikula if (dmi_ident[s]) { 7945017b285SJani Nikula if (!dmi->matches[i].exact_match && 7955017b285SJani Nikula strstr(dmi_ident[s], dmi->matches[i].substr)) 796d7b1956fSRafael J. Wysocki continue; 7975017b285SJani Nikula else if (dmi->matches[i].exact_match && 7985017b285SJani Nikula !strcmp(dmi_ident[s], dmi->matches[i].substr)) 7995017b285SJani Nikula continue; 8005017b285SJani Nikula } 8015017b285SJani Nikula 802d7b1956fSRafael J. Wysocki /* No match */ 803d7b1956fSRafael J. Wysocki return false; 804d7b1956fSRafael J. Wysocki } 805d7b1956fSRafael J. Wysocki return true; 806d7b1956fSRafael J. Wysocki } 807d7b1956fSRafael J. Wysocki 808d7b1956fSRafael J. Wysocki /** 80975757507SDmitry Torokhov * dmi_is_end_of_table - check for end-of-table marker 81075757507SDmitry Torokhov * @dmi: pointer to the dmi_system_id structure to check 81175757507SDmitry Torokhov */ 81275757507SDmitry Torokhov static bool dmi_is_end_of_table(const struct dmi_system_id *dmi) 81375757507SDmitry Torokhov { 81475757507SDmitry Torokhov return dmi->matches[0].slot == DMI_NONE; 81575757507SDmitry Torokhov } 81675757507SDmitry Torokhov 81775757507SDmitry Torokhov /** 8184f705ae3SBjorn Helgaas * dmi_check_system - check system DMI data 8194f705ae3SBjorn Helgaas * @list: array of dmi_system_id structures to match against 820b0ef371eSRandy Dunlap * All non-null elements of the list must match 821b0ef371eSRandy Dunlap * their slot's (field index's) data (i.e., each 822b0ef371eSRandy Dunlap * list string must be a substring of the specified 823b0ef371eSRandy Dunlap * DMI slot's string data) to be considered a 824b0ef371eSRandy Dunlap * successful match. 8254f705ae3SBjorn Helgaas * 8264f705ae3SBjorn Helgaas * Walk the blacklist table running matching functions until someone 8274f705ae3SBjorn Helgaas * returns non zero or we hit the end. Callback function is called for 828b0ef371eSRandy Dunlap * each successful match. Returns the number of matches. 8294f705ae3SBjorn Helgaas */ 8301855256cSJeff Garzik int dmi_check_system(const struct dmi_system_id *list) 8314f705ae3SBjorn Helgaas { 832d7b1956fSRafael J. Wysocki int count = 0; 833d7b1956fSRafael J. Wysocki const struct dmi_system_id *d; 8344f705ae3SBjorn Helgaas 83575757507SDmitry Torokhov for (d = list; !dmi_is_end_of_table(d); d++) 836d7b1956fSRafael J. Wysocki if (dmi_matches(d)) { 8374f705ae3SBjorn Helgaas count++; 8384f705ae3SBjorn Helgaas if (d->callback && d->callback(d)) 8394f705ae3SBjorn Helgaas break; 8404f705ae3SBjorn Helgaas } 8414f705ae3SBjorn Helgaas 8424f705ae3SBjorn Helgaas return count; 8434f705ae3SBjorn Helgaas } 8444f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_check_system); 8454f705ae3SBjorn Helgaas 8464f705ae3SBjorn Helgaas /** 847d7b1956fSRafael J. Wysocki * dmi_first_match - find dmi_system_id structure matching system DMI data 848d7b1956fSRafael J. Wysocki * @list: array of dmi_system_id structures to match against 849d7b1956fSRafael J. Wysocki * All non-null elements of the list must match 850d7b1956fSRafael J. Wysocki * their slot's (field index's) data (i.e., each 851d7b1956fSRafael J. Wysocki * list string must be a substring of the specified 852d7b1956fSRafael J. Wysocki * DMI slot's string data) to be considered a 853d7b1956fSRafael J. Wysocki * successful match. 854d7b1956fSRafael J. Wysocki * 855d7b1956fSRafael J. Wysocki * Walk the blacklist table until the first match is found. Return the 856d7b1956fSRafael J. Wysocki * pointer to the matching entry or NULL if there's no match. 857d7b1956fSRafael J. Wysocki */ 858d7b1956fSRafael J. Wysocki const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list) 859d7b1956fSRafael J. Wysocki { 860d7b1956fSRafael J. Wysocki const struct dmi_system_id *d; 861d7b1956fSRafael J. Wysocki 86275757507SDmitry Torokhov for (d = list; !dmi_is_end_of_table(d); d++) 863d7b1956fSRafael J. Wysocki if (dmi_matches(d)) 864d7b1956fSRafael J. Wysocki return d; 865d7b1956fSRafael J. Wysocki 866d7b1956fSRafael J. Wysocki return NULL; 867d7b1956fSRafael J. Wysocki } 868d7b1956fSRafael J. Wysocki EXPORT_SYMBOL(dmi_first_match); 869d7b1956fSRafael J. Wysocki 870d7b1956fSRafael J. Wysocki /** 8714f705ae3SBjorn Helgaas * dmi_get_system_info - return DMI data value 872b0ef371eSRandy Dunlap * @field: data index (see enum dmi_field) 8734f705ae3SBjorn Helgaas * 8744f705ae3SBjorn Helgaas * Returns one DMI data value, can be used to perform 8754f705ae3SBjorn Helgaas * complex DMI data checks. 8764f705ae3SBjorn Helgaas */ 8771855256cSJeff Garzik const char *dmi_get_system_info(int field) 8784f705ae3SBjorn Helgaas { 8794f705ae3SBjorn Helgaas return dmi_ident[field]; 8804f705ae3SBjorn Helgaas } 8814f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_get_system_info); 8824f705ae3SBjorn Helgaas 883fd8cd7e1SAlok Kataria /** 884c2bacfc4SRandy Dunlap * dmi_name_in_serial - Check if string is in the DMI product serial information 885c2bacfc4SRandy Dunlap * @str: string to check for 886fd8cd7e1SAlok Kataria */ 887fd8cd7e1SAlok Kataria int dmi_name_in_serial(const char *str) 888fd8cd7e1SAlok Kataria { 889fd8cd7e1SAlok Kataria int f = DMI_PRODUCT_SERIAL; 890fd8cd7e1SAlok Kataria if (dmi_ident[f] && strstr(dmi_ident[f], str)) 891fd8cd7e1SAlok Kataria return 1; 892fd8cd7e1SAlok Kataria return 0; 893fd8cd7e1SAlok Kataria } 894a1bae672SAndi Kleen 895a1bae672SAndi Kleen /** 89666e13e66SJean Delvare * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name 897a1bae672SAndi Kleen * @str: Case sensitive Name 898a1bae672SAndi Kleen */ 8991855256cSJeff Garzik int dmi_name_in_vendors(const char *str) 900a1bae672SAndi Kleen { 90166e13e66SJean Delvare static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE }; 902a1bae672SAndi Kleen int i; 903a1bae672SAndi Kleen for (i = 0; fields[i] != DMI_NONE; i++) { 904a1bae672SAndi Kleen int f = fields[i]; 905a1bae672SAndi Kleen if (dmi_ident[f] && strstr(dmi_ident[f], str)) 906a1bae672SAndi Kleen return 1; 907a1bae672SAndi Kleen } 908a1bae672SAndi Kleen return 0; 909a1bae672SAndi Kleen } 910a1bae672SAndi Kleen EXPORT_SYMBOL(dmi_name_in_vendors); 911a1bae672SAndi Kleen 9124f705ae3SBjorn Helgaas /** 9134f705ae3SBjorn Helgaas * dmi_find_device - find onboard device by type/name 9144f705ae3SBjorn Helgaas * @type: device type or %DMI_DEV_TYPE_ANY to match all device types 915b0ef371eSRandy Dunlap * @name: device name string or %NULL to match all 9164f705ae3SBjorn Helgaas * @from: previous device found in search, or %NULL for new search. 9174f705ae3SBjorn Helgaas * 9184f705ae3SBjorn Helgaas * Iterates through the list of known onboard devices. If a device is 919bfab8b48SJean Delvare * found with a matching @type and @name, a pointer to its device 9204f705ae3SBjorn Helgaas * structure is returned. Otherwise, %NULL is returned. 921b0ef371eSRandy Dunlap * A new search is initiated by passing %NULL as the @from argument. 9224f705ae3SBjorn Helgaas * If @from is not %NULL, searches continue from next device. 9234f705ae3SBjorn Helgaas */ 9241855256cSJeff Garzik const struct dmi_device *dmi_find_device(int type, const char *name, 9251855256cSJeff Garzik const struct dmi_device *from) 9264f705ae3SBjorn Helgaas { 9271855256cSJeff Garzik const struct list_head *head = from ? &from->list : &dmi_devices; 9281855256cSJeff Garzik struct list_head *d; 9294f705ae3SBjorn Helgaas 9304f705ae3SBjorn Helgaas for (d = head->next; d != &dmi_devices; d = d->next) { 9311855256cSJeff Garzik const struct dmi_device *dev = 9321855256cSJeff Garzik list_entry(d, struct dmi_device, list); 9334f705ae3SBjorn Helgaas 9344f705ae3SBjorn Helgaas if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) && 9354f705ae3SBjorn Helgaas ((name == NULL) || (strcmp(dev->name, name) == 0))) 9364f705ae3SBjorn Helgaas return dev; 9374f705ae3SBjorn Helgaas } 9384f705ae3SBjorn Helgaas 9394f705ae3SBjorn Helgaas return NULL; 9404f705ae3SBjorn Helgaas } 9414f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_find_device); 9424f705ae3SBjorn Helgaas 9434f705ae3SBjorn Helgaas /** 9443e5cd1f2STejun Heo * dmi_get_date - parse a DMI date 9453e5cd1f2STejun Heo * @field: data index (see enum dmi_field) 9463e5cd1f2STejun Heo * @yearp: optional out parameter for the year 9473e5cd1f2STejun Heo * @monthp: optional out parameter for the month 9483e5cd1f2STejun Heo * @dayp: optional out parameter for the day 9494f705ae3SBjorn Helgaas * 9503e5cd1f2STejun Heo * The date field is assumed to be in the form resembling 9513e5cd1f2STejun Heo * [mm[/dd]]/yy[yy] and the result is stored in the out 9523e5cd1f2STejun Heo * parameters any or all of which can be omitted. 9533e5cd1f2STejun Heo * 9543e5cd1f2STejun Heo * If the field doesn't exist, all out parameters are set to zero 9553e5cd1f2STejun Heo * and false is returned. Otherwise, true is returned with any 9563e5cd1f2STejun Heo * invalid part of date set to zero. 9573e5cd1f2STejun Heo * 9583e5cd1f2STejun Heo * On return, year, month and day are guaranteed to be in the 9593e5cd1f2STejun Heo * range of [0,9999], [0,12] and [0,31] respectively. 9604f705ae3SBjorn Helgaas */ 9613e5cd1f2STejun Heo bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp) 9624f705ae3SBjorn Helgaas { 9633e5cd1f2STejun Heo int year = 0, month = 0, day = 0; 9643e5cd1f2STejun Heo bool exists; 9653e5cd1f2STejun Heo const char *s, *y; 96602c24fa8STejun Heo char *e; 9674f705ae3SBjorn Helgaas 9683e5cd1f2STejun Heo s = dmi_get_system_info(field); 9693e5cd1f2STejun Heo exists = s; 9703e5cd1f2STejun Heo if (!exists) 9713e5cd1f2STejun Heo goto out; 9724f705ae3SBjorn Helgaas 9733e5cd1f2STejun Heo /* 9743e5cd1f2STejun Heo * Determine year first. We assume the date string resembles 9753e5cd1f2STejun Heo * mm/dd/yy[yy] but the original code extracted only the year 9763e5cd1f2STejun Heo * from the end. Keep the behavior in the spirit of no 9773e5cd1f2STejun Heo * surprises. 9783e5cd1f2STejun Heo */ 9793e5cd1f2STejun Heo y = strrchr(s, '/'); 9803e5cd1f2STejun Heo if (!y) 9813e5cd1f2STejun Heo goto out; 9823e5cd1f2STejun Heo 9833e5cd1f2STejun Heo y++; 9843e5cd1f2STejun Heo year = simple_strtoul(y, &e, 10); 9853e5cd1f2STejun Heo if (y != e && year < 100) { /* 2-digit year */ 9864f705ae3SBjorn Helgaas year += 1900; 9874f705ae3SBjorn Helgaas if (year < 1996) /* no dates < spec 1.0 */ 9884f705ae3SBjorn Helgaas year += 100; 9894f705ae3SBjorn Helgaas } 9903e5cd1f2STejun Heo if (year > 9999) /* year should fit in %04d */ 9913e5cd1f2STejun Heo year = 0; 9924f705ae3SBjorn Helgaas 9933e5cd1f2STejun Heo /* parse the mm and dd */ 9943e5cd1f2STejun Heo month = simple_strtoul(s, &e, 10); 9953e5cd1f2STejun Heo if (s == e || *e != '/' || !month || month > 12) { 9963e5cd1f2STejun Heo month = 0; 9973e5cd1f2STejun Heo goto out; 9984f705ae3SBjorn Helgaas } 9993e5cd1f2STejun Heo 10003e5cd1f2STejun Heo s = e + 1; 10013e5cd1f2STejun Heo day = simple_strtoul(s, &e, 10); 10023e5cd1f2STejun Heo if (s == y || s == e || *e != '/' || day > 31) 10033e5cd1f2STejun Heo day = 0; 10043e5cd1f2STejun Heo out: 10053e5cd1f2STejun Heo if (yearp) 10063e5cd1f2STejun Heo *yearp = year; 10073e5cd1f2STejun Heo if (monthp) 10083e5cd1f2STejun Heo *monthp = month; 10093e5cd1f2STejun Heo if (dayp) 10103e5cd1f2STejun Heo *dayp = day; 10113e5cd1f2STejun Heo return exists; 10123e5cd1f2STejun Heo } 10133e5cd1f2STejun Heo EXPORT_SYMBOL(dmi_get_date); 10147fce084aSJean Delvare 10157fce084aSJean Delvare /** 10167fce084aSJean Delvare * dmi_walk - Walk the DMI table and get called back for every record 10177fce084aSJean Delvare * @decode: Callback function 1018e7a19c56SJean Delvare * @private_data: Private data to be passed to the callback function 10197fce084aSJean Delvare * 1020c9268200SAndy Lutomirski * Returns 0 on success, -ENXIO if DMI is not selected or not present, 1021c9268200SAndy Lutomirski * or a different negative error code if DMI walking fails. 10227fce084aSJean Delvare */ 1023e7a19c56SJean Delvare int dmi_walk(void (*decode)(const struct dmi_header *, void *), 1024e7a19c56SJean Delvare void *private_data) 10257fce084aSJean Delvare { 10267fce084aSJean Delvare u8 *buf; 10277fce084aSJean Delvare 10287fce084aSJean Delvare if (!dmi_available) 1029c9268200SAndy Lutomirski return -ENXIO; 10307fce084aSJean Delvare 1031cf074402SArd Biesheuvel buf = dmi_remap(dmi_base, dmi_len); 10327fce084aSJean Delvare if (buf == NULL) 1033c9268200SAndy Lutomirski return -ENOMEM; 10347fce084aSJean Delvare 1035eb4c5ea5SIvan Khoronzhuk dmi_decode_table(buf, decode, private_data); 10367fce084aSJean Delvare 1037cf074402SArd Biesheuvel dmi_unmap(buf); 10387fce084aSJean Delvare return 0; 10397fce084aSJean Delvare } 10407fce084aSJean Delvare EXPORT_SYMBOL_GPL(dmi_walk); 1041d61c72e5SJiri Slaby 1042d61c72e5SJiri Slaby /** 1043d61c72e5SJiri Slaby * dmi_match - compare a string to the dmi field (if exists) 1044c2bacfc4SRandy Dunlap * @f: DMI field identifier 1045c2bacfc4SRandy Dunlap * @str: string to compare the DMI field to 1046d61c72e5SJiri Slaby * 1047d61c72e5SJiri Slaby * Returns true if the requested field equals to the str (including NULL). 1048d61c72e5SJiri Slaby */ 1049d61c72e5SJiri Slaby bool dmi_match(enum dmi_field f, const char *str) 1050d61c72e5SJiri Slaby { 1051d61c72e5SJiri Slaby const char *info = dmi_get_system_info(f); 1052d61c72e5SJiri Slaby 1053d61c72e5SJiri Slaby if (info == NULL || str == NULL) 1054d61c72e5SJiri Slaby return info == str; 1055d61c72e5SJiri Slaby 1056d61c72e5SJiri Slaby return !strcmp(info, str); 1057d61c72e5SJiri Slaby } 1058d61c72e5SJiri Slaby EXPORT_SYMBOL_GPL(dmi_match); 1059dd6dad42SChen, Gong 1060dd6dad42SChen, Gong void dmi_memdev_name(u16 handle, const char **bank, const char **device) 1061dd6dad42SChen, Gong { 1062dd6dad42SChen, Gong int n; 1063dd6dad42SChen, Gong 1064dd6dad42SChen, Gong if (dmi_memdev == NULL) 1065dd6dad42SChen, Gong return; 1066dd6dad42SChen, Gong 1067dd6dad42SChen, Gong for (n = 0; n < dmi_memdev_nr; n++) { 1068dd6dad42SChen, Gong if (handle == dmi_memdev[n].handle) { 1069dd6dad42SChen, Gong *bank = dmi_memdev[n].bank; 1070dd6dad42SChen, Gong *device = dmi_memdev[n].device; 1071dd6dad42SChen, Gong break; 1072dd6dad42SChen, Gong } 1073dd6dad42SChen, Gong } 1074dd6dad42SChen, Gong } 1075dd6dad42SChen, Gong EXPORT_SYMBOL_GPL(dmi_memdev_name); 1076