blob: 35752037bcf1f825460d1fa5c53bb47758d38cf9 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
David Feng85fd5f12013-12-14 11:47:35 +08002/*
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>
David Feng85fd5f12013-12-14 11:47:35 +080011 */
12
13#include <common.h>
14#include <command.h>
Simon Glass1d91ba72019-11-14 12:57:37 -070015#include <cpu_func.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070016#include <irq_func.h>
David Feng85fd5f12013-12-14 11:47:35 +080017#include <asm/system.h>
macro.wave.z@gmail.com05725ed2016-12-08 11:58:25 +080018#include <asm/secure.h>
David Feng85fd5f12013-12-14 11:47:35 +080019#include <linux/compiler.h>
20
Andre Przywara5174d5d2017-01-02 11:48:32 +000021/*
22 * sdelay() - simple spin loop.
23 *
24 * Will delay execution by roughly (@loops * 2) cycles.
25 * This is necessary to be used before timers are accessible.
26 *
27 * A value of "0" will results in 2^64 loops.
28 */
29void sdelay(unsigned long loops)
30{
31 __asm__ volatile ("1:\n" "subs %0, %0, #1\n"
32 "b.ne 1b" : "=r" (loops) : "0"(loops) : "cc");
33}
34
JC Kuof479aca2020-03-26 16:10:09 -070035void __weak board_cleanup_before_linux(void){}
36
David Feng85fd5f12013-12-14 11:47:35 +080037int cleanup_before_linux(void)
38{
39 /*
40 * this function is called just before we call linux
41 * it prepares the processor for linux
42 *
43 * disable interrupt and turn off caches etc ...
44 */
JC Kuof479aca2020-03-26 16:10:09 -070045
46 board_cleanup_before_linux();
47
David Feng85fd5f12013-12-14 11:47:35 +080048 disable_interrupts();
49
50 /*
51 * Turn off I-cache and invalidate it
52 */
53 icache_disable();
54 invalidate_icache_all();
55
56 /*
57 * turn off D-cache
58 * dcache_disable() in turn flushes the d-cache and disables MMU
59 */
60 dcache_disable();
61 invalidate_dcache_all();
62
63 return 0;
64}
macro.wave.z@gmail.com05725ed2016-12-08 11:58:25 +080065
66#ifdef CONFIG_ARMV8_PSCI
67static void relocate_secure_section(void)
68{
69#ifdef CONFIG_ARMV8_SECURE_BASE
70 size_t sz = __secure_end - __secure_start;
71
72 memcpy((void *)CONFIG_ARMV8_SECURE_BASE, __secure_start, sz);
73 flush_dcache_range(CONFIG_ARMV8_SECURE_BASE,
74 CONFIG_ARMV8_SECURE_BASE + sz + 1);
75 invalidate_icache_all();
76#endif
77}
78
79void armv8_setup_psci(void)
80{
81 relocate_secure_section();
82 secure_ram_addr(psci_setup_vectors)();
83 secure_ram_addr(psci_arch_init)();
84}
85#endif