Tue Dec 25 16:45:03 2018 UTC ()
Expose more DMI variables via sysctl.


(mlelstv)
diff -r1.4 -r1.5 src/sys/arch/x86/include/smbiosvar.h
diff -r1.15 -r1.16 src/sys/arch/x86/x86/platform.c

cvs diff -r1.4 -r1.5 src/sys/arch/x86/include/Attic/smbiosvar.h (expand / switch to unified diff)

--- src/sys/arch/x86/include/Attic/smbiosvar.h 2017/03/11 07:21:10 1.4
+++ src/sys/arch/x86/include/Attic/smbiosvar.h 2018/12/25 16:45:02 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: smbiosvar.h,v 1.4 2017/03/11 07:21:10 nonaka Exp $ */ 1/* $NetBSD: smbiosvar.h,v 1.5 2018/12/25 16:45:02 mlelstv Exp $ */
2/* 2/*
3 * Copyright (c) 2006 Gordon Willem Klok <gklok@cogeco.ca> 3 * Copyright (c) 2006 Gordon Willem Klok <gklok@cogeco.ca>
4 * Copyright (c) 2005 Jordan Hargrave 4 * Copyright (c) 2005 Jordan Hargrave
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -175,35 +175,88 @@ struct smbios_sys { @@ -175,35 +175,88 @@ struct smbios_sys {
175 uint8_t sku; /* string */ 175 uint8_t sku; /* string */
176 uint8_t family; /* string */ 176 uint8_t family; /* string */
177} __packed; 177} __packed;
178 178
179/* 179/*
180 * SMBIOS Structure Type 2 "Base Board (Module) Information" 180 * SMBIOS Structure Type 2 "Base Board (Module) Information"
181 * DMTF Specification DSP0134 Section 3.3.3 p.g. 37 181 * DMTF Specification DSP0134 Section 3.3.3 p.g. 37
182 */ 182 */
183struct smbios_board { 183struct smbios_board {
184 uint8_t vendor; /* string */ 184 uint8_t vendor; /* string */
185 uint8_t product; /* string */ 185 uint8_t product; /* string */
186 uint8_t version; /* string */ 186 uint8_t version; /* string */
187 uint8_t serial; /* string */ 187 uint8_t serial; /* string */
188 uint8_t asset; /* stirng */ 188 uint8_t asset; /* string */
189 uint8_t feature; /* feature flags */ 189 uint8_t feature; /* feature flags */
190 uint8_t location; /* location in chassis */ 190 uint8_t location; /* location in chassis */
191 uint16_t handle; /* chassis handle */ 191 uint16_t handle; /* chassis handle */
192 uint8_t type; /* board type */ 192 uint8_t type; /* board type */
193 uint8_t noc; /* number of contained objects */ 193 uint8_t noc; /* number of contained objects */
194} __packed; 194} __packed;
195 195
196/* 196/*
 197 * SMBIOS Structure Type 3 "System Enclosure or Chassis"
 198 * DMTF Specification DSP0134 Section 3.1.1 p.g. 37
 199 */
 200struct smbios_chassis {
 201 uint8_t vendor; /* string */
 202 uint8_t shape;
 203 uint8_t version; /* string */
 204 uint8_t serial; /* string */
 205 uint8_t asset; /* string */
 206 uint8_t bustate;
 207 uint8_t psstate;
 208 uint8_t thstate;
 209 uint8_t security;
 210 uint32_t oemdata;
 211 uint8_t height;
 212 uint8_t powercords;
 213 uint8_t noc; /* number of contained objects */
 214} __packed;
 215
 216/*
 217 * SMBIOS Structure Type 4 "Processor Information"
 218 * DMTF Specification DSP0134 Section 3.1.1 p.g. 42
 219 */
 220struct smbios_processor {
 221 uint8_t socket; /* string */
 222 uint8_t type;
 223 uint8_t family;
 224 uint8_t vendor; /* string */
 225 uint64_t cpuid;
 226 uint8_t version; /* string */
 227 uint8_t voltage;
 228 uint16_t clkspeed;
 229 uint16_t maxspeed;
 230 uint16_t curspeed;
 231 uint8_t status;
 232 uint8_t upgrade;
 233 uint8_t l1cache;
 234 uint8_t l2cache;
 235 uint8_t l3cache;
 236 uint8_t serial; /* string */
 237 uint8_t asset; /* string */
 238 uint8_t part; /* string */
 239 uint8_t cores; /* cores per socket */
 240 uint8_t enabled; /* enabled cores per socket */
 241 uint8_t threads; /* threads per socket */
 242 uint16_t characteristics;
 243 uint16_t family2; /* for values >= 255 */
 244 uint16_t cores2; /* for values >= 255 */
 245 uint16_t enabled2; /* for values >= 255 */
 246 uint16_t threads2; /* for values >= 255 */
 247} __packed;
 248
 249/*
197 * SMBIOS Structure Type 9 "Expansion slot" 250 * SMBIOS Structure Type 9 "Expansion slot"
198 */ 251 */
199struct smbios_slot { 252struct smbios_slot {
200 uint8_t designation; 253 uint8_t designation;
201 uint8_t type; 254 uint8_t type;
202 uint8_t width; 255 uint8_t width;
203 uint8_t usage; 256 uint8_t usage;
204 uint8_t length; 257 uint8_t length;
205 uint8_t slotid[2]; 258 uint8_t slotid[2];
206 uint8_t characteristics[2]; 259 uint8_t characteristics[2];
207} __packed; 260} __packed;
208 261
209#define SMBIOS_SLOT_ISA 0x03 262#define SMBIOS_SLOT_ISA 0x03

