From: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
To: igt-dev@lists.freedesktop.org
Cc: siqueira@igalia.com,
"Thadeu Lima de Souza Cascardo" <cascardo@igalia.com>,
dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org,
intel-xe@lists.freedesktop.org,
"Christian Koenig" <christian.koenig@amd.com>,
maarten.lankhorst@linux.intel.com,
"Thomas Hellström" <thomas.hellstrom@linux.intel.com>,
"Kamil Konieczny" <kamil.konieczny@linux.intel.com>,
"Janusz Krzysztofik" <janusz.krzysztofik@linux.intel.com>,
"Vitaly Prosyak" <vitaly.prosyak@amd.com>,
"Natalie Vock" <natalie.vock@gmx.de>,
"Tvrtko Ursulin" <tvrtko.ursulin@igalia.com>,
kernel-dev@igalia.com
Subject: [PATCH i-g-t v6 4/9] lib/xe: Introduce dmem driver and implement Xe support
Date: Thu, 03 Sep 2026 19:00:26 -0300 [thread overview]
Message-ID: <20260903-dmem_max-v6-4-61dc62970fae@igalia.com> (raw)
In-Reply-To: <20260903-dmem_max-v6-0-61dc62970fae@igalia.com>
In order to be reuse the same dmem tests with multiple drivers, we need to
abstract a few operations. That includes getting the region name, and
allocating and releasing VRAM. As there is some initialization also when
multiple allocations are done, also provide init and deinit functions.
The Xe implementation was based on the original operations from
xe_cgroups.c written by Thomas Hellström. However, instead of doing a
deferred backing, followed by a bind, it does a simple non-deferred GEM
object creation on the VRAM region.
Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
---
lib/igt_dmem_driver.h | 34 ++++++++++++++++++
lib/meson.build | 1 +
lib/xe/xe_dmem.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 132 insertions(+)
diff --git a/lib/igt_dmem_driver.h b/lib/igt_dmem_driver.h
new file mode 100644
index 000000000000..e6998387eff9
--- /dev/null
+++ b/lib/igt_dmem_driver.h
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2026 Valve Corporation
+ * Authors:
+ * Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
+ */
+
+#ifndef __IGT_DMEM_DRIVER_H__
+#define __IGT_DMEM_DRIVER_H__
+
+#include <stdlib.h>
+
+/**
+ * struct igt_dmem_driver - vendor driver to allocate and free device memory
+ *
+ */
+struct igt_dmem_driver {
+ /** @name: Driver name */
+ const char *name;
+ /** @init: Initialize an opaque context given a DRM device fd */
+ int (*init)(void **ctx, int fd);
+ /** @deinit: Release resources associated with context */
+ void (*deinit)(void *ctx);
+ /** @get_region_name: Return expected region name at dmem cgroup files */
+ char * (*get_region_name)(void *ctx);
+ /** @allocate_vram: Allocate @len sized vram and return an opaque @handle */
+ int (*allocate_vram)(void *ctx, size_t len, void **handle);
+ /** @free_vram: Free vram associated with @handle */
+ void (*free_vram)(void *ctx, void *handle);
+};
+
+extern const struct igt_dmem_driver xe_dmem_driver;
+
+#endif
diff --git a/lib/meson.build b/lib/meson.build
index b7e1be61d844..022408ce6864 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -130,6 +130,7 @@ lib_sources = [
'igt_dsc.c',
'igt_hook.c',
'xe/xe_device.c',
+ 'xe/xe_dmem.c',
'xe/xe_ggtt.c',
'xe/xe_gt.c',
'xe/xe_ioctl.c',
diff --git a/lib/xe/xe_dmem.c b/lib/xe/xe_dmem.c
new file mode 100644
index 000000000000..628c905997d4
--- /dev/null
+++ b/lib/xe/xe_dmem.c
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2026 Valve Corporation
+ * Authors:
+ * Thadeu Lima de Souza Cascardo <cascardo@igalia.com>
+ */
+
+#include <errno.h>
+
+#include "igt.h"
+#include "igt_cgroup.h"
+#include "igt_dmem_driver.h"
+#include "xe_drm.h"
+#include "xe/xe_ioctl.h"
+#include "xe/xe_query.h"
+
+struct xe_dmem_ctx {
+ int fd;
+ uint64_t vram_region;
+};
+
+static int xe_dmem_init(void **ctx, int fd)
+{
+ struct xe_dmem_ctx *xe_ctx;
+ uint64_t region;
+
+ xe_ctx = malloc(sizeof(*xe_ctx));
+ if (!xe_ctx)
+ return -ENOMEM;
+
+ xe_ctx->vram_region = 0;
+ /* Find first VRAM region */
+ xe_for_each_mem_region(fd, all_memory_regions(fd), region) {
+ if (xe_region_class(fd, region) == DRM_XE_MEM_REGION_CLASS_VRAM) {
+ xe_ctx->vram_region = region;
+ break;
+ }
+ }
+ if (!xe_ctx->vram_region)
+ goto out;
+
+ xe_ctx->fd = fd;
+
+ *ctx = xe_ctx;
+
+ return 0;
+
+out:
+ free(xe_ctx);
+
+ return -ENOMEM;
+}
+
+static void xe_dmem_deinit(void *ctx)
+{
+ struct xe_dmem_ctx *xe_ctx = ctx;
+
+ free(xe_ctx);
+}
+
+static char * xe_dmem_get_region_name(void *ctx)
+{
+ struct xe_dmem_ctx *xe_ctx = ctx;
+
+ return xe_cgroup_region_name(xe_ctx->fd, xe_ctx->vram_region);
+}
+
+static int xe_dmem_allocate_vram(void *ctx, size_t len, void **ret_handle)
+{
+ struct xe_dmem_ctx *xe_ctx = ctx;
+ uint32_t handle;
+ int err;
+
+ err = __xe_bo_create(xe_ctx->fd, 0, len, xe_ctx->vram_region, 0,
+ NULL, &handle);
+ if (err)
+ return err;
+
+ *ret_handle = (void *)(uintptr_t) handle;
+ return 0;
+}
+
+static void xe_dmem_free_vram(void *ctx, void *handle)
+{
+ struct xe_dmem_ctx *xe_ctx = ctx;
+
+ gem_close(xe_ctx->fd, (uint32_t)(uintptr_t) handle);
+}
+
+const struct igt_dmem_driver xe_dmem_driver = {
+ .name = "xe",
+ .get_region_name = xe_dmem_get_region_name,
+ .init = xe_dmem_init,
+ .deinit = xe_dmem_deinit,
+ .allocate_vram = xe_dmem_allocate_vram,
+ .free_vram = xe_dmem_free_vram,
+};
--
2.47.3
next prev parent reply other threads:[~2026-09-04 7:30 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 22:00 [PATCH i-g-t v6 0/9] add cgroup_dmem test Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` [PATCH i-g-t v6 1/9] lib/igt_cgroup: add cgroup v2 and dmem controller helpers Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` [PATCH i-g-t v6 2/9] tests/cgroup_dmem: add dmem cgroup controller test Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` [PATCH i-g-t v6 3/9] lib/xe: add xe_cgroup_region_name() helper Thadeu Lima de Souza Cascardo
2026-09-03 22:00 ` Thadeu Lima de Souza Cascardo [this message]
2026-09-04 10:02 ` [PATCH i-g-t v6 4/9] lib/xe: Introduce dmem driver and implement Xe support Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 5/9] lib/amdgpu: add amdgpu_cgroup_region_name Thadeu Lima de Souza Cascardo
2026-09-04 10:00 ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 6/9] lib/amdgpu: add amdgpu support to igt_dmem_driver Thadeu Lima de Souza Cascardo
2026-09-04 10:11 ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 7/9] tests/cgroup_dmem: add test for dmem.current Thadeu Lima de Souza Cascardo
2026-09-04 12:40 ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 8/9] tests/cgroup_dmem: add dmem cgroup eviction test Thadeu Lima de Souza Cascardo
2026-09-04 14:48 ` Tvrtko Ursulin
2026-09-03 22:00 ` [PATCH i-g-t v6 9/9] tests/cgroup_dmem: add write_eviction_nonblock subtest Thadeu Lima de Souza Cascardo
2026-09-04 14:51 ` Tvrtko Ursulin
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=20260903-dmem_max-v6-4-61dc62970fae@igalia.com \
--to=cascardo@igalia.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-xe@lists.freedesktop.org \
--cc=janusz.krzysztofik@linux.intel.com \
--cc=kamil.konieczny@linux.intel.com \
--cc=kernel-dev@igalia.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=natalie.vock@gmx.de \
--cc=siqueira@igalia.com \
--cc=thomas.hellstrom@linux.intel.com \
--cc=tvrtko.ursulin@igalia.com \
--cc=vitaly.prosyak@amd.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox