Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | /* * Copyright (c) 2016 Cadence Design Systems, Inc. * SPDX-License-Identifier: Apache-2.0 */ /** * @file * @brief Xtensa specific kernel interface header * This header contains the Xtensa specific kernel interface. It is included * by the generic kernel interface header (include/zephyr/arch/cpu.h) */ #ifndef ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_ #define ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_ #include <zephyr/irq.h> #include <zephyr/devicetree.h> #if !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) #include <zephyr/types.h> #include <zephyr/toolchain.h> #include <zephyr/arch/common/sys_bitops.h> #include <zephyr/arch/common/sys_io.h> #include <zephyr/arch/common/ffs.h> #include <zephyr/sw_isr_table.h> #include <zephyr/arch/xtensa/syscall.h> #include <zephyr/arch/xtensa/thread.h> #include <zephyr/arch/xtensa/irq.h> #include <xtensa/config/core.h> #include <zephyr/arch/common/addr_types.h> #include <zephyr/arch/xtensa/gdbstub.h> #include <zephyr/debug/sparse.h> #include <zephyr/arch/xtensa/thread_stack.h> #include <zephyr/sys/slist.h> #include <zephyr/drivers/timer/system_timer.h> #ifdef CONFIG_XTENSA_MMU #include <zephyr/arch/xtensa/xtensa_mmu.h> #endif #ifdef CONFIG_XTENSA_MPU #include <zephyr/arch/xtensa/mpu.h> #endif /** * @defgroup xtensa_apis Xtensa APIs * @{ * @} * * @defgroup xtensa_internal_apis Xtensa Internal APIs * @ingroup xtensa_apis * @{ * @} */ #include <zephyr/arch/xtensa/exception.h> #ifdef __cplusplus extern "C" { #endif struct arch_mem_domain { #ifdef CONFIG_XTENSA_MMU uint32_t *ptables __aligned(CONFIG_MMU_PAGE_SIZE); uint8_t asid; bool dirty; #endif #ifdef CONFIG_XTENSA_MPU struct xtensa_mpu_map mpu_map; #endif sys_snode_t node; }; /** * @brief Generate hardware exception. * * This generates hardware exception which is used by ARCH_EXCEPT(). * * @param reason_p Reason for exception. */ void xtensa_arch_except(int reason_p); /** * @brief Generate kernel oops. * * This generates kernel oops which is used by arch_syscall_oops(). * * @param reason_p Reason for exception. * @param ssf Stack pointer. */ void xtensa_arch_kernel_oops(int reason_p, void *ssf); #ifdef CONFIG_USERSPACE #define ARCH_EXCEPT(reason_p) do { \ if (k_is_user_context()) { \ arch_syscall_invoke1(reason_p, \ K_SYSCALL_XTENSA_USER_FAULT); \ } else { \ xtensa_arch_except(reason_p); \ } \ CODE_UNREACHABLE; \ } while (false) #else #define ARCH_EXCEPT(reason_p) do { \ xtensa_arch_except(reason_p); \ CODE_UNREACHABLE; \ } while (false) #endif __syscall void xtensa_user_fault(unsigned int reason); #include <zephyr/syscalls/arch.h> /* internal routine documented in C file, needed by IRQ_CONNECT() macro */ void z_irq_priority_set(uint32_t irq, uint32_t prio, uint32_t flags); #define ARCH_IRQ_CONNECT(irq_p, priority_p, isr_p, isr_param_p, flags_p) \ { \ Z_ISR_DECLARE(irq_p, flags_p, isr_p, isr_param_p); \ } /** Implementation of @ref arch_k_cycle_get_32. */ static inline uint32_t arch_k_cycle_get_32(void) { return sys_clock_cycle_get_32(); } /** Implementation of @ref arch_k_cycle_get_64. */ static inline uint64_t arch_k_cycle_get_64(void) { return sys_clock_cycle_get_64(); } /** Implementation of @ref arch_nop. */ static ALWAYS_INLINE void arch_nop(void) { __asm__ volatile("nop"); } /** * @brief Lock VECBASE if supported by hardware. * * The bit 0 of VECBASE acts as a lock bit on hardware supporting * this feature. When this bit is set, VECBASE cannot be changed * until it is cleared by hardware reset. When the hardware does not * support this bit, it is hardwired to 0. */ static ALWAYS_INLINE void xtensa_vecbase_lock(void) { int vecbase; __asm__ volatile("rsr.vecbase %0" : "=r" (vecbase)); __asm__ volatile("wsr.vecbase %0; rsync" : : "r" (vecbase | 1)); } #if defined(CONFIG_XTENSA_RPO_CACHE) || defined(__DOXYGEN__) #if defined(CONFIG_ARCH_HAS_COHERENCE) || defined(__DOXYGEN__) /** Implementation of @ref arch_mem_coherent. */ static inline bool arch_mem_coherent(void *ptr) { size_t addr = (size_t) ptr; return (addr >> 29) == CONFIG_XTENSA_UNCACHED_REGION; } #endif /* Utility to generate an unrolled and optimal[1] code sequence to set * the RPO TLB registers (contra the HAL cacheattr macros, which * generate larger code and can't be called from C), based on the * KERNEL_COHERENCE configuration in use. Selects RPO attribute "2" * for regions (including MMIO registers in region zero) which want to * bypass L1, "4" for the cached region which wants writeback, and * "15" (invalid) elsewhere. * * Note that on cores that have the "translation" option set, we need * to put an identity mapping in the high bits. Also per spec * changing the current code region (by definition cached) requires * that WITLB be followed by an ISYNC and that both instructions live * in the same cache line (two 3-byte instructions fit in an 8-byte * aligned region, so that's guaranteed not to cross a cache line * boundary). * * [1] With the sole exception of gcc's infuriating insistence on * emitting a precomputed literal for addr + addrincr instead of * computing it with a single ADD instruction from values it already * has in registers. Explicitly assigning the variables to registers * via an attribute works, but then emits needless MOV instructions * instead. I tell myself it's just 32 bytes of .text, but... Sigh. */ #define _REGION_ATTR(r) \ ((r) == 0 ? 2 : \ ((r) == CONFIG_XTENSA_CACHED_REGION ? 4 : \ ((r) == CONFIG_XTENSA_UNCACHED_REGION ? 2 : 15))) #define _SET_ONE_TLB(region) do { \ uint32_t attr = _REGION_ATTR(region); \ if (XCHAL_HAVE_XLT_CACHEATTR) { \ attr |= addr; /* RPO with translation */ \ } \ if (region != CONFIG_XTENSA_CACHED_REGION) { \ __asm__ volatile("wdtlb %0, %1; witlb %0, %1" \ :: "r"(attr), "r"(addr)); \ } else { \ __asm__ volatile("wdtlb %0, %1" \ :: "r"(attr), "r"(addr)); \ __asm__ volatile("j 1f; .align 8; 1:"); \ __asm__ volatile("witlb %0, %1; isync" \ :: "r"(attr), "r"(addr)); \ } \ addr += addrincr; \ } while (0) /** * @brief Setup RPO TLB registers. */ #define ARCH_XTENSA_SET_RPO_TLB() \ do { \ register uint32_t addr = 0, addrincr = 0x20000000; \ FOR_EACH(_SET_ONE_TLB, (;), 0, 1, 2, 3, 4, 5, 6, 7); \ } while (0) #endif /* CONFIG_XTENSA_RPO_CACHE */ #if defined(CONFIG_XTENSA_MMU) || defined(__DOXYGEN__) /** * @brief Peform additional steps after MMU initialization. * * This performs additional steps related to memory management * after the main MMU initialization code. This needs to defined * in the SoC layer. Default is do no nothing. * * @param is_core0 True if this is called while executing on * CPU core #0. */ void arch_xtensa_mmu_post_init(bool is_core0); #endif #ifdef __cplusplus } #endif #endif /* !defined(_ASMLANGUAGE) && !defined(__ASSEMBLER__) */ #endif /* ZEPHYR_INCLUDE_ARCH_XTENSA_ARCH_H_ */ |