]>
Commit | Line | Data |
---|---|---|
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 | ||
35 | static int | |
36 | hw_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 | ||
60 | static int | |
61 | hw_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 | ||
74 | SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW, 0, | |
75 | "CPU info"); | |
76 | ||
77 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, vendor, CTLTYPE_STRING | CTLFLAG_RD, | |
78 | (void *)offsetof(i386_cpu_info_t, cpuid_vendor), 0, | |
79 | hw_cpu_sysctl, "A", "CPU vendor"); | |
80 | ||
81 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string, CTLTYPE_STRING | CTLFLAG_RD, | |
82 | (void *)offsetof(i386_cpu_info_t, cpuid_brand_string), 0, | |
83 | hw_cpu_sysctl, "A", "CPU brand string"); | |
84 | ||
91447636 A |
85 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, model_string, CTLTYPE_STRING | CTLFLAG_RD, |
86 | (void *)offsetof(i386_cpu_info_t, cpuid_model_string), -1, | |
87 | hw_cpu_sysctl, "A", "CPU model string"); | |
88 | ||
8f6c56a5 A |
89 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, value, CTLTYPE_INT | CTLFLAG_RD, |
90 | (void *)offsetof(i386_cpu_info_t, cpuid_value), sizeof(uint32_t), | |
91 | hw_cpu_sysctl, "I", "CPU value"); | |
92 | ||
55e303ae A |
93 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, family, CTLTYPE_INT | CTLFLAG_RD, |
94 | (void *)offsetof(i386_cpu_info_t, cpuid_family), sizeof(uint8_t), | |
95 | hw_cpu_sysctl, "I", "CPU family"); | |
96 | ||
97 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, model, CTLTYPE_INT | CTLFLAG_RD, | |
98 | (void *)offsetof(i386_cpu_info_t, cpuid_model), sizeof(uint8_t), | |
99 | hw_cpu_sysctl, "I", "CPU model"); | |
100 | ||
101 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, extmodel, CTLTYPE_INT | CTLFLAG_RD, | |
102 | (void *)offsetof(i386_cpu_info_t, cpuid_extmodel), sizeof(uint8_t), | |
103 | hw_cpu_sysctl, "I", "CPU extended model"); | |
104 | ||
105 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfamily, CTLTYPE_INT | CTLFLAG_RD, | |
106 | (void *)offsetof(i386_cpu_info_t, cpuid_extfamily), sizeof(uint8_t), | |
107 | hw_cpu_sysctl, "I", "CPU extended family"); | |
108 | ||
109 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, stepping, CTLTYPE_INT | CTLFLAG_RD, | |
110 | (void *)offsetof(i386_cpu_info_t, cpuid_stepping), sizeof(uint8_t), | |
111 | hw_cpu_sysctl, "I", "CPU stepping"); | |
112 | ||
8f6c56a5 A |
113 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_INT | CTLFLAG_RD, |
114 | (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint32_t), | |
55e303ae A |
115 | hw_cpu_sysctl, "I", "CPU features"); |
116 | ||
117 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, signature, CTLTYPE_INT | CTLFLAG_RD, | |
118 | (void *)offsetof(i386_cpu_info_t, cpuid_signature), sizeof(uint32_t), | |
119 | hw_cpu_sysctl, "I", "CPU signature"); | |
120 | ||
121 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand, CTLTYPE_INT | CTLFLAG_RD, | |
122 | (void *)offsetof(i386_cpu_info_t, cpuid_brand), sizeof(uint8_t), | |
123 | hw_cpu_sysctl, "I", "CPU brand"); | |
124 | ||
55e303ae A |
125 | SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD, |
126 | 0, 0, | |
127 | hw_cpu_features, "A", "CPU feature names"); | |
128 | ||
129 | ||
130 | struct sysctl_oid *machdep_sysctl_list[] = | |
131 | { | |
132 | &sysctl__machdep_cpu, | |
133 | &sysctl__machdep_cpu_vendor, | |
134 | &sysctl__machdep_cpu_brand_string, | |
91447636 | 135 | &sysctl__machdep_cpu_model_string, |
8f6c56a5 | 136 | &sysctl__machdep_cpu_value, |
55e303ae A |
137 | &sysctl__machdep_cpu_family, |
138 | &sysctl__machdep_cpu_model, | |
139 | &sysctl__machdep_cpu_extmodel, | |
140 | &sysctl__machdep_cpu_extfamily, | |
141 | &sysctl__machdep_cpu_feature_bits, | |
142 | &sysctl__machdep_cpu_stepping, | |
143 | &sysctl__machdep_cpu_signature, | |
144 | &sysctl__machdep_cpu_brand, | |
145 | &sysctl__machdep_cpu_features, | |
146 | (struct sysctl_oid *) 0 | |
147 | }; | |
148 |