git: 53fdb802567d - stable/12 - libsa: smbios: Parse the chassis type and export it as smbios.chassis.type

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Fri, 08 Oct 2021 06:11:03 UTC
The branch stable/12 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=53fdb802567df401b333fa0aa898908ccabaca93

commit 53fdb802567df401b333fa0aa898908ccabaca93
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2020-08-20 12:50:49 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2021-10-08 05:24:27 +0000

    libsa: smbios: Parse the chassis type and export it as smbios.chassis.type
    
    It can be useful to know what type of machine we are running on for desktop
    related thing.
    It also allow us to support all the DMI variable that linux driver can fetch.
    
    (cherry picked from commit 9060f2c3920dde41226cf52b925bc949815c7f01)
---
 stand/libsa/smbios.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/stand/libsa/smbios.c b/stand/libsa/smbios.c
index c621114d9107..5582a2f3ce90 100644
--- a/stand/libsa/smbios.c
+++ b/stand/libsa/smbios.c
@@ -209,6 +209,90 @@ smbios_setuuid(const char *name, const caddr_t addr, const int ver)
 
 #endif
 
+static const char *
+smbios_parse_chassis_type(caddr_t addr)
+{
+	int		type;
+
+	type = SMBIOS_GET8(addr, 0x5);
+	switch (type) {
+	case 0x1:
+		return ("Other");
+	case 0x2:
+		return ("Unknown");
+	case 0x3:
+		return ("Desktop");
+	case 0x4:
+		return ("Low Profile Desktop");
+	case 0x5:
+		return ("Pizza Box");
+	case 0x6:
+		return ("Mini Tower");
+	case 0x7:
+		return ("Tower");
+	case 0x8:
+		return ("Portable");
+	case 0x9:
+		return ("Laptop");
+	case 0xA:
+		return ("Notebook");
+	case 0xB:
+		return ("Hand Held");
+	case 0xC:
+		return ("Docking Station");
+	case 0xD:
+		return ("All in One");
+	case 0xE:
+		return ("Sub Notebook");
+	case 0xF:
+		return ("Lunch Box");
+	case 0x10:
+		return ("Space-saving");
+	case 0x11:
+		return ("Main Server Chassis");
+	case 0x12:
+		return ("Expansion Chassis");
+	case 0x13:
+		return ("SubChassis");
+	case 0x14:
+		return ("Bus Expansion Chassis");
+	case 0x15:
+		return ("Peripheral Chassis");
+	case 0x16:
+		return ("RAID Chassis");
+	case 0x17:
+		return ("Rack Mount Chassis");
+	case 0x18:
+		return ("Sealed-case PC");
+	case 0x19:
+		return ("Multi-system chassis");
+	case 0x1A:
+		return ("Compact PCI");
+	case 0x1B:
+		return ("Advanced TCA");
+	case 0x1C:
+		return ("Blade");
+	case 0x1D:
+		return ("Blade Enclosure");
+	case 0x1E:
+		return ("Tablet");
+	case 0x1F:
+		return ("Convertible");
+	case 0x20:
+		return ("Detachable");
+	case 0x21:
+		return ("IoT Gateway");
+	case 0x22:
+		return ("Embedded PC");
+	case 0x23:
+		return ("Mini PC");
+	case 0x24:
+		return ("Stick PC");
+	}
+
+	return ("Undefined");
+}
+
 static caddr_t
 smbios_parse_table(const caddr_t addr)
 {
@@ -251,6 +335,7 @@ smbios_parse_table(const caddr_t addr)
 
 	case 3:		/* 3.3.4 System Enclosure or Chassis (Type 3) */
 		smbios_setenv("smbios.chassis.maker", addr, 0x04);
+		setenv("smbios.chassis.type", smbios_parse_chassis_type(addr), 1);
 		smbios_setenv("smbios.chassis.version", addr, 0x06);
 #ifdef SMBIOS_SERIAL_NUMBERS
 		smbios_setenv("smbios.chassis.serial", addr, 0x07);