All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org,
	jonathanh@nvidia.com, linux-tegra@vger.kernel.org
Subject: Re: [PATCH 1/3] iommu/tegra-smmu: Do not use PAGE_SHIFT and PAGE_MASK
Date: Thu, 24 Sep 2020 12:23:12 +0200	[thread overview]
Message-ID: <20200924102312.GG2483160@ulmo> (raw)
In-Reply-To: <20200911071643.17212-2-nicoleotsuka@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 2739 bytes --]

On Fri, Sep 11, 2020 at 12:16:41AM -0700, Nicolin Chen wrote:
> PAGE_SHIFT and PAGE_MASK are defined corresponding to the page size
> for CPU virtual addresses, which means PAGE_SHIFT could be a number
> other than 12, but tegra-smmu maintains fixed 4KB IOVA pages and has
> fixed [21:12] bit range for PTE entries.
> 
> So this patch replaces all PAGE_SHIFT/PAGE_MASK references with the
> macros defined with SMMU_PTE_SHIFT.
> 
> Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
> ---
>  drivers/iommu/tegra-smmu.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
> index 046add7acb61..789d21c01b77 100644
> --- a/drivers/iommu/tegra-smmu.c
> +++ b/drivers/iommu/tegra-smmu.c
> @@ -130,6 +130,11 @@ static inline u32 smmu_readl(struct tegra_smmu *smmu, unsigned long offset)
>  #define SMMU_PDE_SHIFT 22
>  #define SMMU_PTE_SHIFT 12
>  
> +#define SMMU_PAGE_MASK		(~(SMMU_SIZE_PT-1))
> +#define SMMU_OFFSET_IN_PAGE(x)	((unsigned long)(x) & ~SMMU_PAGE_MASK)
> +#define SMMU_PFN_PHYS(x)	((phys_addr_t)(x) << SMMU_PTE_SHIFT)
> +#define SMMU_PHYS_PFN(x)	((unsigned long)((x) >> SMMU_PTE_SHIFT))
> +
>  #define SMMU_PD_READABLE	(1 << 31)
>  #define SMMU_PD_WRITABLE	(1 << 30)
>  #define SMMU_PD_NONSECURE	(1 << 29)
> @@ -644,7 +649,7 @@ static void tegra_smmu_set_pte(struct tegra_smmu_as *as, unsigned long iova,
>  			       u32 *pte, dma_addr_t pte_dma, u32 val)
>  {
>  	struct tegra_smmu *smmu = as->smmu;
> -	unsigned long offset = offset_in_page(pte);
> +	unsigned long offset = SMMU_OFFSET_IN_PAGE(pte);
>  
>  	*pte = val;
>  
> @@ -726,7 +731,7 @@ __tegra_smmu_map(struct iommu_domain *domain, unsigned long iova,
>  		pte_attrs |= SMMU_PTE_WRITABLE;
>  
>  	tegra_smmu_set_pte(as, iova, pte, pte_dma,
> -			   __phys_to_pfn(paddr) | pte_attrs);
> +			   SMMU_PHYS_PFN(paddr) | pte_attrs);
>  
>  	return 0;
>  }
> @@ -790,7 +795,7 @@ static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain,
>  
>  	pfn = *pte & as->smmu->pfn_mask;
>  
> -	return PFN_PHYS(pfn);
> +	return SMMU_PFN_PHYS(pfn);
>  }
>  
>  static struct tegra_smmu *tegra_smmu_find(struct device_node *np)
> @@ -1108,7 +1113,8 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
>  	smmu->dev = dev;
>  	smmu->mc = mc;
>  
> -	smmu->pfn_mask = BIT_MASK(mc->soc->num_address_bits - PAGE_SHIFT) - 1;
> +	smmu->pfn_mask =
> +		BIT_MASK(mc->soc->num_address_bits - SMMU_PTE_SHIFT) - 1;

checkpatch no longer warns about lines longer than 80 characters. The
new limit is 100, so you can fit this all on one line.

But either way:

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 156 bytes --]

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

WARNING: multiple messages have this Message-ID (diff)
From: Thierry Reding <thierry.reding@gmail.com>
To: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: joro@8bytes.org, linux-kernel@vger.kernel.org,
	iommu@lists.linux-foundation.org, linux-tegra@vger.kernel.org,
	jonathanh@nvidia.com, vdumpa@nvidia.com
Subject: Re: [PATCH 1/3] iommu/tegra-smmu: Do not use PAGE_SHIFT and PAGE_MASK
Date: Thu, 24 Sep 2020 12:23:12 +0200	[thread overview]
Message-ID: <20200924102312.GG2483160@ulmo> (raw)
In-Reply-To: <20200911071643.17212-2-nicoleotsuka@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2739 bytes --]

