@@ -52,8 +52,19 @@ bool sev_active(void);
#define __bss_decrypted __attribute__((__section__(".bss..decrypted")))
+/*
+ * The __sme_set() and __sme_clr() macros are useful for adding or removing
+ * the encryption mask from a value (e.g. when dealing with pagetable
+ * entries).
+ */
+#define __sme_set(x) ((x) | sme_me_mask)
+#define __sme_clr(x) ((x) & ~sme_me_mask)
+
#else /* !CONFIG_AMD_MEM_ENCRYPT */
+#define __sme_set(x) (x)
+#define __sme_clr(x) (x)
+
#define sme_me_mask 0ULL
static inline void __init sme_early_encrypt(resource_size_t paddr,
@@ -94,4 +105,22 @@ extern char __start_bss_decrypted[], __end_bss_decrypted[], __start_bss_decrypte
#endif /* __ASSEMBLY__ */
+#ifdef CONFIG_X86_MEM_ENCRYPT_COMMON
+
+extern dma_addr_t __mem_encrypt_dma_set(dma_addr_t daddr, phys_addr_t paddr);
+extern phys_addr_t __mem_encrypt_dma_clear(phys_addr_t paddr);
+
+#else
+static inline dma_addr_t __mem_encrypt_dma_set(dma_addr_t daddr, phys_addr_t paddr)
+{
+ return daddr;
+}
+
+static inline phys_addr_t __mem_encrypt_dma_clear(phys_addr_t paddr)
+{
+ return paddr;
+}
+#endif /* CONFIG_X86_MEM_ENCRYPT_COMMON */
+
+
#endif /* __X86_MEM_ENCRYPT_H__ */
@@ -1,6 +1,6 @@
#include <linux/mm.h>
-#include <linux/mem_encrypt.h>
#include <linux/dma-mapping.h>
+#include <asm/mem_encrypt.h>
#include <asm/mktme.h>
/*
@@ -49,12 +49,12 @@ static inline bool force_dma_unencrypted(struct device *dev)
*/
static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
{
- return __sme_set(__phys_to_dma(dev, paddr));
+ return __mem_encrypt_dma_set(__phys_to_dma(dev, paddr), paddr);
}
static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr)
{
- return __sme_clr(__dma_to_phys(dev, daddr));
+ return __mem_encrypt_dma_clear(__dma_to_phys(dev, daddr));
}
u64 dma_direct_get_required_mask(struct device *dev);
@@ -23,6 +23,16 @@
static inline bool sme_active(void) { return false; }
static inline bool sev_active(void) { return false; }
+static inline dma_addr_t __mem_encrypt_dma_set(dma_addr_t daddr, phys_addr_t paddr)
+{
+ return daddr;
+}
+
+static inline phys_addr_t __mem_encrypt_dma_clear(phys_addr_t paddr)
+{
+ return paddr;
+}
+
#endif /* CONFIG_ARCH_HAS_MEM_ENCRYPT */
static inline bool mem_encrypt_active(void)
@@ -35,19 +45,6 @@ static inline u64 sme_get_me_mask(void)
return sme_me_mask;
}
-#ifdef CONFIG_AMD_MEM_ENCRYPT
-/*
- * The __sme_set() and __sme_clr() macros are useful for adding or removing
- * the encryption mask from a value (e.g. when dealing with pagetable
- * entries).
- */
-#define __sme_set(x) ((x) | sme_me_mask)
-#define __sme_clr(x) ((x) & ~sme_me_mask)
-#else
-#define __sme_set(x) (x)
-#define __sme_clr(x) (x)
-#endif
-
#endif /* __ASSEMBLY__ */
#endif /* __MEM_ENCRYPT_H__ */