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>
12*5f60d5f6SAl Viro #include <linux/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;
454d1b28a8SHeiner Kallweit static int dmi_memdev_populated_nr __initdata;
46dd6dad42SChen, Gong
dmi_string_nosave(const struct dmi_header * dm,u8 s)47f3069ae9SJean Delvare static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
484f705ae3SBjorn Helgaas {
491855256cSJeff Garzik const u8 *bp = ((u8 *) dm) + dm->length;
50a7770ae1SJean Delvare const u8 *nsp;
514f705ae3SBjorn Helgaas
524f705ae3SBjorn Helgaas if (s) {
53a7770ae1SJean Delvare while (--s > 0 && *bp)
544f705ae3SBjorn Helgaas bp += strlen(bp) + 1;
554f705ae3SBjorn Helgaas
56a7770ae1SJean Delvare /* Strings containing only spaces are considered empty */
57a7770ae1SJean Delvare nsp = bp;
58a7770ae1SJean Delvare while (*nsp == ' ')
59a7770ae1SJean Delvare nsp++;
60a7770ae1SJean Delvare if (*nsp != '\0')
61f3069ae9SJean Delvare return bp;
62f3069ae9SJean Delvare }
63f3069ae9SJean Delvare
64a7770ae1SJean Delvare return dmi_empty_string;
65f3069ae9SJean Delvare }
66f3069ae9SJean Delvare
dmi_string(const struct dmi_header * dm,u8 s)67ffbbb96dSJean Delvare static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
68f3069ae9SJean Delvare {
69f3069ae9SJean Delvare const char *bp = dmi_string_nosave(dm, s);
70f3069ae9SJean Delvare char *str;
71f3069ae9SJean Delvare size_t len;
72f3069ae9SJean Delvare
73f3069ae9SJean Delvare if (bp == dmi_empty_string)
74f3069ae9SJean Delvare return dmi_empty_string;
75f3069ae9SJean Delvare
76f3069ae9SJean Delvare len = strlen(bp) + 1;
7779da4721SParag Warudkar str = dmi_alloc(len);
784f705ae3SBjorn Helgaas if (str != NULL)
794f705ae3SBjorn Helgaas strcpy(str, bp);
804f705ae3SBjorn Helgaas
814f705ae3SBjorn Helgaas return str;
824f705ae3SBjorn Helgaas }
834f705ae3SBjorn Helgaas
844f705ae3SBjorn Helgaas /*
854f705ae3SBjorn Helgaas * We have to be cautious here. We have seen BIOSes with DMI pointers
864f705ae3SBjorn Helgaas * pointing to completely the wrong place for example
874f705ae3SBjorn Helgaas */
dmi_decode_table(u8 * buf,void (* decode)(const struct dmi_header *,void *),void * private_data)88eb4c5ea5SIvan Khoronzhuk static void dmi_decode_table(u8 *buf,
89e7a19c56SJean Delvare void (*decode)(const struct dmi_header *, void *),
90e7a19c56SJean Delvare void *private_data)
914f705ae3SBjorn Helgaas {
927fce084aSJean Delvare u8 *data = buf;
934f705ae3SBjorn Helgaas int i = 0;
944f705ae3SBjorn Helgaas
954f705ae3SBjorn Helgaas /*
96bfbaafaeSJean Delvare * Stop when we have seen all the items the table claimed to have
9717cd5bd5SJean Delvare * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS
9817cd5bd5SJean Delvare * >= 3.0 only) OR we run off the end of the table (should never
9917cd5bd5SJean Delvare * happen but sometimes does on bogus implementations.)
1004f705ae3SBjorn Helgaas */
1019c65e12aSLinus Torvalds while ((!dmi_num || i < dmi_num) &&
1029c65e12aSLinus Torvalds (data - buf + sizeof(struct dmi_header)) <= dmi_len) {
1031855256cSJeff Garzik const struct dmi_header *dm = (const struct dmi_header *)data;
1041855256cSJeff Garzik
1054f705ae3SBjorn Helgaas /*
1060ef11f60SJean Delvare * If a short entry is found (less than 4 bytes), not only it
1070ef11f60SJean Delvare * is invalid, but we cannot reliably locate the next entry.
1080ef11f60SJean Delvare */
1090ef11f60SJean Delvare if (dm->length < sizeof(struct dmi_header)) {
1100ef11f60SJean Delvare pr_warn(FW_BUG
1110ef11f60SJean Delvare "Corrupted DMI table, offset %zd (only %d entries processed)\n",
1120ef11f60SJean Delvare data - buf, i);
1130ef11f60SJean Delvare break;
1140ef11f60SJean Delvare }
1150ef11f60SJean Delvare
1160ef11f60SJean Delvare /*
1178638545cSAlan Cox * We want to know the total length (formatted area and
1188638545cSAlan Cox * strings) before decoding to make sure we won't run off the
1198638545cSAlan Cox * table in dmi_decode or dmi_string
1204f705ae3SBjorn Helgaas */
1214f705ae3SBjorn Helgaas data += dm->length;
122552e19d8SIvan Khoronzhuk while ((data - buf < dmi_len - 1) && (data[0] || data[1]))
1234f705ae3SBjorn Helgaas data++;
124552e19d8SIvan Khoronzhuk if (data - buf < dmi_len - 1)
125e7a19c56SJean Delvare decode(dm, private_data);
126ce204e9aSIvan Khoronzhuk
1276e0ad59eSJean Delvare data += 2;
1286e0ad59eSJean Delvare i++;
1296e0ad59eSJean Delvare
130ce204e9aSIvan Khoronzhuk /*
131ce204e9aSIvan Khoronzhuk * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
13217cd5bd5SJean Delvare * For tables behind a 64-bit entry point, we have no item
13317cd5bd5SJean Delvare * count and no exact table length, so stop on end-of-table
13417cd5bd5SJean Delvare * marker. For tables behind a 32-bit entry point, we have
13517cd5bd5SJean Delvare * seen OEM structures behind the end-of-table marker on
13617cd5bd5SJean Delvare * some systems, so don't trust it.
137ce204e9aSIvan Khoronzhuk */
13817cd5bd5SJean Delvare if (!dmi_num && dm->type == DMI_ENTRY_END_OF_TABLE)
139ce204e9aSIvan Khoronzhuk break;
1404f705ae3SBjorn Helgaas }
1416e0ad59eSJean Delvare
1426e0ad59eSJean Delvare /* Trim DMI table length if needed */
1436e0ad59eSJean Delvare if (dmi_len > data - buf)
1446e0ad59eSJean Delvare dmi_len = data - buf;
1457fce084aSJean Delvare }
1467fce084aSJean Delvare
147fc430262SArd Biesheuvel static phys_addr_t dmi_base;
1487fce084aSJean Delvare
dmi_walk_early(void (* decode)(const struct dmi_header *,void *))149e7a19c56SJean Delvare static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
150e7a19c56SJean Delvare void *))
1517fce084aSJean Delvare {
1527fce084aSJean Delvare u8 *buf;
1536e0ad59eSJean Delvare u32 orig_dmi_len = dmi_len;
1547fce084aSJean Delvare
1556e0ad59eSJean Delvare buf = dmi_early_remap(dmi_base, orig_dmi_len);
1567fce084aSJean Delvare if (buf == NULL)
157c9268200SAndy Lutomirski return -ENOMEM;
1587fce084aSJean Delvare
159eb4c5ea5SIvan Khoronzhuk dmi_decode_table(buf, decode, NULL);
1607fce084aSJean Delvare
161d114a333STony Luck add_device_randomness(buf, dmi_len);
162d114a333STony Luck
1636e0ad59eSJean Delvare dmi_early_unmap(buf, orig_dmi_len);
1644f705ae3SBjorn Helgaas return 0;
1654f705ae3SBjorn Helgaas }
1664f705ae3SBjorn Helgaas
dmi_checksum(const u8 * buf,u8 len)1679f9c9cbbSZhenzhong Duan static int __init dmi_checksum(const u8 *buf, u8 len)
1684f705ae3SBjorn Helgaas {
1694f705ae3SBjorn Helgaas u8 sum = 0;
1704f705ae3SBjorn Helgaas int a;
1714f705ae3SBjorn Helgaas
1729f9c9cbbSZhenzhong Duan for (a = 0; a < len; a++)
1734f705ae3SBjorn Helgaas sum += buf[a];
1744f705ae3SBjorn Helgaas
1754f705ae3SBjorn Helgaas return sum == 0;
1764f705ae3SBjorn Helgaas }
1774f705ae3SBjorn Helgaas
178ffbbb96dSJean Delvare static const char *dmi_ident[DMI_STRING_MAX];
1794f705ae3SBjorn Helgaas static LIST_HEAD(dmi_devices);
1804f5c791aSLennart Poettering int dmi_available;
181c68fded7SPierre-Louis Bossart EXPORT_SYMBOL_GPL(dmi_available);
1824f705ae3SBjorn Helgaas
1834f705ae3SBjorn Helgaas /*
1844f705ae3SBjorn Helgaas * Save a DMI string
1854f705ae3SBjorn Helgaas */
dmi_save_ident(const struct dmi_header * dm,int slot,int string)18602d9c47fSJean Delvare static void __init dmi_save_ident(const struct dmi_header *dm, int slot,
18702d9c47fSJean Delvare int string)
1884f705ae3SBjorn Helgaas {
1891855256cSJeff Garzik const char *d = (const char *) dm;
190ffbbb96dSJean Delvare const char *p;
1914f705ae3SBjorn Helgaas
192a814c359SJean Delvare if (dmi_ident[slot] || dm->length <= string)
1934f705ae3SBjorn Helgaas return;
1944f705ae3SBjorn Helgaas
1954f705ae3SBjorn Helgaas p = dmi_string(dm, d[string]);
1964f705ae3SBjorn Helgaas if (p == NULL)
1974f705ae3SBjorn Helgaas return;
1984f705ae3SBjorn Helgaas
1994f705ae3SBjorn Helgaas dmi_ident[slot] = p;
2004f705ae3SBjorn Helgaas }
2014f705ae3SBjorn Helgaas
dmi_save_release(const struct dmi_header * dm,int slot,int index)202f5152f4dSErwan Velu static void __init dmi_save_release(const struct dmi_header *dm, int slot,
203f5152f4dSErwan Velu int index)
204f5152f4dSErwan Velu {
205f5152f4dSErwan Velu const u8 *minor, *major;
206f5152f4dSErwan Velu char *s;
207f5152f4dSErwan Velu
208f5152f4dSErwan Velu /* If the table doesn't have the field, let's return */
209f5152f4dSErwan Velu if (dmi_ident[slot] || dm->length < index)
210f5152f4dSErwan Velu return;
211f5152f4dSErwan Velu
212f5152f4dSErwan Velu minor = (u8 *) dm + index;
213f5152f4dSErwan Velu major = (u8 *) dm + index - 1;
214f5152f4dSErwan Velu
215f5152f4dSErwan Velu /* As per the spec, if the system doesn't support this field,
216f5152f4dSErwan Velu * the value is FF
217f5152f4dSErwan Velu */
218f5152f4dSErwan Velu if (*major == 0xFF && *minor == 0xFF)
219f5152f4dSErwan Velu return;
220f5152f4dSErwan Velu
221f5152f4dSErwan Velu s = dmi_alloc(8);
222f5152f4dSErwan Velu if (!s)
223f5152f4dSErwan Velu return;
224f5152f4dSErwan Velu
225f5152f4dSErwan Velu sprintf(s, "%u.%u", *major, *minor);
226f5152f4dSErwan Velu
227f5152f4dSErwan Velu dmi_ident[slot] = s;
228f5152f4dSErwan Velu }
229f5152f4dSErwan Velu
dmi_save_uuid(const struct dmi_header * dm,int slot,int index)23002d9c47fSJean Delvare static void __init dmi_save_uuid(const struct dmi_header *dm, int slot,
23102d9c47fSJean Delvare int index)
2324f5c791aSLennart Poettering {
233a814c359SJean Delvare const u8 *d;
2344f5c791aSLennart Poettering char *s;
2354f5c791aSLennart Poettering int is_ff = 1, is_00 = 1, i;
2364f5c791aSLennart Poettering
23790fe6f8fSJean Delvare if (dmi_ident[slot] || dm->length < index + 16)
2384f5c791aSLennart Poettering return;
2394f5c791aSLennart Poettering
240a814c359SJean Delvare d = (u8 *) dm + index;
2414f5c791aSLennart Poettering for (i = 0; i < 16 && (is_ff || is_00); i++) {
242f1d8e614SZhenzhong Duan if (d[i] != 0x00)
243f1d8e614SZhenzhong Duan is_00 = 0;
244f1d8e614SZhenzhong Duan if (d[i] != 0xFF)
245f1d8e614SZhenzhong Duan is_ff = 0;
2464f5c791aSLennart Poettering }
2474f5c791aSLennart Poettering
2484f5c791aSLennart Poettering if (is_ff || is_00)
2494f5c791aSLennart Poettering return;
2504f5c791aSLennart Poettering
2514f5c791aSLennart Poettering s = dmi_alloc(16*2+4+1);
2524f5c791aSLennart Poettering if (!s)
2534f5c791aSLennart Poettering return;
2544f5c791aSLennart Poettering
255f1d8e614SZhenzhong Duan /*
256f1d8e614SZhenzhong Duan * As of version 2.6 of the SMBIOS specification, the first 3 fields of
257f1d8e614SZhenzhong Duan * the UUID are supposed to be little-endian encoded. The specification
258f1d8e614SZhenzhong Duan * says that this is the defacto standard.
259f1d8e614SZhenzhong Duan */
26095be58dfSIvan Khoronzhuk if (dmi_ver >= 0x020600)
261712ff254SJean Delvare sprintf(s, "%pUl", d);
262f1d8e614SZhenzhong Duan else
263712ff254SJean Delvare sprintf(s, "%pUb", d);
2644f5c791aSLennart Poettering
2654f5c791aSLennart Poettering dmi_ident[slot] = s;
2664f5c791aSLennart Poettering }
2674f5c791aSLennart Poettering
dmi_save_type(const struct dmi_header * dm,int slot,int index)26802d9c47fSJean Delvare static void __init dmi_save_type(const struct dmi_header *dm, int slot,
26902d9c47fSJean Delvare int index)
2704f5c791aSLennart Poettering {
271a814c359SJean Delvare const u8 *d;
2724f5c791aSLennart Poettering char *s;
2734f5c791aSLennart Poettering
274a814c359SJean Delvare if (dmi_ident[slot] || dm->length <= index)
2754f5c791aSLennart Poettering return;
2764f5c791aSLennart Poettering
2774f5c791aSLennart Poettering s = dmi_alloc(4);
2784f5c791aSLennart Poettering if (!s)
2794f5c791aSLennart Poettering return;
2804f5c791aSLennart Poettering
281a814c359SJean Delvare d = (u8 *) dm + index;
2824f5c791aSLennart Poettering sprintf(s, "%u", *d & 0x7F);
2834f5c791aSLennart Poettering dmi_ident[slot] = s;
2844f5c791aSLennart Poettering }
2854f5c791aSLennart Poettering
dmi_save_one_device(int type,const char * name)286f3069ae9SJean Delvare static void __init dmi_save_one_device(int type, const char *name)
287f3069ae9SJean Delvare {
288f3069ae9SJean Delvare struct dmi_device *dev;
289f3069ae9SJean Delvare
290f3069ae9SJean Delvare /* No duplicate device */
291f3069ae9SJean Delvare if (dmi_find_device(type, name, NULL))
292f3069ae9SJean Delvare return;
293f3069ae9SJean Delvare
294f3069ae9SJean Delvare dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
295ae797449SJean Delvare if (!dev)
296f3069ae9SJean Delvare return;
297f3069ae9SJean Delvare
298f3069ae9SJean Delvare dev->type = type;
299f3069ae9SJean Delvare strcpy((char *)(dev + 1), name);
300f3069ae9SJean Delvare dev->name = (char *)(dev + 1);
301f3069ae9SJean Delvare dev->device_data = NULL;
302f3069ae9SJean Delvare list_add(&dev->list, &dmi_devices);
303f3069ae9SJean Delvare }
304f3069ae9SJean Delvare
dmi_save_devices(const struct dmi_header * dm)3051855256cSJeff Garzik static void __init dmi_save_devices(const struct dmi_header *dm)
3064f705ae3SBjorn Helgaas {
3074f705ae3SBjorn Helgaas int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
3084f705ae3SBjorn Helgaas
3094f705ae3SBjorn Helgaas for (i = 0; i < count; i++) {
3101855256cSJeff Garzik const char *d = (char *)(dm + 1) + (i * 2);
3114f705ae3SBjorn Helgaas
3124f705ae3SBjorn Helgaas /* Skip disabled device */
3134f705ae3SBjorn Helgaas if ((*d & 0x80) == 0)
3144f705ae3SBjorn Helgaas continue;
3154f705ae3SBjorn Helgaas
316f3069ae9SJean Delvare dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
3172e0c1f6cSShem Multinymous }
3182e0c1f6cSShem Multinymous }
3192e0c1f6cSShem Multinymous
dmi_save_oem_strings_devices(const struct dmi_header * dm)3201855256cSJeff Garzik static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
3212e0c1f6cSShem Multinymous {
322a814c359SJean Delvare int i, count;
3232e0c1f6cSShem Multinymous struct dmi_device *dev;
3242e0c1f6cSShem Multinymous
325a814c359SJean Delvare if (dm->length < 0x05)
326a814c359SJean Delvare return;
327a814c359SJean Delvare
328a814c359SJean Delvare count = *(u8 *)(dm + 1);
3292e0c1f6cSShem Multinymous for (i = 1; i <= count; i++) {
330ffbbb96dSJean Delvare const char *devname = dmi_string(dm, i);
33179da4721SParag Warudkar
33243fe105aSJean Delvare if (devname == dmi_empty_string)
33379da4721SParag Warudkar continue;
33479da4721SParag Warudkar
3352e0c1f6cSShem Multinymous dev = dmi_alloc(sizeof(*dev));
336ae797449SJean Delvare if (!dev)
3372e0c1f6cSShem Multinymous break;
3382e0c1f6cSShem Multinymous
3392e0c1f6cSShem Multinymous dev->type = DMI_DEV_TYPE_OEM_STRING;
34079da4721SParag Warudkar dev->name = devname;
3412e0c1f6cSShem Multinymous dev->device_data = NULL;
3424f705ae3SBjorn Helgaas
3434f705ae3SBjorn Helgaas list_add(&dev->list, &dmi_devices);
3444f705ae3SBjorn Helgaas }
3454f705ae3SBjorn Helgaas }
3464f705ae3SBjorn Helgaas
dmi_save_ipmi_device(const struct dmi_header * dm)3471855256cSJeff Garzik static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
3484f705ae3SBjorn Helgaas {
3494f705ae3SBjorn Helgaas struct dmi_device *dev;
3504f705ae3SBjorn Helgaas void *data;
3514f705ae3SBjorn Helgaas
3524f705ae3SBjorn Helgaas data = dmi_alloc(dm->length);
353ae797449SJean Delvare if (data == NULL)
3544f705ae3SBjorn Helgaas return;
3554f705ae3SBjorn Helgaas
3564f705ae3SBjorn Helgaas memcpy(data, dm, dm->length);
3574f705ae3SBjorn Helgaas
3584f705ae3SBjorn Helgaas dev = dmi_alloc(sizeof(*dev));
359ae797449SJean Delvare if (!dev)
3604f705ae3SBjorn Helgaas return;
3614f705ae3SBjorn Helgaas
3624f705ae3SBjorn Helgaas dev->type = DMI_DEV_TYPE_IPMI;
3634f705ae3SBjorn Helgaas dev->name = "IPMI controller";
3644f705ae3SBjorn Helgaas dev->device_data = data;
3654f705ae3SBjorn Helgaas
366abd24df8SCarol Hebert list_add_tail(&dev->list, &dmi_devices);
3674f705ae3SBjorn Helgaas }
3684f705ae3SBjorn Helgaas
dmi_save_dev_pciaddr(int instance,int segment,int bus,int devfn,const char * name,int type)369e5b6c151SJordan Hargrave static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus,
370e5b6c151SJordan Hargrave int devfn, const char *name, int type)
371911e1c9bSNarendra K {
372e5b6c151SJordan Hargrave struct dmi_dev_onboard *dev;
373911e1c9bSNarendra K
374e5b6c151SJordan Hargrave /* Ignore invalid values */
375e5b6c151SJordan Hargrave if (type == DMI_DEV_TYPE_DEV_SLOT &&
376e5b6c151SJordan Hargrave segment == 0xFFFF && bus == 0xFF && devfn == 0xFF)
377911e1c9bSNarendra K return;
378ae797449SJean Delvare
379e5b6c151SJordan Hargrave dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
380e5b6c151SJordan Hargrave if (!dev)
381e5b6c151SJordan Hargrave return;
382911e1c9bSNarendra K
383e5b6c151SJordan Hargrave dev->instance = instance;
384e5b6c151SJordan Hargrave dev->segment = segment;
385e5b6c151SJordan Hargrave dev->bus = bus;
386e5b6c151SJordan Hargrave dev->devfn = devfn;
387911e1c9bSNarendra K
388e5b6c151SJordan Hargrave strcpy((char *)&dev[1], name);
389e5b6c151SJordan Hargrave dev->dev.type = type;
390e5b6c151SJordan Hargrave dev->dev.name = (char *)&dev[1];
391e5b6c151SJordan Hargrave dev->dev.device_data = dev;
392e5b6c151SJordan Hargrave
393e5b6c151SJordan Hargrave list_add(&dev->dev.list, &dmi_devices);
394911e1c9bSNarendra K }
395911e1c9bSNarendra K
dmi_save_extended_devices(const struct dmi_header * dm)396b4bd7d59SWim Van Sebroeck static void __init dmi_save_extended_devices(const struct dmi_header *dm)
397b4bd7d59SWim Van Sebroeck {
39896e23943SJean Delvare const char *name;
39945b98257SJean Delvare const u8 *d = (u8 *)dm;
400b4bd7d59SWim Van Sebroeck
401a814c359SJean Delvare if (dm->length < 0x0B)
402a814c359SJean Delvare return;
403a814c359SJean Delvare
404b4bd7d59SWim Van Sebroeck /* Skip disabled device */
40545b98257SJean Delvare if ((d[0x5] & 0x80) == 0)
406b4bd7d59SWim Van Sebroeck return;
407b4bd7d59SWim Van Sebroeck
40845b98257SJean Delvare name = dmi_string_nosave(dm, d[0x4]);
409e5b6c151SJordan Hargrave dmi_save_dev_pciaddr(d[0x6], *(u16 *)(d + 0x7), d[0x9], d[0xA], name,
410e5b6c151SJordan Hargrave DMI_DEV_TYPE_DEV_ONBOARD);
41145b98257SJean Delvare dmi_save_one_device(d[0x5] & 0x7f, name);
412b4bd7d59SWim Van Sebroeck }
413b4bd7d59SWim Van Sebroeck
dmi_save_system_slot(const struct dmi_header * dm)414e5b6c151SJordan Hargrave static void __init dmi_save_system_slot(const struct dmi_header *dm)
415e5b6c151SJordan Hargrave {
416e5b6c151SJordan Hargrave const u8 *d = (u8 *)dm;
417e5b6c151SJordan Hargrave
418e5b6c151SJordan Hargrave /* Need SMBIOS 2.6+ structure */
419e5b6c151SJordan Hargrave if (dm->length < 0x11)
420e5b6c151SJordan Hargrave return;
421e5b6c151SJordan Hargrave dmi_save_dev_pciaddr(*(u16 *)(d + 0x9), *(u16 *)(d + 0xD), d[0xF],
422e5b6c151SJordan Hargrave d[0x10], dmi_string_nosave(dm, d[0x4]),
423e5b6c151SJordan Hargrave DMI_DEV_TYPE_DEV_SLOT);
424e5b6c151SJordan Hargrave }
425e5b6c151SJordan Hargrave
count_mem_devices(const struct dmi_header * dm,void * v)426dd6dad42SChen, Gong static void __init count_mem_devices(const struct dmi_header *dm, void *v)
427dd6dad42SChen, Gong {
428dd6dad42SChen, Gong if (dm->type != DMI_ENTRY_MEM_DEVICE)
429dd6dad42SChen, Gong return;
430dd6dad42SChen, Gong dmi_memdev_nr++;
431dd6dad42SChen, Gong }
432dd6dad42SChen, Gong
save_mem_devices(const struct dmi_header * dm,void * v)433dd6dad42SChen, Gong static void __init save_mem_devices(const struct dmi_header *dm, void *v)
434dd6dad42SChen, Gong {
435dd6dad42SChen, Gong const char *d = (const char *)dm;
436dd6dad42SChen, Gong static int nr;
4376deae96bSTony Luck u64 bytes;
4386deae96bSTony Luck u16 size;
439dd6dad42SChen, Gong
4409e0afe39SJean Delvare if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x13)
441dd6dad42SChen, Gong return;
442dd6dad42SChen, Gong if (nr >= dmi_memdev_nr) {
443dd6dad42SChen, Gong pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n");
444dd6dad42SChen, Gong return;
445dd6dad42SChen, Gong }
4460841c04dSLuck, Tony dmi_memdev[nr].handle = get_unaligned(&dm->handle);
447dd6dad42SChen, Gong dmi_memdev[nr].device = dmi_string(dm, d[0x10]);
448dd6dad42SChen, Gong dmi_memdev[nr].bank = dmi_string(dm, d[0x11]);
4499e0afe39SJean Delvare dmi_memdev[nr].type = d[0x12];
4506deae96bSTony Luck
4516deae96bSTony Luck size = get_unaligned((u16 *)&d[0xC]);
4526deae96bSTony Luck if (size == 0)
4536deae96bSTony Luck bytes = 0;
4546deae96bSTony Luck else if (size == 0xffff)
4556deae96bSTony Luck bytes = ~0ull;
4566deae96bSTony Luck else if (size & 0x8000)
4576deae96bSTony Luck bytes = (u64)(size & 0x7fff) << 10;
45881dde26dSJean Delvare else if (size != 0x7fff || dm->length < 0x20)
4596deae96bSTony Luck bytes = (u64)size << 20;
4606deae96bSTony Luck else
4616deae96bSTony Luck bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20;
4626deae96bSTony Luck
4634d1b28a8SHeiner Kallweit if (bytes)
4644d1b28a8SHeiner Kallweit dmi_memdev_populated_nr++;
4654d1b28a8SHeiner Kallweit
4666deae96bSTony Luck dmi_memdev[nr].size = bytes;
467dd6dad42SChen, Gong nr++;
468dd6dad42SChen, Gong }
469dd6dad42SChen, Gong
dmi_memdev_walk(void)4700fca0812SRobert Richter static void __init dmi_memdev_walk(void)
471dd6dad42SChen, Gong {
472dd6dad42SChen, Gong if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) {
473dd6dad42SChen, Gong dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr);
474dd6dad42SChen, Gong if (dmi_memdev)
475dd6dad42SChen, Gong dmi_walk_early(save_mem_devices);
476dd6dad42SChen, Gong }
477dd6dad42SChen, Gong }
478dd6dad42SChen, Gong
4794f705ae3SBjorn Helgaas /*
4804f705ae3SBjorn Helgaas * Process a DMI table entry. Right now all we care about are the BIOS
4814f705ae3SBjorn Helgaas * and machine entries. For 2.5 we should pull the smbus controller info
4824f705ae3SBjorn Helgaas * out of here.
4834f705ae3SBjorn Helgaas */
dmi_decode(const struct dmi_header * dm,void * dummy)484e7a19c56SJean Delvare static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
4854f705ae3SBjorn Helgaas {
4864f705ae3SBjorn Helgaas switch (dm->type) {
4874f705ae3SBjorn Helgaas case 0: /* BIOS Information */
4884f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
4894f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
4904f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BIOS_DATE, 8);
491f5152f4dSErwan Velu dmi_save_release(dm, DMI_BIOS_RELEASE, 21);
492f5152f4dSErwan Velu dmi_save_release(dm, DMI_EC_FIRMWARE_RELEASE, 23);
4934f705ae3SBjorn Helgaas break;
4944f705ae3SBjorn Helgaas case 1: /* System Information */
4954f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
4964f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
4974f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
4984f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
4994f5c791aSLennart Poettering dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
500b23908d3SSimon Glass dmi_save_ident(dm, DMI_PRODUCT_SKU, 25);
501c61872c9SMika Westerberg dmi_save_ident(dm, DMI_PRODUCT_FAMILY, 26);
5024f705ae3SBjorn Helgaas break;
5034f705ae3SBjorn Helgaas case 2: /* Base Board Information */
5044f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
5054f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_NAME, 5);
5064f705ae3SBjorn Helgaas dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
5074f5c791aSLennart Poettering dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
5084f5c791aSLennart Poettering dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
5094f5c791aSLennart Poettering break;
5104f5c791aSLennart Poettering case 3: /* Chassis Information */
5114f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
5124f5c791aSLennart Poettering dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
5134f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
5144f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
5154f5c791aSLennart Poettering dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
5164f705ae3SBjorn Helgaas break;
517e5b6c151SJordan Hargrave case 9: /* System Slots */
518e5b6c151SJordan Hargrave dmi_save_system_slot(dm);
519e5b6c151SJordan Hargrave break;
5204f705ae3SBjorn Helgaas case 10: /* Onboard Devices Information */
5214f705ae3SBjorn Helgaas dmi_save_devices(dm);
5224f705ae3SBjorn Helgaas break;
5232e0c1f6cSShem Multinymous case 11: /* OEM Strings */
5242e0c1f6cSShem Multinymous dmi_save_oem_strings_devices(dm);
5252e0c1f6cSShem Multinymous break;
5264f705ae3SBjorn Helgaas case 38: /* IPMI Device Information */
5274f705ae3SBjorn Helgaas dmi_save_ipmi_device(dm);
528b4bd7d59SWim Van Sebroeck break;
529b4bd7d59SWim Van Sebroeck case 41: /* Onboard Devices Extended Information */
530b4bd7d59SWim Van Sebroeck dmi_save_extended_devices(dm);
5314f705ae3SBjorn Helgaas }
5324f705ae3SBjorn Helgaas }
5334f705ae3SBjorn Helgaas
print_filtered(char * buf,size_t len,const char * info)534c90fe6bcSTejun Heo static int __init print_filtered(char *buf, size_t len, const char *info)
5358881cdceSBjorn Helgaas {
536c90fe6bcSTejun Heo int c = 0;
5378881cdceSBjorn Helgaas const char *p;
5388881cdceSBjorn Helgaas
5398881cdceSBjorn Helgaas if (!info)
540c90fe6bcSTejun Heo return c;
5418881cdceSBjorn Helgaas
5428881cdceSBjorn Helgaas for (p = info; *p; p++)
5438881cdceSBjorn Helgaas if (isprint(*p))
544c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "%c", *p);
5458881cdceSBjorn Helgaas else
546c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff);
547c90fe6bcSTejun Heo return c;
5488881cdceSBjorn Helgaas }
5498881cdceSBjorn Helgaas
dmi_format_ids(char * buf,size_t len)550c90fe6bcSTejun Heo static void __init dmi_format_ids(char *buf, size_t len)
5518881cdceSBjorn Helgaas {
552c90fe6bcSTejun Heo int c = 0;
55384e383b3SNaga Chumbalkar const char *board; /* Board Name is optional */
55484e383b3SNaga Chumbalkar
555c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c,
556c90fe6bcSTejun Heo dmi_get_system_info(DMI_SYS_VENDOR));
557c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, " ");
558c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c,
559c90fe6bcSTejun Heo dmi_get_system_info(DMI_PRODUCT_NAME));
560c90fe6bcSTejun Heo
56184e383b3SNaga Chumbalkar board = dmi_get_system_info(DMI_BOARD_NAME);
56284e383b3SNaga Chumbalkar if (board) {
563c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, "/");
564c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c, board);
56584e383b3SNaga Chumbalkar }
566c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, ", BIOS ");
567c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c,
568c90fe6bcSTejun Heo dmi_get_system_info(DMI_BIOS_VERSION));
569c90fe6bcSTejun Heo c += scnprintf(buf + c, len - c, " ");
570c90fe6bcSTejun Heo c += print_filtered(buf + c, len - c,
571c90fe6bcSTejun Heo dmi_get_system_info(DMI_BIOS_DATE));
5728881cdceSBjorn Helgaas }
5738881cdceSBjorn Helgaas
574d39de28cSBen Hutchings /*
575d39de28cSBen Hutchings * Check for DMI/SMBIOS headers in the system firmware image. Any
576d39de28cSBen Hutchings * SMBIOS header must start 16 bytes before the DMI header, so take a
577d39de28cSBen Hutchings * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
578d39de28cSBen Hutchings * 0. If the DMI header is present, set dmi_ver accordingly (SMBIOS
579d39de28cSBen Hutchings * takes precedence) and return 0. Otherwise return 1.
580d39de28cSBen Hutchings */
dmi_present(const u8 * buf)58179bae42dSBen Hutchings static int __init dmi_present(const u8 *buf)
5824f705ae3SBjorn Helgaas {
58395be58dfSIvan Khoronzhuk u32 smbios_ver;
5841855256cSJeff Garzik
58513a0ac81SJean Delvare /*
58613a0ac81SJean Delvare * The size of this structure is 31 bytes, but we also accept value
58713a0ac81SJean Delvare * 30 due to a mistake in SMBIOS specification version 2.1.
58813a0ac81SJean Delvare */
58979bae42dSBen Hutchings if (memcmp(buf, "_SM_", 4) == 0 &&
59013a0ac81SJean Delvare buf[5] >= 30 && buf[5] <= 32 &&
59113a0ac81SJean Delvare dmi_checksum(buf, buf[5])) {
592fc430262SArd Biesheuvel smbios_ver = get_unaligned_be16(buf + 6);
593d7f96f97SIvan Khoronzhuk smbios_entry_point_size = buf[5];
594d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, smbios_entry_point_size);
59579bae42dSBen Hutchings
59679bae42dSBen Hutchings /* Some BIOS report weird SMBIOS version, fix that up */
59779bae42dSBen Hutchings switch (smbios_ver) {
59879bae42dSBen Hutchings case 0x021F:
59979bae42dSBen Hutchings case 0x0221:
60079bae42dSBen Hutchings pr_debug("SMBIOS version fixup (2.%d->2.%d)\n",
60179bae42dSBen Hutchings smbios_ver & 0xFF, 3);
60279bae42dSBen Hutchings smbios_ver = 0x0203;
60379bae42dSBen Hutchings break;
60479bae42dSBen Hutchings case 0x0233:
60579bae42dSBen Hutchings pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6);
60679bae42dSBen Hutchings smbios_ver = 0x0206;
60779bae42dSBen Hutchings break;
60879bae42dSBen Hutchings }
60979bae42dSBen Hutchings } else {
61079bae42dSBen Hutchings smbios_ver = 0;
61179bae42dSBen Hutchings }
61279bae42dSBen Hutchings
61379bae42dSBen Hutchings buf += 16;
61479bae42dSBen Hutchings
61579bae42dSBen Hutchings if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) {
6165c1ac56bSJean Delvare if (smbios_ver)
6175c1ac56bSJean Delvare dmi_ver = smbios_ver;
6185c1ac56bSJean Delvare else
6195c1ac56bSJean Delvare dmi_ver = (buf[14] & 0xF0) << 4 | (buf[14] & 0x0F);
620ff4319dcSAndrea Arcangeli dmi_ver <<= 8;
621fc430262SArd Biesheuvel dmi_num = get_unaligned_le16(buf + 12);
622fc430262SArd Biesheuvel dmi_len = get_unaligned_le16(buf + 6);
623fc430262SArd Biesheuvel dmi_base = get_unaligned_le32(buf + 8);
6244f705ae3SBjorn Helgaas
6258881cdceSBjorn Helgaas if (dmi_walk_early(dmi_decode) == 0) {
62679bae42dSBen Hutchings if (smbios_ver) {
627c2493045SJean Delvare pr_info("SMBIOS %d.%d present.\n",
628ff4319dcSAndrea Arcangeli dmi_ver >> 16, (dmi_ver >> 8) & 0xFF);
62979bae42dSBen Hutchings } else {
630d7f96f97SIvan Khoronzhuk smbios_entry_point_size = 15;
631d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf,
632d7f96f97SIvan Khoronzhuk smbios_entry_point_size);
6339f9c9cbbSZhenzhong Duan pr_info("Legacy DMI %d.%d present.\n",
634ff4319dcSAndrea Arcangeli dmi_ver >> 16, (dmi_ver >> 8) & 0xFF);
6359f9c9cbbSZhenzhong Duan }
636c90fe6bcSTejun Heo dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
637d4af49f8SKefeng Wang pr_info("DMI: %s\n", dmi_ids_string);
6384f705ae3SBjorn Helgaas return 0;
6394f705ae3SBjorn Helgaas }
6408881cdceSBjorn Helgaas }
6414f705ae3SBjorn Helgaas
642a40e7cf8SBen Hutchings return 1;
6439f9c9cbbSZhenzhong Duan }
6449f9c9cbbSZhenzhong Duan
645fc430262SArd Biesheuvel /*
646fc430262SArd Biesheuvel * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
647fc430262SArd Biesheuvel * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
648fc430262SArd Biesheuvel */
dmi_smbios3_present(const u8 * buf)649fc430262SArd Biesheuvel static int __init dmi_smbios3_present(const u8 *buf)
650fc430262SArd Biesheuvel {
651fc430262SArd Biesheuvel if (memcmp(buf, "_SM3_", 5) == 0 &&
65213a0ac81SJean Delvare buf[6] >= 24 && buf[6] <= 32 &&
65313a0ac81SJean Delvare dmi_checksum(buf, buf[6])) {
654d2139dfcSAndy Shevchenko dmi_ver = get_unaligned_be24(buf + 7);
655bfbaafaeSJean Delvare dmi_num = 0; /* No longer specified */
656fc430262SArd Biesheuvel dmi_len = get_unaligned_le32(buf + 12);
657fc430262SArd Biesheuvel dmi_base = get_unaligned_le64(buf + 16);
658d7f96f97SIvan Khoronzhuk smbios_entry_point_size = buf[6];
659d7f96f97SIvan Khoronzhuk memcpy(smbios_entry_point, buf, smbios_entry_point_size);
660fc430262SArd Biesheuvel
661fc430262SArd Biesheuvel if (dmi_walk_early(dmi_decode) == 0) {
66295be58dfSIvan Khoronzhuk pr_info("SMBIOS %d.%d.%d present.\n",
66395be58dfSIvan Khoronzhuk dmi_ver >> 16, (dmi_ver >> 8) & 0xFF,
66495be58dfSIvan Khoronzhuk dmi_ver & 0xFF);
665fc430262SArd Biesheuvel dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
666d4af49f8SKefeng Wang pr_info("DMI: %s\n", dmi_ids_string);
667fc430262SArd Biesheuvel return 0;
668fc430262SArd Biesheuvel }
669fc430262SArd Biesheuvel }
670fc430262SArd Biesheuvel return 1;
671fc430262SArd Biesheuvel }
672fc430262SArd Biesheuvel
dmi_scan_machine(void)6730fca0812SRobert Richter static void __init dmi_scan_machine(void)
6744f705ae3SBjorn Helgaas {
6754f705ae3SBjorn Helgaas char __iomem *p, *q;
67679bae42dSBen Hutchings char buf[32];
6774f705ae3SBjorn Helgaas
67883e68189SMatt Fleming if (efi_enabled(EFI_CONFIG_TABLES)) {
679fc430262SArd Biesheuvel /*
680fc430262SArd Biesheuvel * According to the DMTF SMBIOS reference spec v3.0.0, it is
681fc430262SArd Biesheuvel * allowed to define both the 64-bit entry point (smbios3) and
682fc430262SArd Biesheuvel * the 32-bit entry point (smbios), in which case they should
683fc430262SArd Biesheuvel * either both point to the same SMBIOS structure table, or the
684fc430262SArd Biesheuvel * table pointed to by the 64-bit entry point should contain a
685fc430262SArd Biesheuvel * superset of the table contents pointed to by the 32-bit entry
686fc430262SArd Biesheuvel * point (section 5.2)
687fc430262SArd Biesheuvel * This implies that the 64-bit entry point should have
688fc430262SArd Biesheuvel * precedence if it is defined and supported by the OS. If we
689fc430262SArd Biesheuvel * have the 64-bit entry point, but fail to decode it, fall
690fc430262SArd Biesheuvel * back to the legacy one (if available)
691fc430262SArd Biesheuvel */
692fc430262SArd Biesheuvel if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) {
693fc430262SArd Biesheuvel p = dmi_early_remap(efi.smbios3, 32);
694fc430262SArd Biesheuvel if (p == NULL)
695fc430262SArd Biesheuvel goto error;
696fc430262SArd Biesheuvel memcpy_fromio(buf, p, 32);
697fc430262SArd Biesheuvel dmi_early_unmap(p, 32);
698fc430262SArd Biesheuvel
699fc430262SArd Biesheuvel if (!dmi_smbios3_present(buf)) {
700fc430262SArd Biesheuvel dmi_available = 1;
7017117794fSJean Delvare return;
702fc430262SArd Biesheuvel }
703fc430262SArd Biesheuvel }
7044f705ae3SBjorn Helgaas if (efi.smbios == EFI_INVALID_TABLE_ADDR)
7059a22b6e7SIngo Molnar goto error;
7064f705ae3SBjorn Helgaas
7074f705ae3SBjorn Helgaas /* This is called as a core_initcall() because it isn't
7084f705ae3SBjorn Helgaas * needed during early boot. This also means we can
7094f705ae3SBjorn Helgaas * iounmap the space when we're done with it.
7104f705ae3SBjorn Helgaas */
711cf074402SArd Biesheuvel p = dmi_early_remap(efi.smbios, 32);
7124f705ae3SBjorn Helgaas if (p == NULL)
7139a22b6e7SIngo Molnar goto error;
71479bae42dSBen Hutchings memcpy_fromio(buf, p, 32);
715cf074402SArd Biesheuvel dmi_early_unmap(p, 32);
71679bae42dSBen Hutchings
71779bae42dSBen Hutchings if (!dmi_present(buf)) {
7184f5c791aSLennart Poettering dmi_available = 1;
7197117794fSJean Delvare return;
7204f705ae3SBjorn Helgaas }
721cf074402SArd Biesheuvel } else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) {
7223da27a4eSTiezhu Yang p = dmi_early_remap(SMBIOS_ENTRY_POINT_SCAN_START, 0x10000);
7234f705ae3SBjorn Helgaas if (p == NULL)
7249a22b6e7SIngo Molnar goto error;
7254f705ae3SBjorn Helgaas
726d39de28cSBen Hutchings /*
727c9aba143SJean Delvare * Same logic as above, look for a 64-bit entry point
728c9aba143SJean Delvare * first, and if not found, fall back to 32-bit entry point.
729c9aba143SJean Delvare */
730c9aba143SJean Delvare memcpy_fromio(buf, p, 16);
731c9aba143SJean Delvare for (q = p + 16; q < p + 0x10000; q += 16) {
732c9aba143SJean Delvare memcpy_fromio(buf + 16, q, 16);
733c9aba143SJean Delvare if (!dmi_smbios3_present(buf)) {
734c9aba143SJean Delvare dmi_available = 1;
735c9aba143SJean Delvare dmi_early_unmap(p, 0x10000);
7367117794fSJean Delvare return;
737c9aba143SJean Delvare }
738c9aba143SJean Delvare memcpy(buf, buf + 16, 16);
739c9aba143SJean Delvare }
740c9aba143SJean Delvare
741c9aba143SJean Delvare /*
742d39de28cSBen Hutchings * Iterate over all possible DMI header addresses q.
743d39de28cSBen Hutchings * Maintain the 32 bytes around q in buf. On the
744d39de28cSBen Hutchings * first iteration, substitute zero for the
745d39de28cSBen Hutchings * out-of-range bytes so there is no chance of falsely
746d39de28cSBen Hutchings * detecting an SMBIOS header.
747d39de28cSBen Hutchings */
74879bae42dSBen Hutchings memset(buf, 0, 16);
7494f705ae3SBjorn Helgaas for (q = p; q < p + 0x10000; q += 16) {
75079bae42dSBen Hutchings memcpy_fromio(buf + 16, q, 16);
751c9aba143SJean Delvare if (!dmi_present(buf)) {
7524f5c791aSLennart Poettering dmi_available = 1;
753cf074402SArd Biesheuvel dmi_early_unmap(p, 0x10000);
7547117794fSJean Delvare return;
7554f705ae3SBjorn Helgaas }
75679bae42dSBen Hutchings memcpy(buf, buf + 16, 16);
7574f705ae3SBjorn Helgaas }
758cf074402SArd Biesheuvel dmi_early_unmap(p, 0x10000);
7594f5c791aSLennart Poettering }
7609a22b6e7SIngo Molnar error:
76102d9c47fSJean Delvare pr_info("DMI not present or invalid.\n");
7624f705ae3SBjorn Helgaas }
7634f705ae3SBjorn Helgaas
76466bc1a17SLukas Wunner static BIN_ATTR_SIMPLE_ADMIN_RO(smbios_entry_point);
76566bc1a17SLukas Wunner static BIN_ATTR_SIMPLE_ADMIN_RO(DMI);
766d7f96f97SIvan Khoronzhuk
dmi_init(void)767d7f96f97SIvan Khoronzhuk static int __init dmi_init(void)
768d7f96f97SIvan Khoronzhuk {
769d7f96f97SIvan Khoronzhuk struct kobject *tables_kobj;
770d7f96f97SIvan Khoronzhuk u8 *dmi_table;
771d7f96f97SIvan Khoronzhuk int ret = -ENOMEM;
772d7f96f97SIvan Khoronzhuk
773a81114d0SArd Biesheuvel if (!dmi_available)
774a81114d0SArd Biesheuvel return 0;
775d7f96f97SIvan Khoronzhuk
776d7f96f97SIvan Khoronzhuk /*
777d7f96f97SIvan Khoronzhuk * Set up dmi directory at /sys/firmware/dmi. This entry should stay
778d7f96f97SIvan Khoronzhuk * even after farther error, as it can be used by other modules like
779d7f96f97SIvan Khoronzhuk * dmi-sysfs.
780d7f96f97SIvan Khoronzhuk */
781d7f96f97SIvan Khoronzhuk dmi_kobj = kobject_create_and_add("dmi", firmware_kobj);
782d7f96f97SIvan Khoronzhuk if (!dmi_kobj)
783d7f96f97SIvan Khoronzhuk goto err;
784d7f96f97SIvan Khoronzhuk
785d7f96f97SIvan Khoronzhuk tables_kobj = kobject_create_and_add("tables", dmi_kobj);
786d7f96f97SIvan Khoronzhuk if (!tables_kobj)
787d7f96f97SIvan Khoronzhuk goto err;
788d7f96f97SIvan Khoronzhuk
789d7f96f97SIvan Khoronzhuk dmi_table = dmi_remap(dmi_base, dmi_len);
790d7f96f97SIvan Khoronzhuk if (!dmi_table)
791d7f96f97SIvan Khoronzhuk goto err_tables;
792d7f96f97SIvan Khoronzhuk
793d7f96f97SIvan Khoronzhuk bin_attr_smbios_entry_point.size = smbios_entry_point_size;
794d7f96f97SIvan Khoronzhuk bin_attr_smbios_entry_point.private = smbios_entry_point;
795d7f96f97SIvan Khoronzhuk ret = sysfs_create_bin_file(tables_kobj, &bin_attr_smbios_entry_point);
796d7f96f97SIvan Khoronzhuk if (ret)
797d7f96f97SIvan Khoronzhuk goto err_unmap;
798d7f96f97SIvan Khoronzhuk
799d7f96f97SIvan Khoronzhuk bin_attr_DMI.size = dmi_len;
800d7f96f97SIvan Khoronzhuk bin_attr_DMI.private = dmi_table;
801d7f96f97SIvan Khoronzhuk ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI);
802d7f96f97SIvan Khoronzhuk if (!ret)
803d7f96f97SIvan Khoronzhuk return 0;
804d7f96f97SIvan Khoronzhuk
805d7f96f97SIvan Khoronzhuk sysfs_remove_bin_file(tables_kobj,
806d7f96f97SIvan Khoronzhuk &bin_attr_smbios_entry_point);
807d7f96f97SIvan Khoronzhuk err_unmap:
808d7f96f97SIvan Khoronzhuk dmi_unmap(dmi_table);
809d7f96f97SIvan Khoronzhuk err_tables:
810d7f96f97SIvan Khoronzhuk kobject_del(tables_kobj);
811d7f96f97SIvan Khoronzhuk kobject_put(tables_kobj);
812d7f96f97SIvan Khoronzhuk err:
813d7f96f97SIvan Khoronzhuk pr_err("dmi: Firmware registration failed.\n");
814d7f96f97SIvan Khoronzhuk
815d7f96f97SIvan Khoronzhuk return ret;
816d7f96f97SIvan Khoronzhuk }
817d7f96f97SIvan Khoronzhuk subsys_initcall(dmi_init);
818d7f96f97SIvan Khoronzhuk
8194f705ae3SBjorn Helgaas /**
8200fca0812SRobert Richter * dmi_setup - scan and setup DMI system information
82198e5e1bfSTejun Heo *
8220fca0812SRobert Richter * Scan the DMI system information. This setups DMI identifiers
8230fca0812SRobert Richter * (dmi_system_id) for printing it out on task dumps and prepares
8240fca0812SRobert Richter * DIMM entry information (dmi_memdev_info) from the SMBIOS table
8250fca0812SRobert Richter * for using this when reporting memory errors.
82698e5e1bfSTejun Heo */
dmi_setup(void)8270fca0812SRobert Richter void __init dmi_setup(void)
82898e5e1bfSTejun Heo {
8290fca0812SRobert Richter dmi_scan_machine();
8300fca0812SRobert Richter if (!dmi_available)
8310fca0812SRobert Richter return;
8320fca0812SRobert Richter
8330fca0812SRobert Richter dmi_memdev_walk();
8344d1b28a8SHeiner Kallweit pr_info("DMI: Memory slots populated: %d/%d\n",
8354d1b28a8SHeiner Kallweit dmi_memdev_populated_nr, dmi_memdev_nr);
83698e5e1bfSTejun Heo dump_stack_set_arch_desc("%s", dmi_ids_string);
83798e5e1bfSTejun Heo }
83898e5e1bfSTejun Heo
83998e5e1bfSTejun Heo /**
840d7b1956fSRafael J. Wysocki * dmi_matches - check if dmi_system_id structure matches system DMI data
841d7b1956fSRafael J. Wysocki * @dmi: pointer to the dmi_system_id structure to check
842d7b1956fSRafael J. Wysocki */
dmi_matches(const struct dmi_system_id * dmi)843d7b1956fSRafael J. Wysocki static bool dmi_matches(const struct dmi_system_id *dmi)
844d7b1956fSRafael J. Wysocki {
845d7b1956fSRafael J. Wysocki int i;
846d7b1956fSRafael J. Wysocki
847d7b1956fSRafael J. Wysocki for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
848d7b1956fSRafael J. Wysocki int s = dmi->matches[i].slot;
849d7b1956fSRafael J. Wysocki if (s == DMI_NONE)
85075757507SDmitry Torokhov break;
851de40614dSAlex Hung if (s == DMI_OEM_STRING) {
852de40614dSAlex Hung /* DMI_OEM_STRING must be exact match */
853de40614dSAlex Hung const struct dmi_device *valid;
854de40614dSAlex Hung
855de40614dSAlex Hung valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
856de40614dSAlex Hung dmi->matches[i].substr, NULL);
857de40614dSAlex Hung if (valid)
858de40614dSAlex Hung continue;
859de40614dSAlex Hung } else if (dmi_ident[s]) {
8608cf4e6a0SJean Delvare if (dmi->matches[i].exact_match) {
8618cf4e6a0SJean Delvare if (!strcmp(dmi_ident[s],
8628cf4e6a0SJean Delvare dmi->matches[i].substr))
863d7b1956fSRafael J. Wysocki continue;
8648cf4e6a0SJean Delvare } else {
8658cf4e6a0SJean Delvare if (strstr(dmi_ident[s],
8668cf4e6a0SJean Delvare dmi->matches[i].substr))
8675017b285SJani Nikula continue;
8685017b285SJani Nikula }
8698cf4e6a0SJean Delvare }
8705017b285SJani Nikula
871d7b1956fSRafael J. Wysocki /* No match */
872d7b1956fSRafael J. Wysocki return false;
873d7b1956fSRafael J. Wysocki }
874d7b1956fSRafael J. Wysocki return true;
875d7b1956fSRafael J. Wysocki }
876d7b1956fSRafael J. Wysocki
877d7b1956fSRafael J. Wysocki /**
87875757507SDmitry Torokhov * dmi_is_end_of_table - check for end-of-table marker
87975757507SDmitry Torokhov * @dmi: pointer to the dmi_system_id structure to check
88075757507SDmitry Torokhov */
dmi_is_end_of_table(const struct dmi_system_id * dmi)88175757507SDmitry Torokhov static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
88275757507SDmitry Torokhov {
88375757507SDmitry Torokhov return dmi->matches[0].slot == DMI_NONE;
88475757507SDmitry Torokhov }
88575757507SDmitry Torokhov
88675757507SDmitry Torokhov /**
8874f705ae3SBjorn Helgaas * dmi_check_system - check system DMI data
8884f705ae3SBjorn Helgaas * @list: array of dmi_system_id structures to match against
889b0ef371eSRandy Dunlap * All non-null elements of the list must match
890b0ef371eSRandy Dunlap * their slot's (field index's) data (i.e., each
891b0ef371eSRandy Dunlap * list string must be a substring of the specified
892b0ef371eSRandy Dunlap * DMI slot's string data) to be considered a
893b0ef371eSRandy Dunlap * successful match.
8944f705ae3SBjorn Helgaas *
8954f705ae3SBjorn Helgaas * Walk the blacklist table running matching functions until someone
8964f705ae3SBjorn Helgaas * returns non zero or we hit the end. Callback function is called for
897b0ef371eSRandy Dunlap * each successful match. Returns the number of matches.
8987117794fSJean Delvare *
8990fca0812SRobert Richter * dmi_setup must be called before this function is called.
9004f705ae3SBjorn Helgaas */
dmi_check_system(const struct dmi_system_id * list)9011855256cSJeff Garzik int dmi_check_system(const struct dmi_system_id *list)
9024f705ae3SBjorn Helgaas {
903d7b1956fSRafael J. Wysocki int count = 0;
904d7b1956fSRafael J. Wysocki const struct dmi_system_id *d;
9054f705ae3SBjorn Helgaas
90675757507SDmitry Torokhov for (d = list; !dmi_is_end_of_table(d); d++)
907d7b1956fSRafael J. Wysocki if (dmi_matches(d)) {
9084f705ae3SBjorn Helgaas count++;
9094f705ae3SBjorn Helgaas if (d->callback && d->callback(d))
9104f705ae3SBjorn Helgaas break;
9114f705ae3SBjorn Helgaas }
9124f705ae3SBjorn Helgaas
9134f705ae3SBjorn Helgaas return count;
9144f705ae3SBjorn Helgaas }
9154f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_check_system);
9164f705ae3SBjorn Helgaas
9174f705ae3SBjorn Helgaas /**
918d7b1956fSRafael J. Wysocki * dmi_first_match - find dmi_system_id structure matching system DMI data
919d7b1956fSRafael J. Wysocki * @list: array of dmi_system_id structures to match against
920d7b1956fSRafael J. Wysocki * All non-null elements of the list must match
921d7b1956fSRafael J. Wysocki * their slot's (field index's) data (i.e., each
922d7b1956fSRafael J. Wysocki * list string must be a substring of the specified
923d7b1956fSRafael J. Wysocki * DMI slot's string data) to be considered a
924d7b1956fSRafael J. Wysocki * successful match.
925d7b1956fSRafael J. Wysocki *
926d7b1956fSRafael J. Wysocki * Walk the blacklist table until the first match is found. Return the
927d7b1956fSRafael J. Wysocki * pointer to the matching entry or NULL if there's no match.
9287117794fSJean Delvare *
9290fca0812SRobert Richter * dmi_setup must be called before this function is called.
930d7b1956fSRafael J. Wysocki */
dmi_first_match(const struct dmi_system_id * list)931d7b1956fSRafael J. Wysocki const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
932d7b1956fSRafael J. Wysocki {
933d7b1956fSRafael J. Wysocki const struct dmi_system_id *d;
934d7b1956fSRafael J. Wysocki
93575757507SDmitry Torokhov for (d = list; !dmi_is_end_of_table(d); d++)
936d7b1956fSRafael J. Wysocki if (dmi_matches(d))
937d7b1956fSRafael J. Wysocki return d;
938d7b1956fSRafael J. Wysocki
939d7b1956fSRafael J. Wysocki return NULL;
940d7b1956fSRafael J. Wysocki }
941d7b1956fSRafael J. Wysocki EXPORT_SYMBOL(dmi_first_match);
942d7b1956fSRafael J. Wysocki
943d7b1956fSRafael J. Wysocki /**
9444f705ae3SBjorn Helgaas * dmi_get_system_info - return DMI data value
945b0ef371eSRandy Dunlap * @field: data index (see enum dmi_field)
9464f705ae3SBjorn Helgaas *
9474f705ae3SBjorn Helgaas * Returns one DMI data value, can be used to perform
9484f705ae3SBjorn Helgaas * complex DMI data checks.
9494f705ae3SBjorn Helgaas */
dmi_get_system_info(int field)9501855256cSJeff Garzik const char *dmi_get_system_info(int field)
9514f705ae3SBjorn Helgaas {
9524f705ae3SBjorn Helgaas return dmi_ident[field];
9534f705ae3SBjorn Helgaas }
9544f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_get_system_info);
9554f705ae3SBjorn Helgaas
956fd8cd7e1SAlok Kataria /**
957c2bacfc4SRandy Dunlap * dmi_name_in_serial - Check if string is in the DMI product serial information
958c2bacfc4SRandy Dunlap * @str: string to check for
959fd8cd7e1SAlok Kataria */
dmi_name_in_serial(const char * str)960fd8cd7e1SAlok Kataria int dmi_name_in_serial(const char *str)
961fd8cd7e1SAlok Kataria {
962fd8cd7e1SAlok Kataria int f = DMI_PRODUCT_SERIAL;
963fd8cd7e1SAlok Kataria if (dmi_ident[f] && strstr(dmi_ident[f], str))
964fd8cd7e1SAlok Kataria return 1;
965fd8cd7e1SAlok Kataria return 0;
966fd8cd7e1SAlok Kataria }
967a1bae672SAndi Kleen
968a1bae672SAndi Kleen /**
96966e13e66SJean Delvare * dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
970a1bae672SAndi Kleen * @str: Case sensitive Name
971a1bae672SAndi Kleen */
dmi_name_in_vendors(const char * str)9721855256cSJeff Garzik int dmi_name_in_vendors(const char *str)
973a1bae672SAndi Kleen {
97466e13e66SJean Delvare static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
975a1bae672SAndi Kleen int i;
976a1bae672SAndi Kleen for (i = 0; fields[i] != DMI_NONE; i++) {
977a1bae672SAndi Kleen int f = fields[i];
978a1bae672SAndi Kleen if (dmi_ident[f] && strstr(dmi_ident[f], str))
979a1bae672SAndi Kleen return 1;
980a1bae672SAndi Kleen }
981a1bae672SAndi Kleen return 0;
982a1bae672SAndi Kleen }
983a1bae672SAndi Kleen EXPORT_SYMBOL(dmi_name_in_vendors);
984a1bae672SAndi Kleen
9854f705ae3SBjorn Helgaas /**
9864f705ae3SBjorn Helgaas * dmi_find_device - find onboard device by type/name
9874f705ae3SBjorn Helgaas * @type: device type or %DMI_DEV_TYPE_ANY to match all device types
988b0ef371eSRandy Dunlap * @name: device name string or %NULL to match all
9894f705ae3SBjorn Helgaas * @from: previous device found in search, or %NULL for new search.
9904f705ae3SBjorn Helgaas *
9914f705ae3SBjorn Helgaas * Iterates through the list of known onboard devices. If a device is
992bfab8b48SJean Delvare * found with a matching @type and @name, a pointer to its device
9934f705ae3SBjorn Helgaas * structure is returned. Otherwise, %NULL is returned.
994b0ef371eSRandy Dunlap * A new search is initiated by passing %NULL as the @from argument.
9954f705ae3SBjorn Helgaas * If @from is not %NULL, searches continue from next device.
9964f705ae3SBjorn Helgaas */
dmi_find_device(int type,const char * name,const struct dmi_device * from)9971855256cSJeff Garzik const struct dmi_device *dmi_find_device(int type, const char *name,
9981855256cSJeff Garzik const struct dmi_device *from)
9994f705ae3SBjorn Helgaas {
10001855256cSJeff Garzik const struct list_head *head = from ? &from->list : &dmi_devices;
10011855256cSJeff Garzik struct list_head *d;
10024f705ae3SBjorn Helgaas
10034f705ae3SBjorn Helgaas for (d = head->next; d != &dmi_devices; d = d->next) {
10041855256cSJeff Garzik const struct dmi_device *dev =
10051855256cSJeff Garzik list_entry(d, struct dmi_device, list);
10064f705ae3SBjorn Helgaas
10074f705ae3SBjorn Helgaas if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
10084f705ae3SBjorn Helgaas ((name == NULL) || (strcmp(dev->name, name) == 0)))
10094f705ae3SBjorn Helgaas return dev;
10104f705ae3SBjorn Helgaas }
10114f705ae3SBjorn Helgaas
10124f705ae3SBjorn Helgaas return NULL;
10134f705ae3SBjorn Helgaas }
10144f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_find_device);
10154f705ae3SBjorn Helgaas
10164f705ae3SBjorn Helgaas /**
10173e5cd1f2STejun Heo * dmi_get_date - parse a DMI date
10183e5cd1f2STejun Heo * @field: data index (see enum dmi_field)
10193e5cd1f2STejun Heo * @yearp: optional out parameter for the year
10203e5cd1f2STejun Heo * @monthp: optional out parameter for the month
10213e5cd1f2STejun Heo * @dayp: optional out parameter for the day
10224f705ae3SBjorn Helgaas *
10233e5cd1f2STejun Heo * The date field is assumed to be in the form resembling
10243e5cd1f2STejun Heo * [mm[/dd]]/yy[yy] and the result is stored in the out
10253e5cd1f2STejun Heo * parameters any or all of which can be omitted.
10263e5cd1f2STejun Heo *
10273e5cd1f2STejun Heo * If the field doesn't exist, all out parameters are set to zero
10283e5cd1f2STejun Heo * and false is returned. Otherwise, true is returned with any
10293e5cd1f2STejun Heo * invalid part of date set to zero.
10303e5cd1f2STejun Heo *
10313e5cd1f2STejun Heo * On return, year, month and day are guaranteed to be in the
10323e5cd1f2STejun Heo * range of [0,9999], [0,12] and [0,31] respectively.
10334f705ae3SBjorn Helgaas */
dmi_get_date(int field,int * yearp,int * monthp,int * dayp)10343e5cd1f2STejun Heo bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
10354f705ae3SBjorn Helgaas {
10363e5cd1f2STejun Heo int year = 0, month = 0, day = 0;
10373e5cd1f2STejun Heo bool exists;
10383e5cd1f2STejun Heo const char *s, *y;
103902c24fa8STejun Heo char *e;
10404f705ae3SBjorn Helgaas
10413e5cd1f2STejun Heo s = dmi_get_system_info(field);
10423e5cd1f2STejun Heo exists = s;
10433e5cd1f2STejun Heo if (!exists)
10443e5cd1f2STejun Heo goto out;
10454f705ae3SBjorn Helgaas
10463e5cd1f2STejun Heo /*
10473e5cd1f2STejun Heo * Determine year first. We assume the date string resembles
10483e5cd1f2STejun Heo * mm/dd/yy[yy] but the original code extracted only the year
10493e5cd1f2STejun Heo * from the end. Keep the behavior in the spirit of no
10503e5cd1f2STejun Heo * surprises.
10513e5cd1f2STejun Heo */
10523e5cd1f2STejun Heo y = strrchr(s, '/');
10533e5cd1f2STejun Heo if (!y)
10543e5cd1f2STejun Heo goto out;
10553e5cd1f2STejun Heo
10563e5cd1f2STejun Heo y++;
10573e5cd1f2STejun Heo year = simple_strtoul(y, &e, 10);
10583e5cd1f2STejun Heo if (y != e && year < 100) { /* 2-digit year */
10594f705ae3SBjorn Helgaas year += 1900;
10604f705ae3SBjorn Helgaas if (year < 1996) /* no dates < spec 1.0 */
10614f705ae3SBjorn Helgaas year += 100;
10624f705ae3SBjorn Helgaas }
10633e5cd1f2STejun Heo if (year > 9999) /* year should fit in %04d */
10643e5cd1f2STejun Heo year = 0;
10654f705ae3SBjorn Helgaas
10663e5cd1f2STejun Heo /* parse the mm and dd */
10673e5cd1f2STejun Heo month = simple_strtoul(s, &e, 10);
10683e5cd1f2STejun Heo if (s == e || *e != '/' || !month || month > 12) {
10693e5cd1f2STejun Heo month = 0;
10703e5cd1f2STejun Heo goto out;
10714f705ae3SBjorn Helgaas }
10723e5cd1f2STejun Heo
10733e5cd1f2STejun Heo s = e + 1;
10743e5cd1f2STejun Heo day = simple_strtoul(s, &e, 10);
10753e5cd1f2STejun Heo if (s == y || s == e || *e != '/' || day > 31)
10763e5cd1f2STejun Heo day = 0;
10773e5cd1f2STejun Heo out:
10783e5cd1f2STejun Heo if (yearp)
10793e5cd1f2STejun Heo *yearp = year;
10803e5cd1f2STejun Heo if (monthp)
10813e5cd1f2STejun Heo *monthp = month;
10823e5cd1f2STejun Heo if (dayp)
10833e5cd1f2STejun Heo *dayp = day;
10843e5cd1f2STejun Heo return exists;
10853e5cd1f2STejun Heo }
10863e5cd1f2STejun Heo EXPORT_SYMBOL(dmi_get_date);
10877fce084aSJean Delvare
10887fce084aSJean Delvare /**
10893af34525SAndy Shevchenko * dmi_get_bios_year - get a year out of DMI_BIOS_DATE field
10903af34525SAndy Shevchenko *
10913af34525SAndy Shevchenko * Returns year on success, -ENXIO if DMI is not selected,
10923af34525SAndy Shevchenko * or a different negative error code if DMI field is not present
10933af34525SAndy Shevchenko * or not parseable.
10943af34525SAndy Shevchenko */
dmi_get_bios_year(void)10953af34525SAndy Shevchenko int dmi_get_bios_year(void)
10963af34525SAndy Shevchenko {
10973af34525SAndy Shevchenko bool exists;
10983af34525SAndy Shevchenko int year;
10993af34525SAndy Shevchenko
11003af34525SAndy Shevchenko exists = dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL);
11013af34525SAndy Shevchenko if (!exists)
11023af34525SAndy Shevchenko return -ENODATA;
11033af34525SAndy Shevchenko
11043af34525SAndy Shevchenko return year ? year : -ERANGE;
11053af34525SAndy Shevchenko }
11063af34525SAndy Shevchenko EXPORT_SYMBOL(dmi_get_bios_year);
11073af34525SAndy Shevchenko
11083af34525SAndy Shevchenko /**
11097fce084aSJean Delvare * dmi_walk - Walk the DMI table and get called back for every record
11107fce084aSJean Delvare * @decode: Callback function
1111e7a19c56SJean Delvare * @private_data: Private data to be passed to the callback function
11127fce084aSJean Delvare *
1113c9268200SAndy Lutomirski * Returns 0 on success, -ENXIO if DMI is not selected or not present,
1114c9268200SAndy Lutomirski * or a different negative error code if DMI walking fails.
11157fce084aSJean Delvare */
dmi_walk(void (* decode)(const struct dmi_header *,void *),void * private_data)1116e7a19c56SJean Delvare int dmi_walk(void (*decode)(const struct dmi_header *, void *),
1117e7a19c56SJean Delvare void *private_data)
11187fce084aSJean Delvare {
11197fce084aSJean Delvare u8 *buf;
11207fce084aSJean Delvare
11217fce084aSJean Delvare if (!dmi_available)
1122c9268200SAndy Lutomirski return -ENXIO;
11237fce084aSJean Delvare
1124cf074402SArd Biesheuvel buf = dmi_remap(dmi_base, dmi_len);
11257fce084aSJean Delvare if (buf == NULL)
1126c9268200SAndy Lutomirski return -ENOMEM;
11277fce084aSJean Delvare
1128eb4c5ea5SIvan Khoronzhuk dmi_decode_table(buf, decode, private_data);
11297fce084aSJean Delvare
1130cf074402SArd Biesheuvel dmi_unmap(buf);
11317fce084aSJean Delvare return 0;
11327fce084aSJean Delvare }
11337fce084aSJean Delvare EXPORT_SYMBOL_GPL(dmi_walk);
1134d61c72e5SJiri Slaby
1135d61c72e5SJiri Slaby /**
1136d61c72e5SJiri Slaby * dmi_match - compare a string to the dmi field (if exists)
1137c2bacfc4SRandy Dunlap * @f: DMI field identifier
1138c2bacfc4SRandy Dunlap * @str: string to compare the DMI field to
1139d61c72e5SJiri Slaby *
1140d61c72e5SJiri Slaby * Returns true if the requested field equals to the str (including NULL).
1141d61c72e5SJiri Slaby */
dmi_match(enum dmi_field f,const char * str)1142d61c72e5SJiri Slaby bool dmi_match(enum dmi_field f, const char *str)
1143d61c72e5SJiri Slaby {
1144d61c72e5SJiri Slaby const char *info = dmi_get_system_info(f);
1145d61c72e5SJiri Slaby
1146d61c72e5SJiri Slaby if (info == NULL || str == NULL)
1147d61c72e5SJiri Slaby return info == str;
1148d61c72e5SJiri Slaby
1149d61c72e5SJiri Slaby return !strcmp(info, str);
1150d61c72e5SJiri Slaby }
1151d61c72e5SJiri Slaby EXPORT_SYMBOL_GPL(dmi_match);
1152dd6dad42SChen, Gong
dmi_memdev_name(u16 handle,const char ** bank,const char ** device)1153dd6dad42SChen, Gong void dmi_memdev_name(u16 handle, const char **bank, const char **device)
1154dd6dad42SChen, Gong {
1155dd6dad42SChen, Gong int n;
1156dd6dad42SChen, Gong
1157dd6dad42SChen, Gong if (dmi_memdev == NULL)
1158dd6dad42SChen, Gong return;
1159dd6dad42SChen, Gong
1160dd6dad42SChen, Gong for (n = 0; n < dmi_memdev_nr; n++) {
1161dd6dad42SChen, Gong if (handle == dmi_memdev[n].handle) {
1162dd6dad42SChen, Gong *bank = dmi_memdev[n].bank;
1163dd6dad42SChen, Gong *device = dmi_memdev[n].device;
1164dd6dad42SChen, Gong break;
1165dd6dad42SChen, Gong }
1166dd6dad42SChen, Gong }
1167dd6dad42SChen, Gong }
1168dd6dad42SChen, Gong EXPORT_SYMBOL_GPL(dmi_memdev_name);
11696deae96bSTony Luck
dmi_memdev_size(u16 handle)11706deae96bSTony Luck u64 dmi_memdev_size(u16 handle)
11716deae96bSTony Luck {
11726deae96bSTony Luck int n;
11736deae96bSTony Luck
11746deae96bSTony Luck if (dmi_memdev) {
11756deae96bSTony Luck for (n = 0; n < dmi_memdev_nr; n++) {
11766deae96bSTony Luck if (handle == dmi_memdev[n].handle)
11776deae96bSTony Luck return dmi_memdev[n].size;
11786deae96bSTony Luck }
11796deae96bSTony Luck }
11806deae96bSTony Luck return ~0ull;
11816deae96bSTony Luck }
11826deae96bSTony Luck EXPORT_SYMBOL_GPL(dmi_memdev_size);
11839e0afe39SJean Delvare
11849e0afe39SJean Delvare /**
11859e0afe39SJean Delvare * dmi_memdev_type - get the memory type
11869e0afe39SJean Delvare * @handle: DMI structure handle
11879e0afe39SJean Delvare *
11889e0afe39SJean Delvare * Return the DMI memory type of the module in the slot associated with the
11899e0afe39SJean Delvare * given DMI handle, or 0x0 if no such DMI handle exists.
11909e0afe39SJean Delvare */
dmi_memdev_type(u16 handle)11919e0afe39SJean Delvare u8 dmi_memdev_type(u16 handle)
11929e0afe39SJean Delvare {
11939e0afe39SJean Delvare int n;
11949e0afe39SJean Delvare
11959e0afe39SJean Delvare if (dmi_memdev) {
11969e0afe39SJean Delvare for (n = 0; n < dmi_memdev_nr; n++) {
11979e0afe39SJean Delvare if (handle == dmi_memdev[n].handle)
11989e0afe39SJean Delvare return dmi_memdev[n].type;
11999e0afe39SJean Delvare }
12009e0afe39SJean Delvare }
12019e0afe39SJean Delvare return 0x0; /* Not a valid value */
12029e0afe39SJean Delvare }
12039e0afe39SJean Delvare EXPORT_SYMBOL_GPL(dmi_memdev_type);
12047c237880SJean Delvare
12057c237880SJean Delvare /**
12067c237880SJean Delvare * dmi_memdev_handle - get the DMI handle of a memory slot
12077c237880SJean Delvare * @slot: slot number
12087c237880SJean Delvare *
12097c237880SJean Delvare * Return the DMI handle associated with a given memory slot, or %0xFFFF
12107c237880SJean Delvare * if there is no such slot.
12117c237880SJean Delvare */
dmi_memdev_handle(int slot)12127c237880SJean Delvare u16 dmi_memdev_handle(int slot)
12137c237880SJean Delvare {
12147c237880SJean Delvare if (dmi_memdev && slot >= 0 && slot < dmi_memdev_nr)
12157c237880SJean Delvare return dmi_memdev[slot].handle;
12167c237880SJean Delvare
12177c237880SJean Delvare return 0xffff; /* Not a valid value */
12187c237880SJean Delvare }
12197c237880SJean Delvare EXPORT_SYMBOL_GPL(dmi_memdev_handle);
1220