linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: andreas.herrmann@calxeda.com (Andreas Herrmann)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 3/7] ARM: dma-mapping: Always pass proper prot flags to iommu_map()
Date: Tue, 24 Sep 2013 19:40:36 +0200	[thread overview]
Message-ID: <20130924174036.GU4845@alberich> (raw)
In-Reply-To: <20130924153625.GD20774@mudshark.cambridge.arm.com>

On Tue, Sep 24, 2013 at 11:36:25AM -0400, Will Deacon wrote:
> On Tue, Sep 24, 2013 at 04:06:57PM +0100, Andreas Herrmann wrote:
> > ... otherwise it is impossible for the low level iommu driver to
> > figure out which pte flags should be used.
> > 
> > In __map_sg_chunk we can derive the flags from dma_data_direction.
> > 
> > In __iommu_create_mapping we should treat the memory like
> > DMA_BIDIRECTIONAL and pass both IOMMU_READ and IOMMU_WRITE to
> > iommu_map.
> > __iommu_create_mapping is used during dma_alloc_coherent (via
> > arm_iommu_alloc_attrs).  AFAIK dma_alloc_coherent is responsible for
> > allocation _and_ mapping.  I think this implies that access to the
> > mapped pages should be allowed.
> > 
> > Cc: Marek Szyprowski <m.szyprowski@samsung.com>
> > Signed-off-by: Andreas Herrmann <andreas.herrmann@calxeda.com>
> > ---
> >  arch/arm/mm/dma-mapping.c |   20 ++++++++++++++++++--
> >  1 file changed, 18 insertions(+), 2 deletions(-)
> > 
> > diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
> > index f5e1a84..95abed8 100644
> > --- a/arch/arm/mm/dma-mapping.c
> > +++ b/arch/arm/mm/dma-mapping.c
> > @@ -1232,7 +1232,8 @@ __iommu_create_mapping(struct device *dev, struct page **pages, size_t size)
> >  				break;
> >  
> >  		len = (j - i) << PAGE_SHIFT;
> > -		ret = iommu_map(mapping->domain, iova, phys, len, 0);
> > +		ret = iommu_map(mapping->domain, iova, phys, len,
> > +				IOMMU_READ|IOMMU_WRITE);
> >  		if (ret < 0)
> >  			goto fail;
> >  		iova += len;
> > @@ -1444,6 +1445,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
> >  	int ret = 0;
> >  	unsigned int count;
> >  	struct scatterlist *s;
> > +	int prot;
> >  
> >  	size = PAGE_ALIGN(size);
> >  	*handle = DMA_ERROR_CODE;
> > @@ -1460,7 +1462,21 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
> >  			!dma_get_attr(DMA_ATTR_SKIP_CPU_SYNC, attrs))
> >  			__dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
> >  
> > -		ret = iommu_map(mapping->domain, iova, phys, len, 0);
> > +		switch (dir) {
> > +		case DMA_BIDIRECTIONAL:
> > +			prot = IOMMU_READ | IOMMU_WRITE;
> > +			break;
> > +		case DMA_TO_DEVICE:
> > +			prot = IOMMU_READ;
> > +			break;
> > +		case DMA_FROM_DEVICE:
> > +			prot = IOMMU_WRITE;
> > +			break;
> > +		default:
> > +			prot = 0;
> > +		}
> > +
> > +		ret = iommu_map(mapping->domain, iova, phys, len, prot);
> 
> I already added this code to arm_coherent_iommu_map_page but forgot to
> update the rest of the time. Could you shift the switch into a helper and
> call that instead of inlining it explicitly?

Yes, will do so.


Andreas

  reply	other threads:[~2013-09-24 17:40 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-24 15:06 [PATCH 0/7]: iommu/arm-smmu: Misc fixes/adaptions Andreas Herrmann
2013-09-24 15:06 ` [PATCH 1/7] iommu/arm-smmu: Switch to arch_initcall for driver registration Andreas Herrmann
2013-09-24 15:14   ` Andreas Herrmann
2013-09-24 15:19     ` Will Deacon
2013-09-24 15:06 ` [PATCH 2/7] iommu/arm-smmu: Calculate SMMU_CB_BASE from smmu register values Andreas Herrmann
2013-09-24 15:34   ` Will Deacon
2013-09-24 18:07     ` Andreas Herrmann
2013-09-25 16:43       ` Will Deacon
2013-09-24 15:06 ` [PATCH 3/7] ARM: dma-mapping: Always pass proper prot flags to iommu_map() Andreas Herrmann
2013-09-24 15:36   ` Will Deacon
2013-09-24 17:40     ` Andreas Herrmann [this message]
2013-09-24 15:06 ` [PATCH 4/7] iommu/arm-smmu: Check for num_context_irqs > 0 to avoid divide by zero exception Andreas Herrmann
2013-09-24 15:40   ` Will Deacon
2013-09-25 10:50     ` Andreas Herrmann
2013-09-24 15:06 ` [PATCH 5/7] iommu/arm-smmu: Add function that isolates all masters for all SMMUs Andreas Herrmann
2013-09-24 15:07 ` [PATCH 6/7] iommu/arm-smmu: Add module parameter arm-smmu=off|force_isolation Andreas Herrmann
2013-09-24 15:42   ` Will Deacon
2013-09-25 14:56     ` Andreas Herrmann
2013-09-25 15:57     ` Joerg Roedel
2013-09-24 15:07 ` [PATCH 7/7] iommu/arm-smmu: Clear global and context bank fault status and syndrome registers Andreas Herrmann
2013-09-24 15:42   ` Will Deacon
2013-09-24 18:32     ` Andreas Herrmann
2013-09-25 16:49       ` Will Deacon
2013-09-25 18:20         ` Andreas Herrmann
2013-09-24 15:31 ` [PATCH 0/7]: iommu/arm-smmu: Misc fixes/adaptions Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130924174036.GU4845@alberich \
    --to=andreas.herrmann@calxeda.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).