blob: b312b3be356c151c175cfd4a109f2edfff9af8a4 [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>
15#include <asm/system.h>
macro.wave.z@gmail.com05725ed2016-12-08 11:58:25 +080016#include <asm/secure.h>
David Feng85fd5f12013-12-14 11:47:35 +080017#include <linux/compiler.h>
18
Andre Przywara5174d5d2017-01-02 11:48:32 +000019/*
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 */
27void 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
David Feng85fd5f12013-12-14 11:47:35 +080033int 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}
macro.wave.z@gmail.com05725ed2016-12-08 11:58:25 +080058
59#ifdef CONFIG_ARMV8_PSCI
60static 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
72void 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