linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Becky Bruce <beckyb@kernel.crashing.org>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: tony.luck@intel.com, linux-ia64@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org, linuxppc-dev@ozlabs.org
Subject: Re: [PATCH 04/15] swiotlb: remove unnecessary swiotlb_bus_to_virt
Date: Mon, 13 Jul 2009 21:17:21 -0500	[thread overview]
Message-ID: <5E909C02-3FA2-4BEB-8C73-F4E4A5A404BF@kernel.crashing.org> (raw)
In-Reply-To: <1247187904-31999-5-git-send-email-fujita.tomonori@lab.ntt.co.jp>


On Jul 9, 2009, at 8:04 PM, FUJITA Tomonori wrote:

> swiotlb_bus_to_virt is unncessary; we can use swiotlb_bus_to_phys and
> phys_to_virt instead.

phys_to_virt (also, virt_to_phys) is invalid for highmem addresses on  
ppc.  In most of the uses in this file, it doesn't matter, as the  
iotlb buffers themselves are alloc'd out of lowmem, but the  
dma_mark_clean() calls could happen on a highmem addr.  Currently, on  
powerpc, dma_mark_clean() doesn't do anything, so it isn't a  
functional problem.  I'm fine with the bulk of this patch, because in  
reality, if I need to do something with a virtual address of a highmem  
page, I have to get a kmap for the page.  So the existing  
swiotlb_bus_to_virt isn't really helping.

What is dma_mark_clean used for?  Could it be made to take a paddr,  
and let the implementation deal with making sure there's a valid vaddr  
for the actual "clean" operation?

I'd also like to see a comment with swiotlb_virt_to_bus() that notes  
that it should only be called on addresses in lowmem.

Cheers,
Becky

>
>
> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
> ---
> arch/powerpc/kernel/dma-swiotlb.c |   10 ----------
> lib/swiotlb.c                     |   34 +++++++++++++++ 
> +------------------
> 2 files changed, 16 insertions(+), 28 deletions(-)
>
> diff --git a/arch/powerpc/kernel/dma-swiotlb.c b/arch/powerpc/kernel/ 
> dma-swiotlb.c
> index 68ccf11..41534ae 100644
> --- a/arch/powerpc/kernel/dma-swiotlb.c
> +++ b/arch/powerpc/kernel/dma-swiotlb.c
> @@ -24,16 +24,6 @@
> int swiotlb __read_mostly;
> unsigned int ppc_swiotlb_enable;
>
> -void *swiotlb_bus_to_virt(struct device *hwdev, dma_addr_t addr)
> -{
> -	unsigned long pfn = PFN_DOWN(swiotlb_bus_to_phys(hwdev, addr));
> -	void *pageaddr = page_address(pfn_to_page(pfn));
> -
> -	if (pageaddr != NULL)
> -		return pageaddr + (addr % PAGE_SIZE);
> -	return NULL;
> -}
> -
> dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t  
> paddr)
> {
> 	return paddr + get_dma_direct_offset(hwdev);
> diff --git a/lib/swiotlb.c b/lib/swiotlb.c
> index dc1cd1f..1a89c84 100644
> --- a/lib/swiotlb.c
> +++ b/lib/swiotlb.c
> @@ -130,11 +130,6 @@ static dma_addr_t swiotlb_virt_to_bus(struct  
> device *hwdev,
> 	return swiotlb_phys_to_bus(hwdev, virt_to_phys(address));
> }
>
> -void * __weak swiotlb_bus_to_virt(struct device *hwdev, dma_addr_t  
> address)
> -{
> -	return phys_to_virt(swiotlb_bus_to_phys(hwdev, address));
> -}
> -
> int __weak swiotlb_arch_address_needs_mapping(struct device *hwdev,
> 					       dma_addr_t addr, size_t size)
> {
> @@ -307,9 +302,10 @@ address_needs_mapping(struct device *hwdev,  
> dma_addr_t addr, size_t size)
> 	return swiotlb_arch_address_needs_mapping(hwdev, addr, size);
> }
>
> -static int is_swiotlb_buffer(char *addr)
> +static int is_swiotlb_buffer(phys_addr_t paddr)
> {
> -	return addr >= io_tlb_start && addr < io_tlb_end;
> +	return paddr >= virt_to_phys(io_tlb_start) &&
> +		paddr < virt_to_phys(io_tlb_end);
> }
>
> /*
> @@ -582,11 +578,13 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
>
> void
> swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
> -		      dma_addr_t dma_handle)
> +		      dma_addr_t dev_addr)
> {
> +	phys_addr_t paddr = swiotlb_bus_to_phys(hwdev, dev_addr);
> +
> 	WARN_ON(irqs_disabled());
> -	if (!is_swiotlb_buffer(vaddr))
> -		free_pages((unsigned long) vaddr, get_order(size));
> +	if (!is_swiotlb_buffer(paddr))
> +		free_pages((unsigned long)vaddr, get_order(size));
> 	else
> 		/* DMA_TO_DEVICE to avoid memcpy in unmap_single */
> 		do_unmap_single(hwdev, vaddr, size, DMA_TO_DEVICE);
> @@ -671,19 +669,19 @@ EXPORT_SYMBOL_GPL(swiotlb_map_page);
> static void unmap_single(struct device *hwdev, dma_addr_t dev_addr,
> 			 size_t size, int dir)
> {
> -	char *dma_addr = swiotlb_bus_to_virt(hwdev, dev_addr);
> +	phys_addr_t paddr = swiotlb_bus_to_phys(hwdev, dev_addr);
>
> 	BUG_ON(dir == DMA_NONE);
>
> -	if (is_swiotlb_buffer(dma_addr)) {
> -		do_unmap_single(hwdev, dma_addr, size, dir);
> +	if (is_swiotlb_buffer(paddr)) {
> +		do_unmap_single(hwdev, phys_to_virt(paddr), size, dir);
> 		return;
> 	}
>
> 	if (dir != DMA_FROM_DEVICE)
> 		return;
>
> -	dma_mark_clean(dma_addr, size);
> +	dma_mark_clean(phys_to_virt(paddr), size);
> }
>
> void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
> @@ -708,19 +706,19 @@ static void
> swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
> 		    size_t size, int dir, int target)
> {
> -	char *dma_addr = swiotlb_bus_to_virt(hwdev, dev_addr);
> +	phys_addr_t paddr = swiotlb_bus_to_phys(hwdev, dev_addr);
>
> 	BUG_ON(dir == DMA_NONE);
>
> -	if (is_swiotlb_buffer(dma_addr)) {
> -		sync_single(hwdev, dma_addr, size, dir, target);
> +	if (is_swiotlb_buffer(paddr)) {
> +		sync_single(hwdev, phys_to_virt(paddr), size, dir, target);
> 		return;
> 	}
>
> 	if (dir != DMA_FROM_DEVICE)
> 		return;
>
> -	dma_mark_clean(dma_addr, size);
> +	dma_mark_clean(phys_to_virt(paddr), size);

>
> }
>
> void
> -- 
> 1.6.0.6
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux- 
> kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

  reply	other threads:[~2009-07-14  2:23 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-10  1:04 [00/15] swiotlb cleanup FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 01/15] swiotlb: remove unused swiotlb_alloc_boot() FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 02/15] swiotlb: remove unused swiotlb_alloc() FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 03/15] swiotlb: remove swiotlb_arch_range_needs_mapping FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 04/15] swiotlb: remove unnecessary swiotlb_bus_to_virt FUJITA Tomonori
