Print this page
10145 smbios_info_boot() gets NULL check wrong
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/common/smbios/smb_info.c
+++ new/usr/src/common/smbios/smb_info.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
24 - * Copyright (c) 2017, Joyent, Inc.
24 + * Copyright (c) 2018, Joyent, Inc.
25 25 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
26 26 * Use is subject to license terms.
27 27 */
28 28
29 29 /*
30 30 * SMBIOS Information Routines
31 31 *
32 32 * The routines in this file are used to convert from the SMBIOS data format to
33 33 * a more reasonable and stable set of structures offered as part of our ABI.
34 34 * These functions take the general form:
35 35 *
36 36 * stp = smb_lookup_type(shp, foo);
37 37 * smb_foo_t foo;
38 38 *
39 39 * smb_info_bcopy(stp->smbst_hdr, &foo, sizeof (foo));
40 40 * bzero(caller's struct);
41 41 *
42 42 * copy/convert foo members into caller's struct
43 43 *
44 44 * We copy the internal structure on to an automatic variable so as to avoid
45 45 * checks everywhere for structures that the BIOS has improperly truncated, and
46 46 * also to automatically handle the case of a structure that has been extended.
47 47 * When necessary, this code can use smb_gteq() to determine whether the SMBIOS
48 48 * data is of a particular revision that is supposed to contain a new field.
49 49 *
50 50 * Note, when trying to bzero the caller's struct you have to be careful about
51 51 * versions. One can only bzero the initial version that existed in illumos. In
52 52 * other words, if someone passes an older library handle that doesn't support a
53 53 * version you cannot assume that their structures have those additional members
54 54 * in them. Instead, a 'base' version is introduced for such types that have
55 55 * differences and instead we only bzero out the base version and then handle
56 56 * the additional members. In general, because all additional members will be
57 57 * assigned, there's no reason to zero them out unless they are arrays that
58 58 * won't be entirely filled in.
59 59 *
60 60 * Due to history, anything added after the update from version 2.4, in other
61 61 * words additions from or after '5094 Update libsmbios with recent items'
62 62 * (4e901881) is currently being used for this. While we don't allow software
63 63 * compiling against this to get an older form, this was the first major update
64 64 * and a good starting point for us to enforce this behavior which is useful for
65 65 * moving forward to making this more public.
66 66 */
67 67
68 68 #include <sys/smbios_impl.h>
69 69 #include <sys/byteorder.h>
70 70
71 71 #ifdef _KERNEL
72 72 #include <sys/sunddi.h>
73 73 #else
74 74 #include <fcntl.h>
75 75 #include <unistd.h>
76 76 #include <string.h>
77 77 #endif
78 78
79 79 /*
80 80 * A large number of SMBIOS structures contain a set of common strings used to
81 81 * describe a h/w component's serial number, manufacturer, etc. These fields
82 82 * helpfully have different names and offsets and sometimes aren't consistent.
83 83 * To simplify life for our clients, we factor these common things out into
84 84 * smbios_info_t, which can be retrieved for any structure. The following
85 85 * table describes the mapping from a given structure to the smbios_info_t.
86 86 * Multiple SMBIOS stuctures' contained objects are also handled here.
87 87 */
88 88 static const struct smb_infospec {
89 89 uint8_t is_type; /* structure type */
90 90 uint8_t is_manu; /* manufacturer offset */
91 91 uint8_t is_product; /* product name offset */
92 92 uint8_t is_version; /* version offset */
93 93 uint8_t is_serial; /* serial number offset */
94 94 uint8_t is_asset; /* asset tag offset */
95 95 uint8_t is_location; /* location string offset */
96 96 uint8_t is_part; /* part number offset */
97 97 uint8_t is_contc; /* contained count */
98 98 uint8_t is_contsz; /* contained size */
99 99 uint8_t is_contv; /* contained objects */
100 100 } _smb_infospecs[] = {
101 101 { SMB_TYPE_SYSTEM,
102 102 offsetof(smb_system_t, smbsi_manufacturer),
103 103 offsetof(smb_system_t, smbsi_product),
104 104 offsetof(smb_system_t, smbsi_version),
105 105 offsetof(smb_system_t, smbsi_serial),
106 106 0,
107 107 0,
108 108 0,
109 109 0,
110 110 0,
111 111 0 },
112 112 { SMB_TYPE_BASEBOARD,
113 113 offsetof(smb_bboard_t, smbbb_manufacturer),
114 114 offsetof(smb_bboard_t, smbbb_product),
115 115 offsetof(smb_bboard_t, smbbb_version),
116 116 offsetof(smb_bboard_t, smbbb_serial),
117 117 offsetof(smb_bboard_t, smbbb_asset),
118 118 offsetof(smb_bboard_t, smbbb_location),
119 119 0,
120 120 offsetof(smb_bboard_t, smbbb_cn),
121 121 SMB_CONT_WORD,
122 122 offsetof(smb_bboard_t, smbbb_cv) },
123 123 { SMB_TYPE_CHASSIS,
124 124 offsetof(smb_chassis_t, smbch_manufacturer),
125 125 0,
126 126 offsetof(smb_chassis_t, smbch_version),
127 127 offsetof(smb_chassis_t, smbch_serial),
128 128 offsetof(smb_chassis_t, smbch_asset),
129 129 0,
130 130 0,
131 131 offsetof(smb_chassis_t, smbch_cn),
132 132 SMB_CONT_BYTE,
133 133 offsetof(smb_chassis_t, smbch_cv) },
134 134 { SMB_TYPE_PROCESSOR,
135 135 offsetof(smb_processor_t, smbpr_manufacturer),
136 136 0,
137 137 offsetof(smb_processor_t, smbpr_version),
138 138 offsetof(smb_processor_t, smbpr_serial),
139 139 offsetof(smb_processor_t, smbpr_asset),
140 140 offsetof(smb_processor_t, smbpr_socket),
141 141 offsetof(smb_processor_t, smbpr_part),
142 142 0,
143 143 0,
144 144 0 },
145 145 { SMB_TYPE_CACHE,
146 146 0,
147 147 0,
148 148 0,
149 149 0,
150 150 0,
151 151 offsetof(smb_cache_t, smbca_socket),
152 152 0,
153 153 0,
154 154 0,
155 155 0 },
156 156 { SMB_TYPE_PORT,
157 157 0,
158 158 0,
159 159 0,
160 160 0,
161 161 0,
162 162 offsetof(smb_port_t, smbpo_iref),
163 163 0,
164 164 0,
165 165 0,
166 166 0 },
167 167 { SMB_TYPE_SLOT,
168 168 0,
169 169 0,
170 170 0,
171 171 0,
172 172 0,
173 173 offsetof(smb_slot_t, smbsl_name),
174 174 0,
175 175 0,
176 176 0,
177 177 0 },
178 178 { SMB_TYPE_MEMDEVICE,
179 179 offsetof(smb_memdevice_t, smbmdev_manufacturer),
180 180 0,
181 181 0,
182 182 offsetof(smb_memdevice_t, smbmdev_serial),
183 183 offsetof(smb_memdevice_t, smbmdev_asset),
184 184 offsetof(smb_memdevice_t, smbmdev_dloc),
185 185 offsetof(smb_memdevice_t, smbmdev_part),
186 186 0,
187 187 0,
188 188 0 },
189 189 { SMB_TYPE_POWERSUP,
190 190 offsetof(smb_powersup_t, smbpsup_manufacturer),
191 191 offsetof(smb_powersup_t, smbpsup_devname),
192 192 offsetof(smb_powersup_t, smbpsup_rev),
193 193 offsetof(smb_powersup_t, smbpsup_serial),
194 194 offsetof(smb_powersup_t, smbpsup_asset),
195 195 offsetof(smb_powersup_t, smbpsup_loc),
196 196 offsetof(smb_powersup_t, smbpsup_part),
197 197 0,
198 198 0,
199 199 0 },
200 200 { SMB_TYPE_EOT }
201 201 };
202 202
203 203 static const char *
204 204 smb_info_strptr(const smb_struct_t *stp, uint8_t off, int *n)
205 205 {
206 206 const uint8_t *sp = (const uint8_t *)(uintptr_t)stp->smbst_hdr;
207 207
208 208 if (off != 0 && sp + off < stp->smbst_end) {
209 209 (*n)++; /* indicate success for caller */
210 210 return (smb_strptr(stp, sp[off]));
211 211 }
212 212
213 213 return (smb_strptr(stp, 0));
214 214 }
215 215
216 216 static void
217 217 smb_info_bcopy(const smb_header_t *hp, void *dst, size_t dstlen)
218 218 {
219 219 if (dstlen > hp->smbh_len) {
220 220 bcopy(hp, dst, hp->smbh_len);
221 221 bzero((char *)dst + hp->smbh_len, dstlen - hp->smbh_len);
222 222 } else
223 223 bcopy(hp, dst, dstlen);
224 224 }
225 225
226 226 smbios_entry_point_t
227 227 smbios_info_smbios(smbios_hdl_t *shp, smbios_entry_t *ep)
228 228 {
229 229 bcopy(&shp->sh_ent, ep, sizeof (smbios_entry_t));
230 230 return (shp->sh_ent_type);
231 231 }
232 232
233 233 void
234 234 smbios_info_smbios_version(smbios_hdl_t *shp, smbios_version_t *v)
235 235 {
236 236 v->smbv_major = SMB_MAJOR(shp->sh_smbvers);
237 237 v->smbv_minor = SMB_MINOR(shp->sh_smbvers);
238 238 }
239 239
240 240 #ifndef _KERNEL
241 241 static char smbios_product_override[256];
242 242 static boolean_t smbios_product_checked;
243 243 #endif
244 244
245 245 int
246 246 smbios_info_common(smbios_hdl_t *shp, id_t id, smbios_info_t *ip)
247 247 {
248 248 const smb_struct_t *stp = smb_lookup_id(shp, id);
249 249 const struct smb_infospec *isp;
250 250 int n = 0;
251 251
252 252 if (stp == NULL)
253 253 return (-1); /* errno is set for us */
254 254
255 255 for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
256 256 if (isp->is_type == stp->smbst_hdr->smbh_type)
257 257 break;
258 258 }
259 259
260 260 ip->smbi_manufacturer = smb_info_strptr(stp, isp->is_manu, &n);
261 261 ip->smbi_product = smb_info_strptr(stp, isp->is_product, &n);
262 262 ip->smbi_version = smb_info_strptr(stp, isp->is_version, &n);
263 263 ip->smbi_serial = smb_info_strptr(stp, isp->is_serial, &n);
264 264 ip->smbi_asset = smb_info_strptr(stp, isp->is_asset, &n);
265 265 ip->smbi_location = smb_info_strptr(stp, isp->is_location, &n);
266 266 ip->smbi_part = smb_info_strptr(stp, isp->is_part, &n);
267 267
268 268 /*
269 269 * This private file allows developers to experiment with reporting
270 270 * different platform strings from SMBIOS. It is not a supported
271 271 * mechanism in the long term, and does not work in the kernel.
272 272 */
273 273 #ifndef _KERNEL
274 274 if (isp->is_type == SMB_TYPE_SYSTEM) {
275 275 if (!smbios_product_checked) {
276 276 int fd = open("/etc/smbios_product", O_RDONLY);
277 277 if (fd >= 0) {
278 278 (void) read(fd, smbios_product_override,
279 279 sizeof (smbios_product_override) - 1);
280 280 (void) close(fd);
281 281 }
282 282 smbios_product_checked = B_TRUE;
283 283 }
284 284
285 285 if (smbios_product_override[0] != '\0')
286 286 ip->smbi_product = smbios_product_override;
287 287 }
288 288 #endif
289 289
290 290 /*
291 291 * If we have a port with an empty internal reference designator string
292 292 * try using the external reference designator string instead.
293 293 */
294 294 if (isp->is_type == SMB_TYPE_PORT && ip->smbi_location[0] == '\0') {
295 295 ip->smbi_location = smb_info_strptr(stp,
296 296 offsetof(smb_port_t, smbpo_eref), &n);
297 297 }
298 298
299 299 return (n ? 0 : smb_set_errno(shp, ESMB_NOINFO));
300 300 }
301 301
302 302 /*
303 303 * Returns the actual number of contained objects.
304 304 *
305 305 * idc - number of contained objects
306 306 * idv - returned array of contained objects
307 307 */
308 308 int
309 309 smbios_info_contains(smbios_hdl_t *shp, id_t id, uint_t idc, id_t *idv)
310 310 {
311 311 const smb_struct_t *stp = smb_lookup_id(shp, id);
312 312 const struct smb_infospec *isp;
313 313 id_t *cp;
314 314 uint_t size;
315 315 uint8_t cnt;
316 316 int i, n;
317 317
318 318 if (stp == NULL) {
319 319 return (-1); /* errno is set for us */
320 320 }
321 321
322 322 for (isp = _smb_infospecs; isp->is_type != SMB_TYPE_EOT; isp++) {
323 323 if (isp->is_type == stp->smbst_hdr->smbh_type)
324 324 break;
325 325 }
326 326 if (isp->is_type == SMB_TYPE_EOT)
327 327 return (smb_set_errno(shp, ESMB_TYPE));
328 328
329 329 size = isp->is_contsz;
330 330 cnt = *((uint8_t *)(uintptr_t)stp->smbst_hdr + isp->is_contc);
331 331 cp = (id_t *)((uintptr_t)stp->smbst_hdr + isp->is_contv);
332 332
333 333 n = MIN(cnt, idc);
334 334 for (i = 0; i < n; i++) {
335 335 if (size == SMB_CONT_WORD)
336 336 idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 2));
337 337 else if (size == SMB_CONT_BYTE)
338 338 idv[i] = *((uint8_t *)(uintptr_t)cp + (i * 3));
339 339 else
340 340 return (smb_set_errno(shp, ESMB_INVAL));
341 341 }
342 342
343 343 return (cnt);
344 344 }
345 345
346 346 id_t
347 347 smbios_info_bios(smbios_hdl_t *shp, smbios_bios_t *bp)
348 348 {
349 349 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BIOS);
350 350 const smb_bios_t *bip;
351 351
352 352 if (stp == NULL)
353 353 return (-1); /* errno is set for us */
354 354
355 355 if (stp->smbst_hdr->smbh_len < sizeof (smb_bios_t) - sizeof (uint8_t))
356 356 return (smb_set_errno(shp, ESMB_CORRUPT));
357 357
358 358 bip = (smb_bios_t *)(uintptr_t)stp->smbst_hdr;
359 359 bzero(bp, sizeof (smb_base_bios_t));
360 360 if (smb_libgteq(shp, SMB_VERSION_31)) {
361 361 bp->smbb_extromsize = 0;
362 362 }
363 363
364 364 bp->smbb_vendor = smb_strptr(stp, bip->smbbi_vendor);
365 365 bp->smbb_version = smb_strptr(stp, bip->smbbi_version);
366 366 bp->smbb_segment = bip->smbbi_segment;
367 367 bp->smbb_reldate = smb_strptr(stp, bip->smbbi_reldate);
368 368 bp->smbb_romsize = 64 * 1024 * ((uint32_t)bip->smbbi_romsize + 1);
369 369 bp->smbb_runsize = 16 * (0x10000 - (uint32_t)bip->smbbi_segment);
370 370 bp->smbb_cflags = bip->smbbi_cflags;
371 371
372 372 /*
373 373 * If one or more extension bytes are present, reset smbb_xcflags to
374 374 * point to them. Otherwise leave this member set to NULL.
375 375 */
376 376 if (stp->smbst_hdr->smbh_len >= sizeof (smb_bios_t)) {
377 377 bp->smbb_xcflags = bip->smbbi_xcflags;
378 378 bp->smbb_nxcflags = stp->smbst_hdr->smbh_len -
379 379 sizeof (smb_bios_t) + 1;
380 380
381 381 if (bp->smbb_nxcflags > SMB_BIOSXB_ECFW_MIN &&
382 382 smb_gteq(shp, SMB_VERSION_24)) {
383 383 bp->smbb_biosv.smbv_major =
384 384 bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MAJ];
385 385 bp->smbb_biosv.smbv_minor =
386 386 bip->smbbi_xcflags[SMB_BIOSXB_BIOS_MIN];
387 387 bp->smbb_ecfwv.smbv_major =
388 388 bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MAJ];
389 389 bp->smbb_ecfwv.smbv_minor =
390 390 bip->smbbi_xcflags[SMB_BIOSXB_ECFW_MIN];
391 391 }
392 392
393 393 if (bp->smbb_nxcflags > SMB_BIOSXB_EXTROM + 1 &&
394 394 smb_gteq(shp, SMB_VERSION_31)) {
395 395 uint16_t val;
396 396 uint64_t rs;
397 397
398 398 /*
399 399 * Because of the fact that the extended size is a
400 400 * uint16_t and we'd need to define an explicit
401 401 * endian-aware way to access it, we don't include it in
402 402 * the number of extended flags below and thus subtract
403 403 * its size.
404 404 */
405 405 bp->smbb_nxcflags -= sizeof (uint16_t);
406 406 bcopy(&bip->smbbi_xcflags[SMB_BIOSXB_EXTROM], &val,
407 407 sizeof (val));
408 408 val = LE_16(val);
409 409
410 410 /*
411 411 * The upper two bits of the extended rom size are used
412 412 * to indicate whether the other 14 bits are in MB or
413 413 * GB.
414 414 */
415 415 rs = SMB_BIOS_EXTROM_VALUE_MASK(val);
416 416 switch (SMB_BIOS_EXTROM_SHIFT_MASK(val)) {
417 417 case 0:
418 418 rs *= 1024ULL * 1024ULL;
419 419 break;
420 420 case 1:
421 421 rs *= 1024ULL * 1024ULL * 1024ULL;
422 422 break;
423 423 default:
424 424 rs = 0;
425 425 break;
426 426 }
427 427
428 428 if (smb_libgteq(shp, SMB_VERSION_31)) {
429 429 bp->smbb_extromsize = rs;
430 430 }
431 431 }
432 432 }
433 433
434 434 if (smb_libgteq(shp, SMB_VERSION_31) && bp->smbb_extromsize == 0) {
435 435 bp->smbb_extromsize = bp->smbb_romsize;
436 436 }
437 437
438 438 return (stp->smbst_hdr->smbh_hdl);
439 439 }
440 440
441 441 id_t
442 442 smbios_info_system(smbios_hdl_t *shp, smbios_system_t *sip)
443 443 {
444 444 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM);
445 445 smb_system_t si;
446 446
447 447 if (stp == NULL)
448 448 return (-1); /* errno is set for us */
449 449
450 450 smb_info_bcopy(stp->smbst_hdr, &si, sizeof (si));
451 451 bzero(sip, sizeof (smbios_system_t));
452 452
453 453 sip->smbs_uuid = ((smb_system_t *)stp->smbst_hdr)->smbsi_uuid;
454 454 sip->smbs_uuidlen = sizeof (si.smbsi_uuid);
455 455 sip->smbs_wakeup = si.smbsi_wakeup;
456 456 sip->smbs_sku = smb_strptr(stp, si.smbsi_sku);
457 457 sip->smbs_family = smb_strptr(stp, si.smbsi_family);
458 458
459 459 return (stp->smbst_hdr->smbh_hdl);
460 460 }
461 461
462 462 int
463 463 smbios_info_bboard(smbios_hdl_t *shp, id_t id, smbios_bboard_t *bbp)
464 464 {
465 465 const smb_struct_t *stp = smb_lookup_id(shp, id);
466 466 smb_bboard_t bb;
467 467
468 468 if (stp == NULL)
469 469 return (-1); /* errno is set for us */
470 470
471 471 if (stp->smbst_hdr->smbh_type != SMB_TYPE_BASEBOARD)
472 472 return (smb_set_errno(shp, ESMB_TYPE));
473 473
474 474 smb_info_bcopy(stp->smbst_hdr, &bb, sizeof (bb));
475 475 bzero(bbp, sizeof (smbios_bboard_t));
476 476
477 477 bbp->smbb_chassis = bb.smbbb_chassis;
478 478 bbp->smbb_flags = bb.smbbb_flags;
479 479 bbp->smbb_type = bb.smbbb_type;
480 480 bbp->smbb_contn = bb.smbbb_cn;
481 481
482 482 return (0);
483 483 }
484 484
485 485 int
486 486 smbios_info_chassis(smbios_hdl_t *shp, id_t id, smbios_chassis_t *chp)
487 487 {
488 488 const smb_struct_t *stp = smb_lookup_id(shp, id);
489 489 /* Length is measurable by one byte, so it'll be no more than 255. */
490 490 uint8_t buf[256];
491 491 smb_chassis_t *ch = (smb_chassis_t *)&buf[0];
492 492
493 493 if (stp == NULL)
494 494 return (-1); /* errno is set for us */
495 495
496 496 if (stp->smbst_hdr->smbh_type != SMB_TYPE_CHASSIS)
497 497 return (smb_set_errno(shp, ESMB_TYPE));
498 498
499 499 smb_info_bcopy(stp->smbst_hdr, ch, sizeof (buf));
500 500 bzero(chp, sizeof (smb_base_chassis_t));
501 501 if (smb_libgteq(shp, SMB_VERSION_27)) {
502 502 bzero(chp->smbc_sku, sizeof (chp->smbc_sku));
503 503 }
504 504
505 505 chp->smbc_oemdata = ch->smbch_oemdata;
506 506 chp->smbc_lock = (ch->smbch_type & SMB_CHT_LOCK) != 0;
507 507 chp->smbc_type = ch->smbch_type & ~SMB_CHT_LOCK;
508 508 chp->smbc_bustate = ch->smbch_bustate;
509 509 chp->smbc_psstate = ch->smbch_psstate;
510 510 chp->smbc_thstate = ch->smbch_thstate;
511 511 chp->smbc_security = ch->smbch_security;
512 512 chp->smbc_uheight = ch->smbch_uheight;
513 513 chp->smbc_cords = ch->smbch_cords;
514 514 chp->smbc_elems = ch->smbch_cn;
515 515 chp->smbc_elemlen = ch->smbch_cm;
516 516
517 517 if (smb_libgteq(shp, SMB_VERSION_27)) {
518 518 (void) strlcpy(chp->smbc_sku, SMB_CH_SKU(ch),
519 519 sizeof (chp->smbc_sku));
520 520 }
521 521
522 522 return (0);
523 523 }
524 524
525 525 int
526 526 smbios_info_processor(smbios_hdl_t *shp, id_t id, smbios_processor_t *pp)
527 527 {
528 528 const smb_struct_t *stp = smb_lookup_id(shp, id);
529 529 smb_processor_t p;
530 530
531 531 if (stp == NULL)
532 532 return (-1); /* errno is set for us */
533 533
534 534 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PROCESSOR)
535 535 return (smb_set_errno(shp, ESMB_TYPE));
536 536
537 537 smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
538 538 bzero(pp, sizeof (smb_base_processor_t));
539 539
540 540 pp->smbp_cpuid = p.smbpr_cpuid;
541 541 pp->smbp_type = p.smbpr_type;
542 542 pp->smbp_family = p.smbpr_family;
543 543 pp->smbp_voltage = p.smbpr_voltage;
544 544 pp->smbp_maxspeed = p.smbpr_maxspeed;
545 545 pp->smbp_curspeed = p.smbpr_curspeed;
546 546 pp->smbp_status = p.smbpr_status;
547 547 pp->smbp_upgrade = p.smbpr_upgrade;
548 548 pp->smbp_l1cache = p.smbpr_l1cache;
549 549 pp->smbp_l2cache = p.smbpr_l2cache;
550 550 pp->smbp_l3cache = p.smbpr_l3cache;
551 551
552 552 if (smb_libgteq(shp, SMB_VERSION_25)) {
553 553 pp->smbp_corecount = p.smbpr_corecount;
554 554 pp->smbp_coresenabled = p.smbpr_coresenabled;
555 555 pp->smbp_threadcount = p.smbpr_threadcount;
556 556 pp->smbp_cflags = p.smbpr_cflags;
557 557 }
558 558
559 559 if (smb_libgteq(shp, SMB_VERSION_26)) {
560 560 pp->smbp_family2 = p.smbpr_family2;
561 561 }
562 562
563 563 if (smb_libgteq(shp, SMB_VERSION_30)) {
564 564 pp->smbp_corecount2 = p.smbpr_corecount2;
565 565 pp->smbp_coresenabled2 = p.smbpr_coresenabled2;
566 566 pp->smbp_threadcount2 = p.smbpr_threadcount2;
567 567 }
568 568
569 569 return (0);
570 570 }
571 571
572 572 int
573 573 smbios_info_cache(smbios_hdl_t *shp, id_t id, smbios_cache_t *cap)
574 574 {
575 575 const smb_struct_t *stp = smb_lookup_id(shp, id);
576 576 smb_cache_t c;
577 577
578 578 if (stp == NULL)
579 579 return (-1); /* errno is set for us */
580 580
581 581 if (stp->smbst_hdr->smbh_type != SMB_TYPE_CACHE)
582 582 return (smb_set_errno(shp, ESMB_TYPE));
583 583
584 584 smb_info_bcopy(stp->smbst_hdr, &c, sizeof (c));
585 585 bzero(cap, sizeof (smb_base_cache_t));
586 586
587 587 cap->smba_maxsize = SMB_CACHE_SIZE(c.smbca_maxsize);
588 588 cap->smba_size = SMB_CACHE_SIZE(c.smbca_size);
589 589 cap->smba_stype = c.smbca_stype;
590 590 cap->smba_ctype = c.smbca_ctype;
591 591 cap->smba_speed = c.smbca_speed;
592 592 cap->smba_etype = c.smbca_etype;
593 593 cap->smba_ltype = c.smbca_ltype;
594 594 cap->smba_assoc = c.smbca_assoc;
595 595 cap->smba_level = SMB_CACHE_CFG_LEVEL(c.smbca_config);
596 596 cap->smba_mode = SMB_CACHE_CFG_MODE(c.smbca_config);
597 597 cap->smba_location = SMB_CACHE_CFG_LOCATION(c.smbca_config);
598 598
599 599 if (SMB_CACHE_CFG_ENABLED(c.smbca_config))
600 600 cap->smba_flags |= SMB_CAF_ENABLED;
601 601
602 602 if (SMB_CACHE_CFG_SOCKETED(c.smbca_config))
603 603 cap->smba_flags |= SMB_CAF_SOCKETED;
604 604
605 605 if (smb_libgteq(shp, SMB_VERSION_31)) {
606 606 if (smb_gteq(shp, SMB_VERSION_31)) {
607 607 cap->smba_maxsize2 =
608 608 SMB_CACHE_EXT_SIZE(c.smbca_maxsize2);
609 609 cap->smba_size2 = SMB_CACHE_EXT_SIZE(c.smbca_size2);
610 610 } else {
611 611 cap->smba_maxsize2 = cap->smba_maxsize;
612 612 cap->smba_size2 = cap->smba_size;
613 613 }
614 614 }
615 615
616 616 return (0);
617 617 }
618 618
619 619 int
620 620 smbios_info_port(smbios_hdl_t *shp, id_t id, smbios_port_t *pop)
621 621 {
622 622 const smb_struct_t *stp = smb_lookup_id(shp, id);
623 623 smb_port_t p;
624 624
625 625 if (stp == NULL)
626 626 return (-1); /* errno is set for us */
627 627
628 628 if (stp->smbst_hdr->smbh_type != SMB_TYPE_PORT)
629 629 return (smb_set_errno(shp, ESMB_TYPE));
630 630
631 631 smb_info_bcopy(stp->smbst_hdr, &p, sizeof (p));
632 632 bzero(pop, sizeof (smbios_port_t));
633 633
634 634 pop->smbo_iref = smb_strptr(stp, p.smbpo_iref);
635 635 pop->smbo_eref = smb_strptr(stp, p.smbpo_eref);
636 636
637 637 pop->smbo_itype = p.smbpo_itype;
638 638 pop->smbo_etype = p.smbpo_etype;
639 639 pop->smbo_ptype = p.smbpo_ptype;
640 640
641 641 return (0);
642 642 }
643 643
644 644 int
645 645 smbios_info_slot(smbios_hdl_t *shp, id_t id, smbios_slot_t *sp)
646 646 {
647 647 const smb_struct_t *stp = smb_lookup_id(shp, id);
648 648 smb_slot_t s;
649 649
650 650 if (stp == NULL)
651 651 return (-1); /* errno is set for us */
652 652
653 653 if (stp->smbst_hdr->smbh_type != SMB_TYPE_SLOT)
654 654 return (smb_set_errno(shp, ESMB_TYPE));
655 655
656 656 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
657 657 bzero(sp, sizeof (smbios_slot_t));
658 658
659 659 sp->smbl_name = smb_strptr(stp, s.smbsl_name);
660 660 sp->smbl_type = s.smbsl_type;
661 661 sp->smbl_width = s.smbsl_width;
662 662 sp->smbl_usage = s.smbsl_usage;
663 663 sp->smbl_length = s.smbsl_length;
664 664 sp->smbl_id = s.smbsl_id;
665 665 sp->smbl_ch1 = s.smbsl_ch1;
666 666 sp->smbl_ch2 = s.smbsl_ch2;
667 667 sp->smbl_sg = s.smbsl_sg;
668 668 sp->smbl_bus = s.smbsl_bus;
669 669 sp->smbl_df = s.smbsl_df;
670 670
671 671 return (0);
672 672 }
673 673
674 674 int
675 675 smbios_info_obdevs_ext(smbios_hdl_t *shp, id_t id, smbios_obdev_ext_t *oep)
676 676 {
677 677 const smb_struct_t *stp = smb_lookup_id(shp, id);
678 678 smb_obdev_ext_t obe;
679 679
680 680 if (stp == NULL)
681 681 return (-1); /* errno is set for us */
682 682
683 683 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVEXT)
684 684 return (smb_set_errno(shp, ESMB_TYPE));
685 685
686 686 smb_info_bcopy(stp->smbst_hdr, &obe, sizeof (obe));
687 687 bzero(oep, sizeof (smbios_obdev_ext_t));
688 688
689 689 oep->smboe_name = smb_strptr(stp, obe.smbobe_name);
690 690 oep->smboe_dtype = obe.smbobe_dtype;
691 691 oep->smboe_dti = obe.smbobe_dti;
692 692 oep->smboe_sg = obe.smbobe_sg;
693 693 oep->smboe_bus = obe.smbobe_bus;
694 694 oep->smboe_df = obe.smbobe_df;
695 695
696 696 return (0);
697 697 }
698 698
699 699 int
700 700 smbios_info_obdevs(smbios_hdl_t *shp, id_t id, int obc, smbios_obdev_t *obp)
701 701 {
702 702 const smb_struct_t *stp = smb_lookup_id(shp, id);
703 703 const smb_obdev_t *op;
704 704 int i, m, n;
705 705
706 706 if (stp == NULL)
707 707 return (-1); /* errno is set for us */
708 708
709 709 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OBDEVS)
710 710 return (smb_set_errno(shp, ESMB_TYPE));
711 711
712 712 op = (smb_obdev_t *)((uintptr_t)stp->smbst_hdr + sizeof (smb_header_t));
713 713 m = (stp->smbst_hdr->smbh_len - sizeof (smb_header_t)) / sizeof (*op);
714 714 n = MIN(m, obc);
715 715
716 716 for (i = 0; i < n; i++, op++, obp++) {
717 717 obp->smbd_name = smb_strptr(stp, op->smbob_name);
718 718 obp->smbd_type = op->smbob_type & ~SMB_OBT_ENABLED;
719 719 obp->smbd_enabled = (op->smbob_type & SMB_OBT_ENABLED) != 0;
720 720 }
721 721
722 722 return (m);
723 723 }
724 724
725 725 /*
726 726 * The implementation structures for OEMSTR, SYSCONFSTR, and LANG all use the
727 727 * first byte to indicate the size of a string table at the end of the record.
728 728 * Therefore, smbios_info_strtab() can be used to retrieve the table size and
729 729 * strings for any of these underlying record types.
730 730 */
731 731 int
732 732 smbios_info_strtab(smbios_hdl_t *shp, id_t id, int argc, const char *argv[])
733 733 {
734 734 const smb_struct_t *stp = smb_lookup_id(shp, id);
735 735 smb_strtab_t s;
736 736 int i, n;
737 737
738 738 if (stp == NULL)
739 739 return (-1); /* errno is set for us */
740 740
741 741 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR &&
742 742 stp->smbst_hdr->smbh_type != SMB_TYPE_SYSCONFSTR &&
743 743 stp->smbst_hdr->smbh_type != SMB_TYPE_LANG)
744 744 return (smb_set_errno(shp, ESMB_TYPE));
745 745
746 746 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
747 747 n = MIN(s.smbtb_count, argc);
748 748
749 749 for (i = 0; i < n; i++)
750 750 argv[i] = smb_strptr(stp, i + 1);
751 751
752 752 return (s.smbtb_count);
753 753 }
754 754
755 755 id_t
756 756 smbios_info_lang(smbios_hdl_t *shp, smbios_lang_t *lp)
757 757 {
758 758 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_LANG);
759 759 smb_lang_t l;
760 760
761 761 if (stp == NULL)
762 762 return (-1); /* errno is set for us */
763 763
764 764 smb_info_bcopy(stp->smbst_hdr, &l, sizeof (l));
765 765 bzero(lp, sizeof (smbios_lang_t));
766 766
767 767 lp->smbla_cur = smb_strptr(stp, l.smblang_cur);
768 768 lp->smbla_fmt = l.smblang_flags & 1;
769 769 lp->smbla_num = l.smblang_num;
770 770
771 771 return (stp->smbst_hdr->smbh_hdl);
772 772 }
773 773
774 774 id_t
775 775 smbios_info_eventlog(smbios_hdl_t *shp, smbios_evlog_t *evp)
776 776 {
777 777 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_EVENTLOG);
778 778 const smb_sel_t *sel;
779 779 size_t len;
780 780
781 781 if (stp == NULL)
782 782 return (-1); /* errno is set for us */
783 783
784 784 if (stp->smbst_hdr->smbh_len < sizeof (smb_sel_t) - sizeof (uint8_t))
785 785 return (smb_set_errno(shp, ESMB_CORRUPT));
786 786
787 787 sel = (smb_sel_t *)(uintptr_t)stp->smbst_hdr;
788 788 len = stp->smbst_hdr->smbh_len - sizeof (smb_sel_t) + sizeof (uint8_t);
789 789 bzero(evp, sizeof (smbios_evlog_t));
790 790
791 791 if (len < sel->smbsel_typec * sel->smbsel_typesz)
792 792 return (smb_set_errno(shp, ESMB_CORRUPT));
793 793
794 794 evp->smbev_size = sel->smbsel_len;
795 795 evp->smbev_hdr = sel->smbsel_hdroff;
796 796 evp->smbev_data = sel->smbsel_dataoff;
797 797 evp->smbev_method = sel->smbsel_method;
798 798 evp->smbev_flags = sel->smbsel_status;
799 799 evp->smbev_format = sel->smbsel_format;
800 800 evp->smbev_token = sel->smbsel_token;
801 801 evp->smbev_addr.eva_addr = sel->smbsel_addr;
802 802
803 803 if (sel->smbsel_typesz == sizeof (smbios_evtype_t)) {
804 804 evp->smbev_typec = sel->smbsel_typec;
805 805 evp->smbev_typev = (void *)(uintptr_t)sel->smbsel_typev;
806 806 }
807 807
808 808 return (stp->smbst_hdr->smbh_hdl);
809 809 }
810 810
811 811 int
812 812 smbios_info_memarray(smbios_hdl_t *shp, id_t id, smbios_memarray_t *map)
813 813 {
814 814 const smb_struct_t *stp = smb_lookup_id(shp, id);
815 815 smb_memarray_t m;
816 816
817 817 if (stp == NULL)
818 818 return (-1); /* errno is set for us */
819 819
820 820 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAY)
821 821 return (smb_set_errno(shp, ESMB_TYPE));
822 822
823 823 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
824 824 bzero(map, sizeof (smbios_memarray_t));
825 825
826 826 map->smbma_location = m.smbmarr_loc;
827 827 map->smbma_use = m.smbmarr_use;
828 828 map->smbma_ecc = m.smbmarr_ecc;
829 829 map->smbma_ndevs = m.smbmarr_ndevs;
830 830 map->smbma_err = m.smbmarr_err;
831 831
832 832 if (m.smbmarr_cap != 0x80000000)
833 833 map->smbma_size = (uint64_t)m.smbmarr_cap * 1024;
834 834 else if (m.smbmarr_extcap != 0)
835 835 map->smbma_size = m.smbmarr_extcap;
836 836 else
837 837 map->smbma_size = 0; /* unknown */
838 838
839 839 return (0);
840 840 }
841 841
842 842 int
843 843 smbios_info_memarrmap(smbios_hdl_t *shp, id_t id, smbios_memarrmap_t *map)
844 844 {
845 845 const smb_struct_t *stp = smb_lookup_id(shp, id);
846 846 smb_memarrmap_t m;
847 847
848 848 if (stp == NULL)
849 849 return (-1); /* errno is set for us */
850 850
851 851 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMARRAYMAP)
852 852 return (smb_set_errno(shp, ESMB_TYPE));
853 853
854 854 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
855 855 bzero(map, sizeof (smbios_memarrmap_t));
856 856
857 857 map->smbmam_array = m.smbamap_array;
858 858 map->smbmam_width = m.smbamap_width;
859 859
860 860 if (m.smbamap_start != 0xFFFFFFFF && m.smbamap_end != 0xFFFFFFFF) {
861 861 map->smbmam_addr = (uint64_t)m.smbamap_start * 1024;
862 862 map->smbmam_size = (uint64_t)
863 863 (m.smbamap_end - m.smbamap_start + 1) * 1024;
864 864 } else if (m.smbamap_extstart != 0 && m.smbamap_extend != 0) {
865 865 map->smbmam_addr = m.smbamap_extstart;
866 866 map->smbmam_size = m.smbamap_extend - m.smbamap_extstart + 1;
867 867 }
868 868
869 869 return (0);
870 870 }
871 871
872 872 int
873 873 smbios_info_memdevice(smbios_hdl_t *shp, id_t id, smbios_memdevice_t *mdp)
874 874 {
875 875 const smb_struct_t *stp = smb_lookup_id(shp, id);
876 876 smb_memdevice_t m;
877 877
878 878 if (stp == NULL)
879 879 return (-1); /* errno is set for us */
880 880
881 881 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICE)
882 882 return (smb_set_errno(shp, ESMB_TYPE));
883 883
884 884 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
885 885 bzero(mdp, sizeof (smb_base_memdevice_t));
886 886
887 887 mdp->smbmd_array = m.smbmdev_array;
888 888 mdp->smbmd_error = m.smbmdev_error;
889 889 mdp->smbmd_twidth = m.smbmdev_twidth == 0xFFFF ? -1U : m.smbmdev_twidth;
890 890 mdp->smbmd_dwidth = m.smbmdev_dwidth == 0xFFFF ? -1U : m.smbmdev_dwidth;
891 891
892 892 if (m.smbmdev_size == 0x7FFF) {
893 893 mdp->smbmd_size = (uint64_t)m.smbmdev_extsize;
894 894 mdp->smbmd_size *= 1024 * 1024; /* convert MB to bytes */
895 895 } else if (m.smbmdev_size != 0xFFFF) {
896 896 mdp->smbmd_size = (uint64_t)(m.smbmdev_size & ~SMB_MDS_KBYTES);
897 897 if (m.smbmdev_size & SMB_MDS_KBYTES)
898 898 mdp->smbmd_size *= 1024;
899 899 else
900 900 mdp->smbmd_size *= 1024 * 1024;
901 901 } else
902 902 mdp->smbmd_size = -1ULL; /* size unknown */
903 903
904 904 mdp->smbmd_form = m.smbmdev_form;
905 905 mdp->smbmd_set = m.smbmdev_set;
906 906 mdp->smbmd_type = m.smbmdev_type;
907 907 mdp->smbmd_speed = m.smbmdev_speed;
908 908 mdp->smbmd_flags = m.smbmdev_flags;
909 909 mdp->smbmd_dloc = smb_strptr(stp, m.smbmdev_dloc);
910 910 mdp->smbmd_bloc = smb_strptr(stp, m.smbmdev_bloc);
911 911
912 912 if (smb_libgteq(shp, SMB_VERSION_26)) {
913 913 mdp->smbmd_rank = m.smbmdev_attrs & 0x0F;
914 914 }
915 915
916 916 if (smb_libgteq(shp, SMB_VERSION_27)) {
917 917 mdp->smbmd_clkspeed = m.smbmdev_clkspeed;
918 918 }
919 919
920 920 if (smb_libgteq(shp, SMB_VERSION_28)) {
921 921 mdp->smbmd_minvolt = m.smbmdev_minvolt;
922 922 mdp->smbmd_maxvolt = m.smbmdev_maxvolt;
923 923 mdp->smbmd_confvolt = m.smbmdev_confvolt;
924 924 }
925 925
926 926 return (0);
927 927 }
928 928
929 929 int
930 930 smbios_info_memdevmap(smbios_hdl_t *shp, id_t id, smbios_memdevmap_t *mdp)
931 931 {
932 932 const smb_struct_t *stp = smb_lookup_id(shp, id);
933 933 smb_memdevmap_t m;
934 934
935 935 if (stp == NULL)
936 936 return (-1); /* errno is set for us */
937 937
938 938 if (stp->smbst_hdr->smbh_type != SMB_TYPE_MEMDEVICEMAP)
939 939 return (smb_set_errno(shp, ESMB_TYPE));
940 940
941 941 smb_info_bcopy(stp->smbst_hdr, &m, sizeof (m));
942 942 bzero(mdp, sizeof (smbios_memdevmap_t));
943 943
944 944 mdp->smbmdm_device = m.smbdmap_device;
945 945 mdp->smbmdm_arrmap = m.smbdmap_array;
946 946 mdp->smbmdm_rpos = m.smbdmap_rpos;
947 947 mdp->smbmdm_ipos = m.smbdmap_ipos;
948 948 mdp->smbmdm_idepth = m.smbdmap_idepth;
949 949
950 950 if (m.smbdmap_start != 0xFFFFFFFF && m.smbdmap_end != 0xFFFFFFFF) {
951 951 mdp->smbmdm_addr = (uint64_t)m.smbdmap_start * 1024;
952 952 mdp->smbmdm_size = (uint64_t)
953 953 (m.smbdmap_end - m.smbdmap_start + 1) * 1024;
954 954 } else if (m.smbdmap_extstart != 0 && m.smbdmap_extend != 0) {
955 955 mdp->smbmdm_addr = m.smbdmap_extstart;
956 956 mdp->smbmdm_size = m.smbdmap_extend - m.smbdmap_extstart + 1;
957 957 }
958 958
959 959 return (0);
960 960 }
961 961
962 962 id_t
963 963 smbios_info_hwsec(smbios_hdl_t *shp, smbios_hwsec_t *hsp)
964 964 {
965 965 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_SECURITY);
966 966 smb_hwsec_t hs;
967 967
968 968 if (stp == NULL)
969 969 return (-1); /* errno is set for us */
970 970
971 971 smb_info_bcopy(stp->smbst_hdr, &hs, sizeof (hs));
972 972 bzero(hsp, sizeof (smbios_hwsec_t));
973 973
974 974 hsp->smbh_pwr_ps = SMB_HWS_PWR_PS(hs.smbhs_settings);
975 975 hsp->smbh_kbd_ps = SMB_HWS_KBD_PS(hs.smbhs_settings);
↓ open down ↓ |
941 lines elided |
↑ open up ↑ |
976 976 hsp->smbh_adm_ps = SMB_HWS_ADM_PS(hs.smbhs_settings);
977 977 hsp->smbh_pan_ps = SMB_HWS_PAN_PS(hs.smbhs_settings);
978 978
979 979 return (stp->smbst_hdr->smbh_hdl);
980 980 }
981 981
982 982 id_t
983 983 smbios_info_boot(smbios_hdl_t *shp, smbios_boot_t *bp)
984 984 {
985 985 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_BOOT);
986 - const smb_boot_t *b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
986 + const smb_boot_t *b;
987 987
988 988 if (stp == NULL)
989 989 return (-1); /* errno is set for us */
990 990
991 991 bzero(bp, sizeof (smbios_boot_t));
992 992
993 + b = (smb_boot_t *)(uintptr_t)stp->smbst_hdr;
994 +
993 995 bp->smbt_status = b->smbbo_status[0];
994 996 bp->smbt_size = stp->smbst_hdr->smbh_len - sizeof (smb_boot_t);
995 997 bp->smbt_data = bp->smbt_size ? &b->smbbo_status[1] : NULL;
996 998
997 999 return (stp->smbst_hdr->smbh_hdl);
998 1000 }
999 1001
1000 1002 id_t
1001 1003 smbios_info_ipmi(smbios_hdl_t *shp, smbios_ipmi_t *ip)
1002 1004 {
1003 1005 const smb_struct_t *stp = smb_lookup_type(shp, SMB_TYPE_IPMIDEV);
1004 1006 smb_ipmi_t i;
1005 1007
1006 1008 if (stp == NULL)
1007 1009 return (-1); /* errno is set for us */
1008 1010
1009 1011 smb_info_bcopy(stp->smbst_hdr, &i, sizeof (i));
1010 1012 bzero(ip, sizeof (smbios_ipmi_t));
1011 1013
1012 1014 ip->smbip_type = i.smbipm_type;
1013 1015 ip->smbip_vers.smbv_major = SMB_IPM_SPEC_MAJOR(i.smbipm_spec);
1014 1016 ip->smbip_vers.smbv_minor = SMB_IPM_SPEC_MINOR(i.smbipm_spec);
1015 1017 ip->smbip_i2c = i.smbipm_i2c;
1016 1018 ip->smbip_addr = i.smbipm_addr & ~SMB_IPM_ADDR_IO;
1017 1019 ip->smbip_intr = i.smbipm_intr;
1018 1020
1019 1021 if (i.smbipm_bus != (uint8_t)-1)
1020 1022 ip->smbip_bus = i.smbipm_bus;
1021 1023 else
1022 1024 ip->smbip_bus = -1u;
1023 1025
1024 1026 if (SMB_IPM_INFO_LSB(i.smbipm_info))
1025 1027 ip->smbip_addr |= 1; /* turn on least-significant bit of addr */
1026 1028
1027 1029 if (i.smbipm_addr & SMB_IPM_ADDR_IO) {
1028 1030 switch (SMB_IPM_INFO_REGS(i.smbipm_info)) {
1029 1031 case SMB_IPM_REGS_1B:
1030 1032 ip->smbip_regspacing = 1;
1031 1033 break;
1032 1034 case SMB_IPM_REGS_4B:
1033 1035 ip->smbip_regspacing = 4;
1034 1036 break;
1035 1037 case SMB_IPM_REGS_16B:
1036 1038 ip->smbip_regspacing = 16;
1037 1039 break;
1038 1040 default:
1039 1041 ip->smbip_regspacing = 1;
1040 1042 }
1041 1043 ip->smbip_flags |= SMB_IPMI_F_IOADDR;
1042 1044 }
1043 1045
1044 1046 if (SMB_IPM_INFO_ISPEC(i.smbipm_info))
1045 1047 ip->smbip_flags |= SMB_IPMI_F_INTRSPEC;
1046 1048
1047 1049 if (SMB_IPM_INFO_IPOL(i.smbipm_info) == SMB_IPM_IPOL_HI)
1048 1050 ip->smbip_flags |= SMB_IPMI_F_INTRHIGH;
1049 1051
1050 1052 if (SMB_IPM_INFO_IMODE(i.smbipm_info) == SMB_IPM_IMODE_EDGE)
1051 1053 ip->smbip_flags |= SMB_IPMI_F_INTREDGE;
1052 1054
1053 1055 return (stp->smbst_hdr->smbh_hdl);
1054 1056 }
1055 1057
1056 1058 static boolean_t
1057 1059 smbios_has_oemstr(smbios_hdl_t *shp, const char *oemstr)
1058 1060 {
1059 1061 const smb_struct_t *stp = shp->sh_structs;
1060 1062 smb_strtab_t s;
1061 1063 int i, j;
1062 1064
1063 1065 for (i = 0; i < shp->sh_nstructs; i++, stp++) {
1064 1066 if (stp->smbst_hdr->smbh_type != SMB_TYPE_OEMSTR)
1065 1067 continue;
1066 1068
1067 1069 smb_info_bcopy(stp->smbst_hdr, &s, sizeof (s));
1068 1070 for (j = 0; j < s.smbtb_count; j++)
1069 1071 if (strcmp(smb_strptr(stp, j + 1), oemstr) == 0)
1070 1072 return (B_TRUE);
1071 1073 }
1072 1074
1073 1075 return (B_FALSE);
1074 1076 }
1075 1077
1076 1078 static const char *
1077 1079 smb_serial_valid(const char *serial)
1078 1080 {
1079 1081 char buf[MAXNAMELEN];
1080 1082 int i = 0;
1081 1083
1082 1084 if (serial == NULL)
1083 1085 return (NULL);
1084 1086
1085 1087 (void) strlcpy(buf, serial, sizeof (buf));
1086 1088
1087 1089 while (buf[i] != '\0' && buf[i] == ' ')
1088 1090 i++;
1089 1091
1090 1092 if (buf[i] == '\0' || strstr(buf, SMB_DEFAULT1) != NULL ||
1091 1093 strstr(buf, SMB_DEFAULT2) != NULL)
1092 1094 return (NULL);
1093 1095
1094 1096 return (serial);
1095 1097 }
1096 1098
1097 1099 /*
1098 1100 * Get chassis SN or product SN
1099 1101 */
1100 1102 static int
1101 1103 smb_get_sn(smbios_hdl_t *shp, const char **psnp, const char **csnp)
1102 1104 {
1103 1105 const smb_struct_t *stp;
1104 1106 smbios_info_t s1, s3;
1105 1107
1106 1108 if (psnp == NULL || csnp == NULL)
1107 1109 return (smb_set_errno(shp, ESMB_INVAL));
1108 1110
1109 1111 *psnp = *csnp = NULL;
1110 1112
1111 1113 /*
1112 1114 * If SMBIOS meets Sun's PRMS requirements, retrieve product SN
1113 1115 * from type 1 structure, and chassis SN from type 3 structure.
1114 1116 * Otherwise return SN in type 1 structure as chassis SN.
1115 1117 */
1116 1118
1117 1119 /* Get type 1 SN */
1118 1120 if ((stp = smb_lookup_type(shp, SMB_TYPE_SYSTEM)) == NULL ||
1119 1121 smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s1) == SMB_ERR)
1120 1122 s1.smbi_serial = NULL;
1121 1123
1122 1124 /* Get type 3 SN */
1123 1125 if ((stp = smb_lookup_type(shp, SMB_TYPE_CHASSIS)) == NULL ||
1124 1126 smbios_info_common(shp, stp->smbst_hdr->smbh_hdl, &s3) == SMB_ERR)
1125 1127 s3.smbi_serial = NULL;
1126 1128
1127 1129 if (smbios_has_oemstr(shp, SMB_PRMS1)) {
1128 1130 *psnp = smb_serial_valid(s1.smbi_serial);
1129 1131 *csnp = smb_serial_valid(s3.smbi_serial);
1130 1132 } else {
1131 1133 *csnp = smb_serial_valid(s1.smbi_serial);
1132 1134 }
1133 1135
1134 1136 return (0);
1135 1137 }
1136 1138
1137 1139 const char *
1138 1140 smbios_psn(smbios_hdl_t *shp)
1139 1141 {
1140 1142 const char *psn, *csn;
1141 1143
1142 1144 return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : psn);
1143 1145 }
1144 1146
1145 1147 const char *
1146 1148 smbios_csn(smbios_hdl_t *shp)
1147 1149 {
1148 1150 const char *psn, *csn;
1149 1151
1150 1152 return (smb_get_sn(shp, &psn, &csn) == SMB_ERR ? NULL : csn);
1151 1153 }
1152 1154
1153 1155 int
1154 1156 smbios_info_extprocessor(smbios_hdl_t *shp, id_t id,
1155 1157 smbios_processor_ext_t *epp)
1156 1158 {
1157 1159 const smb_struct_t *stp = smb_lookup_id(shp, id);
1158 1160 smb_processor_ext_t *exp;
1159 1161
1160 1162 if (stp == NULL)
1161 1163 return (-1); /* errno is set for us */
1162 1164
1163 1165 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PROCESSOR)
1164 1166 return (smb_set_errno(shp, ESMB_TYPE));
1165 1167
1166 1168 exp = (smb_processor_ext_t *)(uintptr_t)stp->smbst_hdr;
1167 1169 bzero(epp, sizeof (smbios_processor_ext_t));
1168 1170
1169 1171 epp->smbpe_processor = exp->smbpre_processor;
1170 1172 epp->smbpe_fru = exp->smbpre_fru;
1171 1173 epp->smbpe_n = exp->smbpre_n;
1172 1174 epp->smbpe_apicid = exp->smbpre_apicid;
1173 1175
1174 1176 return (0);
1175 1177 }
1176 1178
1177 1179 int
1178 1180 smbios_info_extport(smbios_hdl_t *shp, id_t id, smbios_port_ext_t *eportp)
1179 1181 {
1180 1182 const smb_struct_t *stp = smb_lookup_id(shp, id);
1181 1183 smb_port_ext_t *ep;
1182 1184
1183 1185 if (stp == NULL)
1184 1186 return (-1); /* errno is set for us */
1185 1187
1186 1188 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_PORT)
1187 1189 return (smb_set_errno(shp, ESMB_TYPE));
1188 1190
1189 1191 ep = (smb_port_ext_t *)(uintptr_t)stp->smbst_hdr;
1190 1192 bzero(eportp, sizeof (smbios_port_ext_t));
1191 1193
1192 1194 eportp->smbporte_chassis = ep->smbpoe_chassis;
1193 1195 eportp->smbporte_port = ep->smbpoe_port;
1194 1196 eportp->smbporte_dtype = ep->smbpoe_dtype;
1195 1197 eportp->smbporte_devhdl = ep->smbpoe_devhdl;
1196 1198 eportp->smbporte_phy = ep->smbpoe_phy;
1197 1199
1198 1200 return (0);
1199 1201 }
1200 1202
1201 1203 int
1202 1204 smbios_info_pciexrc(smbios_hdl_t *shp, id_t id,
1203 1205 smbios_pciexrc_t *rcp)
1204 1206 {
1205 1207 const smb_struct_t *stp = smb_lookup_id(shp, id);
1206 1208 smb_pciexrc_t rc;
1207 1209
1208 1210 if (stp == NULL)
1209 1211 return (-1); /* errno is set for us */
1210 1212
1211 1213 if (stp->smbst_hdr->smbh_type != SUN_OEM_PCIEXRC)
1212 1214 return (smb_set_errno(shp, ESMB_TYPE));
1213 1215
1214 1216 smb_info_bcopy(stp->smbst_hdr, &rc, sizeof (rc));
1215 1217 bzero(rcp, sizeof (smbios_pciexrc_t));
1216 1218
1217 1219 rcp->smbpcie_bb = rc.smbpciexrc_bboard;
1218 1220 rcp->smbpcie_bdf = rc.smbpciexrc_bdf;
1219 1221
1220 1222 return (0);
1221 1223 }
1222 1224
1223 1225 int
1224 1226 smbios_info_extmemarray(smbios_hdl_t *shp, id_t id, smbios_memarray_ext_t *emap)
1225 1227 {
1226 1228 const smb_struct_t *stp = smb_lookup_id(shp, id);
1227 1229 smb_memarray_ext_t exma;
1228 1230
1229 1231 if (stp == NULL)
1230 1232 return (-1); /* errno is set for us */
1231 1233
1232 1234 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMARRAY)
1233 1235 return (smb_set_errno(shp, ESMB_TYPE));
1234 1236
1235 1237 smb_info_bcopy(stp->smbst_hdr, &exma, sizeof (exma));
1236 1238 bzero(emap, sizeof (smbios_memarray_ext_t));
1237 1239
1238 1240 emap->smbmae_ma = exma.smbmarre_ma;
1239 1241 emap->smbmae_comp = exma.smbmarre_component;
1240 1242 emap->smbmae_bdf = exma.smbmarre_bdf;
1241 1243
1242 1244 return (0);
1243 1245 }
1244 1246
1245 1247 int
1246 1248 smbios_info_extmemdevice(smbios_hdl_t *shp, id_t id,
1247 1249 smbios_memdevice_ext_t *emdp)
1248 1250 {
1249 1251 const smb_struct_t *stp = smb_lookup_id(shp, id);
1250 1252 smb_memdevice_ext_t exmd;
1251 1253
1252 1254 if (stp == NULL)
1253 1255 return (-1); /* errno is set for us */
1254 1256
1255 1257 if (stp->smbst_hdr->smbh_type != SUN_OEM_EXT_MEMDEVICE)
1256 1258 return (smb_set_errno(shp, ESMB_TYPE));
1257 1259
1258 1260 smb_info_bcopy(stp->smbst_hdr, &exmd, sizeof (exmd));
1259 1261 bzero(emdp, sizeof (smbios_memdevice_ext_t));
1260 1262
1261 1263 emdp->smbmdeve_md = exmd.smbmdeve_mdev;
1262 1264 emdp->smbmdeve_drch = exmd.smbmdeve_dchan;
1263 1265 emdp->smbmdeve_ncs = exmd.smbmdeve_ncs;
1264 1266 emdp->smbmdeve_cs = exmd.smbmdeve_cs;
1265 1267
1266 1268 return (0);
1267 1269 }
1268 1270
1269 1271 int
1270 1272 smbios_info_powersup(smbios_hdl_t *shp, id_t id, smbios_powersup_t *psup)
1271 1273 {
1272 1274 const smb_struct_t *stp = smb_lookup_id(shp, id);
1273 1275 smb_powersup_t psu;
1274 1276
1275 1277 if (stp == NULL)
1276 1278 return (-1); /* errno is set for us */
1277 1279
1278 1280 if (stp->smbst_hdr->smbh_type != SMB_TYPE_POWERSUP)
1279 1281 return (smb_set_errno(shp, ESMB_TYPE));
1280 1282
1281 1283 /* The minimum length required by the spec is 0x10. */
1282 1284 if (stp->smbst_hdr->smbh_len < 0x10)
1283 1285 return (smb_set_errno(shp, ESMB_SHORT));
1284 1286
1285 1287 bzero(psup, sizeof (*psup));
1286 1288 smb_info_bcopy(stp->smbst_hdr, &psu, sizeof (psu));
1287 1289 psup->smbps_group = psu.smbpsup_group;
1288 1290 psup->smbps_maxout = psu.smbpsup_max;
1289 1291
1290 1292 if (SMB_PSU_CHARS_ISHOT(psu.smbpsup_char))
1291 1293 psup->smbps_flags |= SMB_POWERSUP_F_HOT;
1292 1294 if (SMB_PSU_CHARS_ISPRES(psu.smbpsup_char))
1293 1295 psup->smbps_flags |= SMB_POWERSUP_F_PRESENT;
1294 1296 if (SMB_PSU_CHARS_ISUNPLUG(psu.smbpsup_char))
1295 1297 psup->smbps_flags |= SMB_POWERSUP_F_UNPLUG;
1296 1298
1297 1299 psup->smbps_ivrs = SMB_PSU_CHARS_IVRS(psu.smbpsup_char);
1298 1300 psup->smbps_status = SMB_PSU_CHARS_STATUS(psu.smbpsup_char);
1299 1301 psup->smbps_pstype = SMB_PSU_CHARS_TYPE(psu.smbpsup_char);
1300 1302
1301 1303 if (stp->smbst_hdr->smbh_len >= 0x12) {
1302 1304 psup->smbps_vprobe = psu.smbpsup_vprobe;
1303 1305 } else {
1304 1306 psup->smbps_vprobe = 0xffff;
1305 1307 }
1306 1308
1307 1309 if (stp->smbst_hdr->smbh_len >= 0x14) {
1308 1310 psup->smbps_cooldev = psu.smbpsup_cooldev;
1309 1311 } else {
1310 1312 psup->smbps_cooldev = 0xffff;
1311 1313 }
1312 1314
1313 1315 if (stp->smbst_hdr->smbh_len >= 0x16) {
1314 1316 psup->smbps_iprobe = psu.smbpsup_iprobe;
1315 1317 } else {
1316 1318 psup->smbps_iprobe = 0xffff;
1317 1319 }
1318 1320
1319 1321 return (0);
1320 1322 }
1321 1323
1322 1324 int
1323 1325 smbios_info_vprobe(smbios_hdl_t *shp, id_t id, smbios_vprobe_t *vprobe)
1324 1326 {
1325 1327 const smb_struct_t *stp = smb_lookup_id(shp, id);
1326 1328 smb_vprobe_t vp;
1327 1329
1328 1330 if (stp == NULL)
1329 1331 return (-1); /* errno is set for us */
1330 1332
1331 1333 if (stp->smbst_hdr->smbh_type != SMB_TYPE_VPROBE)
1332 1334 return (smb_set_errno(shp, ESMB_TYPE));
1333 1335
1334 1336 if (stp->smbst_hdr->smbh_len < SMB_VPROBE_MINLEN)
1335 1337 return (smb_set_errno(shp, ESMB_SHORT));
1336 1338
1337 1339 bzero(vprobe, sizeof (*vprobe));
1338 1340 smb_info_bcopy(stp->smbst_hdr, &vp, sizeof (vp));
1339 1341 vprobe->smbvp_description = smb_strptr(stp, vp.smbvpr_descr);
1340 1342 vprobe->smbvp_location = SMB_VPROBE_LOCATION(vp.smbvpr_locstat);
1341 1343 vprobe->smbvp_status = SMB_VPROBE_STATUS(vp.smbvpr_locstat);
1342 1344 vprobe->smbvp_maxval = vp.smbvpr_maxval;
1343 1345 vprobe->smbvp_minval = vp.smbvpr_minval;
1344 1346 vprobe->smbvp_resolution = vp.smbvpr_resolution;
1345 1347 vprobe->smbvp_tolerance = vp.smbvpr_tolerance;
1346 1348 vprobe->smbvp_accuracy = vp.smbvpr_accuracy;
1347 1349
1348 1350 if (stp->smbst_hdr->smbh_len >= SMB_VPROBE_NOMINAL_MINLEN) {
1349 1351 vprobe->smbvp_nominal = vp.smbvpr_nominal;
1350 1352 } else {
1351 1353 vprobe->smbvp_nominal = SMB_PROBE_UNKNOWN_VALUE;
1352 1354 }
1353 1355
1354 1356 return (0);
1355 1357 }
1356 1358
1357 1359 int
1358 1360 smbios_info_cooldev(smbios_hdl_t *shp, id_t id, smbios_cooldev_t *cooldev)
1359 1361 {
1360 1362 const smb_struct_t *stp = smb_lookup_id(shp, id);
1361 1363 smb_cooldev_t cd;
1362 1364
1363 1365 if (stp == NULL)
1364 1366 return (-1); /* errno is set for us */
1365 1367
1366 1368 if (stp->smbst_hdr->smbh_type != SMB_TYPE_COOLDEV)
1367 1369 return (smb_set_errno(shp, ESMB_TYPE));
1368 1370
1369 1371 if (stp->smbst_hdr->smbh_len < SMB_COOLDEV_MINLEN)
1370 1372 return (smb_set_errno(shp, ESMB_SHORT));
1371 1373
1372 1374 bzero(cooldev, sizeof (*cooldev));
1373 1375 smb_info_bcopy(stp->smbst_hdr, &cd, sizeof (cd));
1374 1376 cooldev->smbcd_tprobe = cd.smbcdev_tprobe;
1375 1377 cooldev->smbcd_type = SMB_COOLDEV_TYPE(cd.smbcdev_typstat);
1376 1378 cooldev->smbcd_status = SMB_COOLDEV_STATUS(cd.smbcdev_typstat);
1377 1379 cooldev->smbcd_group = cd.smbcdev_group;
1378 1380 cooldev->smbcd_oem = cd.smbcdev_oem;
1379 1381
1380 1382 if (stp->smbst_hdr->smbh_len >= SMB_COOLDEV_NOMINAL_MINLEN) {
1381 1383 cooldev->smbcd_nominal = cd.smbcdev_nominal;
1382 1384 } else {
1383 1385 cooldev->smbcd_nominal = SMB_PROBE_UNKNOWN_VALUE;
1384 1386 }
1385 1387
1386 1388 /*
1387 1389 * The description field was added in SMBIOS version 2.7. The
1388 1390 * SMB_TYPE_COOLDEV support was only added after all of the 2.7+ fields
1389 1391 * were added in the spec. So while a user may request an older version,
1390 1392 * we don't have to worry about old structures and just simply skip it
1391 1393 * if they're not asking for it.
1392 1394 */
1393 1395 if (smb_libgteq(shp, SMB_VERSION_27) &&
1394 1396 smb_gteq(shp, SMB_VERSION_27) &&
1395 1397 stp->smbst_hdr->smbh_len >= SMB_COOLDEV_DESCR_MINLEN) {
1396 1398 cooldev->smbcd_descr = smb_strptr(stp, cd.smbcdev_descr);
1397 1399 } else {
1398 1400 cooldev->smbcd_descr = NULL;
1399 1401 }
1400 1402
1401 1403 return (0);
1402 1404 }
1403 1405
1404 1406 int
1405 1407 smbios_info_tprobe(smbios_hdl_t *shp, id_t id, smbios_tprobe_t *tprobe)
1406 1408 {
1407 1409 const smb_struct_t *stp = smb_lookup_id(shp, id);
1408 1410 smb_tprobe_t tp;
1409 1411
1410 1412 if (stp == NULL)
1411 1413 return (-1); /* errno is set for us */
1412 1414
1413 1415 if (stp->smbst_hdr->smbh_type != SMB_TYPE_TPROBE)
1414 1416 return (smb_set_errno(shp, ESMB_TYPE));
1415 1417
1416 1418 if (stp->smbst_hdr->smbh_len < SMB_TPROBE_MINLEN)
1417 1419 return (smb_set_errno(shp, ESMB_SHORT));
1418 1420
1419 1421 bzero(tprobe, sizeof (*tprobe));
1420 1422 smb_info_bcopy(stp->smbst_hdr, &tp, sizeof (tp));
1421 1423 tprobe->smbtp_description = smb_strptr(stp, tp.smbtpr_descr);
1422 1424 tprobe->smbtp_location = SMB_TPROBE_LOCATION(tp.smbtpr_locstat);
1423 1425 tprobe->smbtp_status = SMB_TPROBE_STATUS(tp.smbtpr_locstat);
1424 1426 tprobe->smbtp_maxval = tp.smbtpr_maxval;
1425 1427 tprobe->smbtp_minval = tp.smbtpr_minval;
1426 1428 tprobe->smbtp_resolution = tp.smbtpr_resolution;
1427 1429 tprobe->smbtp_tolerance = tp.smbtpr_tolerance;
1428 1430 tprobe->smbtp_accuracy = tp.smbtpr_accuracy;
1429 1431
1430 1432 if (stp->smbst_hdr->smbh_len >= SMB_TPROBE_NOMINAL_MINLEN) {
1431 1433 tprobe->smbtp_nominal = tp.smbtpr_nominal;
1432 1434 } else {
1433 1435 tprobe->smbtp_nominal = SMB_PROBE_UNKNOWN_VALUE;
1434 1436 }
1435 1437
1436 1438 return (0);
1437 1439 }
1438 1440
1439 1441 int
1440 1442 smbios_info_iprobe(smbios_hdl_t *shp, id_t id, smbios_iprobe_t *iprobe)
1441 1443 {
1442 1444 const smb_struct_t *sip = smb_lookup_id(shp, id);
1443 1445 smb_iprobe_t ip;
1444 1446
1445 1447 if (sip == NULL)
1446 1448 return (-1); /* errno is set for us */
1447 1449
1448 1450 if (sip->smbst_hdr->smbh_type != SMB_TYPE_IPROBE)
1449 1451 return (smb_set_errno(shp, ESMB_TYPE));
1450 1452
1451 1453 if (sip->smbst_hdr->smbh_len < SMB_IPROBE_MINLEN)
1452 1454 return (smb_set_errno(shp, ESMB_SHORT));
1453 1455
1454 1456 bzero(iprobe, sizeof (*iprobe));
1455 1457 smb_info_bcopy(sip->smbst_hdr, &ip, sizeof (ip));
1456 1458 iprobe->smbip_description = smb_strptr(sip, ip.smbipr_descr);
1457 1459 iprobe->smbip_location = SMB_IPROBE_LOCATION(ip.smbipr_locstat);
1458 1460 iprobe->smbip_status = SMB_IPROBE_STATUS(ip.smbipr_locstat);
1459 1461 iprobe->smbip_maxval = ip.smbipr_maxval;
1460 1462 iprobe->smbip_minval = ip.smbipr_minval;
1461 1463 iprobe->smbip_resolution = ip.smbipr_resolution;
1462 1464 iprobe->smbip_tolerance = ip.smbipr_tolerance;
1463 1465 iprobe->smbip_accuracy = ip.smbipr_accuracy;
1464 1466
1465 1467 if (sip->smbst_hdr->smbh_len >= SMB_IPROBE_NOMINAL_MINLEN) {
1466 1468 iprobe->smbip_nominal = ip.smbipr_nominal;
1467 1469 } else {
1468 1470 iprobe->smbip_nominal = SMB_PROBE_UNKNOWN_VALUE;
1469 1471 }
1470 1472
1471 1473 return (0);
1472 1474 }
↓ open down ↓ |
470 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX