All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Karunika Choo <karunika.choo@arm.com>
Cc: dri-devel@lists.freedesktop.org, nd@arm.com,
	Steven Price <steven.price@arm.com>,
	Liviu Dudau <liviu.dudau@arm.com>,
	linux-kernel@vger.kernel.org, Akash Goel <akash.goel@arm.com>,
	Lukas Zapolskas <lukas.zapolskas@arm.com>,
	Chris Diamand <chris.diamand@arm.com>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>
Subject: Re: [PATCH v3 07/10] drm/panthor: Derive MMU AS register addresses from base and stride
Date: Thu, 19 Nov 2026 09:03:09 +0100	[thread overview]
Message-ID: <20261119090309.77aa58da@fedora1.home> (raw)
In-Reply-To: <20261118175332.519657-8-karunika.choo@arm.com>

On Wed, 18 Nov 2026 17:53:23 +0000
Karunika Choo <karunika.choo@arm.com> wrote:

> Move the MMU address-space register layout into the hardware description
> by storing the MMU_AS base offset and per-AS stride in the Panthor HW
> map.
> 
> Use those values to compute the iomem pointer for each AS slot and make
> the MMU AS register definitions relative to the per-slot register window
> instead of hard-coding the slot offset in every register macro.
> 
> This prepares the MMU code for GPUs where the MMU AS register region is
> not at a fixed offset while keeping the existing register accesses
> scoped to a single AS window.
> 
> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
> Signed-off-by: Karunika Choo <karunika.choo@arm.com>

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>

