* [PATCH] iommu/dma: Add support for mapping memory as device memory
@ 2020-08-04 7:52 Ashish Mhetre
2020-08-04 8:56 ` Mikko Perttunen
2020-08-04 16:47 ` Krishna Reddy
0 siblings, 2 replies; 3+ messages in thread
From: Ashish Mhetre @ 2020-08-04 7:52 UTC (permalink / raw)
To: vdumpa, treding, jonathanh, swarren, Snikam
Cc: SW-Mobile-Linux-Upstreaming, SW-Mobile-Memory-Core, linux-tegra,
Ashish Mhetre
Add DMA_ATTRS_DEVICE_MAP attribute to support mapping memory as device
memory.
Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
---
drivers/iommu/dma-iommu.c | 3 +++
include/linux/dma-mapping.h | 6 ++++++
2 files changed, 9 insertions(+)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index 65ac889..0e411ef 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -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
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iommu/dma: Add support for mapping memory as device memory
2020-08-04 7:52 [PATCH] iommu/dma: Add support for mapping memory as device memory Ashish Mhetre
@ 2020-08-04 8:56 ` Mikko Perttunen
2020-08-04 16:47 ` Krishna Reddy
1 sibling, 0 replies; 3+ messages in thread
From: Mikko Perttunen @ 2020-08-04 8:56 UTC (permalink / raw)
To: Ashish Mhetre, vdumpa, treding, jonathanh, swarren, Snikam; +Cc: linux-tegra
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
On 8/4/20 10:52 AM, Ashish Mhetre wrote:
> Add DMA_ATTRS_DEVICE_MAP attribute to support mapping memory as device
> memory.
>
> Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
> ---
> drivers/iommu/dma-iommu.c | 3 +++
> include/linux/dma-mapping.h | 6 ++++++
> 2 files changed, 9 insertions(+)
>
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index 65ac889..0e411ef 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -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
> --- a/include/linux/dma-mapping.h
> +++ b/include/linux/dma-mapping.h
> @@ -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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] iommu/dma: Add support for mapping memory as device memory
2020-08-04 7:52 [PATCH] iommu/dma: Add support for mapping memory as device memory Ashish Mhetre
2020-08-04 8:56 ` Mikko Perttunen
@ 2020-08-04 16:47 ` Krishna Reddy
1 sibling, 0 replies; 3+ messages in thread
From: Krishna Reddy @ 2020-08-04 16:47 UTC (permalink / raw)
To: Ashish Mhetre, Thierry Reding, Jonathan Hunter, Stephen Warren,
Sachin Nikam
Cc: SW-Mobile-Linux-Upstreaming, SW-Mobile-Memory-Core, linux-tegra
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 <amhetre@nvidia.com>
Sent: Tuesday, August 4, 2020 12:53 AM
To: Krishna Reddy <vdumpa@nvidia.com>; Thierry Reding <treding@nvidia.com>; Jonathan Hunter <jonathanh@nvidia.com>; Stephen Warren <swarren@nvidia.com>; Sachin Nikam <Snikam@nvidia.com>
Cc: SW-Mobile-Linux-Upstreaming <SW-Mobile-Linux-Upstreaming@exchange.nvidia.com>; SW-Mobile-Memory-Core <SW-Mobile-Memory-Core@exchange.nvidia.com>; linux-tegra@vger.kernel.org; Ashish Mhetre <amhetre@nvidia.com>
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.
Signed-off-by: Ashish Mhetre <amhetre@nvidia.com>
---
drivers/iommu/dma-iommu.c | 3 +++
include/linux/dma-mapping.h | 6 ++++++
2 files changed, 9 insertions(+)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 65ac889..0e411ef 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -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
--- a/include/linux/dma-mapping.h
+++ b/include/linux/dma-mapping.h
@@ -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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-08-04 16:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-04 7:52 [PATCH] iommu/dma: Add support for mapping memory as device memory Ashish Mhetre
2020-08-04 8:56 ` Mikko Perttunen
2020-08-04 16:47 ` Krishna Reddy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).