Skip to contentSkip to conversation

MIPS: Use dma-mapping-common.h and use swiotlb for Octeon.

PATCH In review David Daney 5 participants 21 messages Sep 23, 2010 – Sep 28, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover MIPS: Use dma-mapping-common.h and use swiotlb for Octeon.

The Octeon family of SOCs support physical memory outside of the 32-bit addressing range. To support 32-bit devices, we need to use the swiotlb bounce buffer mechanism.

There are several parts to the patch set.

1 - Set the proper dma_masks for the octeon_mgmt platform device so
that it continues to function with the rewritten dma mapping code to follow.

2,3,4 - Establish a properly constrained DMA32 zone for Octeon.

5 - Convert MIPS to use dma-mapping-common.h

6,7 - Trivial swiotlb changes.

8 - Get MIPS ready to use swiotlb.

9 - Rewrite Octeon dma mapping code.

Since the only non-MIPS parts of this patch set are trivial changes to swiotlb, I would suggest that they could all be merged via Ralf's tree if deemed acceptable.

David Daney (9):
MIPS: Octeon: Set dma_masks for octeon_mgmt device.
MIPS: Allow MAX_DMA32_PFN to be overridden.
MIPS: Octeon: Adjust top of DMA32 zone.
MIPS: Octeon: Select ZONE_DMA32
MIPS: Convert DMA to use dma-mapping-common.h
swiotlb: Declare swiotlb_init_with_default_size()
swiotlb: Make bounce buffer bounds non-static.
MIPS: Add a platform hook for swiotlb setup.
MIPS: Octeon: Rewrite DMA mapping functions.

 arch/mips/Kconfig                                  |    3 +
 arch/mips/cavium-octeon/Kconfig                    |   12 +
 arch/mips/cavium-octeon/dma-octeon.c               |  529 +++++++++-----------
 arch/mips/cavium-octeon/octeon-platform.c          |    5 +
 arch/mips/include/asm/bootinfo.h                   |    5 +
 arch/mips/include/asm/device.h                     |   15 +-
 arch/mips/include/asm/dma-mapping.h                |  125 ++++--
 arch/mips/include/asm/dma.h                        |    3 +
 .../asm/mach-cavium-octeon/cpu-feature-overrides.h |    6 +
 .../include/asm/mach-cavium-octeon/dma-coherence.h |   19 +-
 arch/mips/include/asm/octeon/pci-octeon.h          |   10 +
 arch/mips/kernel/setup.c                           |    5 +
 arch/mips/mm/dma-default.c                         |  179 +++----
 arch/mips/pci/pci-octeon.c                         |   60 ++-
 arch/mips/pci/pcie-octeon.c                        |    5 +
 include/linux/swiotlb.h                            |    7 +
 lib/swiotlb.c                                      |   62 ++--
 17 files changed, 571 insertions(+), 479 deletions(-)
Signature · 1 line
1.7.2.2
#1 lore raw

PATCH 1/9 MIPS: Octeon: Set dma_masks for octeon_mgmt device.

This allows follow-on patches to dma mapping functions to work with the octeon mgmt device..

---
 arch/mips/cavium-octeon/octeon-platform.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
arch/mips/cavium-octeon/octeon-platform.c +5 -0
index 62ac30e..c32d40d 100644
@@ -10,6 +10,7 @@
 #include <linux/init.h>
 #include <linux/irq.h>
 #include <linux/i2c.h>
+#include <linux/dma-mapping.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 
@@ -301,6 +302,10 @@ static int __init octeon_mgmt_device_init(void)
 			ret = -ENOMEM;
 			goto out;
 		}
