Skip to content

Commit 1cbc91e

Browse files
committed
drm/vc4: Consolidate Hardware Revision Check
A new generation of controller has been introduced with the BCM2711/RaspberryPi4. This generation needs a bunch of quirks, and over time we've piled on a number of checks in most parts of the drivers. All these checks are performed several times, and are not always consistent. Let's create a single, global, variable to hold it and use it everywhere. Reviewed-by: Melissa Wen <mwen@igalia.com> Signed-off-by: Maxime Ripard <maxime@cerno.tech> Link: https://lore.kernel.org/r/20220610115149.964394-3-maxime@cerno.tech
1 parent cb468c7 commit 1cbc91e

6 files changed

Lines changed: 30 additions & 29 deletions

File tree

drivers/gpu/drm/vc4/vc4_crtc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static u32 vc4_get_fifo_full_level(struct vc4_crtc *vc4_crtc, u32 format)
256256
* Removing 1 from the FIFO full level however
257257
* seems to completely remove that issue.
258258
*/
259-
if (!vc4->hvs->hvs5)
259+
if (!vc4->is_vc5)
260260
return fifo_len_bytes - 3 * HVS_FIFO_LATENCY_PIX - 1;
261261

262262
return fifo_len_bytes - 3 * HVS_FIFO_LATENCY_PIX;
@@ -389,7 +389,7 @@ static void vc4_crtc_config_pv(struct drm_crtc *crtc, struct drm_encoder *encode
389389
if (is_dsi)
390390
CRTC_WRITE(PV_HACT_ACT, mode->hdisplay * pixel_rep);
391391

392-
if (vc4->hvs->hvs5)
392+
if (vc4->is_vc5)
393393
CRTC_WRITE(PV_MUX_CFG,
394394
VC4_SET_FIELD(PV_MUX_CFG_RGB_PIXEL_MUX_MODE_NO_SWAP,
395395
PV_MUX_CFG_RGB_PIXEL_MUX_MODE));
@@ -1149,7 +1149,7 @@ int vc4_crtc_init(struct drm_device *drm, struct vc4_crtc *vc4_crtc,
11491149
crtc_funcs, NULL);
11501150
drm_crtc_helper_add(crtc, crtc_helper_funcs);
11511151

1152-
if (!vc4->hvs->hvs5) {
1152+
if (!vc4->is_vc5) {
11531153
drm_mode_crtc_set_gamma_size(crtc, ARRAY_SIZE(vc4_crtc->lut_r));
11541154

11551155
drm_crtc_enable_color_mgmt(crtc, 0, false, crtc->gamma_size);

drivers/gpu/drm/vc4/vc4_drv.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,13 @@ static int vc4_drm_bind(struct device *dev)
217217
struct vc4_dev *vc4;
218218
struct device_node *node;
219219
struct drm_crtc *crtc;
220+
bool is_vc5;
220221
int ret = 0;
221222

222223
dev->coherent_dma_mask = DMA_BIT_MASK(32);
223224

225+
is_vc5 = of_device_is_compatible(dev->of_node, "brcm,bcm2711-vc5");
226+
224227
/* If VC4 V3D is missing, don't advertise render nodes. */
225228
node = of_find_matching_node_and_match(NULL, vc4_v3d_dt_match, NULL);
226229
if (!node || !of_device_is_available(node))
@@ -230,6 +233,7 @@ static int vc4_drm_bind(struct device *dev)
230233
vc4 = devm_drm_dev_alloc(dev, &vc4_drm_driver, struct vc4_dev, base);
231234
if (IS_ERR(vc4))
232235
return PTR_ERR(vc4);
236+
vc4->is_vc5 = is_vc5;
233237

234238
drm = &vc4->base;
235239
platform_set_drvdata(pdev, drm);

drivers/gpu/drm/vc4/vc4_drv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ struct vc4_perfmon {
7474
struct vc4_dev {
7575
struct drm_device base;
7676

77+
bool is_vc5;
78+
7779
unsigned int irq;
7880

7981
struct vc4_hvs *hvs;
@@ -316,6 +318,7 @@ struct vc4_v3d {
316318
};
317319

318320
struct vc4_hvs {
321+
struct vc4_dev *vc4;
319322
struct platform_device *pdev;
320323
void __iomem *regs;
321324
u32 __iomem *dlist;
@@ -333,9 +336,6 @@ struct vc4_hvs {
333336
struct drm_mm_node mitchell_netravali_filter;
334337

335338
struct debugfs_regset32 regset;
336-
337-
/* HVS version 5 flag, therefore requires updated dlist structures */
338-
bool hvs5;
339339
};
340340

341341
struct vc4_plane {

drivers/gpu/drm/vc4/vc4_hvs.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ u8 vc4_hvs_get_fifo_frame_count(struct vc4_hvs *hvs, unsigned int fifo)
220220

221221
int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output)
222222
{
223+
struct vc4_dev *vc4 = hvs->vc4;
223224
u32 reg;
224225
int ret;
225226

226-
if (!hvs->hvs5)
227+
if (!vc4->is_vc5)
227228
return output;
228229

229230
switch (output) {
@@ -273,6 +274,7 @@ int vc4_hvs_get_fifo_from_output(struct vc4_hvs *hvs, unsigned int output)
273274
static int vc4_hvs_init_channel(struct vc4_hvs *hvs, struct drm_crtc *crtc,
274275
struct drm_display_mode *mode, bool oneshot)
275276
{
277+
struct vc4_dev *vc4 = hvs->vc4;
276278
struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
277279
struct vc4_crtc_state *vc4_crtc_state = to_vc4_crtc_state(crtc->state);
278280
unsigned int chan = vc4_crtc_state->assigned_channel;
@@ -291,7 +293,7 @@ static int vc4_hvs_init_channel(struct vc4_hvs *hvs, struct drm_crtc *crtc,
291293
*/
292294
dispctrl = SCALER_DISPCTRLX_ENABLE;
293295

294-
if (!hvs->hvs5)
296+
if (!vc4->is_vc5)
295297
dispctrl |= VC4_SET_FIELD(mode->hdisplay,
296298
SCALER_DISPCTRLX_WIDTH) |
297299
VC4_SET_FIELD(mode->vdisplay,
@@ -312,7 +314,7 @@ static int vc4_hvs_init_channel(struct vc4_hvs *hvs, struct drm_crtc *crtc,
312314

313315
HVS_WRITE(SCALER_DISPBKGNDX(chan), dispbkgndx |
314316
SCALER_DISPBKGND_AUTOHS |
315-
((!hvs->hvs5) ? SCALER_DISPBKGND_GAMMA : 0) |
317+
((!vc4->is_vc5) ? SCALER_DISPBKGND_GAMMA : 0) |
316318
(interlace ? SCALER_DISPBKGND_INTERLACE : 0));
317319

318320
/* Reload the LUT, since the SRAMs would have been disabled if
@@ -617,11 +619,9 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
617619
if (!hvs)
618620
return -ENOMEM;
619621

622+
hvs->vc4 = vc4;
620623
hvs->pdev = pdev;
621624

622-
if (of_device_is_compatible(pdev->dev.of_node, "brcm,bcm2711-hvs"))
623-
hvs->hvs5 = true;
624-
625625
hvs->regs = vc4_ioremap_regs(pdev, 0);
626626
if (IS_ERR(hvs->regs))
627627
return PTR_ERR(hvs->regs);
@@ -630,7 +630,7 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
630630
hvs->regset.regs = hvs_regs;
631631
hvs->regset.nregs = ARRAY_SIZE(hvs_regs);
632632

633-
if (hvs->hvs5) {
633+
if (vc4->is_vc5) {
634634
hvs->core_clk = devm_clk_get(&pdev->dev, NULL);
635635
if (IS_ERR(hvs->core_clk)) {
636636
dev_err(&pdev->dev, "Couldn't get core clock\n");
@@ -644,7 +644,7 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
644644
}
645645
}
646646

647-
if (!hvs->hvs5)
647+
if (!vc4->is_vc5)
648648
hvs->dlist = hvs->regs + SCALER_DLIST_START;
649649
else
650650
hvs->dlist = hvs->regs + SCALER5_DLIST_START;
@@ -665,7 +665,7 @@ static int vc4_hvs_bind(struct device *dev, struct device *master, void *data)
665665
* between planes when they don't overlap on the screen, but
666666
* for now we just allocate globally.
667667
*/
668-
if (!hvs->hvs5)
668+
if (!vc4->is_vc5)
669669
/* 48k words of 2x12-bit pixels */
670670
drm_mm_init(&hvs->lbm_mm, 0, 48 * 1024);
671671
else

drivers/gpu/drm/vc4/vc4_kms.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void vc4_atomic_commit_tail(struct drm_atomic_state *state)
393393
old_hvs_state->fifo_state[channel].pending_commit = NULL;
394394
}
395395

396-
if (vc4->hvs->hvs5) {
396+
if (vc4->is_vc5) {
397397
unsigned long state_rate = max(old_hvs_state->core_clock_rate,
398398
new_hvs_state->core_clock_rate);
399399
unsigned long core_rate = max_t(unsigned long,
@@ -412,7 +412,7 @@ static void vc4_atomic_commit_tail(struct drm_atomic_state *state)
412412

413413
vc4_ctm_commit(vc4, state);
414414

415-
if (vc4->hvs->hvs5)
415+
if (vc4->is_vc5)
416416
vc5_hvs_pv_muxing_commit(vc4, state);
417417
else
418418
vc4_hvs_pv_muxing_commit(vc4, state);
@@ -430,7 +430,7 @@ static void vc4_atomic_commit_tail(struct drm_atomic_state *state)
430430

431431
drm_atomic_helper_cleanup_planes(dev, state);
432432

433-
if (vc4->hvs->hvs5) {
433+
if (vc4->is_vc5) {
434434
drm_dbg(dev, "Running the core clock at %lu Hz\n",
435435
new_hvs_state->core_clock_rate);
436436

@@ -1000,16 +1000,14 @@ static const struct drm_mode_config_funcs vc4_mode_funcs = {
10001000
int vc4_kms_load(struct drm_device *dev)
10011001
{
10021002
struct vc4_dev *vc4 = to_vc4_dev(dev);
1003-
bool is_vc5 = of_device_is_compatible(dev->dev->of_node,
1004-
"brcm,bcm2711-vc5");
10051003
int ret;
10061004

10071005
/*
10081006
* The limits enforced by the load tracker aren't relevant for
10091007
* the BCM2711, but the load tracker computations are used for
10101008
* the core clock rate calculation.
10111009
*/
1012-
if (!is_vc5) {
1010+
if (!vc4->is_vc5) {
10131011
/* Start with the load tracker enabled. Can be
10141012
* disabled through the debugfs load_tracker file.
10151013
*/
@@ -1025,7 +1023,7 @@ int vc4_kms_load(struct drm_device *dev)
10251023
return ret;
10261024
}
10271025

1028-
if (is_vc5) {
1026+
if (vc4->is_vc5) {
10291027
dev->mode_config.max_width = 7680;
10301028
dev->mode_config.max_height = 7680;
10311029
} else {

drivers/gpu/drm/vc4/vc4_plane.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,10 @@ static u32 vc4_lbm_size(struct drm_plane_state *state)
489489
}
490490

491491
/* Align it to 64 or 128 (hvs5) bytes */
492-
lbm = roundup(lbm, vc4->hvs->hvs5 ? 128 : 64);
492+
lbm = roundup(lbm, vc4->is_vc5 ? 128 : 64);
493493

494494
/* Each "word" of the LBM memory contains 2 or 4 (hvs5) pixels */
495-
lbm /= vc4->hvs->hvs5 ? 4 : 2;
495+
lbm /= vc4->is_vc5 ? 4 : 2;
496496

497497
return lbm;
498498
}
@@ -608,7 +608,7 @@ static int vc4_plane_allocate_lbm(struct drm_plane_state *state)
608608
ret = drm_mm_insert_node_generic(&vc4->hvs->lbm_mm,
609609
&vc4_state->lbm,
610610
lbm_size,
611-
vc4->hvs->hvs5 ? 64 : 32,
611+
vc4->is_vc5 ? 64 : 32,
612612
0, 0);
613613
spin_unlock_irqrestore(&vc4->hvs->mm_lock, irqflags);
614614

@@ -917,7 +917,7 @@ static int vc4_plane_mode_set(struct drm_plane *plane,
917917
mix_plane_alpha = state->alpha != DRM_BLEND_ALPHA_OPAQUE &&
918918
fb->format->has_alpha;
919919

920-
if (!vc4->hvs->hvs5) {
920+
if (!vc4->is_vc5) {
921921
/* Control word */
922922
vc4_dlist_write(vc4_state,
923923
SCALER_CTL0_VALID |
@@ -1457,14 +1457,13 @@ static const struct drm_plane_funcs vc4_plane_funcs = {
14571457
struct drm_plane *vc4_plane_init(struct drm_device *dev,
14581458
enum drm_plane_type type)
14591459
{
1460+
struct vc4_dev *vc4 = to_vc4_dev(dev);
14601461
struct drm_plane *plane = NULL;
14611462
struct vc4_plane *vc4_plane;
14621463
u32 formats[ARRAY_SIZE(hvs_formats)];
14631464
int num_formats = 0;
14641465
int ret = 0;
14651466
unsigned i;
1466-
bool hvs5 = of_device_is_compatible(dev->dev->of_node,
1467-
"brcm,bcm2711-vc5");
14681467
static const uint64_t modifiers[] = {
14691468
DRM_FORMAT_MOD_BROADCOM_VC4_T_TILED,
14701469
DRM_FORMAT_MOD_BROADCOM_SAND128,
@@ -1480,7 +1479,7 @@ struct drm_plane *vc4_plane_init(struct drm_device *dev,
14801479
return ERR_PTR(-ENOMEM);
14811480

14821481
for (i = 0; i < ARRAY_SIZE(hvs_formats); i++) {
1483-
if (!hvs_formats[i].hvs5_only || hvs5) {
1482+
if (!hvs_formats[i].hvs5_only || vc4->is_vc5) {
14841483
formats[num_formats] = hvs_formats[i].drm;
14851484
num_formats++;
14861485
}

0 commit comments

Comments
 (0)