From: Zhen Lei <thunder.leizhen@huawei.com>
To: Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Cc: Zefan Li <lizefan@huawei.com>, Xinwei Hu <huxinwei@huawei.com>,
"Tianhong Ding" <dingtianhong@huawei.com>,
Hanjun Guo <guohanjun@huawei.com>,
Zhen Lei <thunder.leizhen@huawei.com>
Subject: [PATCH v3 1/1] arm64/dma-mapping: reduce an unnecessary conversion for coherent DMA
Date: Tue, 22 Mar 2016 11:18:29 +0800 [thread overview]
Message-ID: <1458616709-21888-2-git-send-email-thunder.leizhen@huawei.com> (raw)
In-Reply-To: <1458616709-21888-1-git-send-email-thunder.leizhen@huawei.com>
1.For coherent DMA
In swiotlb_alloc_coherent, it directly return vaddr on success, and
pass vaddr to free_pages on failure. So, we can directly transparent pass
vaddr from __dma_free to swiotlb_free_coherent.
According to my testing, it can save 8 clock cycles.
2.For non-coherent DMA.
Keep no change for the original processing flow.
Because all DDR memory mapped as cacheable by default. But for
non-coherent devices, both CPUs and devices should use NC(non-cacheable)
attributes to access memory, to keep consistency. So we can not directly
use vaddr retured by __dma_alloc_coherent, but should further remap the
physical memory as NC and return it. So in __dma_free, we first use the
NC-vaddr to unmap, then get vaddr base upon dma_handle and use it to free
memory back to buddy.
Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com>
---
arch/arm64/mm/dma-mapping.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c
index a6e757c..ceb2018 100644
--- a/arch/arm64/mm/dma-mapping.c
+++ b/arch/arm64/mm/dma-mapping.c
@@ -187,16 +187,22 @@ static void __dma_free(struct device *dev, size_t size,
void *vaddr, dma_addr_t dma_handle,
struct dma_attrs *attrs)
{
- void *swiotlb_addr = phys_to_virt(dma_to_phys(dev, dma_handle));
-
size = PAGE_ALIGN(size);
if (!is_device_dma_coherent(dev)) {
if (__free_from_pool(vaddr, size))
return;
vunmap(vaddr);
+
+ /*
+ * For non-coherent DMA, the vaddr is not part of the linear
+ * mapping as it has been remapped by __dma_alloc() via
+ * dma_common_contiguous_remap(), hence for swiotlb freeing we
+ * need the actual linear map address.
+ */
+ vaddr = phys_to_virt(dma_to_phys(dev, dma_handle));
}
- __dma_free_coherent(dev, size, swiotlb_addr, dma_handle, attrs);
+ __dma_free_coherent(dev, size, vaddr, dma_handle, attrs);
}
static dma_addr_t __swiotlb_map_page(struct device *dev, struct page *page,
--
2.5.0
prev parent reply other threads:[~2016-03-22 3:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-22 3:18 [PATCH v3 0/1] " Zhen Lei
2016-03-22 3:18 ` Zhen Lei [this message]
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=1458616709-21888-2-git-send-email-thunder.leizhen@huawei.com \
--to=thunder.leizhen@huawei.com \
--cc=catalin.marinas@arm.com \
--cc=dingtianhong@huawei.com \
--cc=guohanjun@huawei.com \
--cc=huxinwei@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=will.deacon@arm.com \
/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
all inboxes | Powered by JetHome®