* [PATCH v4 1/6] drm/xe: Only have a single drmm release action.
2025-10-09 13:52 [PATCH v4 0/6] drm/xe: Make struct xe_ggtt private Maarten Lankhorst
@ 2025-10-09 13:52 ` Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 2/6] drm/mm: Introduce address space shifting Maarten Lankhorst
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Maarten Lankhorst @ 2025-10-09 13:52 UTC (permalink / raw)
To: intel-xe; +Cc: Maarten Lankhorst, Michal Wajdeczko, Rodrigo Vivi
The broken action happened after ggtt_early_fini, so
it's safe to put the drain_workqueue in there instead of
creating a new place.
Fixes: 89d2835c3680 ("drm/xe: Process deferred GGTT node removals on device unwind")
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
drivers/gpu/drm/xe/xe_ggtt.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index 7fdd0a97a6281..c2f23926b5a7b 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -179,6 +179,7 @@ static void ggtt_fini_early(struct drm_device *drm, void *arg)
{
struct xe_ggtt *ggtt = arg;
+ drain_workqueue(ggtt->wq);
destroy_workqueue(ggtt->wq);
mutex_destroy(&ggtt->lock);
drm_mm_takedown(&ggtt->mm);
@@ -239,13 +240,6 @@ int xe_ggtt_init_kunit(struct xe_ggtt *ggtt, u32 reserved, u32 size)
}
EXPORT_SYMBOL_IF_KUNIT(xe_ggtt_init_kunit);
-static void dev_fini_ggtt(void *arg)
-{
- struct xe_ggtt *ggtt = arg;
-
- drain_workqueue(ggtt->wq);
-}
-
/**
* xe_ggtt_init_early - Early GGTT initialization
* @ggtt: the &xe_ggtt to be initialized
@@ -298,10 +292,6 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
if (err)
return err;
- err = devm_add_action_or_reset(xe->drm.dev, dev_fini_ggtt, ggtt);
- if (err)
- return err;
-
if (IS_SRIOV_VF(xe)) {
err = xe_tile_sriov_vf_prepare_ggtt(ggtt->tile);
if (err)
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 2/6] drm/mm: Introduce address space shifting
2025-10-09 13:52 [PATCH v4 0/6] drm/xe: Make struct xe_ggtt private Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 1/6] drm/xe: Only have a single drmm release action Maarten Lankhorst
@ 2025-10-09 13:52 ` Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 3/6] drm/xe: Start using ggtt->start in preparation of balloon removal Maarten Lankhorst
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Maarten Lankhorst @ 2025-10-09 13:52 UTC (permalink / raw)
To: intel-xe; +Cc: Tomasz Lis, Matthew Brost, Maarten Lankhorst
From: Tomasz Lis <tomasz.lis@intel.com>
Due to resource reprovisioning, sometimes a need arises to move
a living address space to a new area, preserving all the nodes
and holes stored within.
It is possible to do that by removing all nodes to a temporary list,
reiniting the drm_mm instance and re-adding everything while applying
a shift to each node. But that is a lot of extra work for a task
which could be done internally without any node shuffle operations.
This change introduces an interface which allows to shift the range
without pruning the whole drm_mm instance.
Having a drm_mm interface for such shift significantly simplifies
the code required to adjust a KMD for a change in base address
of a space managed by drm_mm instance.
Signed-off-by: Tomasz Lis <tomasz.lis@intel.com>
Link: https://lore.kernel.org/r/20250204224136.3183710-2-tomasz.lis@intel.com
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
drivers/gpu/drm/drm_mm.c | 24 ++++++++++++++++++++++++
include/drm/drm_mm.h | 1 +
2 files changed, 25 insertions(+)
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index ca254611b3823..ce3bd8b5e41f0 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -917,6 +917,30 @@ struct drm_mm_node *drm_mm_scan_color_evict(struct drm_mm_scan *scan)
}
EXPORT_SYMBOL(drm_mm_scan_color_evict);
+/**
+ * drm_mm_shift - move the range of addresses managed by this @mm
+ * @mm: the drm_mm structure instance to shift
+ * @shift: the shift value to be added to addresses of all nodes
+ *
+ * The function shifts all nodes by given offset, moving the address space
+ * range managed by this @mm.
+ */
+void drm_mm_shift(struct drm_mm *mm, s64 shift)
+{
+ struct drm_mm_node *node;
+
+ /*
+ * Head node represents a hole, with negative size and start at the end
+ * of addressable area. This means it is never present within nodes
+ * list - needs to be shifted separately.
+ */
+ mm->head_node.start += shift;
+
+ drm_mm_for_each_node(node, mm)
+ node->start += shift;
+}
+EXPORT_SYMBOL(drm_mm_shift);
+
/**
* drm_mm_init - initialize a drm-mm allocator
* @mm: the drm_mm structure to initialize
diff --git a/include/drm/drm_mm.h b/include/drm/drm_mm.h
index f654874c4ce67..798e5a4f07add 100644
--- a/include/drm/drm_mm.h
+++ b/include/drm/drm_mm.h
@@ -465,6 +465,7 @@ static inline int drm_mm_insert_node(struct drm_mm *mm,
void drm_mm_remove_node(struct drm_mm_node *node);
void drm_mm_init(struct drm_mm *mm, u64 start, u64 size);
void drm_mm_takedown(struct drm_mm *mm);
+void drm_mm_shift(struct drm_mm *mm, s64 shift);
/**
* drm_mm_clean - checks whether an allocator is clean
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 3/6] drm/xe: Start using ggtt->start in preparation of balloon removal
2025-10-09 13:52 [PATCH v4 0/6] drm/xe: Make struct xe_ggtt private Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 1/6] drm/xe: Only have a single drmm release action Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 2/6] drm/mm: Introduce address space shifting Maarten Lankhorst
@ 2025-10-09 13:52 ` Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 4/6] drm/xe: Rewrite GGTT VF initialisation Maarten Lankhorst
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Maarten Lankhorst @ 2025-10-09 13:52 UTC (permalink / raw)
To: intel-xe; +Cc: Maarten Lankhorst, Stuart Summers
Instead of having ggtt->size point to the end of ggtt, have ggtt->size
be the actual size of the GGTT, and introduce ggtt->start to point to
the beginning of GGTT.
This will allow a massive cleanup of GGTT in case of SRIOV-VF.
Reviewed-by: Stuart Summers <stuart.summers@intel.com>
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c | 2 +-
drivers/gpu/drm/xe/xe_ggtt.c | 70 ++++++++++++---------
drivers/gpu/drm/xe/xe_ggtt.h | 2 +
drivers/gpu/drm/xe/xe_ggtt_types.h | 4 +-
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 4 +-
5 files changed, 48 insertions(+), 34 deletions(-)
diff --git a/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c b/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
index d266882adc0e0..acddbedcf17cb 100644
--- a/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
+++ b/drivers/gpu/drm/xe/tests/xe_guc_buf_kunit.c
@@ -67,7 +67,7 @@ static int guc_buf_test_init(struct kunit *test)
KUNIT_ASSERT_EQ(test, 0,
xe_ggtt_init_kunit(ggtt, DUT_GGTT_START,
- DUT_GGTT_START + DUT_GGTT_SIZE));
+ DUT_GGTT_SIZE));
kunit_activate_static_stub(test, xe_managed_bo_create_pin_map,
replacement_xe_managed_bo_create_pin_map);
diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index c2f23926b5a7b..c53fe9f7ce4da 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -124,10 +124,20 @@ static void ggtt_update_access_counter(struct xe_ggtt *ggtt)
}
}
+u64 xe_ggtt_start(struct xe_ggtt *ggtt)
+{
+ return ggtt->start;
+}
+
+u64 xe_ggtt_size(struct xe_ggtt *ggtt)
+{
+ return ggtt->size;
+}
+
static void xe_ggtt_set_pte(struct xe_ggtt *ggtt, u64 addr, u64 pte)
{
xe_tile_assert(ggtt->tile, !(addr & XE_PTE_MASK));
- xe_tile_assert(ggtt->tile, addr < ggtt->size);
+ xe_tile_assert(ggtt->tile, addr < ggtt->start + ggtt->size);
writeq(pte, &ggtt->gsm[addr >> XE_PTE_SHIFT]);
}
@@ -224,18 +234,18 @@ static const struct xe_ggtt_pt_ops xelpg_pt_wa_ops = {
.ggtt_set_pte = xe_ggtt_set_pte_and_flush,
};
-static void __xe_ggtt_init_early(struct xe_ggtt *ggtt, u32 reserved)
+static void __xe_ggtt_init_early(struct xe_ggtt *ggtt, u64 start, u64 size)
{
- drm_mm_init(&ggtt->mm, reserved,
- ggtt->size - reserved);
+ ggtt->start = start;
+ ggtt->size = size;
+ drm_mm_init(&ggtt->mm, start, ggtt->size);
mutex_init(&ggtt->lock);
primelockdep(ggtt);
}
-int xe_ggtt_init_kunit(struct xe_ggtt *ggtt, u32 reserved, u32 size)
+int xe_ggtt_init_kunit(struct xe_ggtt *ggtt, u32 start, u32 size)
{
- ggtt->size = size;
- __xe_ggtt_init_early(ggtt, reserved);
+ __xe_ggtt_init_early(ggtt, start, size);
return 0;
}
EXPORT_SYMBOL_IF_KUNIT(xe_ggtt_init_kunit);
@@ -256,26 +266,32 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
struct xe_device *xe = tile_to_xe(ggtt->tile);
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
unsigned int gsm_size;
+ u64 ggtt_start, wopcm = xe_wopcm_size(xe), ggtt_size;
int err;
- if (IS_SRIOV_VF(xe) || GRAPHICS_VERx100(xe) >= 1250)
- gsm_size = SZ_8M; /* GGTT is expected to be 4GiB */
- else
- gsm_size = probe_gsm_size(pdev);
-
- if (gsm_size == 0) {
- xe_tile_err(ggtt->tile, "Hardware reported no preallocated GSM\n");
- return -ENOMEM;
+ if (!IS_SRIOV_VF(xe)) {
+ if (GRAPHICS_VERx100(xe) >= 1250)
+ gsm_size = SZ_8M; /* GGTT is expected to be 4GiB */
+ else
+ gsm_size = probe_gsm_size(pdev);
+ if (gsm_size == 0) {
+ xe_tile_err(ggtt->tile, "Hardware reported no preallocated GSM\n");
+ return -ENOMEM;
+ }
+ ggtt_start = wopcm;
+ ggtt_size = (gsm_size / 8) * (u64) XE_PAGE_SIZE - ggtt_start;
+ } else {
+ /* GGTT is expected to be 4GiB */
+ ggtt_start = wopcm;
+ ggtt_size = SZ_4G - ggtt_start;
}
ggtt->gsm = ggtt->tile->mmio.regs + SZ_8M;
- ggtt->size = (gsm_size / 8) * (u64) XE_PAGE_SIZE;
-
if (IS_DGFX(xe) && xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K)
ggtt->flags |= XE_GGTT_FLAGS_64K;
- if (ggtt->size > GUC_GGTT_TOP)
- ggtt->size = GUC_GGTT_TOP;
+ if (ggtt_size + ggtt_start > GUC_GGTT_TOP)
+ ggtt_size = GUC_GGTT_TOP - ggtt_start;
if (GRAPHICS_VERx100(xe) >= 1270)
ggtt->pt_ops = (ggtt->tile->media_gt &&
@@ -286,7 +302,7 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
ggtt->pt_ops = &xelp_pt_ops;
ggtt->wq = alloc_workqueue("xe-ggtt-wq", 0, WQ_MEM_RECLAIM);
- __xe_ggtt_init_early(ggtt, xe_wopcm_size(xe));
+ __xe_ggtt_init_early(ggtt, ggtt_start, ggtt_size);
err = drmm_add_action_or_reset(&xe->drm, ggtt_fini_early, ggtt);
if (err)
@@ -520,11 +536,9 @@ void xe_ggtt_node_remove_balloon_locked(struct xe_ggtt_node *node)
static void xe_ggtt_assert_fit(struct xe_ggtt *ggtt, u64 start, u64 size)
{
struct xe_tile *tile = ggtt->tile;
- struct xe_device *xe = tile_to_xe(tile);
- u64 __maybe_unused wopcm = xe_wopcm_size(xe);
- xe_tile_assert(tile, start >= wopcm);
- xe_tile_assert(tile, start + size < ggtt->size - wopcm);
+ xe_tile_assert(tile, start >= ggtt->start);
+ xe_tile_assert(tile, start + size <= ggtt->start + ggtt->size);
}
/**
@@ -833,14 +847,12 @@ u64 xe_ggtt_largest_hole(struct xe_ggtt *ggtt, u64 alignment, u64 *spare)
{
const struct drm_mm *mm = &ggtt->mm;
const struct drm_mm_node *entry;
- u64 hole_min_start = xe_wopcm_size(tile_to_xe(ggtt->tile));
u64 hole_start, hole_end, hole_size;
u64 max_hole = 0;
mutex_lock(&ggtt->lock);
-
drm_mm_for_each_hole(entry, mm, hole_start, hole_end) {
- hole_start = max(hole_start, hole_min_start);
+ hole_start = max(hole_start, ggtt->start);
hole_start = ALIGN(hole_start, alignment);
hole_end = ALIGN_DOWN(hole_end, alignment);
if (hole_start >= hole_end)
@@ -933,15 +945,13 @@ u64 xe_ggtt_print_holes(struct xe_ggtt *ggtt, u64 alignment, struct drm_printer
{
const struct drm_mm *mm = &ggtt->mm;
const struct drm_mm_node *entry;
- u64 hole_min_start = xe_wopcm_size(tile_to_xe(ggtt->tile));
u64 hole_start, hole_end, hole_size;
u64 total = 0;
char buf[10];
mutex_lock(&ggtt->lock);
-
drm_mm_for_each_hole(entry, mm, hole_start, hole_end) {
- hole_start = max(hole_start, hole_min_start);
+ hole_start = max(hole_start, ggtt->start);
hole_start = ALIGN(hole_start, alignment);
hole_end = ALIGN_DOWN(hole_end, alignment);
if (hole_start >= hole_end)
diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
index 75fc7a1efea76..6482bddb2ef36 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.h
+++ b/drivers/gpu/drm/xe/xe_ggtt.h
@@ -23,6 +23,8 @@ int xe_ggtt_node_insert_balloon_locked(struct xe_ggtt_node *node,
u64 start, u64 size);
void xe_ggtt_node_remove_balloon_locked(struct xe_ggtt_node *node);
void xe_ggtt_shift_nodes_locked(struct xe_ggtt *ggtt, s64 shift);
+u64 xe_ggtt_start(struct xe_ggtt *ggtt);
+u64 xe_ggtt_size(struct xe_ggtt *ggtt);
int xe_ggtt_node_insert(struct xe_ggtt_node *node, u32 size, u32 align);
int xe_ggtt_node_insert_locked(struct xe_ggtt_node *node,
diff --git a/drivers/gpu/drm/xe/xe_ggtt_types.h b/drivers/gpu/drm/xe/xe_ggtt_types.h
index c5e999d58ff2a..a27919302d6b2 100644
--- a/drivers/gpu/drm/xe/xe_ggtt_types.h
+++ b/drivers/gpu/drm/xe/xe_ggtt_types.h
@@ -22,7 +22,9 @@ struct xe_gt;
struct xe_ggtt {
/** @tile: Back pointer to tile where this GGTT belongs */
struct xe_tile *tile;
- /** @size: Total size of this GGTT */
+ /** @start: Start offset of GGTT */
+ u64 start;
+ /** @size: Total usable size of this GGTT */
u64 size;
#define XE_GGTT_FLAGS_64K BIT(0)
diff --git a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
index b2e5c52978e6a..2289756761636 100644
--- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
+++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
@@ -343,8 +343,8 @@ static int pf_push_full_vf_config(struct xe_gt *gt, unsigned int vfid)
xe_gt_assert(gt, num_dwords <= max_cfg_dwords);
if (vfid == PFID) {
- u64 ggtt_start = xe_wopcm_size(gt_to_xe(gt));
- u64 ggtt_size = gt_to_tile(gt)->mem.ggtt->size - ggtt_start;
+ u64 ggtt_start = xe_ggtt_start(gt_to_tile(gt)->mem.ggtt);
+ u64 ggtt_size = xe_ggtt_size(gt_to_tile(gt)->mem.ggtt);
/* plain PF config data will never include a real GGTT region */
xe_gt_assert(gt, !encode_config_ggtt(cfg + num_dwords, config, true));
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 4/6] drm/xe: Rewrite GGTT VF initialisation
2025-10-09 13:52 [PATCH v4 0/6] drm/xe: Make struct xe_ggtt private Maarten Lankhorst
` (2 preceding siblings ...)
2025-10-09 13:52 ` [PATCH v4 3/6] drm/xe: Start using ggtt->start in preparation of balloon removal Maarten Lankhorst
@ 2025-10-09 13:52 ` Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 5/6] drm/xe: Convert xe_fb_pin to use a callback for insertion into GGTT Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 6/6] drm/xe: Move struct xe_ggtt to xe_ggtt.c Maarten Lankhorst
5 siblings, 0 replies; 8+ messages in thread
From: Maarten Lankhorst @ 2025-10-09 13:52 UTC (permalink / raw)
To: intel-xe; +Cc: Maarten Lankhorst
The previous code was using a complicated system with 2 balloons to
set GGTT size and adjust GGTT offset. While it works, it's overly
complicated.
A better approach is to set the offset and size when initialising GGTT,
this removes the need for adding balloons. The resize function only
needs to re-initialise GGTT at the new offset.
We use the newly created drm_mm_shift to shift the nodes.
This removes the need to manipulate the internals of xe_ggtt outside
of xe_ggtt, and cleans up a lot of now unneeded code.
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
drivers/gpu/drm/xe/Makefile | 3 +-
drivers/gpu/drm/xe/xe_ggtt.c | 143 +++------------
drivers/gpu/drm/xe/xe_ggtt.h | 5 +-
drivers/gpu/drm/xe/xe_sriov_vf.c | 4 +-
drivers/gpu/drm/xe/xe_tile_sriov_vf.c | 254 --------------------------
drivers/gpu/drm/xe/xe_tile_sriov_vf.h | 18 --
6 files changed, 29 insertions(+), 398 deletions(-)
delete mode 100644 drivers/gpu/drm/xe/xe_tile_sriov_vf.c
delete mode 100644 drivers/gpu/drm/xe/xe_tile_sriov_vf.h
diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
index 84321fad32658..1f573bf53cf1a 100644
--- a/drivers/gpu/drm/xe/Makefile
+++ b/drivers/gpu/drm/xe/Makefile
@@ -158,8 +158,7 @@ xe-y += \
xe_memirq.o \
xe_sriov.o \
xe_sriov_vf.o \
- xe_sriov_vf_ccs.o \
- xe_tile_sriov_vf.o
+ xe_sriov_vf_ccs.o
xe-$(CONFIG_PCI_IOV) += \
xe_gt_sriov_pf.o \
diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index c53fe9f7ce4da..3429e54a43eb5 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -23,13 +23,13 @@
#include "xe_device.h"
#include "xe_gt.h"
#include "xe_gt_printk.h"
+#include "xe_gt_sriov_vf.h"
#include "xe_map.h"
#include "xe_mmio.h"
#include "xe_pm.h"
#include "xe_res_cursor.h"
#include "xe_sriov.h"
#include "xe_tile_printk.h"
-#include "xe_tile_sriov_vf.h"
#include "xe_tlb_inval.h"
#include "xe_wa.h"
#include "xe_wopcm.h"
@@ -267,7 +267,6 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
unsigned int gsm_size;
u64 ggtt_start, wopcm = xe_wopcm_size(xe), ggtt_size;
- int err;
if (!IS_SRIOV_VF(xe)) {
if (GRAPHICS_VERx100(xe) >= 1250)
@@ -281,9 +280,15 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
ggtt_start = wopcm;
ggtt_size = (gsm_size / 8) * (u64) XE_PAGE_SIZE - ggtt_start;
} else {
- /* GGTT is expected to be 4GiB */
- ggtt_start = wopcm;
- ggtt_size = SZ_4G - ggtt_start;
+ ggtt_start = xe_gt_sriov_vf_ggtt_base(ggtt->tile->primary_gt);
+ ggtt_size = xe_gt_sriov_vf_ggtt(ggtt->tile->primary_gt);
+
+ if (ggtt_start < wopcm || ggtt_start > GUC_GGTT_TOP ||
+ ggtt_size > GUC_GGTT_TOP - ggtt_start) {
+ xe_tile_err(ggtt->tile, "tile%u: Invalid GGTT configuration: %#llx-%#llx\n",
+ ggtt->tile->id, ggtt_start, ggtt_start + ggtt_size - 1);
+ return -ERANGE;
+ }
}
ggtt->gsm = ggtt->tile->mmio.regs + SZ_8M;
@@ -304,17 +309,7 @@ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
ggtt->wq = alloc_workqueue("xe-ggtt-wq", 0, WQ_MEM_RECLAIM);
__xe_ggtt_init_early(ggtt, ggtt_start, ggtt_size);
- err = drmm_add_action_or_reset(&xe->drm, ggtt_fini_early, ggtt);
- if (err)
- return err;
-
- if (IS_SRIOV_VF(xe)) {
- err = xe_tile_sriov_vf_prepare_ggtt(ggtt->tile);
- if (err)
- return err;
- }
-
- return 0;
+ return drmm_add_action_or_reset(&xe->drm, ggtt_fini_early, ggtt);
}
ALLOW_ERROR_INJECTION(xe_ggtt_init_early, ERRNO); /* See xe_pci_probe() */
@@ -466,83 +461,8 @@ static void xe_ggtt_invalidate(struct xe_ggtt *ggtt)
ggtt_invalidate_gt_tlb(ggtt->tile->media_gt);
}
-static void xe_ggtt_dump_node(struct xe_ggtt *ggtt,
- const struct drm_mm_node *node, const char *description)
-{
- char buf[10];
-
- if (IS_ENABLED(CONFIG_DRM_XE_DEBUG)) {
- string_get_size(node->size, 1, STRING_UNITS_2, buf, sizeof(buf));
- xe_tile_dbg(ggtt->tile, "GGTT %#llx-%#llx (%s) %s\n",
- node->start, node->start + node->size, buf, description);
- }
-}
-
-/**
- * xe_ggtt_node_insert_balloon_locked - prevent allocation of specified GGTT addresses
- * @node: the &xe_ggtt_node to hold reserved GGTT node
- * @start: the starting GGTT address of the reserved region
- * @end: then end GGTT address of the reserved region
- *
- * To be used in cases where ggtt->lock is already taken.
- * Use xe_ggtt_node_remove_balloon_locked() to release a reserved GGTT node.
- *
- * Return: 0 on success or a negative error code on failure.
- */
-int xe_ggtt_node_insert_balloon_locked(struct xe_ggtt_node *node, u64 start, u64 end)
-{
- struct xe_ggtt *ggtt = node->ggtt;
- int err;
-
- xe_tile_assert(ggtt->tile, start < end);
- xe_tile_assert(ggtt->tile, IS_ALIGNED(start, XE_PAGE_SIZE));
- xe_tile_assert(ggtt->tile, IS_ALIGNED(end, XE_PAGE_SIZE));
- xe_tile_assert(ggtt->tile, !drm_mm_node_allocated(&node->base));
- lockdep_assert_held(&ggtt->lock);
-
- node->base.color = 0;
- node->base.start = start;
- node->base.size = end - start;
-
- err = drm_mm_reserve_node(&ggtt->mm, &node->base);
-
- if (xe_tile_WARN(ggtt->tile, err, "Failed to balloon GGTT %#llx-%#llx (%pe)\n",
- node->base.start, node->base.start + node->base.size, ERR_PTR(err)))
- return err;
-
- xe_ggtt_dump_node(ggtt, &node->base, "balloon");
- return 0;
-}
-
/**
- * xe_ggtt_node_remove_balloon_locked - release a reserved GGTT region
- * @node: the &xe_ggtt_node with reserved GGTT region
- *
- * To be used in cases where ggtt->lock is already taken.
- * See xe_ggtt_node_insert_balloon_locked() for details.
- */
-void xe_ggtt_node_remove_balloon_locked(struct xe_ggtt_node *node)
-{
- if (!xe_ggtt_node_allocated(node))
- return;
-
- lockdep_assert_held(&node->ggtt->lock);
-
- xe_ggtt_dump_node(node->ggtt, &node->base, "remove-balloon");
-
- drm_mm_remove_node(&node->base);
-}
-
-static void xe_ggtt_assert_fit(struct xe_ggtt *ggtt, u64 start, u64 size)
-{
- struct xe_tile *tile = ggtt->tile;
-
- xe_tile_assert(tile, start >= ggtt->start);
- xe_tile_assert(tile, start + size <= ggtt->start + ggtt->size);
-}
-
-/**
- * xe_ggtt_shift_nodes_locked - Shift GGTT nodes to adjust for a change in usable address range.
+ * xe_ggtt_shift_nodes - Shift GGTT nodes to adjust for a change in usable address range.
* @ggtt: the &xe_ggtt struct instance
* @shift: change to the location of area provisioned for current VF
*
@@ -556,29 +476,18 @@ static void xe_ggtt_assert_fit(struct xe_ggtt *ggtt, u64 start, u64 size)
* the list of nodes was either already damaged, or that the shift brings the address range
* outside of valid bounds. Both cases justify an assert rather than error code.
*/
-void xe_ggtt_shift_nodes_locked(struct xe_ggtt *ggtt, s64 shift)
+void xe_ggtt_shift_nodes(struct xe_ggtt *ggtt, s64 shift)
{
- struct xe_tile *tile __maybe_unused = ggtt->tile;
- struct drm_mm_node *node, *tmpn;
- LIST_HEAD(temp_list_head);
+ s64 new_start;
- lockdep_assert_held(&ggtt->lock);
+ mutex_lock(&ggtt->lock);
- if (IS_ENABLED(CONFIG_DRM_XE_DEBUG))
- drm_mm_for_each_node_safe(node, tmpn, &ggtt->mm)
- xe_ggtt_assert_fit(ggtt, node->start + shift, node->size);
+ new_start = ggtt->start + shift;
+ xe_tile_assert(ggtt->tile, new_start >= xe_wopcm_size(tile_to_xe(ggtt->tile)));
+ xe_tile_assert(ggtt->tile, new_start + ggtt->size <= GUC_GGTT_TOP);
- drm_mm_for_each_node_safe(node, tmpn, &ggtt->mm) {
- drm_mm_remove_node(node);
- list_add(&node->node_list, &temp_list_head);
- }
-
- list_for_each_entry_safe(node, tmpn, &temp_list_head, node_list) {
- list_del(&node->node_list);
- node->start += shift;
- drm_mm_reserve_node(&ggtt->mm, node);
- xe_tile_assert(tile, drm_mm_node_allocated(node));
- }
+ drm_mm_shift(&ggtt->mm, shift);
+ mutex_unlock(&ggtt->lock);
}
/**
@@ -630,11 +539,9 @@ int xe_ggtt_node_insert(struct xe_ggtt_node *node, u32 size, u32 align)
* @ggtt: the &xe_ggtt where the new node will later be inserted/reserved.
*
* This function will allocate the struct %xe_ggtt_node and return its pointer.
- * This struct will then be freed after the node removal upon xe_ggtt_node_remove()
- * or xe_ggtt_node_remove_balloon_locked().
+ * This struct will then be freed after the node removal upon xe_ggtt_node_remove().
* Having %xe_ggtt_node struct allocated doesn't mean that the node is already allocated
- * in GGTT. Only the xe_ggtt_node_insert(), xe_ggtt_node_insert_locked(),
- * xe_ggtt_node_insert_balloon_locked() will ensure the node is inserted or reserved in GGTT.
+ * in GGTT. Only xe_ggtt_node_insert() will ensure the node is inserted or reserved in GGTT.
*
* Return: A pointer to %xe_ggtt_node struct on success. An ERR_PTR otherwise.
**/
@@ -655,9 +562,9 @@ struct xe_ggtt_node *xe_ggtt_node_init(struct xe_ggtt *ggtt)
* xe_ggtt_node_fini - Forcebly finalize %xe_ggtt_node struct
* @node: the &xe_ggtt_node to be freed
*
- * If anything went wrong with either xe_ggtt_node_insert(), xe_ggtt_node_insert_locked(),
- * or xe_ggtt_node_insert_balloon_locked(); and this @node is not going to be reused, then,
- * this function needs to be called to free the %xe_ggtt_node struct
+ * If anything went wrong with either xe_ggtt_node_insert() and this @node is
+ * not going to be reused, then this function needs to be called to free the
+ * %xe_ggtt_node struct
**/
void xe_ggtt_node_fini(struct xe_ggtt_node *node)
{
diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
index 6482bddb2ef36..eccef2d2b3cee 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.h
+++ b/drivers/gpu/drm/xe/xe_ggtt.h
@@ -19,10 +19,7 @@ int xe_ggtt_init(struct xe_ggtt *ggtt);
struct xe_ggtt_node *xe_ggtt_node_init(struct xe_ggtt *ggtt);
void xe_ggtt_node_fini(struct xe_ggtt_node *node);
-int xe_ggtt_node_insert_balloon_locked(struct xe_ggtt_node *node,
- u64 start, u64 size);
-void xe_ggtt_node_remove_balloon_locked(struct xe_ggtt_node *node);
-void xe_ggtt_shift_nodes_locked(struct xe_ggtt *ggtt, s64 shift);
+void xe_ggtt_shift_nodes(struct xe_ggtt *ggtt, s64 shift);
u64 xe_ggtt_start(struct xe_ggtt *ggtt);
u64 xe_ggtt_size(struct xe_ggtt *ggtt);
diff --git a/drivers/gpu/drm/xe/xe_sriov_vf.c b/drivers/gpu/drm/xe/xe_sriov_vf.c
index c1830ec8f0fd6..4bfd9013187b2 100644
--- a/drivers/gpu/drm/xe/xe_sriov_vf.c
+++ b/drivers/gpu/drm/xe/xe_sriov_vf.c
@@ -8,6 +8,7 @@
#include "xe_assert.h"
#include "xe_device.h"
+#include "xe_ggtt.h"
#include "xe_gt.h"
#include "xe_gt_sriov_printk.h"
#include "xe_gt_sriov_vf.h"
@@ -20,7 +21,6 @@
#include "xe_sriov_printk.h"
#include "xe_sriov_vf.h"
#include "xe_sriov_vf_ccs.h"
-#include "xe_tile_sriov_vf.h"
/**
* DOC: VF restore procedure in PF KMD and VF KMD
@@ -328,7 +328,7 @@ static int gt_vf_post_migration_fixups(struct xe_gt *gt)
shift = xe_gt_sriov_vf_ggtt_shift(gt);
if (shift) {
- xe_tile_sriov_vf_fixup_ggtt_nodes(gt_to_tile(gt), shift);
+ xe_ggtt_shift_nodes(gt_to_tile(gt)->mem.ggtt, shift);
xe_gt_sriov_vf_default_lrcs_hwsp_rebase(gt);
err = xe_guc_contexts_hwsp_rebase(>->uc.guc, buf);
if (err)
diff --git a/drivers/gpu/drm/xe/xe_tile_sriov_vf.c b/drivers/gpu/drm/xe/xe_tile_sriov_vf.c
deleted file mode 100644
index f221dbed16f09..0000000000000
--- a/drivers/gpu/drm/xe/xe_tile_sriov_vf.c
+++ /dev/null
@@ -1,254 +0,0 @@
-// SPDX-License-Identifier: MIT
-/*
- * Copyright © 2025 Intel Corporation
- */
-
-#include <drm/drm_managed.h>
-
-#include "regs/xe_gtt_defs.h"
-
-#include "xe_assert.h"
-#include "xe_ggtt.h"
-#include "xe_gt_sriov_vf.h"
-#include "xe_sriov.h"
-#include "xe_sriov_printk.h"
-#include "xe_tile_sriov_vf.h"
-#include "xe_wopcm.h"
-
-static int vf_init_ggtt_balloons(struct xe_tile *tile)
-{
- struct xe_ggtt *ggtt = tile->mem.ggtt;
-
- xe_tile_assert(tile, IS_SRIOV_VF(tile_to_xe(tile)));
-
- tile->sriov.vf.ggtt_balloon[0] = xe_ggtt_node_init(ggtt);
- if (IS_ERR(tile->sriov.vf.ggtt_balloon[0]))
- return PTR_ERR(tile->sriov.vf.ggtt_balloon[0]);
-
- tile->sriov.vf.ggtt_balloon[1] = xe_ggtt_node_init(ggtt);
- if (IS_ERR(tile->sriov.vf.ggtt_balloon[1])) {
- xe_ggtt_node_fini(tile->sriov.vf.ggtt_balloon[0]);
- return PTR_ERR(tile->sriov.vf.ggtt_balloon[1]);
- }
-
- return 0;
-}
-
-/**
- * xe_tile_sriov_vf_balloon_ggtt_locked - Insert balloon nodes to limit used GGTT address range.
- * @tile: the &xe_tile struct instance
- *
- * Return: 0 on success or a negative error code on failure.
- */
-int xe_tile_sriov_vf_balloon_ggtt_locked(struct xe_tile *tile)
-{
- u64 ggtt_base = xe_gt_sriov_vf_ggtt_base(tile->primary_gt);
- u64 ggtt_size = xe_gt_sriov_vf_ggtt(tile->primary_gt);
- struct xe_device *xe = tile_to_xe(tile);
- u64 wopcm = xe_wopcm_size(xe);
- u64 start, end;
- int err;
-
- xe_tile_assert(tile, IS_SRIOV_VF(xe));
- xe_tile_assert(tile, ggtt_size);
- lockdep_assert_held(&tile->mem.ggtt->lock);
-
- /*
- * VF can only use part of the GGTT as allocated by the PF:
- *
- * WOPCM GUC_GGTT_TOP
- * |<------------ Total GGTT size ------------------>|
- *
- * VF GGTT base -->|<- size ->|
- *
- * +--------------------+----------+-----------------+
- * |////////////////////| block |\\\\\\\\\\\\\\\\\|
- * +--------------------+----------+-----------------+
- *
- * |<--- balloon[0] --->|<-- VF -->|<-- balloon[1] ->|
- */
-
- if (ggtt_base < wopcm || ggtt_base > GUC_GGTT_TOP ||
- ggtt_size > GUC_GGTT_TOP - ggtt_base) {
- xe_sriov_err(xe, "tile%u: Invalid GGTT configuration: %#llx-%#llx\n",
- tile->id, ggtt_base, ggtt_base + ggtt_size - 1);
- return -ERANGE;
- }
-
- start = wopcm;
- end = ggtt_base;
- if (end != start) {
- err = xe_ggtt_node_insert_balloon_locked(tile->sriov.vf.ggtt_balloon[0],
- start, end);
- if (err)
- return err;
- }
-
- start = ggtt_base + ggtt_size;
- end = GUC_GGTT_TOP;
- if (end != start) {
- err = xe_ggtt_node_insert_balloon_locked(tile->sriov.vf.ggtt_balloon[1],
- start, end);
- if (err) {
- xe_ggtt_node_remove_balloon_locked(tile->sriov.vf.ggtt_balloon[0]);
- return err;
- }
- }
-
- return 0;
-}
-
-static int vf_balloon_ggtt(struct xe_tile *tile)
-{
- struct xe_ggtt *ggtt = tile->mem.ggtt;
- int err;
-
- mutex_lock(&ggtt->lock);
- err = xe_tile_sriov_vf_balloon_ggtt_locked(tile);
- mutex_unlock(&ggtt->lock);
-
- return err;
-}
-
-/**
- * xe_tile_sriov_vf_deballoon_ggtt_locked - Remove balloon nodes.
- * @tile: the &xe_tile struct instance
- */
-void xe_tile_sriov_vf_deballoon_ggtt_locked(struct xe_tile *tile)
-{
- xe_tile_assert(tile, IS_SRIOV_VF(tile_to_xe(tile)));
-
- xe_ggtt_node_remove_balloon_locked(tile->sriov.vf.ggtt_balloon[1]);
- xe_ggtt_node_remove_balloon_locked(tile->sriov.vf.ggtt_balloon[0]);
-}
-
-static void vf_deballoon_ggtt(struct xe_tile *tile)
-{
- mutex_lock(&tile->mem.ggtt->lock);
- xe_tile_sriov_vf_deballoon_ggtt_locked(tile);
- mutex_unlock(&tile->mem.ggtt->lock);
-}
-
-static void vf_fini_ggtt_balloons(struct xe_tile *tile)
-{
- xe_tile_assert(tile, IS_SRIOV_VF(tile_to_xe(tile)));
-
- xe_ggtt_node_fini(tile->sriov.vf.ggtt_balloon[1]);
- xe_ggtt_node_fini(tile->sriov.vf.ggtt_balloon[0]);
-}
-
-static void cleanup_ggtt(struct drm_device *drm, void *arg)
-{
- struct xe_tile *tile = arg;
-
- vf_deballoon_ggtt(tile);
- vf_fini_ggtt_balloons(tile);
-}
-
-/**
- * xe_tile_sriov_vf_prepare_ggtt - Prepare a VF's GGTT configuration.
- * @tile: the &xe_tile
- *
- * This function is for VF use only.
- *
- * Return: 0 on success or a negative error code on failure.
- */
-int xe_tile_sriov_vf_prepare_ggtt(struct xe_tile *tile)
-{
- struct xe_device *xe = tile_to_xe(tile);
- int err;
-
- err = vf_init_ggtt_balloons(tile);
- if (err)
- return err;
-
- err = vf_balloon_ggtt(tile);
- if (err) {
- vf_fini_ggtt_balloons(tile);
- return err;
- }
-
- return drmm_add_action_or_reset(&xe->drm, cleanup_ggtt, tile);
-}
-
-/**
- * DOC: GGTT nodes shifting during VF post-migration recovery
- *
- * The first fixup applied to the VF KMD structures as part of post-migration
- * recovery is shifting nodes within &xe_ggtt instance. The nodes are moved
- * from range previously assigned to this VF, into newly provisioned area.
- * The changes include balloons, which are resized accordingly.
- *
- * The balloon nodes are there to eliminate unavailable ranges from use: one
- * reserves the GGTT area below the range for current VF, and another one
- * reserves area above.
- *
- * Below is a GGTT layout of example VF, with a certain address range assigned to
- * said VF, and inaccessible areas above and below:
- *
- * 0 4GiB
- * |<--------------------------- Total GGTT size ----------------------------->|
- * WOPCM GUC_TOP
- * |<-------------- Area mappable by xe_ggtt instance ---------------->|
- *
- * +---+---------------------------------+----------+----------------------+---+
- * |\\\|/////////////////////////////////| VF mem |//////////////////////|\\\|
- * +---+---------------------------------+----------+----------------------+---+
- *
- * Hardware enforced access rules before migration:
- *
- * |<------- inaccessible for VF ------->|<VF owned>|<-- inaccessible for VF ->|
- *
- * GGTT nodes used for tracking allocations:
- *
- * |<---------- balloon ------------>|<- nodes->|<----- balloon ------>|
- *
- * After the migration, GGTT area assigned to the VF might have shifted, either
- * to lower or to higher address. But we expect the total size and extra areas to
- * be identical, as migration can only happen between matching platforms.
- * Below is an example of GGTT layout of the VF after migration. Content of the
- * GGTT for VF has been moved to a new area, and we receive its address from GuC:
- *
- * +---+----------------------+----------+---------------------------------+---+
- * |\\\|//////////////////////| VF mem |/////////////////////////////////|\\\|
- * +---+----------------------+----------+---------------------------------+---+
- *
- * Hardware enforced access rules after migration:
- *
- * |<- inaccessible for VF -->|<VF owned>|<------- inaccessible for VF ------->|
- *
- * So the VF has a new slice of GGTT assigned, and during migration process, the
- * memory content was copied to that new area. But the &xe_ggtt nodes are still
- * tracking allocations using the old addresses. The nodes within VF owned area
- * have to be shifted, and balloon nodes need to be resized to properly mask out
- * areas not owned by the VF.
- *
- * Fixed &xe_ggtt nodes used for tracking allocations:
- *
- * |<------ balloon ------>|<- nodes->|<----------- balloon ----------->|
- *
- * Due to use of GPU profiles, we do not expect the old and new GGTT ares to
- * overlap; but our node shifting will fix addresses properly regardless.
- */
-
-/**
- * xe_tile_sriov_vf_fixup_ggtt_nodes - Shift GGTT allocations to match assigned range.
- * @tile: the &xe_tile struct instance
- * @shift: the shift value
- *
- * Since Global GTT is not virtualized, each VF has an assigned range
- * within the global space. This range might have changed during migration,
- * which requires all memory addresses pointing to GGTT to be shifted.
- */
-void xe_tile_sriov_vf_fixup_ggtt_nodes(struct xe_tile *tile, s64 shift)
-{
- struct xe_ggtt *ggtt = tile->mem.ggtt;
-
- mutex_lock(&ggtt->lock);
-
- xe_tile_sriov_vf_deballoon_ggtt_locked(tile);
- xe_ggtt_shift_nodes_locked(ggtt, shift);
- xe_tile_sriov_vf_balloon_ggtt_locked(tile);
-
- mutex_unlock(&ggtt->lock);
-}
diff --git a/drivers/gpu/drm/xe/xe_tile_sriov_vf.h b/drivers/gpu/drm/xe/xe_tile_sriov_vf.h
deleted file mode 100644
index 93eb043171e83..0000000000000
--- a/drivers/gpu/drm/xe/xe_tile_sriov_vf.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/* SPDX-License-Identifier: MIT */
-/*
- * Copyright © 2025 Intel Corporation
- */
-
-#ifndef _XE_TILE_SRIOV_VF_H_
-#define _XE_TILE_SRIOV_VF_H_
-
-#include <linux/types.h>
-
-struct xe_tile;
-
-int xe_tile_sriov_vf_prepare_ggtt(struct xe_tile *tile);
-int xe_tile_sriov_vf_balloon_ggtt_locked(struct xe_tile *tile);
-void xe_tile_sriov_vf_deballoon_ggtt_locked(struct xe_tile *tile);
-void xe_tile_sriov_vf_fixup_ggtt_nodes(struct xe_tile *tile, s64 shift);
-
-#endif
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 5/6] drm/xe: Convert xe_fb_pin to use a callback for insertion into GGTT
2025-10-09 13:52 [PATCH v4 0/6] drm/xe: Make struct xe_ggtt private Maarten Lankhorst
` (3 preceding siblings ...)
2025-10-09 13:52 ` [PATCH v4 4/6] drm/xe: Rewrite GGTT VF initialisation Maarten Lankhorst
@ 2025-10-09 13:52 ` Maarten Lankhorst
2025-10-09 13:52 ` [PATCH v4 6/6] drm/xe: Move struct xe_ggtt to xe_ggtt.c Maarten Lankhorst
5 siblings, 0 replies; 8+ messages in thread
From: Maarten Lankhorst @ 2025-10-09 13:52 UTC (permalink / raw)
To: intel-xe
Cc: Maarten Lankhorst, Matthew Brost, Juha-Pekka Heikkila,
Maarten Lankhorst
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
The rotation details belong in xe_fb_pin.c, while the operations involving
GGTT belong to xe_ggtt.c. As directly locking xe_ggtt etc results in
exposing all of xe_ggtt details anyway, create a special function that
allocates a ggtt_node, and allow display to populate it using a callback
as a compromise.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
drivers/gpu/drm/xe/display/xe_fb_pin.c | 111 ++++++++++++-------------
drivers/gpu/drm/xe/xe_ggtt.c | 92 ++++++++++++++------
drivers/gpu/drm/xe/xe_ggtt.h | 9 +-
drivers/gpu/drm/xe/xe_ggtt_types.h | 8 +-
4 files changed, 132 insertions(+), 88 deletions(-)
diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c b/drivers/gpu/drm/xe/display/xe_fb_pin.c
index 1fd4a815e784b..d2e4903de0977 100644
--- a/drivers/gpu/drm/xe/display/xe_fb_pin.c
+++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c
@@ -171,12 +171,13 @@ static int __xe_pin_fb_vma_dpt(const struct intel_framebuffer *fb,
}
static void
-write_ggtt_rotated(struct xe_bo *bo, struct xe_ggtt *ggtt, u32 *ggtt_ofs, u32 bo_ofs,
+write_ggtt_rotated(struct xe_ggtt *ggtt, u32 *ggtt_ofs,
+ u64 pte_flags,
+ xe_ggtt_set_pte_fn write_pte,
+ struct xe_bo *bo, u32 bo_ofs,
u32 width, u32 height, u32 src_stride, u32 dst_stride)
{
- struct xe_device *xe = xe_bo_device(bo);
u32 column, row;
- u64 pte = ggtt->pt_ops->pte_encode_flags(bo, xe->pat.idx[XE_CACHE_NONE]);
for (column = 0; column < width; column++) {
u32 src_idx = src_stride * (height - 1) + column + bo_ofs;
@@ -184,7 +185,7 @@ write_ggtt_rotated(struct xe_bo *bo, struct xe_ggtt *ggtt, u32 *ggtt_ofs, u32 bo
for (row = 0; row < height; row++) {
u64 addr = xe_bo_addr(bo, src_idx * XE_PAGE_SIZE, XE_PAGE_SIZE);
- ggtt->pt_ops->ggtt_set_pte(ggtt, *ggtt_ofs, pte | addr);
+ write_pte(ggtt, *ggtt_ofs, pte_flags | addr);
*ggtt_ofs += XE_PAGE_SIZE;
src_idx -= src_stride;
}
@@ -194,6 +195,28 @@ write_ggtt_rotated(struct xe_bo *bo, struct xe_ggtt *ggtt, u32 *ggtt_ofs, u32 bo
}
}
+struct fb_rotate_args {
+ const struct i915_gtt_view *view;
+ struct xe_bo *bo;
+};
+
+static void write_ggtt_rotated_node(struct xe_ggtt *ggtt, struct xe_ggtt_node *node,
+ u64 pte_flags, xe_ggtt_set_pte_fn write_pte, void *data)
+{
+ struct fb_rotate_args *args = data;
+ struct xe_bo *bo = args->bo;
+ const struct intel_rotation_info *rot_info = &args->view->rotated;
+ u32 ggtt_ofs = node->base.start;
+
+ for (u32 i = 0; i < ARRAY_SIZE(rot_info->plane); i++)
+ write_ggtt_rotated(ggtt, &ggtt_ofs, pte_flags, write_pte,
+ bo, rot_info->plane[i].offset,
+ rot_info->plane[i].width,
+ rot_info->plane[i].height,
+ rot_info->plane[i].src_stride,
+ rot_info->plane[i].dst_stride);
+}
+
static int __xe_pin_fb_vma_ggtt(const struct intel_framebuffer *fb,
const struct i915_gtt_view *view,
struct i915_vma *vma,
@@ -204,70 +227,40 @@ static int __xe_pin_fb_vma_ggtt(const struct intel_framebuffer *fb,
struct xe_device *xe = to_xe_device(fb->base.dev);
struct xe_tile *tile0 = xe_device_get_root_tile(xe);
struct xe_ggtt *ggtt = tile0->mem.ggtt;
+ u64 pte, size;
u32 align;
- int ret;
-
- /* TODO: Consider sharing framebuffer mapping?
- * embed i915_vma inside intel_framebuffer
- */
- xe_pm_runtime_get_noresume(xe);
- ret = mutex_lock_interruptible(&ggtt->lock);
- if (ret)
- goto out;
+ int ret = 0;
align = XE_PAGE_SIZE;
- if (xe_bo_is_vram(bo) && ggtt->flags & XE_GGTT_FLAGS_64K)
- align = max_t(u32, align, SZ_64K);
+ if (xe_bo_is_vram(bo) && xe->info.vram_flags & XE_VRAM_FLAGS_NEED64K)
+ align = max(align, SZ_64K);
+ /* Fast case, preallocated GGTT view? */
if (bo->ggtt_node[tile0->id] && view->type == I915_GTT_VIEW_NORMAL) {
vma->node = bo->ggtt_node[tile0->id];
- } else if (view->type == I915_GTT_VIEW_NORMAL) {
- vma->node = xe_ggtt_node_init(ggtt);
- if (IS_ERR(vma->node)) {
- ret = PTR_ERR(vma->node);
- goto out_unlock;
- }
-
- ret = xe_ggtt_node_insert_locked(vma->node, xe_bo_size(bo), align, 0);
- if (ret) {
- xe_ggtt_node_fini(vma->node);
- goto out_unlock;
- }
-
- xe_ggtt_map_bo(ggtt, vma->node, bo, xe->pat.idx[XE_CACHE_NONE]);
- } else {
- u32 i, ggtt_ofs;
- const struct intel_rotation_info *rot_info = &view->rotated;
-
- /* display seems to use tiles instead of bytes here, so convert it back.. */
- u32 size = intel_rotation_info_size(rot_info) * XE_PAGE_SIZE;
-
- vma->node = xe_ggtt_node_init(ggtt);
- if (IS_ERR(vma->node)) {
- ret = PTR_ERR(vma->node);
- goto out_unlock;
- }
-
- ret = xe_ggtt_node_insert_locked(vma->node, size, align, 0);
- if (ret) {
- xe_ggtt_node_fini(vma->node);
- goto out_unlock;
- }
+ return 0;
+ }
- ggtt_ofs = vma->node->base.start;
+ /* TODO: Consider sharing framebuffer mapping?
+ * embed i915_vma inside intel_framebuffer
+ */
+ xe_pm_runtime_get_noresume(xe);
- for (i = 0; i < ARRAY_SIZE(rot_info->plane); i++)
- write_ggtt_rotated(bo, ggtt, &ggtt_ofs,
- rot_info->plane[i].offset,
- rot_info->plane[i].width,
- rot_info->plane[i].height,
- rot_info->plane[i].src_stride,
- rot_info->plane[i].dst_stride);
- }
+ if (view->type == I915_GTT_VIEW_NORMAL)
+ size = xe_bo_size(bo);
+ else
+ /* display uses tiles instead of bytes here, so convert it back.. */
+ size = intel_rotation_info_size(&view->rotated) * XE_PAGE_SIZE;
+
+ pte = xe_ggtt_encode_pte_flags(ggtt, bo, xe->pat.idx[XE_CACHE_NONE]);
+ vma->node = xe_ggtt_node_insert_transform(ggtt, bo, pte,
+ ALIGN(size, align), align,
+ view->type == I915_GTT_VIEW_NORMAL ?
+ NULL : write_ggtt_rotated_node,
+ &(struct fb_rotate_args){view, bo});
+ if (IS_ERR(vma->node))
+ ret = PTR_ERR(vma->node);
-out_unlock:
- mutex_unlock(&ggtt->lock);
-out:
xe_pm_runtime_put(xe);
return ret;
}
diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index 3429e54a43eb5..e6412046a6489 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -490,19 +490,7 @@ void xe_ggtt_shift_nodes(struct xe_ggtt *ggtt, s64 shift)
mutex_unlock(&ggtt->lock);
}
-/**
- * xe_ggtt_node_insert_locked - Locked version to insert a &xe_ggtt_node into the GGTT
- * @node: the &xe_ggtt_node to be inserted
- * @size: size of the node
- * @align: alignment constrain of the node
- * @mm_flags: flags to control the node behavior
- *
- * It cannot be called without first having called xe_ggtt_init() once.
- * To be used in cases where ggtt->lock is already taken.
- *
- * Return: 0 on success or a negative error code on failure.
- */
-int xe_ggtt_node_insert_locked(struct xe_ggtt_node *node,
+static int xe_ggtt_node_insert_locked(struct xe_ggtt_node *node,
u32 size, u32 align, u32 mm_flags)
{
return drm_mm_insert_node_generic(&node->ggtt->mm, &node->base, size, align, 0,
@@ -539,9 +527,13 @@ int xe_ggtt_node_insert(struct xe_ggtt_node *node, u32 size, u32 align)
* @ggtt: the &xe_ggtt where the new node will later be inserted/reserved.
*
* This function will allocate the struct %xe_ggtt_node and return its pointer.
- * This struct will then be freed after the node removal upon xe_ggtt_node_remove().
- * Having %xe_ggtt_node struct allocated doesn't mean that the node is already allocated
- * in GGTT. Only xe_ggtt_node_insert() will ensure the node is inserted or reserved in GGTT.
+ * This struct will then be freed after the node removal upon
+ * xe_ggtt_node_remove().
+ *
+ * Having %xe_ggtt_node struct allocated doesn't mean that the node is already
+ * allocated in GGTT. Only xe_ggtt_node_insert() or allocation through
+ * xe_ggtt_node_insert_transform() will ensure the node is inserted or reserved
+ * in GGTT.
*
* Return: A pointer to %xe_ggtt_node struct on success. An ERR_PTR otherwise.
**/
@@ -590,13 +582,12 @@ bool xe_ggtt_node_allocated(const struct xe_ggtt_node *node)
* @ggtt: the &xe_ggtt where node will be mapped
* @node: the &xe_ggtt_node where this BO is mapped
* @bo: the &xe_bo to be mapped
- * @pat_index: Which pat_index to use.
+ * @pte: The pte flags to append.
*/
-void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node,
- struct xe_bo *bo, u16 pat_index)
+static void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node,
+ struct xe_bo *bo, u64 pte)
{
-
- u64 start, pte, end;
+ u64 start, end;
struct xe_res_cursor cur;
if (XE_WARN_ON(!node))
@@ -605,7 +596,6 @@ void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node,
start = node->base.start;
end = start + xe_bo_size(bo);
- pte = ggtt->pt_ops->pte_encode_flags(bo, pat_index);
if (!xe_bo_is_vram(bo) && !xe_bo_is_stolen(bo)) {
xe_assert(xe_bo_device(bo), bo->ttm.ttm);
@@ -635,12 +625,65 @@ void xe_ggtt_map_bo_unlocked(struct xe_ggtt *ggtt, struct xe_bo *bo)
{
u16 cache_mode = bo->flags & XE_BO_FLAG_NEEDS_UC ? XE_CACHE_NONE : XE_CACHE_WB;
u16 pat_index = tile_to_xe(ggtt->tile)->pat.idx[cache_mode];
+ u64 pte;
mutex_lock(&ggtt->lock);
- xe_ggtt_map_bo(ggtt, bo->ggtt_node[ggtt->tile->id], bo, pat_index);
+ pte = ggtt->pt_ops->pte_encode_flags(bo, pat_index);
+ xe_ggtt_map_bo(ggtt, bo->ggtt_node[ggtt->tile->id], bo, pte);
mutex_unlock(&ggtt->lock);
}
+/**
+ * xe_ggtt_node_insert_transform - Insert a newly allocated &xe_ggtt_node into the GGTT
+ * @ggtt: the &xe_ggtt where the node will inserted/reserved.
+ * @bo: The bo to be transformed
+ * @pte_flags: The extra GGTT flags to add to mapping.
+ * @size: size of the node
+ * @align: required alignment for node
+ * @transform: transformation function that will populate the GGTT node, or NULL for linear mapping.
+ * @arg: Extra argument to pass to the transformation function.
+ *
+ * This function allows inserting a GGTT node with a custom transformation function.
+ * This is useful for display to allow inserting rotated framebuffers to GGTT.
+ *
+ * Return: A pointer to %xe_ggtt_node struct on success. An ERR_PTR otherwise.
+ */
+struct xe_ggtt_node *xe_ggtt_node_insert_transform(struct xe_ggtt *ggtt,
+ struct xe_bo *bo, u64 pte_flags,
+ u64 size, u32 align,
+ xe_ggtt_transform_cb transform, void *arg)
+{
+ struct xe_ggtt_node *node;
+ int ret;
+
+ node = xe_ggtt_node_init(ggtt);
+ if (IS_ERR(node))
+ return ERR_CAST(node);
+
+ if (mutex_lock_interruptible(&ggtt->lock) < 0) {
+ ret = -ERESTARTSYS;
+ goto err;
+ }
+
+ ret = xe_ggtt_node_insert_locked(node, size, align, 0);
+ if (ret)
+ goto err_unlock;
+
+ if (transform)
+ transform(ggtt, node, pte_flags, ggtt->pt_ops->ggtt_set_pte, arg);
+ else
+ xe_ggtt_map_bo(ggtt, node, bo, pte_flags);
+
+ mutex_unlock(&ggtt->lock);
+ return node;
+
+err_unlock:
+ mutex_unlock(&ggtt->lock);
+err:
+ xe_ggtt_node_fini(node);
+ return ERR_PTR(ret);
+}
+
static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
u64 start, u64 end, struct drm_exec *exec)
{
@@ -679,8 +722,9 @@ static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
} else {
u16 cache_mode = bo->flags & XE_BO_FLAG_NEEDS_UC ? XE_CACHE_NONE : XE_CACHE_WB;
u16 pat_index = tile_to_xe(ggtt->tile)->pat.idx[cache_mode];
+ u64 pte = ggtt->pt_ops->pte_encode_flags(bo, pat_index);
- xe_ggtt_map_bo(ggtt, bo->ggtt_node[tile_id], bo, pat_index);
+ xe_ggtt_map_bo(ggtt, bo->ggtt_node[tile_id], bo, pte);
}
mutex_unlock(&ggtt->lock);
diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
index eccef2d2b3cee..fb518696c3280 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.h
+++ b/drivers/gpu/drm/xe/xe_ggtt.h
@@ -24,12 +24,13 @@ u64 xe_ggtt_start(struct xe_ggtt *ggtt);
u64 xe_ggtt_size(struct xe_ggtt *ggtt);
int xe_ggtt_node_insert(struct xe_ggtt_node *node, u32 size, u32 align);
-int xe_ggtt_node_insert_locked(struct xe_ggtt_node *node,
- u32 size, u32 align, u32 mm_flags);
+struct xe_ggtt_node *
+xe_ggtt_node_insert_transform(struct xe_ggtt *ggtt,
+ struct xe_bo *bo, u64 pte,
+ u64 size, u32 align,
+ xe_ggtt_transform_cb transform, void *arg);
void xe_ggtt_node_remove(struct xe_ggtt_node *node, bool invalidate);
bool xe_ggtt_node_allocated(const struct xe_ggtt_node *node);
-void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node,
- struct xe_bo *bo, u16 pat_index);
void xe_ggtt_map_bo_unlocked(struct xe_ggtt *ggtt, struct xe_bo *bo);
int xe_ggtt_insert_bo(struct xe_ggtt *ggtt, struct xe_bo *bo, struct drm_exec *exec);
int xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
diff --git a/drivers/gpu/drm/xe/xe_ggtt_types.h b/drivers/gpu/drm/xe/xe_ggtt_types.h
index a27919302d6b2..f4aa5671cb3e3 100644
--- a/drivers/gpu/drm/xe/xe_ggtt_types.h
+++ b/drivers/gpu/drm/xe/xe_ggtt_types.h
@@ -71,6 +71,11 @@ struct xe_ggtt_node {
bool invalidate_on_remove;
};
+typedef void (*xe_ggtt_set_pte_fn)(struct xe_ggtt *ggtt, u64 addr, u64 pte);
+typedef void (*xe_ggtt_transform_cb)(struct xe_ggtt *ggtt,
+ struct xe_ggtt_node *node,
+ u64 pte_flags,
+ xe_ggtt_set_pte_fn set_pte, void *arg);
/**
* struct xe_ggtt_pt_ops - GGTT Page table operations
* Which can vary from platform to platform.
@@ -78,8 +83,9 @@ struct xe_ggtt_node {
struct xe_ggtt_pt_ops {
/** @pte_encode_flags: Encode PTE flags for a given BO */
u64 (*pte_encode_flags)(struct xe_bo *bo, u16 pat_index);
+
/** @ggtt_set_pte: Directly write into GGTT's PTE */
- void (*ggtt_set_pte)(struct xe_ggtt *ggtt, u64 addr, u64 pte);
+ xe_ggtt_set_pte_fn ggtt_set_pte;
};
#endif
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread* [PATCH v4 6/6] drm/xe: Move struct xe_ggtt to xe_ggtt.c
2025-10-09 13:52 [PATCH v4 0/6] drm/xe: Make struct xe_ggtt private Maarten Lankhorst
` (4 preceding siblings ...)
2025-10-09 13:52 ` [PATCH v4 5/6] drm/xe: Convert xe_fb_pin to use a callback for insertion into GGTT Maarten Lankhorst
@ 2025-10-09 13:52 ` Maarten Lankhorst
5 siblings, 0 replies; 8+ messages in thread
From: Maarten Lankhorst @ 2025-10-09 13:52 UTC (permalink / raw)
To: intel-xe; +Cc: Maarten Lankhorst, Matthew Brost, Maarten Lankhorst
From: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
No users left outside of xe_ggtt.c, so we can make the struct private.
This prevents us from accidentally touching it before init.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Maarten Lankhorst <dev@lankhorst.se>
---
drivers/gpu/drm/xe/xe_ggtt.c | 52 ++++++++++++++++++++++++++++++
drivers/gpu/drm/xe/xe_ggtt_types.h | 51 -----------------------------
2 files changed, 52 insertions(+), 51 deletions(-)
diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
index e6412046a6489..718abe0023b1d 100644
--- a/drivers/gpu/drm/xe/xe_ggtt.c
+++ b/drivers/gpu/drm/xe/xe_ggtt.c
@@ -67,6 +67,58 @@
* give us the correct placement for free.
*/
+/**
+ * struct xe_ggtt_pt_ops - GGTT Page table operations
+ * Which can vary from platform to platform.
+ */
+struct xe_ggtt_pt_ops {
+ /** @pte_encode_flags: Encode PTE flags for a given BO */
+ u64 (*pte_encode_flags)(struct xe_bo *bo, u16 pat_index);
+
+ /** @ggtt_set_pte: Directly write into GGTT's PTE */
+ xe_ggtt_set_pte_fn ggtt_set_pte;
+};
+
+/**
+ * struct xe_ggtt - Main GGTT struct
+ *
+ * In general, each tile can contains its own Global Graphics Translation Table
+ * (GGTT) instance.
+ */
+struct xe_ggtt {
+ /** @tile: Back pointer to tile where this GGTT belongs */
+ struct xe_tile *tile;
+ /** @start: Start offset of GGTT */
+ u64 start;
+ /** @size: Total usable size of this GGTT */
+ u64 size;
+
+#define XE_GGTT_FLAGS_64K BIT(0)
+ /**
+ * @flags: Flags for this GGTT
+ * Acceptable flags:
+ * - %XE_GGTT_FLAGS_64K - if PTE size is 64K. Otherwise, regular is 4K.
+ */
+ unsigned int flags;
+ /** @scratch: Internal object allocation used as a scratch page */
+ struct xe_bo *scratch;
+ /** @lock: Mutex lock to protect GGTT data */
+ struct mutex lock;
+ /**
+ * @gsm: The iomem pointer to the actual location of the translation
+ * table located in the GSM for easy PTE manipulation
+ */
+ u64 __iomem *gsm;
+ /** @pt_ops: Page Table operations per platform */
+ const struct xe_ggtt_pt_ops *pt_ops;
+ /** @mm: The memory manager used to manage individual GGTT allocations */
+ struct drm_mm mm;
+ /** @access_count: counts GGTT writes */
+ unsigned int access_count;
+ /** @wq: Dedicated unordered work queue to process node removals */
+ struct workqueue_struct *wq;
+};
+
static u64 xelp_ggtt_pte_flags(struct xe_bo *bo, u16 pat_index)
{
u64 pte = XE_PAGE_PRESENT;
diff --git a/drivers/gpu/drm/xe/xe_ggtt_types.h b/drivers/gpu/drm/xe/xe_ggtt_types.h
index f4aa5671cb3e3..4f1fd3c456a3b 100644
--- a/drivers/gpu/drm/xe/xe_ggtt_types.h
+++ b/drivers/gpu/drm/xe/xe_ggtt_types.h
@@ -13,46 +13,6 @@
struct xe_bo;
struct xe_gt;
-/**
- * struct xe_ggtt - Main GGTT struct
- *
- * In general, each tile can contains its own Global Graphics Translation Table
- * (GGTT) instance.
- */
-struct xe_ggtt {
- /** @tile: Back pointer to tile where this GGTT belongs */
- struct xe_tile *tile;
- /** @start: Start offset of GGTT */
- u64 start;
- /** @size: Total usable size of this GGTT */
- u64 size;
-
-#define XE_GGTT_FLAGS_64K BIT(0)
- /**
- * @flags: Flags for this GGTT
- * Acceptable flags:
- * - %XE_GGTT_FLAGS_64K - if PTE size is 64K. Otherwise, regular is 4K.
- */
- unsigned int flags;
- /** @scratch: Internal object allocation used as a scratch page */
- struct xe_bo *scratch;
- /** @lock: Mutex lock to protect GGTT data */
- struct mutex lock;
- /**
- * @gsm: The iomem pointer to the actual location of the translation
- * table located in the GSM for easy PTE manipulation
- */
- u64 __iomem *gsm;
- /** @pt_ops: Page Table operations per platform */
- const struct xe_ggtt_pt_ops *pt_ops;
- /** @mm: The memory manager used to manage individual GGTT allocations */
- struct drm_mm mm;
- /** @access_count: counts GGTT writes */
- unsigned int access_count;
- /** @wq: Dedicated unordered work queue to process node removals */
- struct workqueue_struct *wq;
-};
-
/**
* struct xe_ggtt_node - A node in GGTT.
*
@@ -76,16 +36,5 @@ typedef void (*xe_ggtt_transform_cb)(struct xe_ggtt *ggtt,
struct xe_ggtt_node *node,
u64 pte_flags,
xe_ggtt_set_pte_fn set_pte, void *arg);
-/**
- * struct xe_ggtt_pt_ops - GGTT Page table operations
- * Which can vary from platform to platform.
- */
-struct xe_ggtt_pt_ops {
- /** @pte_encode_flags: Encode PTE flags for a given BO */
- u64 (*pte_encode_flags)(struct xe_bo *bo, u16 pat_index);
-
- /** @ggtt_set_pte: Directly write into GGTT's PTE */
- xe_ggtt_set_pte_fn ggtt_set_pte;
-};
#endif
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread