]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/i386/sysctl.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / bsd / dev / i386 / sysctl.c
CommitLineData
55e303ae 1/*
5d5c5d0d
A
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55e303ae 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@
55e303ae
A
27 */
28
91447636 29#include <string.h>
55e303ae
A
30#include <sys/param.h>
31#include <sys/kernel.h>
32#include <sys/sysctl.h>
33#include <i386/cpuid.h>
34
35static int
36hw_cpu_sysctl SYSCTL_HANDLER_ARGS
37{
91447636
A
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;
55e303ae
A
41 int value;
42
91447636
A
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 }
55e303ae
A
51
52 if (arg2 == sizeof(uint8_t)) {
53 value = (uint32_t) *(uint8_t *)ptr;
54 ptr = &value;
55 arg2 = sizeof(uint32_t);
56 }
91447636 57 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1);
55e303ae
A
58}
59
60static int
61hw_cpu_features SYSCTL_HANDLER_ARGS
62{
91447636
A
63 __unused struct sysctl_oid *unused_oidp = oidp;
64 __unused void *unused_arg1 = arg1;
65 __unused int unused_arg2 = arg2;
55e303ae 66 char buf[256];
55e303ae 67
55e303ae 68 buf[0] = '\0';
91447636 69 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
55e303ae
A
70
71 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
72}
73
89b3af67
A
74static int
75hw_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
55e303ae
A
88SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW, 0,
89 "CPU info");
90
91SYSCTL_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
95SYSCTL_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
91447636
A
99SYSCTL_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
55e303ae
A
103SYSCTL_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
107SYSCTL_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
111SYSCTL_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
115SYSCTL_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
119SYSCTL_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
89b3af67
A
123SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD,
124 (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
55e303ae
A
125 hw_cpu_sysctl, "I", "CPU features");
126
89b3af67
A
127SYSCTL_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
55e303ae
A
131SYSCTL_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
135SYSCTL_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
55e303ae
A
139SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD,
140 0, 0,
141 hw_cpu_features, "A", "CPU feature names");
142
89b3af67
A
143SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD,
144 0, 0,
145 hw_cpu_extfeatures, "A", "CPU extended feature names");
146
147SYSCTL_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
153SYSCTL_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
55e303ae
A
159
160struct sysctl_oid *machdep_sysctl_list[] =
161{
162 &sysctl__machdep_cpu,
163 &sysctl__machdep_cpu_vendor,
164 &sysctl__machdep_cpu_brand_string,
91447636 165 &sysctl__machdep_cpu_model_string,
55e303ae
A
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,
89b3af67 171 &sysctl__machdep_cpu_extfeature_bits,
55e303ae
A
172 &sysctl__machdep_cpu_stepping,
173 &sysctl__machdep_cpu_signature,
174 &sysctl__machdep_cpu_brand,
175 &sysctl__machdep_cpu_features,
89b3af67
A
176 &sysctl__machdep_cpu_extfeatures,
177 &sysctl__machdep_cpu_logical_per_package,
178 &sysctl__machdep_cpu_cores_per_package,
55e303ae
A
179 (struct sysctl_oid *) 0
180};
181