system.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. #ifndef __ASM_ARM_SYSTEM_H
  2. #define __ASM_ARM_SYSTEM_H
  3. #include <common.h>
  4. #include <linux/compiler.h>
  5. #include <asm/barriers.h>
  6. #ifdef CONFIG_ARM64
  7. /*
  8. * SCTLR_EL1/SCTLR_EL2/SCTLR_EL3 bits definitions
  9. */
  10. #define CR_M (1 << 0) /* MMU enable */
  11. #define CR_A (1 << 1) /* Alignment abort enable */
  12. #define CR_C (1 << 2) /* Dcache enable */
  13. #define CR_SA (1 << 3) /* Stack Alignment Check Enable */
  14. #define CR_I (1 << 12) /* Icache enable */
  15. #define CR_WXN (1 << 19) /* Write Permision Imply XN */
  16. #define CR_EE (1 << 25) /* Exception (Big) Endian */
  17. #define ES_TO_AARCH64 1
  18. #define ES_TO_AARCH32 0
  19. /*
  20. * SCR_EL3 bits definitions
  21. */
  22. #define SCR_EL3_RW_AARCH64 (1 << 10) /* Next lower level is AArch64 */
  23. #define SCR_EL3_RW_AARCH32 (0 << 10) /* Lower lowers level are AArch32 */
  24. #define SCR_EL3_HCE_EN (1 << 8) /* Hypervisor Call enable */
  25. #define SCR_EL3_SMD_DIS (1 << 7) /* Secure Monitor Call disable */
  26. #define SCR_EL3_RES1 (3 << 4) /* Reserved, RES1 */
  27. #define SCR_EL3_NS_EN (1 << 0) /* EL0 and EL1 in Non-scure state */
  28. /*
  29. * SPSR_EL3/SPSR_EL2 bits definitions
  30. */
  31. #define SPSR_EL_END_LE (0 << 9) /* Exception Little-endian */
  32. #define SPSR_EL_DEBUG_MASK (1 << 9) /* Debug exception masked */
  33. #define SPSR_EL_ASYN_MASK (1 << 8) /* Asynchronous data abort masked */
  34. #define SPSR_EL_SERR_MASK (1 << 8) /* System Error exception masked */
  35. #define SPSR_EL_IRQ_MASK (1 << 7) /* IRQ exception masked */
  36. #define SPSR_EL_FIQ_MASK (1 << 6) /* FIQ exception masked */
  37. #define SPSR_EL_T_A32 (0 << 5) /* AArch32 instruction set A32 */
  38. #define SPSR_EL_M_AARCH64 (0 << 4) /* Exception taken from AArch64 */
  39. #define SPSR_EL_M_AARCH32 (1 << 4) /* Exception taken from AArch32 */
  40. #define SPSR_EL_M_SVC (0x3) /* Exception taken from SVC mode */
  41. #define SPSR_EL_M_HYP (0xa) /* Exception taken from HYP mode */
  42. #define SPSR_EL_M_EL1H (5) /* Exception taken from EL1h mode */
  43. #define SPSR_EL_M_EL2H (9) /* Exception taken from EL2h mode */
  44. /*
  45. * CPTR_EL2 bits definitions
  46. */
  47. #define CPTR_EL2_RES1 (3 << 12 | 0x3ff) /* Reserved, RES1 */
  48. /*
  49. * SCTLR_EL2 bits definitions
  50. */
  51. #define SCTLR_EL2_RES1 (3 << 28 | 3 << 22 | 1 << 18 | 1 << 16 |\
  52. 1 << 11 | 3 << 4) /* Reserved, RES1 */
  53. #define SCTLR_EL2_EE_LE (0 << 25) /* Exception Little-endian */
  54. #define SCTLR_EL2_WXN_DIS (0 << 19) /* Write permission is not XN */
  55. #define SCTLR_EL2_ICACHE_DIS (0 << 12) /* Instruction cache disabled */
  56. #define SCTLR_EL2_SA_DIS (0 << 3) /* Stack Alignment Check disabled */
  57. #define SCTLR_EL2_DCACHE_DIS (0 << 2) /* Data cache disabled */
  58. #define SCTLR_EL2_ALIGN_DIS (0 << 1) /* Alignment check disabled */
  59. #define SCTLR_EL2_MMU_DIS (0) /* MMU disabled */
  60. /*
  61. * CNTHCTL_EL2 bits definitions
  62. */
  63. #define CNTHCTL_EL2_EL1PCEN_EN (1 << 1) /* Physical timer regs accessible */
  64. #define CNTHCTL_EL2_EL1PCTEN_EN (1 << 0) /* Physical counter accessible */
  65. /*
  66. * HCR_EL2 bits definitions
  67. */
  68. #define HCR_EL2_RW_AARCH64 (1 << 31) /* EL1 is AArch64 */
  69. #define HCR_EL2_RW_AARCH32 (0 << 31) /* Lower levels are AArch32 */
  70. #define HCR_EL2_HCD_DIS (1 << 29) /* Hypervisor Call disabled */
  71. /*
  72. * CPACR_EL1 bits definitions
  73. */
  74. #define CPACR_EL1_FPEN_EN (3 << 20) /* SIMD and FP instruction enabled */
  75. /*
  76. * SCTLR_EL1 bits definitions
  77. */
  78. #define SCTLR_EL1_RES1 (3 << 28 | 3 << 22 | 1 << 20 |\
  79. 1 << 11) /* Reserved, RES1 */
  80. #define SCTLR_EL1_UCI_DIS (0 << 26) /* Cache instruction disabled */
  81. #define SCTLR_EL1_EE_LE (0 << 25) /* Exception Little-endian */
  82. #define SCTLR_EL1_WXN_DIS (0 << 19) /* Write permission is not XN */
  83. #define SCTLR_EL1_NTWE_DIS (0 << 18) /* WFE instruction disabled */
  84. #define SCTLR_EL1_NTWI_DIS (0 << 16) /* WFI instruction disabled */
  85. #define SCTLR_EL1_UCT_DIS (0 << 15) /* CTR_EL0 access disabled */
  86. #define SCTLR_EL1_DZE_DIS (0 << 14) /* DC ZVA instruction disabled */
  87. #define SCTLR_EL1_ICACHE_DIS (0 << 12) /* Instruction cache disabled */
  88. #define SCTLR_EL1_UMA_DIS (0 << 9) /* User Mask Access disabled */
  89. #define SCTLR_EL1_SED_EN (0 << 8) /* SETEND instruction enabled */
  90. #define SCTLR_EL1_ITD_EN (0 << 7) /* IT instruction enabled */
  91. #define SCTLR_EL1_CP15BEN_DIS (0 << 5) /* CP15 barrier operation disabled */
  92. #define SCTLR_EL1_SA0_DIS (0 << 4) /* Stack Alignment EL0 disabled */
  93. #define SCTLR_EL1_SA_DIS (0 << 3) /* Stack Alignment EL1 disabled */
  94. #define SCTLR_EL1_DCACHE_DIS (0 << 2) /* Data cache disabled */
  95. #define SCTLR_EL1_ALIGN_DIS (0 << 1) /* Alignment check disabled */
  96. #define SCTLR_EL1_MMU_DIS (0) /* MMU disabled */
  97. #ifndef __ASSEMBLY__
  98. u64 get_page_table_size(void);
  99. #define PGTABLE_SIZE get_page_table_size()
  100. /* 2MB granularity */
  101. #define MMU_SECTION_SHIFT 21
  102. #define MMU_SECTION_SIZE (1 << MMU_SECTION_SHIFT)
  103. /* These constants need to be synced to the MT_ types in asm/armv8/mmu.h */
  104. enum dcache_option {
  105. DCACHE_OFF = 0 << 2,
  106. DCACHE_WRITETHROUGH = 3 << 2,
  107. DCACHE_WRITEBACK = 4 << 2,
  108. DCACHE_WRITEALLOC = 4 << 2,
  109. };
  110. #define wfi() \
  111. ({asm volatile( \
  112. "wfi" : : : "memory"); \
  113. })
  114. static inline unsigned int current_el(void)
  115. {
  116. unsigned int el;
  117. asm volatile("mrs %0, CurrentEL" : "=r" (el) : : "cc");
  118. return el >> 2;
  119. }
  120. static inline unsigned int get_sctlr(void)
  121. {
  122. unsigned int el, val;
  123. el = current_el();
  124. if (el == 1)
  125. asm volatile("mrs %0, sctlr_el1" : "=r" (val) : : "cc");
  126. else if (el == 2)
  127. asm volatile("mrs %0, sctlr_el2" : "=r" (val) : : "cc");
  128. else
  129. asm volatile("mrs %0, sctlr_el3" : "=r" (val) : : "cc");
  130. return val;
  131. }
  132. static inline void set_sctlr(unsigned int val)
  133. {
  134. unsigned int el;
  135. el = current_el();
  136. if (el == 1)
  137. asm volatile("msr sctlr_el1, %0" : : "r" (val) : "cc");
  138. else if (el == 2)
  139. asm volatile("msr sctlr_el2, %0" : : "r" (val) : "cc");
  140. else
  141. asm volatile("msr sctlr_el3, %0" : : "r" (val) : "cc");
  142. asm volatile("isb");
  143. }
  144. static inline unsigned long read_mpidr(void)
  145. {
  146. unsigned long val;
  147. asm volatile("mrs %0, mpidr_el1" : "=r" (val));
  148. return val;
  149. }
  150. #define BSP_COREID 0
  151. void __asm_flush_dcache_all(void);
  152. void __asm_invalidate_dcache_all(void);
  153. void __asm_flush_dcache_range(u64 start, u64 end);
  154. /**
  155. * __asm_invalidate_dcache_range() - Invalidate a range of virtual addresses
  156. *
  157. * This performance an invalidate from @start to @end - 1. Both addresses
  158. * should be cache-aligned, otherwise this function will align the start
  159. * address and may continue past the end address.
  160. *
  161. * Data in the address range is evicted from the cache and is not written back
  162. * to memory.
  163. *
  164. * @start: Start address to invalidate
  165. * @end: End address to invalidate up to (exclusive)
  166. */
  167. void __asm_invalidate_dcache_range(u64 start, u64 end);
  168. void __asm_invalidate_tlb_all(void);
  169. void __asm_invalidate_icache_all(void);
  170. int __asm_invalidate_l3_dcache(void);
  171. int __asm_flush_l3_dcache(void);
  172. int __asm_invalidate_l3_icache(void);
  173. void __asm_switch_ttbr(u64 new_ttbr);
  174. /*
  175. * Switch from EL3 to EL2 for ARMv8
  176. *
  177. * @args: For loading 64-bit OS, fdt address.
  178. * For loading 32-bit OS, zero.
  179. * @mach_nr: For loading 64-bit OS, zero.
  180. * For loading 32-bit OS, machine nr
  181. * @fdt_addr: For loading 64-bit OS, zero.
  182. * For loading 32-bit OS, fdt address.
  183. * @arg4: Input argument.
  184. * @entry_point: kernel entry point
  185. * @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32
  186. */
  187. void __noreturn armv8_switch_to_el2(u64 args, u64 mach_nr, u64 fdt_addr,
  188. u64 arg4, u64 entry_point, u64 es_flag);
  189. /*
  190. * Switch from EL2 to EL1 for ARMv8
  191. *
  192. * @args: For loading 64-bit OS, fdt address.
  193. * For loading 32-bit OS, zero.
  194. * @mach_nr: For loading 64-bit OS, zero.
  195. * For loading 32-bit OS, machine nr
  196. * @fdt_addr: For loading 64-bit OS, zero.
  197. * For loading 32-bit OS, fdt address.
  198. * @arg4: Input argument.
  199. * @entry_point: kernel entry point
  200. * @es_flag: execution state flag, ES_TO_AARCH64 or ES_TO_AARCH32
  201. */
  202. void armv8_switch_to_el1(u64 args, u64 mach_nr, u64 fdt_addr,
  203. u64 arg4, u64 entry_point, u64 es_flag);
  204. void armv8_el2_to_aarch32(u64 args, u64 mach_nr, u64 fdt_addr,
  205. u64 arg4, u64 entry_point);
  206. void gic_init(void);
  207. void gic_send_sgi(unsigned long sgino);
  208. void wait_for_wakeup(void);
  209. void protect_secure_region(void);
  210. void smp_kick_all_cpus(void);
  211. void flush_l3_cache(void);
  212. void mmu_change_region_attr(phys_addr_t start, size_t size, u64 attrs);
  213. /*
  214. *Issue a secure monitor call in accordance with ARM "SMC Calling convention",
  215. * DEN0028A
  216. *
  217. * @args: input and output arguments
  218. *
  219. */
  220. void smc_call(struct pt_regs *args);
  221. void __noreturn psci_system_reset(void);
  222. void __noreturn psci_system_off(void);
  223. #ifdef CONFIG_ARMV8_PSCI
  224. extern char __secure_start[];
  225. extern char __secure_end[];
  226. extern char __secure_stack_start[];
  227. extern char __secure_stack_end[];
  228. void armv8_setup_psci(void);
  229. void psci_setup_vectors(void);
  230. void psci_arch_init(void);
  231. #endif
  232. #endif /* __ASSEMBLY__ */
  233. #else /* CONFIG_ARM64 */
  234. #ifdef __KERNEL__
  235. #define CPU_ARCH_UNKNOWN 0
  236. #define CPU_ARCH_ARMv3 1
  237. #define CPU_ARCH_ARMv4 2
  238. #define CPU_ARCH_ARMv4T 3
  239. #define CPU_ARCH_ARMv5 4
  240. #define CPU_ARCH_ARMv5T 5
  241. #define CPU_ARCH_ARMv5TE 6
  242. #define CPU_ARCH_ARMv5TEJ 7
  243. #define CPU_ARCH_ARMv6 8
  244. #define CPU_ARCH_ARMv7 9
  245. /*
  246. * CR1 bits (CP#15 CR1)
  247. */
  248. #define CR_M (1 << 0) /* MMU enable */
  249. #define CR_A (1 << 1) /* Alignment abort enable */
  250. #define CR_C (1 << 2) /* Dcache enable */
  251. #define CR_W (1 << 3) /* Write buffer enable */
  252. #define CR_P (1 << 4) /* 32-bit exception handler */
  253. #define CR_D (1 << 5) /* 32-bit data address range */
  254. #define CR_L (1 << 6) /* Implementation defined */
  255. #define CR_B (1 << 7) /* Big endian */
  256. #define CR_S (1 << 8) /* System MMU protection */
  257. #define CR_R (1 << 9) /* ROM MMU protection */
  258. #define CR_F (1 << 10) /* Implementation defined */
  259. #define CR_Z (1 << 11) /* Implementation defined */
  260. #define CR_I (1 << 12) /* Icache enable */
  261. #define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
  262. #define CR_RR (1 << 14) /* Round Robin cache replacement */
  263. #define CR_L4 (1 << 15) /* LDR pc can set T bit */
  264. #define CR_DT (1 << 16)
  265. #define CR_IT (1 << 18)
  266. #define CR_ST (1 << 19)
  267. #define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */
  268. #define CR_U (1 << 22) /* Unaligned access operation */
  269. #define CR_XP (1 << 23) /* Extended page tables */
  270. #define CR_VE (1 << 24) /* Vectored interrupts */
  271. #define CR_EE (1 << 25) /* Exception (Big) Endian */
  272. #define CR_TRE (1 << 28) /* TEX remap enable */
  273. #define CR_AFE (1 << 29) /* Access flag enable */
  274. #define CR_TE (1 << 30) /* Thumb exception enable */
  275. #if defined(CONFIG_ARMV7_LPAE) && !defined(PGTABLE_SIZE)
  276. #define PGTABLE_SIZE (4096 * 5)
  277. #elif !defined(PGTABLE_SIZE)
  278. #define PGTABLE_SIZE (4096 * 4)
  279. #endif
  280. /*
  281. * This is used to ensure the compiler did actually allocate the register we
  282. * asked it for some inline assembly sequences. Apparently we can't trust
  283. * the compiler from one version to another so a bit of paranoia won't hurt.
  284. * This string is meant to be concatenated with the inline asm string and
  285. * will cause compilation to stop on mismatch.
  286. * (for details, see gcc PR 15089)
  287. */
  288. #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
  289. #ifndef __ASSEMBLY__
  290. /**
  291. * save_boot_params() - Save boot parameters before starting reset sequence
  292. *
  293. * If you provide this function it will be called immediately U-Boot starts,
  294. * both for SPL and U-Boot proper.
  295. *
  296. * All registers are unchanged from U-Boot entry. No registers need be
  297. * preserved.
  298. *
  299. * This is not a normal C function. There is no stack. Return by branching to
  300. * save_boot_params_ret.
  301. *
  302. * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3);
  303. */
  304. /**
  305. * save_boot_params_ret() - Return from save_boot_params()
  306. *
  307. * If you provide save_boot_params(), then you should jump back to this
  308. * function when done. Try to preserve all registers.
  309. *
  310. * If your implementation of save_boot_params() is in C then it is acceptable
  311. * to simply call save_boot_params_ret() at the end of your function. Since
  312. * there is no link register set up, you cannot just exit the function. U-Boot
  313. * will return to the (initialised) value of lr, and likely crash/hang.
  314. *
  315. * If your implementation of save_boot_params() is in assembler then you
  316. * should use 'b' or 'bx' to return to save_boot_params_ret.
  317. */
  318. void save_boot_params_ret(void);
  319. #ifdef CONFIG_ARMV7_LPAE
  320. void switch_to_hypervisor_ret(void);
  321. #endif
  322. #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
  323. #ifdef __ARM_ARCH_7A__
  324. #define wfi() __asm__ __volatile__ ("wfi" : : : "memory")
  325. #else
  326. #define wfi()
  327. #endif
  328. static inline unsigned long get_cpsr(void)
  329. {
  330. unsigned long cpsr;
  331. asm volatile("mrs %0, cpsr" : "=r"(cpsr): );
  332. return cpsr;
  333. }
  334. static inline int is_hyp(void)
  335. {
  336. #ifdef CONFIG_ARMV7_LPAE
  337. /* HYP mode requires LPAE ... */
  338. return ((get_cpsr() & 0x1f) == 0x1a);
  339. #else
  340. /* ... so without LPAE support we can optimize all hyp code away */
  341. return 0;
  342. #endif
  343. }
  344. static inline unsigned int get_cr(void)
  345. {
  346. unsigned int val;
  347. if (is_hyp())
  348. asm volatile("mrc p15, 4, %0, c1, c0, 0 @ get CR" : "=r" (val)
  349. :
  350. : "cc");
  351. else
  352. asm volatile("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val)
  353. :
  354. : "cc");
  355. return val;
  356. }
  357. static inline void set_cr(unsigned int val)
  358. {
  359. if (is_hyp())
  360. asm volatile("mcr p15, 4, %0, c1, c0, 0 @ set CR" :
  361. : "r" (val)
  362. : "cc");
  363. else
  364. asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR" :
  365. : "r" (val)
  366. : "cc");
  367. isb();
  368. }
  369. static inline unsigned int get_dacr(void)
  370. {
  371. unsigned int val;
  372. asm("mrc p15, 0, %0, c3, c0, 0 @ get DACR" : "=r" (val) : : "cc");
  373. return val;
  374. }
  375. static inline void set_dacr(unsigned int val)
  376. {
  377. asm volatile("mcr p15, 0, %0, c3, c0, 0 @ set DACR"
  378. : : "r" (val) : "cc");
  379. isb();
  380. }
  381. #ifdef CONFIG_ARMV7_LPAE
  382. /* Long-Descriptor Translation Table Level 1/2 Bits */
  383. #define TTB_SECT_XN_MASK (1ULL << 54)
  384. #define TTB_SECT_NG_MASK (1 << 11)
  385. #define TTB_SECT_AF (1 << 10)
  386. #define TTB_SECT_SH_MASK (3 << 8)
  387. #define TTB_SECT_NS_MASK (1 << 5)
  388. #define TTB_SECT_AP (1 << 6)
  389. /* Note: TTB AP bits are set elsewhere */
  390. #define TTB_SECT_MAIR(x) ((x & 0x7) << 2) /* Index into MAIR */
  391. #define TTB_SECT (1 << 0)
  392. #define TTB_PAGETABLE (3 << 0)
  393. /* TTBCR flags */
  394. #define TTBCR_EAE (1 << 31)
  395. #define TTBCR_T0SZ(x) ((x) << 0)
  396. #define TTBCR_T1SZ(x) ((x) << 16)
  397. #define TTBCR_USING_TTBR0 (TTBCR_T0SZ(0) | TTBCR_T1SZ(0))
  398. #define TTBCR_IRGN0_NC (0 << 8)
  399. #define TTBCR_IRGN0_WBWA (1 << 8)
  400. #define TTBCR_IRGN0_WT (2 << 8)
  401. #define TTBCR_IRGN0_WBNWA (3 << 8)
  402. #define TTBCR_IRGN0_MASK (3 << 8)
  403. #define TTBCR_ORGN0_NC (0 << 10)
  404. #define TTBCR_ORGN0_WBWA (1 << 10)
  405. #define TTBCR_ORGN0_WT (2 << 10)
  406. #define TTBCR_ORGN0_WBNWA (3 << 10)
  407. #define TTBCR_ORGN0_MASK (3 << 10)
  408. #define TTBCR_SHARED_NON (0 << 12)
  409. #define TTBCR_SHARED_OUTER (2 << 12)
  410. #define TTBCR_SHARED_INNER (3 << 12)
  411. #define TTBCR_EPD0 (0 << 7)
  412. /*
  413. * Memory types
  414. */
  415. #define MEMORY_ATTRIBUTES ((0x00 << (0 * 8)) | (0x88 << (1 * 8)) | \
  416. (0xcc << (2 * 8)) | (0xff << (3 * 8)))
  417. /* options available for data cache on each page */
  418. enum dcache_option {
  419. DCACHE_OFF = TTB_SECT | TTB_SECT_MAIR(0) | TTB_SECT_XN_MASK,
  420. DCACHE_WRITETHROUGH = TTB_SECT | TTB_SECT_MAIR(1),
  421. DCACHE_WRITEBACK = TTB_SECT | TTB_SECT_MAIR(2),
  422. DCACHE_WRITEALLOC = TTB_SECT | TTB_SECT_MAIR(3),
  423. };
  424. #elif defined(CONFIG_CPU_V7)
  425. /* Short-Descriptor Translation Table Level 1 Bits */
  426. #define TTB_SECT_NS_MASK (1 << 19)
  427. #define TTB_SECT_NG_MASK (1 << 17)
  428. #define TTB_SECT_S_MASK (1 << 16)
  429. /* Note: TTB AP bits are set elsewhere */
  430. #define TTB_SECT_AP (3 << 10)
  431. #define TTB_SECT_TEX(x) ((x & 0x7) << 12)
  432. #define TTB_SECT_DOMAIN(x) ((x & 0xf) << 5)
  433. #define TTB_SECT_XN_MASK (1 << 4)
  434. #define TTB_SECT_C_MASK (1 << 3)
  435. #define TTB_SECT_B_MASK (1 << 2)
  436. #define TTB_SECT (2 << 0)
  437. /* options available for data cache on each page */
  438. enum dcache_option {
  439. DCACHE_OFF = TTB_SECT_DOMAIN(0) | TTB_SECT_XN_MASK | TTB_SECT,
  440. DCACHE_WRITETHROUGH = DCACHE_OFF | TTB_SECT_C_MASK,
  441. DCACHE_WRITEBACK = DCACHE_WRITETHROUGH | TTB_SECT_B_MASK,
  442. DCACHE_WRITEALLOC = DCACHE_WRITEBACK | TTB_SECT_TEX(1),
  443. };
  444. #else
  445. #define TTB_SECT_AP (3 << 10)
  446. /* options available for data cache on each page */
  447. enum dcache_option {
  448. DCACHE_OFF = 0x12,
  449. DCACHE_WRITETHROUGH = 0x1a,
  450. DCACHE_WRITEBACK = 0x1e,
  451. DCACHE_WRITEALLOC = 0x16,
  452. };
  453. #endif
  454. /* Size of an MMU section */
  455. enum {
  456. #ifdef CONFIG_ARMV7_LPAE
  457. MMU_SECTION_SHIFT = 21, /* 2MB */
  458. #else
  459. MMU_SECTION_SHIFT = 20, /* 1MB */
  460. #endif
  461. MMU_SECTION_SIZE = 1 << MMU_SECTION_SHIFT,
  462. };
  463. #ifdef CONFIG_CPU_V7
  464. /* TTBR0 bits */
  465. #define TTBR0_BASE_ADDR_MASK 0xFFFFC000
  466. #define TTBR0_RGN_NC (0 << 3)
  467. #define TTBR0_RGN_WBWA (1 << 3)
  468. #define TTBR0_RGN_WT (2 << 3)
  469. #define TTBR0_RGN_WB (3 << 3)
  470. /* TTBR0[6] is IRGN[0] and TTBR[0] is IRGN[1] */
  471. #define TTBR0_IRGN_NC (0 << 0 | 0 << 6)
  472. #define TTBR0_IRGN_WBWA (0 << 0 | 1 << 6)
  473. #define TTBR0_IRGN_WT (1 << 0 | 0 << 6)
  474. #define TTBR0_IRGN_WB (1 << 0 | 1 << 6)
  475. #endif
  476. /**
  477. * Register an update to the page tables, and flush the TLB
  478. *
  479. * \param start start address of update in page table
  480. * \param stop stop address of update in page table
  481. */
  482. void mmu_page_table_flush(unsigned long start, unsigned long stop);
  483. #endif /* __ASSEMBLY__ */
  484. #define arch_align_stack(x) (x)
  485. #endif /* __KERNEL__ */
  486. #endif /* CONFIG_ARM64 */
  487. #ifndef __ASSEMBLY__
  488. /**
  489. * Change the cache settings for a region.
  490. *
  491. * \param start start address of memory region to change
  492. * \param size size of memory region to change
  493. * \param option dcache option to select
  494. */
  495. void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
  496. enum dcache_option option);
  497. #ifdef CONFIG_SYS_NONCACHED_MEMORY
  498. void noncached_init(void);
  499. phys_addr_t noncached_alloc(size_t size, size_t align);
  500. #endif /* CONFIG_SYS_NONCACHED_MEMORY */
  501. #endif /* __ASSEMBLY__ */
  502. #endif