Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Feng | 0ae7653 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 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> |
David Feng | 0ae7653 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <command.h> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 15 | #include <cpu_func.h> |
Simon Glass | 36bf446 | 2019-11-14 12:57:42 -0700 | [diff] [blame^] | 16 | #include <irq_func.h> |
David Feng | 0ae7653 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 17 | #include <asm/system.h> |
macro.wave.z@gmail.com | 9a56175 | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 18 | #include <asm/secure.h> |
David Feng | 0ae7653 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 19 | #include <linux/compiler.h> |
| 20 | |
Andre Przywara | 8ed02bc | 2017-01-02 11:48:32 +0000 | [diff] [blame] | 21 | /* |
| 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 | */ |
| 29 | void 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 | |
David Feng | 0ae7653 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 35 | int cleanup_before_linux(void) |
| 36 | { |
| 37 | /* |
| 38 | * this function is called just before we call linux |
| 39 | * it prepares the processor for linux |
| 40 | * |
| 41 | * disable interrupt and turn off caches etc ... |
| 42 | */ |
| 43 | disable_interrupts(); |
| 44 | |
| 45 | /* |
| 46 | * Turn off I-cache and invalidate it |
| 47 | */ |
| 48 | icache_disable(); |
| 49 | invalidate_icache_all(); |
| 50 | |
| 51 | /* |
| 52 | * turn off D-cache |
| 53 | * dcache_disable() in turn flushes the d-cache and disables MMU |
| 54 | */ |
| 55 | dcache_disable(); |
| 56 | invalidate_dcache_all(); |
| 57 | |
| 58 | return 0; |
| 59 | } |
macro.wave.z@gmail.com | 9a56175 | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 60 | |
| 61 | #ifdef CONFIG_ARMV8_PSCI |
| 62 | static void relocate_secure_section(void) |
| 63 | { |
| 64 | #ifdef CONFIG_ARMV8_SECURE_BASE |
| 65 | size_t sz = __secure_end - __secure_start; |
| 66 | |
| 67 | memcpy((void *)CONFIG_ARMV8_SECURE_BASE, __secure_start, sz); |
| 68 | flush_dcache_range(CONFIG_ARMV8_SECURE_BASE, |
| 69 | CONFIG_ARMV8_SECURE_BASE + sz + 1); |
| 70 | invalidate_icache_all(); |
| 71 | #endif |
| 72 | } |
| 73 | |
| 74 | void armv8_setup_psci(void) |
| 75 | { |
| 76 | relocate_secure_section(); |
| 77 | secure_ram_addr(psci_setup_vectors)(); |
| 78 | secure_ram_addr(psci_arch_init)(); |
| 79 | } |
| 80 | #endif |