xref: /linux/drivers/firmware/dmi_scan.c (revision 712ff25450bd01366301eef81c33e865d901e7b7)
14f705ae3SBjorn Helgaas #include <linux/types.h>
24f705ae3SBjorn Helgaas #include <linux/string.h>
34f705ae3SBjorn Helgaas #include <linux/init.h>
44f705ae3SBjorn Helgaas #include <linux/module.h>
58881cdceSBjorn Helgaas #include <linux/ctype.h>
64f705ae3SBjorn Helgaas #include <linux/dmi.h>
74f705ae3SBjorn Helgaas #include <linux/efi.h>
84f705ae3SBjorn Helgaas #include <linux/bootmem.h>
9d114a333STony Luck #include <linux/random.h>
104f705ae3SBjorn Helgaas #include <asm/dmi.h>
110841c04dSLuck, Tony #include <asm/unaligned.h>
124f705ae3SBjorn Helgaas 
13d7f96f97SIvan Khoronzhuk struct kobject *dmi_kobj;
14d7f96f97SIvan Khoronzhuk EXPORT_SYMBOL_GPL(dmi_kobj);
15d7f96f97SIvan Khoronzhuk 
16cb5dd7c1SPaul Jackson /*
17cb5dd7c1SPaul Jackson  * DMI stands for "Desktop Management Interface".  It is part
18cb5dd7c1SPaul Jackson  * of and an antecedent to, SMBIOS, which stands for System
19cb5dd7c1SPaul Jackson  * Management BIOS.  See further: http://www.dmtf.org/standards
20cb5dd7c1SPaul Jackson  */
21ffbbb96dSJean Delvare static const char dmi_empty_string[] = "";
2279da4721SParag Warudkar 
2395be58dfSIvan Khoronzhuk static u32 dmi_ver __initdata;
24552e19d8SIvan Khoronzhuk static u32 dmi_len;
25552e19d8SIvan Khoronzhuk static u16 dmi_num;
26d7f96f97SIvan Khoronzhuk static u8 smbios_entry_point[32];
27d7f96f97SIvan Khoronzhuk static int smbios_entry_point_size;
28d7f96f97SIvan Khoronzhuk 
29c90fe6bcSTejun Heo /* DMI system identification string used during boot */
30c90fe6bcSTejun Heo static char dmi_ids_string[128] __initdata;
31c90fe6bcSTejun Heo 
32dd6dad42SChen, Gong static struct dmi_memdev_info {
33dd6dad42SChen, Gong 	const char *device;
34dd6dad42SChen, Gong 	const char *bank;
35dd6dad42SChen, Gong 	u16 handle;
36dd6dad42SChen, Gong } *dmi_memdev;
37dd6dad42SChen, Gong static int dmi_memdev_nr;
38dd6dad42SChen, Gong 
39f3069ae9SJean Delvare static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
404f705ae3SBjorn Helgaas {
411855256cSJeff Garzik 	const u8 *bp = ((u8 *) dm) + dm->length;
42a7770ae1SJean Delvare 	const u8 *nsp;
434f705ae3SBjorn Helgaas 
444f705ae3SBjorn Helgaas 	if (s) {
45a7770ae1SJean Delvare 		while (--s > 0 && *bp)
464f705ae3SBjorn Helgaas 			bp += strlen(bp) + 1;
474f705ae3SBjorn Helgaas 
48a7770ae1SJean Delvare 		/* Strings containing only spaces are considered empty */
49a7770ae1SJean Delvare 		nsp = bp;
50a7770ae1SJean Delvare 		while (*nsp == ' ')
51a7770ae1SJean Delvare 			nsp++;
52a7770ae1SJean Delvare 		if (*nsp != '\0')
53f3069ae9SJean Delvare 			return bp;
54f3069ae9SJean Delvare 	}
55f3069ae9SJean Delvare 
56a7770ae1SJean Delvare 	return dmi_empty_string;
57f3069ae9SJean Delvare }
58f3069ae9SJean Delvare 
59ffbbb96dSJean Delvare static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
60f3069ae9SJean Delvare {
61f3069ae9SJean Delvare 	const char *bp = dmi_string_nosave(dm, s);
62f3069ae9SJean Delvare 	char *str;
63f3069ae9SJean Delvare 	size_t len;
64f3069ae9SJean Delvare 
65f3069ae9SJean Delvare 	if (bp == dmi_empty_string)
66f3069ae9SJean Delvare 		return dmi_empty_string;
67f3069ae9SJean Delvare 
68f3069ae9SJean Delvare 	len = strlen(bp) + 1;
6979da4721SParag Warudkar 	str = dmi_alloc(len);
704f705ae3SBjorn Helgaas 	if (str != NULL)
714f705ae3SBjorn Helgaas 		strcpy(str, bp);
724f705ae3SBjorn Helgaas 
734f705ae3SBjorn Helgaas 	return str;
744f705ae3SBjorn Helgaas }
754f705ae3SBjorn Helgaas 
764f705ae3SBjorn Helgaas /*
774f705ae3SBjorn Helgaas  *	We have to be cautious here. We have seen BIOSes with DMI pointers
784f705ae3SBjorn Helgaas  *	pointing to completely the wrong place for example
794f705ae3SBjorn Helgaas  */
80eb4c5ea5SIvan Khoronzhuk static void dmi_decode_table(u8 *buf,
81e7a19c56SJean Delvare 			     void (*decode)(const struct dmi_header *, void *),
82e7a19c56SJean Delvare 			     void *private_data)
834f705ae3SBjorn Helgaas {
847fce084aSJean Delvare 	u8 *data = buf;
854f705ae3SBjorn Helgaas 	int i = 0;
864f705ae3SBjorn Helgaas 
874f705ae3SBjorn Helgaas 	/*
88bfbaafaeSJean Delvare 	 * Stop when we have seen all the items the table claimed to have
8917cd5bd5SJean Delvare 	 * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS
9017cd5bd5SJean Delvare 	 * >= 3.0 only) OR we run off the end of the table (should never
9117cd5bd5SJean Delvare 	 * happen but sometimes does on bogus implementations.)
924f705ae3SBjorn Helgaas 	 */
939c65e12aSLinus Torvalds 	while ((!dmi_num || i < dmi_num) &&
949c65e12aSLinus Torvalds 	       (data - buf + sizeof(struct dmi_header)) <= dmi_len) {
951855256cSJeff Garzik 		const struct dmi_header *dm = (const struct dmi_header *)data;
961855256cSJeff Garzik 
974f705ae3SBjorn Helgaas 		/*
988638545cSAlan Cox 		 *  We want to know the total length (formatted area and
998638545cSAlan Cox 		 *  strings) before decoding to make sure we won't run off the
1008638545cSAlan Cox 		 *  table in dmi_decode or dmi_string
1014f705ae3SBjorn Helgaas 		 */
1024f705ae3SBjorn Helgaas 		data += dm->length;
103552e19d8SIvan Khoronzhuk 		while ((data - buf < dmi_len - 1) && (data[0] || data[1]))
1044f705ae3SBjorn Helgaas 			data++;
105552e19d8SIvan Khoronzhuk 		if (data - buf < dmi_len - 1)
106e7a19c56SJean Delvare 			decode(dm, private_data);
107ce204e9aSIvan Khoronzhuk 
1086e0ad59eSJean Delvare 		data += 2;
1096e0ad59eSJean Delvare 		i++;
1106e0ad59eSJean Delvare 
111ce204e9aSIvan Khoronzhuk 		/*
112ce204e9aSIvan Khoronzhuk 		 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
11317cd5bd5SJean Delvare 		 * For tables behind a 64-bit entry point, we have no item
11417cd5bd5SJean Delvare 		 * count and no exact table length, so stop on end-of-table
11517cd5bd5SJean Delvare 		 * marker. For tables behind a 32-bit entry point, we have
11617cd5bd5SJean Delvare 		 * seen OEM structures behind the end-of-table marker on
11717cd5bd5SJean Delvare 		 * some systems, so don't trust it.
118ce204e9aSIvan Khoronzhuk 		 */
11917cd5bd5SJean Delvare 		if (!dmi_num && dm->type == DMI_ENTRY_END_OF_TABLE)
120ce204e9aSIvan Khoronzhuk 			break;
1214f705ae3SBjorn Helgaas 	}
1226e0ad59eSJean Delvare 
1236e0ad59eSJean Delvare 	/* Trim DMI table length if needed */
1246e0ad59eSJean Delvare 	if (dmi_len > data - buf)
1256e0ad59eSJean Delvare 		dmi_len = data - buf;
1267fce084aSJean Delvare }
1277fce084aSJean Delvare 
128fc430262SArd Biesheuvel static phys_addr_t dmi_base;
1297fce084aSJean Delvare 
130e7a19c56SJean Delvare static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
131e7a19c56SJean Delvare 		void *))
1327fce084aSJean Delvare {
1337fce084aSJean Delvare 	u8 *buf;
1346e0ad59eSJean Delvare 	u32 orig_dmi_len = dmi_len;
1357fce084aSJean Delvare 
1366e0ad59eSJean Delvare 	buf = dmi_early_remap(dmi_base, orig_dmi_len);
1377fce084aSJean Delvare 	if (buf == NULL)
138c9268200SAndy Lutomirski 		return -ENOMEM;
1397fce084aSJean Delvare 
140eb4c5ea5SIvan Khoronzhuk 	dmi_decode_table(buf, decode, NULL);
1417fce084aSJean Delvare 
142d114a333STony Luck 	add_device_randomness(buf, dmi_len);
143d114a333STony Luck 
1446e0ad59eSJean Delvare 	dmi_early_unmap(buf, orig_dmi_len);
1454f705ae3SBjorn Helgaas 	return 0;
1464f705ae3SBjorn Helgaas }
1474f705ae3SBjorn Helgaas 
1489f9c9cbbSZhenzhong Duan static int __init dmi_checksum(const u8 *buf, u8 len)
1494f705ae3SBjorn Helgaas {
1504f705ae3SBjorn Helgaas 	u8 sum = 0;
1514f705ae3SBjorn Helgaas 	int a;
1524f705ae3SBjorn Helgaas 
1539f9c9cbbSZhenzhong Duan 	for (a = 0; a < len; a++)
1544f705ae3SBjorn Helgaas 		sum += buf[a];
1554f705ae3SBjorn Helgaas 
1564f705ae3SBjorn Helgaas 	return sum == 0;
1574f705ae3SBjorn Helgaas }
1584f705ae3SBjorn Helgaas 
159ffbbb96dSJean Delvare static const char *dmi_ident[DMI_STRING_MAX];
1604f705ae3SBjorn Helgaas static LIST_HEAD(dmi_devices);
1614f5c791aSLennart Poettering int dmi_available;
1624f705ae3SBjorn Helgaas 
1634f705ae3SBjorn Helgaas /*
1644f705ae3SBjorn Helgaas  *	Save a DMI string
1654f705ae3SBjorn Helgaas  */
16602d9c47fSJean Delvare static void __init dmi_save_ident(const struct dmi_header *dm, int slot,
16702d9c47fSJean Delvare 		int string)
1684f705ae3SBjorn Helgaas {
1691855256cSJeff Garzik 	const char *d = (const char *) dm;
170ffbbb96dSJean Delvare 	const char *p;
1714f705ae3SBjorn Helgaas 
172a814c359SJean Delvare 	if (dmi_ident[slot] || dm->length <= string)
1734f705ae3SBjorn Helgaas 		return;
1744f705ae3SBjorn Helgaas 
1754f705ae3SBjorn Helgaas 	p = dmi_string(dm, d[string]);
1764f705ae3SBjorn Helgaas 	if (p == NULL)
1774f705ae3SBjorn Helgaas 		return;
1784f705ae3SBjorn Helgaas 
1794f705ae3SBjorn Helgaas 	dmi_ident[slot] = p;
1804f705ae3SBjorn Helgaas }
1814f705ae3SBjorn Helgaas 
18202d9c47fSJean Delvare static void __init dmi_save_uuid(const struct dmi_header *dm, int slot,
18302d9c47fSJean Delvare 		int index)
1844f5c791aSLennart Poettering {
185a814c359SJean Delvare 	const u8 *d;
1864f5c791aSLennart Poettering 	char *s;
1874f5c791aSLennart Poettering 	int is_ff = 1, is_00 = 1, i;
1884f5c791aSLennart Poettering 
18990fe6f8fSJean Delvare 	if (dmi_ident[slot] || dm->length < index + 16)
1904f5c791aSLennart Poettering 		return;
1914f5c791aSLennart Poettering 
192a814c359SJean Delvare 	d = (u8 *) dm + index;
1934f5c791aSLennart Poettering 	for (i = 0; i < 16 && (is_ff || is_00); i++) {
194f1d8e614SZhenzhong Duan 		if (d[i] != 0x00)
195f1d8e614SZhenzhong Duan 			is_00 = 0;
196f1d8e614SZhenzhong Duan 		if (d[i] != 0xFF)
197f1d8e614SZhenzhong Duan 			is_ff = 0;
1984f5c791aSLennart Poettering 	}
1994f5c791aSLennart Poettering 
2004f5c791aSLennart Poettering 	if (is_ff || is_00)
2014f5c791aSLennart Poettering 		return;
2024f5c791aSLennart Poettering 
2034f5c791aSLennart Poettering 	s = dmi_alloc(16*2+4+1);
2044f5c791aSLennart Poettering 	if (!s)
2054f5c791aSLennart Poettering 		return;
2064f5c791aSLennart Poettering 
207f1d8e614SZhenzhong Duan 	/*
208f1d8e614SZhenzhong Duan 	 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
209f1d8e614SZhenzhong Duan 	 * the UUID are supposed to be little-endian encoded.  The specification
210f1d8e614SZhenzhong Duan 	 * says that this is the defacto standard.
211f1d8e614SZhenzhong Duan 	 */
21295be58dfSIvan Khoronzhuk 	if (dmi_ver >= 0x020600)
213*712ff254SJean Delvare 		sprintf(s, "%pUl", d);
214f1d8e614SZhenzhong Duan 	else
215*712ff254SJean Delvare 		sprintf(s, "%pUb", d);
2164f5c791aSLennart Poettering 
2174f5c791aSLennart Poettering 	dmi_ident[slot] = s;
2184f5c791aSLennart Poettering }
2194f5c791aSLennart Poettering 
22002d9c47fSJean Delvare static void __init dmi_save_type(const struct dmi_header *dm, int slot,
22102d9c47fSJean Delvare 		int index)
2224f5c791aSLennart Poettering {
223a814c359SJean Delvare 	const u8 *d;
2244f5c791aSLennart Poettering 	char *s;
2254f5c791aSLennart Poettering 
226a814c359SJean Delvare 	if (dmi_ident[slot] || dm->length <= index)
2274f5c791aSLennart Poettering 		return;
2284f5c791aSLennart Poettering 
2294f5c791aSLennart Poettering 	s = dmi_alloc(4);
2304f5c791aSLennart Poettering 	if (!s)
2314f5c791aSLennart Poettering 		return;
2324f5c791aSLennart Poettering 
233a814c359SJean Delvare 	d = (u8 *) dm + index;
2344f5c791aSLennart Poettering 	sprintf(s, "%u", *d & 0x7F);
2354f5c791aSLennart Poettering 	dmi_ident[slot] = s;
2364f5c791aSLennart Poettering }
2374f5c791aSLennart Poettering 
238f3069ae9SJean Delvare static void __init dmi_save_one_device(int type, const char *name)
239f3069ae9SJean Delvare {
240f3069ae9SJean Delvare 	struct dmi_device *dev;
241f3069ae9SJean Delvare 
242f3069ae9SJean Delvare 	/* No duplicate device */
243f3069ae9SJean Delvare 	if (dmi_find_device(type, name, NULL))
244f3069ae9SJean Delvare 		return;
245f3069ae9SJean Delvare 
246f3069ae9SJean Delvare 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
247ae797449SJean Delvare 	if (!dev)
248f3069ae9SJean Delvare 		return;
249f3069ae9SJean Delvare 
250f3069ae9SJean Delvare 	dev->type = type;
251f3069ae9SJean Delvare 	strcpy((char *)(dev + 1), name);
252f3069ae9SJean Delvare 	dev->name = (char *)(dev + 1);
253f3069ae9SJean Delvare 	dev->device_data = NULL;
254f3069ae9SJean Delvare 	list_add(&dev->list, &dmi_devices);
255f3069ae9SJean Delvare }
256f3069ae9SJean Delvare 
2571855256cSJeff Garzik static void __init dmi_save_devices(const struct dmi_header *dm)
2584f705ae3SBjorn Helgaas {
2594f705ae3SBjorn Helgaas 	int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
2604f705ae3SBjorn Helgaas 
2614f705ae3SBjorn Helgaas 	for (i = 0; i < count; i++) {
2621855256cSJeff Garzik 		const char *d = (char *)(dm + 1) + (i * 2);
2634f705ae3SBjorn Helgaas 
2644f705ae3SBjorn Helgaas 		/* Skip disabled device */
2654f705ae3SBjorn Helgaas 		if ((*d & 0x80) == 0)
2664f705ae3SBjorn Helgaas 			continue;
2674f705ae3SBjorn Helgaas 
268f3069ae9SJean Delvare 		dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
2692e0c1f6cSShem Multinymous 	}
2702e0c1f6cSShem Multinymous }
2712e0c1f6cSShem Multinymous 
2721855256cSJeff Garzik static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
2732e0c1f6cSShem Multinymous {
274a814c359SJean Delvare 	int i, count;
2752e0c1f6cSShem Multinymous 	struct dmi_device *dev;
2762e0c1f6cSShem Multinymous 
277a814c359SJean Delvare 	if (dm->length < 0x05)
278a814c359SJean Delvare 		return;
279a814c359SJean Delvare 
280a814c359SJean Delvare 	count = *(u8 *)(dm + 1);
2812e0c1f6cSShem Multinymous 	for (i = 1; i <= count; i++) {
282ffbbb96dSJean Delvare 		const char *devname = dmi_string(dm, i);
28379da4721SParag Warudkar 
28443fe105aSJean Delvare 		if (devname == dmi_empty_string)
28579da4721SParag Warudkar 			continue;
28679da4721SParag Warudkar 
2872e0c1f6cSShem Multinymous 		dev = dmi_alloc(sizeof(*dev));
288ae797449SJean Delvare 		if (!dev)
2892e0c1f6cSShem Multinymous 			break;
2902e0c1f6cSShem Multinymous 
2912e0c1f6cSShem Multinymous 		dev->type = DMI_DEV_TYPE_OEM_STRING;
29279da4721SParag Warudkar 		dev->name = devname;
2932e0c1f6cSShem Multinymous 		dev->device_data = NULL;
2944f705ae3SBjorn Helgaas 
2954f705ae3SBjorn Helgaas 		list_add(&dev->list, &dmi_devices);
2964f705ae3SBjorn Helgaas 	}
2974f705ae3SBjorn Helgaas }
2984f705ae3SBjorn Helgaas 
2991855256cSJeff Garzik static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
3004f705ae3SBjorn Helgaas {
3014f705ae3SBjorn Helgaas 	struct dmi_device *dev;
3024f705ae3SBjorn Helgaas 	void *data;
3034f705ae3SBjorn Helgaas 
3044f705ae3SBjorn Helgaas 	data = dmi_alloc(dm->length);
305ae797449SJean Delvare 	if (data == NULL)
3064f705ae3SBjorn Helgaas 		return;
3074f705ae3SBjorn Helgaas 
3084f705ae3SBjorn Helgaas 	memcpy(data, dm, dm->length);
3094f705ae3SBjorn Helgaas 
3104f705ae3SBjorn Helgaas 	dev = dmi_alloc(sizeof(*dev));
311ae797449SJean Delvare 	if (!dev)
3124f705ae3SBjorn Helgaas 		return;
3134f705ae3SBjorn Helgaas 
3144f705ae3SBjorn Helgaas 	dev->type = DMI_DEV_TYPE_IPMI;
3154f705ae3SBjorn Helgaas 	dev->name = "IPMI controller";
3164f705ae3SBjorn Helgaas 	dev->device_data = data;
3174f705ae3SBjorn Helgaas 
318abd24df8SCarol Hebert 	list_add_tail(&dev->list, &dmi_devices);
3194f705ae3SBjorn Helgaas }
3204f705ae3SBjorn Helgaas 
321e5b6c151SJordan Hargrave static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus,
322e5b6c151SJordan Hargrave 					int devfn, const char *name, int type)
323911e1c9bSNarendra K {
324e5b6c151SJordan Hargrave 	struct dmi_dev_onboard *dev;
325911e1c9bSNarendra K 
326e5b6c151SJordan Hargrave 	/* Ignore invalid values */
327e5b6c151SJordan Hargrave 	if (type == DMI_DEV_TYPE_DEV_SLOT &&
328e5b6c151SJordan Hargrave 	    segment == 0xFFFF && bus == 0xFF && devfn == 0xFF)
329911e1c9bSNarendra K 		return;
330ae797449SJean Delvare 
331e5b6c151SJordan Hargrave 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
332e5b6c151SJordan Hargrave 	if (!dev)
333e5b6c151SJordan Hargrave 		return;
334911e1c9bSNarendra K 
335e5b6c151SJordan Hargrave 	dev->instance = instance;
336e5b6c151SJordan Hargrave 	dev->segment = segment;
337e5b6c151SJordan Hargrave 	dev->bus = bus;
338e5b6c151SJordan Hargrave 	dev->devfn = devfn;
339911e1c9bSNarendra K 
340e5b6c151SJordan Hargrave 	strcpy((char *)&dev[1], name);
341e5b6c151SJordan Hargrave 	dev->dev.type = type;
342e5b6c151SJordan Hargrave 	dev->dev.name = (char *)&dev[1];
343e5b6c151SJordan Hargrave 	dev->dev.device_data = dev;
344e5b6c151SJordan Hargrave 
345e5b6c151SJordan Hargrave 	list_add(&dev->dev.list, &dmi_devices);
346911e1c9bSNarendra K }
347911e1c9bSNarendra K 
348b4bd7d59SWim Van Sebroeck static void __init dmi_save_extended_devices(const struct dmi_header *dm)
349b4bd7d59SWim Van Sebroeck {
35096e23943SJean Delvare 	const char *name;
35145b98257SJean Delvare 	const u8 *d = (u8 *)dm;
352b4bd7d59SWim Van Sebroeck 
353a814c359SJean Delvare 	if (dm->length < 0x0B)
354a814c359SJean Delvare 		return;
355a814c359SJean Delvare 
356b4bd7d59SWim Van Sebroeck 	/* Skip disabled device */
35745b98257SJean Delvare 	if ((d[0x5] & 0x80) == 0)
358b4bd7d59SWim Van Sebroeck 		return;
359b4bd7d59SWim Van Sebroeck 
36045b98257SJean Delvare 	name = dmi_string_nosave(dm, d[0x4]);
361e5b6c151SJordan Hargrave 	dmi_save_dev_pciaddr(d[0x6], *(u16 *)(d + 0x7), d[0x9], d[0xA], name,
362e5b6c151SJordan Hargrave 			     DMI_DEV_TYPE_DEV_ONBOARD);
36345b98257SJean Delvare 	dmi_save_one_device(d[0x5] & 0x7f, name);
364b4bd7d59SWim Van Sebroeck }
365b4bd7d59SWim Van Sebroeck 
366e5b6c151SJordan Hargrave static void __init dmi_save_system_slot(const struct dmi_header *dm)
367e5b6c151SJordan Hargrave {
368e5b6c151SJordan Hargrave 	const u8 *d = (u8 *)dm;
369e5b6c151SJordan Hargrave 
370e5b6c151SJordan Hargrave 	/* Need SMBIOS 2.6+ structure */
371e5b6c151SJordan Hargrave 	if (dm->length < 0x11)
372e5b6c151SJordan Hargrave 		return;
373e5b6c151SJordan Hargrave 	dmi_save_dev_pciaddr(*(u16 *)(d + 0x9), *(u16 *)(d + 0xD), d[0xF],
374e5b6c151SJordan Hargrave 			     d[0x10], dmi_string_nosave(dm, d[0x4]),
375e5b6c151SJordan Hargrave 			     DMI_DEV_TYPE_DEV_SLOT);
376e5b6c151SJordan Hargrave }
377e5b6c151SJordan Hargrave 
378dd6dad42SChen, Gong static void __init count_mem_devices(const struct dmi_header *dm, void *v)
379dd6dad42SChen, Gong {
380dd6dad42SChen, Gong 	if (dm->type != DMI_ENTRY_MEM_DEVICE)
381dd6dad42SChen, Gong 		return;
382dd6dad42SChen, Gong 	dmi_memdev_nr++;
383dd6dad42SChen, Gong }
384dd6dad42SChen, Gong 
385dd6dad42SChen, Gong static void __init save_mem_devices(const struct dmi_header *dm, void *v)
386dd6dad42SChen, Gong {
387dd6dad42SChen, Gong 	const char *d = (const char *)dm;
388dd6dad42SChen, Gong 	static int nr;
389dd6dad42SChen, Gong 
390a814c359SJean Delvare 	if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x12)
391dd6dad42SChen, Gong 		return;
392dd6dad42SChen, Gong 	if (nr >= dmi_memdev_nr) {
393dd6dad42SChen, Gong 		pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n");
394dd6dad42SChen, Gong 		return;
395dd6dad42SChen, Gong 	}
3960841c04dSLuck, Tony 	dmi_memdev[nr].handle = get_unaligned(&dm->handle);
397dd6dad42SChen, Gong 	dmi_memdev[nr].device = dmi_string(dm, d[0x10]);
398dd6dad42SChen, Gong 	dmi_memdev[nr].bank = dmi_string(dm, d[0x11]);
399dd6dad42SChen, Gong 	nr++;
400dd6dad42SChen, Gong }
401dd6dad42SChen, Gong 
402dd6dad42SChen, Gong void __init dmi_memdev_walk(void)
403dd6dad42SChen, Gong {
404dd6dad42SChen, Gong 	if (!dmi_available)
405dd6dad42SChen, Gong 		return;
406dd6dad42SChen, Gong 
407dd6dad42SChen, Gong 	if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) {
408dd6dad42SChen, Gong 		dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr);
409dd6dad42SChen, Gong 		if (dmi_memdev)
410dd6dad42SChen, Gong 			dmi_walk_early(save_mem_devices);
411dd6dad42SChen, Gong 	}
412dd6dad42SChen, Gong }
413dd6dad42SChen, Gong 
4144f705ae3SBjorn Helgaas /*
4154f705ae3SBjorn Helgaas  *	Process a DMI table entry. Right now all we care about are the BIOS
4164f705ae3SBjorn Helgaas  *	and machine entries. For 2.5 we should pull the smbus controller info
4174f705ae3SBjorn Helgaas  *	out of here.
4184f705ae3SBjorn Helgaas  */
419e7a19c56SJean Delvare static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
4204f705ae3SBjorn Helgaas {
4214f705ae3SBjorn Helgaas 	switch (dm->type) {
4224f705ae3SBjorn Helgaas 	case 0:		/* BIOS Information */
4234f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
4244f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
4254f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_BIOS_DATE, 8);
4264f705ae3SBjorn Helgaas 		break;
4274f705ae3SBjorn Helgaas 	case 1:		/* System Information */
4284f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
4294f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
4304f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
4314f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
4324f5c791aSLennart Poettering 		dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
433c61872c9SMika Westerberg 		dmi_save_ident(dm, DMI_PRODUCT_FAMILY, 26);
4344f705ae3SBjorn Helgaas 		break;
4354f705ae3SBjorn Helgaas 	case 2:		/* Base Board Information */
4364f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
4374f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_BOARD_NAME, 5);
4384f705ae3SBjorn Helgaas 		dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
4394f5c791aSLennart Poettering 		dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
4404f5c791aSLennart Poettering 		dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
4414f5c791aSLennart Poettering 		break;
4424f5c791aSLennart Poettering 	case 3:		/* Chassis Information */
4434f5c791aSLennart Poettering 		dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
4444f5c791aSLennart Poettering 		dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
4454f5c791aSLennart Poettering 		dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
4464f5c791aSLennart Poettering 		dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
4474f5c791aSLennart Poettering 		dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
4484f705ae3SBjorn Helgaas 		break;
449e5b6c151SJordan Hargrave 	case 9:		/* System Slots */
450e5b6c151SJordan Hargrave 		dmi_save_system_slot(dm);
451e5b6c151SJordan Hargrave 		break;
4524f705ae3SBjorn Helgaas 	case 10:	/* Onboard Devices Information */
4534f705ae3SBjorn Helgaas 		dmi_save_devices(dm);
4544f705ae3SBjorn Helgaas 		break;
4552e0c1f6cSShem Multinymous 	case 11:	/* OEM Strings */
4562e0c1f6cSShem Multinymous 		dmi_save_oem_strings_devices(dm);
4572e0c1f6cSShem Multinymous 		break;
4584f705ae3SBjorn Helgaas 	case 38:	/* IPMI Device Information */
4594f705ae3SBjorn Helgaas 		dmi_save_ipmi_device(dm);
460b4bd7d59SWim Van Sebroeck 		break;
461b4bd7d59SWim Van Sebroeck 	case 41:	/* Onboard Devices Extended Information */
462b4bd7d59SWim Van Sebroeck 		dmi_save_extended_devices(dm);
4634f705ae3SBjorn Helgaas 	}
4644f705ae3SBjorn Helgaas }
4654f705ae3SBjorn Helgaas 
466c90fe6bcSTejun Heo static int __init print_filtered(char *buf, size_t len, const char *info)
4678881cdceSBjorn Helgaas {
468c90fe6bcSTejun Heo 	int c = 0;
4698881cdceSBjorn Helgaas 	const char *p;
4708881cdceSBjorn Helgaas 
4718881cdceSBjorn Helgaas 	if (!info)
472c90fe6bcSTejun Heo 		return c;
4738881cdceSBjorn Helgaas 
4748881cdceSBjorn Helgaas 	for (p = info; *p; p++)
4758881cdceSBjorn Helgaas 		if (isprint(*p))
476c90fe6bcSTejun Heo 			c += scnprintf(buf + c, len - c, "%c", *p);
4778881cdceSBjorn Helgaas 		else
478c90fe6bcSTejun Heo 			c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff);
479c90fe6bcSTejun Heo 	return c;
4808881cdceSBjorn Helgaas }
4818881cdceSBjorn Helgaas 
482c90fe6bcSTejun Heo static void __init dmi_format_ids(char *buf, size_t len)
4838881cdceSBjorn Helgaas {
484c90fe6bcSTejun Heo 	int c = 0;
48584e383b3SNaga Chumbalkar 	const char *board;	/* Board Name is optional */
48684e383b3SNaga Chumbalkar 
487c90fe6bcSTejun Heo 	c += print_filtered(buf + c, len - c,
488c90fe6bcSTejun Heo 			    dmi_get_system_info(DMI_SYS_VENDOR));
489c90fe6bcSTejun Heo 	c += scnprintf(buf + c, len - c, " ");
490c90fe6bcSTejun Heo 	c += print_filtered(buf + c, len - c,
491c90fe6bcSTejun Heo 			    dmi_get_system_info(DMI_PRODUCT_NAME));
492c90fe6bcSTejun Heo 
49384e383b3SNaga Chumbalkar 	board = dmi_get_system_info(DMI_BOARD_NAME);
49484e383b3SNaga Chumbalkar 	if (board) {
495c90fe6bcSTejun Heo 		c += scnprintf(buf + c, len - c, "/");
496c90fe6bcSTejun Heo 		c += print_filtered(buf + c, len - c, board);
49784e383b3SNaga Chumbalkar 	}
498c90fe6bcSTejun Heo 	c += scnprintf(buf + c, len - c, ", BIOS ");
499c90fe6bcSTejun Heo 	c += print_filtered(buf + c, len - c,
500c90fe6bcSTejun Heo 			    dmi_get_system_info(DMI_BIOS_VERSION));
501c90fe6bcSTejun Heo 	c += scnprintf(buf + c, len - c, " ");
502c90fe6bcSTejun Heo 	c += print_filtered(buf + c, len - c,
503c90fe6bcSTejun Heo 			    dmi_get_system_info(DMI_BIOS_DATE));
5048881cdceSBjorn Helgaas }
5058881cdceSBjorn Helgaas 
506d39de28cSBen Hutchings /*
507d39de28cSBen Hutchings  * Check for DMI/SMBIOS headers in the system firmware image.  Any
508d39de28cSBen Hutchings  * SMBIOS header must start 16 bytes before the DMI header, so take a
509d39de28cSBen Hutchings  * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
510d39de28cSBen Hutchings  * 0.  If the DMI header is present, set dmi_ver accordingly (SMBIOS
511d39de28cSBen Hutchings  * takes precedence) and return 0.  Otherwise return 1.
512d39de28cSBen Hutchings  */
51379bae42dSBen Hutchings static int __init dmi_present(const u8 *buf)
5144f705ae3SBjorn Helgaas {
51595be58dfSIvan Khoronzhuk 	u32 smbios_ver;
5161855256cSJeff Garzik 
51779bae42dSBen Hutchings 	if (memcmp(buf, "_SM_", 4) == 0 &&
51879bae42dSBen Hutchings 	    buf[5] < 32 && dmi_checksum(buf, buf[5])) {
519fc430262SArd Biesheuvel 		smbios_ver = get_unaligned_be16(buf + 6);
520d7f96f97SIvan Khoronzhuk 		smbios_entry_point_size = buf[5];
521d7f96f97SIvan Khoronzhuk 		memcpy(smbios_entry_point, buf, smbios_entry_point_size);
52279bae42dSBen Hutchings 
52379bae42dSBen Hutchings 		/* Some BIOS report weird SMBIOS version, fix that up */
52479bae42dSBen Hutchings 		switch (smbios_ver) {
52579bae42dSBen Hutchings 		case 0x021F:
52679bae42dSBen Hutchings 		case 0x0221:
52779bae42dSBen Hutchings 			pr_debug("SMBIOS version fixup (2.%d->2.%d)\n",
52879bae42dSBen Hutchings 				 smbios_ver & 0xFF, 3);
52979bae42dSBen Hutchings 			smbios_ver = 0x0203;
53079bae42dSBen Hutchings 			break;
53179bae42dSBen Hutchings 		case 0x0233:
53279bae42dSBen Hutchings 			pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6);
53379bae42dSBen Hutchings 			smbios_ver = 0x0206;
53479bae42dSBen Hutchings 			break;
53579bae42dSBen Hutchings 		}
53679bae42dSBen Hutchings 	} else {
53779bae42dSBen Hutchings 		smbios_ver = 0;
53879bae42dSBen Hutchings 	}
53979bae42dSBen Hutchings 
54079bae42dSBen Hutchings 	buf += 16;
54179bae42dSBen Hutchings 
54279bae42dSBen Hutchings 	if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) {
5435c1ac56bSJean Delvare 		if (smbios_ver)
5445c1ac56bSJean Delvare 			dmi_ver = smbios_ver;
5455c1ac56bSJean Delvare 		else
5465c1ac56bSJean Delvare 			dmi_ver = (buf[14] & 0xF0) << 4 | (buf[14] & 0x0F);
547ff4319dcSAndrea Arcangeli 		dmi_ver <<= 8;
548fc430262SArd Biesheuvel 		dmi_num = get_unaligned_le16(buf + 12);
549fc430262SArd Biesheuvel 		dmi_len = get_unaligned_le16(buf + 6);
550fc430262SArd Biesheuvel 		dmi_base = get_unaligned_le32(buf + 8);
5514f705ae3SBjorn Helgaas 
5528881cdceSBjorn Helgaas 		if (dmi_walk_early(dmi_decode) == 0) {
55379bae42dSBen Hutchings 			if (smbios_ver) {
554c2493045SJean Delvare 				pr_info("SMBIOS %d.%d present.\n",
555ff4319dcSAndrea Arcangeli 					dmi_ver >> 16, (dmi_ver >> 8) & 0xFF);
55679bae42dSBen Hutchings 			} else {
557d7f96f97SIvan Khoronzhuk 				smbios_entry_point_size = 15;
558d7f96f97SIvan Khoronzhuk 				memcpy(smbios_entry_point, buf,
559d7f96f97SIvan Khoronzhuk 				       smbios_entry_point_size);
5609f9c9cbbSZhenzhong Duan 				pr_info("Legacy DMI %d.%d present.\n",
561ff4319dcSAndrea Arcangeli 					dmi_ver >> 16, (dmi_ver >> 8) & 0xFF);
5629f9c9cbbSZhenzhong Duan 			}
563c90fe6bcSTejun Heo 			dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
564d4af49f8SKefeng Wang 			pr_info("DMI: %s\n", dmi_ids_string);
5654f705ae3SBjorn Helgaas 			return 0;
5664f705ae3SBjorn Helgaas 		}
5678881cdceSBjorn Helgaas 	}
5684f705ae3SBjorn Helgaas 
569a40e7cf8SBen Hutchings 	return 1;
5709f9c9cbbSZhenzhong Duan }
5719f9c9cbbSZhenzhong Duan 
572fc430262SArd Biesheuvel /*
573fc430262SArd Biesheuvel  * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
574fc430262SArd Biesheuvel  * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
575fc430262SArd Biesheuvel  */
576fc430262SArd Biesheuvel static int __init dmi_smbios3_present(const u8 *buf)
577fc430262SArd Biesheuvel {
578fc430262SArd Biesheuvel 	if (memcmp(buf, "_SM3_", 5) == 0 &&
579fc430262SArd Biesheuvel 	    buf[6] < 32 && dmi_checksum(buf, buf[6])) {
580d1d8704cSJean Delvare 		dmi_ver = get_unaligned_be32(buf + 6) & 0xFFFFFF;
581bfbaafaeSJean Delvare 		dmi_num = 0;			/* No longer specified */
582fc430262SArd Biesheuvel 		dmi_len = get_unaligned_le32(buf + 12);
583fc430262SArd Biesheuvel 		dmi_base = get_unaligned_le64(buf + 16);
584d7f96f97SIvan Khoronzhuk 		smbios_entry_point_size = buf[6];
585d7f96f97SIvan Khoronzhuk 		memcpy(smbios_entry_point, buf, smbios_entry_point_size);
586fc430262SArd Biesheuvel 
587fc430262SArd Biesheuvel 		if (dmi_walk_early(dmi_decode) == 0) {
58895be58dfSIvan Khoronzhuk 			pr_info("SMBIOS %d.%d.%d present.\n",
58995be58dfSIvan Khoronzhuk 				dmi_ver >> 16, (dmi_ver >> 8) & 0xFF,
59095be58dfSIvan Khoronzhuk 				dmi_ver & 0xFF);
591fc430262SArd Biesheuvel 			dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
592d4af49f8SKefeng Wang 			pr_info("DMI: %s\n", dmi_ids_string);
593fc430262SArd Biesheuvel 			return 0;
594fc430262SArd Biesheuvel 		}
595fc430262SArd Biesheuvel 	}
596fc430262SArd Biesheuvel 	return 1;
597fc430262SArd Biesheuvel }
598fc430262SArd Biesheuvel 
5994f705ae3SBjorn Helgaas void __init dmi_scan_machine(void)
6004f705ae3SBjorn Helgaas {
6014f705ae3SBjorn Helgaas 	char __iomem *p, *q;
60279bae42dSBen Hutchings 	char buf[32];
6034f705ae3SBjorn Helgaas 
60483e68189SMatt Fleming 	if (efi_enabled(EFI_CONFIG_TABLES)) {
605fc430262SArd Biesheuvel 		/*
606fc430262SArd Biesheuvel 		 * According to the DMTF SMBIOS reference spec v3.0.0, it is
607fc430262SArd Biesheuvel 		 * allowed to define both the 64-bit entry point (smbios3) and
608fc430262SArd Biesheuvel 		 * the 32-bit entry point (smbios), in which case they should
609fc430262SArd Biesheuvel 		 * either both point to the same SMBIOS structure table, or the
610fc430262SArd Biesheuvel 		 * table pointed to by the 64-bit entry point should contain a
611fc430262SArd Biesheuvel 		 * superset of the table contents pointed to by the 32-bit entry
612fc430262SArd Biesheuvel 		 * point (section 5.2)
613fc430262SArd Biesheuvel 		 * This implies that the 64-bit entry point should have
614fc430262SArd Biesheuvel 		 * precedence if it is defined and supported by the OS. If we
615fc430262SArd Biesheuvel 		 * have the 64-bit entry point, but fail to decode it, fall
616fc430262SArd Biesheuvel 		 * back to the legacy one (if available)
617fc430262SArd Biesheuvel 		 */
618fc430262SArd Biesheuvel 		if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) {
619fc430262SArd Biesheuvel 			p = dmi_early_remap(efi.smbios3, 32);
620fc430262SArd Biesheuvel 			if (p == NULL)
621fc430262SArd Biesheuvel 				goto error;
622fc430262SArd Biesheuvel 			memcpy_fromio(buf, p, 32);
623fc430262SArd Biesheuvel 			dmi_early_unmap(p, 32);
624fc430262SArd Biesheuvel 
625fc430262SArd Biesheuvel 			if (!dmi_smbios3_present(buf)) {
626fc430262SArd Biesheuvel 				dmi_available = 1;
6277117794fSJean Delvare 				return;
628fc430262SArd Biesheuvel 			}
629fc430262SArd Biesheuvel 		}
6304f705ae3SBjorn Helgaas 		if (efi.smbios == EFI_INVALID_TABLE_ADDR)
6319a22b6e7SIngo Molnar 			goto error;
6324f705ae3SBjorn Helgaas 
6334f705ae3SBjorn Helgaas 		/* This is called as a core_initcall() because it isn't
6344f705ae3SBjorn Helgaas 		 * needed during early boot.  This also means we can
6354f705ae3SBjorn Helgaas 		 * iounmap the space when we're done with it.
6364f705ae3SBjorn Helgaas 		 */
637cf074402SArd Biesheuvel 		p = dmi_early_remap(efi.smbios, 32);
6384f705ae3SBjorn Helgaas 		if (p == NULL)
6399a22b6e7SIngo Molnar 			goto error;
64079bae42dSBen Hutchings 		memcpy_fromio(buf, p, 32);
641cf074402SArd Biesheuvel 		dmi_early_unmap(p, 32);
64279bae42dSBen Hutchings 
64379bae42dSBen Hutchings 		if (!dmi_present(buf)) {
6444f5c791aSLennart Poettering 			dmi_available = 1;
6457117794fSJean Delvare 			return;
6464f705ae3SBjorn Helgaas 		}
647cf074402SArd Biesheuvel 	} else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) {
648cf074402SArd Biesheuvel 		p = dmi_early_remap(0xF0000, 0x10000);
6494f705ae3SBjorn Helgaas 		if (p == NULL)
6509a22b6e7SIngo Molnar 			goto error;
6514f705ae3SBjorn Helgaas 
652d39de28cSBen Hutchings 		/*
653c9aba143SJean Delvare 		 * Same logic as above, look for a 64-bit entry point
654c9aba143SJean Delvare 		 * first, and if not found, fall back to 32-bit entry point.
655c9aba143SJean Delvare 		 */
656c9aba143SJean Delvare 		memcpy_fromio(buf, p, 16);
657c9aba143SJean Delvare 		for (q = p + 16; q < p + 0x10000; q += 16) {
658c9aba143SJean Delvare 			memcpy_fromio(buf + 16, q, 16);
659c9aba143SJean Delvare 			if (!dmi_smbios3_present(buf)) {
660c9aba143SJean Delvare 				dmi_available = 1;
661c9aba143SJean Delvare 				dmi_early_unmap(p, 0x10000);
6627117794fSJean Delvare 				return;
663c9aba143SJean Delvare 			}
664c9aba143SJean Delvare 			memcpy(buf, buf + 16, 16);
665c9aba143SJean Delvare 		}
666c9aba143SJean Delvare 
667c9aba143SJean Delvare 		/*
668d39de28cSBen Hutchings 		 * Iterate over all possible DMI header addresses q.
669d39de28cSBen Hutchings 		 * Maintain the 32 bytes around q in buf.  On the
670d39de28cSBen Hutchings 		 * first iteration, substitute zero for the
671d39de28cSBen Hutchings 		 * out-of-range bytes so there is no chance of falsely
672d39de28cSBen Hutchings 		 * detecting an SMBIOS header.
673d39de28cSBen Hutchings 		 */
67479bae42dSBen Hutchings 		memset(buf, 0, 16);
6754f705ae3SBjorn Helgaas 		for (q = p; q < p + 0x10000; q += 16) {
67679bae42dSBen Hutchings 			memcpy_fromio(buf + 16, q, 16);
677c9aba143SJean Delvare 			if (!dmi_present(buf)) {
6784f5c791aSLennart Poettering 				dmi_available = 1;
679cf074402SArd Biesheuvel 				dmi_early_unmap(p, 0x10000);
6807117794fSJean Delvare 				return;
6814f705ae3SBjorn Helgaas 			}
68279bae42dSBen Hutchings 			memcpy(buf, buf + 16, 16);
6834f705ae3SBjorn Helgaas 		}
684cf074402SArd Biesheuvel 		dmi_early_unmap(p, 0x10000);
6854f5c791aSLennart Poettering 	}
6869a22b6e7SIngo Molnar  error:
68702d9c47fSJean Delvare 	pr_info("DMI not present or invalid.\n");
6884f705ae3SBjorn Helgaas }
6894f705ae3SBjorn Helgaas 
690d7f96f97SIvan Khoronzhuk static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
691d7f96f97SIvan Khoronzhuk 			      struct bin_attribute *attr, char *buf,
692d7f96f97SIvan Khoronzhuk 			      loff_t pos, size_t count)
693d7f96f97SIvan Khoronzhuk {
694d7f96f97SIvan Khoronzhuk 	memcpy(buf, attr->private + pos, count);
695d7f96f97SIvan Khoronzhuk 	return count;
696d7f96f97SIvan Khoronzhuk }
697d7f96f97SIvan Khoronzhuk 
698d7f96f97SIvan Khoronzhuk static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
699d7f96f97SIvan Khoronzhuk static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
700d7f96f97SIvan Khoronzhuk 
701d7f96f97SIvan Khoronzhuk static int __init dmi_init(void)
702d7f96f97SIvan Khoronzhuk {
703d7f96f97SIvan Khoronzhuk 	struct kobject *tables_kobj;
704d7f96f97SIvan Khoronzhuk 	u8 *dmi_table;
705d7f96f97SIvan Khoronzhuk 	int ret = -ENOMEM;
706d7f96f97SIvan Khoronzhuk 
707a81114d0SArd Biesheuvel 	if (!dmi_available)
708a81114d0SArd Biesheuvel 		return 0;
709d7f96f97SIvan Khoronzhuk 
710d7f96f97SIvan Khoronzhuk 	/*
711d7f96f97SIvan Khoronzhuk 	 * Set up dmi directory at /sys/firmware/dmi. This entry should stay
712d7f96f97SIvan Khoronzhuk 	 * even after farther error, as it can be used by other modules like
713d7f96f97SIvan Khoronzhuk 	 * dmi-sysfs.
714d7f96f97SIvan Khoronzhuk 	 */
715d7f96f97SIvan Khoronzhuk 	dmi_kobj = kobject_create_and_add("dmi", firmware_kobj);
716d7f96f97SIvan Khoronzhuk 	if (!dmi_kobj)
717d7f96f97SIvan Khoronzhuk 		goto err;
718d7f96f97SIvan Khoronzhuk 
719d7f96f97SIvan Khoronzhuk 	tables_kobj = kobject_create_and_add("tables", dmi_kobj);
720d7f96f97SIvan Khoronzhuk 	if (!tables_kobj)
721d7f96f97SIvan Khoronzhuk 		goto err;
722d7f96f97SIvan Khoronzhuk 
723d7f96f97SIvan Khoronzhuk 	dmi_table = dmi_remap(dmi_base, dmi_len);
724d7f96f97SIvan Khoronzhuk 	if (!dmi_table)
725d7f96f97SIvan Khoronzhuk 		goto err_tables;
726d7f96f97SIvan Khoronzhuk 
727d7f96f97SIvan Khoronzhuk 	bin_attr_smbios_entry_point.size = smbios_entry_point_size;
728d7f96f97SIvan Khoronzhuk 	bin_attr_smbios_entry_point.private = smbios_entry_point;
729d7f96f97SIvan Khoronzhuk 	ret = sysfs_create_bin_file(tables_kobj, &bin_attr_smbios_entry_point);
730d7f96f97SIvan Khoronzhuk 	if (ret)
731d7f96f97SIvan Khoronzhuk 		goto err_unmap;
732d7f96f97SIvan Khoronzhuk 
733d7f96f97SIvan Khoronzhuk 	bin_attr_DMI.size = dmi_len;
734d7f96f97SIvan Khoronzhuk 	bin_attr_DMI.private = dmi_table;
735d7f96f97SIvan Khoronzhuk 	ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI);
736d7f96f97SIvan Khoronzhuk 	if (!ret)
737d7f96f97SIvan Khoronzhuk 		return 0;
738d7f96f97SIvan Khoronzhuk 
739d7f96f97SIvan Khoronzhuk 	sysfs_remove_bin_file(tables_kobj,
740d7f96f97SIvan Khoronzhuk 			      &bin_attr_smbios_entry_point);
741d7f96f97SIvan Khoronzhuk  err_unmap:
742d7f96f97SIvan Khoronzhuk 	dmi_unmap(dmi_table);
743d7f96f97SIvan Khoronzhuk  err_tables:
744d7f96f97SIvan Khoronzhuk 	kobject_del(tables_kobj);
745d7f96f97SIvan Khoronzhuk 	kobject_put(tables_kobj);
746d7f96f97SIvan Khoronzhuk  err:
747d7f96f97SIvan Khoronzhuk 	pr_err("dmi: Firmware registration failed.\n");
748d7f96f97SIvan Khoronzhuk 
749d7f96f97SIvan Khoronzhuk 	return ret;
750d7f96f97SIvan Khoronzhuk }
751d7f96f97SIvan Khoronzhuk subsys_initcall(dmi_init);
752d7f96f97SIvan Khoronzhuk 
7534f705ae3SBjorn Helgaas /**
75498e5e1bfSTejun Heo  * dmi_set_dump_stack_arch_desc - set arch description for dump_stack()
75598e5e1bfSTejun Heo  *
75698e5e1bfSTejun Heo  * Invoke dump_stack_set_arch_desc() with DMI system information so that
75798e5e1bfSTejun Heo  * DMI identifiers are printed out on task dumps.  Arch boot code should
75898e5e1bfSTejun Heo  * call this function after dmi_scan_machine() if it wants to print out DMI
75998e5e1bfSTejun Heo  * identifiers on task dumps.
76098e5e1bfSTejun Heo  */
76198e5e1bfSTejun Heo void __init dmi_set_dump_stack_arch_desc(void)
76298e5e1bfSTejun Heo {
76398e5e1bfSTejun Heo 	dump_stack_set_arch_desc("%s", dmi_ids_string);
76498e5e1bfSTejun Heo }
76598e5e1bfSTejun Heo 
76698e5e1bfSTejun Heo /**
767d7b1956fSRafael J. Wysocki  *	dmi_matches - check if dmi_system_id structure matches system DMI data
768d7b1956fSRafael J. Wysocki  *	@dmi: pointer to the dmi_system_id structure to check
769d7b1956fSRafael J. Wysocki  */
770d7b1956fSRafael J. Wysocki static bool dmi_matches(const struct dmi_system_id *dmi)
771d7b1956fSRafael J. Wysocki {
772d7b1956fSRafael J. Wysocki 	int i;
773d7b1956fSRafael J. Wysocki 
774d7b1956fSRafael J. Wysocki 	for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
775d7b1956fSRafael J. Wysocki 		int s = dmi->matches[i].slot;
776d7b1956fSRafael J. Wysocki 		if (s == DMI_NONE)
77775757507SDmitry Torokhov 			break;
778de40614dSAlex Hung 		if (s == DMI_OEM_STRING) {
779de40614dSAlex Hung 			/* DMI_OEM_STRING must be exact match */
780de40614dSAlex Hung 			const struct dmi_device *valid;
781de40614dSAlex Hung 
782de40614dSAlex Hung 			valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
783de40614dSAlex Hung 						dmi->matches[i].substr, NULL);
784de40614dSAlex Hung 			if (valid)
785de40614dSAlex Hung 				continue;
786de40614dSAlex Hung 		} else if (dmi_ident[s]) {
7878cf4e6a0SJean Delvare 			if (dmi->matches[i].exact_match) {
7888cf4e6a0SJean Delvare 				if (!strcmp(dmi_ident[s],
7898cf4e6a0SJean Delvare 					    dmi->matches[i].substr))
790d7b1956fSRafael J. Wysocki 					continue;
7918cf4e6a0SJean Delvare 			} else {
7928cf4e6a0SJean Delvare 				if (strstr(dmi_ident[s],
7938cf4e6a0SJean Delvare 					   dmi->matches[i].substr))
7945017b285SJani Nikula 					continue;
7955017b285SJani Nikula 			}
7968cf4e6a0SJean Delvare 		}
7975017b285SJani Nikula 
798d7b1956fSRafael J. Wysocki 		/* No match */
799d7b1956fSRafael J. Wysocki 		return false;
800d7b1956fSRafael J. Wysocki 	}
801d7b1956fSRafael J. Wysocki 	return true;
802d7b1956fSRafael J. Wysocki }
803d7b1956fSRafael J. Wysocki 
804d7b1956fSRafael J. Wysocki /**
80575757507SDmitry Torokhov  *	dmi_is_end_of_table - check for end-of-table marker
80675757507SDmitry Torokhov  *	@dmi: pointer to the dmi_system_id structure to check
80775757507SDmitry Torokhov  */
80875757507SDmitry Torokhov static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
80975757507SDmitry Torokhov {
81075757507SDmitry Torokhov 	return dmi->matches[0].slot == DMI_NONE;
81175757507SDmitry Torokhov }
81275757507SDmitry Torokhov 
81375757507SDmitry Torokhov /**
8144f705ae3SBjorn Helgaas  *	dmi_check_system - check system DMI data
8154f705ae3SBjorn Helgaas  *	@list: array of dmi_system_id structures to match against
816b0ef371eSRandy Dunlap  *		All non-null elements of the list must match
817b0ef371eSRandy Dunlap  *		their slot's (field index's) data (i.e., each
818b0ef371eSRandy Dunlap  *		list string must be a substring of the specified
819b0ef371eSRandy Dunlap  *		DMI slot's string data) to be considered a
820b0ef371eSRandy Dunlap  *		successful match.
8214f705ae3SBjorn Helgaas  *
8224f705ae3SBjorn Helgaas  *	Walk the blacklist table running matching functions until someone
8234f705ae3SBjorn Helgaas  *	returns non zero or we hit the end. Callback function is called for
824b0ef371eSRandy Dunlap  *	each successful match. Returns the number of matches.
8257117794fSJean Delvare  *
8267117794fSJean Delvare  *	dmi_scan_machine must be called before this function is called.
8274f705ae3SBjorn Helgaas  */
8281855256cSJeff Garzik int dmi_check_system(const struct dmi_system_id *list)
8294f705ae3SBjorn Helgaas {
830d7b1956fSRafael J. Wysocki 	int count = 0;
831d7b1956fSRafael J. Wysocki 	const struct dmi_system_id *d;
8324f705ae3SBjorn Helgaas 
83375757507SDmitry Torokhov 	for (d = list; !dmi_is_end_of_table(d); d++)
834d7b1956fSRafael J. Wysocki 		if (dmi_matches(d)) {
8354f705ae3SBjorn Helgaas 			count++;
8364f705ae3SBjorn Helgaas 			if (d->callback && d->callback(d))
8374f705ae3SBjorn Helgaas 				break;
8384f705ae3SBjorn Helgaas 		}
8394f705ae3SBjorn Helgaas 
8404f705ae3SBjorn Helgaas 	return count;
8414f705ae3SBjorn Helgaas }
8424f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_check_system);
8434f705ae3SBjorn Helgaas 
8444f705ae3SBjorn Helgaas /**
845d7b1956fSRafael J. Wysocki  *	dmi_first_match - find dmi_system_id structure matching system DMI data
846d7b1956fSRafael J. Wysocki  *	@list: array of dmi_system_id structures to match against
847d7b1956fSRafael J. Wysocki  *		All non-null elements of the list must match
848d7b1956fSRafael J. Wysocki  *		their slot's (field index's) data (i.e., each
849d7b1956fSRafael J. Wysocki  *		list string must be a substring of the specified
850d7b1956fSRafael J. Wysocki  *		DMI slot's string data) to be considered a
851d7b1956fSRafael J. Wysocki  *		successful match.
852d7b1956fSRafael J. Wysocki  *
853d7b1956fSRafael J. Wysocki  *	Walk the blacklist table until the first match is found.  Return the
854d7b1956fSRafael J. Wysocki  *	pointer to the matching entry or NULL if there's no match.
8557117794fSJean Delvare  *
8567117794fSJean Delvare  *	dmi_scan_machine must be called before this function is called.
857d7b1956fSRafael J. Wysocki  */
858d7b1956fSRafael J. Wysocki const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
859d7b1956fSRafael J. Wysocki {
860d7b1956fSRafael J. Wysocki 	const struct dmi_system_id *d;
861d7b1956fSRafael J. Wysocki 
86275757507SDmitry Torokhov 	for (d = list; !dmi_is_end_of_table(d); d++)
863d7b1956fSRafael J. Wysocki 		if (dmi_matches(d))
864d7b1956fSRafael J. Wysocki 			return d;
865d7b1956fSRafael J. Wysocki 
866d7b1956fSRafael J. Wysocki 	return NULL;
867d7b1956fSRafael J. Wysocki }
868d7b1956fSRafael J. Wysocki EXPORT_SYMBOL(dmi_first_match);
869d7b1956fSRafael J. Wysocki 
870d7b1956fSRafael J. Wysocki /**
8714f705ae3SBjorn Helgaas  *	dmi_get_system_info - return DMI data value
872b0ef371eSRandy Dunlap  *	@field: data index (see enum dmi_field)
8734f705ae3SBjorn Helgaas  *
8744f705ae3SBjorn Helgaas  *	Returns one DMI data value, can be used to perform
8754f705ae3SBjorn Helgaas  *	complex DMI data checks.
8764f705ae3SBjorn Helgaas  */
8771855256cSJeff Garzik const char *dmi_get_system_info(int field)
8784f705ae3SBjorn Helgaas {
8794f705ae3SBjorn Helgaas 	return dmi_ident[field];
8804f705ae3SBjorn Helgaas }
8814f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_get_system_info);
8824f705ae3SBjorn Helgaas 
883fd8cd7e1SAlok Kataria /**
884c2bacfc4SRandy Dunlap  * dmi_name_in_serial - Check if string is in the DMI product serial information
885c2bacfc4SRandy Dunlap  * @str: string to check for
886fd8cd7e1SAlok Kataria  */
887fd8cd7e1SAlok Kataria int dmi_name_in_serial(const char *str)
888fd8cd7e1SAlok Kataria {
889fd8cd7e1SAlok Kataria 	int f = DMI_PRODUCT_SERIAL;
890fd8cd7e1SAlok Kataria 	if (dmi_ident[f] && strstr(dmi_ident[f], str))
891fd8cd7e1SAlok Kataria 		return 1;
892fd8cd7e1SAlok Kataria 	return 0;
893fd8cd7e1SAlok Kataria }
894a1bae672SAndi Kleen 
895a1bae672SAndi Kleen /**
89666e13e66SJean Delvare  *	dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
897a1bae672SAndi Kleen  *	@str: Case sensitive Name
898a1bae672SAndi Kleen  */
8991855256cSJeff Garzik int dmi_name_in_vendors(const char *str)
900a1bae672SAndi Kleen {
90166e13e66SJean Delvare 	static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
902a1bae672SAndi Kleen 	int i;
903a1bae672SAndi Kleen 	for (i = 0; fields[i] != DMI_NONE; i++) {
904a1bae672SAndi Kleen 		int f = fields[i];
905a1bae672SAndi Kleen 		if (dmi_ident[f] && strstr(dmi_ident[f], str))
906a1bae672SAndi Kleen 			return 1;
907a1bae672SAndi Kleen 	}
908a1bae672SAndi Kleen 	return 0;
909a1bae672SAndi Kleen }
910a1bae672SAndi Kleen EXPORT_SYMBOL(dmi_name_in_vendors);
911a1bae672SAndi Kleen 
9124f705ae3SBjorn Helgaas /**
9134f705ae3SBjorn Helgaas  *	dmi_find_device - find onboard device by type/name
9144f705ae3SBjorn Helgaas  *	@type: device type or %DMI_DEV_TYPE_ANY to match all device types
915b0ef371eSRandy Dunlap  *	@name: device name string or %NULL to match all
9164f705ae3SBjorn Helgaas  *	@from: previous device found in search, or %NULL for new search.
9174f705ae3SBjorn Helgaas  *
9184f705ae3SBjorn Helgaas  *	Iterates through the list of known onboard devices. If a device is
919bfab8b48SJean Delvare  *	found with a matching @type and @name, a pointer to its device
9204f705ae3SBjorn Helgaas  *	structure is returned.  Otherwise, %NULL is returned.
921b0ef371eSRandy Dunlap  *	A new search is initiated by passing %NULL as the @from argument.
9224f705ae3SBjorn Helgaas  *	If @from is not %NULL, searches continue from next device.
9234f705ae3SBjorn Helgaas  */
9241855256cSJeff Garzik const struct dmi_device *dmi_find_device(int type, const char *name,
9251855256cSJeff Garzik 				    const struct dmi_device *from)
9264f705ae3SBjorn Helgaas {
9271855256cSJeff Garzik 	const struct list_head *head = from ? &from->list : &dmi_devices;
9281855256cSJeff Garzik 	struct list_head *d;
9294f705ae3SBjorn Helgaas 
9304f705ae3SBjorn Helgaas 	for (d = head->next; d != &dmi_devices; d = d->next) {
9311855256cSJeff Garzik 		const struct dmi_device *dev =
9321855256cSJeff Garzik 			list_entry(d, struct dmi_device, list);
9334f705ae3SBjorn Helgaas 
9344f705ae3SBjorn Helgaas 		if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
9354f705ae3SBjorn Helgaas 		    ((name == NULL) || (strcmp(dev->name, name) == 0)))
9364f705ae3SBjorn Helgaas 			return dev;
9374f705ae3SBjorn Helgaas 	}
9384f705ae3SBjorn Helgaas 
9394f705ae3SBjorn Helgaas 	return NULL;
9404f705ae3SBjorn Helgaas }
9414f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_find_device);
9424f705ae3SBjorn Helgaas 
9434f705ae3SBjorn Helgaas /**
9443e5cd1f2STejun Heo  *	dmi_get_date - parse a DMI date
9453e5cd1f2STejun Heo  *	@field:	data index (see enum dmi_field)
9463e5cd1f2STejun Heo  *	@yearp: optional out parameter for the year
9473e5cd1f2STejun Heo  *	@monthp: optional out parameter for the month
9483e5cd1f2STejun Heo  *	@dayp: optional out parameter for the day
9494f705ae3SBjorn Helgaas  *
9503e5cd1f2STejun Heo  *	The date field is assumed to be in the form resembling
9513e5cd1f2STejun Heo  *	[mm[/dd]]/yy[yy] and the result is stored in the out
9523e5cd1f2STejun Heo  *	parameters any or all of which can be omitted.
9533e5cd1f2STejun Heo  *
9543e5cd1f2STejun Heo  *	If the field doesn't exist, all out parameters are set to zero
9553e5cd1f2STejun Heo  *	and false is returned.  Otherwise, true is returned with any
9563e5cd1f2STejun Heo  *	invalid part of date set to zero.
9573e5cd1f2STejun Heo  *
9583e5cd1f2STejun Heo  *	On return, year, month and day are guaranteed to be in the
9593e5cd1f2STejun Heo  *	range of [0,9999], [0,12] and [0,31] respectively.
9604f705ae3SBjorn Helgaas  */
9613e5cd1f2STejun Heo bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
9624f705ae3SBjorn Helgaas {
9633e5cd1f2STejun Heo 	int year = 0, month = 0, day = 0;
9643e5cd1f2STejun Heo 	bool exists;
9653e5cd1f2STejun Heo 	const char *s, *y;
96602c24fa8STejun Heo 	char *e;
9674f705ae3SBjorn Helgaas 
9683e5cd1f2STejun Heo 	s = dmi_get_system_info(field);
9693e5cd1f2STejun Heo 	exists = s;
9703e5cd1f2STejun Heo 	if (!exists)
9713e5cd1f2STejun Heo 		goto out;
9724f705ae3SBjorn Helgaas 
9733e5cd1f2STejun Heo 	/*
9743e5cd1f2STejun Heo 	 * Determine year first.  We assume the date string resembles
9753e5cd1f2STejun Heo 	 * mm/dd/yy[yy] but the original code extracted only the year
9763e5cd1f2STejun Heo 	 * from the end.  Keep the behavior in the spirit of no
9773e5cd1f2STejun Heo 	 * surprises.
9783e5cd1f2STejun Heo 	 */
9793e5cd1f2STejun Heo 	y = strrchr(s, '/');
9803e5cd1f2STejun Heo 	if (!y)
9813e5cd1f2STejun Heo 		goto out;
9823e5cd1f2STejun Heo 
9833e5cd1f2STejun Heo 	y++;
9843e5cd1f2STejun Heo 	year = simple_strtoul(y, &e, 10);
9853e5cd1f2STejun Heo 	if (y != e && year < 100) {	/* 2-digit year */
9864f705ae3SBjorn Helgaas 		year += 1900;
9874f705ae3SBjorn Helgaas 		if (year < 1996)	/* no dates < spec 1.0 */
9884f705ae3SBjorn Helgaas 			year += 100;
9894f705ae3SBjorn Helgaas 	}
9903e5cd1f2STejun Heo 	if (year > 9999)		/* year should fit in %04d */
9913e5cd1f2STejun Heo 		year = 0;
9924f705ae3SBjorn Helgaas 
9933e5cd1f2STejun Heo 	/* parse the mm and dd */
9943e5cd1f2STejun Heo 	month = simple_strtoul(s, &e, 10);
9953e5cd1f2STejun Heo 	if (s == e || *e != '/' || !month || month > 12) {
9963e5cd1f2STejun Heo 		month = 0;
9973e5cd1f2STejun Heo 		goto out;
9984f705ae3SBjorn Helgaas 	}
9993e5cd1f2STejun Heo 
10003e5cd1f2STejun Heo 	s = e + 1;
10013e5cd1f2STejun Heo 	day = simple_strtoul(s, &e, 10);
10023e5cd1f2STejun Heo 	if (s == y || s == e || *e != '/' || day > 31)
10033e5cd1f2STejun Heo 		day = 0;
10043e5cd1f2STejun Heo out:
10053e5cd1f2STejun Heo 	if (yearp)
10063e5cd1f2STejun Heo 		*yearp = year;
10073e5cd1f2STejun Heo 	if (monthp)
10083e5cd1f2STejun Heo 		*monthp = month;
10093e5cd1f2STejun Heo 	if (dayp)
10103e5cd1f2STejun Heo 		*dayp = day;
10113e5cd1f2STejun Heo 	return exists;
10123e5cd1f2STejun Heo }
10133e5cd1f2STejun Heo EXPORT_SYMBOL(dmi_get_date);
10147fce084aSJean Delvare 
10157fce084aSJean Delvare /**
10167fce084aSJean Delvare  *	dmi_walk - Walk the DMI table and get called back for every record
10177fce084aSJean Delvare  *	@decode: Callback function
1018e7a19c56SJean Delvare  *	@private_data: Private data to be passed to the callback function
10197fce084aSJean Delvare  *
1020c9268200SAndy Lutomirski  *	Returns 0 on success, -ENXIO if DMI is not selected or not present,
1021c9268200SAndy Lutomirski  *	or a different negative error code if DMI walking fails.
10227fce084aSJean Delvare  */
1023e7a19c56SJean Delvare int dmi_walk(void (*decode)(const struct dmi_header *, void *),
1024e7a19c56SJean Delvare 	     void *private_data)
10257fce084aSJean Delvare {
10267fce084aSJean Delvare 	u8 *buf;
10277fce084aSJean Delvare 
10287fce084aSJean Delvare 	if (!dmi_available)
1029c9268200SAndy Lutomirski 		return -ENXIO;
10307fce084aSJean Delvare 
1031cf074402SArd Biesheuvel 	buf = dmi_remap(dmi_base, dmi_len);
10327fce084aSJean Delvare 	if (buf == NULL)
1033c9268200SAndy Lutomirski 		return -ENOMEM;
10347fce084aSJean Delvare 
1035eb4c5ea5SIvan Khoronzhuk 	dmi_decode_table(buf, decode, private_data);
10367fce084aSJean Delvare 
1037cf074402SArd Biesheuvel 	dmi_unmap(buf);
10387fce084aSJean Delvare 	return 0;
10397fce084aSJean Delvare }
10407fce084aSJean Delvare EXPORT_SYMBOL_GPL(dmi_walk);
1041d61c72e5SJiri Slaby 
1042d61c72e5SJiri Slaby /**
1043d61c72e5SJiri Slaby  * dmi_match - compare a string to the dmi field (if exists)
1044c2bacfc4SRandy Dunlap  * @f: DMI field identifier
1045c2bacfc4SRandy Dunlap  * @str: string to compare the DMI field to
1046d61c72e5SJiri Slaby  *
1047d61c72e5SJiri Slaby  * Returns true if the requested field equals to the str (including NULL).
1048d61c72e5SJiri Slaby  */
1049d61c72e5SJiri Slaby bool dmi_match(enum dmi_field f, const char *str)
1050d61c72e5SJiri Slaby {
1051d61c72e5SJiri Slaby 	const char *info = dmi_get_system_info(f);
1052d61c72e5SJiri Slaby 
1053d61c72e5SJiri Slaby 	if (info == NULL || str == NULL)
1054d61c72e5SJiri Slaby 		return info == str;
1055d61c72e5SJiri Slaby 
1056d61c72e5SJiri Slaby 	return !strcmp(info, str);
1057d61c72e5SJiri Slaby }
1058d61c72e5SJiri Slaby EXPORT_SYMBOL_GPL(dmi_match);
1059dd6dad42SChen, Gong 
1060dd6dad42SChen, Gong void dmi_memdev_name(u16 handle, const char **bank, const char **device)
1061dd6dad42SChen, Gong {
1062dd6dad42SChen, Gong 	int n;
1063dd6dad42SChen, Gong 
1064dd6dad42SChen, Gong 	if (dmi_memdev == NULL)
1065dd6dad42SChen, Gong 		return;
1066dd6dad42SChen, Gong 
1067dd6dad42SChen, Gong 	for (n = 0; n < dmi_memdev_nr; n++) {
1068dd6dad42SChen, Gong 		if (handle == dmi_memdev[n].handle) {
1069dd6dad42SChen, Gong 			*bank = dmi_memdev[n].bank;
1070dd6dad42SChen, Gong 			*device = dmi_memdev[n].device;
1071dd6dad42SChen, Gong 			break;
1072dd6dad42SChen, Gong 		}
1073dd6dad42SChen, Gong 	}
1074dd6dad42SChen, Gong }
1075dd6dad42SChen, Gong EXPORT_SYMBOL_GPL(dmi_memdev_name);
1076