cpu.h revision 1.32 1 1.32 jmcneill /* $NetBSD: cpu.h,v 1.32 2021/02/21 15:00:04 jmcneill Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.26 skrll * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas of 3am Software Foundry.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt #ifndef _AARCH64_CPU_H_
33 1.1 matt #define _AARCH64_CPU_H_
34 1.1 matt
35 1.21 skrll #include <arm/cpu.h>
36 1.21 skrll
37 1.1 matt #ifdef __aarch64__
38 1.1 matt
39 1.2 ryo #ifdef _KERNEL_OPT
40 1.2 ryo #include "opt_multiprocessor.h"
41 1.2 ryo #endif
42 1.2 ryo
43 1.7 ryo #include <sys/param.h>
44 1.7 ryo
45 1.1 matt #if defined(_KERNEL) || defined(_KMEMUSER)
46 1.2 ryo #include <sys/evcnt.h>
47 1.11 mrg
48 1.2 ryo #include <aarch64/frame.h>
49 1.11 mrg #include <aarch64/armreg.h>
50 1.2 ryo
51 1.1 matt struct clockframe {
52 1.2 ryo struct trapframe cf_tf;
53 1.1 matt };
54 1.1 matt
55 1.2 ryo /* (spsr & 15) == SPSR_M_EL0T(64bit,0) or USER(32bit,0) */
56 1.2 ryo #define CLKF_USERMODE(cf) ((((cf)->cf_tf.tf_spsr) & 0x0f) == 0)
57 1.2 ryo #define CLKF_PC(cf) ((cf)->cf_tf.tf_pc)
58 1.2 ryo #define CLKF_INTR(cf) ((void)(cf), curcpu()->ci_intr_depth > 1)
59 1.1 matt
60 1.12 skrll /*
61 1.12 skrll * LWP_PC: Find out the program counter for the given lwp.
62 1.12 skrll */
63 1.12 skrll #define LWP_PC(l) ((l)->l_md.md_utf->tf_pc)
64 1.12 skrll
65 1.1 matt #include <sys/cpu_data.h>
66 1.1 matt #include <sys/device_if.h>
67 1.1 matt #include <sys/intr.h>
68 1.1 matt
69 1.13 ryo struct aarch64_cpufuncs {
70 1.13 ryo void (*cf_set_ttbr0)(uint64_t);
71 1.24 ryo void (*cf_icache_sync_range)(vaddr_t, vsize_t);
72 1.13 ryo };
73 1.13 ryo
74 1.1 matt struct cpu_info {
75 1.1 matt struct cpu_data ci_data;
76 1.1 matt device_t ci_dev;
77 1.1 matt cpuid_t ci_cpuid;
78 1.26 skrll
79 1.26 skrll /*
80 1.26 skrll * the following are in their own cache line, as they are stored to
81 1.26 skrll * regularly by remote CPUs; when they were mixed with other fields
82 1.26 skrll * we observed frequent cache misses.
83 1.26 skrll */
84 1.26 skrll int ci_want_resched __aligned(COHERENCY_UNIT);
85 1.26 skrll /* XXX pending IPIs? */
86 1.26 skrll
87 1.26 skrll /*
88 1.26 skrll * this is stored frequently, and is fetched by remote CPUs.
89 1.26 skrll */
90 1.26 skrll struct lwp *ci_curlwp __aligned(COHERENCY_UNIT);
91 1.16 ad struct lwp *ci_onproc;
92 1.26 skrll
93 1.26 skrll /*
94 1.26 skrll * largely CPU-private.
95 1.26 skrll */
96 1.26 skrll struct lwp *ci_softlwps[SOFTINT_COUNT] __aligned(COHERENCY_UNIT);
97 1.1 matt
98 1.1 matt uint64_t ci_lastintr;
99 1.1 matt
100 1.1 matt int ci_mtx_oldspl;
101 1.1 matt int ci_mtx_count;
102 1.1 matt
103 1.32 jmcneill int ci_cpl; /* current processor level (spl) */
104 1.32 jmcneill int ci_hwpl; /* current hardware priority */
105 1.2 ryo volatile u_int ci_softints;
106 1.1 matt volatile u_int ci_intr_depth;
107 1.31 jmcneill volatile uint32_t ci_blocked_pics;
108 1.31 jmcneill volatile uint32_t ci_pending_pics;
109 1.31 jmcneill volatile uint32_t ci_pending_ipls;
110 1.2 ryo
111 1.23 riastrad int ci_kfpu_spl;
112 1.23 riastrad
113 1.2 ryo /* event counters */
114 1.2 ryo struct evcnt ci_vfp_use;
115 1.2 ryo struct evcnt ci_vfp_reuse;
116 1.2 ryo struct evcnt ci_vfp_save;
117 1.2 ryo struct evcnt ci_vfp_release;
118 1.25 ryo struct evcnt ci_uct_trap;
119 1.29 jmcneill struct evcnt ci_intr_preempt;
120 1.6 jmcneill
121 1.18 mrg /* FDT or similar supplied "cpu capacity" */
122 1.18 mrg uint32_t ci_capacity_dmips_mhz;
123 1.18 mrg
124 1.6 jmcneill /* interrupt controller */
125 1.6 jmcneill u_int ci_gic_redist; /* GICv3 redistributor index */
126 1.6 jmcneill uint64_t ci_gic_sgir; /* GICv3 SGIR target */
127 1.7 ryo
128 1.9 jmcneill /* ACPI */
129 1.30 jmcneill uint32_t ci_acpiid; /* ACPI Processor Unique ID */
130 1.9 jmcneill
131 1.11 mrg struct aarch64_sysctl_cpu_id ci_id;
132 1.7 ryo
133 1.7 ryo struct aarch64_cache_info *ci_cacheinfo;
134 1.13 ryo struct aarch64_cpufuncs ci_cpufuncs;
135 1.7 ryo
136 1.7 ryo } __aligned(COHERENCY_UNIT);
137 1.1 matt
138 1.22 christos #ifdef _KERNEL
139 1.26 skrll static inline struct lwp * __attribute__ ((const))
140 1.26 skrll aarch64_curlwp(void)
141 1.1 matt {
142 1.26 skrll struct lwp *l;
143 1.26 skrll __asm("mrs %0, tpidr_el1" : "=r"(l));
144 1.26 skrll return l;
145 1.1 matt }
146 1.1 matt
147 1.26 skrll /* forward declaration; defined in sys/lwp.h. */
148 1.26 skrll static __inline struct cpu_info *lwp_getcpu(struct lwp *);
149 1.26 skrll
150 1.26 skrll #define curcpu() (lwp_getcpu(aarch64_curlwp()))
151 1.26 skrll #define setsoftast(ci) (cpu_signotify((ci)->ci_onproc))
152 1.26 skrll #undef curlwp
153 1.26 skrll #define curlwp (aarch64_curlwp())
154 1.10 skrll
155 1.27 ryo int cpu_maxproc(void);
156 1.26 skrll void cpu_signotify(struct lwp *l);
157 1.21 skrll void cpu_need_proftick(struct lwp *l);
158 1.21 skrll
159 1.21 skrll void cpu_hatch(struct cpu_info *);
160 1.2 ryo
161 1.2 ryo extern struct cpu_info *cpu_info[];
162 1.21 skrll extern struct cpu_info cpu_info_store[];
163 1.1 matt
164 1.28 ryo #define CPU_INFO_ITERATOR int
165 1.20 riastrad #if defined(MULTIPROCESSOR) || defined(_MODULE)
166 1.2 ryo #define cpu_number() (curcpu()->ci_index)
167 1.2 ryo #define CPU_IS_PRIMARY(ci) ((ci)->ci_index == 0)
168 1.3 ryo #define CPU_INFO_FOREACH(cii, ci) \
169 1.3 ryo cii = 0, ci = cpu_info[0]; \
170 1.3 ryo cii < (ncpu ? ncpu : 1) && (ci = cpu_info[cii]) != NULL; \
171 1.2 ryo cii++
172 1.2 ryo #else /* MULTIPROCESSOR */
173 1.2 ryo #define cpu_number() 0
174 1.2 ryo #define CPU_IS_PRIMARY(ci) true
175 1.3 ryo #define CPU_INFO_FOREACH(cii, ci) \
176 1.2 ryo cii = 0, __USE(cii), ci = curcpu(); ci != NULL; ci = NULL
177 1.2 ryo #endif /* MULTIPROCESSOR */
178 1.1 matt
179 1.26 skrll #define LWP0_CPU_INFO (&cpu_info_store[0])
180 1.1 matt
181 1.1 matt static inline void
182 1.1 matt cpu_dosoftints(void)
183 1.1 matt {
184 1.2 ryo #if defined(__HAVE_FAST_SOFTINTS) && !defined(__HAVE_PIC_FAST_SOFTINTS)
185 1.2 ryo void dosoftints(void);
186 1.2 ryo struct cpu_info * const ci = curcpu();
187 1.2 ryo
188 1.2 ryo if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0)
189 1.2 ryo dosoftints();
190 1.2 ryo #endif
191 1.1 matt }
192 1.1 matt
193 1.22 christos #endif /* _KERNEL */
194 1.22 christos
195 1.1 matt #endif /* _KERNEL || _KMEMUSER */
196 1.1 matt
197 1.1 matt #endif
198 1.1 matt
199 1.1 matt #endif /* _AARCH64_CPU_H_ */
200