mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] drm/nouveau: add initial KUnit test suite
@ 2026-12-06  8:50 Munique Feitoza
  2026-12-06  8:50 ` [PATCH 1/2] drm/nouveau: add KUnit tests for dispnv50 head helpers Munique Feitoza
  2026-12-06  8:50 ` [PATCH 2/2] drm/nouveau: add KUnit tests for gt215_pll_calc() Munique Feitoza
  0 siblings, 2 replies; 3+ messages in thread
From: Munique Feitoza @ 2026-12-06  8:50 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, nouveau, dri-devel, kunit-dev,
	linux-kernel, Munique Feitoza

Add CONFIG_DRM_NOUVEAU_KUNIT_TEST and an initial KUnit test suite for
Nouveau covering dispnv50 head mode/view calculations and nvkm
gt215_pll_calc() (9 tests passing via kunit.py).

Munique Feitoza (2):
  drm/nouveau: add KUnit tests for dispnv50 head helpers
  drm/nouveau: add KUnit tests for gt215_pll_calc()

 drivers/gpu/drm/nouveau/Kbuild                |   1 +
 drivers/gpu/drm/nouveau/Kconfig               |  10 +
 drivers/gpu/drm/nouveau/dispnv50/head.c       |   7 +-
 drivers/gpu/drm/nouveau/dispnv50/head.h       |  10 +
 .../drm/nouveau/nvkm/subdev/clk/pllgt215.c    |   2 +
 drivers/gpu/drm/nouveau/tests/Makefile        |  12 +
 .../gpu/drm/nouveau/tests/nv50_head_test.c    | 260 ++++++++++++++++++
 drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c |  99 +++++++
 8 files changed, 399 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/nouveau/tests/Makefile
 create mode 100644 drivers/gpu/drm/nouveau/tests/nv50_head_test.c
 create mode 100644 drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c

-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] drm/nouveau: add KUnit tests for dispnv50 head helpers
  2026-12-06  8:50 [PATCH 0/2] drm/nouveau: add initial KUnit test suite Munique Feitoza
@ 2026-12-06  8:50 ` Munique Feitoza
  2026-12-06  8:50 ` [PATCH 2/2] drm/nouveau: add KUnit tests for gt215_pll_calc() Munique Feitoza
  1 sibling, 0 replies; 3+ messages in thread
From: Munique Feitoza @ 2026-12-06  8:50 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, nouveau, dri-devel, kunit-dev,
	linux-kernel, Munique Feitoza

Add CONFIG_DRM_NOUVEAU_KUNIT_TEST and initial KUnit test suite for
dispnv50 head mode and view calculations (nv50_head_atomic_check_mode()
and nv50_head_atomic_check_view()).

Signed-off-by: Munique Feitoza <muniquefeitoz4@gmail.com>
---
 drivers/gpu/drm/nouveau/Kbuild                |   1 +
 drivers/gpu/drm/nouveau/Kconfig               |  10 +
 drivers/gpu/drm/nouveau/dispnv50/head.c       |   7 +-
 drivers/gpu/drm/nouveau/dispnv50/head.h       |  10 +
 drivers/gpu/drm/nouveau/tests/Makefile        |  11 +
 .../gpu/drm/nouveau/tests/nv50_head_test.c    | 260 ++++++++++++++++++
 6 files changed, 297 insertions(+), 2 deletions(-)
 create mode 100644 drivers/gpu/drm/nouveau/tests/Makefile
 create mode 100644 drivers/gpu/drm/nouveau/tests/nv50_head_test.c

diff --git a/drivers/gpu/drm/nouveau/Kbuild b/drivers/gpu/drm/nouveau/Kbuild
index 385d24530d1e60..cee8616bdad649 100644
--- a/drivers/gpu/drm/nouveau/Kbuild
+++ b/drivers/gpu/drm/nouveau/Kbuild
@@ -72,3 +72,4 @@ nouveau-y += nvc0_fence.o
 nouveau-y += gv100_fence.o
 
 obj-$(CONFIG_DRM_NOUVEAU) += nouveau.o
