Skip to contentSkip to conversation

Consolidate zone adjustment

PATCH New Russell King - ARM Linux 4 participants 9 messages May 11, 2011 – May 19, 2011

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

cover Consolidate zone adjustment

This patch mini-series consolidates the adjustment to system zones which some of our platforms require. Rather than having each platform/machine class specify ISA_DMA_THRESHOLD, MAX_DMA_ADDRESS and an arch_adjust_zones function, they really only need to provide a single sizing definition, which in this series will be called ARM_DMA_ZONE_SIZE.

 arch/arm/common/sa1111.c                     |    8 -------
 arch/arm/include/asm/dma.h                   |    4 ++-
 arch/arm/include/asm/memory.h                |   10 ++------
 arch/arm/mach-davinci/include/mach/memory.h  |   18 +----------------
 arch/arm/mach-h720x/include/mach/memory.h    |    3 +-
 arch/arm/mach-ixp4xx/common-pci.c            |   23 ----------------------
 arch/arm/mach-ixp4xx/include/mach/memory.h   |   12 +---------
 arch/arm/mach-pxa/cm-x2xx-pci.c              |   27 --------------------------
 arch/arm/mach-pxa/include/mach/memory.h      |   10 +-------
 arch/arm/mach-realview/core.c                |   19 ------------------
 arch/arm/mach-realview/include/mach/memory.h |    9 +------
 arch/arm/mach-sa1100/include/mach/memory.h   |   12 +----------
 arch/arm/mach-shark/include/mach/memory.h    |   20 +------------------
 arch/arm/mm/init.c                           |   23 +++++++++++++++++++++-
 14 files changed, 38 insertions(+), 160 deletions(-)
#1 lore raw

PATCH 1/2 ARM: Replace platform definition of ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS

The values of ISA_DMA_THRESHOLD and MAX_DMA_ADDRESS are related; one is the physical/bus address, the other is the virtual address. Both need to be kept in step, so rather than having platforms define both, allow them to define a single macro which sets both of these macros appropraitely.

---
 arch/arm/include/asm/dma.h                   |    4 +++-
 arch/arm/include/asm/memory.h                |    4 +++-
 arch/arm/mach-davinci/include/mach/memory.h  |    3 +--
 arch/arm/mach-h720x/include/mach/memory.h    |    3 +--
 arch/arm/mach-ixp4xx/include/mach/memory.h   |    3 +--
 arch/arm/mach-pxa/include/mach/memory.h      |    3 +--
 arch/arm/mach-realview/include/mach/memory.h |    3 +--
 arch/arm/mach-sa1100/include/mach/memory.h   |    3 +--
 arch/arm/mach-shark/include/mach/memory.h    |    3 +--
 9 files changed, 13 insertions(+), 16 deletions(-)
arch/arm/include/asm/dma.h +3 -1
index ca51143..4200554 100644
@@ -6,8 +6,10 @@
 /*
  * This is the maximum virtual address which can be DMA'd from.
  */
-#ifndef MAX_DMA_ADDRESS
+#ifndef ARM_DMA_ZONE_SIZE
 #define MAX_DMA_ADDRESS	0xffffffff
+#else
+#define MAX_DMA_ADDRESS	(PAGE_OFFSET + ARM_DMA_ZONE_SIZE)
 #endif
 
 #ifdef CONFIG_ISA_DMA_API
arch/arm/include/asm/memory.h +3 -1
index 431077c..ee5ff41 100644
@@ -209,8 +209,10 @@ static inline unsigned long __phys_to_virt(unsigned long x)
  * allocations.  This must be the smallest DMA mask in the system,
  * so a successful GFP_DMA allocation will always satisfy this.
  */
-#ifndef ISA_DMA_THRESHOLD
+#ifndef ARM_DMA_ZONE_SIZE
 #define ISA_DMA_THRESHOLD	(0xffffffffULL)
+#else
+#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + ARM_DMA_ZONE_SIZE - 1)
 #endif
 
 #ifndef arch_adjust_zones
arch/arm/mach-davinci/include/mach/memory.h +1 -2
index 7882272..8d27246 100644
@@ -59,8 +59,7 @@ __arch_adjust_zones(unsigned long *size, unsigned long *holes)
 #define arch_adjust_zones(zone_size, holes) \
         if ((meminfo.bank[0].size >> 20) > 128) __arch_adjust_zones(zone_size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + (128<<20) - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + (128<<20))
+#define ARM_DMA_ZONE_SIZE	SZ_128M
 
 #endif
 
arch/arm/mach-h720x/include/mach/memory.h +1 -2
index 9d36876..b0b3bae 100644
@@ -13,7 +13,6 @@
  * There should not be more than (0xd0000000 - 0xc0000000)
  * bytes of RAM.
  */
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_256M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_256M)
+#define ARM_DMA_ZONE_SIZE	SZ_256M
 
 #endif
arch/arm/mach-ixp4xx/include/mach/memory.h +1 -2
index 6d388c9..a5c26f8 100644
@@ -21,8 +21,7 @@ void ixp4xx_adjust_zones(unsigned long *size, unsigned long *holes);
 #define arch_adjust_zones(size, holes) \
 	ixp4xx_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD (SZ_64M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_64M)
