xref: /illumos-gate/usr/src/test/util-tests/tests/smbios/smbios_test_extproc.c (revision a3d73cfd151b1e83f74b4f6d1f3497dd064d8c84)
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 2026 Oxide Computer Company
14  */
15 
16 /*
17  * Tests for Sun OEM Extended Processor, Type 132.
18  */
19 
20 #include "smbios_test.h"
21 
22 static uint16_t proc_hdl = 0x1234;
23 static uint8_t proc_fru = 0x23;
24 static uint16_t proc_apicid[] = { 0x23, 0x42, 0x169, 0x7777, UINT16_MAX };
25 
26 boolean_t
smbios_test_extproc_mktable_short(smbios_test_table_t * table)27 smbios_test_extproc_mktable_short(smbios_test_table_t *table)
28 {
29 	smb_header_t hdr;
30 
31 	smbios_test_table_add_sunoem(table);
32 
33 	hdr.smbh_type = SUN_OEM_EXT_PROCESSOR;
34 	hdr.smbh_len = sizeof (hdr);
35 
36 	(void) smbios_test_table_append(table, &hdr, sizeof (hdr));
37 	smbios_test_table_append_eot(table);
38 	return (B_TRUE);
39 }
40 
41 boolean_t
smbios_test_extproc_mktable_noapic(smbios_test_table_t * table)42 smbios_test_extproc_mktable_noapic(smbios_test_table_t *table)
43 {
44 	smb_processor_ext_t proc;
45 
46 	smbios_test_table_add_sunoem(table);
47 
48 	proc.smbpre_hdr.smbh_type = SUN_OEM_EXT_PROCESSOR;
49 	proc.smbpre_hdr.smbh_len = sizeof (proc);
50 
51 	proc.smbpre_processor = proc_hdl;
52 	proc.smbpre_fru = proc_fru;
53 	proc.smbpre_n = 0;
54 	(void) smbios_test_table_append(table, &proc, sizeof (proc));
55 	smbios_test_table_append_eot(table);
56 	return (B_TRUE);
57 }
58 
59 boolean_t
smbios_test_extproc_mktable_short_apic(smbios_test_table_t * table)60 smbios_test_extproc_mktable_short_apic(smbios_test_table_t *table)
61 {
62 	smb_processor_ext_t proc;
63 
64 	smbios_test_table_add_sunoem(table);
65 
66 	proc.smbpre_hdr.smbh_type = SUN_OEM_EXT_PROCESSOR;
67 	proc.smbpre_hdr.smbh_len = sizeof (proc);
68 
69 	proc.smbpre_processor = proc_hdl;
70 	proc.smbpre_fru = proc_fru;
71 	proc.smbpre_n = ARRAY_SIZE(proc_apicid);
72 	(void) smbios_test_table_append(table, &proc, sizeof (proc));
73 	smbios_test_table_append_eot(table);
74 	return (B_TRUE);
75 }
76 
77 boolean_t
smbios_test_extproc_mktable_apic(smbios_test_table_t * table)78 smbios_test_extproc_mktable_apic(smbios_test_table_t *table)
79 {
80 	smb_processor_ext_t proc;
81 
82 	smbios_test_table_add_sunoem(table);
83 
84 	proc.smbpre_hdr.smbh_type = SUN_OEM_EXT_PROCESSOR;
85 	proc.smbpre_hdr.smbh_len = sizeof (proc) + sizeof (proc_apicid);
86 
87 	proc.smbpre_processor = proc_hdl;
88 	proc.smbpre_fru = proc_fru;
89 	proc.smbpre_n = ARRAY_SIZE(proc_apicid);
90 	(void) smbios_test_table_append(table, &proc, sizeof (proc));
91 	smbios_test_table_append_raw(table, proc_apicid, sizeof (proc_apicid));
92 	smbios_test_table_append_eot(table);
93 	return (B_TRUE);
94 }
95 
96 boolean_t
smbios_test_extproc_verify_short(smbios_hdl_t * hdl)97 smbios_test_extproc_verify_short(smbios_hdl_t *hdl)
98 {
99 	smbios_struct_t sp;
100 	smbios_processor_ext_t proc;
101 
102 	if (smbios_lookup_type(hdl, SUN_OEM_EXT_PROCESSOR, &sp) == -1) {
103 		warnx("failed to lookup SMBIOS Sun OEM processor: %s",
104 		    smbios_errmsg(smbios_errno(hdl)));
105 		return (B_FALSE);
106 	}
107 
108 	if (smbios_info_extprocessor(hdl, sp.smbstr_id, &proc) != -1) {
109 		warnx("accidentally parsed invalid extended processor as "
110 		    "valid");
111 		return (B_FALSE);
112 	}
113 
114 	if (smbios_errno(hdl) != ESMB_SHORT) {
115 		warnx("encountered wrong error for extended processor, "
116 		    "expected: 0x%x, found: 0x%x", ESMB_SHORT,
117 		    smbios_errno(hdl));
118 		return (B_FALSE);
119 	}
120 
121 	return (B_TRUE);
122 }
123 
124 static boolean_t
smbios_test_extproc_verify_common(smbios_hdl_t * hdl,const uint16_t * apics,size_t napics)125 smbios_test_extproc_verify_common(smbios_hdl_t *hdl, const uint16_t *apics,
126     size_t napics)
127 {
128 	smbios_processor_ext_t proc;
129 	boolean_t ret = B_TRUE;
130 	smbios_struct_t sp;
131 
132 	if (smbios_lookup_type(hdl, SUN_OEM_EXT_PROCESSOR, &sp) == -1) {
133 		warnx("failed to lookup SMBIOS Sun OEM processor: %s",
134 		    smbios_errmsg(smbios_errno(hdl)));
135 		return (B_FALSE);
136 	}
137 
138 	if (smbios_info_extprocessor(hdl, sp.smbstr_id, &proc) == -1) {
139 		warnx("failed to get extended processor information: %s",
140 		    smbios_errmsg(smbios_errno(hdl)));
141 		return (B_FALSE);
142 	}
143 
144 	if (proc.smbpe_processor != proc_hdl) {
145 		warnx("encountered wrong proc handle 0x%x, expected 0x%x",
146 		    proc.smbpe_processor, proc_hdl);
147 		ret = B_FALSE;
148 	}
149 
150 	if (proc.smbpe_fru != proc_fru) {
151 		warnx("encountered wrong proc fru 0x%x, expected 0x%x",
152 		    proc.smbpe_fru, proc_fru);
153 		ret = B_FALSE;
154 	}
155 
156 	if (proc.smbpe_n != napics) {
157 		warnx("encountered wrong apic id count 0x%x, expected 0x%zx",
158 		    proc.smbpe_n, napics);
159 		ret = B_FALSE;
160 	}
161 
162 	if (napics > 0 && proc.smbpe_apicid == NULL) {
163 		warnx("expected 0x%zx apic ids, but found NULL APIC pointer",
164 		    napics);
165 		ret = B_FALSE;
166 	} else if (napics == 0 && proc.smbpe_apicid != NULL) {
167 		warnx("found non-NULL APIC pointer, but expected no APIC ids");
168 		ret = B_FALSE;
169 	}
170 
171 	if (napics > 0 && proc.smbpe_n == napics && proc.smbpe_apicid != NULL) {
172 		for (size_t i = 0; i < napics; i++) {
173 			if (proc.smbpe_apicid[i] != apics[i]) {
174 				warnx("APIC ID %zu mismatch: found 0x%x, "
175 				    "expected 0x%x", i, proc.smbpe_apicid[i],
176 				    apics[i]);
177 				ret = B_FALSE;
178 			}
179 		}
180 	}
181 
182 	return (ret);
183 }
184 
185 boolean_t
smbios_test_extproc_verify_noapic(smbios_hdl_t * hdl)186 smbios_test_extproc_verify_noapic(smbios_hdl_t *hdl)
187 {
188 	return (smbios_test_extproc_verify_common(hdl, NULL, 0));
189 }
190 
191 boolean_t
smbios_test_extproc_verify_apic(smbios_hdl_t * hdl)192 smbios_test_extproc_verify_apic(smbios_hdl_t *hdl)
193 {
194 	return (smbios_test_extproc_verify_common(hdl, proc_apicid,
195 	    ARRAY_SIZE(proc_apicid)));
196 }
197