1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 24f705ae3SBjorn Helgaas #include <linux/types.h> 34f705ae3SBjorn Helgaas #include <linux/string.h> 44f705ae3SBjorn Helgaas #include <linux/init.h> 54f705ae3SBjorn Helgaas #include <linux/module.h> 68881cdceSBjorn Helgaas #include <linux/ctype.h> 74f705ae3SBjorn Helgaas #include <linux/dmi.h> 84f705ae3SBjorn Helgaas #include <linux/efi.h> 957c8a661SMike Rapoport #include <linux/memblock.h> 10d114a333STony Luck #include <linux/random.h> 114f705ae3SBjorn Helgaas #include <asm/dmi.h> 120841c04dSLuck, Tony #include <asm/unaligned.h> 134f705ae3SBjorn Helgaas 143da27a4eSTiezhu Yang #ifndef SMBIOS_ENTRY_POINT_SCAN_START 153da27a4eSTiezhu Yang #define SMBIOS_ENTRY_POINT_SCAN_START 0xF0000 163da27a4eSTiezhu Yang #endif 173da27a4eSTiezhu Yang 18d7f96f97SIvan Khoronzhuk struct kobject *dmi_kobj; 19d7f96f97SIvan Khoronzhuk EXPORT_SYMBOL_GPL(dmi_kobj); 20d7f96f97SIvan Khoronzhuk 21cb5dd7c1SPaul Jackson /* 22cb5dd7c1SPaul Jackson * DMI stands for "Desktop Management Interface". It is part 23cb5dd7c1SPaul Jackson * of and an antecedent to, SMBIOS, which stands for System 24a3d13a0aSAlexander A. Klimov * Management BIOS. See further: https://www.dmtf.org/standards 25cb5dd7c1SPaul Jackson */ 26ffbbb96dSJean Delvare static const char dmi_empty_string[] = ""; 2779da4721SParag Warudkar 2895be58dfSIvan Khoronzhuk static u32 dmi_ver __initdata; 29552e19d8SIvan Khoronzhuk static u32 dmi_len; 30552e19d8SIvan Khoronzhuk static u16 dmi_num; 31d7f96f97SIvan Khoronzhuk static u8 smbios_entry_point[32]; 32d7f96f97SIvan Khoronzhuk static int smbios_entry_point_size; 33d7f96f97SIvan Khoronzhuk 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; 406deae96bSTony Luck u64 size; /* bytes */ 41dd6dad42SChen, Gong u16 handle; 429e0afe39SJean Delvare u8 type; /* DDR2, DDR3, DDR4 etc */ 43dd6dad42SChen, Gong } *dmi_memdev; 44dd6dad42SChen, Gong static int dmi_memdev_nr; 45dd6dad42SChen, Gong 46f3069ae9SJean Delvare static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s) 474f705ae3SBjorn Helgaas { 481855256cSJeff Garzik const u8 *bp = ((u8 *) dm) + dm->length; 49a7770ae1SJean Delvare const u8 *nsp; 504f705ae3SBjorn Helgaas 514f705ae3SBjorn Helgaas if (s) { 52a7770ae1SJean Delvare while (--s > 0 && *bp) 534f705ae3SBjorn Helgaas bp += strlen(bp) + 1; 544f705ae3SBjorn Helgaas 55a7770ae1SJean Delvare /* Strings containing only spaces are considered empty */ 56a7770ae1SJean Delvare nsp = bp; 57a7770ae1SJean Delvare while (*nsp == ' ') 58a7770ae1SJean Delvare nsp++; 59a7770ae1SJean Delvare if (*nsp != '\0') 60f3069ae9SJean Delvare return bp; 61f3069ae9SJean Delvare } 62f3069ae9SJean Delvare 63a7770ae1SJean Delvare return dmi_empty_string; 64f3069ae9SJean Delvare } 65f3069ae9SJean Delvare 66ffbbb96dSJean Delvare static const char * __init dmi_string(const struct dmi_header *dm, u8 s) 67f3069ae9SJean Delvare { 68f3069ae9SJean Delvare const char *bp = dmi_string_nosave(dm, s); 69f3069ae9SJean Delvare char *str; 70f3069ae9SJean Delvare size_t len; 71f3069ae9SJean Delvare 72f3069ae9SJean Delvare if (bp == dmi_empty_string) 73f3069ae9SJean Delvare return dmi_empty_string; 74f3069ae9SJean Delvare 75f3069ae9SJean Delvare len = strlen(bp) + 1; 7679da4721SParag Warudkar str = dmi_alloc(len); 774f705ae3SBjorn Helgaas if (str != NULL) 784f705ae3SBjorn Helgaas strcpy(str, bp); 794f705ae3SBjorn Helgaas 804f705ae3SBjorn Helgaas return str; 814f705ae3SBjorn Helgaas } 824f705ae3SBjorn Helgaas 834f705ae3SBjorn Helgaas /* 844f705ae3SBjorn Helgaas * We have to be cautious here. We have seen BIOSes with DMI pointers 854f705ae3SBjorn Helgaas * pointing to completely the wrong place for example 864f705ae3SBjorn Helgaas */ 87eb4c5ea5SIvan Khoronzhuk static void dmi_decode_table(u8 *buf, 88e7a19c56SJean Delvare void (*decode)(const struct dmi_header *, void *), 89e7a19c56SJean Delvare void *private_data) 904f705ae3SBjorn Helgaas { 917fce084aSJean Delvare u8 *data = buf; 924f705ae3SBjorn Helgaas int i = 0; 934f705ae3SBjorn Helgaas 944f705ae3SBjorn Helgaas /* 95bfbaafaeSJean Delvare * Stop when we have seen all the items the table claimed to have 9617cd5bd5SJean Delvare * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS 9717cd5bd5SJean Delvare * >= 3.0 only) OR we run off the end of the table (should never 9817cd5bd5SJean Delvare * happen but sometimes does on bogus implementations.) 994f705ae3SBjorn Helgaas */ 1009c65e12aSLinus Torvalds while ((!dmi_num || i < dmi_num) && 1019c65e12aSLinus Torvalds (data - buf + sizeof(struct dmi_header)) <= dmi_len) { 1021855256cSJeff Garzik const struct dmi_header *dm = (const struct dmi_header *)data; 1031855256cSJeff Garzik 1044f705ae3SBjorn Helgaas /* 105*0ef11f60SJean Delvare * If a short entry is found (less than 4 bytes), not only it 106*0ef11f60SJean Delvare * is invalid, but we cannot reliably locate the next entry. 107*0ef11f60SJean Delvare */ 108*0ef11f60SJean Delvare if (dm->length < sizeof(struct dmi_header)) { 109*0ef11f60SJean Delvare pr_warn(FW_BUG 110*0ef11f60SJean Delvare "Corrupted DMI table, offset %zd (only %d entries processed)\n", 111*0ef11f60SJean Delvare data - buf, i); 112*0ef11f60SJean Delvare break; 113*0ef11f60SJean Delvare } 114*0ef11f60SJean Delvare 115*0ef11f60SJean Delvare /* 1168638545cSAlan Cox * We want to know the total length (formatted area and 1178638545cSAlan Cox * strings) before decoding to make sure we won't run off the 1188638545cSAlan Cox * table in dmi_decode or dmi_string 1194f705ae3SBjorn Helgaas */ 1204f705ae3SBjorn Helgaas data += dm->length; 121552e19d8SIvan Khoronzhuk while ((data - buf < dmi_len - 1) && (data[0] || data[1])) 1224f705ae3SBjorn Helgaas data++; 123552e19d8SIvan Khoronzhuk if (data - buf < dmi_len - 1) 124e7a19c56SJean Delvare decode(dm, private_data); 125ce204e9aSIvan Khoronzhuk 1266e0ad59eSJean Delvare data += 2; 1276e0ad59eSJean Delvare i++; 1286e0ad59eSJean Delvare 129ce204e9aSIvan Khoronzhuk /* 130ce204e9aSIvan Khoronzhuk * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0] 13117cd5bd5SJean Delvare * For tables behind a 64-bit entry point, we have no item 13217cd5bd5SJean Delvare * count and no exact table length, so stop on end-of-table 13317cd5bd5SJean Delvare * marker. For tables behind a 32-bit entry point, we have 13417cd5bd5SJean Delvare * seen OEM structures behind the end-of-table marker on 13517cd5bd5SJean Delvare * some systems, so don't trust it. 136ce204e9aSIvan Khoronzhuk */ 13717cd5bd5SJean Delvare if (!dmi_num && dm->type == DMI_ENTRY_END_OF_TABLE) 138ce204e9aSIvan Khoronzhuk break; 1394f705ae3SBjorn Helgaas } 1406e0ad59eSJean Delvare 1416e0ad59eSJean Delvare /* Trim DMI table length if needed */ 1426e0ad59eSJean Delvare if (dmi_len > data - buf) 1436e0ad59eSJean Delvare dmi_len = data - buf; 1447fce084aSJean Delvare } 1457fce084aSJean Delvare 146fc430262SArd Biesheuvel static phys_addr_t dmi_base; 1477fce084aSJean Delvare 148e7a19c56SJean Delvare static int __init dmi_walk_early(void (*decode)(const struct dmi_header *, 149e7a19c56SJean Delvare void *)) 1507fce084aSJean Delvare { 1517fce084aSJean Delvare u8 *buf; 1526e0ad59eSJean Delvare u32 orig_dmi_len = dmi_len; 1537fce084aSJean Delvare 1546e0ad59eSJean Delvare buf = dmi_early_remap(dmi_base, orig_dmi_len); 1557fce084aSJean Delvare if (buf == NULL) 156c9268200SAndy Lutomirski return -ENOMEM; 1577fce084aSJean Delvare 158eb4c5ea5SIvan Khoronzhuk dmi_decode_table(buf, decode, NULL); 1597fce084aSJean Delvare 160d114a333STony Luck add_device_randomness(buf, dmi_len); 161d114a333STony Luck 1626e0ad59eSJean Delvare dmi_early_unmap(buf, orig_dmi_len); 1634f705ae3SBjorn Helgaas return 0; 1644f705ae3SBjorn Helgaas } 1654f705ae3SBjorn Helgaas 1669f9c9cbbSZhenzhong Duan static int __init dmi_checksum(const u8 *buf, u8 len) 1674f705ae3SBjorn Helgaas { 1684f705ae3SBjorn Helgaas u8 sum = 0; 1694f705ae3SBjorn Helgaas int a; 1704f705ae3SBjorn Helgaas 1719f9c9cbbSZhenzhong Duan for (a = 0; a < len; a++) 1724f705ae3SBjorn Helgaas sum += buf[a]; 1734f705ae3SBjorn Helgaas 1744f705ae3SBjorn Helgaas return sum == 0; 1754f705ae3SBjorn Helgaas } 1764f705ae3SBjorn Helgaas 177ffbbb96dSJean Delvare static const char *dmi_ident[DMI_STRING_MAX]; 1784f705ae3SBjorn Helgaas static LIST_HEAD(dmi_devices); 1794f5c791aSLennart Poettering int dmi_available; 180c68fded7SPierre-Louis Bossart EXPORT_SYMBOL_GPL(dmi_available); 1814f705ae3SBjorn Helgaas 1824f705ae3SBjorn Helgaas /* 1834f705ae3SBjorn Helgaas * Save a DMI string 1844f705ae3SBjorn Helgaas */ 18502d9c47fSJean Delvare static void __init dmi_save_ident(const struct dmi_header *dm, int slot, 18602d9c47fSJean Delvare int string) 1874f705ae3SBjorn Helgaas { 1881855256cSJeff Garzik const char *d = (const char *) dm; 189ffbbb96dSJean Delvare const char *p; 1904f705ae3SBjorn Helgaas 191a814c359SJean Delvare if (dmi_ident[slot] || dm->length <= string) 1924f705ae3SBjorn Helgaas return; 1934f705ae3SBjorn Helgaas 1944f705ae3SBjorn Helgaas p = dmi_string(dm, d[string]); 1954f705ae3SBjorn Helgaas if (p == NULL) 1964f705ae3SBjorn Helgaas return; 1974f705ae3SBjorn Helgaas 1984f705ae3SBjorn Helgaas dmi_ident[slot] = p; 1994f705ae3SBjorn Helgaas } 2004f705ae3SBjorn Helgaas 201f5152f4dSErwan Velu static void __init dmi_save_release(const struct dmi_header *dm, int slot, 202f5152f4dSErwan Velu int index) 203f5152f4dSErwan Velu { 204f5152f4dSErwan Velu const u8 *minor, *major; 205f5152f4dSErwan Velu char *s; 206f5152f4dSErwan Velu 207f5152f4dSErwan Velu /* If the table doesn't have the field, let's return */ 208f5152f4dSErwan Velu if (dmi_ident[slot] || dm->length < index) 209f5152f4dSErwan Velu return; 210f5152f4dSErwan Velu 211f5152f4dSErwan Velu minor = (u8 *) dm + index; 212f5152f4dSErwan Velu major = (u8 *) dm + index - 1; 213f5152f4dSErwan Velu 214f5152f4dSErwan Velu /* As per the spec, if the system doesn't support this field, 215f5152f4dSErwan Velu * the value is FF 216f5152f4dSErwan Velu */ 217f5152f4dSErwan Velu if (*major == 0xFF && *minor == 0xFF) 218f5152f4dSErwan Velu return; 219f5152f4dSErwan Velu 220f5152f4dSErwan Velu s = dmi_alloc(8); 221f5152f4dSErwan Velu if (!s) 222f5152f4dSErwan Velu return; 223f5152f4dSErwan Velu 224f5152f4dSErwan Velu sprintf(s, "%u.%u", *major, *minor); 225f5152f4dSErwan Velu 226f5152f4dSErwan Velu dmi_ident[slot] = s; 227f5152f4dSErwan Velu } 228f5152f4dSErwan Velu 22902d9c47fSJean Delvare static void __init dmi_save_uuid(const struct dmi_header *dm, int slot, 23002d9c47fSJean Delvare int index) 2314f5c791aSLennart Poettering { 232a814c359SJean Delvare const u8 *d; 2334f5c791aSLennart Poettering char *s; 2344f5c791aSLennart Poettering int is_ff = 1, is_00 = 1, i; 2354f5c791aSLennart Poettering 23690fe6f8fSJean Delvare if (dmi_ident[slot] || dm->length < index + 16) 2374f5c791aSLennart Poettering return; 2384f5c791aSLennart Poettering 239a814c359SJean Delvare d = (u8 *) dm + index; 2404f5c791aSLennart Poettering for (i = 0; i < 16 && (is_ff || is_00); i++) { 241f1d8e614SZhenzhong Duan if (d[i] != 0x00) 242f1d8e614SZhenzhong Duan is_00 = 0; 243f1d8e614SZhenzhong Duan if (d[i] != 0xFF) 244f1d8e614SZhenzhong Duan is_ff = 0; 2454f5c791aSLennart Poettering } 2464f5c791aSLennart Poettering 2474f5c791aSLennart Poettering if (is_ff || is_00) 2484f5c791aSLennart Poettering return; 2494f5c791aSLennart Poettering 2504f5c791aSLennart Poettering s = dmi_alloc(16*2+4+1); 2514f5c791aSLennart Poettering if (!s) 2524f5c791aSLennart Poettering return; 2534f5c791aSLennart Poettering 254f1d8e614SZhenzhong Duan /* 255f1d8e614SZhenzhong Duan * As of version 2.6 of the SMBIOS specification, the first 3 fields of 256f1d8e614SZhenzhong Duan * the UUID are supposed to be little-endian encoded. The specification 257f1d8e614SZhenzhong Duan * says that this is the defacto standard. 258f1d8e614SZhenzhong Duan */ 25995be58dfSIvan Khoronzhuk if (dmi_ver >= 0x020600) 260712ff254SJean Delvare sprintf(s, "%pUl", d); 261f1d8e614SZhenzhong Duan else 262712ff254SJean Delvare sprintf(s, "%pUb", d); 2634f5c791aSLennart Poettering 2644f5c791aSLennart Poettering dmi_ident[slot] = s; 2654f5c791aSLennart Poettering } 2664f5c791aSLennart Poettering 26702d9c47fSJean Delvare static void __init dmi_save_type(const struct dmi_header *dm, int slot, 26802d9c47fSJean Delvare int index) 2694f5c791aSLennart Poettering { 270a814c359SJean Delvare const u8 *d; 2714f5c791aSLennart Poettering char *s; 2724f5c791aSLennart Poettering 273a814c359SJean Delvare if (dmi_ident[slot] || dm->length <= index) 2744f5c791aSLennart Poettering return; 2754f5c791aSLennart Poettering 2764f5c791aSLennart Poettering s = dmi_alloc(4); 2774f5c791aSLennart Poettering if (!s) 2784f5c791aSLennart Poettering return; 2794f5c791aSLennart Poettering 280a814c359SJean Delvare d = (u8 *) dm + index; 2814f5c791aSLennart Poettering sprintf(s, "%u", *d & 0x7F); 2824f5c791aSLennart Poettering dmi_ident[slot] = s; 2834f5c791aSLennart Poettering } 2844f5c791aSLennart Poettering 285f3069ae9SJean Delvare static void __init dmi_save_one_device(int type, const char *name) 286f3069ae9SJean Delvare { 287f3069ae9SJean Delvare struct dmi_device *dev; 288f3069ae9SJean Delvare 289f3069ae9SJean Delvare /* No duplicate device */ 290f3069ae9SJean Delvare if (dmi_find_device(type, name, NULL)) 291f3069ae9SJean Delvare return; 292f3069ae9SJean Delvare 293f3069ae9SJean Delvare dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1); 294ae797449SJean Delvare if (!dev) 295f3069ae9SJean Delvare return; 296f3069ae9SJean Delvare 297f3069ae9SJean Delvare dev->type = type; 298f3069ae9SJean Delvare strcpy((char *)(dev + 1), name); 299f3069ae9SJean Delvare dev->name = (char *)(dev + 1); 300f3069ae9SJean Delvare dev->device_data = NULL; 301f3069ae9SJean Delvare list_add(&dev->list, &dmi_devices); 302f3069ae9SJean Delvare } 303f3069ae9SJean Delvare 3041855256cSJeff Garzik static void __init dmi_save_devices(const struct dmi_header *dm) 3054f705ae3SBjorn Helgaas { 3064f705ae3SBjorn Helgaas int i, count = (dm->length - sizeof(struct dmi_header)) / 2; 3074f705ae3SBjorn Helgaas 3084f705ae3SBjorn Helgaas for (i = 0; i < count; i++) { 3091855256cSJeff Garzik const char *d = (char *)(dm + 1) + (i * 2); 3104f705ae3SBjorn Helgaas 3114f705ae3SBjorn Helgaas /* Skip disabled device */ 3124f705ae3SBjorn Helgaas if ((*d & 0x80) == 0) 3134f705ae3SBjorn Helgaas continue; 3144f705ae3SBjorn Helgaas 315f3069ae9SJean Delvare dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1))); 3162e0c1f6cSShem Multinymous } 3172e0c1f6cSShem Multinymous } 3182e0c1f6cSShem Multinymous 3191855256cSJeff Garzik static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm) 3202e0c1f6cSShem Multinymous { 321a814c359SJean Delvare int i, count; 3222e0c1f6cSShem Multinymous struct dmi_device *dev; 3232e0c1f6cSShem Multinymous 324a814c359SJean Delvare if (dm->length < 0x05) 325a814c359SJean Delvare return; 326a814c359SJean Delvare 327a814c359SJean Delvare count = *(u8 *)(dm + 1); 3282e0c1f6cSShem Multinymous for (i = 1; i <= count; i++) { 329ffbbb96dSJean Delvare const char *devname = dmi_string(dm, i); 33079da4721SParag Warudkar 33143fe105aSJean Delvare if (devname == dmi_empty_string) 33279da4721SParag Warudkar continue; 33379da4721SParag Warudkar 3342e0c1f6cSShem Multinymous dev = dmi_alloc(sizeof(*dev)); 335ae797449SJean Delvare if (!dev) 3362e0c1f6cSShem Multinymous break; 3372e0c1f6cSShem Multinymous 3382e0c1f6cSShem Multinymous dev->type = DMI_DEV_TYPE_OEM_STRING; 33979da4721SParag Warudkar dev->name = devname; 3402e0c1f6cSShem Multinymous dev->device_data = NULL; 3414f705ae3SBjorn Helgaas 3424f705ae3SBjorn Helgaas list_add(&dev->list, &dmi_devices); 3434f705ae3SBjorn Helgaas } 3444f705ae3SBjorn Helgaas } 3454f705ae3SBjorn Helgaas 3461855256cSJeff Garzik static void __init dmi_save_ipmi_device(const struct dmi_header *dm) 3474f705ae3SBjorn Helgaas { 3484f705ae3SBjorn Helgaas struct dmi_device *dev; 3494f705ae3SBjorn Helgaas void *data; 3504f705ae3SBjorn Helgaas 3514f705ae3SBjorn Helgaas data = dmi_alloc(dm->length); 352ae797449SJean Delvare if (data == NULL) 3534f705ae3SBjorn Helgaas return; 3544f705ae3SBjorn Helgaas 3554f705ae3SBjorn Helgaas memcpy(data, dm, dm->length); 3564f705ae3SBjorn Helgaas 3574f705ae3SBjorn Helgaas dev = dmi_alloc(sizeof(*dev)); 358ae797449SJean Delvare if (!dev) 3594f705ae3SBjorn Helgaas return; 3604f705ae3SBjorn Helgaas 3614f705ae3SBjorn Helgaas dev->type = DMI_DEV_TYPE_IPMI; 3624f705ae3SBjorn Helgaas dev->name = "IPMI controller"; 3634f705ae3SBjorn Helgaas dev->device_data = data; 3644f705ae3SBjorn Helgaas 365abd24df8SCarol Hebert list_add_tail(&dev->list, &dmi_devices); 3664f705ae3SBjorn Helgaas } 3674f705ae3SBjorn Helgaas 368e5b6c151SJordan Hargrave static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus, 369e5b6c151SJordan Hargrave int devfn, const char *name, int type) 370911e1c9bSNarendra K { 371e5b6c151SJordan Hargrave struct dmi_dev_onboard *dev; 372911e1c9bSNarendra K 373e5b6c151SJordan Hargrave /* Ignore invalid values */ 374e5b6c151SJordan Hargrave if (type == DMI_DEV_TYPE_DEV_SLOT && 375e5b6c151SJordan Hargrave segment == 0xFFFF && bus == 0xFF && devfn == 0xFF) 376911e1c9bSNarendra K return; 377ae797449SJean Delvare 378e5b6c151SJordan Hargrave dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1); 379e5b6c151SJordan Hargrave if (!dev) 380e5b6c151SJordan Hargrave return; 381911e1c9bSNarendra K 382e5b6c151SJordan Hargrave dev->instance = instance; 383e5b6c151SJordan Hargrave dev->segment = segment; 384e5b6c151SJordan Hargrave dev->bus = bus; 385e5b6c151SJordan Hargrave dev->devfn = devfn; 386911e1c9bSNarendra K 387e5b6c151SJordan Hargrave strcpy((char *)&dev[1], name); 388e5b6c151SJordan Hargrave dev->dev.type = type; 389e5b6c151SJordan Hargrave dev->dev.name = (char *)&dev[1]; 390e5b6c151SJordan Hargrave dev->dev.device_data = dev; 391e5b6c151SJordan Hargrave 392e5b6c151SJordan Hargrave list_add(&dev->dev.list, &dmi_devices); 393911e1c9bSNarendra K } 394911e1c9bSNarendra K 395b4bd7d59SWim Van Sebroeck static void __init dmi_save_extended_devices(const struct dmi_header *dm) 396b4bd7d59SWim Van Sebroeck { 39796e23943SJean Delvare const char *name; 39845b98257SJean Delvare const u8 *d = (u8 *)dm; 399b4bd7d59SWim Van Sebroeck 400a814c359SJean Delvare if (dm->length < 0x0B) 401a814c359SJean Delvare return; 402a814c359SJean Delvare 403b4bd7d59SWim Van Sebroeck /* Skip disabled device */ 40445b98257SJean Delvare if ((d[0x5] & 0x80) == 0) 405b4bd7d59SWim Van Sebroeck return; 406b4bd7d59SWim Van Sebroeck 40745b98257SJean Delvare name = dmi_string_nosave(dm, d[0x4]); 408e5b6c151SJordan Hargrave dmi_save_dev_pciaddr(d[0x6], *(u16 *)(d + 0x7), d[0x9], d[0xA], name, 409e5b6c151SJordan Hargrave DMI_DEV_TYPE_DEV_ONBOARD); 41045b98257SJean Delvare dmi_save_one_device(d[0x5] & 0x7f, name); 411b4bd7d59SWim Van Sebroeck } 412b4bd7d59SWim Van Sebroeck 413e5b6c151SJordan Hargrave static void __init dmi_save_system_slot(const struct dmi_header *dm) 414e5b6c151SJordan Hargrave { 415e5b6c151SJordan Hargrave const u8 *d = (u8 *)dm; 416e5b6c151SJordan Hargrave 417e5b6c151SJordan Hargrave /* Need SMBIOS 2.6+ structure */ 418e5b6c151SJordan Hargrave if (dm->length < 0x11) 419e5b6c151SJordan Hargrave return; 420e5b6c151SJordan Hargrave dmi_save_dev_pciaddr(*(u16 *)(d + 0x9), *(u16 *)(d + 0xD), d[0xF], 421e5b6c151SJordan Hargrave d[0x10], dmi_string_nosave(dm, d[0x4]), 422e5b6c151SJordan Hargrave DMI_DEV_TYPE_DEV_SLOT); 423e5b6c151SJordan Hargrave } 424e5b6c151SJordan Hargrave 425dd6dad42SChen, Gong static void __init count_mem_devices(const struct dmi_header *dm, void *v) 426dd6dad42SChen, Gong { 427dd6dad42SChen, Gong if (dm->type != DMI_ENTRY_MEM_DEVICE) 428dd6dad42SChen, Gong return; 429dd6dad42SChen, Gong dmi_memdev_nr++; 430dd6dad42SChen, Gong } 431dd6dad42SChen, Gong 432dd6dad42SChen, Gong static void __init save_mem_devices(const struct dmi_header *dm, void *v) 433dd6dad42SChen, Gong { 434dd6dad42SChen, Gong const char *d = (const char *)dm; 435dd6dad42SChen, Gong static int nr; 4366deae96bSTony Luck u64 bytes; 4376deae96bSTony Luck u16 size; 438dd6dad42SChen, Gong 4399e0afe39SJean Delvare if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x13) 440dd6dad42SChen, Gong return; 441dd6dad42SChen, Gong if (nr >= dmi_memdev_nr) { 442dd6dad42SChen, Gong pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n"); 443dd6dad42SChen, Gong return; 444dd6dad42SChen, Gong } 4450841c04dSLuck, Tony dmi_memdev[nr].handle = get_unaligned(&dm->handle); 446dd6dad42SChen, Gong dmi_memdev[nr].device = dmi_string(dm, d[0x10]); 447dd6dad42SChen, Gong dmi_memdev[nr].bank = dmi_string(dm, d[0x11]); 4489e0afe39SJean Delvare dmi_memdev[nr].type = d[0x12]; 4496deae96bSTony Luck 4506deae96bSTony Luck size = get_unaligned((u16 *)&d[0xC]); 4516deae96bSTony Luck if (size == 0) 4526deae96bSTony Luck bytes = 0; 4536deae96bSTony Luck else if (size == 0xffff) 4546deae96bSTony Luck bytes = ~0ull; 4556deae96bSTony Luck else if (size & 0x8000) 4566deae96bSTony Luck bytes = (u64)(size & 0x7fff) << 10; 45781dde26dSJean Delvare else if (size != 0x7fff || dm->length < 0x20) 4586deae96bSTony Luck bytes = (u64)size << 20; 4596deae96bSTony Luck else 4606deae96bSTony Luck bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20; 4616deae96bSTony Luck 4626deae96bSTony Luck dmi_memdev[nr].size = bytes; 463dd6dad42SChen, Gong nr++; 464dd6dad42SChen, Gong } 465dd6dad42SChen, Gong 4660fca0812SRobert Richter static void __init dmi_memdev_walk(void) 467dd6dad42SChen, Gong { 468dd6dad42SChen, Gong if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) { 469dd6dad42SChen, Gong dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr); 470dd6dad42SChen, Gong if (dmi_memdev) 471dd6dad42SChen, Gong dmi_walk_early(save_mem_devices); 472dd6dad42SChen, Gong } 473dd6dad42SChen, Gong } 474dd6dad42SChen, Gong 4754f705ae3SBjorn Helgaas /* 4764f705ae3SBjorn Helgaas * Process a DMI table entry. Right now all we care about are the BIOS 4774f705ae3SBjorn Helgaas * and machine entries. For 2.5 we should pull the smbus controller info 4784f705ae3SBjorn Helgaas * out of here. 4794f705ae3SBjorn Helgaas */ 480e7a19c56SJean Delvare static void __init dmi_decode(const struct dmi_header *dm, void *dummy) 4814f705ae3SBjorn Helgaas { 4824f705ae3SBjorn Helgaas switch (dm->type) { 4834f705ae3SBjorn Helgaas case 0: /* BIOS Information */ 4844f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_VENDOR, 4); 4854f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_VERSION, 5); 4864f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_DATE, 8); 487f5152f4dSErwan Velu dmi_save_release(dm, DMI_BIOS_RELEASE, 21); 488f5152f4dSErwan Velu dmi_save_release(dm, DMI_EC_FIRMWARE_RELEASE, 23); 4894f705ae3SBjorn Helgaas break; 4904f705ae3SBjorn Helgaas case 1: /* System Information */ 4914f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_SYS_VENDOR, 4); 4924f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_NAME, 5); 4934f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6); 4944f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7); 4954f5c791aSLennart Poettering dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8); 496b23908d3SSimon Glass dmi_save_ident(dm, DMI_PRODUCT_SKU, 25); 497c61872c9SMika Westerberg dmi_save_ident(dm, DMI_PRODUCT_FAMILY, 26); 4984f705ae3SBjorn Helgaas break; 4994f705ae3SBjorn Helgaas case 2: /* Base Board Information */ 5004f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_VENDOR, 4); 5014f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_NAME, 5); 5024f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_VERSION, 6); 5034f5c791aSLennart Poettering dmi_save_ident(dm, DMI_BOARD_SERIAL, 7); 5044f5c791aSLennart Poettering dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8); 5054f5c791aSLennart Poettering break; 5064f5c791aSLennart Poettering case 3: /* Chassis Information */ 5074f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4); 5084f5c791aSLennart Poettering dmi_save_type(dm, DMI_CHASSIS_TYPE, 5); 5094f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6); 5104f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7); 5114f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8); 5124f705ae3SBjorn Helgaas break; 513e5b6c151SJordan Hargrave case 9: /* System Slots */ 514e5b6c151SJordan Hargrave dmi_save_system_slot(dm); 515e5b6c151SJordan Hargrave break; 5164f705ae3SBjorn Helgaas case 10: /* Onboard Devices Information */ 5174f705ae3SBjorn Helgaas dmi_save_devices(dm); 5184f705ae3SBjorn Helgaas break; 5192e0c1f6cSShem Multinymous case 11: /* OEM Strings */ 5202e0c1f6cSShem Multinymous dmi_save_oem_strings_devices(dm); 5212e0c1f6cSShem Multinymous break; 5224f705ae3SBjorn Helgaas case 38: /* IPMI Device Information */ 5234f705ae3SBjorn Helgaas dmi_save_ipmi_device(dm); 524b4bd7d59SWim Van Sebroeck break; 525b4bd7d59SWim Van Sebroeck case 41: /* Onboard Devices Extended Information */ 526b4bd7d59SWim Van Sebroeck dmi_save_extended_devices(dm); 5274f705ae3SBjorn Helgaas } 5284f705ae3SBjorn Helgaas } 5294f705ae3SBjorn Helgaas 530c90fe6bcSTejun Heo static int __init print_filtered(char *buf, size_t len, const char *info) 5318881cdceSBjorn Helgaas { 532c90fe6bcSTejun Heo int c = 0; 5338881cdceSBjorn Helgaas const char *p; 5348881cdceSBjorn Helgaas 5358881cdceSBjorn Helgaas if (!info) 536c90fe6bcSTejun Heo return c; 5378881cdceSBjorn Helgaas 5388881cdceSBjorn Helgaas for (p = info; *p; p++) 5398881cdceSBjorn Helgaas if (isprint(*p)) 540c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "%c", *p); 5418881cdceSBjorn Helgaas else 542c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff); 543c90fe6bcSTejun Heo return c; 5448881cdceSBjorn Helgaas } 5458881cdceSBjorn Helgaas 546c90fe6bcSTejun Heo static void __init dmi_format_ids(char *buf, size_t len) 5478881cdceSBjorn Helgaas { 548c90fe6bcSTejun Heo int c = 0; 54984e383b3SNaga Chumbalkar const char *board; /* Board Name is optional */ 55084e383b3SNaga Chumbalkar 551c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 552c90fe6bcSTejun Heo dmi_get_system_info(DMI_SYS_VENDOR)); 553c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, " "); 554c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 555c90fe6bcSTejun Heo dmi_get_system_info(DMI_PRODUCT_NAME)); 556c90fe6bcSTejun Heo 55784e383b3SNaga Chumbalkar board = dmi_get_system_info(DMI_BOARD_NAME); 55884e383b3SNaga Chumbalkar if (board) { 559c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "/"); 560c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, board); 56184e383b3SNaga Chumbalkar } 562c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, ", BIOS "); 563c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 564c90fe6bcSTejun Heo dmi_get_system_info(DMI_BIOS_VERSION)); 565c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, " "); 566c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, 567c90fe6bcSTejun Heo dmi_get_system_info(DMI_BIOS_DATE)); 5688881cdceSBjorn Helgaas } 5698881cdceSBjorn Helgaas 570d39de28cSBen Hutchings /* 571d39de28cSBen Hutchings * Check for DMI/SMBIOS headers in the system firmware image. Any 572d39de28cSBen Hutchings * SMBIOS header must start 16 bytes before the DMI header, so take a 573d39de28cSBen Hutchings * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset 574d39de28cSBen Hutchings * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS 575d39de28cSBen Hutchings * takes precedence) and return 0. Otherwise return 1. 576d39de28cSBen Hutchings */ 57779bae42dSBen Hutchings static int __init dmi_present(const u8 *buf) 5784f705ae3SBjorn Helgaas { 57995be58dfSIvan Khoronzhuk u32 smbios_ver; 5801855256cSJeff Garzik 58113a0ac81SJean Delvare /* 58213a0ac81SJean Delvare * The size of this structure is 31 bytes, but we also accept value 58313a0ac81SJean Delvare * 30 due to a mistake in SMBIOS specification version 2.1. 58413a0ac81SJean Delvare */ 58579bae42dSBen Hutchings if (memcmp(buf, "_SM_", 4) == 0 && 58613a0ac81SJean Delvare buf[5] >= 30 && buf[5] <= 32 && 58713a0ac81SJean Delvare dmi_checksum(buf, buf[5])) { 588fc430262SArd Biesheuvel smbios_ver = get_unaligned_be16(buf + 6); 589d7f96f97SIvan Khoronzhuk smbios_entry_point_size = buf[5]; 590d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, smbios_entry_point_size); 59179bae42dSBen Hutchings 59279bae42dSBen Hutchings /* Some BIOS report weird SMBIOS version, fix that up */ 59379bae42dSBen Hutchings switch (smbios_ver) { 59479bae42dSBen Hutchings case 0x021F: 59579bae42dSBen Hutchings case 0x0221: 59679bae42dSBen Hutchings pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 59779bae42dSBen Hutchings smbios_ver & 0xFF, 3); 59879bae42dSBen Hutchings smbios_ver = 0x0203; 59979bae42dSBen Hutchings break; 60079bae42dSBen Hutchings case 0x0233: 60179bae42dSBen Hutchings pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6); 60279bae42dSBen Hutchings smbios_ver = 0x0206; 60379bae42dSBen Hutchings break; 60479bae42dSBen Hutchings } 60579bae42dSBen Hutchings } else { 60679bae42dSBen Hutchings smbios_ver = 0; 60779bae42dSBen Hutchings } 60879bae42dSBen Hutchings 60979bae42dSBen Hutchings buf += 16; 61079bae42dSBen Hutchings 61179bae42dSBen Hutchings if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) { 6125c1ac56bSJean Delvare if (smbios_ver) 6135c1ac56bSJean Delvare dmi_ver = smbios_ver; 6145c1ac56bSJean Delvare else 6155c1ac56bSJean Delvare dmi_ver = (buf[14] & 0xF0) << 4 | (buf[14] & 0x0F); 616ff4319dcSAndrea Arcangeli dmi_ver <<= 8; 617fc430262SArd Biesheuvel dmi_num = get_unaligned_le16(buf + 12); 618fc430262SArd Biesheuvel dmi_len = get_unaligned_le16(buf + 6); 619fc430262SArd Biesheuvel dmi_base = get_unaligned_le32(buf + 8); 6204f705ae3SBjorn Helgaas 6218881cdceSBjorn Helgaas if (dmi_walk_early(dmi_decode) == 0) { 62279bae42dSBen Hutchings if (smbios_ver) { 623c2493045SJean Delvare pr_info("SMBIOS %d.%d present.\n", 624ff4319dcSAndrea Arcangeli dmi_ver >> 16, (dmi_ver >> 8) & 0xFF); 62579bae42dSBen Hutchings } else { 626d7f96f97SIvan Khoronzhuk smbios_entry_point_size = 15; 627d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, 628d7f96f97SIvan Khoronzhuk smbios_entry_point_size); 6299f9c9cbbSZhenzhong Duan pr_info("Legacy DMI %d.%d present.\n", 630ff4319dcSAndrea Arcangeli dmi_ver >> 16, (dmi_ver >> 8) & 0xFF); 6319f9c9cbbSZhenzhong Duan } 632c90fe6bcSTejun Heo dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); 633d4af49f8SKefeng Wang pr_info("DMI: %s\n", dmi_ids_string); 6344f705ae3SBjorn Helgaas return 0; 6354f705ae3SBjorn Helgaas } 6368881cdceSBjorn Helgaas } 6374f705ae3SBjorn Helgaas 638a40e7cf8SBen Hutchings return 1; 6399f9c9cbbSZhenzhong Duan } 6409f9c9cbbSZhenzhong Duan 641fc430262SArd Biesheuvel /* 642fc430262SArd Biesheuvel * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy 643fc430262SArd Biesheuvel * 32-bit entry point, there is no embedded DMI header (_DMI_) in here. 644fc430262SArd Biesheuvel */ 645fc430262SArd Biesheuvel static int __init dmi_smbios3_present(const u8 *buf) 646fc430262SArd Biesheuvel { 647fc430262SArd Biesheuvel if (memcmp(buf, "_SM3_", 5) == 0 && 64813a0ac81SJean Delvare buf[6] >= 24 && buf[6] <= 32 && 64913a0ac81SJean Delvare dmi_checksum(buf, buf[6])) { 650d2139dfcSAndy Shevchenko dmi_ver = get_unaligned_be24(buf + 7); 651bfbaafaeSJean Delvare dmi_num = 0; /* No longer specified */ 652fc430262SArd Biesheuvel dmi_len = get_unaligned_le32(buf + 12); 653fc430262SArd Biesheuvel dmi_base = get_unaligned_le64(buf + 16); 654d7f96f97SIvan Khoronzhuk smbios_entry_point_size = buf[6]; 655d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, smbios_entry_point_size); 656fc430262SArd Biesheuvel 657fc430262SArd Biesheuvel if (dmi_walk_early(dmi_decode) == 0) { 65895be58dfSIvan Khoronzhuk pr_info("SMBIOS %d.%d.%d present.\n", 65995be58dfSIvan Khoronzhuk dmi_ver >> 16, (dmi_ver >> 8) & 0xFF, 66095be58dfSIvan Khoronzhuk dmi_ver & 0xFF); 661fc430262SArd Biesheuvel dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string)); 662d4af49f8SKefeng Wang pr_info("DMI: %s\n", dmi_ids_string); 663fc430262SArd Biesheuvel return 0; 664fc430262SArd Biesheuvel } 665fc430262SArd Biesheuvel } 666fc430262SArd Biesheuvel return 1; 667fc430262SArd Biesheuvel } 668fc430262SArd Biesheuvel 6690fca0812SRobert Richter static void __init dmi_scan_machine(void) 6704f705ae3SBjorn Helgaas { 6714f705ae3SBjorn Helgaas char __iomem *p, *q; 67279bae42dSBen Hutchings char buf[32]; 6734f705ae3SBjorn Helgaas 67483e68189SMatt Fleming if (efi_enabled(EFI_CONFIG_TABLES)) { 675fc430262SArd Biesheuvel /* 676fc430262SArd Biesheuvel * According to the DMTF SMBIOS reference spec v3.0.0, it is 677fc430262SArd Biesheuvel * allowed to define both the 64-bit entry point (smbios3) and 678fc430262SArd Biesheuvel * the 32-bit entry point (smbios), in which case they should 679fc430262SArd Biesheuvel * either both point to the same SMBIOS structure table, or the 680fc430262SArd Biesheuvel * table pointed to by the 64-bit entry point should contain a 681fc430262SArd Biesheuvel * superset of the table contents pointed to by the 32-bit entry 682fc430262SArd Biesheuvel * point (section 5.2) 683fc430262SArd Biesheuvel * This implies that the 64-bit entry point should have 684fc430262SArd Biesheuvel * precedence if it is defined and supported by the OS. If we 685fc430262SArd Biesheuvel * have the 64-bit entry point, but fail to decode it, fall 686fc430262SArd Biesheuvel * back to the legacy one (if available) 687fc430262SArd Biesheuvel */ 688fc430262SArd Biesheuvel if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) { 689fc430262SArd Biesheuvel p = dmi_early_remap(efi.smbios3, 32); 690fc430262SArd Biesheuvel if (p == NULL) 691fc430262SArd Biesheuvel goto error; 692fc430262SArd Biesheuvel memcpy_fromio(buf, p, 32); 693fc430262SArd Biesheuvel dmi_early_unmap(p, 32); 694fc430262SArd Biesheuvel 695fc430262SArd Biesheuvel if (!dmi_smbios3_present(buf)) { 696fc430262SArd Biesheuvel dmi_available = 1; 6977117794fSJean Delvare return; 698fc430262SArd Biesheuvel } 699fc430262SArd Biesheuvel } 7004f705ae3SBjorn Helgaas if (efi.smbios == EFI_INVALID_TABLE_ADDR) 7019a22b6e7SIngo Molnar goto error; 7024f705ae3SBjorn Helgaas 7034f705ae3SBjorn Helgaas /* This is called as a core_initcall() because it isn't 7044f705ae3SBjorn Helgaas * needed during early boot. This also means we can 7054f705ae3SBjorn Helgaas * iounmap the space when we're done with it. 7064f705ae3SBjorn Helgaas */ 707cf074402SArd Biesheuvel p = dmi_early_remap(efi.smbios, 32); 7084f705ae3SBjorn Helgaas if (p == NULL) 7099a22b6e7SIngo Molnar goto error; 71079bae42dSBen Hutchings memcpy_fromio(buf, p, 32); 711cf074402SArd Biesheuvel dmi_early_unmap(p, 32); 71279bae42dSBen Hutchings 71379bae42dSBen Hutchings if (!dmi_present(buf)) { 7144f5c791aSLennart Poettering dmi_available = 1; 7157117794fSJean Delvare return; 7164f705ae3SBjorn Helgaas } 717cf074402SArd Biesheuvel } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) { 7183da27a4eSTiezhu Yang p = dmi_early_remap(SMBIOS_ENTRY_POINT_SCAN_START, 0x10000); 7194f705ae3SBjorn Helgaas if (p == NULL) 7209a22b6e7SIngo Molnar goto error; 7214f705ae3SBjorn Helgaas 722d39de28cSBen Hutchings /* 723c9aba143SJean Delvare * Same logic as above, look for a 64-bit entry point 724c9aba143SJean Delvare * first, and if not found, fall back to 32-bit entry point. 725c9aba143SJean Delvare */ 726c9aba143SJean Delvare memcpy_fromio(buf, p, 16); 727c9aba143SJean Delvare for (q = p + 16; q < p + 0x10000; q += 16) { 728c9aba143SJean Delvare memcpy_fromio(buf + 16, q, 16); 729c9aba143SJean Delvare if (!dmi_smbios3_present(buf)) { 730c9aba143SJean Delvare dmi_available = 1; 731c9aba143SJean Delvare dmi_early_unmap(p, 0x10000); 7327117794fSJean Delvare return; 733c9aba143SJean Delvare } 734c9aba143SJean Delvare memcpy(buf, buf + 16, 16); 735c9aba143SJean Delvare } 736c9aba143SJean Delvare 737c9aba143SJean Delvare /* 738d39de28cSBen Hutchings * Iterate over all possible DMI header addresses q. 739d39de28cSBen Hutchings * Maintain the 32 bytes around q in buf. On the 740d39de28cSBen Hutchings * first iteration, substitute zero for the 741d39de28cSBen Hutchings * out-of-range bytes so there is no chance of falsely 742d39de28cSBen Hutchings * detecting an SMBIOS header. 743d39de28cSBen Hutchings */ 74479bae42dSBen Hutchings memset(buf, 0, 16); 7454f705ae3SBjorn Helgaas for (q = p; q < p + 0x10000; q += 16) { 74679bae42dSBen Hutchings memcpy_fromio(buf + 16, q, 16); 747c9aba143SJean Delvare if (!dmi_present(buf)) { 7484f5c791aSLennart Poettering dmi_available = 1; 749cf074402SArd Biesheuvel dmi_early_unmap(p, 0x10000); 7507117794fSJean Delvare return; 7514f705ae3SBjorn Helgaas } 75279bae42dSBen Hutchings memcpy(buf, buf + 16, 16); 7534f705ae3SBjorn Helgaas } 754cf074402SArd Biesheuvel dmi_early_unmap(p, 0x10000); 7554f5c791aSLennart Poettering } 7569a22b6e7SIngo Molnar error: 75702d9c47fSJean Delvare pr_info("DMI not present or invalid.\n"); 7584f705ae3SBjorn Helgaas } 7594f705ae3SBjorn Helgaas 760d7f96f97SIvan Khoronzhuk static ssize_t raw_table_read(struct file *file, struct kobject *kobj, 761d7f96f97SIvan Khoronzhuk struct bin_attribute *attr, char *buf, 762d7f96f97SIvan Khoronzhuk loff_t pos, size_t count) 763d7f96f97SIvan Khoronzhuk { 764d7f96f97SIvan Khoronzhuk memcpy(buf, attr->private + pos, count); 765d7f96f97SIvan Khoronzhuk return count; 766d7f96f97SIvan Khoronzhuk } 767d7f96f97SIvan Khoronzhuk 768d7f96f97SIvan Khoronzhuk static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0); 769d7f96f97SIvan Khoronzhuk static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0); 770d7f96f97SIvan Khoronzhuk 771d7f96f97SIvan Khoronzhuk static int __init dmi_init(void) 772d7f96f97SIvan Khoronzhuk { 773d7f96f97SIvan Khoronzhuk struct kobject *tables_kobj; 774d7f96f97SIvan Khoronzhuk u8 *dmi_table; 775d7f96f97SIvan Khoronzhuk int ret = -ENOMEM; 776d7f96f97SIvan Khoronzhuk 777a81114d0SArd Biesheuvel if (!dmi_available) 778a81114d0SArd Biesheuvel return 0; 779d7f96f97SIvan Khoronzhuk 780d7f96f97SIvan Khoronzhuk /* 781d7f96f97SIvan Khoronzhuk * Set up dmi directory at /sys/firmware/dmi. This entry should stay 782d7f96f97SIvan Khoronzhuk * even after farther error, as it can be used by other modules like 783d7f96f97SIvan Khoronzhuk * dmi-sysfs. 784d7f96f97SIvan Khoronzhuk */ 785d7f96f97SIvan Khoronzhuk dmi_kobj = kobject_create_and_add("dmi", firmware_kobj); 786d7f96f97SIvan Khoronzhuk if (!dmi_kobj) 787d7f96f97SIvan Khoronzhuk goto err; 788d7f96f97SIvan Khoronzhuk 789d7f96f97SIvan Khoronzhuk tables_kobj = kobject_create_and_add("tables", dmi_kobj); 790d7f96f97SIvan Khoronzhuk if (!tables_kobj) 791d7f96f97SIvan Khoronzhuk goto err; 792d7f96f97SIvan Khoronzhuk 793d7f96f97SIvan Khoronzhuk dmi_table = dmi_remap(dmi_base, dmi_len); 794d7f96f97SIvan Khoronzhuk if (!dmi_table) 795d7f96f97SIvan Khoronzhuk goto err_tables; 796d7f96f97SIvan Khoronzhuk 797d7f96f97SIvan Khoronzhuk bin_attr_smbios_entry_point.size = smbios_entry_point_size; 798d7f96f97SIvan Khoronzhuk bin_attr_smbios_entry_point.private = smbios_entry_point; 799d7f96f97SIvan Khoronzhuk ret = sysfs_create_bin_file(tables_kobj, &bin_attr_smbios_entry_point); 800d7f96f97SIvan Khoronzhuk if (ret) 801d7f96f97SIvan Khoronzhuk goto err_unmap; 802d7f96f97SIvan Khoronzhuk 803d7f96f97SIvan Khoronzhuk bin_attr_DMI.size = dmi_len; 804d7f96f97SIvan Khoronzhuk bin_attr_DMI.private = dmi_table; 805d7f96f97SIvan Khoronzhuk ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI); 806d7f96f97SIvan Khoronzhuk if (!ret) 807d7f96f97SIvan Khoronzhuk return 0; 808d7f96f97SIvan Khoronzhuk 809d7f96f97SIvan Khoronzhuk sysfs_remove_bin_file(tables_kobj, 810d7f96f97SIvan Khoronzhuk &bin_attr_smbios_entry_point); 811d7f96f97SIvan Khoronzhuk err_unmap: 812d7f96f97SIvan Khoronzhuk dmi_unmap(dmi_table); 813d7f96f97SIvan Khoronzhuk err_tables: 814d7f96f97SIvan Khoronzhuk kobject_del(tables_kobj); 815d7f96f97SIvan Khoronzhuk kobject_put(tables_kobj); 816d7f96f97SIvan Khoronzhuk err: 817d7f96f97SIvan Khoronzhuk pr_err("dmi: Firmware registration failed.\n"); 818d7f96f97SIvan Khoronzhuk 819d7f96f97SIvan Khoronzhuk return ret; 820d7f96f97SIvan Khoronzhuk } 821d7f96f97SIvan Khoronzhuk subsys_initcall(dmi_init); 822d7f96f97SIvan Khoronzhuk 8234f705ae3SBjorn Helgaas /** 8240fca0812SRobert Richter * dmi_setup - scan and setup DMI system information 82598e5e1bfSTejun Heo * 8260fca0812SRobert Richter * Scan the DMI system information. This setups DMI identifiers 8270fca0812SRobert Richter * (dmi_system_id) for printing it out on task dumps and prepares 8280fca0812SRobert Richter * DIMM entry information (dmi_memdev_info) from the SMBIOS table 8290fca0812SRobert Richter * for using this when reporting memory errors. 83098e5e1bfSTejun Heo */ 8310fca0812SRobert Richter void __init dmi_setup(void) 83298e5e1bfSTejun Heo { 8330fca0812SRobert Richter dmi_scan_machine(); 8340fca0812SRobert Richter if (!dmi_available) 8350fca0812SRobert Richter return; 8360fca0812SRobert Richter 8370fca0812SRobert Richter dmi_memdev_walk(); 83898e5e1bfSTejun Heo dump_stack_set_arch_desc("%s", dmi_ids_string); 83998e5e1bfSTejun Heo } 84098e5e1bfSTejun Heo 84198e5e1bfSTejun Heo /** 842d7b1956fSRafael J. Wysocki * dmi_matches - check if dmi_system_id structure matches system DMI data 843d7b1956fSRafael J. Wysocki * @dmi: pointer to the dmi_system_id structure to check 844d7b1956fSRafael J. Wysocki */ 845d7b1956fSRafael J. Wysocki static bool dmi_matches(const struct dmi_system_id *dmi) 846d7b1956fSRafael J. Wysocki { 847d7b1956fSRafael J. Wysocki int i; 848d7b1956fSRafael J. Wysocki 849d7b1956fSRafael J. Wysocki for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) { 850d7b1956fSRafael J. Wysocki int s = dmi->matches[i].slot; 851d7b1956fSRafael J. Wysocki if (s == DMI_NONE) 85275757507SDmitry Torokhov break; 853de40614dSAlex Hung if (s == DMI_OEM_STRING) { 854de40614dSAlex Hung /* DMI_OEM_STRING must be exact match */ 855de40614dSAlex Hung const struct dmi_device *valid; 856de40614dSAlex Hung 857de40614dSAlex Hung valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, 858de40614dSAlex Hung dmi->matches[i].substr, NULL); 859de40614dSAlex Hung if (valid) 860de40614dSAlex Hung continue; 861de40614dSAlex Hung } else if (dmi_ident[s]) { 8628cf4e6a0SJean Delvare if (dmi->matches[i].exact_match) { 8638cf4e6a0SJean Delvare if (!strcmp(dmi_ident[s], 8648cf4e6a0SJean Delvare dmi->matches[i].substr)) 865d7b1956fSRafael J. Wysocki continue; 8668cf4e6a0SJean Delvare } else { 8678cf4e6a0SJean Delvare if (strstr(dmi_ident[s], 8688cf4e6a0SJean Delvare dmi->matches[i].substr)) 8695017b285SJani Nikula continue; 8705017b285SJani Nikula } 8718cf4e6a0SJean Delvare } 8725017b285SJani Nikula 873d7b1956fSRafael J. Wysocki /* No match */ 874d7b1956fSRafael J. Wysocki return false; 875d7b1956fSRafael J. Wysocki } 876d7b1956fSRafael J. Wysocki return true; 877d7b1956fSRafael J. Wysocki } 878d7b1956fSRafael J. Wysocki 879d7b1956fSRafael J. Wysocki /** 88075757507SDmitry Torokhov * dmi_is_end_of_table - check for end-of-table marker 88175757507SDmitry Torokhov * @dmi: pointer to the dmi_system_id structure to check 88275757507SDmitry Torokhov */ 88375757507SDmitry Torokhov static bool dmi_is_end_of_table(const struct dmi_system_id *dmi) 88475757507SDmitry Torokhov { 88575757507SDmitry Torokhov return dmi->matches[0].slot == DMI_NONE; 88675757507SDmitry Torokhov } 88775757507SDmitry Torokhov 88875757507SDmitry Torokhov /** 8894f705ae3SBjorn Helgaas * dmi_check_system - check system DMI data 8904f705ae3SBjorn Helgaas * @list: array of dmi_system_id structures to match against 891b0ef371eSRandy Dunlap * All non-null elements of the list must match 892b0ef371eSRandy Dunlap * their slot's (field index's) data (i.e., each 893b0ef371eSRandy Dunlap * list string must be a substring of the specified 894b0ef371eSRandy Dunlap * DMI slot's string data) to be considered a 895b0ef371eSRandy Dunlap * successful match. 8964f705ae3SBjorn Helgaas * 8974f705ae3SBjorn Helgaas * Walk the blacklist table running matching functions until someone 8984f705ae3SBjorn Helgaas * returns non zero or we hit the end. Callback function is called for 899b0ef371eSRandy Dunlap * each successful match. Returns the number of matches. 9007117794fSJean Delvare * 9010fca0812SRobert Richter * dmi_setup must be called before this function is called. 9024f705ae3SBjorn Helgaas */ 9031855256cSJeff Garzik int dmi_check_system(const struct dmi_system_id *list) 9044f705ae3SBjorn Helgaas { 905d7b1956fSRafael J. Wysocki int count = 0; 906d7b1956fSRafael J. Wysocki const struct dmi_system_id *d; 9074f705ae3SBjorn Helgaas 90875757507SDmitry Torokhov for (d = list; !dmi_is_end_of_table(d); d++) 909d7b1956fSRafael J. Wysocki if (dmi_matches(d)) { 9104f705ae3SBjorn Helgaas count++; 9114f705ae3SBjorn Helgaas if (d->callback && d->callback(d)) 9124f705ae3SBjorn Helgaas break; 9134f705ae3SBjorn Helgaas } 9144f705ae3SBjorn Helgaas 9154f705ae3SBjorn Helgaas return count; 9164f705ae3SBjorn Helgaas } 9174f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_check_system); 9184f705ae3SBjorn Helgaas 9194f705ae3SBjorn Helgaas /** 920d7b1956fSRafael J. Wysocki * dmi_first_match - find dmi_system_id structure matching system DMI data 921d7b1956fSRafael J. Wysocki * @list: array of dmi_system_id structures to match against 922d7b1956fSRafael J. Wysocki * All non-null elements of the list must match 923d7b1956fSRafael J. Wysocki * their slot's (field index's) data (i.e., each 924d7b1956fSRafael J. Wysocki * list string must be a substring of the specified 925d7b1956fSRafael J. Wysocki * DMI slot's string data) to be considered a 926d7b1956fSRafael J. Wysocki * successful match. 927d7b1956fSRafael J. Wysocki * 928d7b1956fSRafael J. Wysocki * Walk the blacklist table until the first match is found. Return the 929d7b1956fSRafael J. Wysocki * pointer to the matching entry or NULL if there's no match. 9307117794fSJean Delvare * 9310fca0812SRobert Richter * dmi_setup must be called before this function is called. 932d7b1956fSRafael J. Wysocki */ 933d7b1956fSRafael J. Wysocki const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list) 934d7b1956fSRafael J. Wysocki { 935d7b1956fSRafael J. Wysocki const struct dmi_system_id *d; 936d7b1956fSRafael J. Wysocki 93775757507SDmitry Torokhov for (d = list; !dmi_is_end_of_table(d); d++) 938d7b1956fSRafael J. Wysocki if (dmi_matches(d)) 939d7b1956fSRafael J. Wysocki return d; 940d7b1956fSRafael J. Wysocki 941d7b1956fSRafael J. Wysocki return NULL; 942d7b1956fSRafael J. Wysocki } 943d7b1956fSRafael J. Wysocki EXPORT_SYMBOL(dmi_first_match); 944d7b1956fSRafael J. Wysocki 945d7b1956fSRafael J. Wysocki /** 9464f705ae3SBjorn Helgaas * dmi_get_system_info - return DMI data value 947b0ef371eSRandy Dunlap * @field: data index (see enum dmi_field) 9484f705ae3SBjorn Helgaas * 9494f705ae3SBjorn Helgaas * Returns one DMI data value, can be used to perform 9504f705ae3SBjorn Helgaas * complex DMI data checks. 9514f705ae3SBjorn Helgaas */ 9521855256cSJeff Garzik const char *dmi_get_system_info(int field) 9534f705ae3SBjorn Helgaas { 9544f705ae3SBjorn Helgaas return dmi_ident[field]; 9554f705ae3SBjorn Helgaas } 9564f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_get_system_info); 9574f705ae3SBjorn Helgaas 958fd8cd7e1SAlok Kataria /** 959c2bacfc4SRandy Dunlap * dmi_name_in_serial - Check if string is in the DMI product serial information 960c2bacfc4SRandy Dunlap * @str: string to check for 961fd8cd7e1SAlok Kataria */ 962fd8cd7e1SAlok Kataria int dmi_name_in_serial(const char *str) 963fd8cd7e1SAlok Kataria { 964fd8cd7e1SAlok Kataria int f = DMI_PRODUCT_SERIAL; 965fd8cd7e1SAlok Kataria if (dmi_ident[f] && strstr(dmi_ident[f], str)) 966fd8cd7e1SAlok Kataria return 1; 967fd8cd7e1SAlok Kataria return 0; 968fd8cd7e1SAlok Kataria } 969a1bae672SAndi Kleen 970a1bae672SAndi Kleen /** 97166e13e66SJean Delvare * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name 972a1bae672SAndi Kleen * @str: Case sensitive Name 973a1bae672SAndi Kleen */ 9741855256cSJeff Garzik int dmi_name_in_vendors(const char *str) 975a1bae672SAndi Kleen { 97666e13e66SJean Delvare static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE }; 977a1bae672SAndi Kleen int i; 978a1bae672SAndi Kleen for (i = 0; fields[i] != DMI_NONE; i++) { 979a1bae672SAndi Kleen int f = fields[i]; 980a1bae672SAndi Kleen if (dmi_ident[f] && strstr(dmi_ident[f], str)) 981a1bae672SAndi Kleen return 1; 982a1bae672SAndi Kleen } 983a1bae672SAndi Kleen return 0; 984a1bae672SAndi Kleen } 985a1bae672SAndi Kleen EXPORT_SYMBOL(dmi_name_in_vendors); 986a1bae672SAndi Kleen 9874f705ae3SBjorn Helgaas /** 9884f705ae3SBjorn Helgaas * dmi_find_device - find onboard device by type/name 9894f705ae3SBjorn Helgaas * @type: device type or %DMI_DEV_TYPE_ANY to match all device types 990b0ef371eSRandy Dunlap * @name: device name string or %NULL to match all 9914f705ae3SBjorn Helgaas * @from: previous device found in search, or %NULL for new search. 9924f705ae3SBjorn Helgaas * 9934f705ae3SBjorn Helgaas * Iterates through the list of known onboard devices. If a device is 994bfab8b48SJean Delvare * found with a matching @type and @name, a pointer to its device 9954f705ae3SBjorn Helgaas * structure is returned. Otherwise, %NULL is returned. 996b0ef371eSRandy Dunlap * A new search is initiated by passing %NULL as the @from argument. 9974f705ae3SBjorn Helgaas * If @from is not %NULL, searches continue from next device. 9984f705ae3SBjorn Helgaas */ 9991855256cSJeff Garzik const struct dmi_device *dmi_find_device(int type, const char *name, 10001855256cSJeff Garzik const struct dmi_device *from) 10014f705ae3SBjorn Helgaas { 10021855256cSJeff Garzik const struct list_head *head = from ? &from->list : &dmi_devices; 10031855256cSJeff Garzik struct list_head *d; 10044f705ae3SBjorn Helgaas 10054f705ae3SBjorn Helgaas for (d = head->next; d != &dmi_devices; d = d->next) { 10061855256cSJeff Garzik const struct dmi_device *dev = 10071855256cSJeff Garzik list_entry(d, struct dmi_device, list); 10084f705ae3SBjorn Helgaas 10094f705ae3SBjorn Helgaas if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) && 10104f705ae3SBjorn Helgaas ((name == NULL) || (strcmp(dev->name, name) == 0))) 10114f705ae3SBjorn Helgaas return dev; 10124f705ae3SBjorn Helgaas } 10134f705ae3SBjorn Helgaas 10144f705ae3SBjorn Helgaas return NULL; 10154f705ae3SBjorn Helgaas } 10164f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_find_device); 10174f705ae3SBjorn Helgaas 10184f705ae3SBjorn Helgaas /** 10193e5cd1f2STejun Heo * dmi_get_date - parse a DMI date 10203e5cd1f2STejun Heo * @field: data index (see enum dmi_field) 10213e5cd1f2STejun Heo * @yearp: optional out parameter for the year 10223e5cd1f2STejun Heo * @monthp: optional out parameter for the month 10233e5cd1f2STejun Heo * @dayp: optional out parameter for the day 10244f705ae3SBjorn Helgaas * 10253e5cd1f2STejun Heo * The date field is assumed to be in the form resembling 10263e5cd1f2STejun Heo * [mm[/dd]]/yy[yy] and the result is stored in the out 10273e5cd1f2STejun Heo * parameters any or all of which can be omitted. 10283e5cd1f2STejun Heo * 10293e5cd1f2STejun Heo * If the field doesn't exist, all out parameters are set to zero 10303e5cd1f2STejun Heo * and false is returned. Otherwise, true is returned with any 10313e5cd1f2STejun Heo * invalid part of date set to zero. 10323e5cd1f2STejun Heo * 10333e5cd1f2STejun Heo * On return, year, month and day are guaranteed to be in the 10343e5cd1f2STejun Heo * range of [0,9999], [0,12] and [0,31] respectively. 10354f705ae3SBjorn Helgaas */ 10363e5cd1f2STejun Heo bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp) 10374f705ae3SBjorn Helgaas { 10383e5cd1f2STejun Heo int year = 0, month = 0, day = 0; 10393e5cd1f2STejun Heo bool exists; 10403e5cd1f2STejun Heo const char *s, *y; 104102c24fa8STejun Heo char *e; 10424f705ae3SBjorn Helgaas 10433e5cd1f2STejun Heo s = dmi_get_system_info(field); 10443e5cd1f2STejun Heo exists = s; 10453e5cd1f2STejun Heo if (!exists) 10463e5cd1f2STejun Heo goto out; 10474f705ae3SBjorn Helgaas 10483e5cd1f2STejun Heo /* 10493e5cd1f2STejun Heo * Determine year first. We assume the date string resembles 10503e5cd1f2STejun Heo * mm/dd/yy[yy] but the original code extracted only the year 10513e5cd1f2STejun Heo * from the end. Keep the behavior in the spirit of no 10523e5cd1f2STejun Heo * surprises. 10533e5cd1f2STejun Heo */ 10543e5cd1f2STejun Heo y = strrchr(s, '/'); 10553e5cd1f2STejun Heo if (!y) 10563e5cd1f2STejun Heo goto out; 10573e5cd1f2STejun Heo 10583e5cd1f2STejun Heo y++; 10593e5cd1f2STejun Heo year = simple_strtoul(y, &e, 10); 10603e5cd1f2STejun Heo if (y != e && year < 100) { /* 2-digit year */ 10614f705ae3SBjorn Helgaas year += 1900; 10624f705ae3SBjorn Helgaas if (year < 1996) /* no dates < spec 1.0 */ 10634f705ae3SBjorn Helgaas year += 100; 10644f705ae3SBjorn Helgaas } 10653e5cd1f2STejun Heo if (year > 9999) /* year should fit in %04d */ 10663e5cd1f2STejun Heo year = 0; 10674f705ae3SBjorn Helgaas 10683e5cd1f2STejun Heo /* parse the mm and dd */ 10693e5cd1f2STejun Heo month = simple_strtoul(s, &e, 10); 10703e5cd1f2STejun Heo if (s == e || *e != '/' || !month || month > 12) { 10713e5cd1f2STejun Heo month = 0; 10723e5cd1f2STejun Heo goto out; 10734f705ae3SBjorn Helgaas } 10743e5cd1f2STejun Heo 10753e5cd1f2STejun Heo s = e + 1; 10763e5cd1f2STejun Heo day = simple_strtoul(s, &e, 10); 10773e5cd1f2STejun Heo if (s == y || s == e || *e != '/' || day > 31) 10783e5cd1f2STejun Heo day = 0; 10793e5cd1f2STejun Heo out: 10803e5cd1f2STejun Heo if (yearp) 10813e5cd1f2STejun Heo *yearp = year; 10823e5cd1f2STejun Heo if (monthp) 10833e5cd1f2STejun Heo *monthp = month; 10843e5cd1f2STejun Heo if (dayp) 10853e5cd1f2STejun Heo *dayp = day; 10863e5cd1f2STejun Heo return exists; 10873e5cd1f2STejun Heo } 10883e5cd1f2STejun Heo EXPORT_SYMBOL(dmi_get_date); 10897fce084aSJean Delvare 10907fce084aSJean Delvare /** 10913af34525SAndy Shevchenko * dmi_get_bios_year - get a year out of DMI_BIOS_DATE field 10923af34525SAndy Shevchenko * 10933af34525SAndy Shevchenko * Returns year on success, -ENXIO if DMI is not selected, 10943af34525SAndy Shevchenko * or a different negative error code if DMI field is not present 10953af34525SAndy Shevchenko * or not parseable. 10963af34525SAndy Shevchenko */ 10973af34525SAndy Shevchenko int dmi_get_bios_year(void) 10983af34525SAndy Shevchenko { 10993af34525SAndy Shevchenko bool exists; 11003af34525SAndy Shevchenko int year; 11013af34525SAndy Shevchenko 11023af34525SAndy Shevchenko exists = dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL); 11033af34525SAndy Shevchenko if (!exists) 11043af34525SAndy Shevchenko return -ENODATA; 11053af34525SAndy Shevchenko 11063af34525SAndy Shevchenko return year ? year : -ERANGE; 11073af34525SAndy Shevchenko } 11083af34525SAndy Shevchenko EXPORT_SYMBOL(dmi_get_bios_year); 11093af34525SAndy Shevchenko 11103af34525SAndy Shevchenko /** 11117fce084aSJean Delvare * dmi_walk - Walk the DMI table and get called back for every record 11127fce084aSJean Delvare * @decode: Callback function 1113e7a19c56SJean Delvare * @private_data: Private data to be passed to the callback function 11147fce084aSJean Delvare * 1115c9268200SAndy Lutomirski * Returns 0 on success, -ENXIO if DMI is not selected or not present, 1116c9268200SAndy Lutomirski * or a different negative error code if DMI walking fails. 11177fce084aSJean Delvare */ 1118e7a19c56SJean Delvare int dmi_walk(void (*decode)(const struct dmi_header *, void *), 1119e7a19c56SJean Delvare void *private_data) 11207fce084aSJean Delvare { 11217fce084aSJean Delvare u8 *buf; 11227fce084aSJean Delvare 11237fce084aSJean Delvare if (!dmi_available) 1124c9268200SAndy Lutomirski return -ENXIO; 11257fce084aSJean Delvare 1126cf074402SArd Biesheuvel buf = dmi_remap(dmi_base, dmi_len); 11277fce084aSJean Delvare if (buf == NULL) 1128c9268200SAndy Lutomirski return -ENOMEM; 11297fce084aSJean Delvare 1130eb4c5ea5SIvan Khoronzhuk dmi_decode_table(buf, decode, private_data); 11317fce084aSJean Delvare 1132cf074402SArd Biesheuvel dmi_unmap(buf); 11337fce084aSJean Delvare return 0; 11347fce084aSJean Delvare } 11357fce084aSJean Delvare EXPORT_SYMBOL_GPL(dmi_walk); 1136d61c72e5SJiri Slaby 1137d61c72e5SJiri Slaby /** 1138d61c72e5SJiri Slaby * dmi_match - compare a string to the dmi field (if exists) 1139c2bacfc4SRandy Dunlap * @f: DMI field identifier 1140c2bacfc4SRandy Dunlap * @str: string to compare the DMI field to 1141d61c72e5SJiri Slaby * 1142d61c72e5SJiri Slaby * Returns true if the requested field equals to the str (including NULL). 1143d61c72e5SJiri Slaby */ 1144d61c72e5SJiri Slaby bool dmi_match(enum dmi_field f, const char *str) 1145d61c72e5SJiri Slaby { 1146d61c72e5SJiri Slaby const char *info = dmi_get_system_info(f); 1147d61c72e5SJiri Slaby 1148d61c72e5SJiri Slaby if (info == NULL || str == NULL) 1149d61c72e5SJiri Slaby return info == str; 1150d61c72e5SJiri Slaby 1151d61c72e5SJiri Slaby return !strcmp(info, str); 1152d61c72e5SJiri Slaby } 1153d61c72e5SJiri Slaby EXPORT_SYMBOL_GPL(dmi_match); 1154dd6dad42SChen, Gong 1155dd6dad42SChen, Gong void dmi_memdev_name(u16 handle, const char **bank, const char **device) 1156dd6dad42SChen, Gong { 1157dd6dad42SChen, Gong int n; 1158dd6dad42SChen, Gong 1159dd6dad42SChen, Gong if (dmi_memdev == NULL) 1160dd6dad42SChen, Gong return; 1161dd6dad42SChen, Gong 1162dd6dad42SChen, Gong for (n = 0; n < dmi_memdev_nr; n++) { 1163dd6dad42SChen, Gong if (handle == dmi_memdev[n].handle) { 1164dd6dad42SChen, Gong *bank = dmi_memdev[n].bank; 1165dd6dad42SChen, Gong *device = dmi_memdev[n].device; 1166dd6dad42SChen, Gong break; 1167dd6dad42SChen, Gong } 1168dd6dad42SChen, Gong } 1169dd6dad42SChen, Gong } 1170dd6dad42SChen, Gong EXPORT_SYMBOL_GPL(dmi_memdev_name); 11716deae96bSTony Luck 11726deae96bSTony Luck u64 dmi_memdev_size(u16 handle) 11736deae96bSTony Luck { 11746deae96bSTony Luck int n; 11756deae96bSTony Luck 11766deae96bSTony Luck if (dmi_memdev) { 11776deae96bSTony Luck for (n = 0; n < dmi_memdev_nr; n++) { 11786deae96bSTony Luck if (handle == dmi_memdev[n].handle) 11796deae96bSTony Luck return dmi_memdev[n].size; 11806deae96bSTony Luck } 11816deae96bSTony Luck } 11826deae96bSTony Luck return ~0ull; 11836deae96bSTony Luck } 11846deae96bSTony Luck EXPORT_SYMBOL_GPL(dmi_memdev_size); 11859e0afe39SJean Delvare 11869e0afe39SJean Delvare /** 11879e0afe39SJean Delvare * dmi_memdev_type - get the memory type 11889e0afe39SJean Delvare * @handle: DMI structure handle 11899e0afe39SJean Delvare * 11909e0afe39SJean Delvare * Return the DMI memory type of the module in the slot associated with the 11919e0afe39SJean Delvare * given DMI handle, or 0x0 if no such DMI handle exists. 11929e0afe39SJean Delvare */ 11939e0afe39SJean Delvare u8 dmi_memdev_type(u16 handle) 11949e0afe39SJean Delvare { 11959e0afe39SJean Delvare int n; 11969e0afe39SJean Delvare 11979e0afe39SJean Delvare if (dmi_memdev) { 11989e0afe39SJean Delvare for (n = 0; n < dmi_memdev_nr; n++) { 11999e0afe39SJean Delvare if (handle == dmi_memdev[n].handle) 12009e0afe39SJean Delvare return dmi_memdev[n].type; 12019e0afe39SJean Delvare } 12029e0afe39SJean Delvare } 12039e0afe39SJean Delvare return 0x0; /* Not a valid value */ 12049e0afe39SJean Delvare } 12059e0afe39SJean Delvare EXPORT_SYMBOL_GPL(dmi_memdev_type); 12067c237880SJean Delvare 12077c237880SJean Delvare /** 12087c237880SJean Delvare * dmi_memdev_handle - get the DMI handle of a memory slot 12097c237880SJean Delvare * @slot: slot number 12107c237880SJean Delvare * 12117c237880SJean Delvare * Return the DMI handle associated with a given memory slot, or %0xFFFF 12127c237880SJean Delvare * if there is no such slot. 12137c237880SJean Delvare */ 12147c237880SJean Delvare u16 dmi_memdev_handle(int slot) 12157c237880SJean Delvare { 12167c237880SJean Delvare if (dmi_memdev && slot >= 0 && slot < dmi_memdev_nr) 12177c237880SJean Delvare return dmi_memdev[slot].handle; 12187c237880SJean Delvare 12197c237880SJean Delvare return 0xffff; /* Not a valid value */ 12207c237880SJean Delvare } 12217c237880SJean Delvare EXPORT_SYMBOL_GPL(dmi_memdev_handle); 1222