]>
Commit | Line | Data |
---|---|---|
55e303ae A |
1 | /* |
2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
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. | |
55e303ae | 11 | * |
37839358 A |
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 | |
55e303ae A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
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. | |
55e303ae A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | ||
91447636 | 23 | #include <string.h> |
55e303ae A |
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 | { | |
91447636 A |
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; | |
55e303ae A |
35 | int value; |
36 | ||
91447636 A |
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 | } | |
55e303ae A |
45 | |
46 | if (arg2 == sizeof(uint8_t)) { | |
47 | value = (uint32_t) *(uint8_t *)ptr; | |
48 | ptr = &value; | |
49 | arg2 = sizeof(uint32_t); | |
50 | } | |
91447636 | 51 | return SYSCTL_OUT(req, ptr, arg2 ? (size_t) arg2 : strlen((char *)ptr)+1); |
55e303ae A |
52 | } |
53 | ||
54 | static int | |
55 | hw_cpu_features SYSCTL_HANDLER_ARGS | |
56 | { | |
91447636 A |
57 | __unused struct sysctl_oid *unused_oidp = oidp; |
58 | __unused void *unused_arg1 = arg1; | |
59 | __unused int unused_arg2 = arg2; | |
55e303ae | 60 | char buf[256]; |
55e303ae | 61 | |
55e303ae | 62 | buf[0] = '\0'; |
91447636 | 63 | cpuid_get_feature_names(cpuid_features(), buf, sizeof(buf)); |
55e303ae A |
64 | |
65 | return SYSCTL_OUT(req, buf, strlen(buf) + 1); | |
66 | } | |
67 | ||
c0fea474 A |
68 | static int |
69 | hw_cpu_extfeatures SYSCTL_HANDLER_ARGS | |
70 | { | |
71 | __unused struct sysctl_oid *unused_oidp = oidp; | |
72 | __unused void *unused_arg1 = arg1; | |
73 | __unused int unused_arg2 = arg2; | |
74 | char buf[256]; | |
75 | ||
76 | buf[0] = '\0'; | |
77 | cpuid_get_extfeature_names(cpuid_extfeatures(), buf, sizeof(buf)); | |
78 | ||
79 | return SYSCTL_OUT(req, buf, strlen(buf) + 1); | |
80 | } | |
81 | ||
55e303ae A |
82 | SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW, 0, |
83 | "CPU info"); | |
84 | ||
85 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD, | |
86 | (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0, | |
87 | hw_cpu_sysctl, "A", "CPU vendor"); | |
88 | ||
89 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD, | |
90 | (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0, | |
91 | hw_cpu_sysctl, "A", "CPU brand string"); | |
92 | ||
91447636 A |
93 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, model_string, CTLTYPE_STRING | CTLFLAG_RD, |
94 | (void *)offsetof(i386_cpu_info_t, cpuid_model_string), -1, | |
95 | hw_cpu_sysctl, "A", "CPU model string"); | |
96 | ||
55e303ae A |
97 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD, |
98 | (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t), | |
99 | hw_cpu_sysctl, "I", "CPU family"); | |
100 | ||
101 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD, | |
102 | (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t), | |
103 | hw_cpu_sysctl, "I", "CPU model"); | |
104 | ||
105 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD, | |
106 | (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t), | |
107 | hw_cpu_sysctl, "I", "CPU extended model"); | |
108 | ||
109 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD, | |
110 | (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t), | |
111 | hw_cpu_sysctl, "I", "CPU extended family"); | |
112 | ||
113 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD, | |
114 | (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t), | |
115 | hw_cpu_sysctl, "I", "CPU stepping"); | |
116 | ||
c0fea474 A |
117 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD, |
118 | (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t), | |
55e303ae A |
119 | hw_cpu_sysctl, "I", "CPU features"); |
120 | ||
c0fea474 A |
121 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD, |
122 | (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t), | |
123 | hw_cpu_sysctl, "I", "CPU extended features"); | |
124 | ||
55e303ae A |
125 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD, |
126 | (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t), | |
127 | hw_cpu_sysctl, "I", "CPU signature"); | |
128 | ||
129 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD, | |
130 | (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t), | |
131 | hw_cpu_sysctl, "I", "CPU brand"); | |
132 | ||
55e303ae A |
133 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD, |
134 | 0, 0, | |
135 | hw_cpu_features, "A", "CPU feature names"); | |
136 | ||
c0fea474 A |
137 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD, |
138 | 0, 0, | |
139 | hw_cpu_extfeatures, "A", "CPU extended feature names"); | |
140 | ||
141 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package, | |
142 | CTLTYPE_INT | CTLFLAG_RD, | |
143 | (void *)offsetof(i386_cpu_info_t, cpuid_logical_per_package), | |
144 | sizeof(uint32_t), | |
145 | hw_cpu_sysctl, "I", "CPU logical cpus per package"); | |
146 | ||
147 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package, | |
148 | CTLTYPE_INT | CTLFLAG_RD, | |
149 | (void *)offsetof(i386_cpu_info_t, cpuid_cores_per_package), | |
150 | sizeof(uint32_t), | |
151 | hw_cpu_sysctl, "I", "CPU cores per package"); | |
152 | ||
55e303ae A |
153 | |
154 | struct sysctl_oid *machdep_sysctl_list[] = | |
155 | { | |
156 | &sysctl__machdep_cpu, | |
157 | &sysctl__machdep_cpu_vendor, | |
158 | &sysctl__machdep_cpu_brand_string, | |
91447636 | 159 | &sysctl__machdep_cpu_model_string, |
55e303ae A |
160 | &sysctl__machdep_cpu_family, |
161 | &sysctl__machdep_cpu_model, | |
162 | &sysctl__machdep_cpu_extmodel, | |
163 | &sysctl__machdep_cpu_extfamily, | |
164 | &sysctl__machdep_cpu_feature_bits, | |
c0fea474 | 165 | &sysctl__machdep_cpu_extfeature_bits, |
55e303ae A |
166 | &sysctl__machdep_cpu_stepping, |
167 | &sysctl__machdep_cpu_signature, | |
168 | &sysctl__machdep_cpu_brand, | |
169 | &sysctl__machdep_cpu_features, | |
c0fea474 A |
170 | &sysctl__machdep_cpu_extfeatures, |
171 | &sysctl__machdep_cpu_logical_per_package, | |
172 | &sysctl__machdep_cpu_cores_per_package, | |
55e303ae A |
173 | (struct sysctl_oid *) 0 |
174 | }; | |
175 |