Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Levi, Ilia" <ilia.levi@intel.com>
To: Michal Wajdeczko <michal.wajdeczko@intel.com>,
	<intel-xe@lists.freedesktop.org>
Cc: <matthew.d.roper@intel.com>, <lucas.demarchi@intel.com>,
	<koby.elbaz@intel.com>, <yaron.avizrat@intel.com>
Subject: Re: [PATCH 2/2] drm/xe: Add xe_mmio_init() initialization function
Date: Fri, 31 Jan 2025 09:37:15 +0200	[thread overview]
Message-ID: <54eff7e0-9c48-4b4c-9d86-41b5c8c1040f@intel.com> (raw)
In-Reply-To: <efc3c364-a41d-4ab6-a3bc-f1e571326712@intel.com>

On 30/01/2025 21:54, Michal Wajdeczko wrote:
>
> On 30.01.2025 11:50, Ilia Levi wrote:
>> Add a convenience function for minimal initialization of struct xe_mmio.
>> This function also validates that the space referred by this xe_mmio is
>> small enough to be accessed with struct xe_reg.
> hmm, maybe is _large_ enough ?


The addr field of struct xe_reg is currently 22 bits, i. e. the biggest offset
that can be used within xe_mmio is up to 8MiB. This means that there's
no sense in instantiating xe_mmio bigger than 8MiB, as xe_mmio_read &
xe_mmio_write functions will not be able to access a register placed at
an offset after 8MiB. Hence, I validate that xe_mmio is no larger than 8MiB
(~ small enough). This patch is in continuation of the discussion I had with Matt in
https://lore.kernel.org/all/55e647fd-08b0-4395-8fb0-ad53ac3f9be7@intel.com
(specifically my 2nd comment there).

- Ilia

