From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Becky Bruce <beckyb@kernel.crashing.org>
Cc: mingo@elte.hu, fujita.tomonori@lab.ntt.co.jp,
linux-kernel@vger.kernel.org, ian.campbell@citrix.com,
jbeulich@novell.com, joerg.roedel@amd.com,
benh@kernel.crashing.org
Subject: Re: [PATCH 07/11] swiotlb: Add support for systems with highmem
Date: Fri, 19 Dec 2008 09:46:29 -0800 [thread overview]
Message-ID: <494BDDF5.1090304@goop.org> (raw)
In-Reply-To: <1229663480-10757-8-git-send-email-beckyb@kernel.crashing.org>
Becky Bruce wrote:
> On highmem systems, the original dma buffer might not
> have a virtual mapping - we need to kmap it in to perform
> the bounce. Extract the code that does the actual
> copy into a function that does the kmap if highmem
> is enabled, and defaults to the normal swiotlb memcpy
> if not.
>
> Signed-off-by: Becky Bruce <beckyb@kernel.crashing.org>
> ---
> lib/swiotlb.c | 53 +++++++++++++++++++++++++++++++++++++++++++++--------
> 1 files changed, 45 insertions(+), 8 deletions(-)
>
> diff --git a/lib/swiotlb.c b/lib/swiotlb.c
> index e9d5bf6..ab5d3d7 100644
> --- a/lib/swiotlb.c
> +++ b/lib/swiotlb.c
> @@ -14,6 +14,7 @@
> * 04/07/.. ak Better overflow handling. Assorted fixes.
> * 05/09/10 linville Add support for syncing ranges, support syncing for
> * DMA_BIDIRECTIONAL mappings, miscellaneous cleanup.
> + * 08/12/11 beckyb Add highmem support
> */
>
> #include <linux/cache.h>
> @@ -24,6 +25,7 @@
> #include <linux/string.h>
> #include <linux/types.h>
> #include <linux/ctype.h>
> +#include <linux/highmem.h>
>
> #include <asm/io.h>
> #include <asm/dma.h>
> @@ -306,6 +308,45 @@ static int is_swiotlb_buffer(char *addr)
> }
>
> /*
> + * 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)
> +{
> +#ifdef CONFIG_HIGHMEM
>
Rather than using #ifdef CONFIG_HIGHMEM, I think it would be better to
use something like:
if (PageHighMem(phys_to_page(phys))) {
/* handle high page */
} else {
/* simple path */
}
This will still exclude all the highmem code on non-highmem systems, and
will use the fast-path for lowmem pages too.
> + /* 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;
> +
> + while (size) {
> + sz = ((PAGE_SIZE - offset) > size) ? size :
> + PAGE_SIZE - offset;
>
sz = min(size, PAGE_SIZE - offset)?
> + local_irq_save(flags);
> + buffer = kmap_atomic(pfn_to_page(phys >> PAGE_SHIFT),
>
phys_to_page() does this for you.
> + 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;
> + phys += sz;
> + dma_addr += sz;
> + offset = 0;
> + }
> +#else
> + if (dir == DMA_TO_DEVICE)
> + memcpy(dma_addr, phys_to_virt(phys), size);
> + else
> + memcpy(phys_to_virt(phys), dma_addr, size);
> +#endif
> +}
>
J
next prev parent reply other threads:[~2008-12-19 17:46 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-16 20:17 [PATCH 00 of 14] swiotlb/x86: lay groundwork for xen dom0 use of swiotlb Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 01 of 14] x86: remove unused iommu_nr_pages Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 02 of 14] swiotlb: allow architectures to override swiotlb pool allocation Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 03 of 14] swiotlb: move some definitions to header Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 04 of 14] swiotlb: consistently use address_needs_mapping everywhere Jeremy Fitzhardinge
2008-12-17 2:48 ` FUJITA Tomonori
2008-12-17 2:51 ` FUJITA Tomonori
2008-12-17 16:43 ` Ian Campbell
2008-12-17 16:40 ` Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 05 of 14] swiotlb: add comment where we handle the overflow of a dma mask on 32 bit Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 06 of 14] swiotlb: allow architectures to override phys<->bus<->phys conversions Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 07 of 14] swiotlb: add arch hook to force mapping Jeremy Fitzhardinge
2008-12-22 5:34 ` FUJITA Tomonori
2008-12-16 20:17 ` [PATCH 08 of 14] swiotlb: factor out copy to/from device Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 09 of 14] swiotlb: support bouncing of HighMem pages Jeremy Fitzhardinge
2008-12-17 2:48 ` FUJITA Tomonori
2008-12-16 20:17 ` [PATCH 10 of 14] swiotlb: consolidate swiotlb info message printing Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 11 of 14] x86: add swiotlb allocation functions Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 12 of 14] x86: unify pci iommu setup and allow swiotlb to compile for 32 bit Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 13 of 14] x86/swiotlb: add default phys<->bus conversion Jeremy Fitzhardinge
2008-12-16 20:17 ` [PATCH 14 of 14] x86/swiotlb: add default swiotlb_arch_range_needs_mapping Jeremy Fitzhardinge
2008-12-16 20:35 ` [PATCH 00 of 14] swiotlb/x86: lay groundwork for xen dom0 use of swiotlb Ingo Molnar
2008-12-17 5:25 ` FUJITA Tomonori
2008-12-17 8:47 ` [PATCH 00 of 14] swiotlb/x86: lay groundwork for xen dom0 useof swiotlb Jan Beulich
2008-12-17 16:51 ` FUJITA Tomonori
2008-12-17 16:31 ` [PATCH 00 of 14] swiotlb/x86: lay groundwork for xen dom0 use of swiotlb Jeremy Fitzhardinge
2008-12-17 16:56 ` FUJITA Tomonori
2008-12-17 18:58 ` Jeremy Fitzhardinge
2008-12-18 13:23 ` Ingo Molnar
2008-12-18 15:45 ` FUJITA Tomonori
2008-12-18 18:17 ` Becky Bruce
2008-12-18 20:09 ` Jeremy Fitzhardinge
2008-12-18 21:02 ` Ingo Molnar
2008-12-19 5:03 ` Becky Bruce
2008-12-19 7:02 ` Jeremy Fitzhardinge
2008-12-19 14:25 ` Becky Bruce
2008-12-19 17:48 ` Jeremy Fitzhardinge
2008-12-19 5:11 ` swiotlb highmem for ppc series Becky Bruce
2008-12-19 5:16 ` Becky Bruce
2008-12-19 5:11 ` [PATCH 01/11] swiotlb: Drop SG_ENT_VIRT_ADDRESS macro Becky Bruce
2008-12-19 5:11 ` [PATCH 02/11] swiotlb: Allow arch to provide address_needs_mapping Becky Bruce
2008-12-19 5:11 ` [PATCH 03/11] swiotlb: Rename SG_ENT_PHYS_ADDRESS to SG_ENT_BUS_ADDRESS Becky Bruce
2008-12-19 5:11 ` [PATCH 04/11] swiotlb: Print physical addr instead of bus addr in info printks Becky Bruce
2008-12-19 5:11 ` [PATCH 05/11] swiotlb: Create virt to/from dma_addr and phys_to_dma_addr funcs Becky Bruce
2008-12-19 5:11 ` [PATCH 06/11] swiotlb: Store phys address in io_tlb_orig_addr array Becky Bruce
2008-12-19 17:39 ` Jeremy Fitzhardinge
2008-12-22 5:34 ` FUJITA Tomonori
2008-12-19 5:11 ` [PATCH 07/11] swiotlb: Add support for systems with highmem Becky Bruce
2008-12-19 17:46 ` Jeremy Fitzhardinge [this message]
2008-12-19 18:12 ` Becky Bruce
2008-12-19 5:11 ` [PATCH 08/11] ia64/x86/swiotlb: use enum dma_data_direciton in dma_ops Becky Bruce
2008-12-19 5:11 ` [PATCH 09/11] swiotlb: add swiotlb_map/unmap_page Becky Bruce
2008-12-19 2:47 ` [PATCH 00 of 14] swiotlb/x86: lay groundwork for xen dom0 use of swiotlb FUJITA Tomonori
2008-12-19 8:18 ` 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=494BDDF5.1090304@goop.org \
--to=jeremy@goop.org \
--cc=beckyb@kernel.crashing.org \
--cc=benh@kernel.crashing.org \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=ian.campbell@citrix.com \
--cc=jbeulich@novell.com \
--cc=joerg.roedel@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
/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