+obj-$(CONFIG_DRM_NOUVEAU_KUNIT_TEST) += tests/
diff --git a/drivers/gpu/drm/nouveau/Kconfig b/drivers/gpu/drm/nouveau/Kconfig
index 3b5757aed9c842..7bf606213a633b 100644
--- a/drivers/gpu/drm/nouveau/Kconfig
+++ b/drivers/gpu/drm/nouveau/Kconfig
@@ -120,3 +120,13 @@ config DRM_NOUVEAU_SIL164
 	help
 	  Support for sil164 and similar single-link (or dual-link
 	  when used in pairs) TMDS transmitters.
+
+config DRM_NOUVEAU_KUNIT_TEST
+	tristate "KUnit tests for Nouveau" if !KUNIT_ALL_TESTS
+	depends on DRM_NOUVEAU && KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds KUnit unit tests for the Nouveau DRM driver, covering
+	  dispnv50 head mode and view calculations without requiring physical
+	  NVIDIA GPU hardware. This option is not useful for distributions
+	  or general kernels, only for kernel developers working on Nouveau.
diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.c b/drivers/gpu/drm/nouveau/dispnv50/head.c
index 6a3a93de0cbfe7..a297a59953a9bd 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/head.c
+++ b/drivers/gpu/drm/nouveau/dispnv50/head.c
@@ -33,6 +33,7 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_edid.h>
+#include <kunit/visibility.h>
 #include <drm/drm_vblank.h>
 #include "nouveau_connector.h"
 
@@ -123,7 +124,7 @@ nv50_head_atomic_check_dither(struct nv50_head_atom *armh,
 	asyh->set.dither = true;
 }
 
-static void
+VISIBLE_IF_KUNIT void
 nv50_head_atomic_check_view(struct nv50_head_atom *armh,
 			    struct nv50_head_atom *asyh,
 			    struct nouveau_conn_atom *asyc)
@@ -220,6 +221,7 @@ nv50_head_atomic_check_view(struct nv50_head_atom *armh,
 
 	asyh->set.view = true;
 }
+EXPORT_SYMBOL_IF_KUNIT(nv50_head_atomic_check_view);
 
 static int
 nv50_head_atomic_check_lut(struct nv50_head *head,
@@ -279,7 +281,7 @@ nv50_head_atomic_check_lut(struct nv50_head *head,
 	return 0;
 }
 
-static void
+VISIBLE_IF_KUNIT void
 nv50_head_atomic_check_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
 {
 	struct drm_display_mode *mode = &asyh->state.adjusted_mode;
@@ -328,6 +330,7 @@ nv50_head_atomic_check_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
 	asyh->set.or = head->func->or != NULL;
 	asyh->set.mode = true;
 }
+EXPORT_SYMBOL_IF_KUNIT(nv50_head_atomic_check_mode);
 
 static int
 nv50_head_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state)