+#define ARM_DMA_ZONE_SIZE	SZ_64M
 
 #endif
 
arch/arm/mach-pxa/include/mach/memory.h +1 -2
index 7f68724..57a0b68 100644
@@ -23,8 +23,7 @@ void cmx2xx_pci_adjust_zones(unsigned long *size, unsigned long *holes);
 #define arch_adjust_zones(size, holes) \
 	cmx2xx_pci_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_64M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_64M)
+#define ARM_DMA_ZONE_SIZE	SZ_64M
 #endif
 
 #endif
arch/arm/mach-realview/include/mach/memory.h +1 -2
index e05fc2c..973428d 100644
@@ -34,8 +34,7 @@ extern void realview_adjust_zones(unsigned long *size, unsigned long *hole);
 #define arch_adjust_zones(size, hole) \
 	realview_adjust_zones(size, hole)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_256M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_256M)
+#define ARM_DMA_ZONE_SIZE	SZ_256M
 #endif
 
 #ifdef CONFIG_SPARSEMEM
arch/arm/mach-sa1100/include/mach/memory.h +1 -2
index a44da6a..090b829 100644
@@ -22,8 +22,7 @@ void sa1111_adjust_zones(unsigned long *size, unsigned long *holes);
 #define arch_adjust_zones(size, holes) \
 	sa1111_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_1M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_1M)
+#define ARM_DMA_ZONE_SIZE	SZ_1M
 
 #endif
 #endif
arch/arm/mach-shark/include/mach/memory.h +1 -2
index 9afb170..48fe84b 100644
@@ -32,8 +32,7 @@ static inline void __arch_adjust_zones(unsigned long *zone_size, unsigned long *
 #define arch_adjust_zones(size, holes) \
 	__arch_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_4M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_4M)
+#define ARM_DMA_ZONE_SIZE	SZ_4M
 
 #endif
 
Signature · 1 line
1.7.4.4
#4 lore raw

PATCH 2/2 ARM: use ARM_DMA_ZONE_SIZE to adjust the zone sizes

In reply to Russell King - ARM Linux

Rather than each platform providing its own function to adjust the zone sizes, use the new ARM_DMA_ZONE_SIZE definition to perform this adjustment. This ensures that the actual DMA zone size and the ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS definitions are consistent with each other, and moves this complexity out of the platform code.

---
 arch/arm/common/sa1111.c                     |    8 -------
 arch/arm/include/asm/memory.h                |    6 -----
 arch/arm/mach-davinci/include/mach/memory.h  |   15 --------------
 arch/arm/mach-ixp4xx/common-pci.c            |   23 ----------------------
 arch/arm/mach-ixp4xx/include/mach/memory.h   |    9 +-------
 arch/arm/mach-pxa/cm-x2xx-pci.c              |   27 --------------------------
 arch/arm/mach-pxa/include/mach/memory.h      |    7 +-----
 arch/arm/mach-realview/core.c                |   19 ------------------
 arch/arm/mach-realview/include/mach/memory.h |    6 +----
 arch/arm/mach-sa1100/include/mach/memory.h   |    9 --------
 arch/arm/mach-shark/include/mach/memory.h    |   17 ----------------
 arch/arm/mm/init.c                           |   23 +++++++++++++++++++++-
 12 files changed, 25 insertions(+), 144 deletions(-)
arch/arm/common/sa1111.c +0 -8
index a12b33c..9c49a46 100644
@@ -185,14 +185,6 @@ static struct sa1111_dev_info sa1111_devices[] = {
 	},
 };
 
-void __init sa1111_adjust_zones(unsigned long *size, unsigned long *holes)
-{
-	unsigned int sz = SZ_1M >> PAGE_SHIFT;
-
-	size[1] = size[0] - sz;
-	size[0] = sz;
-}
-
 /*
  * SA1111 interrupt support.  Since clearing an IRQ while there are
  * active IRQs causes the interrupt output to pulse, the upper levels
arch/arm/include/asm/memory.h +0 -6
index ee5ff41..af44a8f 100644
@@ -215,12 +215,6 @@ static inline unsigned long __phys_to_virt(unsigned long x)
 #define ISA_DMA_THRESHOLD	(PHYS_OFFSET + ARM_DMA_ZONE_SIZE - 1)
 #endif
 
-#ifndef arch_adjust_zones
-#define arch_adjust_zones(size,holes) do { } while (0)
-#elif !defined(CONFIG_ZONE_DMA)
-#error "custom arch_adjust_zones() requires CONFIG_ZONE_DMA"
-#endif
-
 /*
  * PFNs are used to describe any physical page; this means
  * PFN 0 == physical address 0.
arch/arm/mach-davinci/include/mach/memory.h +0 -15
index 8d27246..491249e 100644
@@ -41,26 +41,11 @@
  */
 #define CONSISTENT_DMA_SIZE (14<<20)
 
-#ifndef __ASSEMBLY__
 /*
  * Restrict DMA-able region to workaround silicon bug.  The bug
  * restricts buffers available for DMA to video hardware to be
  * below 128M
  */
