Skip to content

Commit 16ba2b2

Browse files
committed
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: Michal Wajdeczko <[email protected]> Reviewed-by: Piotr Piórkowski <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 02a416a commit 16ba2b2

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "xe_guc_submit.h"
3030
#include "xe_lmtt.h"
3131
#include "xe_map.h"
32+
#include "xe_migrate.h"
3233
#include "xe_sriov.h"
3334
#include "xe_ttm_vram_mgr.h"
3435
#include "xe_wopcm.h"
@@ -1881,6 +1882,87 @@ int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool forc
18811882
return force ? 0 : err;
18821883
}
18831884

1885+
static void pf_sanitize_ggtt(struct xe_ggtt_node *ggtt_region, unsigned int vfid)
1886+
{
1887+
if (xe_ggtt_node_allocated(ggtt_region))
1888+
xe_ggtt_assign(ggtt_region, vfid);
1889+
}
1890+
1891+
static int pf_sanitize_lmem(struct xe_tile *tile, struct xe_bo *bo, long timeout)
1892+
{
1893+
struct xe_migrate *m = tile->migrate;
1894+
struct dma_fence *fence;
1895+
int err;
1896+
1897+
if (!bo)
1898+
return 0;
1899+
1900+
xe_bo_lock(bo, false);
1901+
fence = xe_migrate_clear(m, bo, bo->ttm.resource, XE_MIGRATE_CLEAR_FLAG_FULL);
1902+
if (IS_ERR(fence)) {
1903+
err = PTR_ERR(fence);
1904+
} else if (!fence) {
1905+
err = -ENOMEM;
1906+
} else {
1907+
long ret = dma_fence_wait_timeout(fence, false, timeout);
1908+
1909+
err = ret > 0 ? 0 : ret < 0 ? ret : -ETIMEDOUT;
1910+
dma_fence_put(fence);
1911+
if (!err)
1912+
xe_gt_sriov_dbg_verbose(tile->primary_gt, "LMEM cleared in %dms\n",
1913+
jiffies_to_msecs(timeout - ret));
1914+
}
1915+
xe_bo_unlock(bo);
1916+
1917+
return err;
1918+
}
1919+
1920+
static int pf_sanitize_vf_resources(struct xe_gt *gt, u32 vfid, long timeout)
1921+
{
1922+
struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
1923+
struct xe_tile *tile = gt_to_tile(gt);
1924+
struct xe_device *xe = gt_to_xe(gt);
1925+
int err = 0;
1926+
1927+
/*
1928+
* Only GGTT and LMEM requires to be cleared by the PF.
1929+
* GuC doorbell IDs and context IDs do not need any clearing.
1930+
*/
1931+
if (!xe_gt_is_media_type(gt)) {
1932+
pf_sanitize_ggtt(config->ggtt_region, vfid);
1933+
if (IS_DGFX(xe))
1934+
err = pf_sanitize_lmem(tile, config->lmem_obj, timeout);
1935+
}
1936+
1937+
return err;
1938+
}
1939+
1940+
/**
1941+
* xe_gt_sriov_pf_config_sanitize() - Sanitize VF's resources.
1942+
* @gt: the &xe_gt
1943+
* @vfid: the VF identifier (can't be PF)
1944+
* @timeout: maximum timeout to wait for completion in jiffies
1945+
*
1946+
* This function can only be called on PF.
1947+
*
1948+
* Return: 0 on success or a negative error code on failure.
1949+
*/
1950+
int xe_gt_sriov_pf_config_sanitize(struct xe_gt *gt, unsigned int vfid, long timeout)
1951+
{
1952+
int err;
1953+
1954+
xe_gt_assert(gt, vfid != PFID);
1955+
1956+
mutex_lock(xe_gt_sriov_pf_master_mutex(gt));
1957+
err = pf_sanitize_vf_resources(gt, vfid, timeout);
1958+
mutex_unlock(xe_gt_sriov_pf_master_mutex(gt));
1959+
1960+
if (unlikely(err))
1961+
xe_gt_sriov_notice(gt, "VF%u resource sanitizing failed (%pe)\n",
1962+
vfid, ERR_PTR(err));
1963+
return err;
1964+
}
1965+
18841966
/**
18851967
* xe_gt_sriov_pf_config_push - Reprovision VF's configuration.
18861968
* @gt: the &xe_gt

drivers/gpu/drm/xe/xe_gt_sriov_pf_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int xe_gt_sriov_pf_config_set_threshold(struct xe_gt *gt, unsigned int vfid,
5050
enum xe_guc_klv_threshold_index index, u32 value);
5151

5252
int xe_gt_sriov_pf_config_set_fair(struct xe_gt *gt, unsigned int vfid, unsigned int num_vfs);
53+
int xe_gt_sriov_pf_config_sanitize(struct xe_gt *gt, unsigned int vfid, long timeout);
5354
int xe_gt_sriov_pf_config_release(struct xe_gt *gt, unsigned int vfid, bool force);
5455
int xe_gt_sriov_pf_config_push(struct xe_gt *gt, unsigned int vfid, bool refresh);
5556

0 commit comments

Comments
 (0)