hyp_image.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2020 Google LLC.
  4. * Written by David Brazdil <[email protected]>
  5. */
  6. #ifndef __ARM64_HYP_IMAGE_H__
  7. #define __ARM64_HYP_IMAGE_H__
  8. #define __HYP_CONCAT(a, b) a ## b
  9. #define HYP_CONCAT(a, b) __HYP_CONCAT(a, b)
  10. #ifndef __KVM_NVHE_HYPERVISOR__
  11. /*
  12. * KVM nVHE code has its own symbol namespace prefixed with __kvm_nvhe_,
  13. * to separate it from the kernel proper.
  14. */
  15. #define kvm_nvhe_sym(sym) __kvm_nvhe_##sym
  16. #else
  17. #define kvm_nvhe_sym(sym) sym
  18. #endif
  19. #ifdef LINKER_SCRIPT
  20. /*
  21. * KVM nVHE ELF section names are prefixed with .hyp, to separate them
  22. * from the kernel proper.
  23. */
  24. #define HYP_SECTION_NAME(NAME) .hyp##NAME
  25. /* Symbol defined at the beginning of each hyp section. */
  26. #define HYP_SECTION_SYMBOL_NAME(NAME) \
  27. HYP_CONCAT(__hyp_section_, HYP_SECTION_NAME(NAME))
  28. /*
  29. * Helper to generate linker script statements starting a hyp section.
  30. *
  31. * A symbol with a well-known name is defined at the first byte. This
  32. * is used as a base for hyp relocations (see gen-hyprel.c). It must
  33. * be defined inside the section so the linker of `vmlinux` cannot
  34. * separate it from the section data.
  35. */
  36. #define BEGIN_HYP_SECTION(NAME) \
  37. HYP_SECTION_NAME(NAME) : { \
  38. HYP_SECTION_SYMBOL_NAME(NAME) = .;
  39. /* Helper to generate linker script statements ending a hyp section. */
  40. #define END_HYP_SECTION \
  41. }
  42. /* Defines an ELF hyp section from input section @NAME and its subsections. */
  43. #define HYP_SECTION(NAME) \
  44. BEGIN_HYP_SECTION(NAME) \
  45. *(NAME NAME##.*) \
  46. END_HYP_SECTION
  47. /*
  48. * Defines a linker script alias of a kernel-proper symbol referenced by
  49. * KVM nVHE hyp code.
  50. */
  51. #define KVM_NVHE_ALIAS(sym) kvm_nvhe_sym(sym) = sym;
  52. /* Defines a linker script alias for KVM nVHE hyp symbols */
  53. #define KVM_NVHE_ALIAS_HYP(first, sec) kvm_nvhe_sym(first) = kvm_nvhe_sym(sec);
  54. #endif /* LINKER_SCRIPT */
  55. #endif /* __ARM64_HYP_IMAGE_H__ */