From: Christoph Hellwig <hch@lst.de>
To: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Cc: linux-snps-arc@lists.infradead.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org,
Vineet Gupta <Vineet.Gupta1@synopsys.com>,
Alexey Brodkin <Alexey.Brodkin@synopsys.com>,
hch@lst.de
Subject: Re: [PATCH 3/4] ARC: refactor arch/arc/mm/dma.c
Date: Thu, 26 Jul 2018 11:17:32 +0200 [thread overview]
Message-ID: <20180726091731.GC24209@lst.de> (raw)
In-Reply-To: <20180724101001.31965-4-Eugeniy.Paltsev@synopsys.com>
On Tue, Jul 24, 2018 at 01:10:00PM +0300, Eugeniy Paltsev wrote:
> Refactoring, no functional change intended.
Might be worth explaining a bit why you are refactoring it (i.e. what is the
benefit).
>
> Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
> ---
> arch/arc/mm/dma.c | 28 ++++++++++------------------
> 1 file changed, 10 insertions(+), 18 deletions(-)
>
> diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c
> index b693818cd8e5..46584c7c2858 100644
> --- a/arch/arc/mm/dma.c
> +++ b/arch/arc/mm/dma.c
> @@ -27,30 +27,24 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
> struct page *page;
> phys_addr_t paddr;
> void *kvaddr;
> - int need_coh = 1, need_kvaddr = 0;
> + bool need_coh = !(attrs & DMA_ATTR_NON_CONSISTENT);
>
> page = alloc_pages(gfp, order);
> if (!page)
> return NULL;
>
> /* This is linear addr (0x8000_0000 based) */
> paddr = page_to_phys(page);
>
> *dma_handle = paddr;
>
> + /*
> + * - A coherent buffer needs MMU mapping to enforce non-cachability
> + * - A highmem page needs a virtual handle (hence MMU mapping)
> + * independent of cachability.
> + * kvaddr is kernel Virtual address (0x7000_0000 based)
> + */
> + if (PageHighMem(page) || need_coh) {
dma_alloc_attrs clears __GFP_HIGHMEM from the passed in gfp mask, so
you'll never get a highmem page here.
That also means you can merge this conditional with the one for the cache
writeback and invalidation and kill the need_coh flag entirely.
> kvaddr = ioremap_nocache(paddr, size);
> if (kvaddr == NULL) {
> __free_pages(page, order);
> @@ -81,11 +75,9 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr,
> {
> phys_addr_t paddr = dma_handle;
> struct page *page = virt_to_page(paddr);
> - int is_non_coh = 1;
> -
> - is_non_coh = (attrs & DMA_ATTR_NON_CONSISTENT);
> + bool is_coh = !(attrs & DMA_ATTR_NON_CONSISTENT);
>
> - if (PageHighMem(page) || !is_non_coh)
> + if (PageHighMem(page) || is_coh)
> iounmap((void __force __iomem *)vaddr);
>
Same here.
Also if you clean this up it would be great to take the per-device pfn offset
into account, even if that isn't used anywhere on arc yet, that is call
phys_to_dma and dma_to_phys to convert to an from the dma address.
WARNING: multiple messages have this Message-ID (diff)
From: hch@lst.de (Christoph Hellwig)
To: linux-snps-arc@lists.infradead.org
Subject: [PATCH 3/4] ARC: refactor arch/arc/mm/dma.c
Date: Thu, 26 Jul 2018 11:17:32 +0200 [thread overview]
Message-ID: <20180726091731.GC24209@lst.de> (raw)
In-Reply-To: <20180724101001.31965-4-Eugeniy.Paltsev@synopsys.com>
On Tue, Jul 24, 2018@01:10:00PM +0300, Eugeniy Paltsev wrote:
> Refactoring, no functional change intended.
Might be worth explaining a bit why you are refactoring it (i.e. what is the
benefit).
>
> Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev at synopsys.com>
> ---
> arch/arc/mm/dma.c | 28 ++++++++++------------------
> 1 file changed, 10 insertions(+), 18 deletions(-)
>
> diff --git a/arch/arc/mm/dma.c b/arch/arc/mm/dma.c
> index b693818cd8e5..46584c7c2858 100644
> --- a/arch/arc/mm/dma.c
> +++ b/arch/arc/mm/dma.c
> @@ -27,30 +27,24 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
> struct page *page;
> phys_addr_t paddr;
> void *kvaddr;
> - int need_coh = 1, need_kvaddr = 0;
> + bool need_coh = !(attrs & DMA_ATTR_NON_CONSISTENT);
>
> page = alloc_pages(gfp, order);
> if (!page)
> return NULL;
>
> /* This is linear addr (0x8000_0000 based) */
> paddr = page_to_phys(page);
>
> *dma_handle = paddr;
>
> + /*
> + * - A coherent buffer needs MMU mapping to enforce non-cachability
> + * - A highmem page needs a virtual handle (hence MMU mapping)
> + * independent of cachability.
> + * kvaddr is kernel Virtual address (0x7000_0000 based)
> + */
> + if (PageHighMem(page) || need_coh) {
dma_alloc_attrs clears __GFP_HIGHMEM from the passed in gfp mask, so
you'll never get a highmem page here.
That also means you can merge this conditional with the one for the cache
writeback and invalidation and kill the need_coh flag entirely.
> kvaddr = ioremap_nocache(paddr, size);
> if (kvaddr == NULL) {
> __free_pages(page, order);
> @@ -81,11 +75,9 @@ void arch_dma_free(struct device *dev, size_t size, void *vaddr,
> {
> phys_addr_t paddr = dma_handle;
> struct page *page = virt_to_page(paddr);
> - int is_non_coh = 1;
> -
> - is_non_coh = (attrs & DMA_ATTR_NON_CONSISTENT);
> + bool is_coh = !(attrs & DMA_ATTR_NON_CONSISTENT);
>
> - if (PageHighMem(page) || !is_non_coh)
> + if (PageHighMem(page) || is_coh)
> iounmap((void __force __iomem *)vaddr);
>
Same here.
Also if you clean this up it would be great to take the per-device pfn offset
into account, even if that isn't used anywhere on arc yet, that is call
phys_to_dma and dma_to_phys to convert to an from the dma address.
next prev parent reply other threads:[~2018-07-26 9:17 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-24 10:09 [PATCH 0/4] ARC: allow to use IOC and non-IOC DMA devices simultaneously Eugeniy Paltsev
2018-07-24 10:09 ` Eugeniy Paltsev
2018-07-24 10:09 ` [PATCH 1/4] ARC: DTS: mark DMA devices connected through IOC port as dma-coherent Eugeniy Paltsev
2018-07-24 10:09 ` Eugeniy Paltsev
2018-07-24 10:09 ` [PATCH 2/4] ARC: allow to use IOC and non-IOC DMA devices simultaneously Eugeniy Paltsev
2018-07-24 10:09 ` Eugeniy Paltsev
2018-07-26 9:13 ` Christoph Hellwig
2018-07-26 9:13 ` Christoph Hellwig
2018-07-24 10:10 ` [PATCH 3/4] ARC: refactor arch/arc/mm/dma.c Eugeniy Paltsev
2018-07-24 10:10 ` Eugeniy Paltsev
2018-07-26 9:17 ` Christoph Hellwig [this message]
2018-07-26 9:17 ` Christoph Hellwig
2018-07-30 10:34 ` Eugeniy Paltsev
2018-07-30 10:34 ` Eugeniy Paltsev
2018-07-24 10:10 ` [PATCH 4/4] ARC: IOC: panic if both IOC and ZONE_HIGHMEM enabled Eugeniy Paltsev
2018-07-24 10:10 ` Eugeniy Paltsev
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=20180726091731.GC24209@lst.de \
--to=hch@lst.de \
--cc=Alexey.Brodkin@synopsys.com \
--cc=Eugeniy.Paltsev@synopsys.com \
--cc=Vineet.Gupta1@synopsys.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-snps-arc@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.