+		/* No DMA restrictions */
+		pd->dev.coherent_dma_mask = DMA_BIT_MASK(64);
+		pd->dev.dma_mask = &pd->dev.coherent_dma_mask;
+
 		switch (port) {
 		case 0:
 			mgmt_port_resource.start = OCTEON_IRQ_MII0;
Signature · 1 line
1.7.2.2
#2 lore raw

PATCH 2/9 MIPS: Allow MAX_DMA32_PFN to be overridden.

In reply to David Daney

DMA mapping may reduce the usable physical address range usable for 32-bit DMA.

---
 arch/mips/include/asm/dma.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
arch/mips/include/asm/dma.h +3 -0
index 1353c81..2d47da6 100644
@@ -91,7 +91,10 @@
 #define MAX_DMA_ADDRESS		(PAGE_OFFSET + 0x01000000)
 #endif
 #define MAX_DMA_PFN		PFN_DOWN(virt_to_phys((void *)MAX_DMA_ADDRESS))
+
+#ifndef MAX_DMA32_PFN
 #define MAX_DMA32_PFN		(1UL << (32 - PAGE_SHIFT))
+#endif
 
 /* 8237 DMA controllers */
 #define IO_DMA1_BASE	0x00	/* 8 bit slave DMA, channels 0..3 */
Signature · 1 line
1.7.2.2
#3 lore raw

PATCH 3/9 MIPS: Octeon: Adjust top of DMA32 zone.

In reply to David Daney

On OCTEON, we reserve the last 256MB of 32-bit PCI address space, mapping the RAM in this region at a high DMA address. This makes memory in this region unavailable for 32-bit DMA.

---
 .../asm/mach-cavium-octeon/cpu-feature-overrides.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
arch/mips/include/asm/mach-cavium-octeon/cpu-feature-overrides.h +6 -0
index b952fc7..c84ed74 100644
@@ -81,4 +81,10 @@ static inline int octeon_has_saa(void)
 	return id >= 0x000d0300;
 }
 
+/*
+ * The last 256MB are reserved for device to device mappings and the
+ * BAR1 hole.
+ */
+#define MAX_DMA32_PFN (((1ULL << 32) - (1ULL << 28)) >> PAGE_SHIFT)
+
 #endif
Signature · 1 line
1.7.2.2
#4 lore raw

PATCH 4/9 MIPS: Octeon: Select ZONE_DMA32

In reply to David Daney

Give us a nice place to allocate coherent DMA memory for 32-bit devices.

---
 arch/mips/Kconfig |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/mips/Kconfig +1 -0
index 5526faa..6c33709 100644
@@ -693,6 +693,7 @@ config CAVIUM_OCTEON_REFERENCE_BOARD
 	select SWAP_IO_SPACE
 	select HW_HAS_PCI
 	select ARCH_SUPPORTS_MSI
+	select ZONE_DMA32
 	help
 	  This option supports all of the Octeon reference boards from Cavium
 	  Networks. It builds a kernel that dynamically determines the Octeon
Signature · 1 line
1.7.2.2
#5 lore raw

PATCH 5/9 MIPS: Convert DMA to use dma-mapping-common.h

In reply to David Daney

Use asm-generic/dma-mapping-common.h to handle all DMA mapping operations and establish a default get_dma_ops() that forwards all operations to the existing code.

Augment dev_archdata to carry a pointer to the struct dma_map_ops, allowing DMA operations to be overridden on a per device basis. Currently this is never filled in, so the default dma_map_ops are used. A follow-on patch sets this for Octeon PCI devices.

Also initialize the dma_debug system as it is now used if it is configured.

---
 arch/mips/Kconfig                   |    2 +
 arch/mips/include/asm/device.h      |   15 +++-
 arch/mips/include/asm/dma-mapping.h |  125 +++++++++++++++++--------
 arch/mips/mm/dma-default.c          |  179 +++++++++++++---------------------
 4 files changed, 172 insertions(+), 149 deletions(-)
arch/mips/Kconfig +2 -0
index 6c33709..e68b89f 100644
@@ -14,6 +14,8 @@ config MIPS
 	select HAVE_KRETPROBES
 	select RTC_LIB if !MACH_LOONGSON
 	select GENERIC_ATOMIC64 if !64BIT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
 
 mainmenu "Linux/MIPS Kernel Configuration"
 
arch/mips/include/asm/device.h +14 -1
index 06746c5..65bf274 100644
@@ -3,4 +3,17 @@
  *
  * This file is released under the GPLv2
  */
-#include <asm-generic/device.h>
+#ifndef _ASM_MIPS_DEVICE_H
+#define _ASM_MIPS_DEVICE_H
+
+struct mips_dma_map_ops;
+
+struct dev_archdata {
+	/* DMA operations on that device */
+	struct mips_dma_map_ops	*dma_ops;
+};
+
+struct pdev_archdata {
+};
+
+#endif /* _ASM_MIPS_DEVICE_H*/
arch/mips/include/asm/dma-mapping.h +87 -38

142 lines not on this page · raw message

arch/mips/mm/dma-default.c +69 -110