-static inline void
-__arch_adjust_zones(unsigned long *size, unsigned long *holes)
-{
-	unsigned int sz = (128<<20) >> PAGE_SHIFT;
-
-	size[1] = size[0] - sz;
-	size[0] = sz;
-}
-
-#define arch_adjust_zones(zone_size, holes) \
-        if ((meminfo.bank[0].size >> 20) > 128) __arch_adjust_zones(zone_size, holes)
-
 #define ARM_DMA_ZONE_SIZE	SZ_128M
 
-#endif
-
 #endif /* __ASM_ARCH_MEMORY_H */
arch/arm/mach-ixp4xx/common-pci.c +0 -23
index a54b3db..e9a5893 100644
@@ -342,29 +342,6 @@ int dma_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
 	return (dev->bus == &pci_bus_type ) && ((dma_addr + size) >= SZ_64M);
 }
 
-/*
- * Only first 64MB of memory can be accessed via PCI.
- * We use GFP_DMA to allocate safe buffers to do map/unmap.
- * This is really ugly and we need a better way of specifying
- * DMA-capable regions of memory.
- */
-void __init ixp4xx_adjust_zones(unsigned long *zone_size,
-	unsigned long *zhole_size)
-{
-	unsigned int sz = SZ_64M >> PAGE_SHIFT;
-
-	/*
-	 * Only adjust if > 64M on current system
-	 */
-	if (zone_size[0] <= sz)
-		return;
-
-	zone_size[1] = zone_size[0] - sz;
-	zone_size[0] = sz;
-	zhole_size[1] = zhole_size[0];
-	zhole_size[0] = 0;
-}
-
 void __init ixp4xx_pci_preinit(void)
 {
 	unsigned long cpuid = read_cpuid_id();
arch/arm/mach-ixp4xx/include/mach/memory.h +1 -8
index a5c26f8..34e7940 100644
@@ -14,15 +14,8 @@
  */
 #define PLAT_PHYS_OFFSET	UL(0x00000000)
 
-#if !defined(__ASSEMBLY__) && defined(CONFIG_PCI)
-
-void ixp4xx_adjust_zones(unsigned long *size, unsigned long *holes);
-
-#define arch_adjust_zones(size, holes) \
-	ixp4xx_adjust_zones(size, holes)
-
+#ifdef CONFIG_PCI
 #define ARM_DMA_ZONE_SIZE	SZ_64M
-
 #endif
 
 #endif
arch/arm/mach-pxa/cm-x2xx-pci.c +0 -27
index 8b1a309..1afc0fb 100644
@@ -29,33 +29,6 @@
 unsigned long it8152_base_address;
 static int cmx2xx_it8152_irq_gpio;
 
-/*
- * Only first 64MB of memory can be accessed via PCI.
- * We use GFP_DMA to allocate safe buffers to do map/unmap.
- * This is really ugly and we need a better way of specifying
- * DMA-capable regions of memory.
- */
-void __init cmx2xx_pci_adjust_zones(unsigned long *zone_size,
-	unsigned long *zhole_size)
-{
-	unsigned int sz = SZ_64M >> PAGE_SHIFT;
-
-	if (machine_is_armcore()) {
-		pr_info("Adjusting zones for CM-X2XX\n");
-
-		/*
-		 * Only adjust if > 64M on current system
-		 */
-		if (zone_size[0] <= sz)
-			return;
-
-		zone_size[1] = zone_size[0] - sz;
-		zone_size[0] = sz;
-		zhole_size[1] = zhole_size[0];
-		zhole_size[0] = 0;
-	}
-}
-
 static void cmx2xx_it8152_irq_demux(unsigned int irq, struct irq_desc *desc)
 {
 	/* clear our parent irq */
arch/arm/mach-pxa/include/mach/memory.h +1 -6
index 57a0b68..07734f3 100644
@@ -17,12 +17,7 @@
  */
 #define PLAT_PHYS_OFFSET	UL(0xa0000000)
 
-#if !defined(__ASSEMBLY__) && defined(CONFIG_MACH_ARMCORE) && defined(CONFIG_PCI)
-void cmx2xx_pci_adjust_zones(unsigned long *size, unsigned long *holes);
-
-#define arch_adjust_zones(size, holes) \
-	cmx2xx_pci_adjust_zones(size, holes)
-
+#if defined(CONFIG_MACH_ARMCORE) && defined(CONFIG_PCI)
 #define ARM_DMA_ZONE_SIZE	SZ_64M
 #endif
 
arch/arm/mach-realview/core.c +0 -19
index 75dbc87..525ad17 100644
@@ -56,25 +56,6 @@
 
 #include "core.h"
 
-#ifdef CONFIG_ZONE_DMA
-/*
- * Adjust the zones if there are restrictions for DMA access.
- */
-void __init realview_adjust_zones(unsigned long *size, unsigned long *hole)
-{
-	unsigned long dma_size = SZ_256M >> PAGE_SHIFT;
-
-	if (!machine_is_realview_pbx() || size[0] <= dma_size)
-		return;
-
-	size[ZONE_NORMAL] = size[0] - dma_size;
-	size[ZONE_DMA] = dma_size;
-	hole[ZONE_NORMAL] = hole[0];
-	hole[ZONE_DMA] = 0;
-}
-#endif
-
-
 #define REALVIEW_FLASHCTRL    (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
 
 static int realview_flash_init(void)
arch/arm/mach-realview/include/mach/memory.h +1 -5
index 973428d..1759fa6 100644
@@ -29,11 +29,7 @@
 #define PLAT_PHYS_OFFSET		UL(0x00000000)
 #endif
 
-#if !defined(__ASSEMBLY__) && defined(CONFIG_ZONE_DMA)
-extern void realview_adjust_zones(unsigned long *size, unsigned long *hole);
-#define arch_adjust_zones(size, hole) \
-	realview_adjust_zones(size, hole)
-
+#ifdef CONFIG_ZONE_DMA
 #define ARM_DMA_ZONE_SIZE	SZ_256M
 #endif
 
arch/arm/mach-sa1100/include/mach/memory.h +0 -9
index 090b829..cff31ee 100644
@@ -14,17 +14,8 @@
  */
 #define PLAT_PHYS_OFFSET	UL(0xc0000000)
 
-#ifndef __ASSEMBLY__
-
 #ifdef CONFIG_SA1111
-void sa1111_adjust_zones(unsigned long *size, unsigned long *holes);
-
-#define arch_adjust_zones(size, holes) \
-	sa1111_adjust_zones(size, holes)
-
 #define ARM_DMA_ZONE_SIZE	SZ_1M
-
-#endif
 #endif
 
 /*
arch/arm/mach-shark/include/mach/memory.h +0 -17
index 48fe84b..4c0831f8 100644
@@ -17,25 +17,8 @@
  */
 #define PLAT_PHYS_OFFSET     UL(0x08000000)
 
-#ifndef __ASSEMBLY__
-
-static inline void __arch_adjust_zones(unsigned long *zone_size, unsigned long *zhole_size)
-{
-  /* Only the first 4 MB (=1024 Pages) are usable for DMA */
-  /* See dev / -> .properties in OpenFirmware. */
-  zone_size[1] = zone_size[0] - 1024;
-  zone_size[0] = 1024;
-  zhole_size[1] = zhole_size[0];
-  zhole_size[0] = 0;
-}
-
-#define arch_adjust_zones(size, holes) \
-	__arch_adjust_zones(size, holes)
-
 #define ARM_DMA_ZONE_SIZE	SZ_4M
 
-#endif
-
 /*
  * Cache flushing area
  */
arch/arm/mm/init.c +22 -1
index e5f6fc4..49eaad9 100644
@@ -201,6 +201,20 @@ static void __init arm_bootmem_init(unsigned long start_pfn,
 	}
 }
 
+#ifdef CONFIG_ZONE_DMA
+static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole,
+	unsigned long dma_size)
+{
+	if (size[0] <= dma_size)
+		return;
+
+	size[ZONE_NORMAL] = size[0] - dma_size;
+	size[ZONE_DMA] = dma_size;
+	hole[ZONE_NORMAL] = hole[0];
+	hole[ZONE_DMA] = 0;
+}
+#endif
+
 static void __init arm_bootmem_free(unsigned long min, unsigned long max_low,
 	unsigned long max_high)
 {
@@ -243,11 +257,18 @@ static void __init arm_bootmem_free(unsigned long min, unsigned long max_low,
 #endif
 	}
 
+#ifdef ARM_DMA_ZONE_SIZE
+#ifndef CONFIG_ZONE_DMA
+#error ARM_DMA_ZONE_SIZE set but no DMA zone to limit allocations
+#endif
+
 	/*
 	 * Adjust the sizes according to any special requirements for
 	 * this machine type.
 	 */
-	arch_adjust_zones(zone_size, zhole_size);
+	arm_adjust_dma_zone(zone_size, zhole_size,
+		ARM_DMA_ZONE_SIZE >> PAGE_SHIFT);
+#endif
 
 	free_area_init_node(0, zone_size, min, zhole_size);
 }
