David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2012 Linaro Limited. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef VIRT_H |
| 7 | #define VIRT_H |
| 8 | |
| 9 | #include <asm/ptrace.h> |
| 10 | |
| 11 | /* |
| 12 | * Flag indicating that the kernel was not entered in the same mode on every |
| 13 | * CPU. The zImage loader stashes this value in an SPSR, so we need an |
| 14 | * architecturally defined flag bit here. |
| 15 | */ |
| 16 | #define BOOT_CPU_MODE_MISMATCH PSR_N_BIT |
| 17 | |
| 18 | #ifndef __ASSEMBLY__ |
| 19 | #include <asm/cacheflush.h> |
| 20 | |
| 21 | #ifdef CONFIG_ARM_VIRT_EXT |
| 22 | /* |
| 23 | * __boot_cpu_mode records what mode the primary CPU was booted in. |
| 24 | * A correctly-implemented bootloader must start all CPUs in the same mode: |
| 25 | * if it fails to do this, the flag BOOT_CPU_MODE_MISMATCH is set to indicate |
| 26 | * that some CPU(s) were booted in a different mode. |
| 27 | * |
| 28 | * This allows the kernel to flag an error when the secondaries have come up. |
| 29 | */ |
| 30 | extern int __boot_cpu_mode; |
| 31 | |
| 32 | static inline void sync_boot_mode(void) |
| 33 | { |
| 34 | /* |
| 35 | * As secondaries write to __boot_cpu_mode with caches disabled, we |
| 36 | * must flush the corresponding cache entries to ensure the visibility |
| 37 | * of their writes. |
| 38 | */ |
| 39 | sync_cache_r(&__boot_cpu_mode); |
| 40 | } |
| 41 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 42 | #else |
| 43 | #define __boot_cpu_mode (SVC_MODE) |
| 44 | #define sync_boot_mode() |
| 45 | #endif |
| 46 | |
| 47 | #ifndef ZIMAGE |
| 48 | void hyp_mode_check(void); |
| 49 | |
| 50 | /* Reports the availability of HYP mode */ |
| 51 | static inline bool is_hyp_mode_available(void) |
| 52 | { |
| 53 | return ((__boot_cpu_mode & MODE_MASK) == HYP_MODE && |
| 54 | !(__boot_cpu_mode & BOOT_CPU_MODE_MISMATCH)); |
| 55 | } |
| 56 | |
| 57 | /* Check if the bootloader has booted CPUs in different modes */ |
| 58 | static inline bool is_hyp_mode_mismatched(void) |
| 59 | { |
| 60 | return !!(__boot_cpu_mode & BOOT_CPU_MODE_MISMATCH); |
| 61 | } |
| 62 | |
| 63 | static inline bool is_kernel_in_hyp_mode(void) |
| 64 | { |
| 65 | return false; |
| 66 | } |
| 67 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 68 | #endif |
| 69 | |
| 70 | #else |
| 71 | |
| 72 | /* Only assembly code should need those */ |
| 73 | |
| 74 | #define HVC_SET_VECTORS 0 |
| 75 | #define HVC_SOFT_RESTART 1 |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 76 | |
| 77 | #endif /* __ASSEMBLY__ */ |
| 78 | |
| 79 | #define HVC_STUB_ERR 0xbadca11 |
| 80 | |
| 81 | #endif /* ! VIRT_H */ |