288 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#6 lore raw

PATCH 1/1 MIPS: Remove plat_map_dma_mem_page().

It is now unused.

Cc Wu Zhangjin <[email protected]>
Cc David VomLehn <[email protected]>

---

This is a small addition to the rest of the patch set. It could be rolled into [PATCH 5/9] MIPS: Convert DMA to use dma-mapping-common.h

 arch/mips/include/asm/mach-generic/dma-coherence.h |    6 ------
 arch/mips/include/asm/mach-ip27/dma-coherence.h    |    7 -------
 arch/mips/include/asm/mach-ip32/dma-coherence.h    |   12 ------------
 arch/mips/include/asm/mach-jazz/dma-coherence.h    |    5 -----
 .../mips/include/asm/mach-loongson/dma-coherence.h |    6 ------
 arch/mips/include/asm/mach-powertv/dma-coherence.h |    6 ------
 6 files changed, 0 insertions(+), 42 deletions(-)
arch/mips/include/asm/mach-generic/dma-coherence.h +0 -6
index 8da9807..8259966 100644
@@ -17,12 +17,6 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 	return virt_to_phys(addr);
 }
 
-static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
-	struct page *page)
-{
-	return page_to_phys(page);
-}
-
 static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
arch/mips/include/asm/mach-ip27/dma-coherence.h +0 -7
index d3d0401..e35bfbc 100644
@@ -26,13 +26,6 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 	return pa;
 }
 
-static dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page)
-{
-	dma_addr_t pa = dev_to_baddr(dev, page_to_phys(page));
-
-	return pa;
-}
-
 static unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
arch/mips/include/asm/mach-ip32/dma-coherence.h +0 -12
index 3785595..7dd1907 100644
@@ -37,18 +37,6 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 	return pa;
 }
 
-static dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page)
-{
-	dma_addr_t pa;
-
-	pa = page_to_phys(page) & RAM_OFFSET_MASK;
-
-	if (dev == NULL)
-		pa += CRIME_HI_MEM_BASE;
-
-	return pa;
-}
-
 /* This is almost certainly wrong but it's what dma-ip32.c used to use  */
 static unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
arch/mips/include/asm/mach-jazz/dma-coherence.h +0 -5
index f93aee5..e0d340b 100644
@@ -17,11 +17,6 @@ static dma_addr_t plat_map_dma_mem(struct device *dev, void *addr, size_t size)
 	return vdma_alloc(virt_to_phys(addr), size);
 }
 
-static dma_addr_t plat_map_dma_mem_page(struct device *dev, struct page *page)
-{
-	return vdma_alloc(page_to_phys(page), PAGE_SIZE);
-}
-
 static unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
arch/mips/include/asm/mach-loongson/dma-coherence.h +0 -6
index 981c75f..8daeaee 100644
@@ -19,12 +19,6 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 	return virt_to_phys(addr) | 0x80000000;
 }
 
-static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
-					       struct page *page)
-{
-	return page_to_phys(page) | 0x80000000;
-}
-
 static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
arch/mips/include/asm/mach-powertv/dma-coherence.h +0 -6
index f76029c..647de8c 100644
@@ -70,12 +70,6 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 		return phys_to_dma(virt_to_phys(addr));
 }
 
-static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
-	struct page *page)
-{
-	return phys_to_dma(page_to_phys(page));
-}
-
 static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
Signature · 1 line
1.7.2.2
#7 lore raw

Re: [PATCH 5/9] MIPS: Convert DMA to use dma-mapping-common.h

In reply to David Daney
Quoted 61 lines · On Thu, 23 Sep 2010 15:38:12 -0700 David Daney <[email protected]>…

Use asm-generic/dma-mapping-common.h to handle all DMA mapping operations and establish a default get_dma_ops() that forwards all operations to the existing code.

Augment dev_archdata to carry a pointer to the struct dma_map_ops, allowing DMA operations to be overridden on a per device basis. Currently this is never filled in, so the default dma_map_ops are used. A follow-on patch sets this for Octeon PCI devices.

Also initialize the dma_debug system as it is now used if it is configured.

---
 arch/mips/Kconfig                   |    2 +
 arch/mips/include/asm/device.h      |   15 +++-
 arch/mips/include/asm/dma-mapping.h |  125 +++++++++++++++++--------
 arch/mips/mm/dma-default.c          |  179 +++++++++++++---------------------
 4 files changed, 172 insertions(+), 149 deletions(-)
