@@ -71,6 +71,11 @@ struct dma_map_ops {
unsigned long (*get_merge_boundary)(struct device *dev);
};
+struct dma_memory_decrypted_ops {
+ void *(*map)(void *addr, unsigned long size);
+ void (*unmap)(void *addr);
+};
+
#ifdef CONFIG_DMA_OPS
#include <asm/dma-mapping.h>
@@ -374,6 +379,10 @@ static inline void debug_dma_dump_mappings(struct device *dev)
}
#endif /* CONFIG_DMA_API_DEBUG */
+void *dma_map_decrypted(void *addr, unsigned long size);
+int dma_unmap_decrypted(void *addr, unsigned long size);
+
extern const struct dma_map_ops dma_dummy_ops;
+extern struct dma_memory_decrypted_ops dma_memory_generic_decrypted_ops;
#endif /* _LINUX_DMA_MAP_OPS_H */
@@ -13,11 +13,13 @@
#include <linux/of_device.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
+#include <asm/set_memory.h>
#include "debug.h"
#include "direct.h"
bool dma_default_coherent;
+struct dma_memory_decrypted_ops dma_memory_generic_decrypted_ops;
/*
* Managed DMA API
*/
@@ -736,3 +738,23 @@ unsigned long dma_get_merge_boundary(struct device *dev)
return ops->get_merge_boundary(dev);
}
EXPORT_SYMBOL_GPL(dma_get_merge_boundary);
+
+void *dma_map_decrypted(void *addr, unsigned long size)
+{
+ if (set_memory_decrypted((unsigned long)addr,
+ size / PAGE_SIZE))
+ return NULL;
+
+ if (dma_memory_generic_decrypted_ops.map)
+ return dma_memory_generic_decrypted_ops.map(addr, size);
+ else
+ return addr;
+}
+
+int dma_unmap_encrypted(void *addr, unsigned long size)
+{
+ if (dma_memory_generic_decrypted_ops.unmap)
+ dma_memory_generic_decrypted_ops.unmap(addr);
+
+ return set_memory_encrypted((unsigned long)addr, size / PAGE_SIZE);
+}