All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Chee, Tien Fong" <tien.fong.chee@altera.com>
To: Chen Huei Lok <chen.huei.lok@altera.com>, u-boot@lists.denx.de
Cc: Tom Rini <trini@konsulko.com>, Marek Vasut <marex@denx.de>,
	Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>,
	Alif Zakuan Yuslaimi <alif.zakuan.yuslaimi@altera.com>,
	Boon Khai Ng <boon.khai.ng@altera.com>,
	Kok Kiang Hea <kok.kiang.hea@altera.com>
Subject: Re: [PATCH v4 14/15] ddr: altera: n5x: reconfigure DDR when mem-clk handoff changes
Date: Wed, 21 Oct 2026 10:30:08 +0800	[thread overview]
Message-ID: <e5b56bd2-6018-4bac-ad5f-db95fac6471f@altera.com> (raw)
In-Reply-To: <20261016044047.21496-15-chen.huei.lok@altera.com>

On 16/10/2026 12:40 pm, Chen Huei Lok wrote:
> Trigger a DDR reconfiguration when the memory clock values in the handoff
> data have changed, so that a retention restore is not attempted against a
> DDR configuration that no longer matches the running mem-clk settings.
>
> Signed-off-by: Chen Huei Lok <chen.huei.lok@altera.com>
> ---
>   .../mach-socfpga/include/mach/handoff_soc64.h |  1 +
>   arch/arm/mach-socfpga/wrap_handoff_soc64.c    |  7 ++-
>   drivers/ddr/altera/sdram_n5x.c                | 59 ++++++++++++++++++-
>   3 files changed, 65 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
> index ae5af1f0100..0fb43acc98b 100644
> --- a/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
> +++ b/arch/arm/mach-socfpga/include/mach/handoff_soc64.h
> @@ -47,6 +47,7 @@
>   #define SOC64_HANDOFF_BASE		0x0007F000
>   #elif IS_ENABLED(CONFIG_ARCH_SOCFPGA_N5X)
>   #define SOC64_HANDOFF_BASE		0xFFE5F000
> +#define SOC64_HANDOFF_DDR_CLK_HANDOFF	(SOC64_HANDOFF_BASE + 0x610)
>   #define SOC64_HANDOFF_MISC		(SOC64_HANDOFF_BASE + 0x630)
>   
>   /* DDR handoff */
> diff --git a/arch/arm/mach-socfpga/wrap_handoff_soc64.c b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
> index ecde90f76f4..72e98806f8d 100644
> --- a/arch/arm/mach-socfpga/wrap_handoff_soc64.c
> +++ b/arch/arm/mach-socfpga/wrap_handoff_soc64.c
> @@ -27,7 +27,6 @@ static enum endianness check_endianness(u32 handoff)
>   	case SOC64_HANDOFF_MAGIC_IOCTL:
>   	case SOC64_HANDOFF_MAGIC_FPGA:
>   	case SOC64_HANDOFF_MAGIC_DELAY:
> -	case SOC64_HANDOFF_MAGIC_CLOCK:
>   	case SOC64_HANDOFF_MAGIC_SDRAM:
>   #if IS_ENABLED(CONFIG_ARCH_SOCFPGA_AGILEX5)
>   	case SOC64_HANDOFF_MAGIC_PERI:
> @@ -35,6 +34,12 @@ static enum endianness check_endianness(u32 handoff)
>   	case SOC64_HANDOFF_MAGIC_MISC:
>   #endif
>   		return BIG_ENDIAN;
> +	case SOC64_HANDOFF_MAGIC_CLOCK:
> +		if (IS_ENABLED(CONFIG_ARCH_SOCFPGA_N5X)) {
> +			debug("%s: mem clk  handoff data\n", __func__);
> +			return LITTLE_ENDIAN;
> +		}
> +		return BIG_ENDIAN;
>   #if IS_ENABLED(CONFIG_ARCH_SOCFPGA_N5X)
>   	case SOC64_HANDOFF_DDR_UMCTL2_MAGIC:
>   		debug("%s: umctl2 handoff data\n", __func__);
> diff --git a/drivers/ddr/altera/sdram_n5x.c b/drivers/ddr/altera/sdram_n5x.c
> index 558415d7931..11aa020d380 100644
> --- a/drivers/ddr/altera/sdram_n5x.c
> +++ b/drivers/ddr/altera/sdram_n5x.c
> @@ -37,8 +37,9 @@ DECLARE_GLOBAL_DATA_PTR;
>   
>   /* DDR handoff SHA384 attribute */
>   #define DDR_HANDOFF_IMG_ADDR	0xFFE44000
> -#define DDR_HANDOFF_IMG_LEN	0x1A000
> +#define DDR_HANDOFF_IMG_LEN	0x1A200
>   #define CHUNKSZ_PER_WD_RESET	(256 * 1024)
> +#define MEMCLK_HANDOFF_SIZE 0x2C
>   
>   /* MPFE NOC registers */
>   #define FPGA2SDRAM_MGR_MAIN_SIDEBANDMGR_FLAGOUTSET0	0xF8024050
> @@ -1105,6 +1106,28 @@ static void phy_ocram(phys_addr_t phy_base, phys_addr_t phy_offset,
>   	}
>   }
>   
> +static int populate_memclk_handoff(void *handoff_base, u32 *mclk_table, u32 size)
> +{
> +	u32 handoff_table[MEMCLK_HANDOFF_SIZE - 4];
> +	u32 length = ARRAY_SIZE(handoff_table);
> +	u32 offset = length - 8;
> +	u32 i;
> +	int ret = 0;
> +
> +	ret = socfpga_handoff_read((void *)handoff_base, handoff_table, length);
> +	if (ret) {
> +		debug("%s: handoff read failed. ret: %d\n", __func__, ret);
> +		return ret;
> +	}
> +
> +	for (i = 0; i < size; i++) {
> +		mclk_table[i] = handoff_table[offset + i];
> +		debug("mclk_table[%d]: 0x%x\n", i, mclk_table[i]);
> +	}
> +
> +	return ret;
> +}
> +
>   static int cal_data_ocram(phys_addr_t phy_base, u32 addr,
>   			  enum data_process proc)
>   {
> @@ -1390,6 +1413,11 @@ static int cal_data_ocram(phys_addr_t phy_base, u32 addr,
>   	size_t phybak_num;
>   	const u32 *phybak_p = phybak;
>   	u16 *data;
> +	u32 memclk_table[4];
> +	u32 size = ARRAY_SIZE(memclk_table);
> +	u8 *memclk_hash_offset = (u8 *)(SOC64_OCRAM_PHY_BACKUP_BASE - SZ_1K);
> +	int ret = 0;
> +
>   	struct bac_cal_data_t *cal = (struct bac_cal_data_t *)
>   					((uintptr_t)addr);
>   
> @@ -1424,6 +1452,17 @@ static int cal_data_ocram(phys_addr_t phy_base, u32 addr,
>   	};
>   
>   	if (proc == STORE) {
> +		ret = populate_memclk_handoff((void *)SOC64_HANDOFF_CLOCK,
> +					      memclk_table, size);
> +		if (ret) {
> +			debug("%s: Memclks config Magic Number miss match. ret :%d\n",
> +			      __func__, ret);
> +			return -EFAULT;
> +		}
> +
> +		sha384_csum_wd((u8 *)memclk_table, 4 * size,
> +			       memclk_hash_offset, CHUNKSZ_PER_WD_RESET);
> +
>   		/* Creating header */
>   		/* Generate HASH384 from the DDR config */
>   		sha384_csum_wd((u8 *)DDR_HANDOFF_IMG_ADDR,
> @@ -1454,10 +1493,28 @@ static bool is_ddrconfig_hash_match(const void *buffer)
>   {
>   	int ret;
>   	u8 hash[SHA384_SUM_LEN];
> +	u32 memclk_table[4];
> +	u32 size = ARRAY_SIZE(memclk_table);
>   
>   	/* Magic symbol in first 4 bytes of header */
>   	struct cal_header_t *header = (struct cal_header_t *)buffer;
>   
> +	/*
> +	 * Read and generate the hash for the Mem clk values and store before
> +	 * calcuting the HASH384 generation before Image.
> +	 */
> +	ret = populate_memclk_handoff((void *)SOC64_HANDOFF_CLOCK,
> +				      memclk_table, size);
> +	if (ret) {
> +		debug("%s: Memclks config Magic Number miss match. ret : %d\n",
> +		      __func__, ret);
> +		return false;
> +	}
> +
> +	sha384_csum_wd((u8 *)memclk_table, (4 * sizeof(u32)),
> +		       (u8 *)DDR_HANDOFF_IMG_ADDR + DDR_HANDOFF_IMG_LEN - SZ_512,
> +		       CHUNKSZ_PER_WD_RESET);
> +
>   	/* Generate HASH384 from the image */
>   	sha384_csum_wd((u8 *)DDR_HANDOFF_IMG_ADDR, DDR_HANDOFF_IMG_LEN,
>   		       hash, CHUNKSZ_PER_WD_RESET);


Reviewed-by: Tien Fong Chee <tien.fong.chee@altera.com>

Best regards,
Tien Fong


  parent reply	other threads:[~2026-10-21  2:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261016044047.21496-1-chen.huei.lok@altera.com>
     [not found] ` <20261016044047.21496-2-chen.huei.lok@altera.com>
2026-10-21  1:55   ` [PATCH v4 01/15] misc: fs_loader: Add QSPI RAW offset loading support Chee, Tien Fong
     [not found] ` <20261016044047.21496-3-chen.huei.lok@altera.com>
2026-10-21  2:07   ` [PATCH v4 02/15] arm: dts: socfpga: n5x: add DDR retention calibration backup nodes Chee, Tien Fong
     [not found] ` <20261016044047.21496-4-chen.huei.lok@altera.com>
2026-10-21  2:09   ` [PATCH v4 03/15] arm: socfpga: n5x: enable QSPI mailbox before DDR init Chee, Tien Fong
     [not found] ` <20261016044047.21496-5-chen.huei.lok@altera.com>
2026-10-21  2:14   ` [PATCH v4 04/15] ddr: altera: n5x: Add self-refresh support in DDR4 Chee, Tien Fong
     [not found] ` <20261016044047.21496-6-chen.huei.lok@altera.com>
2026-10-21  2:16   ` [PATCH v4 05/15] configs: socfpga: n5x: enable required configs for DDR retention Chee, Tien Fong
     [not found] ` <20261016044047.21496-7-chen.huei.lok@altera.com>
2026-10-21  2:18   ` [PATCH v4 06/15] ddr: altera: n5x: set DDR init progress bit for watchdog recovery Chee, Tien Fong
     [not found] ` <20261016044047.21496-8-chen.huei.lok@altera.com>
2026-10-21  2:20   ` [PATCH v4 07/15] ddr: altera: n5x: re-init DDR when double-bit ECC error is detected Chee, Tien Fong
     [not found] ` <20261016044047.21496-9-chen.huei.lok@altera.com>
2026-10-21  2:21   ` [PATCH v4 08/15] ddr: altera: n5x: re-init DDR after watchdog reset from init hang Chee, Tien Fong
     [not found] ` <20261016044047.21496-10-chen.huei.lok@altera.com>
2026-10-21  2:22   ` [PATCH v4 09/15] ddr: altera: n5x: return error on invalid DDR controller type Chee, Tien Fong
     [not found] ` <20261016044047.21496-11-chen.huei.lok@altera.com>
2026-10-21  2:24   ` [PATCH v4 10/15] ddr: altera: n5x: use correct cast for reset status register read Chee, Tien Fong
     [not found] ` <20261016044047.21496-12-chen.huei.lok@altera.com>
2026-10-21  2:25   ` [PATCH v4 11/15] ddr: altera: n5x: fix debug log typo Chee, Tien Fong
     [not found] ` <20261016044047.21496-13-chen.huei.lok@altera.com>
2026-10-21  2:27   ` [PATCH v4 12/15] ddr: altera: n5x: rename is_ddr_init_skipped() and quieten reset log Chee, Tien Fong
     [not found] ` <20261016044047.21496-14-chen.huei.lok@altera.com>
2026-10-21  2:29   ` [PATCH v4 13/15] ddr: altera: n5x: drop always-false unsigned less-than-zero checks Chee, Tien Fong
     [not found] ` <20261016044047.21496-15-chen.huei.lok@altera.com>
2026-10-21  2:30   ` Chee, Tien Fong [this message]
     [not found] ` <20261016044047.21496-16-chen.huei.lok@altera.com>
2026-10-21  2:31   ` [PATCH v4 15/15] ddr: altera: n5x: Replay PIE handoff on DDR retention restore Chee, Tien Fong

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=e5b56bd2-6018-4bac-ad5f-db95fac6471f@altera.com \
    --to=tien.fong.chee@altera.com \
    --cc=alif.zakuan.yuslaimi@altera.com \
    --cc=boon.khai.ng@altera.com \
    --cc=chen.huei.lok@altera.com \
    --cc=kok.kiang.hea@altera.com \
    --cc=marex@denx.de \
    --cc=simon.k.r.goldschmidt@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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.