Print this page
5094 Update libsmbios with recent items
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Reviewed by: Garrett D'Amore <garrett@damore.org>
Reviewed by: Robert Mustacchi <rm@joyent.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/smbios/smbios.c
+++ new/usr/src/cmd/smbios/smbios.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 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
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 + * Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
23 24 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 25 * Use is subject to license terms.
25 26 */
26 27
27 28 #include <sys/sysmacros.h>
28 29 #include <sys/param.h>
29 30
30 31 #include <smbios.h>
31 32 #include <alloca.h>
32 33 #include <limits.h>
33 34 #include <unistd.h>
34 35 #include <strings.h>
35 36 #include <stdlib.h>
36 37 #include <stdarg.h>
37 38 #include <stdio.h>
38 39 #include <fcntl.h>
39 40 #include <errno.h>
40 41 #include <ctype.h>
41 42
42 43 #define SMBIOS_SUCCESS 0
43 44 #define SMBIOS_ERROR 1
44 45 #define SMBIOS_USAGE 2
45 46
46 47 static const char *g_pname;
47 48 static int g_hdr;
48 49
49 50 static int opt_e;
50 51 static int opt_i = -1;
51 52 static int opt_O;
52 53 static int opt_s;
53 54 static int opt_t = -1;
54 55 static int opt_x;
55 56
56 57 /*PRINTFLIKE2*/
57 58 static void
58 59 oprintf(FILE *fp, const char *format, ...)
59 60 {
60 61 va_list ap;
61 62
62 63 va_start(ap, format);
63 64 (void) vfprintf(fp, format, ap);
64 65 va_end(ap);
65 66 }
66 67
67 68 /*PRINTFLIKE3*/
68 69 static void
69 70 desc_printf(const char *d, FILE *fp, const char *format, ...)
70 71 {
71 72 va_list ap;
72 73
73 74 va_start(ap, format);
74 75 (void) vfprintf(fp, format, ap);
75 76 va_end(ap);
76 77
77 78 if (d != NULL)
78 79 (void) fprintf(fp, " (%s)\n", d);
79 80 else
80 81 (void) fprintf(fp, "\n");
81 82 }
82 83
83 84 static void
84 85 flag_printf(FILE *fp, const char *s, uint_t flags, size_t bits,
85 86 const char *(*flag_name)(uint_t), const char *(*flag_desc)(uint_t))
86 87 {
87 88 size_t i;
88 89
89 90 oprintf(fp, " %s: 0x%x\n", s, flags);
90 91
91 92 for (i = 0; i < bits; i++) {
92 93 uint_t f = 1 << i;
93 94 const char *n;
94 95
95 96 if (!(flags & f))
96 97 continue;
97 98
98 99 if ((n = flag_name(f)) != NULL)
99 100 desc_printf(flag_desc(f), fp, "\t%s", n);
100 101 else
101 102 desc_printf(flag_desc(f), fp, "\t0x%x", f);
102 103 }
103 104 }
104 105
105 106 static void
106 107 flag64_printf(FILE *fp, const char *s, uint64_t flags, size_t bits,
107 108 const char *(*flag_name)(uint64_t), const char *(*flag_desc)(uint64_t))
108 109 {
109 110 size_t i;
110 111
111 112 oprintf(fp, " %s: 0x%llx\n", s, (u_longlong_t)flags);
112 113
113 114 for (i = 0; i < bits; i++) {
114 115 u_longlong_t f = 1ULL << i;
115 116 const char *n;
116 117
117 118 if (!(flags & f))
118 119 continue;
119 120
120 121 if ((n = flag_name(f)) != NULL)
121 122 desc_printf(flag_desc(f), fp, "\t%s", n);
122 123 else
123 124 desc_printf(flag_desc(f), fp, "\t0x%llx", f);
124 125 }
125 126 }
126 127
127 128 static void
128 129 id_printf(FILE *fp, const char *s, id_t id)
129 130 {
130 131 switch (id) {
131 132 case SMB_ID_NONE:
132 133 oprintf(fp, "%sNone\n", s);
133 134 break;
134 135 case SMB_ID_NOTSUP:
135 136 oprintf(fp, "%sNot Supported\n", s);
136 137 break;
137 138 default:
138 139 oprintf(fp, "%s%u\n", s, (uint_t)id);
139 140 }
140 141 }
141 142
142 143 static int
143 144 check_oem(smbios_hdl_t *shp)
144 145 {
145 146 int i;
146 147 int cnt;
147 148 int rv;
148 149 id_t oem_id;
149 150 smbios_struct_t s;
150 151 const char **oem_str;
151 152
152 153 rv = smbios_lookup_type(shp, SMB_TYPE_OEMSTR, &s);
153 154 if (rv != 0) {
154 155 return (-1);
155 156 }
156 157
157 158 oem_id = s.smbstr_id;
158 159
159 160 cnt = smbios_info_strtab(shp, oem_id, 0, NULL);
160 161 if (cnt > 0) {
161 162 oem_str = alloca(sizeof (char *) * cnt);
162 163 (void) smbios_info_strtab(shp, oem_id, cnt, oem_str);
163 164
164 165 for (i = 0; i < cnt; i++) {
165 166 if (strncmp(oem_str[i], SMB_PRMS1,
166 167 strlen(SMB_PRMS1) + 1) == 0) {
167 168 return (0);
168 169 }
169 170 }
170 171 }
171 172
172 173 return (-1);
173 174 }
174 175
175 176 static void
176 177 print_smbios(smbios_hdl_t *shp, FILE *fp)
177 178 {
178 179 smbios_entry_t ep;
179 180 int i;
180 181
181 182 smbios_info_smbios(shp, &ep);
182 183
183 184 oprintf(fp, "Entry Point Anchor Tag: %*.*s\n",
184 185 (int)sizeof (ep.smbe_eanchor), (int)sizeof (ep.smbe_eanchor),
185 186 ep.smbe_eanchor);
186 187
187 188 oprintf(fp, "Entry Point Checksum: 0x%x\n", ep.smbe_ecksum);
188 189 oprintf(fp, "Entry Point Length: %u\n", ep.smbe_elen);
189 190 oprintf(fp, "Entry Point Version: %u.%u\n",
190 191 ep.smbe_major, ep.smbe_minor);
191 192 oprintf(fp, "Max Structure Size: %u\n", ep.smbe_maxssize);
192 193 oprintf(fp, "Entry Point Revision: 0x%x\n", ep.smbe_revision);
193 194
194 195 oprintf(fp, "Entry Point Revision Data:");
195 196 for (i = 0; i < sizeof (ep.smbe_format); i++)
196 197 oprintf(fp, " 0x%02x", ep.smbe_format[i]);
197 198 oprintf(fp, "\n");
198 199
199 200 oprintf(fp, "Intermediate Anchor Tag: %*.*s\n",
200 201 (int)sizeof (ep.smbe_ianchor), (int)sizeof (ep.smbe_ianchor),
201 202 ep.smbe_ianchor);
202 203
203 204 oprintf(fp, "Intermediate Checksum: 0x%x\n", ep.smbe_icksum);
204 205 oprintf(fp, "Structure Table Length: %u\n", ep.smbe_stlen);
205 206 oprintf(fp, "Structure Table Address: 0x%x\n", ep.smbe_staddr);
206 207 oprintf(fp, "Structure Table Entries: %u\n", ep.smbe_stnum);
207 208 oprintf(fp, "DMI BCD Revision: 0x%x\n", ep.smbe_bcdrev);
208 209 }
209 210
210 211 static void
211 212 print_common(const smbios_info_t *ip, FILE *fp)
212 213 {
213 214 if (ip->smbi_manufacturer[0] != '\0')
214 215 oprintf(fp, " Manufacturer: %s\n", ip->smbi_manufacturer);
215 216 if (ip->smbi_product[0] != '\0')
216 217 oprintf(fp, " Product: %s\n", ip->smbi_product);
217 218 if (ip->smbi_version[0] != '\0')
218 219 oprintf(fp, " Version: %s\n", ip->smbi_version);
219 220 if (ip->smbi_serial[0] != '\0')
220 221 oprintf(fp, " Serial Number: %s\n", ip->smbi_serial);
221 222 if (ip->smbi_asset[0] != '\0')
222 223 oprintf(fp, " Asset Tag: %s\n", ip->smbi_asset);
223 224 if (ip->smbi_location[0] != '\0')
224 225 oprintf(fp, " Location Tag: %s\n", ip->smbi_location);
225 226 if (ip->smbi_part[0] != '\0')
226 227 oprintf(fp, " Part Number: %s\n", ip->smbi_part);
227 228 }
228 229
229 230 static void
230 231 print_bios(smbios_hdl_t *shp, FILE *fp)
231 232 {
232 233 smbios_bios_t b;
233 234
234 235 (void) smbios_info_bios(shp, &b);
235 236
236 237 oprintf(fp, " Vendor: %s\n", b.smbb_vendor);
237 238 oprintf(fp, " Version String: %s\n", b.smbb_version);
238 239 oprintf(fp, " Release Date: %s\n", b.smbb_reldate);
239 240 oprintf(fp, " Address Segment: 0x%x\n", b.smbb_segment);
240 241 oprintf(fp, " ROM Size: %u bytes\n", b.smbb_romsize);
241 242 oprintf(fp, " Image Size: %u bytes\n", b.smbb_runsize);
242 243
243 244 flag64_printf(fp, "Characteristics",
244 245 b.smbb_cflags, sizeof (b.smbb_cflags) * NBBY,
245 246 smbios_bios_flag_name, smbios_bios_flag_desc);
246 247
247 248 if (b.smbb_nxcflags > SMB_BIOSXB_1) {
248 249 flag_printf(fp, "Characteristics Extension Byte 1",
249 250 b.smbb_xcflags[SMB_BIOSXB_1],
250 251 sizeof (b.smbb_xcflags[SMB_BIOSXB_1]) * NBBY,
251 252 smbios_bios_xb1_name, smbios_bios_xb1_desc);
252 253 }
253 254
254 255 if (b.smbb_nxcflags > SMB_BIOSXB_2) {
255 256 flag_printf(fp, "Characteristics Extension Byte 2",
256 257 b.smbb_xcflags[SMB_BIOSXB_2],
257 258 sizeof (b.smbb_xcflags[SMB_BIOSXB_2]) * NBBY,
258 259 smbios_bios_xb2_name, smbios_bios_xb2_desc);
259 260 }
260 261
261 262 if (b.smbb_nxcflags > SMB_BIOSXB_BIOS_MIN) {
262 263 oprintf(fp, " Version Number: %u.%u\n",
263 264 b.smbb_biosv.smbv_major, b.smbb_biosv.smbv_minor);
264 265 }
265 266
266 267 if (b.smbb_nxcflags > SMB_BIOSXB_ECFW_MIN) {
267 268 oprintf(fp, " Embedded Ctlr Firmware Version Number: %u.%u\n",
268 269 b.smbb_ecfwv.smbv_major, b.smbb_ecfwv.smbv_minor);
269 270 }
270 271 }
271 272
272 273 static void
273 274 print_system(smbios_hdl_t *shp, FILE *fp)
274 275 {
275 276 smbios_system_t s;
276 277 uint_t i;
277 278
278 279 (void) smbios_info_system(shp, &s);
279 280
280 281 oprintf(fp, " UUID: ");
281 282 for (i = 0; i < s.smbs_uuidlen; i++) {
282 283 oprintf(fp, "%02x", s.smbs_uuid[i]);
283 284 if (i == 3 || i == 5 || i == 7 || i == 9)
284 285 oprintf(fp, "-");
285 286 }
286 287 oprintf(fp, "\n");
287 288
288 289 desc_printf(smbios_system_wakeup_desc(s.smbs_wakeup),
289 290 fp, " Wake-Up Event: 0x%x", s.smbs_wakeup);
290 291
291 292 oprintf(fp, " SKU Number: %s\n", s.smbs_sku);
292 293 oprintf(fp, " Family: %s\n", s.smbs_family);
293 294 }
294 295
295 296 static void
296 297 print_bboard(smbios_hdl_t *shp, id_t id, FILE *fp)
297 298 {
298 299 smbios_bboard_t b;
299 300 int chdl_cnt;
300 301
301 302 (void) smbios_info_bboard(shp, id, &b);
302 303
303 304 oprintf(fp, " Chassis: %u\n", (uint_t)b.smbb_chassis);
304 305
305 306 flag_printf(fp, "Flags", b.smbb_flags, sizeof (b.smbb_flags) * NBBY,
306 307 smbios_bboard_flag_name, smbios_bboard_flag_desc);
307 308
308 309 desc_printf(smbios_bboard_type_desc(b.smbb_type),
309 310 fp, " Board Type: 0x%x", b.smbb_type);
310 311
311 312 chdl_cnt = b.smbb_contn;
312 313 if (chdl_cnt != 0) {
313 314 id_t *chdl;
314 315 uint16_t hdl;
315 316 int i, n, cnt;
316 317
317 318 chdl = alloca(chdl_cnt * sizeof (id_t));
318 319 cnt = smbios_info_contains(shp, id, chdl_cnt, chdl);
319 320 if (cnt > SMB_CONT_MAX)
320 321 return;
321 322 n = MIN(chdl_cnt, cnt);
322 323
323 324 oprintf(fp, "\n");
324 325 for (i = 0; i < n; i++) {
325 326 hdl = (uint16_t)chdl[i];
326 327 oprintf(fp, " Contained Handle: %u\n", hdl);
327 328 }
328 329 }
329 330 }
|
↓ open down ↓ |
297 lines elided |
↑ open up ↑ |
330 331
331 332 static void
332 333 print_chassis(smbios_hdl_t *shp, id_t id, FILE *fp)
333 334 {
334 335 smbios_chassis_t c;
335 336 int elem_cnt;
336 337
337 338 (void) smbios_info_chassis(shp, id, &c);
338 339
339 340 oprintf(fp, " OEM Data: 0x%x\n", c.smbc_oemdata);
341 + oprintf(fp, " SKU number: %s\n",
342 + c.smbc_sku == NULL ? "<unknown>" : c.smbc_sku);
340 343 oprintf(fp, " Lock Present: %s\n", c.smbc_lock ? "Y" : "N");
341 344
342 345 desc_printf(smbios_chassis_type_desc(c.smbc_type),
343 346 fp, " Chassis Type: 0x%x", c.smbc_type);
344 347
345 348 desc_printf(smbios_chassis_state_desc(c.smbc_bustate),
346 349 fp, " Boot-Up State: 0x%x", c.smbc_bustate);
347 350
348 351 desc_printf(smbios_chassis_state_desc(c.smbc_psstate),
349 352 fp, " Power Supply State: 0x%x", c.smbc_psstate);
350 353
351 354 desc_printf(smbios_chassis_state_desc(c.smbc_thstate),
352 355 fp, " Thermal State: 0x%x", c.smbc_thstate);
353 356
354 357 oprintf(fp, " Chassis Height: %uu\n", c.smbc_uheight);
355 358 oprintf(fp, " Power Cords: %u\n", c.smbc_cords);
356 359
357 360 elem_cnt = c.smbc_elems;
358 361 oprintf(fp, " Element Records: %u\n", elem_cnt);
359 362
360 363 if (elem_cnt > 0) {
361 364 id_t *elems;
362 365 uint8_t type;
363 366 int i, n, cnt;
364 367
365 368 elems = alloca(c.smbc_elems * sizeof (id_t));
366 369 cnt = smbios_info_contains(shp, id, elem_cnt, elems);
367 370 if (cnt > SMB_CONT_MAX)
368 371 return;
369 372 n = MIN(elem_cnt, cnt);
370 373
371 374 oprintf(fp, "\n");
372 375 for (i = 0; i < n; i++) {
373 376 type = (uint8_t)elems[i];
374 377 if (type & 0x80) {
375 378 /* SMBIOS structrure Type */
376 379 desc_printf(smbios_type_name(type & 0x7f), fp,
377 380 " Contained SMBIOS structure Type: %u",
378 381 type & 0x80);
379 382 } else {
380 383 /* SMBIOS Base Board Type */
381 384 desc_printf(smbios_bboard_type_desc(type), fp,
382 385 " Contained SMBIOS Base Board Type: 0x%x",
383 386 type);
384 387 }
385 388 }
386 389 }
387 390 }
388 391
389 392 static void
390 393 print_processor(smbios_hdl_t *shp, id_t id, FILE *fp)
|
↓ open down ↓ |
41 lines elided |
↑ open up ↑ |
391 394 {
392 395 smbios_processor_t p;
393 396 uint_t status;
394 397
395 398 (void) smbios_info_processor(shp, id, &p);
396 399 status = SMB_PRSTATUS_STATUS(p.smbp_status);
397 400
398 401 desc_printf(smbios_processor_family_desc(p.smbp_family),
399 402 fp, " Family: %u", p.smbp_family);
400 403
404 + if (p.smbp_family2 != 0)
405 + desc_printf(smbios_processor_family_desc(p.smbp_family2),
406 + fp, " Family Ext: %u", p.smbp_family2);
407 +
401 408 oprintf(fp, " CPUID: 0x%llx\n", (u_longlong_t)p.smbp_cpuid);
402 409
403 410 desc_printf(smbios_processor_type_desc(p.smbp_type),
404 411 fp, " Type: %u", p.smbp_type);
405 412
406 413 desc_printf(smbios_processor_upgrade_desc(p.smbp_upgrade),
407 414 fp, " Socket Upgrade: %u", p.smbp_upgrade);
408 415
409 416 oprintf(fp, " Socket Status: %s\n",
410 417 SMB_PRSTATUS_PRESENT(p.smbp_status) ?
411 418 "Populated" : "Not Populated");
412 419
413 420 desc_printf(smbios_processor_status_desc(status),
414 421 fp, " Processor Status: %u", status);
415 422
416 423 if (SMB_PRV_LEGACY(p.smbp_voltage)) {
417 424 oprintf(fp, " Supported Voltages:");
418 425 switch (p.smbp_voltage) {
419 426 case SMB_PRV_5V:
420 427 oprintf(fp, " 5.0V");
421 428 break;
422 429 case SMB_PRV_33V:
423 430 oprintf(fp, " 3.3V");
424 431 break;
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
425 432 case SMB_PRV_29V:
426 433 oprintf(fp, " 2.9V");
427 434 break;
428 435 }
429 436 oprintf(fp, "\n");
430 437 } else {
431 438 oprintf(fp, " Supported Voltages: %.1fV\n",
432 439 (float)SMB_PRV_VOLTAGE(p.smbp_voltage) / 10);
433 440 }
434 441
442 + if (p.smbp_corecount != 0)
443 + oprintf(fp, " Core Count: %u\n", p.smbp_corecount);
444 + else
445 + oprintf(fp, " Core Count: Unknown\n");
446 +
447 + if (p.smbp_coresenabled != 0)
448 + oprintf(fp, " Cores Enabled: %u\n", p.smbp_coresenabled);
449 + else
450 + oprintf(fp, " Cores Enabled: Unknown\n");
451 +
452 + if (p.smbp_threadcount != 0)
453 + oprintf(fp, " Thread Count: %u\n", p.smbp_threadcount);
454 + else
455 + oprintf(fp, " Thread Count: Unknown\n");
456 +
457 + if (p.smbp_cflags) {
458 + flag_printf(fp, "Processor Characteristics",
459 + p.smbp_cflags, sizeof (p.smbp_cflags) * NBBY,
460 + smbios_processor_core_flag_name,
461 + smbios_processor_core_flag_desc);
462 + }
463 +
435 464 if (p.smbp_clkspeed != 0)
436 465 oprintf(fp, " External Clock Speed: %uMHz\n", p.smbp_clkspeed);
437 466 else
438 467 oprintf(fp, " External Clock Speed: Unknown\n");
439 468
440 469 if (p.smbp_maxspeed != 0)
441 470 oprintf(fp, " Maximum Speed: %uMHz\n", p.smbp_maxspeed);
442 471 else
443 472 oprintf(fp, " Maximum Speed: Unknown\n");
444 473
445 474 if (p.smbp_curspeed != 0)
446 475 oprintf(fp, " Current Speed: %uMHz\n", p.smbp_curspeed);
447 476 else
448 477 oprintf(fp, " Current Speed: Unknown\n");
449 478
450 - id_printf(fp, " L1 Cache: ", p.smbp_l1cache);
451 - id_printf(fp, " L2 Cache: ", p.smbp_l2cache);
452 - id_printf(fp, " L3 Cache: ", p.smbp_l3cache);
479 + id_printf(fp, " L1 Cache: ", p.smbp_l1cache);
480 + id_printf(fp, " L2 Cache: ", p.smbp_l2cache);
481 + id_printf(fp, " L3 Cache: ", p.smbp_l3cache);
453 482 }
454 483
455 484 static void
456 485 print_cache(smbios_hdl_t *shp, id_t id, FILE *fp)
457 486 {
458 487 smbios_cache_t c;
459 488
460 489 (void) smbios_info_cache(shp, id, &c);
461 490
462 491 oprintf(fp, " Level: %u\n", c.smba_level);
463 492 oprintf(fp, " Maximum Installed Size: %u bytes\n", c.smba_maxsize);
464 493
465 494 if (c.smba_size != 0)
466 495 oprintf(fp, " Installed Size: %u bytes\n", c.smba_size);
467 496 else
468 497 oprintf(fp, " Installed Size: Not Installed\n");
469 498
470 499 if (c.smba_speed != 0)
471 500 oprintf(fp, " Speed: %uns\n", c.smba_speed);
472 501 else
473 502 oprintf(fp, " Speed: Unknown\n");
474 503
475 504 flag_printf(fp, "Supported SRAM Types",
476 505 c.smba_stype, sizeof (c.smba_stype) * NBBY,
477 506 smbios_cache_ctype_name, smbios_cache_ctype_desc);
478 507
479 508 desc_printf(smbios_cache_ctype_desc(c.smba_ctype),
480 509 fp, " Current SRAM Type: 0x%x", c.smba_ctype);
481 510
482 511 desc_printf(smbios_cache_ecc_desc(c.smba_etype),
483 512 fp, " Error Correction Type: %u", c.smba_etype);
484 513
485 514 desc_printf(smbios_cache_logical_desc(c.smba_ltype),
486 515 fp, " Logical Cache Type: %u", c.smba_ltype);
487 516
488 517 desc_printf(smbios_cache_assoc_desc(c.smba_assoc),
489 518 fp, " Associativity: %u", c.smba_assoc);
490 519
491 520 desc_printf(smbios_cache_mode_desc(c.smba_mode),
492 521 fp, " Mode: %u", c.smba_mode);
493 522
494 523 desc_printf(smbios_cache_loc_desc(c.smba_location),
495 524 fp, " Location: %u", c.smba_location);
496 525
497 526 flag_printf(fp, "Flags", c.smba_flags, sizeof (c.smba_flags) * NBBY,
498 527 smbios_cache_flag_name, smbios_cache_flag_desc);
499 528 }
500 529
501 530 static void
502 531 print_port(smbios_hdl_t *shp, id_t id, FILE *fp)
503 532 {
504 533 smbios_port_t p;
505 534
506 535 (void) smbios_info_port(shp, id, &p);
507 536
508 537 oprintf(fp, " Internal Reference Designator: %s\n", p.smbo_iref);
509 538 oprintf(fp, " External Reference Designator: %s\n", p.smbo_eref);
510 539
511 540 desc_printf(smbios_port_conn_desc(p.smbo_itype),
512 541 fp, " Internal Connector Type: %u", p.smbo_itype);
513 542
514 543 desc_printf(smbios_port_conn_desc(p.smbo_etype),
515 544 fp, " External Connector Type: %u", p.smbo_etype);
516 545
517 546 desc_printf(smbios_port_type_desc(p.smbo_ptype),
518 547 fp, " Port Type: %u", p.smbo_ptype);
519 548 }
520 549
521 550 static void
522 551 print_slot(smbios_hdl_t *shp, id_t id, FILE *fp)
523 552 {
524 553 smbios_slot_t s;
525 554 smbios_entry_t e;
526 555
527 556 (void) smbios_info_slot(shp, id, &s);
528 557 (void) smbios_info_smbios(shp, &e);
529 558
530 559 oprintf(fp, " Reference Designator: %s\n", s.smbl_name);
531 560 oprintf(fp, " Slot ID: 0x%x\n", s.smbl_id);
532 561
533 562 desc_printf(smbios_slot_type_desc(s.smbl_type),
534 563 fp, " Type: 0x%x", s.smbl_type);
535 564
536 565 desc_printf(smbios_slot_width_desc(s.smbl_width),
537 566 fp, " Width: 0x%x", s.smbl_width);
538 567
539 568 desc_printf(smbios_slot_usage_desc(s.smbl_usage),
540 569 fp, " Usage: 0x%x", s.smbl_usage);
541 570
542 571 desc_printf(smbios_slot_length_desc(s.smbl_length),
543 572 fp, " Length: 0x%x", s.smbl_length);
544 573
545 574 flag_printf(fp, "Slot Characteristics 1",
546 575 s.smbl_ch1, sizeof (s.smbl_ch1) * NBBY,
547 576 smbios_slot_ch1_name, smbios_slot_ch1_desc);
548 577
549 578 flag_printf(fp, "Slot Characteristics 2",
550 579 s.smbl_ch2, sizeof (s.smbl_ch2) * NBBY,
551 580 smbios_slot_ch2_name, smbios_slot_ch2_desc);
552 581
553 582 if (check_oem(shp) != 0 && (e.smbe_major < 2 || e.smbe_minor < 6))
554 583 return;
555 584
556 585 oprintf(fp, " Segment Group: %u\n", s.smbl_sg);
557 586 oprintf(fp, " Bus Number: %u\n", s.smbl_bus);
558 587 oprintf(fp, " Device/Function Number: %u\n", s.smbl_df);
559 588 }
560 589
561 590 static void
562 591 print_obdevs_ext(smbios_hdl_t *shp, id_t id, FILE *fp)
563 592 {
564 593 smbios_obdev_ext_t oe;
565 594
566 595 (void) smbios_info_obdevs_ext(shp, id, &oe);
567 596
568 597 oprintf(fp, " Reference Designator: %s\n", oe.smboe_name);
569 598 oprintf(fp, " Device Type: %u\n", oe.smboe_dtype);
570 599 oprintf(fp, " Device Type Instance: %u\n", oe.smboe_dti);
571 600 oprintf(fp, " Segment Group Number: %u\n", oe.smboe_sg);
572 601 oprintf(fp, " Bus Number: %u\n", oe.smboe_bus);
573 602 oprintf(fp, " Device/Function Number: %u\n", oe.smboe_df);
574 603 }
575 604
576 605 static void
577 606 print_obdevs(smbios_hdl_t *shp, id_t id, FILE *fp)
578 607 {
579 608 smbios_obdev_t *argv;
580 609 int i, argc;
581 610
582 611 if ((argc = smbios_info_obdevs(shp, id, 0, NULL)) > 0) {
583 612 argv = alloca(sizeof (smbios_obdev_t) * argc);
584 613 (void) smbios_info_obdevs(shp, id, argc, argv);
585 614 for (i = 0; i < argc; i++)
586 615 oprintf(fp, " %s\n", argv[i].smbd_name);
587 616 }
588 617 }
589 618
590 619 static void
591 620 print_strtab(smbios_hdl_t *shp, id_t id, FILE *fp)
592 621 {
593 622 const char **argv;
594 623 int i, argc;
595 624
596 625 if ((argc = smbios_info_strtab(shp, id, 0, NULL)) > 0) {
597 626 argv = alloca(sizeof (char *) * argc);
598 627 (void) smbios_info_strtab(shp, id, argc, argv);
599 628 for (i = 0; i < argc; i++)
600 629 oprintf(fp, " %s\n", argv[i]);
601 630 }
602 631 }
603 632
604 633 static void
605 634 print_lang(smbios_hdl_t *shp, id_t id, FILE *fp)
606 635 {
607 636 smbios_lang_t l;
608 637
609 638 (void) smbios_info_lang(shp, &l);
610 639
611 640 oprintf(fp, " Current Language: %s\n", l.smbla_cur);
612 641 oprintf(fp, " Language String Format: %u\n", l.smbla_fmt);
613 642 oprintf(fp, " Number of Installed Languages: %u\n", l.smbla_num);
614 643 oprintf(fp, " Installed Languages:\n");
615 644
616 645 print_strtab(shp, id, fp);
617 646 }
618 647
619 648 /*ARGSUSED*/
620 649 static void
621 650 print_evlog(smbios_hdl_t *shp, id_t id, FILE *fp)
622 651 {
623 652 smbios_evlog_t ev;
624 653 uint32_t i;
625 654
626 655 (void) smbios_info_eventlog(shp, &ev);
627 656
628 657 oprintf(fp, " Log Area Size: %lu bytes\n", (ulong_t)ev.smbev_size);
629 658 oprintf(fp, " Header Offset: %lu\n", (ulong_t)ev.smbev_hdr);
630 659 oprintf(fp, " Data Offset: %lu\n", (ulong_t)ev.smbev_data);
631 660
632 661 desc_printf(smbios_evlog_method_desc(ev.smbev_method),
633 662 fp, " Data Access Method: %u", ev.smbev_method);
634 663
635 664 flag_printf(fp, "Log Flags",
636 665 ev.smbev_flags, sizeof (ev.smbev_flags) * NBBY,
637 666 smbios_evlog_flag_name, smbios_evlog_flag_desc);
638 667
639 668 desc_printf(smbios_evlog_format_desc(ev.smbev_format),
640 669 fp, " Log Header Format: %u", ev.smbev_format);
641 670
642 671 oprintf(fp, " Update Token: 0x%x\n", ev.smbev_token);
643 672 oprintf(fp, " Data Access Address: ");
644 673
645 674 switch (ev.smbev_method) {
646 675 case SMB_EVM_1x1i_1x1d:
647 676 case SMB_EVM_2x1i_1x1d:
648 677 case SMB_EVM_1x2i_1x1d:
649 678 oprintf(fp, "Index Address 0x%x, Data Address 0x%x\n",
650 679 ev.smbev_addr.eva_io.evi_iaddr,
651 680 ev.smbev_addr.eva_io.evi_daddr);
652 681 break;
653 682 case SMB_EVM_GPNV:
654 683 oprintf(fp, "0x%x\n", ev.smbev_addr.eva_gpnv);
655 684 break;
656 685 default:
657 686 oprintf(fp, "0x%x\n", ev.smbev_addr.eva_addr);
658 687 }
659 688
660 689 oprintf(fp, " Type Descriptors:\n");
661 690
662 691 for (i = 0; i < ev.smbev_typec; i++) {
663 692 oprintf(fp, " %u: Log Type 0x%x, Data Type 0x%x\n", i,
664 693 ev.smbev_typev[i].smbevt_ltype,
665 694 ev.smbev_typev[i].smbevt_dtype);
666 695 }
667 696 }
|
↓ open down ↓ |
205 lines elided |
↑ open up ↑ |
668 697
669 698 static void
670 699 print_bytes(const uint8_t *data, size_t size, FILE *fp)
671 700 {
672 701 size_t row, rows = P2ROUNDUP(size, 16) / 16;
673 702 size_t col, cols;
674 703
675 704 char buf[17];
676 705 uint8_t x;
677 706
678 - oprintf(fp, "\n offset: 0 1 2 3 4 5 6 7 8 9 a b c d e f "
707 + oprintf(fp, "\n offset: 0 1 2 3 4 5 6 7 8 9 a b c d e f "
679 708 "0123456789abcdef\n");
680 709
681 710 for (row = 0; row < rows; row++) {
682 - oprintf(fp, " %#4lx: ", (ulong_t)row * 16);
711 + oprintf(fp, " %#4lx: ", (ulong_t)row * 16);
683 712 cols = MIN(size - row * 16, 16);
684 713
685 714 for (col = 0; col < cols; col++) {
686 715 if (col % 4 == 0)
687 716 oprintf(fp, " ");
688 717 x = *data++;
689 718 oprintf(fp, "%02x", x);
690 719 buf[col] = x <= ' ' || x > '~' ? '.' : x;
691 720 }
692 721
693 722 for (; col < 16; col++) {
694 723 if (col % 4 == 0)
695 724 oprintf(fp, " ");
696 725 oprintf(fp, " ");
697 726 buf[col] = ' ';
698 727 }
699 728
700 729 buf[col] = '\0';
701 730 oprintf(fp, " %s\n", buf);
702 731 }
703 732
704 733 oprintf(fp, "\n");
705 734 }
706 735
707 736 static void
708 737 print_memarray(smbios_hdl_t *shp, id_t id, FILE *fp)
709 738 {
710 739 smbios_memarray_t ma;
711 740
712 741 (void) smbios_info_memarray(shp, id, &ma);
713 742
|
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
714 743 desc_printf(smbios_memarray_loc_desc(ma.smbma_location),
715 744 fp, " Location: %u", ma.smbma_location);
716 745
717 746 desc_printf(smbios_memarray_use_desc(ma.smbma_use),
718 747 fp, " Use: %u", ma.smbma_use);
719 748
720 749 desc_printf(smbios_memarray_ecc_desc(ma.smbma_ecc),
721 750 fp, " ECC: %u", ma.smbma_ecc);
722 751
723 752 oprintf(fp, " Number of Slots/Sockets: %u\n", ma.smbma_ndevs);
724 - id_printf(fp, " Memory Error Data: ", ma.smbma_err);
753 + id_printf(fp, " Memory Error Data: ", ma.smbma_err);
725 754 oprintf(fp, " Max Capacity: %llu bytes\n",
726 755 (u_longlong_t)ma.smbma_size);
727 756 }
728 757
729 758 static void
730 759 print_memdevice(smbios_hdl_t *shp, id_t id, FILE *fp)
731 760 {
732 761 smbios_memdevice_t md;
733 762
734 763 (void) smbios_info_memdevice(shp, id, &md);
735 764
736 - id_printf(fp, " Physical Memory Array: ", md.smbmd_array);
737 - id_printf(fp, " Memory Error Data: ", md.smbmd_error);
765 + id_printf(fp, " Physical Memory Array: ", md.smbmd_array);
766 + id_printf(fp, " Memory Error Data: ", md.smbmd_error);
738 767
739 768 if (md.smbmd_twidth != -1u)
740 769 oprintf(fp, " Total Width: %u bits\n", md.smbmd_twidth);
741 770 else
742 771 oprintf(fp, " Total Width: Unknown\n");
743 772
744 773 if (md.smbmd_dwidth != -1u)
745 774 oprintf(fp, " Data Width: %u bits\n", md.smbmd_dwidth);
746 775 else
747 776 oprintf(fp, " Data Width: Unknown\n");
748 777
749 778 switch (md.smbmd_size) {
750 779 case -1ull:
751 780 oprintf(fp, " Size: Unknown\n");
752 781 break;
753 782 case 0:
754 783 oprintf(fp, " Size: Not Populated\n");
755 784 break;
756 785 default:
757 786 oprintf(fp, " Size: %llu bytes\n",
758 787 (u_longlong_t)md.smbmd_size);
759 788 }
760 789
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
761 790 desc_printf(smbios_memdevice_form_desc(md.smbmd_form),
762 791 fp, " Form Factor: %u", md.smbmd_form);
763 792
764 793 if (md.smbmd_set == 0)
765 794 oprintf(fp, " Set: None\n");
766 795 else if (md.smbmd_set == (uint8_t)-1u)
767 796 oprintf(fp, " Set: Unknown\n");
768 797 else
769 798 oprintf(fp, " Set: %u\n", md.smbmd_set);
770 799
800 + if (md.smbmd_rank != 0) {
801 + desc_printf(smbios_memdevice_rank_desc(md.smbmd_rank),
802 + fp, " Rank: %u", md.smbmd_rank);
803 + } else {
804 + oprintf(fp, " Rank: Unknown\n");
805 + }
806 +
771 807 desc_printf(smbios_memdevice_type_desc(md.smbmd_type),
772 808 fp, " Memory Type: %u", md.smbmd_type);
773 809
774 810 flag_printf(fp, "Flags", md.smbmd_flags, sizeof (md.smbmd_flags) * NBBY,
775 811 smbios_memdevice_flag_name, smbios_memdevice_flag_desc);
776 812
777 813 if (md.smbmd_speed != 0)
778 - oprintf(fp, " Speed: %uns\n", md.smbmd_speed);
814 + oprintf(fp, " Speed: %u MHz\n", md.smbmd_speed);
779 815 else
780 816 oprintf(fp, " Speed: Unknown\n");
781 817
818 + if (md.smbmd_clkspeed != 0)
819 + oprintf(fp, " Configured Speed: %u MHz\n", md.smbmd_clkspeed);
820 + else
821 + oprintf(fp, " Configured Speed: Unknown\n");
822 +
782 823 oprintf(fp, " Device Locator: %s\n", md.smbmd_dloc);
783 824 oprintf(fp, " Bank Locator: %s\n", md.smbmd_bloc);
825 +
826 + if (md.smbmd_minvolt != 0) {
827 + oprintf(fp, " Minimum Voltage: %.2fV\n",
828 + md.smbmd_minvolt / 1000.0);
829 + } else {
830 + oprintf(fp, " Minimum Voltage: Unknown\n");
831 + }
832 +
833 + if (md.smbmd_maxvolt != 0) {
834 + oprintf(fp, " Maximum Voltage: %.2fV\n",
835 + md.smbmd_maxvolt / 1000.0);
836 + } else {
837 + oprintf(fp, " Maximum Voltage: Unknown\n");
838 + }
839 +
840 + if (md.smbmd_confvolt != 0) {
841 + oprintf(fp, " Configured Voltage: %.2fV\n",
842 + md.smbmd_confvolt / 1000.0);
843 + } else {
844 + oprintf(fp, " Configured Voltage: Unknown\n");
845 + }
784 846 }
785 847
786 848 static void
787 849 print_memarrmap(smbios_hdl_t *shp, id_t id, FILE *fp)
788 850 {
789 851 smbios_memarrmap_t ma;
790 852
791 853 (void) smbios_info_memarrmap(shp, id, &ma);
792 854
793 - id_printf(fp, " Physical Memory Array: ", ma.smbmam_array);
855 + id_printf(fp, " Physical Memory Array: ", ma.smbmam_array);
794 856 oprintf(fp, " Devices per Row: %u\n", ma.smbmam_width);
795 857
796 858 oprintf(fp, " Physical Address: 0x%llx\n Size: %llu bytes\n",
797 859 (u_longlong_t)ma.smbmam_addr, (u_longlong_t)ma.smbmam_size);
798 860 }
799 861
800 862 static void
801 863 print_memdevmap(smbios_hdl_t *shp, id_t id, FILE *fp)
802 864 {
803 865 smbios_memdevmap_t md;
804 866
805 867 (void) smbios_info_memdevmap(shp, id, &md);
806 868
807 - id_printf(fp, " Memory Device: ", md.smbmdm_device);
808 - id_printf(fp, " Memory Array Mapped Address: ", md.smbmdm_arrmap);
869 + id_printf(fp, " Memory Device: ", md.smbmdm_device);
870 + id_printf(fp, " Memory Array Mapped Address: ", md.smbmdm_arrmap);
809 871
810 872 oprintf(fp, " Physical Address: 0x%llx\n Size: %llu bytes\n",
811 873 (u_longlong_t)md.smbmdm_addr, (u_longlong_t)md.smbmdm_size);
812 874
813 875 oprintf(fp, " Partition Row Position: %u\n", md.smbmdm_rpos);
814 876 oprintf(fp, " Interleave Position: %u\n", md.smbmdm_ipos);
815 877 oprintf(fp, " Interleave Data Depth: %u\n", md.smbmdm_idepth);
816 878 }
817 879
818 880 static void
819 881 print_hwsec(smbios_hdl_t *shp, FILE *fp)
820 882 {
821 883 smbios_hwsec_t h;
822 884
823 885 (void) smbios_info_hwsec(shp, &h);
824 886
825 887 desc_printf(smbios_hwsec_desc(h.smbh_pwr_ps),
826 888 fp, " Power-On Password Status: %u", h.smbh_pwr_ps);
827 889 desc_printf(smbios_hwsec_desc(h.smbh_kbd_ps),
828 890 fp, " Keyboard Password Status: %u", h.smbh_kbd_ps);
829 891 desc_printf(smbios_hwsec_desc(h.smbh_adm_ps),
830 892 fp, " Administrator Password Status: %u", h.smbh_adm_ps);
831 893 desc_printf(smbios_hwsec_desc(h.smbh_pan_ps),
832 894 fp, " Front Panel Reset Status: %u", h.smbh_pan_ps);
833 895 }
834 896
835 897 static void
836 898 print_boot(smbios_hdl_t *shp, FILE *fp)
837 899 {
838 900 smbios_boot_t b;
839 901
840 902 (void) smbios_info_boot(shp, &b);
841 903
842 904 desc_printf(smbios_boot_desc(b.smbt_status),
843 905 fp, " Boot Status Code: 0x%x", b.smbt_status);
844 906
845 907 if (b.smbt_size != 0) {
846 908 oprintf(fp, " Boot Data (%lu bytes):\n", (ulong_t)b.smbt_size);
847 909 print_bytes(b.smbt_data, b.smbt_size, fp);
848 910 }
849 911 }
850 912
851 913 static void
852 914 print_ipmi(smbios_hdl_t *shp, FILE *fp)
853 915 {
854 916 smbios_ipmi_t i;
855 917
856 918 (void) smbios_info_ipmi(shp, &i);
857 919
858 920 desc_printf(smbios_ipmi_type_desc(i.smbip_type),
859 921 fp, " Type: %u", i.smbip_type);
860 922
861 923 oprintf(fp, " BMC IPMI Version: %u.%u\n",
862 924 i.smbip_vers.smbv_major, i.smbip_vers.smbv_minor);
863 925
864 926 oprintf(fp, " i2c Bus Slave Address: 0x%x\n", i.smbip_i2c);
865 927 oprintf(fp, " NV Storage Device Bus ID: 0x%x\n", i.smbip_bus);
866 928 oprintf(fp, " BMC Base Address: 0x%llx\n", (u_longlong_t)i.smbip_addr);
867 929 oprintf(fp, " Interrupt Number: %u\n", i.smbip_intr);
868 930 oprintf(fp, " Register Spacing: %u\n", i.smbip_regspacing);
869 931
870 932 flag_printf(fp, "Flags", i.smbip_flags, sizeof (i.smbip_flags) * NBBY,
871 933 smbios_ipmi_flag_name, smbios_ipmi_flag_desc);
872 934 }
873 935
874 936 static void
875 937 print_extprocessor(smbios_hdl_t *shp, id_t id, FILE *fp)
876 938 {
877 939 int i;
878 940 smbios_processor_ext_t ep;
879 941
880 942 if (check_oem(shp) != 0)
881 943 return;
882 944
883 945 (void) smbios_info_extprocessor(shp, id, &ep);
884 946
885 947 oprintf(fp, " Processor: %u\n", ep.smbpe_processor);
886 948 oprintf(fp, " FRU: %u\n", ep.smbpe_fru);
887 949 oprintf(fp, " Initial APIC ID count: %u\n\n", ep.smbpe_n);
888 950
889 951 for (i = 0; i < ep.smbpe_n; i++) {
890 952 oprintf(fp, " Logical Strand %u: Initial APIC ID: %u\n", i,
891 953 ep.smbpe_apicid[i]);
892 954 }
893 955 }
894 956
895 957 static void
896 958 print_extport(smbios_hdl_t *shp, id_t id, FILE *fp)
897 959 {
898 960 smbios_port_ext_t epo;
899 961
900 962 if (check_oem(shp) != 0)
901 963 return;
902 964
903 965 (void) smbios_info_extport(shp, id, &epo);
904 966
905 967 oprintf(fp, " Chassis Handle: %u\n", epo.smbporte_chassis);
906 968 oprintf(fp, " Port Connector Handle: %u\n", epo.smbporte_port);
907 969 oprintf(fp, " Device Type: %u\n", epo.smbporte_dtype);
908 970 oprintf(fp, " Device Handle: %u\n", epo.smbporte_devhdl);
909 971 oprintf(fp, " PHY: %u\n", epo.smbporte_phy);
910 972 }
911 973
912 974 static void
913 975 print_pciexrc(smbios_hdl_t *shp, id_t id, FILE *fp)
914 976 {
915 977 smbios_pciexrc_t pcie;
916 978
917 979 if (check_oem(shp) != 0)
918 980 return;
919 981
920 982 (void) smbios_info_pciexrc(shp, id, &pcie);
921 983
922 984 oprintf(fp, " Component ID: %u\n", pcie.smbpcie_bb);
923 985 oprintf(fp, " BDF: 0x%x\n", pcie.smbpcie_bdf);
924 986 }
925 987
926 988 static void
927 989 print_extmemarray(smbios_hdl_t *shp, id_t id, FILE *fp)
928 990 {
929 991 smbios_memarray_ext_t em;
930 992
931 993 if (check_oem(shp) != 0)
932 994 return;
933 995
934 996 (void) smbios_info_extmemarray(shp, id, &em);
935 997
936 998 oprintf(fp, " Physical Memory Array Handle: %u\n", em.smbmae_ma);
937 999 oprintf(fp, " Component Parent Handle: %u\n", em.smbmae_comp);
938 1000 oprintf(fp, " BDF: 0x%x\n", em.smbmae_bdf);
939 1001 }
940 1002
941 1003 static void
942 1004 print_extmemdevice(smbios_hdl_t *shp, id_t id, FILE *fp)
943 1005 {
944 1006 int i;
945 1007 smbios_memdevice_ext_t emd;
946 1008
947 1009 if (check_oem(shp) != 0)
948 1010 return;
949 1011
950 1012 (void) smbios_info_extmemdevice(shp, id, &emd);
951 1013
952 1014 oprintf(fp, " Memory Device Handle: %u\n", emd.smbmdeve_md);
953 1015 oprintf(fp, " DRAM Channel: %u\n", emd.smbmdeve_drch);
954 1016 oprintf(fp, " Number of Chip Selects: %u\n", emd.smbmdeve_ncs);
955 1017
956 1018 for (i = 0; i < emd.smbmdeve_ncs; i++) {
957 1019 oprintf(fp, " Chip Select: %u\n", emd.smbmdeve_cs[i]);
958 1020 }
959 1021 }
960 1022
961 1023 static int
962 1024 print_struct(smbios_hdl_t *shp, const smbios_struct_t *sp, void *fp)
963 1025 {
964 1026 smbios_info_t info;
965 1027 int hex = opt_x;
966 1028 const char *s;
967 1029
968 1030 if (opt_t != -1 && opt_t != sp->smbstr_type)
969 1031 return (0); /* skip struct if type doesn't match -t */
970 1032
971 1033 if (!opt_O && (sp->smbstr_type == SMB_TYPE_MEMCTL ||
|
↓ open down ↓ |
153 lines elided |
↑ open up ↑ |
972 1034 sp->smbstr_type == SMB_TYPE_MEMMOD))
973 1035 return (0); /* skip struct if type is obsolete */
974 1036
975 1037 if (g_hdr++ == 0 || !opt_s)
976 1038 oprintf(fp, "%-5s %-4s %s\n", "ID", "SIZE", "TYPE");
977 1039
978 1040 oprintf(fp, "%-5u %-4lu",
979 1041 (uint_t)sp->smbstr_id, (ulong_t)sp->smbstr_size);
980 1042
981 1043 if ((s = smbios_type_name(sp->smbstr_type)) != NULL)
982 - oprintf(fp, " %s", s);
1044 + oprintf(fp, " (%u) %s", sp->smbstr_type, s);
983 1045 else if (sp->smbstr_type > SMB_TYPE_OEM_LO &&
984 1046 sp->smbstr_type < SMB_TYPE_OEM_HI)
985 - oprintf(fp, " %s+%u", "SMB_TYPE_OEM_LO",
1047 + oprintf(fp, " (%u) %s+%u", sp->smbstr_type, "SMB_TYPE_OEM_LO",
986 1048 sp->smbstr_type - SMB_TYPE_OEM_LO);
987 1049 else
988 1050 oprintf(fp, " %u", sp->smbstr_type);
989 1051
990 1052 if ((s = smbios_type_desc(sp->smbstr_type)) != NULL)
991 1053 oprintf(fp, " (%s)\n", s);
992 1054 else
993 1055 oprintf(fp, "\n");
994 1056
995 1057 if (opt_s)
996 1058 return (0); /* only print header line if -s specified */
997 1059
998 1060 if (smbios_info_common(shp, sp->smbstr_id, &info) == 0) {
999 1061 oprintf(fp, "\n");
1000 1062 print_common(&info, fp);
1001 1063 }
1002 1064
1003 1065 switch (sp->smbstr_type) {
1004 1066 case SMB_TYPE_BIOS:
1005 1067 oprintf(fp, "\n");
1006 1068 print_bios(shp, fp);
1007 1069 break;
1008 1070 case SMB_TYPE_SYSTEM:
1009 1071 oprintf(fp, "\n");
1010 1072 print_system(shp, fp);
1011 1073 break;
1012 1074 case SMB_TYPE_BASEBOARD:
1013 1075 oprintf(fp, "\n");
1014 1076 print_bboard(shp, sp->smbstr_id, fp);
1015 1077 break;
1016 1078 case SMB_TYPE_CHASSIS:
1017 1079 oprintf(fp, "\n");
1018 1080 print_chassis(shp, sp->smbstr_id, fp);
1019 1081 break;
1020 1082 case SMB_TYPE_PROCESSOR:
1021 1083 oprintf(fp, "\n");
1022 1084 print_processor(shp, sp->smbstr_id, fp);
1023 1085 break;
1024 1086 case SMB_TYPE_CACHE:
1025 1087 oprintf(fp, "\n");
1026 1088 print_cache(shp, sp->smbstr_id, fp);
1027 1089 break;
1028 1090 case SMB_TYPE_PORT:
1029 1091 oprintf(fp, "\n");
1030 1092 print_port(shp, sp->smbstr_id, fp);
1031 1093 break;
1032 1094 case SMB_TYPE_SLOT:
1033 1095 oprintf(fp, "\n");
1034 1096 print_slot(shp, sp->smbstr_id, fp);
1035 1097 break;
1036 1098 case SMB_TYPE_OBDEVS:
1037 1099 oprintf(fp, "\n");
1038 1100 print_obdevs(shp, sp->smbstr_id, fp);
1039 1101 break;
1040 1102 case SMB_TYPE_OEMSTR:
1041 1103 case SMB_TYPE_SYSCONFSTR:
1042 1104 oprintf(fp, "\n");
1043 1105 print_strtab(shp, sp->smbstr_id, fp);
1044 1106 break;
1045 1107 case SMB_TYPE_LANG:
1046 1108 oprintf(fp, "\n");
1047 1109 print_lang(shp, sp->smbstr_id, fp);
1048 1110 break;
1049 1111 case SMB_TYPE_EVENTLOG:
1050 1112 oprintf(fp, "\n");
1051 1113 print_evlog(shp, sp->smbstr_id, fp);
1052 1114 break;
1053 1115 case SMB_TYPE_MEMARRAY:
1054 1116 oprintf(fp, "\n");
1055 1117 print_memarray(shp, sp->smbstr_id, fp);
1056 1118 break;
1057 1119 case SMB_TYPE_MEMDEVICE:
1058 1120 oprintf(fp, "\n");
1059 1121 print_memdevice(shp, sp->smbstr_id, fp);
1060 1122 break;
1061 1123 case SMB_TYPE_MEMARRAYMAP:
1062 1124 oprintf(fp, "\n");
1063 1125 print_memarrmap(shp, sp->smbstr_id, fp);
1064 1126 break;
1065 1127 case SMB_TYPE_MEMDEVICEMAP:
1066 1128 oprintf(fp, "\n");
1067 1129 print_memdevmap(shp, sp->smbstr_id, fp);
1068 1130 break;
1069 1131 case SMB_TYPE_SECURITY:
1070 1132 oprintf(fp, "\n");
1071 1133 print_hwsec(shp, fp);
1072 1134 break;
1073 1135 case SMB_TYPE_BOOT:
1074 1136 oprintf(fp, "\n");
1075 1137 print_boot(shp, fp);
1076 1138 break;
1077 1139 case SMB_TYPE_IPMIDEV:
1078 1140 oprintf(fp, "\n");
1079 1141 print_ipmi(shp, fp);
1080 1142 break;
1081 1143 case SMB_TYPE_OBDEVEXT:
1082 1144 oprintf(fp, "\n");
1083 1145 print_obdevs_ext(shp, sp->smbstr_id, fp);
1084 1146 break;
1085 1147 case SUN_OEM_EXT_PROCESSOR:
1086 1148 oprintf(fp, "\n");
1087 1149 print_extprocessor(shp, sp->smbstr_id, fp);
1088 1150 break;
1089 1151 case SUN_OEM_EXT_PORT:
1090 1152 oprintf(fp, "\n");
1091 1153 print_extport(shp, sp->smbstr_id, fp);
1092 1154 break;
1093 1155 case SUN_OEM_PCIEXRC:
1094 1156 oprintf(fp, "\n");
1095 1157 print_pciexrc(shp, sp->smbstr_id, fp);
1096 1158 break;
1097 1159 case SUN_OEM_EXT_MEMARRAY:
1098 1160 oprintf(fp, "\n");
1099 1161 print_extmemarray(shp, sp->smbstr_id, fp);
1100 1162 break;
1101 1163 case SUN_OEM_EXT_MEMDEVICE:
1102 1164 oprintf(fp, "\n");
1103 1165 print_extmemdevice(shp, sp->smbstr_id, fp);
1104 1166 break;
1105 1167 default:
1106 1168 hex++;
1107 1169 }
1108 1170
1109 1171 if (hex)
1110 1172 print_bytes(sp->smbstr_data, sp->smbstr_size, fp);
1111 1173 else
1112 1174 oprintf(fp, "\n");
1113 1175
1114 1176 return (0);
1115 1177 }
1116 1178
1117 1179 static uint16_t
1118 1180 getu16(const char *name, const char *s)
1119 1181 {
1120 1182 u_longlong_t val;
1121 1183 char *p;
1122 1184
1123 1185 errno = 0;
1124 1186 val = strtoull(s, &p, 0);
1125 1187
1126 1188 if (errno != 0 || p == s || *p != '\0' || val > UINT16_MAX) {
1127 1189 (void) fprintf(stderr, "%s: invalid %s argument -- %s\n",
1128 1190 g_pname, name, s);
1129 1191 exit(SMBIOS_USAGE);
1130 1192 }
1131 1193
1132 1194 return ((uint16_t)val);
1133 1195 }
1134 1196
1135 1197 static uint16_t
1136 1198 getstype(const char *name, const char *s)
1137 1199 {
1138 1200 const char *ts;
1139 1201 uint16_t t;
1140 1202
1141 1203 for (t = 0; t < SMB_TYPE_OEM_LO; t++) {
1142 1204 if ((ts = smbios_type_name(t)) != NULL && strcmp(s, ts) == 0)
1143 1205 return (t);
1144 1206 }
1145 1207
1146 1208 (void) fprintf(stderr, "%s: invalid %s argument -- %s\n",
1147 1209 g_pname, name, s);
1148 1210
1149 1211 exit(SMBIOS_USAGE);
1150 1212 /*NOTREACHED*/
1151 1213 }
1152 1214
1153 1215 static int
1154 1216 usage(FILE *fp)
1155 1217 {
1156 1218 (void) fprintf(fp, "Usage: %s "
1157 1219 "[-BeOsx] [-i id] [-t type] [-w file] [file]\n\n", g_pname);
1158 1220
1159 1221 (void) fprintf(fp,
1160 1222 "\t-B disable header validation for broken BIOSes\n"
1161 1223 "\t-e display SMBIOS entry point information\n"
1162 1224 "\t-i display only the specified structure\n"
1163 1225 "\t-O display obsolete structure types\n"
1164 1226 "\t-s display only a summary of structure identifiers and types\n"
1165 1227 "\t-t display only the specified structure type\n"
1166 1228 "\t-w write the raw data to the specified file\n"
1167 1229 "\t-x display raw data for structures\n");
1168 1230
1169 1231 return (SMBIOS_USAGE);
1170 1232 }
1171 1233
1172 1234 int
1173 1235 main(int argc, char *argv[])
1174 1236 {
1175 1237 const char *ifile = NULL;
1176 1238 const char *ofile = NULL;
1177 1239 int oflags = 0;
1178 1240
1179 1241 smbios_hdl_t *shp;
1180 1242 smbios_struct_t s;
1181 1243 int err, fd, c;
1182 1244 char *p;
1183 1245
1184 1246 if ((p = strrchr(argv[0], '/')) == NULL)
1185 1247 g_pname = argv[0];
1186 1248 else
1187 1249 g_pname = p + 1;
1188 1250
1189 1251 while (optind < argc) {
1190 1252 while ((c = getopt(argc, argv, "Bei:Ost:w:xZ")) != EOF) {
1191 1253 switch (c) {
1192 1254 case 'B':
1193 1255 oflags |= SMB_O_NOCKSUM | SMB_O_NOVERS;
1194 1256 break;
1195 1257 case 'e':
1196 1258 opt_e++;
1197 1259 break;
1198 1260 case 'i':
1199 1261 opt_i = getu16("struct ID", optarg);
1200 1262 break;
1201 1263 case 'O':
1202 1264 opt_O++;
1203 1265 break;
1204 1266 case 's':
1205 1267 opt_s++;
1206 1268 break;
1207 1269 case 't':
1208 1270 if (isdigit(optarg[0]))
1209 1271 opt_t = getu16("struct type", optarg);
1210 1272 else
1211 1273 opt_t = getstype("struct type", optarg);
1212 1274 break;
1213 1275 case 'w':
1214 1276 ofile = optarg;
1215 1277 break;
1216 1278 case 'x':
1217 1279 opt_x++;
1218 1280 break;
1219 1281 case 'Z':
1220 1282 oflags |= SMB_O_ZIDS; /* undocumented */
1221 1283 break;
1222 1284 default:
1223 1285 return (usage(stderr));
1224 1286 }
1225 1287 }
1226 1288
1227 1289 if (optind < argc) {
1228 1290 if (ifile != NULL) {
1229 1291 (void) fprintf(stderr, "%s: illegal "
1230 1292 "argument -- %s\n", g_pname, argv[optind]);
1231 1293 return (SMBIOS_USAGE);
1232 1294 }
1233 1295 ifile = argv[optind++];
1234 1296 }
1235 1297 }
1236 1298
1237 1299 if ((shp = smbios_open(ifile, SMB_VERSION, oflags, &err)) == NULL) {
1238 1300 (void) fprintf(stderr, "%s: failed to load SMBIOS: %s\n",
1239 1301 g_pname, smbios_errmsg(err));
1240 1302 return (SMBIOS_ERROR);
1241 1303 }
1242 1304
1243 1305 if (ofile != NULL) {
1244 1306 if ((fd = open(ofile, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) {
1245 1307 (void) fprintf(stderr, "%s: failed to open %s: %s\n",
1246 1308 g_pname, ofile, strerror(errno));
1247 1309 err = SMBIOS_ERROR;
1248 1310 } else if (smbios_write(shp, fd) != 0) {
1249 1311 (void) fprintf(stderr, "%s: failed to write %s: %s\n",
1250 1312 g_pname, ofile, smbios_errmsg(smbios_errno(shp)));
1251 1313 err = SMBIOS_ERROR;
1252 1314 }
1253 1315 smbios_close(shp);
1254 1316 return (err);
1255 1317 }
1256 1318
1257 1319 if (opt_e) {
1258 1320 print_smbios(shp, stdout);
1259 1321 smbios_close(shp);
1260 1322 return (SMBIOS_SUCCESS);
1261 1323 }
1262 1324
1263 1325 if (opt_O && (opt_i != -1 || opt_t != -1))
1264 1326 opt_O++; /* -i or -t imply displaying obsolete records */
1265 1327
1266 1328 if (opt_i != -1)
1267 1329 err = smbios_lookup_id(shp, opt_i, &s);
1268 1330 else
1269 1331 err = smbios_iter(shp, print_struct, stdout);
1270 1332
1271 1333 if (err != 0) {
1272 1334 (void) fprintf(stderr, "%s: failed to access SMBIOS: %s\n",
1273 1335 g_pname, smbios_errmsg(smbios_errno(shp)));
1274 1336 smbios_close(shp);
1275 1337 return (SMBIOS_ERROR);
1276 1338 }
1277 1339
1278 1340 if (opt_i != -1)
1279 1341 (void) print_struct(shp, &s, stdout);
1280 1342
1281 1343 smbios_close(shp);
1282 1344 return (SMBIOS_SUCCESS);
1283 1345 }
|
↓ open down ↓ |
288 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX