Skip to content

Commit 93bc903

Browse files
mairacanalpopcornmix
authored andcommitted
drm/v3d: Use V3D_SMS registers for power on/off and reset on V3D 7.x
In addition to the standard reset controller, V3D 7.x requires configuring the V3D_SMS registers for proper power on/off and reset. Add the new registers to `v3d_regs.h` and ensure they are properly configured during device probing, removal, and reset. This change fixes GPU reset issues on the Raspberry Pi 5 (BCM2712). Without exposing these registers, a GPU reset causes the GPU to hang, stopping any further job execution and freezing the desktop GUI. The same issue occurs when unloading and loading the v3d driver. Link: #6660 Reviewed-by: Iago Toral Quiroga <[email protected]> Signed-off-by: Maíra Canal <[email protected]>
1 parent fc1294c commit 93bc903

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

drivers/gpu/drm/v3d/v3d_drv.c

+40
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,36 @@ static const struct of_device_id v3d_of_match[] = {
266266
};
267267
MODULE_DEVICE_TABLE(of, v3d_of_match);
268268

269+
static void
270+
v3d_idle_sms(struct v3d_dev *v3d)
271+
{
272+
if (v3d->ver < V3D_GEN_71)
273+
return;
274+
275+
V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_CLEAR_POWER_OFF);
276+
277+
if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
278+
V3D_SMS_STATE) == V3D_SMS_IDLE), 100)) {
279+
DRM_ERROR("Failed to power up SMS\n");
280+
}
281+
282+
v3d_reset_sms(v3d);
283+
}
284+
285+
static void
286+
v3d_power_off_sms(struct v3d_dev *v3d)
287+
{
288+
if (v3d->ver < V3D_GEN_71)
289+
return;
290+
291+
V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_POWER_OFF);
292+
293+
if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
294+
V3D_SMS_STATE) == V3D_SMS_POWER_OFF_STATE), 100)) {
295+
DRM_ERROR("Failed to power off SMS\n");
296+
}
297+
}
298+
269299
static int
270300
map_regs(struct v3d_dev *v3d, void __iomem **regs, const char *name)
271301
{
@@ -305,6 +335,12 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
305335
if (ret)
306336
return ret;
307337

338+
if (v3d->ver >= V3D_GEN_71) {
339+
ret = map_regs(v3d, &v3d->sms_regs, "sms");
340+
if (ret)
341+
return ret;
342+
}
343+
308344
v3d->clk = devm_clk_get_optional(dev, NULL);
309345
if (IS_ERR(v3d->clk))
310346
return dev_err_probe(dev, PTR_ERR(v3d->clk), "Failed to get V3D clock\n");
@@ -315,6 +351,8 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
315351
return ret;
316352
}
317353

354+
v3d_idle_sms(v3d);
355+
318356
mmu_debug = V3D_READ(V3D_MMU_DEBUG_INFO);
319357
mask = DMA_BIT_MASK(30 + V3D_GET_FIELD(mmu_debug, V3D_MMU_PA_WIDTH));
320358
ret = dma_set_mask_and_coherent(dev, mask);
@@ -445,6 +483,8 @@ static void v3d_platform_drm_remove(struct platform_device *pdev)
445483
dma_free_wc(v3d->drm.dev, 4096, v3d->mmu_scratch,
446484
v3d->mmu_scratch_paddr);
447485

486+
v3d_power_off_sms(v3d);
487+
448488
clk_disable_unprepare(v3d->clk);
449489
}
450490

drivers/gpu/drm/v3d/v3d_drv.h

+11
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct v3d_dev {
118118
void __iomem *core_regs[3];
119119
void __iomem *bridge_regs;
120120
void __iomem *gca_regs;
121+
void __iomem *sms_regs;
121122
struct clk *clk;
122123
struct delayed_work clk_down_work;
123124
unsigned long clk_up_rate, clk_down_rate;
@@ -274,6 +275,15 @@ to_v3d_fence(struct dma_fence *fence)
274275
#define V3D_GCA_READ(offset) readl(v3d->gca_regs + offset)
275276
#define V3D_GCA_WRITE(offset, val) writel(val, v3d->gca_regs + offset)
276277

278+
#define V3D_SMS_IDLE 0x0
279+
#define V3D_SMS_ISOLATING_FOR_RESET 0xa
280+
#define V3D_SMS_RESETTING 0xb
281+
#define V3D_SMS_ISOLATING_FOR_POWER_OFF 0xc
282+
#define V3D_SMS_POWER_OFF_STATE 0xd
283+
284+
#define V3D_SMS_READ(offset) readl(v3d->sms_regs + (offset))
285+
#define V3D_SMS_WRITE(offset, val) writel(val, v3d->sms_regs + (offset))
286+
277287
#define V3D_CORE_READ(core, offset) readl(v3d->core_regs[core] + offset)
278288
#define V3D_CORE_WRITE(core, offset, val) writel(val, v3d->core_regs[core] + offset)
279289

@@ -552,6 +562,7 @@ struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue queue);
552562
/* v3d_gem.c */
553563
int v3d_gem_init(struct drm_device *dev);
554564
void v3d_gem_destroy(struct drm_device *dev);
565+
void v3d_reset_sms(struct v3d_dev *v3d);
555566
void v3d_reset(struct v3d_dev *v3d);
556567
void v3d_invalidate_caches(struct v3d_dev *v3d);
557568
void v3d_clean_caches(struct v3d_dev *v3d);

