arm.c revision 1.1.4.2 1 1.1.4.2 tls /* $NetBSD: arm.c,v 1.1.4.2 2013/02/25 00:30:42 tls Exp $ */
2 1.1.4.2 tls
3 1.1.4.2 tls /*-
4 1.1.4.2 tls * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.1.4.2 tls * All rights reserved.
6 1.1.4.2 tls *
7 1.1.4.2 tls * This code is derived from software contributed to The NetBSD Foundation
8 1.1.4.2 tls * by Matt Thomas of 3am Software Foundry.
9 1.1.4.2 tls *
10 1.1.4.2 tls * Redistribution and use in source and binary forms, with or without
11 1.1.4.2 tls * modification, are permitted provided that the following conditions
12 1.1.4.2 tls * are met:
13 1.1.4.2 tls * 1. Redistributions of source code must retain the above copyright
14 1.1.4.2 tls * notice, this list of conditions and the following disclaimer.
15 1.1.4.2 tls * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.4.2 tls * notice, this list of conditions and the following disclaimer in the
17 1.1.4.2 tls * documentation and/or other materials provided with the distribution.
18 1.1.4.2 tls *
19 1.1.4.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1.4.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1.4.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1.4.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1.4.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1.4.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1.4.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1.4.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1.4.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1.4.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1.4.2 tls * POSSIBILITY OF SUCH DAMAGE.
30 1.1.4.2 tls */
31 1.1.4.2 tls
32 1.1.4.2 tls #include <sys/cdefs.h>
33 1.1.4.2 tls
34 1.1.4.2 tls #ifndef lint
35 1.1.4.2 tls __RCSID("$NetBSD: arm.c,v 1.1.4.2 2013/02/25 00:30:42 tls Exp $");
36 1.1.4.2 tls #endif /* not lint */
37 1.1.4.2 tls
38 1.1.4.2 tls #include <sys/types.h>
39 1.1.4.2 tls #include <sys/cpuio.h>
40 1.1.4.2 tls #include <sys/sysctl.h>
41 1.1.4.2 tls #include <stdio.h>
42 1.1.4.2 tls #include <stdbool.h>
43 1.1.4.2 tls #include <stdlib.h>
44 1.1.4.2 tls #include <string.h>
45 1.1.4.2 tls #include <inttypes.h>
46 1.1.4.2 tls #include <err.h>
47 1.1.4.2 tls
48 1.1.4.2 tls #include "../cpuctl.h"
49 1.1.4.2 tls
50 1.1.4.2 tls static const char * const id_isar_fieldnames[][8] = {
51 1.1.4.2 tls {
52 1.1.4.2 tls "Swap", "Bitcount", "Bitfield", "CmpBranch",
53 1.1.4.2 tls "Coproc", "Debug", "Divde", NULL
54 1.1.4.2 tls }, {
55 1.1.4.2 tls "Endian", "Except", "Except_AR", "Extend",
56 1.1.4.2 tls "IfThen", "Immediate", "Interwork", "Jazelle"
57 1.1.4.2 tls }, {
58 1.1.4.2 tls "LoadStore", "MemHint", "MultAccessInt", "Mult",
59 1.1.4.2 tls "MultS", "MultU", "PSR_AR", "Reversal"
60 1.1.4.2 tls }, {
61 1.1.4.2 tls "Saturate", "SIMD", "SVC", "SynchPrim",
62 1.1.4.2 tls "TabBranch", "ThumbCopy", "TrueNOP", "ThumbEE_Extn"
63 1.1.4.2 tls }, {
64 1.1.4.2 tls "Unpriv", "WithShifts", "Writeback", "SMC",
65 1.1.4.2 tls "Barrier", "SynchPrim_frac", "PSR_M", "SWP"
66 1.1.4.2 tls }
67 1.1.4.2 tls };
68 1.1.4.2 tls
69 1.1.4.2 tls static const uint8_t id_isar_boolean[] = {
70 1.1.4.2 tls 0x2f, 0xb7, 0x41, 0xf5, 0xfc
71 1.1.4.2 tls };
72 1.1.4.2 tls
73 1.1.4.2 tls static const char * const id_mmfr_fieldnames[][8] = {
74 1.1.4.2 tls {
75 1.1.4.2 tls "VMSA-Support",
76 1.1.4.2 tls "PMSA-Support",
77 1.1.4.2 tls "Outermost-Shareablity",
78 1.1.4.2 tls "Shareability-Levels",
79 1.1.4.2 tls "TCM-Support",
80 1.1.4.2 tls "Auxilary-Registers",
81 1.1.4.2 tls "FCSE-Support",
82 1.1.4.2 tls "Innermost-Shareability"
83 1.1.4.2 tls }, {
84 1.1.4.2 tls "L1-Harvard-Cache-VA",
85 1.1.4.2 tls "L1-Unified-Cache-VA",
86 1.1.4.2 tls "L1-Harvard-Cache-Set/Way",
87 1.1.4.2 tls "L1-Unified-Cache-Set/Way",
88 1.1.4.2 tls "L1-Harvard-Cache",
89 1.1.4.2 tls "L1-Unified-Cache",
90 1.1.4.2 tls "L1-Cache-Test-and-Clean",
91 1.1.4.2 tls "Branch-Predictor",
92 1.1.4.2 tls }, {
93 1.1.4.2 tls "L1-Harvard-Foreground-Fetch",
94 1.1.4.2 tls "L1-Unified-Background-Fetch",
95 1.1.4.2 tls "L1-Harvard-Range",
96 1.1.4.2 tls "Harvard-TLB",
97 1.1.4.2 tls "Unified-TLB",
98 1.1.4.2 tls "Mem-Barrier",
99 1.1.4.2 tls "WFI-Stall",
100 1.1.4.2 tls "HW-Access",
101 1.1.4.2 tls }, {
102 1.1.4.2 tls "Cache-Maintenance-MVA",
103 1.1.4.2 tls "Cache-Maintenance-Set/Way",
104 1.1.4.2 tls "BP-Maintenance",
105 1.1.4.2 tls "Maintenance-Broadcast",
106 1.1.4.2 tls NULL,
107 1.1.4.2 tls "Coherent-Tablewalk",
108 1.1.4.2 tls "Cached-Memory-Size",
109 1.1.4.2 tls "Supersection-Support",
110 1.1.4.2 tls },
111 1.1.4.2 tls };
112 1.1.4.2 tls
113 1.1.4.2 tls static const uint8_t id_mmfr_present[] = {
114 1.1.4.2 tls 0x8c, 0x00, 0x00, 0x68
115 1.1.4.2 tls };
116 1.1.4.2 tls
117 1.1.4.2 tls static const char * const id_pfr_fieldnames[][8] = {
118 1.1.4.2 tls {
119 1.1.4.2 tls "ThumbEE",
120 1.1.4.2 tls "Jazelle",
121 1.1.4.2 tls "Thumb",
122 1.1.4.2 tls "ARM",
123 1.1.4.2 tls }, {
124 1.1.4.2 tls "Programmer",
125 1.1.4.2 tls "Security",
126 1.1.4.2 tls "M-profile",
127 1.1.4.2 tls "Virtualization",
128 1.1.4.2 tls "Generic-Timer",
129 1.1.4.2 tls },
130 1.1.4.2 tls };
131 1.1.4.2 tls
132 1.1.4.2 tls static const char * const id_mvfr_fieldnames[][8] = {
133 1.1.4.2 tls {
134 1.1.4.2 tls "ASIMD-Registers",
135 1.1.4.2 tls "Single-Precision",
136 1.1.4.2 tls "Double-Precision",
137 1.1.4.2 tls "VFP-Exception-Trapping",
138 1.1.4.2 tls "Divide",
139 1.1.4.2 tls "Square-Root",
140 1.1.4.2 tls "Short-Vectors",
141 1.1.4.2 tls "VFP-Rounding-Modes",
142 1.1.4.2 tls }, {
143 1.1.4.2 tls "Flush-To-Zero",
144 1.1.4.2 tls "Default-NaN",
145 1.1.4.2 tls "ASIMD-Load/Store",
146 1.1.4.2 tls "ASIMD-Integer",
147 1.1.4.2 tls "ASIMD-SPFP",
148 1.1.4.2 tls "ASIMD-HPFP",
149 1.1.4.2 tls "VFP-HPFP",
150 1.1.4.2 tls "ASIMD-FMAC",
151 1.1.4.2 tls },
152 1.1.4.2 tls };
153 1.1.4.2 tls
154 1.1.4.2 tls static const uint8_t id_mvfr_present[] = {
155 1.1.4.2 tls 0x80, 0x03,
156 1.1.4.2 tls };
157 1.1.4.2 tls
158 1.1.4.2 tls static void
159 1.1.4.2 tls print_features(const char *cpuname, const char *setname,
160 1.1.4.2 tls const int *id_data, size_t id_len, const char * const id_fieldnames[][8],
161 1.1.4.2 tls size_t id_nfieldnames, const uint8_t *id_boolean, const uint8_t *id_present)
162 1.1.4.2 tls {
163 1.1.4.2 tls char buf[81];
164 1.1.4.2 tls size_t len = 0;
165 1.1.4.2 tls const char *sep = "";
166 1.1.4.2 tls for (size_t i = 0; i < id_len / sizeof(id_data[0]); i++) {
167 1.1.4.2 tls int isar = id_data[i];
168 1.1.4.2 tls for (u_int j = 0; isar != 0 && j < 8; j++, isar >>= 4) {
169 1.1.4.2 tls const char *name = NULL;
170 1.1.4.2 tls const char *value = "";
171 1.1.4.2 tls char namebuf[12], valuebuf[12], tmpbuf[30];
172 1.1.4.2 tls if ((isar & 0x0f) == 0
173 1.1.4.2 tls && (id_present == NULL
174 1.1.4.2 tls || (id_present[i] & (1 << j))) == 0) {
175 1.1.4.2 tls continue;
176 1.1.4.2 tls }
177 1.1.4.2 tls if (len == 0) {
178 1.1.4.2 tls len = snprintf(buf, sizeof(buf),
179 1.1.4.2 tls "%s: %s: ", cpuname, setname);
180 1.1.4.2 tls }
181 1.1.4.2 tls if (i < id_nfieldnames) {
182 1.1.4.2 tls name = id_fieldnames[i][j];
183 1.1.4.2 tls }
184 1.1.4.2 tls if (name == NULL) {
185 1.1.4.2 tls name = namebuf;
186 1.1.4.2 tls snprintf(namebuf, sizeof(namebuf),
187 1.1.4.2 tls "%zu[%u]", i, j);
188 1.1.4.2 tls }
189 1.1.4.2 tls if (id_boolean == NULL
190 1.1.4.2 tls || (id_boolean[i] & (1 << j)) == 0
191 1.1.4.2 tls || (isar & 0xe) != 0) {
192 1.1.4.2 tls value = valuebuf;
193 1.1.4.2 tls snprintf(valuebuf, sizeof(valuebuf),
194 1.1.4.2 tls "=%u", isar & 0x0f);
195 1.1.4.2 tls }
196 1.1.4.2 tls size_t tmplen = snprintf(tmpbuf, sizeof(tmpbuf),
197 1.1.4.2 tls "%s%s%s", sep, name, value);
198 1.1.4.2 tls if (len + tmplen > 78) {
199 1.1.4.2 tls printf("%s\n", buf);
200 1.1.4.2 tls len = snprintf(buf, sizeof(buf),
201 1.1.4.2 tls "%s: %s: %s", cpuname, setname, tmpbuf + 2);
202 1.1.4.2 tls } else {
203 1.1.4.2 tls len = strlcat(buf, tmpbuf, sizeof(buf));
204 1.1.4.2 tls }
205 1.1.4.2 tls sep = ", ";
206 1.1.4.2 tls }
207 1.1.4.2 tls }
208 1.1.4.2 tls if (len > 0) {
209 1.1.4.2 tls printf("%s\n", buf);
210 1.1.4.2 tls }
211 1.1.4.2 tls }
212 1.1.4.2 tls
213 1.1.4.2 tls void
214 1.1.4.2 tls identifycpu(int fd, const char *cpuname)
215 1.1.4.2 tls {
216 1.1.4.2 tls int *id_data;
217 1.1.4.2 tls size_t id_isar_len = 0;
218 1.1.4.2 tls size_t id_mmfr_len = 0;
219 1.1.4.2 tls size_t id_pfr_len = 0;
220 1.1.4.2 tls size_t id_mvfr_len = 0;
221 1.1.4.2 tls
222 1.1.4.2 tls if (sysctlbyname("machdep.id_isar", NULL, &id_isar_len, NULL, 0) < 0
223 1.1.4.2 tls || sysctlbyname("machdep.id_mmfr", NULL, &id_mmfr_len, NULL, 0) < 0
224 1.1.4.2 tls || sysctlbyname("machdep.id_pfr", NULL, &id_pfr_len, NULL, 0) < 0
225 1.1.4.2 tls || sysctlbyname("machdep.id_mvfr", NULL, &id_mvfr_len, NULL, 0) < 0) {
226 1.1.4.2 tls warn("sysctlbyname");
227 1.1.4.2 tls return;
228 1.1.4.2 tls }
229 1.1.4.2 tls
230 1.1.4.2 tls id_data = malloc(id_isar_len);
231 1.1.4.2 tls
232 1.1.4.2 tls sysctlbyname("machdep.id_isar", id_data, &id_isar_len, NULL, 0);
233 1.1.4.2 tls print_features(cpuname, "isa features", id_data, id_isar_len,
234 1.1.4.2 tls id_isar_fieldnames, __arraycount(id_isar_fieldnames),
235 1.1.4.2 tls id_isar_boolean, NULL);
236 1.1.4.2 tls
237 1.1.4.2 tls free(id_data);
238 1.1.4.2 tls id_data = malloc(id_mmfr_len);
239 1.1.4.2 tls
240 1.1.4.2 tls sysctlbyname("machdep.id_mmfr", id_data, &id_mmfr_len, NULL, 0);
241 1.1.4.2 tls print_features(cpuname, "memory model", id_data, id_mmfr_len,
242 1.1.4.2 tls id_mmfr_fieldnames, __arraycount(id_mmfr_fieldnames),
243 1.1.4.2 tls NULL /*id_mmfr_boolean*/, id_mmfr_present);
244 1.1.4.2 tls
245 1.1.4.2 tls free(id_data);
246 1.1.4.2 tls id_data = malloc(id_pfr_len);
247 1.1.4.2 tls
248 1.1.4.2 tls sysctlbyname("machdep.id_pfr", id_data, &id_pfr_len, NULL, 0);
249 1.1.4.2 tls print_features(cpuname, "processor features", id_data, id_pfr_len,
250 1.1.4.2 tls id_pfr_fieldnames, __arraycount(id_pfr_fieldnames),
251 1.1.4.2 tls NULL /*id_pfr_boolean*/, NULL /*id_pfr_present*/);
252 1.1.4.2 tls
253 1.1.4.2 tls free(id_data);
254 1.1.4.2 tls id_data = malloc(id_mvfr_len);
255 1.1.4.2 tls
256 1.1.4.2 tls sysctlbyname("machdep.id_mvfr", id_data, &id_mvfr_len, NULL, 0);
257 1.1.4.2 tls print_features(cpuname, "media and VFP features", id_data, id_mvfr_len,
258 1.1.4.2 tls id_mvfr_fieldnames, __arraycount(id_mvfr_fieldnames),
259 1.1.4.2 tls NULL /*id_mvfr_boolean*/, id_mvfr_present);
260 1.1.4.2 tls
261 1.1.4.2 tls free(id_data);
262 1.1.4.2 tls }
263 1.1.4.2 tls
264 1.1.4.2 tls int
265 1.1.4.2 tls ucodeupdate_check(int fd, struct cpu_ucode *uc)
266 1.1.4.2 tls {
267 1.1.4.2 tls
268 1.1.4.2 tls return 0;
269 1.1.4.2 tls }
270