[PATCH v1 01/10] drm/panthor: Factor out GPU_ID register read into separate function

Karunika Choo posted 10 patches 3 months, 3 weeks ago
There is a newer version of this series
[PATCH v1 01/10] drm/panthor: Factor out GPU_ID register read into separate function
Posted by Karunika Choo 3 months, 3 weeks ago
Split the GPU_ID register read into its own helper function. The GPU_ID
value will be used to enable architecture-specific behaviours, which may
also affect how other registers (such as those used for gpu_info) are
read.

This change separates the read operation so that subsequent code can
depend on the intermediate result of processing the GPU_ID.

Signed-off-by: Karunika Choo <karunika.choo@arm.com>
---
 drivers/gpu/drm/panthor/panthor_hw.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panthor/panthor_hw.c b/drivers/gpu/drm/panthor/panthor_hw.c
index 4f2858114e5e..326a9db0b5c2 100644
--- a/drivers/gpu/drm/panthor/panthor_hw.c
+++ b/drivers/gpu/drm/panthor/panthor_hw.c
@@ -62,7 +62,6 @@ static void panthor_gpu_info_init(struct panthor_device *ptdev)
 {
 	unsigned int i;
 
-	ptdev->gpu_info.gpu_id = gpu_read(ptdev, GPU_ID);
 	ptdev->gpu_info.csf_id = gpu_read(ptdev, GPU_CSF_ID);
 	ptdev->gpu_info.gpu_rev = gpu_read(ptdev, GPU_REVID);
 	ptdev->gpu_info.core_features = gpu_read(ptdev, GPU_CORE_FEATURES);
@@ -117,8 +116,23 @@ static void panthor_hw_info_init(struct panthor_device *ptdev)
 		 ptdev->gpu_info.tiler_present);
 }
 
+static int panthor_hw_gpu_id_init(struct panthor_device *ptdev)
+{
+	ptdev->gpu_info.gpu_id = gpu_read(ptdev, GPU_ID);
+	if (!ptdev->gpu_info.gpu_id)
+		return -ENXIO;
+
+	return 0;
+}
+
 int panthor_hw_init(struct panthor_device *ptdev)
 {
+	int ret = 0;
+
+	ret = panthor_hw_gpu_id_init(ptdev);
+	if (ret)
+		return ret;
+
 	panthor_hw_info_init(ptdev);
 
 	return 0;
-- 
2.49.0
Re: [PATCH v1 01/10] drm/panthor: Factor out GPU_ID register read into separate function
Posted by Steven Price 3 months, 3 weeks ago
On 14/10/2025 10:43, Karunika Choo wrote:
> Split the GPU_ID register read into its own helper function. The GPU_ID
> value will be used to enable architecture-specific behaviours, which may
> also affect how other registers (such as those used for gpu_info) are
> read.
> 
> This change separates the read operation so that subsequent code can
> depend on the intermediate result of processing the GPU_ID.
> 
> Signed-off-by: Karunika Choo <karunika.choo@arm.com>

I'd be very tempted to squash this into the next commit and simple read
the GPU ID at the beginning of panthor_hw_bind_device(). Is there any
reason not to?

Steve

> ---
>  drivers/gpu/drm/panthor/panthor_hw.c | 16 +++++++++++++++-
>  1 file changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/panthor/panthor_hw.c b/drivers/gpu/drm/panthor/panthor_hw.c
> index 4f2858114e5e..326a9db0b5c2 100644
> --- a/drivers/gpu/drm/panthor/panthor_hw.c
> +++ b/drivers/gpu/drm/panthor/panthor_hw.c
> @@ -62,7 +62,6 @@ static void panthor_gpu_info_init(struct panthor_device *ptdev)
>  {
>  	unsigned int i;
>  
> -	ptdev->gpu_info.gpu_id = gpu_read(ptdev, GPU_ID);
>  	ptdev->gpu_info.csf_id = gpu_read(ptdev, GPU_CSF_ID);
>  	ptdev->gpu_info.gpu_rev = gpu_read(ptdev, GPU_REVID);
>  	ptdev->gpu_info.core_features = gpu_read(ptdev, GPU_CORE_FEATURES);
> @@ -117,8 +116,23 @@ static void panthor_hw_info_init(struct panthor_device *ptdev)
>  		 ptdev->gpu_info.tiler_present);
>  }
>  
> +static int panthor_hw_gpu_id_init(struct panthor_device *ptdev)
> +{
> +	ptdev->gpu_info.gpu_id = gpu_read(ptdev, GPU_ID);
> +	if (!ptdev->gpu_info.gpu_id)
> +		return -ENXIO;
> +
> +	return 0;
> +}
> +
>  int panthor_hw_init(struct panthor_device *ptdev)
>  {
> +	int ret = 0;
> +
> +	ret = panthor_hw_gpu_id_init(ptdev);
> +	if (ret)
> +		return ret;
> +
>  	panthor_hw_info_init(ptdev);
>  
>  	return 0;