mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Johannes Schneider <johannes.schneider@leica-geosystems.com>
To: barebox@lists.infradead.org
Cc: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Subject: [PATCH v2 10/11] mci: sdhci: honour dma_map/dma_sync in the PBL
Date: Sat,  4 Jul 2026 12:26:27 +0000	[thread overview]
Message-ID: <20260704122628.3326142-11-johannes.schneider@leica-geosystems.com> (raw)
In-Reply-To: <20260704122628.3326142-1-johannes.schneider@leica-geosystems.com>

The SDHCI DMA path already funnels through dma_map_single() (invalidate
the destination before a read) and dma_unmap_single() (invalidate it
again afterwards), but two things kept that from working in the PBL:

  - sdhci_teardown_data() short-circuited on IN_PBL, so the post-transfer
    invalidate never ran. Drop the IN_PBL guard; with CONFIG_PBL_HAS_DMA
    dma_unmap_single() now does the cache maintenance, and without it the
    call is a no-op stub, so a plain PBL is unaffected.

  - the ADMA2 descriptor table in the PBL is a plain buffer (cacheable
    once the MMU is on) rather than the dma_alloc_coherent() region used
    in barebox proper, so the CPU-written descriptors could sit in the
    D-cache while the engine reads stale DRAM. Clean the table out to
    memory right after building it. Guarded by IN_PBL (proper keeps its
    coherent table) and a no-op without CONFIG_PBL_HAS_DMA.

Together with CONFIG_PBL_HAS_DMA this makes SDMA and ADMA2 transfers
coherent in the PBL with the MMU on. No functional change for barebox
proper or for a PBL built without PBL_HAS_DMA.

Assisted-by: Claude Opus 4.8 (1M context)
Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>

---

Notes:
    v2:
    - New patch. Wire the SDHCI PBL transfer path to the new PBL DMA API
      (post-transfer invalidate + ADMA descriptor-table flush).

 drivers/mci/sdhci.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/sdhci.c b/drivers/mci/sdhci.c
index 8ed8a59342..8108e0b54f 100644
--- a/drivers/mci/sdhci.c
+++ b/drivers/mci/sdhci.c
@@ -732,6 +732,12 @@ void sdhci_setup_data_dma(struct sdhci *sdhci, struct mci_data *data,
 			return;
 		}
 		sdhci_set_adma_addr(sdhci, sdhci->adma_addr);
+
+		/* PBL descriptor table is cacheable; flush it before the engine reads it. */
+		if (IN_PBL)
+			dma_sync_single_for_device(dev, sdhci->adma_addr,
+						   sdhci->adma_table_sz,
+						   DMA_TO_DEVICE);
 	} else {
 		sdhci_set_sdma_addr(sdhci, *dma);
 	}
@@ -743,7 +749,7 @@ void sdhci_teardown_data(struct sdhci *sdhci,
 	struct device *dev = sdhci_dev(sdhci);
 	unsigned nbytes;
 
-	if (IN_PBL || !data || dma_mapping_error(dev, dma))
+	if (!data || dma_mapping_error(dev, dma))
 		return;
 
 	nbytes = data->blocks * data->blocksize;
-- 
2.43.0




  parent reply	other threads:[~2026-07-04 12:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-04 12:26 [PATCH v2 00/11] i.MX8M: speed up the PBL boot path (MMU, SHA-256, eMMC) Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 01/11] ARM: i.MX8M: enable MMU in PBL around fw-external BL32 verify Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 02/11] crypto: sha256: PBL SHA-256 fast path via pbl/sha256.c Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 03/11] mci: sdhci: bail out on ADMA/transfer errors instead of hanging Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 04/11] mci: sdhci: honor BROKEN_ADMA_ZEROLEN_DESC / NO_ENDATTR_IN_NOPDESC quirks Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 05/11] mci: imx-esdhc: mark the uSDHC ADMA2 descriptor quirks Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 06/11] mci: imx-esdhc: support HS400 and HS400ES on i.MX8M Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 07/11] mci: imx-esdhc: make the transfer mode selectable (PIO/SDMA/ADMA2) Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 08/11] ARM: i.MX8M: enable the MMU before the PBL eMMC load Johannes Schneider
2026-07-04 12:26 ` [PATCH v2 09/11] dma: provide the streaming DMA API in the PBL (opt-in via PBL_HAS_DMA) Johannes Schneider
2026-07-04 12:26 ` Johannes Schneider [this message]
2026-07-04 12:26 ` [PATCH v2 11/11] mci: imx-esdhc: DMA in the i.MX8M PBL eMMC loader Johannes Schneider

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=20260704122628.3326142-11-johannes.schneider@leica-geosystems.com \
    --to=johannes.schneider@leica-geosystems.com \
    --cc=barebox@lists.infradead.org \
    /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