>
>> Signed-off-by: Ilia Levi <ilia.levi@intel.com>
>> ---
>>  drivers/gpu/drm/xe/regs/xe_reg_defs.h |  4 +++-
>>  drivers/gpu/drm/xe/xe_gt.c            |  7 +++----
>>  drivers/gpu/drm/xe/xe_mmio.c          | 24 +++++++++++++-----------
>>  drivers/gpu/drm/xe/xe_mmio.h          |  2 ++
>>  4 files changed, 21 insertions(+), 16 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/xe/regs/xe_reg_defs.h b/drivers/gpu/drm/xe/regs/xe_reg_defs.h
>> index 89716172fbb8..26d00d825454 100644
>> --- a/drivers/gpu/drm/xe/regs/xe_reg_defs.h
>> +++ b/drivers/gpu/drm/xe/regs/xe_reg_defs.h
>> @@ -10,6 +10,8 @@
>>  
>>  #include "compat-i915-headers/i915_reg_defs.h"
>>  
>> +#define XE_REG_ADDR_WIDTH	22
>> +
>>  /**
>>   * struct xe_reg - Register definition
>>   *
>> @@ -21,7 +23,7 @@ struct xe_reg {
>>  	union {
>>  		struct {
>>  			/** @addr: address */
>> -			u32 addr:22;
>> +			u32 addr:XE_REG_ADDR_WIDTH;
>>  			/**
>>  			 * @masked: register is "masked", with upper 16bits used
>>  			 * to identify the bits that are updated on the lower
>> diff --git a/drivers/gpu/drm/xe/xe_gt.c b/drivers/gpu/drm/xe/xe_gt.c
>> index 01a4a852b8f4..f10c1f5fbbe1 100644
>> --- a/drivers/gpu/drm/xe/xe_gt.c
>> +++ b/drivers/gpu/drm/xe/xe_gt.c
>> @@ -637,10 +637,9 @@ int xe_gt_init(struct xe_gt *gt)
>>  void xe_gt_mmio_init(struct xe_gt *gt)
>>  {
>>  	struct xe_tile *tile = gt_to_tile(gt);
>> +	struct xe_device *xe = tile_to_xe(tile);
>>  
>> -	gt->mmio.regs = tile->mmio.regs;
>> -	gt->mmio.regs_size = tile->mmio.regs_size;
>> -	gt->mmio.tile = tile;
>> +	xe_mmio_init(&gt->mmio, tile, tile->mmio.regs, tile->mmio.regs_size);
>>  
>>  	if (gt->info.type == XE_GT_TYPE_MEDIA) {
>>  		gt->mmio.adj_offset = MEDIA_GT_GSI_OFFSET;
>> @@ -650,7 +649,7 @@ void xe_gt_mmio_init(struct xe_gt *gt)
>>  		gt->mmio.adj_limit = 0;
>>  	}
>>  
>> -	if (IS_SRIOV_VF(gt_to_xe(gt)))
>> +	if (IS_SRIOV_VF(xe))
>>  		gt->mmio.sriov_vf_gt = gt;
>>  }
>>  
>> diff --git a/drivers/gpu/drm/xe/xe_mmio.c b/drivers/gpu/drm/xe/xe_mmio.c
>> index 3aed849a128b..8cee986947bc 100644
>> --- a/drivers/gpu/drm/xe/xe_mmio.c
>> +++ b/drivers/gpu/drm/xe/xe_mmio.c
>> @@ -55,7 +55,6 @@ static void tiles_fini(void *arg)
>>  static void mmio_multi_tile_setup(struct xe_device *xe, size_t tile_mmio_size)
>>  {
>>  	struct xe_tile *tile;
>> -	void __iomem *regs;
>>  	u8 id;
>>  
>>  	/*
>> @@ -94,13 +93,8 @@ static void mmio_multi_tile_setup(struct xe_device *xe, size_t tile_mmio_size)
>>  		}
>>  	}
>>  
>> -	regs = xe->mmio.regs;
>> -	for_each_tile(tile, xe, id) {
>> -		tile->mmio.regs_size = SZ_4M;
>> -		tile->mmio.regs = regs;
>> -		tile->mmio.tile = tile;
>> -		regs += tile_mmio_size;
>> -	}
>> +	for_each_remote_tile(tile, xe, id)
>> +		xe_mmio_init(&tile->mmio, tile, xe->mmio.regs + id * tile_mmio_size, SZ_4M);
>>  }
>>  
>>  int xe_mmio_probe_tiles(struct xe_device *xe)
>> @@ -140,13 +134,21 @@ int xe_mmio_probe_early(struct xe_device *xe)
>>  	}
>>  
>>  	/* Setup first tile; other tiles (if present) will be setup later. */
>> -	root_tile->mmio.regs_size = SZ_4M;
>> -	root_tile->mmio.regs = xe->mmio.regs;
>> -	root_tile->mmio.tile = root_tile;
>> +	xe_mmio_init(&root_tile->mmio, root_tile, xe->mmio.regs, SZ_4M);
>>  
>>  	return devm_add_action_or_reset(xe->drm.dev, mmio_fini, xe);
>>  }
>>  
> missing kernel-doc for this new public function
>
>> +void xe_mmio_init(struct xe_mmio *mmio, struct xe_tile *tile, void __iomem *ptr, u32 size)
>> +{
>> +	/* Validate that we can use XE_REG macro with this xe_mmio later */
>> +	xe_assert(tile_to_xe(tile), size <= (1 << (XE_REG_ADDR_WIDTH + 1)));
> you can use xe_tile_assert(tile, ...) here and BIT() instead of shift
>
> but I'm not sure I follow the logic here: if in the future we will
> change xe_reg.addr to more than 22 bits to allow new extended register
> definitions for new platforms, this assert will trigger when we would
> initialize older platforms with smaller MMIO BAR, no?
>
> maybe better place for such assert would be in xe_mmio_read|write():
>
> 	xe_tile_assert(mmio->tile, reg.addr < mmio->regs_size);
>
> and likely this new assert/ADDR_WIDTH could be added in separate patch

See my explanation above, I check the other direction - that xe_mmio is not too big to be
addressed with 22 bits. You're suggesting a check that the provided register offset, while
still being 22 bits, is smaller than xe_mmio size. It sounds like a good check to add, but
different from the concern that I had. I'll implement it in an additional patch.

- Ilia

>
>> +
>> +	mmio->regs = ptr;
>> +	mmio->regs_size = size;
>> +	mmio->tile = tile;
>> +}
>> +
>>  static void mmio_flush_pending_writes(struct xe_mmio *mmio)
>>  {
>>  #define DUMMY_REG_OFFSET	0x130030
>> diff --git a/drivers/gpu/drm/xe/xe_mmio.h b/drivers/gpu/drm/xe/xe_mmio.h
>> index b32e7ee4b23e..c151ba569003 100644
>> --- a/drivers/gpu/drm/xe/xe_mmio.h
>> +++ b/drivers/gpu/drm/xe/xe_mmio.h
>> @@ -14,6 +14,8 @@ struct xe_reg;
>>  int xe_mmio_probe_early(struct xe_device *xe);
>>  int xe_mmio_probe_tiles(struct xe_device *xe);
>>  
>> +void xe_mmio_init(struct xe_mmio *mmio, struct xe_tile *tile, void __iomem *ptr, u32 size);
>> +
>>  u8 xe_mmio_read8(struct xe_mmio *mmio, struct xe_reg reg);
>>  u16 xe_mmio_read16(struct xe_mmio *mmio, struct xe_reg reg);
>>  void xe_mmio_write32(struct xe_mmio *mmio, struct xe_reg reg, u32 val);



  reply	other threads:[~2025-01-31  7:38 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-30 10:50 [PATCH 1/2] drm/xe: s/xe_mmio_init/xe_mmio_probe_early Ilia Levi
2025-01-30 10:50 ` [PATCH 2/2] drm/xe: Add xe_mmio_init() initialization function Ilia Levi
2025-01-30 19:03   ` Lucas De Marchi
2025-01-30 19:54   ` Michal Wajdeczko
2025-01-31  7:37     ` Levi, Ilia [this message]
2025-02-02 11:00     ` [PATCH v2 " Ilia Levi
2025-02-05 15:56       ` Michal Wajdeczko
2025-02-09 13:13         ` [PATCH v3 " Ilia Levi
2025-02-12 23:18           ` Michal Wajdeczko
2025-02-13  9:35             ` [PATCH v4 " Ilia Levi
2025-02-13 23:53               ` Michal Wajdeczko
2025-02-09 13:34         ` [PATCH v2 " Levi, Ilia
2025-01-30 11:48 ` ✓ CI.Patch_applied: success for series starting with [1/2] drm/xe: s/xe_mmio_init/xe_mmio_probe_early Patchwork
2025-01-30 11:49 ` ✓ CI.checkpatch: " Patchwork
2025-01-30 11:50 ` ✓ CI.KUnit: " Patchwork
2025-01-30 12:06 ` ✓ CI.Build: " Patchwork
2025-01-30 12:09 ` ✓ CI.Hooks: " Patchwork
2025-01-30 12:10 ` ✓ CI.checksparse: " Patchwork
2025-01-30 12:38 ` ✓ Xe.CI.BAT: " Patchwork
2025-01-30 14:42 ` ✗ Xe.CI.Full: failure " Patchwork
2025-01-30 18:48 ` [PATCH 1/2] " Lucas De Marchi
2025-02-02 11:55 ` ✓ CI.Patch_applied: success for series starting with [1/2] drm/xe: s/xe_mmio_init/xe_mmio_probe_early (rev2) Patchwork
2025-02-02 11:56 ` ✓ CI.checkpatch: " Patchwork
2025-02-02 11:57 ` ✓ CI.KUnit: " Patchwork
2025-02-02 12:13 ` ✓ CI.Build: " Patchwork
2025-02-02 12:15 ` ✓ CI.Hooks: " Patchwork
2025-02-02 12:17 ` ✓ CI.checksparse: " Patchwork
2025-02-02 12:36 ` ✓ Xe.CI.BAT: " Patchwork
2025-02-02 13:45 ` ✗ Xe.CI.Full: failure " Patchwork
2025-02-09 13:30 ` ✓ CI.Patch_applied: success for series starting with [1/2] drm/xe: s/xe_mmio_init/xe_mmio_probe_early (rev3) Patchwork
2025-02-09 13:30 ` ✓ CI.checkpatch: " Patchwork
2025-02-09 13:31 ` ✓ CI.KUnit: " Patchwork
2025-02-09 13:48 ` ✓ CI.Build: " Patchwork
2025-02-09 13:50 ` ✓ CI.Hooks: " Patchwork
2025-02-09 13:51 ` ✓ CI.checksparse: " Patchwork
2025-02-09 14:11 ` ✓ Xe.CI.BAT: " Patchwork
2025-02-09 15:23 ` ✗ Xe.CI.Full: failure " Patchwork
2025-02-13  9:41 ` ✓ CI.Patch_applied: success for series starting with [1/2] drm/xe: s/xe_mmio_init/xe_mmio_probe_early (rev4) Patchwork
2025-02-13  9:42 ` ✓ CI.checkpatch: " Patchwork
2025-02-13  9:43 ` ✓ CI.KUnit: " Patchwork
2025-02-13  9:59 ` ✓ CI.Build: " Patchwork
2025-02-13 10:02 ` ✓ CI.Hooks: " Patchwork
2025-02-13 10:03 ` ✓ CI.checksparse: " Patchwork
2025-02-14  5:58 ` ✓ Xe.CI.BAT: " Patchwork
2025-02-17  8:02 ` ✗ Xe.CI.Full: failure " Patchwork
2025-02-18 16:31 ` [PATCH 1/2] drm/xe: s/xe_mmio_init/xe_mmio_probe_early Lucas De Marchi

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=54eff7e0-9c48-4b4c-9d86-41b5c8c1040f@intel.com \
    --to=ilia.levi@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=koby.elbaz@intel.com \
    --cc=lucas.demarchi@intel.com \
    --cc=matthew.d.roper@intel.com \
    --cc=michal.wajdeczko@intel.com \
    --cc=yaron.avizrat@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox