Re: [PATCH 06/18] iommu/fsl_pamu: remove ->domain_window_enable

2021-04-01 Thread Christoph Hellwig
On Tue, Mar 30, 2021 at 01:40:09PM +0100, Will Deacon wrote:
> > +   ret = pamu_config_ppaace(liodn, geom->aperture_start,
> > +geom->aperture_end - 1, ~(u32)0,
> 
> You're passing 'geom->aperture_end - 1' as the size here, but the old code
> seemed to _add_ 1:
> 

> > -   win_size = (domain->geometry.aperture_end + 1) >> ilog2(1);
> 
> here ^^ when calculating the exclusive upper bound. In other words, I think
> '1ULL << 36' used to get passed to pamu_config_ppaace(). Is that an
> intentional change?

No, I've fixed it up.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH 06/18] iommu/fsl_pamu: remove ->domain_window_enable

2021-03-30 Thread Will Deacon
On Tue, Mar 16, 2021 at 04:38:12PM +0100, Christoph Hellwig wrote:
> The only thing that fsl_pamu_window_enable does for the current caller
> is to fill in the prot value in the only dma_window structure, and to
> propagate a few values from the iommu_domain_geometry struture into the
> dma_window.  Remove the dma_window entirely, hardcode the prot value and
> otherwise use the iommu_domain_geometry structure instead.
> 
> Remove the now unused ->domain_window_enable iommu method.
> 
> Signed-off-by: Christoph Hellwig 
> Acked-by: Li Yang 
> ---
>  drivers/iommu/fsl_pamu_domain.c | 182 +++-
>  drivers/iommu/fsl_pamu_domain.h |  17 ---
>  drivers/iommu/iommu.c   |  11 --
>  drivers/soc/fsl/qbman/qman_portal.c |   7 --
>  include/linux/iommu.h   |  17 ---
>  5 files changed, 14 insertions(+), 220 deletions(-)
> 
> diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
> index e6bdd38fc18409..fd2bc88b690465 100644
> --- a/drivers/iommu/fsl_pamu_domain.c
> +++ b/drivers/iommu/fsl_pamu_domain.c
> @@ -54,34 +54,18 @@ static int __init iommu_init_mempool(void)
>   return 0;
>  }
>  
> -static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, 
> dma_addr_t iova)
> -{
> - struct dma_window *win_ptr = _domain->win_arr[0];
> - struct iommu_domain_geometry *geom;
> -
> - geom = _domain->iommu_domain.geometry;
> -
> - if (win_ptr->valid)
> - return win_ptr->paddr + (iova & (win_ptr->size - 1));
> -
> - return 0;
> -}
> -
>  /* Map the DMA window corresponding to the LIODN */
>  static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain)
>  {
>   int ret;
> - struct dma_window *wnd = _domain->win_arr[0];
> - phys_addr_t wnd_addr = dma_domain->iommu_domain.geometry.aperture_start;
> + struct iommu_domain_geometry *geom = _domain->iommu_domain.geometry;
>   unsigned long flags;
>  
>   spin_lock_irqsave(_lock, flags);
> - ret = pamu_config_ppaace(liodn, wnd_addr,
> -  wnd->size,
> -  ~(u32)0,
> -  wnd->paddr >> PAMU_PAGE_SHIFT,
> -  dma_domain->snoop_id, dma_domain->stash_id,
> -  wnd->prot);
> + ret = pamu_config_ppaace(liodn, geom->aperture_start,
> +  geom->aperture_end - 1, ~(u32)0,

You're passing 'geom->aperture_end - 1' as the size here, but the old code
seemed to _add_ 1:

> -static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr,
> -   phys_addr_t paddr, u64 size, int prot)
> -{
> - struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
> - struct dma_window *wnd;
> - int pamu_prot = 0;
> - int ret;
> - unsigned long flags;
> - u64 win_size;
> -
> - if (prot & IOMMU_READ)
> - pamu_prot |= PAACE_AP_PERMS_QUERY;
> - if (prot & IOMMU_WRITE)
> - pamu_prot |= PAACE_AP_PERMS_UPDATE;
> -
> - spin_lock_irqsave(_domain->domain_lock, flags);
> - if (wnd_nr > 0) {
> - pr_debug("Invalid window index\n");
> - spin_unlock_irqrestore(_domain->domain_lock, flags);
> - return -EINVAL;
> - }
> -
> - win_size = (domain->geometry.aperture_end + 1) >> ilog2(1);

here ^^ when calculating the exclusive upper bound. In other words, I think
'1ULL << 36' used to get passed to pamu_config_ppaace(). Is that an
intentional change?

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


[PATCH 06/18] iommu/fsl_pamu: remove ->domain_window_enable

2021-03-16 Thread Christoph Hellwig
The only thing that fsl_pamu_window_enable does for the current caller
is to fill in the prot value in the only dma_window structure, and to
propagate a few values from the iommu_domain_geometry struture into the
dma_window.  Remove the dma_window entirely, hardcode the prot value and
otherwise use the iommu_domain_geometry structure instead.

Remove the now unused ->domain_window_enable iommu method.

Signed-off-by: Christoph Hellwig 
Acked-by: Li Yang 
---
 drivers/iommu/fsl_pamu_domain.c | 182 +++-
 drivers/iommu/fsl_pamu_domain.h |  17 ---
 drivers/iommu/iommu.c   |  11 --
 drivers/soc/fsl/qbman/qman_portal.c |   7 --
 include/linux/iommu.h   |  17 ---
 5 files changed, 14 insertions(+), 220 deletions(-)

diff --git a/drivers/iommu/fsl_pamu_domain.c b/drivers/iommu/fsl_pamu_domain.c
index e6bdd38fc18409..fd2bc88b690465 100644
--- a/drivers/iommu/fsl_pamu_domain.c
+++ b/drivers/iommu/fsl_pamu_domain.c
@@ -54,34 +54,18 @@ static int __init iommu_init_mempool(void)
return 0;
 }
 
-static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, dma_addr_t 
iova)
-{
-   struct dma_window *win_ptr = _domain->win_arr[0];
-   struct iommu_domain_geometry *geom;
-
-   geom = _domain->iommu_domain.geometry;
-
-   if (win_ptr->valid)
-   return win_ptr->paddr + (iova & (win_ptr->size - 1));
-
-   return 0;
-}
-
 /* Map the DMA window corresponding to the LIODN */
 static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain)
 {
int ret;
-   struct dma_window *wnd = _domain->win_arr[0];
-   phys_addr_t wnd_addr = dma_domain->iommu_domain.geometry.aperture_start;
+   struct iommu_domain_geometry *geom = _domain->iommu_domain.geometry;
unsigned long flags;
 
spin_lock_irqsave(_lock, flags);
-   ret = pamu_config_ppaace(liodn, wnd_addr,
-wnd->size,
-~(u32)0,
-wnd->paddr >> PAMU_PAGE_SHIFT,
-dma_domain->snoop_id, dma_domain->stash_id,
-wnd->prot);
+   ret = pamu_config_ppaace(liodn, geom->aperture_start,
+geom->aperture_end - 1, ~(u32)0,
+0, dma_domain->snoop_id, dma_domain->stash_id,
+PAACE_AP_PERMS_QUERY | PAACE_AP_PERMS_UPDATE);
spin_unlock_irqrestore(_lock, flags);
if (ret)
pr_debug("PAACE configuration failed for liodn %d\n", liodn);
@@ -89,33 +73,6 @@ static int map_liodn(int liodn, struct fsl_dma_domain 
*dma_domain)
return ret;
 }
 
