[Intel-xe] [PATCH v3 13/20] drm/xe: Reorder GGTT init to earlier point in probe

Matt Roper matthew.d.roper at intel.com
Wed Nov 15 22:19:16 UTC 2023


On Tue, Nov 14, 2023 at 02:02:24PM +0100, Michał Winiarski wrote:
> GuC will need to be loaded earlier during probe. Having functional GGTT
> is one of the prerequisites.
> Also rename xe_ggtt_init_noalloc to xe_ggtt_init_early to match the new
> call site.
> 
> Signed-off-by: Michał Winiarski <michal.winiarski at intel.com>

Reviewed-by: Matt Roper <matthew.d.roper at intel.com>

> ---
>  drivers/gpu/drm/xe/xe_device.c |  7 +++++++
>  drivers/gpu/drm/xe/xe_ggtt.c   | 20 ++++++++++++++++----
>  drivers/gpu/drm/xe/xe_ggtt.h   |  2 +-
>  drivers/gpu/drm/xe/xe_tile.c   |  4 ----
>  4 files changed, 24 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> index fde597fe0b513..531aca74e8eb4 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -24,6 +24,7 @@
>  #include "xe_drv.h"
>  #include "xe_exec_queue.h"
>  #include "xe_exec.h"
> +#include "xe_ggtt.h"
>  #include "xe_gt.h"
>  #include "xe_irq.h"
>  #include "xe_mmio.h"
> @@ -407,6 +408,12 @@ int xe_device_probe(struct xe_device *xe)
>  	for_each_gt(gt, xe, id)
>  		xe_force_wake_init_gt(gt, gt_to_fw(gt));
>  
> +	for_each_tile(tile, xe, id) {
> +		err = xe_ggtt_init_early(tile->mem.ggtt);
> +		if (err)
> +			return err;
> +	}
> +
>  	err = drmm_add_action_or_reset(&xe->drm, xe_driver_flr_fini, xe);
>  	if (err)
>  		return err;
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
> index 0e2a41837f169..fab3cc04882da 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.c
> +++ b/drivers/gpu/drm/xe/xe_ggtt.c
> @@ -96,14 +96,20 @@ static void xe_ggtt_clear(struct xe_ggtt *ggtt, u64 start, u64 size)
>  	}
>  }
>  
> -static void ggtt_fini_noalloc(struct drm_device *drm, void *arg)
> +static void ggtt_fini_early(struct drm_device *drm, void *arg)
>  {
>  	struct xe_ggtt *ggtt = arg;
>  
>  	mutex_destroy(&ggtt->lock);
>  	drm_mm_takedown(&ggtt->mm);
> +}
> +
> +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;
>  }
>  
>  static void primelockdep(struct xe_ggtt *ggtt)
> @@ -124,7 +130,12 @@ static const struct xe_ggtt_pt_ops xelpg_pt_ops = {
>  	.pte_encode_bo = xelpg_ggtt_pte_encode_bo,
>  };
>  
> -int xe_ggtt_init_noalloc(struct xe_ggtt *ggtt)
> +/*
> + * Early GGTT initialization, which allows to create new mappings usable by the GuC.
> + * Mappings are not usable by the HW engines, as it doesn't have scratch / initial clear done to it
> + * yet. That will happen in the regular, non-early GGTT init.
> + */
> +int xe_ggtt_init_early(struct xe_ggtt *ggtt)
>  {
>  	struct xe_device *xe = tile_to_xe(ggtt->tile);
>  	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
> @@ -178,7 +189,7 @@ int xe_ggtt_init_noalloc(struct xe_ggtt *ggtt)
>  	mutex_init(&ggtt->lock);
>  	primelockdep(ggtt);
>  
> -	return drmm_add_action_or_reset(&xe->drm, ggtt_fini_noalloc, ggtt);
> +	return drmm_add_action_or_reset(&xe->drm, ggtt_fini_early, ggtt);
>  }
>  
>  static void xe_ggtt_initial_clear(struct xe_ggtt *ggtt)
> @@ -226,7 +237,8 @@ int xe_ggtt_init(struct xe_ggtt *ggtt)
>  	xe_map_memset(xe, &ggtt->scratch->vmap, 0, 0, ggtt->scratch->size);
>  
>  	xe_ggtt_initial_clear(ggtt);
> -	return 0;
> +
> +	return drmm_add_action_or_reset(&xe->drm, ggtt_fini, ggtt);
>  err:
>  	ggtt->scratch = NULL;
>  	return err;
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.h b/drivers/gpu/drm/xe/xe_ggtt.h
> index 3faa3c6d0375f..a09c166dff701 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.h
> +++ b/drivers/gpu/drm/xe/xe_ggtt.h
> @@ -12,7 +12,7 @@ struct drm_printer;
>  
>  void xe_ggtt_set_pte(struct xe_ggtt *ggtt, u64 addr, u64 pte);
>  void xe_ggtt_invalidate(struct xe_ggtt *ggtt);
> -int xe_ggtt_init_noalloc(struct xe_ggtt *ggtt);
> +int xe_ggtt_init_early(struct xe_ggtt *ggtt);
>  int xe_ggtt_init(struct xe_ggtt *ggtt);
>  void xe_ggtt_printk(struct xe_ggtt *ggtt, const char *prefix);
>  
> diff --git a/drivers/gpu/drm/xe/xe_tile.c b/drivers/gpu/drm/xe/xe_tile.c
> index daf1ac39dcbb1..731869e49b016 100644
> --- a/drivers/gpu/drm/xe/xe_tile.c
> +++ b/drivers/gpu/drm/xe/xe_tile.c
> @@ -166,10 +166,6 @@ int xe_tile_init_noalloc(struct xe_tile *tile)
>  	if (err)
>  		goto err_mem_access;
>  
> -	err = xe_ggtt_init_noalloc(tile->mem.ggtt);
> -	if (err)
> -		goto err_mem_access;
> -
>  	tile->mem.kernel_bb_pool = xe_sa_bo_manager_init(tile, SZ_1M, 16);
>  	if (IS_ERR(tile->mem.kernel_bb_pool))
>  		err = PTR_ERR(tile->mem.kernel_bb_pool);
> -- 
> 2.42.1
> 

-- 
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation


More information about the Intel-xe mailing list