Skip to content

Commit

Permalink
drm/vc4: tests: Fail the current test if we access a register
Browse files Browse the repository at this point in the history
Accessing a register when running under kunit is a bad idea since our
device is completely mocked.

Fail the current test if we ever access any of our hardware registers.

Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Maíra Canal <mcanal@igalia.com>
Link: https://lore.kernel.org/r/20221123-rpi-kunit-tests-v3-18-4615a663a84a@cerno.tech
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
  • Loading branch information
Maxime Ripard committed Dec 8, 2022
1 parent f759f5b commit da43ff0
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 13 deletions.
13 changes: 11 additions & 2 deletions drivers/gpu/drm/vc4/vc4_crtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,17 @@

#define HVS_FIFO_LATENCY_PIX 6

#define CRTC_WRITE(offset, val) writel(val, vc4_crtc->regs + (offset))
#define CRTC_READ(offset) readl(vc4_crtc->regs + (offset))
#define CRTC_WRITE(offset, val) \
do { \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
writel(val, vc4_crtc->regs + (offset)); \
} while (0)

#define CRTC_READ(offset) \
({ \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
readl(vc4_crtc->regs + (offset)); \
})

static const struct debugfs_reg32 crtc_regs[] = {
VC4_REG32(PV_CONTROL),
Expand Down
13 changes: 11 additions & 2 deletions drivers/gpu/drm/vc4/vc4_dpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,17 @@ to_vc4_dpi(struct drm_encoder *encoder)
return container_of(encoder, struct vc4_dpi, encoder.base);
}

#define DPI_READ(offset) readl(dpi->regs + (offset))
#define DPI_WRITE(offset, val) writel(val, dpi->regs + (offset))
#define DPI_READ(offset) \
({ \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
readl(dpi->regs + (offset)); \
})

#define DPI_WRITE(offset, val) \
do { \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
writel(val, dpi->regs + (offset)); \
} while (0)

static const struct debugfs_reg32 dpi_regs[] = {
VC4_REG32(DPI_C),
Expand Down
29 changes: 25 additions & 4 deletions drivers/gpu/drm/vc4/vc4_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <drm/drm_mm.h>
#include <drm/drm_modeset_lock.h>

#include <kunit/test-bug.h>

#include "uapi/drm/vc4_drm.h"

struct drm_device;
Expand Down Expand Up @@ -645,10 +647,29 @@ to_vc4_crtc_state(const struct drm_crtc_state *crtc_state)
return container_of(crtc_state, struct vc4_crtc_state, base);
}

#define V3D_READ(offset) readl(vc4->v3d->regs + offset)
#define V3D_WRITE(offset, val) writel(val, vc4->v3d->regs + offset)
#define HVS_READ(offset) readl(hvs->regs + offset)
#define HVS_WRITE(offset, val) writel(val, hvs->regs + offset)
#define V3D_READ(offset) \
({ \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
readl(vc4->v3d->regs + (offset)); \
})

#define V3D_WRITE(offset, val) \
do { \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
writel(val, vc4->v3d->regs + (offset)); \
} while (0)

#define HVS_READ(offset) \
({ \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
readl(hvs->regs + (offset)); \
})

#define HVS_WRITE(offset, val) \
do { \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
writel(val, hvs->regs + (offset)); \
} while (0)

#define VC4_REG32(reg) { .name = #reg, .offset = reg }

Expand Down
9 changes: 8 additions & 1 deletion drivers/gpu/drm/vc4/vc4_dsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ dsi_dma_workaround_write(struct vc4_dsi *dsi, u32 offset, u32 val)
dma_cookie_t cookie;
int ret;

kunit_fail_current_test("Accessing a register in a unit test!\n");

/* DSI0 should be able to write normally. */
if (!chan) {
writel(val, dsi->regs + offset);
Expand Down Expand Up @@ -645,7 +647,12 @@ dsi_dma_workaround_write(struct vc4_dsi *dsi, u32 offset, u32 val)
DRM_ERROR("Failed to wait for DMA: %d\n", ret);
}

#define DSI_READ(offset) readl(dsi->regs + (offset))
#define DSI_READ(offset) \
({ \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
readl(dsi->regs + (offset)); \
})

#define DSI_WRITE(offset, val) dsi_dma_workaround_write(dsi, offset, val)
#define DSI_PORT_READ(offset) \
DSI_READ(dsi->variant->port ? DSI1_##offset : DSI0_##offset)
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/vc4/vc4_hdmi_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,8 @@ static inline u32 vc4_hdmi_read(struct vc4_hdmi *hdmi,

WARN_ON(pm_runtime_status_suspended(&hdmi->pdev->dev));

kunit_fail_current_test("Accessing an HDMI register in a unit test!\n");

if (reg >= variant->num_registers) {
dev_warn(&hdmi->pdev->dev,
"Invalid register ID %u\n", reg);
Expand Down Expand Up @@ -486,6 +488,8 @@ static inline void vc4_hdmi_write(struct vc4_hdmi *hdmi,

WARN_ON(pm_runtime_status_suspended(&hdmi->pdev->dev));

kunit_fail_current_test("Accessing an HDMI register in a unit test!\n");

if (reg >= variant->num_registers) {
dev_warn(&hdmi->pdev->dev,
"Invalid register ID %u\n", reg);
Expand Down
13 changes: 11 additions & 2 deletions drivers/gpu/drm/vc4/vc4_txp.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,17 @@
/* Number of lines received and committed to memory. */
#define TXP_PROGRESS 0x10

#define TXP_READ(offset) readl(txp->regs + (offset))
#define TXP_WRITE(offset, val) writel(val, txp->regs + (offset))
#define TXP_READ(offset) \
({ \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
readl(txp->regs + (offset)); \
})

#define TXP_WRITE(offset, val) \
do { \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
writel(val, txp->regs + (offset)); \
} while (0)

struct vc4_txp {
struct vc4_crtc base;
Expand Down
13 changes: 11 additions & 2 deletions drivers/gpu/drm/vc4/vc4_vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,17 @@ struct vc4_vec {
struct debugfs_regset32 regset;
};

#define VEC_READ(offset) readl(vec->regs + (offset))
#define VEC_WRITE(offset, val) writel(val, vec->regs + (offset))
#define VEC_READ(offset) \
({ \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
readl(vec->regs + (offset)); \
})

#define VEC_WRITE(offset, val) \
do { \
kunit_fail_current_test("Accessing a register in a unit test!\n"); \
writel(val, vec->regs + (offset)); \
} while (0)

static inline struct vc4_vec *
encoder_to_vc4_vec(struct drm_encoder *encoder)
Expand Down

0 comments on commit da43ff0

Please sign in to comment.