Message ID | 20240127-mmc-proper-kmap-v2-8-d8e732aa97d1@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | mmc: Use proper sg_miter for scatterlists | expand |
On 27/01/24 02:19, Linus Walleij wrote: > Use sg_miter iterator instead of sg_virt() and custom code > to loop over the scatterlist. The memory iterator will do > bounce buffering if the page happens to be located in high memory, > which the driver may or may not be using. > > Suggested-by: Christoph Hellwig <hch@lst.de> > Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ > Signed-off-by: Linus Walleij <linus.walleij@linaro.org> > --- > drivers/mmc/host/sdhci-esdhc-mcf.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/drivers/mmc/host/sdhci-esdhc-mcf.c b/drivers/mmc/host/sdhci-esdhc-mcf.c > index a07f8333cd6b..1909a11fd065 100644 > --- a/drivers/mmc/host/sdhci-esdhc-mcf.c > +++ b/drivers/mmc/host/sdhci-esdhc-mcf.c > @@ -299,9 +299,8 @@ static void esdhc_mcf_pltfm_set_bus_width(struct sdhci_host *host, int width) > static void esdhc_mcf_request_done(struct sdhci_host *host, > struct mmc_request *mrq) > { > - struct scatterlist *sg; > + struct sg_mapping_iter sgm; > u32 *buffer; > - int i; > > if (!mrq->data || !mrq->data->bytes_xfered) > goto exit_done; > @@ -313,10 +312,13 @@ static void esdhc_mcf_request_done(struct sdhci_host *host, > * On mcf5441x there is no hw sdma option/flag to select the dma > * transfer endiannes. A swap after the transfer is needed. > */ > - for_each_sg(mrq->data->sg, sg, mrq->data->sg_len, i) { > - buffer = (u32 *)sg_virt(sg); > - esdhc_mcf_buffer_swap32(buffer, sg->length); > + sg_miter_start(&sgm, mrq->data->sg, mrq->data->sg_len, > + SG_MITER_TO_SG | SG_MITER_FROM_SG); Could be called from atomic context, so probably needs SG_MITER_ATOMIC > + while (sg_miter_next(&sgm)) { > + buffer = sgm.addr; > + esdhc_mcf_buffer_swap32(buffer, sgm.length); > } > + sg_miter_stop(&sgm); > > exit_done: > mmc_request_done(host->mmc, mrq); >
diff --git a/drivers/mmc/host/sdhci-esdhc-mcf.c b/drivers/mmc/host/sdhci-esdhc-mcf.c index a07f8333cd6b..1909a11fd065 100644 --- a/drivers/mmc/host/sdhci-esdhc-mcf.c +++ b/drivers/mmc/host/sdhci-esdhc-mcf.c @@ -299,9 +299,8 @@ static void esdhc_mcf_pltfm_set_bus_width(struct sdhci_host *host, int width) static void esdhc_mcf_request_done(struct sdhci_host *host, struct mmc_request *mrq) { - struct scatterlist *sg; + struct sg_mapping_iter sgm; u32 *buffer; - int i; if (!mrq->data || !mrq->data->bytes_xfered) goto exit_done; @@ -313,10 +312,13 @@ static void esdhc_mcf_request_done(struct sdhci_host *host, * On mcf5441x there is no hw sdma option/flag to select the dma * transfer endiannes. A swap after the transfer is needed. */ - for_each_sg(mrq->data->sg, sg, mrq->data->sg_len, i) { - buffer = (u32 *)sg_virt(sg); - esdhc_mcf_buffer_swap32(buffer, sg->length); + sg_miter_start(&sgm, mrq->data->sg, mrq->data->sg_len, + SG_MITER_TO_SG | SG_MITER_FROM_SG); + while (sg_miter_next(&sgm)) { + buffer = sgm.addr; + esdhc_mcf_buffer_swap32(buffer, sgm.length); } + sg_miter_stop(&sgm); exit_done: mmc_request_done(host->mmc, mrq);
Use sg_miter iterator instead of sg_virt() and custom code to loop over the scatterlist. The memory iterator will do bounce buffering if the page happens to be located in high memory, which the driver may or may not be using. Suggested-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/linux-mmc/20240122073423.GA25859@lst.de/ Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/mmc/host/sdhci-esdhc-mcf.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)