xref: /openbmc/u-boot/arch/arm/cpu/armv8/cpu.c (revision b9553986)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2008 Texas Insturments
4  *
5  * (C) Copyright 2002
6  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
7  * Marius Groeger <mgroeger@sysgo.de>
8  *
9  * (C) Copyright 2002
10  * Gary Jennejohn, DENX Software Engineering, <garyj@denx.de>
11  */
12 
13 #include <common.h>
14 #include <command.h>
15 #include <asm/system.h>
16 #include <asm/secure.h>
17 #include <linux/compiler.h>
18 
19 /*
20  * sdelay() - simple spin loop.
21  *
22  * Will delay execution by roughly (@loops * 2) cycles.
23  * This is necessary to be used before timers are accessible.
24  *
25  * A value of "0" will results in 2^64 loops.
26  */
27 void sdelay(unsigned long loops)
28 {
29 	__asm__ volatile ("1:\n" "subs %0, %0, #1\n"
30 			  "b.ne 1b" : "=r" (loops) : "0"(loops) : "cc");
31 }
32 
33 int cleanup_before_linux(void)
34 {
35 	/*
36 	 * this function is called just before we call linux
37 	 * it prepares the processor for linux
38 	 *
39 	 * disable interrupt and turn off caches etc ...
40 	 */
41 	disable_interrupts();
42 
43 	/*
44 	 * Turn off I-cache and invalidate it
45 	 */
46 	icache_disable();
47 	invalidate_icache_all();
48 
49 	/*
50 	 * turn off D-cache
51 	 * dcache_disable() in turn flushes the d-cache and disables MMU
52 	 */
53 	dcache_disable();
54 	invalidate_dcache_all();
55 
56 	return 0;
57 }
58 
59 #ifdef CONFIG_ARMV8_PSCI
60 static void relocate_secure_section(void)
61 {
62 #ifdef CONFIG_ARMV8_SECURE_BASE
63 	size_t sz = __secure_end - __secure_start;
64 
65 	memcpy((void *)CONFIG_ARMV8_SECURE_BASE, __secure_start, sz);
66 	flush_dcache_range(CONFIG_ARMV8_SECURE_BASE,
67 			   CONFIG_ARMV8_SECURE_BASE + sz + 1);
68 	invalidate_icache_all();
69 #endif
70 }
71 
72 void armv8_setup_psci(void)
73 {
74 	relocate_secure_section();
75 	secure_ram_addr(psci_setup_vectors)();
76 	secure_ram_addr(psci_arch_init)();
77 }
78 #endif
79