virt.h 1.8 KB

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