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