virt.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  21. * number. A value less than HVC_STUB_HCALL_NR indicates a special
  22. * hcall, such as set vector. Any other value is handled in a
  23. * hypervisor specific way.
  24. *
  25. * The hypercall is allowed to clobber any of the caller-saved
  26. * registers (x0-x18), so it is advisable to use it through the
  27. * indirection of a function call (as implemented in hyp-stub.S).
  28. */
  29. /*
  30. * HVC_SET_VECTORS - Set the value of the vbar_el2 register.
  31. *
  32. * @x1: Physical address of the new vector table.
  33. */
  34. #define HVC_SET_VECTORS 0
  35. /*
  36. * HVC_SOFT_RESTART - CPU soft reset, used by the cpu_soft_restart routine.
  37. */
  38. #define HVC_SOFT_RESTART 1
  39. /*
  40. * HVC_RESET_VECTORS - Restore the vectors to the original HYP stubs
  41. */
  42. #define HVC_RESET_VECTORS 2
  43. /* Max number of HYP stub hypercalls */
  44. #define HVC_STUB_HCALL_NR 3
  45. /* Error returned when an invalid stub number is passed into x0 */
  46. #define HVC_STUB_ERR 0xbadca11
  47. #define BOOT_CPU_MODE_EL1 (0xe11)
  48. #define BOOT_CPU_MODE_EL2 (0xe12)
  49. #ifndef __ASSEMBLY__
  50. #include <asm/ptrace.h>
  51. #include <asm/sections.h>
  52. #include <asm/sysreg.h>
  53. #include <asm/cpufeature.h>
  54. /*
  55. * __boot_cpu_mode records what mode CPUs were booted in.
  56. * A correctly-implemented bootloader must start all CPUs in the same mode:
  57. * In this case, both 32bit halves of __boot_cpu_mode will contain the
  58. * same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2).
  59. *
  60. * Should the bootloader fail to do this, the two values will be different.
  61. * This allows the kernel to flag an error when the secondaries have come up.
  62. */
  63. extern u32 __boot_cpu_mode[2];
  64. void __hyp_set_vectors(phys_addr_t phys_vector_base);
  65. void __hyp_reset_vectors(void);
  66. /* Reports the availability of HYP mode */
  67. static inline bool is_hyp_mode_available(void)
  68. {
  69. return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
  70. __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
  71. }
  72. /* Check if the bootloader has booted CPUs in different modes */
  73. static inline bool is_hyp_mode_mismatched(void)
  74. {
  75. return __boot_cpu_mode[0] != __boot_cpu_mode[1];
  76. }
  77. static inline bool is_kernel_in_hyp_mode(void)
  78. {
  79. return read_sysreg(CurrentEL) == CurrentEL_EL2;
  80. }
  81. static inline bool has_vhe(void)
  82. {
  83. if (cpus_have_const_cap(ARM64_HAS_VIRT_HOST_EXTN))
  84. return true;
  85. return false;
  86. }
  87. #endif /* __ASSEMBLY__ */
  88. #endif /* ! __ASM__VIRT_H */