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 06/11] swiotlb: Store phys address in io_tlb_orig_addr array
Date: Fri, 19 Dec 2008 09:39:58 -0800 [thread overview]
Message-ID: <494BDC6E.8050509@goop.org> (raw)
In-Reply-To: <1229663480-10757-7-git-send-email-beckyb@kernel.crashing.org>
Becky Bruce wrote:
> When we enable swiotlb for platforms that support HIGHMEM, we
> can no longer store the virtual address of the original dma
> buffer, because that buffer might not have a permament mapping.
> Change the iotlb code to instead store the physical address of
> the original buffer.
>
Hm, yes, I think using a phys_addr_t may end up being cleaner than using
struct page *+offset.
J
> Signed-off-by: Becky Bruce <beckyb@kernel.crashing.org>
> ---
> lib/swiotlb.c | 47 ++++++++++++++++++++++++-----------------------
> 1 files changed, 24 insertions(+), 23 deletions(-)
>
> diff --git a/lib/swiotlb.c b/lib/swiotlb.c
> index ed4f44a..e9d5bf6 100644
> --- a/lib/swiotlb.c
> +++ b/lib/swiotlb.c
> @@ -118,7 +118,7 @@ static unsigned int io_tlb_index;
> * We need to save away the original address corresponding to a mapped entry
> * for the sync operations.
> */
> -static unsigned char **io_tlb_orig_addr;
> +static phys_addr_t *io_tlb_orig_addr;
>
> /*
> * Protect the above data structures in the map and unmap calls
> @@ -175,7 +175,7 @@ swiotlb_init_with_default_size(size_t default_size)
> for (i = 0; i < io_tlb_nslabs; i++)
> io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
> io_tlb_index = 0;
> - io_tlb_orig_addr = alloc_bootmem(io_tlb_nslabs * sizeof(char *));
> + io_tlb_orig_addr = alloc_bootmem(io_tlb_nslabs * sizeof(phys_addr_t));
>
> /*
> * Get the overflow emergency buffer
> @@ -253,12 +253,14 @@ swiotlb_late_init_with_default_size(size_t default_size)
> io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
> io_tlb_index = 0;
>
> - io_tlb_orig_addr = (unsigned char **)__get_free_pages(GFP_KERNEL,
> - get_order(io_tlb_nslabs * sizeof(char *)));
> + io_tlb_orig_addr = (phys_addr_t *)
> + __get_free_pages(GFP_KERNEL,
> + get_order(io_tlb_nslabs *
> + sizeof(phys_addr_t)));
> if (!io_tlb_orig_addr)
> goto cleanup3;
>
> - memset(io_tlb_orig_addr, 0, io_tlb_nslabs * sizeof(char *));
> + memset(io_tlb_orig_addr, 0, io_tlb_nslabs * sizeof(phys_addr_t));
>
> /*
> * Get the overflow emergency buffer
> @@ -276,8 +278,8 @@ swiotlb_late_init_with_default_size(size_t default_size)
> return 0;
>
> cleanup4:
> - free_pages((unsigned long)io_tlb_orig_addr, get_order(io_tlb_nslabs *
> - sizeof(char *)));
> + free_pages((unsigned long)io_tlb_orig_addr,
> + get_order(io_tlb_nslabs * sizeof(phys_addr_t)));
> io_tlb_orig_addr = NULL;
> cleanup3:
> free_pages((unsigned long)io_tlb_list, get_order(io_tlb_nslabs *
> @@ -307,7 +309,7 @@ static int is_swiotlb_buffer(char *addr)
> * Allocates bounce buffer and returns its kernel virtual address.
> */
> static void *
> -map_single(struct device *hwdev, char *buffer, size_t size, int dir)
> +map_single(struct device *hwdev, phys_addr_t phys, size_t size, int dir)
> {
> unsigned long flags;
> char *dma_addr;
> @@ -398,9 +400,9 @@ found:
> * needed.
> */
> for (i = 0; i < nslots; i++)
> - io_tlb_orig_addr[index+i] = buffer + (i << IO_TLB_SHIFT);
> + io_tlb_orig_addr[index+i] = phys + (i << IO_TLB_SHIFT);
> if (dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL)
> - memcpy(dma_addr, buffer, size);
> + memcpy(dma_addr, phys_to_virt(phys), size);
>
> return dma_addr;
> }
> @@ -414,17 +416,17 @@ unmap_single(struct device *hwdev, char *dma_addr, size_t size, int dir)
> unsigned long flags;
> int i, count, nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
> int index = (dma_addr - io_tlb_start) >> IO_TLB_SHIFT;
> - char *buffer = io_tlb_orig_addr[index];
> + phys_addr_t phys = io_tlb_orig_addr[index];
>
> /*
> * First, sync the memory before unmapping the entry
> */
> - if (buffer && ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL)))
> + if (phys && ((dir == DMA_FROM_DEVICE) || (dir == DMA_BIDIRECTIONAL)))
> /*
> * bounce... copy the data back into the original buffer * and
> * delete the bounce buffer.
> */
> - memcpy(buffer, dma_addr, size);
> + memcpy(phys_to_virt(phys), dma_addr, size);
>
> /*
> * Return the buffer to the free list by setting the corresponding
> @@ -457,20 +459,20 @@ sync_single(struct device *hwdev, char *dma_addr, size_t size,
> int dir, int target)
> {
> int index = (dma_addr - io_tlb_start) >> IO_TLB_SHIFT;
> - char *buffer = io_tlb_orig_addr[index];
> + phys_addr_t phys = io_tlb_orig_addr[index];
>
> - buffer += ((unsigned long)dma_addr & ((1 << IO_TLB_SHIFT) - 1));
> + phys += ((unsigned long)dma_addr & ((1 << IO_TLB_SHIFT) - 1));
>
> switch (target) {
> case SYNC_FOR_CPU:
> if (likely(dir == DMA_FROM_DEVICE || dir == DMA_BIDIRECTIONAL))
> - memcpy(buffer, dma_addr, size);
> + memcpy(phys_to_virt(phys), dma_addr, size);
> else
> BUG_ON(dir != DMA_TO_DEVICE);
> break;
> case SYNC_FOR_DEVICE:
> if (likely(dir == DMA_TO_DEVICE || dir == DMA_BIDIRECTIONAL))
> - memcpy(dma_addr, buffer, size);
> + memcpy(dma_addr, phys_to_virt(phys), size);
> else
> BUG_ON(dir != DMA_FROM_DEVICE);
> break;
> @@ -509,7 +511,7 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,
> * swiotlb_map_single(), which will grab memory from
> * the lowest available address range.
> */
> - ret = map_single(hwdev, NULL, size, DMA_FROM_DEVICE);
> + ret = map_single(hwdev, 0, size, DMA_FROM_DEVICE);
> if (!ret)
> return NULL;
> }
> @@ -591,7 +593,7 @@ swiotlb_map_single_attrs(struct device *hwdev, void *ptr, size_t size,
> /*
> * Oh well, have to allocate and map a bounce buffer.
> */
> - map = map_single(hwdev, ptr, size, dir);
> + map = map_single(hwdev, virt_to_phys(ptr), size, dir);
> if (!map) {
> swiotlb_full(hwdev, size, dir, 1);
> map = io_tlb_overflow_buffer;
> @@ -736,18 +738,17 @@ swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
> int dir, struct dma_attrs *attrs)
> {
> struct scatterlist *sg;
> - void *addr;
> dma_addr_t dev_addr;
> int i;
>
> BUG_ON(dir == DMA_NONE);
>
> for_each_sg(sgl, sg, nelems, i) {
> - addr = sg_virt(sg);
> - dev_addr = virt_to_dma_addr(hwdev, addr);
> + dev_addr = SG_ENT_BUS_ADDRESS(hwdev, sg);
> if (swiotlb_force ||
> swiotlb_addr_needs_mapping(hwdev, dev_addr, sg->length)) {
> - void *map = map_single(hwdev, addr, sg->length, dir);
> + void *map = map_single(hwdev, sg_phys(sg), sg->length,
> + dir);
> if (!map) {
> /* Don't panic here, we expect map_sg users
> to do proper error handling. */
>
next prev parent reply other threads:[~2008-12-19 17:40 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 [this message]
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
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=494BDC6E.8050509@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