diff --git a/drivers/gpu/drm/nouveau/dispnv50/head.h b/drivers/gpu/drm/nouveau/dispnv50/head.h
index 8bd2fcb1eff5eb..dbfc8aa9f87dc4 100644
--- a/drivers/gpu/drm/nouveau/dispnv50/head.h
+++ b/drivers/gpu/drm/nouveau/dispnv50/head.h
@@ -27,6 +27,16 @@ void nv50_head_flush_set_wndw(struct nv50_head *head, struct nv50_head_atom *asy
 void nv50_head_flush_clr(struct nv50_head *head,
 			 struct nv50_head_atom *asyh, bool flush);
 
+#if IS_ENABLED(CONFIG_KUNIT)
+struct nouveau_conn_atom;
+
+void nv50_head_atomic_check_view(struct nv50_head_atom *armh,
+				 struct nv50_head_atom *asyh,
+				 struct nouveau_conn_atom *asyc);
+void nv50_head_atomic_check_mode(struct nv50_head *head,
+				 struct nv50_head_atom *asyh);
+#endif
+
 struct nv50_head_func {
 	int (*view)(struct nv50_head *, struct nv50_head_atom *);
 	int (*mode)(struct nv50_head *, struct nv50_head_atom *);
diff --git a/drivers/gpu/drm/nouveau/tests/Makefile b/drivers/gpu/drm/nouveau/tests/Makefile
new file mode 100644
index 00000000000000..e9e16933295a6a
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/tests/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+ccflags-y += -I $(src)/../include
+ccflags-y += -I $(src)/../include/nvkm
+ccflags-y += -I $(src)/../nvkm
+ccflags-y += -I $(src)/..
+
+nouveau-kunit-tests-y := \
+	nv50_head_test.o
+
+obj-$(CONFIG_DRM_NOUVEAU_KUNIT_TEST) += nouveau-kunit-tests.o
diff --git a/drivers/gpu/drm/nouveau/tests/nv50_head_test.c b/drivers/gpu/drm/nouveau/tests/nv50_head_test.c
new file mode 100644
index 00000000000000..a54a2cebfed3a6
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/tests/nv50_head_test.c
@@ -0,0 +1,260 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <kunit/test.h>
+
+#include <drm/drm_connector.h>
+#include <drm/drm_modes.h>
+
+#include "../dispnv50/head.h"
+#include "../nouveau_connector.h"
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static const struct nv50_head_func test_head_func_with_or = {
+	.or = (void *)0x1,
+};
+
+static struct drm_display_mode make_1080p_mode(void)
+{
+	return (struct drm_display_mode) {
+		.clock = 148500,
+		.hdisplay = 1920,
+		.hsync_start = 2008,
+		.hsync_end = 2052,
+		.htotal = 2200,
+		.vdisplay = 1080,
+		.vsync_start = 1084,
+		.vsync_end = 1089,
+		.vtotal = 1125,
+		.flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
+	};
+}
+
+static void nv50_head_test_mode_progressive(struct kunit *test)
+{
+	struct nv50_head *head;
+	struct nv50_head_atom *asyh;
+
+	head = kunit_kzalloc(test, sizeof(*head), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, head);
+	asyh = kunit_kzalloc(test, sizeof(*asyh), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, asyh);
+
+	head->func = &test_head_func_with_or;
+	asyh->state.adjusted_mode = make_1080p_mode();
+
+	nv50_head_atomic_check_mode(head, asyh);
+
+	KUNIT_EXPECT_EQ(test, asyh->mode.h.active, 2200);
+	KUNIT_EXPECT_EQ(test, asyh->mode.h.synce, 2052 - 2008 - 1);
+	KUNIT_EXPECT_EQ(test, asyh->mode.h.blanke, 2200 - 2008 - 1);
+	KUNIT_EXPECT_EQ(test, asyh->mode.h.blanks, (2200 - 2008 - 1) + 1920);
+
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.active, 1125);
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.synce, 1089 - 1084 - 1);
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.blanke, 1125 - 1084 - 1);
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.blanks, (1125 - 1084 - 1) + 1080);
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2e, 0);
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2s, 1);
+
+	KUNIT_EXPECT_FALSE(test, asyh->mode.interlace);
+	KUNIT_EXPECT_EQ(test, asyh->mode.clock, 148500);
+	KUNIT_EXPECT_FALSE(test, asyh->or.nhsync);
+	KUNIT_EXPECT_FALSE(test, asyh->or.nvsync);
+	KUNIT_EXPECT_TRUE(test, asyh->set.or);
+	KUNIT_EXPECT_TRUE(test, asyh->set.mode);
+}
+
+static void nv50_head_test_mode_interlaced_neg_sync(struct kunit *test)
+{
+	struct nv50_head *head;
+	struct nv50_head_atom *asyh;
+	struct drm_display_mode mode = make_1080p_mode();
+
+	head = kunit_kzalloc(test, sizeof(*head), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, head);
+	asyh = kunit_kzalloc(test, sizeof(*asyh), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, asyh);
+
+	head->func = &test_head_func_with_or;
+	mode.flags = DRM_MODE_FLAG_INTERLACE |
+		     DRM_MODE_FLAG_NHSYNC |
+		     DRM_MODE_FLAG_NVSYNC;
+	asyh->state.adjusted_mode = mode;
+
+	nv50_head_atomic_check_mode(head, asyh);
+
+	KUNIT_EXPECT_TRUE(test, asyh->mode.interlace);
+	/* CRTC_INTERLACE_HALVE_V halves vertical timings before doubling */
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2e,
+			(1125 / 2) + ((1125 / 2) - (1084 / 2) - 1));
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.blank2s,
+			asyh->mode.v.blank2e + (1080 / 2));
+	KUNIT_EXPECT_EQ(test, asyh->mode.v.active, ((1125 / 2) * 2) + 1);
+	KUNIT_EXPECT_TRUE(test, asyh->or.nhsync);
+	KUNIT_EXPECT_TRUE(test, asyh->or.nvsync);
+}
+
+static void alloc_view_fixtures(struct kunit *test,
+				struct drm_connector **conn,
+				struct nv50_head_atom **armh,
+				struct nv50_head_atom **asyh,
+				struct nouveau_conn_atom **asyc)
+{
+	*conn = kunit_kzalloc(test, sizeof(**conn), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, *conn);
+	*armh = kunit_kzalloc(test, sizeof(**armh), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, *armh);
+	*asyh = kunit_kzalloc(test, sizeof(**asyh), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, *asyh);
+	*asyc = kunit_kzalloc(test, sizeof(**asyc), GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, *asyc);
+	(*asyc)->state.connector = *conn;
+}
+
+static void nv50_head_test_view_scale_none(struct kunit *test)
+{
+	struct drm_connector *conn;
+	struct nv50_head_atom *armh, *asyh;
+	struct nouveau_conn_atom *asyc;
+
+	alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+	asyc->scaler.mode = DRM_MODE_SCALE_NONE;
+	asyc->scaler.full = false;
+
+	asyh->state.mode = (struct drm_display_mode) {
+		.hdisplay = 1280,
+		.vdisplay = 720,
+		.vtotal = 750,
+	};
+	asyh->state.adjusted_mode = make_1080p_mode();
+
+	nv50_head_atomic_check_view(armh, asyh, asyc);
+
+	KUNIT_EXPECT_EQ(test, asyh->view.iW, 1280);
+	KUNIT_EXPECT_EQ(test, asyh->view.iH, 720);
+	KUNIT_EXPECT_EQ(test, asyh->view.oW, 1280);
+	KUNIT_EXPECT_EQ(test, asyh->view.oH, 720);
+	KUNIT_EXPECT_TRUE(test, asyh->set.view);
+}
+
+static void nv50_head_test_view_scale_center(struct kunit *test)
+{
+	struct drm_connector *conn;
+	struct nv50_head_atom *armh, *asyh;
+	struct nouveau_conn_atom *asyc;
+
+	alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+	asyc->scaler.mode = DRM_MODE_SCALE_CENTER;
+
+	/* Smaller input than output: centered 1:1 */
+	asyh->state.mode = (struct drm_display_mode) {
+		.hdisplay = 800,
+		.vdisplay = 600,
+		.vtotal = 628,
+	};
+	asyh->state.adjusted_mode = make_1080p_mode();
+
+	nv50_head_atomic_check_view(armh, asyh, asyc);
+
+	KUNIT_EXPECT_EQ(test, asyh->view.iW, 800);
+	KUNIT_EXPECT_EQ(test, asyh->view.iH, 600);
+	KUNIT_EXPECT_EQ(test, asyh->view.oW, 800);
+	KUNIT_EXPECT_EQ(test, asyh->view.oH, 600);
+
+	/* Larger input than output: clamped to output dimensions */
+	asyh->state.mode = (struct drm_display_mode) {
+		.hdisplay = 2560,
+		.vdisplay = 1440,
+		.vtotal = 1481,
+	};
+
+	nv50_head_atomic_check_view(armh, asyh, asyc);
+
+	KUNIT_EXPECT_EQ(test, asyh->view.oW, 1920);
+	KUNIT_EXPECT_EQ(test, asyh->view.oH, 1080);
+}
+
+static void nv50_head_test_view_scale_aspect(struct kunit *test)
+{
+	struct drm_connector *conn;
+	struct nv50_head_atom *armh, *asyh;
+	struct nouveau_conn_atom *asyc;
+
+	alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+	asyc->scaler.mode = DRM_MODE_SCALE_ASPECT;
+
+	/* 4:3 input on 16:9 output -> letterbox left/right (1440x1080) */
+	asyh->state.mode = (struct drm_display_mode) {
+		.hdisplay = 800,
+		.vdisplay = 600,
+		.vtotal = 628,
+	};
+	asyh->state.adjusted_mode = make_1080p_mode();
+
+	nv50_head_atomic_check_view(armh, asyh, asyc);
+
+	KUNIT_EXPECT_EQ(test, asyh->view.oW, 1440);
+	KUNIT_EXPECT_EQ(test, asyh->view.oH, 1080);
+
+	/* 16:9 input on 4:3 output -> letterbox top/bottom (1024x576) */
+	asyh->state.mode = make_1080p_mode();
+	asyh->state.adjusted_mode = (struct drm_display_mode) {
+		.hdisplay = 1024,
+		.vdisplay = 768,
+		.vtotal = 806,
+	};
+
+	nv50_head_atomic_check_view(armh, asyh, asyc);
+
+	KUNIT_EXPECT_EQ(test, asyh->view.oW, 1024);
+	KUNIT_EXPECT_EQ(test, asyh->view.oH, 576);
+}
+
+static void nv50_head_test_view_underscan_and_3d(struct kunit *test)
+{
+	struct drm_connector *conn;
+	struct nv50_head_atom *armh, *asyh;
+	struct nouveau_conn_atom *asyc;
+
+	alloc_view_fixtures(test, &conn, &armh, &asyh, &asyc);
+	asyc->scaler.mode = DRM_MODE_SCALE_FULLSCREEN;
+	asyc->scaler.underscan.mode = UNDERSCAN_ON;
+	asyc->scaler.underscan.hborder = 40;
+	asyc->scaler.underscan.vborder = 20;
+
+	asyh->state.mode = (struct drm_display_mode) {
+		.hdisplay = 1920,
+		.vdisplay = 1080,
+		.vtotal = 1125,
+		.flags = DRM_MODE_FLAG_3D_FRAME_PACKING,
+	};
+	asyh->state.adjusted_mode = make_1080p_mode();
+
+	nv50_head_atomic_check_view(armh, asyh, asyc);
+
+	KUNIT_EXPECT_EQ(test, asyh->view.iW, 1920);
+	KUNIT_EXPECT_EQ(test, asyh->view.iH, 1080 + 1125);
+	KUNIT_EXPECT_EQ(test, asyh->view.oW, 1920 - 80);
+	KUNIT_EXPECT_EQ(test, asyh->view.oH, 1080 - 40);
+}
+
+static struct kunit_case nv50_head_test_cases[] = {
+	KUNIT_CASE(nv50_head_test_mode_progressive),
+	KUNIT_CASE(nv50_head_test_mode_interlaced_neg_sync),
+	KUNIT_CASE(nv50_head_test_view_scale_none),
+	KUNIT_CASE(nv50_head_test_view_scale_center),
+	KUNIT_CASE(nv50_head_test_view_scale_aspect),
+	KUNIT_CASE(nv50_head_test_view_underscan_and_3d),
+	{ }
+};
+
+static struct kunit_suite nv50_head_test_suite = {
+	.name = "nouveau-nv50-head",
+	.test_cases = nv50_head_test_cases,
+};
+
+kunit_test_suite(nv50_head_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for Nouveau dispnv50 head helpers");
+MODULE_LICENSE("GPL");
-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] drm/nouveau: add KUnit tests for gt215_pll_calc()
  2026-12-06  8:50 [PATCH 0/2] drm/nouveau: add initial KUnit test suite Munique Feitoza
  2026-12-06  8:50 ` [PATCH 1/2] drm/nouveau: add KUnit tests for dispnv50 head helpers Munique Feitoza
@ 2026-12-06  8:50 ` Munique Feitoza
  1 sibling, 0 replies; 3+ messages in thread