cvs diff -r1.15 -r1.16 src/sys/arch/x86/x86/Attic/platform.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/Attic/platform.c 2014/03/26 08:04:19 1.15
+++ src/sys/arch/x86/x86/Attic/platform.c 2018/12/25 16:45:02 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: platform.c,v 1.15 2014/03/26 08:04:19 christos Exp $ */ 1/* $NetBSD: platform.c,v 1.16 2018/12/25 16:45:02 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2007 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -19,66 +19,71 @@ @@ -19,66 +19,71 @@
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29#include "isa.h" 29#include "isa.h"
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.15 2014/03/26 08:04:19 christos Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: platform.c,v 1.16 2018/12/25 16:45:02 mlelstv Exp $");
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/kernel.h> 36#include <sys/kernel.h>
37#include <sys/sysctl.h> 37#include <sys/sysctl.h>
38#include <sys/uuid.h> 38#include <sys/uuid.h>
39#include <sys/pmf.h> 39#include <sys/pmf.h>
40 40
41#if NISA > 0 41#if NISA > 0
42#include <dev/isa/isavar.h> 42#include <dev/isa/isavar.h>
43#endif 43#endif
44 44
45#include <arch/x86/include/smbiosvar.h> 45#include <arch/x86/include/smbiosvar.h>
46 46
47static int platform_dminode = CTL_EOL; 47static int platform_dminode = CTL_EOL;
48 48
49void platform_init(void); /* XXX */ 49void platform_init(void); /* XXX */
50static void platform_add(struct smbtable *, const char *, int); 50static void platform_add(struct smbtable *, const char *, int);
 51static void platform_add_word(struct smbtable *, const char *, uint16_t,
 52 const char *);
