1*1031c584SApple OSS Distributions /*
2*1031c584SApple OSS Distributions * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
3*1031c584SApple OSS Distributions */
4*1031c584SApple OSS Distributions #include <sys/param.h>
5*1031c584SApple OSS Distributions #include <sys/kernel.h>
6*1031c584SApple OSS Distributions #include <sys/sysctl.h>
7*1031c584SApple OSS Distributions
8*1031c584SApple OSS Distributions #include <machine/machine_routines.h>
9*1031c584SApple OSS Distributions
10*1031c584SApple OSS Distributions #include <mach/host_info.h>
11*1031c584SApple OSS Distributions #include <mach/mach_host.h>
12*1031c584SApple OSS Distributions #include <arm/cpuid.h>
13*1031c584SApple OSS Distributions #include <kern/hvg_hypercall.h>
14*1031c584SApple OSS Distributions #include <vm/pmap.h>
15*1031c584SApple OSS Distributions #include <kern/zalloc.h>
16*1031c584SApple OSS Distributions #include <libkern/libkern.h>
17*1031c584SApple OSS Distributions #include <pexpert/device_tree.h>
18*1031c584SApple OSS Distributions
19*1031c584SApple OSS Distributions #if HYPERVISOR
20*1031c584SApple OSS Distributions #include <kern/hv_support.h>
21*1031c584SApple OSS Distributions #include <kern/bits.h>
22*1031c584SApple OSS Distributions #endif
23*1031c584SApple OSS Distributions
24*1031c584SApple OSS Distributions extern uint64_t wake_abstime;
25*1031c584SApple OSS Distributions
26*1031c584SApple OSS Distributions #if DEVELOPMENT || DEBUG
27*1031c584SApple OSS Distributions /* Various tuneables to modulate selection of WFE in the idle path */
28*1031c584SApple OSS Distributions extern int wfe_rec_max;
29*1031c584SApple OSS Distributions extern int wfe_allowed;
30*1031c584SApple OSS Distributions
31*1031c584SApple OSS Distributions extern int wfe_rec_none;
32*1031c584SApple OSS Distributions extern uint32_t idle_proximate_timer_wfe;
33*1031c584SApple OSS Distributions extern uint32_t idle_proximate_io_wfe_masked;
34*1031c584SApple OSS Distributions extern uint32_t idle_proximate_io_wfe_unmasked;
35*1031c584SApple OSS Distributions
36*1031c584SApple OSS Distributions static
37*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, wfe_rec_max,
38*1031c584SApple OSS Distributions CTLFLAG_RW, &wfe_rec_max, 0,
39*1031c584SApple OSS Distributions "");
40*1031c584SApple OSS Distributions
41*1031c584SApple OSS Distributions static
42*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, wfe_allowed,
43*1031c584SApple OSS Distributions CTLFLAG_RW, &wfe_allowed, 0,
44*1031c584SApple OSS Distributions "");
45*1031c584SApple OSS Distributions
46*1031c584SApple OSS Distributions static
47*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, idle_timer_wfe,
48*1031c584SApple OSS Distributions CTLFLAG_RW, &idle_proximate_timer_wfe, 0,
49*1031c584SApple OSS Distributions "");
50*1031c584SApple OSS Distributions
51*1031c584SApple OSS Distributions static
52*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, idle_io_wfe_masked,
53*1031c584SApple OSS Distributions CTLFLAG_RW, &idle_proximate_io_wfe_masked, 0,
54*1031c584SApple OSS Distributions "");
55*1031c584SApple OSS Distributions static
56*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, idle_io_wfe_unmasked,
57*1031c584SApple OSS Distributions CTLFLAG_RW, &idle_proximate_io_wfe_unmasked, 0,
58*1031c584SApple OSS Distributions "");
59*1031c584SApple OSS Distributions
60*1031c584SApple OSS Distributions static
61*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, wfe_rec_none,
62*1031c584SApple OSS Distributions CTLFLAG_RW, &wfe_rec_none, 0,
63*1031c584SApple OSS Distributions "");
64*1031c584SApple OSS Distributions
65*1031c584SApple OSS Distributions extern uint64_t wfe_rec_override_mat;
66*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, wfe_rec_override_mat,
67*1031c584SApple OSS Distributions CTLFLAG_RW, &wfe_rec_override_mat,
68*1031c584SApple OSS Distributions "");
69*1031c584SApple OSS Distributions
70*1031c584SApple OSS Distributions extern uint64_t wfe_rec_clamp;
71*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, wfe_rec_clamp,
72*1031c584SApple OSS Distributions CTLFLAG_RW, &wfe_rec_clamp,
73*1031c584SApple OSS Distributions "");
74*1031c584SApple OSS Distributions
75*1031c584SApple OSS Distributions #endif
76*1031c584SApple OSS Distributions
77*1031c584SApple OSS Distributions static
78*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, wake_abstime,
79*1031c584SApple OSS Distributions CTLFLAG_RD, &wake_abstime,
80*1031c584SApple OSS Distributions "Absolute Time at the last wakeup");
81*1031c584SApple OSS Distributions
82*1031c584SApple OSS Distributions static int
83*1031c584SApple OSS Distributions sysctl_time_since_reset SYSCTL_HANDLER_ARGS
84*1031c584SApple OSS Distributions {
85*1031c584SApple OSS Distributions #pragma unused(arg1, arg2, oidp)
86*1031c584SApple OSS Distributions uint64_t return_value = ml_get_time_since_reset();
87*1031c584SApple OSS Distributions return SYSCTL_OUT(req, &return_value, sizeof(return_value));
88*1031c584SApple OSS Distributions }
89*1031c584SApple OSS Distributions
90*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep, OID_AUTO, time_since_reset,
91*1031c584SApple OSS Distributions CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED,
92*1031c584SApple OSS Distributions 0, 0, sysctl_time_since_reset, "I",
93*1031c584SApple OSS Distributions "Continuous time since last SOC boot/wake started");
94*1031c584SApple OSS Distributions
95*1031c584SApple OSS Distributions static int
96*1031c584SApple OSS Distributions sysctl_wake_conttime SYSCTL_HANDLER_ARGS
97*1031c584SApple OSS Distributions {
98*1031c584SApple OSS Distributions #pragma unused(arg1, arg2, oidp)
99*1031c584SApple OSS Distributions uint64_t return_value = ml_get_conttime_wake_time();
100*1031c584SApple OSS Distributions return SYSCTL_OUT(req, &return_value, sizeof(return_value));
101*1031c584SApple OSS Distributions }
102*1031c584SApple OSS Distributions
103*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep, OID_AUTO, wake_conttime,
104*1031c584SApple OSS Distributions CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED,
105*1031c584SApple OSS Distributions 0, 0, sysctl_wake_conttime, "I",
106*1031c584SApple OSS Distributions "Continuous Time at the last wakeup");
107*1031c584SApple OSS Distributions
108*1031c584SApple OSS Distributions #if defined(HAS_IPI)
109*1031c584SApple OSS Distributions static int
cpu_signal_deferred_timer(__unused struct sysctl_oid * oidp,__unused void * arg1,__unused int arg2,struct sysctl_req * req)110*1031c584SApple OSS Distributions cpu_signal_deferred_timer(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
111*1031c584SApple OSS Distributions {
112*1031c584SApple OSS Distributions int new_value = 0;
113*1031c584SApple OSS Distributions int changed = 0;
114*1031c584SApple OSS Distributions
115*1031c584SApple OSS Distributions int old_value = (int)ml_cpu_signal_deferred_get_timer();
116*1031c584SApple OSS Distributions
117*1031c584SApple OSS Distributions int error = sysctl_io_number(req, old_value, sizeof(int), &new_value, &changed);
118*1031c584SApple OSS Distributions
119*1031c584SApple OSS Distributions if (error == 0 && changed) {
120*1031c584SApple OSS Distributions ml_cpu_signal_deferred_adjust_timer((uint64_t)new_value);
121*1031c584SApple OSS Distributions }
122*1031c584SApple OSS Distributions
123*1031c584SApple OSS Distributions return error;
124*1031c584SApple OSS Distributions }
125*1031c584SApple OSS Distributions
126*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep, OID_AUTO, deferred_ipi_timeout,
127*1031c584SApple OSS Distributions CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_LOCKED,
128*1031c584SApple OSS Distributions 0, 0,
129*1031c584SApple OSS Distributions cpu_signal_deferred_timer, "I", "Deferred IPI timeout (nanoseconds)");
130*1031c584SApple OSS Distributions
131*1031c584SApple OSS Distributions #endif /* defined(HAS_IPI) */
132*1031c584SApple OSS Distributions
133*1031c584SApple OSS Distributions /*
134*1031c584SApple OSS Distributions * For source compatibility, here's some machdep.cpu mibs that
135*1031c584SApple OSS Distributions * use host_info() to simulate reasonable answers.
136*1031c584SApple OSS Distributions */
137*1031c584SApple OSS Distributions
138*1031c584SApple OSS Distributions SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW | CTLFLAG_LOCKED, 0,
139*1031c584SApple OSS Distributions "CPU info");
140*1031c584SApple OSS Distributions
141*1031c584SApple OSS Distributions static int
142*1031c584SApple OSS Distributions arm_host_info SYSCTL_HANDLER_ARGS
143*1031c584SApple OSS Distributions {
144*1031c584SApple OSS Distributions __unused struct sysctl_oid *unused_oidp = oidp;
145*1031c584SApple OSS Distributions
146*1031c584SApple OSS Distributions host_basic_info_data_t hinfo;
147*1031c584SApple OSS Distributions mach_msg_type_number_t count = HOST_BASIC_INFO_COUNT;
148*1031c584SApple OSS Distributions #define BSD_HOST 1
149*1031c584SApple OSS Distributions kern_return_t kret = host_info((host_t)BSD_HOST,
150*1031c584SApple OSS Distributions HOST_BASIC_INFO, (host_info_t)&hinfo, &count);
151*1031c584SApple OSS Distributions if (KERN_SUCCESS != kret) {
152*1031c584SApple OSS Distributions return EINVAL;
153*1031c584SApple OSS Distributions }
154*1031c584SApple OSS Distributions
155*1031c584SApple OSS Distributions if (sizeof(uint32_t) != arg2) {
156*1031c584SApple OSS Distributions panic("size mismatch");
157*1031c584SApple OSS Distributions }
158*1031c584SApple OSS Distributions
159*1031c584SApple OSS Distributions uintptr_t woffset = (uintptr_t)arg1 / sizeof(uint32_t);
160*1031c584SApple OSS Distributions uint32_t datum = *(uint32_t *)(((uint32_t *)&hinfo) + woffset);
161*1031c584SApple OSS Distributions return SYSCTL_OUT(req, &datum, sizeof(datum));
162*1031c584SApple OSS Distributions }
163*1031c584SApple OSS Distributions
164*1031c584SApple OSS Distributions /*
165*1031c584SApple OSS Distributions * machdep.cpu.cores_per_package
166*1031c584SApple OSS Distributions *
167*1031c584SApple OSS Distributions * x86: derived from CPUID data.
168*1031c584SApple OSS Distributions * ARM: how many physical cores we have in the AP; aka hw.physicalcpu_max
169*1031c584SApple OSS Distributions */
170*1031c584SApple OSS Distributions static
171*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep_cpu, OID_AUTO, cores_per_package,
172*1031c584SApple OSS Distributions CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
173*1031c584SApple OSS Distributions (void *)offsetof(host_basic_info_data_t, physical_cpu_max),
174*1031c584SApple OSS Distributions sizeof(integer_t),
175*1031c584SApple OSS Distributions arm_host_info, "I", "CPU cores per package");
176*1031c584SApple OSS Distributions
177*1031c584SApple OSS Distributions /*
178*1031c584SApple OSS Distributions * machdep.cpu.core_count
179*1031c584SApple OSS Distributions *
180*1031c584SApple OSS Distributions * x86: derived from CPUID data.
181*1031c584SApple OSS Distributions * ARM: # active physical cores in the AP; aka hw.physicalcpu
182*1031c584SApple OSS Distributions */
183*1031c584SApple OSS Distributions static
184*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep_cpu, OID_AUTO, core_count,
185*1031c584SApple OSS Distributions CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
186*1031c584SApple OSS Distributions (void *)offsetof(host_basic_info_data_t, physical_cpu),
187*1031c584SApple OSS Distributions sizeof(integer_t),
188*1031c584SApple OSS Distributions arm_host_info, "I", "Number of enabled cores per package");
189*1031c584SApple OSS Distributions
190*1031c584SApple OSS Distributions /*
191*1031c584SApple OSS Distributions * machdep.cpu.logical_per_package
192*1031c584SApple OSS Distributions *
193*1031c584SApple OSS Distributions * x86: derived from CPUID data. Returns ENOENT if HTT bit not set, but
194*1031c584SApple OSS Distributions * most x64 CPUs have that, so assume it's available.
195*1031c584SApple OSS Distributions * ARM: total # logical cores in the AP; aka hw.logicalcpu_max
196*1031c584SApple OSS Distributions */
197*1031c584SApple OSS Distributions static
198*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep_cpu, OID_AUTO, logical_per_package,
199*1031c584SApple OSS Distributions CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
200*1031c584SApple OSS Distributions (void *)offsetof(host_basic_info_data_t, logical_cpu_max),
201*1031c584SApple OSS Distributions sizeof(integer_t),
202*1031c584SApple OSS Distributions arm_host_info, "I", "CPU logical cpus per package");
203*1031c584SApple OSS Distributions
204*1031c584SApple OSS Distributions /*
205*1031c584SApple OSS Distributions * machdep.cpu.thread_count
206*1031c584SApple OSS Distributions *
207*1031c584SApple OSS Distributions * x86: derived from CPUID data.
208*1031c584SApple OSS Distributions * ARM: # active logical cores in the AP; aka hw.logicalcpu
209*1031c584SApple OSS Distributions */
210*1031c584SApple OSS Distributions static
211*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep_cpu, OID_AUTO, thread_count,
212*1031c584SApple OSS Distributions CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
213*1031c584SApple OSS Distributions (void *)offsetof(host_basic_info_data_t, logical_cpu),
214*1031c584SApple OSS Distributions sizeof(integer_t),
215*1031c584SApple OSS Distributions arm_host_info, "I", "Number of enabled threads per package");
216*1031c584SApple OSS Distributions
217*1031c584SApple OSS Distributions static SECURITY_READ_ONLY_LATE(char*) brand_string = NULL;
218*1031c584SApple OSS Distributions static SECURITY_READ_ONLY_LATE(size_t) brand_string_len = 0;
219*1031c584SApple OSS Distributions
220*1031c584SApple OSS Distributions /*
221*1031c584SApple OSS Distributions * SecureDTLookupEntry() is only guaranteed to work before PE_init_iokit(),
222*1031c584SApple OSS Distributions * so we load the brand string (if available) in a startup handler.
223*1031c584SApple OSS Distributions */
224*1031c584SApple OSS Distributions __startup_func
225*1031c584SApple OSS Distributions static void
sysctl_load_brand_string(void)226*1031c584SApple OSS Distributions sysctl_load_brand_string(void)
227*1031c584SApple OSS Distributions {
228*1031c584SApple OSS Distributions DTEntry node;
229*1031c584SApple OSS Distributions void const *value = NULL;
230*1031c584SApple OSS Distributions unsigned int size = 0;
231*1031c584SApple OSS Distributions
232*1031c584SApple OSS Distributions if (kSuccess != SecureDTLookupEntry(0, "/product", &node)) {
233*1031c584SApple OSS Distributions return;
234*1031c584SApple OSS Distributions }
235*1031c584SApple OSS Distributions
236*1031c584SApple OSS Distributions if (kSuccess != SecureDTGetProperty(node, "product-soc-name", (void const **) &value, &size)) {
237*1031c584SApple OSS Distributions return;
238*1031c584SApple OSS Distributions }
239*1031c584SApple OSS Distributions
240*1031c584SApple OSS Distributions if (size == 0) {
241*1031c584SApple OSS Distributions return;
242*1031c584SApple OSS Distributions }
243*1031c584SApple OSS Distributions
244*1031c584SApple OSS Distributions brand_string = zalloc_permanent(size, ZALIGN_NONE);
245*1031c584SApple OSS Distributions if (brand_string == NULL) {
246*1031c584SApple OSS Distributions return;
247*1031c584SApple OSS Distributions }
248*1031c584SApple OSS Distributions
249*1031c584SApple OSS Distributions memcpy(brand_string, value, size);
250*1031c584SApple OSS Distributions brand_string_len = size;
251*1031c584SApple OSS Distributions }
252*1031c584SApple OSS Distributions STARTUP(SYSCTL, STARTUP_RANK_MIDDLE, sysctl_load_brand_string);
253*1031c584SApple OSS Distributions
254*1031c584SApple OSS Distributions /*
255*1031c584SApple OSS Distributions * machdep.cpu.brand_string
256*1031c584SApple OSS Distributions *
257*1031c584SApple OSS Distributions * x86: derived from CPUID data.
258*1031c584SApple OSS Distributions * ARM: Grab the product string from the device tree, if it exists.
259*1031c584SApple OSS Distributions * Otherwise, cons something up from the CPUID register.
260*1031c584SApple OSS Distributions * the value is already exported via the commpage. So keep it simple.
261*1031c584SApple OSS Distributions */
262*1031c584SApple OSS Distributions static int
263*1031c584SApple OSS Distributions make_brand_string SYSCTL_HANDLER_ARGS
264*1031c584SApple OSS Distributions {
265*1031c584SApple OSS Distributions __unused struct sysctl_oid *unused_oidp = oidp;
266*1031c584SApple OSS Distributions __unused void *unused_arg1 = arg1;
267*1031c584SApple OSS Distributions __unused int unused_arg2 = arg2;
268*1031c584SApple OSS Distributions
269*1031c584SApple OSS Distributions if (brand_string != NULL) {
270*1031c584SApple OSS Distributions return SYSCTL_OUT(req, brand_string, brand_string_len);
271*1031c584SApple OSS Distributions }
272*1031c584SApple OSS Distributions
273*1031c584SApple OSS Distributions const char *impl;
274*1031c584SApple OSS Distributions
275*1031c584SApple OSS Distributions switch (cpuid_info()->arm_info.arm_implementor) {
276*1031c584SApple OSS Distributions case CPU_VID_APPLE:
277*1031c584SApple OSS Distributions impl = "Apple";
278*1031c584SApple OSS Distributions break;
279*1031c584SApple OSS Distributions case CPU_VID_ARM:
280*1031c584SApple OSS Distributions impl = "ARM";
281*1031c584SApple OSS Distributions break;
282*1031c584SApple OSS Distributions default:
283*1031c584SApple OSS Distributions impl = "ARM architecture";
284*1031c584SApple OSS Distributions break;
285*1031c584SApple OSS Distributions }
286*1031c584SApple OSS Distributions
287*1031c584SApple OSS Distributions char buf[80];
288*1031c584SApple OSS Distributions snprintf(buf, sizeof(buf), "%s processor", impl);
289*1031c584SApple OSS Distributions return SYSCTL_OUT(req, buf, strlen(buf) + 1);
290*1031c584SApple OSS Distributions }
291*1031c584SApple OSS Distributions
292*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep_cpu, OID_AUTO, brand_string,
293*1031c584SApple OSS Distributions CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,
294*1031c584SApple OSS Distributions 0, 0, make_brand_string, "A", "CPU brand string");
295*1031c584SApple OSS Distributions
296*1031c584SApple OSS Distributions
297*1031c584SApple OSS Distributions static int
298*1031c584SApple OSS Distributions virtual_address_size SYSCTL_HANDLER_ARGS
299*1031c584SApple OSS Distributions {
300*1031c584SApple OSS Distributions #pragma unused(arg1, arg2, oidp)
301*1031c584SApple OSS Distributions int return_value = 64 - T0SZ_BOOT;
302*1031c584SApple OSS Distributions return SYSCTL_OUT(req, &return_value, sizeof(return_value));
303*1031c584SApple OSS Distributions }
304*1031c584SApple OSS Distributions
305*1031c584SApple OSS Distributions static
306*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep, OID_AUTO, virtual_address_size,
307*1031c584SApple OSS Distributions CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED,
308*1031c584SApple OSS Distributions 0, 0, virtual_address_size, "I",
309*1031c584SApple OSS Distributions "Number of addressable bits in userspace virtual addresses");
310*1031c584SApple OSS Distributions
311*1031c584SApple OSS Distributions
312*1031c584SApple OSS Distributions #if DEVELOPMENT || DEBUG
313*1031c584SApple OSS Distributions extern uint64_t TLockTimeOut;
314*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, tlto,
315*1031c584SApple OSS Distributions CTLFLAG_RW | CTLFLAG_LOCKED, &TLockTimeOut,
316*1031c584SApple OSS Distributions "Ticket spinlock timeout (MATUs): use with care");
317*1031c584SApple OSS Distributions
318*1031c584SApple OSS Distributions extern uint32_t timebase_validation;
319*1031c584SApple OSS Distributions SYSCTL_UINT(_machdep, OID_AUTO, timebase_validation,
320*1031c584SApple OSS Distributions CTLFLAG_RW | CTLFLAG_LOCKED, &timebase_validation, 0,
321*1031c584SApple OSS Distributions "Monotonicity validation of kernel mach_absolute_time()");
322*1031c584SApple OSS Distributions
323*1031c584SApple OSS Distributions #if __WKDM_ISA_2P_WORKAROUND__
324*1031c584SApple OSS Distributions extern uint64_t wkdmdretries, wkdmdretriespb;
325*1031c584SApple OSS Distributions extern uint32_t simulate_wkdm2p_error, wkdm_isa_2p_war_required;
326*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, wkdmdretries,
327*1031c584SApple OSS Distributions CTLFLAG_RW | CTLFLAG_LOCKED, &wkdmdretries,
328*1031c584SApple OSS Distributions "Number of WKDM errata retries");
329*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, wkdmdretriespb,
330*1031c584SApple OSS Distributions CTLFLAG_RW | CTLFLAG_LOCKED, &wkdmdretriespb,
331*1031c584SApple OSS Distributions "Number of retries where payload was on page boundary");
332*1031c584SApple OSS Distributions SYSCTL_UINT(_machdep, OID_AUTO, simulate_wkdm2p_error,
333*1031c584SApple OSS Distributions CTLFLAG_RW | CTLFLAG_LOCKED,
334*1031c584SApple OSS Distributions &simulate_wkdm2p_error, 0, "");
335*1031c584SApple OSS Distributions SYSCTL_UINT(_machdep, OID_AUTO, wkdm_isa_2p_war_required,
336*1031c584SApple OSS Distributions CTLFLAG_RW | CTLFLAG_LOCKED,
337*1031c584SApple OSS Distributions &wkdm_isa_2p_war_required, 0, "");
338*1031c584SApple OSS Distributions #endif /* __WKDM_ISA_2P_WORKAROUND__ */
339*1031c584SApple OSS Distributions
340*1031c584SApple OSS Distributions
341*1031c584SApple OSS Distributions /*
342*1031c584SApple OSS Distributions * macro to generate a sysctl machdep.cpu.sysreg_* for a given system register
343*1031c584SApple OSS Distributions * using __builtin_arm_rsr64.
344*1031c584SApple OSS Distributions */
345*1031c584SApple OSS Distributions #define SYSCTL_PROC_MACHDEP_CPU_SYSREG(name) \
346*1031c584SApple OSS Distributions static int \
347*1031c584SApple OSS Distributions sysctl_sysreg_##name SYSCTL_HANDLER_ARGS \
348*1031c584SApple OSS Distributions { \
349*1031c584SApple OSS Distributions _Pragma("unused(arg1, arg2, oidp)") \
350*1031c584SApple OSS Distributions uint64_t return_value = __builtin_arm_rsr64(#name); \
351*1031c584SApple OSS Distributions return SYSCTL_OUT(req, &return_value, sizeof(return_value)); \
352*1031c584SApple OSS Distributions } \
353*1031c584SApple OSS Distributions SYSCTL_PROC(_machdep_cpu, OID_AUTO, sysreg_##name, \
354*1031c584SApple OSS Distributions CTLFLAG_RD | CTLTYPE_QUAD | CTLFLAG_LOCKED, \
355*1031c584SApple OSS Distributions 0, 0, sysctl_sysreg_##name, "Q", \
356*1031c584SApple OSS Distributions #name " register on the current CPU");
357*1031c584SApple OSS Distributions
358*1031c584SApple OSS Distributions
359*1031c584SApple OSS Distributions // CPU system registers
360*1031c584SApple OSS Distributions // ARM64: AArch64 Vector Base Address Register
361*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(VBAR_EL1);
362*1031c584SApple OSS Distributions // ARM64: AArch64 Memory Attribute Indirection Register
363*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(MAIR_EL1);
364*1031c584SApple OSS Distributions // ARM64: AArch64 Translation table base register 1
365*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(TTBR1_EL1);
366*1031c584SApple OSS Distributions // ARM64: AArch64 System Control Register
367*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(SCTLR_EL1);
368*1031c584SApple OSS Distributions // ARM64: AArch64 Translation Control Register
369*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(TCR_EL1);
370*1031c584SApple OSS Distributions // ARM64: AArch64 Memory Model Feature Register 0
371*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(ID_AA64MMFR0_EL1);
372*1031c584SApple OSS Distributions // ARM64: AArch64 Instruction Set Attribute Register 1
373*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(ID_AA64ISAR1_EL1);
374*1031c584SApple OSS Distributions #if APPLE_ARM64_ARCH_FAMILY
375*1031c584SApple OSS Distributions // Apple ID Register
376*1031c584SApple OSS Distributions SYSCTL_PROC_MACHDEP_CPU_SYSREG(AIDR_EL1);
377*1031c584SApple OSS Distributions #endif /* APPLE_ARM64_ARCH_FAMILY */
378*1031c584SApple OSS Distributions
379*1031c584SApple OSS Distributions #endif /* DEVELOPMENT || DEBUG */
380*1031c584SApple OSS Distributions
381*1031c584SApple OSS Distributions
382*1031c584SApple OSS Distributions #ifdef ML_IO_TIMEOUTS_ENABLED
383*1031c584SApple OSS Distributions /*
384*1031c584SApple OSS Distributions * Timeouts for ml_{io|phys}_{read|write}...
385*1031c584SApple OSS Distributions * RO on DEVELOPMENT/DEBUG kernels.
386*1031c584SApple OSS Distributions */
387*1031c584SApple OSS Distributions
388*1031c584SApple OSS Distributions #if DEVELOPMENT || DEBUG
389*1031c584SApple OSS Distributions #define MMIO_TIMEOUT_FLAGS (CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED)
390*1031c584SApple OSS Distributions #else
391*1031c584SApple OSS Distributions #define MMIO_TIMEOUT_FLAGS (CTLFLAG_KERN | CTLFLAG_RD | CTLFLAG_LOCKED)
392*1031c584SApple OSS Distributions #endif
393*1031c584SApple OSS Distributions
394*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, report_phy_read_delay, MMIO_TIMEOUT_FLAGS,
395*1031c584SApple OSS Distributions &report_phy_read_delay_to, "Maximum time before io/phys read gets reported or panics");
396*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, report_phy_write_delay, MMIO_TIMEOUT_FLAGS,
397*1031c584SApple OSS Distributions &report_phy_write_delay_to, "Maximum time before io/phys write gets reported or panics");
398*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, trace_phy_read_delay, MMIO_TIMEOUT_FLAGS,
399*1031c584SApple OSS Distributions &trace_phy_read_delay_to, "Maximum time before io/phys read gets ktraced");
400*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, trace_phy_write_delay, MMIO_TIMEOUT_FLAGS,
401*1031c584SApple OSS Distributions &trace_phy_write_delay_to, "Maximum time before io/phys write gets ktraced");
402*1031c584SApple OSS Distributions
403*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, phy_read_delay_panic, CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
404*1031c584SApple OSS Distributions &phy_read_panic, 0, "if set, report-phy-read-delay timeout panics");
405*1031c584SApple OSS Distributions SYSCTL_INT(_machdep, OID_AUTO, phy_write_delay_panic, CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
406*1031c584SApple OSS Distributions &phy_write_panic, 0, "if set, report-phy-write-delay timeout panics");
407*1031c584SApple OSS Distributions
408*1031c584SApple OSS Distributions #if ML_IO_SIMULATE_STRETCHED_ENABLED
409*1031c584SApple OSS Distributions SYSCTL_QUAD(_machdep, OID_AUTO, sim_stretched_io_ns, CTLFLAG_KERN | CTLFLAG_RW | CTLFLAG_LOCKED,
410*1031c584SApple OSS Distributions &simulate_stretched_io, "simulate stretched io in ml_read_io, ml_write_io");
411*1031c584SApple OSS Distributions #endif /* ML_IO_SIMULATE_STRETCHED_ENABLED */
412*1031c584SApple OSS Distributions
413*1031c584SApple OSS Distributions #endif /* ML_IO_TIMEOUTS_ENABLED */
414