]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/arm/sysctl.c
xnu-4903.241.1.tar.gz
[apple/xnu.git] / bsd / dev / arm / sysctl.c
CommitLineData
5ba3f43e
A
1/*
2 * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
3 */
4#include <sys/param.h>
5#include <sys/kernel.h>
6#include <sys/sysctl.h>
7
8#include <machine/machine_routines.h>
9
d9a64523
A
10#include <mach/host_info.h>
11#include <mach/mach_host.h>
12#include <arm/cpuid.h>
13#include <libkern/libkern.h>
14
5ba3f43e
A
15extern int trap_on_alignment_fault;
16extern uint64_t wake_abstime;
17
18static
19SYSCTL_INT(_machdep, OID_AUTO, alignmenttrap,
20 CTLFLAG_RW, &trap_on_alignment_fault, 0,
21 "trap on alignment faults (number of alignment faults per trap)");
22
23static
24SYSCTL_QUAD(_machdep, OID_AUTO, wake_abstime,
25 CTLFLAG_RD | CTLFLAG_KERN, &wake_abstime,
26 "Absolute Time at the last wakeup");
27
28static int
29sysctl_time_since_reset SYSCTL_HANDLER_ARGS
30{
31#pragma unused(arg1, arg2, oidp)
32 int error = 0;
33 uint64_t return_value = 0;
34
35 return_value = ml_get_time_since_reset();
36
37 SYSCTL_OUT(req, &return_value, sizeof(return_value));
38
39 return error;
40}
41
42SYSCTL_PROC(_machdep, OID_AUTO, time_since_reset,
43 CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED,
44 0, 0, sysctl_time_since_reset, "I",
45 "Continuous time since last SOC boot/wake started");
46
47static int
48sysctl_wake_conttime SYSCTL_HANDLER_ARGS
49{
50#pragma unused(arg1, arg2, oidp)
51 int error = 0;
52 uint64_t return_value = 0;
53
54 return_value = ml_get_conttime_wake_time();
55
56 SYSCTL_OUT(req, &return_value, sizeof(return_value));
57
58 return error;
59}
60
61SYSCTL_PROC(_machdep, OID_AUTO, wake_conttime,
62 CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED,
63 0, 0, sysctl_wake_conttime, "I",
64 "Continuous Time at the last wakeup");
65
d9a64523
A
66/*
67 * For source compatibility, here's some machdep.cpu mibs that
68 * use host_info() to simulate reasonable answers.
69 */
70
71SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
72 "CPU info");
73
74static int
75arm_host_info SYSCTL_HANDLER_ARGS
76{
77 __unused struct sysctl_oid *unused_oidp = oidp;
78
79 host_basic_info_data_t hinfo;
80 mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
81#define BSD_HOST 1
82 kern_return_t kret = host_info((host_t)BSD_HOST,
83 HOST_BASIC_INFO, (host_info_t)&hinfo, &count);
84 if (KERN_SUCCESS != kret)
85 return (EINVAL);
86
87 if (sizeof (uint32_t) != arg2)
88 panic("size mismatch");
89
90 uintptr_t woffset = (uintptr_t)arg1 / sizeof (uint32_t);
91 uint32_t datum = *(uint32_t *)(((uint32_t *)&hinfo) + woffset);
92 return (SYSCTL_OUT(req, &datum, sizeof (datum)));
93}
94
95/*
96 * machdep.cpu.cores_per_package
97 *
98 * x86: derived from CPUID data.
99 * ARM: how many physical cores we have in the AP; aka hw.physicalcpu_max
100 */
101static
102SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package,
103 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
104 (void *)offsetof(host_basic_info_data_t, physical_cpu_max),
105 sizeof (integer_t),
106 arm_host_info, "I", "CPU cores per package");
107
108/*
109 * machdep.cpu.core_count
110 *
111 * x86: derived from CPUID data.
112 * ARM: # active physical cores in the AP; aka hw.physicalcpu
113 */
114static
115SYSCTL_PROC(_machdep_cpu, OID_AUTO, core_count,
116 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
117 (void *)offsetof(host_basic_info_data_t, physical_cpu),
118 sizeof (integer_t),
119 arm_host_info, "I", "Number of enabled cores per package");
120
121/*
122 * machdep.cpu.logical_per_package
123 *
124 * x86: derived from CPUID data. Returns ENOENT if HTT bit not set, but
125 * most x64 CPUs have that, so assume it's available.
126 * ARM: total # logical cores in the AP; aka hw.logicalcpu_max
127 */
128static
129SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package,
130 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
131 (void *)offsetof(host_basic_info_data_t, logical_cpu_max),
132 sizeof (integer_t),
133 arm_host_info, "I", "CPU logical cpus per package");
134
135/*
136 * machdep.cpu.thread_count
137 *
138 * x86: derived from CPUID data.
139 * ARM: # active logical cores in the AP; aka hw.logicalcpu
140 */
141static
142SYSCTL_PROC(_machdep_cpu, OID_AUTO, thread_count,
143 CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
144 (void *)offsetof(host_basic_info_data_t, logical_cpu),
145 sizeof (integer_t),
146 arm_host_info, "I", "Number of enabled threads per package");
147
148/*
149 * machdep.cpu.brand_string
150 *
151 * x86: derived from CPUID data.
152 * ARM: cons something up from the CPUID register. Could include cpufamily
153 * here and map it to a "marketing" name, but there's no obvious need;
154 * the value is already exported via the commpage. So keep it simple.
155 */
156static int
157make_brand_string SYSCTL_HANDLER_ARGS
158{
159 __unused struct sysctl_oid *unused_oidp = oidp;
160 __unused void *unused_arg1 = arg1;
161 __unused int unused_arg2 = arg2;
162
163 const char *impl;
164
165 switch (cpuid_info()->arm_info.arm_implementor) {
166 case CPU_VID_APPLE:
167 impl = "Apple";
168 break;
169 case CPU_VID_ARM:
170 impl = "ARM";
171 break;
172 default:
173 impl = "ARM architecture";
174 break;
175 }
176 char buf[80];
177 snprintf(buf, sizeof (buf), "%s processor", impl);
178 return (SYSCTL_OUT(req, buf, strlen(buf) + 1));
179}
180
181SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string,
182 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
183 0, 0, make_brand_string, "A", "CPU brand string");