All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Roper <matthew.d.roper@intel.com>
To: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
Cc: intel-xe@lists.freedesktop.org,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Shuicheng Lin" <shuicheng.lin@intel.com>,
	"Piotr Piórkowski" <piotr.piorkowski@intel.com>
Subject: Re: [PATCH v4 1/2] drm/xe/wopcm: Use the size from HW when excluding the wopcm range from GGTT
Date: Wed, 18 Nov 2026 14:48:55 -0800	[thread overview]
Message-ID: <20261118224855.GG6134@mdroper-desk1> (raw)
In-Reply-To: <20261118220120.109186-3-daniele.ceraolospurio@intel.com>

On Wed, Nov 18, 2026 at 10:01:20PM +0000, Daniele Ceraolo Spurio wrote:
> The WOPCM size is available in HW (we read it during the stolen memory
> init), so when excluding the WOPCM range from the base of GGTT we can
> use the HW value instead of a hardcoded one (which needs to be updated
> any time the config changes on newer HW). This value is not available to
> VFs, but the only use VF has for it is to make sure that the PF has done
> its programming correctly, so we can just trust PF and drop the checks.
> Since the WOPCM is a per-tile value, we can store its size in the tile
> structure and re-use it for both GGTT and stolen memory setup.
> We also have a kunit that uses the wopcm size, but as a static kunit it
> doesn't actually require a real value but just a non-zero one for
> testing, so we can use the already defined GGTT_TEST_START.
> 
> Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com>
> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> Cc: Shuicheng Lin <shuicheng.lin@intel.com>
> Cc: Matt Roper <matthew.d.roper@intel.com>
> Cc: Piotr Piórkowski <piotr.piorkowski@intel.com>
> Reviewed-by: Matt Roper <matthew.d.roper@intel.com> #v2

With the Sashiko feedback addressed, my r-b still stands.

Thanks.


Matt

