mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Tretter <m.tretter@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 BAREBOX <barebox@lists.infradead.org>
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>,
	 Michael Tretter <m.tretter@pengutronix.de>
Subject: [PATCH 09/10] arm: socfpga: iossm: add memory initialization with inline ecc
Date: Tue, 07 Apr 2026 19:10:03 +0200	[thread overview]
Message-ID: <20260407-socfpga-iossm-v1-v1-9-6440a5337eff@pengutronix.de> (raw)
In-Reply-To: <20260407-socfpga-iossm-v1-v1-0-6440a5337eff@pengutronix.de>

The memory interfaces may support for inline ECC and report their
configuration via the ECC status. The software is responsible for
initializing the memory accordingly.

Check the memory interface configuration and initialize the memory if
necessary.

Inline ECC uses 1/8 of the available memory for error correction. Thus,
only 7/8 of the reported memory size is actually available.

Signed-off-by: Michael Tretter <m.tretter@pengutronix.de>
---
 arch/arm/mach-socfpga/agilex5-sdram.c |  2 ++
 arch/arm/mach-socfpga/iossm_mailbox.c | 31 +++++++++++++++++++++++++++----
 arch/arm/mach-socfpga/iossm_mailbox.h |  1 +
 3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-socfpga/agilex5-sdram.c b/arch/arm/mach-socfpga/agilex5-sdram.c
index 5fb59d413e8f..4e7994985d26 100644
--- a/arch/arm/mach-socfpga/agilex5-sdram.c
+++ b/arch/arm/mach-socfpga/agilex5-sdram.c
@@ -323,6 +323,8 @@ int agilex5_ddr_init_full(void)
 	}
 
 	hw_size = io96b_ctrl.overall_size;
+	if (io96b_ctrl.inline_ecc)
+		hw_size -= hw_size / 8;
 	pr_debug("%s: %lld MiB\n", io96b_ctrl.ddr_type, hw_size / SZ_1M);
 
 	sdram_set_firewall(hw_size);
diff --git a/arch/arm/mach-socfpga/iossm_mailbox.c b/arch/arm/mach-socfpga/iossm_mailbox.c
index 6be1119724d6..4c6a84feccc5 100644
--- a/arch/arm/mach-socfpga/iossm_mailbox.c
+++ b/arch/arm/mach-socfpga/iossm_mailbox.c
@@ -456,6 +456,7 @@ int io96b_ecc_enable_status(struct io96b_info *io96b_ctrl)
 	u32 ecc_enable_intf;
 	bool ecc_stat_set = false;
 	bool ecc_stat;
+	bool inline_ecc = false;
 
 	/* Initialize ECC status */
 	io96b_ctrl->ecc_status = false;
@@ -472,13 +473,19 @@ int io96b_ecc_enable_status(struct io96b_info *io96b_ctrl)
 			ecc_enable_intf = IOSSM_CMD_RESPONSE_DATA_SHORT(usr_resp.cmd_resp_status)
 
 			ecc_stat = (ecc_enable_intf & GENMASK(1, 0)) == 0 ? false : true;
+			inline_ecc = FIELD_GET(BIT(8), ecc_enable_intf);
 
 			if (!ecc_stat_set) {
 				io96b_ctrl->ecc_status = ecc_stat;
+
+				if (io96b_ctrl->ecc_status)
+					io96b_ctrl->inline_ecc = inline_ecc;
+
 				ecc_stat_set = true;
 			}
 
-			if (ecc_stat != io96b_ctrl->ecc_status) {
+			if (ecc_stat != io96b_ctrl->ecc_status ||
+			    (io96b_ctrl->ecc_status && inline_ecc != io96b_ctrl->inline_ecc)) {
 				pr_err("%s: Mismatch DDR ECC status on IO96B_%d\n",
 				       __func__, i);
 				return -ENOEXEC;
@@ -539,9 +546,25 @@ static int bist_mem_init_by_addr(struct io96b_info *io96b_ctrl,
 	int ret = 0;
 	u32 mem_exp;
 
-	pr_debug("%s: Start memory initialization BIST on full memory address",
-		 __func__);
-	mem_exp = 0x40;
+	if (io96b_ctrl->inline_ecc) {
+		phys_size_t chunk_size;
+
+		/* Check if size is a power of 2 */
+		if (size == 0 || (size & (size - 1)) != 0)
+			return -EINVAL;
+
+		mem_exp = 0;
+		chunk_size = size;
+		while (chunk_size >>= 1)
+			mem_exp++;
+
+		pr_debug("%s: Initializing memory: Addr=0x%llx, Size=2^%u\n",
+			 __func__, base_addr, mem_exp);
+	} else {
+		pr_debug("%s: Start memory initialization BIST on full memory address",
+			 __func__);
+		mem_exp = 0x40;
+	}
 
 	ret = io96b_mb_req(io96b_csr_addr,
 			   mb_ctrl->ip_type[interface],
diff --git a/arch/arm/mach-socfpga/iossm_mailbox.h b/arch/arm/mach-socfpga/iossm_mailbox.h
index 1b1bb1c7a19a..940678fa9d2b 100644
--- a/arch/arm/mach-socfpga/iossm_mailbox.h
+++ b/arch/arm/mach-socfpga/iossm_mailbox.h
@@ -127,6 +127,7 @@ struct io96b_info {
 	bool			 overall_cal_status;
 	const char		*ddr_type;
 	bool			 ecc_status;
+	bool			 inline_ecc;
 	phys_size_t		 overall_size;
 	struct io96b_instance	 io96b[MAX_IO96B_SUPPORTED];
 	bool			 ckgen_lock;

-- 
2.47.3




  parent reply	other threads:[~2026-04-07 17:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-07 17:09 [PATCH 00/10] arm: socfpga: iossm: add support for mailbox v1 Michael Tretter
2026-04-07 17:09 ` [PATCH 01/10] arm: socfpga: iossm: remove uninitialized variable Michael Tretter
2026-04-07 17:09 ` [PATCH 02/10] arm: socfpga: iossm: add version check Michael Tretter
2026-04-07 17:09 ` [PATCH 03/10] arm: socfpga: iossm: use local mb_ctrl variable Michael Tretter
2026-04-07 17:09 ` [PATCH 04/10] arm: socfpga: iossm: store size in bytes Michael Tretter
2026-04-07 17:43   ` Ahmad Fatoum
2026-04-08  7:12     ` Michael Tretter
2026-04-07 17:09 ` [PATCH 05/10] arm: socfpga: iossm: refactor io96b_mb_init Michael Tretter
2026-04-07 17:10 ` [PATCH 06/10] arm: socfpga: iossm: refactor return value handling Michael Tretter
2026-04-07 17:10 ` [PATCH 07/10] arm: socfgpa: iossm: extract poll_bist_mem_init_status Michael Tretter
2026-04-07 17:10 ` [PATCH 08/10] arm: socfgpa: iossm: extract initialization of one interface Michael Tretter
2026-04-07 17:10 ` Michael Tretter [this message]
2026-04-07 17:10 ` [PATCH 10/10] arm: socfpga: iossm: add support for mailbox v1 Michael Tretter

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=20260407-socfpga-iossm-v1-v1-9-6440a5337eff@pengutronix.de \
    --to=m.tretter@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.de \
    --cc=s.trumtrar@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox