Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Feng | 85fd5f1 | 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 | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 15 | #include <cpu_func.h> |
Simon Glass | 8f3f761 | 2019-11-14 12:57:42 -0700 | [diff] [blame] | 16 | #include <irq_func.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 17 | #include <asm/cache.h> |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 18 | #include <asm/system.h> |
macro.wave.z@gmail.com | 05725ed | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 19 | #include <asm/secure.h> |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 20 | #include <linux/compiler.h> |
| 21 | |
Andre Przywara | 5174d5d | 2017-01-02 11:48:32 +0000 | [diff] [blame] | 22 | /* |
| 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 | */ |
| 30 | void 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 Kuo | f479aca | 2020-03-26 16:10:09 -0700 | [diff] [blame] | 36 | void __weak board_cleanup_before_linux(void){} |
| 37 | |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 38 | int 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 Kuo | f479aca | 2020-03-26 16:10:09 -0700 | [diff] [blame] | 46 | |
| 47 | board_cleanup_before_linux(); |
| 48 | |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 49 | disable_interrupts(); |
| 50 | |
Marc Zyngier | b67855c | 2023-02-09 04:54:27 +0800 | [diff] [blame^] | 51 | if (IS_ENABLED(CONFIG_CMO_BY_VA_ONLY)) { |
| 52 | /* |
| 53 | * Disable D-cache. |
| 54 | */ |
| 55 | dcache_disable(); |
| 56 | } else { |
| 57 | /* |
| 58 | * Turn off I-cache and invalidate it |
| 59 | */ |
| 60 | icache_disable(); |
| 61 | invalidate_icache_all(); |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 62 | |
Marc Zyngier | b67855c | 2023-02-09 04:54:27 +0800 | [diff] [blame^] | 63 | /* |
| 64 | * turn off D-cache |
| 65 | * dcache_disable() in turn flushes the d-cache and disables |
| 66 | * MMU |
| 67 | */ |
| 68 | dcache_disable(); |
| 69 | invalidate_dcache_all(); |
| 70 | } |
David Feng | 85fd5f1 | 2013-12-14 11:47:35 +0800 | [diff] [blame] | 71 | |
| 72 | return 0; |
| 73 | } |
macro.wave.z@gmail.com | 05725ed | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 74 | |
| 75 | #ifdef CONFIG_ARMV8_PSCI |
| 76 | static void relocate_secure_section(void) |
| 77 | { |
| 78 | #ifdef CONFIG_ARMV8_SECURE_BASE |
| 79 | size_t sz = __secure_end - __secure_start; |
| 80 | |
| 81 | memcpy((void *)CONFIG_ARMV8_SECURE_BASE, __secure_start, sz); |
| 82 | flush_dcache_range(CONFIG_ARMV8_SECURE_BASE, |
| 83 | CONFIG_ARMV8_SECURE_BASE + sz + 1); |
| 84 | invalidate_icache_all(); |
| 85 | #endif |
| 86 | } |
| 87 | |
| 88 | void armv8_setup_psci(void) |
| 89 | { |
Michael Walle | 616833b | 2022-02-28 13:48:39 +0100 | [diff] [blame] | 90 | if (current_el() != 3) |
| 91 | return; |
| 92 | |
macro.wave.z@gmail.com | 05725ed | 2016-12-08 11:58:25 +0800 | [diff] [blame] | 93 | relocate_secure_section(); |
| 94 | secure_ram_addr(psci_setup_vectors)(); |
| 95 | secure_ram_addr(psci_arch_init)(); |
| 96 | } |
| 97 | #endif |