xref: /openbmc/u-boot/arch/arm/include/asm/system.h (revision a78cd8613204188991c192b8dae2de0aae3b1722)
1819833afSPeter Tyser #ifndef __ASM_ARM_SYSTEM_H
2819833afSPeter Tyser #define __ASM_ARM_SYSTEM_H
3819833afSPeter Tyser 
4a5b9fa30SSergey Temerkhanov #include <common.h>
5a5b9fa30SSergey Temerkhanov #include <linux/compiler.h>
6*a78cd861STom Rini #include <asm/barriers.h>
7a5b9fa30SSergey Temerkhanov 
80ae76531SDavid Feng #ifdef CONFIG_ARM64
90ae76531SDavid Feng 
100ae76531SDavid Feng /*
110ae76531SDavid Feng  * SCTLR_EL1/SCTLR_EL2/SCTLR_EL3 bits definitions
120ae76531SDavid Feng  */
130ae76531SDavid Feng #define CR_M		(1 << 0)	/* MMU enable			*/
140ae76531SDavid Feng #define CR_A		(1 << 1)	/* Alignment abort enable	*/
150ae76531SDavid Feng #define CR_C		(1 << 2)	/* Dcache enable		*/
160ae76531SDavid Feng #define CR_SA		(1 << 3)	/* Stack Alignment Check Enable	*/
170ae76531SDavid Feng #define CR_I		(1 << 12)	/* Icache enable		*/
180ae76531SDavid Feng #define CR_WXN		(1 << 19)	/* Write Permision Imply XN	*/
190ae76531SDavid Feng #define CR_EE		(1 << 25)	/* Exception (Big) Endian	*/
200ae76531SDavid Feng 
217985cdf7SAlexander Graf #ifndef __ASSEMBLY__
227985cdf7SAlexander Graf 
237985cdf7SAlexander Graf u64 get_page_table_size(void);
247985cdf7SAlexander Graf #define PGTABLE_SIZE	get_page_table_size()
257985cdf7SAlexander Graf 
26dad17fd5SSiva Durga Prasad Paladugu /* 2MB granularity */
27dad17fd5SSiva Durga Prasad Paladugu #define MMU_SECTION_SHIFT	21
2888f965d7SStephen Warren #define MMU_SECTION_SIZE	(1 << MMU_SECTION_SHIFT)
290ae76531SDavid Feng 
3053eb45efSAlexander Graf /* These constants need to be synced to the MT_ types in asm/armv8/mmu.h */
31dad17fd5SSiva Durga Prasad Paladugu enum dcache_option {
3253eb45efSAlexander Graf 	DCACHE_OFF = 0 << 2,
3353eb45efSAlexander Graf 	DCACHE_WRITETHROUGH = 3 << 2,
3453eb45efSAlexander Graf 	DCACHE_WRITEBACK = 4 << 2,
3553eb45efSAlexander Graf 	DCACHE_WRITEALLOC = 4 << 2,
36dad17fd5SSiva Durga Prasad Paladugu };
37dad17fd5SSiva Durga Prasad Paladugu 
380ae76531SDavid Feng #define wfi()				\
390ae76531SDavid Feng 	({asm volatile(			\
400ae76531SDavid Feng 	"wfi" : : : "memory");		\
410ae76531SDavid Feng 	})
420ae76531SDavid Feng 
430ae76531SDavid Feng static inline unsigned int current_el(void)
440ae76531SDavid Feng {
450ae76531SDavid Feng 	unsigned int el;
460ae76531SDavid Feng 	asm volatile("mrs %0, CurrentEL" : "=r" (el) : : "cc");
470ae76531SDavid Feng 	return el >> 2;
480ae76531SDavid Feng }
490ae76531SDavid Feng 
500ae76531SDavid Feng static inline unsigned int get_sctlr(void)
510ae76531SDavid Feng {
520ae76531SDavid Feng 	unsigned int el, val;
530ae76531SDavid Feng 
540ae76531SDavid Feng 	el = current_el();
550ae76531SDavid Feng 	if (el == 1)
560ae76531SDavid Feng 		asm volatile("mrs %0, sctlr_el1" : "=r" (val) : : "cc");
570ae76531SDavid Feng 	else if (el == 2)
580ae76531SDavid Feng 		asm volatile("mrs %0, sctlr_el2" : "=r" (val) : : "cc");
590ae76531SDavid Feng 	else
600ae76531SDavid Feng 		asm volatile("mrs %0, sctlr_el3" : "=r" (val) : : "cc");
610ae76531SDavid Feng 
620ae76531SDavid Feng 	return val;
630ae76531SDavid Feng }
640ae76531SDavid Feng 
650ae76531SDavid Feng static inline void set_sctlr(unsigned int val)
660ae76531SDavid Feng {
670ae76531SDavid Feng 	unsigned int el;
680ae76531SDavid Feng 
690ae76531SDavid Feng 	el = current_el();
700ae76531SDavid Feng 	if (el == 1)
710ae76531SDavid Feng 		asm volatile("msr sctlr_el1, %0" : : "r" (val) : "cc");
720ae76531SDavid Feng 	else if (el == 2)
730ae76531SDavid Feng 		asm volatile("msr sctlr_el2, %0" : : "r" (val) : "cc");
740ae76531SDavid Feng 	else
750ae76531SDavid Feng 		asm volatile("msr sctlr_el3, %0" : : "r" (val) : "cc");
760ae76531SDavid Feng 
770ae76531SDavid Feng 	asm volatile("isb");
780ae76531SDavid Feng }
790ae76531SDavid Feng 
80ba5648cdSSergey Temerkhanov static inline unsigned long read_mpidr(void)
81ba5648cdSSergey Temerkhanov {
82ba5648cdSSergey Temerkhanov 	unsigned long val;
83ba5648cdSSergey Temerkhanov 
84ba5648cdSSergey Temerkhanov 	asm volatile("mrs %0, mpidr_el1" : "=r" (val));
85ba5648cdSSergey Temerkhanov 
86ba5648cdSSergey Temerkhanov 	return val;
87ba5648cdSSergey Temerkhanov }
88ba5648cdSSergey Temerkhanov 
89ba5648cdSSergey Temerkhanov #define BSP_COREID	0
90ba5648cdSSergey Temerkhanov 
910ae76531SDavid Feng void __asm_flush_dcache_all(void);
921e6ad55cSYork Sun void __asm_invalidate_dcache_all(void);
930ae76531SDavid Feng void __asm_flush_dcache_range(u64 start, u64 end);
940ae76531SDavid Feng void __asm_invalidate_tlb_all(void);
950ae76531SDavid Feng void __asm_invalidate_icache_all(void);
96dcd468b8SYork Sun int __asm_flush_l3_cache(void);
975e2ec773SAlexander Graf void __asm_switch_ttbr(u64 new_ttbr);
980ae76531SDavid Feng 
990ae76531SDavid Feng void armv8_switch_to_el2(void);
1000ae76531SDavid Feng void armv8_switch_to_el1(void);
1010ae76531SDavid Feng void gic_init(void);
1020ae76531SDavid Feng void gic_send_sgi(unsigned long sgino);
1030ae76531SDavid Feng void wait_for_wakeup(void);
10473169874SIan Campbell void protect_secure_region(void);
1050ae76531SDavid Feng void smp_kick_all_cpus(void);
1060ae76531SDavid Feng 
1072f78eae5SYork Sun void flush_l3_cache(void);
1082f78eae5SYork Sun 
109a5b9fa30SSergey Temerkhanov /*
110a5b9fa30SSergey Temerkhanov  *Issue a hypervisor call in accordance with ARM "SMC Calling convention",
111a5b9fa30SSergey Temerkhanov  * DEN0028A
112a5b9fa30SSergey Temerkhanov  *
113a5b9fa30SSergey Temerkhanov  * @args: input and output arguments
114a5b9fa30SSergey Temerkhanov  *
115a5b9fa30SSergey Temerkhanov  */
116a5b9fa30SSergey Temerkhanov void hvc_call(struct pt_regs *args);
117a5b9fa30SSergey Temerkhanov 
118a5b9fa30SSergey Temerkhanov /*
119a5b9fa30SSergey Temerkhanov  *Issue a secure monitor call in accordance with ARM "SMC Calling convention",
120a5b9fa30SSergey Temerkhanov  * DEN0028A
121a5b9fa30SSergey Temerkhanov  *
122a5b9fa30SSergey Temerkhanov  * @args: input and output arguments
123a5b9fa30SSergey Temerkhanov  *
124a5b9fa30SSergey Temerkhanov  */
125a5b9fa30SSergey Temerkhanov void smc_call(struct pt_regs *args);
126a5b9fa30SSergey Temerkhanov 
1275a07abb3SBeniamino Galvani void __noreturn psci_system_reset(bool smc);
1285a07abb3SBeniamino Galvani 
1290ae76531SDavid Feng #endif	/* __ASSEMBLY__ */
1300ae76531SDavid Feng 
1310ae76531SDavid Feng #else /* CONFIG_ARM64 */
1320ae76531SDavid Feng 
133819833afSPeter Tyser #ifdef __KERNEL__
134819833afSPeter Tyser 
135819833afSPeter Tyser #define CPU_ARCH_UNKNOWN	0
136819833afSPeter Tyser #define CPU_ARCH_ARMv3		1
137819833afSPeter Tyser #define CPU_ARCH_ARMv4		2
138819833afSPeter Tyser #define CPU_ARCH_ARMv4T		3
139819833afSPeter Tyser #define CPU_ARCH_ARMv5		4
140819833afSPeter Tyser #define CPU_ARCH_ARMv5T		5
141819833afSPeter Tyser #define CPU_ARCH_ARMv5TE	6
142819833afSPeter Tyser #define CPU_ARCH_ARMv5TEJ	7
143819833afSPeter Tyser #define CPU_ARCH_ARMv6		8
144819833afSPeter Tyser #define CPU_ARCH_ARMv7		9
145819833afSPeter Tyser 
146819833afSPeter Tyser /*
147819833afSPeter Tyser  * CR1 bits (CP#15 CR1)
148819833afSPeter Tyser  */
149819833afSPeter Tyser #define CR_M	(1 << 0)	/* MMU enable				*/
150819833afSPeter Tyser #define CR_A	(1 << 1)	/* Alignment abort enable		*/
151819833afSPeter Tyser #define CR_C	(1 << 2)	/* Dcache enable			*/
152819833afSPeter Tyser #define CR_W	(1 << 3)	/* Write buffer enable			*/
153819833afSPeter Tyser #define CR_P	(1 << 4)	/* 32-bit exception handler		*/
154819833afSPeter Tyser #define CR_D	(1 << 5)	/* 32-bit data address range		*/
155819833afSPeter Tyser #define CR_L	(1 << 6)	/* Implementation defined		*/
156819833afSPeter Tyser #define CR_B	(1 << 7)	/* Big endian				*/
157819833afSPeter Tyser #define CR_S	(1 << 8)	/* System MMU protection		*/
158819833afSPeter Tyser #define CR_R	(1 << 9)	/* ROM MMU protection			*/
159819833afSPeter Tyser #define CR_F	(1 << 10)	/* Implementation defined		*/
160819833afSPeter Tyser #define CR_Z	(1 << 11)	/* Implementation defined		*/
161819833afSPeter Tyser #define CR_I	(1 << 12)	/* Icache enable			*/
162819833afSPeter Tyser #define CR_V	(1 << 13)	/* Vectors relocated to 0xffff0000	*/
163819833afSPeter Tyser #define CR_RR	(1 << 14)	/* Round Robin cache replacement	*/
164819833afSPeter Tyser #define CR_L4	(1 << 15)	/* LDR pc can set T bit			*/
165819833afSPeter Tyser #define CR_DT	(1 << 16)
166819833afSPeter Tyser #define CR_IT	(1 << 18)
167819833afSPeter Tyser #define CR_ST	(1 << 19)
168819833afSPeter Tyser #define CR_FI	(1 << 21)	/* Fast interrupt (lower latency mode)	*/
169819833afSPeter Tyser #define CR_U	(1 << 22)	/* Unaligned access operation		*/
170819833afSPeter Tyser #define CR_XP	(1 << 23)	/* Extended page tables			*/
171819833afSPeter Tyser #define CR_VE	(1 << 24)	/* Vectored interrupts			*/
172819833afSPeter Tyser #define CR_EE	(1 << 25)	/* Exception (Big) Endian		*/
173819833afSPeter Tyser #define CR_TRE	(1 << 28)	/* TEX remap enable			*/
174819833afSPeter Tyser #define CR_AFE	(1 << 29)	/* Access flag enable			*/
175819833afSPeter Tyser #define CR_TE	(1 << 30)	/* Thumb exception enable		*/
176819833afSPeter Tyser 
177d990f5c8SAlexander Graf #if defined(CONFIG_ARMV7_LPAE) && !defined(PGTABLE_SIZE)
178d990f5c8SAlexander Graf #define PGTABLE_SIZE		(4096 * 5)
179d990f5c8SAlexander Graf #elif !defined(PGTABLE_SIZE)
1800ae76531SDavid Feng #define PGTABLE_SIZE		(4096 * 4)
18194f7ff36SSergey Temerkhanov #endif
1820ae76531SDavid Feng 
183819833afSPeter Tyser /*
184819833afSPeter Tyser  * This is used to ensure the compiler did actually allocate the register we
185819833afSPeter Tyser  * asked it for some inline assembly sequences.  Apparently we can't trust
186819833afSPeter Tyser  * the compiler from one version to another so a bit of paranoia won't hurt.
187819833afSPeter Tyser  * This string is meant to be concatenated with the inline asm string and
188819833afSPeter Tyser  * will cause compilation to stop on mismatch.
189819833afSPeter Tyser  * (for details, see gcc PR 15089)
190819833afSPeter Tyser  */
191819833afSPeter Tyser #define __asmeq(x, y)  ".ifnc " x "," y " ; .err ; .endif\n\t"
192819833afSPeter Tyser 
193819833afSPeter Tyser #ifndef __ASSEMBLY__
194819833afSPeter Tyser 
195e11c6c27SSimon Glass /**
196e11c6c27SSimon Glass  * save_boot_params() - Save boot parameters before starting reset sequence
197e11c6c27SSimon Glass  *
198e11c6c27SSimon Glass  * If you provide this function it will be called immediately U-Boot starts,
199e11c6c27SSimon Glass  * both for SPL and U-Boot proper.
200e11c6c27SSimon Glass  *
201e11c6c27SSimon Glass  * All registers are unchanged from U-Boot entry. No registers need be
202e11c6c27SSimon Glass  * preserved.
203e11c6c27SSimon Glass  *
204e11c6c27SSimon Glass  * This is not a normal C function. There is no stack. Return by branching to
205e11c6c27SSimon Glass  * save_boot_params_ret.
206e11c6c27SSimon Glass  *
207e11c6c27SSimon Glass  * void save_boot_params(u32 r0, u32 r1, u32 r2, u32 r3);
208e11c6c27SSimon Glass  */
209e11c6c27SSimon Glass 
21055199121SSimon Glass /**
21155199121SSimon Glass  * save_boot_params_ret() - Return from save_boot_params()
21255199121SSimon Glass  *
21355199121SSimon Glass  * If you provide save_boot_params(), then you should jump back to this
21455199121SSimon Glass  * function when done. Try to preserve all registers.
21555199121SSimon Glass  *
21655199121SSimon Glass  * If your implementation of save_boot_params() is in C then it is acceptable
21755199121SSimon Glass  * to simply call save_boot_params_ret() at the end of your function. Since
21855199121SSimon Glass  * there is no link register set up, you cannot just exit the function. U-Boot
21955199121SSimon Glass  * will return to the (initialised) value of lr, and likely crash/hang.
22055199121SSimon Glass  *
22155199121SSimon Glass  * If your implementation of save_boot_params() is in assembler then you
22255199121SSimon Glass  * should use 'b' or 'bx' to return to save_boot_params_ret.
22355199121SSimon Glass  */
22455199121SSimon Glass void save_boot_params_ret(void);
22555199121SSimon Glass 
226819833afSPeter Tyser #define nop() __asm__ __volatile__("mov\tr0,r0\t@ nop\n\t");
227819833afSPeter Tyser 
2282ff467c0SRob Herring #ifdef __ARM_ARCH_7A__
2292ff467c0SRob Herring #define wfi() __asm__ __volatile__ ("wfi" : : : "memory")
2302ff467c0SRob Herring #else
2312ff467c0SRob Herring #define wfi()
2322ff467c0SRob Herring #endif
2332ff467c0SRob Herring 
234d990f5c8SAlexander Graf static inline unsigned long get_cpsr(void)
235d990f5c8SAlexander Graf {
236d990f5c8SAlexander Graf 	unsigned long cpsr;
237d990f5c8SAlexander Graf 
238d990f5c8SAlexander Graf 	asm volatile("mrs %0, cpsr" : "=r"(cpsr): );
239d990f5c8SAlexander Graf 	return cpsr;
240d990f5c8SAlexander Graf }
241d990f5c8SAlexander Graf 
242d990f5c8SAlexander Graf static inline int is_hyp(void)
243d990f5c8SAlexander Graf {
244d990f5c8SAlexander Graf #ifdef CONFIG_ARMV7_LPAE
245d990f5c8SAlexander Graf 	/* HYP mode requires LPAE ... */
246d990f5c8SAlexander Graf 	return ((get_cpsr() & 0x1f) == 0x1a);
247d990f5c8SAlexander Graf #else
248d990f5c8SAlexander Graf 	/* ... so without LPAE support we can optimize all hyp code away */
249d990f5c8SAlexander Graf 	return 0;
250d990f5c8SAlexander Graf #endif
251d990f5c8SAlexander Graf }
252d990f5c8SAlexander Graf 
253819833afSPeter Tyser static inline unsigned int get_cr(void)
254819833afSPeter Tyser {
255819833afSPeter Tyser 	unsigned int val;
256d990f5c8SAlexander Graf 
257d990f5c8SAlexander Graf 	if (is_hyp())
258d990f5c8SAlexander Graf 		asm volatile("mrc p15, 4, %0, c1, c0, 0	@ get CR" : "=r" (val)
259d990f5c8SAlexander Graf 								  :
260d990f5c8SAlexander Graf 								  : "cc");
261d990f5c8SAlexander Graf 	else
262d990f5c8SAlexander Graf 		asm volatile("mrc p15, 0, %0, c1, c0, 0	@ get CR" : "=r" (val)
263d990f5c8SAlexander Graf 								  :
264d990f5c8SAlexander Graf 								  : "cc");
265819833afSPeter Tyser 	return val;
266819833afSPeter Tyser }
267819833afSPeter Tyser 
268819833afSPeter Tyser static inline void set_cr(unsigned int val)
269819833afSPeter Tyser {
270d990f5c8SAlexander Graf 	if (is_hyp())
271d990f5c8SAlexander Graf 		asm volatile("mcr p15, 4, %0, c1, c0, 0	@ set CR" :
272d990f5c8SAlexander Graf 								  : "r" (val)
273d990f5c8SAlexander Graf 								  : "cc");
274d990f5c8SAlexander Graf 	else
275d990f5c8SAlexander Graf 		asm volatile("mcr p15, 0, %0, c1, c0, 0	@ set CR" :
276d990f5c8SAlexander Graf 								  : "r" (val)
277d990f5c8SAlexander Graf 								  : "cc");
278819833afSPeter Tyser 	isb();
279819833afSPeter Tyser }
280819833afSPeter Tyser 
281de63ac27SR Sricharan static inline unsigned int get_dacr(void)
282de63ac27SR Sricharan {
283de63ac27SR Sricharan 	unsigned int val;
284de63ac27SR Sricharan 	asm("mrc p15, 0, %0, c3, c0, 0	@ get DACR" : "=r" (val) : : "cc");
285de63ac27SR Sricharan 	return val;
286de63ac27SR Sricharan }
287de63ac27SR Sricharan 
288de63ac27SR Sricharan static inline void set_dacr(unsigned int val)
289de63ac27SR Sricharan {
290de63ac27SR Sricharan 	asm volatile("mcr p15, 0, %0, c3, c0, 0	@ set DACR"
291de63ac27SR Sricharan 	  : : "r" (val) : "cc");
292de63ac27SR Sricharan 	isb();
293de63ac27SR Sricharan }
294de63ac27SR Sricharan 
295d990f5c8SAlexander Graf #ifdef CONFIG_ARMV7_LPAE
296d990f5c8SAlexander Graf /* Long-Descriptor Translation Table Level 1/2 Bits */
297d990f5c8SAlexander Graf #define TTB_SECT_XN_MASK	(1ULL << 54)
298d990f5c8SAlexander Graf #define TTB_SECT_NG_MASK	(1 << 11)
299d990f5c8SAlexander Graf #define TTB_SECT_AF		(1 << 10)
300d990f5c8SAlexander Graf #define TTB_SECT_SH_MASK	(3 << 8)
301d990f5c8SAlexander Graf #define TTB_SECT_NS_MASK	(1 << 5)
302d990f5c8SAlexander Graf #define TTB_SECT_AP		(1 << 6)
303d990f5c8SAlexander Graf /* Note: TTB AP bits are set elsewhere */
304d990f5c8SAlexander Graf #define TTB_SECT_MAIR(x)	((x & 0x7) << 2) /* Index into MAIR */
305d990f5c8SAlexander Graf #define TTB_SECT		(1 << 0)
306d990f5c8SAlexander Graf #define TTB_PAGETABLE		(3 << 0)
307d990f5c8SAlexander Graf 
308d990f5c8SAlexander Graf /* TTBCR flags */
309d990f5c8SAlexander Graf #define TTBCR_EAE		(1 << 31)
310d990f5c8SAlexander Graf #define TTBCR_T0SZ(x)		((x) << 0)
311d990f5c8SAlexander Graf #define TTBCR_T1SZ(x)		((x) << 16)
312d990f5c8SAlexander Graf #define TTBCR_USING_TTBR0	(TTBCR_T0SZ(0) | TTBCR_T1SZ(0))
313d990f5c8SAlexander Graf #define TTBCR_IRGN0_NC		(0 << 8)
314d990f5c8SAlexander Graf #define TTBCR_IRGN0_WBWA	(1 << 8)
315d990f5c8SAlexander Graf #define TTBCR_IRGN0_WT		(2 << 8)
316d990f5c8SAlexander Graf #define TTBCR_IRGN0_WBNWA	(3 << 8)
317d990f5c8SAlexander Graf #define TTBCR_IRGN0_MASK	(3 << 8)
318d990f5c8SAlexander Graf #define TTBCR_ORGN0_NC		(0 << 10)
319d990f5c8SAlexander Graf #define TTBCR_ORGN0_WBWA	(1 << 10)
320d990f5c8SAlexander Graf #define TTBCR_ORGN0_WT		(2 << 10)
321d990f5c8SAlexander Graf #define TTBCR_ORGN0_WBNWA	(3 << 10)
322d990f5c8SAlexander Graf #define TTBCR_ORGN0_MASK	(3 << 10)
323d990f5c8SAlexander Graf #define TTBCR_SHARED_NON	(0 << 12)
324d990f5c8SAlexander Graf #define TTBCR_SHARED_OUTER	(2 << 12)
325d990f5c8SAlexander Graf #define TTBCR_SHARED_INNER	(3 << 12)
326d990f5c8SAlexander Graf #define TTBCR_EPD0		(0 << 7)
327d990f5c8SAlexander Graf 
328d990f5c8SAlexander Graf /*
329d990f5c8SAlexander Graf  * Memory types
330d990f5c8SAlexander Graf  */
331d990f5c8SAlexander Graf #define MEMORY_ATTRIBUTES	((0x00 << (0 * 8)) | (0x88 << (1 * 8)) | \
332d990f5c8SAlexander Graf 				 (0xcc << (2 * 8)) | (0xff << (3 * 8)))
333d990f5c8SAlexander Graf 
334d990f5c8SAlexander Graf /* options available for data cache on each page */
335d990f5c8SAlexander Graf enum dcache_option {
336d990f5c8SAlexander Graf 	DCACHE_OFF = TTB_SECT | TTB_SECT_MAIR(0),
337d990f5c8SAlexander Graf 	DCACHE_WRITETHROUGH = TTB_SECT | TTB_SECT_MAIR(1),
338d990f5c8SAlexander Graf 	DCACHE_WRITEBACK = TTB_SECT | TTB_SECT_MAIR(2),
339d990f5c8SAlexander Graf 	DCACHE_WRITEALLOC = TTB_SECT | TTB_SECT_MAIR(3),
340d990f5c8SAlexander Graf };
341d990f5c8SAlexander Graf #elif defined(CONFIG_CPU_V7)
34297840b5dSBryan Brinsko /* Short-Descriptor Translation Table Level 1 Bits */
34397840b5dSBryan Brinsko #define TTB_SECT_NS_MASK	(1 << 19)
34497840b5dSBryan Brinsko #define TTB_SECT_NG_MASK	(1 << 17)
34597840b5dSBryan Brinsko #define TTB_SECT_S_MASK		(1 << 16)
34697840b5dSBryan Brinsko /* Note: TTB AP bits are set elsewhere */
347d990f5c8SAlexander Graf #define TTB_SECT_AP		(3 << 10)
34897840b5dSBryan Brinsko #define TTB_SECT_TEX(x)		((x & 0x7) << 12)
34997840b5dSBryan Brinsko #define TTB_SECT_DOMAIN(x)	((x & 0xf) << 5)
35097840b5dSBryan Brinsko #define TTB_SECT_XN_MASK	(1 << 4)
35197840b5dSBryan Brinsko #define TTB_SECT_C_MASK		(1 << 3)
35297840b5dSBryan Brinsko #define TTB_SECT_B_MASK		(1 << 2)
35397840b5dSBryan Brinsko #define TTB_SECT			(2 << 0)
35497840b5dSBryan Brinsko 
35597840b5dSBryan Brinsko /* options available for data cache on each page */
35697840b5dSBryan Brinsko enum dcache_option {
3578890c2fbSMarek Vasut 	DCACHE_OFF = TTB_SECT_DOMAIN(0) | TTB_SECT_XN_MASK | TTB_SECT,
35897840b5dSBryan Brinsko 	DCACHE_WRITETHROUGH = DCACHE_OFF | TTB_SECT_C_MASK,
35997840b5dSBryan Brinsko 	DCACHE_WRITEBACK = DCACHE_WRITETHROUGH | TTB_SECT_B_MASK,
36097840b5dSBryan Brinsko 	DCACHE_WRITEALLOC = DCACHE_WRITEBACK | TTB_SECT_TEX(1),
36197840b5dSBryan Brinsko };
36297840b5dSBryan Brinsko #else
363d990f5c8SAlexander Graf #define TTB_SECT_AP		(3 << 10)
3640dde7f53SSimon Glass /* options available for data cache on each page */
3650dde7f53SSimon Glass enum dcache_option {
3660dde7f53SSimon Glass 	DCACHE_OFF = 0x12,
3670dde7f53SSimon Glass 	DCACHE_WRITETHROUGH = 0x1a,
3680dde7f53SSimon Glass 	DCACHE_WRITEBACK = 0x1e,
369ff7e9700SMarek Vasut 	DCACHE_WRITEALLOC = 0x16,
3700dde7f53SSimon Glass };
37197840b5dSBryan Brinsko #endif
3720dde7f53SSimon Glass 
3730dde7f53SSimon Glass /* Size of an MMU section */
3740dde7f53SSimon Glass enum {
375d990f5c8SAlexander Graf #ifdef CONFIG_ARMV7_LPAE
376d990f5c8SAlexander Graf 	MMU_SECTION_SHIFT	= 21, /* 2MB */
377d990f5c8SAlexander Graf #else
378d990f5c8SAlexander Graf 	MMU_SECTION_SHIFT	= 20, /* 1MB */
379d990f5c8SAlexander Graf #endif
3800dde7f53SSimon Glass 	MMU_SECTION_SIZE	= 1 << MMU_SECTION_SHIFT,
3810dde7f53SSimon Glass };
3820dde7f53SSimon Glass 
383a592e6fbSMarek Vasut #ifdef CONFIG_CPU_V7
38497840b5dSBryan Brinsko /* TTBR0 bits */
38597840b5dSBryan Brinsko #define TTBR0_BASE_ADDR_MASK	0xFFFFC000
38697840b5dSBryan Brinsko #define TTBR0_RGN_NC			(0 << 3)
38797840b5dSBryan Brinsko #define TTBR0_RGN_WBWA			(1 << 3)
38897840b5dSBryan Brinsko #define TTBR0_RGN_WT			(2 << 3)
38997840b5dSBryan Brinsko #define TTBR0_RGN_WB			(3 << 3)
39097840b5dSBryan Brinsko /* TTBR0[6] is IRGN[0] and TTBR[0] is IRGN[1] */
39197840b5dSBryan Brinsko #define TTBR0_IRGN_NC			(0 << 0 | 0 << 6)
39297840b5dSBryan Brinsko #define TTBR0_IRGN_WBWA			(0 << 0 | 1 << 6)
39397840b5dSBryan Brinsko #define TTBR0_IRGN_WT			(1 << 0 | 0 << 6)
39497840b5dSBryan Brinsko #define TTBR0_IRGN_WB			(1 << 0 | 1 << 6)
39597840b5dSBryan Brinsko #endif
39697840b5dSBryan Brinsko 
3970dde7f53SSimon Glass /**
3980dde7f53SSimon Glass  * Register an update to the page tables, and flush the TLB
3990dde7f53SSimon Glass  *
4000dde7f53SSimon Glass  * \param start		start address of update in page table
4010dde7f53SSimon Glass  * \param stop		stop address of update in page table
4020dde7f53SSimon Glass  */
4030dde7f53SSimon Glass void mmu_page_table_flush(unsigned long start, unsigned long stop);
4040dde7f53SSimon Glass 
405819833afSPeter Tyser #endif /* __ASSEMBLY__ */
406819833afSPeter Tyser 
407819833afSPeter Tyser #define arch_align_stack(x) (x)
408819833afSPeter Tyser 
409819833afSPeter Tyser #endif /* __KERNEL__ */
410819833afSPeter Tyser 
4110ae76531SDavid Feng #endif /* CONFIG_ARM64 */
4120ae76531SDavid Feng 
413dad17fd5SSiva Durga Prasad Paladugu #ifndef __ASSEMBLY__
414dad17fd5SSiva Durga Prasad Paladugu /**
415dad17fd5SSiva Durga Prasad Paladugu  * Change the cache settings for a region.
416dad17fd5SSiva Durga Prasad Paladugu  *
417dad17fd5SSiva Durga Prasad Paladugu  * \param start		start address of memory region to change
418dad17fd5SSiva Durga Prasad Paladugu  * \param size		size of memory region to change
419dad17fd5SSiva Durga Prasad Paladugu  * \param option	dcache option to select
420dad17fd5SSiva Durga Prasad Paladugu  */
421dad17fd5SSiva Durga Prasad Paladugu void mmu_set_region_dcache_behaviour(phys_addr_t start, size_t size,
422dad17fd5SSiva Durga Prasad Paladugu 				     enum dcache_option option);
423dad17fd5SSiva Durga Prasad Paladugu 
42488f965d7SStephen Warren #ifdef CONFIG_SYS_NONCACHED_MEMORY
42588f965d7SStephen Warren void noncached_init(void);
42688f965d7SStephen Warren phys_addr_t noncached_alloc(size_t size, size_t align);
42788f965d7SStephen Warren #endif /* CONFIG_SYS_NONCACHED_MEMORY */
42888f965d7SStephen Warren 
429dad17fd5SSiva Durga Prasad Paladugu #endif /* __ASSEMBLY__ */
430dad17fd5SSiva Durga Prasad Paladugu 
431819833afSPeter Tyser #endif
432