arch/mips/Kconfig +2 -0
index 6c33709..e68b89f 100644
@@ -14,6 +14,8 @@ config MIPS
 	select HAVE_KRETPROBES
 	select RTC_LIB if !MACH_LOONGSON
 	select GENERIC_ATOMIC64 if !64BIT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
 
 mainmenu "Linux/MIPS Kernel Configuration"
 
arch/mips/include/asm/device.h +14 -1
index 06746c5..65bf274 100644
@@ -3,4 +3,17 @@
  *
  * This file is released under the GPLv2
  */
-#include <asm-generic/device.h>
+#ifndef _ASM_MIPS_DEVICE_H
+#define _ASM_MIPS_DEVICE_H
+
+struct mips_dma_map_ops;
+
+struct dev_archdata {
+	/* DMA operations on that device */
+	struct mips_dma_map_ops	*dma_ops;
+};
+
+struct pdev_archdata {
+};
+
+#endif /* _ASM_MIPS_DEVICE_H*/
arch/mips/include/asm/dma-mapping.h +0 -0
index 18fbf7a..9a4c307 100644

arch/mips/include/asm/dma-mapping.h line 12

Quoted 10 lines
arch/mips/include/asm/dma-mapping.h +5 -2
@@ -5,51 +5,67 @@
 #include <asm/cache.h>
 #include <asm-generic/dma-coherent.h>
 
-void *dma_alloc_noncoherent(struct device *dev, size_t size,
-			   dma_addr_t *dma_handle, gfp_t flag);
+struct mips_dma_map_ops {
+	struct dma_map_ops dma_map_ops;
+	dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
+	phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
+};

The above code doesn't look great but we don't want to add phys_to_dma and dma_to_phys to dma_map_ops struct, and these functions on MIPS looks too complicated for ifdef. So I guess that we need to live with the above code.

#8 lore raw

Re: [PATCH 5/9] MIPS: Convert DMA to use dma-mapping-common.h

Quoted 67 lines · FUJITA Tomonori
Quoted 64 lines · On Thu, 23 Sep 2010 15:38:12 -0700 David Daney<[email protected]>…

Use asm-generic/dma-mapping-common.h to handle all DMA mapping operations and establish a default get_dma_ops() that forwards all operations to the existing code.

Augment dev_archdata to carry a pointer to the struct dma_map_ops, allowing DMA operations to be overridden on a per device basis. Currently this is never filled in, so the default dma_map_ops are used. A follow-on patch sets this for Octeon PCI devices.

Also initialize the dma_debug system as it is now used if it is configured.

---
  arch/mips/Kconfig                   |    2 +
  arch/mips/include/asm/device.h      |   15 +++-
  arch/mips/include/asm/dma-mapping.h |  125 +++++++++++++++++--------
  arch/mips/mm/dma-default.c          |  179 +++++++++++++---------------------
  4 files changed, 172 insertions(+), 149 deletions(-)
arch/mips/Kconfig +2 -0
index 6c33709..e68b89f 100644
@@ -14,6 +14,8 @@ config MIPS
  	select HAVE_KRETPROBES
  	select RTC_LIB if !MACH_LOONGSON
  	select GENERIC_ATOMIC64 if !64BIT
+	select HAVE_DMA_ATTRS
+	select HAVE_DMA_API_DEBUG
 
  mainmenu "Linux/MIPS Kernel Configuration"
 
arch/mips/include/asm/device.h +14 -1
index 06746c5..65bf274 100644
@@ -3,4 +3,17 @@
   *
   * This file is released under the GPLv2
   */
-#include<asm-generic/device.h>
+#ifndef _ASM_MIPS_DEVICE_H
+#define _ASM_MIPS_DEVICE_H
+
+struct mips_dma_map_ops;
+
+struct dev_archdata {
+	/* DMA operations on that device */
+	struct mips_dma_map_ops	*dma_ops;
+};
+
+struct pdev_archdata {
+};
+
+#endif /* _ASM_MIPS_DEVICE_H*/
arch/mips/include/asm/dma-mapping.h +0 -0
index 18fbf7a..9a4c307 100644
@@ -5,51 +5,67 @@
  #include<asm/cache.h>
  #include<asm-generic/dma-coherent.h>
 
