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 3/4] drm/xe/vram: Add initial support for PF-mem regions
Date: Fri, 21 Aug 2026 11:46:00 +0200	[thread overview]
Message-ID: <20260821094601.607060-4-piotr.piorkowski@intel.com> (raw)
In-Reply-To: <20260821094601.607060-1-piotr.piorkowski@intel.com>

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

Add helpers to allocate and initialize such a region from a
caller-provided parent, offset, and size, and assign the matching TTM
placement. The helpers do not decide when the region is needed or how
large it should be. A separate TTM VRAM manager is initialized when a
caller installs the region as the tile kernel_vram.

v2:
 - Enforce page alignment on offset/size and guard against a NULL
   parent BAR mapping (Sashiko).

Assisted-by: Claude:claude-5-sonnet
Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
---
 drivers/gpu/drm/xe/xe_tile.c       |  8 ++++++
 drivers/gpu/drm/xe/xe_vram.c       | 46 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_vram.h       |  4 +++
 drivers/gpu/drm/xe/xe_vram_types.h |  2 ++
 4 files changed, 60 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_tile.c b/drivers/gpu/drm/xe/xe_tile.c
index fd0c2e4cbdd2..e196f424fda4 100644
--- a/drivers/gpu/drm/xe/xe_tile.c
+++ b/drivers/gpu/drm/xe/xe_tile.c
@@ -198,6 +198,14 @@ int xe_tile_init_noalloc(struct xe_tile *tile)
 		xe->info.mem_region_mask |= BIT(tile->mem.vram->id) << 1;
 	}
 
+	if (IS_DGFX(xe) && tile->mem.kernel_vram &&
+	    tile->mem.kernel_vram != tile->mem.vram &&
+	    !ttm_resource_manager_used(&tile->mem.kernel_vram->ttm.manager)) {
+		err = xe_ttm_vram_mgr_init(xe, tile->mem.kernel_vram);
+		if (err)
+			return err;
+	}
+
 	return xe_tile_sysfs_init(tile);
 }
 
diff --git a/drivers/gpu/drm/xe/xe_vram.c b/drivers/gpu/drm/xe/xe_vram.c
index e5f83df98826..408733c01d4b 100644
--- a/drivers/gpu/drm/xe/xe_vram.c
+++ b/drivers/gpu/drm/xe/xe_vram.c
@@ -29,6 +29,8 @@ static const char *stringify_vram_binding(enum xe_vram_binding binding)
 	switch (binding) {
 	case XE_VRAM_BINDING_TILE:
 		return "Tile";
+	case XE_VRAM_BINDING_PFMEM:
+		return "PF-mem";
 	}
 
 	return "Unknown";
@@ -258,6 +260,11 @@ static int vram_region_init(struct xe_device *xe, struct xe_vram_region *vram,
 	if (vram->mapping)
 		return 0;
 
+	if (!lmem_bar->mapping) {
+		drm_err(&xe->drm, "Failed to map LMEM BAR\n");
+		return -ENOMEM;
+	}
+
 	vram->actual_physical_size = region_size;
 	vram->io_start = lmem_bar->io_start + offset;
 	vram->io_size = min_t(u64, usable_size, remain_io_size);
@@ -276,6 +283,45 @@ static int vram_region_init(struct xe_device *xe, struct xe_vram_region *vram,
 	return 0;
 }
 
+/**
+ * xe_vram_region_alloc_pfmem - Allocate a PF-mem VRAM region
+ * @xe: the &xe_device
+ * @id: tile id the region belongs to
+ *
+ * Return: the allocated VRAM region, or NULL on failure.
+ */
+struct xe_vram_region *xe_vram_region_alloc_pfmem(struct xe_device *xe, u8 id)
+{
+	return vram_region_alloc(xe, XE_VRAM_BINDING_PFMEM, id, XE_PL_VRAM0_PFMEM + id);
+}
+
+/**
+ * xe_vram_region_init_pfmem - Initialize a PF-mem VRAM region
+ * @vram: pre-allocated VRAM region to initialize
+ * @parent: tile VRAM region that provides the address space context
+ * @offset: region offset relative to the parent
+ * @size: region size
+ *
+ * Return: 0 on success, negative error code on failure.
+ */
+int xe_vram_region_init_pfmem(struct xe_vram_region *vram,
+			      struct xe_vram_region *parent,
+			      u64 offset, u64 size)
+{
+	struct xe_device *xe = parent->xe;
+	resource_size_t remain_io_size;
+
+	if (!size || !PAGE_ALIGNED(offset) || !PAGE_ALIGNED(size) ||
+	    offset > parent->usable_size || size > parent->usable_size - offset)
+		return -EINVAL;
+
+	remain_io_size = offset < parent->io_size ? parent->io_size - offset : 0;
+	if (!remain_io_size)
+		return -EINVAL;
+
+	return vram_region_init(xe, vram, parent, offset, size, size, remain_io_size);
+}
+
 /**
  * xe_map_resource_to_region - Map ttm resource to vram memory region
  * @res: The ttm resource
diff --git a/drivers/gpu/drm/xe/xe_vram.h b/drivers/gpu/drm/xe/xe_vram.h
index 87088ffbfd5e..021f044e496b 100644
--- a/drivers/gpu/drm/xe/xe_vram.h
+++ b/drivers/gpu/drm/xe/xe_vram.h
@@ -17,6 +17,10 @@ struct xe_vram_region *xe_map_resource_to_region(struct ttm_resource *res);
 int xe_vram_probe(struct xe_device *xe);
 
 struct xe_vram_region *xe_vram_region_alloc_tile(struct xe_device *xe, u8 id);
+struct xe_vram_region *xe_vram_region_alloc_pfmem(struct xe_device *xe, u8 id);
+int xe_vram_region_init_pfmem(struct xe_vram_region *vram,
+			      struct xe_vram_region *parent,
+			      u64 offset, u64 size);
 resource_size_t xe_vram_region_io_start(const struct xe_vram_region *vram);
 resource_size_t xe_vram_region_io_size(const struct xe_vram_region *vram);
 resource_size_t xe_vram_region_dpa_base(const struct xe_vram_region *vram);
diff --git a/drivers/gpu/drm/xe/xe_vram_types.h b/drivers/gpu/drm/xe/xe_vram_types.h
index 51884e7a679d..01690bfbcce0 100644
--- a/drivers/gpu/drm/xe/xe_vram_types.h
+++ b/drivers/gpu/drm/xe/xe_vram_types.h
@@ -18,9 +18,11 @@ struct xe_migrate;
 /**
  * enum xe_vram_binding - VRAM binding types
  * @XE_VRAM_BINDING_TILE: general-purpose VRAM region bound to a tile
+ * @XE_VRAM_BINDING_PFMEM: VRAM region reserved solely for PF kernel allocations
  */
 enum xe_vram_binding {
 	XE_VRAM_BINDING_TILE = 0,
+	XE_VRAM_BINDING_PFMEM,
 };
 
 /**
-- 
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 ` Piórkowski, Piotr [this message]
2026-08-21  9:46 ` [PATCH v2 4/4] drm/xe/kunit: Add tests for PF-mem regions Piórkowski, Piotr
2026-08-21  9:54   ` 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-4-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.