51static void platform_add_date(struct smbtable *, const char *, int); 53static void platform_add_date(struct smbtable *, const char *, int);
52static void platform_add_uuid(struct smbtable *, const char *, 54static void platform_add_uuid(struct smbtable *, const char *,
53 const uint8_t *); 55 const uint8_t *);
54static int platform_dmi_sysctl(SYSCTLFN_PROTO); 56static int platform_dmi_sysctl(SYSCTLFN_PROTO);
55static void platform_print(void); 57static void platform_print(void);
56 58
57/* list of private DMI sysctl nodes */ 59/* list of private DMI sysctl nodes */
58static const char *platform_private_nodes[] = { 60static const char *platform_private_nodes[] = {
 61 "chassis-serial",
59 "board-serial", 62 "board-serial",
60 "system-serial", 63 "system-serial",
61 "system-uuid", 64 "system-uuid",
62 NULL 65 NULL
63}; 66};
64 67
65void 68void
66platform_init(void) 69platform_init(void)
67{ 70{
68 struct smbtable smbios; 71 struct smbtable smbios;
69 struct smbios_sys *psys; 72 struct smbios_sys *psys;
70 struct smbios_struct_bios *pbios; 73 struct smbios_struct_bios *pbios;
71 struct smbios_board *pboard; 74 struct smbios_board *pboard;
 75 struct smbios_chassis *pchassis;
 76 struct smbios_processor *pproc;
72 struct smbios_slot *pslot; 77 struct smbios_slot *pslot;
73 int nisa, nother; 78 int nisa, nother;
74 79
75 smbios.cookie = 0; 80 smbios.cookie = 0;
76 if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) { 81 if (smbios_find_table(SMBIOS_TYPE_SYSTEM, &smbios)) {
77 psys = smbios.tblhdr; 82 psys = smbios.tblhdr;
78 83
79 platform_add(&smbios, "system-vendor", psys->vendor); 84 platform_add(&smbios, "system-vendor", psys->vendor);
80 platform_add(&smbios, "system-product", psys->product); 85 platform_add(&smbios, "system-product", psys->product);
81 platform_add(&smbios, "system-version", psys->version); 86 platform_add(&smbios, "system-version", psys->version);
82 platform_add(&smbios, "system-serial", psys->serial); 87 platform_add(&smbios, "system-serial", psys->serial);
83 platform_add_uuid(&smbios, "system-uuid", psys->uuid); 88 platform_add_uuid(&smbios, "system-uuid", psys->uuid);
84 } 89 }
@@ -94,26 +99,47 @@ platform_init(void) @@ -94,26 +99,47 @@ platform_init(void)
94 99
95 smbios.cookie = 0; 100 smbios.cookie = 0;
96 if (smbios_find_table(SMBIOS_TYPE_BASEBOARD, &smbios)) { 101 if (smbios_find_table(SMBIOS_TYPE_BASEBOARD, &smbios)) {
97 pboard = smbios.tblhdr; 102 pboard = smbios.tblhdr;
98 103
99 platform_add(&smbios, "board-vendor", pboard->vendor); 104 platform_add(&smbios, "board-vendor", pboard->vendor);
100 platform_add(&smbios, "board-product", pboard->product); 105 platform_add(&smbios, "board-product", pboard->product);
101 platform_add(&smbios, "board-version", pboard->version); 106 platform_add(&smbios, "board-version", pboard->version);
102 platform_add(&smbios, "board-serial", pboard->serial); 107 platform_add(&smbios, "board-serial", pboard->serial);
103 platform_add(&smbios, "board-asset-tag", pboard->asset); 108 platform_add(&smbios, "board-asset-tag", pboard->asset);
104 } 109 }
105 110
106 smbios.cookie = 0; 111 smbios.cookie = 0;
 112 if (smbios_find_table(SMBIOS_TYPE_ENCLOSURE, &smbios)) {
 113 pchassis = smbios.tblhdr;
 114
 115 platform_add(&smbios, "chassis-vendor", pchassis->vendor);
 116 platform_add(&smbios, "chassis-type", pchassis->shape);
 117 platform_add(&smbios, "chassis-version", pchassis->version);
 118 platform_add(&smbios, "chassis-serial", pchassis->serial);
 119 platform_add(&smbios, "chassis-asset-tag", pchassis->asset);
 120 }
 121
 122 smbios.cookie = 0;
 123 if (smbios_find_table(SMBIOS_TYPE_PROCESSOR, &smbios)) {
 124 pproc = smbios.tblhdr;
 125
 126 platform_add(&smbios, "processor-vendor", pproc->vendor);
 127 platform_add(&smbios, "processor-version", pproc->version);
 128 platform_add_word(&smbios, "processor-frequency",
 129 pproc->curspeed, " MHz");
 130 }
 131
 132 smbios.cookie = 0;
107 nisa = 0; 133 nisa = 0;
108 nother = 0; 134 nother = 0;
109 while (smbios_find_table(SMBIOS_TYPE_SLOTS, &smbios)) { 135 while (smbios_find_table(SMBIOS_TYPE_SLOTS, &smbios)) {
110 pslot = smbios.tblhdr; 136 pslot = smbios.tblhdr;
111 switch (pslot->type) { 137 switch (pslot->type) {
112 case SMBIOS_SLOT_ISA: 138 case SMBIOS_SLOT_ISA:
113 case SMBIOS_SLOT_EISA: 139 case SMBIOS_SLOT_EISA:
114 nisa++; 140 nisa++;
115 break; 141 break;
116 default: 142 default:
117 nother++; 143 nother++;
118 break; 144 break;
119 } 145 }
@@ -191,26 +217,41 @@ static void @@ -191,26 +217,41 @@ static void
191platform_add(struct smbtable *tbl, const char *key, int idx) 217platform_add(struct smbtable *tbl, const char *key, int idx)
192{ 218{
193 char tmpbuf[128]; /* XXX is this long enough? */ 219 char tmpbuf[128]; /* XXX is this long enough? */
194 220
195 if (smbios_get_string(tbl, idx, tmpbuf, 128) != NULL) { 221 if (smbios_get_string(tbl, idx, tmpbuf, 128) != NULL) {
196 /* add to platform dictionary */ 222 /* add to platform dictionary */
197 pmf_set_platform(key, tmpbuf); 223 pmf_set_platform(key, tmpbuf);
198 224
199 /* create sysctl node */ 225 /* create sysctl node */
200 platform_create_sysctl(key); 226 platform_create_sysctl(key);
201 } 227 }
202} 228}
203 229
 230static void
 231platform_add_word(struct smbtable *tbl, const char *key, uint16_t val,
 232 const char *suf)
 233{
 234 char tmpbuf[128]; /* XXX is this long enough? */
 235
 236 if (snprintf(tmpbuf, sizeof(tmpbuf), "%u%s", val, suf)) {
 237 /* add to platform dictionary */
 238 pmf_set_platform(key, tmpbuf);
 239
 240 /* create sysctl node */
 241 platform_create_sysctl(key);
 242 }
 243}
 244
204static int 245static int
205platform_scan_date(char *buf, unsigned int *month, unsigned int *day, 246platform_scan_date(char *buf, unsigned int *month, unsigned int *day,
206 unsigned int *year) 247 unsigned int *year)
207{ 248{
208 char *p, *s; 249 char *p, *s;
209 250
210 s = buf; 251 s = buf;
211 p = strchr(s, '/'); 252 p = strchr(s, '/');
212 if (p) *p = '\0'; 253 if (p) *p = '\0';
213 *month = strtoul(s, NULL, 10); 254 *month = strtoul(s, NULL, 10);
214 if (!p) return 1; 255 if (!p) return 1;
215 256
216 s = p + 1; 257 s = p + 1;