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