Quoted 13 lines

arch/mips/include/asm/dma-mapping.h line 12

Quoted 7 lines
arch/mips/include/asm/dma-mapping.h +5 -2
-void *dma_alloc_noncoherent(struct device *dev, size_t size,
-			   dma_addr_t *dma_handle, gfp_t flag);
+struct mips_dma_map_ops {
+	struct dma_map_ops dma_map_ops;
+	dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
+	phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
+};

The above code doesn't look great but we don't want to add phys_to_dma and dma_to_phys to dma_map_ops struct, and these functions on MIPS looks too complicated for ifdef. So I guess that we need to live with the above code.

I think you have a point here. I will attempt to move these two into a chip specific operations vector, and leave the more generic MIPS version with the simplified static definition.

Thanks,
David Daney

#9 lore raw

Re: [PATCH 5/9] MIPS: Convert DMA to use dma-mapping-common.h

Quoted 22 lines · On Mon, 27 Sep 2010 10:35:15 -0700 David Daney <[email protected]>…
Quoted 8 lines
Quoted 8 lines
arch/mips/include/asm/dma-mapping.h +0 -0
index 18fbf7a..9a4c307 100644
@@ -5,51 +5,67 @@
  #include<asm/cache.h>
  #include<asm-generic/dma-coherent.h>
 
Quoted 13 lines

arch/mips/include/asm/dma-mapping.h line 12

Quoted 7 lines
arch/mips/include/asm/dma-mapping.h +5 -2
-void *dma_alloc_noncoherent(struct device *dev, size_t size,
-			   dma_addr_t *dma_handle, gfp_t flag);
+struct mips_dma_map_ops {
+	struct dma_map_ops dma_map_ops;
+	dma_addr_t (*phys_to_dma)(struct device *dev, phys_addr_t paddr);
+	phys_addr_t (*dma_to_phys)(struct device *dev, dma_addr_t daddr);
+};

The above code doesn't look great but we don't want to add phys_to_dma and dma_to_phys to dma_map_ops struct, and these functions on MIPS looks too complicated for ifdef. So I guess that we need to live with the above code.

Quoted 3 lines

I think you have a point here. I will attempt to move these two into a chip specific operations vector, and leave the more generic MIPS version with the simplified static definition.

Yeah, that sounds a better (cleaner) approach.

#10 lore raw

PATCH 6/9 swiotlb: Declare swiotlb_init_with_default_size()

In reply to David Daney

It comes from swiotlb.c and must be called by external code, so declare it.

Cc Andrew Morton <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andre Goddard Rosa <[email protected]>
---
 include/linux/swiotlb.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/swiotlb.h +1 -0
index 8c0e349..dba51fe 100644
@@ -23,6 +23,7 @@ extern int swiotlb_force;
 #define IO_TLB_SHIFT 11
 
 extern void swiotlb_init(int verbose);
+extern void swiotlb_init_with_default_size(size_t, int);
 extern void swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
 
 /*
Signature · 1 line
1.7.2.2
#11 lore raw

Re: [PATCH 6/9] swiotlb: Declare swiotlb_init_with_default_size()

Quoted 17 lines · David Daney

It comes from swiotlb.c and must be called by external code, so declare it.

Cc Andrew Morton <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andre Goddard Rosa <[email protected]>
---
 include/linux/swiotlb.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
include/linux/swiotlb.h +0 -0
index 8c0e349..dba51fe 100644

include/linux/swiotlb.h extern int swiotlb_force; · line 27

Quoted 5 lines
include/linux/swiotlb.h +1 -0
@@ -23,6 +23,7 @@ extern int swiotlb_force;
 #define IO_TLB_SHIFT 11
 
 extern void swiotlb_init(int verbose);
+extern void swiotlb_init_with_default_size(size_t, int);
 extern void swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);

Just use the swiotlb_init_with_tbl. If you need an example of how it is utilized, take a look at how swiotlb-xen.c does it.

#12 lore raw

PATCH 7/9 swiotlb: Make bounce buffer bounds non-static.

In reply to David Daney

Octeon PCI mapping has to be established to cover the bounce buffers, so it has to have access to the bounds.

Rename the bounds variables to match the names of other parts of swiotlb.

Cc Andrew Morton <[email protected]>
Cc FUJITA Tomonori <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Andre Goddard Rosa <[email protected]>
---
 include/linux/swiotlb.h |    6 ++++
 lib/swiotlb.c           |   62 +++++++++++++++++++++++-----------------------
 2 files changed, 37 insertions(+), 31 deletions(-)
include/linux/swiotlb.h +6 -0
index dba51fe..0b8fbe9 100644
@@ -22,6 +22,12 @@ extern int swiotlb_force;
  */
 #define IO_TLB_SHIFT 11
 
