Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2020 Google LLC.
0004  * Written by David Brazdil <dbrazdil@google.com>
0005  */
0006 
0007 #ifndef __ARM64_HYP_IMAGE_H__
0008 #define __ARM64_HYP_IMAGE_H__
0009 
0010 #define __HYP_CONCAT(a, b)  a ## b
0011 #define HYP_CONCAT(a, b)    __HYP_CONCAT(a, b)
0012 
0013 #ifndef __KVM_NVHE_HYPERVISOR__
0014 /*
0015  * KVM nVHE code has its own symbol namespace prefixed with __kvm_nvhe_,
0016  * to separate it from the kernel proper.
0017  */
0018 #define kvm_nvhe_sym(sym)   __kvm_nvhe_##sym
0019 #else
0020 #define kvm_nvhe_sym(sym)   sym
0021 #endif
0022 
0023 #ifdef LINKER_SCRIPT
0024 
0025 /*
0026  * KVM nVHE ELF section names are prefixed with .hyp, to separate them
0027  * from the kernel proper.
0028  */
0029 #define HYP_SECTION_NAME(NAME)  .hyp##NAME
0030 
0031 /* Symbol defined at the beginning of each hyp section. */
0032 #define HYP_SECTION_SYMBOL_NAME(NAME) \
0033     HYP_CONCAT(__hyp_section_, HYP_SECTION_NAME(NAME))
0034 
0035 /*
0036  * Helper to generate linker script statements starting a hyp section.
0037  *
0038  * A symbol with a well-known name is defined at the first byte. This
0039  * is used as a base for hyp relocations (see gen-hyprel.c). It must
0040  * be defined inside the section so the linker of `vmlinux` cannot
0041  * separate it from the section data.
0042  */
0043 #define BEGIN_HYP_SECTION(NAME)             \
0044     HYP_SECTION_NAME(NAME) : {          \
0045         HYP_SECTION_SYMBOL_NAME(NAME) = .;
0046 
0047 /* Helper to generate linker script statements ending a hyp section. */
0048 #define END_HYP_SECTION                 \
0049     }
0050 
0051 /* Defines an ELF hyp section from input section @NAME and its subsections. */
0052 #define HYP_SECTION(NAME)           \
0053     BEGIN_HYP_SECTION(NAME)         \
0054         *(NAME NAME##.*)        \
0055     END_HYP_SECTION
0056 
0057 /*
0058  * Defines a linker script alias of a kernel-proper symbol referenced by
0059  * KVM nVHE hyp code.
0060  */
0061 #define KVM_NVHE_ALIAS(sym) kvm_nvhe_sym(sym) = sym;
0062 
0063 /* Defines a linker script alias for KVM nVHE hyp symbols */
0064 #define KVM_NVHE_ALIAS_HYP(first, sec)  kvm_nvhe_sym(first) = kvm_nvhe_sym(sec);
0065 
0066 #endif /* LINKER_SCRIPT */
0067 
0068 #endif /* __ARM64_HYP_IMAGE_H__ */