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