devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yong Wu <yong.wu@mediatek.com>
To: Robin Murphy <Robin.Murphy@arm.com>
Cc: Joerg Roedel <joro@8bytes.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	"youlin.pei@mediatek.com" <youlin.pei@mediatek.com>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"srv_heupstream@mediatek.com" <srv_heupstream@mediatek.com>,
	Will Deacon <Will.Deacon@arm.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Tomasz Figa <tfiga@google.com>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	Daniel Kurtz <djkurtz@google.com>,
	"yingjoe.chen@mediatek.com" <yingjoe.chen@mediatek.com>,
	nd <nd@arm.com>,
	"linux-arm-kernel@lists.infradead.org" <linux-arm-kernel@l>
Subject: Re: [PATCH v2 04/14] iommu/io-pgtable-arm-v7s: Add paddr_to_iopte and iopte_to_paddr helpers
Date: Fri, 2 Nov 2018 14:23:31 +0800	[thread overview]
Message-ID: <1541139811.22369.11.camel@mhfsdcap03> (raw)
In-Reply-To: <d24bd2a4-1030-e255-b339-d02eadc93f28@arm.com>

Hi Robin,

Thanks very much for your review.

On Thu, 2018-11-01 at 16:34 +0000, Robin Murphy wrote:
> [ apologies if anyone gets this twice, looks like our email's eaten 
> itself again... ]
> 
> On 24/09/2018 09:58, Yong Wu wrote:
> > Add two helper functions: paddr_to_iopte and iopte_to_paddr.
> 
> Nice and tidy! (although it will need rebasing now, but I think that's 
> just context conflicts)
> 
> > Signed-off-by: Yong Wu <yong.wu@mediatek.com>
> > ---
> >   drivers/iommu/io-pgtable-arm-v7s.c | 45 ++++++++++++++++++++++++++++----------
> >   1 file changed, 33 insertions(+), 12 deletions(-)
> > 
> > diff --git a/drivers/iommu/io-pgtable-arm-v7s.c b/drivers/iommu/io-pgtable-arm-v7s.c
> > index b5948ba..fa3b9ec 100644
> > --- a/drivers/iommu/io-pgtable-arm-v7s.c
> > +++ b/drivers/iommu/io-pgtable-arm-v7s.c
> > @@ -173,18 +173,38 @@ struct arm_v7s_io_pgtable {
> >   	spinlock_t		split_lock;
> >   };
> >   
> > +static bool arm_v7s_pte_is_cont(arm_v7s_iopte pte, int lvl);
> > +
> >   static dma_addr_t __arm_v7s_dma_addr(void *pages)
> >   {
> >   	return (dma_addr_t)virt_to_phys(pages);
> >   }
> >   
> > -static arm_v7s_iopte *iopte_deref(arm_v7s_iopte pte, int lvl)
> > +static arm_v7s_iopte paddr_to_iopte(phys_addr_t paddr, int lvl,
> > +				    struct arm_v7s_io_pgtable *data)
> 
> Nit: it seems to work out a little cleaner if we pass the io_pgtable_cfg 
> to these helpers directly, rather than re-deriving it from data each time.

I will use "io_pgtable_cfg" instead of "arm_v7s_io_pgtable" in the next
version. This is a minor change and I will keep your R-b.

