1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2020 Google LLC.
4 * Written by David Brazdil <dbrazdil@google.com>
7 #ifndef __ARM64_HYP_IMAGE_H__
8 #define __ARM64_HYP_IMAGE_H__
10 #define __HYP_CONCAT(a, b) a ## b
11 #define HYP_CONCAT(a, b) __HYP_CONCAT(a, b)
13 #ifndef __KVM_NVHE_HYPERVISOR__
15 * KVM nVHE code has its own symbol namespace prefixed with __kvm_nvhe_,
16 * to separate it from the kernel proper.
18 #define kvm_nvhe_sym(sym) __kvm_nvhe_##sym
20 #define kvm_nvhe_sym(sym) sym
26 * KVM nVHE ELF section names are prefixed with .hyp, to separate them
27 * from the kernel proper.
29 #define HYP_SECTION_NAME(NAME) .hyp##NAME
31 /* Symbol defined at the beginning of each hyp section. */
32 #define HYP_SECTION_SYMBOL_NAME(NAME) \
33 HYP_CONCAT(__hyp_section_, HYP_SECTION_NAME(NAME))
36 * Helper to generate linker script statements starting a hyp section.
38 * A symbol with a well-known name is defined at the first byte. This
39 * is used as a base for hyp relocations (see gen-hyprel.c). It must
40 * be defined inside the section so the linker of `vmlinux` cannot
41 * separate it from the section data.
43 #define BEGIN_HYP_SECTION(NAME) \
44 HYP_SECTION_NAME(NAME) : { \
45 HYP_SECTION_SYMBOL_NAME(NAME) = .;
47 /* Helper to generate linker script statements ending a hyp section. */
48 #define END_HYP_SECTION \
51 /* Defines an ELF hyp section from input section @NAME and its subsections. */
52 #define HYP_SECTION(NAME) \
53 BEGIN_HYP_SECTION(NAME) \
58 * Defines a linker script alias of a kernel-proper symbol referenced by
61 #define KVM_NVHE_ALIAS(sym) kvm_nvhe_sym(sym) = sym;
63 /* Defines a linker script alias for KVM nVHE hyp symbols */
64 #define KVM_NVHE_ALIAS_HYP(first, sec) kvm_nvhe_sym(first) = kvm_nvhe_sym(sec);
66 #endif /* LINKER_SCRIPT */
68 #endif /* __ARM64_HYP_IMAGE_H__ */