mem_encrypt.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. void sme_encrypt_execute(unsigned long encrypted_kernel_vaddr,
  20. unsigned long decrypted_kernel_vaddr,
  21. unsigned long kernel_len,
  22. unsigned long encryption_wa,
  23. unsigned long encryption_pgd);
  24. void __init sme_early_encrypt(resource_size_t paddr,
  25. unsigned long size);
  26. void __init sme_early_decrypt(resource_size_t paddr,
  27. unsigned long size);
  28. void __init sme_map_bootdata(char *real_mode_data);
  29. void __init sme_unmap_bootdata(char *real_mode_data);
  30. void __init sme_early_init(void);
  31. void __init sme_encrypt_kernel(void);
  32. void __init sme_enable(struct boot_params *bp);
  33. int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size);
  34. int __init early_set_memory_encrypted(unsigned long vaddr, unsigned long size);
  35. /* Architecture __weak replacement functions */
  36. void __init mem_encrypt_init(void);
  37. void swiotlb_set_mem_attributes(void *vaddr, unsigned long size);
  38. bool sme_active(void);
  39. bool sev_active(void);
  40. #else /* !CONFIG_AMD_MEM_ENCRYPT */
  41. #define sme_me_mask 0ULL
  42. static inline void __init sme_early_encrypt(resource_size_t paddr,
  43. unsigned long size) { }
  44. static inline void __init sme_early_decrypt(resource_size_t paddr,
  45. unsigned long size) { }
  46. static inline void __init sme_map_bootdata(char *real_mode_data) { }
  47. static inline void __init sme_unmap_bootdata(char *real_mode_data) { }
  48. static inline void __init sme_early_init(void) { }
  49. static inline void __init sme_encrypt_kernel(void) { }
  50. static inline void __init sme_enable(struct boot_params *bp) { }
  51. static inline bool sme_active(void) { return false; }
  52. static inline bool sev_active(void) { return false; }
  53. static inline int __init
  54. early_set_memory_decrypted(unsigned long vaddr, unsigned long size) { return 0; }
  55. static inline int __init
  56. early_set_memory_encrypted(unsigned long vaddr, unsigned long size) { return 0; }
  57. #endif /* CONFIG_AMD_MEM_ENCRYPT */
  58. /*
  59. * The __sme_pa() and __sme_pa_nodebug() macros are meant for use when
  60. * writing to or comparing values from the cr3 register. Having the
  61. * encryption mask set in cr3 enables the PGD entry to be encrypted and
  62. * avoid special case handling of PGD allocations.
  63. */
  64. #define __sme_pa(x) (__pa(x) | sme_me_mask)
  65. #define __sme_pa_nodebug(x) (__pa_nodebug(x) | sme_me_mask)
  66. #endif /* __ASSEMBLY__ */
  67. #endif /* __X86_MEM_ENCRYPT_H__ */