Commit 16ba2b28 authored by Michal Wajdeczko's avatar Michal Wajdeczko

drm/xe/pf: Add function to sanitize VF resources

On current platforms it is a PF driver responsibility to clear
some of the VF's resources during a VF FLR. Add simple function
that will clear configured VF resources (GGTT, LMEM). We will
start using this function soon.
Signed-off-by: default avatarMichal Wajdeczko <michal.wajdeczko@intel.com>
Reviewed-by: default avatarPiotr Piórkowski <piotr.piorkowski@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240828210809.1528-2-michal.wajdeczko@intel.com
parent 02a416af
......@@ -29,6 +29,7 @@
#include "xe_guc_submit.h"
#include "xe_lmtt.h"
#include "xe_map.h"
#include "xe_migrate.h"
#include "xe_sriov.h"
#include "xe_ttm_vram_mgr.h"
#include "xe_wopcm.h"
......@@ -1881,6 +1882,87 @@ int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool forc
return force ? 0 : err;
}
static void pf_sanitize_ggtt(struct xe_ggtt_node *ggtt_region, unsigned int vfid)
{
if (xe_ggtt_node_allocated(ggtt_region))
xe_ggtt_assign(ggtt_region, vfid);
}
static int pf_sanitize_lmem(struct xe_tile *tile, struct xe_bo *bo, long timeout)
{
struct xe_migrate *m = tile->migrate;
struct dma_fence *fence;
int err;
if (!bo)
return 0;
xe_bo_lock(bo, false);
fence = xe_migrate_clear(m, bo, bo->ttm.resource, XE_MIGRATE_CLEAR_FLAG_FULL);
if (IS_ERR(fence)) {
err = PTR_ERR(fence);
} else if (!fence) {
err = -ENOMEM;
} else {
long ret = dma_fence_wait_timeout(fence, false, timeout);
err = ret > 0 ? 0 : ret < 0 ? ret : -ETIMEDOUT;
dma_fence_put(fence);
if (!err)
xe_gt_sriov_dbg_verbose(tile->primary_gt, "LMEM cleared in %dms\n",
jiffies_to_msecs(timeout - ret));
}
xe_bo_unlock(bo);
return err;
}
static int pf_sanitize_vf_resources(struct xe_gt *gt, u32 vfid, long timeout)
{
struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
struct xe_tile *tile = gt_to_tile(gt);
struct xe_device *xe = gt_to_xe(gt);
int err = 0;
/*
* Only GGTT and LMEM requires to be cleared by the PF.
* GuC doorbell IDs and context IDs do not need any clearing.
*/
if (!xe_gt_is_media_type(gt)) {
pf_sanitize_ggtt(config->ggtt_region, vfid);
if (IS_DGFX(xe))
err = pf_sanitize_lmem(tile, config->lmem_obj, timeout);
}
return err;
}
/**
* xe_gt_sriov_pf_config_sanitize() - Sanitize VF's resources.
* @gt: the &xe_gt
* @vfid: the VF identifier (can't be PF)
* @timeout: maximum timeout to wait for completion in jiffies
*
* This function can only be called on PF.
*
* Return: 0 on success or a negative error code on failure.
*/
int xe_gt_sriov_pf_config_sanitize(struct xe_gt *gt, unsigned int vfid, long timeout)
{
int err;
xe_gt_assert(gt, vfid != PFID);
mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
err = pf_sanitize_vf_resources(gt, vfid, timeout);
mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
if (unlikely(err))
xe_gt_sriov_notice(gt, "VF%u resource sanitizing failed (%pe)\n",
vfid, ERR_PTR(err));
return err;
}
/**
* xe_gt_sriov_pf_config_push - Reprovision VF's configuration.
* @gt: the &xe_gt
......
......@@ -50,6 +50,7 @@ int xe_gt_sriov_pf_config_set_threshold(struct xe_gt *gt, unsigned int vfid,
enum xe_guc_klv_threshold_index index, u32 value);
int xe_gt_sriov_pf_config_set_fair(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs);
int xe_gt_sriov_pf_config_sanitize(struct xe_gt *gt, unsigned int vfid, long timeout);
int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool force);
int xe_gt_sriov_pf_config_push(struct xe_gt *gt, unsigned int vfid, bool refresh);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment