[PATCH v1 7/7] mci: imx-esdhc: support DMA in the i.MX8M PBL eMMC loader
Johannes Schneider <[email protected]> Sat, 27 Jun 2026 19:43:24 +0000
| Newsgroups | org.infradead.lists.barebox |
|---|---|
| Message-ID | <[email protected]> |
The PBL eMMC loader was hardwired to PIO via esdhc_use_pio_mode(): IN_PBL forced PIO unconditionally. PIO is slow -- on an i.MX8MM board loading the ~1.6 MB next stage took ~559 ms; SDMA/ADMA2 do it in ~21 ms. Let esdhc_use_pio_mode() in the PBL honour the SDHCI DMA flags, add a transfer-mode choice for the loader (PIO default / SDMA / ADMA2), and route both the imx8m and imx8mp/imx8mn loaders through shared helpers. The PBL has no mci and runs before BL31, so host.sdhci.version is set by hand (no __sdhci_read_caps()) and the ADMA2 descriptor table lives in a static buffer (the PBL has no allocator), compiled in only for the ADMA2 option. On the imx8mp loader the DMA mode is set up *before* the bootpart EXT_CSD read so that read also goes through ADMA: a PIO transfer preceding the first ADMA transfer wedges the uSDHC ADMA engine. Either way the loader retries in PIO if the DMA attempt fails, so a misconfigured board still boots. SDMA and ADMA2 perform identically here (the transfer is bus-bound), and SDMA needs no descriptor table, so it is the simpler default for boards that just want the speedup. Assisted-by: Claude Opus 4.8 (1M context) Signed-off-by: Johannes Schneider <[email protected]> --- drivers/mci/Kconfig | 21 +++++++++++ drivers/mci/imx-esdhc-common.c | 16 ++++++-- drivers/mci/imx-esdhc-pbl.c | 68 +++++++++++++++++++++++++++++++--- 3 files changed, 96 insertions(+), 9 deletions(-) diff --git a/drivers/mci/Kconfig b/drivers/mci/Kconfig index cd8862722c..e071bb5650 100644 --- a/drivers/mci/Kconfig +++ b/drivers/mci/Kconfig @@ -288,6 +288,27 @@ config MCI_IMX_ESDHC_PBL bool select MCI_SDHCI +choice + prompt "i.MX8M PBL eMMC loader transfer mode" + default MCI_IMX_ESDHC_PBL_PIO + depends on MCI_IMX_ESDHC_PBL + help + How the i.MX8M PBL reads the next boot stage from eMMC. DMA is much + faster than PIO; on failure the loader falls back to PIO so the board + still boots. ADMA2 additionally needs the board PBL to set up an early + malloc pool (pbl_malloc_init) for the descriptor table; SDMA does not. + +config MCI_IMX_ESDHC_PBL_PIO + bool "PIO" + +config MCI_IMX_ESDHC_PBL_SDMA + bool "SDMA" + +config MCI_IMX_ESDHC_PBL_ADMA2 + bool "ADMA2" + +endchoice + config MCI_ATMEL_PBL bool select MCI_ATMEL diff --git a/drivers/mci/imx-esdhc-common.c b/drivers/mci/imx-esdhc-common.c index a0c2dee32d..1bf70d4e65 100644 --- a/drivers/mci/imx-esdhc-common.c +++ b/drivers/mci/imx-esdhc-common.c @@ -295,9 +295,17 @@ void esdhc_populate_sdhci(struct fsl_esdhc_host *host) SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC; } -static bool esdhc_use_pio_mode(void) +static bool esdhc_use_pio_mode(struct fsl_esdhc_host *host) { - return IN_PBL || IS_ENABLED(CONFIG_MCI_IMX_ESDHC_PIO); + /* + * In the PBL default to PIO, unless a caller explicitly opted into + * ADMA2 (SDHCI_USE_ADMA, descriptor table set up) or SDMA + * (SDHCI_USE_SDMA). + */ + if (IN_PBL) + return !(host->sdhci.flags & (SDHCI_USE_ADMA | SDHCI_USE_SDMA)); + + return IS_ENABLED(CONFIG_MCI_IMX_ESDHC_PIO); } static int esdhc_setup_data(struct fsl_esdhc_host *host, struct mci_data *data, @@ -317,7 +325,7 @@ static int esdhc_setup_data(struct fsl_esdhc_host *host, struct mci_data *data, host->sdhci.sdma_boundary = 0; - if (esdhc_use_pio_mode()) + if (esdhc_use_pio_mode(host)) sdhci_setup_data_pio(&host->sdhci, data); else sdhci_setup_data_dma(&host->sdhci, data, dma); @@ -411,7 +419,7 @@ int __esdhc_send_cmd(struct fsl_esdhc_host *host, struct mci_cmd *cmd, /* Wait until all of the blocks are transferred */ if (data) { - if (esdhc_use_pio_mode()) + if (esdhc_use_pio_mode(host)) ret = sdhci_transfer_data_pio(&host->sdhci, cmd, data); else ret = sdhci_transfer_data_dma(&host->sdhci, cmd, data, dma); diff --git a/drivers/mci/imx-esdhc-pbl.c b/drivers/mci/imx-esdhc-pbl.c index fe06d418b0..80e80b24a0 100644 --- a/drivers/mci/imx-esdhc-pbl.c +++ b/drivers/mci/imx-esdhc-pbl.c @@ -33,6 +33,12 @@ static u8 ext_csd[512] __aligned(64); +#ifdef CONFIG_MCI_IMX_ESDHC_PBL_ADMA2 +/* ADMA2 descriptor table for the PBL eMMC loader (the PBL has no allocator). */ +static u8 esdhc_adma_table[SDHCI_DEFAULT_ADMA_DESCS * SDHCI_ADMA2_32_DESC_SZ] + __aligned(8); +#endif + static int esdhc_send_ext_csd(struct fsl_esdhc_host *host) { struct mci_cmd cmd = {}; @@ -252,6 +258,51 @@ int imx7_esdhc_start_image(int instance) * Return: If image successfully loaded, returns 0. * A negative error code is returned when this function fails. */ +/* + * Configure the PBL eMMC loader's DMA mode (ADMA2 or SDMA per Kconfig). The + * PBL has no mci, so host->sdhci.version is set by hand because + * __sdhci_read_caps() cannot run. + */ +static void imx8m_esdhc_pbl_setup_dma(struct fsl_esdhc_host *host) +{ + if (IS_ENABLED(CONFIG_MCI_IMX_ESDHC_PBL_SDMA)) { + host->sdhci.version = SDHCI_SPEC_300; + host->sdhci.flags |= SDHCI_USE_SDMA; + } + +#ifdef CONFIG_MCI_IMX_ESDHC_PBL_ADMA2 + host->sdhci.version = SDHCI_SPEC_300; + host->sdhci.adma_table = esdhc_adma_table; + host->sdhci.adma_addr = virt_to_phys(esdhc_adma_table); + host->sdhci.desc_sz = SDHCI_ADMA2_32_DESC_SZ; + host->sdhci.adma_table_cnt = SDHCI_DEFAULT_ADMA_DESCS; + host->sdhci.adma_table_sz = sizeof(esdhc_adma_table); + host->sdhci.flags |= SDHCI_USE_ADMA; +#endif +} + +static int imx8m_esdhc_load_image_dma(struct fsl_esdhc_host *host, + struct esdhc_soc_data *data, int instance, + void *bl33, u32 offset, u32 ivt_offset) +{ + int ret; + + ret = esdhc_load_image(host, MX8M_DDR_CSD1_BASE_ADDR, + (ptrdiff_t)bl33, offset, ivt_offset, false); + if (!ret) + return 0; + + /* Fall back to PIO so a failed DMA attempt still boots. */ + if (host->sdhci.flags & (SDHCI_USE_ADMA | SDHCI_USE_SDMA)) { + host->sdhci.flags &= ~(SDHCI_USE_ADMA | SDHCI_USE_SDMA); + imx8m_esdhc_init(host, data, instance); + ret = esdhc_load_image(host, MX8M_DDR_CSD1_BASE_ADDR, + (ptrdiff_t)bl33, offset, ivt_offset, false); + } + + return ret; +} + int imx8m_esdhc_load_image(int instance, void *bl33) { struct esdhc_soc_data data; @@ -262,9 +313,10 @@ int imx8m_esdhc_load_image(int instance, void *bl33) if (ret) return ret; - return esdhc_load_image(&host, MX8M_DDR_CSD1_BASE_ADDR, - (ptrdiff_t)bl33, SZ_32K, SZ_1K, - false); + imx8m_esdhc_pbl_setup_dma(&host); + + return imx8m_esdhc_load_image_dma(&host, &data, instance, bl33, + SZ_32K, SZ_1K); } /** @@ -291,10 +343,16 @@ int imx8mp_esdhc_load_image(int instance, void *bl33) if (ret) return ret; + /* + * Set up DMA first so the EXT_CSD read below also goes through ADMA -- + * a PIO transfer before the first ADMA transfer wedges the 8MP uSDHC. + */ + imx8m_esdhc_pbl_setup_dma(&host); + offset = esdhc_bootpart_active(&host)? 0 : SZ_32K; - return esdhc_load_image(&host, MX8M_DDR_CSD1_BASE_ADDR, - (ptrdiff_t)bl33, offset, 0, false); + return imx8m_esdhc_load_image_dma(&host, &data, instance, bl33, + offset, 0); } int imx8mn_esdhc_load_image(int instance, void *bl33) -- 2.43.0