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