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