virt.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #define BOOT_CPU_MODE_EL2 (0x0e12b007)
  20. #ifndef __ASSEMBLY__
  21. #include <asm/cacheflush.h>
  22. /*
  23. * __boot_cpu_mode records what mode CPUs were booted in.
  24. * A correctly-implemented bootloader must start all CPUs in the same mode:
  25. * In this case, both 32bit halves of __boot_cpu_mode will contain the
  26. * same value (either 0 if booted in EL1, BOOT_CPU_MODE_EL2 if booted in EL2).
  27. *
  28. * Should the bootloader fail to do this, the two values will be different.
  29. * This allows the kernel to flag an error when the secondaries have come up.
  30. */
  31. extern u32 __boot_cpu_mode[2];
  32. void __hyp_set_vectors(phys_addr_t phys_vector_base);
  33. phys_addr_t __hyp_get_vectors(void);
  34. static inline void sync_boot_mode(void)
  35. {
  36. /*
  37. * As secondaries write to __boot_cpu_mode with caches disabled, we
  38. * must flush the corresponding cache entries to ensure the visibility
  39. * of their writes.
  40. */
  41. __flush_dcache_area(__boot_cpu_mode, sizeof(__boot_cpu_mode));
  42. }
  43. /* Reports the availability of HYP mode */
  44. static inline bool is_hyp_mode_available(void)
  45. {
  46. sync_boot_mode();
  47. return (__boot_cpu_mode[0] == BOOT_CPU_MODE_EL2 &&
  48. __boot_cpu_mode[1] == BOOT_CPU_MODE_EL2);
  49. }
  50. /* Check if the bootloader has booted CPUs in different modes */
  51. static inline bool is_hyp_mode_mismatched(void)
  52. {
  53. sync_boot_mode();
  54. return __boot_cpu_mode[0] != __boot_cpu_mode[1];
  55. }
  56. #endif /* __ASSEMBLY__ */
  57. #endif /* ! __ASM__VIRT_H */