Skip to content

Commit 9433252

Browse files
Karunika Choostevenprice-arm
authored andcommitted
drm/panthor: Add panthor_hw and move gpu_info initialization into it
This patch introduces panthor_hw and moves the initialization of the gpu_info struct into panthor_hw.c in preparation of handling future GPU register and naming changes. Future GPU support can be added by extending panthor_gpu_info_init() with the necessary register reads behind GPU architecture version guards if the change is minor. For more complex changes, the function can be forked and the appropriate function will need to be called based on the GPU architecture version. Reviewed-by: Steven Price <steven.price@arm.com> Reviewed-by: Chia-I Wu <olvaffe@gmail.com> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com> Signed-off-by: Karunika Choo <karunika.choo@arm.com> Signed-off-by: Steven Price <steven.price@arm.com> Link: https://lore.kernel.org/r/20250807162633.3666310-2-karunika.choo@arm.com
1 parent 5fbc0db commit 9433252

5 files changed

Lines changed: 130 additions & 95 deletions

File tree

drivers/gpu/drm/panthor/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ panthor-y := \
88
panthor_gem.o \
99
panthor_gpu.o \
1010
panthor_heap.o \
11+
panthor_hw.o \
1112
panthor_mmu.o \
1213
panthor_sched.o
1314

drivers/gpu/drm/panthor/panthor_device.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "panthor_device.h"
1919
#include "panthor_fw.h"
2020
#include "panthor_gpu.h"
21+
#include "panthor_hw.h"
2122
#include "panthor_mmu.h"
2223
#include "panthor_regs.h"
2324
#include "panthor_sched.h"
@@ -244,6 +245,10 @@ int panthor_device_init(struct panthor_device *ptdev)
244245
return ret;
245246
}
246247

248+
ret = panthor_hw_init(ptdev);
249+
if (ret)
250+
goto err_rpm_put;
251+
247252
ret = panthor_gpu_init(ptdev);
248253
if (ret)
249254
goto err_rpm_put;

drivers/gpu/drm/panthor/panthor_gpu.c

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,6 @@ struct panthor_gpu {
3737
wait_queue_head_t reqs_acked;
3838
};
3939

40-
/**
41-
* struct panthor_model - GPU model description
42-
*/
43-
struct panthor_model {
44-
/** @name: Model name. */
45-
const char *name;
46-
47-
/** @arch_major: Major version number of architecture. */
48-
u8 arch_major;
49-
50-
/** @product_major: Major version number of product. */
51-
u8 product_major;
52-
};
53-
54-
/**
55-
* GPU_MODEL() - Define a GPU model. A GPU product can be uniquely identified
56-
* by a combination of the major architecture version and the major product
57-
* version.
58-
* @_name: Name for the GPU model.
59-
* @_arch_major: Architecture major.
60-
* @_product_major: Product major.
61-
*/
62-
#define GPU_MODEL(_name, _arch_major, _product_major) \
63-
{\
64-
.name = __stringify(_name), \
65-
.arch_major = _arch_major, \
66-
.product_major = _product_major, \
67-
}
68-
69-
static const struct panthor_model gpu_models[] = {
70-
GPU_MODEL(g610, 10, 7),
71-
{},
72-
};
73-
7440
#define GPU_INTERRUPTS_MASK \
7541
(GPU_IRQ_FAULT | \
7642
GPU_IRQ_PROTM_FAULT | \
@@ -83,66 +49,6 @@ static void panthor_gpu_coherency_set(struct panthor_device *ptdev)
8349
ptdev->coherent ? GPU_COHERENCY_PROT_BIT(ACE_LITE) : GPU_COHERENCY_NONE);
8450
}
8551

