1 From 01e67fe435419efedf2431d582fdd17340041453 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Mon, 21 Nov 2022 17:04:31 +0100
4 Subject: [PATCH] drm/vc4: tests: Fail the current test if we access a
7 Accessing a register when running under kunit is a bad idea since our
8 device is completely mocked.
10 Fail the current test if we ever access any of our hardware registers.
12 Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
13 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
15 drivers/gpu/drm/vc4/vc4_crtc.c | 13 +++++++++++--
16 drivers/gpu/drm/vc4/vc4_dpi.c | 13 +++++++++++--
17 drivers/gpu/drm/vc4/vc4_drv.h | 29 +++++++++++++++++++++++++----
18 drivers/gpu/drm/vc4/vc4_dsi.c | 9 ++++++++-
19 drivers/gpu/drm/vc4/vc4_hdmi_regs.h | 4 ++++
20 drivers/gpu/drm/vc4/vc4_txp.c | 13 +++++++++++--
21 drivers/gpu/drm/vc4/vc4_vec.c | 13 +++++++++++--
22 7 files changed, 81 insertions(+), 13 deletions(-)
24 --- a/drivers/gpu/drm/vc4/vc4_crtc.c
25 +++ b/drivers/gpu/drm/vc4/vc4_crtc.c
28 #define HVS_FIFO_LATENCY_PIX 6
30 -#define CRTC_WRITE(offset, val) writel(val, vc4_crtc->regs + (offset))
31 -#define CRTC_READ(offset) readl(vc4_crtc->regs + (offset))
32 +#define CRTC_WRITE(offset, val) \
34 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
35 + writel(val, vc4_crtc->regs + (offset)); \
38 +#define CRTC_READ(offset) \
40 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
41 + readl(vc4_crtc->regs + (offset)); \
44 static const struct debugfs_reg32 crtc_regs[] = {
45 VC4_REG32(PV_CONTROL),
46 --- a/drivers/gpu/drm/vc4/vc4_dpi.c
47 +++ b/drivers/gpu/drm/vc4/vc4_dpi.c
48 @@ -103,8 +103,17 @@ to_vc4_dpi(struct drm_encoder *encoder)
49 return container_of(encoder, struct vc4_dpi, encoder.base);
52 -#define DPI_READ(offset) readl(dpi->regs + (offset))
53 -#define DPI_WRITE(offset, val) writel(val, dpi->regs + (offset))
54 +#define DPI_READ(offset) \
56 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
57 + readl(dpi->regs + (offset)); \
60 +#define DPI_WRITE(offset, val) \
62 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
63 + writel(val, dpi->regs + (offset)); \
66 static const struct debugfs_reg32 dpi_regs[] = {
68 --- a/drivers/gpu/drm/vc4/vc4_drv.h
69 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
71 #include <drm/drm_mm.h>
72 #include <drm/drm_modeset_lock.h>
74 +#include <kunit/test-bug.h>
76 #include "uapi/drm/vc4_drm.h"
79 @@ -669,10 +671,29 @@ to_vc4_crtc_state(const struct drm_crtc_
80 return container_of(crtc_state, struct vc4_crtc_state, base);
83 -#define V3D_READ(offset) readl(vc4->v3d->regs + offset)
84 -#define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
85 -#define HVS_READ(offset) readl(hvs->regs + offset)
86 -#define HVS_WRITE(offset, val) writel(val, hvs->regs + offset)
87 +#define V3D_READ(offset) \
89 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
90 + readl(vc4->v3d->regs + (offset)); \
93 +#define V3D_WRITE(offset, val) \
95 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
96 + writel(val, vc4->v3d->regs + (offset)); \
99 +#define HVS_READ(offset) \
101 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
102 + readl(hvs->regs + (offset)); \
105 +#define HVS_WRITE(offset, val) \
107 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
108 + writel(val, hvs->regs + (offset)); \
111 #define VC4_REG32(reg) { .name = #reg, .offset = reg }
113 --- a/drivers/gpu/drm/vc4/vc4_dsi.c
114 +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
115 @@ -623,6 +623,8 @@ dsi_dma_workaround_write(struct vc4_dsi
119 + kunit_fail_current_test("Accessing a register in a unit test!\n");
121 /* DSI0 should be able to write normally. */
123 writel(val, dsi->regs + offset);
124 @@ -651,7 +653,12 @@ dsi_dma_workaround_write(struct vc4_dsi
125 DRM_ERROR("Failed to wait for DMA: %d\n", ret);
128 -#define DSI_READ(offset) readl(dsi->regs + (offset))
129 +#define DSI_READ(offset) \
131 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
132 + readl(dsi->regs + (offset)); \
135 #define DSI_WRITE(offset, val) dsi_dma_workaround_write(dsi, offset, val)
136 #define DSI_PORT_READ(offset) \
137 DSI_READ(dsi->variant->port ? DSI1_##offset : DSI0_##offset)
138 --- a/drivers/gpu/drm/vc4/vc4_hdmi_regs.h
139 +++ b/drivers/gpu/drm/vc4/vc4_hdmi_regs.h
140 @@ -456,6 +456,8 @@ static inline u32 vc4_hdmi_read(struct v
142 WARN_ON(pm_runtime_status_suspended(&hdmi->pdev->dev));
144 + kunit_fail_current_test("Accessing an HDMI register in a unit test!\n");
146 if (reg >= variant->num_registers) {
147 dev_warn(&hdmi->pdev->dev,
148 "Invalid register ID %u\n", reg);
149 @@ -486,6 +488,8 @@ static inline void vc4_hdmi_write(struct
151 WARN_ON(pm_runtime_status_suspended(&hdmi->pdev->dev));
153 + kunit_fail_current_test("Accessing an HDMI register in a unit test!\n");
155 if (reg >= variant->num_registers) {
156 dev_warn(&hdmi->pdev->dev,
157 "Invalid register ID %u\n", reg);
158 --- a/drivers/gpu/drm/vc4/vc4_txp.c
159 +++ b/drivers/gpu/drm/vc4/vc4_txp.c
161 /* Number of lines received and committed to memory. */
162 #define TXP_PROGRESS 0x10
164 -#define TXP_READ(offset) readl(txp->regs + (offset))
165 -#define TXP_WRITE(offset, val) writel(val, txp->regs + (offset))
166 +#define TXP_READ(offset) \
168 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
169 + readl(txp->regs + (offset)); \
172 +#define TXP_WRITE(offset, val) \
174 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
175 + writel(val, txp->regs + (offset)); \
179 struct vc4_crtc base;
180 --- a/drivers/gpu/drm/vc4/vc4_vec.c
181 +++ b/drivers/gpu/drm/vc4/vc4_vec.c
182 @@ -207,8 +207,17 @@ struct vc4_vec {
183 struct debugfs_regset32 regset;
186 -#define VEC_READ(offset) readl(vec->regs + (offset))
187 -#define VEC_WRITE(offset, val) writel(val, vec->regs + (offset))
188 +#define VEC_READ(offset) \
190 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
191 + readl(vec->regs + (offset)); \
194 +#define VEC_WRITE(offset, val) \
196 + kunit_fail_current_test("Accessing a register in a unit test!\n"); \
197 + writel(val, vec->regs + (offset)); \
200 static inline struct vc4_vec *
201 encoder_to_vc4_vec(struct drm_encoder *encoder)