2009-07-14  2:17   ` Becky Bruce [this message]
2009-07-14  5:08     ` FUJITA Tomonori
2009-07-16  3:40     ` Benjamin Herrenschmidt
2009-07-10  1:04 ` [PATCH 05/15] x86: add dma_capable() to replace is_buffer_dma_capable() FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 06/15] x86: replace is_buffer_dma_capable() with dma_capable FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 07/15] ia64: add dma_capable() to replace is_buffer_dma_capable() FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 08/15] powerpc: " FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 09/15] swiotlb: use dma_capable() FUJITA Tomonori
2009-07-10  1:04 ` [PATCH 10/15] powerpc: remove unncesary swiotlb_arch_address_needs_mapping FUJITA Tomonori
2009-07-10  1:05 ` [PATCH 11/15] remove is_buffer_dma_capable() FUJITA Tomonori
2009-07-10  1:05 ` [PATCH 12/15] x86, IA64, powerpc: add phys_to_dma() and dma_to_phys() FUJITA Tomonori
2009-07-10  1:05 ` [PATCH 13/15] swiotlb: use phys_to_dma and dma_to_phys FUJITA Tomonori
2009-07-10  1:05 ` [PATCH 14/15] powerpc: remove unused swiotlb_phys_to_bus() and swiotlb_bus_to_phys() FUJITA Tomonori
2009-07-10  1:05 ` [PATCH 15/15] x86: " FUJITA Tomonori
2009-07-10  5:12 ` [00/15] swiotlb cleanup Ingo Molnar
2009-07-10  5:35   ` FUJITA Tomonori
2009-07-10 14:02     ` Ian Campbell
2009-07-13  4:20       ` FUJITA Tomonori
2009-07-13  9:40         ` Ian Campbell
2009-07-13  9:53           ` FUJITA Tomonori
2009-07-13 10:05             ` Ian Campbell
2009-07-10 14:01   ` Ian Campbell
2009-07-10 14:12     ` Ingo Molnar
2009-07-13  4:20       ` FUJITA Tomonori
2009-07-13  9:16         ` FUJITA Tomonori
2009-07-18 10:41           ` Ingo Molnar
2009-07-14  3:13   ` Becky Bruce
2009-07-15 20:24     ` Becky Bruce

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=5E909C02-3FA2-4BEB-8C73-F4E4A5A404BF@kernel.crashing.org \
    --to=beckyb@kernel.crashing.org \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=linux-ia64@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@ozlabs.org \
    --cc=tony.luck@intel.com \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).