xref: /linux/drivers/firmware/dmi_scan.c (revision c9aba14362a6eec583819ec8f4b872c1816f5cbe)
14f705ae3SBjorn Helgaas #include <linux/types.h>
24f705ae3SBjorn Helgaas #include <linux/string.h>
34f705ae3SBjorn Helgaas #include <linux/init.h>
44f705ae3SBjorn Helgaas #include <linux/module.h>
58881cdceSBjorn Helgaas #include <linux/ctype.h>
64f705ae3SBjorn Helgaas #include <linux/dmi.h>
74f705ae3SBjorn Helgaas #include <linux/efi.h>
84f705ae3SBjorn Helgaas #include <linux/bootmem.h>
9d114a333STony Luck #include <linux/random.h>
104f705ae3SBjorn Helgaas #include <asm/dmi.h>
110841c04dSLuck, Tony #include <asm/unaligned.h>
124f705ae3SBjorn Helgaas 
13d7f96f97SIvan Khoronzhuk struct kobject *dmi_kobj;
14d7f96f97SIvan Khoronzhuk EXPORT_SYMBOL_GPL(dmi_kobj);
15d7f96f97SIvan Khoronzhuk 
16cb5dd7c1SPaul Jackson /*
17cb5dd7c1SPaul Jackson  * DMI stands for "Desktop Management Interface".  It is part
18cb5dd7c1SPaul Jackson  * of and an antecedent to, SMBIOS, which stands for System
19cb5dd7c1SPaul Jackson  * Management BIOS.  See further: http://www.dmtf.org/standards
20cb5dd7c1SPaul Jackson  */
21ffbbb96dSJean Delvare static const char dmi_empty_string[] = "        ";
2279da4721SParag Warudkar 
2395be58dfSIvan Khoronzhuk static u32 dmi_ver __initdata;
24552e19d8SIvan Khoronzhuk static u32 dmi_len;
25552e19d8SIvan Khoronzhuk static u16 dmi_num;
26d7f96f97SIvan Khoronzhuk static u8 smbios_entry_point[32];
27d7f96f97SIvan Khoronzhuk static int smbios_entry_point_size;
28d7f96f97SIvan Khoronzhuk 
299a22b6e7SIngo Molnar /*
309a22b6e7SIngo Molnar  * Catch too early calls to dmi_check_system():
319a22b6e7SIngo Molnar  */
329a22b6e7SIngo Molnar static int dmi_initialized;
339a22b6e7SIngo Molnar 
34c90fe6bcSTejun Heo /* DMI system identification string used during boot */
35c90fe6bcSTejun Heo static char dmi_ids_string[128] __initdata;
36c90fe6bcSTejun Heo 
37dd6dad42SChen, Gong static struct dmi_memdev_info {
38dd6dad42SChen, Gong 	const char *device;
39dd6dad42SChen, Gong 	const char *bank;
40dd6dad42SChen, Gong 	u16 handle;
41dd6dad42SChen, Gong } *dmi_memdev;
42dd6dad42SChen, Gong static int dmi_memdev_nr;
43dd6dad42SChen, Gong 
44f3069ae9SJean Delvare static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
454f705ae3SBjorn Helgaas {
461855256cSJeff Garzik 	const u8 *bp = ((u8 *) dm) + dm->length;
474f705ae3SBjorn Helgaas 
484f705ae3SBjorn Helgaas 	if (s) {
494f705ae3SBjorn Helgaas 		s--;
504f705ae3SBjorn Helgaas 		while (s > 0 && *bp) {
514f705ae3SBjorn Helgaas 			bp += strlen(bp) + 1;
524f705ae3SBjorn Helgaas 			s--;
534f705ae3SBjorn Helgaas 		}
544f705ae3SBjorn Helgaas 
554f705ae3SBjorn Helgaas 		if (*bp != 0) {
5679da4721SParag Warudkar 			size_t len = strlen(bp)+1;
5779da4721SParag Warudkar 			size_t cmp_len = len > 8 ? 8 : len;
5879da4721SParag Warudkar 
5979da4721SParag Warudkar 			if (!memcmp(bp, dmi_empty_string, cmp_len))
6079da4721SParag Warudkar 				return dmi_empty_string;
61f3069ae9SJean Delvare 			return bp;
62f3069ae9SJean Delvare 		}
63f3069ae9SJean Delvare 	}
64f3069ae9SJean Delvare 
65f3069ae9SJean Delvare 	return "";
66f3069ae9SJean Delvare }
67f3069ae9SJean Delvare 
68ffbbb96dSJean Delvare static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
69f3069ae9SJean Delvare {
70f3069ae9SJean Delvare 	const char *bp = dmi_string_nosave(dm, s);
71f3069ae9SJean Delvare 	char *str;
72f3069ae9SJean Delvare 	size_t len;
73f3069ae9SJean Delvare 
74f3069ae9SJean Delvare 	if (bp == dmi_empty_string)
75f3069ae9SJean Delvare 		return dmi_empty_string;
76f3069ae9SJean Delvare 
77f3069ae9SJean Delvare 	len = strlen(bp) + 1;
7879da4721SParag Warudkar 	str = dmi_alloc(len);
794f705ae3SBjorn Helgaas 	if (str != NULL)
804f705ae3SBjorn Helgaas 		strcpy(str, bp);
814f705ae3SBjorn Helgaas 
824f705ae3SBjorn Helgaas 	return str;
834f705ae3SBjorn Helgaas }
844f705ae3SBjorn Helgaas 
854f705ae3SBjorn Helgaas /*
864f705ae3SBjorn Helgaas  *	We have to be cautious here. We have seen BIOSes with DMI pointers
874f705ae3SBjorn Helgaas  *	pointing to completely the wrong place for example
884f705ae3SBjorn Helgaas  */
89eb4c5ea5SIvan Khoronzhuk static void dmi_decode_table(u8 *buf,
90e7a19c56SJean Delvare 			     void (*decode)(const struct dmi_header *, void *),
91e7a19c56SJean Delvare 			     void *private_data)
924f705ae3SBjorn Helgaas {
937fce084aSJean Delvare 	u8 *data = buf;
944f705ae3SBjorn Helgaas 	int i = 0;
954f705ae3SBjorn Helgaas 
964f705ae3SBjorn Helgaas 	/*
97bfbaafaeSJean Delvare 	 * Stop when we have seen all the items the table claimed to have
9817cd5bd5SJean Delvare 	 * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS
9917cd5bd5SJean Delvare 	 * >= 3.0 only) OR we run off the end of the table (should never
10017cd5bd5SJean Delvare 	 * happen but sometimes does on bogus implementations.)
1014f705ae3SBjorn Helgaas 	 */
1029c65e12aSLinus Torvalds 	while ((!dmi_num || i < dmi_num) &&
1039c65e12aSLinus Torvalds 	       (data - buf + sizeof(struct dmi_header)) <= dmi_len) {
1041855256cSJeff Garzik 		const struct dmi_header *dm = (const struct dmi_header *)data;
1051855256cSJeff Garzik 
1064f705ae3SBjorn Helgaas 		/*
1078638545cSAlan Cox 		 *  We want to know the total length (formatted area and
1088638545cSAlan Cox 		 *  strings) before decoding to make sure we won't run off the
1098638545cSAlan Cox 		 *  table in dmi_decode or dmi_string
1104f705ae3SBjorn Helgaas 		 */
1114f705ae3SBjorn Helgaas 		data += dm->length;
112552e19d8SIvan Khoronzhuk 		while ((data - buf < dmi_len - 1) && (data[0] || data[1]))
1134f705ae3SBjorn Helgaas 			data++;
114552e19d8SIvan Khoronzhuk 		if (data - buf < dmi_len - 1)
115e7a19c56SJean Delvare 			decode(dm, private_data);
116ce204e9aSIvan Khoronzhuk 
1176e0ad59eSJean Delvare 		data += 2;
1186e0ad59eSJean Delvare 		i++;
1196e0ad59eSJean Delvare 
120ce204e9aSIvan Khoronzhuk 		/*
121ce204e9aSIvan Khoronzhuk 		 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
12217cd5bd5SJean Delvare 		 * For tables behind a 64-bit entry point, we have no item
12317cd5bd5SJean Delvare 		 * count and no exact table length, so stop on end-of-table
12417cd5bd5SJean Delvare 		 * marker. For tables behind a 32-bit entry point, we have
12517cd5bd5SJean Delvare 		 * seen OEM structures behind the end-of-table marker on
12617cd5bd5SJean Delvare 		 * some systems, so don't trust it.
127ce204e9aSIvan Khoronzhuk 		 */
12817cd5bd5SJean Delvare 		if (!dmi_num && dm->type == DMI_ENTRY_END_OF_TABLE)
129ce204e9aSIvan Khoronzhuk 			break;
1304f705ae3SBjorn Helgaas 	}
1316e0ad59eSJean Delvare 
1326e0ad59eSJean Delvare 	/* Trim DMI table length if needed */
1336e0ad59eSJean Delvare 	if (dmi_len > data - buf)
1346e0ad59eSJean Delvare 		dmi_len = data - buf;
1357fce084aSJean Delvare }
1367fce084aSJean Delvare 
137fc430262SArd Biesheuvel static phys_addr_t dmi_base;
1387fce084aSJean Delvare 
139e7a19c56SJean Delvare static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
140e7a19c56SJean Delvare 		void *))
1417fce084aSJean Delvare {
1427fce084aSJean Delvare 	u8 *buf;
1436e0ad59eSJean Delvare 	u32 orig_dmi_len = dmi_len;
1447fce084aSJean Delvare 
1456e0ad59eSJean Delvare 	buf = dmi_early_remap(dmi_base, orig_dmi_len);
1467fce084aSJean Delvare 	if (buf == NULL)
1477fce084aSJean Delvare 		return -1;
1487fce084aSJean Delvare 
149eb4c5ea5SIvan Khoronzhuk 	dmi_decode_table(buf, decode, NULL);
1507fce084aSJean Delvare 
151d114a333STony Luck 	add_device_randomness(buf, dmi_len);
152d114a333STony Luck 
1536e0ad59eSJean Delvare 	dmi_early_unmap(buf, orig_dmi_len);
1544f705ae3SBjorn Helgaas 	return 0;
1554f705ae3SBjorn Helgaas }
1564f705ae3SBjorn Helgaas 
1579f9c9cbbSZhenzhong Duan static int __init dmi_checksum(const u8 *buf, u8 len)
1584f705ae3SBjorn Helgaas {
1594f705ae3SBjorn Helgaas 	u8 sum = 0;
1604f705ae3SBjorn Helgaas 	int a;
1614f705ae3SBjorn Helgaas 
1629f9c9cbbSZhenzhong Duan 	for (a = 0; a < len; a++)
1634f705ae3SBjorn Helgaas 		sum += buf[a];
1644f705ae3SBjorn Helgaas 
1654f705ae3SBjorn Helgaas 	return sum == 0;
1664f705ae3SBjorn Helgaas }
1674f705ae3SBjorn Helgaas 
168ffbbb96dSJean Delvare static const char *dmi_ident[DMI_STRING_MAX];
1694f705ae3SBjorn Helgaas static LIST_HEAD(dmi_devices);
1704f5c791aSLennart Poettering int dmi_available;
1714f705ae3SBjorn Helgaas 
1724f705ae3SBjorn Helgaas /*
1734f705ae3SBjorn Helgaas  *	Save a DMI string
1744f705ae3SBjorn Helgaas  */
17502d9c47fSJean Delvare static void __init dmi_save_ident(const struct dmi_header *dm, int slot,
17602d9c47fSJean Delvare 		int string)
1774f705ae3SBjorn Helgaas {
1781855256cSJeff Garzik 	const char *d = (const char *) dm;
179ffbbb96dSJean Delvare 	const char *p;
1804f705ae3SBjorn Helgaas 
1814f705ae3SBjorn Helgaas 	if (dmi_ident[slot])
1824f705ae3SBjorn Helgaas 		return;
1834f705ae3SBjorn Helgaas 
1844f705ae3SBjorn Helgaas 	p = dmi_string(dm, d[string]);
1854f705ae3SBjorn Helgaas 	if (p == NULL)
1864f705ae3SBjorn Helgaas 		return;
1874f705ae3SBjorn Helgaas 
1884f705ae3SBjorn Helgaas 	dmi_ident[slot] = p;
1894f705ae3SBjorn Helgaas }
1904f705ae3SBjorn Helgaas 
19102d9c47fSJean Delvare static void __init dmi_save_uuid(const struct dmi_header *dm, int slot,
19202d9c47fSJean Delvare 		int index)
1934f5c791aSLennart Poettering {
1941855256cSJeff Garzik 	const u8 *d = (u8 *) dm + index;
1954f5c791aSLennart Poettering 	char *s;
1964f5c791aSLennart Poettering 	int is_ff = 1, is_00 = 1, i;
1974f5c791aSLennart Poettering 
1984f5c791aSLennart Poettering 	if (dmi_ident[slot])
1994f5c791aSLennart Poettering 		return;
2004f5c791aSLennart Poettering 
2014f5c791aSLennart Poettering 	for (i = 0; i < 16 && (is_ff || is_00); i++) {
202f1d8e614SZhenzhong Duan 		if (d[i] != 0x00)
203f1d8e614SZhenzhong Duan 			is_00 = 0;
204f1d8e614SZhenzhong Duan 		if (d[i] != 0xFF)
205f1d8e614SZhenzhong Duan 			is_ff = 0;
2064f5c791aSLennart Poettering 	}
2074f5c791aSLennart Poettering 
2084f5c791aSLennart Poettering 	if (is_ff || is_00)
2094f5c791aSLennart Poettering 		return;
2104f5c791aSLennart Poettering 
2114f5c791aSLennart Poettering 	s = dmi_alloc(16*2+4+1);
2124f5c791aSLennart Poettering 	if (!s)
2134f5c791aSLennart Poettering 		return;
2144f5c791aSLennart Poettering 
215f1d8e614SZhenzhong Duan 	/*
216f1d8e614SZhenzhong Duan 	 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
217f1d8e614SZhenzhong Duan 	 * the UUID are supposed to be little-endian encoded.  The specification
218f1d8e614SZhenzhong Duan 	 * says that this is the defacto standard.
219f1d8e614SZhenzhong Duan 	 */
22095be58dfSIvan Khoronzhuk 	if (dmi_ver >= 0x020600)
221f1d8e614SZhenzhong Duan 		sprintf(s, "%pUL", d);
222f1d8e614SZhenzhong Duan 	else
223bc058f65SJoe Perches 		sprintf(s, "%pUB", d);
2244f5c791aSLennart Poettering 
2254f5c791aSLennart Poettering 	dmi_ident[slot] = s;
2264f5c791aSLennart Poettering }
2274f5c791aSLennart Poettering 
22802d9c47fSJean Delvare static void __init dmi_save_type(const struct dmi_header *dm, int slot,
22902d9c47fSJean Delvare 		int index)
2304f5c791aSLennart Poettering {
2311855256cSJeff Garzik 	const u8 *d = (u8 *) dm + index;
2324f5c791aSLennart Poettering 	char *s;
2334f5c791aSLennart Poettering 
2344f5c791aSLennart Poettering 	if (dmi_ident[slot])
2354f5c791aSLennart Poettering 		return;
2364f5c791aSLennart Poettering 
2374f5c791aSLennart Poettering 	s = dmi_alloc(4);
2384f5c791aSLennart Poettering 	if (!s)
2394f5c791aSLennart Poettering 		return;
2404f5c791aSLennart Poettering 
2414f5c791aSLennart Poettering 	sprintf(s, "%u", *d & 0x7F);
2424f5c791aSLennart Poettering 	dmi_ident[slot] = s;
2434f5c791aSLennart Poettering }
2444f5c791aSLennart Poettering 
245f3069ae9SJean Delvare static void __init dmi_save_one_device(int type, const char *name)
246f3069ae9SJean Delvare {
247f3069ae9SJean Delvare 	struct dmi_device *dev;
248f3069ae9SJean Delvare 
249f3069ae9SJean Delvare 	/* No duplicate device */
250f3069ae9SJean Delvare 	if (dmi_find_device(type, name, NULL))
251f3069ae9SJean Delvare 		return;
252f3069ae9SJean Delvare 
253f3069ae9SJean Delvare 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
254ae797449SJean Delvare 	if (!dev)
255f3069ae9SJean Delvare 		return;
256f3069ae9SJean Delvare 
257f3069ae9SJean Delvare 	dev->type = type;
258f3069ae9SJean Delvare 	strcpy((char *)(dev + 1), name);
259f3069ae9SJean Delvare 	dev->name = (char *)(dev + 1);
260f3069ae9SJean Delvare 	dev->device_data = NULL;
261f3069ae9SJean Delvare 	list_add(&dev->list, &dmi_devices);
262f3069ae9SJean Delvare }
263f3069ae9SJean Delvare 
2641855256cSJeff Garzik static void __init dmi_save_devices(const struct dmi_header *dm)
2654f705ae3SBjorn Helgaas {
2664f705ae3SBjorn Helgaas 	int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
2674f705ae3SBjorn Helgaas 
2684f705ae3SBjorn Helgaas 	for (i = 0; i < count; i++) {
2691855256cSJeff Garzik 		const char *d = (char *)(dm + 1) + (i * 2);
2704f705ae3SBjorn Helgaas 
2714f705ae3SBjorn Helgaas 		/* Skip disabled device */
2724f705ae3SBjorn Helgaas 		if ((*d & 0x80) == 0)
2734f705ae3SBjorn Helgaas 			continue;
2744f705ae3SBjorn Helgaas 
275f3069ae9SJean Delvare 		dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
2762e0c1f6cSShem Multinymous 	}
2772e0c1f6cSShem Multinymous }
2782e0c1f6cSShem Multinymous 
2791855256cSJeff Garzik static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
2802e0c1f6cSShem Multinymous {
2812e0c1f6cSShem Multinymous 	int i, count = *(u8 *)(dm + 1);
2822e0c1f6cSShem Multinymous 	struct dmi_device *dev;
2832e0c1f6cSShem Multinymous 
2842e0c1f6cSShem Multinymous 	for (i = 1; i <= count; i++) {
285ffbbb96dSJean Delvare 		const char *devname = dmi_string(dm, i);
28679da4721SParag Warudkar 
28743fe105aSJean Delvare 		if (devname == dmi_empty_string)
28879da4721SParag Warudkar 			continue;
28979da4721SParag Warudkar 
2902e0c1f6cSShem Multinymous 		dev = dmi_alloc(sizeof(*dev));
291ae797449SJean Delvare 		if (!dev)
2922e0c1f6cSShem Multinymous 			break;
2932e0c1f6cSShem Multinymous 
2942e0c1f6cSShem Multinymous 		dev->type = DMI_DEV_TYPE_OEM_STRING;
29579da4721SParag Warudkar 		dev->name = devname;
2962e0c1f6cSShem Multinymous 		dev->device_data = NULL;
2974f705ae3SBjorn Helgaas 
2984f705ae3SBjorn Helgaas 		list_add(&dev->list, &dmi_devices);
2994f705ae3SBjorn Helgaas 	}
3004f705ae3SBjorn Helgaas }
3014f705ae3SBjorn Helgaas 
3021855256cSJeff Garzik static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
3034f705ae3SBjorn Helgaas {
3044f705ae3SBjorn Helgaas 	struct dmi_device *dev;
3054f705ae3SBjorn Helgaas 	void *data;
3064f705ae3SBjorn Helgaas 
3074f705ae3SBjorn Helgaas 	data = dmi_alloc(dm->length);
308ae797449SJean Delvare 	if (data == NULL)
3094f705ae3SBjorn Helgaas 		return;
3104f705ae3SBjorn Helgaas 
3114f705ae3SBjorn Helgaas 	memcpy(data, dm, dm->length);
3124f705ae3SBjorn Helgaas 
3134f705ae3SBjorn Helgaas 	dev = dmi_alloc(sizeof(*dev));
314ae797449SJean Delvare 	if (!dev)
3154f705ae3SBjorn Helgaas 		return;
3164f705ae3SBjorn Helgaas 
3174f705ae3SBjorn Helgaas 	dev->type = DMI_DEV_TYPE_IPMI;
3184f705ae3SBjorn Helgaas 	dev->name = "IPMI controller";
3194f705ae3SBjorn Helgaas 	dev->device_data = data;
3204f705ae3SBjorn Helgaas 
321abd24df8SCarol Hebert 	list_add_tail(&dev->list, &dmi_devices);
3224f705ae3SBjorn Helgaas }
3234f705ae3SBjorn Helgaas 
324e5b6c151SJordan Hargrave static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus,
325e5b6c151SJordan Hargrave 					int devfn, const char *name, int type)
326911e1c9bSNarendra K {
327e5b6c151SJordan Hargrave 	struct dmi_dev_onboard *dev;
328911e1c9bSNarendra K 
329e5b6c151SJordan Hargrave 	/* Ignore invalid values */
330e5b6c151SJordan Hargrave 	if (type == DMI_DEV_TYPE_DEV_SLOT &&
331e5b6c151SJordan Hargrave 	    segment == 0xFFFF && bus == 0xFF && devfn == 0xFF)
332911e1c9bSNarendra K 		return;
333ae797449SJean Delvare 
334e5b6c151SJordan Hargrave 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
335e5b6c151SJordan Hargrave 	if (!dev)
336e5b6c151SJordan Hargrave 		return;
337911e1c9bSNarendra K 
338e5b6c151SJordan Hargrave 	dev->instance = instance;
339e5b6c151SJordan Hargrave 	dev->segment = segment;
340e5b6c151SJordan Hargrave 	dev->bus = bus;
341e5b6c151SJordan Hargrave 	dev->devfn = devfn;
342911e1c9bSNarendra K 
343e5b6c151SJordan Hargrave 	strcpy((char *)&dev[1], name);
344e5b6c151SJordan Hargrave 	dev->dev.type = type;
345e5b6c151SJordan Hargrave 	dev->dev.name = (char *)&dev[1];
346e5b6c151SJordan Hargrave 	dev->dev.device_data = dev;
347e5b6c151SJordan Hargrave 
348e5b6c151SJordan Hargrave 	list_add(&dev->dev.list, &dmi_devices);
349911e1c9bSNarendra K }
350911e1c9bSNarendra K 
351b4bd7d59SWim Van Sebroeck static void __init dmi_save_extended_devices(const struct dmi_header *dm)
352b4bd7d59SWim Van Sebroeck {
35396e23943SJean Delvare 	const char *name;
35445b98257SJean Delvare 	const u8 *d = (u8 *)dm;
355b4bd7d59SWim Van Sebroeck 
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 
390dd6dad42SChen, Gong 	if (dm->type != DMI_ENTRY_MEM_DEVICE)
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;
627fc430262SArd Biesheuvel 				goto out;
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;
6459a22b6e7SIngo Molnar 			goto out;
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 		/*
653*c9aba143SJean Delvare 		 * Same logic as above, look for a 64-bit entry point
654*c9aba143SJean Delvare 		 * first, and if not found, fall back to 32-bit entry point.
655*c9aba143SJean Delvare 		 */
656*c9aba143SJean Delvare 		memcpy_fromio(buf, p, 16);
657*c9aba143SJean Delvare 		for (q = p + 16; q < p + 0x10000; q += 16) {
658*c9aba143SJean Delvare 			memcpy_fromio(buf + 16, q, 16);
659*c9aba143SJean Delvare 			if (!dmi_smbios3_present(buf)) {
660*c9aba143SJean Delvare 				dmi_available = 1;
661*c9aba143SJean Delvare 				dmi_early_unmap(p, 0x10000);
662*c9aba143SJean Delvare 				goto out;
663*c9aba143SJean Delvare 			}
664*c9aba143SJean Delvare 			memcpy(buf, buf + 16, 16);
665*c9aba143SJean Delvare 		}
666*c9aba143SJean Delvare 
667*c9aba143SJean 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);
677*c9aba143SJean Delvare 			if (!dmi_present(buf)) {
6784f5c791aSLennart Poettering 				dmi_available = 1;
679cf074402SArd Biesheuvel 				dmi_early_unmap(p, 0x10000);
6809a22b6e7SIngo Molnar 				goto out;
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");
6889a22b6e7SIngo Molnar  out:
6899a22b6e7SIngo Molnar 	dmi_initialized = 1;
6904f705ae3SBjorn Helgaas }
6914f705ae3SBjorn Helgaas 
692d7f96f97SIvan Khoronzhuk static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
693d7f96f97SIvan Khoronzhuk 			      struct bin_attribute *attr, char *buf,
694d7f96f97SIvan Khoronzhuk 			      loff_t pos, size_t count)
695d7f96f97SIvan Khoronzhuk {
696d7f96f97SIvan Khoronzhuk 	memcpy(buf, attr->private + pos, count);
697d7f96f97SIvan Khoronzhuk 	return count;
698d7f96f97SIvan Khoronzhuk }
699d7f96f97SIvan Khoronzhuk 
700d7f96f97SIvan Khoronzhuk static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
701d7f96f97SIvan Khoronzhuk static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
702d7f96f97SIvan Khoronzhuk 
703d7f96f97SIvan Khoronzhuk static int __init dmi_init(void)
704d7f96f97SIvan Khoronzhuk {
705d7f96f97SIvan Khoronzhuk 	struct kobject *tables_kobj;
706d7f96f97SIvan Khoronzhuk 	u8 *dmi_table;
707d7f96f97SIvan Khoronzhuk 	int ret = -ENOMEM;
708d7f96f97SIvan Khoronzhuk 
709d7f96f97SIvan Khoronzhuk 	if (!dmi_available) {
710d7f96f97SIvan Khoronzhuk 		ret = -ENODATA;
711d7f96f97SIvan Khoronzhuk 		goto err;
712d7f96f97SIvan Khoronzhuk 	}
713d7f96f97SIvan Khoronzhuk 
714d7f96f97SIvan Khoronzhuk 	/*
715d7f96f97SIvan Khoronzhuk 	 * Set up dmi directory at /sys/firmware/dmi. This entry should stay
716d7f96f97SIvan Khoronzhuk 	 * even after farther error, as it can be used by other modules like
717d7f96f97SIvan Khoronzhuk 	 * dmi-sysfs.
718d7f96f97SIvan Khoronzhuk 	 */
719d7f96f97SIvan Khoronzhuk 	dmi_kobj = kobject_create_and_add("dmi", firmware_kobj);
720d7f96f97SIvan Khoronzhuk 	if (!dmi_kobj)
721d7f96f97SIvan Khoronzhuk 		goto err;
722d7f96f97SIvan Khoronzhuk 
723d7f96f97SIvan Khoronzhuk 	tables_kobj = kobject_create_and_add("tables", dmi_kobj);
724d7f96f97SIvan Khoronzhuk 	if (!tables_kobj)
725d7f96f97SIvan Khoronzhuk 		goto err;
726d7f96f97SIvan Khoronzhuk 
727d7f96f97SIvan Khoronzhuk 	dmi_table = dmi_remap(dmi_base, dmi_len);
728d7f96f97SIvan Khoronzhuk 	if (!dmi_table)
729d7f96f97SIvan Khoronzhuk 		goto err_tables;
730d7f96f97SIvan Khoronzhuk 
731d7f96f97SIvan Khoronzhuk 	bin_attr_smbios_entry_point.size = smbios_entry_point_size;
732d7f96f97SIvan Khoronzhuk 	bin_attr_smbios_entry_point.private = smbios_entry_point;
733d7f96f97SIvan Khoronzhuk 	ret = sysfs_create_bin_file(tables_kobj, &bin_attr_smbios_entry_point);
734d7f96f97SIvan Khoronzhuk 	if (ret)
735d7f96f97SIvan Khoronzhuk 		goto err_unmap;
736d7f96f97SIvan Khoronzhuk 
737d7f96f97SIvan Khoronzhuk 	bin_attr_DMI.size = dmi_len;
738d7f96f97SIvan Khoronzhuk 	bin_attr_DMI.private = dmi_table;
739d7f96f97SIvan Khoronzhuk 	ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI);
740d7f96f97SIvan Khoronzhuk 	if (!ret)
741d7f96f97SIvan Khoronzhuk 		return 0;
742d7f96f97SIvan Khoronzhuk 
743d7f96f97SIvan Khoronzhuk 	sysfs_remove_bin_file(tables_kobj,
744d7f96f97SIvan Khoronzhuk 			      &bin_attr_smbios_entry_point);
745d7f96f97SIvan Khoronzhuk  err_unmap:
746d7f96f97SIvan Khoronzhuk 	dmi_unmap(dmi_table);
747d7f96f97SIvan Khoronzhuk  err_tables:
748d7f96f97SIvan Khoronzhuk 	kobject_del(tables_kobj);
749d7f96f97SIvan Khoronzhuk 	kobject_put(tables_kobj);
750d7f96f97SIvan Khoronzhuk  err:
751d7f96f97SIvan Khoronzhuk 	pr_err("dmi: Firmware registration failed.\n");
752d7f96f97SIvan Khoronzhuk 
753d7f96f97SIvan Khoronzhuk 	return ret;
754d7f96f97SIvan Khoronzhuk }
755d7f96f97SIvan Khoronzhuk subsys_initcall(dmi_init);
756d7f96f97SIvan Khoronzhuk 
7574f705ae3SBjorn Helgaas /**
75898e5e1bfSTejun Heo  * dmi_set_dump_stack_arch_desc - set arch description for dump_stack()
75998e5e1bfSTejun Heo  *
76098e5e1bfSTejun Heo  * Invoke dump_stack_set_arch_desc() with DMI system information so that
76198e5e1bfSTejun Heo  * DMI identifiers are printed out on task dumps.  Arch boot code should
76298e5e1bfSTejun Heo  * call this function after dmi_scan_machine() if it wants to print out DMI
76398e5e1bfSTejun Heo  * identifiers on task dumps.
76498e5e1bfSTejun Heo  */
76598e5e1bfSTejun Heo void __init dmi_set_dump_stack_arch_desc(void)
76698e5e1bfSTejun Heo {
76798e5e1bfSTejun Heo 	dump_stack_set_arch_desc("%s", dmi_ids_string);
76898e5e1bfSTejun Heo }
76998e5e1bfSTejun Heo 
77098e5e1bfSTejun Heo /**
771d7b1956fSRafael J. Wysocki  *	dmi_matches - check if dmi_system_id structure matches system DMI data
772d7b1956fSRafael J. Wysocki  *	@dmi: pointer to the dmi_system_id structure to check
773d7b1956fSRafael J. Wysocki  */
774d7b1956fSRafael J. Wysocki static bool dmi_matches(const struct dmi_system_id *dmi)
775d7b1956fSRafael J. Wysocki {
776d7b1956fSRafael J. Wysocki 	int i;
777d7b1956fSRafael J. Wysocki 
778d7b1956fSRafael J. Wysocki 	WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
779d7b1956fSRafael J. Wysocki 
780d7b1956fSRafael J. Wysocki 	for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
781d7b1956fSRafael J. Wysocki 		int s = dmi->matches[i].slot;
782d7b1956fSRafael J. Wysocki 		if (s == DMI_NONE)
78375757507SDmitry Torokhov 			break;
7845017b285SJani Nikula 		if (dmi_ident[s]) {
7855017b285SJani Nikula 			if (!dmi->matches[i].exact_match &&
7865017b285SJani Nikula 			    strstr(dmi_ident[s], dmi->matches[i].substr))
787d7b1956fSRafael J. Wysocki 				continue;
7885017b285SJani Nikula 			else if (dmi->matches[i].exact_match &&
7895017b285SJani Nikula 				 !strcmp(dmi_ident[s], dmi->matches[i].substr))
7905017b285SJani Nikula 				continue;
7915017b285SJani Nikula 		}
7925017b285SJani Nikula 
793d7b1956fSRafael J. Wysocki 		/* No match */
794d7b1956fSRafael J. Wysocki 		return false;
795d7b1956fSRafael J. Wysocki 	}
796d7b1956fSRafael J. Wysocki 	return true;
797d7b1956fSRafael J. Wysocki }
798d7b1956fSRafael J. Wysocki 
799d7b1956fSRafael J. Wysocki /**
80075757507SDmitry Torokhov  *	dmi_is_end_of_table - check for end-of-table marker
80175757507SDmitry Torokhov  *	@dmi: pointer to the dmi_system_id structure to check
80275757507SDmitry Torokhov  */
80375757507SDmitry Torokhov static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
80475757507SDmitry Torokhov {
80575757507SDmitry Torokhov 	return dmi->matches[0].slot == DMI_NONE;
80675757507SDmitry Torokhov }
80775757507SDmitry Torokhov 
80875757507SDmitry Torokhov /**
8094f705ae3SBjorn Helgaas  *	dmi_check_system - check system DMI data
8104f705ae3SBjorn Helgaas  *	@list: array of dmi_system_id structures to match against
811b0ef371eSRandy Dunlap  *		All non-null elements of the list must match
812b0ef371eSRandy Dunlap  *		their slot's (field index's) data (i.e., each
813b0ef371eSRandy Dunlap  *		list string must be a substring of the specified
814b0ef371eSRandy Dunlap  *		DMI slot's string data) to be considered a
815b0ef371eSRandy Dunlap  *		successful match.
8164f705ae3SBjorn Helgaas  *
8174f705ae3SBjorn Helgaas  *	Walk the blacklist table running matching functions until someone
8184f705ae3SBjorn Helgaas  *	returns non zero or we hit the end. Callback function is called for
819b0ef371eSRandy Dunlap  *	each successful match. Returns the number of matches.
8204f705ae3SBjorn Helgaas  */
8211855256cSJeff Garzik int dmi_check_system(const struct dmi_system_id *list)
8224f705ae3SBjorn Helgaas {
823d7b1956fSRafael J. Wysocki 	int count = 0;
824d7b1956fSRafael J. Wysocki 	const struct dmi_system_id *d;
8254f705ae3SBjorn Helgaas 
82675757507SDmitry Torokhov 	for (d = list; !dmi_is_end_of_table(d); d++)
827d7b1956fSRafael J. Wysocki 		if (dmi_matches(d)) {
8284f705ae3SBjorn Helgaas 			count++;
8294f705ae3SBjorn Helgaas 			if (d->callback && d->callback(d))
8304f705ae3SBjorn Helgaas 				break;
8314f705ae3SBjorn Helgaas 		}
8324f705ae3SBjorn Helgaas 
8334f705ae3SBjorn Helgaas 	return count;
8344f705ae3SBjorn Helgaas }
8354f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_check_system);
8364f705ae3SBjorn Helgaas 
8374f705ae3SBjorn Helgaas /**
838d7b1956fSRafael J. Wysocki  *	dmi_first_match - find dmi_system_id structure matching system DMI data
839d7b1956fSRafael J. Wysocki  *	@list: array of dmi_system_id structures to match against
840d7b1956fSRafael J. Wysocki  *		All non-null elements of the list must match
841d7b1956fSRafael J. Wysocki  *		their slot's (field index's) data (i.e., each
842d7b1956fSRafael J. Wysocki  *		list string must be a substring of the specified
843d7b1956fSRafael J. Wysocki  *		DMI slot's string data) to be considered a
844d7b1956fSRafael J. Wysocki  *		successful match.
845d7b1956fSRafael J. Wysocki  *
846d7b1956fSRafael J. Wysocki  *	Walk the blacklist table until the first match is found.  Return the
847d7b1956fSRafael J. Wysocki  *	pointer to the matching entry or NULL if there's no match.
848d7b1956fSRafael J. Wysocki  */
849d7b1956fSRafael J. Wysocki const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
850d7b1956fSRafael J. Wysocki {
851d7b1956fSRafael J. Wysocki 	const struct dmi_system_id *d;
852d7b1956fSRafael J. Wysocki 
85375757507SDmitry Torokhov 	for (d = list; !dmi_is_end_of_table(d); d++)
854d7b1956fSRafael J. Wysocki 		if (dmi_matches(d))
855d7b1956fSRafael J. Wysocki 			return d;
856d7b1956fSRafael J. Wysocki 
857d7b1956fSRafael J. Wysocki 	return NULL;
858d7b1956fSRafael J. Wysocki }
859d7b1956fSRafael J. Wysocki EXPORT_SYMBOL(dmi_first_match);
860d7b1956fSRafael J. Wysocki 
861d7b1956fSRafael J. Wysocki /**
8624f705ae3SBjorn Helgaas  *	dmi_get_system_info - return DMI data value
863b0ef371eSRandy Dunlap  *	@field: data index (see enum dmi_field)
8644f705ae3SBjorn Helgaas  *
8654f705ae3SBjorn Helgaas  *	Returns one DMI data value, can be used to perform
8664f705ae3SBjorn Helgaas  *	complex DMI data checks.
8674f705ae3SBjorn Helgaas  */
8681855256cSJeff Garzik const char *dmi_get_system_info(int field)
8694f705ae3SBjorn Helgaas {
8704f705ae3SBjorn Helgaas 	return dmi_ident[field];
8714f705ae3SBjorn Helgaas }
8724f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_get_system_info);
8734f705ae3SBjorn Helgaas 
874fd8cd7e1SAlok Kataria /**
875c2bacfc4SRandy Dunlap  * dmi_name_in_serial - Check if string is in the DMI product serial information
876c2bacfc4SRandy Dunlap  * @str: string to check for
877fd8cd7e1SAlok Kataria  */
878fd8cd7e1SAlok Kataria int dmi_name_in_serial(const char *str)
879fd8cd7e1SAlok Kataria {
880fd8cd7e1SAlok Kataria 	int f = DMI_PRODUCT_SERIAL;
881fd8cd7e1SAlok Kataria 	if (dmi_ident[f] && strstr(dmi_ident[f], str))
882fd8cd7e1SAlok Kataria 		return 1;
883fd8cd7e1SAlok Kataria 	return 0;
884fd8cd7e1SAlok Kataria }
885a1bae672SAndi Kleen 
886a1bae672SAndi Kleen /**
88766e13e66SJean Delvare  *	dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
888a1bae672SAndi Kleen  *	@str: Case sensitive Name
889a1bae672SAndi Kleen  */
8901855256cSJeff Garzik int dmi_name_in_vendors(const char *str)
891a1bae672SAndi Kleen {
89266e13e66SJean Delvare 	static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
893a1bae672SAndi Kleen 	int i;
894a1bae672SAndi Kleen 	for (i = 0; fields[i] != DMI_NONE; i++) {
895a1bae672SAndi Kleen 		int f = fields[i];
896a1bae672SAndi Kleen 		if (dmi_ident[f] && strstr(dmi_ident[f], str))
897a1bae672SAndi Kleen 			return 1;
898a1bae672SAndi Kleen 	}
899a1bae672SAndi Kleen 	return 0;
900a1bae672SAndi Kleen }
901a1bae672SAndi Kleen EXPORT_SYMBOL(dmi_name_in_vendors);
902a1bae672SAndi Kleen 
9034f705ae3SBjorn Helgaas /**
9044f705ae3SBjorn Helgaas  *	dmi_find_device - find onboard device by type/name
9054f705ae3SBjorn Helgaas  *	@type: device type or %DMI_DEV_TYPE_ANY to match all device types
906b0ef371eSRandy Dunlap  *	@name: device name string or %NULL to match all
9074f705ae3SBjorn Helgaas  *	@from: previous device found in search, or %NULL for new search.
9084f705ae3SBjorn Helgaas  *
9094f705ae3SBjorn Helgaas  *	Iterates through the list of known onboard devices. If a device is
910bfab8b48SJean Delvare  *	found with a matching @type and @name, a pointer to its device
9114f705ae3SBjorn Helgaas  *	structure is returned.  Otherwise, %NULL is returned.
912b0ef371eSRandy Dunlap  *	A new search is initiated by passing %NULL as the @from argument.
9134f705ae3SBjorn Helgaas  *	If @from is not %NULL, searches continue from next device.
9144f705ae3SBjorn Helgaas  */
9151855256cSJeff Garzik const struct dmi_device *dmi_find_device(int type, const char *name,
9161855256cSJeff Garzik 				    const struct dmi_device *from)
9174f705ae3SBjorn Helgaas {
9181855256cSJeff Garzik 	const struct list_head *head = from ? &from->list : &dmi_devices;
9191855256cSJeff Garzik 	struct list_head *d;
9204f705ae3SBjorn Helgaas 
9214f705ae3SBjorn Helgaas 	for (d = head->next; d != &dmi_devices; d = d->next) {
9221855256cSJeff Garzik 		const struct dmi_device *dev =
9231855256cSJeff Garzik 			list_entry(d, struct dmi_device, list);
9244f705ae3SBjorn Helgaas 
9254f705ae3SBjorn Helgaas 		if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
9264f705ae3SBjorn Helgaas 		    ((name == NULL) || (strcmp(dev->name, name) == 0)))
9274f705ae3SBjorn Helgaas 			return dev;
9284f705ae3SBjorn Helgaas 	}
9294f705ae3SBjorn Helgaas 
9304f705ae3SBjorn Helgaas 	return NULL;
9314f705ae3SBjorn Helgaas }
9324f705ae3SBjorn Helgaas EXPORT_SYMBOL(dmi_find_device);
9334f705ae3SBjorn Helgaas 
9344f705ae3SBjorn Helgaas /**
9353e5cd1f2STejun Heo  *	dmi_get_date - parse a DMI date
9363e5cd1f2STejun Heo  *	@field:	data index (see enum dmi_field)
9373e5cd1f2STejun Heo  *	@yearp: optional out parameter for the year
9383e5cd1f2STejun Heo  *	@monthp: optional out parameter for the month
9393e5cd1f2STejun Heo  *	@dayp: optional out parameter for the day
9404f705ae3SBjorn Helgaas  *
9413e5cd1f2STejun Heo  *	The date field is assumed to be in the form resembling
9423e5cd1f2STejun Heo  *	[mm[/dd]]/yy[yy] and the result is stored in the out
9433e5cd1f2STejun Heo  *	parameters any or all of which can be omitted.
9443e5cd1f2STejun Heo  *
9453e5cd1f2STejun Heo  *	If the field doesn't exist, all out parameters are set to zero
9463e5cd1f2STejun Heo  *	and false is returned.  Otherwise, true is returned with any
9473e5cd1f2STejun Heo  *	invalid part of date set to zero.
9483e5cd1f2STejun Heo  *
9493e5cd1f2STejun Heo  *	On return, year, month and day are guaranteed to be in the
9503e5cd1f2STejun Heo  *	range of [0,9999], [0,12] and [0,31] respectively.
9514f705ae3SBjorn Helgaas  */
9523e5cd1f2STejun Heo bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
9534f705ae3SBjorn Helgaas {
9543e5cd1f2STejun Heo 	int year = 0, month = 0, day = 0;
9553e5cd1f2STejun Heo 	bool exists;
9563e5cd1f2STejun Heo 	const char *s, *y;
95702c24fa8STejun Heo 	char *e;
9584f705ae3SBjorn Helgaas 
9593e5cd1f2STejun Heo 	s = dmi_get_system_info(field);
9603e5cd1f2STejun Heo 	exists = s;
9613e5cd1f2STejun Heo 	if (!exists)
9623e5cd1f2STejun Heo 		goto out;
9634f705ae3SBjorn Helgaas 
9643e5cd1f2STejun Heo 	/*
9653e5cd1f2STejun Heo 	 * Determine year first.  We assume the date string resembles
9663e5cd1f2STejun Heo 	 * mm/dd/yy[yy] but the original code extracted only the year
9673e5cd1f2STejun Heo 	 * from the end.  Keep the behavior in the spirit of no
9683e5cd1f2STejun Heo 	 * surprises.
9693e5cd1f2STejun Heo 	 */
9703e5cd1f2STejun Heo 	y = strrchr(s, '/');
9713e5cd1f2STejun Heo 	if (!y)
9723e5cd1f2STejun Heo 		goto out;
9733e5cd1f2STejun Heo 
9743e5cd1f2STejun Heo 	y++;
9753e5cd1f2STejun Heo 	year = simple_strtoul(y, &e, 10);
9763e5cd1f2STejun Heo 	if (y != e && year < 100) {	/* 2-digit year */
9774f705ae3SBjorn Helgaas 		year += 1900;
9784f705ae3SBjorn Helgaas 		if (year < 1996)	/* no dates < spec 1.0 */
9794f705ae3SBjorn Helgaas 			year += 100;
9804f705ae3SBjorn Helgaas 	}
9813e5cd1f2STejun Heo 	if (year > 9999)		/* year should fit in %04d */
9823e5cd1f2STejun Heo 		year = 0;
9834f705ae3SBjorn Helgaas 
9843e5cd1f2STejun Heo 	/* parse the mm and dd */
9853e5cd1f2STejun Heo 	month = simple_strtoul(s, &e, 10);
9863e5cd1f2STejun Heo 	if (s == e || *e != '/' || !month || month > 12) {
9873e5cd1f2STejun Heo 		month = 0;
9883e5cd1f2STejun Heo 		goto out;
9894f705ae3SBjorn Helgaas 	}
9903e5cd1f2STejun Heo 
9913e5cd1f2STejun Heo 	s = e + 1;
9923e5cd1f2STejun Heo 	day = simple_strtoul(s, &e, 10);
9933e5cd1f2STejun Heo 	if (s == y || s == e || *e != '/' || day > 31)
9943e5cd1f2STejun Heo 		day = 0;
9953e5cd1f2STejun Heo out:
9963e5cd1f2STejun Heo 	if (yearp)
9973e5cd1f2STejun Heo 		*yearp = year;
9983e5cd1f2STejun Heo 	if (monthp)
9993e5cd1f2STejun Heo 		*monthp = month;
10003e5cd1f2STejun Heo 	if (dayp)
10013e5cd1f2STejun Heo 		*dayp = day;
10023e5cd1f2STejun Heo 	return exists;
10033e5cd1f2STejun Heo }
10043e5cd1f2STejun Heo EXPORT_SYMBOL(dmi_get_date);
10057fce084aSJean Delvare 
10067fce084aSJean Delvare /**
10077fce084aSJean Delvare  *	dmi_walk - Walk the DMI table and get called back for every record
10087fce084aSJean Delvare  *	@decode: Callback function
1009e7a19c56SJean Delvare  *	@private_data: Private data to be passed to the callback function
10107fce084aSJean Delvare  *
10117fce084aSJean Delvare  *	Returns -1 when the DMI table can't be reached, 0 on success.
10127fce084aSJean Delvare  */
1013e7a19c56SJean Delvare int dmi_walk(void (*decode)(const struct dmi_header *, void *),
1014e7a19c56SJean Delvare 	     void *private_data)
10157fce084aSJean Delvare {
10167fce084aSJean Delvare 	u8 *buf;
10177fce084aSJean Delvare 
10187fce084aSJean Delvare 	if (!dmi_available)
10197fce084aSJean Delvare 		return -1;
10207fce084aSJean Delvare 
1021cf074402SArd Biesheuvel 	buf = dmi_remap(dmi_base, dmi_len);
10227fce084aSJean Delvare 	if (buf == NULL)
10237fce084aSJean Delvare 		return -1;
10247fce084aSJean Delvare 
1025eb4c5ea5SIvan Khoronzhuk 	dmi_decode_table(buf, decode, private_data);
10267fce084aSJean Delvare 
1027cf074402SArd Biesheuvel 	dmi_unmap(buf);
10287fce084aSJean Delvare 	return 0;
10297fce084aSJean Delvare }
10307fce084aSJean Delvare EXPORT_SYMBOL_GPL(dmi_walk);
1031d61c72e5SJiri Slaby 
1032d61c72e5SJiri Slaby /**
1033d61c72e5SJiri Slaby  * dmi_match - compare a string to the dmi field (if exists)
1034c2bacfc4SRandy Dunlap  * @f: DMI field identifier
1035c2bacfc4SRandy Dunlap  * @str: string to compare the DMI field to
1036d61c72e5SJiri Slaby  *
1037d61c72e5SJiri Slaby  * Returns true if the requested field equals to the str (including NULL).
1038d61c72e5SJiri Slaby  */
1039d61c72e5SJiri Slaby bool dmi_match(enum dmi_field f, const char *str)
1040d61c72e5SJiri Slaby {
1041d61c72e5SJiri Slaby 	const char *info = dmi_get_system_info(f);
1042d61c72e5SJiri Slaby 
1043d61c72e5SJiri Slaby 	if (info == NULL || str == NULL)
1044d61c72e5SJiri Slaby 		return info == str;
1045d61c72e5SJiri Slaby 
1046d61c72e5SJiri Slaby 	return !strcmp(info, str);
1047d61c72e5SJiri Slaby }
1048d61c72e5SJiri Slaby EXPORT_SYMBOL_GPL(dmi_match);
1049dd6dad42SChen, Gong 
1050dd6dad42SChen, Gong void dmi_memdev_name(u16 handle, const char **bank, const char **device)
1051dd6dad42SChen, Gong {
1052dd6dad42SChen, Gong 	int n;
1053dd6dad42SChen, Gong 
1054dd6dad42SChen, Gong 	if (dmi_memdev == NULL)
1055dd6dad42SChen, Gong 		return;
1056dd6dad42SChen, Gong 
1057dd6dad42SChen, Gong 	for (n = 0; n < dmi_memdev_nr; n++) {
1058dd6dad42SChen, Gong 		if (handle == dmi_memdev[n].handle) {
1059dd6dad42SChen, Gong 			*bank = dmi_memdev[n].bank;
1060dd6dad42SChen, Gong 			*device = dmi_memdev[n].device;
1061dd6dad42SChen, Gong 			break;
1062dd6dad42SChen, Gong 		}
1063dd6dad42SChen, Gong 	}
1064dd6dad42SChen, Gong }
1065dd6dad42SChen, Gong EXPORT_SYMBOL_GPL(dmi_memdev_name);
1066