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