On Fri, Sep 11, 2020 at 12:16:41AM -0700, Nicolin Chen wrote:
> PAGE_SHIFT and PAGE_MASK are defined corresponding to the page size
> for CPU virtual addresses, which means PAGE_SHIFT could be a number
> other than 12, but tegra-smmu maintains fixed 4KB IOVA pages and has
> fixed [21:12] bit range for PTE entries.
> 
> So this patch replaces all PAGE_SHIFT/PAGE_MASK references with the
> macros defined with SMMU_PTE_SHIFT.
> 
> Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
> ---
>  drivers/iommu/tegra-smmu.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
> index 046add7acb61..789d21c01b77 100644
> --- a/drivers/iommu/tegra-smmu.c
> +++ b/drivers/iommu/tegra-smmu.c
> @@ -130,6 +130,11 @@ static inline u32 smmu_readl(struct tegra_smmu *smmu, unsigned long offset)
>  #define SMMU_PDE_SHIFT 22
>  #define SMMU_PTE_SHIFT 12
>  
> +#define SMMU_PAGE_MASK		(~(SMMU_SIZE_PT-1))
> +#define SMMU_OFFSET_IN_PAGE(x)	((unsigned long)(x) & ~SMMU_PAGE_MASK)
> +#define SMMU_PFN_PHYS(x)	((phys_addr_t)(x) << SMMU_PTE_SHIFT)
> +#define SMMU_PHYS_PFN(x)	((unsigned long)((x) >> SMMU_PTE_SHIFT))
> +
>  #define SMMU_PD_READABLE	(1 << 31)
>  #define SMMU_PD_WRITABLE	(1 << 30)
>  #define SMMU_PD_NONSECURE	(1 << 29)
> @@ -644,7 +649,7 @@ static void tegra_smmu_set_pte(struct tegra_smmu_as *as, unsigned long iova,
>  			       u32 *pte, dma_addr_t pte_dma, u32 val)
>  {
>  	struct tegra_smmu *smmu = as->smmu;
> -	unsigned long offset = offset_in_page(pte);
> +	unsigned long offset = SMMU_OFFSET_IN_PAGE(pte);
>  
>  	*pte = val;
>  
> @@ -726,7 +731,7 @@ __tegra_smmu_map(struct iommu_domain *domain, unsigned long iova,
>  		pte_attrs |= SMMU_PTE_WRITABLE;
>  
>  	tegra_smmu_set_pte(as, iova, pte, pte_dma,
> -			   __phys_to_pfn(paddr) | pte_attrs);
> +			   SMMU_PHYS_PFN(paddr) | pte_attrs);
>  
>  	return 0;
>  }
> @@ -790,7 +795,7 @@ static phys_addr_t tegra_smmu_iova_to_phys(struct iommu_domain *domain,
>  
>  	pfn = *pte & as->smmu->pfn_mask;
>  
> -	return PFN_PHYS(pfn);
> +	return SMMU_PFN_PHYS(pfn);
>  }
>  
>  static struct tegra_smmu *tegra_smmu_find(struct device_node *np)
> @@ -1108,7 +1113,8 @@ struct tegra_smmu *tegra_smmu_probe(struct device *dev,
>  	smmu->dev = dev;
>  	smmu->mc = mc;
>  
> -	smmu->pfn_mask = BIT_MASK(mc->soc->num_address_bits - PAGE_SHIFT) - 1;
> +	smmu->pfn_mask =
> +		BIT_MASK(mc->soc->num_address_bits - SMMU_PTE_SHIFT) - 1;

checkpatch no longer warns about lines longer than 80 characters. The
new limit is 100, so you can fit this all on one line.

But either way:

Acked-by: Thierry Reding <treding@nvidia.com>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2020-09-24 10:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-11  7:16 [PATCH 0/3] iommu/tegra-smmu: Some small fixes Nicolin Chen
2020-09-11  7:16 ` Nicolin Chen
2020-09-11  7:16 ` [PATCH 1/3] iommu/tegra-smmu: Do not use PAGE_SHIFT and PAGE_MASK Nicolin Chen
2020-09-11  7:16   ` Nicolin Chen
2020-09-24 10:23   ` Thierry Reding [this message]
2020-09-24 10:23     ` Thierry Reding
2020-09-11  7:16 ` [PATCH 2/3] iommu/tegra-smmu: Fix iova->phys translation Nicolin Chen
2020-09-11  7:16   ` Nicolin Chen
2020-09-24 10:23   ` Thierry Reding
2020-09-24 10:23     ` Thierry Reding
2020-09-11  7:16 ` [PATCH 3/3] iommu/tegra-smmu: Allow to group clients in same swgroup Nicolin Chen
2020-09-11  7:16   ` Nicolin Chen
2020-09-24 10:25   ` Thierry Reding
2020-09-24 10:25     ` Thierry Reding
2020-09-24 10:33 ` [PATCH 0/3] iommu/tegra-smmu: Some small fixes Joerg Roedel
2020-09-24 10:33   ` Joerg Roedel

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=20200924102312.GG2483160@ulmo \
    --to=thierry.reding@gmail.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=jonathanh@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=nicoleotsuka@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.