mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: <linux-kernel@vger.kernel.org>
Cc: Ian Campbell <ian.campbell@citrix.com>,
	FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
	Jeremy Fitzhardinge <jeremy@goop.org>, Olaf Kirch <okir@suse.de>,
	Greg KH <gregkh@suse.de>, Ingo Molnar <mingo@elte.hu>
Subject: [PATCH 11/11] swiotlb: allow initialisation with pre-allocated bounce-buffer
Date: Mon, 1 Jun 2009 16:33:03 +0100	[thread overview]
Message-ID: <1243870383-12954-12-git-send-email-ian.campbell@citrix.com> (raw)
In-Reply-To: <1243870383-12954-1-git-send-email-ian.campbell@citrix.com>

This allows the generic swiotlb code to be used by users with unusual
requirements for the buffer allocation by allowing them to provide
their own swiotlb buffer.

Also:
- swiotlb_init_with_default_size is unused so collapse into
  swiotlb_init.
- move declarations of swiotlb_late_init_with_default_size out of *.c
  into linux/swiotlb.h where they belong
- Make io_tlb_nslabs and io_tlb_overflow non-static since callers of the
  new interface will want to access them.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Olaf Kirch <okir@suse.de>
Cc: Greg KH <gregkh@suse.de>
Cc: Ingo Molnar <mingo@elte.hu>
---
 arch/ia64/hp/common/hwsw_iommu.c |    3 --
 arch/ia64/hp/common/sba_iommu.c  |    2 -
 include/linux/swiotlb.h          |   14 ++++++++
 lib/swiotlb.c                    |   64 +++++++++++++++++++++----------------
 4 files changed, 50 insertions(+), 33 deletions(-)

diff --git a/arch/ia64/hp/common/hwsw_iommu.c b/arch/ia64/hp/common/hwsw_iommu.c
index e4a80d8..d557779 100644
--- a/arch/ia64/hp/common/hwsw_iommu.c
+++ b/arch/ia64/hp/common/hwsw_iommu.c
@@ -19,9 +19,6 @@
 
 extern struct dma_map_ops sba_dma_ops, swiotlb_dma_ops;
 
-/* swiotlb declarations & definitions: */
-extern int swiotlb_late_init_with_default_size (size_t size);
-
 /*
  * Note: we need to make the determination of whether or not to use
  * the sw I/O TLB based purely on the device structure.  Anything else
diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c
index 56ceb68..eeb5b49 100644
--- a/arch/ia64/hp/common/sba_iommu.c
+++ b/arch/ia64/hp/common/sba_iommu.c
@@ -46,8 +46,6 @@
 
 #include <asm/acpi-ext.h>
 
-extern int swiotlb_late_init_with_default_size (size_t size);
-
 #define PFX "IOC: "
 
 /*
diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
index b5b2245..7c6f4c1 100644
--- a/include/linux/swiotlb.h
+++ b/include/linux/swiotlb.h
@@ -21,8 +21,22 @@ struct scatterlist;
  */
 #define IO_TLB_SHIFT 11
 
+/*
+ * number of IO TLB slabs.
+ */
+extern unsigned long io_tlb_nslabs;
+
+/*
+ * size of emergency overflow buffer.
+ */
+extern unsigned long io_tlb_overflow;
+
 extern void
 swiotlb_init(void);
+extern void
+swiotlb_init_with_buffer(unsigned long bytes, void *buffer, void *emergency);
+extern int
+swiotlb_late_init_with_default_size(size_t size);
 
 extern void
 *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
diff --git a/lib/swiotlb.c b/lib/swiotlb.c
index 6076bb7..2449669 100644
--- a/lib/swiotlb.c
+++ b/lib/swiotlb.c
@@ -70,14 +70,14 @@ static char *io_tlb_start, *io_tlb_end;
  * The number of IO TLB blocks (in groups of 64) betweeen io_tlb_start and
  * io_tlb_end.  This is command line adjustable via setup_io_tlb_npages.
  */
-static unsigned long io_tlb_nslabs;
+unsigned long io_tlb_nslabs;
 
 /*
  * When the IOMMU overflows we return a fallback buffer. This sets the size.
  */
-static unsigned long io_tlb_overflow = 32*1024;
+unsigned long io_tlb_overflow = 32*1024;
 
-void *io_tlb_overflow_buffer;
+static void *io_tlb_overflow_buffer;
 
 /*
  * This is a free list describing the number of free entries available from
@@ -148,14 +148,40 @@ static void swiotlb_print_info(unsigned long bytes)
 	       (unsigned long long)pend);
 }
 
+void __init
+swiotlb_init_with_buffer(unsigned long bytes, void *buffer, void *overflow)
+{
+	unsigned long i;
+
+	io_tlb_start = buffer;
+	io_tlb_end = io_tlb_start + bytes;
+
+	io_tlb_overflow_buffer = overflow;
+
+	/*
+	 * Allocate and initialize the free list array.  This array is used
+	 * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
+	 * between io_tlb_start and io_tlb_end.
+	 */
+	io_tlb_list = alloc_bootmem(io_tlb_nslabs * sizeof(int));
+	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(phys_addr_t));
+
+	swiotlb_print_info(bytes);
+}
+
 /*
  * Statically reserve bounce buffer space and initialize bounce buffer data
  * structures for the software IO TLB used to implement the DMA API.
  */
 void __init
-swiotlb_init_with_default_size(size_t default_size)
+swiotlb_init(void)
 {
-	unsigned long i, bytes;
+	unsigned long bytes;
+	void *buffer, *overflow;
+	size_t default_size = 64 * (1<<20);	/* default to 64MB */
 
 	if (!io_tlb_nslabs) {
 		io_tlb_nslabs = (default_size >> IO_TLB_SHIFT);
@@ -167,36 +193,18 @@ swiotlb_init_with_default_size(size_t default_size)
 	/*
 	 * Get IO TLB memory from the low pages
 	 */
-	io_tlb_start = alloc_bootmem_low_pages(bytes);
-	if (!io_tlb_start)
+	buffer = alloc_bootmem_low_pages(bytes);
+	if (!buffer)
 		panic("Cannot allocate SWIOTLB buffer");
-	io_tlb_end = io_tlb_start + bytes;
-
-	/*
-	 * Allocate and initialize the free list array.  This array is used
-	 * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
-	 * between io_tlb_start and io_tlb_end.
-	 */
-	io_tlb_list = alloc_bootmem(io_tlb_nslabs * sizeof(int));
-	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(phys_addr_t));
 
 	/*
 	 * Get the overflow emergency buffer
 	 */
-	io_tlb_overflow_buffer = alloc_bootmem_low(io_tlb_overflow);
-	if (!io_tlb_overflow_buffer)
+	overflow = alloc_bootmem_low(io_tlb_overflow);
+	if (!overflow)
 		panic("Cannot allocate SWIOTLB overflow buffer!\n");
 
-	swiotlb_print_info(bytes);
-}
-
-void __init
-swiotlb_init(void)
-{
-	swiotlb_init_with_default_size(64 * (1<<20));	/* default to 64MB */
+	swiotlb_init_with_buffer(bytes, buffer, overflow);
 }
 
 /*
-- 
1.5.6.5


  parent reply	other threads:[~2009-06-01 15:36 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 ` Ian Campbell [this message]
2009-06-02  4:08   ` [PATCH 11/11] swiotlb: allow initialisation with pre-allocated bounce-buffer FUJITA Tomonori
2009-06-02  9:27     ` Ian Campbell
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=1243870383-12954-12-git-send-email-ian.campbell@citrix.com \
    --to=ian.campbell@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®