]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/sysctl.c
99986d752966e073d5a6b25e5d59c1147429fefc
[apple/xnu.git] / bsd / dev / i386 / sysctl.c
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31 #include <string.h>
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/sysctl.h>
35 #include <i386/cpuid.h>
36
37 static int
38 hw_cpu_sysctl SYSCTL_HANDLER_ARGS
39 {
40 __unused struct sysctl_oid *unused_oidp = oidp;
41 i386_cpu_info_t *cpu_info = cpuid_info();
42 void *ptr = (uint8_t *)cpu_info + (uint32_t)arg1;
43 int value;
44
45 if (arg2 == -1) {
46 ptr = *(char **)ptr;
47 arg2 = 0;
48 }
49
50 if (arg2 == 0 && ((char *)ptr)[0] == '\0') {
51 return ENOENT;
52 }
53
54 if (arg2 == sizeof(uint8_t)) {
55 value = (uint32_t) *(uint8_t *)ptr;
56 ptr = &value;
57 arg2 = sizeof(uint32_t);
58 }
59 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1);
60 }
61
62 static int
63 hw_cpu_features SYSCTL_HANDLER_ARGS
64 {
65 __unused struct sysctl_oid *unused_oidp = oidp;
66 __unused void *unused_arg1 = arg1;
67 __unused int unused_arg2 = arg2;
68 char buf[256];
69
70 buf[0] = '\0';
71 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
72
73 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
74 }
75
76 static int
77 hw_cpu_extfeatures SYSCTL_HANDLER_ARGS
78 {
79 __unused struct sysctl_oid *unused_oidp = oidp;
80 __unused void *unused_arg1 = arg1;
81 __unused int unused_arg2 = arg2;
82 char buf[256];
83
84 buf[0] = '\0';
85 cpuid_get_extfeature_names(cpuid_extfeatures(), buf, sizeof(buf));
86
87 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
88 }
89
90 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW, 0,
91 "CPU info");
92
93 SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD,
94 (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0,
95 hw_cpu_sysctl, "A", "CPU vendor");
96
97 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD,
98 (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0,
99 hw_cpu_sysctl, "A", "CPU brand string");
100
101 SYSCTL_PROC(_machdep_cpu, OID_AUTO, model_string, CTLTYPE_STRING | CTLFLAG_RD,
102 (void *)offsetof(i386_cpu_info_t, cpuid_model_string), -1,
103 hw_cpu_sysctl, "A", "CPU model string");
104
105 SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD,
106 (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t),
107 hw_cpu_sysctl, "I", "CPU family");
108
109 SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD,
110 (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t),
111 hw_cpu_sysctl, "I", "CPU model");
112
113 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD,
114 (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t),
115 hw_cpu_sysctl, "I", "CPU extended model");
116
117 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD,
118 (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t),
119 hw_cpu_sysctl, "I", "CPU extended family");
120
121 SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD,
122 (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t),
123 hw_cpu_sysctl, "I", "CPU stepping");
124
125 SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
126 (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
127 hw_cpu_sysctl, "I", "CPU features");
128
129 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
130 (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t),
131 hw_cpu_sysctl, "I", "CPU extended features");
132
133 SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD,
134 (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t),
135 hw_cpu_sysctl, "I", "CPU signature");
136
137 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD,
138 (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t),
139 hw_cpu_sysctl, "I", "CPU brand");
140
141 SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD,
142 0, 0,
143 hw_cpu_features, "A", "CPU feature names");
144
145 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD,
146 0, 0,
147 hw_cpu_extfeatures, "A", "CPU extended feature names");
148
149 SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package,
150 CTLTYPE_INT | CTLFLAG_RD,
151 (void *)offsetof(i386_cpu_info_t, cpuid_logical_per_package),
152 sizeof(uint32_t),
153 hw_cpu_sysctl, "I", "CPU logical cpus per package");
154
155 SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package,
156 CTLTYPE_INT | CTLFLAG_RD,
157 (void *)offsetof(i386_cpu_info_t, cpuid_cores_per_package),
158 sizeof(uint32_t),
159 hw_cpu_sysctl, "I", "CPU cores per package");
160
161
162 struct sysctl_oid *machdep_sysctl_list[] =
163 {
164 &sysctl__machdep_cpu,
165 &sysctl__machdep_cpu_vendor,
166 &sysctl__machdep_cpu_brand_string,
167 &sysctl__machdep_cpu_model_string,
168 &sysctl__machdep_cpu_family,
169 &sysctl__machdep_cpu_model,
170 &sysctl__machdep_cpu_extmodel,
171 &sysctl__machdep_cpu_extfamily,
172 &sysctl__machdep_cpu_feature_bits,
173 &sysctl__machdep_cpu_extfeature_bits,
174 &sysctl__machdep_cpu_stepping,
175 &sysctl__machdep_cpu_signature,
176 &sysctl__machdep_cpu_brand,
177 &sysctl__machdep_cpu_features,
178 &sysctl__machdep_cpu_extfeatures,
179 &sysctl__machdep_cpu_logical_per_package,
180 &sysctl__machdep_cpu_cores_per_package,
181 (struct sysctl_oid *) 0
182 };
183