* [PATCH v2 1/2] iommu/dma: Implement dma_{map,unmap}_resource()
@ 2016-10-26 17:43 Robin Murphy
[not found] ` <4e84146ae49a4edd5f1226d76617be9aa92a58ee.1477503578.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2016-10-26 17:43 UTC (permalink / raw)
To: joro-zLv9SwRftAIdnm+yROfE0A, catalin.marinas-5wv7dgnIgG8,
will.deacon-5wv7dgnIgG8
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
niklas.soderlund+renesas-1zkq55x86MTxsAP9Fp7wbw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
With the new dma_{map,unmap}_resource() functions added to the DMA API
for the benefit of cases like slave DMA, add suitable implementations to
the arsenal of our generic layer. Since cache maintenance should not be
a concern, these can both be standalone callback implementations without
the need for arch code wrappers.
CC: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
---
v2: Use iommu_dma_unmap_page for symmetry, instead of being sneaky.
drivers/iommu/dma-iommu.c | 13 +++++++++++++
include/linux/dma-iommu.h | 4 ++++
2 files changed, 17 insertions(+)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index c5ab8667e6f2..a2fd90a6a782 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -624,6 +624,19 @@ void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
__iommu_dma_unmap(iommu_get_domain_for_dev(dev), sg_dma_address(sg));
}
+dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
+ size_t size, enum dma_data_direction dir, unsigned long attrs)
+{
+ return iommu_dma_map_page(dev, phys_to_page(phys), offset_in_page(phys),
+ size, dma_direction_to_prot(dir, false) | IOMMU_MMIO);
+}
+
+void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
+ size_t size, enum dma_data_direction dir, unsigned long attrs)
+{
+ iommu_dma_unmap_page(dev, handle, size, dir, attrs);
+}
+
int iommu_dma_supported(struct device *dev, u64 mask)
{
/*
diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h
index 32c589062bd9..7f7e9a7e3839 100644
--- a/include/linux/dma-iommu.h
+++ b/include/linux/dma-iommu.h
@@ -61,6 +61,10 @@ void iommu_dma_unmap_page(struct device *dev, dma_addr_t handle, size_t size,
enum dma_data_direction dir, unsigned long attrs);
void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
enum dma_data_direction dir, unsigned long attrs);
+dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
+ size_t size, enum dma_data_direction dir, unsigned long attrs);
+void iommu_dma_unmap_resource(struct device *dev, dma_addr_t handle,
+ size_t size, enum dma_data_direction dir, unsigned long attrs);
int iommu_dma_supported(struct device *dev, u64 mask);
int iommu_dma_mapping_error(struct device *dev, dma_addr_t dma_addr);
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/2] arm64: Wire up iommu_dma_{map, unmap}_resource()
[not found] ` <4e84146ae49a4edd5f1226d76617be9aa92a58ee.1477503578.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
@ 2016-10-26 17:43 ` Robin Murphy
2016-11-10 12:24 ` [PATCH v2 1/2] iommu/dma: Implement dma_{map,unmap}_resource() Joerg Roedel
1 sibling, 0 replies; 5+ messages in thread
From: Robin Murphy @ 2016-10-26 17:43 UTC (permalink / raw)
To: joro-zLv9SwRftAIdnm+yROfE0A, catalin.marinas-5wv7dgnIgG8,
will.deacon-5wv7dgnIgG8
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
niklas.soderlund+renesas-1zkq55x86MTxsAP9Fp7wbw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
With no coherency to worry about, just plug'em straight in.
CC: Catalin Marinas <catalin.marinas-5wv7dgnIgG8@public.gmane.org>
CC: Will Deacon <will.deacon-5wv7dgnIgG8@public.gmane.org>
Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
---
arch/arm64/mm/dma-mapping.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index 3f74d0d98de6..5cd0a383b14b 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -796,6 +796,8 @@ static void __iommu_unmap_sg_attrs(struct device *dev,
.sync_single_for_device = __iommu_sync_single_for_device,
.sync_sg_for_cpu = __iommu_sync_sg_for_cpu,
.sync_sg_for_device = __iommu_sync_sg_for_device,
+ .map_resource = iommu_dma_map_resource,
+ .unmap_resource = iommu_dma_unmap_resource,
.dma_supported = iommu_dma_supported,
.mapping_error = iommu_dma_mapping_error,
};
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] iommu/dma: Implement dma_{map,unmap}_resource()
[not found] ` <4e84146ae49a4edd5f1226d76617be9aa92a58ee.1477503578.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2016-10-26 17:43 ` [PATCH v2 2/2] arm64: Wire up iommu_dma_{map, unmap}_resource() Robin Murphy
@ 2016-11-10 12:24 ` Joerg Roedel
[not found] ` <20161110122420.GH9996-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
1 sibling, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2016-11-10 12:24 UTC (permalink / raw)
To: Robin Murphy
Cc: catalin.marinas-5wv7dgnIgG8,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
will.deacon-5wv7dgnIgG8,
niklas.soderlund+renesas-1zkq55x86MTxsAP9Fp7wbw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Wed, Oct 26, 2016 at 06:43:56PM +0100, Robin Murphy wrote:
> With the new dma_{map,unmap}_resource() functions added to the DMA API
> for the benefit of cases like slave DMA, add suitable implementations to
> the arsenal of our generic layer. Since cache maintenance should not be
> a concern, these can both be standalone callback implementations without
> the need for arch code wrappers.
>
> CC: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
> Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
> ---
>
> v2: Use iommu_dma_unmap_page for symmetry, instead of being sneaky.
>
> drivers/iommu/dma-iommu.c | 13 +++++++++++++
> include/linux/dma-iommu.h | 4 ++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> index c5ab8667e6f2..a2fd90a6a782 100644
> --- a/drivers/iommu/dma-iommu.c
> +++ b/drivers/iommu/dma-iommu.c
> @@ -624,6 +624,19 @@ void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
> __iommu_dma_unmap(iommu_get_domain_for_dev(dev), sg_dma_address(sg));
> }
>
> +dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
> + size_t size, enum dma_data_direction dir, unsigned long attrs)
> +{
> + return iommu_dma_map_page(dev, phys_to_page(phys), offset_in_page(phys),
> + size, dma_direction_to_prot(dir, false) | IOMMU_MMIO);
> +}
Isn't the whole point of map_resource that we can map regions which have
no 'struct page' associated? The use phys_to_page() will certainly not
do the right thing here.
Joerg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] iommu/dma: Implement dma_{map,unmap}_resource()
[not found] ` <20161110122420.GH9996-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
@ 2016-11-10 14:30 ` Robin Murphy
[not found] ` <1ae5dc0f-2e59-3e10-a61a-1f5452ad560f-5wv7dgnIgG8@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Robin Murphy @ 2016-11-10 14:30 UTC (permalink / raw)
To: Joerg Roedel
Cc: catalin.marinas-5wv7dgnIgG8,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
will.deacon-5wv7dgnIgG8,
niklas.soderlund+renesas-1zkq55x86MTxsAP9Fp7wbw,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On 10/11/16 12:24, Joerg Roedel wrote:
> On Wed, Oct 26, 2016 at 06:43:56PM +0100, Robin Murphy wrote:
>> With the new dma_{map,unmap}_resource() functions added to the DMA API
>> for the benefit of cases like slave DMA, add suitable implementations to
>> the arsenal of our generic layer. Since cache maintenance should not be
>> a concern, these can both be standalone callback implementations without
>> the need for arch code wrappers.
>>
>> CC: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
>> Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
>> ---
>>
>> v2: Use iommu_dma_unmap_page for symmetry, instead of being sneaky.
>>
>> drivers/iommu/dma-iommu.c | 13 +++++++++++++
>> include/linux/dma-iommu.h | 4 ++++
>> 2 files changed, 17 insertions(+)
>>
>> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
>> index c5ab8667e6f2..a2fd90a6a782 100644
>> --- a/drivers/iommu/dma-iommu.c
>> +++ b/drivers/iommu/dma-iommu.c
>> @@ -624,6 +624,19 @@ void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
>> __iommu_dma_unmap(iommu_get_domain_for_dev(dev), sg_dma_address(sg));
>> }
>>
>> +dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
>> + size_t size, enum dma_data_direction dir, unsigned long attrs)
>> +{
>> + return iommu_dma_map_page(dev, phys_to_page(phys), offset_in_page(phys),
>> + size, dma_direction_to_prot(dir, false) | IOMMU_MMIO);
>> +}
>
> Isn't the whole point of map_resource that we can map regions which have
> no 'struct page' associated? The use phys_to_page() will certainly not
> do the right thing here.
Perhaps it's a bit cheeky, but the struct page pointer is never
dereferenced - the only thing iommu_dma_map_page() does with it is
immediately convert it back again. Is there ever a case where
page_to_phys(phys_to_page(phys)) != phys ?
Robin.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/2] iommu/dma: Implement dma_{map,unmap}_resource()
[not found] ` <1ae5dc0f-2e59-3e10-a61a-1f5452ad560f-5wv7dgnIgG8@public.gmane.org>
@ 2016-11-10 18:37 ` Catalin Marinas
0 siblings, 0 replies; 5+ messages in thread
From: Catalin Marinas @ 2016-11-10 18:37 UTC (permalink / raw)
To: Robin Murphy
Cc: niklas.soderlund+renesas-1zkq55x86MTxsAP9Fp7wbw,
will.deacon-5wv7dgnIgG8,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
On Thu, Nov 10, 2016 at 02:30:04PM +0000, Robin Murphy wrote:
> On 10/11/16 12:24, Joerg Roedel wrote:
> > On Wed, Oct 26, 2016 at 06:43:56PM +0100, Robin Murphy wrote:
> >> With the new dma_{map,unmap}_resource() functions added to the DMA API
> >> for the benefit of cases like slave DMA, add suitable implementations to
> >> the arsenal of our generic layer. Since cache maintenance should not be
> >> a concern, these can both be standalone callback implementations without
> >> the need for arch code wrappers.
> >>
> >> CC: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
> >> Signed-off-by: Robin Murphy <robin.murphy-5wv7dgnIgG8@public.gmane.org>
> >> ---
> >>
> >> v2: Use iommu_dma_unmap_page for symmetry, instead of being sneaky.
> >>
> >> drivers/iommu/dma-iommu.c | 13 +++++++++++++
> >> include/linux/dma-iommu.h | 4 ++++
> >> 2 files changed, 17 insertions(+)
> >>
> >> diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
> >> index c5ab8667e6f2..a2fd90a6a782 100644
> >> --- a/drivers/iommu/dma-iommu.c
> >> +++ b/drivers/iommu/dma-iommu.c
> >> @@ -624,6 +624,19 @@ void iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents,
> >> __iommu_dma_unmap(iommu_get_domain_for_dev(dev), sg_dma_address(sg));
> >> }
> >>
> >> +dma_addr_t iommu_dma_map_resource(struct device *dev, phys_addr_t phys,
> >> + size_t size, enum dma_data_direction dir, unsigned long attrs)
> >> +{
> >> + return iommu_dma_map_page(dev, phys_to_page(phys), offset_in_page(phys),
> >> + size, dma_direction_to_prot(dir, false) | IOMMU_MMIO);
> >> +}
> >
> > Isn't the whole point of map_resource that we can map regions which have
> > no 'struct page' associated? The use phys_to_page() will certainly not
> > do the right thing here.
>
> Perhaps it's a bit cheeky, but the struct page pointer is never
> dereferenced - the only thing iommu_dma_map_page() does with it is
> immediately convert it back again. Is there ever a case where
> page_to_phys(phys_to_page(phys)) != phys ?
Without SPARSEMEM_VMEMMAP or FLATMEM, it wouldn't work. For example,
__page_to_pfn() in the SPARSEMEM case, used by page_to_phys(), even
accesses the page structure (through page_to_section()).
If the page struct is not relevant to the iommu code in question, you
could factor it out into an __iommu_dma_map_pfn(). Or maybe move the
whole logic to iommu_dma_map_resource() and call it from
iommu_dma_map_page() with the page_to_phys(page) argument.
--
Catalin
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-11-10 18:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-26 17:43 [PATCH v2 1/2] iommu/dma: Implement dma_{map,unmap}_resource() Robin Murphy
[not found] ` <4e84146ae49a4edd5f1226d76617be9aa92a58ee.1477503578.git.robin.murphy-5wv7dgnIgG8@public.gmane.org>
2016-10-26 17:43 ` [PATCH v2 2/2] arm64: Wire up iommu_dma_{map, unmap}_resource() Robin Murphy
2016-11-10 12:24 ` [PATCH v2 1/2] iommu/dma: Implement dma_{map,unmap}_resource() Joerg Roedel
[not found] ` <20161110122420.GH9996-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
2016-11-10 14:30 ` Robin Murphy
[not found] ` <1ae5dc0f-2e59-3e10-a61a-1f5452ad560f-5wv7dgnIgG8@public.gmane.org>
2016-11-10 18:37 ` Catalin Marinas
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).