public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeremy Fitzhardinge <jeremy@goop.org>
To: Dave Airlie <airlied@linux.ie>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	dri-devel <dri-devel@lists.sourceforge.net>
Subject: [PATCH 1/2] agp: use more dma-ops-like operations for agp memory
Date: Tue, 24 Mar 2009 10:59:32 -0700	[thread overview]
Message-ID: <49C91F84.5020109@goop.org> (raw)

Impact: make agp work under Xen

[ Hi Dave,  I was about to post this, but I'm not sure if you've had this
  explicitly brought to your attention for ack/nack.  Thanks -J ]

When using AGP under Xen, we need to be careful to
1) properly translate between physical and machine addresses, and
2) make sure memory is physically contigious when the hardware expects it

This change uses swiotlb_phys_to_bus/bus_to_phys to do the phys<->gart
conversion, since they already do the right thing, and dma_alloc_coherent
for gatt allocations.  This works equally well running native.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: David Airlie <airlied@linux.ie>

diff --git a/arch/x86/include/asm/agp.h b/arch/x86/include/asm/agp.h
index 9825cd6..7ba2639 100644
--- a/arch/x86/include/asm/agp.h
+++ b/arch/x86/include/asm/agp.h
@@ -1,8 +1,11 @@
 #ifndef _ASM_X86_AGP_H
 #define _ASM_X86_AGP_H
 
+#include <linux/swiotlb.h>
+
 #include <asm/pgtable.h>
 #include <asm/cacheflush.h>
+#include <asm/dma-mapping.h>
 
 /*
  * Functions to keep the agpgart mappings coherent with the MMU. The
@@ -23,13 +26,15 @@
 #define flush_agp_cache() wbinvd()
 
 /* Convert a physical address to an address suitable for the GART. */
-#define phys_to_gart(x) (x)
-#define gart_to_phys(x) (x)
+#define phys_to_gart(x) swiotlb_phys_to_bus(NULL, (x))
+#define gart_to_phys(x) swiotlb_bus_to_phys(x)
 
 /* GATT allocation. Returns/accepts GATT kernel virtual address. */
-#define alloc_gatt_pages(order)		\
-	((char *)__get_free_pages(GFP_KERNEL, (order)))
+#define alloc_gatt_pages(order)	({                                          \
+	char *_t; dma_addr_t _d;                                            \
+	_t = dma_alloc_coherent(NULL,PAGE_SIZE<<(order),&_d,GFP_KERNEL);    \
+	_t; })
 #define free_gatt_pages(table, order)	\
-	free_pages((unsigned long)(table), (order))
+	dma_free_coherent(NULL,PAGE_SIZE<<(order),(table),virt_to_bus(table))
 
 #endif /* _ASM_X86_AGP_H */
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 8e6f6c8..98fb7d3 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -128,11 +128,13 @@ dma_addr_t __weak swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
 {
 	return paddr;
 }
+EXPORT_SYMBOL_GPL(swiotlb_phys_to_bus);
 
 phys_addr_t __weak swiotlb_bus_to_phys(dma_addr_t baddr)
 {
 	return baddr;
 }
+EXPORT_SYMBOL_GPL(swiotlb_bus_to_phys);
 
 static dma_addr_t swiotlb_virt_to_bus(struct device *hwdev,
 				      volatile void *address)



                 reply	other threads:[~2009-03-24 17:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=49C91F84.5020109@goop.org \
    --to=jeremy@goop.org \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.sourceforge.net \
    --cc=linux-kernel@vger.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