From: Munique Feitoza @ 2026-12-06  8:50 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich
  Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	David Airlie, Simona Vetter, nouveau, dri-devel, kunit-dev,
	linux-kernel, Munique Feitoza

Export gt215_pll_calc() for KUnit testing and add unit tests covering
integer mode, fractional mode, and post-divider P clamping.

Signed-off-by: Munique Feitoza <muniquefeitoz4@gmail.com>
---
 .../drm/nouveau/nvkm/subdev/clk/pllgt215.c    |  2 +
 drivers/gpu/drm/nouveau/tests/Makefile        |  3 +-
 drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c | 99 +++++++++++++++++++
 3 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c

diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c
index c6fccd600db4d0..b236d50d627ffc 100644
--- a/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c
+++ b/drivers/gpu/drm/nouveau/nvkm/subdev/clk/pllgt215.c
@@ -23,6 +23,7 @@
  */
 #include "pll.h"
 
+#include <kunit/visibility.h>
 #include <subdev/bios.h>
 #include <subdev/bios/pll.h>
 
@@ -85,3 +86,4 @@ gt215_pll_calc(struct nvkm_subdev *subdev, struct nvbios_pll *info,
 
 	return info->refclk * *pN / *pM / *P;
 }
+EXPORT_SYMBOL_IF_KUNIT(gt215_pll_calc);
diff --git a/drivers/gpu/drm/nouveau/tests/Makefile b/drivers/gpu/drm/nouveau/tests/Makefile
index e9e16933295a6a..d050e70fde61ad 100644
--- a/drivers/gpu/drm/nouveau/tests/Makefile
+++ b/drivers/gpu/drm/nouveau/tests/Makefile
@@ -6,6 +6,7 @@ ccflags-y += -I $(src)/../nvkm
 ccflags-y += -I $(src)/..
 
 nouveau-kunit-tests-y := \
