]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/sysctl.c
xnu-792.6.56.tar.gz
[apple/xnu.git] / bsd / dev / i386 / sysctl.c
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <string.h>
25 #include <sys/param.h>
26 #include <sys/kernel.h>
27 #include <sys/sysctl.h>
28 #include <i386/cpuid.h>
29
30 static int
31 hw_cpu_sysctl SYSCTL_HANDLER_ARGS
32 {
33 __unused struct sysctl_oid *unused_oidp = oidp;
34 i386_cpu_info_t *cpu_info = cpuid_info();
35 void *ptr = (uint8_t *)cpu_info + (uint32_t)arg1;
36 int value;
37
38 if (arg2 == -1) {
39 ptr = *(char **)ptr;
40 arg2 = 0;
41 }
42
43 if (arg2 == 0 && ((char *)ptr)[0] == '\0') {
44 return ENOENT;
45 }
46
47 if (arg2 == sizeof(uint8_t)) {
48 value = (uint32_t) *(uint8_t *)ptr;
49 ptr = &value;
50 arg2 = sizeof(uint32_t);
51 }
52 return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1);
53 }
54
55 static int
56 hw_cpu_features SYSCTL_HANDLER_ARGS
57 {
58 __unused struct sysctl_oid *unused_oidp = oidp;
59 __unused void *unused_arg1 = arg1;
60 __unused int unused_arg2 = arg2;
61 char buf[256];
62
63 buf[0] = '\0';
64 cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf));
65
66 return SYSCTL_OUT(req, buf, strlen(buf) + 1);
67 }
68
69 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW, 0,
70 "CPU info");
71
72 SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD,
73 (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0,
74 hw_cpu_sysctl, "A", "CPU vendor");
75
76 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD,
77 (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0,
78 hw_cpu_sysctl, "A", "CPU brand string");
79
80 SYSCTL_PROC(_machdep_cpu, OID_AUTO, model_string, CTLTYPE_STRING | CTLFLAG_RD,
81 (void *)offsetof(i386_cpu_info_t, cpuid_model_string), -1,
82 hw_cpu_sysctl, "A", "CPU model string");
83
84 SYSCTL_PROC(_machdep_cpu, OID_AUTO, value, CTLTYPE_INT | CTLFLAG_RD,
85 (void *)offsetof(i386_cpu_info_t, cpuid_value), sizeof(uint32_t),
86 hw_cpu_sysctl, "I", "CPU value");
87
88 SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD,
89 (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t),
90 hw_cpu_sysctl, "I", "CPU family");
91
92 SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD,
93 (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t),
94 hw_cpu_sysctl, "I", "CPU model");
95
96 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD,
97 (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t),
98 hw_cpu_sysctl, "I", "CPU extended model");
99
100 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD,
101 (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t),
102 hw_cpu_sysctl, "I", "CPU extended family");
103
104 SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD,
105 (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t),
106 hw_cpu_sysctl, "I", "CPU stepping");
107
108 SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_INT | CTLFLAG_RD,
109 (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint32_t),
110 hw_cpu_sysctl, "I", "CPU features");
111
112 SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD,
113 (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t),
114 hw_cpu_sysctl, "I", "CPU signature");
115
116 SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD,
117 (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t),
118 hw_cpu_sysctl, "I", "CPU brand");
119
120 SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD,
121 0, 0,
122 hw_cpu_features, "A", "CPU feature names");
123
124
125 struct sysctl_oid *machdep_sysctl_list[] =
126 {
127 &sysctl__machdep_cpu,
128 &sysctl__machdep_cpu_vendor,
129 &sysctl__machdep_cpu_brand_string,
130 &sysctl__machdep_cpu_model_string,
131 &sysctl__machdep_cpu_value,
132 &sysctl__machdep_cpu_family,
133 &sysctl__machdep_cpu_model,
134 &sysctl__machdep_cpu_extmodel,
135 &sysctl__machdep_cpu_extfamily,
136 &sysctl__machdep_cpu_feature_bits,
137 &sysctl__machdep_cpu_stepping,
138 &sysctl__machdep_cpu_signature,
139 &sysctl__machdep_cpu_brand,
140 &sysctl__machdep_cpu_features,
141 (struct sysctl_oid *) 0
142 };
143