xref: /freebsd/stand/libsa/smbios.c (revision 4d846d26)
1 /*-
2  * Copyright (c) 2005-2009 Jung-uk Kim <jkim@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *	notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *	notice, this list of conditions and the following disclaimer in the
12  *	documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <stand.h>
31 #include <sys/endian.h>
32 
33 #define PTOV(x)		ptov(x)
34 
35 /* Only enable 64-bit entry point if it makes sense */
36 #if __SIZEOF_POINTER__ > 4
37 #define	HAS_SMBV3	1
38 #endif
39 
40 /*
41  * Detect SMBIOS and export information about the SMBIOS into the
42  * environment.
43  *
44  * System Management BIOS Reference Specification, v2.6 Final
45  * http://www.dmtf.org/standards/published_documents/DSP0134_2.6.0.pdf
46  *
47  * System Management BIOS (SMBIOS) Reference Specification, 3.6.0
48  * https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.6.0.pdf
49  */
50 
51 /*
52  * The first quoted paragraph below can also be found in section 2.1.1 SMBIOS
53  * Structure Table Entry Point of System Management BIOS Reference
54  * Specification, v2.6 Final
55  *
56  * (From System Management BIOS (SMBIOS) Reference Specification, 3.6.0)
57  * 5.2.1 SMBIOS 2.1 (32-bit) Entry Point
58  *
59  * "On non-UEFI systems, the 32-bit SMBIOS Entry Point structure, can be
60  * located by application software by searching for the anchor-string on
61  * paragraph (16-byte) boundaries within the physical memory address
62  * range 000F0000h to 000FFFFFh. This entry point encapsulates an intermediate
63  * anchor string that is used by some existing DMI browsers.
64  *
65  * On UEFI-based systems, the SMBIOS Entry Point structure can be located by
66  * looking in the EFI Configuration Table for the SMBIOS GUID
67  * (SMBIOS_TABLE_GUID, {EB9D2D31-2D88-11D3-9A16-0090273FC14D}) and using the
68  * associated pointer. See section 4.6 of the UEFI Specification for details.
69  * See section 2.3 of the UEFI Specification for how to report the containing
70  * memory type.
71  *
72  * NOTE While the SMBIOS Major and Minor Versions (offsets 06h and 07h)
73  * currently duplicate the information that is present in the SMBIOS BCD
74  * Revision (offset 1Eh), they provide a path for future growth in this
75  * specification. The BCD Revision, for example, provides only a single digit
76  * for each of the major and minor version numbers."
77  *
78  * 5.2.2 SMBIOS 860 3.0 (64-bit) Entry Point
79  *
80  * "On non-UEFI systems, the 64-bit SMBIOS Entry Point structure can be located
81  * by application software by searching for the anchor-string on paragraph
82  * (16-byte) boundaries within the physical memory address range 000F0000h to
83  * 000FFFFFh.
84  *
85  * On UEFI-based systems, the SMBIOS Entry Point structure can be located by
86  * looking in the EFI Configuration Table for the SMBIOS 3.x GUID
87  * (SMBIOS3_TABLE_GUID, {F2FD1544-9794-4A2C-992E-E5BBCF20E394}) and using the
88  * associated pointer. See section 4.6 of the UEFI Specification for details.
89  * See section 2.3 of the UEFI Specification for how to report the containing
90  * memory type."
91  */
92 #define	SMBIOS_START		0xf0000
93 #define	SMBIOS_LENGTH		0x10000
94 #define	SMBIOS_STEP		0x10
95 #define	SMBIOS_SIG		"_SM_"
96 #define	SMBIOS3_SIG		"_SM3_"
97 #define	SMBIOS_DMI_SIG		"_DMI_"
98 
99 /*
100  * 5.1 General
101  *...
102  * NOTE The Entry Point Structure and all SMBIOS structures assume a
103  * little-endian ordering convention...
104  * ...
105  *
106  * We use memcpy to avoid unaligned access to memory. To normal memory, this is
107  * fine, but the memory we are using might be mmap'd /dev/mem which under Linux
108  * on aarch64 doesn't allow unaligned access. leXdec and friends can't be used
109  * because those can optimize to an unaligned load (which often is fine, but not
110  * for mmap'd /dev/mem which has special memory attributes).
111  */
112 static inline uint8_t SMBIOS_GET8(const caddr_t base, int off) { return (base[off]); }
113 
114 static inline uint16_t
115 SMBIOS_GET16(const caddr_t base, int off)
116 {
117 	uint16_t v;
118 
119 	memcpy(&v, base + off, sizeof(v));
120 	return (le16toh(v));
121 }
122 
123 static inline uint32_t
124 SMBIOS_GET32(const caddr_t base, int off)
125 {
126 	uint32_t v;
127 
128 	memcpy(&v, base + off, sizeof(v));
129 	return (le32toh(v));
130 }
131 
132 static inline uint64_t
133 SMBIOS_GET64(const caddr_t base, int off)
134 {
135 	uint64_t v;
136 
137 	memcpy(&v, base + off, sizeof(v));
138 	return (le64toh(v));
139 }
140 
141 #define	SMBIOS_GETLEN(base)	SMBIOS_GET8(base, 0x01)
142 #define	SMBIOS_GETSTR(base)	((base) + SMBIOS_GETLEN(base))
143 
144 struct smbios_attr {
145 	int		probed;
146 	caddr_t 	addr;
147 	size_t		length;
148 	size_t		count;
149 	int		major;
150 	int		minor;
151 	int		ver;
152 	const char*	bios_vendor;
153 	const char*	maker;
154 	const char*	product;
155 	uint32_t	enabled_memory;
156 	uint32_t	old_enabled_memory;
157 	uint8_t		enabled_sockets;
158 	uint8_t		populated_sockets;
159 };
160 
161 static struct smbios_attr smbios;
162 #ifdef HAS_SMBV3
163 static int isv3;
164 #endif
165 
166 static uint8_t
167 smbios_checksum(const caddr_t addr, const uint8_t len)
168 {
169 	uint8_t		sum;
170 	int		i;
171 
172 	for (sum = 0, i = 0; i < len; i++)
173 		sum += SMBIOS_GET8(addr, i);
174 	return (sum);
175 }
176 
177 static caddr_t
178 smbios_sigsearch(const caddr_t addr, const uint32_t len)
179 {
180 	caddr_t		cp;
181 
182 	/* Search on 16-byte boundaries. */
183 	for (cp = addr; cp < addr + len; cp += SMBIOS_STEP) {
184 		/* v2.1, 32-bit Entry point */
185 		if (strncmp(cp, SMBIOS_SIG, sizeof(SMBIOS_SIG) - 1) == 0 &&
186 		    smbios_checksum(cp, SMBIOS_GET8(cp, 0x05)) == 0 &&
187 		    strncmp(cp + 0x10, SMBIOS_DMI_SIG, 5) == 0 &&
188 		    smbios_checksum(cp + 0x10, 0x0f) == 0)
189 			return (cp);
190 
191 #ifdef HAS_SMBV3
192 		/* v3.0, 64-bit Entry point */
193 		if (strncmp(cp, SMBIOS3_SIG, sizeof(SMBIOS3_SIG) - 1) == 0 &&
194 		    smbios_checksum(cp, SMBIOS_GET8(cp, 0x06)) == 0) {
195 			isv3 = 1;
196 			return (cp);
197 		}
198 #endif
199 	}
200 	return (NULL);
201 }
202 
203 static const char*
204 smbios_getstring(caddr_t addr, const int offset)
205 {
206 	caddr_t		cp;
207 	int		i, idx;
208 
209 	idx = SMBIOS_GET8(addr, offset);
210 	if (idx != 0) {
211 		cp = SMBIOS_GETSTR(addr);
212 		for (i = 1; i < idx; i++)
213 			cp += strlen(cp) + 1;
214 		return cp;
215 	}
216 	return (NULL);
217 }
218 
219 static void
220 smbios_setenv(const char *name, caddr_t addr, const int offset)
221 {
222 	const char*	val;
223 
224 	val = smbios_getstring(addr, offset);
225 	if (val != NULL)
226 		setenv(name, val, 1);
227 }
228 
229 #ifdef SMBIOS_SERIAL_NUMBERS
230 
231 #define	UUID_SIZE		16
232 #define	UUID_TYPE		uint32_t
233 #define	UUID_STEP		sizeof(UUID_TYPE)
234 #define	UUID_ALL_BITS		(UUID_SIZE / UUID_STEP)
235 #define	UUID_GET(base, off)	SMBIOS_GET32(base, off)
236 
237 static void
238 smbios_setuuid(const char *name, const caddr_t addr, const int ver __unused)
239 {
240 	char		uuid[37];
241 	int		byteorder, i, ones, zeros;
242 	UUID_TYPE	n;
243 	uint32_t	f1;
244 	uint16_t	f2, f3;
245 
246 	for (i = 0, ones = 0, zeros = 0; i < UUID_SIZE; i += UUID_STEP) {
247 		n = UUID_GET(addr, i) + 1;
248 		if (zeros == 0 && n == 0)
249 			ones++;
250 		else if (ones == 0 && n == 1)
251 			zeros++;
252 		else
253 			break;
254 	}
255 
256 	if (ones != UUID_ALL_BITS && zeros != UUID_ALL_BITS) {
257 		/*
258 		 * 3.3.2.1 System UUID
259 		 *
260 		 * "Although RFC 4122 recommends network byte order for all
261 		 * fields, the PC industry (including the ACPI, UEFI, and
262 		 * Microsoft specifications) has consistently used
263 		 * little-endian byte encoding for the first three fields:
264 		 * time_low, time_mid, time_hi_and_version. The same encoding,
265 		 * also known as wire format, should also be used for the
266 		 * SMBIOS representation of the UUID."
267 		 *
268 		 * Note: We use network byte order for backward compatibility
269 		 * unless SMBIOS version is 2.6+ or little-endian is forced.
270 		 */
271 #if defined(SMBIOS_LITTLE_ENDIAN_UUID)
272 		byteorder = LITTLE_ENDIAN;
273 #elif defined(SMBIOS_NETWORK_ENDIAN_UUID)
274 		byteorder = BIG_ENDIAN;
275 #else
276 		byteorder = ver < 0x0206 ? BIG_ENDIAN : LITTLE_ENDIAN;
277 #endif
278 		if (byteorder != LITTLE_ENDIAN) {
279 			f1 = ntohl(SMBIOS_GET32(addr, 0));
280 			f2 = ntohs(SMBIOS_GET16(addr, 4));
281 			f3 = ntohs(SMBIOS_GET16(addr, 6));
282 		} else {
283 			f1 = le32toh(SMBIOS_GET32(addr, 0));
284 			f2 = le16toh(SMBIOS_GET16(addr, 4));
285 			f3 = le16toh(SMBIOS_GET16(addr, 6));
286 		}
287 		sprintf(uuid,
288 		    "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
289 		    f1, f2, f3, SMBIOS_GET8(addr, 8), SMBIOS_GET8(addr, 9),
290 		    SMBIOS_GET8(addr, 10), SMBIOS_GET8(addr, 11),
291 		    SMBIOS_GET8(addr, 12), SMBIOS_GET8(addr, 13),
292 		    SMBIOS_GET8(addr, 14), SMBIOS_GET8(addr, 15));
293 		setenv(name, uuid, 1);
294 	}
295 }
296 
297 #undef UUID_SIZE
298 #undef UUID_TYPE
299 #undef UUID_STEP
300 #undef UUID_ALL_BITS
301 #undef UUID_GET
302 
303 #endif
304 
305 static const char *
306 smbios_parse_chassis_type(caddr_t addr)
307 {
308 	int		type;
309 
310 	type = SMBIOS_GET8(addr, 0x5);
311 	switch (type) {
312 	case 0x1:
313 		return ("Other");
314 	case 0x2:
315 		return ("Unknown");
316 	case 0x3:
317 		return ("Desktop");
318 	case 0x4:
319 		return ("Low Profile Desktop");
320 	case 0x5:
321 		return ("Pizza Box");
322 	case 0x6:
323 		return ("Mini Tower");
324 	case 0x7:
325 		return ("Tower");
326 	case 0x8:
327 		return ("Portable");
328 	case 0x9:
329 		return ("Laptop");
330 	case 0xA:
331 		return ("Notebook");
332 	case 0xB:
333 		return ("Hand Held");
334 	case 0xC:
335 		return ("Docking Station");
336 	case 0xD:
337 		return ("All in One");
338 	case 0xE:
339 		return ("Sub Notebook");
340 	case 0xF:
341 		return ("Lunch Box");
342 	case 0x10:
343 		return ("Space-saving");
344 	case 0x11:
345 		return ("Main Server Chassis");
346 	case 0x12:
347 		return ("Expansion Chassis");
348 	case 0x13:
349 		return ("SubChassis");
350 	case 0x14:
351 		return ("Bus Expansion Chassis");
352 	case 0x15:
353 		return ("Peripheral Chassis");
354 	case 0x16:
355 		return ("RAID Chassis");
356 	case 0x17:
357 		return ("Rack Mount Chassis");
358 	case 0x18:
359 		return ("Sealed-case PC");
360 	case 0x19:
361 		return ("Multi-system chassis");
362 	case 0x1A:
363 		return ("Compact PCI");
364 	case 0x1B:
365 		return ("Advanced TCA");
366 	case 0x1C:
367 		return ("Blade");
368 	case 0x1D:
369 		return ("Blade Enclosure");
370 	case 0x1E:
371 		return ("Tablet");
372 	case 0x1F:
373 		return ("Convertible");
374 	case 0x20:
375 		return ("Detachable");
376 	case 0x21:
377 		return ("IoT Gateway");
378 	case 0x22:
379 		return ("Embedded PC");
380 	case 0x23:
381 		return ("Mini PC");
382 	case 0x24:
383 		return ("Stick PC");
384 	}
385 
386 	return ("Undefined");
387 }
388 
389 static caddr_t
390 smbios_parse_table(const caddr_t addr)
391 {
392 	caddr_t		cp;
393 	int		proc, size, osize, type;
394 	uint8_t		bios_minor, bios_major;
395 	char		buf[16];
396 
397 	type = SMBIOS_GET8(addr, 0);	/* 3.1.2 Structure Header Format */
398 	switch(type) {
399 	case 0:		/* 3.3.1 BIOS Information (Type 0) */
400 		smbios_setenv("smbios.bios.vendor", addr, 0x04);
401 		smbios_setenv("smbios.bios.version", addr, 0x05);
402 		smbios_setenv("smbios.bios.reldate", addr, 0x08);
403 		bios_major = SMBIOS_GET8(addr, 0x14);
404 		bios_minor = SMBIOS_GET8(addr, 0x15);
405 		if (bios_minor != 0xFF && bios_major != 0xFF) {
406 			snprintf(buf, sizeof(buf), "%u.%u",
407 			    bios_major, bios_minor);
408 			setenv("smbios.bios.revision", buf, 1);
409 		}
410 		break;
411 
412 	case 1:		/* 3.3.2 System Information (Type 1) */
413 		smbios_setenv("smbios.system.maker", addr, 0x04);
414 		smbios_setenv("smbios.system.product", addr, 0x05);
415 		smbios_setenv("smbios.system.version", addr, 0x06);
416 #ifdef SMBIOS_SERIAL_NUMBERS
417 		smbios_setenv("smbios.system.serial", addr, 0x07);
418 		smbios_setuuid("smbios.system.uuid", addr + 0x08, smbios.ver);
419 #endif
420 		if (smbios.major > 2 ||
421 		    (smbios.major == 2 && smbios.minor >= 4)) {
422 			smbios_setenv("smbios.system.sku", addr, 0x19);
423 			smbios_setenv("smbios.system.family", addr, 0x1a);
424 		}
425 		break;
426 
427 	case 2:		/* 3.3.3 Base Board (or Module) Information (Type 2) */
428 		smbios_setenv("smbios.planar.maker", addr, 0x04);
429 		smbios_setenv("smbios.planar.product", addr, 0x05);
430 		smbios_setenv("smbios.planar.version", addr, 0x06);
431 #ifdef SMBIOS_SERIAL_NUMBERS
432 		smbios_setenv("smbios.planar.serial", addr, 0x07);
433 		smbios_setenv("smbios.planar.tag", addr, 0x08);
434 #endif
435 		smbios_setenv("smbios.planar.location", addr, 0x0a);
436 		break;
437 
438 	case 3:		/* 3.3.4 System Enclosure or Chassis (Type 3) */
439 		smbios_setenv("smbios.chassis.maker", addr, 0x04);
440 		setenv("smbios.chassis.type", smbios_parse_chassis_type(addr), 1);
441 		smbios_setenv("smbios.chassis.version", addr, 0x06);
442 #ifdef SMBIOS_SERIAL_NUMBERS
443 		smbios_setenv("smbios.chassis.serial", addr, 0x07);
444 		smbios_setenv("smbios.chassis.tag", addr, 0x08);
445 #endif
446 		break;
447 
448 	case 4:		/* 3.3.5 Processor Information (Type 4) */
449 		/*
450 		 * Offset 18h: Processor Status
451 		 *
452 		 * Bit 7	Reserved, must be 0
453 		 * Bit 6	CPU Socket Populated
454 		 *		1 - CPU Socket Populated
455 		 *		0 - CPU Socket Unpopulated
456 		 * Bit 5:3	Reserved, must be zero
457 		 * Bit 2:0	CPU Status
458 		 *		0h - Unknown
459 		 *		1h - CPU Enabled
460 		 *		2h - CPU Disabled by User via BIOS Setup
461 		 *		3h - CPU Disabled by BIOS (POST Error)
462 		 *		4h - CPU is Idle, waiting to be enabled
463 		 *		5-6h - Reserved
464 		 *		7h - Other
465 		 */
466 		proc = SMBIOS_GET8(addr, 0x18);
467 		if ((proc & 0x07) == 1)
468 			smbios.enabled_sockets++;
469 		if ((proc & 0x40) != 0)
470 			smbios.populated_sockets++;
471 		break;
472 
473 	case 6:		/* 3.3.7 Memory Module Information (Type 6, Obsolete) */
474 		/*
475 		 * Offset 0Ah: Enabled Size
476 		 *
477 		 * Bit 7	Bank connection
478 		 *		1 - Double-bank connection
479 		 *		0 - Single-bank connection
480 		 * Bit 6:0	Size (n), where 2**n is the size in MB
481 		 *		7Dh - Not determinable (Installed Size only)
482 		 *		7Eh - Module is installed, but no memory
483 		 *		      has been enabled
484 		 *		7Fh - Not installed
485 		 */
486 		osize = SMBIOS_GET8(addr, 0x0a) & 0x7f;
487 		if (osize > 0 && osize < 22)
488 			smbios.old_enabled_memory += 1 << (osize + 10);
489 		break;
490 
491 	case 17:	/* 3.3.18 Memory Device (Type 17) */
492 		/*
493 		 * Offset 0Ch: Size
494 		 *
495 		 * Bit 15	Granularity
496 		 *		1 - Value is in kilobytes units
497 		 *		0 - Value is in megabytes units
498 		 * Bit 14:0	Size
499 		 */
500 		size = SMBIOS_GET16(addr, 0x0c);
501 		if (size != 0 && size != 0xffff)
502 			smbios.enabled_memory += (size & 0x8000) != 0 ?
503 			    (size & 0x7fff) : (size << 10);
504 		break;
505 
506 	default:	/* skip other types */
507 		break;
508 	}
509 
510 	/* Find structure terminator. */
511 	cp = SMBIOS_GETSTR(addr);
512 	while (SMBIOS_GET16(cp, 0) != 0)
513 		cp++;
514 
515 	return (cp + 2);
516 }
517 
518 static caddr_t
519 smbios_find_struct(int type)
520 {
521 	caddr_t		dmi;
522 	size_t		i;
523 	caddr_t		ep;
524 
525 	if (smbios.addr == NULL)
526 		return (NULL);
527 
528 	ep = smbios.addr + smbios.length;
529 	for (dmi = smbios.addr, i = 0;
530 	     dmi < ep && i < smbios.count; i++) {
531 		if (SMBIOS_GET8(dmi, 0) == type) {
532 			return dmi;
533 		}
534 		/* Find structure terminator. */
535 		dmi = SMBIOS_GETSTR(dmi);
536 		while (SMBIOS_GET16(dmi, 0) != 0 && dmi < ep) {
537 			dmi++;
538 		}
539 		dmi += 2;	/* For checksum */
540 	}
541 
542 	return (NULL);
543 }
544 
545 static void
546 smbios_probe(const caddr_t addr)
547 {
548 	caddr_t		saddr, info;
549 	uintptr_t	paddr;
550 	int		maj_off;
551 	int		min_off;
552 
553 	if (smbios.probed)
554 		return;
555 	smbios.probed = 1;
556 
557 	/* Search signatures and validate checksums. */
558 	saddr = smbios_sigsearch(addr ? addr : PTOV(SMBIOS_START),
559 	    SMBIOS_LENGTH);
560 	if (saddr == NULL)
561 		return;
562 
563 #ifdef HAS_SMBV3
564 	if (isv3) {
565 		smbios.length = SMBIOS_GET32(saddr, 0x0c);	/* Structure Table Length */
566 		paddr = SMBIOS_GET64(saddr, 0x10);		/* Structure Table Address */
567 		smbios.count = -1;				/* not present in V3 */
568 		smbios.ver = 0;					/* not present in V3 */
569 		maj_off = 0x07;
570 		min_off = 0x08;
571 	} else
572 #endif
573 	{
574 		smbios.length = SMBIOS_GET16(saddr, 0x16);	/* Structure Table Length */
575 		paddr = SMBIOS_GET32(saddr, 0x18);		/* Structure Table Address */
576 		smbios.count = SMBIOS_GET16(saddr, 0x1c);	/* No of SMBIOS Structures */
577 		smbios.ver = SMBIOS_GET8(saddr, 0x1e);		/* SMBIOS BCD Revision */
578 		maj_off = 0x06;
579 		min_off = 0x07;
580 	}
581 
582 
583 	if (smbios.ver != 0) {
584 		smbios.major = smbios.ver >> 4;
585 		smbios.minor = smbios.ver & 0x0f;
586 		if (smbios.major > 9 || smbios.minor > 9)
587 			smbios.ver = 0;
588 	}
589 	if (smbios.ver == 0) {
590 		smbios.major = SMBIOS_GET8(saddr, maj_off);/* SMBIOS Major Version */
591 		smbios.minor = SMBIOS_GET8(saddr, min_off);/* SMBIOS Minor Version */
592 	}
593 	smbios.ver = (smbios.major << 8) | smbios.minor;
594 	smbios.addr = PTOV(paddr);
595 
596 	/* Get system information from SMBIOS */
597 	info = smbios_find_struct(0x00);
598 	if (info != NULL) {
599 		smbios.bios_vendor = smbios_getstring(info, 0x04);
600 	}
601 	info = smbios_find_struct(0x01);
602 	if (info != NULL) {
603 		smbios.maker = smbios_getstring(info, 0x04);
604 		smbios.product = smbios_getstring(info, 0x05);
605 	}
606 }
607 
608 void
609 smbios_detect(const caddr_t addr)
610 {
611 	char		buf[16];
612 	caddr_t		dmi;
613 	size_t		i;
614 
615 	smbios_probe(addr);
616 	if (smbios.addr == NULL)
617 		return;
618 
619 	for (dmi = smbios.addr, i = 0;
620 	     dmi < smbios.addr + smbios.length && i < smbios.count; i++)
621 		dmi = smbios_parse_table(dmi);
622 
623 	sprintf(buf, "%d.%d", smbios.major, smbios.minor);
624 	setenv("smbios.version", buf, 1);
625 	if (smbios.enabled_memory > 0 || smbios.old_enabled_memory > 0) {
626 		sprintf(buf, "%u", smbios.enabled_memory > 0 ?
627 		    smbios.enabled_memory : smbios.old_enabled_memory);
628 		setenv("smbios.memory.enabled", buf, 1);
629 	}
630 	if (smbios.enabled_sockets > 0) {
631 		sprintf(buf, "%u", smbios.enabled_sockets);
632 		setenv("smbios.socket.enabled", buf, 1);
633 	}
634 	if (smbios.populated_sockets > 0) {
635 		sprintf(buf, "%u", smbios.populated_sockets);
636 		setenv("smbios.socket.populated", buf, 1);
637 	}
638 }
639 
640 static int
641 smbios_match_str(const char* s1, const char* s2)
642 {
643 	return (s1 == NULL || (s2 != NULL && !strcmp(s1, s2)));
644 }
645 
646 int
647 smbios_match(const char* bios_vendor, const char* maker,
648     const char* product)
649 {
650 	/* XXXRP currently, only called from non-EFI. */
651 	smbios_probe(NULL);
652 	return (smbios_match_str(bios_vendor, smbios.bios_vendor) &&
653 	    smbios_match_str(maker, smbios.maker) &&
654 	    smbios_match_str(product, smbios.product));
655 }
656