+/*
+ * The memory range used by the swiotlb
+ */
+extern char *swiotlb_start;
+extern char *swiotlb_end;
+
 extern void swiotlb_init(int verbose);
 extern void swiotlb_init_with_default_size(size_t, int);
 extern void swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
lib/swiotlb.c +31 -31

169 lines not on this page · raw message

Signature · 1 line
1.7.2.2
#13 lore raw

Re: [PATCH 7/9] swiotlb: Make bounce buffer bounds non-static.

Quoted 2 lines · On Thu, 23 Sep 2010 15:47:31 -0700 David Daney <[email protected]>…

Octeon PCI mapping has to be established to cover the bounce buffers, so it has to have access to the bounds.

Why can't you use swiotlb_init_with_tbl() instead?

#14 lore raw

Re: [PATCH 7/9] swiotlb: Make bounce buffer bounds non-static.

Quoted 8 lines · FUJITA Tomonori
Quoted 2 lines · On Thu, 23 Sep 2010 15:47:31 -0700 David Daney<[email protected]>…

Octeon PCI mapping has to be established to cover the bounce buffers, so it has to have access to the bounds.

Why can't you use swiotlb_init_with_tbl() instead?

Yes, as pointed out be several people, that would be better.

The swiotlb_init_with_tbl() didn't exist in earlier kernel versions and this simplification was missed when I forward ported the patch set.

By using this function, I think the entire patch set will be MIPS specific, making it unnecessary to touch the generic swiotlb code.

Thanks,
David Daney

#15 lore raw

PATCH 8/9 MIPS: Add a platform hook for swiotlb setup.

In reply to David Daney

This allows platforms that are using the swiotlb to initialize it.

---
 arch/mips/include/asm/bootinfo.h |    5 +++++
 arch/mips/kernel/setup.c         |    5 +++++
 2 files changed, 10 insertions(+), 0 deletions(-)
arch/mips/include/asm/bootinfo.h +5 -0
index 15a8ef0..b3cf989 100644
@@ -125,4 +125,9 @@ extern unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  */
 extern void plat_mem_setup(void);
 
+/*
+ * Optional platform hook to call swiotlb_setup().
+ */
+extern void plat_swiotlb_setup(void);
+
 #endif /* _ASM_BOOTINFO_H */
arch/mips/kernel/setup.c +5 -0
index 85aef3f..8b650da 100644
@@ -488,6 +488,11 @@ static void __init arch_mem_init(char **cmdline_p)
 
 	bootmem_init();
 	sparse_init();
+
+#ifdef CONFIG_SWIOTLB
+	plat_swiotlb_setup();
+#endif
+
 	paging_init();
 }
 
Signature · 1 line
1.7.2.2
#16 lore raw

Re: [PATCH 8/9] MIPS: Add a platform hook for swiotlb setup.

Hello.

Quoted 27 lines · David Daney

This allows platforms that are using the swiotlb to initialize it.

---
 arch/mips/include/asm/bootinfo.h |    5 +++++
 arch/mips/kernel/setup.c         |    5 +++++
 2 files changed, 10 insertions(+), 0 deletions(-)
arch/mips/include/asm/bootinfo.h +5 -0
index 15a8ef0..b3cf989 100644
@@ -125,4 +125,9 @@ extern unsigned long fw_arg0, fw_arg1, fw_arg2, fw_arg3;
  */
 extern void plat_mem_setup(void);
 
+/*
+ * Optional platform hook to call swiotlb_setup().
+ */
+extern void plat_swiotlb_setup(void);
+
 #endif /* _ASM_BOOTINFO_H */
arch/mips/kernel/setup.c +0 -0
index 85aef3f..8b650da 100644

arch/mips/kernel/setup.c static void __init arch_mem_init(char **cmdline_p) · line 494

Quoted 7 lines
arch/mips/kernel/setup.c +4 -0
@@ -488,6 +488,11 @@ static void __init arch_mem_init(char **cmdline_p)
 
 	bootmem_init();
 	sparse_init();
