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