virt.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (c) 2012 Linaro Limited.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  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 along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #ifndef VIRT_H
  19. #define VIRT_H
  20. #include <asm/ptrace.h>
  21. /*
  22. * Flag indicating that the kernel was not entered in the same mode on every
  23. * CPU. The zImage loader stashes this value in an SPSR, so we need an
  24. * architecturally defined flag bit here.
  25. */
  26. #define BOOT_CPU_MODE_MISMATCH PSR_N_BIT
  27. #ifndef __ASSEMBLY__
  28. #include <asm/cacheflush.h>
  29. #ifdef CONFIG_ARM_VIRT_EXT
  30. /*
  31. * __boot_cpu_mode records what mode the primary CPU was booted in.
  32. * A correctly-implemented bootloader must start all CPUs in the same mode:
  33. * if it fails to do this, the flag BOOT_CPU_MODE_MISMATCH is set to indicate
  34. * that some CPU(s) were booted in a different mode.
  35. *
  36. * This allows the kernel to flag an error when the secondaries have come up.
  37. */
  38. extern int __boot_cpu_mode;
  39. static inline void sync_boot_mode(void)
  40. {
  41. /*
  42. * As secondaries write to __boot_cpu_mode with caches disabled, we
  43. * must flush the corresponding cache entries to ensure the visibility
  44. * of their writes.
  45. */
  46. sync_cache_r(&__boot_cpu_mode);
  47. }
  48. void __hyp_set_vectors(unsigned long phys_vector_base);
  49. unsigned long __hyp_get_vectors(void);
  50. #else
  51. #define __boot_cpu_mode (SVC_MODE)
  52. #define sync_boot_mode()
  53. #endif
  54. #ifndef ZIMAGE
  55. void hyp_mode_check(void);
  56. /* Reports the availability of HYP mode */
  57. static inline bool is_hyp_mode_available(void)
  58. {
  59. return ((__boot_cpu_mode & MODE_MASK) == HYP_MODE &&
  60. !(__boot_cpu_mode & BOOT_CPU_MODE_MISMATCH));
  61. }
  62. /* Check if the bootloader has booted CPUs in different modes */
  63. static inline bool is_hyp_mode_mismatched(void)
  64. {
  65. return !!(__boot_cpu_mode & BOOT_CPU_MODE_MISMATCH);
  66. }
  67. static inline bool is_kernel_in_hyp_mode(void)
  68. {
  69. return false;
  70. }
  71. /* The section containing the hypervisor idmap text */
  72. extern char __hyp_idmap_text_start[];
  73. extern char __hyp_idmap_text_end[];
  74. /* The section containing the hypervisor text */
  75. extern char __hyp_text_start[];
  76. extern char __hyp_text_end[];
  77. #endif
  78. #endif /* __ASSEMBLY__ */
  79. #endif /* ! VIRT_H */