+
+#ifdef CONFIG_SWIOTLB
+	plat_swiotlb_setup();
+#endif

We should avoid #ifdef's in function bodies. Why not defile an empty
'inline' in the header above if CONFIG_SWIOTLB is not defined?

WBR, Sergei

#17 lore raw

Re: [PATCH 8/9] MIPS: Add a platform hook for swiotlb setup.

Quoted 34 lines · Sergei Shtylyov

Hello.

Quoted 30 lines · David Daney

This allows platforms that are using the swiotlb to initialize it.

---
arch/mips/include/asm/bootinfo.h | 5 +++++
arch/mips/kernel/setup.c | 5 +++++

2 files changed, 10 insertions(+), 0 deletions(-)
arch/mips/include/asm/bootinfo.h +5 -0
index 15a8ef0..b3cf989 100644
@@ -125,4 +125,9 @@ extern unsigned long fw_arg0, fw_arg1, fw_arg2,
 fw_arg3;
 */
 extern void plat_mem_setup(void);
 
+/*
+ * Optional platform hook to call swiotlb_setup().
+ */
+extern void plat_swiotlb_setup(void);
+

#endif /* _ASM_BOOTINFO_H */

arch/mips/kernel/setup.c +0 -0
index 85aef3f..8b650da 100644
@@ -488,6 +488,11 @@ static void __init arch_mem_init(char **cmdline_p)
 
Quoted 10 lines

arch/mips/kernel/setup.c static void __init arch_mem_init(char **cmdline_p) · line 494

Quoted 6 lines
arch/mips/kernel/setup.c +4 -0
 bootmem_init();
 sparse_init();
+
+#ifdef CONFIG_SWIOTLB
+ plat_swiotlb_setup();
+#endif

We should avoid #ifdef's in function bodies. Why not defile an empty 'inline' in the header above if CONFIG_SWIOTLB is not defined?

Good idea. I will wait several days and collect any more feedback and generate a new patch set.

David Daney

#18 lore raw

Re: [PATCH 8/9] MIPS: Add a platform hook for swiotlb setup.

Quoted 10 lines · David Daney
Quoted 7 lines

arch/mips/kernel/setup.c static void __init arch_mem_init(char **cmdline_p) · line 494

Quoted 3 lines
arch/mips/kernel/setup.c +3 -0
+#ifdef CONFIG_SWIOTLB
+ plat_swiotlb_setup();
+#endif

We should avoid #ifdef's in function bodies. Why not defile an empty 'inline' in the header above if CONFIG_SWIOTLB is not defined?

Good idea. I will wait several days and collect any more feedback and generate a new patch set.

I'd also wait for a few more days so interested parties outside of the MIPS world will have a chance to comment.

Ralf

#19 lore raw

PATCH 9/9 MIPS: Octeon: Rewrite DMA mapping functions.

In reply to David Daney

All Octeon chips can support more than 4GB of RAM. Also due to how Octeon PCI is setup, even some configurations with less than 4GB of RAM will have portions that are not accessible from 32-bit devices.

Enable the swiotlb code to handle the cases where a device cannot directly do DMA. This is a complete rewrite of the Octeon DMA mapping code.

---
 arch/mips/cavium-octeon/Kconfig                    |   12 +
 arch/mips/cavium-octeon/dma-octeon.c               |  529 +++++++++-----------
 .../include/asm/mach-cavium-octeon/dma-coherence.h |   19 +-
 arch/mips/include/asm/octeon/pci-octeon.h          |   10 +
 arch/mips/pci/pci-octeon.c                         |   60 ++-
 arch/mips/pci/pcie-octeon.c                        |    5 +
 6 files changed, 336 insertions(+), 299 deletions(-)
arch/mips/cavium-octeon/Kconfig +12 -0
index 47323ca..475156b 100644
@@ -87,3 +87,15 @@ config ARCH_SPARSEMEM_ENABLE
 config CAVIUM_OCTEON_HELPER
 	def_bool y
 	depends on OCTEON_ETHERNET || PCI
+
+config IOMMU_HELPER
+	bool
+
+config NEED_SG_DMA_LENGTH
+	bool
+
+config SWIOTLB
+	def_bool y
+	depends on CPU_CAVIUM_OCTEON
+	select IOMMU_HELPER
+	select NEED_SG_DMA_LENGTH
arch/mips/cavium-octeon/dma-octeon.c +245 -284

