Commit 0e1a47fc authored by Michał Winiarski's avatar Michał Winiarski Committed by Rodrigo Vivi
Browse files

drm/xe: Add a helper for DRM device-lifetime BO create



A helper for managed BO allocations makes it possible to remove specific
"fini" actions and will simplify the following patches adding ability to
execute a release action for specific BO directly.

Signed-off-by: default avatarMichał Winiarski <michal.winiarski@intel.com>
Reviewed-by: default avatarMatthew Brost <matthew.brost@intel.com>
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
parent 791d0362
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@

#include <drm/drm_drv.h>
#include <drm/drm_gem_ttm_helper.h>
#include <drm/drm_managed.h>
#include <drm/ttm/ttm_device.h>
#include <drm/ttm/ttm_placement.h>
#include <drm/ttm/ttm_tt.h>
@@ -1540,6 +1541,41 @@ struct xe_bo *xe_bo_create_from_data(struct xe_device *xe, struct xe_tile *tile,
	return bo;
}

static void __xe_bo_unpin_map_no_vm(struct drm_device *drm, void *arg)
{
	xe_bo_unpin_map_no_vm(arg);
}

struct xe_bo *xe_managed_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
					   size_t size, u32 flags)
{
	struct xe_bo *bo;
	int ret;

	bo = xe_bo_create_pin_map(xe, tile, NULL, size, ttm_bo_type_kernel, flags);
	if (IS_ERR(bo))
		return bo;

	ret = drmm_add_action_or_reset(&xe->drm, __xe_bo_unpin_map_no_vm, bo);
	if (ret)
		return ERR_PTR(ret);

	return bo;
}

struct xe_bo *xe_managed_bo_create_from_data(struct xe_device *xe, struct xe_tile *tile,
					     const void *data, size_t size, u32 flags)
{
	struct xe_bo *bo = xe_managed_bo_create_pin_map(xe, tile, size, flags);

	if (IS_ERR(bo))
		return bo;

	xe_map_memcpy_to(xe, &bo->vmap, 0, data, size);

	return bo;
}

/*
 * XXX: This is in the VM bind data path, likely should calculate this once and
 * store, with a recalculation if the BO is moved.
+4 −0
Original line number Diff line number Diff line
@@ -124,6 +124,10 @@ struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile
struct xe_bo *xe_bo_create_from_data(struct xe_device *xe, struct xe_tile *tile,
				     const void *data, size_t size,
				     enum ttm_bo_type type, u32 flags);
struct xe_bo *xe_managed_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
					   size_t size, u32 flags);
struct xe_bo *xe_managed_bo_create_from_data(struct xe_device *xe, struct xe_tile *tile,
					     const void *data, size_t size, u32 flags);

int xe_bo_placement_for_flags(struct xe_device *xe, struct xe_bo *bo,
			      u32 bo_flags);
+1 −5
Original line number Diff line number Diff line
@@ -108,7 +108,6 @@ static void ggtt_fini(struct drm_device *drm, void *arg)
{
	struct xe_ggtt *ggtt = arg;

	xe_bo_unpin_map_no_vm(ggtt->scratch);
	ggtt->scratch = NULL;
}

@@ -227,10 +226,7 @@ int xe_ggtt_init(struct xe_ggtt *ggtt)
	else
		flags |= XE_BO_CREATE_VRAM_IF_DGFX(ggtt->tile);

	ggtt->scratch = xe_bo_create_pin_map(xe, ggtt->tile, NULL, XE_PAGE_SIZE,
					     ttm_bo_type_kernel,
					     flags);

	ggtt->scratch = xe_managed_bo_create_pin_map(xe, ggtt->tile, XE_PAGE_SIZE, flags);
	if (IS_ERR(ggtt->scratch)) {
		err = PTR_ERR(ggtt->scratch);
		goto err;
+3 −17
Original line number Diff line number Diff line
@@ -202,13 +202,6 @@ static size_t guc_ads_size(struct xe_guc_ads *ads)
		guc_ads_private_data_size(ads);
}

static void guc_ads_fini(struct drm_device *drm, void *arg)
{
	struct xe_guc_ads *ads = arg;

	xe_bo_unpin_map_no_vm(ads->bo);
}

static bool needs_wa_1607983814(struct xe_device *xe)
{
	return GRAPHICS_VERx100(xe) < 1250;
@@ -274,14 +267,11 @@ int xe_guc_ads_init(struct xe_guc_ads *ads)
	struct xe_gt *gt = ads_to_gt(ads);
	struct xe_tile *tile = gt_to_tile(gt);
	struct xe_bo *bo;
	int err;

	ads->golden_lrc_size = calculate_golden_lrc_size(ads);
	ads->regset_size = calculate_regset_size(gt);

	bo = xe_bo_create_pin_map(xe, tile, NULL, guc_ads_size(ads) +
				  MAX_GOLDEN_LRC_SIZE,
				  ttm_bo_type_kernel,
	bo = xe_managed_bo_create_pin_map(xe, tile, guc_ads_size(ads) + MAX_GOLDEN_LRC_SIZE,
					  XE_BO_CREATE_VRAM_IF_DGFX(tile) |
					  XE_BO_CREATE_GGTT_BIT);
	if (IS_ERR(bo))
@@ -289,10 +279,6 @@ int xe_guc_ads_init(struct xe_guc_ads *ads)

	ads->bo = bo;

	err = drmm_add_action_or_reset(&xe->drm, guc_ads_fini, ads);
	if (err)
		return err;

	return 0;
}

+3 −5
Original line number Diff line number Diff line
@@ -114,7 +114,6 @@ static void guc_ct_fini(struct drm_device *drm, void *arg)
	struct xe_guc_ct *ct = arg;

	xa_destroy(&ct->fence_lookup);
	xe_bo_unpin_map_no_vm(ct->bo);
}

static void g2h_worker_func(struct work_struct *w);
@@ -148,8 +147,7 @@ int xe_guc_ct_init(struct xe_guc_ct *ct)

	primelockdep(ct);

	bo = xe_bo_create_pin_map(xe, tile, NULL, guc_ct_size(),
				  ttm_bo_type_kernel,
	bo = xe_managed_bo_create_pin_map(xe, tile, guc_ct_size(),
					  XE_BO_CREATE_VRAM_IF_DGFX(tile) |
					  XE_BO_CREATE_GGTT_BIT);
	if (IS_ERR(bo))
Loading