Message ID | 20210628123411.119778-3-narmstrong@baylibre.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | scatterlist: add I/O variant of sg_pcopy & sg_copy and use them | expand |
On 2021-06-28 13:34, Neil Armstrong wrote: > Use the proper sg_copy_to_io & sg_copy_from_io instead of having a local > sg_copy_buffer variant to handle the I/O mapped buffer case. > > Cc: Robin Murphy <robin.murphy@arm.com> > Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> > --- > drivers/mmc/host/meson-gx-mmc.c | 53 +++++++-------------------------- > 1 file changed, 10 insertions(+), 43 deletions(-) > > diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c > index 3f28eb4d17fe..c13436efb414 100644 > --- a/drivers/mmc/host/meson-gx-mmc.c > +++ b/drivers/mmc/host/meson-gx-mmc.c > @@ -746,47 +746,6 @@ static void meson_mmc_desc_chain_transfer(struct mmc_host *mmc, u32 cmd_cfg) > writel(start, host->regs + SD_EMMC_START); > } > > -/* local sg copy to buffer version with _to/fromio usage for dram_access_quirk */ > -static void meson_mmc_copy_buffer(struct meson_host *host, struct mmc_data *data, > - size_t buflen, bool to_buffer) > -{ > - unsigned int sg_flags = SG_MITER_ATOMIC; > - struct scatterlist *sgl = data->sg; > - unsigned int nents = data->sg_len; > - struct sg_mapping_iter miter; > - unsigned int offset = 0; > - > - if (to_buffer) > - sg_flags |= SG_MITER_FROM_SG; > - else > - sg_flags |= SG_MITER_TO_SG; > - > - sg_miter_start(&miter, sgl, nents, sg_flags); > - > - while ((offset < buflen) && sg_miter_next(&miter)) { > - unsigned int len; > - > - len = min(miter.length, buflen - offset); > - > - /* When dram_access_quirk, the bounce buffer is a iomem mapping */ > - if (host->dram_access_quirk) { > - if (to_buffer) > - memcpy_toio(host->bounce_iomem_buf + offset, miter.addr, len); > - else > - memcpy_fromio(miter.addr, host->bounce_iomem_buf + offset, len); > - } else { > - if (to_buffer) > - memcpy(host->bounce_buf + offset, miter.addr, len); > - else > - memcpy(miter.addr, host->bounce_buf + offset, len); > - } > - > - offset += len; > - } > - > - sg_miter_stop(&miter); > -} > - > static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) > { > struct meson_host *host = mmc_priv(mmc); > @@ -830,7 +789,12 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) > if (data->flags & MMC_DATA_WRITE) { > cmd_cfg |= CMD_CFG_DATA_WR; > WARN_ON(xfer_bytes > host->bounce_buf_size); > - meson_mmc_copy_buffer(host, data, xfer_bytes, true); > + if (host->dram_access_quirk) > + sg_copy_to_io(data->sg, data->sg_len, > + host->bounce_iomem_buf, xfer_bytes); Maybe you could just use host->regs + SD_EMMC_SRAM_DATA_BUF_OFF directly here (and below) and save carrying host->bounce_iomem_buf around? Robin. > + else > + sg_copy_to_buffer(data->sg, data->sg_len, > + host->bounce_buf, xfer_bytes); > dma_wmb(); > } > > @@ -999,7 +963,10 @@ static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id) > if (meson_mmc_bounce_buf_read(data)) { > xfer_bytes = data->blksz * data->blocks; > WARN_ON(xfer_bytes > host->bounce_buf_size); > - meson_mmc_copy_buffer(host, data, xfer_bytes, false); > + if (host->dram_access_quirk) > + sg_copy_from_io(data->sg, data->sg_len, host->bounce_iomem_buf, xfer_bytes); > + else > + sg_copy_from_buffer(data->sg, data->sg_len, host->bounce_buf, xfer_bytes); > } > > next_cmd = meson_mmc_get_next_command(cmd); >
diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index 3f28eb4d17fe..c13436efb414 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -746,47 +746,6 @@ static void meson_mmc_desc_chain_transfer(struct mmc_host *mmc, u32 cmd_cfg) writel(start, host->regs + SD_EMMC_START); } -/* local sg copy to buffer version with _to/fromio usage for dram_access_quirk */ -static void meson_mmc_copy_buffer(struct meson_host *host, struct mmc_data *data, - size_t buflen, bool to_buffer) -{ - unsigned int sg_flags = SG_MITER_ATOMIC; - struct scatterlist *sgl = data->sg; - unsigned int nents = data->sg_len; - struct sg_mapping_iter miter; - unsigned int offset = 0; - - if (to_buffer) - sg_flags |= SG_MITER_FROM_SG; - else - sg_flags |= SG_MITER_TO_SG; - - sg_miter_start(&miter, sgl, nents, sg_flags); - - while ((offset < buflen) && sg_miter_next(&miter)) { - unsigned int len; - - len = min(miter.length, buflen - offset); - - /* When dram_access_quirk, the bounce buffer is a iomem mapping */ - if (host->dram_access_quirk) { - if (to_buffer) - memcpy_toio(host->bounce_iomem_buf + offset, miter.addr, len); - else - memcpy_fromio(miter.addr, host->bounce_iomem_buf + offset, len); - } else { - if (to_buffer) - memcpy(host->bounce_buf + offset, miter.addr, len); - else - memcpy(miter.addr, host->bounce_buf + offset, len); - } - - offset += len; - } - - sg_miter_stop(&miter); -} - static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) { struct meson_host *host = mmc_priv(mmc); @@ -830,7 +789,12 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) if (data->flags & MMC_DATA_WRITE) { cmd_cfg |= CMD_CFG_DATA_WR; WARN_ON(xfer_bytes > host->bounce_buf_size); - meson_mmc_copy_buffer(host, data, xfer_bytes, true); + if (host->dram_access_quirk) + sg_copy_to_io(data->sg, data->sg_len, + host->bounce_iomem_buf, xfer_bytes); + else + sg_copy_to_buffer(data->sg, data->sg_len, + host->bounce_buf, xfer_bytes); dma_wmb(); } @@ -999,7 +963,10 @@ static irqreturn_t meson_mmc_irq_thread(int irq, void *dev_id) if (meson_mmc_bounce_buf_read(data)) { xfer_bytes = data->blksz * data->blocks; WARN_ON(xfer_bytes > host->bounce_buf_size); - meson_mmc_copy_buffer(host, data, xfer_bytes, false); + if (host->dram_access_quirk) + sg_copy_from_io(data->sg, data->sg_len, host->bounce_iomem_buf, xfer_bytes); + else + sg_copy_from_buffer(data->sg, data->sg_len, host->bounce_buf, xfer_bytes); } next_cmd = meson_mmc_get_next_command(cmd);
Use the proper sg_copy_to_io & sg_copy_from_io instead of having a local sg_copy_buffer variant to handle the I/O mapped buffer case. Cc: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Neil Armstrong <narmstrong@baylibre.com> --- drivers/mmc/host/meson-gx-mmc.c | 53 +++++++-------------------------- 1 file changed, 10 insertions(+), 43 deletions(-)