580 lines not on this page · raw message

arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h +10 -9
index 17d5794..a0058fb 100644
@@ -15,41 +15,40 @@
 
 struct device;
 
-dma_addr_t octeon_map_dma_mem(struct device *, void *, size_t);
-void octeon_unmap_dma_mem(struct device *, dma_addr_t);
+void octeon_pci_dma_init(void);
 
 static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 	size_t size)
 {
-	return octeon_map_dma_mem(dev, addr, size);
+	BUG();
 }
 
 static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
 	struct page *page)
 {
-	return octeon_map_dma_mem(dev, page_address(page), PAGE_SIZE);
+	BUG();
 }
 
 static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
-	return dma_addr;
+	BUG();
 }
 
 static inline void plat_unmap_dma_mem(struct device *dev, dma_addr_t dma_addr,
 	size_t size, enum dma_data_direction direction)
 {
-	octeon_unmap_dma_mem(dev, dma_addr);
+	BUG();
 }
 
 static inline int plat_dma_supported(struct device *dev, u64 mask)
 {
-	return 1;
+	BUG();
 }
 
 static inline void plat_extra_sync_for_device(struct device *dev)
 {
-	mb();
+	BUG();
 }
 
 static inline int plat_device_is_coherent(struct device *dev)
@@ -60,7 +59,9 @@ static inline int plat_device_is_coherent(struct device *dev)
 static inline int plat_dma_mapping_error(struct device *dev,
 					 dma_addr_t dma_addr)
 {
-	return dma_addr == -1;
+	BUG();
 }
 
+extern struct mips_dma_map_ops octeon_pci_dma_map_ops;
+
 #endif /* __ASM_MACH_CAVIUM_OCTEON_DMA_COHERENCE_H */
arch/mips/include/asm/octeon/pci-octeon.h +10 -0
index ece7804..fba2ba2 100644
@@ -36,6 +36,16 @@ extern int (*octeon_pcibios_map_irq)(const struct pci_dev *dev,
 				     u8 slot, u8 pin);
 
 /*
+ * For PCI (not PCIe) the BAR2 base address.
+ */
+#define OCTEON_BAR2_PCI_ADDRESS 0x8000000000ull
+
+/*
+ * For PCI (not PCIe) the base of the memory mapped by BAR1
+ */
+extern u64 octeon_bar1_pci_phys;
+
+/*
  * The following defines are used when octeon_dma_bar_type =
  * OCTEON_DMA_BAR_TYPE_BIG
  */
arch/mips/pci/pci-octeon.c +54 -6

108 lines not on this page · raw message

arch/mips/pci/pcie-octeon.c +5 -0
index 861361e..385f035 100644
@@ -75,6 +75,8 @@ union cvmx_pcie_address {
 	} mem;
 };
 
+#include <dma-coherence.h>
+
 /**
  * Return the Core virtual base address for PCIe IO access. IOs are
  * read/written as an offset from this address.
@@ -1391,6 +1393,9 @@ static int __init octeon_pcie_setup(void)
 			cvmx_pcie_get_io_size(1) - 1;
 		register_pci_controller(&octeon_pcie1_controller);
 	}
+
+	octeon_pci_dma_init();
+
 	return 0;
 }
 
Signature · 1 line
1.7.2.2
#20 lore raw

PATCH 1/1 MIPS: Octeon: Remove plat_map_dma_mem_page().

It is now unused.

---

This is a small addition to the rest of the patch set. It could be rolled into [PATCH 9/9] MIPS: Octeon: Rewrite DMA mapping functions.

 .../include/asm/mach-cavium-octeon/dma-coherence.h |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
arch/mips/include/asm/mach-cavium-octeon/dma-coherence.h +0 -6
index a0058fb..cedf254 100644
@@ -23,12 +23,6 @@ static inline dma_addr_t plat_map_dma_mem(struct device *dev, void *addr,
 	BUG();
 }
 
-static inline dma_addr_t plat_map_dma_mem_page(struct device *dev,
-	struct page *page)
-{
-	BUG();
-}
-
 static inline unsigned long plat_dma_addr_to_phys(struct device *dev,
 	dma_addr_t dma_addr)
 {
Signature · 1 line
1.7.2.2