]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/sysctl.c
xnu-792.22.5.tar.gz
[apple/xnu.git] / bsd / dev / i386 / sysctl.c
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include <string.h>
30 #include <sys/param.h>
31 #include <sys/kernel.h>
32 #include <sys/sysctl.h>
33 #include <i386/cpuid.h>
34
35 static int
36 hw_cpu_sysctl SYSCTL_HANDLER_ARGS
37 {
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;
41 int value;
42
43 if (arg2 == -1) {
44 ptr = *(char **)ptr;
45 arg2 = 0;
46 }
47
48 if (arg2 == 0 && ((char *)ptr)[0] == '\0') {
49 return ENOENT;
50 }
51
52 if (arg2 == sizeof(uint8_t)) {
53 value = (uint32_t) *(uint8_t *)ptr;
54 ptr = &value;
55 arg2 = sizeof(uint32_t);
56 }
57 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1);
58 }
59
60 static int
61 hw_cpu_features SYSCTL_HANDLER_ARGS
62 {
63 __unused struct sysctl_oid *unused_oidp = oidp;
64 __unused void *unused_arg1 = arg1;
65 __unused int unused_arg2 = arg2;
66 char buf[256];
67
68 buf[0] = '\0';
69 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
70
71 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
72 }
73
74 static int
75 hw_cpu_extfeatures SYSCTL_HANDLER_ARGS
76 {
77 __unused struct sysctl_oid *unused_oidp = oidp;
78 __unused void *unused_arg1 = arg1;
79 __unused int unused_arg2 = arg2;
80 char buf[256];
81
82 buf[0] = '\0';
83 cpuid_get_extfeature_names(cpuid_extfeatures(), buf, sizeof(buf));
84
85 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
86 }
87
88 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW, 0,
89 "CPU info");
90
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");
94
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");
98
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");
102
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");
106
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");
110
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");
114
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");
118
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");
122
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");
126
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");
130
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");
134
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");
138
139 SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD,
140 0, 0,
141 hw_cpu_features, "A", "CPU feature names");
142
143 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD,
144 0, 0,
145 hw_cpu_extfeatures, "A", "CPU extended feature names");
146
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),
150 sizeof(uint32_t),
151 hw_cpu_sysctl, "I", "CPU logical cpus per package");
152
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),
156 sizeof(uint32_t),
157 hw_cpu_sysctl, "I", "CPU cores per package");
158
159
160 struct sysctl_oid *machdep_sysctl_list[] =
161 {
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
180 };
181