Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <asm/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #ifndef SMBIOS_ENTRY_POINT_SCAN_START
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #define SMBIOS_ENTRY_POINT_SCAN_START 0xF0000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) struct kobject *dmi_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) EXPORT_SYMBOL_GPL(dmi_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22)  * DMI stands for "Desktop Management Interface".  It is part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23)  * of and an antecedent to, SMBIOS, which stands for System
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24)  * Management BIOS.  See further: https://www.dmtf.org/standards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) static const char dmi_empty_string[] = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) static u32 dmi_ver __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) static u32 dmi_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) static u16 dmi_num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) static u8 smbios_entry_point[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) static int smbios_entry_point_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) /* DMI system identification string used during boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static char dmi_ids_string[128] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) static struct dmi_memdev_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 	const char *device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	const char *bank;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) 	u64 size;		/* bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 	u16 handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	u8 type;		/* DDR2, DDR3, DDR4 etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) } *dmi_memdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) static int dmi_memdev_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 	const u8 *bp = ((u8 *) dm) + dm->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	const u8 *nsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	if (s) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) 		while (--s > 0 && *bp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 			bp += strlen(bp) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 		/* Strings containing only spaces are considered empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 		nsp = bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 		while (*nsp == ' ')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 			nsp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		if (*nsp != '\0')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 			return bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	return dmi_empty_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static const char * __init dmi_string(const struct dmi_header *dm, u8 s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) 	const char *bp = dmi_string_nosave(dm, s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) 	char *str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 	if (bp == dmi_empty_string)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 		return dmi_empty_string;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	len = strlen(bp) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 	str = dmi_alloc(len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	if (str != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		strcpy(str, bp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	return str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84)  *	We have to be cautious here. We have seen BIOSes with DMI pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85)  *	pointing to completely the wrong place for example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) static void dmi_decode_table(u8 *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 			     void (*decode)(const struct dmi_header *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 			     void *private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	u8 *data = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	 * Stop when we have seen all the items the table claimed to have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	 * (SMBIOS < 3.0 only) OR we reach an end-of-table marker (SMBIOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	 * >= 3.0 only) OR we run off the end of the table (should never
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	 * happen but sometimes does on bogus implementations.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	while ((!dmi_num || i < dmi_num) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	       (data - buf + sizeof(struct dmi_header)) <= dmi_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 		const struct dmi_header *dm = (const struct dmi_header *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 		 *  We want to know the total length (formatted area and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 		 *  strings) before decoding to make sure we won't run off the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 		 *  table in dmi_decode or dmi_string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 		data += dm->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 		while ((data - buf < dmi_len - 1) && (data[0] || data[1]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 			data++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 		if (data - buf < dmi_len - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			decode(dm, private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 		data += 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 		 * 7.45 End-of-Table (Type 127) [SMBIOS reference spec v3.0.0]
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 		 * For tables behind a 64-bit entry point, we have no item
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 		 * count and no exact table length, so stop on end-of-table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 		 * marker. For tables behind a 32-bit entry point, we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 		 * seen OEM structures behind the end-of-table marker on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 		 * some systems, so don't trust it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 		if (!dmi_num && dm->type == DMI_ENTRY_END_OF_TABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	/* Trim DMI table length if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	if (dmi_len > data - buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 		dmi_len = data - buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) static phys_addr_t dmi_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) static int __init dmi_walk_early(void (*decode)(const struct dmi_header *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 		void *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	u32 orig_dmi_len = dmi_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	buf = dmi_early_remap(dmi_base, orig_dmi_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	if (buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	dmi_decode_table(buf, decode, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	add_device_randomness(buf, dmi_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	dmi_early_unmap(buf, orig_dmi_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) static int __init dmi_checksum(const u8 *buf, u8 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	u8 sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	int a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	for (a = 0; a < len; a++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 		sum += buf[a];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	return sum == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) static const char *dmi_ident[DMI_STRING_MAX];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) static LIST_HEAD(dmi_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) int dmi_available;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  *	Save a DMI string
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) static void __init dmi_save_ident(const struct dmi_header *dm, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 		int string)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	const char *d = (const char *) dm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	const char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	if (dmi_ident[slot] || dm->length <= string)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	p = dmi_string(dm, d[string]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	if (p == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	dmi_ident[slot] = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) static void __init dmi_save_release(const struct dmi_header *dm, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	const u8 *minor, *major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	/* If the table doesn't have the field, let's return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	if (dmi_ident[slot] || dm->length < index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	minor = (u8 *) dm + index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	major = (u8 *) dm + index - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	/* As per the spec, if the system doesn't support this field,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	 * the value is FF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	if (*major == 0xFF && *minor == 0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	s = dmi_alloc(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	sprintf(s, "%u.%u", *major, *minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 	dmi_ident[slot] = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) static void __init dmi_save_uuid(const struct dmi_header *dm, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 		int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	const u8 *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	int is_ff = 1, is_00 = 1, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 	if (dmi_ident[slot] || dm->length < index + 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 	d = (u8 *) dm + index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 	for (i = 0; i < 16 && (is_ff || is_00); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		if (d[i] != 0x00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			is_00 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 		if (d[i] != 0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 			is_ff = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	if (is_ff || is_00)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 	s = dmi_alloc(16*2+4+1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	 * As of version 2.6 of the SMBIOS specification, the first 3 fields of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 	 * the UUID are supposed to be little-endian encoded.  The specification
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	 * says that this is the defacto standard.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	if (dmi_ver >= 0x020600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		sprintf(s, "%pUl", d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 		sprintf(s, "%pUb", d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) 	dmi_ident[slot] = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) static void __init dmi_save_type(const struct dmi_header *dm, int slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 		int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	const u8 *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	char *s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	if (dmi_ident[slot] || dm->length <= index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	s = dmi_alloc(4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	if (!s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 	d = (u8 *) dm + index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	sprintf(s, "%u", *d & 0x7F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 	dmi_ident[slot] = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) static void __init dmi_save_one_device(int type, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	struct dmi_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	/* No duplicate device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	if (dmi_find_device(type, name, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	dev->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	strcpy((char *)(dev + 1), name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	dev->name = (char *)(dev + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	dev->device_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	list_add(&dev->list, &dmi_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) static void __init dmi_save_devices(const struct dmi_header *dm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 	int i, count = (dm->length - sizeof(struct dmi_header)) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 		const char *d = (char *)(dm + 1) + (i * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 		/* Skip disabled device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 		if ((*d & 0x80) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		dmi_save_one_device(*d & 0x7f, dmi_string_nosave(dm, *(d + 1)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) static void __init dmi_save_oem_strings_devices(const struct dmi_header *dm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	int i, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 	struct dmi_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 	if (dm->length < 0x05)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	count = *(u8 *)(dm + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	for (i = 1; i <= count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		const char *devname = dmi_string(dm, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		if (devname == dmi_empty_string)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		dev = dmi_alloc(sizeof(*dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		dev->type = DMI_DEV_TYPE_OEM_STRING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 		dev->name = devname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		dev->device_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 		list_add(&dev->list, &dmi_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) static void __init dmi_save_ipmi_device(const struct dmi_header *dm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	struct dmi_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	data = dmi_alloc(dm->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	if (data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	memcpy(data, dm, dm->length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	dev = dmi_alloc(sizeof(*dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	dev->type = DMI_DEV_TYPE_IPMI;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	dev->name = "IPMI controller";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	dev->device_data = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	list_add_tail(&dev->list, &dmi_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) static void __init dmi_save_dev_pciaddr(int instance, int segment, int bus,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 					int devfn, const char *name, int type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	struct dmi_dev_onboard *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 	/* Ignore invalid values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 	if (type == DMI_DEV_TYPE_DEV_SLOT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	    segment == 0xFFFF && bus == 0xFF && devfn == 0xFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	dev = dmi_alloc(sizeof(*dev) + strlen(name) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	if (!dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	dev->instance = instance;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	dev->segment = segment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	dev->bus = bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	dev->devfn = devfn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	strcpy((char *)&dev[1], name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	dev->dev.type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	dev->dev.name = (char *)&dev[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	dev->dev.device_data = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	list_add(&dev->dev.list, &dmi_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) static void __init dmi_save_extended_devices(const struct dmi_header *dm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	const u8 *d = (u8 *)dm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	if (dm->length < 0x0B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	/* Skip disabled device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	if ((d[0x5] & 0x80) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	name = dmi_string_nosave(dm, d[0x4]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	dmi_save_dev_pciaddr(d[0x6], *(u16 *)(d + 0x7), d[0x9], d[0xA], name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 			     DMI_DEV_TYPE_DEV_ONBOARD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	dmi_save_one_device(d[0x5] & 0x7f, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) static void __init dmi_save_system_slot(const struct dmi_header *dm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 	const u8 *d = (u8 *)dm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	/* Need SMBIOS 2.6+ structure */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	if (dm->length < 0x11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	dmi_save_dev_pciaddr(*(u16 *)(d + 0x9), *(u16 *)(d + 0xD), d[0xF],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 			     d[0x10], dmi_string_nosave(dm, d[0x4]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 			     DMI_DEV_TYPE_DEV_SLOT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) static void __init count_mem_devices(const struct dmi_header *dm, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	if (dm->type != DMI_ENTRY_MEM_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	dmi_memdev_nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) static void __init save_mem_devices(const struct dmi_header *dm, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	const char *d = (const char *)dm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	static int nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 	u64 bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	u16 size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	if (dm->type != DMI_ENTRY_MEM_DEVICE || dm->length < 0x13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	if (nr >= dmi_memdev_nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 		pr_warn(FW_BUG "Too many DIMM entries in SMBIOS table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	dmi_memdev[nr].handle = get_unaligned(&dm->handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	dmi_memdev[nr].device = dmi_string(dm, d[0x10]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	dmi_memdev[nr].bank = dmi_string(dm, d[0x11]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	dmi_memdev[nr].type = d[0x12];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	size = get_unaligned((u16 *)&d[0xC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	if (size == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	else if (size == 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 		bytes = ~0ull;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	else if (size & 0x8000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		bytes = (u64)(size & 0x7fff) << 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	else if (size != 0x7fff || dm->length < 0x20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 		bytes = (u64)size << 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		bytes = (u64)get_unaligned((u32 *)&d[0x1C]) << 20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	dmi_memdev[nr].size = bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) static void __init dmi_memdev_walk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	if (dmi_walk_early(count_mem_devices) == 0 && dmi_memdev_nr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 		dmi_memdev = dmi_alloc(sizeof(*dmi_memdev) * dmi_memdev_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 		if (dmi_memdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 			dmi_walk_early(save_mem_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464)  *	Process a DMI table entry. Right now all we care about are the BIOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465)  *	and machine entries. For 2.5 we should pull the smbus controller info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466)  *	out of here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) static void __init dmi_decode(const struct dmi_header *dm, void *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	switch (dm->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	case 0:		/* BIOS Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		dmi_save_ident(dm, DMI_BIOS_VENDOR, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 		dmi_save_ident(dm, DMI_BIOS_VERSION, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		dmi_save_ident(dm, DMI_BIOS_DATE, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 		dmi_save_release(dm, DMI_BIOS_RELEASE, 21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 		dmi_save_release(dm, DMI_EC_FIRMWARE_RELEASE, 23);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	case 1:		/* System Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		dmi_save_ident(dm, DMI_SYS_VENDOR, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		dmi_save_ident(dm, DMI_PRODUCT_NAME, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		dmi_save_ident(dm, DMI_PRODUCT_VERSION, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		dmi_save_ident(dm, DMI_PRODUCT_SERIAL, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		dmi_save_uuid(dm, DMI_PRODUCT_UUID, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		dmi_save_ident(dm, DMI_PRODUCT_SKU, 25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 		dmi_save_ident(dm, DMI_PRODUCT_FAMILY, 26);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	case 2:		/* Base Board Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 		dmi_save_ident(dm, DMI_BOARD_VENDOR, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 		dmi_save_ident(dm, DMI_BOARD_NAME, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 		dmi_save_ident(dm, DMI_BOARD_VERSION, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		dmi_save_ident(dm, DMI_BOARD_SERIAL, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 		dmi_save_ident(dm, DMI_BOARD_ASSET_TAG, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	case 3:		/* Chassis Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		dmi_save_ident(dm, DMI_CHASSIS_VENDOR, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 		dmi_save_type(dm, DMI_CHASSIS_TYPE, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		dmi_save_ident(dm, DMI_CHASSIS_VERSION, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		dmi_save_ident(dm, DMI_CHASSIS_SERIAL, 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		dmi_save_ident(dm, DMI_CHASSIS_ASSET_TAG, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	case 9:		/* System Slots */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 		dmi_save_system_slot(dm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	case 10:	/* Onboard Devices Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 		dmi_save_devices(dm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	case 11:	/* OEM Strings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		dmi_save_oem_strings_devices(dm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 	case 38:	/* IPMI Device Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 		dmi_save_ipmi_device(dm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	case 41:	/* Onboard Devices Extended Information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		dmi_save_extended_devices(dm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) static int __init print_filtered(char *buf, size_t len, const char *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	int c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	const char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	if (!info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		return c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	for (p = info; *p; p++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 		if (isprint(*p))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 			c += scnprintf(buf + c, len - c, "%c", *p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 			c += scnprintf(buf + c, len - c, "\\x%02x", *p & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	return c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) static void __init dmi_format_ids(char *buf, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	int c = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	const char *board;	/* Board Name is optional */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	c += print_filtered(buf + c, len - c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 			    dmi_get_system_info(DMI_SYS_VENDOR));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	c += scnprintf(buf + c, len - c, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	c += print_filtered(buf + c, len - c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 			    dmi_get_system_info(DMI_PRODUCT_NAME));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	board = dmi_get_system_info(DMI_BOARD_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	if (board) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 		c += scnprintf(buf + c, len - c, "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		c += print_filtered(buf + c, len - c, board);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	c += scnprintf(buf + c, len - c, ", BIOS ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 	c += print_filtered(buf + c, len - c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 			    dmi_get_system_info(DMI_BIOS_VERSION));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	c += scnprintf(buf + c, len - c, " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	c += print_filtered(buf + c, len - c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 			    dmi_get_system_info(DMI_BIOS_DATE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559)  * Check for DMI/SMBIOS headers in the system firmware image.  Any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)  * SMBIOS header must start 16 bytes before the DMI header, so take a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  * 32 byte buffer and check for DMI at offset 16 and SMBIOS at offset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  * 0.  If the DMI header is present, set dmi_ver accordingly (SMBIOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  * takes precedence) and return 0.  Otherwise return 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) static int __init dmi_present(const u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	u32 smbios_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	if (memcmp(buf, "_SM_", 4) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 	    buf[5] < 32 && dmi_checksum(buf, buf[5])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		smbios_ver = get_unaligned_be16(buf + 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 		smbios_entry_point_size = buf[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 		memcpy(smbios_entry_point, buf, smbios_entry_point_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 		/* Some BIOS report weird SMBIOS version, fix that up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 		switch (smbios_ver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 		case 0x021F:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 		case 0x0221:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			pr_debug("SMBIOS version fixup (2.%d->2.%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 				 smbios_ver & 0xFF, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 			smbios_ver = 0x0203;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		case 0x0233:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 			pr_debug("SMBIOS version fixup (2.%d->2.%d)\n", 51, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 			smbios_ver = 0x0206;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		smbios_ver = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	buf += 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	if (memcmp(buf, "_DMI_", 5) == 0 && dmi_checksum(buf, 15)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 		if (smbios_ver)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 			dmi_ver = smbios_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 			dmi_ver = (buf[14] & 0xF0) << 4 | (buf[14] & 0x0F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		dmi_ver <<= 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 		dmi_num = get_unaligned_le16(buf + 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 		dmi_len = get_unaligned_le16(buf + 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		dmi_base = get_unaligned_le32(buf + 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 		if (dmi_walk_early(dmi_decode) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 			if (smbios_ver) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 				pr_info("SMBIOS %d.%d present.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 					dmi_ver >> 16, (dmi_ver >> 8) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 				smbios_entry_point_size = 15;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 				memcpy(smbios_entry_point, buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 				       smbios_entry_point_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 				pr_info("Legacy DMI %d.%d present.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 					dmi_ver >> 16, (dmi_ver >> 8) & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 			dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 			pr_info("DMI: %s\n", dmi_ids_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)  * Check for the SMBIOS 3.0 64-bit entry point signature. Unlike the legacy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626)  * 32-bit entry point, there is no embedded DMI header (_DMI_) in here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) static int __init dmi_smbios3_present(const u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	if (memcmp(buf, "_SM3_", 5) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	    buf[6] < 32 && dmi_checksum(buf, buf[6])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 		dmi_ver = get_unaligned_be32(buf + 6) & 0xFFFFFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 		dmi_num = 0;			/* No longer specified */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 		dmi_len = get_unaligned_le32(buf + 12);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		dmi_base = get_unaligned_le64(buf + 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		smbios_entry_point_size = buf[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 		memcpy(smbios_entry_point, buf, smbios_entry_point_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 		if (dmi_walk_early(dmi_decode) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 			pr_info("SMBIOS %d.%d.%d present.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 				dmi_ver >> 16, (dmi_ver >> 8) & 0xFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 				dmi_ver & 0xFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 			dmi_format_ids(dmi_ids_string, sizeof(dmi_ids_string));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 			pr_info("DMI: %s\n", dmi_ids_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) static void __init dmi_scan_machine(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	char __iomem *p, *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 	char buf[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 	if (efi_enabled(EFI_CONFIG_TABLES)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 		 * According to the DMTF SMBIOS reference spec v3.0.0, it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		 * allowed to define both the 64-bit entry point (smbios3) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		 * the 32-bit entry point (smbios), in which case they should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 		 * either both point to the same SMBIOS structure table, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 		 * table pointed to by the 64-bit entry point should contain a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		 * superset of the table contents pointed to by the 32-bit entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		 * point (section 5.2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		 * This implies that the 64-bit entry point should have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		 * precedence if it is defined and supported by the OS. If we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 		 * have the 64-bit entry point, but fail to decode it, fall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		 * back to the legacy one (if available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 		if (efi.smbios3 != EFI_INVALID_TABLE_ADDR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 			p = dmi_early_remap(efi.smbios3, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 			if (p == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 				goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 			memcpy_fromio(buf, p, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 			dmi_early_unmap(p, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 			if (!dmi_smbios3_present(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 				dmi_available = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 		if (efi.smbios == EFI_INVALID_TABLE_ADDR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		/* This is called as a core_initcall() because it isn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		 * needed during early boot.  This also means we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 		 * iounmap the space when we're done with it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 		p = dmi_early_remap(efi.smbios, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		if (p == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		memcpy_fromio(buf, p, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		dmi_early_unmap(p, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		if (!dmi_present(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 			dmi_available = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	} else if (IS_ENABLED(CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 		p = dmi_early_remap(SMBIOS_ENTRY_POINT_SCAN_START, 0x10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		if (p == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		 * Same logic as above, look for a 64-bit entry point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		 * first, and if not found, fall back to 32-bit entry point.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		memcpy_fromio(buf, p, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		for (q = p + 16; q < p + 0x10000; q += 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 			memcpy_fromio(buf + 16, q, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 			if (!dmi_smbios3_present(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 				dmi_available = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 				dmi_early_unmap(p, 0x10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 			memcpy(buf, buf + 16, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 		 * Iterate over all possible DMI header addresses q.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		 * Maintain the 32 bytes around q in buf.  On the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		 * first iteration, substitute zero for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		 * out-of-range bytes so there is no chance of falsely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 		 * detecting an SMBIOS header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 		memset(buf, 0, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 		for (q = p; q < p + 0x10000; q += 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 			memcpy_fromio(buf + 16, q, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 			if (!dmi_present(buf)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 				dmi_available = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 				dmi_early_unmap(p, 0x10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 				return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 			memcpy(buf, buf + 16, 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 		dmi_early_unmap(p, 0x10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738)  error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 	pr_info("DMI not present or invalid.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) static ssize_t raw_table_read(struct file *file, struct kobject *kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 			      struct bin_attribute *attr, char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 			      loff_t pos, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	memcpy(buf, attr->private + pos, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) static BIN_ATTR(smbios_entry_point, S_IRUSR, raw_table_read, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) static BIN_ATTR(DMI, S_IRUSR, raw_table_read, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) static int __init dmi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	struct kobject *tables_kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	u8 *dmi_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	int ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	if (!dmi_available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	 * Set up dmi directory at /sys/firmware/dmi. This entry should stay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	 * even after farther error, as it can be used by other modules like
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 	 * dmi-sysfs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	dmi_kobj = kobject_create_and_add("dmi", firmware_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	if (!dmi_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	tables_kobj = kobject_create_and_add("tables", dmi_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	if (!tables_kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	dmi_table = dmi_remap(dmi_base, dmi_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	if (!dmi_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		goto err_tables;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 	bin_attr_smbios_entry_point.size = smbios_entry_point_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	bin_attr_smbios_entry_point.private = smbios_entry_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	ret = sysfs_create_bin_file(tables_kobj, &bin_attr_smbios_entry_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 		goto err_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	bin_attr_DMI.size = dmi_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 	bin_attr_DMI.private = dmi_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	ret = sysfs_create_bin_file(tables_kobj, &bin_attr_DMI);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	sysfs_remove_bin_file(tables_kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 			      &bin_attr_smbios_entry_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793)  err_unmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	dmi_unmap(dmi_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795)  err_tables:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	kobject_del(tables_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	kobject_put(tables_kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798)  err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 	pr_err("dmi: Firmware registration failed.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) subsys_initcall(dmi_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806)  *	dmi_setup - scan and setup DMI system information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808)  *	Scan the DMI system information. This setups DMI identifiers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809)  *	(dmi_system_id) for printing it out on task dumps and prepares
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810)  *	DIMM entry information (dmi_memdev_info) from the SMBIOS table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811)  *	for using this when reporting memory errors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) void __init dmi_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	dmi_scan_machine();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (!dmi_available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	dmi_memdev_walk();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	dump_stack_set_arch_desc("%s", dmi_ids_string);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824)  *	dmi_matches - check if dmi_system_id structure matches system DMI data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825)  *	@dmi: pointer to the dmi_system_id structure to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) static bool dmi_matches(const struct dmi_system_id *dmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	for (i = 0; i < ARRAY_SIZE(dmi->matches); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		int s = dmi->matches[i].slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		if (s == DMI_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		if (s == DMI_OEM_STRING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			/* DMI_OEM_STRING must be exact match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 			const struct dmi_device *valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 			valid = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 						dmi->matches[i].substr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			if (valid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 		} else if (dmi_ident[s]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 			if (dmi->matches[i].exact_match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 				if (!strcmp(dmi_ident[s],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 					    dmi->matches[i].substr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 				if (strstr(dmi_ident[s],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 					   dmi->matches[i].substr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		/* No match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862)  *	dmi_is_end_of_table - check for end-of-table marker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863)  *	@dmi: pointer to the dmi_system_id structure to check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) static bool dmi_is_end_of_table(const struct dmi_system_id *dmi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	return dmi->matches[0].slot == DMI_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871)  *	dmi_check_system - check system DMI data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872)  *	@list: array of dmi_system_id structures to match against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873)  *		All non-null elements of the list must match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874)  *		their slot's (field index's) data (i.e., each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875)  *		list string must be a substring of the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876)  *		DMI slot's string data) to be considered a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877)  *		successful match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879)  *	Walk the blacklist table running matching functions until someone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880)  *	returns non zero or we hit the end. Callback function is called for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881)  *	each successful match. Returns the number of matches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883)  *	dmi_setup must be called before this function is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) int dmi_check_system(const struct dmi_system_id *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	const struct dmi_system_id *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	for (d = list; !dmi_is_end_of_table(d); d++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 		if (dmi_matches(d)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 			count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 			if (d->callback && d->callback(d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) EXPORT_SYMBOL(dmi_check_system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)  *	dmi_first_match - find dmi_system_id structure matching system DMI data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)  *	@list: array of dmi_system_id structures to match against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904)  *		All non-null elements of the list must match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905)  *		their slot's (field index's) data (i.e., each
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906)  *		list string must be a substring of the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907)  *		DMI slot's string data) to be considered a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908)  *		successful match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910)  *	Walk the blacklist table until the first match is found.  Return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911)  *	pointer to the matching entry or NULL if there's no match.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913)  *	dmi_setup must be called before this function is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) const struct dmi_system_id *dmi_first_match(const struct dmi_system_id *list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 	const struct dmi_system_id *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 	for (d = list; !dmi_is_end_of_table(d); d++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		if (dmi_matches(d))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 			return d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) EXPORT_SYMBOL(dmi_first_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928)  *	dmi_get_system_info - return DMI data value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929)  *	@field: data index (see enum dmi_field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931)  *	Returns one DMI data value, can be used to perform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932)  *	complex DMI data checks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) const char *dmi_get_system_info(int field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	return dmi_ident[field];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) EXPORT_SYMBOL(dmi_get_system_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941)  * dmi_name_in_serial - Check if string is in the DMI product serial information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942)  * @str: string to check for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) int dmi_name_in_serial(const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	int f = DMI_PRODUCT_SERIAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	if (dmi_ident[f] && strstr(dmi_ident[f], str))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953)  *	dmi_name_in_vendors - Check if string is in the DMI system or board vendor name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954)  *	@str: Case sensitive Name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) int dmi_name_in_vendors(const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 	static int fields[] = { DMI_SYS_VENDOR, DMI_BOARD_VENDOR, DMI_NONE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	for (i = 0; fields[i] != DMI_NONE; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 		int f = fields[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		if (dmi_ident[f] && strstr(dmi_ident[f], str))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 			return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) EXPORT_SYMBOL(dmi_name_in_vendors);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970)  *	dmi_find_device - find onboard device by type/name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971)  *	@type: device type or %DMI_DEV_TYPE_ANY to match all device types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972)  *	@name: device name string or %NULL to match all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973)  *	@from: previous device found in search, or %NULL for new search.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975)  *	Iterates through the list of known onboard devices. If a device is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976)  *	found with a matching @type and @name, a pointer to its device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977)  *	structure is returned.  Otherwise, %NULL is returned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978)  *	A new search is initiated by passing %NULL as the @from argument.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979)  *	If @from is not %NULL, searches continue from next device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) const struct dmi_device *dmi_find_device(int type, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 				    const struct dmi_device *from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 	const struct list_head *head = from ? &from->list : &dmi_devices;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	struct list_head *d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	for (d = head->next; d != &dmi_devices; d = d->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 		const struct dmi_device *dev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 			list_entry(d, struct dmi_device, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 		if (((type == DMI_DEV_TYPE_ANY) || (dev->type == type)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 		    ((name == NULL) || (strcmp(dev->name, name) == 0)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 			return dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) EXPORT_SYMBOL(dmi_find_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)  *	dmi_get_date - parse a DMI date
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002)  *	@field:	data index (see enum dmi_field)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003)  *	@yearp: optional out parameter for the year
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004)  *	@monthp: optional out parameter for the month
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)  *	@dayp: optional out parameter for the day
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007)  *	The date field is assumed to be in the form resembling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008)  *	[mm[/dd]]/yy[yy] and the result is stored in the out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)  *	parameters any or all of which can be omitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011)  *	If the field doesn't exist, all out parameters are set to zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012)  *	and false is returned.  Otherwise, true is returned with any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013)  *	invalid part of date set to zero.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  *	On return, year, month and day are guaranteed to be in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)  *	range of [0,9999], [0,12] and [0,31] respectively.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) bool dmi_get_date(int field, int *yearp, int *monthp, int *dayp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	int year = 0, month = 0, day = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	bool exists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	const char *s, *y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	char *e;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	s = dmi_get_system_info(field);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	exists = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 	if (!exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	 * Determine year first.  We assume the date string resembles
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 	 * mm/dd/yy[yy] but the original code extracted only the year
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	 * from the end.  Keep the behavior in the spirit of no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	 * surprises.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 	y = strrchr(s, '/');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	if (!y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 	y++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	year = simple_strtoul(y, &e, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 	if (y != e && year < 100) {	/* 2-digit year */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		year += 1900;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 		if (year < 1996)	/* no dates < spec 1.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 			year += 100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	if (year > 9999)		/* year should fit in %04d */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 		year = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	/* parse the mm and dd */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	month = simple_strtoul(s, &e, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	if (s == e || *e != '/' || !month || month > 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 		month = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	s = e + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	day = simple_strtoul(s, &e, 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	if (s == y || s == e || *e != '/' || day > 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 		day = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 	if (yearp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		*yearp = year;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 	if (monthp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 		*monthp = month;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	if (dayp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		*dayp = day;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	return exists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) EXPORT_SYMBOL(dmi_get_date);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)  *	dmi_get_bios_year - get a year out of DMI_BIOS_DATE field
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)  *	Returns year on success, -ENXIO if DMI is not selected,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)  *	or a different negative error code if DMI field is not present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)  *	or not parseable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) int dmi_get_bios_year(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	bool exists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	int year;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	exists = dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	if (!exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 		return -ENODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	return year ? year : -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) EXPORT_SYMBOL(dmi_get_bios_year);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)  *	dmi_walk - Walk the DMI table and get called back for every record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)  *	@decode: Callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)  *	@private_data: Private data to be passed to the callback function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)  *	Returns 0 on success, -ENXIO if DMI is not selected or not present,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)  *	or a different negative error code if DMI walking fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) int dmi_walk(void (*decode)(const struct dmi_header *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	     void *private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	u8 *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	if (!dmi_available)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 		return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	buf = dmi_remap(dmi_base, dmi_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	if (buf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	dmi_decode_table(buf, decode, private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	dmi_unmap(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) EXPORT_SYMBOL_GPL(dmi_walk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)  * dmi_match - compare a string to the dmi field (if exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121)  * @f: DMI field identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)  * @str: string to compare the DMI field to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124)  * Returns true if the requested field equals to the str (including NULL).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) bool dmi_match(enum dmi_field f, const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	const char *info = dmi_get_system_info(f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	if (info == NULL || str == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 		return info == str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	return !strcmp(info, str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) EXPORT_SYMBOL_GPL(dmi_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) void dmi_memdev_name(u16 handle, const char **bank, const char **device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	if (dmi_memdev == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	for (n = 0; n < dmi_memdev_nr; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		if (handle == dmi_memdev[n].handle) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 			*bank = dmi_memdev[n].bank;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 			*device = dmi_memdev[n].device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) EXPORT_SYMBOL_GPL(dmi_memdev_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) u64 dmi_memdev_size(u16 handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	if (dmi_memdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		for (n = 0; n < dmi_memdev_nr; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			if (handle == dmi_memdev[n].handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 				return dmi_memdev[n].size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	return ~0ull;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) EXPORT_SYMBOL_GPL(dmi_memdev_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)  * dmi_memdev_type - get the memory type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170)  * @handle: DMI structure handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)  * Return the DMI memory type of the module in the slot associated with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173)  * given DMI handle, or 0x0 if no such DMI handle exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) u8 dmi_memdev_type(u16 handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	int n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	if (dmi_memdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 		for (n = 0; n < dmi_memdev_nr; n++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 			if (handle == dmi_memdev[n].handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 				return dmi_memdev[n].type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	return 0x0;	/* Not a valid value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) EXPORT_SYMBOL_GPL(dmi_memdev_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)  *	dmi_memdev_handle - get the DMI handle of a memory slot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)  *	@slot: slot number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)  *	Return the DMI handle associated with a given memory slot, or %0xFFFF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)  *      if there is no such slot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) u16 dmi_memdev_handle(int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	if (dmi_memdev && slot >= 0 && slot < dmi_memdev_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 		return dmi_memdev[slot].handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	return 0xffff;	/* Not a valid value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) EXPORT_SYMBOL_GPL(dmi_memdev_handle);