1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright 2021 Oxide Computer Company
14 */
15
16 /*
17 * This is a hodgepodge to validate that the string tables are directionally
18 * correct.
19 */
20
21 #include "smbios_test.h"
22
23 typedef const char *(*smbios_strfunc_f)(uint_t);
24
25 typedef struct smbios_strtest {
26 smbios_strfunc_f ss_func;
27 uint_t ss_num;
28 const char *ss_str;
29 } smbios_strtest_t;
30
31 static smbios_strtest_t smbios_strs[] = {
32 { smbios_battery_chem_desc, SMB_BDC_LEADACID, "Lead Acid" },
33 { smbios_bboard_flag_name, SMB_BBFL_NEEDAUX, "SMB_BBFL_NEEDAUX" },
34 { smbios_bboard_flag_name, SMB_BBFL_HOTSWAP, "SMB_BBFL_HOTSWAP" },
35 { smbios_bboard_flag_desc, SMB_BBFL_REMOVABLE, "board is removable" },
36 { smbios_bboard_flag_desc, SMB_BBFL_HOTSWAP, "board is hot-swappable" },
37 { smbios_bboard_type_desc, SMB_BBT_PROC, "processor module" },
38 { smbios_bboard_type_desc, SMB_BBT_MOTHER, "motherboard" },
39 { smbios_bios_xb1_desc, SMB_BIOSXB1_ACPI, "ACPI is supported" },
40 { smbios_bios_xb1_name, SMB_BIOSXB1_ACPI, "SMB_BIOSXB1_ACPI" },
41 { smbios_bios_xb2_desc, SMB_BIOSXB2_VM, "SMBIOS table describes a VM" },
42 { smbios_bios_xb2_name, SMB_BIOSXB2_UEFI, "SMB_BIOSXB2_UEFI" },
43 { smbios_boot_desc, SMB_BOOT_NOMEDIA, "no bootable media" },
44 { smbios_cache_assoc_desc, SMB_CAA_4WAY, "4-way set associative" },
45 { smbios_cache_ctype_desc, SMB_CAT_BURST, "burst" },
46 { smbios_cache_ctype_desc, SMB_CAT_SYNC, "synchronous" },
47 { smbios_cache_ctype_name, SMB_CAT_ASYNC, "SMB_CAT_ASYNC" },
48 { smbios_cache_ecc_desc, SMB_CAE_PARITY, "parity" },
49 { smbios_cache_flag_desc, SMB_CAF_SOCKETED, "cache is socketed" },
50 { smbios_cache_flag_name, SMB_CAF_ENABLED, "SMB_CAF_ENABLED" },
51 { smbios_cache_logical_desc, SMB_CAG_INSTR, "instruction" },
52 { smbios_cache_mode_desc, SMB_CAM_WB, "write-back" },
53 { smbios_chassis_type_desc, SMB_CHT_PIZZA, "pizza box" },
54 { smbios_chassis_state_desc, SMB_CHST_SAFE, "safe" },
55 { smbios_evlog_flag_desc, SMB_EVFL_VALID, "log area valid" },
56 { smbios_evlog_flag_name, SMB_EVFL_FULL, "SMB_EVFL_FULL" },
57 { smbios_evlog_format_desc, SMB_EVHF_F1, "DMTF log header type 1" },
58 { smbios_evlog_method_desc, SMB_EVM_GPNV,
59 "GP Non-Volatile API Access" },
60 { smbios_fwinfo_ch_name, SMB_FWC_UPDATE, "SMB_FWC_UPDATE" },
61 { smbios_fwinfo_ch_desc, SMB_FWC_WP, "write-protect" },
62 { smbios_fwinfo_id_desc, SMB_FWI_UEFI, "UEFI GUID" },
63 { smbios_fwinfo_state_desc, SMB_FWS_DISABLED, "disabled" },
64 { smbios_fwinfo_state_desc, SMB_FWS_STB_SPARE, "standby spare" },
65 { smbios_fwinfo_vers_desc, SMB_FWV_HEX64, "64-bit hex" },
66 { smbios_vprobe_loc_desc, SMB_VPROBE_L_PROC, "processor" },
67 { smbios_vprobe_loc_desc, SMB_VPROBE_L_PROCMOD, "processor module" },
68 { smbios_vprobe_status_desc, SMB_VPROBE_S_CRIT, "critical" },
69 { smbios_cooldev_status_desc, SMB_COOLDEV_S_OK, "OK" },
70 { smbios_cooldev_type_desc, SMB_COOLDEV_T_FAN, "fan" },
71 { smbios_tprobe_loc_desc, SMB_TPROBE_L_DISK, "disk" },
72 { smbios_tprobe_status_desc, SMB_TPROBE_S_NONRECOV, "non-recoverable" },
73 { smbios_iprobe_loc_desc, SMB_IPROBE_L_AIC, "add-in card" },
74 { smbios_iprobe_status_desc, SMB_IPROBE_S_UNKNOWN, "unknown" },
75 { smbios_ipmi_flag_desc, SMB_IPMI_F_INTRHIGH,
76 "intr active high (else low)" },
77 { smbios_ipmi_flag_name, SMB_IPMI_F_IOADDR,
78 "SMB_IPMI_F_IOADDR" },
79 { smbios_ipmi_type_desc, SMB_IPMI_T_KCS,
80 "KCS: Keyboard Controller Style" },
81 { smbios_powersup_flag_name, SMB_POWERSUP_F_PRESENT,
82 "SMB_POWERSUP_F_PRESENT" },
83 { smbios_powersup_flag_desc, SMB_POWERSUP_F_HOT,
84 "PSU is hot-replaceable" },
85 { smbios_powersup_input_desc, SMB_POWERSUP_I_WIDE, "wide range" },
86 { smbios_powersup_status_desc, SMB_POWERSUP_S_OK, "OK" },
87 { smbios_powersup_type_desc, SMB_POWERSUP_T_UPS, "UPS" },
88 { smbios_hwsec_desc, SMB_HWSEC_PS_ENABLED, "password enabled" },
89 { smbios_memarray_loc_desc, SMB_MAL_NUBUS, "NuBus" },
90 { smbios_memarray_use_desc, SMB_MAU_CACHE, "cache memory" },
91 { smbios_memarray_ecc_desc, SMB_MAE_CRC, "CRC" },
92 { smbios_memdevice_form_desc, SMB_MDFF_ZIP, "ZIP" },
93 { smbios_memdevice_type_desc, SMB_MDT_LPDDR5, "LPDDR5" },
94 { smbios_memdevice_flag_name, SMB_MDF_EDO, "SMB_MDF_EDO" },
95 { smbios_memdevice_flag_desc, SMB_MDF_PSTATIC, "pseudo-static" },
96 { smbios_memdevice_rank_desc, SMB_MDR_OCTAL, "octal" },
97 { smbios_memdevice_memtech_desc, SMB_MTECH_DRAM, "DRAM" },
98 { smbios_memdevice_op_capab_name, SMB_MOMC_VOLATILE,
99 "SMB_MOMC_VOLATILE" },
100 { smbios_memdevice_op_capab_desc, SMB_MOMC_BLOCK_PM,
101 "Block-accessible persistent memory" },
102 { smbios_onboard_type_desc, SMB_OBT_SAS, "sas" },
103 { smbios_onboard_ext_type_desc, SMB_OBET_EMMC, "eMMC" },
104 { smbios_pointdev_iface_desc, SMB_PDI_PS2, "PS/2" },
105 { smbios_pointdev_type_desc, SMB_PDT_TOPAD, "Touch Pad" },
106 { smbios_port_conn_desc, SMB_POC_RJ45, "RJ-45" },
107 { smbios_port_type_desc, SMB_POT_NETWORK, "Network port" },
108 { smbios_processor_family_desc, SMB_PRF_HOBBIT, "Hobbit" },
109 { smbios_processor_status_desc, SMB_PRS_IDLE, "waiting to be enabled" },
110 { smbios_processor_type_desc, SMB_PRT_DSP, "DSP processor" },
111 { smbios_processor_upgrade_desc, SMB_PRU_SP3, "socket SP3" },
112 { smbios_processor_core_flag_name, SMB_PRC_PM, "SMB_PRC_PM" },
113 { smbios_processor_core_flag_desc, SMB_PRC_MC, "multi-core" },
114 { smbios_processor_info_type_desc, SMB_PROCINFO_T_AARCH64,
115 "64-bit ARM (aarch64)" },
116 { smbios_riscv_priv_desc, SMB_RV_PRIV_S, "Supervisor Mode" },
117 { smbios_riscv_priv_name, SMB_RV_PRIV_U, "SMB_RV_PRIV_U" },
118 { smbios_riscv_width_desc, SMB_RV_WIDTH_64B, "64-bit" },
119 { smbios_slot_type_desc, SMB_SLT_AGP, "AGP" },
120 { smbios_slot_width_desc, SMB_SLW_32X, "32x or x32" },
121 { smbios_slot_usage_desc, SMB_SLU_AVAIL, "available" },
122 { smbios_slot_length_desc, SMB_SLL_LONG, "long length" },
123 { smbios_slot_ch1_desc, SMB_SLCH1_33V, "provides 3.3V" },
124 { smbios_slot_ch1_name, SMB_SLCH1_PCMRR, "SMB_SLCH1_PCMRR" },
125 { smbios_slot_ch2_desc, SMB_SLCH2_HOTPLUG,
126 "slot supports hot-plug devices" },
127 { smbios_slot_ch2_name, SMB_SLCH2_CXL2, "SMB_SLCH2_CXL2" },
128 { smbios_slot_height_desc, SMB_SLHT_FULL, "full height" },
129 { smbios_strprop_id_desc, SMB_STRP_UEFI_DEVPATH, "UEFI device path" },
130 { smbios_type_desc, SMB_TYPE_COOLDEV, "cooling device" },
131 { smbios_type_name, SMB_TYPE_POWERSUP, "SMB_TYPE_POWERSUP" },
132 { smbios_system_wakeup_desc, SMB_WAKEUP_LAN, "LAN remote" },
133 };
134
135 boolean_t
smbios_test_verify_strings(smbios_hdl_t * hdl)136 smbios_test_verify_strings(smbios_hdl_t *hdl)
137 {
138 boolean_t ret = B_TRUE;
139
140 for (uint_t i = 0; i < ARRAY_SIZE(smbios_strs); i++) {
141 uint_t in = smbios_strs[i].ss_num;
142 const char *exp = smbios_strs[i].ss_str;
143 const char *out = smbios_strs[i].ss_func(in);
144
145 if (out == NULL) {
146 warnx("failed to look up string, expected %u->%s",
147 in, exp);
148 ret = B_FALSE;
149 } else if (strcmp(exp, out) != 0) {
150 warnx("found wrong string for %u->%s: %s", in, exp,
151 out);
152 ret = B_FALSE;
153 }
154 }
155
156 return (ret);
157 }
158