Signature · 1 line
1.7.4.4
#5 lore raw

PATCH 2/2 ARM: use ARM_DMA_ZONE_SIZE to adjust the zone sizes

Quoted 5 lines · Russell King - ARM Linux

Rather than each platform providing its own function to adjust the zone sizes, use the new ARM_DMA_ZONE_SIZE definition to perform this adjustment. This ensures that the actual DMA zone size and the ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS definitions are consistent with each other, and moves this complexity out of the platform code.

...

Quoted 6 lines
arch/arm/mach-realview/include/mach/memory.h +0 -0
index 973428d..1759fa6 100644
@@ -29,11 +29,7 @@
 #define PLAT_PHYS_OFFSET               UL(0x00000000)

arch/arm/mach-realview/include/mach/memory.h line 34

Quoted 10 lines
arch/arm/mach-realview/include/mach/memory.h +1 -5
 #endif
 
-#if !defined(__ASSEMBLY__) && defined(CONFIG_ZONE_DMA)
-extern void realview_adjust_zones(unsigned long *size, unsigned long *hole);
-#define arch_adjust_zones(size, hole) \
-       realview_adjust_zones(size, hole)
-
+#ifdef CONFIG_ZONE_DMA
 #define ARM_DMA_ZONE_SIZE      SZ_256M
 #endif

We only use ZONE_DMA for PBX and realview_adjust_zones() does this check. We end up with limiting the DMA zone to 256MB on all RealView platforms if we compile a single kernel image that includes PBX. Not a big problem though:

#2 lore raw

PATCH 1/2 ARM: Replace platform definition of ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS

In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux

