]>
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> |
cb323159 | 104 | #include <pexpert/device_tree.h> |
43866e37 A |
105 | |
106 | extern vm_map_t bsd_pageable_map; | |
107 | ||
91447636 | 108 | #include <sys/mount_internal.h> |
43866e37 A |
109 | #include <sys/kdebug.h> |
110 | ||
111 | #include <IOKit/IOPlatformExpert.h> | |
112 | #include <pexpert/pexpert.h> | |
113 | ||
114 | #include <machine/machine_routines.h> | |
115 | #include <machine/cpu_capabilities.h> | |
116 | ||
0a7de745 | 117 | #include <mach/mach_host.h> /* for host_info() */ |
2d21ac55 | 118 | |
b0d623f7 | 119 | #if defined(__i386__) || defined(__x86_64__) |
0a7de745 | 120 | #include <i386/cpuid.h> /* for cpuid_info() */ |
0c530ab8 A |
121 | #endif |
122 | ||
5ba3f43e | 123 | #if defined(__arm__) || defined(__arm64__) |
0a7de745 | 124 | #include <arm/cpuid.h> /* for cpuid_info() & cache_info() */ |
5ba3f43e | 125 | #endif |
2d21ac55 A |
126 | |
127 | ||
0c530ab8 | 128 | #ifndef MAX |
0a7de745 | 129 | #define MAX(a, b) (a >= b ? a : b) |
0c530ab8 A |
130 | #endif |
131 | ||
2d21ac55 A |
132 | /* XXX This should be in a BSD accessible Mach header, but isn't. */ |
133 | extern unsigned int vm_page_wire_count; | |
134 | ||
0a7de745 A |
135 | static int cputype, cpusubtype, cputhreadtype, cpufamily, cpu64bit; |
136 | static uint64_t cacheconfig[10], cachesize[10]; | |
137 | static int packages; | |
138 | ||
cb323159 A |
139 | static char * osenvironment; |
140 | static uint32_t osenvironment_size = 0; | |
141 | static uint32_t ephemeral_storage = 0; | |
142 | static uint32_t use_recovery_securityd = 0; | |
143 | ||
144 | static struct { | |
145 | uint32_t ephemeral_storage:1; | |
146 | uint32_t use_recovery_securityd:1; | |
147 | } property_existence = {0, 0}; | |
148 | ||
0a7de745 A |
149 | SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW | CTLFLAG_LOCKED, 0, |
150 | "Sysctl internal magic"); | |
151 | SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
152 | "High kernel, proc, limits &c"); | |
153 | SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
154 | "Virtual memory"); | |
155 | SYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
156 | "File system"); | |
157 | SYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
158 | "Network, (see socket.h)"); | |
159 | SYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
160 | "Debugging"); | |
161 | SYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
162 | "hardware"); | |
163 | SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
164 | "machine dependent"); | |
165 | SYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
166 | "user-level"); | |
167 | ||
168 | SYSCTL_NODE(_kern, OID_AUTO, bridge, CTLFLAG_RW | CTLFLAG_LOCKED, 0, | |
169 | "bridge"); | |
170 | ||
171 | #define SYSCTL_RETURN(r, x) SYSCTL_OUT(r, &x, sizeof(x)) | |
43866e37 A |
172 | |
173 | /****************************************************************************** | |
174 | * hw.* MIB | |
175 | */ | |
176 | ||
cb323159 A |
177 | #define CTLHW_RETQUAD (1U << 31) |
178 | #define CTLHW_LOCAL (1U << 30) | |
91447636 | 179 | |
0a7de745 A |
180 | #define HW_LOCAL_CPUTHREADTYPE (1 | CTLHW_LOCAL) |
181 | #define HW_LOCAL_PHYSICALCPU (2 | CTLHW_LOCAL) | |
182 | #define HW_LOCAL_PHYSICALCPUMAX (3 | CTLHW_LOCAL) | |
183 | #define HW_LOCAL_LOGICALCPU (4 | CTLHW_LOCAL) | |
184 | #define HW_LOCAL_LOGICALCPUMAX (5 | CTLHW_LOCAL) | |
91447636 | 185 | |
43866e37 A |
186 | |
187 | /* | |
a39ff7e2 | 188 | * Supporting some variables requires us to do "real" work. We |
43866e37 A |
189 | * gather some of that here. |
190 | */ | |
191 | static int | |
2d21ac55 | 192 | sysctl_hw_generic(__unused struct sysctl_oid *oidp, __unused void *arg1, |
0a7de745 | 193 | int arg2, struct sysctl_req *req) |
43866e37 A |
194 | { |
195 | char dummy[65]; | |
196 | int epochTemp; | |
43866e37 A |
197 | ml_cpu_info_t cpu_info; |
198 | int val, doquad; | |
199 | long long qval; | |
91447636 A |
200 | host_basic_info_data_t hinfo; |
201 | kern_return_t kret; | |
2d21ac55 | 202 | mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT; |
43866e37 A |
203 | |
204 | /* | |
205 | * Test and mask off the 'return quad' flag. | |
206 | * Note that only some things here support it. | |
207 | */ | |
208 | doquad = arg2 & CTLHW_RETQUAD; | |
209 | arg2 &= ~CTLHW_RETQUAD; | |
210 | ||
211 | ml_cpu_get_info(&cpu_info); | |
212 | ||
91447636 | 213 | #define BSD_HOST 1 |
2d21ac55 | 214 | kret = host_info((host_t)BSD_HOST, HOST_BASIC_INFO, (host_info_t)&hinfo, &count); |
91447636 | 215 | |
43866e37 A |
216 | /* |
217 | * Handle various OIDs. | |
218 | * | |
219 | * OIDs that can return int or quad set val and qval and then break. | |
220 | * Errors and int-only values return inline. | |
221 | */ | |
222 | switch (arg2) { | |
223 | case HW_NCPU: | |
91447636 | 224 | if (kret == KERN_SUCCESS) { |
0a7de745 | 225 | return SYSCTL_RETURN(req, hinfo.max_cpus); |
91447636 | 226 | } else { |
0a7de745 | 227 | return EINVAL; |
43866e37 A |
228 | } |
229 | case HW_AVAILCPU: | |
91447636 | 230 | if (kret == KERN_SUCCESS) { |
0a7de745 | 231 | return SYSCTL_RETURN(req, hinfo.avail_cpus); |
91447636 | 232 | } else { |
0a7de745 | 233 | return EINVAL; |
91447636 A |
234 | } |
235 | case HW_LOCAL_PHYSICALCPU: | |
236 | if (kret == KERN_SUCCESS) { | |
0a7de745 | 237 | return SYSCTL_RETURN(req, hinfo.physical_cpu); |
91447636 | 238 | } else { |
0a7de745 | 239 | return EINVAL; |
91447636 A |
240 | } |
241 | case HW_LOCAL_PHYSICALCPUMAX: | |
242 | if (kret == KERN_SUCCESS) { | |
0a7de745 | 243 | return SYSCTL_RETURN(req, hinfo.physical_cpu_max); |
91447636 | 244 | } else { |
0a7de745 | 245 | return EINVAL; |
91447636 A |
246 | } |
247 | case HW_LOCAL_LOGICALCPU: | |
248 | if (kret == KERN_SUCCESS) { | |
0a7de745 | 249 | return SYSCTL_RETURN(req, hinfo.logical_cpu); |
91447636 | 250 | } else { |
0a7de745 | 251 | return EINVAL; |
91447636 A |
252 | } |
253 | case HW_LOCAL_LOGICALCPUMAX: | |
254 | if (kret == KERN_SUCCESS) { | |
0a7de745 | 255 | return SYSCTL_RETURN(req, hinfo.logical_cpu_max); |
91447636 | 256 | } else { |
0a7de745 | 257 | return EINVAL; |
43866e37 | 258 | } |
39236c6e A |
259 | case HW_PAGESIZE: |
260 | { | |
261 | vm_map_t map = get_task_map(current_task()); | |
262 | val = vm_map_page_size(map); | |
263 | qval = (long long)val; | |
264 | break; | |
265 | } | |
43866e37 A |
266 | case HW_CACHELINE: |
267 | val = cpu_info.cache_line_size; | |
268 | qval = (long long)val; | |
269 | break; | |
270 | case HW_L1ICACHESIZE: | |
271 | val = cpu_info.l1_icache_size; | |
272 | qval = (long long)val; | |
273 | break; | |
274 | case HW_L1DCACHESIZE: | |
275 | val = cpu_info.l1_dcache_size; | |
276 | qval = (long long)val; | |
277 | break; | |
278 | case HW_L2CACHESIZE: | |
0a7de745 A |
279 | if (cpu_info.l2_cache_size == 0xFFFFFFFF) { |
280 | return EINVAL; | |
281 | } | |
43866e37 A |
282 | val = cpu_info.l2_cache_size; |
283 | qval = (long long)val; | |
284 | break; | |
285 | case HW_L3CACHESIZE: | |
0a7de745 A |
286 | if (cpu_info.l3_cache_size == 0xFFFFFFFF) { |
287 | return EINVAL; | |
288 | } | |
43866e37 A |
289 | val = cpu_info.l3_cache_size; |
290 | qval = (long long)val; | |
291 | break; | |
292 | ||
0a7de745 A |
293 | /* |
294 | * Deprecated variables. We still support these for | |
295 | * backwards compatibility purposes only. | |
296 | */ | |
43866e37 A |
297 | case HW_MACHINE: |
298 | bzero(dummy, sizeof(dummy)); | |
0a7de745 A |
299 | if (!PEGetMachineName(dummy, 64)) { |
300 | return EINVAL; | |
301 | } | |
43866e37 | 302 | dummy[64] = 0; |
0a7de745 | 303 | return SYSCTL_OUT(req, dummy, strlen(dummy) + 1); |
43866e37 A |
304 | case HW_MODEL: |
305 | bzero(dummy, sizeof(dummy)); | |
0a7de745 A |
306 | if (!PEGetModelName(dummy, 64)) { |
307 | return EINVAL; | |
308 | } | |
43866e37 | 309 | dummy[64] = 0; |
0a7de745 | 310 | return SYSCTL_OUT(req, dummy, strlen(dummy) + 1); |
43866e37 | 311 | case HW_USERMEM: |
0a7de745 | 312 | { |
43866e37 A |
313 | int usermem = mem_size - vm_page_wire_count * page_size; |
314 | ||
0a7de745 A |
315 | return SYSCTL_RETURN(req, usermem); |
316 | } | |
43866e37 | 317 | case HW_EPOCH: |
0a7de745 A |
318 | epochTemp = PEGetPlatformEpoch(); |
319 | if (epochTemp == -1) { | |
320 | return EINVAL; | |
321 | } | |
322 | return SYSCTL_RETURN(req, epochTemp); | |
0c530ab8 A |
323 | case HW_VECTORUNIT: { |
324 | int vector = cpu_info.vector_unit == 0? 0 : 1; | |
0a7de745 | 325 | return SYSCTL_RETURN(req, vector); |
0c530ab8 | 326 | } |
43866e37 | 327 | case HW_L2SETTINGS: |
0a7de745 A |
328 | if (cpu_info.l2_cache_size == 0xFFFFFFFF) { |
329 | return EINVAL; | |
330 | } | |
331 | return SYSCTL_RETURN(req, cpu_info.l2_settings); | |
43866e37 | 332 | case HW_L3SETTINGS: |
0a7de745 A |
333 | if (cpu_info.l3_cache_size == 0xFFFFFFFF) { |
334 | return EINVAL; | |
335 | } | |
336 | return SYSCTL_RETURN(req, cpu_info.l3_settings); | |
43866e37 | 337 | default: |
0a7de745 | 338 | return ENOTSUP; |
43866e37 A |
339 | } |
340 | /* | |
341 | * Callers may come to us with either int or quad buffers. | |
342 | */ | |
343 | if (doquad) { | |
0a7de745 | 344 | return SYSCTL_RETURN(req, qval); |
43866e37 | 345 | } |
0a7de745 | 346 | return SYSCTL_RETURN(req, val); |
43866e37 A |
347 | } |
348 | ||
2d21ac55 A |
349 | /* hw.pagesize and hw.tbfrequency are expected as 64 bit values */ |
350 | static int | |
351 | sysctl_pagesize | |
352 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
353 | { | |
39236c6e A |
354 | vm_map_t map = get_task_map(current_task()); |
355 | long long l = vm_map_page_size(map); | |
2d21ac55 A |
356 | return sysctl_io_number(req, l, sizeof(l), NULL, NULL); |
357 | } | |
358 | ||
3e170ce0 A |
359 | static int |
360 | sysctl_pagesize32 | |
361 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
362 | { | |
363 | long long l; | |
5ba3f43e A |
364 | #if __arm64__ |
365 | l = (long long) (1 << page_shift_user32); | |
366 | #else /* __arm64__ */ | |
3e170ce0 | 367 | l = (long long) PAGE_SIZE; |
5ba3f43e | 368 | #endif /* __arm64__ */ |
3e170ce0 A |
369 | return sysctl_io_number(req, l, sizeof(l), NULL, NULL); |
370 | } | |
371 | ||
2d21ac55 A |
372 | static int |
373 | sysctl_tbfrequency | |
374 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
375 | { | |
376 | long long l = gPEClockFrequencyInfo.timebase_frequency_hz; | |
377 | return sysctl_io_number(req, l, sizeof(l), NULL, NULL); | |
378 | } | |
379 | ||
cb323159 A |
380 | /* |
381 | * Create sysctl entries coming from device tree. | |
382 | * | |
383 | * Entries from device tree are loaded here because DTLookupEntry() only works before | |
384 | * PE_init_iokit(). Doing this also avoids the extern-C hackery to access these entries | |
385 | * from IORegistry (which requires C++). | |
386 | */ | |
387 | void | |
388 | sysctl_load_devicetree_entries(void) | |
389 | { | |
390 | DTEntry chosen; | |
391 | void *value; | |
392 | unsigned int size; | |
393 | ||
394 | if (kSuccess != DTLookupEntry(0, "/chosen", &chosen)) { | |
395 | return; | |
396 | } | |
397 | ||
398 | /* load osenvironment */ | |
399 | if (kSuccess == DTGetProperty(chosen, "osenvironment", (void **) &value, &size)) { | |
400 | MALLOC(osenvironment, char *, size, M_TEMP, M_WAITOK); | |
401 | if (osenvironment) { | |
402 | memcpy(osenvironment, value, size); | |
403 | osenvironment_size = size; | |
404 | } | |
405 | } | |
406 | ||
407 | /* load ephemeral_storage */ | |
408 | if (kSuccess == DTGetProperty(chosen, "ephemeral-storage", (void **) &value, &size)) { | |
409 | if (size == sizeof(uint32_t)) { | |
410 | ephemeral_storage = *(uint32_t *)value; | |
411 | property_existence.ephemeral_storage = 1; | |
412 | } | |
413 | } | |
414 | ||
415 | /* load use_recovery_securityd */ | |
416 | if (kSuccess == DTGetProperty(chosen, "use-recovery-securityd", (void **) &value, &size)) { | |
417 | if (size == sizeof(uint32_t)) { | |
418 | use_recovery_securityd = *(uint32_t *)value; | |
419 | property_existence.use_recovery_securityd = 1; | |
420 | } | |
421 | } | |
422 | } | |
423 | ||
424 | static int | |
425 | sysctl_osenvironment | |
426 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
427 | { | |
428 | if (osenvironment_size > 0) { | |
429 | return SYSCTL_OUT(req, osenvironment, osenvironment_size); | |
430 | } else { | |
431 | return EINVAL; | |
432 | } | |
433 | } | |
434 | ||
435 | static int | |
436 | sysctl_ephemeral_storage | |
437 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
438 | { | |
439 | if (property_existence.ephemeral_storage) { | |
440 | return SYSCTL_OUT(req, &ephemeral_storage, sizeof(ephemeral_storage)); | |
441 | } else { | |
442 | return EINVAL; | |
443 | } | |
444 | } | |
445 | ||
446 | static int | |
447 | sysctl_use_recovery_securityd | |
448 | (__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req) | |
449 | { | |
450 | if (property_existence.use_recovery_securityd) { | |
451 | return SYSCTL_OUT(req, &use_recovery_securityd, sizeof(use_recovery_securityd)); | |
452 | } else { | |
453 | return EINVAL; | |
454 | } | |
455 | } | |
456 | ||
43866e37 A |
457 | /* |
458 | * hw.* MIB variables. | |
459 | */ | |
0a7de745 A |
460 | SYSCTL_PROC(_hw, HW_NCPU, ncpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_NCPU, sysctl_hw_generic, "I", ""); |
461 | SYSCTL_PROC(_hw, HW_AVAILCPU, activecpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_AVAILCPU, sysctl_hw_generic, "I", ""); | |
462 | SYSCTL_PROC(_hw, OID_AUTO, physicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_PHYSICALCPU, sysctl_hw_generic, "I", ""); | |
463 | SYSCTL_PROC(_hw, OID_AUTO, physicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_PHYSICALCPUMAX, sysctl_hw_generic, "I", ""); | |
464 | SYSCTL_PROC(_hw, OID_AUTO, logicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_LOGICALCPU, sysctl_hw_generic, "I", ""); | |
465 | SYSCTL_PROC(_hw, OID_AUTO, logicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_LOGICALCPUMAX, sysctl_hw_generic, "I", ""); | |
466 | SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (int *)NULL, BYTE_ORDER, ""); | |
467 | SYSCTL_INT(_hw, OID_AUTO, cputype, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cputype, 0, ""); | |
468 | SYSCTL_INT(_hw, OID_AUTO, cpusubtype, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpusubtype, 0, ""); | |
469 | SYSCTL_INT(_hw, OID_AUTO, cpu64bit_capable, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpu64bit, 0, ""); | |
470 | SYSCTL_INT(_hw, OID_AUTO, cpufamily, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpufamily, 0, ""); | |
471 | SYSCTL_OPAQUE(_hw, OID_AUTO, cacheconfig, CTLFLAG_RD | CTLFLAG_LOCKED, &cacheconfig, sizeof(cacheconfig), "Q", ""); | |
472 | SYSCTL_OPAQUE(_hw, OID_AUTO, cachesize, CTLFLAG_RD | CTLFLAG_LOCKED, &cachesize, sizeof(cachesize), "Q", ""); | |
473 | SYSCTL_PROC(_hw, OID_AUTO, pagesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_pagesize, "Q", ""); | |
474 | SYSCTL_PROC(_hw, OID_AUTO, pagesize32, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_pagesize32, "Q", ""); | |
5ba3f43e | 475 | #if DEBUG || DEVELOPMENT || (!defined(__arm__) && !defined(__arm64__)) |
0a7de745 A |
476 | SYSCTL_QUAD(_hw, OID_AUTO, busfrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_hz, ""); |
477 | SYSCTL_QUAD(_hw, OID_AUTO, busfrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_min_hz, ""); | |
478 | SYSCTL_QUAD(_hw, OID_AUTO, busfrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_max_hz, ""); | |
479 | SYSCTL_QUAD(_hw, OID_AUTO, cpufrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_hz, ""); | |
480 | SYSCTL_QUAD(_hw, OID_AUTO, cpufrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_min_hz, ""); | |
481 | SYSCTL_QUAD(_hw, OID_AUTO, cpufrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_max_hz, ""); | |
5ba3f43e | 482 | #endif |
0a7de745 A |
483 | SYSCTL_PROC(_hw, OID_AUTO, cachelinesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_CACHELINE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); |
484 | SYSCTL_PROC(_hw, OID_AUTO, l1icachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L1ICACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
485 | SYSCTL_PROC(_hw, OID_AUTO, l1dcachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L1DCACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
486 | SYSCTL_PROC(_hw, OID_AUTO, l2cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L2CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
487 | SYSCTL_PROC(_hw, OID_AUTO, l3cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L3CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", ""); | |
5ba3f43e | 488 | #if (defined(__arm__) || defined(__arm64__)) && (DEBUG || DEVELOPMENT) |
0a7de745 A |
489 | SYSCTL_QUAD(_hw, OID_AUTO, memfrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.mem_frequency_hz, ""); |
490 | SYSCTL_QUAD(_hw, OID_AUTO, memfrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.mem_frequency_min_hz, ""); | |
491 | SYSCTL_QUAD(_hw, OID_AUTO, memfrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.mem_frequency_max_hz, ""); | |
492 | SYSCTL_QUAD(_hw, OID_AUTO, prffrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.prf_frequency_hz, ""); | |
493 | SYSCTL_QUAD(_hw, OID_AUTO, prffrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.prf_frequency_min_hz, ""); | |
494 | SYSCTL_QUAD(_hw, OID_AUTO, prffrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.prf_frequency_max_hz, ""); | |
495 | SYSCTL_QUAD(_hw, OID_AUTO, fixfrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.fix_frequency_hz, ""); | |
5ba3f43e | 496 | #endif /* __arm__ || __arm64__ */ |
6d2010ae | 497 | SYSCTL_PROC(_hw, OID_AUTO, tbfrequency, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_tbfrequency, "Q", ""); |
0a7de745 A |
498 | SYSCTL_QUAD(_hw, HW_MEMSIZE, memsize, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &max_mem, ""); |
499 | SYSCTL_INT(_hw, OID_AUTO, packages, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &packages, 0, ""); | |
cb323159 A |
500 | SYSCTL_PROC(_hw, OID_AUTO, osenvironment, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_osenvironment, "A", ""); |
501 | SYSCTL_PROC(_hw, OID_AUTO, ephemeral_storage, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_ephemeral_storage, "I", ""); | |
502 | SYSCTL_PROC(_hw, OID_AUTO, use_recovery_securityd, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_use_recovery_securityd, "I", ""); | |
43866e37 A |
503 | |
504 | /* | |
39037602 | 505 | * Optional CPU features can register nodes below hw.optional. |
43866e37 A |
506 | * |
507 | * If the feature is not present, the node should either not be registered, | |
508 | * or it should return -1. If the feature is present, the node should return | |
a39ff7e2 | 509 | * 0. If the feature is present and its use is advised, the node should |
43866e37 A |
510 | * return 1. |
511 | */ | |
0a7de745 | 512 | SYSCTL_NODE(_hw, OID_AUTO, optional, CTLFLAG_RW | CTLFLAG_LOCKED, NULL, "optional features"); |
43866e37 | 513 | |
0a7de745 | 514 | SYSCTL_INT(_hw_optional, OID_AUTO, floatingpoint, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (int *)NULL, 1, ""); /* always set */ |
43866e37 | 515 | |
39037602 A |
516 | /* |
517 | * Optional device hardware features can be registered by drivers below hw.features | |
518 | */ | |
519 | SYSCTL_NODE(_hw, OID_AUTO, features, CTLFLAG_RD | CTLFLAG_LOCKED, NULL, "hardware features"); | |
520 | ||
43866e37 A |
521 | /* |
522 | * Deprecated variables. These are supported for backwards compatibility | |
523 | * purposes only. The MASKED flag requests that the variables not be | |
524 | * printed by sysctl(8) and similar utilities. | |
525 | * | |
526 | * The variables named *_compat here are int-sized versions of variables | |
527 | * that are now exported as quads. The int-sized versions are normally | |
528 | * looked up only by number, wheras the quad-sized versions should be | |
529 | * looked up by name. | |
530 | * | |
531 | * The *_compat nodes are *NOT* visible within the kernel. | |
532 | */ | |
0a7de745 | 533 | SYSCTL_PROC(_hw, HW_PAGESIZE, pagesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_PAGESIZE, sysctl_hw_generic, "I", ""); |
5ba3f43e | 534 | #if DEBUG || DEVELOPMENT || (!defined(__arm__) && !defined(__arm64__)) |
0a7de745 A |
535 | SYSCTL_COMPAT_INT(_hw, HW_BUS_FREQ, busfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_clock_rate_hz, 0, ""); |
536 | SYSCTL_COMPAT_INT(_hw, HW_CPU_FREQ, cpufrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_clock_rate_hz, 0, ""); | |
5ba3f43e | 537 | #endif |
0a7de745 | 538 | SYSCTL_PROC(_hw, HW_CACHELINE, cachelinesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_CACHELINE, sysctl_hw_generic, "I", ""); |
6d2010ae A |
539 | SYSCTL_PROC(_hw, HW_L1ICACHESIZE, l1icachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L1ICACHESIZE, sysctl_hw_generic, "I", ""); |
540 | SYSCTL_PROC(_hw, HW_L1DCACHESIZE, l1dcachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L1DCACHESIZE, sysctl_hw_generic, "I", ""); | |
0a7de745 A |
541 | SYSCTL_PROC(_hw, HW_L2CACHESIZE, l2cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L2CACHESIZE, sysctl_hw_generic, "I", ""); |
542 | SYSCTL_PROC(_hw, HW_L3CACHESIZE, l3cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L3CACHESIZE, sysctl_hw_generic, "I", ""); | |
543 | SYSCTL_COMPAT_INT(_hw, HW_TB_FREQ, tbfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.timebase_frequency_hz, 0, ""); | |
544 | SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_MACHINE, sysctl_hw_generic, "A", ""); | |
545 | SYSCTL_PROC(_hw, HW_MODEL, model, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_MODEL, sysctl_hw_generic, "A", ""); | |
546 | SYSCTL_COMPAT_UINT(_hw, HW_PHYSMEM, physmem, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &mem_size, 0, ""); | |
547 | SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_USERMEM, sysctl_hw_generic, "I", ""); | |
548 | SYSCTL_PROC(_hw, HW_EPOCH, epoch, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_EPOCH, sysctl_hw_generic, "I", ""); | |
549 | SYSCTL_PROC(_hw, HW_VECTORUNIT, vectorunit, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_VECTORUNIT, sysctl_hw_generic, "I", ""); | |
550 | SYSCTL_PROC(_hw, HW_L2SETTINGS, l2settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L2SETTINGS, sysctl_hw_generic, "I", ""); | |
551 | SYSCTL_PROC(_hw, HW_L3SETTINGS, l3settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L3SETTINGS, sysctl_hw_generic, "I", ""); | |
552 | SYSCTL_INT(_hw, OID_AUTO, cputhreadtype, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN | CTLFLAG_LOCKED, &cputhreadtype, 0, ""); | |
6d2010ae | 553 | |
316670eb | 554 | #if defined(__i386__) || defined(__x86_64__) |
bd504ef0 A |
555 | static int |
556 | sysctl_cpu_capability | |
557 | (__unused struct sysctl_oid *oidp, void *arg1, __unused int arg2, struct sysctl_req *req) | |
558 | { | |
0a7de745 A |
559 | uint64_t mask = (uint64_t) (uintptr_t) arg1; |
560 | boolean_t is_capable = (_get_cpu_capabilities() & mask) != 0; | |
a39ff7e2 | 561 | |
bd504ef0 | 562 | return SYSCTL_OUT(req, &is_capable, sizeof(is_capable)); |
bd504ef0 A |
563 | } |
564 | ||
0a7de745 A |
565 | SYSCTL_PROC(_hw_optional, OID_AUTO, mmx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasMMX, 0, sysctl_cpu_capability, "I", ""); |
566 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE, 0, sysctl_cpu_capability, "I", ""); | |
567 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse2, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE2, 0, sysctl_cpu_capability, "I", ""); | |
568 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse3, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE3, 0, sysctl_cpu_capability, "I", ""); | |
569 | SYSCTL_PROC(_hw_optional, OID_AUTO, supplementalsse3, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSupplementalSSE3, 0, sysctl_cpu_capability, "I", ""); | |
570 | SYSCTL_PROC(_hw_optional, OID_AUTO, sse4_1, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE4_1, 0, sysctl_cpu_capability, "I", ""); | |
571 | 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 |
572 | /* "x86_64" is actually a preprocessor symbol on the x86_64 kernel, so we have to hack this */ |
573 | #undef x86_64 | |
0a7de745 A |
574 | SYSCTL_PROC(_hw_optional, OID_AUTO, x86_64, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) k64Bit, 0, sysctl_cpu_capability, "I", ""); |
575 | SYSCTL_PROC(_hw_optional, OID_AUTO, aes, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAES, 0, sysctl_cpu_capability, "I", ""); | |
576 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx1_0, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX1_0, 0, sysctl_cpu_capability, "I", ""); | |
577 | SYSCTL_PROC(_hw_optional, OID_AUTO, rdrand, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasRDRAND, 0, sysctl_cpu_capability, "I", ""); | |
578 | SYSCTL_PROC(_hw_optional, OID_AUTO, f16c, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasF16C, 0, sysctl_cpu_capability, "I", ""); | |
579 | SYSCTL_PROC(_hw_optional, OID_AUTO, enfstrg, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasENFSTRG, 0, sysctl_cpu_capability, "I", ""); | |
580 | SYSCTL_PROC(_hw_optional, OID_AUTO, fma, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasFMA, 0, sysctl_cpu_capability, "I", ""); | |
581 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx2_0, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX2_0, 0, sysctl_cpu_capability, "I", ""); | |
582 | SYSCTL_PROC(_hw_optional, OID_AUTO, bmi1, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasBMI1, 0, sysctl_cpu_capability, "I", ""); | |
583 | SYSCTL_PROC(_hw_optional, OID_AUTO, bmi2, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasBMI2, 0, sysctl_cpu_capability, "I", ""); | |
584 | SYSCTL_PROC(_hw_optional, OID_AUTO, rtm, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasRTM, 0, sysctl_cpu_capability, "I", ""); | |
585 | SYSCTL_PROC(_hw_optional, OID_AUTO, hle, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasHLE, 0, sysctl_cpu_capability, "I", ""); | |
586 | SYSCTL_PROC(_hw_optional, OID_AUTO, adx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasADX, 0, sysctl_cpu_capability, "I", ""); | |
587 | SYSCTL_PROC(_hw_optional, OID_AUTO, mpx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasMPX, 0, sysctl_cpu_capability, "I", ""); | |
588 | SYSCTL_PROC(_hw_optional, OID_AUTO, sgx, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSGX, 0, sysctl_cpu_capability, "I", ""); | |
0a7de745 A |
589 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512f, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512F, 0, sysctl_cpu_capability, "I", ""); |
590 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512cd, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512CD, 0, sysctl_cpu_capability, "I", ""); | |
591 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512dq, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512DQ, 0, sysctl_cpu_capability, "I", ""); | |
592 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512bw, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512BW, 0, sysctl_cpu_capability, "I", ""); | |
593 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512vl, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512VL, 0, sysctl_cpu_capability, "I", ""); | |
594 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512ifma, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512IFMA, 0, sysctl_cpu_capability, "I", ""); | |
595 | SYSCTL_PROC(_hw_optional, OID_AUTO, avx512vbmi, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX512VBMI, 0, sysctl_cpu_capability, "I", ""); | |
5ba3f43e A |
596 | #elif defined (__arm__) || defined (__arm64__) |
597 | int watchpoint_flag = -1; | |
598 | int breakpoint_flag = -1; | |
599 | int gNeon = -1; | |
600 | int gNeonHpfp = -1; | |
d9a64523 | 601 | int gNeonFp16 = -1; |
5ba3f43e | 602 | int gARMv81Atomics = 0; |
d9a64523 | 603 | int gARMv8Crc32 = 0; |
cb323159 | 604 | int gARMv82FHM = 0; |
5ba3f43e A |
605 | |
606 | #if defined (__arm__) | |
607 | int arm64_flag = 0; | |
608 | #elif defined (__arm64__) /* end __arm__*/ | |
609 | int arm64_flag = 1; | |
610 | #else /* end __arm64__*/ | |
611 | int arm64_flag = -1; | |
612 | #endif | |
613 | ||
614 | SYSCTL_INT(_hw_optional, OID_AUTO, watchpoint, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &watchpoint_flag, 0, ""); | |
615 | SYSCTL_INT(_hw_optional, OID_AUTO, breakpoint, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &breakpoint_flag, 0, ""); | |
616 | SYSCTL_INT(_hw_optional, OID_AUTO, neon, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gNeon, 0, ""); | |
617 | SYSCTL_INT(_hw_optional, OID_AUTO, neon_hpfp, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gNeonHpfp, 0, ""); | |
d9a64523 | 618 | SYSCTL_INT(_hw_optional, OID_AUTO, neon_fp16, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gNeonFp16, 0, ""); |
5ba3f43e | 619 | SYSCTL_INT(_hw_optional, OID_AUTO, armv8_1_atomics, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gARMv81Atomics, 0, ""); |
d9a64523 | 620 | SYSCTL_INT(_hw_optional, OID_AUTO, armv8_crc32, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gARMv8Crc32, 0, ""); |
cb323159 | 621 | SYSCTL_INT(_hw_optional, OID_AUTO, armv8_2_fhm, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gARMv82FHM, 0, ""); |
5ba3f43e A |
622 | |
623 | /* | |
624 | * Without this little ifdef dance, the preprocessor replaces "arm64" with "1", | |
625 | * leaving us with a less-than-helpful sysctl.hwoptional.1. | |
626 | */ | |
627 | #ifdef arm64 | |
628 | #undef arm64 | |
629 | SYSCTL_INT(_hw_optional, OID_AUTO, arm64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &arm64_flag, 0, ""); | |
630 | #define arm64 1 | |
631 | #else | |
632 | SYSCTL_INT(_hw_optional, OID_AUTO, arm64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &arm64_flag, 0, ""); | |
633 | #endif | |
634 | ||
316670eb A |
635 | #else |
636 | #error Unsupported arch | |
fe8ab488 | 637 | #endif /* !__i386__ && !__x86_64 && !__arm__ && ! __arm64__ */ |
43866e37 | 638 | |
0c530ab8 | 639 | |
43866e37 A |
640 | /****************************************************************************** |
641 | * Generic MIB initialisation. | |
642 | * | |
643 | * This is a hack, and should be replaced with SYSINITs | |
644 | * at some point. | |
645 | */ | |
646 | void | |
647 | sysctl_mib_init(void) | |
648 | { | |
91447636 A |
649 | cputype = cpu_type(); |
650 | cpusubtype = cpu_subtype(); | |
651 | cputhreadtype = cpu_threadtype(); | |
6d2010ae | 652 | #if defined(__i386__) || defined (__x86_64__) |
39236c6e | 653 | cpu64bit = (_get_cpu_capabilities() & k64Bit) == k64Bit; |
5ba3f43e A |
654 | #elif defined(__arm__) || defined (__arm64__) |
655 | cpu64bit = (cputype & CPU_ARCH_ABI64) == CPU_ARCH_ABI64; | |
316670eb A |
656 | #else |
657 | #error Unsupported arch | |
2d21ac55 | 658 | #endif |
91447636 | 659 | |
43866e37 A |
660 | /* |
661 | * Populate the optional portion of the hw.* MIB. | |
662 | * | |
663 | * XXX This could be broken out into parts of the code | |
664 | * that actually directly relate to the functions in | |
665 | * question. | |
666 | */ | |
91447636 A |
667 | |
668 | if (cputhreadtype != CPU_THREADTYPE_NONE) { | |
91447636 A |
669 | sysctl_register_oid(&sysctl__hw_cputhreadtype); |
670 | } | |
671 | ||
6d2010ae | 672 | #if defined (__i386__) || defined (__x86_64__) |
0c530ab8 | 673 | /* hw.cpufamily */ |
7e4a7d39 A |
674 | cpufamily = cpuid_cpufamily(); |
675 | ||
0c530ab8 | 676 | /* hw.cacheconfig */ |
2d21ac55 A |
677 | cacheconfig[0] = ml_cpu_cache_sharing(0); |
678 | cacheconfig[1] = ml_cpu_cache_sharing(1); | |
679 | cacheconfig[2] = ml_cpu_cache_sharing(2); | |
680 | cacheconfig[3] = ml_cpu_cache_sharing(3); | |
0c530ab8 A |
681 | cacheconfig[4] = 0; |
682 | ||
2d21ac55 A |
683 | /* hw.cachesize */ |
684 | cachesize[0] = ml_cpu_cache_size(0); | |
685 | cachesize[1] = ml_cpu_cache_size(1); | |
686 | cachesize[2] = ml_cpu_cache_size(2); | |
687 | cachesize[3] = ml_cpu_cache_size(3); | |
688 | cachesize[4] = 0; | |
689 | ||
690 | /* hw.packages */ | |
593a1d5f | 691 | packages = roundup(ml_cpu_cache_sharing(0), cpuid_info()->thread_count) |
0a7de745 | 692 | / cpuid_info()->thread_count; |
593a1d5f | 693 | |
5ba3f43e A |
694 | #elif defined(__arm__) || defined(__arm64__) /* end __i386 */ |
695 | ||
696 | cpufamily = cpuid_get_cpufamily(); | |
697 | ||
698 | watchpoint_flag = arm_debug_info()->num_watchpoint_pairs; | |
699 | breakpoint_flag = arm_debug_info()->num_breakpoint_pairs; | |
700 | ||
5c9f4661 | 701 | arm_mvfp_info_t *mvfp_info = arm_mvfp_info(); |
5ba3f43e A |
702 | gNeon = mvfp_info->neon; |
703 | gNeonHpfp = mvfp_info->neon_hpfp; | |
d9a64523 | 704 | gNeonFp16 = mvfp_info->neon_fp16; |
5ba3f43e A |
705 | |
706 | cacheconfig[0] = ml_get_max_cpus(); | |
707 | cacheconfig[1] = 1; | |
708 | cacheconfig[2] = cache_info()->c_l2size ? 1:0; | |
709 | cacheconfig[3] = 0; | |
710 | cacheconfig[4] = 0; | |
711 | cacheconfig[5] = 0; | |
712 | cacheconfig[6] = 0; | |
713 | ||
714 | cachesize[0] = ml_get_machine_mem(); | |
715 | cachesize[1] = cache_info()->c_dsize; /* Using the DCache */ | |
716 | cachesize[2] = cache_info()->c_l2size; | |
717 | cachesize[3] = 0; | |
718 | cachesize[4] = 0; | |
719 | ||
720 | packages = 1; | |
cb323159 | 721 | |
316670eb A |
722 | #else |
723 | #error unknown architecture | |
fe8ab488 | 724 | #endif /* !__i386__ && !__x86_64 && !__arm__ && !__arm64__ */ |
43866e37 | 725 | } |