]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/kern_mib.c
xnu-2422.110.17.tar.gz
[apple/xnu.git] / bsd / kern / kern_mib.c
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
5d5c5d0d 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 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.
8f6c56a5 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.
17 *
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.
8f6c56a5 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>
43866e37 101#include <mach/host_info.h>
0c530ab8 102#include <kern/pms.h>
43866e37
A
103
104extern vm_map_t bsd_pageable_map;
105
91447636 106#include <sys/mount_internal.h>
43866e37
A
107#include <sys/kdebug.h>
108
109#include <IOKit/IOPlatformExpert.h>
110#include <pexpert/pexpert.h>
111
112#include <machine/machine_routines.h>
113#include <machine/cpu_capabilities.h>
114
2d21ac55
A
115#include <mach/mach_host.h> /* for host_info() */
116
b0d623f7
A
117#if defined(__i386__) || defined(__x86_64__)
118#include <i386/cpuid.h> /* for cpuid_info() */
0c530ab8
A
119#endif
120
2d21ac55
A
121
122
0c530ab8
A
123#ifndef MAX
124#define MAX(a,b) (a >= b ? a : b)
125#endif
126
2d21ac55
A
127/* XXX This should be in a BSD accessible Mach header, but isn't. */
128extern unsigned int vm_page_wire_count;
129
130static int cputype, cpusubtype, cputhreadtype, cpufamily, cpu64bit;
131static uint64_t cacheconfig[10], cachesize[10];
132static int packages;
43866e37 133
2d21ac55 134SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 135 "Sysctl internal magic");
2d21ac55 136SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 137 "High kernel, proc, limits &c");
2d21ac55 138SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 139 "Virtual memory");
2d21ac55 140SYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 141 "File system");
2d21ac55 142SYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 143 "Network, (see socket.h)");
2d21ac55 144SYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 145 "Debugging");
2d21ac55 146SYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 147 "hardware");
2d21ac55 148SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b 149 "machine dependent");
2d21ac55 150SYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
1c79356b
A
151 "user-level");
152
43866e37
A
153#define SYSCTL_RETURN(r, x) SYSCTL_OUT(r, &x, sizeof(x))
154
155/******************************************************************************
156 * hw.* MIB
157 */
158
159#define CTLHW_RETQUAD (1 << 31)
91447636
A
160#define CTLHW_LOCAL (1 << 30)
161
162#define HW_LOCAL_CPUTHREADTYPE (1 | CTLHW_LOCAL)
163#define HW_LOCAL_PHYSICALCPU (2 | CTLHW_LOCAL)
164#define HW_LOCAL_PHYSICALCPUMAX (3 | CTLHW_LOCAL)
165#define HW_LOCAL_LOGICALCPU (4 | CTLHW_LOCAL)
166#define HW_LOCAL_LOGICALCPUMAX (5 | CTLHW_LOCAL)
167
43866e37
A
168
169/*
170 * Supporting some variables requires us to do "real" work. We
171 * gather some of that here.
172 */
173static int
2d21ac55
A
174sysctl_hw_generic(__unused struct sysctl_oid *oidp, __unused void *arg1,
175 int arg2, struct sysctl_req *req)
43866e37
A
176{
177 char dummy[65];
178 int epochTemp;
43866e37
A
179 ml_cpu_info_t cpu_info;
180 int val, doquad;
181 long long qval;
91447636
A
182 host_basic_info_data_t hinfo;
183 kern_return_t kret;
2d21ac55 184 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
43866e37
A
185
186 /*
187 * Test and mask off the 'return quad' flag.
188 * Note that only some things here support it.
189 */
190 doquad = arg2 & CTLHW_RETQUAD;
191 arg2 &= ~CTLHW_RETQUAD;
192
193 ml_cpu_get_info(&cpu_info);
194
91447636 195#define BSD_HOST 1
2d21ac55 196 kret = host_info((host_t)BSD_HOST, HOST_BASIC_INFO, (host_info_t)&hinfo, &count);
91447636 197
43866e37
A
198 /*
199 * Handle various OIDs.
200 *
201 * OIDs that can return int or quad set val and qval and then break.
202 * Errors and int-only values return inline.
203 */
204 switch (arg2) {
205 case HW_NCPU:
91447636
A
206 if (kret == KERN_SUCCESS) {
207 return(SYSCTL_RETURN(req, hinfo.max_cpus));
208 } else {
209 return(EINVAL);
43866e37
A
210 }
211 case HW_AVAILCPU:
91447636
A
212 if (kret == KERN_SUCCESS) {
213 return(SYSCTL_RETURN(req, hinfo.avail_cpus));
214 } else {
215 return(EINVAL);
216 }
217 case HW_LOCAL_PHYSICALCPU:
218 if (kret == KERN_SUCCESS) {
219 return(SYSCTL_RETURN(req, hinfo.physical_cpu));
220 } else {
221 return(EINVAL);
222 }
223 case HW_LOCAL_PHYSICALCPUMAX:
224 if (kret == KERN_SUCCESS) {
225 return(SYSCTL_RETURN(req, hinfo.physical_cpu_max));
226 } else {
227 return(EINVAL);
228 }
229 case HW_LOCAL_LOGICALCPU:
230 if (kret == KERN_SUCCESS) {
231 return(SYSCTL_RETURN(req, hinfo.logical_cpu));
232 } else {
233 return(EINVAL);
234 }
235 case HW_LOCAL_LOGICALCPUMAX:
236 if (kret == KERN_SUCCESS) {
237 return(SYSCTL_RETURN(req, hinfo.logical_cpu_max));
238 } else {
239 return(EINVAL);
43866e37 240 }
39236c6e
A
241 case HW_PAGESIZE:
242 {
243 vm_map_t map = get_task_map(current_task());
244 val = vm_map_page_size(map);
245 qval = (long long)val;
246 break;
247 }
43866e37
A
248 case HW_CACHELINE:
249 val = cpu_info.cache_line_size;
250 qval = (long long)val;
251 break;
252 case HW_L1ICACHESIZE:
253 val = cpu_info.l1_icache_size;
254 qval = (long long)val;
255 break;
256 case HW_L1DCACHESIZE:
257 val = cpu_info.l1_dcache_size;
258 qval = (long long)val;
259 break;
260 case HW_L2CACHESIZE:
261 if (cpu_info.l2_cache_size == 0xFFFFFFFF)
262 return(EINVAL);
263 val = cpu_info.l2_cache_size;
264 qval = (long long)val;
265 break;
266 case HW_L3CACHESIZE:
267 if (cpu_info.l3_cache_size == 0xFFFFFFFF)
268 return(EINVAL);
269 val = cpu_info.l3_cache_size;
270 qval = (long long)val;
271 break;
272
273 /*
274 * Deprecated variables. We still support these for
275 * backwards compatibility purposes only.
276 */
277 case HW_MACHINE:
278 bzero(dummy, sizeof(dummy));
279 if(!PEGetMachineName(dummy,64))
280 return(EINVAL);
281 dummy[64] = 0;
282 return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
283 case HW_MODEL:
284 bzero(dummy, sizeof(dummy));
285 if(!PEGetModelName(dummy,64))
286 return(EINVAL);
287 dummy[64] = 0;
288 return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
289 case HW_USERMEM:
290 {
291 int usermem = mem_size - vm_page_wire_count * page_size;
292
293 return(SYSCTL_RETURN(req, usermem));
294 }
295 case HW_EPOCH:
296 epochTemp = PEGetPlatformEpoch();
297 if (epochTemp == -1)
298 return(EINVAL);
299 return(SYSCTL_RETURN(req, epochTemp));
0c530ab8
A
300 case HW_VECTORUNIT: {
301 int vector = cpu_info.vector_unit == 0? 0 : 1;
302 return(SYSCTL_RETURN(req, vector));
303 }
43866e37
A
304 case HW_L2SETTINGS:
305 if (cpu_info.l2_cache_size == 0xFFFFFFFF)
306 return(EINVAL);
307 return(SYSCTL_RETURN(req, cpu_info.l2_settings));
308 case HW_L3SETTINGS:
309 if (cpu_info.l3_cache_size == 0xFFFFFFFF)
310 return(EINVAL);
311 return(SYSCTL_RETURN(req, cpu_info.l3_settings));
312 default:
313 return(ENOTSUP);
314 }
315 /*
316 * Callers may come to us with either int or quad buffers.
317 */
318 if (doquad) {
319 return(SYSCTL_RETURN(req, qval));
320 }
321 return(SYSCTL_RETURN(req, val));
322}
323
2d21ac55
A
324/* hw.pagesize and hw.tbfrequency are expected as 64 bit values */
325static int
326sysctl_pagesize
327(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
328{
39236c6e
A
329 vm_map_t map = get_task_map(current_task());
330 long long l = vm_map_page_size(map);
2d21ac55
A
331 return sysctl_io_number(req, l, sizeof(l), NULL, NULL);
332}
333
334static int
335sysctl_tbfrequency
336(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
337{
338 long long l = gPEClockFrequencyInfo.timebase_frequency_hz;
339 return sysctl_io_number(req, l, sizeof(l), NULL, NULL);
340}
341
43866e37
A
342/*
343 * hw.* MIB variables.
344 */
6d2010ae
A
345SYSCTL_PROC (_hw, HW_NCPU, ncpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_NCPU, sysctl_hw_generic, "I", "");
346SYSCTL_PROC (_hw, HW_AVAILCPU, activecpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_AVAILCPU, sysctl_hw_generic, "I", "");
347SYSCTL_PROC (_hw, OID_AUTO, physicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_PHYSICALCPU, sysctl_hw_generic, "I", "");
348SYSCTL_PROC (_hw, OID_AUTO, physicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_PHYSICALCPUMAX, sysctl_hw_generic, "I", "");
349SYSCTL_PROC (_hw, OID_AUTO, logicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_LOGICALCPU, sysctl_hw_generic, "I", "");
350SYSCTL_PROC (_hw, OID_AUTO, logicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_LOCAL_LOGICALCPUMAX, sysctl_hw_generic, "I", "");
351SYSCTL_INT (_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (int *)NULL, BYTE_ORDER, "");
352SYSCTL_INT (_hw, OID_AUTO, cputype, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cputype, 0, "");
353SYSCTL_INT (_hw, OID_AUTO, cpusubtype, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpusubtype, 0, "");
354SYSCTL_INT (_hw, OID_AUTO, cpu64bit_capable, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpu64bit, 0, "");
355SYSCTL_INT (_hw, OID_AUTO, cpufamily, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &cpufamily, 0, "");
356SYSCTL_OPAQUE (_hw, OID_AUTO, cacheconfig, CTLFLAG_RD | CTLFLAG_LOCKED, &cacheconfig, sizeof(cacheconfig), "Q", "");
357SYSCTL_OPAQUE (_hw, OID_AUTO, cachesize, CTLFLAG_RD | CTLFLAG_LOCKED, &cachesize, sizeof(cachesize), "Q", "");
358SYSCTL_PROC (_hw, OID_AUTO, pagesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_pagesize, "Q", "");
359SYSCTL_QUAD (_hw, OID_AUTO, busfrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_hz, "");
360SYSCTL_QUAD (_hw, OID_AUTO, busfrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_min_hz, "");
361SYSCTL_QUAD (_hw, OID_AUTO, busfrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_frequency_max_hz, "");
362SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_hz, "");
363SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency_min, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_min_hz, "");
364SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency_max, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_frequency_max_hz, "");
365SYSCTL_PROC (_hw, OID_AUTO, cachelinesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_CACHELINE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
366SYSCTL_PROC (_hw, OID_AUTO, l1icachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L1ICACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
367SYSCTL_PROC (_hw, OID_AUTO, l1dcachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L1DCACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
368SYSCTL_PROC (_hw, OID_AUTO, l2cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L2CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
369SYSCTL_PROC (_hw, OID_AUTO, l3cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, HW_L3CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
370SYSCTL_PROC(_hw, OID_AUTO, tbfrequency, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, 0, 0, sysctl_tbfrequency, "Q", "");
371SYSCTL_QUAD (_hw, HW_MEMSIZE, memsize, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &max_mem, "");
372SYSCTL_INT (_hw, OID_AUTO, packages, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, &packages, 0, "");
43866e37
A
373
374/*
375 * Optional features can register nodes below hw.optional.
376 *
377 * If the feature is not present, the node should either not be registered,
378 * or it should return -1. If the feature is present, the node should return
379 * 0. If the feature is present and its use is advised, the node should
380 * return 1.
381 */
2d21ac55 382SYSCTL_NODE(_hw, OID_AUTO, optional, CTLFLAG_RW|CTLFLAG_LOCKED, NULL, "optional features");
43866e37 383
6d2010ae 384SYSCTL_INT(_hw_optional, OID_AUTO, floatingpoint, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (int *)NULL, 1, ""); /* always set */
43866e37 385
43866e37
A
386/*
387 * Deprecated variables. These are supported for backwards compatibility
388 * purposes only. The MASKED flag requests that the variables not be
389 * printed by sysctl(8) and similar utilities.
390 *
391 * The variables named *_compat here are int-sized versions of variables
392 * that are now exported as quads. The int-sized versions are normally
393 * looked up only by number, wheras the quad-sized versions should be
394 * looked up by name.
395 *
396 * The *_compat nodes are *NOT* visible within the kernel.
397 */
39236c6e 398SYSCTL_PROC(_hw, HW_PAGESIZE, pagesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_PAGESIZE, sysctl_hw_generic, "I", "");
6d2010ae
A
399SYSCTL_COMPAT_INT (_hw, HW_BUS_FREQ, busfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.bus_clock_rate_hz, 0, "");
400SYSCTL_COMPAT_INT (_hw, HW_CPU_FREQ, cpufrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.cpu_clock_rate_hz, 0, "");
401SYSCTL_PROC(_hw, HW_CACHELINE, cachelinesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_CACHELINE, sysctl_hw_generic, "I", "");
402SYSCTL_PROC(_hw, HW_L1ICACHESIZE, l1icachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L1ICACHESIZE, sysctl_hw_generic, "I", "");
403SYSCTL_PROC(_hw, HW_L1DCACHESIZE, l1dcachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L1DCACHESIZE, sysctl_hw_generic, "I", "");
404SYSCTL_PROC(_hw, HW_L2CACHESIZE, l2cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L2CACHESIZE, sysctl_hw_generic, "I", "");
405SYSCTL_PROC(_hw, HW_L3CACHESIZE, l3cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L3CACHESIZE, sysctl_hw_generic, "I", "");
406SYSCTL_COMPAT_INT (_hw, HW_TB_FREQ, tbfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &gPEClockFrequencyInfo.timebase_frequency_hz, 0, "");
407SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_MACHINE, sysctl_hw_generic, "A", "");
408SYSCTL_PROC(_hw, HW_MODEL, model, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_MODEL, sysctl_hw_generic, "A", "");
409SYSCTL_COMPAT_UINT(_hw, HW_PHYSMEM, physmem, CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, &mem_size, 0, "");
410SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_USERMEM, sysctl_hw_generic, "I", "");
411SYSCTL_PROC(_hw, HW_EPOCH, epoch, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_EPOCH, sysctl_hw_generic, "I", "");
412SYSCTL_PROC(_hw, HW_VECTORUNIT, vectorunit, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_VECTORUNIT, sysctl_hw_generic, "I", "");
413SYSCTL_PROC(_hw, HW_L2SETTINGS, l2settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L2SETTINGS, sysctl_hw_generic, "I", "");
414SYSCTL_PROC(_hw, HW_L3SETTINGS, l3settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED | CTLFLAG_LOCKED, 0, HW_L3SETTINGS, sysctl_hw_generic, "I", "");
415SYSCTL_INT (_hw, OID_AUTO, cputhreadtype, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN | CTLFLAG_LOCKED, &cputhreadtype, 0, "");
416
316670eb 417#if defined(__i386__) || defined(__x86_64__)
bd504ef0
A
418static int
419sysctl_cpu_capability
420(__unused struct sysctl_oid *oidp, void *arg1, __unused int arg2, struct sysctl_req *req)
421{
422 uint64_t mask = (uint64_t) (uintptr_t) arg1;
423 boolean_t is_capable = (_get_cpu_capabilities() & mask) != 0;
424
425 return SYSCTL_OUT(req, &is_capable, sizeof(is_capable));
426
427}
428
429SYSCTL_PROC(_hw_optional, OID_AUTO, mmx, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasMMX, 0, sysctl_cpu_capability, "I", "");
430SYSCTL_PROC(_hw_optional, OID_AUTO, sse, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE, 0, sysctl_cpu_capability, "I", "");
431SYSCTL_PROC(_hw_optional, OID_AUTO, sse2, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE2, 0, sysctl_cpu_capability, "I", "");
432SYSCTL_PROC(_hw_optional, OID_AUTO, sse3, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE3, 0, sysctl_cpu_capability, "I", "");
433SYSCTL_PROC(_hw_optional, OID_AUTO, supplementalsse3, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSupplementalSSE3, 0, sysctl_cpu_capability, "I", "");
434SYSCTL_PROC(_hw_optional, OID_AUTO, sse4_1, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE4_1, 0, sysctl_cpu_capability, "I", "");
435SYSCTL_PROC(_hw_optional, OID_AUTO, sse4_2, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasSSE4_2, 0, sysctl_cpu_capability, "I", "");
b0d623f7
A
436/* "x86_64" is actually a preprocessor symbol on the x86_64 kernel, so we have to hack this */
437#undef x86_64
bd504ef0
A
438SYSCTL_PROC(_hw_optional, OID_AUTO, x86_64, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) k64Bit, 0, sysctl_cpu_capability, "I", "");
439SYSCTL_PROC(_hw_optional, OID_AUTO, aes, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAES, 0, sysctl_cpu_capability, "I", "");
440SYSCTL_PROC(_hw_optional, OID_AUTO, avx1_0, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX1_0, 0, sysctl_cpu_capability, "I", "");
441SYSCTL_PROC(_hw_optional, OID_AUTO, rdrand, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasRDRAND, 0, sysctl_cpu_capability, "I", "");
442SYSCTL_PROC(_hw_optional, OID_AUTO, f16c, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasF16C, 0, sysctl_cpu_capability, "I", "");
443SYSCTL_PROC(_hw_optional, OID_AUTO, enfstrg, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasENFSTRG, 0, sysctl_cpu_capability, "I", "");
444SYSCTL_PROC(_hw_optional, OID_AUTO, fma, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasFMA, 0, sysctl_cpu_capability, "I", "");
445SYSCTL_PROC(_hw_optional, OID_AUTO, avx2_0, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasAVX2_0, 0, sysctl_cpu_capability, "I", "");
446SYSCTL_PROC(_hw_optional, OID_AUTO, bmi1, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasBMI1, 0, sysctl_cpu_capability, "I", "");
447SYSCTL_PROC(_hw_optional, OID_AUTO, bmi2, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasBMI2, 0, sysctl_cpu_capability, "I", "");
448SYSCTL_PROC(_hw_optional, OID_AUTO, rtm, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasRTM, 0, sysctl_cpu_capability, "I", "");
449SYSCTL_PROC(_hw_optional, OID_AUTO, hle, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (void *) kHasHLE, 0, sysctl_cpu_capability, "I", "");
316670eb
A
450#else
451#error Unsupported arch
6d2010ae 452#endif /* !__i386__ && !__x86_64 && !__arm__ */
43866e37 453
0c530ab8 454
43866e37
A
455/******************************************************************************
456 * Generic MIB initialisation.
457 *
458 * This is a hack, and should be replaced with SYSINITs
459 * at some point.
460 */
461void
462sysctl_mib_init(void)
463{
91447636
A
464 cputype = cpu_type();
465 cpusubtype = cpu_subtype();
466 cputhreadtype = cpu_threadtype();
6d2010ae 467#if defined(__i386__) || defined (__x86_64__)
39236c6e 468 cpu64bit = (_get_cpu_capabilities() & k64Bit) == k64Bit;
316670eb
A
469#else
470#error Unsupported arch
2d21ac55 471#endif
91447636 472
43866e37
A
473 /*
474 * Populate the optional portion of the hw.* MIB.
475 *
476 * XXX This could be broken out into parts of the code
477 * that actually directly relate to the functions in
478 * question.
479 */
91447636
A
480
481 if (cputhreadtype != CPU_THREADTYPE_NONE) {
91447636
A
482 sysctl_register_oid(&sysctl__hw_cputhreadtype);
483 }
484
6d2010ae 485#if defined (__i386__) || defined (__x86_64__)
0c530ab8 486 /* hw.cpufamily */
7e4a7d39
A
487 cpufamily = cpuid_cpufamily();
488
0c530ab8 489 /* hw.cacheconfig */
2d21ac55
A
490 cacheconfig[0] = ml_cpu_cache_sharing(0);
491 cacheconfig[1] = ml_cpu_cache_sharing(1);
492 cacheconfig[2] = ml_cpu_cache_sharing(2);
493 cacheconfig[3] = ml_cpu_cache_sharing(3);
0c530ab8
A
494 cacheconfig[4] = 0;
495
2d21ac55
A
496 /* hw.cachesize */
497 cachesize[0] = ml_cpu_cache_size(0);
498 cachesize[1] = ml_cpu_cache_size(1);
499 cachesize[2] = ml_cpu_cache_size(2);
500 cachesize[3] = ml_cpu_cache_size(3);
501 cachesize[4] = 0;
502
503 /* hw.packages */
593a1d5f
A
504 packages = roundup(ml_cpu_cache_sharing(0), cpuid_info()->thread_count)
505 / cpuid_info()->thread_count;
506
316670eb
A
507#else
508#error unknown architecture
6d2010ae 509#endif /* !__i386__ && !__x86_64 && !__arm__ */
43866e37 510
43866e37 511}