> 
> Otherwise, though,
> 
> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
> 
> >   {
> > +	return paddr & ARM_V7S_LVL_MASK(lvl);
> > +}
> > +
> > +static phys_addr_t iopte_to_paddr(arm_v7s_iopte pte, int lvl,
> > +				  struct arm_v7s_io_pgtable *data)
> > +{
> > +	arm_v7s_iopte mask;
> > +
> >   	if (ARM_V7S_PTE_IS_TABLE(pte, lvl))
> > -		pte &= ARM_V7S_TABLE_MASK;
> > +		mask = ARM_V7S_TABLE_MASK;
> > +	else if (arm_v7s_pte_is_cont(pte, lvl))
> > +		mask = ARM_V7S_LVL_MASK(lvl) * ARM_V7S_CONT_PAGES;
> >   	else
> > -		pte &= ARM_V7S_LVL_MASK(lvl);
> > -	return phys_to_virt(pte);
> > +		mask = ARM_V7S_LVL_MASK(lvl);
> > +
> > +	return pte & mask;
> > +}
> > +
> > +static arm_v7s_iopte *iopte_deref(arm_v7s_iopte pte, int lvl,
> > +				  struct arm_v7s_io_pgtable *data)
> > +{
> > +	return phys_to_virt(iopte_to_paddr(pte, lvl, data));
> >   }
> >   
> >   static void *__arm_v7s_alloc_table(int lvl, gfp_t gfp,
> > @@ -396,7 +416,7 @@ static int arm_v7s_init_pte(struct arm_v7s_io_pgtable *data,
> >   	if (num_entries > 1)
> >   		pte = arm_v7s_pte_to_cont(pte, lvl);
> >   
> > -	pte |= paddr & ARM_V7S_LVL_MASK(lvl);
> > +	pte |= paddr_to_iopte(paddr, lvl, data);
> >   
> >   	__arm_v7s_set_pte(ptep, pte, num_entries, cfg);
> >   	return 0;
> > @@ -462,7 +482,7 @@ static int __arm_v7s_map(struct arm_v7s_io_pgtable *data, unsigned long iova,
> >   	}
> >   
> >   	if (ARM_V7S_PTE_IS_TABLE(pte, lvl)) {
> > -		cptep = iopte_deref(pte, lvl);
> > +		cptep = iopte_deref(pte, lvl, data);
> >   	} else if (pte) {
> >   		/* We require an unmap first */
> >   		WARN_ON(!selftest_running);
> > @@ -512,7 +532,8 @@ static void arm_v7s_free_pgtable(struct io_pgtable *iop)
> >   		arm_v7s_iopte pte = data->pgd[i];
> >   
> >   		if (ARM_V7S_PTE_IS_TABLE(pte, 1))
> > -			__arm_v7s_free_table(iopte_deref(pte, 1), 2, data);
> > +			__arm_v7s_free_table(iopte_deref(pte, 1, data),
> > +					     2, data);
> >   	}
> >   	__arm_v7s_free_table(data->pgd, 1, data);
> >   	kmem_cache_destroy(data->l2_tables);
> > @@ -582,7 +603,7 @@ static size_t arm_v7s_split_blk_unmap(struct arm_v7s_io_pgtable *data,
> >   		if (!ARM_V7S_PTE_IS_TABLE(pte, 1))
> >   			return 0;
> >   
> > -		tablep = iopte_deref(pte, 1);
> > +		tablep = iopte_deref(pte, 1, data);
> >   		return __arm_v7s_unmap(data, iova, size, 2, tablep);
> >   	}
> >   
> > @@ -640,7 +661,7 @@ static size_t __arm_v7s_unmap(struct arm_v7s_io_pgtable *data,
> >   				io_pgtable_tlb_add_flush(iop, iova, blk_size,
> >   					ARM_V7S_BLOCK_SIZE(lvl + 1), false);
> >   				io_pgtable_tlb_sync(iop);
> > -				ptep = iopte_deref(pte[i], lvl);
> > +				ptep = iopte_deref(pte[i], lvl, data);
> >   				__arm_v7s_free_table(ptep, lvl + 1, data);
> >   			} else {
> >   				io_pgtable_tlb_add_flush(iop, iova, blk_size,
> > @@ -658,7 +679,7 @@ static size_t __arm_v7s_unmap(struct arm_v7s_io_pgtable *data,
> >   	}
> >   
> >   	/* Keep on walkin' */
> > -	ptep = iopte_deref(pte[0], lvl);
> > +	ptep = iopte_deref(pte[0], lvl, data);
> >   	return __arm_v7s_unmap(data, iova, size, lvl + 1, ptep);
> >   }
> >   
> > @@ -684,7 +705,7 @@ static phys_addr_t arm_v7s_iova_to_phys(struct io_pgtable_ops *ops,
> >   	do {
> >   		ptep += ARM_V7S_LVL_IDX(iova, ++lvl);
> >   		pte = READ_ONCE(*ptep);
> > -		ptep = iopte_deref(pte, lvl);
> > +		ptep = iopte_deref(pte, lvl, data);
> >   	} while (ARM_V7S_PTE_IS_TABLE(pte, lvl));
> >   
> >   	if (!ARM_V7S_PTE_IS_VALID(pte))
> > @@ -693,7 +714,7 @@ static phys_addr_t arm_v7s_iova_to_phys(struct io_pgtable_ops *ops,
> >   	mask = ARM_V7S_LVL_MASK(lvl);
> >   	if (arm_v7s_pte_is_cont(pte, lvl))
> >   		mask *= ARM_V7S_CONT_PAGES;
> > -	return (pte & mask) | (iova & ~mask);
> > +	return iopte_to_paddr(pte, lvl, data) | (iova & ~mask);
> >   }
> >   
> >   static struct io_pgtable *arm_v7s_alloc_pgtable(struct io_pgtable_cfg *cfg,
> > 
> _______________________________________________
> Linux-mediatek mailing list
> Linux-mediatek@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-mediatek

  reply	other threads:[~2018-11-02  6:23 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-24  8:58 [PATCH v2 00/14] MT8183 IOMMU SUPPORT Yong Wu
2018-09-24  8:58 ` [PATCH v2 02/14] iommu/mediatek: Use a struct as the platform data Yong Wu
2018-09-24  8:58 ` [PATCH v2 04/14] iommu/io-pgtable-arm-v7s: Add paddr_to_iopte and iopte_to_paddr helpers Yong Wu
2018-11-01 16:34   ` Robin Murphy
2018-11-02  6:23     ` Yong Wu [this message]
     [not found] ` <1537779534-23575-1-git-send-email-yong.wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2018-09-24  8:58   ` [PATCH v2 01/14] dt-bindings: mediatek: Add binding for mt8183 IOMMU and SMI Yong Wu
2018-09-24  8:58   ` [PATCH v2 03/14] memory: mtk-smi: Use a general config_port interface Yong Wu
2018-09-24  8:58   ` [PATCH v2 05/14] iommu/io-pgtable-arm-v7s: Extend MediaTek 4GB Mode Yong Wu
     [not found]     ` <1537779534-23575-6-git-send-email-yong.wu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2018-11-01 16:35       ` Robin Murphy
     [not found]         ` <2033be12-3d32-3155-4202-386281cbbaa0-5wv7dgnIgG8@public.gmane.org>
2018-11-02  6:23           ` Yong Wu
2018-09-24  8:58   ` [PATCH v2 08/14] memory: mtk-smi: Invoke pm runtime_callback to enable clocks Yong Wu
2018-09-24  8:58   ` [PATCH v2 09/14] memory: mtk-smi: Use a struct for the platform data for smi-common Yong Wu
2018-09-24  8:58   ` [PATCH v2 10/14] memory: mtk-smi: Add bus_sel for mt8183 Yong Wu
2018-09-24  8:58   ` [PATCH v2 11/14] iommu/mediatek: Add VLD_PA_RANGE register backup when suspend Yong Wu
2018-09-24  8:58   ` [PATCH v2 12/14] iommu/mediatek: Add shutdown callback Yong Wu
2018-09-24  8:58   ` [PATCH v2 13/14] memory: mtk-smi: Get rid of need_larbid Yong Wu
2018-09-24  8:58 ` [PATCH v2 06/14] iommu/mediatek: Add mt8183 IOMMU support Yong Wu
2018-09-24  8:58 ` [PATCH v2 07/14] iommu/mediatek: Add mmu1 support Yong Wu
2018-09-24  8:58 ` [PATCH v2 14/14] iommu/mediatek: Switch to SPDX license identifier Yong Wu

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=1541139811.22369.11.camel@mhfsdcap03 \
    --to=yong.wu@mediatek.com \
    --cc=Robin.Murphy@arm.com \
    --cc=Will.Deacon@arm.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=djkurtz@google.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-arm-kernel@l \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=nd@arm.com \
    --cc=robh+dt@kernel.org \
    --cc=srv_heupstream@mediatek.com \
    --cc=tfiga@google.com \
    --cc=yingjoe.chen@mediatek.com \
    --cc=youlin.pei@mediatek.com \
    /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).