On 26/11/2025 09:50, Boris Brezillon wrote:
> The meat in lock_region() is about packing a region range into a
> single u64. The rest is just a regular reg write plus a
> as_send_cmd_and_wait() call that can easily be inlined in
> mmu_hw_do_operation_locked().
> 
> v2:
> - New patch
> 
> v3:
> - Don't LOCK is the region has a zero size
> 
> Signed-off-by: Boris Brezillon <[email protected]>

Reviewed-by: Steven Price <[email protected]>

> ---
>  drivers/gpu/drm/panthor/panthor_mmu.c | 20 ++++++++++----------
>  1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c 
> b/drivers/gpu/drm/panthor/panthor_mmu.c
> index 186048fc2c25..752d88e61aec 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -538,14 +538,12 @@ static int as_send_cmd_and_wait(struct panthor_device 
> *ptdev, u32 as_nr, u32 cmd
>       return status;
>  }
>  
> -static int lock_region(struct panthor_device *ptdev, u32 as_nr,
> -                    u64 region_start, u64 size)
> +static u64 pack_region_range(struct panthor_device *ptdev, u64 region_start, 
> u64 size)
>  {
>       u8 region_width;
> -     u64 region;
>       u64 region_end = region_start + size;
>  
> -     if (!size)
> +     if (drm_WARN_ON_ONCE(&ptdev->base, !size))
>               return 0;
>  
>       /*
> @@ -565,11 +563,7 @@ static int lock_region(struct panthor_device *ptdev, u32 
> as_nr,
>        */
>       region_start &= GENMASK_ULL(63, region_width);
>  
> -     region = region_width | region_start;
> -
> -     /* Lock the region that needs to be updated */
> -     gpu_write64(ptdev, AS_LOCKADDR(as_nr), region);
> -     return as_send_cmd_and_wait(ptdev, as_nr, AS_COMMAND_LOCK);
> +     return region_width | region_start;
>  }
>  
>  static int mmu_hw_do_operation_locked(struct panthor_device *ptdev, int 
> as_nr,
> @@ -581,6 +575,9 @@ static int mmu_hw_do_operation_locked(struct 
> panthor_device *ptdev, int as_nr,
>  
>       lockdep_assert_held(&ptdev->mmu->as.slots_lock);
>  
> +     if (!size)
> +             return 0;
> +
>       switch (op) {
>       case AS_COMMAND_FLUSH_MEM:
>               lsc_flush_op = CACHE_CLEAN | CACHE_INV;
> @@ -602,7 +599,10 @@ static int mmu_hw_do_operation_locked(struct 
> panthor_device *ptdev, int as_nr,
>        * power it up
>        */
>  
> -     ret = lock_region(ptdev, as_nr, iova, size);
> +     /* Lock the region that needs to be updated */
> +     gpu_write64(ptdev, AS_LOCKADDR(as_nr),
> +                 pack_region_range(ptdev, iova, size));
> +     ret = as_send_cmd_and_wait(ptdev, as_nr, AS_COMMAND_LOCK);
>       if (ret)
>               return ret;
>  

Reply via email to