mem_encrypt.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * AMD Memory Encryption Support
  4. *
  5. * Copyright (C) 2016 Advanced Micro Devices, Inc.
  6. *
  7. * Author: Tom Lendacky <[email protected]>
  8. */
  9. #ifndef __X86_MEM_ENCRYPT_H__
  10. #define __X86_MEM_ENCRYPT_H__
  11. #ifndef __ASSEMBLY__
  12. #include <linux/init.h>
  13. #include <linux/cc_platform.h>
  14. #include <asm/bootparam.h>
  15. #ifdef CONFIG_X86_MEM_ENCRYPT
  16. void __init mem_encrypt_init(void);
  17. #else
  18. static inline void mem_encrypt_init(void) { }
  19. #endif
  20. #ifdef CONFIG_AMD_MEM_ENCRYPT
  21. extern u64 sme_me_mask;
  22. extern u64 sev_status;
  23. void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr,
  24. unsigned long decrypted_kernel_vaddr,
  25. unsigned long kernel_len,
  26. unsigned long encryption_wa,
  27. unsigned long encryption_pgd);
  28. void __init sme_early_encrypt(resource_size_t paddr,
  29. unsigned long size);
  30. void __init sme_early_decrypt(resource_size_t paddr,
  31. unsigned long size);
  32. void __init sme_map_bootdata(char *real_mode_data);
  33. void __init sme_unmap_bootdata(char *real_mode_data);
  34. void __init sme_early_init(void);
  35. void __init sev_setup_arch(void);
  36. void __init sme_encrypt_kernel(struct boot_params *bp);
  37. void __init sme_enable(struct boot_params *bp);
  38. int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size);
  39. int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);
  40. void __init early_set_mem_enc_dec_hypercall(unsigned long vaddr,
  41. unsigned long size, bool enc);
  42. void __init mem_encrypt_free_decrypted_mem(void);
  43. void __init sev_es_init_vc_handling(void);
  44. #define __bss_decrypted __section(".bss..decrypted")
  45. #else /* !CONFIG_AMD_MEM_ENCRYPT */
  46. #define sme_me_mask 0ULL
  47. static inline void __init sme_early_encrypt(resource_size_t paddr,
  48. unsigned long size) { }
  49. static inline void __init sme_early_decrypt(resource_size_t paddr,
  50. unsigned long size) { }
  51. static inline void __init sme_map_bootdata(char *real_mode_data) { }
  52. static inline void __init sme_unmap_bootdata(char *real_mode_data) { }
  53. static inline void __init sme_early_init(void) { }
  54. static inline void __init sev_setup_arch(void) { }
  55. static inline void __init sme_encrypt_kernel(struct boot_params *bp) { }
  56. static inline void __init sme_enable(struct boot_params *bp) { }
  57. static inline void sev_es_init_vc_handling(void) { }
  58. static inline int __init
  59. early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; }
  60. static inline int __init
  61. early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; }
  62. static inline void __init
  63. early_set_mem_enc_dec_hypercall(unsigned long vaddr, unsigned long size, bool enc) {}
  64. static inline void mem_encrypt_free_decrypted_mem(void) { }
  65. #define __bss_decrypted
  66. #endif /* CONFIG_AMD_MEM_ENCRYPT */
  67. void add_encrypt_protection_map(void);
  68. /*
  69. * The __sme_pa() and __sme_pa_nodebug() macros are meant for use when
  70. * writing to or comparing values from the cr3 register. Having the
  71. * encryption mask set in cr3 enables the PGD entry to be encrypted and
  72. * avoid special case handling of PGD allocations.
  73. */
  74. #define __sme_pa(x) (__pa(x) | sme_me_mask)
  75. #define __sme_pa_nodebug(x) (__pa_nodebug(x) | sme_me_mask)
  76. extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];
  77. static inline u64 sme_get_me_mask(void)
  78. {
  79. return sme_me_mask;
  80. }
  81. #endif /* __ASSEMBLY__ */
  82. #endif /* __X86_MEM_ENCRYPT_H__ */