All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Piórkowski, Piotr" <piotr.piorkowski@intel.com>
To: <intel-xe@lists.freedesktop.org>
Cc: "Piotr Piórkowski" <piotr.piorkowski@intel.com>
Subject: [PATCH v2 4/4] drm/xe/kunit: Add tests for PF-mem regions
Date: Fri, 21 Aug 2026 11:46:01 +0200	[thread overview]
Message-ID: <20260821094601.607060-5-piotr.piorkowski@intel.com> (raw)
In-Reply-To: <20260821094601.607060-1-piotr.piorkowski@intel.com>

From: Piotr Piórkowski <piotr.piorkowski@intel.com>

Add coverage for PF-mem VRAM region metadata, bounds checking, and
full, partial, and missing CPU visibility.

Assisted-by: Claude:claude-5-sonnet
Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
---
 drivers/gpu/drm/xe/tests/xe_vram.c | 115 +++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vram.c       |   4 +
 2 files changed, 119 insertions(+)
 create mode 100644 drivers/gpu/drm/xe/tests/xe_vram.c

diff --git a/drivers/gpu/drm/xe/tests/xe_vram.c b/drivers/gpu/drm/xe/tests/xe_vram.c
new file mode 100644
index 000000000000..36a49fbef220
--- /dev/null
+++ b/drivers/gpu/drm/xe/tests/xe_vram.c
@@ -0,0 +1,115 @@
+// SPDX-License-Identifier: GPL-2.0 AND MIT
+/*
+ * Copyright © 2026 Intel Corporation
+ */
+
+#include <kunit/test.h>
+
+#include "xe_kunit_helpers.h"
+#include "xe_pci_test.h"
+
+static int xe_vram_test_init(struct kunit *test)
+{
+	struct xe_pci_fake_data fake = {
+		.platform = XE_BATTLEMAGE,
+		.graphics_verx100 = 2001,
+	};
+
+	test->priv = &fake;
+	xe_kunit_helper_xe_device_test_init(test);
+
+	return 0;
+}
+
+static struct xe_vram_region pfmem_parent(struct xe_device *xe, u64 io_size)
+{
+	struct xe_vram_region parent = {
+		.xe = xe,
+		.id = 0,
+		.io_start = SZ_1G,
+		.io_size = io_size,
+		.dpa_base = SZ_2G,
+		.mapping = (__force void __iomem *)SZ_4G,
+		.usable_size = SZ_64M,
+	};
+
+	return parent;
+}
+
+static void pfmem_create(struct kunit *test)
+{
+	struct xe_device *xe = test->priv;
+	struct xe_vram_region parent = pfmem_parent(xe, SZ_64M);
+	struct xe_vram_region *vram;
+
+	vram = xe_vram_region_alloc_pfmem(xe, 0);
+	KUNIT_ASSERT_NOT_NULL(test, vram);
+	KUNIT_ASSERT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, SZ_4M, SZ_16M), 0);
+	KUNIT_EXPECT_EQ(test, vram->binding, XE_VRAM_BINDING_PFMEM);
+	KUNIT_EXPECT_EQ(test, vram->placement, (u32)XE_PL_VRAM0_PFMEM);
+	KUNIT_EXPECT_EQ(test, vram->id, (u8)0);
+	KUNIT_EXPECT_EQ(test, vram->actual_physical_size, (resource_size_t)SZ_16M);
+	KUNIT_EXPECT_EQ(test, vram->usable_size, (resource_size_t)SZ_16M);
+	KUNIT_EXPECT_EQ(test, vram->io_start, (resource_size_t)(SZ_1G + SZ_4M));
+	KUNIT_EXPECT_EQ(test, vram->io_size, (resource_size_t)SZ_16M);
+	KUNIT_EXPECT_EQ(test, vram->dpa_base, (resource_size_t)(SZ_2G + SZ_4M));
+	KUNIT_EXPECT_PTR_EQ(test, vram->mapping, parent.mapping + SZ_4M);
+}
+
+static void pfmem_small_bar(struct kunit *test)
+{
+	struct xe_device *xe = test->priv;
+	struct xe_vram_region parent = pfmem_parent(xe, SZ_8M);
+	struct xe_vram_region *vram;
+
+	vram = xe_vram_region_alloc_pfmem(xe, 0);
+	KUNIT_ASSERT_NOT_NULL(test, vram);
+	KUNIT_ASSERT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, SZ_4M, SZ_16M), 0);
+	KUNIT_EXPECT_EQ(test, vram->io_size, (resource_size_t)SZ_4M);
+
+	vram = xe_vram_region_alloc_pfmem(xe, 0);
+	KUNIT_ASSERT_NOT_NULL(test, vram);
+	KUNIT_EXPECT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, SZ_8M, SZ_16M), -EINVAL);
+}
+
+static void pfmem_invalid_range(struct kunit *test)
+{
+	struct xe_device *xe = test->priv;
+	struct xe_vram_region parent = pfmem_parent(xe, SZ_64M);
+	struct xe_vram_region *vram;
+
+	vram = xe_vram_region_alloc_pfmem(xe, 0);
+	KUNIT_ASSERT_NOT_NULL(test, vram);
+	KUNIT_EXPECT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, 0, 0), -EINVAL);
+	KUNIT_EXPECT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, SZ_64M + 1, SZ_4M), -EINVAL);
+	KUNIT_EXPECT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, SZ_64M - SZ_4M, SZ_8M),
+			-EINVAL);
+	KUNIT_EXPECT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, SZ_64M, SZ_4M), -EINVAL);
+}
+
+static void pfmem_no_io(struct kunit *test)
+{
+	struct xe_device *xe = test->priv;
+	struct xe_vram_region parent = pfmem_parent(xe, 0);
+	struct xe_vram_region *vram;
+
+	vram = xe_vram_region_alloc_pfmem(xe, 0);
+	KUNIT_ASSERT_NOT_NULL(test, vram);
+	KUNIT_EXPECT_EQ(test, xe_vram_region_init_pfmem(vram, &parent, 0, SZ_4M), -EINVAL);
+}
+
+static struct kunit_case xe_vram_tests[] = {
+	KUNIT_CASE(pfmem_create),
+	KUNIT_CASE(pfmem_small_bar),
+	KUNIT_CASE(pfmem_invalid_range),
+	KUNIT_CASE(pfmem_no_io),
+	{}
+};
+
+static struct kunit_suite xe_vram_test_suite = {
+	.name = "xe_vram",
+	.test_cases = xe_vram_tests,
+	.init = xe_vram_test_init,
+};
+
+kunit_test_suite(xe_vram_test_suite);
diff --git a/drivers/gpu/drm/xe/xe_vram.c b/drivers/gpu/drm/xe/xe_vram.c
index 408733c01d4b..dbe6b33fbaf0 100644
--- a/drivers/gpu/drm/xe/xe_vram.c
+++ b/drivers/gpu/drm/xe/xe_vram.c
@@ -459,3 +459,7 @@ resource_size_t xe_vram_region_actual_physical_size(const struct xe_vram_region
 	return vram ? vram->actual_physical_size : 0;
 }
 EXPORT_SYMBOL_IF_KUNIT(xe_vram_region_actual_physical_size);
