2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1982, 1986, 1989, 1993
24 * The Regents of the University of California. All rights reserved.
26 * This code is derived from software contributed to Berkeley by
27 * Mike Karels at Berkeley Software Design, Inc.
29 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
30 * project, to make these variables more userfriendly.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
63 #include <sys/param.h>
64 #include <sys/kernel.h>
65 #include <sys/systm.h>
66 #include <sys/sysctl.h>
67 #include <sys/proc_internal.h>
68 #include <sys/unistd.h>
71 #include <machine/smp.h>
74 #include <sys/param.h> /* XXX prune includes */
75 #include <sys/systm.h>
76 #include <sys/kernel.h>
77 #include <sys/malloc.h>
79 #include <sys/file_internal.h>
80 #include <sys/vnode.h>
81 #include <sys/unistd.h>
82 #include <sys/ioctl.h>
83 #include <sys/namei.h>
85 #include <sys/disklabel.h>
87 #include <sys/sysctl.h>
89 #include <mach/machine.h>
90 #include <mach/mach_types.h>
91 #include <mach/vm_param.h>
92 #include <kern/task.h>
93 #include <vm/vm_kern.h>
94 #include <mach/host_info.h>
97 extern vm_map_t bsd_pageable_map
;
99 #include <sys/mount_internal.h>
100 #include <sys/kdebug.h>
102 #include <IOKit/IOPlatformExpert.h>
103 #include <pexpert/pexpert.h>
105 #include <machine/machine_routines.h>
106 #include <machine/cpu_capabilities.h>
109 #include <i386/cpuid.h> /* for cpuid_info() */
113 #define MAX(a,b) (a >= b ? a : b)
116 static int cputype
, cpusubtype
, cputhreadtype
, cpufamily
, cacheconfig
[10];;
118 SYSCTL_NODE(, 0, sysctl
, CTLFLAG_RW
, 0,
119 "Sysctl internal magic");
120 SYSCTL_NODE(, CTL_KERN
, kern
, CTLFLAG_RW
, 0,
121 "High kernel, proc, limits &c");
122 SYSCTL_NODE(, CTL_VM
, vm
, CTLFLAG_RW
, 0,
124 SYSCTL_NODE(, CTL_VFS
, vfs
, CTLFLAG_RW
, 0,
126 SYSCTL_NODE(, CTL_NET
, net
, CTLFLAG_RW
, 0,
127 "Network, (see socket.h)");
128 SYSCTL_NODE(, CTL_DEBUG
, debug
, CTLFLAG_RW
, 0,
130 SYSCTL_NODE(, CTL_HW
, hw
, CTLFLAG_RW
, 0,
132 SYSCTL_NODE(, CTL_MACHDEP
, machdep
, CTLFLAG_RW
, 0,
133 "machine dependent");
134 SYSCTL_NODE(, CTL_USER
, user
, CTLFLAG_RW
, 0,
137 #define SYSCTL_RETURN(r, x) SYSCTL_OUT(r, &x, sizeof(x))
139 /******************************************************************************
143 #define CTLHW_RETQUAD (1 << 31)
144 #define CTLHW_LOCAL (1 << 30)
146 #define HW_LOCAL_CPUTHREADTYPE (1 | CTLHW_LOCAL)
147 #define HW_LOCAL_PHYSICALCPU (2 | CTLHW_LOCAL)
148 #define HW_LOCAL_PHYSICALCPUMAX (3 | CTLHW_LOCAL)
149 #define HW_LOCAL_LOGICALCPU (4 | CTLHW_LOCAL)
150 #define HW_LOCAL_LOGICALCPUMAX (5 | CTLHW_LOCAL)
154 * Supporting some variables requires us to do "real" work. We
155 * gather some of that here.
158 sysctl_hw_generic SYSCTL_HANDLER_ARGS
162 extern int vm_page_wire_count
;
163 ml_cpu_info_t cpu_info
;
166 host_basic_info_data_t hinfo
;
168 int count
= HOST_BASIC_INFO_COUNT
;
171 * Test and mask off the 'return quad' flag.
172 * Note that only some things here support it.
174 doquad
= arg2
& CTLHW_RETQUAD
;
175 arg2
&= ~CTLHW_RETQUAD
;
177 ml_cpu_get_info(&cpu_info
);
180 kret
= host_info(BSD_HOST
, HOST_BASIC_INFO
, &hinfo
, &count
);
183 * Handle various OIDs.
185 * OIDs that can return int or quad set val and qval and then break.
186 * Errors and int-only values return inline.
190 if (kret
== KERN_SUCCESS
) {
191 return(SYSCTL_RETURN(req
, hinfo
.max_cpus
));
196 if (kret
== KERN_SUCCESS
) {
197 return(SYSCTL_RETURN(req
, hinfo
.avail_cpus
));
201 case HW_LOCAL_PHYSICALCPU
:
202 if (kret
== KERN_SUCCESS
) {
203 return(SYSCTL_RETURN(req
, hinfo
.physical_cpu
));
207 case HW_LOCAL_PHYSICALCPUMAX
:
208 if (kret
== KERN_SUCCESS
) {
209 return(SYSCTL_RETURN(req
, hinfo
.physical_cpu_max
));
213 case HW_LOCAL_LOGICALCPU
:
214 if (kret
== KERN_SUCCESS
) {
215 return(SYSCTL_RETURN(req
, hinfo
.logical_cpu
));
219 case HW_LOCAL_LOGICALCPUMAX
:
220 if (kret
== KERN_SUCCESS
) {
221 return(SYSCTL_RETURN(req
, hinfo
.logical_cpu_max
));
226 val
= cpu_info
.cache_line_size
;
227 qval
= (long long)val
;
229 case HW_L1ICACHESIZE
:
230 val
= cpu_info
.l1_icache_size
;
231 qval
= (long long)val
;
233 case HW_L1DCACHESIZE
:
234 val
= cpu_info
.l1_dcache_size
;
235 qval
= (long long)val
;
238 if (cpu_info
.l2_cache_size
== 0xFFFFFFFF)
240 val
= cpu_info
.l2_cache_size
;
241 qval
= (long long)val
;
244 if (cpu_info
.l3_cache_size
== 0xFFFFFFFF)
246 val
= cpu_info
.l3_cache_size
;
247 qval
= (long long)val
;
251 * Deprecated variables. We still support these for
252 * backwards compatibility purposes only.
255 bzero(dummy
, sizeof(dummy
));
256 if(!PEGetMachineName(dummy
,64))
259 return(SYSCTL_OUT(req
, dummy
, strlen(dummy
) + 1));
261 bzero(dummy
, sizeof(dummy
));
262 if(!PEGetModelName(dummy
,64))
265 return(SYSCTL_OUT(req
, dummy
, strlen(dummy
) + 1));
268 int usermem
= mem_size
- vm_page_wire_count
* page_size
;
270 return(SYSCTL_RETURN(req
, usermem
));
273 epochTemp
= PEGetPlatformEpoch();
276 return(SYSCTL_RETURN(req
, epochTemp
));
277 case HW_VECTORUNIT
: {
278 int vector
= cpu_info
.vector_unit
== 0? 0 : 1;
279 return(SYSCTL_RETURN(req
, vector
));
282 if (cpu_info
.l2_cache_size
== 0xFFFFFFFF)
284 return(SYSCTL_RETURN(req
, cpu_info
.l2_settings
));
286 if (cpu_info
.l3_cache_size
== 0xFFFFFFFF)
288 return(SYSCTL_RETURN(req
, cpu_info
.l3_settings
));
293 * Callers may come to us with either int or quad buffers.
296 return(SYSCTL_RETURN(req
, qval
));
298 return(SYSCTL_RETURN(req
, val
));
302 * hw.* MIB variables.
304 SYSCTL_PROC (_hw
, HW_NCPU
, ncpu
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_NCPU
, sysctl_hw_generic
, "I", "");
305 SYSCTL_PROC (_hw
, HW_AVAILCPU
, activecpu
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_AVAILCPU
, sysctl_hw_generic
, "I", "");
306 SYSCTL_PROC (_hw
, OID_AUTO
, physicalcpu
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_LOCAL_PHYSICALCPU
, sysctl_hw_generic
, "I", "");
307 SYSCTL_PROC (_hw
, OID_AUTO
, physicalcpu_max
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_LOCAL_PHYSICALCPUMAX
, sysctl_hw_generic
, "I", "");
308 SYSCTL_PROC (_hw
, OID_AUTO
, logicalcpu
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_LOCAL_LOGICALCPU
, sysctl_hw_generic
, "I", "");
309 SYSCTL_PROC (_hw
, OID_AUTO
, logicalcpu_max
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_LOCAL_LOGICALCPUMAX
, sysctl_hw_generic
, "I", "");
310 SYSCTL_INT (_hw
, HW_BYTEORDER
, byteorder
, CTLFLAG_RD
| CTLFLAG_KERN
, NULL
, BYTE_ORDER
, "");
311 SYSCTL_INT (_hw
, OID_AUTO
, cputype
, CTLFLAG_RD
| CTLFLAG_KERN
, &cputype
, 0, "");
312 SYSCTL_INT (_hw
, OID_AUTO
, cpusubtype
, CTLFLAG_RD
| CTLFLAG_KERN
, &cpusubtype
, 0, "");
313 SYSCTL_INT (_hw
, OID_AUTO
, cpufamily
, CTLFLAG_RD
| CTLFLAG_KERN
, &cpufamily
, 0, "");
314 SYSCTL_OPAQUE (_hw
, OID_AUTO
, cacheconfig
, CTLFLAG_RD
, &cacheconfig
, sizeof(cacheconfig
), "I", "");
315 SYSCTL_INT2QUAD(_hw
, OID_AUTO
, pagesize
, CTLFLAG_RD
| CTLFLAG_KERN
, &page_size
, "");
316 SYSCTL_QUAD (_hw
, OID_AUTO
, busfrequency
, CTLFLAG_RD
| CTLFLAG_KERN
, &gPEClockFrequencyInfo
.bus_frequency_hz
, "");
317 SYSCTL_QUAD (_hw
, OID_AUTO
, busfrequency_min
, CTLFLAG_RD
| CTLFLAG_KERN
, &gPEClockFrequencyInfo
.bus_frequency_min_hz
, "");
318 SYSCTL_QUAD (_hw
, OID_AUTO
, busfrequency_max
, CTLFLAG_RD
| CTLFLAG_KERN
, &gPEClockFrequencyInfo
.bus_frequency_max_hz
, "");
319 SYSCTL_QUAD (_hw
, OID_AUTO
, cpufrequency
, CTLFLAG_RD
| CTLFLAG_KERN
, &gPEClockFrequencyInfo
.cpu_frequency_hz
, "");
320 SYSCTL_QUAD (_hw
, OID_AUTO
, cpufrequency_min
, CTLFLAG_RD
| CTLFLAG_KERN
, &gPEClockFrequencyInfo
.cpu_frequency_min_hz
, "");
321 SYSCTL_QUAD (_hw
, OID_AUTO
, cpufrequency_max
, CTLFLAG_RD
| CTLFLAG_KERN
, &gPEClockFrequencyInfo
.cpu_frequency_max_hz
, "");
322 SYSCTL_PROC (_hw
, OID_AUTO
, cachelinesize
, CTLTYPE_QUAD
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_CACHELINE
| CTLHW_RETQUAD
, sysctl_hw_generic
, "Q", "");
323 SYSCTL_PROC (_hw
, OID_AUTO
, l1icachesize
, CTLTYPE_QUAD
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_L1ICACHESIZE
| CTLHW_RETQUAD
, sysctl_hw_generic
, "Q", "");
324 SYSCTL_PROC (_hw
, OID_AUTO
, l1dcachesize
, CTLTYPE_QUAD
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_L1DCACHESIZE
| CTLHW_RETQUAD
, sysctl_hw_generic
, "Q", "");
325 SYSCTL_PROC (_hw
, OID_AUTO
, l2cachesize
, CTLTYPE_QUAD
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_L2CACHESIZE
| CTLHW_RETQUAD
, sysctl_hw_generic
, "Q", "");
326 SYSCTL_PROC (_hw
, OID_AUTO
, l3cachesize
, CTLTYPE_QUAD
| CTLFLAG_RD
| CTLFLAG_KERN
, 0, HW_L3CACHESIZE
| CTLHW_RETQUAD
, sysctl_hw_generic
, "Q", "");
327 SYSCTL_INT2QUAD(_hw
, OID_AUTO
, tbfrequency
, CTLFLAG_RD
| CTLFLAG_KERN
, &gPEClockFrequencyInfo
.timebase_frequency_hz
, "");
328 SYSCTL_QUAD (_hw
, HW_MEMSIZE
, memsize
, CTLFLAG_RD
| CTLFLAG_KERN
, &max_mem
, "");
331 * Optional features can register nodes below hw.optional.
333 * If the feature is not present, the node should either not be registered,
334 * or it should return -1. If the feature is present, the node should return
335 * 0. If the feature is present and its use is advised, the node should
338 SYSCTL_NODE(_hw
, OID_AUTO
, optional
, CTLFLAG_RW
, NULL
, "optional features");
340 SYSCTL_INT(_hw_optional
, OID_AUTO
, floatingpoint
, CTLFLAG_RD
| CTLFLAG_KERN
, 0, 1, ""); /* always set */
343 * Deprecated variables. These are supported for backwards compatibility
344 * purposes only. The MASKED flag requests that the variables not be
345 * printed by sysctl(8) and similar utilities.
347 * The variables named *_compat here are int-sized versions of variables
348 * that are now exported as quads. The int-sized versions are normally
349 * looked up only by number, wheras the quad-sized versions should be
352 * The *_compat nodes are *NOT* visible within the kernel.
354 SYSCTL_INT (_hw
, HW_PAGESIZE
, pagesize_compat
, CTLFLAG_RD
| CTLFLAG_MASKED
, &page_size
, 0, "");
355 SYSCTL_INT (_hw
, HW_BUS_FREQ
, busfrequency_compat
, CTLFLAG_RD
| CTLFLAG_MASKED
, &gPEClockFrequencyInfo
.bus_clock_rate_hz
, 0, "");
356 SYSCTL_INT (_hw
, HW_CPU_FREQ
, cpufrequency_compat
, CTLFLAG_RD
| CTLFLAG_MASKED
, &gPEClockFrequencyInfo
.cpu_clock_rate_hz
, 0, "");
357 SYSCTL_PROC(_hw
, HW_CACHELINE
, cachelinesize_compat
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_CACHELINE
, sysctl_hw_generic
, "I", "");
358 SYSCTL_PROC(_hw
, HW_L1ICACHESIZE
, l1icachesize_compat
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_L1ICACHESIZE
, sysctl_hw_generic
, "I", "");
359 SYSCTL_PROC(_hw
, HW_L1DCACHESIZE
, l1dcachesize_compat
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_L1DCACHESIZE
, sysctl_hw_generic
, "I", "");
360 SYSCTL_PROC(_hw
, HW_L2CACHESIZE
, l2cachesize_compat
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_L2CACHESIZE
, sysctl_hw_generic
, "I", "");
361 SYSCTL_PROC(_hw
, HW_L3CACHESIZE
, l3cachesize_compat
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_L3CACHESIZE
, sysctl_hw_generic
, "I", "");
362 SYSCTL_INT (_hw
, HW_TB_FREQ
, tbfrequency_compat
, CTLFLAG_RD
| CTLFLAG_MASKED
, &gPEClockFrequencyInfo
.timebase_frequency_hz
, 0, "");
363 SYSCTL_PROC(_hw
, HW_MACHINE
, machine
, CTLTYPE_STRING
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_MACHINE
, sysctl_hw_generic
, "A", "");
364 SYSCTL_PROC(_hw
, HW_MODEL
, model
, CTLTYPE_STRING
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_MODEL
, sysctl_hw_generic
, "A", "");
365 SYSCTL_UINT(_hw
, HW_PHYSMEM
, physmem
, CTLFLAG_RD
| CTLFLAG_MASKED
, &mem_size
, 0, "");
366 SYSCTL_PROC(_hw
, HW_USERMEM
, usermem
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_USERMEM
, sysctl_hw_generic
, "I", "");
367 SYSCTL_PROC(_hw
, HW_EPOCH
, epoch
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_EPOCH
, sysctl_hw_generic
, "I", "");
368 SYSCTL_PROC(_hw
, HW_VECTORUNIT
, vectorunit
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_VECTORUNIT
, sysctl_hw_generic
, "I", "");
369 SYSCTL_PROC(_hw
, HW_L2SETTINGS
, l2settings
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_L2SETTINGS
, sysctl_hw_generic
, "I", "");
370 SYSCTL_PROC(_hw
, HW_L3SETTINGS
, l3settings
, CTLTYPE_INT
| CTLFLAG_RD
| CTLFLAG_MASKED
, 0, HW_L3SETTINGS
, sysctl_hw_generic
, "I", "");
373 * Debugging interface to the CPU power management code.
375 static void pmsSysctl SYSCTL_HANDLER_ARGS
{
381 if ((error
= SYSCTL_IN(req
, &ctl
, sizeof(ctl
))))
384 intr
= ml_set_interrupts_enabled(FALSE
); /* No interruptions in here */
385 error
= pmsControl(ctl
.request
, (user_addr_t
)ctl
.reqaddr
, ctl
.reqsize
);
386 (void)ml_set_interrupts_enabled(intr
); /* Restore interruptions */
391 SYSCTL_PROC(_hw
, OID_AUTO
, pms
, CTLTYPE_STRUCT
| CTLFLAG_WR
, 0, 0, pmsSysctl
, "S", "Processor Power Management");
395 /******************************************************************************
396 * Generic MIB initialisation.
398 * This is a hack, and should be replaced with SYSINITs
402 sysctl_mib_init(void)
404 cputype
= cpu_type();
405 cpusubtype
= cpu_subtype();
406 cputhreadtype
= cpu_threadtype();
409 * Populate the optional portion of the hw.* MIB.
411 * XXX This could be broken out into parts of the code
412 * that actually directly relate to the functions in
416 if (cputhreadtype
!= CPU_THREADTYPE_NONE
) {
417 static SYSCTL_INT(_hw
, OID_AUTO
, cputhreadtype
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &cputhreadtype
, 0, "");
418 sysctl_register_oid(&sysctl__hw_cputhreadtype
);
423 static int altivec_flag
= -1;
424 static SYSCTL_INT(_hw_optional
, OID_AUTO
, altivec
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &altivec_flag
, 0, "");
426 if (_cpu_capabilities
& kHasAltivec
) {
428 sysctl_register_oid(&sysctl__hw_optional_altivec
);
432 static int graphicsops_flag
= -1;
433 static SYSCTL_INT(_hw_optional
, OID_AUTO
, graphicsops
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &graphicsops_flag
, 0, "");
435 if (_cpu_capabilities
& kHasGraphicsOps
) {
436 graphicsops_flag
= 1;
437 sysctl_register_oid(&sysctl__hw_optional_graphicsops
);
441 static int x64bitops_flag
= -1;
442 static SYSCTL_INT(_hw_optional
, OID_AUTO
, 64bitops
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &x64bitops_flag
, 0, "");
444 if (_cpu_capabilities
& k64Bit
) {
446 sysctl_register_oid(&sysctl__hw_optional_64bitops
);
450 static int fsqrt_flag
= -1;
451 static SYSCTL_INT(_hw_optional
, OID_AUTO
, fsqrt
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &fsqrt_flag
, 0, "");
453 if (_cpu_capabilities
& kHasFsqrt
) {
455 sysctl_register_oid(&sysctl__hw_optional_fsqrt
);
459 static int stfiwx_flag
= -1;
460 static SYSCTL_INT(_hw_optional
, OID_AUTO
, stfiwx
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &stfiwx_flag
, 0, "");
462 if (_cpu_capabilities
& kHasStfiwx
) {
464 sysctl_register_oid(&sysctl__hw_optional_stfiwx
);
468 static int dcba_flag
= -1;
469 static SYSCTL_INT(_hw_optional
, OID_AUTO
, dcba
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &dcba_flag
, 0, "");
471 if (_cpu_capabilities
& kDcbaAvailable
)
473 if (_cpu_capabilities
& kDcbaRecommended
)
476 sysctl_register_oid(&sysctl__hw_optional_dcba
);
479 static int datastreams_flag
= -1;
480 static SYSCTL_INT(_hw_optional
, OID_AUTO
, datastreams
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &datastreams_flag
, 0, "");
482 if (_cpu_capabilities
& kDataStreamsAvailable
)
483 datastreams_flag
= 0;
484 if (_cpu_capabilities
& kDataStreamsRecommended
)
485 datastreams_flag
= 1;
486 if (datastreams_flag
>= 0)
487 sysctl_register_oid(&sysctl__hw_optional_datastreams
);
490 static int dcbtstreams_flag
= -1;
491 static SYSCTL_INT(_hw_optional
, OID_AUTO
, dcbtstreams
, CTLFLAG_RD
| CTLFLAG_NOAUTO
| CTLFLAG_KERN
, &dcbtstreams_flag
, 0, "");
493 if (_cpu_capabilities
& kDcbtStreamsAvailable
)
494 dcbtstreams_flag
= 0;
495 if (_cpu_capabilities
& kDcbtStreamsRecommended
)
496 dcbtstreams_flag
= 1;
497 if (dcbtstreams_flag
>= 0)
498 sysctl_register_oid(&sysctl__hw_optional_dcbtstreams
);
502 switch (cpusubtype
) {
503 case CPU_SUBTYPE_POWERPC_750
:
504 cpufamily
= CPUFAMILY_POWERPC_G3
;
506 case CPU_SUBTYPE_POWERPC_7400
:
507 case CPU_SUBTYPE_POWERPC_7450
:
508 cpufamily
= CPUFAMILY_POWERPC_G4
;
510 case CPU_SUBTYPE_POWERPC_970
:
511 cpufamily
= CPUFAMILY_POWERPC_G5
;
514 cpufamily
= CPUFAMILY_UNKNOWN
;
518 cacheconfig
[0] = 0; /* XXX not supported on PowerPC */
520 #elif defined (__i386__)
523 #define DECLARE_X86_HW_OPTIONAL_FLAGS(named, BITS, flags) { \
524 static int named##_flag = -1; \
525 static SYSCTL_INT(_hw_optional, OID_AUTO, named, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN | flags, &named##_flag, 0, ""); \
526 named##_flag = ((_get_cpu_capabilities() & BITS) == BITS)? 1 : 0; \
527 sysctl_register_oid(&sysctl__hw_optional_##named); \
530 #define DECLARE_X86_HW_OPTIONAL(named, BITS) \
531 DECLARE_X86_HW_OPTIONAL_FLAGS(named, BITS, 0)
533 #define DECLARE_X86_HW_OPTIONAL_MASKED(named, BITS) \
534 DECLARE_X86_HW_OPTIONAL_FLAGS(named, BITS, CTLFLAG_MASKED)
536 DECLARE_X86_HW_OPTIONAL(mmx
, kHasMMX
);
537 DECLARE_X86_HW_OPTIONAL(sse
, kHasSSE
);
538 DECLARE_X86_HW_OPTIONAL(sse2
, kHasSSE2
);
539 DECLARE_X86_HW_OPTIONAL(sse3
, kHasSSE3
);
540 if (_get_cpu_capabilities() & k64Bit
)
541 DECLARE_X86_HW_OPTIONAL(x86_64
, k64Bit
);
542 if (_get_cpu_capabilities() & kHasSupplementalSSE3
) {
543 DECLARE_X86_HW_OPTIONAL_MASKED(mni
, kHasSupplementalSSE3
); /* XXX */
544 DECLARE_X86_HW_OPTIONAL(supplementalsse3
, kHasSupplementalSSE3
);
548 switch (cpuid_info()->cpuid_family
) {
550 switch (cpuid_info()->cpuid_model
) {
552 cpufamily
= CPUFAMILY_INTEL_6_14
; /* Core Solo/Duo */
555 cpufamily
= CPUFAMILY_INTEL_6_15
;
558 cpufamily
= CPUFAMILY_UNKNOWN
;
562 cpufamily
= CPUFAMILY_UNKNOWN
;
565 cacheconfig
[0] = cpuid_info()->cpuid_cores_per_package
;
566 cacheconfig
[1] = MAX(cpuid_info()->cache_sharing
[L1I
], cpuid_info()->cache_sharing
[L1D
]);
567 cacheconfig
[2] = cpuid_info()->cache_sharing
[L2U
];
568 cacheconfig
[3] = cpuid_info()->cache_sharing
[L3U
];
571 #else /* end __i386 */
572 # warning we do not support this platform yet