Skip to content

Commit 03096a4

Browse files
superna9999Sasha Levin
authored andcommitted
mmc: meson-gx: use memcpy_to/fromio for dram-access-quirk
commit 103a534 upstream. It has been reported that usage of memcpy() to/from an iomem mapping is invalid, and a recent arm64 memcpy update [1] triggers a memory abort when dram-access-quirk is used on the G12A/G12B platforms. This adds a local sg_copy_to_buffer which makes usage of io versions of memcpy when dram-access-quirk is enabled. [1] 2851330 ("arm64: Import latest memcpy()/memmove() implementation") Fixes: acdc8e7 ("mmc: meson-gx: add dram-access-quirk") Reported-by: Marek Szyprowski <m.szyprowski@samsung.com> Suggested-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Link: https://lore.kernel.org/r/20210609150230.9291-1-narmstrong@baylibre.com Cc: stable@vger.kernel.org Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b8fd230 commit 03096a4

1 file changed

Lines changed: 45 additions & 5 deletions

File tree

‎drivers/mmc/host/meson-gx-mmc.c‎

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ struct meson_host {
165165

166166
unsigned int bounce_buf_size;
167167
void *bounce_buf;
168+
void __iomem *bounce_iomem_buf;
168169
dma_addr_t bounce_dma_addr;
169170
struct sd_emmc_desc *descs;
170171
dma_addr_t descs_dma_addr;
@@ -734,6 +735,47 @@ static void meson_mmc_desc_chain_transfer(struct mmc_host *mmc, u32 cmd_cfg)
734735
writel(start, host->regs + SD_EMMC_START);
735736
}
736737

738+
/* local sg copy to buffer version with _to/fromio usage for dram_access_quirk */
739+
static void meson_mmc_copy_buffer(struct meson_host *host, struct mmc_data *data,
740+
size_t buflen, bool to_buffer)
741+
{
742+
unsigned int sg_flags = SG_MITER_ATOMIC;
743+
struct scatterlist *sgl = data->sg;
744+
unsigned int nents = data->sg_len;
745+
struct sg_mapping_iter miter;
746+
unsigned int offset = 0;
747+
748+
if (to_buffer)
749+
sg_flags |= SG_MITER_FROM_SG;
750+
else
751+
sg_flags |= SG_MITER_TO_SG;
752+
753+
sg_miter_start(&miter, sgl, nents, sg_flags);
754+
755+
while ((offset < buflen) && sg_miter_next(&miter)) {
756+
unsigned int len;
757+
758+
len = min(miter.length, buflen - offset);
759+
760+
/* When dram_access_quirk, the bounce buffer is a iomem mapping */
761+
if (host->dram_access_quirk) {
762+
if (to_buffer)
763+
memcpy_toio(host->bounce_iomem_buf + offset, miter.addr, len);
764+
else
765+
memcpy_fromio(miter.addr, host->bounce_iomem_buf + offset, len);
766+
} else {
767+
if (to_buffer)
768+
memcpy(host->bounce_buf + offset, miter.addr, len);
769+
else
770+
memcpy(miter.addr, host->bounce_buf + offset, len);
771+
}
772+
773+
offset += len;
774+
}
775+
776+
sg_miter_stop(&miter);
777+
}
778+
737779
static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd)
738780
{
739781
struct meson_host *host = mmc_priv(mmc);
@@ -777,8 +819,7 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd)
777819
if (data->flags & MMC_DATA_WRITE) {
778820
cmd_cfg |= CMD_CFG_DATA_WR;
779821
WARN_ON(xfer_bytes > host->bounce_buf_size);
780-
sg_copy_to_buffer(data->sg, data->sg_len,
781-
host->bounce_buf, xfer_bytes);
822+
meson_mmc_copy_buffer(host, data, xfer_bytes, true);
782823
dma_wmb();
783824
}
784825

@@ -947,8 +988,7 @@ static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id)
947988
if (meson_mmc_bounce_buf_read(data)) {
948989
xfer_bytes = data->blksz * data->blocks;
949990
WARN_ON(xfer_bytes > host->bounce_buf_size);
950-
sg_copy_from_buffer(data->sg, data->sg_len,
951-
host->bounce_buf, xfer_bytes);
991+
meson_mmc_copy_buffer(host, data, xfer_bytes, false);
952992
}
953993

954994
next_cmd = meson_mmc_get_next_command(cmd);
@@ -1168,7 +1208,7 @@ static int meson_mmc_probe(struct platform_device *pdev)
11681208
* instead of the DDR memory
11691209
*/
11701210
host->bounce_buf_size = SD_EMMC_SRAM_DATA_BUF_LEN;
1171-
host->bounce_buf = host->regs + SD_EMMC_SRAM_DATA_BUF_OFF;
1211+
host->bounce_iomem_buf = host->regs + SD_EMMC_SRAM_DATA_BUF_OFF;
11721212
host->bounce_dma_addr = res->start + SD_EMMC_SRAM_DATA_BUF_OFF;
11731213
} else {
11741214
/* data bounce buffer */

0 commit comments

Comments
 (0)