> ---
> v2: drop wopcm size usage from VF
> v3: move guc_ggtt assert from next patch to this one (Sashiko), rebase
> on SRIOV updates, add kernel-doc for new functions.
> v4: fix kunit
> ---
>  drivers/gpu/drm/xe/tests/xe_ggtt_kunit.c |  4 +-
>  drivers/gpu/drm/xe/xe_device.c           |  4 ++
>  drivers/gpu/drm/xe/xe_ggtt.c             | 19 +++-----
>  drivers/gpu/drm/xe/xe_guc.c              | 11 +++--
>  drivers/gpu/drm/xe/xe_tile.c             | 61 ++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_tile.h             |  3 ++
>  drivers/gpu/drm/xe/xe_tile_types.h       |  3 ++
>  drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c   | 53 +++++++++-----------
>  8 files changed, 107 insertions(+), 51 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/tests/xe_ggtt_kunit.c b/drivers/gpu/drm/xe/tests/xe_ggtt_kunit.c
> index 25471317d781..202b48b0c984 100644
> --- a/drivers/gpu/drm/xe/tests/xe_ggtt_kunit.c
> +++ b/drivers/gpu/drm/xe/tests/xe_ggtt_kunit.c
> @@ -12,9 +12,7 @@
>  
>  static u64 ggtt_test_accessible_size(struct kunit *test)
>  {
> -	struct xe_tile *tile = xe_device_get_root_tile(test->priv);
> -
> -	return GUC_GGTT_TOP - xe_wopcm_size(tile_to_xe(tile));
> +	return GUC_GGTT_TOP - GGTT_TEST_START;
>  }
>  
>  static void ggtt_test_fini(void *data)
> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> index 6911c2ac39f8..93cd91fb620d 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -934,6 +934,10 @@ int xe_device_probe(struct xe_device *xe)
>  	override_has_cached_pt(xe);
>  
>  	for_each_tile(tile, xe, id) {
> +		err = xe_tile_wopcm_init(tile);
> +		if (err)
> +			return err;
> +
>  		err = xe_ggtt_init_early(tile->mem.ggtt);
>  		if (err)
>  			return err;
> diff --git a/drivers/gpu/drm/xe/xe_ggtt.c b/drivers/gpu/drm/xe/xe_ggtt.c
> index 44480fad2767..1bc5b8c0f2b9 100644
> --- a/drivers/gpu/drm/xe/xe_ggtt.c
> +++ b/drivers/gpu/drm/xe/xe_ggtt.c
> @@ -30,11 +30,11 @@
>  #include "xe_pm.h"
>  #include "xe_res_cursor.h"
>  #include "xe_sriov.h"
> +#include "xe_tile.h"
>  #include "xe_tile_printk.h"
>  #include "xe_tile_sriov_vf.h"
>  #include "xe_tlb_inval.h"
>  #include "xe_wa.h"
> -#include "xe_wopcm.h"
>  
>  /**
>   * DOC: Global Graphics Translation Table (GGTT)
> @@ -414,7 +414,7 @@ static int ggtt_probe(struct xe_ggtt *ggtt, u64 *start, u64 *size)
>  		return -ENOMEM;
>  	}
>  
> -	*start = xe_wopcm_size(xe);
> +	*start = xe_tile_wopcm_size(ggtt->tile);
>  	*size = (gsm_size / 8) * (u64)XE_PAGE_SIZE - *start;
>  
>  	return 0;
> @@ -422,13 +422,11 @@ static int ggtt_probe(struct xe_ggtt *ggtt, u64 *start, u64 *size)
>  
>  static int ggtt_get_range_from_guc(struct xe_ggtt *ggtt, u64 *start, u64 *size)
>  {
> -	struct xe_device *xe = tile_to_xe(ggtt->tile);
> -	u64 wopcm = xe_wopcm_size(xe);
> -
>  	*start = xe_tile_sriov_vf_ggtt_base(ggtt->tile);
>  	*size = xe_tile_sriov_vf_ggtt(ggtt->tile);
>  
> -	if (*start < wopcm || *start + *size > GUC_GGTT_TOP) {
> +	/* We can't check start against WOPCM as VF doesn't have access to the WOPCM size */
> +	if (*size > GUC_GGTT_TOP) {
>  		xe_log_err_fatal(ggtt->tile, GGTT, -ERANGE,
>  				 "Invalid GGTT configuration: %#llx-%#llx\n",
>  				 *start, *start + *size - 1);
> @@ -734,11 +732,6 @@ static void xe_ggtt_invalidate_engine(struct xe_ggtt *ggtt)
>  	ggtt_invalidate_gt_engine_tlb(ggtt->tile->media_gt);
>  }
>  
> -static inline u64 xe_ggtt_bottom(struct xe_ggtt *ggtt)
> -{
> -	return xe_wopcm_size(tile_to_xe(ggtt->tile));
> -}
> -
>  /**
>   * xe_ggtt_shift_nodes() - Shift GGTT nodes to adjust for a change in usable address range.
>   * @ggtt: the &xe_ggtt struct instance
> @@ -750,13 +743,13 @@ static inline u64 xe_ggtt_bottom(struct xe_ggtt *ggtt)
>   * This function may be called multiple times during recovery, but if
>   * @new_start is unchanged from the current base, it's a noop.
>   *
> - * @new_start should be a value between the GGTT bottom and #GUC_GGTT_TOP.
> + * @new_start should be a value between the WOPCM size and #GUC_GGTT_TOP. VFs
> + * don't have access to the WOPCM size so we can't test against that.
>   */
>  void xe_ggtt_shift_nodes(struct xe_ggtt *ggtt, u64 new_start)
>  {
>  	guard(mutex)(&ggtt->lock);
>  
> -	xe_tile_assert(ggtt->tile, new_start >= xe_ggtt_bottom(ggtt));
>  	xe_tile_assert(ggtt->tile, new_start + ggtt->size <= GUC_GGTT_TOP);
>  #ifdef CONFIG_PCI_IOV
>  	xe_tile_assert(ggtt->tile, ggtt->shareable_size == 0);
> diff --git a/drivers/gpu/drm/xe/xe_guc.c b/drivers/gpu/drm/xe/xe_guc.c
> index c4fb34e64cd6..e7e818897bf5 100644
> --- a/drivers/gpu/drm/xe/xe_guc.c
> +++ b/drivers/gpu/drm/xe/xe_guc.c
> @@ -47,15 +47,16 @@
>  #include "xe_sleep.h"
>  #include "xe_sriov.h"
>  #include "xe_sriov_pf_migration.h"
> +#include "xe_tile.h"
>  #include "xe_uc.h"
>  #include "xe_uc_fw.h"
>  #include "xe_wa.h"
> -#include "xe_wopcm.h"
>  
>  static u32 guc_bo_ggtt_addr(struct xe_guc *guc,
>  			    struct xe_bo *bo)
>  {
> -	struct xe_device *xe = guc_to_xe(guc);
> +	struct xe_tile *tile = gt_to_tile(guc_to_gt(guc));
> +	struct xe_device *xe = tile_to_xe(tile);
>  	u32 addr;
>  
>  	/*
> @@ -64,10 +65,12 @@ static u32 guc_bo_ggtt_addr(struct xe_guc *guc,
>  	 * might be different for each tile. So, just always ask for the address
>  	 * on the target GuC.
>  	 */
> -	addr = __xe_bo_ggtt_addr(bo, gt_to_tile(guc_to_gt(guc))->id);
> +	addr = __xe_bo_ggtt_addr(bo, tile->id);
> +
> +	if (!IS_SRIOV_VF(xe))
> +		xe_assert(xe, addr >= xe_tile_wopcm_size(tile));
>  
>  	/* GuC addresses above GUC_GGTT_TOP don't map through the GTT */
> -	xe_assert(xe, addr >= xe_wopcm_size(guc_to_xe(guc)));
>  	xe_assert(xe, addr < GUC_GGTT_TOP);
>  	xe_assert(xe, xe_bo_size(bo) <= GUC_GGTT_TOP - addr);
>  
> diff --git a/drivers/gpu/drm/xe/xe_tile.c b/drivers/gpu/drm/xe/xe_tile.c
> index 810dfd98d830..014b5efdb152 100644
> --- a/drivers/gpu/drm/xe/xe_tile.c
> +++ b/drivers/gpu/drm/xe/xe_tile.c
> @@ -13,15 +13,18 @@
>  #include "xe_ggtt.h"
>  #include "xe_memirq.h"
>  #include "xe_migrate.h"
> +#include "xe_mmio.h"
>  #include "xe_pcode.h"
>  #include "xe_sa.h"
>  #include "xe_svm.h"
>  #include "xe_tile.h"
> +#include "xe_tile_printk.h"
>  #include "xe_tile_sysfs.h"
>  #include "xe_ttm_vram_mgr.h"
>  #include "xe_vram.h"
>  #include "xe_vram_types.h"
>  #include "xe_wa.h"
> +#include "regs/xe_regs.h"
>  
>  /**
>   * DOC: Multi-tile Design
> @@ -225,6 +228,64 @@ void xe_tile_migrate_wait(struct xe_tile *tile)
>  	xe_migrate_wait(tile->migrate);
>  }
>  
> +/**
> + * xe_tile_wopcm_init() - cache the WOPCM size for the tile.
> + * @tile: The tile for which to cache the WOPCM size.
> + *
> + * This function reads the WOPCM size from the hardware and caches it in the tile
> + * structure. It does not perform any memory allocations. The cached value can
> + * be retrieved later using xe_tile_wopcm_size().
> + * This function can't be called on VFs since VFs don't have access to the
> + * register holding the WOPCM size.
> + *
> + * Returns: 0 on success, negative error code on error.
> + */
> +int xe_tile_wopcm_init(struct xe_tile *tile)
> +{
> +	u32 wopcm_size;
> +	u64 val;
> +
> +	if (IS_SRIOV_VF(tile_to_xe(tile)))
> +		return 0;
> +
> +	val = xe_mmio_read64_2x32(&tile->mmio, STOLEN_RESERVED);
> +	val = REG_FIELD_GET64(WOPCM_SIZE_MASK, val);
> +
> +	switch (val) {
> +	case 0x5 ... 0x6:
> +		val--;
> +		fallthrough;
> +	case 0x0 ... 0x3:
> +		wopcm_size = (1U << val) * SZ_1M;
> +		break;
> +	default:
> +		WARN(1, "Missing case wopcm_size=%llx\n", val);
> +		return -EIO;
> +	}
> +
> +	tile->mem.wopcm_size = wopcm_size;
> +
> +	xe_tile_info(tile, "WOPCM size: %uKB\n", wopcm_size / 1024);
> +	return 0;
> +}
> +
> +/**
> + * xe_tile_wopcm_size() - get the WOPCM size for the tile.
> + * @tile: The tile for which to get the WOPCM size.
> + *
> + * This function returns the cached WOPCM size for the tile. This function must
> + * be called after xe_tile_wopcm_init() has been called for the tile.
> + * This function can't be called on VFs since VFs don't have access to the
> + * register holding the WOPCM size.
> + *
> + * Returns: The cached WOPCM size in bytes.
> + */
> +u32 xe_tile_wopcm_size(struct xe_tile *tile)
> +{
> +	xe_assert(tile_to_xe(tile), tile->mem.wopcm_size != 0);
> +	return tile->mem.wopcm_size;
> +}
> +
>  #if IS_ENABLED(CONFIG_DRM_XE_PAGEMAP)
>  /**
>   * xe_tile_local_pagemap() - Return a pointer to the tile's local drm_pagemap if any
> diff --git a/drivers/gpu/drm/xe/xe_tile.h b/drivers/gpu/drm/xe/xe_tile.h
> index a2a2c0e936b8..5ae9f6753f96 100644
> --- a/drivers/gpu/drm/xe/xe_tile.h
> +++ b/drivers/gpu/drm/xe/xe_tile.h
> @@ -19,6 +19,9 @@ int xe_tile_alloc_vram(struct xe_tile *tile);
>  
>  void xe_tile_migrate_wait(struct xe_tile *tile);
>  
> +int xe_tile_wopcm_init(struct xe_tile *tile);
> +u32 xe_tile_wopcm_size(struct xe_tile *tile);
> +
>  static inline bool xe_tile_is_root(struct xe_tile *tile)
>  {
>  	return tile->id == 0;
> diff --git a/drivers/gpu/drm/xe/xe_tile_types.h b/drivers/gpu/drm/xe/xe_tile_types.h
> index 3dc011f111a4..dea17282501c 100644
> --- a/drivers/gpu/drm/xe/xe_tile_types.h
> +++ b/drivers/gpu/drm/xe/xe_tile_types.h
> @@ -84,6 +84,9 @@ struct xe_tile {
>  		/** @mem.ggtt: Global graphics translation table */
>  		struct xe_ggtt *ggtt;
>  
> +		/** @mem.wopcm_size: Size of the WOPCM for this tile */
> +		u32 wopcm_size;
> +
>  		/**
>  		 * @mem.kernel_bb_pool: Pool from which batchbuffers are allocated.
>  		 *
> diff --git a/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c b/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c
> index 60f39efb02d0..5983b6c0ac3f 100644
> --- a/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c
> +++ b/drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c
> @@ -20,6 +20,7 @@
>  #include "xe_gt_printk.h"
>  #include "xe_mmio.h"
>  #include "xe_sriov.h"
> +#include "xe_tile.h"
>  #include "xe_ttm_stolen_mgr.h"
>  #include "xe_vram.h"
>  #include "xe_wa.h"
> @@ -38,34 +39,12 @@ bool xe_ttm_stolen_cpu_access_needs_ggtt(struct xe_device *xe)
>  	return GRAPHICS_VERx100(xe) < 1270 && !IS_DGFX(xe);
>  }
>  
> -static u32 get_wopcm_size(struct xe_device *xe)
> -{
> -	u32 wopcm_size;
> -	u64 val;
> -
> -	val = xe_mmio_read64_2x32(xe_root_tile_mmio(xe), STOLEN_RESERVED);
> -	val = REG_FIELD_GET64(WOPCM_SIZE_MASK, val);
> -
> -	switch (val) {
> -	case 0x5 ... 0x6:
> -		val--;
> -		fallthrough;
> -	case 0x0 ... 0x3:
> -		wopcm_size = (1U << val) * SZ_1M;
> -		break;
> -	default:
> -		WARN(1, "Missing case wopcm_size=%llx\n", val);
> -		wopcm_size = 0;
> -	}
> -
> -	return wopcm_size;
> -}
> -
>  static u64 detect_lmembar_dgfx(struct xe_device *xe, struct xe_ttm_stolen_mgr *mgr)
>  {
> -	struct xe_vram_region *tile_vram = xe_device_get_root_tile(xe)->mem.vram;
> +	struct xe_tile *root_tile = xe_device_get_root_tile(xe);
> +	struct xe_vram_region *tile_vram = root_tile->mem.vram;
>  	resource_size_t tile_io_start = xe_vram_region_io_start(tile_vram);
> -	struct xe_mmio *mmio = xe_root_tile_mmio(xe);
> +	struct xe_mmio *mmio = &root_tile->mmio;
>  	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
>  	u64 stolen_size, wopcm_size;
>  	u64 tile_offset;
> @@ -79,8 +58,14 @@ static u64 detect_lmembar_dgfx(struct xe_device *xe, struct xe_ttm_stolen_mgr *m
>  	if (drm_WARN_ON(&xe->drm, tile_size < mgr->stolen_base))
>  		return 0;
>  
> -	/* Carve out the top of DSM as it contains the reserved WOPCM region */
> -	wopcm_size = get_wopcm_size(xe);
> +	/*
> +	 * Carve out the top of DSM as it contains the reserved WOPCM region.
> +	 * Note that the WOPCM region is per-tile, but the code below only looks
> +	 * at the root tile values for both stolen and WOPCM; this works because
> +	 * on PVC there is no driver-usable stolen, so stolen_size is 0 for
> +	 * both tiles, but if that changes we'll need to rework this.
> +	 */
> +	wopcm_size = xe_tile_wopcm_size(root_tile);
>  	if (drm_WARN_ON(&xe->drm, !wopcm_size))
>  		return 0;
>  
> @@ -105,11 +90,12 @@ static u64 detect_lmembar_dgfx(struct xe_device *xe, struct xe_ttm_stolen_mgr *m
>  static u32 detect_lmembar_integrated(struct xe_device *xe, struct xe_ttm_stolen_mgr *mgr)
>  {
>  	struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
> -	struct xe_gt *media_gt = xe_device_get_root_tile(xe)->media_gt;
> +	struct xe_tile *root_tile = xe_device_get_root_tile(xe);
> +	struct xe_gt *media_gt = root_tile->media_gt;
>  	u32 stolen_size, wopcm_size;
>  	u32 ggc, gms;
>  
> -	ggc = xe_mmio_read32(xe_root_tile_mmio(xe), GGC);
> +	ggc = xe_mmio_read32(&root_tile->mmio, GGC);
>  
>  	/*
>  	 * Check GGMS: it should be fixed 0x3 (8MB), which corresponds to the
> @@ -141,8 +127,13 @@ static u32 detect_lmembar_integrated(struct xe_device *xe, struct xe_ttm_stolen_
>  		return 0;
>  	}
>  
> -	/* Carve out the top of DSM as it contains the reserved WOPCM region */
> -	wopcm_size = get_wopcm_size(xe);
> +	/*
> +	 * Carve out the top of DSM as it contains the reserved WOPCM region. We
> +	 * assume only the root tile is present, so we don't need to worry about
> +	 * the WOPCM size for the remote tiles.
> +	 */
> +	xe_assert(xe, xe->info.tile_count == 1);
> +	wopcm_size = xe_tile_wopcm_size(root_tile);
>  	if (drm_WARN_ON(&xe->drm, !wopcm_size))
>  		return 0;
>  
> -- 
> 2.53.0
> 

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

  parent reply	other threads:[~2026-11-18 22:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 22:01 [PATCH v4 1/2] drm/xe/wopcm: Use the size from HW when excluding the wopcm range from GGTT Daniele Ceraolo Spurio
2026-11-18 22:01 ` [PATCH v4 2/2] drm/xe/wopcm: Simplify GuC WOPCM programming Daniele Ceraolo Spurio
2026-11-18 22:10 ` [PATCH v4 1/2] drm/xe/wopcm: Use the size from HW when excluding the wopcm range from GGTT sashiko-bot
2026-11-18 22:48 ` Matt Roper [this message]
2026-11-19  3:10 ` ✗ CI.checkpatch: warning for series starting with [v4,1/2] " Patchwork
2026-11-19  3:12 ` ✓ CI.KUnit: success " Patchwork
2026-11-19  3:54 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-20  4:20 ` ✗ Xe.CI.FULL: failure " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118224855.GG6134@mdroper-desk1 \
    --to=matthew.d.roper@intel.com \
    --cc=daniele.ceraolospurio@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=piotr.piorkowski@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=shuicheng.lin@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.