6c8689e169cb46e130666d0f346bc6b332db0668
[openwrt/staging/xback.git] /
1 From e546f85606dcf2cdff94ff32a0756e2541bccb05 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Wed, 25 Jan 2023 13:05:26 +0100
4 Subject: [PATCH 0033/1085] drm/vc4: hvs: Destroy dlist allocations immediately
5 when running a test
6
7 When running a kunit test, the driver runs with a mock device. As such,
8 any attempt to read or write to a hardware register will fail the
9 current test immediately.
10
11 The dlist allocation management recently introduced will read the
12 current frame count from the HVS to defer its destruction until a
13 subsequent frame has been output. This obviously involves a register
14 read that fails the Kunit tests.
15
16 Change the destruction deferral function to destroy the allocation
17 immediately if we run under kunit. This is essentially harmless since
18 the main reason for that deferall is to prevent any access to the
19 hardware dlist while a frame described by that list is rendered. On our
20 mock driver, we have neither a hardware dlist nor a rendering, so it
21 doesn't matter.
22
23 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
24 ---
25 drivers/gpu/drm/vc4/vc4_hvs.c | 12 ++++++++++++
26 1 file changed, 12 insertions(+)
27
28 --- a/drivers/gpu/drm/vc4/vc4_hvs.c
29 +++ b/drivers/gpu/drm/vc4/vc4_hvs.c
30 @@ -490,6 +490,18 @@ void vc4_hvs_mark_dlist_entry_stale(stru
31 if (!drm_mm_node_allocated(&alloc->mm_node))
32 return;
33
34 + /*
35 + * Kunit tests run with a mock device and we consider any hardware
36 + * access a test failure. Let's free the dlist allocation right away if
37 + * we're running under kunit, we won't risk a dlist corruption anyway.
38 + */
39 + if (kunit_get_current_test()) {
40 + spin_lock_irqsave(&hvs->mm_lock, flags);
41 + vc4_hvs_free_dlist_entry_locked(hvs, alloc);
42 + spin_unlock_irqrestore(&hvs->mm_lock, flags);
43 + return;
44 + }
45 +
46 frcnt = vc4_hvs_get_fifo_frame_count(hvs, alloc->channel);
47 alloc->target_frame_count = (frcnt + 1) & ((1 << 6) - 1);
48