mem_encrypt.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * AMD Memory Encryption Support
  3. *
  4. * Copyright (C) 2016 Advanced Micro Devices, Inc.
  5. *
  6. * Author: Tom Lendacky <thomas.lendacky@amd.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #ifndef __X86_MEM_ENCRYPT_H__
  13. #define __X86_MEM_ENCRYPT_H__
  14. #ifndef __ASSEMBLY__
  15. #include <linux/init.h>
  16. #include <asm/bootparam.h>
  17. #ifdef CONFIG_AMD_MEM_ENCRYPT
  18. extern u64 sme_me_mask;
  19. extern bool sev_enabled;
  20. void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr,
  21. unsigned long decrypted_kernel_vaddr,
  22. unsigned long kernel_len,
  23. unsigned long encryption_wa,
  24. unsigned long encryption_pgd);
  25. void __init sme_early_encrypt(resource_size_t paddr,
  26. unsigned long size);
  27. void __init sme_early_decrypt(resource_size_t paddr,
  28. unsigned long size);
  29. void __init sme_map_bootdata(char *real_mode_data);
  30. void __init sme_unmap_bootdata(char *real_mode_data);
  31. void __init sme_early_init(void);
  32. void __init sme_encrypt_kernel(struct boot_params *bp);
  33. void __init sme_enable(struct boot_params *bp);
  34. int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size);
  35. int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);
  36. /* Architecture __weak replacement functions */
  37. void __init mem_encrypt_init(void);
  38. void __init mem_encrypt_free_decrypted_mem(void);
  39. bool sme_active(void);
  40. bool sev_active(void);
  41. #define __bss_decrypted __attribute__((__section__(".bss..decrypted")))
  42. #else /* !CONFIG_AMD_MEM_ENCRYPT */
  43. #define sme_me_mask 0ULL
  44. static inline void __init sme_early_encrypt(resource_size_t paddr,
  45. unsigned long size) { }
  46. static inline void __init sme_early_decrypt(resource_size_t paddr,
  47. unsigned long size) { }
  48. static inline void __init sme_map_bootdata(char *real_mode_data) { }
  49. static inline void __init sme_unmap_bootdata(char *real_mode_data) { }
  50. static inline void __init sme_early_init(void) { }
  51. static inline void __init sme_encrypt_kernel(struct boot_params *bp) { }
  52. static inline void __init sme_enable(struct boot_params *bp) { }
  53. static inline bool sme_active(void) { return false; }
  54. static inline bool sev_active(void) { return false; }
  55. static inline int __init
  56. early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; }
  57. static inline int __init
  58. early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; }
  59. #define __bss_decrypted
  60. #endif /* CONFIG_AMD_MEM_ENCRYPT */
  61. /*
  62. * The __sme_pa() and __sme_pa_nodebug() macros are meant for use when
  63. * writing to or comparing values from the cr3 register. Having the
  64. * encryption mask set in cr3 enables the PGD entry to be encrypted and
  65. * avoid special case handling of PGD allocations.
  66. */
  67. #define __sme_pa(x) (__pa(x) | sme_me_mask)
  68. #define __sme_pa_nodebug(x) (__pa_nodebug(x) | sme_me_mask)
  69. extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypted_unused[];
  70. #endif /* __ASSEMBLY__ */
  71. #endif /* __X86_MEM_ENCRYPT_H__ */