2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/sysctl.h>
33 #include <i386/cpuid.h>
36 hw_cpu_sysctl SYSCTL_HANDLER_ARGS
38 __unused
struct sysctl_oid
*unused_oidp
= oidp
;
39 i386_cpu_info_t
*cpu_info
= cpuid_info();
40 void *ptr
= (uint8_t *)cpu_info
+ (uint32_t)arg1
;
48 if (arg2
== 0 && ((char *)ptr
)[0] == '\0') {
52 if (arg2
== sizeof(uint8_t)) {
53 value
= (uint32_t) *(uint8_t *)ptr
;
55 arg2
= sizeof(uint32_t);
57 return SYSCTL_OUT(req
, ptr
, arg2
? (size_t) arg2
: strlen((char *)ptr
)+1);
61 hw_cpu_features SYSCTL_HANDLER_ARGS
63 __unused
struct sysctl_oid
*unused_oidp
= oidp
;
64 __unused
void *unused_arg1
= arg1
;
65 __unused
int unused_arg2
= arg2
;
69 cpuid_get_feature_names(cpuid_features(), buf
, sizeof(buf
));
71 return SYSCTL_OUT(req
, buf
, strlen(buf
) + 1);
75 hw_cpu_extfeatures SYSCTL_HANDLER_ARGS
77 __unused
struct sysctl_oid
*unused_oidp
= oidp
;
78 __unused
void *unused_arg1
= arg1
;
79 __unused
int unused_arg2
= arg2
;
83 cpuid_get_extfeature_names(cpuid_extfeatures(), buf
, sizeof(buf
));
85 return SYSCTL_OUT(req
, buf
, strlen(buf
) + 1);
88 SYSCTL_NODE(_machdep
, OID_AUTO
, cpu
, CTLFLAG_RW
, 0,
91 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, vendor
, CTLTYPE_STRING
| CTLFLAG_RD
,
92 (void *)offsetof(i386_cpu_info_t
, cpuid_vendor
), 0,
93 hw_cpu_sysctl
, "A", "CPU vendor");
95 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, brand_string
, CTLTYPE_STRING
| CTLFLAG_RD
,
96 (void *)offsetof(i386_cpu_info_t
, cpuid_brand_string
), 0,
97 hw_cpu_sysctl
, "A", "CPU brand string");
99 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, model_string
, CTLTYPE_STRING
| CTLFLAG_RD
,
100 (void *)offsetof(i386_cpu_info_t
, cpuid_model_string
), -1,
101 hw_cpu_sysctl
, "A", "CPU model string");
103 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, family
, CTLTYPE_INT
| CTLFLAG_RD
,
104 (void *)offsetof(i386_cpu_info_t
, cpuid_family
), sizeof(uint8_t),
105 hw_cpu_sysctl
, "I", "CPU family");
107 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, model
, CTLTYPE_INT
| CTLFLAG_RD
,
108 (void *)offsetof(i386_cpu_info_t
, cpuid_model
), sizeof(uint8_t),
109 hw_cpu_sysctl
, "I", "CPU model");
111 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, extmodel
, CTLTYPE_INT
| CTLFLAG_RD
,
112 (void *)offsetof(i386_cpu_info_t
, cpuid_extmodel
), sizeof(uint8_t),
113 hw_cpu_sysctl
, "I", "CPU extended model");
115 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, extfamily
, CTLTYPE_INT
| CTLFLAG_RD
,
116 (void *)offsetof(i386_cpu_info_t
, cpuid_extfamily
), sizeof(uint8_t),
117 hw_cpu_sysctl
, "I", "CPU extended family");
119 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, stepping
, CTLTYPE_INT
| CTLFLAG_RD
,
120 (void *)offsetof(i386_cpu_info_t
, cpuid_stepping
), sizeof(uint8_t),
121 hw_cpu_sysctl
, "I", "CPU stepping");
123 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, feature_bits
, CTLTYPE_QUAD
| CTLFLAG_RD
,
124 (void *)offsetof(i386_cpu_info_t
, cpuid_features
), sizeof(uint64_t),
125 hw_cpu_sysctl
, "I", "CPU features");
127 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, extfeature_bits
, CTLTYPE_QUAD
| CTLFLAG_RD
,
128 (void *)offsetof(i386_cpu_info_t
, cpuid_extfeatures
), sizeof(uint64_t),
129 hw_cpu_sysctl
, "I", "CPU extended features");
131 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, signature
, CTLTYPE_INT
| CTLFLAG_RD
,
132 (void *)offsetof(i386_cpu_info_t
, cpuid_signature
), sizeof(uint32_t),
133 hw_cpu_sysctl
, "I", "CPU signature");
135 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, brand
, CTLTYPE_INT
| CTLFLAG_RD
,
136 (void *)offsetof(i386_cpu_info_t
, cpuid_brand
), sizeof(uint8_t),
137 hw_cpu_sysctl
, "I", "CPU brand");
139 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, features
, CTLTYPE_STRING
| CTLFLAG_RD
,
141 hw_cpu_features
, "A", "CPU feature names");
143 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, extfeatures
, CTLTYPE_STRING
| CTLFLAG_RD
,
145 hw_cpu_extfeatures
, "A", "CPU extended feature names");
147 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, logical_per_package
,
148 CTLTYPE_INT
| CTLFLAG_RD
,
149 (void *)offsetof(i386_cpu_info_t
, cpuid_logical_per_package
),
151 hw_cpu_sysctl
, "I", "CPU logical cpus per package");
153 SYSCTL_PROC(_machdep_cpu
, OID_AUTO
, cores_per_package
,
154 CTLTYPE_INT
| CTLFLAG_RD
,
155 (void *)offsetof(i386_cpu_info_t
, cpuid_cores_per_package
),
157 hw_cpu_sysctl
, "I", "CPU cores per package");
160 struct sysctl_oid
*machdep_sysctl_list
[] =
162 &sysctl__machdep_cpu
,
163 &sysctl__machdep_cpu_vendor
,
164 &sysctl__machdep_cpu_brand_string
,
165 &sysctl__machdep_cpu_model_string
,
166 &sysctl__machdep_cpu_family
,
167 &sysctl__machdep_cpu_model
,
168 &sysctl__machdep_cpu_extmodel
,
169 &sysctl__machdep_cpu_extfamily
,
170 &sysctl__machdep_cpu_feature_bits
,
171 &sysctl__machdep_cpu_extfeature_bits
,
172 &sysctl__machdep_cpu_stepping
,
173 &sysctl__machdep_cpu_signature
,
174 &sysctl__machdep_cpu_brand
,
175 &sysctl__machdep_cpu_features
,
176 &sysctl__machdep_cpu_extfeatures
,
177 &sysctl__machdep_cpu_logical_per_package
,
178 &sysctl__machdep_cpu_cores_per_package
,
179 (struct sysctl_oid
*) 0