From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: barebox@lists.infradead.org, Sascha Hauer <s.hauer@pengutronix.de>
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>,
David Jander <david@protonic.nl>
Subject: [PATCH v4 2/4] arm: mach-imx: esdctl.c: Add support for imx8mp inline ECC
Date: Mon, 16 Mar 2026 09:14:32 +0100 [thread overview]
Message-ID: <20260316-v2026-02-0-topic-imx8-ecc-v4-2-e5ecc09cfafd@pengutronix.de> (raw)
In-Reply-To: <20260316-v2026-02-0-topic-imx8-ecc-v4-0-e5ecc09cfafd@pengutronix.de>
From: David Jander <david@protonic.nl>
This adds support for detecting the use of inline ECC and compute the
correct memory bank(s) in that case.
In case inline ECC is active the memory map is modified as follows:
The total memory size is reduced to 7/8th of the raw memory size.
If a reduced-address-space type RAM is used (0.75, 1.5, 3, 6... GiB), then
the whole address space is split up into 3 equal parts, separated by 1/3rd
of the raw address space, but each 7/8th that size.
The ECC area at the end of each part is not addressable and must be
excluded from the map.
Signed-off-by: David Jander <david@protonic.nl>
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
arch/arm/mach-imx/Kconfig | 10 +++++++
arch/arm/mach-imx/esdctl.c | 73 +++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig
index 2e4d1ac80a..377b74b31f 100644
--- a/arch/arm/mach-imx/Kconfig
+++ b/arch/arm/mach-imx/Kconfig
@@ -1060,6 +1060,16 @@ config HABV3_IMG_CRT_DER
endif
+config IMX8MP_DRAM_ECC
+ bool
+ depends on ARCH_IMX8MP
+ help
+ This option is selected by boards that make use of the inline ECC
+ support for LPDDR4 memory on i.MX8MP SoCs. For board images that
+ configure ECC, the total amount of memory available will be reduced by
+ 1/8th.
+ Boards that don't explicitly make use of it are not affected.
+
endmenu
endif
diff --git a/arch/arm/mach-imx/esdctl.c b/arch/arm/mach-imx/esdctl.c
index bad5064d14..21fee174a9 100644
--- a/arch/arm/mach-imx/esdctl.c
+++ b/arch/arm/mach-imx/esdctl.c
@@ -334,6 +334,9 @@ static int vf610_ddrmc_add_mem(void *mmdcbase, const struct imx_esdctl_data *dat
#define DDRC_MSTR_ACTIVE_RANKS GENMASK(27, 24)
#define DDRC_MSTR_DEVICE_CONFIG GENMASK(31, 30)
+#define DDRC_ECCCFG0 0x0070
+#define DDRC_ECCCFG0_ECC_MODE GENMASK(2, 0)
+
#define DDRC_ADDRMAP0_CS_BIT1 GENMASK(12, 8)
#define DDRC_ADDRMAP1_BANK_B2 GENMASK(20, 16)
@@ -364,6 +367,11 @@ static int vf610_ddrmc_add_mem(void *mmdcbase, const struct imx_esdctl_data *dat
#define DDRC_ADDRMAP_LENGTH 9
+static inline int imx_esdctl_ecc_enabled(void __iomem *ddrc)
+{
+ return FIELD_GET(DDRC_ECCCFG0_ECC_MODE, readl(ddrc + DDRC_ECCCFG0));
+}
+
static unsigned int
imx_ddrc_count_bits(unsigned int bits, const u8 config[],
unsigned int config_num)
@@ -522,6 +530,35 @@ resource_size_t imx8m_ddrc_sdram_size(unsigned buswidth)
reduced_address_space, mstr);
}
+static resource_size_t imx8m_ddrc_ecc_sdram_size(unsigned int *chunks,
+ resource_size_t *stride,
+ unsigned int buswidth)
+{
+ void __iomem *ddrc = IOMEM(MX8M_DDRC_CTL_BASE_ADDR);
+ resource_size_t size = imx8m_ddrc_sdram_size(buswidth);
+ const bool reduced_address_space = FIELD_GET(
+ DDRC_ADDRMAP6_LPDDR4_6GB_12GB_24GB, readl(ddrc + DDRC_ADDRMAP(6)));
+
+ /* ECC divides the accessible address space into 1 or 3 contiguous
+ * regions depending on reduced_address_space. For simplicity, give
+ * barebox only one contiguous region to use.
+ * Each region is only 7/8th the raw size due to ECC data.
+ */
+ if (chunks)
+ *chunks = 1;
+ if (imx_esdctl_ecc_enabled(ddrc)) {
+ if (reduced_address_space) {
+ size /= 3;
+ if (chunks)
+ *chunks = 3;
+ if (stride)
+ *stride = size;
+ }
+ size = (size * 7) / 8;
+ }
+ return size;
+}
+
static int _imx8m_ddrc_add_mem(const struct imx_esdctl_data *data,
unsigned int buswidth)
{
@@ -562,6 +599,29 @@ static int imx8m_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data
return _imx8m_ddrc_add_mem(data, 32);
}
+static int imx8mp_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
+{
+ unsigned int chunks;
+ unsigned long base;
+ resource_size_t chunksize = 0, stride = 0;
+ int ret = -ENOMEM;
+ int i;
+ char name[5];
+
+ chunksize = imx8m_ddrc_ecc_sdram_size(&chunks, &stride, 32);
+
+ base = data->base0;
+ for (i = 0; i < chunks; i++) {
+ snprintf(name, sizeof(name), "ram%d", i);
+ ret = arm_add_mem_device(name, base, chunksize);
+ if (ret)
+ break;
+ base += stride;
+ }
+
+ return ret;
+}
+
static int imx8mn_ddrc_add_mem(void *mmdcbase, const struct imx_esdctl_data *data)
{
return _imx8m_ddrc_add_mem(data, 16);
@@ -745,6 +805,11 @@ static __maybe_unused const struct imx_esdctl_data imx8mn_data = {
.add_mem = imx8mn_ddrc_add_mem,
};
+static __maybe_unused const struct imx_esdctl_data imx8mp_data = {
+ .base0 = MX8M_DDR_CSD1_BASE_ADDR,
+ .add_mem = imx8mp_ddrc_add_mem,
+};
+
static __maybe_unused const struct imx_esdctl_data imx9_data = {
.base0 = MX9_DDR_CSD1_BASE_ADDR,
.add_mem = imx9_ddrc_add_mem,
@@ -825,6 +890,9 @@ static __maybe_unused struct of_device_id imx_esdctl_dt_ids[] = {
}, {
.compatible = "fsl,imx8mn-ddrc",
.data = &imx8mn_data
+ }, {
+ .compatible = "fsl,imx8mp-ddrc",
+ .data = &imx8mp_data
}, {
.compatible = "fsl,imx93-ddrc",
.data = &imx9_data
@@ -1084,7 +1152,10 @@ resource_size_t imx8m_barebox_earlymem_size(unsigned buswidth)
{
resource_size_t size;
- size = imx8m_ddrc_sdram_size(buswidth);
+ if (imx_esdctl_ecc_enabled(IOMEM(MX8M_DDRC_CTL_BASE_ADDR)))
+ size = imx8m_ddrc_ecc_sdram_size(NULL, NULL, buswidth);
+ else
+ size = imx8m_ddrc_sdram_size(buswidth);
/*
* We artificially limit detected memory size to force malloc
* pool placement to be within 4GiB address space, so as to
--
2.52.0
next prev parent reply other threads:[~2026-03-16 8:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-16 8:14 [PATCH v4 0/4] ARM: i.MX8: add DDRC-ECC support Steffen Trumtrar
2026-03-16 8:14 ` [PATCH v4 1/4] ARM: i.MX: esdctl: fix spelling of ad(d)ress Steffen Trumtrar
2026-03-16 8:14 ` Steffen Trumtrar [this message]
2026-03-16 8:14 ` [PATCH v4 3/4] drivers: ddr: imx8m: ddr_init.c: support ECC scrubbing Steffen Trumtrar
2026-03-16 8:14 ` [PATCH v4 4/4] arm: boards: protonic-imx8ml: Add ECC + scrubbing Steffen Trumtrar
2026-03-17 10:22 ` [PATCH v4 0/4] ARM: i.MX8: add DDRC-ECC support Sascha Hauer
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=20260316-v2026-02-0-topic-imx8-ecc-v4-2-e5ecc09cfafd@pengutronix.de \
--to=s.trumtrar@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=david@protonic.nl \
--cc=s.hauer@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