drivers/gpu/drm/v3d/v3d_gem.c

+17
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ v3d_reset_v3d(struct v3d_dev *v3d)
105105
v3d_init_hw_state(v3d);
106106
}
107107

108+
void
109+
v3d_reset_sms(struct v3d_dev *v3d)
110+
{
111+
if (v3d->ver < V3D_GEN_71)
112+
return;
113+
114+
V3D_SMS_WRITE(V3D_SMS_REE_CS, V3D_SET_FIELD(0x4, V3D_SMS_STATE));
115+
116+
if (wait_for(!(V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_REE_CS),
117+
V3D_SMS_STATE) == V3D_SMS_ISOLATING_FOR_RESET) &&
118+
!(V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_REE_CS),
119+
V3D_SMS_STATE) == V3D_SMS_RESETTING), 100)) {
120+
DRM_ERROR("Failed to wait for SMS reset\n");
121+
}
122+
}
123+
108124
void
109125
v3d_reset(struct v3d_dev *v3d)
110126
{
@@ -120,6 +136,7 @@ v3d_reset(struct v3d_dev *v3d)
120136
v3d_idle_axi(v3d, 0);
121137

122138
v3d_idle_gca(v3d);
139+
v3d_reset_sms(v3d);
123140
v3d_reset_v3d(v3d);
124141

125142
v3d_mmu_set_page_table(v3d);

drivers/gpu/drm/v3d/v3d_regs.h

+26
Original file line numberDiff line numberDiff line change
@@ -515,4 +515,30 @@
515515
# define V3D_ERR_VPAERGS BIT(1)
516516
# define V3D_ERR_VPAEABB BIT(0)
517517

518+
#define V3D_SMS_REE_CS 0x00000
519+
#define V3D_SMS_TEE_CS 0x00400
520+
# define V3D_SMS_INTERRUPT BIT(31)
521+
# define V3D_SMS_POWER_OFF BIT(30)
522+
# define V3D_SMS_CLEAR_POWER_OFF BIT(29)
523+
# define V3D_SMS_LOCK BIT(28)
524+
# define V3D_SMS_CLEAR_LOCK BIT(27)
525+
# define V3D_SMS_SVP_MODE_EXIT BIT(26)
526+
# define V3D_SMS_CLEAR_SVP_MODE_EXIT BIT(25)
527+
# define V3D_SMS_SVP_MODE_ENTER BIT(24)
528+
# define V3D_SMS_CLEAR_SVP_MODE_ENTER BIT(23)
529+
# define V3D_SMS_THEIR_MODE_EXIT BIT(22)
530+
# define V3D_SMS_THEIR_MODE_ENTER BIT(21)
531+
# define V3D_SMS_OUR_MODE_EXIT BIT(20)
532+
# define V3D_SMS_CLEAR_OUR_MODE_EXIT BIT(19)
533+
# define V3D_SMS_SEQ_PC_MASK V3D_MASK(16, 10)
534+
# define V3D_SMS_SEQ_PC_SHIFT 10
535+
# define V3D_SMS_HUBCORE_STATUS_MASK V3D_MASK(9, 8)
536+
# define V3D_SMS_HUBCORE_STATUS_SHIFT 8
537+
# define V3D_SMS_NEW_MODE_MASK V3D_MASK(7, 6)
538+
# define V3D_SMS_NEW_MODE_SHIFT 6
539+
# define V3D_SMS_OLD_MODE_MASK V3D_MASK(5, 4)
540+
# define V3D_SMS_OLD_MODE_SHIFT 4
541+
# define V3D_SMS_STATE_MASK V3D_MASK(3, 0)
542+
# define V3D_SMS_STATE_SHIFT 0
543+
518544
#endif /* V3D_REGS_H */

0 commit comments

Comments
 (0)