dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Gregory Williams" <gregory.williams@amd.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks
Date: Wed, 18 Nov 2026 23:45:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-222208@kernel.org> (raw)
In-Reply-To: <20261118233211.4121361-15-gregory.williams@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] accel/amd-ai-engine: aiemlv2_set_part_clocks() clobbers
  tiles_inuse bitmap
- [Low] accel/amd-ai-engine: % 2 discards mask bit 1 in
  aiemlv2_scan_part_clocks()
--

commit 31b6ed2773ef86bbc6d6e5049ee938eccc623dd5
Author: Gregory Williams <gregory.williams@amd.com>

accel/amd-ai-engine: Add support to enable/disable tile clocks

This commit adds partition clock scanning and tile clock enable/disable
operations for requesting and releasing AI Engine tiles.

> diff --git a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> index 0c9c7ccdd54e0..26dd1d726bfad 100644
> --- a/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> +++ b/drivers/accel/amd-ai-engine/ai-engine-aiemlv2.c
> @@ -13,6 +13,16 @@
>  #define AIEMLV2_COL_SHIFT		25U
>  #define AIEMLV2_ROW_SHIFT		20U
>  
> +/*
> + * Register offsets
> + */
> +#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF		0x0007FF20U
> +
> +/*
> + * Register masks
> + */
> +#define AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK		GENMASK(1, 0)
> +
>  static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *loc)
>  {
>  	u8 num_mem_rows = adev->ttype_attr[AIE_TILE_TYPE_MEMORY].num_rows;
> @@ -25,8 +35,148 @@ static u32 aiemlv2_get_tile_type(struct aie_device *adev, struct aie_location *l
>  	return AIE_TILE_TYPE_SHIMNOC;
>  }
>  
> +static int aiemlv2_scan_part_clocks(struct aie_partition *apart)
> +{
> +	struct aie_range *range = &apart->range;
> +	struct aie_device *adev = apart->adev;
> +	struct aie_location loc;
> +
> +	/* Clear the bitmap of cores and memories clock state */
> +	aie_resource_put_region(&apart->cores_clk_state, 0,
> +				apart->cores_clk_state.total);
> +
> +	/*
> +	 * If the clock buffer on shim tile is enabled, then all tiles above in
> +	 * the same column are also enabled.
> +	 */
> +
> +	loc.row = 0;
> +	for (loc.col = range->start.col;
> +	     loc.col < range->start.col + range->size.col;
> +	     loc.col++) {
> +		void __iomem *va;
> +		u32 val, nbitpos;
> +
> +		nbitpos = (loc.col - range->start.col) * (range->size.row - 1) + loc.row;
> +
> +		va = adev->base +
> +		     aie_cal_regoff(adev, loc,
> +				    AIEMLV2_SHIMPL_COLCLOCK_CTRL_REGOFF);
> +		val = readl(va);
> +
> +		if (!((val & AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK) % 2))
> +			continue;

[Severity: Low]
Does applying "% 2" after masking with AIEMLV2_SHIMPL_COLCLOCK_CTRL_MASK
(GENMASK(1, 0)) unintentionally discard bit 1?  Since (val & 0x3) % 2 only
tests bit 0, a column with bit 1 set and bit 0 clear will be treated as
clocked off during aie_part_create() -> aie_part_scan_clk_state().

> +
> +		aie_resource_set(&apart->cores_clk_state, nbitpos,
> +				 range->size.row - 1);
> +	}
> +	/*
> +	 * Set the tiles in use bitmap.
> +	 * In case of scanning, tiles which are powered on are considered as
> +	 * tiles in use.
> +	 */
> +	bitmap_copy(apart->tiles_inuse.bitmap, apart->cores_clk_state.bitmap,
> +		    apart->tiles_inuse.total);
> +
> +	return 0;
> +}
> +
> +static int aiemlv2_set_part_clocks(struct aie_partition *apart)
> +{
> +	struct aie_range *range = &apart->range;
> +	struct aie_range prev_range = {};
> +	struct aie_location loc;
> +	int ret = -EINVAL;
> +	u32 prev_ops = 0;
> +
> +	for (loc.col = 0; loc.col < range->size.col; loc.col++) {
> +		u32 startbit, col_inuse = 0;
> +
> +		startbit = loc.col * (range->size.row - 1);
> +
> +		for (loc.row = range->start.row + 1;
> +		     loc.row < range->start.row + range->size.row;
> +		     loc.row++) {
> +			u32 nbitpos = startbit + loc.row - 1;
> +
> +			if (aie_resource_testbit(&apart->tiles_inuse, nbitpos)) {
> +				col_inuse = 1;
> +				break;
> +			}
> +		}
> +
> +		if (col_inuse) {
> +			struct aie_range op_range = {
> +				.start.col = loc.col + range->start.col,
> +				.size.col = 1,
> +			};
> +
> +			ret = aie_resource_set(&apart->tiles_inuse, startbit,
> +					       apart->range.size.row - 1);
> +			if (ret)
> +				return ret;
> +			ret = aie_resource_set(&apart->cores_clk_state, startbit,
> +					       apart->range.size.row - 1);

[Severity: Medium]
Should aiemlv2_set_part_clocks() avoid setting the entire column in
apart->tiles_inuse when col_inuse is true?

When aie_part_request_tiles() requests a subset of tiles in a column, it
sets only those tile bits in apart->tiles_inuse, but this call marks every
row in the column as in use.  If the caller later releases the requested
tiles via aie_part_release_tiles(), only the specified tile bits are
cleared in apart->tiles_inuse, so aiemlv2_set_part_clocks() sees the remaining
row bits still set, re-sets the released bits in apart->tiles_inuse, and
never disables the column clock buffer.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261118233211.4121361-1-gregory.williams@amd.com?part=14

  reply	other threads:[~2026-11-18 23:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 23:31 [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Gregory Williams
2026-11-18 23:32 ` [PATCH 11/15] dt-bindings: soc: xilinx: Add Versal AI Engine DT binding Gregory Williams
2026-11-18 23:45   ` sashiko-bot
2026-11-19 10:59   ` Krzysztof Kozlowski
2026-11-18 23:32 ` [PATCH 12/15] accel/amd-ai-engine: Add AMD AI Engine device driver Gregory Williams
2026-11-18 23:45   ` sashiko-bot
2026-11-18 23:32 ` [PATCH 13/15] accel/amd-ai-engine: Add pm ops for firmware calls Gregory Williams
2026-11-18 23:46   ` sashiko-bot
2026-11-18 23:32 ` [PATCH 14/15] accel/amd-ai-engine: Add support to enable/disable tile clocks Gregory Williams
2026-11-18 23:45   ` sashiko-bot [this message]
2026-11-18 23:32 ` [PATCH 15/15] accel/amd-ai-engine: Add reset operations Gregory Williams
2026-11-18 23:51   ` sashiko-bot
2026-11-19  8:19 ` [PATCH 00/15] accel: Add AMD Versal AI Engine driver (with Versal Gen 2 firmware support) Jerome Brunet

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=sashiko-outbox-222208@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregory.williams@amd.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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