The values of ISA_DMA_THRESHOLD and MAX_DMA_ADDRESS are related; one is the physical/bus address, the other is the virtual address. Both need to be kept in step, so rather than having platforms define both, allow them to define a single macro which sets both of these macros appropraitely.

#6 lore raw

PATCH 2/2 ARM: use ARM_DMA_ZONE_SIZE to adjust the zone sizes

In reply to Catalin Marinas
Quoted 15 lines · Catalin Marinas
Quoted 5 lines · Russell King - ARM Linux

Rather than each platform providing its own function to adjust the zone sizes, use the new ARM_DMA_ZONE_SIZE definition to perform this adjustment. This ensures that the actual DMA zone size and the ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS definitions are consistent with each other, and moves this complexity out of the platform code.

...

Quoted 8 lines
arch/arm/mach-realview/include/mach/memory.h +0 -0
index 973428d..1759fa6 100644
@@ -29,11 +29,7 @@
 #define PLAT_PHYS_OFFSET               UL(0x00000000)
 #endif
 
Quoted 13 lines

arch/arm/mach-realview/include/mach/memory.h line 34

Quoted 8 lines
arch/arm/mach-realview/include/mach/memory.h +1 -5
-#if !defined(__ASSEMBLY__) && defined(CONFIG_ZONE_DMA)
-extern void realview_adjust_zones(unsigned long *size, unsigned long *hole);
-#define arch_adjust_zones(size, hole) \
-       realview_adjust_zones(size, hole)
-
+#ifdef CONFIG_ZONE_DMA
 #define ARM_DMA_ZONE_SIZE      SZ_256M
 #endif

We only use ZONE_DMA for PBX and realview_adjust_zones() does this check. We end up with limiting the DMA zone to 256MB on all RealView platforms if we compile a single kernel image that includes PBX. Not a big problem though:

You've already implicitly limited it by the ISA_DMA_THRESHOLD/ MAX_DMA_ADDRESS definition - what's left is an inconsistent relative size of those definitions and the actual DMA zone. That inconsistency can cause the DMA allocator to fail unexpectedly as it assumes that GFP_DMA will return a page which will satisfy ISA_DMA_THRESHOLD.

Quoted 1 line

Thanks.

#3 lore raw

PATCH 1/2 ARM: Replace platform definition of ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS

In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux

The values of ISA_DMA_THRESHOLD and MAX_DMA_ADDRESS are related; one is the physical/bus address, the other is the virtual address. Both need to be kept in step, so rather than having platforms define both, allow them to define a single macro which sets both of these macros appropraitely.

Quoted 144 lines
---
 arch/arm/include/asm/dma.h                   |    4 +++-
 arch/arm/include/asm/memory.h                |    4 +++-
 arch/arm/mach-davinci/include/mach/memory.h  |    3 +--
 arch/arm/mach-h720x/include/mach/memory.h    |    3 +--
 arch/arm/mach-ixp4xx/include/mach/memory.h   |    3 +--
 arch/arm/mach-pxa/include/mach/memory.h      |    3 +--
 arch/arm/mach-realview/include/mach/memory.h |    3 +--
 arch/arm/mach-sa1100/include/mach/memory.h   |    3 +--
 arch/arm/mach-shark/include/mach/memory.h    |    3 +--
 9 files changed, 13 insertions(+), 16 deletions(-)
arch/arm/include/asm/dma.h +3 -1
index ca51143..4200554 100644
@@ -6,8 +6,10 @@
 /*
  * This is the maximum virtual address which can be DMA'd from.
  */
-#ifndef MAX_DMA_ADDRESS
+#ifndef ARM_DMA_ZONE_SIZE
 #define MAX_DMA_ADDRESS	0xffffffff
+#else
+#define MAX_DMA_ADDRESS	(PAGE_OFFSET + ARM_DMA_ZONE_SIZE)
 #endif
 
 #ifdef CONFIG_ISA_DMA_API
arch/arm/include/asm/memory.h +3 -1
index 431077c..ee5ff41 100644
@@ -209,8 +209,10 @@ static inline unsigned long __phys_to_virt(unsigned long x)
  * allocations.  This must be the smallest DMA mask in the system,
  * so a successful GFP_DMA allocation will always satisfy this.
  */
-#ifndef ISA_DMA_THRESHOLD
+#ifndef ARM_DMA_ZONE_SIZE
 #define ISA_DMA_THRESHOLD	(0xffffffffULL)
+#else
+#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + ARM_DMA_ZONE_SIZE - 1)
 #endif
 
 #ifndef arch_adjust_zones
arch/arm/mach-davinci/include/mach/memory.h +1 -2
index 7882272..8d27246 100644
@@ -59,8 +59,7 @@ __arch_adjust_zones(unsigned long *size, unsigned long *holes)
 #define arch_adjust_zones(zone_size, holes) \
         if ((meminfo.bank[0].size >> 20) > 128) __arch_adjust_zones(zone_size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + (128<<20) - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + (128<<20))
+#define ARM_DMA_ZONE_SIZE	SZ_128M
 
 #endif
 
arch/arm/mach-h720x/include/mach/memory.h +1 -2
index 9d36876..b0b3bae 100644
@@ -13,7 +13,6 @@
  * There should not be more than (0xd0000000 - 0xc0000000)
  * bytes of RAM.
  */
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_256M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_256M)
+#define ARM_DMA_ZONE_SIZE	SZ_256M
 
 #endif
