diff mbox series

[24/24] drm/vc4: tests: Add unit test suite for the PV muxing

Message ID 20221123-rpi-kunit-tests-v1-24-051a0bb60a16@cerno.tech (mailing list archive)
State New, archived
Headers show
Series drm: Introduce Kunit Tests to VC4 | expand

Commit Message

Maxime Ripard Nov. 23, 2022, 3:26 p.m. UTC
The HVS to PixelValve muxing code is fairly error prone and has a bunch
of arbitrary constraints due to the hardware setup.

Let's create a test suite that makes sure that the possible combinations
work and the invalid ones don't.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/gpu/drm/vc4/tests/Makefile             |   3 +-
 drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c | 624 +++++++++++++++++++++++++
 2 files changed, 626 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vc4/tests/Makefile b/drivers/gpu/drm/vc4/tests/Makefile
index 3e8a7b4f9017..1ae143c415a4 100644
--- a/drivers/gpu/drm/vc4/tests/Makefile
+++ b/drivers/gpu/drm/vc4/tests/Makefile
@@ -4,4 +4,5 @@  obj-$(CONFIG_DRM_VC4_KUNIT_TEST) += \
 	vc4_mock.o \
 	vc4_mock_crtc.o \
 	vc4_mock_output.o \
-	vc4_mock_plane.o
+	vc4_mock_plane.o \
+	vc4_test_pv_muxing.o
diff --git a/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c
new file mode 100644
index 000000000000..3047fc768c09
--- /dev/null
+++ b/drivers/gpu/drm/vc4/tests/vc4_test_pv_muxing.c
@@ -0,0 +1,624 @@ 
+// SPDX-License-Identifier: GPL-2.0
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_state_helper.h>
+#include <drm/drm_atomic_uapi.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_drv.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_mode.h>
+#include <drm/drm_modeset_helper_vtables.h>
+#include <drm/drm_plane.h>
+
+#include <kunit/test.h>
+
+#include "../../tests/drm_kunit_helpers.h"
+
+#include "../vc4_drv.h"
+
+#include "vc4_mock.h"
+
+struct pv_muxing_priv {
+	struct vc4_dev *vc4;
+	struct drm_modeset_acquire_ctx ctx;
+	struct drm_atomic_state *state;
+};
+
+static bool check_fifo_conflict(struct kunit *test,
+				const struct drm_atomic_state *state)
+{
+	struct vc4_hvs_state *hvs_state;
+	unsigned int used_fifos = 0;
+	unsigned int i;
+
+	hvs_state = vc4_hvs_get_new_global_state(state);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hvs_state);
+
+	for (i = 0; i < HVS_NUM_CHANNELS; i++) {
+		if (!hvs_state->fifo_state[i].in_use)
+			continue;
+
+		KUNIT_EXPECT_FALSE(test, used_fifos & BIT(i));
+		used_fifos |= BIT(i);
+	}
+
+	return true;
+}
+
+struct encoder_constraint {
+	enum vc4_encoder_type type;
+	unsigned int *channels;
+	size_t nchannels;
+};
+
+#define ENCODER_CONSTRAINT(_type, ...)					\
+	{								\
+		.type = _type,						\
+		.channels = (unsigned int[]) { __VA_ARGS__ },		\
+		.nchannels = sizeof((unsigned int[]) { __VA_ARGS__ }) /	\
+			     sizeof(unsigned int),			\
+	}
+
+static bool __check_encoder_constraints(const struct encoder_constraint *constraints,
+					size_t nconstraints,
+					enum vc4_encoder_type type,
+					unsigned int channel)
+{
+	unsigned int i;
+
+	for (i = 0; i < nconstraints; i++) {
+		const struct encoder_constraint *constraint = &constraints[i];
+		unsigned int j;
+
+		if (constraint->type != type)
+			continue;
+
+		for (j = 0; j < constraint->nchannels; j++) {
+			unsigned int _channel = constraint->channels[j];
+
+			if (channel != _channel)
+				continue;
+
+			return true;
+		}
+	}
+
+	return false;
+}
+
+static const struct encoder_constraint vc5_encoder_constraints[] = {
+	ENCODER_CONSTRAINT(VC4_ENCODER_TYPE_DPI, 0),
+	ENCODER_CONSTRAINT(VC4_ENCODER_TYPE_DSI0, 0),
+	ENCODER_CONSTRAINT(VC4_ENCODER_TYPE_VEC, 1),
+	ENCODER_CONSTRAINT(VC4_ENCODER_TYPE_TXP, 0, 2),
+	ENCODER_CONSTRAINT(VC4_ENCODER_TYPE_DSI1, 0, 1, 2),
+	ENCODER_CONSTRAINT(VC4_ENCODER_TYPE_HDMI0, 0, 1, 2),
+	ENCODER_CONSTRAINT(VC4_ENCODER_TYPE_HDMI1, 0, 1, 2),
+};
+
+static bool check_vc5_encoder_constraints(enum vc4_encoder_type type, unsigned int channel)
+{
+	return __check_encoder_constraints(vc5_encoder_constraints,
+					   ARRAY_SIZE(vc5_encoder_constraints),
+					   type, channel);
+}
+
+static bool check_channel_for_encoder(struct kunit *test,
+				      const struct drm_atomic_state *state,
+				      enum vc4_encoder_type type)
+{
+	struct drm_device *drm = state->dev;
+	struct drm_encoder *encoder;
+	struct drm_crtc *crtc;
+	struct drm_crtc_state *crtc_state;
+	struct vc4_crtc_state *new_vc4_crtc_state;
+	struct vc4_hvs_state *new_hvs_state;
+	unsigned int channel;
+
+	new_hvs_state = vc4_hvs_get_new_global_state(state);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, new_hvs_state);
+
+	encoder = vc4_find_encoder_by_type(drm, type);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, encoder);
+
+	crtc = vc4_find_crtc_for_encoder(test, drm, encoder);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc);
+
+	crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, crtc_state);
+
+	new_vc4_crtc_state = to_vc4_crtc_state(crtc_state);
+	channel = new_vc4_crtc_state->assigned_channel;
+	KUNIT_EXPECT_NE(test, channel, VC4_HVS_CHANNEL_DISABLED);
+
+	KUNIT_EXPECT_TRUE(test, new_hvs_state->fifo_state[channel].in_use);
+
+	KUNIT_EXPECT_TRUE(test,
+			  check_vc5_encoder_constraints(type,
+							channel));
+
+	return true;
+}
+
+struct pv_muxing_param {
+	const char *name;
+	enum vc4_encoder_type *encoders;
+	size_t nencoders;
+};
+
+#define PV_MUXING_TEST(_name, ...)							\
+	{										\
+		.name = _name,								\
+		.encoders = (enum vc4_encoder_type[]) { __VA_ARGS__ },			\
+		.nencoders = sizeof((enum vc4_encoder_type[]) { __VA_ARGS__ }) /	\
+			     sizeof(enum vc4_encoder_type),				\
+	}
+
+static const struct pv_muxing_param vc5_test_pv_muxing_params[] = {
+	PV_MUXING_TEST("1 output: DPI",
+		       VC4_ENCODER_TYPE_DPI),
+	PV_MUXING_TEST("1 output: DSI0",
+		       VC4_ENCODER_TYPE_DSI0),
+	PV_MUXING_TEST("1 output: DSI1",
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("1 output: HDMI0",
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("1 output: HDMI1",
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("1 output: VEC",
+		       VC4_ENCODER_TYPE_VEC),
+	PV_MUXING_TEST("2 output: DPI, DSI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("2 output: DPI, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("2 output: DPI, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("2 output: DPI, TXP",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP),
+	PV_MUXING_TEST("2 output: DPI, VEC",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC),
+	PV_MUXING_TEST("2 output: DPI, DSI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("2 output: DSI0, DSI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("2 output: DSI0, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("2 output: DSI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("2 output: DSI0, TXP",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP),
+	PV_MUXING_TEST("2 output: DSI0, VEC",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC),
+	PV_MUXING_TEST("2 output: DSI0, DSI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("2 output: DSI1, VEC",
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_VEC),
+	PV_MUXING_TEST("2 output: DSI1, TXP",
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_TXP),
+	PV_MUXING_TEST("2 output: DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("2 output: DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("2 output: HDMI0, VEC",
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_VEC),
+	PV_MUXING_TEST("2 output: HDMI0, TXP",
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_TXP),
+	PV_MUXING_TEST("2 output: HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("2 output: HDMI1, VEC",
+		       VC4_ENCODER_TYPE_HDMI1,
+		       VC4_ENCODER_TYPE_VEC),
+	PV_MUXING_TEST("2 output: HDMI1, TXP",
+		       VC4_ENCODER_TYPE_HDMI1,
+		       VC4_ENCODER_TYPE_TXP),
+	PV_MUXING_TEST("2 output: TXP, VEC",
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_VEC),
+	PV_MUXING_TEST("3 output: DPI, VEC, TXP",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP),
+	PV_MUXING_TEST("3 output: DPI, VEC, DSI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("3 output: DPI, VEC, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("3 output: DPI, VEC, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("3 output: DPI, TXP, DSI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("3 output: DPI, TXP, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("3 output: DPI, TXP, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("3 output: DPI, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("3 output: DPI, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("3 output: DPI, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("3 output: DSI0, VEC, TXP",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP),
+	PV_MUXING_TEST("3 output: DSI0, VEC, DSI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("3 output: DSI0, VEC, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("3 output: DSI0, VEC, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("3 output: DSI0, TXP, DSI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("3 output: DSI0, TXP, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("3 output: DSI0, TXP, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("3 output: DSI0, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("3 output: DSI0, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("3 output: DSI0, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+};
+
+static void vc4_test_pv_muxing_desc(const struct pv_muxing_param *t, char *desc)
+{
+	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(vc5_test_pv_muxing,
+		  vc5_test_pv_muxing_params,
+		  vc4_test_pv_muxing_desc);
+
+static const struct pv_muxing_param vc5_test_pv_muxing_invalid_params[] = {
+	PV_MUXING_TEST("DPI/DSI0 Conflict",
+		       VC4_ENCODER_TYPE_DPI, VC4_ENCODER_TYPE_DSI0),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, TXP, DSI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, TXP, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, TXP, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, TXP, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DPI, TXP, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, TXP, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, TXP, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, TXP, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, TXP, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, TXP, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, TXP, DSI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, TXP, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, TXP, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, TXP, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DSI0, TXP, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, TXP, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, TXP, DSI1, HDMI0",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, TXP, DSI1, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, TXP, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, TXP, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: VEC, TXP, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DPI, VEC, TXP, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DPI,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+	PV_MUXING_TEST("More than 3 output: DSI0, VEC, TXP, DSI1, HDMI0, HDMI1",
+		       VC4_ENCODER_TYPE_DSI0,
+		       VC4_ENCODER_TYPE_VEC,
+		       VC4_ENCODER_TYPE_TXP,
+		       VC4_ENCODER_TYPE_DSI1,
+		       VC4_ENCODER_TYPE_HDMI0,
+		       VC4_ENCODER_TYPE_HDMI1),
+};
+
+KUNIT_ARRAY_PARAM(vc5_test_pv_muxing_invalid,
+		  vc5_test_pv_muxing_invalid_params,
+		  vc4_test_pv_muxing_desc);
+
+static void drm_vc5_test_pv_muxing(struct kunit *test)
+{
+	const struct pv_muxing_priv *priv = test->priv;
+	const struct pv_muxing_param *params = test->param_value;
+	struct vc4_dev *vc4 = priv->vc4;
+	struct drm_device *drm = &vc4->base;
+	struct drm_atomic_state *state = priv->state;
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < params->nencoders; i++) {
+		enum vc4_encoder_type enc_type = params->encoders[i];
+
+		ret = vc4_mock_atomic_add_output(test, drm, enc_type, state);
+		KUNIT_ASSERT_EQ(test, ret, 0);
+	}
+
+	ret = drm_atomic_check_only(state);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+
+	KUNIT_EXPECT_TRUE(test,
+			  check_fifo_conflict(test, state));
+
+	for (i = 0; i < params->nencoders; i++) {
+		enum vc4_encoder_type enc_type = params->encoders[i];
+
+		KUNIT_EXPECT_TRUE(test, check_channel_for_encoder(test, state, enc_type));
+	}
+}
+
+static void drm_vc4_test_pv_muxing_invalid(struct kunit *test)
+{
+	const struct pv_muxing_priv *priv = test->priv;
+	const struct pv_muxing_param *params = test->param_value;
+	struct vc4_dev *vc4 = priv->vc4;
+	struct drm_device *drm = &vc4->base;
+	struct drm_atomic_state *state = priv->state;
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < params->nencoders; i++) {
+		enum vc4_encoder_type enc_type = params->encoders[i];
+
+		ret = vc4_mock_atomic_add_output(test, drm, enc_type, state);
+		KUNIT_ASSERT_EQ(test, ret, 0);
+	}
+
+	ret = drm_atomic_check_only(state);
+	KUNIT_EXPECT_LT(test, ret, 0);
+}
+
+static int vc5_pv_muxing_test_init(struct kunit *test)
+{
+	struct drm_atomic_state *state;
+	struct pv_muxing_priv *priv;
+	struct drm_device *drm;
+	struct vc4_dev *vc4;
+
+	priv = kunit_kzalloc(test, sizeof(*priv), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, priv);
+	test->priv = priv;
+
+	vc4 = vc5_mock_device(test);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, vc4);
+	priv->vc4 = vc4;
+
+	drm_modeset_acquire_init(&priv->ctx, 0);
+
+	drm = &vc4->base;
+	state = drm_atomic_state_alloc(drm);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, state);
+
+	state->acquire_ctx = &priv->ctx;
+
+	priv->state = state;
+
+	return 0;
+}
+
+static void vc4_pv_muxing_test_exit(struct kunit *test)
+{
+	struct pv_muxing_priv *priv = test->priv;
+	struct vc4_dev *vc4 = priv->vc4;
+	struct drm_device *drm = &vc4->base;
+	struct drm_atomic_state *state = priv->state;
+
+	drm_atomic_state_put(state);
+	drm_modeset_drop_locks(&priv->ctx);
+	drm_modeset_acquire_fini(&priv->ctx);
+	drm_dev_unregister(drm);
+	drm_kunit_helper_free_device(test, vc4->dev);
+}
+
+static struct kunit_case vc5_pv_muxing_tests[] = {
+	KUNIT_CASE_PARAM(drm_vc5_test_pv_muxing,
+			 vc5_test_pv_muxing_gen_params),
+	KUNIT_CASE_PARAM(drm_vc4_test_pv_muxing_invalid,
+			 vc5_test_pv_muxing_invalid_gen_params),
+	{}
+};
+
+static struct kunit_suite vc5_pv_muxing_test_suite = {
+	.name = "vc5-pv-muxing",
+	.init = vc5_pv_muxing_test_init,
+	.exit = vc4_pv_muxing_test_exit,
+	.test_cases = vc5_pv_muxing_tests,
+};
+
+kunit_test_suite(vc5_pv_muxing_test_suite);