[PATCH v2 09/11] drm/xe/pf: Use GuC Buffer Cache during VFs provisioning
Matthew Brost
matthew.brost at intel.com
Fri Dec 20 21:23:47 UTC 2024
On Fri, Dec 20, 2024 at 08:42:02PM +0100, Michal Wajdeczko wrote:
> Start using GuC buffer cache for the VF's configuration actions.
>
> Signed-off-by: Michal Wajdeczko <michal.wajdeczko at intel.com>
Reviewed-by: Matthew Brost <matthew.brost at intel.com>
> ---
> v2: rebased (Michal)
> v3: make sure to call xe_guc_buf_flush() (Michal)
> ---
> drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 68 +++++++++++-----------
> 1 file changed, 35 insertions(+), 33 deletions(-)
>
> 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 bd621df3ab91..c5c0879d1d9a 100644
> --- a/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> +++ b/drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c
> @@ -20,6 +20,7 @@
> #include "xe_gt_sriov_pf_policy.h"
> #include "xe_gt_sriov_printk.h"
> #include "xe_guc.h"
> +#include "xe_guc_buf.h"
> #include "xe_guc_ct.h"
> #include "xe_guc_db_mgr.h"
> #include "xe_guc_fwif.h"
> @@ -71,48 +72,27 @@ static int pf_send_vf_cfg_reset(struct xe_gt *gt, u32 vfid)
> * Return: number of KLVs that were successfully parsed and saved,
> * negative error code on failure.
> */
> -static int pf_send_vf_cfg_klvs(struct xe_gt *gt, u32 vfid, const u32 *klvs, u32 num_dwords)
> +static int pf_send_vf_buf_klvs(struct xe_gt *gt, u32 vfid, struct xe_guc_buf buf, u32 num_dwords)
> {
> - const u32 bytes = num_dwords * sizeof(u32);
> - struct xe_tile *tile = gt_to_tile(gt);
> - struct xe_device *xe = tile_to_xe(tile);
> struct xe_guc *guc = >->uc.guc;
> - struct xe_bo *bo;
> - int ret;
>
> - bo = xe_bo_create_pin_map(xe, tile, NULL,
> - ALIGN(bytes, PAGE_SIZE),
> - ttm_bo_type_kernel,
> - XE_BO_FLAG_VRAM_IF_DGFX(tile) |
> - XE_BO_FLAG_GGTT |
> - XE_BO_FLAG_GGTT_INVALIDATE);
> - if (IS_ERR(bo))
> - return PTR_ERR(bo);
> -
> - xe_map_memcpy_to(xe, &bo->vmap, 0, klvs, bytes);
> -
> - ret = guc_action_update_vf_cfg(guc, vfid, xe_bo_ggtt_addr(bo), num_dwords);
> -
> - xe_bo_unpin_map_no_vm(bo);
> -
> - return ret;
> + return guc_action_update_vf_cfg(guc, vfid, xe_guc_buf_flush(buf), num_dwords);
> }
>
> /*
> * Return: 0 on success, -ENOKEY if some KLVs were not updated, -EPROTO if reply was malformed,
> * negative error code on failure.
> */
> -static int pf_push_vf_cfg_klvs(struct xe_gt *gt, unsigned int vfid, u32 num_klvs,
> - const u32 *klvs, u32 num_dwords)
> +static int pf_push_vf_buf_klvs(struct xe_gt *gt, unsigned int vfid, u32 num_klvs,
> + struct xe_guc_buf buf, u32 num_dwords)
> {
> int ret;
>
> - xe_gt_assert(gt, num_klvs == xe_guc_klv_count(klvs, num_dwords));
> -
> - ret = pf_send_vf_cfg_klvs(gt, vfid, klvs, num_dwords);
> + ret = pf_send_vf_buf_klvs(gt, vfid, buf, num_dwords);
>
> if (ret != num_klvs) {
> int err = ret < 0 ? ret : ret < num_klvs ? -ENOKEY : -EPROTO;
> + void *klvs = xe_guc_buf_cpu_ptr(buf);
> struct drm_printer p = xe_gt_info_printer(gt);
> char name[8];
>
> @@ -125,13 +105,35 @@ static int pf_push_vf_cfg_klvs(struct xe_gt *gt, unsigned int vfid, u32 num_klvs
>
> if (IS_ENABLED(CONFIG_DRM_XE_DEBUG_SRIOV)) {
> struct drm_printer p = xe_gt_info_printer(gt);
> + void *klvs = xe_guc_buf_cpu_ptr(buf);
> + char name[8];
>
> + xe_gt_sriov_info(gt, "pushed %s config with %u KLV%s:\n",
> + xe_sriov_function_name(vfid, name, sizeof(name)),
> + num_klvs, str_plural(num_klvs));
> xe_guc_klv_print(klvs, num_dwords, &p);
> }
>
> return 0;
> }
>
> +/*
> + * Return: 0 on success, -ENOBUFS if no free buffer for the indirect data,
> + * negative error code on failure.
> + */
> +static int pf_push_vf_cfg_klvs(struct xe_gt *gt, unsigned int vfid, u32 num_klvs,
> + const u32 *klvs, u32 num_dwords)
> +{
> + CLASS(xe_guc_buf_from_data, buf)(>->uc.guc.buf, klvs, num_dwords * sizeof(u32));
> +
> + xe_gt_assert(gt, num_klvs == xe_guc_klv_count(klvs, num_dwords));
> +
> + if (!xe_guc_buf_is_valid(buf))
> + return -ENOBUFS;
> +
> + return pf_push_vf_buf_klvs(gt, vfid, num_klvs, buf, num_dwords);
> +}
> +
> static int pf_push_vf_cfg_u32(struct xe_gt *gt, unsigned int vfid, u16 key, u32 value)
> {
> u32 klv[] = {
> @@ -304,16 +306,17 @@ static u32 encode_config(u32 *cfg, const struct xe_gt_sriov_config *config, bool
> static int pf_push_full_vf_config(struct xe_gt *gt, unsigned int vfid)
> {
> struct xe_gt_sriov_config *config = pf_pick_vf_config(gt, vfid);
> - u32 max_cfg_dwords = SZ_4K / sizeof(u32);
> + u32 max_cfg_dwords = xe_guc_buf_cache_dwords(>->uc.guc.buf);
> + CLASS(xe_guc_buf, buf)(>->uc.guc.buf, max_cfg_dwords);
> u32 num_dwords;
> int num_klvs;
> u32 *cfg;
> int err;
>
> - cfg = kcalloc(max_cfg_dwords, sizeof(u32), GFP_KERNEL);
> - if (!cfg)
> - return -ENOMEM;
> + if (!xe_guc_buf_is_valid(buf))
> + return -ENOBUFS;
>
> + cfg = xe_guc_buf_cpu_ptr(buf);
> num_dwords = encode_config(cfg, config, true);
> xe_gt_assert(gt, num_dwords <= max_cfg_dwords);
>
> @@ -330,9 +333,8 @@ static int pf_push_full_vf_config(struct xe_gt *gt, unsigned int vfid)
> xe_gt_assert(gt, num_dwords <= max_cfg_dwords);
>
> num_klvs = xe_guc_klv_count(cfg, num_dwords);
> - err = pf_push_vf_cfg_klvs(gt, vfid, num_klvs, cfg, num_dwords);
> + err = pf_push_vf_buf_klvs(gt, vfid, num_klvs, buf, num_dwords);
>
> - kfree(cfg);
> return err;
> }
>
> --
> 2.47.1
>
More information about the Intel-xe
mailing list