]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
a39ff7e2 | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
a39ff7e2 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
a39ff7e2 | 17 | * |
2d21ac55 A |
18 | * The Original Code and all software distributed under the License are |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
a39ff7e2 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /*- | |
29 | * Copyright (c) 1982, 1986, 1989, 1993 | |
30 | * The Regents of the University of California. All rights reserved. | |
31 | * | |
32 | * This code is derived from software contributed to Berkeley by | |
33 | * Mike Karels at Berkeley Software Design, Inc. | |
34 | * | |
35 | * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD | |
36 | * project, to make these variables more userfriendly. | |
37 | * | |
38 | * Redistribution and use in source and binary forms, with or without | |
39 | * modification, are permitted provided that the following conditions | |
40 | * are met: | |
41 | * 1. Redistributions of source code must retain the above copyright | |
42 | * notice, this list of conditions and the following disclaimer. | |
43 | * 2. Redistributions in binary form must reproduce the above copyright | |
44 | * notice, this list of conditions and the following disclaimer in the | |
45 | * documentation and/or other materials provided with the distribution. | |
46 | * 3. All advertising materials mentioning features or use of this software | |
47 | * must display the following acknowledgement: | |
48 | * This product includes software developed by the University of | |
49 | * California, Berkeley and its contributors. | |
50 | * 4. Neither the name of the University nor the names of its contributors | |
51 | * may be used to endorse or promote products derived from this software | |
52 | * without specific prior written permission. | |
53 | * | |
54 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
55 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
56 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
64 | * SUCH DAMAGE. | |
65 | * | |
66 | * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94 | |
67 | */ | |
68 | ||
69 | #include <sys/param.h> | |
70 | #include <sys/kernel.h> | |
71 | #include <sys/systm.h> | |
72 | #include <sys/sysctl.h> | |
91447636 | 73 | #include <sys/proc_internal.h> |
1c79356b A |
74 | #include <sys/unistd.h> |
75 | ||
76 | #if defined(SMP) | |
77 | #include <machine/smp.h> | |
78 | #endif | |
79 | ||
43866e37 A |
80 | #include <sys/param.h> /* XXX prune includes */ |
81 | #include <sys/systm.h> | |
82 | #include <sys/kernel.h> | |
83 | #include <sys/malloc.h> | |
84 | #include <sys/proc.h> | |
91447636 | 85 | #include <sys/file_internal.h> |
43866e37 A |
86 | #include <sys/vnode.h> |
87 | #include <sys/unistd.h> | |
43866e37 A |
88 | #include <sys/ioctl.h> |
89 | #include <sys/namei.h> | |
90 | #include <sys/tty.h> | |
91 | #include <sys/disklabel.h> | |
92 | #include <sys/vm.h> | |
93 | #include <sys/sysctl.h> | |
94 | #include <sys/user.h> | |
95 | #include <mach/machine.h> | |
96 | #include <mach/mach_types.h> | |
97 | #include <mach/vm_param.h> | |
98 | #include <kern/task.h> | |
99 | #include <vm/vm_kern.h> | |
39236c6e | 100 | #include <vm/vm_map.h> |
3e170ce0 | 101 | #include <vm/vm_protos.h> |
43866e37 | 102 | #include <mach/host_info.h> |
0c530ab8 | 103 | #include <kern/pms.h> |
43866e37 A |
104 | |
105 | extern vm_map_t bsd_pageable_map; | |
106 | ||
91447636 | 107 | #include <sys/mount_internal.h> |
43866e37 A |
108 | #include <sys/kdebug.h> |
109 | ||
110 | #include <IOKit/IOPlatformExpert.h> | |
111 | #include <pexpert/pexpert.h> | |
112 | ||
113 | #include <machine/machine_routines.h> | |
114 | #include <machine/cpu_capabilities.h> | |
115 | ||
2d21ac55 A |
116 | #include <mach/mach_host.h> /* for host_info() */ |
117 | ||
b0d623f7 A |
118 | #if defined(__i386__) || defined(__x86_64__) |
119 | #include <i386/cpuid.h> /* for cpuid_info() */ | |
0c530ab8 A |
120 | #endif |
121 | ||
5ba3f43e A |
122 | #if defined(__arm__) || defined(__arm64__) |
123 | #include <arm/cpuid.h> /* for cpuid_info() & cache_info() */ | |
124 | #endif | |
2d21ac55 A |
125 | |
126 | ||
0c530ab8 A |
127 | #ifndef MAX |
128 | #define MAX(a,b) (a >= b ? a : b) | |
129 | #endif | |
130 | ||
2d21ac55 A |
131 | /* XXX This should be in a BSD accessible Mach header, but isn't. */ |
132 | extern unsigned int vm_page_wire_count; | |
133 | ||
134 | static int cputype, cpusubtype, cputhreadtype, cpufamily, cpu64bit; | |
135 | static uint64_t cacheconfig[10], cachesize[10]; | |
136 | static int packages; | |
43866e37 | 137 | |
2d21ac55 | 138 | SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 139 | "Sysctl internal magic"); |
2d21ac55 | 140 | SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 141 | "High kernel, proc, limits &c"); |
2d21ac55 | 142 | SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 143 | "Virtual memory"); |
2d21ac55 | 144 | SYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 145 | "File system"); |
2d21ac55 | 146 | SYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 147 | "Network, (see socket.h)"); |
2d21ac55 | 148 | SYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 149 | "Debugging"); |
2d21ac55 | 150 | SYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 151 | "hardware"); |
2d21ac55 | 152 | SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b | 153 | "machine dependent"); |
2d21ac55 | 154 | SYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
1c79356b A |
155 | "user-level"); |
156 | ||
a39ff7e2 A |
157 | SYSCTL_NODE(_kern, OID_AUTO, bridge, CTLFLAG_RW|CTLFLAG_LOCKED, 0, |
158 | "bridge"); | |
159 | ||
43866e37 A |
160 | #define SYSCTL_RETURN(r, x) SYSCTL_OUT(r, &x, sizeof(x)) |
161 | ||
162 | /****************************************************************************** | |
163 | * hw.* MIB | |
164 | */ | |
165 | ||
166 | #define CTLHW_RETQUAD (1 << 31) | |
91447636 A |
167 | #define CTLHW_LOCAL (1 << 30) |
168 | ||
169 | #define HW_LOCAL_CPUTHREADTYPE (1 | CTLHW_LOCAL) | |
170 | #define HW_LOCAL_PHYSICALCPU (2 | CTLHW_LOCAL) | |
171 | #define HW_LOCAL_PHYSICALCPUMAX (3 | CTLHW_LOCAL) | |
172 | #define HW_LOCAL_LOGICALCPU (4 | CTLHW_LOCAL) | |
173 | #define HW_LOCAL_LOGICALCPUMAX (5 | CTLHW_LOCAL) | |
174 | ||
43866e37 A |
175 | |
176 | /* | |
a39ff7e2 | 177 | * Supporting some variables requires us to do "real" work. We |
43866e37 A |
178 | * gather some of that here. |
179 | */ | |
180 | static int | |
2d21ac55 A |
181 | sysctl_hw_generic(__unused struct sysctl_oid *oidp, __unused void *arg1, |
182 | int arg2, struct sysctl_req *req) | |
43866e37 A |
183 | { |
184 | char dummy[65]; | |
185 | int epochTemp; | |
43866e37 A |
186 | ml_cpu_info_t cpu_info; |
187 | int val, doquad; | |
188 | long long qval; | |
91447636 A |
189 | host_basic_info_data_t hinfo; |
190 | kern_return_t kret; | |
2d21ac55 | 191 | mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
43866e37 A |
192 | |
193 | /* | |
194 | * Test and mask off the 'return quad' flag. | |
195 | * Note that only some things here support it. | |
196 | */ | |
197 | doquad = arg2 & CTLHW_RETQUAD; | |
198 | arg2 &= ~CTLHW_RETQUAD; | |
199 | ||
200 | ml_cpu_get_info(&cpu_info); | |
201 | ||
91447636 | 202 | #define BSD_HOST 1 |
2d21ac55 | 203 | kret = host_info((host_t)BSD_HOST, HOST_BASIC_INFO, (host_info_t)&hinfo, &count); |
91447636 | 204 | |
43866e37 A |
205 | /* |
206 | * Handle various OIDs. | |
207 | * | |
208 | * OIDs that can return int or quad set val and qval and then break. | |
209 | * Errors and int-only values return inline. | |
210 | */ | |
211 | switch (arg2) { | |
212 | case HW_NCPU: | |
91447636 A |
213 | if (kret == KERN_SUCCESS) { |
214 | return(SYSCTL_RETURN(req, hinfo.max_cpus)); | |
215 | } else { | |
216 | return(EINVAL); | |
43866e37 A |
217 | } |
218 | case HW_AVAILCPU: | |
91447636 A |
219 | if (kret == KERN_SUCCESS) { |
220 | return(SYSCTL_RETURN(req, hinfo.avail_cpus)); | |
221 | } else { | |
222 | return(EINVAL); | |
223 | } | |
224 | case HW_LOCAL_PHYSICALCPU: | |
225 | if (kret == KERN_SUCCESS) { | |
226 | return(SYSCTL_RETURN(req, hinfo.physical_cpu)); | |
227 | } else { | |
228 | return(EINVAL); | |
229 | } | |
230 | case HW_LOCAL_PHYSICALCPUMAX: | |
231 | if (kret == KERN_SUCCESS) { | |
232 | return(SYSCTL_RETURN(req, hinfo.physical_cpu_max)); | |
233 | } else { | |
234 | return(EINVAL); | |
235 | } | |
236 | case HW_LOCAL_LOGICALCPU: | |
237 | if (kret == KERN_SUCCESS) { | |
238 | return(SYSCTL_RETURN(req, hinfo.logical_cpu)); | |
239 | } else { | |
240 | return(EINVAL); | |
241 | } | |
242 | case HW_LOCAL_LOGICALCPUMAX: | |
243 | if (kret == KERN_SUCCESS) { | |
244 | return(SYSCTL_RETURN(req, hinfo.logical_cpu_max)); | |
245 | } else { | |
246 | return(EINVAL); | |
43866e37 | 247 | } |
39236c6e A |
248 | case HW_PAGESIZE: |
249 | { | |
250 | vm_map_t map = get_task_map(current_task()); | |
251 | val = vm_map_page_size(map); | |
252 | qval = (long long)val; | |
253 | break; | |
254 | } | |
43866e37 A |
255 | case HW_CACHELINE: |
256 | val = cpu_info.cache_line_size; | |
257 | qval = (long long)val; | |
258 | break; | |
259 | case HW_L1ICACHESIZE: | |
260 | val = cpu_info.l1_icache_size; | |
261 | qval = (long long)val; | |
262 | break; | |
263 | case HW_L1DCACHESIZE: | |
264 | val = cpu_info.l1_dcache_size; | |
265 | qval = (long long)val; | |
266 | break; | |
267 | case HW_L2CACHESIZE: | |
268 | if (cpu_info.l2_cache_size == 0xFFFFFFFF) | |
269 | return(EINVAL); | |
270 | val = cpu_info.l2_cache_size; | |
271 | qval = (long long)val; | |
272 | break; | |
273 | case HW_L3CACHESIZE: | |
274 | if (cpu_info.l3_cache_size == 0xFFFFFFFF) | |
275 | return(EINVAL); | |
276 | val = cpu_info.l3_cache_size; | |
277 | qval = (long long)val; | |
278 | break; | |
279 | ||
280 | /* | |
281 | * Deprecated variables. We still support these for | |
282 | * backwards compatibility purposes only. | |
283 | */ | |
284 | case HW_MACHINE: | |
285 | bzero(dummy, sizeof(dummy)); | |
286 | if(!PEGetMachineName(dummy,64)) | |
287 | return(EINVAL); | |
288 | dummy[64] = 0; | |
289 | return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1)); | |
290 | case HW_MODEL: | |
291 | bzero(dummy, sizeof(dummy)); | |
292 | if(!PEGetModelName(dummy,64)) | |
293 | return(EINVAL); | |
294 | dummy[64] = 0; | |
295 | return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1)); | |
296 | case HW_USERMEM: | |
297 | { | |
298 | int usermem = mem_size - vm_page_wire_count * page_size; | |
299 | ||
300 | return(SYSCTL_RETURN(req, usermem)); | |
301 | } | |
302 | case HW_EPOCH: | |
303 | epochTemp = PEGetPlatformEpoch(); | |
304 | if (epochTemp == -1) | |
305 | return(EINVAL); | |
306 | return(SYSCTL_RETURN(req, epochTemp)); | |
0c530ab8 A |
307 | case HW_VECTORUNIT: { |
308 | int vector = cpu_info.vector_unit == 0? 0 : 1; | |
309 | return(SYSCTL_RETURN(req, vector)); | |
310 | } | |
43866e37 A |
311 | case HW_L2SETTINGS: |
312 | if (cpu_info.l2_cache_size == 0xFFFFFFFF) | |
313 | return(EINVAL); | |
314 | return(SYSCTL_RETURN(req, cpu_info.l2_settings)); | |
315 | case HW_L3SETTINGS: | |
316 | if (cpu_info.l3_cache_size == 0xFFFFFFFF) | |
317 | return(EINVAL); | |
318 | return(SYSCTL_RETURN(req, cpu_info.l3_settings)); | |
319 | default: | |
320 | return(ENOTSUP); | |
321 | } | |
322 | /* | |
323 | * Callers may come to us with either int or quad buffers. | |
324 | */ | |
325 | if (doquad) { | |
326 | return(SYSCTL_RETURN(req, qval)); | |
327 | } | |
328 | return(SYSCTL_RETURN(req, val)); | |
329 | } | |
330 | ||
2d21ac55 A |
331 | /* hw.pagesize and hw.tbfrequency are expected as 64 bit values */ |
332 | static int | |
333 | sysctl_pagesize | |
334 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
335 | { | |
39236c6e A |
336 | vm_map_t map = get_task_map(current_task()); |
337 | long long l = vm_map_page_size(map); | |
2d21ac55 A |
338 | return sysctl_io_number(req, l, sizeof(l), NULL, NULL); |
339 | } | |
340 | ||
3e170ce0 A |
341 | static int |
342 | sysctl_pagesize32 | |
343 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
344 | { | |
345 | long long l; | |
5ba3f43e A |
346 | #if __arm64__ |
347 | l = (long long) (1 << page_shift_user32); | |
348 | #else /* __arm64__ */ | |
3e170ce0 | 349 | l = (long long) PAGE_SIZE; |
5ba3f43e | 350 | #endif /* __arm64__ */ |
3e170ce0 A |
351 | return sysctl_io_number(req, l, sizeof(l), NULL, NULL); |
352 | } | |
353 | ||
2d21ac55 A |
354 | static int |
355 | sysctl_tbfrequency | |
356 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
357 | { | |
358 | long long l = gPEClockFrequencyInfo.timebase_frequency_hz; | |
359 | return sysctl_io_number(req, l, sizeof(l), NULL, NULL); | |
360 | } | |
361 | ||
43866e37 A |
362 | /* |
363 | * hw.* MIB variables. | |
364 | */ | |
6d2010ae A |
365 | SYSCTL_PROC (_hw, HW_NCPU, ncpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_NCPU, sysctl_hw_generic, "I", ""); |
366 | SYSCTL_PROC (_hw, HW_AVAILCPU, activecpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_AVAILCPU, sysctl_hw_generic, "I", ""); | |
367 | SYSCTL_PROC (_hw, OID_AUTO, physicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_PHYSICALCPU, sysctl_hw_generic, "I", ""); | |
368 | SYSCTL_PROC (_hw, OID_AUTO, physicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_PHYSICALCPUMAX, sysctl_hw_generic, "I", ""); | |
369 | SYSCTL_PROC (_hw, OID_AUTO, logicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_LOGICALCPU, sysctl_hw_generic, "I", ""); | |
370 | SYSCTL_PROC (_hw, OID_AUTO, logicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_LOGICALCPUMAX, sysctl_hw_generic, "I", ""); | |
371 | SYSCTL_INT (_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (int *)NULL, BYTE_ORDER, ""); | |
372 | SYSCTL_INT (_hw, OID_AUTO, cputype, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cputype, 0, ""); | |
373 | SYSCTL_INT (_hw, OID_AUTO, cpusubtype, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpusubtype, 0, ""); | |
374 | SYSCTL_INT (_hw, OID_AUTO, cpu64bit_capable, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpu64bit, 0, ""); | |
375 | SYSCTL_INT (_hw, OID_AUTO, cpufamily, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpufamily, 0, ""); | |
376 | SYSCTL_OPAQUE (_hw, OID_AUTO, cacheconfig, CTLFLAG_RD | CTLFLAG_LOCKED, &cacheconfig, sizeof(cacheconfig), "Q", ""); | |
377 | SYSCTL_OPAQUE (_hw, OID_AUTO, cachesize, CTLFLAG_RD | CTLFLAG_LOCKED, &cachesize, sizeof(cachesize), "Q", ""); | |
378 | SYSCTL_PROC (_hw, OID_AUTO, pagesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_pagesize, "Q", ""); | |
3e170ce0 | 379 | SYSCTL_PROC (_hw, OID_AUTO, pagesize32, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_pagesize32, "Q", ""); |
5ba3f43e | 380 | #if DEBUG || DEVELOPMENT || (!defined(__arm__) && !defined(__arm64__)) |
6d2010ae A |
381 | SYSCTL_QUAD (_hw, OID_AUTO, busfrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_hz, ""); |
382 | SYSCTL_QUAD (_hw, OID_AUTO, busfrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_min_hz, ""); | |
383 | SYSCTL_QUAD (_hw, OID_AUTO, busfrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_max_hz, ""); | |
384 | SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_hz, ""); | |
385 | SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_min_hz, ""); | |
386 | SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_max_hz, ""); | |
5ba3f43e | 387 | #endif |
6d2010ae A |
388 | SYSCTL_PROC (_hw, OID_AUTO, cachelinesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_CACHELINE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); |
389 | SYSCTL_PROC (_hw, OID_AUTO, l1icachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L1ICACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
390 | SYSCTL_PROC (_hw, OID_AUTO, l1dcachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L1DCACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
391 | SYSCTL_PROC (_hw, OID_AUTO, l2cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L2CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
392 | SYSCTL_PROC (_hw, OID_AUTO, l3cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L3CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
5ba3f43e A |
393 | #if (defined(__arm__) || defined(__arm64__)) && (DEBUG || DEVELOPMENT) |
394 | SYSCTL_QUAD (_hw, OID_AUTO, memfrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.mem_frequency_hz, ""); | |
395 | SYSCTL_QUAD (_hw, OID_AUTO, memfrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.mem_frequency_min_hz, ""); | |
396 | SYSCTL_QUAD (_hw, OID_AUTO, memfrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.mem_frequency_max_hz, ""); | |
397 | SYSCTL_QUAD (_hw, OID_AUTO, prffrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.prf_frequency_hz, ""); | |
398 | SYSCTL_QUAD (_hw, OID_AUTO, prffrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.prf_frequency_min_hz, ""); | |
399 | SYSCTL_QUAD (_hw, OID_AUTO, prffrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.prf_frequency_max_hz, ""); | |
400 | SYSCTL_QUAD (_hw, OID_AUTO, fixfrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.fix_frequency_hz, ""); | |
401 | #endif /* __arm__ || __arm64__ */ | |
6d2010ae A |
402 | SYSCTL_PROC(_hw, OID_AUTO, tbfrequency, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_tbfrequency, "Q", ""); |
403 | SYSCTL_QUAD (_hw, HW_MEMSIZE, memsize, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &max_mem, ""); | |
404 | SYSCTL_INT (_hw, OID_AUTO, packages, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &packages, 0, ""); | |
43866e37 A |
405 | |
406 | /* | |
39037602 | 407 | * Optional CPU features can register nodes below hw.optional. |
43866e37 A |
408 | * |
409 | * If the feature is not present, the node should either not be registered, | |
410 | * or it should return -1. If the feature is present, the node should return | |
a39ff7e2 | 411 | * 0. If the feature is present and its use is advised, the node should |
43866e37 A |
412 | * return 1. |
413 | */ | |
2d21ac55 | 414 | SYSCTL_NODE(_hw, OID_AUTO, optional, CTLFLAG_RW|CTLFLAG_LOCKED, NULL, "optional features"); |
43866e37 | 415 | |
6d2010ae | 416 | SYSCTL_INT(_hw_optional, OID_AUTO, floatingpoint, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (int *)NULL, 1, ""); /* always set */ |
43866e37 | 417 | |
39037602 A |
418 | /* |
419 | * Optional device hardware features can be registered by drivers below hw.features | |
420 | */ | |
421 | SYSCTL_NODE(_hw, OID_AUTO, features, CTLFLAG_RD | CTLFLAG_LOCKED, NULL, "hardware features"); | |
422 | ||
43866e37 A |
423 | /* |
424 | * Deprecated variables. These are supported for backwards compatibility | |
425 | * purposes only. The MASKED flag requests that the variables not be | |
426 | * printed by sysctl(8) and similar utilities. | |
427 | * | |
428 | * The variables named *_compat here are int-sized versions of variables | |
429 | * that are now exported as quads. The int-sized versions are normally | |
430 | * looked up only by number, wheras the quad-sized versions should be | |
431 | * looked up by name. | |
432 | * | |
433 | * The *_compat nodes are *NOT* visible within the kernel. | |
434 | */ | |
39236c6e | 435 | SYSCTL_PROC(_hw, HW_PAGESIZE, pagesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_PAGESIZE, sysctl_hw_generic, "I", ""); |
5ba3f43e | 436 | #if DEBUG || DEVELOPMENT || (!defined(__arm__) && !defined(__arm64__)) |
6d2010ae A |
437 | SYSCTL_COMPAT_INT (_hw, HW_BUS_FREQ, busfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_clock_rate_hz, 0, ""); |
438 | SYSCTL_COMPAT_INT (_hw, HW_CPU_FREQ, cpufrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_clock_rate_hz, 0, ""); | |
5ba3f43e | 439 | #endif |
6d2010ae A |
440 | SYSCTL_PROC(_hw, HW_CACHELINE, cachelinesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_CACHELINE, sysctl_hw_generic, "I", ""); |
441 | SYSCTL_PROC(_hw, HW_L1ICACHESIZE, l1icachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L1ICACHESIZE, sysctl_hw_generic, "I", ""); | |
442 | SYSCTL_PROC(_hw, HW_L1DCACHESIZE, l1dcachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L1DCACHESIZE, sysctl_hw_generic, "I", ""); | |
443 | SYSCTL_PROC(_hw, HW_L2CACHESIZE, l2cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L2CACHESIZE, sysctl_hw_generic, "I", ""); | |
444 | SYSCTL_PROC(_hw, HW_L3CACHESIZE, l3cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L3CACHESIZE, sysctl_hw_generic, "I", ""); | |
445 | SYSCTL_COMPAT_INT (_hw, HW_TB_FREQ, tbfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.timebase_frequency_hz, 0, ""); | |
446 | SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_MACHINE, sysctl_hw_generic, "A", ""); | |
447 | SYSCTL_PROC(_hw, HW_MODEL, model, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_MODEL, sysctl_hw_generic, "A", ""); | |
448 | SYSCTL_COMPAT_UINT(_hw, HW_PHYSMEM, physmem, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &mem_size, 0, ""); | |
449 | SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_USERMEM, sysctl_hw_generic, "I", ""); | |
450 | SYSCTL_PROC(_hw, HW_EPOCH, epoch, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_EPOCH, sysctl_hw_generic, "I", ""); | |
451 | SYSCTL_PROC(_hw, HW_VECTORUNIT, vectorunit, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_VECTORUNIT, sysctl_hw_generic, "I", ""); | |
452 | SYSCTL_PROC(_hw, HW_L2SETTINGS, l2settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L2SETTINGS, sysctl_hw_generic, "I", ""); | |
453 | SYSCTL_PROC(_hw, HW_L3SETTINGS, l3settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L3SETTINGS, sysctl_hw_generic, "I", ""); | |
454 | SYSCTL_INT (_hw, OID_AUTO, cputhreadtype, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN | CTLFLAG_LOCKED, &cputhreadtype, 0, ""); | |
455 | ||
316670eb | 456 | #if defined(__i386__) || defined(__x86_64__) |
bd504ef0 A |
457 | static int |
458 | sysctl_cpu_capability | |
459 | (__unused struct sysctl_oid *oidp, void *arg1, __unused int arg2, struct sysctl_req *req) | |
460 | { | |
461 | uint64_t mask = (uint64_t) (uintptr_t) arg1; | |
462 | boolean_t is_capable = (_get_cpu_capabilities() & mask) != 0; | |
a39ff7e2 | 463 | |
bd504ef0 A |
464 | return SYSCTL_OUT(req, &is_capable, sizeof(is_capable)); |
465 | ||
466 | } | |
467 | ||
fe8ab488 A |
468 | SYSCTL_PROC(_hw_optional, OID_AUTO, mmx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasMMX, 0, sysctl_cpu_capability, "I", ""); |
469 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE, 0, sysctl_cpu_capability, "I", ""); | |
470 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse2, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE2, 0, sysctl_cpu_capability, "I", ""); | |
471 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse3, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE3, 0, sysctl_cpu_capability, "I", ""); | |
472 | SYSCTL_PROC(_hw_optional, OID_AUTO, supplementalsse3, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSupplementalSSE3, 0, sysctl_cpu_capability, "I", ""); | |
473 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse4_1, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE4_1, 0, sysctl_cpu_capability, "I", ""); | |
474 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse4_2, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE4_2, 0, sysctl_cpu_capability, "I", ""); | |
b0d623f7 A |
475 | /* "x86_64" is actually a preprocessor symbol on the x86_64 kernel, so we have to hack this */ |
476 | #undef x86_64 | |
fe8ab488 A |
477 | SYSCTL_PROC(_hw_optional, OID_AUTO, x86_64, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) k64Bit, 0, sysctl_cpu_capability, "I", ""); |
478 | SYSCTL_PROC(_hw_optional, OID_AUTO, aes, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAES, 0, sysctl_cpu_capability, "I", ""); | |
479 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx1_0, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX1_0, 0, sysctl_cpu_capability, "I", ""); | |
480 | SYSCTL_PROC(_hw_optional, OID_AUTO, rdrand, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasRDRAND, 0, sysctl_cpu_capability, "I", ""); | |
481 | SYSCTL_PROC(_hw_optional, OID_AUTO, f16c, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasF16C, 0, sysctl_cpu_capability, "I", ""); | |
482 | SYSCTL_PROC(_hw_optional, OID_AUTO, enfstrg, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasENFSTRG, 0, sysctl_cpu_capability, "I", ""); | |
483 | SYSCTL_PROC(_hw_optional, OID_AUTO, fma, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasFMA, 0, sysctl_cpu_capability, "I", ""); | |
484 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx2_0, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX2_0, 0, sysctl_cpu_capability, "I", ""); | |
485 | SYSCTL_PROC(_hw_optional, OID_AUTO, bmi1, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasBMI1, 0, sysctl_cpu_capability, "I", ""); | |
486 | SYSCTL_PROC(_hw_optional, OID_AUTO, bmi2, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasBMI2, 0, sysctl_cpu_capability, "I", ""); | |
487 | SYSCTL_PROC(_hw_optional, OID_AUTO, rtm, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasRTM, 0, sysctl_cpu_capability, "I", ""); | |
488 | SYSCTL_PROC(_hw_optional, OID_AUTO, hle, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasHLE, 0, sysctl_cpu_capability, "I", ""); | |
a1c7dba1 | 489 | SYSCTL_PROC(_hw_optional, OID_AUTO, adx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasADX, 0, sysctl_cpu_capability, "I", ""); |
2dced7af A |
490 | SYSCTL_PROC(_hw_optional, OID_AUTO, mpx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasMPX, 0, sysctl_cpu_capability, "I", ""); |
491 | SYSCTL_PROC(_hw_optional, OID_AUTO, sgx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSGX, 0, sysctl_cpu_capability, "I", ""); | |
5ba3f43e A |
492 | #if !defined(RC_HIDE_XNU_J137) |
493 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512f, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512F, 0, sysctl_cpu_capability, "I", ""); | |
494 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512cd, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512CD, 0, sysctl_cpu_capability, "I", ""); | |
495 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512dq, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512DQ, 0, sysctl_cpu_capability, "I", ""); | |
496 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512bw, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512BW, 0, sysctl_cpu_capability, "I", ""); | |
497 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512vl, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512VL, 0, sysctl_cpu_capability, "I", ""); | |
498 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512ifma, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512IFMA, 0, sysctl_cpu_capability, "I", ""); | |
499 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512vbmi, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512VBMI, 0, sysctl_cpu_capability, "I", ""); | |
500 | #endif /* not RC_HIDE_XNU_J137 */ | |
501 | #elif defined (__arm__) || defined (__arm64__) | |
502 | int watchpoint_flag = -1; | |
503 | int breakpoint_flag = -1; | |
504 | int gNeon = -1; | |
505 | int gNeonHpfp = -1; | |
d9a64523 | 506 | int gNeonFp16 = -1; |
5ba3f43e | 507 | int gARMv81Atomics = 0; |
d9a64523 | 508 | int gARMv8Crc32 = 0; |
5ba3f43e A |
509 | |
510 | #if defined (__arm__) | |
511 | int arm64_flag = 0; | |
512 | #elif defined (__arm64__) /* end __arm__*/ | |
513 | int arm64_flag = 1; | |
514 | #else /* end __arm64__*/ | |
515 | int arm64_flag = -1; | |
516 | #endif | |
517 | ||
518 | SYSCTL_INT(_hw_optional, OID_AUTO, watchpoint, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &watchpoint_flag, 0, ""); | |
519 | SYSCTL_INT(_hw_optional, OID_AUTO, breakpoint, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &breakpoint_flag, 0, ""); | |
520 | SYSCTL_INT(_hw_optional, OID_AUTO, neon, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gNeon, 0, ""); | |
521 | SYSCTL_INT(_hw_optional, OID_AUTO, neon_hpfp, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gNeonHpfp, 0, ""); | |
d9a64523 | 522 | SYSCTL_INT(_hw_optional, OID_AUTO, neon_fp16, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gNeonFp16, 0, ""); |
5ba3f43e | 523 | SYSCTL_INT(_hw_optional, OID_AUTO, armv8_1_atomics, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gARMv81Atomics, 0, ""); |
d9a64523 | 524 | SYSCTL_INT(_hw_optional, OID_AUTO, armv8_crc32, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gARMv8Crc32, 0, ""); |
5ba3f43e A |
525 | |
526 | /* | |
527 | * Without this little ifdef dance, the preprocessor replaces "arm64" with "1", | |
528 | * leaving us with a less-than-helpful sysctl.hwoptional.1. | |
529 | */ | |
530 | #ifdef arm64 | |
531 | #undef arm64 | |
532 | SYSCTL_INT(_hw_optional, OID_AUTO, arm64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &arm64_flag, 0, ""); | |
533 | #define arm64 1 | |
534 | #else | |
535 | SYSCTL_INT(_hw_optional, OID_AUTO, arm64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &arm64_flag, 0, ""); | |
536 | #endif | |
537 | ||
316670eb A |
538 | #else |
539 | #error Unsupported arch | |
fe8ab488 | 540 | #endif /* !__i386__ && !__x86_64 && !__arm__ && ! __arm64__ */ |
43866e37 | 541 | |
0c530ab8 | 542 | |
43866e37 A |
543 | /****************************************************************************** |
544 | * Generic MIB initialisation. | |
545 | * | |
546 | * This is a hack, and should be replaced with SYSINITs | |
547 | * at some point. | |
548 | */ | |
549 | void | |
550 | sysctl_mib_init(void) | |
551 | { | |
91447636 A |
552 | cputype = cpu_type(); |
553 | cpusubtype = cpu_subtype(); | |
554 | cputhreadtype = cpu_threadtype(); | |
6d2010ae | 555 | #if defined(__i386__) || defined (__x86_64__) |
39236c6e | 556 | cpu64bit = (_get_cpu_capabilities() & k64Bit) == k64Bit; |
5ba3f43e A |
557 | #elif defined(__arm__) || defined (__arm64__) |
558 | cpu64bit = (cputype & CPU_ARCH_ABI64) == CPU_ARCH_ABI64; | |
316670eb A |
559 | #else |
560 | #error Unsupported arch | |
2d21ac55 | 561 | #endif |
91447636 | 562 | |
43866e37 A |
563 | /* |
564 | * Populate the optional portion of the hw.* MIB. | |
565 | * | |
566 | * XXX This could be broken out into parts of the code | |
567 | * that actually directly relate to the functions in | |
568 | * question. | |
569 | */ | |
91447636 A |
570 | |
571 | if (cputhreadtype != CPU_THREADTYPE_NONE) { | |
91447636 A |
572 | sysctl_register_oid(&sysctl__hw_cputhreadtype); |
573 | } | |
574 | ||
6d2010ae | 575 | #if defined (__i386__) || defined (__x86_64__) |
0c530ab8 | 576 | /* hw.cpufamily */ |
7e4a7d39 A |
577 | cpufamily = cpuid_cpufamily(); |
578 | ||
0c530ab8 | 579 | /* hw.cacheconfig */ |
2d21ac55 A |
580 | cacheconfig[0] = ml_cpu_cache_sharing(0); |
581 | cacheconfig[1] = ml_cpu_cache_sharing(1); | |
582 | cacheconfig[2] = ml_cpu_cache_sharing(2); | |
583 | cacheconfig[3] = ml_cpu_cache_sharing(3); | |
0c530ab8 A |
584 | cacheconfig[4] = 0; |
585 | ||
2d21ac55 A |
586 | /* hw.cachesize */ |
587 | cachesize[0] = ml_cpu_cache_size(0); | |
588 | cachesize[1] = ml_cpu_cache_size(1); | |
589 | cachesize[2] = ml_cpu_cache_size(2); | |
590 | cachesize[3] = ml_cpu_cache_size(3); | |
591 | cachesize[4] = 0; | |
592 | ||
593 | /* hw.packages */ | |
593a1d5f A |
594 | packages = roundup(ml_cpu_cache_sharing(0), cpuid_info()->thread_count) |
595 | / cpuid_info()->thread_count; | |
596 | ||
5ba3f43e A |
597 | #elif defined(__arm__) || defined(__arm64__) /* end __i386 */ |
598 | ||
599 | cpufamily = cpuid_get_cpufamily(); | |
600 | ||
601 | watchpoint_flag = arm_debug_info()->num_watchpoint_pairs; | |
602 | breakpoint_flag = arm_debug_info()->num_breakpoint_pairs; | |
603 | ||
5c9f4661 | 604 | arm_mvfp_info_t *mvfp_info = arm_mvfp_info(); |
5ba3f43e A |
605 | gNeon = mvfp_info->neon; |
606 | gNeonHpfp = mvfp_info->neon_hpfp; | |
d9a64523 | 607 | gNeonFp16 = mvfp_info->neon_fp16; |
5ba3f43e A |
608 | |
609 | cacheconfig[0] = ml_get_max_cpus(); | |
610 | cacheconfig[1] = 1; | |
611 | cacheconfig[2] = cache_info()->c_l2size ? 1:0; | |
612 | cacheconfig[3] = 0; | |
613 | cacheconfig[4] = 0; | |
614 | cacheconfig[5] = 0; | |
615 | cacheconfig[6] = 0; | |
616 | ||
617 | cachesize[0] = ml_get_machine_mem(); | |
618 | cachesize[1] = cache_info()->c_dsize; /* Using the DCache */ | |
619 | cachesize[2] = cache_info()->c_l2size; | |
620 | cachesize[3] = 0; | |
621 | cachesize[4] = 0; | |
622 | ||
623 | packages = 1; | |
316670eb A |
624 | #else |
625 | #error unknown architecture | |
fe8ab488 | 626 | #endif /* !__i386__ && !__x86_64 && !__arm__ && !__arm64__ */ |
43866e37 | 627 | |
43866e37 | 628 | } |