> ---
> v2:
> - Picked up R-b from Liviu
> - Avoid enabling all AS IRQs on init and replace with explicit IRQ clear
>   to preserve init behaviour. AS IRQs are enabled as part of
>   panthor_mmu_as_enable(). This also prevents accessing NULL iomem
>   pointers for initialized AS during init per sashiko's comment.
> - Link: https://lore.kernel.org/all/20260922210016.0C0961F000FF@smtp.kernel.org/
> v1:
> - align with updated panthor_hw_regbank structure.
> - moved AS iomem tracking into panthor_as_slot and introduced as_iomem()
>   to retrieve it.
> 
>  drivers/gpu/drm/panthor/panthor_hw.c       |  8 ++++
>  drivers/gpu/drm/panthor/panthor_hw.h       |  3 ++
>  drivers/gpu/drm/panthor/panthor_mmu.c      | 47 ++++++++++++++--------
>  drivers/gpu/drm/panthor/panthor_mmu_regs.h | 23 +++++------
>  4 files changed, 51 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_hw.c b/drivers/gpu/drm/panthor/panthor_hw.c
> index f72cff260065e..6a8645bda1e7d 100644
> --- a/drivers/gpu/drm/panthor/panthor_hw.c
> +++ b/drivers/gpu/drm/panthor/panthor_hw.c
> @@ -45,6 +45,10 @@ static struct panthor_hw panthor_hw_arch_v10 = {
>  		.mcu_control = {
>  			.offset = 0x700,
>  		},
> +		.mmu_as_control = {
> +			.offset = 0x2400,
> +			.stride = 0x40,
> +		},
>  	},
>  };
>  
> @@ -64,6 +68,10 @@ static struct panthor_hw panthor_hw_arch_v14 = {
>  		.pwr_control = {
>  			.offset = 0x800,
>  		},
> +		.mmu_as_control = {
> +			.offset = 0x2400,
> +			.stride = 0x40,
> +		},
>  	},
>  };
>  
> diff --git a/drivers/gpu/drm/panthor/panthor_hw.h b/drivers/gpu/drm/panthor/panthor_hw.h
> index 0a82152d772ad..4cb603a3acef6 100644
> --- a/drivers/gpu/drm/panthor/panthor_hw.h
> +++ b/drivers/gpu/drm/panthor/panthor_hw.h
> @@ -49,6 +49,9 @@ struct panthor_hw_regs_layout {
>  
>  	/** @mcu_control: MCU_CONTROL register bank layout */
>  	struct panthor_hw_regbank mcu_control;
> +
> +	/** @mmu_as_control: MMU_AS_CONTROL register bank layout */
> +	struct panthor_hw_regbank mmu_as_control;
>  };
>  
>  /**
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index d1c29eec46f21..718160c0779ae 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -35,6 +35,7 @@
>  #include "panthor_gpu.h"
>  #include "panthor_gpu_regs.h"
>  #include "panthor_heap.h"
> +#include "panthor_hw.h"
>  #include "panthor_mmu.h"
>  #include "panthor_mmu_regs.h"
>  #include "panthor_sched.h"
> @@ -49,15 +50,15 @@ struct panthor_vm;
>  struct panthor_as_slot {
>  	/** @vm: VM bound to this slot. NULL is no VM is bound. */
>  	struct panthor_vm *vm;
> +
> +	/** @iomem: CPU mapping for MMU_AS_CONTROL iomem region */
> +	void __iomem *iomem;
>  };
>  
>  /**
>   * struct panthor_mmu - MMU related data
>   */
>  struct panthor_mmu {
> -	/** @iomem: CPU mapping of MMU_AS_CONTROL iomem region */
> -	void __iomem *iomem;
> -
>  	/** @irq: The MMU irq. */
>  	struct panthor_irq irq;
>  
> @@ -533,6 +534,11 @@ static void free_pt(void *cookie, void *data, size_t size)
>  	kmem_cache_free(pt_cache, data);
>  }
>  
> +static void __iomem *as_iomem(struct panthor_mmu *mmu, u32 as_nr)
> +{
> +	return mmu->as.slots[as_nr].iomem;
> +}
> +
>  static int wait_ready(struct panthor_device *ptdev, u32 as_nr)
>  {
>  	struct panthor_mmu *mmu = ptdev->mmu;
> @@ -542,7 +548,7 @@ static int wait_ready(struct panthor_device *ptdev, u32 as_nr)
>  	/* Wait for the MMU status to indicate there is no active command, in
>  	 * case one is pending.
>  	 */
> -	ret = gpu_read_relaxed_poll_timeout_atomic(mmu->iomem, AS_STATUS(as_nr), val,
> +	ret = gpu_read_relaxed_poll_timeout_atomic(as_iomem(mmu, as_nr), AS_STATUS, val,
>  						   !(val & AS_STATUS_AS_ACTIVE), 10, 100000);
>  
>  	if (ret) {
> @@ -560,7 +566,7 @@ static int as_send_cmd_and_wait(struct panthor_device *ptdev, u32 as_nr, u32 cmd
>  	/* write AS_COMMAND when MMU is ready to accept another command */
>  	status = wait_ready(ptdev, as_nr);
>  	if (!status) {
> -		gpu_write(ptdev->mmu->iomem, AS_COMMAND(as_nr), cmd);
> +		gpu_write(as_iomem(ptdev->mmu, as_nr), AS_COMMAND, cmd);
>  		status = wait_ready(ptdev, as_nr);
>  	}
>  
> @@ -603,9 +609,9 @@ static int panthor_mmu_as_enable(struct panthor_device *ptdev, u32 as_nr,
>  
>  	panthor_irq_enable_events(&ptdev->mmu->irq, MMU_INT_AS_FAULT(as_nr));
>  
> -	gpu_write64(mmu->iomem, AS_TRANSTAB(as_nr), transtab);
> -	gpu_write64(mmu->iomem, AS_MEMATTR(as_nr), memattr);
> -	gpu_write64(mmu->iomem, AS_TRANSCFG(as_nr), transcfg);
> +	gpu_write64(as_iomem(mmu, as_nr), AS_TRANSTAB, transtab);
> +	gpu_write64(as_iomem(mmu, as_nr), AS_MEMATTR, memattr);
> +	gpu_write64(as_iomem(mmu, as_nr), AS_TRANSCFG, transcfg);
>  
>  	return as_send_cmd_and_wait(ptdev, as_nr, AS_COMMAND_UPDATE);
>  }
> @@ -627,9 +633,9 @@ static int panthor_mmu_as_disable(struct panthor_device *ptdev, u32 as_nr)
>  			return ret;
>  	}
>  
> -	gpu_write64(mmu->iomem, AS_TRANSTAB(as_nr), 0);
> -	gpu_write64(mmu->iomem, AS_MEMATTR(as_nr), 0);
> -	gpu_write64(mmu->iomem, AS_TRANSCFG(as_nr), AS_TRANSCFG_ADRMODE_UNMAPPED);
> +	gpu_write64(as_iomem(mmu, as_nr), AS_TRANSTAB, 0);
> +	gpu_write64(as_iomem(mmu, as_nr), AS_MEMATTR, 0);
> +	gpu_write64(as_iomem(mmu, as_nr), AS_TRANSCFG, AS_TRANSCFG_ADRMODE_UNMAPPED);
>  
>  	ret = as_send_cmd_and_wait(ptdev, as_nr, AS_COMMAND_UPDATE);
>  	if (ret)
> @@ -1799,7 +1805,7 @@ static int panthor_vm_lock_region(struct panthor_vm *vm, u64 start, u64 size)
>  	mutex_lock(&ptdev->mmu->as.slots_lock);
>  	if (vm->as.id >= 0 && size) {
>  		/* Lock the region that needs to be updated */
> -		gpu_write64(ptdev->mmu->iomem, AS_LOCKADDR(vm->as.id),
> +		gpu_write64(as_iomem(ptdev->mmu, vm->as.id), AS_LOCKADDR,
>  			    pack_region_range(ptdev, &start, &size));
>  
>  		/* If the lock succeeded, update the locked_region info. */
> @@ -1861,8 +1867,8 @@ static void panthor_mmu_irq_handler(struct panthor_irq *pirq, u32 status)
>  		u32 access_type;
>  		u32 source_id;
>  
> -		fault_status = gpu_read(mmu->iomem, AS_FAULTSTATUS(as));
> -		addr = gpu_read64(mmu->iomem, AS_FAULTADDRESS(as));
> +		fault_status = gpu_read(as_iomem(mmu, as), AS_FAULTSTATUS);
> +		addr = gpu_read64(as_iomem(mmu, as), AS_FAULTADDRESS);
>  
>  		/* decode the fault status */
>  		exception_type = fault_status & 0xFF;
> @@ -3429,8 +3435,11 @@ static void panthor_mmu_info_init(struct panthor_device *ptdev)
>  int panthor_mmu_init(struct panthor_device *ptdev)
>  {
>  	u32 va_bits = GPU_MMU_FEATURES_VA_BITS(ptdev->gpu_info.mmu_features);
> +	unsigned long as_present_mask = ptdev->gpu_info.as_present;
> +	struct panthor_hw_regbank *regbank = &ptdev->hw->regs.mmu_as_control;
>  	struct panthor_mmu *mmu;
>  	int ret, irq;
> +	u32 as_id;
>  
>  	panthor_mmu_info_init(ptdev);
>  
> @@ -3449,7 +3458,13 @@ int panthor_mmu_init(struct panthor_device *ptdev)
>  	if (ret)
>  		return ret;
>  
> -	mmu->iomem = ptdev->iomem + MMU_AS_BASE;
> +	for_each_set_bit(as_id, &as_present_mask, MAX_AS_SLOTS) {
> +		u64 offset = regbank->offset + (regbank->stride * as_id);
> +
> +		guard(mutex)(&mmu->as.slots_lock);
> +		mmu->as.slots[as_id].iomem = ptdev->iomem + offset;
> +	}
> +
>  	ptdev->mmu = mmu;
>  
>  	irq = platform_get_irq_byname(to_platform_device(ptdev->base.dev), "mmu");
> @@ -3479,7 +3494,7 @@ int panthor_mmu_init(struct panthor_device *ptdev)
>  	if (ret)
>  		return ret;
>  
> -	panthor_irq_enable_events(&mmu->irq, panthor_mmu_fault_mask(ptdev, ~0));
> +	gpu_write(mmu->irq.iomem, INT_CLEAR, panthor_mmu_fault_mask(ptdev, ~0));
>  	panthor_irq_resume(&mmu->irq);
>  	return 0;
>  }
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu_regs.h b/drivers/gpu/drm/panthor/panthor_mmu_regs.h
> index 1ec7f5ef2b196..82661283b46ab 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu_regs.h
> +++ b/drivers/gpu/drm/panthor/panthor_mmu_regs.h
> @@ -11,13 +11,8 @@
>  
>  /* AS_COMMAND register commands */
>  
> -#define MMU_AS_BASE					0x2400
> -
> -#define MMU_AS_SHIFT					6
> -#define MMU_AS(as)					((as) << MMU_AS_SHIFT)
> -
> -#define AS_TRANSTAB(as)					(MMU_AS(as) + 0x0)
> -#define AS_MEMATTR(as)					(MMU_AS(as) + 0x8)
> +#define AS_TRANSTAB					0x0
> +#define AS_MEMATTR					0x8
>  #define   AS_MEMATTR_AARCH64_INNER_ALLOC_IMPL		(2 << 2)
>  #define   AS_MEMATTR_AARCH64_INNER_ALLOC_EXPL(w, r)	((3 << 2) | \
>  							 ((w) ? BIT(0) : 0) | \
> @@ -29,8 +24,8 @@
>  #define   AS_MEMATTR_AARCH64_INNER_OUTER_NC		(1 << 6)
>  #define   AS_MEMATTR_AARCH64_INNER_OUTER_WB		(2 << 6)
>  #define   AS_MEMATTR_AARCH64_FAULT			(3 << 6)
> -#define AS_LOCKADDR(as)					(MMU_AS(as) + 0x10)
> -#define AS_COMMAND(as)					(MMU_AS(as) + 0x18)
> +#define AS_LOCKADDR					0x10
> +#define AS_COMMAND					0x18
>  #define   AS_COMMAND_NOP				0
>  #define   AS_COMMAND_UPDATE				1
>  #define   AS_COMMAND_LOCK				2
> @@ -38,16 +33,16 @@
>  #define   AS_COMMAND_FLUSH_PT				4
>  #define   AS_COMMAND_FLUSH_MEM				5
>  #define   AS_LOCK_REGION_MIN_SIZE			(1ULL << 15)
> -#define AS_FAULTSTATUS(as)				(MMU_AS(as) + 0x1C)
> +#define AS_FAULTSTATUS					0x1C
>  #define  AS_FAULTSTATUS_ACCESS_TYPE_MASK		(0x3 << 8)
>  #define  AS_FAULTSTATUS_ACCESS_TYPE_ATOMIC		(0x0 << 8)
>  #define  AS_FAULTSTATUS_ACCESS_TYPE_EX			(0x1 << 8)
>  #define  AS_FAULTSTATUS_ACCESS_TYPE_READ		(0x2 << 8)
>  #define  AS_FAULTSTATUS_ACCESS_TYPE_WRITE		(0x3 << 8)
> -#define AS_FAULTADDRESS(as)				(MMU_AS(as) + 0x20)
> -#define AS_STATUS(as)					(MMU_AS(as) + 0x28)
> +#define AS_FAULTADDRESS					0x20
> +#define AS_STATUS					0x28
>  #define   AS_STATUS_AS_ACTIVE				BIT(0)
> -#define AS_TRANSCFG(as)					(MMU_AS(as) + 0x30)
> +#define AS_TRANSCFG					0x30
>  #define   AS_TRANSCFG_ADRMODE_UNMAPPED			(1 << 0)
>  #define   AS_TRANSCFG_ADRMODE_IDENTITY			(2 << 0)
>  #define   AS_TRANSCFG_ADRMODE_AARCH64_4K		(6 << 0)
> @@ -65,6 +60,6 @@
>  #define   AS_TRANSCFG_DISABLE_AF_FAULT			BIT(34)
>  #define   AS_TRANSCFG_WXN				BIT(35)
>  #define   AS_TRANSCFG_XREADABLE				BIT(36)
> -#define AS_FAULTEXTRA(as)				(MMU_AS(as) + 0x38)
> +#define AS_FAULTEXTRA					0x38
>  
>  #endif /* __PANTHOR_MMU_REGS_H__ */


  reply	other threads:[~2026-11-19  8:03 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 17:53 [PATCH v3 00/10] drm/panthor: Add initial Mali v15 support Karunika Choo
2026-11-18 17:53 ` [PATCH v3 01/10] drm/panthor: Ignore -EOPNOTSUPP for shader-present nvmem lookup Karunika Choo
2026-11-18 17:53 ` [PATCH v3 02/10] drm/panthor: Rename neural accelerator feature macro to NX Karunika Choo
2026-11-18 17:59   ` sashiko-bot
2026-11-19  7:52   ` Boris Brezillon
2026-11-19  9:47   ` Liviu Dudau
2026-11-18 17:53 ` [PATCH v3 03/10] drm/panthor: Move register access helpers out of panthor_device.h Karunika Choo
2026-11-19  7:53   ` Boris Brezillon
2026-11-18 17:53 ` [PATCH v3 04/10] drm/panthor: Parse and store GPU_ID fields Karunika Choo
2026-11-19  7:53   ` Boris Brezillon
2026-11-18 17:53 ` [PATCH v3 05/10] drm/panthor: Add 64-bit GPU_ID decoding for v15 GPUs Karunika Choo
2026-11-19  8:01   ` Boris Brezillon
2026-11-18 17:53 ` [PATCH v3 06/10] drm/panthor: Move register base offsets to the HW description Karunika Choo
2026-11-19  8:01   ` Boris Brezillon
2026-11-18 17:53 ` [PATCH v3 07/10] drm/panthor: Derive MMU AS register addresses from base and stride Karunika Choo
2026-11-19  8:03   ` Boris Brezillon [this message]
2026-11-18 17:53 ` [PATCH v3 08/10] dt-bindings: gpu: mali-gen5-am: Add Mali 5th-Gen AM schema Karunika Choo
2026-11-19  8:04   ` Boris Brezillon
2026-11-18 17:53 ` [PATCH v3 09/10] drm/panthor: Add Mali v15 hardware support Karunika Choo
2026-11-19  8:08   ` Boris Brezillon
2026-11-18 17:53 ` [PATCH v3 10/10] drm/panthor: Skip devfreq when no OPP table is present Karunika Choo
2026-11-18 18:11   ` sashiko-bot
2026-11-19  8:12   ` Boris Brezillon

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=20261119090309.77aa58da@fedora1.home \
    --to=boris.brezillon@collabora.com \
    --cc=airlied@gmail.com \
    --cc=akash.goel@arm.com \
    --cc=chris.diamand@arm.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karunika.choo@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=lukas.zapolskas@arm.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nd@arm.com \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=tzimmermann@suse.de \
    /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.