86-
static void panthor_gpu_init_info(struct panthor_device *ptdev)
87-
{
88-
const struct panthor_model *model;
89-
u32 arch_major, product_major;
90-
u32 major, minor, status;
91-
unsigned int i;
92-
93-
ptdev->gpu_info.gpu_id = gpu_read(ptdev, GPU_ID);
94-
ptdev->gpu_info.csf_id = gpu_read(ptdev, GPU_CSF_ID);
95-
ptdev->gpu_info.gpu_rev = gpu_read(ptdev, GPU_REVID);
96-
ptdev->gpu_info.core_features = gpu_read(ptdev, GPU_CORE_FEATURES);
97-
ptdev->gpu_info.l2_features = gpu_read(ptdev, GPU_L2_FEATURES);
98-
ptdev->gpu_info.tiler_features = gpu_read(ptdev, GPU_TILER_FEATURES);
99-
ptdev->gpu_info.mem_features = gpu_read(ptdev, GPU_MEM_FEATURES);
100-
ptdev->gpu_info.mmu_features = gpu_read(ptdev, GPU_MMU_FEATURES);
101-
ptdev->gpu_info.thread_features = gpu_read(ptdev, GPU_THREAD_FEATURES);
102-
ptdev->gpu_info.max_threads = gpu_read(ptdev, GPU_THREAD_MAX_THREADS);
103-
ptdev->gpu_info.thread_max_workgroup_size = gpu_read(ptdev, GPU_THREAD_MAX_WORKGROUP_SIZE);
104-
ptdev->gpu_info.thread_max_barrier_size = gpu_read(ptdev, GPU_THREAD_MAX_BARRIER_SIZE);
105-
ptdev->gpu_info.coherency_features = gpu_read(ptdev, GPU_COHERENCY_FEATURES);
106-
for (i = 0; i < 4; i++)
107-
ptdev->gpu_info.texture_features[i] = gpu_read(ptdev, GPU_TEXTURE_FEATURES(i));
108-
109-
ptdev->gpu_info.as_present = gpu_read(ptdev, GPU_AS_PRESENT);
110-
111-
ptdev->gpu_info.shader_present = gpu_read64(ptdev, GPU_SHADER_PRESENT);
112-
ptdev->gpu_info.tiler_present = gpu_read64(ptdev, GPU_TILER_PRESENT);
113-
ptdev->gpu_info.l2_present = gpu_read64(ptdev, GPU_L2_PRESENT);
114-
115-
arch_major = GPU_ARCH_MAJOR(ptdev->gpu_info.gpu_id);
116-
product_major = GPU_PROD_MAJOR(ptdev->gpu_info.gpu_id);
117-
major = GPU_VER_MAJOR(ptdev->gpu_info.gpu_id);
118-
minor = GPU_VER_MINOR(ptdev->gpu_info.gpu_id);
119-
status = GPU_VER_STATUS(ptdev->gpu_info.gpu_id);
120-
121-
for (model = gpu_models; model->name; model++) {
122-
if (model->arch_major == arch_major &&
123-
model->product_major == product_major)
124-
break;
125-
}
126-
127-
drm_info(&ptdev->base,
128-
"mali-%s id 0x%x major 0x%x minor 0x%x status 0x%x",
129-
model->name ?: "unknown", ptdev->gpu_info.gpu_id >> 16,
130-
major, minor, status);
131-
132-
drm_info(&ptdev->base,
133-
"Features: L2:%#x Tiler:%#x Mem:%#x MMU:%#x AS:%#x",
134-
ptdev->gpu_info.l2_features,
135-
ptdev->gpu_info.tiler_features,
136-
ptdev->gpu_info.mem_features,
137-
ptdev->gpu_info.mmu_features,
138-
ptdev->gpu_info.as_present);
139-
140-
drm_info(&ptdev->base,
141-
"shader_present=0x%0llx l2_present=0x%0llx tiler_present=0x%0llx",
142-
ptdev->gpu_info.shader_present, ptdev->gpu_info.l2_present,
143-
ptdev->gpu_info.tiler_present);
144-
}
145-
14652
static void panthor_gpu_irq_handler(struct panthor_device *ptdev, u32 status)
14753
{
14854
gpu_write(ptdev, GPU_INT_CLEAR, status);
@@ -205,7 +111,6 @@ int panthor_gpu_init(struct panthor_device *ptdev)
205111
spin_lock_init(&gpu->reqs_lock);
206112
init_waitqueue_head(&gpu->reqs_acked);
207113
ptdev->gpu = gpu;
208-
panthor_gpu_init_info(ptdev);
209114

210115
dma_set_max_seg_size(ptdev->base.dev, UINT_MAX);
211116
pa_bits = GPU_MMU_FEATURES_PA_BITS(ptdev->gpu_info.mmu_features);
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// SPDX-License-Identifier: GPL-2.0 or MIT
2+
/* Copyright 2025 ARM Limited. All rights reserved. */
3+
4+
#include "panthor_device.h"
5+
#include "panthor_hw.h"
6+
#include "panthor_regs.h"
7+
8+
/**
9+
* struct panthor_model - GPU model description
10+
*/
11+
struct panthor_model {
12+
/** @name: Model name. */
13+
const char *name;
14+
15+
/** @arch_major: Major version number of architecture. */
16+
u8 arch_major;
17+
18+
/** @product_major: Major version number of product. */
19+
u8 product_major;
20+
};
21+
22+
/**
23+
* GPU_MODEL() - Define a GPU model. A GPU product can be uniquely identified
24+
* by a combination of the major architecture version and the major product
25+
* version.
26+
* @_name: Name for the GPU model.
27+
* @_arch_major: Architecture major.
28+
* @_product_major: Product major.
29+
*/
30+
#define GPU_MODEL(_name, _arch_major, _product_major) \
31+
{\
32+
.name = __stringify(_name), \
33+
.arch_major = _arch_major, \
34+
.product_major = _product_major, \
35+
}
36+
37+
static const struct panthor_model gpu_models[] = {
38+
GPU_MODEL(g610, 10, 7),
39+
{},
40+
};
41+
42+
static void panthor_gpu_info_init(struct panthor_device *ptdev)
43+
{
44+
unsigned int i;
45+
46+
ptdev->gpu_info.gpu_id = gpu_read(ptdev, GPU_ID);
47+
ptdev->gpu_info.csf_id = gpu_read(ptdev, GPU_CSF_ID);
48+
ptdev->gpu_info.gpu_rev = gpu_read(ptdev, GPU_REVID);
49+
ptdev->gpu_info.core_features = gpu_read(ptdev, GPU_CORE_FEATURES);
50+
ptdev->gpu_info.l2_features = gpu_read(ptdev, GPU_L2_FEATURES);
51+
ptdev->gpu_info.tiler_features = gpu_read(ptdev, GPU_TILER_FEATURES);
52+
ptdev->gpu_info.mem_features = gpu_read(ptdev, GPU_MEM_FEATURES);
53+
ptdev->gpu_info.mmu_features = gpu_read(ptdev, GPU_MMU_FEATURES);
54+
ptdev->gpu_info.thread_features = gpu_read(ptdev, GPU_THREAD_FEATURES);
55+
ptdev->gpu_info.max_threads = gpu_read(ptdev, GPU_THREAD_MAX_THREADS);
56+
ptdev->gpu_info.thread_max_workgroup_size = gpu_read(ptdev, GPU_THREAD_MAX_WORKGROUP_SIZE);
57+
ptdev->gpu_info.thread_max_barrier_size = gpu_read(ptdev, GPU_THREAD_MAX_BARRIER_SIZE);
58+
ptdev->gpu_info.coherency_features = gpu_read(ptdev, GPU_COHERENCY_FEATURES);
59+
for (i = 0; i < 4; i++)
60+
ptdev->gpu_info.texture_features[i] = gpu_read(ptdev, GPU_TEXTURE_FEATURES(i));
61+
62+
ptdev->gpu_info.as_present = gpu_read(ptdev, GPU_AS_PRESENT);
63+
64+
ptdev->gpu_info.shader_present = gpu_read64(ptdev, GPU_SHADER_PRESENT);
65+
ptdev->gpu_info.tiler_present = gpu_read64(ptdev, GPU_TILER_PRESENT);
66+
ptdev->gpu_info.l2_present = gpu_read64(ptdev, GPU_L2_PRESENT);
67+
}
68+
69+
static void panthor_hw_info_init(struct panthor_device *ptdev)
70+
{
71+
const struct panthor_model *model;
72+
u32 arch_major, product_major;
73+
u32 major, minor, status;
74+
75+
panthor_gpu_info_init(ptdev);
76+
77+
arch_major = GPU_ARCH_MAJOR(ptdev->gpu_info.gpu_id);
78+
product_major = GPU_PROD_MAJOR(ptdev->gpu_info.gpu_id);
79+
major = GPU_VER_MAJOR(ptdev->gpu_info.gpu_id);
80+
minor = GPU_VER_MINOR(ptdev->gpu_info.gpu_id);
81+
status = GPU_VER_STATUS(ptdev->gpu_info.gpu_id);
82+
83+
for (model = gpu_models; model->name; model++) {
84+
if (model->arch_major == arch_major &&
85+
model->product_major == product_major)
86+
break;
87+
}
88+
89+
drm_info(&ptdev->base,
90+
"mali-%s id 0x%x major 0x%x minor 0x%x status 0x%x",
91+
model->name ?: "unknown", ptdev->gpu_info.gpu_id >> 16,
92+
major, minor, status);
93+
94+
drm_info(&ptdev->base,
95+
"Features: L2:%#x Tiler:%#x Mem:%#x MMU:%#x AS:%#x",
96+
ptdev->gpu_info.l2_features,
97+
ptdev->gpu_info.tiler_features,
98+
ptdev->gpu_info.mem_features,
99+
ptdev->gpu_info.mmu_features,
100+
ptdev->gpu_info.as_present);
101+
102+
drm_info(&ptdev->base,
103+
"shader_present=0x%0llx l2_present=0x%0llx tiler_present=0x%0llx",
104+
ptdev->gpu_info.shader_present, ptdev->gpu_info.l2_present,
105+
ptdev->gpu_info.tiler_present);
106+
}
107+
108+
int panthor_hw_init(struct panthor_device *ptdev)
109+
{
110+
panthor_hw_info_init(ptdev);
111+
112+
return 0;
113+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* SPDX-License-Identifier: GPL-2.0 or MIT */
2+
/* Copyright 2025 ARM Limited. All rights reserved. */
3+
4+
#ifndef __PANTHOR_HW_H__
5+
#define __PANTHOR_HW_H__
6+
7+
struct panthor_device;
8+
9+
int panthor_hw_init(struct panthor_device *ptdev);
10+
11+
#endif /* __PANTHOR_HW_H__ */

0 commit comments

Comments
 (0)