-/* Update window/subwindow mapping for the LIODN */
-static int update_liodn(int liodn, struct fsl_dma_domain *dma_domain, u32 
wnd_nr)
-{
-   int ret;
-   struct dma_window *wnd = _domain->win_arr[wnd_nr];
-   phys_addr_t wnd_addr;
-   unsigned long flags;
-
-   spin_lock_irqsave(_lock, flags);
-
-   wnd_addr = dma_domain->iommu_domain.geometry.aperture_start;
-
-   ret = pamu_config_ppaace(liodn, wnd_addr,
-wnd->size,
-~(u32)0,
-wnd->paddr >> PAMU_PAGE_SHIFT,
-dma_domain->snoop_id, dma_domain->stash_id,
-wnd->prot);
-   if (ret)
-   pr_debug("Window reconfiguration failed for liodn %d\n",
-liodn);
-
-   spin_unlock_irqrestore(_lock, flags);
-
-   return ret;
-}
-
 static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain,
  u32 val)
 {
@@ -172,26 +129,6 @@ static int pamu_set_liodn(int liodn, struct device *dev,
return ret;
 }
 
-static int check_size(u64 size, dma_addr_t iova)
-{
-   /*
-* Size must be a power of two and at least be equal
-* to PAMU page size.
-*/
-   if ((size & (size - 1)) || size < PAMU_PAGE_SIZE) {
-   pr_debug("Size too small or not a power of two\n");
-   return -EINVAL;
-   }
-
-   /* iova must be page size aligned */
-   if (iova & (size - 1)) {
-   pr_debug("Address is not aligned with window size\n");
-   return -EINVAL;
-   }
-
-   return 0;
-}
-
 static void remove_device_ref(struct device_domain_info *info)
 {
unsigned long flags;
@@ -257,13 +194,10 @@ static void attach_device(struct fsl_dma_domain 
*dma_domain, int liodn, struct d
 static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain,
 dma_addr_t iova)
 {
-   struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
-
if (iova < domain->geometry.aperture_start ||
iova > domain->geometry.aperture_end)
return 0;
-
-   return get_phys_addr(dma_domain, iova);
+