]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/kern_mib.c
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / kern / kern_mib.c
CommitLineData
1c79356b 1/*
4452a7af 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
5d5c5d0d 3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
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>
100#include <mach/host_info.h>
4452a7af 101#include <kern/pms.h>
43866e37
A
102
103extern vm_map_t bsd_pageable_map;
104
91447636 105#include <sys/mount_internal.h>
43866e37
A
106#include <sys/kdebug.h>
107
108#include <IOKit/IOPlatformExpert.h>
109#include <pexpert/pexpert.h>
110
111#include <machine/machine_routines.h>
112#include <machine/cpu_capabilities.h>
113
4452a7af
A
114#ifdef __i386__
115#include <i386/cpuid.h> /* for cpuid_info() */
116#endif
117
118#ifndef MAX
119#define MAX(a,b) (a >= b ? a : b)
120#endif
121
122static int cputype, cpusubtype, cputhreadtype, cpufamily, cacheconfig[10];;
43866e37 123
1c79356b
A
124SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
125 "Sysctl internal magic");
126SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0,
127 "High kernel, proc, limits &c");
128SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0,
129 "Virtual memory");
130SYSCTL_NODE(, CTL_VFS, vfs, CTLFLAG_RW, 0,
131 "File system");
132SYSCTL_NODE(, CTL_NET, net, CTLFLAG_RW, 0,
133 "Network, (see socket.h)");
134SYSCTL_NODE(, CTL_DEBUG, debug, CTLFLAG_RW, 0,
135 "Debugging");
136SYSCTL_NODE(, CTL_HW, hw, CTLFLAG_RW, 0,
137 "hardware");
138SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
139 "machine dependent");
140SYSCTL_NODE(, CTL_USER, user, CTLFLAG_RW, 0,
141 "user-level");
142
43866e37
A
143#define SYSCTL_RETURN(r, x) SYSCTL_OUT(r, &x, sizeof(x))
144
145/******************************************************************************
146 * hw.* MIB
147 */
148
149#define CTLHW_RETQUAD (1 << 31)
91447636
A
150#define CTLHW_LOCAL (1 << 30)
151
152#define HW_LOCAL_CPUTHREADTYPE (1 | CTLHW_LOCAL)
153#define HW_LOCAL_PHYSICALCPU (2 | CTLHW_LOCAL)
154#define HW_LOCAL_PHYSICALCPUMAX (3 | CTLHW_LOCAL)
155#define HW_LOCAL_LOGICALCPU (4 | CTLHW_LOCAL)
156#define HW_LOCAL_LOGICALCPUMAX (5 | CTLHW_LOCAL)
157
43866e37
A
158
159/*
160 * Supporting some variables requires us to do "real" work. We
161 * gather some of that here.
162 */
163static int
164sysctl_hw_generic SYSCTL_HANDLER_ARGS
165{
166 char dummy[65];
167 int epochTemp;
168 extern int vm_page_wire_count;
169 ml_cpu_info_t cpu_info;
170 int val, doquad;
171 long long qval;
91447636
A
172 host_basic_info_data_t hinfo;
173 kern_return_t kret;
174 int count = HOST_BASIC_INFO_COUNT;
43866e37
A
175
176 /*
177 * Test and mask off the 'return quad' flag.
178 * Note that only some things here support it.
179 */
180 doquad = arg2 & CTLHW_RETQUAD;
181 arg2 &= ~CTLHW_RETQUAD;
182
183 ml_cpu_get_info(&cpu_info);
184
91447636
A
185#define BSD_HOST 1
186 kret = host_info(BSD_HOST, HOST_BASIC_INFO, &hinfo, &count);
187
43866e37
A
188 /*
189 * Handle various OIDs.
190 *
191 * OIDs that can return int or quad set val and qval and then break.
192 * Errors and int-only values return inline.
193 */
194 switch (arg2) {
195 case HW_NCPU:
91447636
A
196 if (kret == KERN_SUCCESS) {
197 return(SYSCTL_RETURN(req, hinfo.max_cpus));
198 } else {
199 return(EINVAL);
43866e37
A
200 }
201 case HW_AVAILCPU:
91447636
A
202 if (kret == KERN_SUCCESS) {
203 return(SYSCTL_RETURN(req, hinfo.avail_cpus));
204 } else {
205 return(EINVAL);
206 }
207 case HW_LOCAL_PHYSICALCPU:
208 if (kret == KERN_SUCCESS) {
209 return(SYSCTL_RETURN(req, hinfo.physical_cpu));
210 } else {
211 return(EINVAL);
212 }
213 case HW_LOCAL_PHYSICALCPUMAX:
214 if (kret == KERN_SUCCESS) {
215 return(SYSCTL_RETURN(req, hinfo.physical_cpu_max));
216 } else {
217 return(EINVAL);
218 }
219 case HW_LOCAL_LOGICALCPU:
220 if (kret == KERN_SUCCESS) {
221 return(SYSCTL_RETURN(req, hinfo.logical_cpu));
222 } else {
223 return(EINVAL);
224 }
225 case HW_LOCAL_LOGICALCPUMAX:
226 if (kret == KERN_SUCCESS) {
227 return(SYSCTL_RETURN(req, hinfo.logical_cpu_max));
228 } else {
229 return(EINVAL);
43866e37
A
230 }
231 case HW_CACHELINE:
232 val = cpu_info.cache_line_size;
233 qval = (long long)val;
234 break;
235 case HW_L1ICACHESIZE:
236 val = cpu_info.l1_icache_size;
237 qval = (long long)val;
238 break;
239 case HW_L1DCACHESIZE:
240 val = cpu_info.l1_dcache_size;
241 qval = (long long)val;
242 break;
243 case HW_L2CACHESIZE:
244 if (cpu_info.l2_cache_size == 0xFFFFFFFF)
245 return(EINVAL);
246 val = cpu_info.l2_cache_size;
247 qval = (long long)val;
248 break;
249 case HW_L3CACHESIZE:
250 if (cpu_info.l3_cache_size == 0xFFFFFFFF)
251 return(EINVAL);
252 val = cpu_info.l3_cache_size;
253 qval = (long long)val;
254 break;
255
256 /*
257 * Deprecated variables. We still support these for
258 * backwards compatibility purposes only.
259 */
260 case HW_MACHINE:
261 bzero(dummy, sizeof(dummy));
262 if(!PEGetMachineName(dummy,64))
263 return(EINVAL);
264 dummy[64] = 0;
265 return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
266 case HW_MODEL:
267 bzero(dummy, sizeof(dummy));
268 if(!PEGetModelName(dummy,64))
269 return(EINVAL);
270 dummy[64] = 0;
271 return(SYSCTL_OUT(req, dummy, strlen(dummy) + 1));
272 case HW_USERMEM:
273 {
274 int usermem = mem_size - vm_page_wire_count * page_size;
275
276 return(SYSCTL_RETURN(req, usermem));
277 }
278 case HW_EPOCH:
279 epochTemp = PEGetPlatformEpoch();
280 if (epochTemp == -1)
281 return(EINVAL);
282 return(SYSCTL_RETURN(req, epochTemp));
4452a7af
A
283 case HW_VECTORUNIT: {
284 int vector = cpu_info.vector_unit == 0? 0 : 1;
285 return(SYSCTL_RETURN(req, vector));
286 }
43866e37
A
287 case HW_L2SETTINGS:
288 if (cpu_info.l2_cache_size == 0xFFFFFFFF)
289 return(EINVAL);
290 return(SYSCTL_RETURN(req, cpu_info.l2_settings));
291 case HW_L3SETTINGS:
292 if (cpu_info.l3_cache_size == 0xFFFFFFFF)
293 return(EINVAL);
294 return(SYSCTL_RETURN(req, cpu_info.l3_settings));
295 default:
296 return(ENOTSUP);
297 }
298 /*
299 * Callers may come to us with either int or quad buffers.
300 */
301 if (doquad) {
302 return(SYSCTL_RETURN(req, qval));
303 }
304 return(SYSCTL_RETURN(req, val));
305}
306
307/*
308 * hw.* MIB variables.
309 */
91447636 310SYSCTL_PROC (_hw, HW_NCPU, ncpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_NCPU, sysctl_hw_generic, "I", "");
43866e37 311SYSCTL_PROC (_hw, HW_AVAILCPU, activecpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_AVAILCPU, sysctl_hw_generic, "I", "");
91447636
A
312SYSCTL_PROC (_hw, OID_AUTO, physicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_LOCAL_PHYSICALCPU, sysctl_hw_generic, "I", "");
313SYSCTL_PROC (_hw, OID_AUTO, physicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_LOCAL_PHYSICALCPUMAX, sysctl_hw_generic, "I", "");
314SYSCTL_PROC (_hw, OID_AUTO, logicalcpu, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_LOCAL_LOGICALCPU, sysctl_hw_generic, "I", "");
315SYSCTL_PROC (_hw, OID_AUTO, logicalcpu_max, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_LOCAL_LOGICALCPUMAX, sysctl_hw_generic, "I", "");
43866e37 316SYSCTL_INT (_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD | CTLFLAG_KERN, NULL, BYTE_ORDER, "");
91447636
A
317SYSCTL_INT (_hw, OID_AUTO, cputype, CTLFLAG_RD | CTLFLAG_KERN, &cputype, 0, "");
318SYSCTL_INT (_hw, OID_AUTO, cpusubtype, CTLFLAG_RD | CTLFLAG_KERN, &cpusubtype, 0, "");
4452a7af
A
319SYSCTL_INT (_hw, OID_AUTO, cpufamily, CTLFLAG_RD | CTLFLAG_KERN, &cpufamily, 0, "");
320SYSCTL_OPAQUE (_hw, OID_AUTO, cacheconfig, CTLFLAG_RD, &cacheconfig, sizeof(cacheconfig), "I", "");
43866e37
A
321SYSCTL_INT2QUAD(_hw, OID_AUTO, pagesize, CTLFLAG_RD | CTLFLAG_KERN, &page_size, "");
322SYSCTL_QUAD (_hw, OID_AUTO, busfrequency, CTLFLAG_RD | CTLFLAG_KERN, &gPEClockFrequencyInfo.bus_frequency_hz, "");
323SYSCTL_QUAD (_hw, OID_AUTO, busfrequency_min, CTLFLAG_RD | CTLFLAG_KERN, &gPEClockFrequencyInfo.bus_frequency_min_hz, "");
324SYSCTL_QUAD (_hw, OID_AUTO, busfrequency_max, CTLFLAG_RD | CTLFLAG_KERN, &gPEClockFrequencyInfo.bus_frequency_max_hz, "");
325SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency, CTLFLAG_RD | CTLFLAG_KERN, &gPEClockFrequencyInfo.cpu_frequency_hz, "");
326SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency_min, CTLFLAG_RD | CTLFLAG_KERN, &gPEClockFrequencyInfo.cpu_frequency_min_hz, "");
327SYSCTL_QUAD (_hw, OID_AUTO, cpufrequency_max, CTLFLAG_RD | CTLFLAG_KERN, &gPEClockFrequencyInfo.cpu_frequency_max_hz, "");
328SYSCTL_PROC (_hw, OID_AUTO, cachelinesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_CACHELINE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
329SYSCTL_PROC (_hw, OID_AUTO, l1icachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_L1ICACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
330SYSCTL_PROC (_hw, OID_AUTO, l1dcachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_L1DCACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
331SYSCTL_PROC (_hw, OID_AUTO, l2cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_L2CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
332SYSCTL_PROC (_hw, OID_AUTO, l3cachesize, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_KERN, 0, HW_L3CACHESIZE | CTLHW_RETQUAD, sysctl_hw_generic, "Q", "");
333SYSCTL_INT2QUAD(_hw, OID_AUTO, tbfrequency, CTLFLAG_RD | CTLFLAG_KERN, &gPEClockFrequencyInfo.timebase_frequency_hz, "");
334SYSCTL_QUAD (_hw, HW_MEMSIZE, memsize, CTLFLAG_RD | CTLFLAG_KERN, &max_mem, "");
335
336/*
337 * Optional features can register nodes below hw.optional.
338 *
339 * If the feature is not present, the node should either not be registered,
340 * or it should return -1. If the feature is present, the node should return
341 * 0. If the feature is present and its use is advised, the node should
342 * return 1.
343 */
344SYSCTL_NODE(_hw, OID_AUTO, optional, CTLFLAG_RW, NULL, "optional features");
345
346SYSCTL_INT(_hw_optional, OID_AUTO, floatingpoint, CTLFLAG_RD | CTLFLAG_KERN, 0, 1, ""); /* always set */
347
43866e37
A
348/*
349 * Deprecated variables. These are supported for backwards compatibility
350 * purposes only. The MASKED flag requests that the variables not be
351 * printed by sysctl(8) and similar utilities.
352 *
353 * The variables named *_compat here are int-sized versions of variables
354 * that are now exported as quads. The int-sized versions are normally
355 * looked up only by number, wheras the quad-sized versions should be
356 * looked up by name.
357 *
358 * The *_compat nodes are *NOT* visible within the kernel.
359 */
360SYSCTL_INT (_hw, HW_PAGESIZE, pagesize_compat, CTLFLAG_RD | CTLFLAG_MASKED, &page_size, 0, "");
361SYSCTL_INT (_hw, HW_BUS_FREQ, busfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED, &gPEClockFrequencyInfo.bus_clock_rate_hz, 0, "");
362SYSCTL_INT (_hw, HW_CPU_FREQ, cpufrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED, &gPEClockFrequencyInfo.cpu_clock_rate_hz, 0, "");
363SYSCTL_PROC(_hw, HW_CACHELINE, cachelinesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_CACHELINE, sysctl_hw_generic, "I", "");
364SYSCTL_PROC(_hw, HW_L1ICACHESIZE, l1icachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_L1ICACHESIZE, sysctl_hw_generic, "I", "");
365SYSCTL_PROC(_hw, HW_L1DCACHESIZE, l1dcachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_L1DCACHESIZE, sysctl_hw_generic, "I", "");
366SYSCTL_PROC(_hw, HW_L2CACHESIZE, l2cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_L2CACHESIZE, sysctl_hw_generic, "I", "");
367SYSCTL_PROC(_hw, HW_L3CACHESIZE, l3cachesize_compat, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_L3CACHESIZE, sysctl_hw_generic, "I", "");
368SYSCTL_INT (_hw, HW_TB_FREQ, tbfrequency_compat, CTLFLAG_RD | CTLFLAG_MASKED, &gPEClockFrequencyInfo.timebase_frequency_hz, 0, "");
369SYSCTL_PROC(_hw, HW_MACHINE, machine, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_MACHINE, sysctl_hw_generic, "A", "");
370SYSCTL_PROC(_hw, HW_MODEL, model, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_MODEL, sysctl_hw_generic, "A", "");
55e303ae 371SYSCTL_UINT(_hw, HW_PHYSMEM, physmem, CTLFLAG_RD | CTLFLAG_MASKED, &mem_size, 0, "");
43866e37
A
372SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_USERMEM, sysctl_hw_generic, "I", "");
373SYSCTL_PROC(_hw, HW_EPOCH, epoch, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_EPOCH, sysctl_hw_generic, "I", "");
374SYSCTL_PROC(_hw, HW_VECTORUNIT, vectorunit, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_VECTORUNIT, sysctl_hw_generic, "I", "");
375SYSCTL_PROC(_hw, HW_L2SETTINGS, l2settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_L2SETTINGS, sysctl_hw_generic, "I", "");
376SYSCTL_PROC(_hw, HW_L3SETTINGS, l3settings, CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MASKED, 0, HW_L3SETTINGS, sysctl_hw_generic, "I", "");
377
4452a7af
A
378/*
379 * Debugging interface to the CPU power management code.
380 */
381static void pmsSysctl SYSCTL_HANDLER_ARGS {
382
383 pmsctl_t ctl;
384 int error;
385 boolean_t intr;
386
387 if ((error = SYSCTL_IN(req, &ctl, sizeof(ctl))))
388 return(error);
389
390 intr = ml_set_interrupts_enabled(FALSE); /* No interruptions in here */
391 error = pmsControl(ctl.request, (user_addr_t)ctl.reqaddr, ctl.reqsize);
392 (void)ml_set_interrupts_enabled(intr); /* Restore interruptions */
393
394 return(error);
395}
396
397SYSCTL_PROC(_hw, OID_AUTO, pms, CTLTYPE_STRUCT | CTLFLAG_WR, 0, 0, pmsSysctl, "S", "Processor Power Management");
398
399
400
43866e37
A
401/******************************************************************************
402 * Generic MIB initialisation.
403 *
404 * This is a hack, and should be replaced with SYSINITs
405 * at some point.
406 */
407void
408sysctl_mib_init(void)
409{
91447636
A
410 cputype = cpu_type();
411 cpusubtype = cpu_subtype();
412 cputhreadtype = cpu_threadtype();
413
43866e37
A
414 /*
415 * Populate the optional portion of the hw.* MIB.
416 *
417 * XXX This could be broken out into parts of the code
418 * that actually directly relate to the functions in
419 * question.
420 */
91447636
A
421
422 if (cputhreadtype != CPU_THREADTYPE_NONE) {
423 static SYSCTL_INT(_hw, OID_AUTO, cputhreadtype, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &cputhreadtype, 0, "");
424 sysctl_register_oid(&sysctl__hw_cputhreadtype);
425 }
426
43866e37
A
427#ifdef __ppc__
428 {
429 static int altivec_flag = -1;
430 static SYSCTL_INT(_hw_optional, OID_AUTO, altivec, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &altivec_flag, 0, "");
431
432 if (_cpu_capabilities & kHasAltivec) {
433 altivec_flag = 1;
434 sysctl_register_oid(&sysctl__hw_optional_altivec);
435 }
436 }
437 {
438 static int graphicsops_flag = -1;
439 static SYSCTL_INT(_hw_optional, OID_AUTO, graphicsops, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &graphicsops_flag, 0, "");
440
441 if (_cpu_capabilities & kHasGraphicsOps) {
442 graphicsops_flag = 1;
443 sysctl_register_oid(&sysctl__hw_optional_graphicsops);
444 }
445 }
446 {
447 static int x64bitops_flag = -1;
448 static SYSCTL_INT(_hw_optional, OID_AUTO, 64bitops, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &x64bitops_flag, 0, "");
449
450 if (_cpu_capabilities & k64Bit) {
451 x64bitops_flag = 1;
452 sysctl_register_oid(&sysctl__hw_optional_64bitops);
453 }
454 }
455 {
456 static int fsqrt_flag = -1;
457 static SYSCTL_INT(_hw_optional, OID_AUTO, fsqrt, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &fsqrt_flag, 0, "");
458
459 if (_cpu_capabilities & kHasFsqrt) {
460 fsqrt_flag = 1;
461 sysctl_register_oid(&sysctl__hw_optional_fsqrt);
462 }
463 }
464 {
465 static int stfiwx_flag = -1;
466 static SYSCTL_INT(_hw_optional, OID_AUTO, stfiwx, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &stfiwx_flag, 0, "");
467
468 if (_cpu_capabilities & kHasStfiwx) {
469 stfiwx_flag = 1;
470 sysctl_register_oid(&sysctl__hw_optional_stfiwx);
471 }
472 }
473 {
474 static int dcba_flag = -1;
475 static SYSCTL_INT(_hw_optional, OID_AUTO, dcba, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &dcba_flag, 0, "");
476
477 if (_cpu_capabilities & kDcbaAvailable)
478 dcba_flag = 0;
479 if (_cpu_capabilities & kDcbaRecommended)
480 dcba_flag = 1;
481 if (dcba_flag >= 0)
482 sysctl_register_oid(&sysctl__hw_optional_dcba);
483 }
484 {
485 static int datastreams_flag = -1;
486 static SYSCTL_INT(_hw_optional, OID_AUTO, datastreams, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &datastreams_flag, 0, "");
487
488 if (_cpu_capabilities & kDataStreamsAvailable)
489 datastreams_flag = 0;
490 if (_cpu_capabilities & kDataStreamsRecommended)
491 datastreams_flag = 1;
492 if (datastreams_flag >= 0)
493 sysctl_register_oid(&sysctl__hw_optional_datastreams);
494 }
495 {
496 static int dcbtstreams_flag = -1;
497 static SYSCTL_INT(_hw_optional, OID_AUTO, dcbtstreams, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN, &dcbtstreams_flag, 0, "");
498
499 if (_cpu_capabilities & kDcbtStreamsAvailable)
500 dcbtstreams_flag = 0;
501 if (_cpu_capabilities & kDcbtStreamsRecommended)
502 dcbtstreams_flag = 1;
503 if (dcbtstreams_flag >= 0)
504 sysctl_register_oid(&sysctl__hw_optional_dcbtstreams);
505 }
4452a7af
A
506
507 /* hw.cpufamily */
508 switch (cpusubtype) {
509 case CPU_SUBTYPE_POWERPC_750:
510 cpufamily = CPUFAMILY_POWERPC_G3;
511 break;
512 case CPU_SUBTYPE_POWERPC_7400:
513 case CPU_SUBTYPE_POWERPC_7450:
514 cpufamily = CPUFAMILY_POWERPC_G4;
515 break;
516 case CPU_SUBTYPE_POWERPC_970:
517 cpufamily = CPUFAMILY_POWERPC_G5;
518 break;
519 default:
520 cpufamily = CPUFAMILY_UNKNOWN;
521 }
522
523 /* hw.cacheconfig */
524 cacheconfig[0] = 0; /* XXX not supported on PowerPC */
525
526#elif defined (__i386__)
527
528
529#define DECLARE_X86_HW_OPTIONAL_FLAGS(named, BITS, flags) { \
530 static int named##_flag = -1; \
531 static SYSCTL_INT(_hw_optional, OID_AUTO, named, CTLFLAG_RD | CTLFLAG_NOAUTO | CTLFLAG_KERN | flags, &named##_flag, 0, ""); \
532 named##_flag = ((_get_cpu_capabilities() & BITS) == BITS)? 1 : 0; \
533 sysctl_register_oid(&sysctl__hw_optional_##named); \
534 }
535
536#define DECLARE_X86_HW_OPTIONAL(named, BITS) \
537 DECLARE_X86_HW_OPTIONAL_FLAGS(named, BITS, 0)
538
539#define DECLARE_X86_HW_OPTIONAL_MASKED(named, BITS) \
540 DECLARE_X86_HW_OPTIONAL_FLAGS(named, BITS, CTLFLAG_MASKED)
541
542 DECLARE_X86_HW_OPTIONAL(mmx, kHasMMX);
543 DECLARE_X86_HW_OPTIONAL(sse, kHasSSE);
544 DECLARE_X86_HW_OPTIONAL(sse2, kHasSSE2);
545 DECLARE_X86_HW_OPTIONAL(sse3, kHasSSE3);
546 if (_get_cpu_capabilities() & k64Bit)
547 DECLARE_X86_HW_OPTIONAL(x86_64, k64Bit);
548 if (_get_cpu_capabilities() & kHasSupplementalSSE3) {
549 DECLARE_X86_HW_OPTIONAL_MASKED(mni, kHasSupplementalSSE3); /* XXX */
550 DECLARE_X86_HW_OPTIONAL(supplementalsse3, kHasSupplementalSSE3);
551 }
552
553 /* hw.cpufamily */
554 switch (cpuid_info()->cpuid_family) {
555 case 6:
556 switch (cpuid_info()->cpuid_model) {
557 case 14:
558 cpufamily = CPUFAMILY_INTEL_6_14; /* Core Solo/Duo */
559 break;
560 case 15:
561 cpufamily = CPUFAMILY_INTEL_6_15;
562 break;
563 default:
564 cpufamily = CPUFAMILY_UNKNOWN;
565 }
566 break;
567 default:
568 cpufamily = CPUFAMILY_UNKNOWN;
569 }
570 /* hw.cacheconfig */
571 cacheconfig[0] = cpuid_info()->cpuid_cores_per_package;
572 cacheconfig[1] = MAX(cpuid_info()->cache_sharing[L1I], cpuid_info()->cache_sharing[L1D]);
573 cacheconfig[2] = cpuid_info()->cache_sharing[L2U];
574 cacheconfig[3] = cpuid_info()->cache_sharing[L3U];
575 cacheconfig[4] = 0;
576
577#else /* end __i386 */
43866e37
A
578# warning we do not support this platform yet
579#endif /* __ppc__ */
580
581
582}