From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org,
Xen-devel <xen-devel@lists.xensource.com>,
the arch/x86 maintainers <x86@kernel.org>,
Ian Campbell <ian.campbell@citrix.com>,
Becky Bruce <beckyb@kernel.crashing.org>,
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Subject: [PATCH 8 of 9] swiotlb: cleanups to swiotlb_bounce()
Date: Mon, 22 Dec 2008 10:26:10 -0800 [thread overview]
Message-ID: <0e514a12d8a05941d55b.1229970370@abulafia.goop.org> (raw)
In-Reply-To: <patchbomb.1229970362@abulafia.goop.org>
Make swiotlb_bounce test each page for highness rather than relying on
CONFIG_HIGHMEM, and a couple of other cleanups.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
lib/swiotlb.c | 61 +++++++++++++++++++++++++++++----------------------------
1 file changed, 32 insertions(+), 29 deletions(-)
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -25,6 +25,7 @@
#include <linux/swiotlb.h>
#include <linux/string.h>
#include <linux/swiotlb.h>
+#include <linux/pfn.h>
#include <linux/types.h>
#include <linux/ctype.h>
#include <linux/highmem.h>
@@ -330,40 +331,42 @@
/*
* Bounce: copy the swiotlb buffer back to the original dma location
*/
-void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
- enum dma_data_direction dir)
+static void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
+ enum dma_data_direction dir)
{
-#ifdef CONFIG_HIGHMEM
- /* The buffer may not have a mapping. Map it in and copy */
- unsigned int offset = ((unsigned long)phys &
- ((1 << PAGE_SHIFT) - 1));
- char *buffer;
- unsigned int sz = 0;
- unsigned long flags;
+ unsigned long pfn = PFN_DOWN(phys);
- while (size) {
- sz = ((PAGE_SIZE - offset) > size) ? size :
- PAGE_SIZE - offset;
- local_irq_save(flags);
- buffer = kmap_atomic(pfn_to_page(phys >> PAGE_SHIFT),
- KM_BOUNCE_READ);
+ if (PageHighMem(pfn_to_page(pfn))) {
+ /* The buffer does not have a mapping. Map it in and copy */
+ unsigned int offset = phys & ~PAGE_MASK;
+ char *buffer;
+ unsigned int sz = 0;
+ unsigned long flags;
+
+ while (size) {
+ sz = min(PAGE_SIZE - offset, size);
+
+ local_irq_save(flags);
+ buffer = kmap_atomic(pfn_to_page(pfn),
+ KM_BOUNCE_READ);
+ if (dir == DMA_TO_DEVICE)
+ memcpy(dma_addr, buffer + offset, sz);
+ else
+ memcpy(buffer + offset, dma_addr, sz);
+ kunmap_atomic(buffer, KM_BOUNCE_READ);
+ local_irq_restore(flags);
+
+ size -= sz;
+ pfn++;
+ dma_addr += sz;
+ offset = 0;
+ }
+ } else {
if (dir == DMA_TO_DEVICE)
- memcpy(dma_addr, buffer + offset, sz);
+ memcpy(dma_addr, phys_to_virt(phys), size);
else
- memcpy(buffer + offset, dma_addr, sz);
- kunmap_atomic(buffer, KM_BOUNCE_READ);
- local_irq_restore(flags);
- size -= sz;
- phys += sz;
- dma_addr += sz;
- offset = 0;
+ memcpy(phys_to_virt(phys), dma_addr, size);
}
-#else
- if (dir == DMA_TO_DEVICE)
- memcpy(dma_addr, phys_to_virt(phys), size);
- else
- memcpy(phys_to_virt(phys), dma_addr, size);
-#endif
}
/*
next prev parent reply other threads:[~2008-12-22 18:29 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-22 18:26 [PATCH 0 of 9] swiotlb: use phys_addr_t for pages Jeremy Fitzhardinge
2008-12-22 18:26 ` [PATCH 1 of 9] revert "swiotlb: support bouncing of HighMem pages." Jeremy Fitzhardinge
2008-12-22 18:26 ` [PATCH 2 of 9] revert "swiotlb: factor out copy to/from device." Jeremy Fitzhardinge
2008-12-22 18:26 ` [PATCH 3 of 9] swiotlb: add hwdev to swiotlb_phys_to_bus Jeremy Fitzhardinge
2008-12-22 18:26 ` [PATCH 4 of 9] swiotlb: Drop SG_ENT_VIRT_ADDRESS macro Jeremy Fitzhardinge
2008-12-22 18:26 ` [PATCH 5 of 9] swiotlb: Rename SG_ENT_PHYS_ADDRESS to SG_ENT_BUS_ADDRESS Jeremy Fitzhardinge
2008-12-22 18:26 ` [PATCH 6 of 9] swiotlb: Store phys address in io_tlb_orig_addr array Jeremy Fitzhardinge
2008-12-22 18:26 ` [PATCH 7 of 9] swiotlb: Add support for systems with highmem Jeremy Fitzhardinge
2008-12-22 18:26 ` Jeremy Fitzhardinge [this message]
2008-12-22 18:26 ` [PATCH 9 of 9] ia64/x86/swiotlb: use enum dma_data_direciton in dma_ops Jeremy Fitzhardinge
2008-12-22 18:43 ` [PATCH 0 of 9] swiotlb: use phys_addr_t for pages FUJITA Tomonori
2008-12-27 10:48 ` Ingo Molnar
2008-12-27 15:06 ` FUJITA Tomonori
2008-12-28 5:01 ` Jeremy Fitzhardinge
2008-12-28 9:50 ` Ingo Molnar
2008-12-27 16:44 ` FUJITA Tomonori
2008-12-27 16:56 ` Ingo Molnar
2008-12-27 17:03 ` FUJITA Tomonori
2008-12-28 5:29 ` FUJITA Tomonori
2008-12-28 7:30 ` Christoph Hellwig
2008-12-28 9:36 ` FUJITA Tomonori
2008-12-28 21:37 ` Benjamin Herrenschmidt
2008-12-28 9:37 ` Ingo Molnar
2008-12-28 10:02 ` FUJITA Tomonori
2008-12-28 10:34 ` Ingo Molnar
2008-12-28 11:00 ` FUJITA Tomonori
2008-12-28 11:56 ` Ingo Molnar
2008-12-28 12:34 ` FUJITA Tomonori
2008-12-28 12:49 ` Ingo Molnar
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=0e514a12d8a05941d55b.1229970370@abulafia.goop.org \
--to=jeremy@goop.org \
--cc=beckyb@kernel.crashing.org \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=ian.campbell@citrix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=x86@kernel.org \
--cc=xen-devel@lists.xensource.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®