Skip to content

Commit

Permalink
drm/xe: Make xe_ggtt_node struct independent
Browse files Browse the repository at this point in the history
In some rare cases, the drm_mm node cannot be removed synchronously
due to runtime PM conditions. In this situation, the node removal will
be delegated to a workqueue that will be able to wake up the device
before removing the node.

However, in this situation, the lifetime of the xe_ggtt_node cannot
be restricted to the lifetime of the parent object. So, this patch
introduces the infrastructure so the xe_ggtt_node struct can be
allocated in advance and freed when needed.

By having the ggtt backpointer, it also ensure that the init function
is always called before any attempt to insert or reserve the node
in the GGTT.

v2: s/xe_ggtt_node_force_fini/xe_ggtt_node_fini and use it
    internaly (Brost)
v3: - Use GF_NOFS for node allocation (CI)
    - Avoid ggtt argument, now that we have it inside the node (Lucas)
    - Fix some missed fini cases (CI)
v4: - Fix SRIOV critical case where config->ggtt_region was
      lost (Michal)
    - Avoid ggtt argument also on removal (missed case on v3) (Michal)
    - Remove useless checks (Michal)
    - Return 0 instead of negative errno on a u32 addr. (Michal)
    - s/xe_ggtt_assign/xe_ggtt_node_assign for coherence, while we
      are touching it (Michal)
v5: - Fix VFs' ggtt_balloon

Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240821193842.352557-11-rodrigo.vivi@intel.com
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
  • Loading branch information
rodrigovivi committed Aug 22, 2024
1 parent 15ca094 commit 34e8042
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 104 deletions.
4 changes: 2 additions & 2 deletions drivers/gpu/drm/xe/compat-i915-headers/i915_vma.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct xe_bo;

struct i915_vma {
struct xe_bo *bo, *dpt;
struct xe_ggtt_node node;
struct xe_ggtt_node *node;
};

#define i915_ggtt_clear_scanout(bo) do { } while (0)
Expand All @@ -29,7 +29,7 @@ struct i915_vma {

static inline u32 i915_ggtt_offset(const struct i915_vma *vma)
{
return vma->node.base.start;
return vma->node->base.start;
}

#endif
39 changes: 26 additions & 13 deletions drivers/gpu/drm/xe/display/xe_fb_pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,28 @@ static int __xe_pin_fb_vma_ggtt(const struct intel_framebuffer *fb,
if (xe_bo_is_vram(bo) && ggtt->flags & XE_GGTT_FLAGS_64K)
align = max_t(u32, align, SZ_64K);

if (bo->ggtt_node.base.size && view->type == I915_GTT_VIEW_NORMAL) {
if (bo->ggtt_node && view->type == I915_GTT_VIEW_NORMAL) {
vma->node = bo->ggtt_node;
} else if (view->type == I915_GTT_VIEW_NORMAL) {
u32 x, size = bo->ttm.base.size;

ret = xe_ggtt_node_insert_locked(ggtt, &vma->node, size, align, 0);
if (ret)
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;
}

for (x = 0; x < size; x += XE_PAGE_SIZE) {
u64 pte = ggtt->pt_ops->pte_encode_bo(bo, x,
xe->pat.idx[XE_CACHE_NONE]);

ggtt->pt_ops->ggtt_set_pte(ggtt, vma->node.base.start + x, pte);
ggtt->pt_ops->ggtt_set_pte(ggtt, vma->node->base.start + x, pte);
}
} else {
u32 i, ggtt_ofs;
Expand All @@ -226,11 +234,19 @@ static int __xe_pin_fb_vma_ggtt(const struct intel_framebuffer *fb,
/* display seems to use tiles instead of bytes here, so convert it back.. */
u32 size = intel_rotation_info_size(rot_info) * XE_PAGE_SIZE;

ret = xe_ggtt_node_insert_locked(ggtt, &vma->node, size, align, 0);
if (ret)
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;
}

ggtt_ofs = vma->node.base.start;
ggtt_ofs = vma->node->base.start;

for (i = 0; i < ARRAY_SIZE(rot_info->plane); i++)
write_ggtt_rotated(bo, ggtt, &ggtt_ofs,
Expand Down Expand Up @@ -318,14 +334,11 @@ static struct i915_vma *__xe_pin_fb_vma(const struct intel_framebuffer *fb,

static void __xe_unpin_fb_vma(struct i915_vma *vma)
{
struct xe_device *xe = to_xe_device(vma->bo->ttm.base.dev);
struct xe_ggtt *ggtt = xe_device_get_root_tile(xe)->mem.ggtt;

if (vma->dpt)
xe_bo_unpin_map_no_vm(vma->dpt);
else if (!xe_ggtt_node_allocated(&vma->bo->ggtt_node) ||
vma->bo->ggtt_node.base.start != vma->node.base.start)
xe_ggtt_node_remove(ggtt, &vma->node, false);
else if (!xe_ggtt_node_allocated(vma->bo->ggtt_node) ||
vma->bo->ggtt_node->base.start != vma->node->base.start)
xe_ggtt_node_remove(vma->node, false);

ttm_bo_reserve(&vma->bo->ttm, false, false, NULL);
ttm_bo_unpin(&vma->bo->ttm);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/xe/xe_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ static void xe_ttm_bo_destroy(struct ttm_buffer_object *ttm_bo)

xe_assert(xe, list_empty(&ttm_bo->base.gpuva.list));

if (bo->ggtt_node.base.size)
if (bo->ggtt_node && bo->ggtt_node->base.size)
xe_ggtt_remove_bo(bo->tile->mem.ggtt, bo);

#ifdef CONFIG_PROC_FS
Expand Down
9 changes: 6 additions & 3 deletions drivers/gpu/drm/xe/xe_bo.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@ xe_bo_main_addr(struct xe_bo *bo, size_t page_size)
static inline u32
xe_bo_ggtt_addr(struct xe_bo *bo)
{
XE_WARN_ON(bo->ggtt_node.base.size > bo->size);
XE_WARN_ON(bo->ggtt_node.base.start + bo->ggtt_node.base.size > (1ull << 32));
return bo->ggtt_node.base.start;
if (XE_WARN_ON(!bo->ggtt_node))
return 0;

XE_WARN_ON(bo->ggtt_node->base.size > bo->size);
XE_WARN_ON(bo->ggtt_node->base.start + bo->ggtt_node->base.size > (1ull << 32));
return bo->ggtt_node->base.start;
}

int xe_bo_vmap(struct xe_bo *bo);
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/xe/xe_bo_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct xe_bo {
/** @placement: current placement for this BO */
struct ttm_placement placement;
/** @ggtt_node: GGTT node if this BO is mapped in the GGTT */
struct xe_ggtt_node ggtt_node;
struct xe_ggtt_node *ggtt_node;
/** @vmap: iosys map of this buffer */
struct iosys_map vmap;
/** @ttm_kmap: TTM bo kmap object for internal use only. Keep off. */
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/xe/xe_device_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ struct xe_tile {
struct xe_memirq memirq;

/** @sriov.vf.ggtt_balloon: GGTT regions excluded from use. */
struct xe_ggtt_node ggtt_balloon[2];
struct xe_ggtt_node *ggtt_balloon[2];
} vf;
} sriov;

Expand Down
Loading

0 comments on commit 34e8042

Please sign in to comment.