+
+#if IS_BUILTIN(CONFIG_DRM_XE_KUNIT_TEST)
+#include "tests/xe_vram.c"
+#endif
-- 
2.34.1


  parent reply	other threads:[~2026-08-21  9:46 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-21  9:45 [PATCH v2 0/4] Introduce PF-mem VRAM regions Piórkowski, Piotr
2026-08-21  9:45 ` [PATCH v2 1/4] drm/xe/vram: Add binding information to " Piórkowski, Piotr
2026-08-21  9:54   ` sashiko-bot
2026-08-21  9:45 ` [PATCH v2 2/4] drm/xe/ttm: Add PF-mem VRAM placement types for TTM Piórkowski, Piotr
2026-08-21  9:46 ` [PATCH v2 3/4] drm/xe/vram: Add initial support for PF-mem regions Piórkowski, Piotr
2026-08-21  9:46 ` Piórkowski, Piotr [this message]
2026-08-21  9:54   ` [PATCH v2 4/4] drm/xe/kunit: Add tests " sashiko-bot
2026-08-21  9:52 ` ✗ CI.checkpatch: warning for Introduce PF-mem VRAM regions (rev2) Patchwork
2026-08-21  9:53 ` ✓ CI.KUnit: success " Patchwork
2026-08-21 10:16 ` [PATCH v2 0/4] Introduce PF-mem VRAM regions Matthew Auld
2026-08-21 10:33 ` ✓ Xe.CI.BAT: success for Introduce PF-mem VRAM regions (rev2) Patchwork
2026-08-21 11:43 ` ✓ Xe.CI.FULL: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260821094601.607060-5-piotr.piorkowski@intel.com \
    --to=piotr.piorkowski@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.