mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Campbell <Ian.Campbell@eu.citrix.com>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"jeremy@goop.org" <jeremy@goop.org>,
	"okir@suse.de" <okir@suse.de>, "gregkh@suse.de" <gregkh@suse.de>,
	"mingo@elte.hu" <mingo@elte.hu>
Subject: Re: [PATCH 11/11] swiotlb: allow initialisation with pre-allocated bounce-buffer
Date: Tue, 2 Jun 2009 10:27:58 +0100	[thread overview]
Message-ID: <1243934878.8488.44.camel@zakaz.uk.xensource.com> (raw)
In-Reply-To: <20090602130023W.fujita.tomonori@lab.ntt.co.jp>

On Tue, 2009-06-02 at 00:08 -0400, FUJITA Tomonori wrote:
> Please tell me a pointer to Xen code to use this patch. I think that
> we could have more clean interfaces.

Certainly. This is the relevant bit of my current WIP patch. I'm not
happy about the interaction with the global swiotlb/swiotlb_force flags
at the moment, I was planning to spend today figuring out something
nicer (hence its WIP status).

Ian.

diff --git a/drivers/pci/xen-iommu.c b/drivers/pci/xen-iommu.c
index 4918938..ca005d8 100644
--- a/drivers/pci/xen-iommu.c
+++ b/drivers/pci/xen-iommu.c
@@ -5,8 +5,11 @@
 #include <linux/module.h>
 #include <linux/version.h>
 #include <linux/scatterlist.h>
+#include <linux/swiotlb.h>
+#include <linux/dma-mapping.h>
 #include <linux/io.h>
 #include <linux/bug.h>
+#include <linux/bootmem.h>
 
 #include <xen/interface/xen.h>
 #include <xen/grant_table.h>
@@ -44,3 +47,33 @@ static phys_addr_t xen_dma_to_phys(struct device *hwdev, dma_addr_t daddr)
 	return machine_to_phys(XMADDR(daddr)).paddr;
 }
 
+
+static int max_dma_bits = 32;
+
+static void xen_swiotlb_fixup(void *buf, size_t size, unsigned long nslabs)
+{
+	int i, rc;
+	int dma_bits;
+
+	printk(KERN_DEBUG "xen_swiotlb_fixup: buf=%p size=%zu\n",
+		buf, size);
+
+	dma_bits = get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT) + PAGE_SHIFT;
+
+	i = 0;
+	do {
+		int slabs = min(nslabs - i, (unsigned long)IO_TLB_SEGSIZE);
+
+		do {
+			rc = xen_create_contiguous_region(
+				(unsigned long)buf + (i << IO_TLB_SHIFT),
+				get_order(slabs << IO_TLB_SHIFT),
+				dma_bits);
+		} while (rc && dma_bits++ < max_dma_bits);
+		if (rc)
+			panic(KERN_ERR "xen_create_contiguous_region failed\n");
+
+		i += slabs;
+	} while(i < nslabs);
+}
+
@@ -300,9 +340,42 @@ void __init xen_iommu_init(void)
 
 	dma_ops = &xen_dma_ops;
 
-	if (swiotlb) {
+	if (xen_initial_domain() || swiotlb_force) {
+		unsigned long bytes;
+		void *buffer, *overflow;
+		size_t default_size = 64 * (1<<20);	/* default to 64MB */
+
 		printk(KERN_INFO "Xen: Enabling DMA fallback to swiotlb\n");
+
+		swiotlb = 0; /* Avoid native swiotlb initialisation path. */
+		swiotlb_force = 0;
+
 		dma_ops = &xen_swiotlb_dma_ops;
+
+		if (!io_tlb_nslabs) {
+			io_tlb_nslabs = (default_size >> IO_TLB_SHIFT);
+			io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
+		}
+
+		bytes = io_tlb_nslabs << IO_TLB_SHIFT;
+
+		/*
+		 * Get IO TLB memory. No need for low low pages under Xen.
+		 */
+		buffer = alloc_bootmem_pages(bytes);
+		if (!buffer)
+			panic("Cannot allocate SWIOTLB buffer");
+		xen_swiotlb_fixup(buffer, bytes, io_tlb_nslabs);
+
+		/*
+		 * Get the overflow emergency buffer
+		 */
+		overflow = alloc_bootmem(io_tlb_overflow);
+		if (!overflow)
+			panic("Cannot allocate SWIOTLB overflow buffer!\n");
+		xen_swiotlb_fixup(overflow, io_tlb_overflow, io_tlb_overflow >> IO_TLB_SHIFT);
+
+		swiotlb_init_with_buffer(bytes, buffer, overflow);
 	}
 }
 



  reply	other threads:[~2009-06-02  9:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-01 15:32 [PATCH 00/11] swiotlb: Introduce architecture-specific APIs to replace __weak functions (v2) Ian Campbell
2009-06-01 15:32 ` [PATCH 01/11] ia64: introduce arch-specific dma-mapping interfaces Ian Campbell
2009-06-02  4:08   ` FUJITA Tomonori
2009-06-02  9:18     ` Ian Campbell
2009-06-01 15:32 ` [PATCH 02/11] x86: introduce arch-specific dma-mapping interface Ian Campbell
2009-06-02  4:08   ` FUJITA Tomonori
2009-06-01 15:32 ` [PATCH 03/11] x86: use dma_map_range when allocating PCI DMA memory Ian Campbell
2009-06-02 22:07   ` Thomas Gleixner
2009-06-01 15:32 ` [PATCH 04/11] x86: use dma_map_range when allocating PCI DMA memory with no IOMMU Ian Campbell
2009-06-01 15:32 ` [PATCH 05/11] x86: use dma_map_range when allocating PCI GART memory Ian Campbell
2009-06-02 22:08   ` Thomas Gleixner
2009-06-01 15:32 ` [PATCH 06/11] swiotlb: use dma_to_phys and phys_to_dma Ian Campbell
2009-06-01 15:32 ` [PATCH 07/11] swiotlb: use dma_map_range Ian Campbell
2009-06-01 15:33 ` [PATCH 08/11] swiotlb: support HIGHMEM in swiotlb_bus_to_virt Ian Campbell
2009-06-01 15:33 ` [PATCH 09/11] swiotlb: rename swiotlb_virt_to_bus as virt_to_dma Ian Campbell
2009-06-01 15:33 ` [PATCH 10/11] swiotlb: remove __weak swiotlb_alloc* hooks Ian Campbell
2009-06-01 15:33 ` [PATCH 11/11] swiotlb: allow initialisation with pre-allocated bounce-buffer Ian Campbell
2009-06-02  4:08   ` FUJITA Tomonori
2009-06-02  9:27     ` Ian Campbell [this message]
2009-07-10  5:55 ` [PATCH 00/11] swiotlb: Introduce architecture-specific APIs to replace __weak functions (v2) Benjamin Herrenschmidt
2009-07-10 14:02   ` Ian Campbell

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=1243934878.8488.44.camel@zakaz.uk.xensource.com \
    --to=ian.campbell@eu.citrix.com \
    --cc=fujita.tomonori@lab.ntt.co.jp \
    --cc=gregkh@suse.de \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=okir@suse.de \
    /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®