system.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. #ifndef __ASM_ARM_SYSTEM_H
  2. #define __ASM_ARM_SYSTEM_H
  3. #include <common.h>
  4. #include <linux/compiler.h>
  5. #ifdef CONFIG_ARM64
  6. /*
  7. * SCTLR_EL1/SCTLR_EL2/SCTLR_EL3 bits definitions
  8. */
  9. #define CR_M (1 << 0) /* MMU enable */
  10. #define CR_A (1 << 1) /* Alignment abort enable */
  11. #define CR_C (1 << 2) /* Dcache enable */
  12. #define CR_SA (1 << 3) /* Stack Alignment Check Enable */
  13. #define CR_I (1 << 12) /* Icache enable */
  14. #define CR_WXN (1 << 19) /* Write Permision Imply XN */
  15. #define CR_EE (1 << 25) /* Exception (Big) Endian */
  16. #ifndef CONFIG_SYS_FULL_VA
  17. #define PGTABLE_SIZE (0x10000)
  18. #else
  19. #define PGTABLE_SIZE CONFIG_SYS_PGTABLE_SIZE
  20. #endif
  21. /* 2MB granularity */
  22. #define MMU_SECTION_SHIFT 21
  23. #define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT)
  24. #ifndef __ASSEMBLY__
  25. enum dcache_option {
  26. DCACHE_OFF = 0x3,
  27. };
  28. #define isb() \
  29. ({asm volatile( \
  30. "isb" : : : "memory"); \
  31. })
  32. #define wfi() \
  33. ({asm volatile( \
  34. "wfi" : : : "memory"); \
  35. })
  36. static inline unsigned int current_el(void)
  37. {
  38. unsigned int el;
  39. asm volatile("mrs %0, CurrentEL" : "=r" (el) : : "cc");
  40. return el >> 2;
  41. }
  42. static inline unsigned int get_sctlr(void)
  43. {
  44. unsigned int el, val;
  45. el = current_el();
  46. if (el == 1)
  47. asm volatile("mrs %0, sctlr_el1" : "=r" (val) : : "cc");
  48. else if (el == 2)
  49. asm volatile("mrs %0, sctlr_el2" : "=r" (val) : : "cc");
  50. else
  51. asm volatile("mrs %0, sctlr_el3" : "=r" (val) : : "cc");
  52. return val;
  53. }
  54. static inline void set_sctlr(unsigned int val)
  55. {
  56. unsigned int el;
  57. el = current_el();
  58. if (el == 1)
  59. asm volatile("msr sctlr_el1, %0" : : "r" (val) : "cc");
  60. else if (el == 2)
  61. asm volatile("msr sctlr_el2, %0" : : "r" (val) : "cc");
  62. else
  63. asm volatile("msr sctlr_el3, %0" : : "r" (val) : "cc");
  64. asm volatile("isb");
  65. }
  66. static inline unsigned long read_mpidr(void)
  67. {
  68. unsigned long val;
  69. asm volatile("mrs %0, mpidr_el1" : "=r" (val));
  70. return val;
  71. }
  72. #define BSP_COREID 0
  73. void __asm_flush_dcache_all(void);
  74. void __asm_invalidate_dcache_all(void);
  75. void __asm_flush_dcache_range(u64 start, u64 end);
  76. void __asm_invalidate_tlb_all(void);
  77. void __asm_invalidate_icache_all(void);
  78. int __asm_flush_l3_cache(void);
  79. void armv8_switch_to_el2(void);
  80. void armv8_switch_to_el1(void);
  81. void gic_init(void);
  82. void gic_send_sgi(unsigned long sgino);
  83. void wait_for_wakeup(void);
  84. void protect_secure_region(void);
  85. void smp_kick_all_cpus(void);
  86. void flush_l3_cache(void);
  87. /*
  88. *Issue a hypervisor call in accordance with ARM "SMC Calling convention",
  89. * DEN0028A
  90. *
  91. * @args: input and output arguments
  92. *
  93. */
  94. void hvc_call(struct pt_regs *args);
  95. /*
  96. *Issue a secure monitor call in accordance with ARM "SMC Calling convention",
  97. * DEN0028A
  98. *
  99. * @args: input and output arguments
  100. *
  101. */
  102. void smc_call(struct pt_regs *args);
  103. #endif /* __ASSEMBLY__ */
  104. #else /* CONFIG_ARM64 */
  105. #ifdef __KERNEL__
  106. #define CPU_ARCH_UNKNOWN 0
  107. #define CPU_ARCH_ARMv3 1
  108. #define CPU_ARCH_ARMv4 2
  109. #define CPU_ARCH_ARMv4T 3
  110. #define CPU_ARCH_ARMv5 4
  111. #define CPU_ARCH_ARMv5T 5
  112. #define CPU_ARCH_ARMv5TE 6
  113. #define CPU_ARCH_ARMv5TEJ 7
  114. #define CPU_ARCH_ARMv6 8
  115. #define CPU_ARCH_ARMv7 9
  116. /*
  117. * CR1 bits (CP#15 CR1)
  118. */
  119. #define CR_M (1 << 0) /* MMU enable */
  120. #define CR_A (1 << 1) /* Alignment abort enable */
  121. #define CR_C (1 << 2) /* Dcache enable */
  122. #define CR_W (1 << 3) /* Write buffer enable */
  123. #define CR_P (1 << 4) /* 32-bit exception handler */
  124. #define CR_D (1 << 5) /* 32-bit data address range */
  125. #define CR_L (1 << 6) /* Implementation defined */
  126. #define CR_B (1 << 7) /* Big endian */
  127. #define CR_S (1 << 8) /* System MMU protection */
  128. #define CR_R (1 << 9) /* ROM MMU protection */
  129. #define CR_F (1 << 10) /* Implementation defined */
  130. #define CR_Z (1 << 11) /* Implementation defined */
  131. #define CR_I (1 << 12) /* Icache enable */
  132. #define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
  133. #define CR_RR (1 << 14) /* Round Robin cache replacement */
  134. #define CR_L4 (1 << 15) /* LDR pc can set T bit */
  135. #define CR_DT (1 << 16)
  136. #define CR_IT (1 << 18)
  137. #define CR_ST (1 << 19)
  138. #define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */
  139. #define CR_U (1 << 22) /* Unaligned access operation */
  140. #define CR_XP (1 << 23) /* Extended page tables */
  141. #define CR_VE (1 << 24) /* Vectored interrupts */
  142. #define CR_EE (1 << 25) /* Exception (Big) Endian */
  143. #define CR_TRE (1 << 28) /* TEX remap enable */
  144. #define CR_AFE (1 << 29) /* Access flag enable */
  145. #define CR_TE (1 << 30) /* Thumb exception enable */
  146. #ifndef PGTABLE_SIZE
  147. #define PGTABLE_SIZE (4096 * 4)
  148. #endif
  149. /*
  150. * This is used to ensure the compiler did actually allocate the register we
  151. * asked it for some inline assembly sequences. Apparently we can't trust
  152. * the compiler from one version to another so a bit of paranoia won't hurt.
  153. * This string is meant to be concatenated with the inline asm string and
  154. * will cause compilation to stop on mismatch.
  155. * (for details, see gcc PR 15089)
  156. */
  157. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  158. #ifndef __ASSEMBLY__
  159. /**
  160. * save_boot_params() - Save boot parameters before starting reset sequence
  161. *
  162. * If you provide this function it will be called immediately U-Boot starts,
  163. * both for SPL and U-Boot proper.
  164. *
  165. * All registers are unchanged from U-Boot entry. No registers need be
  166. * preserved.
  167. *
  168. * This is not a normal C function. There is no stack. Return by branching to
  169. * save_boot_params_ret.
  170. *
  171. * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3);
  172. */
  173. /**
  174. * save_boot_params_ret() - Return from save_boot_params()
  175. *
  176. * If you provide save_boot_params(), then you should jump back to this
  177. * function when done. Try to preserve all registers.
  178. *
  179. * If your implementation of save_boot_params() is in C then it is acceptable
  180. * to simply call save_boot_params_ret() at the end of your function. Since
  181. * there is no link register set up, you cannot just exit the function. U-Boot
  182. * will return to the (initialised) value of lr, and likely crash/hang.
  183. *
  184. * If your implementation of save_boot_params() is in assembler then you
  185. * should use 'b' or 'bx' to return to save_boot_params_ret.
  186. */
  187. void save_boot_params_ret(void);
  188. #define isb() __asm__ __volatile__ ("" : : : "memory")
  189. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  190. #ifdef __ARM_ARCH_7A__
  191. #define wfi() __asm__ __volatile__ ("wfi" : : : "memory")
  192. #else
  193. #define wfi()
  194. #endif
  195. static inline unsigned int get_cr(void)
  196. {
  197. unsigned int val;
  198. asm volatile("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
  199. return val;
  200. }
  201. static inline void set_cr(unsigned int val)
  202. {
  203. asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
  204. : : "r" (val) : "cc");
  205. isb();
  206. }
  207. static inline unsigned int get_dacr(void)
  208. {
  209. unsigned int val;
  210. asm("mrc p15, 0, %0, c3, c0, 0 @ get DACR" : "=r" (val) : : "cc");
  211. return val;
  212. }
  213. static inline void set_dacr(unsigned int val)
  214. {
  215. asm volatile("mcr p15, 0, %0, c3, c0, 0 @ set DACR"
  216. : : "r" (val) : "cc");
  217. isb();
  218. }
  219. #ifdef CONFIG_CPU_V7
  220. /* Short-Descriptor Translation Table Level 1 Bits */
  221. #define TTB_SECT_NS_MASK (1 << 19)
  222. #define TTB_SECT_NG_MASK (1 << 17)
  223. #define TTB_SECT_S_MASK (1 << 16)
  224. /* Note: TTB AP bits are set elsewhere */
  225. #define TTB_SECT_TEX(x) ((x & 0x7) << 12)
  226. #define TTB_SECT_DOMAIN(x) ((x & 0xf) << 5)
  227. #define TTB_SECT_XN_MASK (1 << 4)
  228. #define TTB_SECT_C_MASK (1 << 3)
  229. #define TTB_SECT_B_MASK (1 << 2)
  230. #define TTB_SECT (2 << 0)
  231. /* options available for data cache on each page */
  232. enum dcache_option {
  233. DCACHE_OFF = TTB_SECT_DOMAIN(0) | TTB_SECT_XN_MASK | TTB_SECT,
  234. DCACHE_WRITETHROUGH = DCACHE_OFF | TTB_SECT_C_MASK,
  235. DCACHE_WRITEBACK = DCACHE_WRITETHROUGH | TTB_SECT_B_MASK,
  236. DCACHE_WRITEALLOC = DCACHE_WRITEBACK | TTB_SECT_TEX(1),
  237. };
  238. #else
  239. /* options available for data cache on each page */
  240. enum dcache_option {
  241. DCACHE_OFF = 0x12,
  242. DCACHE_WRITETHROUGH = 0x1a,
  243. DCACHE_WRITEBACK = 0x1e,
  244. DCACHE_WRITEALLOC = 0x16,
  245. };
  246. #endif
  247. /* Size of an MMU section */
  248. enum {
  249. MMU_SECTION_SHIFT = 20,
  250. MMU_SECTION_SIZE = 1 << MMU_SECTION_SHIFT,
  251. };
  252. #ifdef CONFIG_CPU_V7
  253. /* TTBR0 bits */
  254. #define TTBR0_BASE_ADDR_MASK 0xFFFFC000
  255. #define TTBR0_RGN_NC (0 << 3)
  256. #define TTBR0_RGN_WBWA (1 << 3)
  257. #define TTBR0_RGN_WT (2 << 3)
  258. #define TTBR0_RGN_WB (3 << 3)
  259. /* TTBR0[6] is IRGN[0] and TTBR[0] is IRGN[1] */
  260. #define TTBR0_IRGN_NC (0 << 0 | 0 << 6)
  261. #define TTBR0_IRGN_WBWA (0 << 0 | 1 << 6)
  262. #define TTBR0_IRGN_WT (1 << 0 | 0 << 6)
  263. #define TTBR0_IRGN_WB (1 << 0 | 1 << 6)
  264. #endif
  265. /**
  266. * Register an update to the page tables, and flush the TLB
  267. *
  268. * \param start start address of update in page table
  269. * \param stop stop address of update in page table
  270. */
  271. void mmu_page_table_flush(unsigned long start, unsigned long stop);
  272. #endif /* __ASSEMBLY__ */
  273. #define arch_align_stack(x) (x)
  274. #endif /* __KERNEL__ */
  275. #endif /* CONFIG_ARM64 */
  276. #ifndef __ASSEMBLY__
  277. /**
  278. * Change the cache settings for a region.
  279. *
  280. * \param start start address of memory region to change
  281. * \param size size of memory region to change
  282. * \param option dcache option to select
  283. */
  284. void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
  285. enum dcache_option option);
  286. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  287. void noncached_init(void);
  288. phys_addr_t noncached_alloc(size_t size, size_t align);
  289. #endif /* CONFIG_SYS_NONCACHED_MEMORY */
  290. #endif /* __ASSEMBLY__ */
  291. #endif