arch/arm/mach-ixp4xx/include/mach/memory.h +1 -2
index 6d388c9..a5c26f8 100644
@@ -21,8 +21,7 @@ void ixp4xx_adjust_zones(unsigned long *size, unsigned long *holes);
 #define arch_adjust_zones(size, holes) \
 	ixp4xx_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD (SZ_64M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_64M)
+#define ARM_DMA_ZONE_SIZE	SZ_64M
 
 #endif
 
arch/arm/mach-pxa/include/mach/memory.h +1 -2
index 7f68724..57a0b68 100644
@@ -23,8 +23,7 @@ void cmx2xx_pci_adjust_zones(unsigned long *size, unsigned long *holes);
 #define arch_adjust_zones(size, holes) \
 	cmx2xx_pci_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_64M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_64M)
+#define ARM_DMA_ZONE_SIZE	SZ_64M
 #endif
 
 #endif
arch/arm/mach-realview/include/mach/memory.h +1 -2
index e05fc2c..973428d 100644
@@ -34,8 +34,7 @@ extern void realview_adjust_zones(unsigned long *size, unsigned long *hole);
 #define arch_adjust_zones(size, hole) \
 	realview_adjust_zones(size, hole)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_256M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_256M)
+#define ARM_DMA_ZONE_SIZE	SZ_256M
 #endif
 
 #ifdef CONFIG_SPARSEMEM
arch/arm/mach-sa1100/include/mach/memory.h +1 -2
index a44da6a..090b829 100644
@@ -22,8 +22,7 @@ void sa1111_adjust_zones(unsigned long *size, unsigned long *holes);
 #define arch_adjust_zones(size, holes) \
 	sa1111_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_1M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_1M)
+#define ARM_DMA_ZONE_SIZE	SZ_1M
 
 #endif
 #endif
arch/arm/mach-shark/include/mach/memory.h +1 -2
index 9afb170..48fe84b 100644
@@ -32,8 +32,7 @@ static inline void __arch_adjust_zones(unsigned long *zone_size, unsigned long *
 #define arch_adjust_zones(size, holes) \
 	__arch_adjust_zones(size, holes)
 
-#define ISA_DMA_THRESHOLD	(PHYS_OFFSET + SZ_4M - 1)
-#define MAX_DMA_ADDRESS		(PAGE_OFFSET + SZ_4M)
+#define ARM_DMA_ZONE_SIZE	SZ_4M
 
 #endif
 
Signature · 1 line
1.7.4.4
#7 lore raw

PATCH 2/2 ARM: use ARM_DMA_ZONE_SIZE to adjust the zone sizes

In reply to Russell King - ARM Linux
Quoted 7 lines · Russell King - ARM Linux

Rather than each platform providing its own function to adjust the zone sizes, use the new ARM_DMA_ZONE_SIZE definition to perform this adjustment. This ensures that the actual DMA zone size and the ISA_DMA_THRESHOLD/MAX_DMA_ADDRESS definitions are consistent with each other, and moves this complexity out of the platform code.

Quoted 340 lines
---
 arch/arm/common/sa1111.c                     |    8 -------
 arch/arm/include/asm/memory.h                |    6 -----
 arch/arm/mach-davinci/include/mach/memory.h  |   15 --------------
 arch/arm/mach-ixp4xx/common-pci.c            |   23 ----------------------
 arch/arm/mach-ixp4xx/include/mach/memory.h   |    9 +-------
 arch/arm/mach-pxa/cm-x2xx-pci.c              |   27 --------------------------
 arch/arm/mach-pxa/include/mach/memory.h      |    7 +-----
 arch/arm/mach-realview/core.c                |   19 ------------------
 arch/arm/mach-realview/include/mach/memory.h |    6 +----
 arch/arm/mach-sa1100/include/mach/memory.h   |    9 --------
 arch/arm/mach-shark/include/mach/memory.h    |   17 ----------------
 arch/arm/mm/init.c                           |   23 +++++++++++++++++++++-
 12 files changed, 25 insertions(+), 144 deletions(-)
arch/arm/common/sa1111.c +0 -8
index a12b33c..9c49a46 100644
@@ -185,14 +185,6 @@ static struct sa1111_dev_info sa1111_devices[] = {
 	},
 };
 
-void __init sa1111_adjust_zones(unsigned long *size, unsigned long *holes)
-{
-	unsigned int sz = SZ_1M >> PAGE_SHIFT;
-
-	size[1] = size[0] - sz;
-	size[0] = sz;
-}
-
 /*
  * SA1111 interrupt support.  Since clearing an IRQ while there are
  * active IRQs causes the interrupt output to pulse, the upper levels
arch/arm/include/asm/memory.h +0 -6
index ee5ff41..af44a8f 100644
@@ -215,12 +215,6 @@ static inline unsigned long __phys_to_virt(unsigned long x)
 #define ISA_DMA_THRESHOLD	(PHYS_OFFSET + ARM_DMA_ZONE_SIZE - 1)
 #endif
 
-#ifndef arch_adjust_zones
-#define arch_adjust_zones(size,holes) do { } while (0)
-#elif !defined(CONFIG_ZONE_DMA)
-#error "custom arch_adjust_zones() requires CONFIG_ZONE_DMA"
-#endif
-
 /*
  * PFNs are used to describe any physical page; this means
  * PFN 0 == physical address 0.
arch/arm/mach-davinci/include/mach/memory.h +0 -15
index 8d27246..491249e 100644
@@ -41,26 +41,11 @@
  */
 #define CONSISTENT_DMA_SIZE (14<<20)
 
