Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * AMD Memory Encryption Support
0004  *
0005  * Copyright (C) 2016 Advanced Micro Devices, Inc.
0006  *
0007  * Author: Tom Lendacky <thomas.lendacky@amd.com>
0008  */
0009 
0010 #ifndef __X86_MEM_ENCRYPT_H__
0011 #define __X86_MEM_ENCRYPT_H__
0012 
0013 #ifndef __ASSEMBLY__
0014 
0015 #include <linux/init.h>
0016 #include <linux/cc_platform.h>
0017 
0018 #include <asm/bootparam.h>
0019 
0020 #ifdef CONFIG_AMD_MEM_ENCRYPT
0021 
0022 extern u64 sme_me_mask;
0023 extern u64 sev_status;
0024 
0025 void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr,
0026              unsigned long decrypted_kernel_vaddr,
0027              unsigned long kernel_len,
0028              unsigned long encryption_wa,
0029              unsigned long encryption_pgd);
0030 
0031 void __init sme_early_encrypt(resource_size_t paddr,
0032                   unsigned long size);
0033 void __init sme_early_decrypt(resource_size_t paddr,
0034                   unsigned long size);
0035 
0036 void __init sme_map_bootdata(char *real_mode_data);
0037 void __init sme_unmap_bootdata(char *real_mode_data);
0038 
0039 void __init sme_early_init(void);
0040 void __init sev_setup_arch(void);
0041 
0042 void __init sme_encrypt_kernel(struct boot_params *bp);
0043 void __init sme_enable(struct boot_params *bp);
0044 
0045 int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size);
0046 int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);
0047 void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages,
0048                         bool enc);
0049 
0050 void __init mem_encrypt_free_decrypted_mem(void);
0051 
0052 void __init sev_es_init_vc_handling(void);
0053 
0054 #define __bss_decrypted __section(".bss..decrypted")
0055 
0056 #else   /* !CONFIG_AMD_MEM_ENCRYPT */
0057 
0058 #define sme_me_mask 0ULL
0059 
0060 static inline void __init sme_early_encrypt(resource_size_t paddr,
0061                         unsigned long size) { }
0062 static inline void __init sme_early_decrypt(resource_size_t paddr,
0063                         unsigned long size) { }
0064 
0065 static inline void __init sme_map_bootdata(char *real_mode_data) { }
0066 static inline void __init sme_unmap_bootdata(char *real_mode_data) { }
0067 
0068 static inline void __init sme_early_init(void) { }
0069 static inline void __init sev_setup_arch(void) { }
0070 
0071 static inline void __init sme_encrypt_kernel(struct boot_params *bp) { }
0072 static inline void __init sme_enable(struct boot_params *bp) { }
0073 
0074 static inline void sev_es_init_vc_handling(void) { }
0075 
0076 static inline int __init
0077 early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; }
0078 static inline int __init
0079 early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; }
0080 static inline void __init
0081 early_set_mem_enc_dec_hypercall(unsigned long vaddr, int npages, bool enc) {}
0082 
0083 static inline void mem_encrypt_free_decrypted_mem(void) { }
0084 
0085 #define __bss_decrypted
0086 
0087 #endif  /* CONFIG_AMD_MEM_ENCRYPT */
0088 
0089 /* Architecture __weak replacement functions */
0090 void __init mem_encrypt_init(void);
0091 
0092 void add_encrypt_protection_map(void);
0093 
0094 /*
0095  * The __sme_pa() and __sme_pa_nodebug() macros are meant for use when
0096  * writing to or comparing values from the cr3 register.  Having the
0097  * encryption mask set in cr3 enables the PGD entry to be encrypted and
0098  * avoid special case handling of PGD allocations.
0099  */
0100 #define __sme_pa(x)     (__pa(x) | sme_me_mask)
0101 #define __sme_pa_nodebug(x) (__pa_nodebug(x) | sme_me_mask)
0102 
0103 extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];
0104 
0105 static inline u64 sme_get_me_mask(void)
0106 {
0107     return sme_me_mask;
0108 }
0109 
0110 #endif  /* __ASSEMBLY__ */
0111 
0112 #endif  /* __X86_MEM_ENCRYPT_H__ */