Skip to content

Commit ea92769

Browse files
mairacanalintel-lab-lkp
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: raspberrypi/linux#6660 Reviewed-by: Iago Toral Quiroga <[email protected]> Signed-off-by: Maíra Canal <[email protected]>
1 parent ff59bcd commit ea92769

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

Diff for: drivers/gpu/drm/v3d/v3d_drv.c

+40
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,36 @@ static const struct of_device_id v3d_of_match[] = {
263263
};
264264
MODULE_DEVICE_TABLE(of, v3d_of_match);
265265

266+
static void
267+
v3d_idle_sms(struct v3d_dev *v3d)
268+
{
269+
if (v3d->ver < V3D_GEN_71)
270+
return;
271+
272+
V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_CLEAR_POWER_OFF);
273+
274+
if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
275+
V3D_SMS_STATE) == V3D_SMS_IDLE), 100)) {
276+
DRM_ERROR("Failed to power up SMS\n");
277+
}
278+
279+
v3d_reset_sms(v3d);
280+
}
281+
282+
static void
283+
v3d_power_off_sms(struct v3d_dev *v3d)
284+
{
285+
if (v3d->ver < V3D_GEN_71)
286+
return;
287+
288+
V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_POWER_OFF);
289+
290+
if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
291+
V3D_SMS_STATE) == V3D_SMS_POWER_OFF_STATE), 100)) {
292+
DRM_ERROR("Failed to power off SMS\n");
293+
}
294+
}
295+
266296
static int
267297
map_regs(struct v3d_dev *v3d, void __iomem **regs, const char *name)
268298
{
@@ -300,6 +330,12 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
300330
if (ret)
301331
return ret;
302332

333+
if (v3d->ver >= V3D_GEN_71) {
334+
ret = map_regs(v3d, &v3d->sms_regs, "sms");
335+
if (ret)
336+
return ret;
337+
}
338+
303339
v3d->clk = devm_clk_get_optional(dev, NULL);
304340
if (IS_ERR(v3d->clk))
305341
return dev_err_probe(dev, PTR_ERR(v3d->clk), "Failed to get V3D clock\n");
@@ -310,6 +346,8 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
310346
return ret;
311347
}
312348

349+
v3d_idle_sms(v3d);
350+
313351
mmu_debug = V3D_READ(V3D_MMU_DEBUG_INFO);
314352
mask = DMA_BIT_MASK(30 + V3D_GET_FIELD(mmu_debug, V3D_MMU_PA_WIDTH));
315353
ret = dma_set_mask_and_coherent(dev, mask);
@@ -410,6 +448,8 @@ static void v3d_platform_drm_remove(struct platform_device *pdev)
410448
dma_free_wc(v3d->drm.dev, 4096, v3d->mmu_scratch,
411449
v3d->mmu_scratch_paddr);
412450

451+
v3d_power_off_sms(v3d);
452+
413453
clk_disable_unprepare(v3d->clk);
414454
}
415455

Diff for: 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 reset_control *reset;
123124

@@ -268,6 +269,15 @@ to_v3d_fence(struct dma_fence *fence)
268269
#define V3D_GCA_READ(offset) readl(v3d->gca_regs + offset)
269270
#define V3D_GCA_WRITE(offset, val) writel(val, v3d->gca_regs + offset)
270271

272+
#define V3D_SMS_IDLE 0x0
273+
#define V3D_SMS_ISOLATING_FOR_RESET 0xa
274+
#define V3D_SMS_RESETTING 0xb
275+
#define V3D_SMS_ISOLATING_FOR_POWER_OFF 0xc
276+
#define V3D_SMS_POWER_OFF_STATE 0xd
277+
278+
#define V3D_SMS_READ(offset) readl(v3d->sms_regs + (offset))
279+
#define V3D_SMS_WRITE(offset, val) writel(val, v3d->sms_regs + (offset))
280+
271281
#define V3D_CORE_READ(core, offset) readl(v3d->core_regs[core] + offset)
272282
#define V3D_CORE_WRITE(core, offset, val) writel(val, v3d->core_regs[core] + offset)
273283

@@ -546,6 +556,7 @@ struct dma_fence *v3d_fence_create(struct v3d_dev *v3d, enum v3d_queue queue);
546556
/* v3d_gem.c */
547557
int v3d_gem_init(struct drm_device *dev);
548558
void v3d_gem_destroy(struct drm_device *dev);
559+
void v3d_reset_sms(struct v3d_dev *v3d);
549560
void v3d_reset(struct v3d_dev *v3d);
550561
void v3d_invalidate_caches(struct v3d_dev *v3d);
551562
void v3d_clean_caches(struct v3d_dev *v3d);

Diff for: drivers/gpu/drm/v3d/v3d_gem.c

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

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

121137
v3d_idle_gca(v3d);
138+
v3d_reset_sms(v3d);
122139
v3d_reset_v3d(v3d);
123140

124141
v3d_mmu_set_page_table(v3d);

Diff for: 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)