-#ifndef __ASSEMBLY__
 /*
  * Restrict DMA-able region to workaround silicon bug.  The bug
  * restricts buffers available for DMA to video hardware to be
  * below 128M
  */
-static inline void
-__arch_adjust_zones(unsigned long *size, unsigned long *holes)
-{
-	unsigned int sz = (128<<20) >> PAGE_SHIFT;
-
-	size[1] = size[0] - sz;
-	size[0] = sz;
-}
-
-#define arch_adjust_zones(zone_size, holes) \
-        if ((meminfo.bank[0].size >> 20) > 128) __arch_adjust_zones(zone_size, holes)
-
 #define ARM_DMA_ZONE_SIZE	SZ_128M
 
-#endif
-
 #endif /* __ASM_ARCH_MEMORY_H */
arch/arm/mach-ixp4xx/common-pci.c +0 -23
index a54b3db..e9a5893 100644
@@ -342,29 +342,6 @@ int dma_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
 	return (dev->bus == &pci_bus_type ) && ((dma_addr + size) >= SZ_64M);
 }
 
-/*
- * Only first 64MB of memory can be accessed via PCI.
- * We use GFP_DMA to allocate safe buffers to do map/unmap.
- * This is really ugly and we need a better way of specifying
- * DMA-capable regions of memory.
- */
-void __init ixp4xx_adjust_zones(unsigned long *zone_size,
-	unsigned long *zhole_size)
-{
-	unsigned int sz = SZ_64M >> PAGE_SHIFT;
-
-	/*
-	 * Only adjust if > 64M on current system
-	 */
-	if (zone_size[0] <= sz)
-		return;
-
-	zone_size[1] = zone_size[0] - sz;
-	zone_size[0] = sz;
-	zhole_size[1] = zhole_size[0];
-	zhole_size[0] = 0;
-}
-
 void __init ixp4xx_pci_preinit(void)
 {
 	unsigned long cpuid = read_cpuid_id();
arch/arm/mach-ixp4xx/include/mach/memory.h +1 -8
index a5c26f8..34e7940 100644
@@ -14,15 +14,8 @@
  */
 #define PLAT_PHYS_OFFSET	UL(0x00000000)
 
-#if !defined(__ASSEMBLY__) && defined(CONFIG_PCI)
-
-void ixp4xx_adjust_zones(unsigned long *size, unsigned long *holes);
-
-#define arch_adjust_zones(size, holes) \
-	ixp4xx_adjust_zones(size, holes)
-
+#ifdef CONFIG_PCI
 #define ARM_DMA_ZONE_SIZE	SZ_64M
-
 #endif
 
 #endif
arch/arm/mach-pxa/cm-x2xx-pci.c +0 -27
index 8b1a309..1afc0fb 100644
@@ -29,33 +29,6 @@
 unsigned long it8152_base_address;
 static int cmx2xx_it8152_irq_gpio;
 
-/*
- * Only first 64MB of memory can be accessed via PCI.
- * We use GFP_DMA to allocate safe buffers to do map/unmap.
- * This is really ugly and we need a better way of specifying
- * DMA-capable regions of memory.
- */
-void __init cmx2xx_pci_adjust_zones(unsigned long *zone_size,
-	unsigned long *zhole_size)
-{
-	unsigned int sz = SZ_64M >> PAGE_SHIFT;
-
-	if (machine_is_armcore()) {
-		pr_info("Adjusting zones for CM-X2XX\n");
-
-		/*
-		 * Only adjust if > 64M on current system
-		 */
-		if (zone_size[0] <= sz)
-			return;
-
-		zone_size[1] = zone_size[0] - sz;
-		zone_size[0] = sz;
-		zhole_size[1] = zhole_size[0];
-		zhole_size[0] = 0;
-	}
-}
-
 static void cmx2xx_it8152_irq_demux(unsigned int irq, struct irq_desc *desc)
 {
 	/* clear our parent irq */
arch/arm/mach-pxa/include/mach/memory.h +1 -6
index 57a0b68..07734f3 100644
@@ -17,12 +17,7 @@
  */
 #define PLAT_PHYS_OFFSET	UL(0xa0000000)
 
-#if !defined(__ASSEMBLY__) && defined(CONFIG_MACH_ARMCORE) && defined(CONFIG_PCI)
-void cmx2xx_pci_adjust_zones(unsigned long *size, unsigned long *holes);
-
-#define arch_adjust_zones(size, holes) \
-	cmx2xx_pci_adjust_zones(size, holes)
-
+#if defined(CONFIG_MACH_ARMCORE) && defined(CONFIG_PCI)
 #define ARM_DMA_ZONE_SIZE	SZ_64M
 #endif
 
arch/arm/mach-realview/core.c +0 -19
index 75dbc87..525ad17 100644
@@ -56,25 +56,6 @@
 
 #include "core.h"
 
-#ifdef CONFIG_ZONE_DMA
-/*
- * Adjust the zones if there are restrictions for DMA access.
- */
-void __init realview_adjust_zones(unsigned long *size, unsigned long *hole)
-{
-	unsigned long dma_size = SZ_256M >> PAGE_SHIFT;
-
-	if (!machine_is_realview_pbx() || size[0] <= dma_size)
-		return;
-
-	size[ZONE_NORMAL] = size[0] - dma_size;
-	size[ZONE_DMA] = dma_size;
-	hole[ZONE_NORMAL] = hole[0];
-	hole[ZONE_DMA] = 0;
-}
-#endif
-
-
 #define REALVIEW_FLASHCTRL    (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_FLASH_OFFSET)
 
 static int realview_flash_init(void)
arch/arm/mach-realview/include/mach/memory.h +1 -5
index 973428d..1759fa6 100644
@@ -29,11 +29,7 @@
 #define PLAT_PHYS_OFFSET		UL(0x00000000)
 #endif
 
-#if !defined(__ASSEMBLY__) && defined(CONFIG_ZONE_DMA)
-extern void realview_adjust_zones(unsigned long *size, unsigned long *hole);
-#define arch_adjust_zones(size, hole) \
-	realview_adjust_zones(size, hole)
-
+#ifdef CONFIG_ZONE_DMA
 #define ARM_DMA_ZONE_SIZE	SZ_256M
 #endif
 
arch/arm/mach-sa1100/include/mach/memory.h +0 -9
index 090b829..cff31ee 100644
@@ -14,17 +14,8 @@
  */
 #define PLAT_PHYS_OFFSET	UL(0xc0000000)
 
-#ifndef __ASSEMBLY__
-
 #ifdef CONFIG_SA1111
-void sa1111_adjust_zones(unsigned long *size, unsigned long *holes);
-
-#define arch_adjust_zones(size, holes) \
-	sa1111_adjust_zones(size, holes)
-
 #define ARM_DMA_ZONE_SIZE	SZ_1M
-
-#endif
 #endif
 
 /*
arch/arm/mach-shark/include/mach/memory.h +0 -17
index 48fe84b..4c0831f8 100644
@@ -17,25 +17,8 @@
  */
 #define PLAT_PHYS_OFFSET     UL(0x08000000)
 
-#ifndef __ASSEMBLY__
-
-static inline void __arch_adjust_zones(unsigned long *zone_size, unsigned long *zhole_size)
-{
-  /* Only the first 4 MB (=1024 Pages) are usable for DMA */
-  /* See dev / -> .properties in OpenFirmware. */
-  zone_size[1] = zone_size[0] - 1024;
-  zone_size[0] = 1024;
-  zhole_size[1] = zhole_size[0];
-  zhole_size[0] = 0;
-}
-
-#define arch_adjust_zones(size, holes) \
-	__arch_adjust_zones(size, holes)
-
 #define ARM_DMA_ZONE_SIZE	SZ_4M
 
-#endif
-
 /*
  * Cache flushing area
  */
arch/arm/mm/init.c +22 -1
index e5f6fc4..49eaad9 100644
@@ -201,6 +201,20 @@ static void __init arm_bootmem_init(unsigned long start_pfn,
 	}
 }
 
+#ifdef CONFIG_ZONE_DMA
+static void __init arm_adjust_dma_zone(unsigned long *size, unsigned long *hole,
+	unsigned long dma_size)
+{
+	if (size[0] <= dma_size)
+		return;
+
+	size[ZONE_NORMAL] = size[0] - dma_size;
+	size[ZONE_DMA] = dma_size;
+	hole[ZONE_NORMAL] = hole[0];
+	hole[ZONE_DMA] = 0;
+}
+#endif
+
 static void __init arm_bootmem_free(unsigned long min, unsigned long max_low,
 	unsigned long max_high)
 {
@@ -243,11 +257,18 @@ static void __init arm_bootmem_free(unsigned long min, unsigned long max_low,
 #endif
 	}
 
+#ifdef ARM_DMA_ZONE_SIZE
+#ifndef CONFIG_ZONE_DMA
+#error ARM_DMA_ZONE_SIZE set but no DMA zone to limit allocations
+#endif
+
 	/*
 	 * Adjust the sizes according to any special requirements for
 	 * this machine type.
 	 */
-	arch_adjust_zones(zone_size, zhole_size);
+	arm_adjust_dma_zone(zone_size, zhole_size,
+		ARM_DMA_ZONE_SIZE >> PAGE_SHIFT);
+#endif
 
 	free_area_init_node(0, zone_size, min, zhole_size);
 }
Signature · 1 line
1.7.4.4
#8 lore raw

cover Consolidate zone adjustment

In reply to Russell King - ARM Linux
Quoted 6 lines · Russell King - ARM Linux

This patch mini-series consolidates the adjustment to system zones which some of our platforms require. Rather than having each platform/machine class specify ISA_DMA_THRESHOLD, MAX_DMA_ADDRESS and an arch_adjust_zones function, they really only need to provide a single sizing definition, which in this series will be called ARM_DMA_ZONE_SIZE.

Boot tested this series on DaVinci DA850.

Thanks,
Sekhar