iommu/dma: Add support for mapping memory as device memory
PATCH 1/1 iommu/dma: Add support for mapping memory as device memory
Add DMA_ATTRS_DEVICE_MAP attribute to support mapping memory as device memory.
--- drivers/iommu/dma-iommu.c | 3 +++ include/linux/dma-mapping.h | 6 ++++++ 2 files changed, 9 insertions(+)
drivers/iommu/dma-iommu.c +3 -0
@@ -388,6 +388,9 @@ static int dma_info_to_prot(enum dma_data_direction dir, bool coherent,if (attrs &DMA_ATTR_PRIVILEGED ) prot |=IOMMU_PRIV ; +if (attrs &DMA_ATTR_DEVICE_MAP ) + prot |=IOMMU_MMIO ; +switch (dir) {case DMA_BIDIRECTIONAL :return prot |IOMMU_READ |IOMMU_WRITE ;
include/linux/dma-mapping.h +6 -0
@@ -68,6 +68,12 @@#define DMA_ATTR_PRIVILEGED (1UL << 9)/* +* DMA_ATTR_DEVICE_MAP: This specifies DMA-mapping subsystem to map memory +* as device memory. +*/ +#define DMA_ATTR_DEVICE_MAP (1UL << 10) + +/* * A dma_addr_t can hold any valid DMA or bus address for the platform. * It can be given to a device to use as a DMA source or target. A CPU cannot * reference a dma_addr_t directly because there may be translation between
Signature · 1 line
2.7.4
From what I can tell, dma_map_resource already does this (see iommu_dma_map_resource). Can you use that?
(also, dropping internal MLs)
Mikko
Quoted 41 lines · Ashish Mhetre
Add
DMA_ATTRS_DEVICE_MAPattribute to support mapping memory as device memory.Signed-off-by Ashish Mhetre <[email protected]>--- drivers/iommu/dma-iommu.c | 3 +++ include/linux/dma-mapping.h | 6 ++++++ 2 files changed, 9 insertions(+)drivers/iommu/dma-iommu.c +3
-0@@ -388,6 +388,9 @@ static int dma_info_to_prot(enum dma_data_direction dir, bool coherent,if (attrs &DMA_ATTR_PRIVILEGED ) prot |=IOMMU_PRIV ; +if (attrs &DMA_ATTR_DEVICE_MAP ) + prot |=IOMMU_MMIO ; +switch (dir) {case DMA_BIDIRECTIONAL :return prot |IOMMU_READ |IOMMU_WRITE ;include/linux/dma-mapping.h +6
-0@@ -68,6 +68,12 @@#define DMA_ATTR_PRIVILEGED (1UL << 9)/* +* DMA_ATTR_DEVICE_MAP: This specifies DMA-mapping subsystem to map memory +* as device memory. +*/ +#define DMA_ATTR_DEVICE_MAP (1UL << 10) + +/* * A dma_addr_t can hold any valid DMA or bus address for the platform. * It can be given to a device to use as a DMA source or target. A CPU cannot * reference a dma_addr_t directly because there may be translation between
Can you explain why it is necessary? Can you also include a client driver patches that uses this new attribute? Including the patches that uses this attribute would make it easy to upstream.
-KR
-----Original Message-----
From: Ashish Mhetre <[email protected]>
Sent: Tuesday, August 4, 2020 12:53 AM
To: Krishna Reddy <[email protected]>; Thierry Reding <[email protected]>; Jonathan Hunter <[email protected]>; Stephen Warren <[email protected]>; Sachin Nikam <[email protected]>
Cc: SW-Mobile-Linux-Upstreaming <[email protected]>; SW-Mobile-Memory-Core <[email protected]>; [email protected]; Ashish Mhetre <[email protected]>
Subject: [PATCH] iommu/dma: Add support for mapping memory as device memory
Add DMA_ATTRS_DEVICE_MAP attribute to support mapping memory as device memory.
--- drivers/iommu/dma-iommu.c | 3 +++ include/linux/dma-mapping.h | 6 ++++++ 2 files changed, 9 insertions(+)
drivers/iommu/dma-iommu.c +3 -0
@@ -388,6 +388,9 @@ static int dma_info_to_prot(enum dma_data_direction dir, bool coherent,if (attrs &DMA_ATTR_PRIVILEGED ) prot |=IOMMU_PRIV ; +if (attrs &DMA_ATTR_DEVICE_MAP ) + prot |=IOMMU_MMIO ; +switch (dir) {case DMA_BIDIRECTIONAL : return prot | IOMMU_READ | IOMMU_WRITE; diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index 330ad58..b0cb1b3 100644
include/linux/dma-mapping.h +7 -0
@@ -68,6 +68,12 @@#define DMA_ATTR_PRIVILEGED (1UL << 9)/* +* DMA_ATTR_DEVICE_MAP: This specifies DMA-mapping subsystem to map +memory +* as device memory. +*/ +#define DMA_ATTR_DEVICE_MAP (1UL << 10) + +/* * A dma_addr_t can hold any valid DMA or bus address for the platform. * It can be given to a device to use as a DMA source or target. A CPU cannot
* reference a dma_addr_t directly because there may be translation between
--
2.7.4