| @@ -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 | |
47 | static int platform_dminode = CTL_EOL; | | 47 | static int platform_dminode = CTL_EOL; |
48 | | | 48 | |
49 | void platform_init(void); /* XXX */ | | 49 | void platform_init(void); /* XXX */ |
50 | static void platform_add(struct smbtable *, const char *, int); | | 50 | static void platform_add(struct smbtable *, const char *, int); |
| | | 51 | static void platform_add_word(struct smbtable *, const char *, uint16_t, |
| | | 52 | const char *); |
51 | static void platform_add_date(struct smbtable *, const char *, int); | | 53 | static void platform_add_date(struct smbtable *, const char *, int); |
52 | static void platform_add_uuid(struct smbtable *, const char *, | | 54 | static void platform_add_uuid(struct smbtable *, const char *, |
53 | const uint8_t *); | | 55 | const uint8_t *); |
54 | static int platform_dmi_sysctl(SYSCTLFN_PROTO); | | 56 | static int platform_dmi_sysctl(SYSCTLFN_PROTO); |
55 | static void platform_print(void); | | 57 | static void platform_print(void); |
56 | | | 58 | |
57 | /* list of private DMI sysctl nodes */ | | 59 | /* list of private DMI sysctl nodes */ |
58 | static const char *platform_private_nodes[] = { | | 60 | static 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 | |
65 | void | | 68 | void |
66 | platform_init(void) | | 69 | platform_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 |
191 | platform_add(struct smbtable *tbl, const char *key, int idx) | | 217 | platform_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 | |
| | | 230 | static void |
| | | 231 | platform_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 | |
204 | static int | | 245 | static int |
205 | platform_scan_date(char *buf, unsigned int *month, unsigned int *day, | | 246 | platform_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; |