From: Jeremy Fitzhardinge <jeremy@goop.org>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: the arch/x86 maintainers <x86@kernel.org>,
Ingo Molnar <mingo@elte.hu>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Jeremy Fitzhardinge <jeremy@goop.org>,
Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Subject: [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious
Date: Tue, 31 Mar 2009 15:52:07 -0700 [thread overview]
Message-ID: <1238539935-4295-2-git-send-email-jeremy@goop.org> (raw)
In-Reply-To: <1238539935-4295-1-git-send-email-jeremy@goop.org>
Impact: make swiotlb allocation suitable for Xen
When allocating the swiotlb buffer under Xen, make sure the memory is
physically contiguous so that its really suitable for DMA.
Do this by allocating the memory as usual, but then call a Xen
function to rearrange the underlying pages to be physically
contiguous.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Reviewed-by: "H. Peter Anvin" <hpa@zytor.com>
---
arch/x86/kernel/pci-swiotlb_64.c | 17 +++++++++++++++--
drivers/pci/xen-iommu.c | 16 ++++++++++++++++
include/xen/swiotlb.h | 12 ++++++++++++
3 files changed, 43 insertions(+), 2 deletions(-)
create mode 100644 include/xen/swiotlb.h
diff --git a/arch/x86/kernel/pci-swiotlb_64.c b/arch/x86/kernel/pci-swiotlb_64.c
index 0f03b06..be379af 100644
--- a/arch/x86/kernel/pci-swiotlb_64.c
+++ b/arch/x86/kernel/pci-swiotlb_64.c
@@ -11,16 +11,29 @@
#include <asm/swiotlb.h>
#include <asm/dma.h>
+#include <xen/swiotlb.h>
+#include <asm/xen/hypervisor.h>
+
int swiotlb __read_mostly;
void * __init swiotlb_alloc_boot(size_t size, unsigned long nslabs)
{
- return alloc_bootmem_low_pages(size);
+ void *ret = alloc_bootmem_low_pages(size);
+
+ if (ret && xen_pv_domain())
+ xen_swiotlb_fixup(ret, size, nslabs);
+
+ return ret;
}
void *swiotlb_alloc(unsigned order, unsigned long nslabs)
{
- return (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, order);
+ void *ret = (void *)__get_free_pages(GFP_DMA | __GFP_NOWARN, order);
+
+ if (ret && xen_pv_domain())
+ xen_swiotlb_fixup(ret, 1u << order, nslabs);
+
+ return ret;
}
dma_addr_t swiotlb_phys_to_bus(struct device *hwdev, phys_addr_t paddr)
diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 32a8b49..c593058 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -12,6 +12,7 @@
#include <xen/grant_table.h>
#include <xen/page.h>
#include <xen/xen-ops.h>
+#include <xen/swiotlb.h>
#include <asm/iommu.h>
#include <asm/swiotlb.h>
@@ -34,6 +35,21 @@ do { \
(unsigned long long)addr + size); \
} while (0)
+
+void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
+{
+ unsigned order = get_order(size);
+
+ printk(KERN_DEBUG "xen_swiotlb_fixup: buf=%p size=%zu order=%u\n",
+ buf, size, order);
+
+ if (WARN_ON(size != (PAGE_SIZE << order)))
+ return;
+
+ if (xen_create_contiguous_region((unsigned long)buf,
+ order, 0xffffffff))
+ printk(KERN_ERR "xen_create_contiguous_region failed\n");
+}
static inline int address_needs_mapping(struct device *hwdev,
dma_addr_t addr)
{
diff --git a/include/xen/swiotlb.h b/include/xen/swiotlb.h
new file mode 100644
index 0000000..8d59439
--- /dev/null
+++ b/include/xen/swiotlb.h
@@ -0,0 +1,12 @@
+#ifndef _XEN_SWIOTLB_H
+#define _XEN_SWIOTLB_H
+
+#ifdef CONFIG_PCI_XEN
+extern void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs);
+#else
+static inline void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
+{
+}
+#endif
+
+#endif /* _XEN_SWIOTLB_H */
--
1.6.0.6
next prev parent reply other threads:[~2009-03-31 22:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-31 22:52 [PATCH] swiotlb updates for Xen dom0 Jeremy Fitzhardinge
2009-03-31 22:52 ` Jeremy Fitzhardinge [this message]
2009-03-31 22:52 ` [PATCH 2/9] xen swiotlb: fixup swiotlb is chunks smaller than MAX_CONTIG_ORDER Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 3/9] xen: add hooks for mapping phys<->bus addresses in swiotlb Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 4/9] xen/swiotlb: add hook for swiotlb_arch_range_needs_mapping Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 5/9] xen: enable swiotlb for xen domain 0 Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 6/9] swiotlb: use swiotlb_alloc_boot to allocate emergency pool Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 7/9] xen/swiotlb: improve comment on gfp flags in xen_alloc_coherent() Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 8/9] xen/swiotlb: add sync functions Jeremy Fitzhardinge
2009-03-31 22:52 ` [PATCH 9/9] pci-swiotlb: remove __weak vs __weak binding Jeremy Fitzhardinge
2009-04-02 6:29 ` [PATCH] swiotlb updates for Xen dom0 FUJITA Tomonori
2009-04-02 7:12 ` Jeremy Fitzhardinge
2009-05-08 0:17 [GIT PULL] xen: swiotlb support " Jeremy Fitzhardinge
2009-05-08 0:17 ` [PATCH 1/9] xen: make sure swiotlb allocation is physically contigious Jeremy Fitzhardinge
2009-05-11 3:40 ` FUJITA Tomonori
2009-05-11 13:55 ` Joerg Roedel
2009-05-11 18:42 ` Jeremy Fitzhardinge
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=1238539935-4295-2-git-send-email-jeremy@goop.org \
--to=jeremy@goop.org \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=jeremy.fitzhardinge@citrix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--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
all inboxes | Powered by JetHome®