-	nv50_head_test.o
+	nv50_head_test.o \
+	nvkm_pll_test.o
 
 obj-$(CONFIG_DRM_NOUVEAU_KUNIT_TEST) += nouveau-kunit-tests.o
diff --git a/drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c b/drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c
new file mode 100644
index 00000000000000..72ea1831deef6f
--- /dev/null
+++ b/drivers/gpu/drm/nouveau/tests/nvkm_pll_test.c
@@ -0,0 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#include <kunit/test.h>
+
+#include <subdev/bios.h>
+#include <subdev/bios/pll.h>
+#include <subdev/clk/pll.h>
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static struct nvbios_pll make_gf108_vpll(void)
+{
+	return (struct nvbios_pll) {
+		.refclk = 27000,
+		.min_p = 1,
+		.max_p = 16,
+		.vco1 = {
+			.min_freq = 400000,
+			.max_freq = 1000000,
+			.min_inputfreq = 1000,
+			.max_inputfreq = 27000,
+			.min_m = 1,
+			.max_m = 14,
+			.min_n = 8,
+			.max_n = 255,
+		},
+	};
+}
+
+static void nvkm_pll_test_gt215_integer(struct kunit *test)
+{
+	struct nvbios_pll info = make_gf108_vpll();
+	int N = 0, M = 0, P = 0;
+	int ret;
+
+	ret = gt215_pll_calc(NULL, &info, 148500, &N, NULL, &M, &P);
+
+	KUNIT_EXPECT_GT(test, ret, 0);
+	KUNIT_EXPECT_GE(test, P, (int)info.min_p);
+	KUNIT_EXPECT_LE(test, P, (int)info.max_p);
+	KUNIT_EXPECT_GE(test, M, (int)info.vco1.min_m);
+	KUNIT_EXPECT_LE(test, M, (int)info.vco1.max_m);
+	KUNIT_EXPECT_GE(test, N, (int)info.vco1.min_n);
+	KUNIT_EXPECT_LE(test, N, (int)info.vco1.max_n);
+	KUNIT_EXPECT_EQ(test, ret, (int)(info.refclk * N / M / P));
+	/* 148500 kHz from 27000 kHz refclk: exact match with N=66, M=2, P=6 */
+	KUNIT_EXPECT_EQ(test, ret, 148500);
+}
+
+static void nvkm_pll_test_gt215_fractional(struct kunit *test)
+{
+	struct nvbios_pll info = make_gf108_vpll();
+	int N = 0, fN = 0, M = 0, P = 0;
+	int ret;
+
+	ret = gt215_pll_calc(NULL, &info, 106500, &N, &fN, &M, &P);
+
+	KUNIT_EXPECT_EQ(test, ret, 106500);
+	KUNIT_EXPECT_GE(test, P, (int)info.min_p);
+	KUNIT_EXPECT_LE(test, P, (int)info.max_p);
+	KUNIT_EXPECT_GE(test, M, (int)info.vco1.min_m);
+	KUNIT_EXPECT_LE(test, M, (int)info.vco1.max_m);
+	KUNIT_EXPECT_GE(test, N, (int)info.vco1.min_n);
+	KUNIT_EXPECT_LE(test, N, (int)info.vco1.max_n);
+}
+
+static void nvkm_pll_test_gt215_p_clamping(struct kunit *test)
+{
+	struct nvbios_pll info = make_gf108_vpll();
+	int N = 0, M = 0, P = 0;
+	int ret;
+
+	/* High frequency forces P down to min_p (1) */
+	ret = gt215_pll_calc(NULL, &info, 1200000, &N, NULL, &M, &P);
+	KUNIT_EXPECT_GT(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, P, (int)info.min_p);
+
+	/* Low frequency forces P up to max_p (16) */
+	ret = gt215_pll_calc(NULL, &info, 25175, &N, NULL, &M, &P);
+	KUNIT_EXPECT_GT(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, P, (int)info.max_p);
+}
+
+static struct kunit_case nvkm_pll_test_cases[] = {
+	KUNIT_CASE(nvkm_pll_test_gt215_integer),
+	KUNIT_CASE(nvkm_pll_test_gt215_fractional),
+	KUNIT_CASE(nvkm_pll_test_gt215_p_clamping),
+	{ }
+};
+
+static struct kunit_suite nvkm_pll_test_suite = {
+	.name = "nouveau-nvkm-pll",
+	.test_cases = nvkm_pll_test_cases,
+};
+
+kunit_test_suite(nvkm_pll_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for Nouveau nvkm PLL helpers");
+MODULE_LICENSE("GPL");
-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-06  8:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-06  8:50 [PATCH 0/2] drm/nouveau: add initial KUnit test suite Munique Feitoza
2026-12-06  8:50 ` [PATCH 1/2] drm/nouveau: add KUnit tests for dispnv50 head helpers Munique Feitoza
2026-12-06  8:50 ` [PATCH 2/2] drm/nouveau: add KUnit tests for gt215_pll_calc() Munique Feitoza

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®