virt.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. * Author: Marc Zyngier <marc.zyngier@arm.com>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef __ASM__VIRT_H
  18. #define __ASM__VIRT_H
  19. /*
  20. * The arm64 hcall implementation uses x0 to specify the hcall type. A value
  21. * less than 0xfff indicates a special hcall, such as get/set vector.
  22. * Any other value is used as a pointer to the function to call.
  23. */
  24. /* HVC_GET_VECTORS - Return the value of the vbar_el2 register. */
  25. #define HVC_GET_VECTORS 0
  26. /*
  27. * HVC_SET_VECTORS - Set the value of the vbar_el2 register.
  28. *
  29. * @x1: Physical address of the new vector table.
  30. */
  31. #define HVC_SET_VECTORS 1
  32. /*
  33. * HVC_SOFT_RESTART - CPU soft reset, used by the cpu_soft_restart routine.
  34. */
  35. #define HVC_SOFT_RESTART 2
  36. #define BOOT_CPU_MODE_EL1 (0xe11)
  37. #define BOOT_CPU_MODE_EL2 (0xe12)
  38. #ifndef __ASSEMBLY__
  39. #include <asm/ptrace.h>
  40. #include <asm/sections.h>
  41. #include <asm/sysreg.h>
  42. /*
  43. * __boot_cpu_mode records what mode CPUs were booted in.
  44. * A correctly-implemented bootloader must start all CPUs in the same mode:
  45. * In this case, both 32bit halves of __boot_cpu_mode will contain the
  46. * same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2).
  47. *
  48. * Should the bootloader fail to do this, the two values will be different.
  49. * This allows the kernel to flag an error when the secondaries have come up.
  50. */
  51. extern u32 __boot_cpu_mode[2];
  52. void __hyp_set_vectors(phys_addr_t phys_vector_base);
  53. phys_addr_t __hyp_get_vectors(void);
  54. /* Reports the availability of HYP mode */
  55. static inline bool is_hyp_mode_available(void)
  56. {
  57. return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
  58. __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
  59. }
  60. /* Check if the bootloader has booted CPUs in different modes */
  61. static inline bool is_hyp_mode_mismatched(void)
  62. {
  63. return __boot_cpu_mode[0] != __boot_cpu_mode[1];
  64. }
  65. static inline bool is_kernel_in_hyp_mode(void)
  66. {
  67. return read_sysreg(CurrentEL) == CurrentEL_EL2;
  68. }
  69. #ifdef CONFIG_ARM64_VHE
  70. extern void verify_cpu_run_el(void);
  71. #else
  72. static inline void verify_cpu_run_el(void) {}
  73. #endif
  74. #endif /* __ASSEMBLY__ */
  75. #endif /* ! __ASM__VIRT_H */