mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* rework MMU support
@ 2011-08-01 13:26 Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 1/9 v2] arm: introduce arm_add_mem_device to register dram device Jean-Christophe PLAGNIOL-VILLARD
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:26 UTC (permalink / raw)
  To: barebox

Hi,

	This series reworks the barebox MMU support. We now use second
	level page tables which allows us to remap the dma coherent area
	dynamically. We don't have to map our sdram twice anymore which
	helps us on newer systems with big memory.

	As a bonus there is no board specific MMU code anymore. All a board
	has to do to enable MMU support via Kconfig is to register its SDRAM banks
	at mem_initcall

The following changes since commit b821d73607cc6387b1ee588af97a44e8eb2b4fe2:

  Merge branch 'resource' of git://uboot.jcrosoft.org/barebox into next (2011-08-01 14:10:38 +0200)

are available in the git repository at:

  git://uboot.jcrosoft.org/barebox.git mmu

Jean-Christophe PLAGNIOL-VILLARD (2):
      arm: introduce arm_add_mem_device to register dram device
      init: introduce mem, mmu and postmmu initcall

Sascha Hauer (7):
      ARM cache l2x0: depend on MMU
      ARM: move armlinux_add_dram to location which is always compiled
      ARM l2x0: make init function static inline if l2 is not available
      ARM: pass size to dma_free_coherent
      ARM boards: move sdram setup before mmu setup
      ARM: rework MMU support
      ARM boards: remove now unnecessary mmu calls

 arch/arm/boards/a9m2410/a9m2410.c                 |   20 ++-
 arch/arm/boards/a9m2440/a9m2440.c                 |   20 ++-
 arch/arm/boards/at91rm9200ek/init.c               |    9 +-
 arch/arm/boards/at91sam9260ek/init.c              |    9 +-
 arch/arm/boards/at91sam9261ek/init.c              |    9 +-
 arch/arm/boards/at91sam9263ek/init.c              |    9 +-
 arch/arm/boards/at91sam9m10g45ek/init.c           |    8 +-
 arch/arm/boards/chumby_falconwing/falconwing.c    |   21 +--
 arch/arm/boards/edb93xx/edb93xx.c                 |   46 +++---
 arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c |   26 +---
 arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |   24 +---
 arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c |   28 +---
 arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c |   31 +---
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c     |   15 +-
 arch/arm/boards/freescale-mx25-3-stack/3stack.c   |   30 ++--
 arch/arm/boards/freescale-mx35-3-stack/3stack.c   |   11 +-
 arch/arm/boards/freescale-mx51-pdk/board.c        |   26 +---
 arch/arm/boards/freescale-mx53-loco/board.c       |   33 +----
 arch/arm/boards/guf-cupid/board.c                 |   26 +--
 arch/arm/boards/guf-neso/board.c                  |   25 +---
 arch/arm/boards/imx21ads/imx21ads.c               |   12 +-
 arch/arm/boards/imx27ads/imx27ads.c               |   12 +-
 arch/arm/boards/karo-tx25/board.c                 |   36 +----
 arch/arm/boards/karo-tx28/tx28.c                  |   21 +--
 arch/arm/boards/mini2440/mini2440.c               |   15 +-
 arch/arm/boards/mmccpu/init.c                     |    9 +-
 arch/arm/boards/netx/netx.c                       |   13 +-
 arch/arm/boards/nhk8815/setup.c                   |    8 +-
 arch/arm/boards/omap/board-beagle.c               |   14 +-
 arch/arm/boards/omap/board-omap3evm.c             |   14 +-
 arch/arm/boards/omap/board-sdp343x.c              |   24 +--
 arch/arm/boards/panda/board.c                     |   18 +--
 arch/arm/boards/pcm037/pcm037.c                   |   41 ++----
 arch/arm/boards/pcm038/pcm038.c                   |   29 +---
 arch/arm/boards/pcm043/pcm043.c                   |   27 ++--
 arch/arm/boards/pcm049/board.c                    |   23 +--
 arch/arm/boards/phycard-i.MX27/pca100.c           |   23 +---
 arch/arm/boards/pm9261/init.c                     |    9 +-
 arch/arm/boards/pm9263/init.c                     |    9 +-
 arch/arm/boards/pm9g45/init.c                     |    9 +-
 arch/arm/boards/scb9328/env/config                |   56 +++++++
 arch/arm/boards/scb9328/scb9328.c                 |   12 +-
 arch/arm/boards/versatile/versatilepb.c           |    8 +-
 arch/arm/cpu/Kconfig                              |    2 +-
 arch/arm/cpu/cpu.c                                |   14 ++
 arch/arm/cpu/mmu.c                                |  178 +++++++++++++++++----
 arch/arm/include/asm/armlinux.h                   |   10 +-
 arch/arm/include/asm/memory.h                     |   24 ++--
 arch/arm/include/asm/mmu.h                        |   28 +++-
 arch/arm/lib/armlinux.c                           |   19 +--
 arch/arm/mach-at91/at91rm9200_devices.c           |    6 +-
 arch/arm/mach-at91/at91sam9260_devices.c          |    6 +-
 arch/arm/mach-at91/at91sam9261_devices.c          |    6 +-
 arch/arm/mach-at91/at91sam9263_devices.c          |    6 +-
 arch/arm/mach-at91/at91sam9g45_devices.c          |    6 +-
 arch/arm/mach-nomadik/8815.c                      |    6 +-
 arch/arm/mach-versatile/core.c                    |    6 +-
 drivers/base/resource.c                           |   15 ++
 drivers/usb/gadget/fsl_udc.c                      |    2 +-
 include/common.h                                  |    1 +
 include/init.h                                    |   11 +-
 61 files changed, 616 insertions(+), 598 deletions(-)
 create mode 100644 arch/arm/boards/scb9328/env/config

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/9 v2] arm: introduce arm_add_mem_device to register dram device
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 2/9] ARM cache l2x0: depend on MMU Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

this will automaticaly register the device to armlinux_add_dram

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/boards/a9m2410/a9m2410.c                 |    4 +--
 arch/arm/boards/a9m2440/a9m2440.c                 |    4 +--
 arch/arm/boards/chumby_falconwing/falconwing.c    |    4 +--
 arch/arm/boards/edb93xx/edb93xx.c                 |   26 ++++++--------------
 arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c |    6 +----
 arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |    5 +---
 arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c |    6 +----
 arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c |    6 +----
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c     |    4 +--
 arch/arm/boards/freescale-mx25-3-stack/3stack.c   |   10 ++-----
 arch/arm/boards/freescale-mx35-3-stack/3stack.c   |    5 +---
 arch/arm/boards/freescale-mx51-pdk/board.c        |    6 +----
 arch/arm/boards/freescale-mx53-loco/board.c       |   11 +-------
 arch/arm/boards/guf-cupid/board.c                 |    5 +---
 arch/arm/boards/guf-neso/board.c                  |    5 +---
 arch/arm/boards/imx21ads/imx21ads.c               |    5 +---
 arch/arm/boards/imx27ads/imx27ads.c               |    5 +---
 arch/arm/boards/karo-tx25/board.c                 |   10 +------
 arch/arm/boards/karo-tx28/tx28.c                  |    4 +--
 arch/arm/boards/mini2440/mini2440.c               |    4 +--
 arch/arm/boards/netx/netx.c                       |    6 +----
 arch/arm/boards/omap/board-beagle.c               |    9 +------
 arch/arm/boards/omap/board-omap3evm.c             |    8 +-----
 arch/arm/boards/omap/board-sdp343x.c              |    7 +-----
 arch/arm/boards/panda/board.c                     |    6 +----
 arch/arm/boards/pcm037/pcm037.c                   |   10 +------
 arch/arm/boards/pcm038/pcm038.c                   |    5 +---
 arch/arm/boards/pcm043/pcm043.c                   |    5 +---
 arch/arm/boards/pcm049/board.c                    |    6 +----
 arch/arm/boards/phycard-i.MX27/pca100.c           |    5 +---
 arch/arm/boards/scb9328/scb9328.c                 |    5 +---
 arch/arm/include/asm/armlinux.h                   |    3 ++
 arch/arm/mach-at91/at91rm9200_devices.c           |    6 +----
 arch/arm/mach-at91/at91sam9260_devices.c          |    6 +----
 arch/arm/mach-at91/at91sam9261_devices.c          |    6 +----
 arch/arm/mach-at91/at91sam9263_devices.c          |    6 +----
 arch/arm/mach-at91/at91sam9g45_devices.c          |    6 +----
 arch/arm/mach-nomadik/8815.c                      |    6 +----
 arch/arm/mach-versatile/core.c                    |    6 +----
 drivers/base/resource.c                           |   15 ++++++++++++
 40 files changed, 68 insertions(+), 199 deletions(-)

diff --git a/arch/arm/boards/a9m2410/a9m2410.c b/arch/arm/boards/a9m2410/a9m2410.c
index 64fabd2..b249a1d 100644
--- a/arch/arm/boards/a9m2410/a9m2410.c
+++ b/arch/arm/boards/a9m2410/a9m2410.c
@@ -124,8 +124,7 @@ static int a9m2410_devices_init(void)
 	/* ----------- the devices the boot loader should work with -------- */
 	add_generic_device("s3c24x0_nand", -1, NULL, S3C24X0_NAND_BASE, 0,
 			   IORESOURCE_MEM, &nand_info);
-	sdram_dev = add_mem_device("ram0", CS6_BASE, size,
-				   IORESOURCE_MEM_WRITEABLE);
+	sdram_dev = arm_add_mem_device("ram0", CS6_BASE, size);
 	/*
 	 * SMSC 91C111 network controller on the baseboard
 	 * connected to CS line 1 and interrupt line
@@ -143,7 +142,6 @@ static int a9m2410_devices_init(void)
 	dev_add_bb_dev("env_raw", "env0");
 #endif
 
-	armlinux_add_dram(sdram_dev);
 	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
 	armlinux_set_architecture(MACH_TYPE_A9M2410);
 
diff --git a/arch/arm/boards/a9m2440/a9m2440.c b/arch/arm/boards/a9m2440/a9m2440.c
index d52f4c2..c5b467a 100644
--- a/arch/arm/boards/a9m2440/a9m2440.c
+++ b/arch/arm/boards/a9m2440/a9m2440.c
@@ -128,8 +128,7 @@ static int a9m2440_devices_init(void)
 	/* ----------- the devices the boot loader should work with -------- */
 	add_generic_device("s3c24x0_nand", -1, NULL, S3C24X0_NAND_BASE, 0,
 			   IORESOURCE_MEM, &nand_info);
-	sdram_dev = add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size(),
-				   IORESOURCE_MEM_WRITEABLE);
+	sdram_dev = arm_add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size());
 	/*
 	 * cs8900 network controller onboard
 	 * Connected to CS line 5 + A24 and interrupt line EINT9,
@@ -146,7 +145,6 @@ static int a9m2440_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x20000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 #endif
-	armlinux_add_dram(sdram_dev);
 	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
 	armlinux_set_architecture(MACH_TYPE_A9M2440);
 
diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c b/arch/arm/boards/chumby_falconwing/falconwing.c
index 69c3a61..06916f0 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -339,8 +339,7 @@ static int falconwing_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(pad_setup); i++)
 		imx_gpio_mode(pad_setup[i]);
 
-	sdram_dev = add_mem_device("ram0", IMX_MEMORY_BASE, 64 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
+	sdram_dev = arm_add_mem_device("ram0", IMX_MEMORY_BASE, 64 * 1024 * 1024);
 	imx_set_ioclk(480000000); /* enable IOCLK to run at the PLL frequency */
 	/* run the SSP unit clock at 100,000 kHz */
 	imx_set_sspclk(0, 100000000, 1);
@@ -351,7 +350,6 @@ static int falconwing_devices_init(void)
 
 	falconwing_init_usb();
 
-	armlinux_add_dram(sdram_dev);
 	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
 	armlinux_set_architecture(MACH_TYPE_CHUMBY);
 
diff --git a/arch/arm/boards/edb93xx/edb93xx.c b/arch/arm/boards/edb93xx/edb93xx.c
index 7f9e647..fd838bf 100644
--- a/arch/arm/boards/edb93xx/edb93xx.c
+++ b/arch/arm/boards/edb93xx/edb93xx.c
@@ -36,8 +36,6 @@
 
 static int ep93xx_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	add_cfi_flash_device(-1, 0x60000000, EDB93XX_CFI_FLASH_SIZE, 0);
 
 	/*
@@ -49,27 +47,19 @@ static int ep93xx_devices_init(void)
 
 	protect_file("/dev/env0", 1);
 
-	sdram_dev = add_mem_device("ram0", CONFIG_EP93XX_SDRAM_BANK0_BASE,
-				   CONFIG_EP93XX_SDRAM_BANK0_SIZE,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", CONFIG_EP93XX_SDRAM_BANK0_BASE,
+				   CONFIG_EP93XX_SDRAM_BANK0_SIZE);
 #if (CONFIG_EP93XX_SDRAM_NUM_BANKS >= 2)
-	sdram_dev = add_mem_device("ram1", CONFIG_EP93XX_SDRAM_BANK1_BASE,
-				   CONFIG_EP93XX_SDRAM_BANK1_SIZE,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram1", CONFIG_EP93XX_SDRAM_BANK1_BASE,
+				   CONFIG_EP93XX_SDRAM_BANK1_SIZE);
 #endif
 #if (CONFIG_EP93XX_SDRAM_NUM_BANKS >= 3)
-	sdram_dev = add_mem_device("ram2", CONFIG_EP93XX_SDRAM_BANK2_BASE,
-				   CONFIG_EP93XX_SDRAM_BANK2_SIZE,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram2", CONFIG_EP93XX_SDRAM_BANK2_BASE,
+				   CONFIG_EP93XX_SDRAM_BANK2_SIZE);
 #endif
 #if (CONFIG_EP93XX_SDRAM_NUM_BANKS == 4)
-	sdram_dev = add_mem_device("ram3", CONFIG_EP93XX_SDRAM_BANK3_BASE,
-				   CONFIG_EP93XX_SDRAM_BANK2_SIZE,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram3", CONFIG_EP93XX_SDRAM_BANK3_BASE,
+				   CONFIG_EP93XX_SDRAM_BANK2_SIZE);
 #endif
 
 	/*
diff --git a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
index aeeed17..e188fab 100644
--- a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
+++ b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
@@ -230,8 +230,6 @@ static struct pad_desc eukrea_cpuimx25_pads[] = {
 
 static int eukrea_cpuimx25_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	eukrea_cpuimx25_mmu_init();
 
 	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx25_pads,
@@ -253,9 +251,7 @@ static int eukrea_cpuimx25_devices_init(void)
 		PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, 64 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 64 * 1024 * 1024);
 
 	/* enable LCD */
 	gpio_direction_output(26, 1);
diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
index b38decf..e42ad7c 100644
--- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
+++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
@@ -134,7 +134,6 @@ static struct imx_fb_platform_data eukrea_cpuimx27_fb_data = {
 
 static int eukrea_cpuimx27_devices_init(void)
 {
-	struct device_d *sdram_dev;
 	char *envdev = "no";
 	int i;
 
@@ -209,9 +208,7 @@ static int eukrea_cpuimx27_devices_init(void)
 	add_cfi_flash_device(-1, 0xC2000000, 32 * 1024 * 1024, 0);
 #endif
 	imx27_add_nand(&nand_info);
-	sdram_dev = add_mem_device("ram0", 0xa0000000, SDRAM0 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0xa0000000, SDRAM0 * 1024 * 1024);
 
 	PCCR0 |= PCCR0_I2C1_EN;
 	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
diff --git a/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c b/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
index 53e5bad..29b9edf 100644
--- a/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
+++ b/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -148,8 +148,6 @@ postcore_initcall(eukrea_cpuimx35_mmu_init);
 
 static int eukrea_cpuimx35_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	imx35_add_nand(&nand_info);
 
 	devfs_add_partition("nand0", 0x00000, 0x40000, PARTITION_FIXED, "self_raw");
@@ -159,9 +157,7 @@ static int eukrea_cpuimx35_devices_init(void)
 
 	imx35_add_fec(&fec_info);
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 
 	imx35_add_i2c0(NULL);
diff --git a/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c b/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
index 4d281f4..2510e07 100644
--- a/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
+++ b/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
@@ -119,13 +119,9 @@ static void eukrea_cpuimx51_mmu_init(void)
 
 static int eukrea_cpuimx51_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	eukrea_cpuimx51_mmu_init();
 
-	sdram_dev = add_mem_device("ram0", 0x90000000, 256 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x90000000, 256 * 1024 * 1024);
 	imx51_add_fec(&fec_info);
 #ifdef CONFIG_MCI_IMX_ESDHC
 	imx51_add_mmc0(NULL);
diff --git a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
index f9f85fa..7e23e9a 100644
--- a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
+++ b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
@@ -29,9 +29,7 @@ static int mx23_evk_devices_init(void)
 {
 	struct device_d *sdram_dev;
 
-	sdram_dev = add_mem_device("ram0", IMX_MEMORY_BASE, 32 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	sdram_dev = arm_add_mem_device("ram0", IMX_MEMORY_BASE, 32 * 1024 * 1024);
 	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
 	armlinux_set_architecture(MACH_TYPE_MX23EVK);
 
diff --git a/arch/arm/boards/freescale-mx25-3-stack/3stack.c b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
index 3902ccf..b142232 100644
--- a/arch/arm/boards/freescale-mx25-3-stack/3stack.c
+++ b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
@@ -194,8 +194,6 @@ late_initcall(imx25_3ds_fec_init);
 
 static int imx25_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 #ifdef CONFIG_USB
 	/* USB does not work yet. Don't know why. Maybe
 	 * the CPLD has to be initialized.
@@ -218,17 +216,15 @@ static int imx25_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x20000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, 
 #if defined CONFIG_FREESCALE_MX25_3STACK_SDRAM_64MB_DDR2
-	64 * 1024 * 1024,
+#define SDRAM_SIZE	64 * 1024 * 1024
 #elif defined CONFIG_FREESCALE_MX25_3STACK_SDRAM_128MB_MDDR
-	128 * 1024 * 1024,
+#define SDRAM_SIZE	128 * 1024 * 1024
 #else
 #error "Unsupported SDRAM type"
 #endif
-				   IORESOURCE_MEM_WRITEABLE);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM_SIZE);
 	add_mem_device("sram0", 0x78000000, 128 * 1024, IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
 
 	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
 	imx25_add_i2c0(NULL);
diff --git a/arch/arm/boards/freescale-mx35-3-stack/3stack.c b/arch/arm/boards/freescale-mx35-3-stack/3stack.c
index e513439..27d4e83 100644
--- a/arch/arm/boards/freescale-mx35-3-stack/3stack.c
+++ b/arch/arm/boards/freescale-mx35-3-stack/3stack.c
@@ -132,7 +132,6 @@ static void set_board_rev(int rev)
 static int f3s_devices_init(void)
 {
 	uint32_t reg;
-	struct device_d *sdram_dev;
 
 	/* CS0: Nor Flash */
 	writel(0x0000cf03, CSCR_U(0));
@@ -178,9 +177,7 @@ static int f3s_devices_init(void)
 
 	imx35_add_mmc0(NULL);
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, 124 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 124 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 
 	armlinux_set_bootparams((void *)0x80000100);
diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index b205a23..509e3c4 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -227,13 +227,9 @@ static void babbage_power_init(void)
 
 static int f3s_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	babbage_mmu_init();
 
-	sdram_dev = add_mem_device("ram0", 0x90000000, 512 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x90000000, 512 * 1024 * 1024);
 
 	imx51_iim_register_fec_ethaddr();
 	imx51_add_fec(&fec_info);
diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index e3db7f3..8ffe964 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -104,17 +104,10 @@ static void loco_fec_reset(void)
 
 static int loco_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	loco_mmu_init();
 
-	sdram_dev = add_mem_device("ram0", 0x70000000, SZ_512M,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
-
-	sdram_dev = add_mem_device("ram1", 0xb0000000, SZ_512M,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x70000000, SZ_512M);
+	arm_add_mem_device("ram1", 0xb0000000, SZ_512M);
 
 	imx51_iim_register_fec_ethaddr();
 	imx53_add_fec(&fec_info);
diff --git a/arch/arm/boards/guf-cupid/board.c b/arch/arm/boards/guf-cupid/board.c
index 6906f0a..d66afac 100644
--- a/arch/arm/boards/guf-cupid/board.c
+++ b/arch/arm/boards/guf-cupid/board.c
@@ -119,7 +119,6 @@ postcore_initcall(cupid_mmu_init);
 static int cupid_devices_init(void)
 {
 	uint32_t reg;
-	struct device_d *sdram_dev;
 
 	gpio_direction_output(GPIO_LCD_ENABLE, 0);
 	gpio_direction_output(GPIO_LCD_BACKLIGHT, 0);
@@ -139,9 +138,7 @@ static int cupid_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x80000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 	imx35_add_mmc0(NULL);
 
diff --git a/arch/arm/boards/guf-neso/board.c b/arch/arm/boards/guf-neso/board.c
index f3a4635..6486f3a 100644
--- a/arch/arm/boards/guf-neso/board.c
+++ b/arch/arm/boards/guf-neso/board.c
@@ -157,7 +157,6 @@ static void neso_mmu_init(void)
 static int neso_devices_init(void)
 {
 	int i;
-	struct device_d *sdram_dev;
 
 	unsigned int mode[] = {
 		/* UART1 */
@@ -289,9 +288,7 @@ static int neso_devices_init(void)
 		imx_gpio_mode(mode[i]);
 
 	imx27_add_nand(&nand_info);
-	sdram_dev = add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 	imx27_add_fb(&neso_fb_data);
 
 #ifdef CONFIG_USB
diff --git a/arch/arm/boards/imx21ads/imx21ads.c b/arch/arm/boards/imx21ads/imx21ads.c
index 2661064..b449279 100644
--- a/arch/arm/boards/imx21ads/imx21ads.c
+++ b/arch/arm/boards/imx21ads/imx21ads.c
@@ -118,7 +118,6 @@ core_initcall(imx21ads_timing_init);
 static int mx21ads_devices_init(void)
 {
 	int i;
-	struct device_d *sdram_dev;
 	unsigned int mode[] = {
 		PA5_PF_LSCLK,
 		PA6_PF_LD0,
@@ -158,9 +157,7 @@ static int mx21ads_devices_init(void)
 		imx_gpio_mode(mode[i]);
 
 	add_cfi_flash_device(-1, 0xC8000000, 32 * 1024 * 1024, 0);
-	sdram_dev = add_mem_device("ram0", 0xc0000000, 64 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0xc0000000, 64 * 1024 * 1024);
 	imx21_add_nand(&nand_info);
 	add_generic_device("cs8900", -1, NULL,	IMX_CS1_BASE, 0x1000,
 			IORESOURCE_MEM, NULL);
diff --git a/arch/arm/boards/imx27ads/imx27ads.c b/arch/arm/boards/imx27ads/imx27ads.c
index db49aac..299b2ea 100644
--- a/arch/arm/boards/imx27ads/imx27ads.c
+++ b/arch/arm/boards/imx27ads/imx27ads.c
@@ -77,7 +77,6 @@ core_initcall(imx27ads_timing_init);
 static int mx27ads_devices_init(void)
 {
 	int i;
-	struct device_d *sdram_dev;
 	unsigned int mode[] = {
 		PD0_AIN_FEC_TXD0,
 		PD1_AIN_FEC_TXD1,
@@ -109,9 +108,7 @@ static int mx27ads_devices_init(void)
 
 	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 
-	sdram_dev = add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 	imx27_add_fec(&fec_info);
 	devfs_add_partition("nor0", 0x00000, 0x20000, PARTITION_FIXED, "self0");
 	devfs_add_partition("nor0", 0x20000, 0x20000, PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/karo-tx25/board.c b/arch/arm/boards/karo-tx25/board.c
index e4a9aeb..4e5eafa 100644
--- a/arch/arm/boards/karo-tx25/board.c
+++ b/arch/arm/boards/karo-tx25/board.c
@@ -118,8 +118,6 @@ static void noinline gpio_fec_active(void)
 
 static int tx25_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	gpio_fec_active();
 
 	imx25_iim_register_fec_ethaddr();
@@ -136,12 +134,8 @@ static int tx25_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x80000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, 32 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS1, 32 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 32 * 1024 * 1024);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS1, 32 * 1024 * 1024);
 	add_mem_device("ram0", 0x78000000, 128 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
 
diff --git a/arch/arm/boards/karo-tx28/tx28.c b/arch/arm/boards/karo-tx28/tx28.c
index b9d5454..095835b 100644
--- a/arch/arm/boards/karo-tx28/tx28.c
+++ b/arch/arm/boards/karo-tx28/tx28.c
@@ -96,9 +96,7 @@ static int tx28_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(tx28_pad_setup); i++)
 		imx_gpio_mode(tx28_pad_setup[i]);
 
-	sdram_dev = add_mem_device("ram0", IMX_MEMORY_BASE, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	sdram_dev = arm_add_mem_device("ram0", IMX_MEMORY_BASE, 128 * 1024 * 1024);
 	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
 	armlinux_set_architecture(MACH_TYPE_TX28);
 
diff --git a/arch/arm/boards/mini2440/mini2440.c b/arch/arm/boards/mini2440/mini2440.c
index c6b4932..df7e617 100644
--- a/arch/arm/boards/mini2440/mini2440.c
+++ b/arch/arm/boards/mini2440/mini2440.c
@@ -290,9 +290,7 @@ static int mini2440_devices_init(void)
 	add_generic_device("s3c24x0_nand", -1, NULL, S3C24X0_NAND_BASE, 0,
 			   IORESOURCE_MEM, &nand_info);
 
-	sdram_dev = add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size(),
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	sdram_dev = arm_add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size());
 
 	add_dm9000_device(0, CS4_BASE + 0x300, CS4_BASE + 0x304,
 			  IORESOURCE_MEM_16BIT, &dm9000_data);
diff --git a/arch/arm/boards/netx/netx.c b/arch/arm/boards/netx/netx.c
index 65681aa..e9b834a 100644
--- a/arch/arm/boards/netx/netx.c
+++ b/arch/arm/boards/netx/netx.c
@@ -39,13 +39,9 @@ struct netx_eth_platform_data eth1_data = {
 };
 
 static int netx_devices_init(void) {
-	struct device_d *sdram_dev;
-
 	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 
-	sdram_dev = add_mem_device("ram0", 0x80000000, 64 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x80000000, 64 * 1024 * 1024);
 	add_generic_device("netx-eth", -1, NULL, 0, 0, IORESOURCE_MEM, &eth0_data);
 	add_generic_device("netx-eth", -1, NULL, 0, 0, IORESOURCE_MEM, &eth1_data);
 
diff --git a/arch/arm/boards/omap/board-beagle.c b/arch/arm/boards/omap/board-beagle.c
index e12e2fe..4602631 100644
--- a/arch/arm/boards/omap/board-beagle.c
+++ b/arch/arm/boards/omap/board-beagle.c
@@ -280,14 +280,7 @@ static struct i2c_board_info i2c_devices[] = {
 
 static int beagle_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	if (!sdram_dev)
-		return -EIO;
-	armlinux_add_dram(sdram_dev);
-
+	arm_add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024);
 	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
 	add_generic_device("i2c-omap", -1, NULL, 0x4809C000, SZ_4K,
 			   IORESOURCE_MEM, NULL);
diff --git a/arch/arm/boards/omap/board-omap3evm.c b/arch/arm/boards/omap/board-omap3evm.c
index 8b5c9b3..68d971b 100644
--- a/arch/arm/boards/omap/board-omap3evm.c
+++ b/arch/arm/boards/omap/board-omap3evm.c
@@ -237,13 +237,7 @@ console_initcall(omap3evm_init_console);
 
 static int omap3evm_init_devices(void)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	if (!sdram_dev)
-		return -EIO;
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024);
 
 #ifdef CONFIG_GPMC
 	/*
diff --git a/arch/arm/boards/omap/board-sdp343x.c b/arch/arm/boards/omap/board-sdp343x.c
index 7c6df05..8fcae12 100644
--- a/arch/arm/boards/omap/board-sdp343x.c
+++ b/arch/arm/boards/omap/board-sdp343x.c
@@ -638,13 +638,8 @@ static int sdp3430_flash_init(void)
 
 static int sdp3430_devices_init(void)
 {
-	struct device_d *sdram_dev;
+	arm_add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024);
 
-	sdram_dev = add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	if (!sdram_dev)
-		return -EIO;
-	armlinux_add_dram(sdram_dev);
 	return sdp3430_flash_init();
 }
 
diff --git a/arch/arm/boards/panda/board.c b/arch/arm/boards/panda/board.c
index deded28..e27f0a4 100644
--- a/arch/arm/boards/panda/board.c
+++ b/arch/arm/boards/panda/board.c
@@ -113,8 +113,6 @@ static void __init panda_boardrev_init(void)
 
 static int panda_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	panda_boardrev_init();
 
 	if (gpio_get_value(182)) {
@@ -141,9 +139,7 @@ static int panda_devices_init(void)
 		sr32(OMAP44XX_SCRM_ALTCLKSRC, 2, 2, 0x3);
 	}
 
-	sdram_dev = add_mem_device("ram0", 0x80000000, SZ_1G,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x80000000, SZ_1G);
 	add_generic_device("omap-hsmmc", -1, NULL, 0x4809C100, SZ_4K,
 			   IORESOURCE_MEM, NULL);
 	panda_ehci_init();
diff --git a/arch/arm/boards/pcm037/pcm037.c b/arch/arm/boards/pcm037/pcm037.c
index f4b4444..56db9a8 100644
--- a/arch/arm/boards/pcm037/pcm037.c
+++ b/arch/arm/boards/pcm037/pcm037.c
@@ -170,8 +170,6 @@ static void pcm037_mmu_init(void)
 
 static int imx31_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
 	pcm037_mmu_init();
 
 	__REG(CSCR_U(0)) = 0x0000cf03; /* CS0: Nor Flash */
@@ -221,13 +219,9 @@ static int imx31_devices_init(void)
 	add_generic_device("smc911x", -1, NULL,	IMX_CS1_BASE, IMX_CS1_RANGE,
 			IORESOURCE_MEM, NULL);
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM0 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM0 * 1024 * 1024);
 #ifndef CONFIG_PCM037_SDRAM_BANK1_NONE
-	sdram_dev = add_mem_device("ram1", IMX_SDRAM_CS1, SDRAM1 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram1", IMX_SDRAM_CS1, SDRAM1 * 1024 * 1024);
 #endif
 #ifdef CONFIG_USB
 	pcm037_usb_init();
diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 02c3dba..bf15cfd 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -151,7 +151,6 @@ static int pcm038_devices_init(void)
 {
 	int i;
 	char *envdev;
-	struct device_d *sdram_dev;
 
 	unsigned int mode[] = {
 		PD0_AIN_FEC_TXD0,
@@ -255,9 +254,7 @@ static int pcm038_devices_init(void)
 
 	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 	imx27_add_nand(&nand_info);
-	sdram_dev = add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 	add_mem_device("ram0", 0xc8000000, 512 * 1024, /* Can be up to 2MiB */
 				   IORESOURCE_MEM_WRITEABLE);
 	imx27_add_fb(&pcm038_fb_data);
diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index 3bd6402..0f25354 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -125,7 +125,6 @@ struct gpio_led led0 = {
 
 static int imx35_devices_init(void)
 {
-	struct device_d *sdram_dev;
 	uint32_t reg;
 
 	/* CS0: Nor Flash */
@@ -171,9 +170,7 @@ static int imx35_devices_init(void)
 	}
 
 
-	sdram_dev = add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 
 	armlinux_set_bootparams((void *)0x80000100);
diff --git a/arch/arm/boards/pcm049/board.c b/arch/arm/boards/pcm049/board.c
index d3f1310..20419a3 100644
--- a/arch/arm/boards/pcm049/board.c
+++ b/arch/arm/boards/pcm049/board.c
@@ -93,11 +93,7 @@ static void pcm049_network_init(void)
 
 static int pcm049_devices_init(void)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", 0x80000000, SZ_512M,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x80000000, SZ_512M);
 	add_mem_device("ram0", 0x40300000, 48 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
 	add_generic_device("omap-hsmmc", -1, NULL, 0x4809C100, SZ_4K,
diff --git a/arch/arm/boards/phycard-i.MX27/pca100.c b/arch/arm/boards/phycard-i.MX27/pca100.c
index 9a10a9d..68f972a 100644
--- a/arch/arm/boards/phycard-i.MX27/pca100.c
+++ b/arch/arm/boards/phycard-i.MX27/pca100.c
@@ -123,7 +123,6 @@ static int pca100_devices_init(void)
 {
 	int i;
 	struct device_d *nand;
-	struct device_d *sdram_dev;
 
 	unsigned int mode[] = {
 		PD0_AIN_FEC_TXD0,
@@ -198,9 +197,7 @@ static int pca100_devices_init(void)
 		imx_gpio_mode(mode[i]);
 
 	imx27_add_nand(&nand_info);
-	sdram_dev = add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 	imx27_add_fec(&fec_info);
 	imx27_add_mmc0(NULL);
 
diff --git a/arch/arm/boards/scb9328/scb9328.c b/arch/arm/boards/scb9328/scb9328.c
index 5c52af9..68a39bf 100644
--- a/arch/arm/boards/scb9328/scb9328.c
+++ b/arch/arm/boards/scb9328/scb9328.c
@@ -53,7 +53,6 @@ struct gpio_led leds[] = {
 static int scb9328_devices_init(void)
 {
 	int i;
-	struct device_d *sdram_dev;
 
 	imx_gpio_mode(PA23_PF_CS5);
 	imx_gpio_mode(GPIO_PORTB | GPIO_GPIO | GPIO_OUT | 21);
@@ -82,9 +81,7 @@ static int scb9328_devices_init(void)
 	CS5L = 0x00000D03;
 
 	add_cfi_flash_device(-1, 0x10000000, 16 * 1024 * 1024, 0);
-	sdram_dev = add_mem_device("ram0", 0x08000000, 16 * 1024 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x08000000, 16 * 1024 * 1024);
 	add_dm9000_device(-1, 0x16000000, 0x16000004,
 			  IORESOURCE_MEM_16BIT, &dm9000_data);
 
diff --git a/arch/arm/include/asm/armlinux.h b/arch/arm/include/asm/armlinux.h
index 3cab209..f76cca8 100644
--- a/arch/arm/include/asm/armlinux.h
+++ b/arch/arm/include/asm/armlinux.h
@@ -34,4 +34,7 @@ struct image_data;
 
 void start_linux(void *adr, int swap, struct image_data *data);
 
+struct device_d *arm_add_mem_device(const char* name, resource_size_t start,
+				    resource_size_t size);
+
 #endif /* __ARCH_ARMLINUX_H */
diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c
index 289f2c3..84605e4 100644
--- a/arch/arm/mach-at91/at91rm9200_devices.c
+++ b/arch/arm/mach-at91/at91rm9200_devices.c
@@ -22,11 +22,7 @@
 
 void at91_add_device_sdram(u32 size)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", AT91_CHIPSELECT_1, size,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", AT91_CHIPSELECT_1, size);
 }
 
 /* --------------------------------------------------------------------
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c
index 468f00d..5c1bbbe 100644
--- a/arch/arm/mach-at91/at91sam9260_devices.c
+++ b/arch/arm/mach-at91/at91sam9260_devices.c
@@ -23,11 +23,7 @@
 
 void at91_add_device_sdram(u32 size)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", AT91_CHIPSELECT_1, size,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", AT91_CHIPSELECT_1, size);
 }
 
 #if defined(CONFIG_DRIVER_NET_MACB)
diff --git a/arch/arm/mach-at91/at91sam9261_devices.c b/arch/arm/mach-at91/at91sam9261_devices.c
index 1e741fd..4985cf1 100644
--- a/arch/arm/mach-at91/at91sam9261_devices.c
+++ b/arch/arm/mach-at91/at91sam9261_devices.c
@@ -23,11 +23,7 @@
 
 void at91_add_device_sdram(u32 size)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", AT91_CHIPSELECT_1, size,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", AT91_CHIPSELECT_1, size);
 }
 
 #if defined(CONFIG_NAND_ATMEL)
diff --git a/arch/arm/mach-at91/at91sam9263_devices.c b/arch/arm/mach-at91/at91sam9263_devices.c
index 07bd02f..540220e 100644
--- a/arch/arm/mach-at91/at91sam9263_devices.c
+++ b/arch/arm/mach-at91/at91sam9263_devices.c
@@ -23,11 +23,7 @@
 
 void at91_add_device_sdram(u32 size)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", AT91_CHIPSELECT_1, size,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", AT91_CHIPSELECT_1, size);
 }
 
 #if defined(CONFIG_DRIVER_NET_MACB)
diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c b/arch/arm/mach-at91/at91sam9g45_devices.c
index 4d55e22..2cd5a95 100644
--- a/arch/arm/mach-at91/at91sam9g45_devices.c
+++ b/arch/arm/mach-at91/at91sam9g45_devices.c
@@ -23,11 +23,7 @@
 
 void at91_add_device_sdram(u32 size)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", AT91_CHIPSELECT_6, size,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", AT91_CHIPSELECT_6, size);
 }
 
 #if defined(CONFIG_DRIVER_NET_MACB)
diff --git a/arch/arm/mach-nomadik/8815.c b/arch/arm/mach-nomadik/8815.c
index f2b8fd0..bcc3406 100644
--- a/arch/arm/mach-nomadik/8815.c
+++ b/arch/arm/mach-nomadik/8815.c
@@ -33,11 +33,7 @@ static struct clk st8815_clk_48 = {
 
 void st8815_add_device_sdram(u32 size)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", 0x00000000, size,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x00000000, size);
 }
 
 void st8815_register_uart(unsigned id)
diff --git a/arch/arm/mach-versatile/core.c b/arch/arm/mach-versatile/core.c
index 249d97a..28582f7 100644
--- a/arch/arm/mach-versatile/core.c
+++ b/arch/arm/mach-versatile/core.c
@@ -44,11 +44,7 @@
 
 void versatile_add_sdram(u32 size)
 {
-	struct device_d *sdram_dev;
-
-	sdram_dev = add_mem_device("ram0", 0x00000000, size,
-				   IORESOURCE_MEM_WRITEABLE);
-	armlinux_add_dram(sdram_dev);
+	arm_add_mem_device("ram0", 0x00000000, size);
 }
 
 struct clk {
diff --git a/drivers/base/resource.c b/drivers/base/resource.c
index 5fc705f..175beb9 100644
--- a/drivers/base/resource.c
+++ b/drivers/base/resource.c
@@ -118,3 +118,18 @@ struct device_d *add_usb_ehci_device(int id, resource_size_t hccr,
 }
 EXPORT_SYMBOL(add_usb_ehci_device);
 #endif
+
+#ifdef CONFIG_ARM
+#include <asm/armlinux.h>
+
+struct device_d *arm_add_mem_device(const char* name, resource_size_t start,
+				    resource_size_t size)
+{
+	struct device_d *dev;
+
+	dev = add_mem_device(name, start, size, IORESOURCE_MEM_WRITEABLE);
+	armlinux_add_dram(dev);
+
+	return dev;
+}
+#endif
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/9] ARM cache l2x0: depend on MMU
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 1/9 v2] arm: introduce arm_add_mem_device to register dram device Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 3/9] ARM: move armlinux_add_dram to location which is always compiled Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

l2x0 cache support does not work without MMU, so depend
on it in Kconfig.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/arm/cpu/Kconfig b/arch/arm/cpu/Kconfig
index 8ee7d6c..5337c46 100644
--- a/arch/arm/cpu/Kconfig
+++ b/arch/arm/cpu/Kconfig
@@ -87,5 +87,5 @@ config ARCH_HAS_L2X0
 
 config CACHE_L2X0
 	bool "Enable L2x0 PrimeCell"
-	depends on ARCH_HAS_L2X0
+	depends on MMU && ARCH_HAS_L2X0
 
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 3/9] ARM: move armlinux_add_dram to location which is always compiled
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 1/9 v2] arm: introduce arm_add_mem_device to register dram device Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 2/9] ARM cache l2x0: depend on MMU Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 4/9] ARM l2x0: make init function static inline if l2 is not available Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

We want to use the memory banks later in the MMU which is
independent of Linux, so move this to a location which is
always compiled.

Also, make the memory bank list global and add an iterator
for it.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/cpu.c              |   14 ++++++++++++++
 arch/arm/include/asm/armlinux.h |    7 ++-----
 arch/arm/include/asm/memory.h   |   34 ++++++++++++++++++----------------
 arch/arm/lib/armlinux.c         |   19 ++-----------------
 4 files changed, 36 insertions(+), 38 deletions(-)
 rewrite arch/arm/include/asm/memory.h (79%)

diff --git a/arch/arm/cpu/cpu.c b/arch/arm/cpu/cpu.c
index cf30789..3df0c0f 100644
--- a/arch/arm/cpu/cpu.c
+++ b/arch/arm/cpu/cpu.c
@@ -30,6 +30,7 @@
 #include <cache.h>
 #include <asm/mmu.h>
 #include <asm/system.h>
+#include <asm/memory.h>
 
 /**
  * Enable processor's instruction cache
@@ -89,6 +90,19 @@ void arch_shutdown(void)
 #endif
 }
 
+LIST_HEAD(memory_list);
+
+void armlinux_add_dram(struct device_d *dev)
+{
+	struct arm_memory *mem = xzalloc(sizeof(*mem));
+
+	mem->dev = dev;
+	mem->start = dev->resource[0].start;
+	mem->size = dev->resource[0].size;
+
+	list_add_tail(&mem->list, &memory_list);
+}
+
 /**
  * @page arm_boot_preparation Linux Preparation on ARM
  *
diff --git a/arch/arm/include/asm/armlinux.h b/arch/arm/include/asm/armlinux.h
index f76cca8..bb25f9a 100644
--- a/arch/arm/include/asm/armlinux.h
+++ b/arch/arm/include/asm/armlinux.h
@@ -1,11 +1,12 @@
 #ifndef __ARCH_ARMLINUX_H
 #define __ARCH_ARMLINUX_H
 
+#include <asm/memory.h>
+
 #if defined CONFIG_CMD_BOOTM || defined CONFIG_CMD_BOOTZ || \
 	defined CONFIG_CMD_BOOTU
 void armlinux_set_bootparams(void *params);
 void armlinux_set_architecture(int architecture);
-void armlinux_add_dram(struct device_d *dev);
 void armlinux_set_revision(unsigned int);
 void armlinux_set_serial(u64);
 #else
@@ -17,10 +18,6 @@ static inline void armlinux_set_architecture(int architecture)
 {
 }
 
-static inline void armlinux_add_dram(struct device_d *dev)
-{
-}
-
 static inline void armlinux_set_revision(unsigned int rev)
 {
 }
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
dissimilarity index 79%
index f746bc2..93c2fe6 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -1,16 +1,18 @@
-/*
- *  linux/include/asm-arm/memory.h
- *
- *  Copyright (C) 2000-2002 Russell King
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- *  Note: this file should not be included by non-asm/.h files
- */
-#ifndef __ASM_ARM_MEMORY_H
-#define __ASM_ARM_MEMORY_H
-
-
-#endif	/* __ASM_ARM_MEMORY_H */
+#ifndef __ASM_ARM_MEMORY_H
+#define __ASM_ARM_MEMORY_H
+
+struct arm_memory {
+	struct list_head list;
+	struct device_d *dev;
+	u32 *ptes;
+	unsigned long start;
+	unsigned long size;
+};
+
+extern struct list_head memory_list;
+
+void armlinux_add_dram(struct device_d *dev);
+
+#define for_each_sdram_bank(mem)	list_for_each_entry(mem, &memory_list, list)
+
+#endif	/* __ASM_ARM_MEMORY_H */
diff --git a/arch/arm/lib/armlinux.c b/arch/arm/lib/armlinux.c
index e35e45d..c8ed402 100644
--- a/arch/arm/lib/armlinux.c
+++ b/arch/arm/lib/armlinux.c
@@ -42,6 +42,7 @@
 #include <asm/barebox-arm.h>
 #include <asm/armlinux.h>
 #include <asm/system.h>
+#include <asm/memory.h>
 
 static struct tag *params;
 static int armlinux_architecture = 0;
@@ -64,18 +65,11 @@ static void setup_start_tag(void)
 	params = tag_next(params);
 }
 
-struct arm_memory {
-	struct list_head list;
-	struct device_d *dev;
-};
-
-static LIST_HEAD(memory_list);
-
 static void setup_memory_tags(void)
 {
 	struct arm_memory *mem;
 
-	list_for_each_entry(mem, &memory_list, list) {
+	for_each_sdram_bank(mem) {
 		params->hdr.tag = ATAG_MEM;
 		params->hdr.size = tag_size(tag_mem32);
 
@@ -196,15 +190,6 @@ void armlinux_set_architecture(int architecture)
 	armlinux_architecture = architecture;
 }
 
-void armlinux_add_dram(struct device_d *dev)
-{
-	struct arm_memory *mem = xzalloc(sizeof(*mem));
-
-	mem->dev = dev;
-
-	list_add_tail(&mem->list, &memory_list);
-}
-
 void armlinux_set_revision(unsigned int rev)
 {
 	system_rev = rev;
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 4/9] ARM l2x0: make init function static inline if l2 is not available
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 preceding siblings ...)
  2011-08-01 13:29 ` [PATCH 3/9] ARM: move armlinux_add_dram to location which is always compiled Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 5/9] ARM: pass size to dma_free_coherent Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

So that the ifdeffery can be moved out of the board code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/include/asm/mmu.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index f235448..d96c728 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -60,7 +60,13 @@ static inline void dma_inv_range(unsigned long s, unsigned long e)
 
 #endif
 
+#ifdef CONFIG_CACHE_L2X0
 void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask);
+#else
+static inline void __init l2x0_init(void __iomem *base, __u32 aux_val, __u32 aux_mask)
+{
+}
+#endif
 
 struct outer_cache_fns {
 	void (*inv_range)(unsigned long, unsigned long);
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 5/9] ARM: pass size to dma_free_coherent
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 preceding siblings ...)
  2011-08-01 13:29 ` [PATCH 4/9] ARM l2x0: make init function static inline if l2 is not available Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 6/9] init: introduce mem, mmu and postmmu initcall Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

We'll need it later once we remap dma memory.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/mmu.c           |    2 +-
 arch/arm/include/asm/mmu.h   |    9 +++++++--
 drivers/usb/gadget/fsl_udc.c |    2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 8465d1a..bb067e3 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -155,7 +155,7 @@ void *phys_to_virt(unsigned long phys)
 	return (void *)(phys + dma_coherent_offset);
 }
 
-void dma_free_coherent(void *mem)
+void dma_free_coherent(void *mem, size_t size)
 {
 	free(mem - dma_coherent_offset);
 }
diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index d96c728..9ebc2cd 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -17,7 +17,7 @@ void setup_dma_coherent(unsigned long offset);
 
 #ifdef CONFIG_MMU
 void *dma_alloc_coherent(size_t size);
-void dma_free_coherent(void *mem);
+void dma_free_coherent(void *mem, size_t size);
 
 void dma_clean_range(unsigned long, unsigned long);
 void dma_flush_range(unsigned long, unsigned long);
@@ -26,12 +26,17 @@ unsigned long virt_to_phys(void *virt);
 void *phys_to_virt(unsigned long phys);
 
 #else
+static inline int mmu_init(void)
+{
+	return -EINVAL;
+}
+
 static inline void *dma_alloc_coherent(size_t size)
 {
 	return xmemalign(4096, size);
 }
 
-static inline void dma_free_coherent(void *mem)
+static inline void dma_free_coherent(void *mem, size_t size)
 {
 	free(mem);
 }
diff --git a/drivers/usb/gadget/fsl_udc.c b/drivers/usb/gadget/fsl_udc.c
index c321e8f..1e4d4b0 100644
--- a/drivers/usb/gadget/fsl_udc.c
+++ b/drivers/usb/gadget/fsl_udc.c
@@ -560,7 +560,7 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
 		if (j != req->dtd_count - 1) {
 			next_td = curr_td->next_td_virt;
 		}
-		dma_free_coherent(curr_td);
+		dma_free_coherent(curr_td, sizeof(struct ep_td_struct));
 	}
 
 	dma_inv_range((unsigned long)req->req.buf,
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 6/9] init: introduce mem, mmu and postmmu initcall
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 preceding siblings ...)
  2011-08-01 13:29 ` [PATCH 5/9] ARM: pass size to dma_free_coherent Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 7/9 v2] ARM boards: move sdram setup before mmu setup Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

on ARM we need to init all the memory before the mmu and before any drivers
use dma_alloc_coherent

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/init.h |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/init.h b/include/init.h
index 2f4fac1..976f643 100644
--- a/include/init.h
+++ b/include/init.h
@@ -30,10 +30,13 @@ typedef int (*initcall_t)(void);
 #define postcore_initcall(fn)		__define_initcall("2",fn,2)
 #define console_initcall(fn)		__define_initcall("3",fn,3)
 #define postconsole_initcall(fn)	__define_initcall("4",fn,4)
-#define coredevice_initcall(fn)		__define_initcall("5",fn,5)
-#define fs_initcall(fn)			__define_initcall("6",fn,6)
-#define device_initcall(fn)		__define_initcall("7",fn,7)
-#define late_initcall(fn)		__define_initcall("8",fn,8)
+#define mem_initcall(fn)		__define_initcall("5",fn,5)
+#define mmu_initcall(fn)		__define_initcall("6",fn,6)
+#define postmmu_initcall(fn)		__define_initcall("7",fn,7)
+#define coredevice_initcall(fn)		__define_initcall("8",fn,8)
+#define fs_initcall(fn)			__define_initcall("9",fn,9)
+#define device_initcall(fn)		__define_initcall("10",fn,10)
+#define late_initcall(fn)		__define_initcall("11",fn,11)
 
 /* section for code used very early when
  * - we're not running from where we linked at
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 7/9 v2] ARM boards: move sdram setup before mmu setup
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 preceding siblings ...)
  2011-08-01 13:29 ` [PATCH 6/9] init: introduce mem, mmu and postmmu initcall Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 8/9] ARM: rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

The new MMU setup will need SDRAM base addresses and sizes.
For this reason convert the MMU enabled ARM boards:

- move mem setup to mem_initcall. This is early but
  still makes sure that we already have the console available
- move MMU setup in this initcall temporary as after the mmu_init will generic

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/boards/a9m2410/a9m2410.c                 |   18 +++++++++---
 arch/arm/boards/a9m2440/a9m2440.c                 |   18 ++++++++----
 arch/arm/boards/at91rm9200ek/init.c               |    9 +++++-
 arch/arm/boards/at91sam9260ek/init.c              |    9 +++++-
 arch/arm/boards/at91sam9261ek/init.c              |    9 +++++-
 arch/arm/boards/at91sam9263ek/init.c              |    9 +++++-
 arch/arm/boards/at91sam9m10g45ek/init.c           |    8 +++++-
 arch/arm/boards/chumby_falconwing/falconwing.c    |   15 +++++-----
 arch/arm/boards/edb93xx/edb93xx.c                 |   30 ++++++++++++--------
 arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c |   18 +++++-------
 arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |   17 +++++-------
 arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c |   12 ++++----
 arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c |   17 +++++-------
 arch/arm/boards/freescale-mx23-evk/mx23-evk.c     |   13 ++++++---
 arch/arm/boards/freescale-mx25-3-stack/3stack.c   |   26 +++++++++++-------
 arch/arm/boards/freescale-mx35-3-stack/3stack.c   |    8 +++++-
 arch/arm/boards/freescale-mx51-pdk/board.c        |   18 +++++-------
 arch/arm/boards/freescale-mx53-loco/board.c       |   20 +++++--------
 arch/arm/boards/guf-cupid/board.c                 |   11 ++++---
 arch/arm/boards/guf-neso/board.c                  |   18 +++++-------
 arch/arm/boards/imx21ads/imx21ads.c               |    9 +++++-
 arch/arm/boards/imx27ads/imx27ads.c               |    9 +++++-
 arch/arm/boards/karo-tx25/board.c                 |   24 ++++++----------
 arch/arm/boards/karo-tx28/tx28.c                  |   15 +++++-----
 arch/arm/boards/mini2440/mini2440.c               |   13 ++++++---
 arch/arm/boards/mmccpu/init.c                     |    9 +++++-
 arch/arm/boards/netx/netx.c                       |    9 +++++-
 arch/arm/boards/nhk8815/setup.c                   |    8 +++++-
 arch/arm/boards/omap/board-beagle.c               |    9 +++++-
 arch/arm/boards/omap/board-omap3evm.c             |    8 +++++-
 arch/arm/boards/omap/board-sdp343x.c              |   19 ++++++-------
 arch/arm/boards/panda/board.c                     |   12 ++++----
 arch/arm/boards/pcm037/pcm037.c                   |   23 +++++++---------
 arch/arm/boards/pcm038/pcm038.c                   |   22 +++++++--------
 arch/arm/boards/pcm043/pcm043.c                   |   13 +++++---
 arch/arm/boards/pcm049/board.c                    |   16 +++++-----
 arch/arm/boards/phycard-i.MX27/pca100.c           |   16 +++++------
 arch/arm/boards/pm9261/init.c                     |    9 +++++-
 arch/arm/boards/pm9263/init.c                     |    9 +++++-
 arch/arm/boards/pm9g45/init.c                     |    9 +++++-
 arch/arm/boards/scb9328/scb9328.c                 |    9 +++++-
 arch/arm/boards/versatile/versatilepb.c           |    8 +++++-
 42 files changed, 352 insertions(+), 229 deletions(-)

diff --git a/arch/arm/boards/a9m2410/a9m2410.c b/arch/arm/boards/a9m2410/a9m2410.c
index b249a1d..44ac44b 100644
--- a/arch/arm/boards/a9m2410/a9m2410.c
+++ b/arch/arm/boards/a9m2410/a9m2410.c
@@ -40,11 +40,10 @@ static struct s3c24x0_nand_platform_data nand_info = {
 	.nand_timing = CALC_NFCONF_TIMING(A9M2410_TACLS, A9M2410_TWRPH0, A9M2410_TWRPH1)
 };
 
-static int a9m2410_devices_init(void)
+static int a9m2410_mem_init(void)
 {
-	uint32_t reg;
 	resource_size_t size = 0;
-	struct device_d *sdram_dev;
+	uint32_t reg;
 
 	/*
 	 * detect the current memory size
@@ -101,6 +100,16 @@ static int a9m2410_devices_init(void)
 	 */
 	writel(0x40140, MISCCR);
 
+	arm_add_mem_device("ram0", CS6_BASE, size);
+
+	return 0;
+}
+mem_initcall(a9m2410_mem_init);
+
+static int a9m2410_devices_init(void)
+{
+	uint32_t reg;
+
 	/* ----------- configure the access to the outer space ---------- */
 	reg = readl(BWSCON);
 
@@ -124,7 +133,6 @@ static int a9m2410_devices_init(void)
 	/* ----------- the devices the boot loader should work with -------- */
 	add_generic_device("s3c24x0_nand", -1, NULL, S3C24X0_NAND_BASE, 0,
 			   IORESOURCE_MEM, &nand_info);
-	sdram_dev = arm_add_mem_device("ram0", CS6_BASE, size);
 	/*
 	 * SMSC 91C111 network controller on the baseboard
 	 * connected to CS line 1 and interrupt line
@@ -142,7 +150,7 @@ static int a9m2410_devices_init(void)
 	dev_add_bb_dev("env_raw", "env0");
 #endif
 
-	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
+	armlinux_set_bootparams((void*)CS6_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_A9M2410);
 
 	return 0;
diff --git a/arch/arm/boards/a9m2440/a9m2440.c b/arch/arm/boards/a9m2440/a9m2440.c
index c5b467a..89c9cdf 100644
--- a/arch/arm/boards/a9m2440/a9m2440.c
+++ b/arch/arm/boards/a9m2440/a9m2440.c
@@ -72,11 +72,8 @@ static void a9m2440_disable_second_sdram_bank(void)
 	writel(readl(MISCCR) | (1 << 18), MISCCR); /* disable clock */
 }
 
-static int a9m2440_devices_init(void)
+static int a9m2440_mem_init(void)
 {
-	uint32_t reg;
-	struct device_d *sdram_dev;
-
 	/*
 	 * The special SDRAM setup code for this machine will always enable
 	 * both SDRAM banks. But the second SDRAM device may not exists!
@@ -106,6 +103,16 @@ static int a9m2440_devices_init(void)
 		break;
 	}
 
+	arm_add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size());
+
+	return 0;
+}
+mem_initcall(a9m2440_mem_init);
+
+static int a9m2440_devices_init(void)
+{
+	uint32_t reg;
+
 	/* ----------- configure the access to the outer space ---------- */
 	reg = readl(BWSCON);
 
@@ -128,7 +135,6 @@ static int a9m2440_devices_init(void)
 	/* ----------- the devices the boot loader should work with -------- */
 	add_generic_device("s3c24x0_nand", -1, NULL, S3C24X0_NAND_BASE, 0,
 			   IORESOURCE_MEM, &nand_info);
-	sdram_dev = arm_add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size());
 	/*
 	 * cs8900 network controller onboard
 	 * Connected to CS line 5 + A24 and interrupt line EINT9,
@@ -145,7 +151,7 @@ static int a9m2440_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x20000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 #endif
-	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
+	armlinux_set_bootparams((void*)CS6_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_A9M2440);
 
 	return 0;
diff --git a/arch/arm/boards/at91rm9200ek/init.c b/arch/arm/boards/at91rm9200ek/init.c
index 9b58996..cff7ede 100644
--- a/arch/arm/boards/at91rm9200ek/init.c
+++ b/arch/arm/boards/at91rm9200ek/init.c
@@ -39,6 +39,14 @@ static struct at91_ether_platform_data ether_pdata = {
 	.phy_addr = 0,
 };
 
+static int at91rm9200ek_mem_init(void)
+{
+	at91_add_device_sdram(64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(at91rm9200ek_mem_init);
+
 static int at91rm9200ek_devices_init(void)
 {
 	/*
@@ -47,7 +55,6 @@ static int at91rm9200ek_devices_init(void)
 	 */
 	at91_set_gpio_output(AT91_PIN_PA23, 1);
 
-	at91_add_device_sdram(64 * 1024 * 1024);
 	at91_add_device_eth(&ether_pdata);
 
 	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 0, 0);
diff --git a/arch/arm/boards/at91sam9260ek/init.c b/arch/arm/boards/at91sam9260ek/init.c
index 966dd2f..861e898 100644
--- a/arch/arm/boards/at91sam9260ek/init.c
+++ b/arch/arm/boards/at91sam9260ek/init.c
@@ -141,13 +141,20 @@ static void at91sam9260ek_phy_reset(void)
 				     AT91_RSTC_URSTEN);
 }
 
+static int at91sam9260ek_mem_init(void)
+{
+	at91_add_device_sdram(64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(at91sam9260ek_mem_init);
+
 static int at91sam9260ek_devices_init(void)
 {
 	ek_add_device_nand();
 	at91sam9260ek_phy_reset();
 	at91_add_device_eth(&macb_pdata);
 
-	at91_add_device_sdram(64 * 1024 * 1024);
 	armlinux_set_bootparams((void *)(AT91_CHIPSELECT_1 + 0x100));
 	ek_set_board_type();
 
diff --git a/arch/arm/boards/at91sam9261ek/init.c b/arch/arm/boards/at91sam9261ek/init.c
index 627202f..69111a0 100644
--- a/arch/arm/boards/at91sam9261ek/init.c
+++ b/arch/arm/boards/at91sam9261ek/init.c
@@ -132,10 +132,17 @@ static void __init ek_add_device_dm9000(void)
 static void __init ek_add_device_dm9000(void) {}
 #endif /* CONFIG_DRIVER_NET_DM9000 */
 
+static int at91sam9261ek_mem_init(void)
+{
+	at91_add_device_sdram(64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(at91sam9261ek_mem_init);
+
 static int at91sam9261ek_devices_init(void)
 {
 
-	at91_add_device_sdram(64 * 1024 * 1024);
 	ek_add_device_nand();
 	ek_add_device_dm9000();
 
diff --git a/arch/arm/boards/at91sam9263ek/init.c b/arch/arm/boards/at91sam9263ek/init.c
index 036a1c4..46f3a7e 100644
--- a/arch/arm/boards/at91sam9263ek/init.c
+++ b/arch/arm/boards/at91sam9263ek/init.c
@@ -107,6 +107,14 @@ static void ek_add_device_mci(void)
 static void ek_add_device_mci(void) {}
 #endif
 
+static int at91sam9263ek_mem_init(void)
+{
+	at91_add_device_sdram(64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(at91sam9263ek_mem_init);
+
 static int at91sam9263ek_devices_init(void)
 {
 	/*
@@ -117,7 +125,6 @@ static int at91sam9263ek_devices_init(void)
 	at91_set_gpio_output(AT91_PIN_PB27, 1);
 	at91_set_gpio_value(AT91_PIN_PB27, 1); /* 1- enable, 0 - disable */
 
-	at91_add_device_sdram(64 * 1024 * 1024);
 	ek_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
 	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 8 * 1024 * 1024, 0);
diff --git a/arch/arm/boards/at91sam9m10g45ek/init.c b/arch/arm/boards/at91sam9m10g45ek/init.c
index 8cdcb8d..ba7c2ff 100644
--- a/arch/arm/boards/at91sam9m10g45ek/init.c
+++ b/arch/arm/boards/at91sam9m10g45ek/init.c
@@ -126,10 +126,16 @@ static void ek_add_device_mci(void)
 static void ek_add_device_mci(void) {}
 #endif
 
+static int at91sam9m10g45ek_mem_init(void)
+{
+	at91_add_device_sdram(128 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(at91sam9m10g45ek_mem_init);
 
 static int at91sam9m10g45ek_devices_init(void)
 {
-	at91_add_device_sdram(128 * 1024 * 1024);
 	ek_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
 	ek_add_device_mci();
diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c b/arch/arm/boards/chumby_falconwing/falconwing.c
index 06916f0..b20dd74 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -261,9 +261,11 @@ static const uint32_t pad_setup[] = {
 	GPMI_RDY3_GPIO | GPIO_IN | PULLUP(1),
 };
 
-#ifdef CONFIG_MMU
-static int falconwing_mmu_init(void)
+static int falconwing_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_MEMORY_BASE, 64 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x40000000, 0x40000000, 64, PMD_SECT_DEF_CACHED);
@@ -272,11 +274,10 @@ static int falconwing_mmu_init(void)
 	setup_dma_coherent(0x10000000);
 
 	mmu_enable();
-
+#endif
 	return 0;
 }
-postcore_initcall(falconwing_mmu_init);
-#endif
+mem_initcall(falconwing_mem_init);
 
 /**
  * Try to register an environment storage on the attached MCI card
@@ -333,13 +334,11 @@ static void falconwing_init_usb(void)
 static int falconwing_devices_init(void)
 {
 	int i, rc;
-	struct device_d *sdram_dev;
 
 	/* initizalize gpios */
 	for (i = 0; i < ARRAY_SIZE(pad_setup); i++)
 		imx_gpio_mode(pad_setup[i]);
 
-	sdram_dev = arm_add_mem_device("ram0", IMX_MEMORY_BASE, 64 * 1024 * 1024);
 	imx_set_ioclk(480000000); /* enable IOCLK to run at the PLL frequency */
 	/* run the SSP unit clock at 100,000 kHz */
 	imx_set_sspclk(0, 100000000, 1);
@@ -350,7 +349,7 @@ static int falconwing_devices_init(void)
 
 	falconwing_init_usb();
 
-	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
+	armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_CHUMBY);
 
 	rc = register_persistant_environment();
diff --git a/arch/arm/boards/edb93xx/edb93xx.c b/arch/arm/boards/edb93xx/edb93xx.c
index fd838bf..3e4e0b0 100644
--- a/arch/arm/boards/edb93xx/edb93xx.c
+++ b/arch/arm/boards/edb93xx/edb93xx.c
@@ -34,19 +34,8 @@
 
 #define DEVCFG_U1EN (1 << 18)
 
-static int ep93xx_devices_init(void)
+static int ep93xx_mem_init(void)
 {
-	add_cfi_flash_device(-1, 0x60000000, EDB93XX_CFI_FLASH_SIZE, 0);
-
-	/*
-	 * Create partitions that should be
-	 * not touched by any regular user
-	 */
-	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self0");
-	devfs_add_partition("nor0", 0x40000, 0x20000, PARTITION_FIXED, "env0");
-
-	protect_file("/dev/env0", 1);
-
 	arm_add_mem_device("ram0", CONFIG_EP93XX_SDRAM_BANK0_BASE,
 				   CONFIG_EP93XX_SDRAM_BANK0_SIZE);
 #if (CONFIG_EP93XX_SDRAM_NUM_BANKS >= 2)
@@ -62,6 +51,23 @@ static int ep93xx_devices_init(void)
 				   CONFIG_EP93XX_SDRAM_BANK2_SIZE);
 #endif
 
+	return 0;
+}
+mem_initcall(ep93xx_mem_init);
+
+static int ep93xx_devices_init(void)
+{
+	add_cfi_flash_device(-1, 0x60000000, EDB93XX_CFI_FLASH_SIZE, 0);
+
+	/*
+	 * Create partitions that should be
+	 * not touched by any regular user
+	 */
+	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self0");
+	devfs_add_partition("nor0", 0x40000, 0x20000, PARTITION_FIXED, "env0");
+
+	protect_file("/dev/env0", 1);
+
 	/*
 	 * Up to 32MiB NOR type flash, connected to
 	 * CS line 6, data width is 16 bit
diff --git a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
index e188fab..5c07597 100644
--- a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
+++ b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
@@ -156,9 +156,11 @@ static struct fsl_usb2_platform_data usb_pdata = {
 	.phy_mode	= FSL_USB2_PHY_UTMI,
 };
 
-#ifdef CONFIG_MMU
-static void eukrea_cpuimx25_mmu_init(void)
+static int eukrea_cpuimx25_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 64 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
@@ -167,12 +169,10 @@ static void eukrea_cpuimx25_mmu_init(void)
 	setup_dma_coherent(0x10000000);
 
 	mmu_enable();
-}
-#else
-static void eukrea_cpuimx25_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(eukrea_cpuimx25_mem_init);
 
 static struct pad_desc eukrea_cpuimx25_pads[] = {
 	MX25_PAD_FEC_MDC__FEC_MDC,
@@ -230,8 +230,6 @@ static struct pad_desc eukrea_cpuimx25_pads[] = {
 
 static int eukrea_cpuimx25_devices_init(void)
 {
-	eukrea_cpuimx25_mmu_init();
-
 	mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx25_pads,
 		ARRAY_SIZE(eukrea_cpuimx25_pads));
 
@@ -251,8 +249,6 @@ static int eukrea_cpuimx25_devices_init(void)
 		PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 64 * 1024 * 1024);
-
 	/* enable LCD */
 	gpio_direction_output(26, 1);
 	gpio_set_value(26, 1);
diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
index e42ad7c..ac886fa 100644
--- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
+++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
@@ -88,9 +88,11 @@ static struct i2c_board_info i2c_devices[] = {
 	},
 };
 
-#ifdef CONFIG_MMU
-static void eukrea_cpuimx27_mmu_init(void)
+static int eukrea_cpuimx27_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0xa0000000, SDRAM0 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
@@ -99,12 +101,10 @@ static void eukrea_cpuimx27_mmu_init(void)
 	setup_dma_coherent(0x10000000);
 
 	mmu_enable();
-}
-#else
-static void eukrea_cpuimx27_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(eukrea_cpuimx27_mem_init);
 
 #ifdef CONFIG_DRIVER_VIDEO_IMX
 static struct imx_fb_videomode imxfb_mode = {
@@ -192,8 +192,6 @@ static int eukrea_cpuimx27_devices_init(void)
 #endif
 	};
 
-	eukrea_cpuimx27_mmu_init();
-
 	/* configure 16 bit nor flash on cs0 */
 	CS0U = 0x00008F03;
 	CS0L = 0xA0330D01;
@@ -208,7 +206,6 @@ static int eukrea_cpuimx27_devices_init(void)
 	add_cfi_flash_device(-1, 0xC2000000, 32 * 1024 * 1024, 0);
 #endif
 	imx27_add_nand(&nand_info);
-	arm_add_mem_device("ram0", 0xa0000000, SDRAM0 * 1024 * 1024);
 
 	PCCR0 |= PCCR0_I2C1_EN;
 	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
diff --git a/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c b/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
index 29b9edf..02df444 100644
--- a/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
+++ b/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -126,9 +126,11 @@ static struct fsl_usb2_platform_data usb_pdata = {
 };
 #endif
 
-#ifdef CONFIG_MMU
-static int eukrea_cpuimx35_mmu_init(void)
+static int eukrea_cpuimx35_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
@@ -141,10 +143,10 @@ static int eukrea_cpuimx35_mmu_init(void)
 #ifdef CONFIG_CACHE_L2X0
 	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
 #endif
+#endif
 	return 0;
 }
-postcore_initcall(eukrea_cpuimx35_mmu_init);
-#endif
+mem_initcall(eukrea_cpuimx35_mem_init);
 
 static int eukrea_cpuimx35_devices_init(void)
 {
@@ -156,8 +158,6 @@ static int eukrea_cpuimx35_devices_init(void)
 	dev_add_bb_dev("env_raw", "env0");
 
 	imx35_add_fec(&fec_info);
-
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 
 	imx35_add_i2c0(NULL);
diff --git a/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c b/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
index 2510e07..b6fce93 100644
--- a/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
+++ b/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
@@ -93,9 +93,11 @@ static struct pad_desc eukrea_cpuimx51_pads[] = {
 #define GPIO_LAN8700_RESET	(1 * 32 + 31)
 #define GPIO_LCD_BL		(2 * 32 + 4)
 
-#ifdef CONFIG_MMU
-static void eukrea_cpuimx51_mmu_init(void)
+static int eukrea_cpuimx51_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0x90000000, 256 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x90000000, 0x90000000, 256, PMD_SECT_DEF_CACHED);
@@ -110,18 +112,13 @@ static void eukrea_cpuimx51_mmu_init(void)
 #endif
 
 	mmu_enable();
-}
-#else
-static void eukrea_cpuimx51_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(eukrea_cpuimx51_mem_init);
 
 static int eukrea_cpuimx51_devices_init(void)
 {
-	eukrea_cpuimx51_mmu_init();
-
-	arm_add_mem_device("ram0", 0x90000000, 256 * 1024 * 1024);
 	imx51_add_fec(&fec_info);
 #ifdef CONFIG_MCI_IMX_ESDHC
 	imx51_add_mmc0(NULL);
diff --git a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
index 7e23e9a..47f6769 100644
--- a/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
+++ b/arch/arm/boards/freescale-mx23-evk/mx23-evk.c
@@ -25,12 +25,17 @@
 #include <generated/mach-types.h>
 #include <mach/imx-regs.h>
 
-static int mx23_evk_devices_init(void)
+static int mx23_evk_mem_init(void)
 {
-	struct device_d *sdram_dev;
+	arm_add_mem_device("ram0", IMX_MEMORY_BASE, 32 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(mx23_evk_mem_init);
 
-	sdram_dev = arm_add_mem_device("ram0", IMX_MEMORY_BASE, 32 * 1024 * 1024);
-	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
+static int mx23_evk_devices_init(void)
+{
+	armlinux_set_bootparams((void*)IMX_MEMORY_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_MX23EVK);
 
 	return 0;
diff --git a/arch/arm/boards/freescale-mx25-3-stack/3stack.c b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
index b142232..979115d 100644
--- a/arch/arm/boards/freescale-mx25-3-stack/3stack.c
+++ b/arch/arm/boards/freescale-mx25-3-stack/3stack.c
@@ -192,6 +192,22 @@ static int imx25_3ds_fec_init(void)
 }
 late_initcall(imx25_3ds_fec_init);
 
+static int imx25_mem_init(void)
+{
+#if defined CONFIG_FREESCALE_MX25_3STACK_SDRAM_64MB_DDR2
+#define SDRAM_SIZE	64 * 1024 * 1024
+#elif defined CONFIG_FREESCALE_MX25_3STACK_SDRAM_128MB_MDDR
+#define SDRAM_SIZE	128 * 1024 * 1024
+#else
+#error "Unsupported SDRAM type"
+#endif
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM_SIZE);
+	add_mem_device("sram0", 0x78000000, 128 * 1024, IORESOURCE_MEM_WRITEABLE);
+
+	return 0;
+}
+mem_initcall(imx25_mem_init);
+
 static int imx25_devices_init(void)
 {
 #ifdef CONFIG_USB
@@ -216,16 +232,6 @@ static int imx25_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x20000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-#if defined CONFIG_FREESCALE_MX25_3STACK_SDRAM_64MB_DDR2
-#define SDRAM_SIZE	64 * 1024 * 1024
-#elif defined CONFIG_FREESCALE_MX25_3STACK_SDRAM_128MB_MDDR
-#define SDRAM_SIZE	128 * 1024 * 1024
-#else
-#error "Unsupported SDRAM type"
-#endif
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM_SIZE);
-	add_mem_device("sram0", 0x78000000, 128 * 1024, IORESOURCE_MEM_WRITEABLE);
-
 	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
 	imx25_add_i2c0(NULL);
 
diff --git a/arch/arm/boards/freescale-mx35-3-stack/3stack.c b/arch/arm/boards/freescale-mx35-3-stack/3stack.c
index 27d4e83..ab70265 100644
--- a/arch/arm/boards/freescale-mx35-3-stack/3stack.c
+++ b/arch/arm/boards/freescale-mx35-3-stack/3stack.c
@@ -128,6 +128,13 @@ static void set_board_rev(int rev)
 	imx35_3ds_system_rev =  (imx35_3ds_system_rev & ~(0xF << 8)) | (rev & 0xF) << 8;
 }
 
+static int f3s_mem_init(void)
+{
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 124 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(f3s_mem_init);
 
 static int f3s_devices_init(void)
 {
@@ -177,7 +184,6 @@ static int f3s_devices_init(void)
 
 	imx35_add_mmc0(NULL);
 
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 124 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 
 	armlinux_set_bootparams((void *)0x80000100);
diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index 509e3c4..f347657 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -73,9 +73,11 @@ static struct pad_desc f3s_pads[] = {
 	IOMUX_PAD(0x60C, 0x21C, 3, 0x0, 0, 0x85), /* FIXME: needed? */
 };
 
-#ifdef CONFIG_MMU
-static void babbage_mmu_init(void)
+static int babbage_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0x90000000, 512 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x90000000, 0x90000000, 512, PMD_SECT_DEF_CACHED);
@@ -84,12 +86,10 @@ static void babbage_mmu_init(void)
 	setup_dma_coherent(0x20000000);
 
 	mmu_enable();
-}
-#else
-static void babbage_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(babbage_mem_init);
 
 #define BABBAGE_ECSPI1_CS0	(3 * 32 + 24)
 static int spi_0_cs[] = {BABBAGE_ECSPI1_CS0};
@@ -227,10 +227,6 @@ static void babbage_power_init(void)
 
 static int f3s_devices_init(void)
 {
-	babbage_mmu_init();
-
-	arm_add_mem_device("ram0", 0x90000000, 512 * 1024 * 1024);
-
 	imx51_iim_register_fec_ethaddr();
 	imx51_add_fec(&fec_info);
 	imx51_add_mmc0(NULL);
diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index 8ffe964..92cff01 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -73,9 +73,12 @@ static struct pad_desc loco_pads[] = {
 	MX53_PAD_EIM_DA13__GPIO3_13,
 };
 
-#ifdef CONFIG_MMU
-static void loco_mmu_init(void)
+static int loco_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0x70000000, SZ_512M);
+	arm_add_mem_device("ram1", 0xb0000000, SZ_512M);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x70000000, 0x70000000, 512, PMD_SECT_DEF_CACHED);
@@ -86,12 +89,10 @@ static void loco_mmu_init(void)
 	setup_dma_coherent(0x20000000);
 
 	mmu_enable();
-}
-#else
-static void loco_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(loco_mem_init);
 
 #define LOCO_FEC_PHY_RST		IMX_GPIO_NR(7, 6)
 
@@ -104,11 +105,6 @@ static void loco_fec_reset(void)
 
 static int loco_devices_init(void)
 {
-	loco_mmu_init();
-
-	arm_add_mem_device("ram0", 0x70000000, SZ_512M);
-	arm_add_mem_device("ram1", 0xb0000000, SZ_512M);
-
 	imx51_iim_register_fec_ethaddr();
 	imx53_add_fec(&fec_info);
 	imx53_add_mmc0(NULL);
diff --git a/arch/arm/boards/guf-cupid/board.c b/arch/arm/boards/guf-cupid/board.c
index d66afac..134f377 100644
--- a/arch/arm/boards/guf-cupid/board.c
+++ b/arch/arm/boards/guf-cupid/board.c
@@ -96,9 +96,11 @@ static struct imx_ipu_fb_platform_data ipu_fb_data = {
 	.enable		= cupid_fb_enable,
 };
 
-#ifdef CONFIG_MMU
-static int cupid_mmu_init(void)
+static int cupid_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
@@ -111,10 +113,10 @@ static int cupid_mmu_init(void)
 #ifdef CONFIG_CACHE_L2X0
 	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
 #endif
+#endif
 	return 0;
 }
-postcore_initcall(cupid_mmu_init);
-#endif
+mem_initcall(cupid_mem_init);
 
 static int cupid_devices_init(void)
 {
@@ -138,7 +140,6 @@ static int cupid_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x80000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 	imx35_add_mmc0(NULL);
 
diff --git a/arch/arm/boards/guf-neso/board.c b/arch/arm/boards/guf-neso/board.c
index 6486f3a..3517a5d 100644
--- a/arch/arm/boards/guf-neso/board.c
+++ b/arch/arm/boards/guf-neso/board.c
@@ -136,9 +136,11 @@ static void neso_usbh_init(void)
 }
 #endif
 
-#ifdef CONFIG_MMU
-static void neso_mmu_init(void)
+static int neso_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
@@ -147,12 +149,10 @@ static void neso_mmu_init(void)
 	setup_dma_coherent(0x10000000);
 
 	mmu_enable();
-}
-#else
-static void neso_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(neso_mem_init);
 
 static int neso_devices_init(void)
 {
@@ -280,15 +280,11 @@ static int neso_devices_init(void)
 	gpio_direction_output(OTG_PHY_CS_GPIO, 1);
 	gpio_direction_output(USBH2_PHY_CS_GPIO, 1);
 
-
-	neso_mmu_init();
-
 	/* initialize gpios */
 	for (i = 0; i < ARRAY_SIZE(mode); i++)
 		imx_gpio_mode(mode[i]);
 
 	imx27_add_nand(&nand_info);
-	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 	imx27_add_fb(&neso_fb_data);
 
 #ifdef CONFIG_USB
diff --git a/arch/arm/boards/imx21ads/imx21ads.c b/arch/arm/boards/imx21ads/imx21ads.c
index b449279..d58831e 100644
--- a/arch/arm/boards/imx21ads/imx21ads.c
+++ b/arch/arm/boards/imx21ads/imx21ads.c
@@ -115,6 +115,14 @@ static int imx21ads_timing_init(void)
 
 core_initcall(imx21ads_timing_init);
 
+static int mx21ads_mem_init(void)
+{
+	arm_add_mem_device("ram0", 0xc0000000, 64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(mx21ads_mem_init);
+
 static int mx21ads_devices_init(void)
 {
 	int i;
@@ -157,7 +165,6 @@ static int mx21ads_devices_init(void)
 		imx_gpio_mode(mode[i]);
 
 	add_cfi_flash_device(-1, 0xC8000000, 32 * 1024 * 1024, 0);
-	arm_add_mem_device("ram0", 0xc0000000, 64 * 1024 * 1024);
 	imx21_add_nand(&nand_info);
 	add_generic_device("cs8900", -1, NULL,	IMX_CS1_BASE, 0x1000,
 			IORESOURCE_MEM, NULL);
diff --git a/arch/arm/boards/imx27ads/imx27ads.c b/arch/arm/boards/imx27ads/imx27ads.c
index 299b2ea..da4260f 100644
--- a/arch/arm/boards/imx27ads/imx27ads.c
+++ b/arch/arm/boards/imx27ads/imx27ads.c
@@ -74,6 +74,14 @@ static int imx27ads_timing_init(void)
 
 core_initcall(imx27ads_timing_init);
 
+static int mx27ads_mem_init(void)
+{
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(mx27ads_mem_init);
+
 static int mx27ads_devices_init(void)
 {
 	int i;
@@ -108,7 +116,6 @@ static int mx27ads_devices_init(void)
 
 	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 
-	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 	imx27_add_fec(&fec_info);
 	devfs_add_partition("nor0", 0x00000, 0x20000, PARTITION_FIXED, "self0");
 	devfs_add_partition("nor0", 0x20000, 0x20000, PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/karo-tx25/board.c b/arch/arm/boards/karo-tx25/board.c
index 4e5eafa..a01fa3c 100644
--- a/arch/arm/boards/karo-tx25/board.c
+++ b/arch/arm/boards/karo-tx25/board.c
@@ -52,9 +52,14 @@ struct imx_nand_platform_data nand_info = {
 	.flash_bbt = 1,
 };
 
-#ifdef CONFIG_MMU
-static int tx25_mmu_init(void)
+static int tx25_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 32 * 1024 * 1024);
+	arm_add_mem_device("ram0", IMX_SDRAM_CS1, 32 * 1024 * 1024);
+	add_mem_device("ram0", 0x78000000, 128 * 1024,
+				   IORESOURCE_MEM_WRITEABLE);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 32, PMD_SECT_DEF_CACHED);
@@ -64,17 +69,11 @@ static int tx25_mmu_init(void)
 
 	setup_dma_coherent(0x02000000);
 
-#if TEXT_BASE & (0x100000 - 1)
-#warning cannot create vector section. Adjust TEXT_BASE to a 1M boundary
-#else
-	arm_create_section(0x0,        TEXT_BASE,   1, PMD_SECT_DEF_UNCACHED);
-#endif
 	mmu_enable();
-
+#endif
 	return 0;
 }
-postcore_initcall(tx25_mmu_init);
-#endif
+mem_initcall(tx25_mem_init);
 
 static struct pad_desc karo_tx25_padsd_fec[] = {
 	MX25_PAD_D11__GPIO_4_9,		/* FEC PHY power on pin */
@@ -134,11 +133,6 @@ static int tx25_devices_init(void)
 	devfs_add_partition("nand0", 0x40000, 0x80000, PARTITION_FIXED, "env_raw");
 	dev_add_bb_dev("env_raw", "env0");
 
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 32 * 1024 * 1024);
-	arm_add_mem_device("ram0", IMX_SDRAM_CS1, 32 * 1024 * 1024);
-	add_mem_device("ram0", 0x78000000, 128 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
-
 	armlinux_set_bootparams((void *)0x80000100);
 	armlinux_set_architecture(MACH_TYPE_TX25);
 	armlinux_set_serial(imx_uid());
diff --git a/arch/arm/boards/karo-tx28/tx28.c b/arch/arm/boards/karo-tx28/tx28.c
index 095835b..d6e3f9c 100644
--- a/arch/arm/boards/karo-tx28/tx28.c
+++ b/arch/arm/boards/karo-tx28/tx28.c
@@ -70,9 +70,11 @@ static const uint32_t tx28_pad_setup[] = {
 
 extern void base_board_init(void);
 
-#ifdef CONFIG_MMU
-static int tx28_mmu_init(void)
+static int tx28_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_MEMORY_BASE, 128 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x40000000, 0x40000000, 128, PMD_SECT_DEF_CACHED);
@@ -81,23 +83,20 @@ static int tx28_mmu_init(void)
 	setup_dma_coherent(0x10000000);
 
 	mmu_enable();
-
+#endif
 	return 0;
 }
-postcore_initcall(tx28_mmu_init);
-#endif
+mem_initcall(tx28_mem_init);
 
 static int tx28_devices_init(void)
 {
 	int i;
-	struct device_d *sdram_dev;
 
 	/* initizalize gpios */
 	for (i = 0; i < ARRAY_SIZE(tx28_pad_setup); i++)
 		imx_gpio_mode(tx28_pad_setup[i]);
 
-	sdram_dev = arm_add_mem_device("ram0", IMX_MEMORY_BASE, 128 * 1024 * 1024);
-	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
+	armlinux_set_bootparams((void *)IMX_MEMORY_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_TX28);
 
 	base_board_init();
diff --git a/arch/arm/boards/mini2440/mini2440.c b/arch/arm/boards/mini2440/mini2440.c
index df7e617..fd1f2f2 100644
--- a/arch/arm/boards/mini2440/mini2440.c
+++ b/arch/arm/boards/mini2440/mini2440.c
@@ -263,11 +263,18 @@ static const unsigned pin_usage[] = {
 	GPH7_RXD2,
 };
 
+static int mini2440_mem_init(void)
+{
+	arm_add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size());
+
+	return 0;
+}
+mem_initcall(mini2440_mem_init);
+
 static int mini2440_devices_init(void)
 {
 	uint32_t reg;
 	int i;
-	struct device_d *sdram_dev;
 
 	/* ----------- configure the access to the outer space ---------- */
 	for (i = 0; i < ARRAY_SIZE(pin_usage); i++)
@@ -290,8 +297,6 @@ static int mini2440_devices_init(void)
 	add_generic_device("s3c24x0_nand", -1, NULL, S3C24X0_NAND_BASE, 0,
 			   IORESOURCE_MEM, &nand_info);
 
-	sdram_dev = arm_add_mem_device("ram0", CS6_BASE, s3c24x0_get_memory_size());
-
 	add_dm9000_device(0, CS4_BASE + 0x300, CS4_BASE + 0x304,
 			  IORESOURCE_MEM_16BIT, &dm9000_data);
 #ifdef CONFIG_NAND
@@ -308,7 +313,7 @@ static int mini2440_devices_init(void)
 			   IORESOURCE_MEM, &mci_data);
 	add_generic_device("s3c_fb", 0, NULL, S3C2410_LCD_BASE, 0,
 			   IORESOURCE_MEM, &s3c24x0_fb_data);
-	armlinux_set_bootparams(dev_get_mem_region(sdram_dev, 0) + 0x100);
+	armlinux_set_bootparams((void*)CS6_BASE + 0x100);
 	armlinux_set_architecture(MACH_TYPE_MINI2440);
 
 	return 0;
diff --git a/arch/arm/boards/mmccpu/init.c b/arch/arm/boards/mmccpu/init.c
index eb6b490..36bc193 100644
--- a/arch/arm/boards/mmccpu/init.c
+++ b/arch/arm/boards/mmccpu/init.c
@@ -42,6 +42,14 @@ static struct at91_ether_platform_data macb_pdata = {
 	.phy_addr	= 4,
 };
 
+static int mmccpu_mem_init(void)
+{
+	at91_add_device_sdram(128 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(mmccpu_mem_init);
+
 static int mmccpu_devices_init(void)
 {
 	/*
@@ -52,7 +60,6 @@ static int mmccpu_devices_init(void)
 	at91_set_gpio_output(AT91_PIN_PB27, 1);
 	at91_set_gpio_value(AT91_PIN_PB27, 1); /* 1- enable, 0 - disable */
 
-	at91_add_device_sdram(128 * 1024 * 1024);
 	at91_add_device_eth(&macb_pdata);
 	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 0, 0);
 
diff --git a/arch/arm/boards/netx/netx.c b/arch/arm/boards/netx/netx.c
index e9b834a..92d2911 100644
--- a/arch/arm/boards/netx/netx.c
+++ b/arch/arm/boards/netx/netx.c
@@ -38,10 +38,17 @@ struct netx_eth_platform_data eth1_data = {
 	.xcno = 1,
 };
 
+static int netx_mem_init(void)
+{
+	arm_add_mem_device("ram0", 0x80000000, 64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(netx_mem_init);
+
 static int netx_devices_init(void) {
 	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 
-	arm_add_mem_device("ram0", 0x80000000, 64 * 1024 * 1024);
 	add_generic_device("netx-eth", -1, NULL, 0, 0, IORESOURCE_MEM, &eth0_data);
 	add_generic_device("netx-eth", -1, NULL, 0, 0, IORESOURCE_MEM, &eth1_data);
 
diff --git a/arch/arm/boards/nhk8815/setup.c b/arch/arm/boards/nhk8815/setup.c
index da6be93..dcf7166 100644
--- a/arch/arm/boards/nhk8815/setup.c
+++ b/arch/arm/boards/nhk8815/setup.c
@@ -76,10 +76,16 @@ static struct device_d nhk8815_nand_device = {
 	.platform_data	= &nhk8815_nand_data,
 };
 
-static int nhk8815_devices_init(void)
+static int nhk8815_mem_init(void)
 {
 	st8815_add_device_sdram(64 * 1024 *1024);
 
+	return 0;
+}
+mem_initcall(nhk8815_mem_init);
+
+static int nhk8815_devices_init(void)
+{
 	writel(0xC37800F0, NOMADIK_GPIO1_BASE + 0x20);
 	writel(0x00000000, NOMADIK_GPIO1_BASE + 0x24);
 	writel(0x00000000, NOMADIK_GPIO1_BASE + 0x28);
diff --git a/arch/arm/boards/omap/board-beagle.c b/arch/arm/boards/omap/board-beagle.c
index 4602631..49af40c 100644
--- a/arch/arm/boards/omap/board-beagle.c
+++ b/arch/arm/boards/omap/board-beagle.c
@@ -278,9 +278,16 @@ static struct i2c_board_info i2c_devices[] = {
 	},
 };
 
-static int beagle_devices_init(void)
+static int beagle_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(beagle_mem_init);
+
+static int beagle_devices_init(void)
+{
 	i2c_register_board_info(0, i2c_devices, ARRAY_SIZE(i2c_devices));
 	add_generic_device("i2c-omap", -1, NULL, 0x4809C000, SZ_4K,
 			   IORESOURCE_MEM, NULL);
diff --git a/arch/arm/boards/omap/board-omap3evm.c b/arch/arm/boards/omap/board-omap3evm.c
index 68d971b..a2532d5 100644
--- a/arch/arm/boards/omap/board-omap3evm.c
+++ b/arch/arm/boards/omap/board-omap3evm.c
@@ -235,10 +235,16 @@ static int omap3evm_init_console(void)
 console_initcall(omap3evm_init_console);
 #endif /* CONFIG_DRIVER_SERIAL_NS16550 */
 
-static int omap3evm_init_devices(void)
+static int omap3evm_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024);
 
+	return 0;
+}
+mem_initcall(omap3evm_mem_init);
+
+static int omap3evm_init_devices(void)
+{
 #ifdef CONFIG_GPMC
 	/*
 	 * WP is made high and WAIT1 active Low
diff --git a/arch/arm/boards/omap/board-sdp343x.c b/arch/arm/boards/omap/board-sdp343x.c
index 8fcae12..82fc16d 100644
--- a/arch/arm/boards/omap/board-sdp343x.c
+++ b/arch/arm/boards/omap/board-sdp343x.c
@@ -624,23 +624,22 @@ static int sdp3430_console_init(void)
 console_initcall(sdp3430_console_init);
 #endif				/* CONFIG_DRIVER_SERIAL_NS16550 */
 
-/*------------------------- FLASH Devices -----------------------------------*/
-static int sdp3430_flash_init(void)
+static int sdp3430_mem_init(void)
 {
-#ifdef CONFIG_GPMC
-	/* WP is made high and WAIT1 active Low */
-	gpmc_generic_init(0x10);
-#endif
+	arm_add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024);
+
 	return 0;
 }
-
-/*-----------------------Generic Devices Initialization ---------------------*/
+mem_initcall(sdp3430_mem_init);
 
 static int sdp3430_devices_init(void)
 {
-	arm_add_mem_device("ram0", 0x80000000, 128 * 1024 * 1024);
+#ifdef CONFIG_GPMC
+	/* WP is made high and WAIT1 active Low */
+	gpmc_generic_init(0x10);
+#endif
 
-	return sdp3430_flash_init();
+	return 0;
 }
 
 device_initcall(sdp3430_devices_init);
diff --git a/arch/arm/boards/panda/board.c b/arch/arm/boards/panda/board.c
index e27f0a4..696d44a 100644
--- a/arch/arm/boards/panda/board.c
+++ b/arch/arm/boards/panda/board.c
@@ -44,20 +44,21 @@ static int panda_console_init(void)
 }
 console_initcall(panda_console_init);
 
-#ifdef CONFIG_MMU
-static int panda_mmu_init(void)
+static int panda_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0x80000000, SZ_1G);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 256, PMD_SECT_DEF_CACHED);
 	arm_create_section(0x90000000, 0x80000000, 256, PMD_SECT_DEF_UNCACHED);
 
 	mmu_enable();
-
+#endif
 	return 0;
 }
-device_initcall(panda_mmu_init);
-#endif
+mem_initcall(panda_mem_init);
 
 #ifdef CONFIG_USB_EHCI
 static struct ehci_platform_data ehci_pdata = {
@@ -139,7 +140,6 @@ static int panda_devices_init(void)
 		sr32(OMAP44XX_SCRM_ALTCLKSRC, 2, 2, 0x3);
 	}
 
-	arm_add_mem_device("ram0", 0x80000000, SZ_1G);
 	add_generic_device("omap-hsmmc", -1, NULL, 0x4809C100, SZ_4K,
 			   IORESOURCE_MEM, NULL);
 	panda_ehci_init();
diff --git a/arch/arm/boards/pcm037/pcm037.c b/arch/arm/boards/pcm037/pcm037.c
index 56db9a8..a026f23 100644
--- a/arch/arm/boards/pcm037/pcm037.c
+++ b/arch/arm/boards/pcm037/pcm037.c
@@ -146,9 +146,14 @@ static void pcm037_usb_init(void)
 }
 #endif
 
-#ifdef CONFIG_MMU
-static void pcm037_mmu_init(void)
+static int pcm037_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM0 * 1024 * 1024);
+#ifndef CONFIG_PCM037_SDRAM_BANK1_NONE
+	arm_add_mem_device("ram1", IMX_SDRAM_CS1, SDRAM1 * 1024 * 1024);
+#endif
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
@@ -161,17 +166,13 @@ static void pcm037_mmu_init(void)
 #ifdef CONFIG_CACHE_L2X0
 	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
 #endif
-}
-#else
-static void pcm037_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(pcm037_mem_init);
 
 static int imx31_devices_init(void)
 {
-	pcm037_mmu_init();
-
 	__REG(CSCR_U(0)) = 0x0000cf03; /* CS0: Nor Flash */
 	__REG(CSCR_L(0)) = 0x10000d03;
 	__REG(CSCR_A(0)) = 0x00720900;
@@ -219,10 +220,6 @@ static int imx31_devices_init(void)
 	add_generic_device("smc911x", -1, NULL,	IMX_CS1_BASE, IMX_CS1_RANGE,
 			IORESOURCE_MEM, NULL);
 
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM0 * 1024 * 1024);
-#ifndef CONFIG_PCM037_SDRAM_BANK1_NONE
-	arm_add_mem_device("ram1", IMX_SDRAM_CS1, SDRAM1 * 1024 * 1024);
-#endif
 #ifdef CONFIG_USB
 	pcm037_usb_init();
 	add_generic_usb_ehci_device(-1, IMX_OTG_BASE, NULL);
diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index bf15cfd..9588b9b 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -129,9 +129,13 @@ static void pcm038_usbh_init(void)
 }
 #endif
 
-#ifdef CONFIG_MMU
-static void pcm038_mmu_init(void)
+static int pcm038_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
+
+	add_mem_device("ram0", 0xc8000000, 512 * 1024, /* Can be up to 2MiB */
+				   IORESOURCE_MEM_WRITEABLE);
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
@@ -140,12 +144,10 @@ static void pcm038_mmu_init(void)
 	setup_dma_coherent(0x10000000);
 
 	mmu_enable();
-}
-#else
-static void pcm038_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(pcm038_mem_init);
 
 static int pcm038_devices_init(void)
 {
@@ -223,8 +225,6 @@ static int pcm038_devices_init(void)
 		PD26_AF_USBH2_DATA5,
 	};
 
-	pcm038_mmu_init();
-
 	/* configure 16 bit nor flash on cs0 */
 	CS0U = 0x0000CC03;
 	CS0L = 0xa0330D01;
@@ -249,14 +249,12 @@ static int pcm038_devices_init(void)
 
 	gpio_direction_output(GPIO_PORTD | 28, 0);
 	gpio_set_value(GPIO_PORTD | 28, 0);
+
 	spi_register_board_info(pcm038_spi_board_info, ARRAY_SIZE(pcm038_spi_board_info));
 	imx27_add_spi0(&pcm038_spi_0_data);
 
 	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 	imx27_add_nand(&nand_info);
-	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
-	add_mem_device("ram0", 0xc8000000, 512 * 1024, /* Can be up to 2MiB */
-				   IORESOURCE_MEM_WRITEABLE);
 	imx27_add_fb(&pcm038_fb_data);
 
 #ifdef CONFIG_USB
diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index 0f25354..10d319f 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -99,9 +99,11 @@ static struct imx_ipu_fb_platform_data ipu_fb_data = {
 	.bpp		= 16,
 };
 
-#ifdef CONFIG_MMU
-static int pcm043_mmu_init(void)
+static int pcm043_mem_init(void)
 {
+	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
@@ -114,10 +116,11 @@ static int pcm043_mmu_init(void)
 #ifdef CONFIG_CACHE_L2X0
 	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
 #endif
+#endif
 	return 0;
 }
-postcore_initcall(pcm043_mmu_init);
-#endif
+mem_initcall(pcm043_mem_init);
+
 
 struct gpio_led led0 = {
 	.gpio = 1 * 32 + 6,
@@ -170,7 +173,6 @@ static int imx35_devices_init(void)
 	}
 
 
-	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 	imx35_add_fb(&ipu_fb_data);
 
 	armlinux_set_bootparams((void *)0x80000100);
@@ -216,6 +218,7 @@ static int imx35_console_init(void)
 	mxc_iomux_v3_setup_multiple_pads(pcm043_pads, ARRAY_SIZE(pcm043_pads));
 
 	imx35_add_uart0();
+
 	return 0;
 }
 
diff --git a/arch/arm/boards/pcm049/board.c b/arch/arm/boards/pcm049/board.c
index 20419a3..83eb9be 100644
--- a/arch/arm/boards/pcm049/board.c
+++ b/arch/arm/boards/pcm049/board.c
@@ -54,9 +54,13 @@ static int pcm049_console_init(void)
 }
 console_initcall(pcm049_console_init);
 
-#ifdef CONFIG_MMU
-static int pcm049_mmu_init(void)
+static int pcm049_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0x80000000, SZ_512M);
+
+	add_mem_device("sram0", 0x40300000, 48 * 1024,
+				   IORESOURCE_MEM_WRITEABLE);
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0x80000000, 0x80000000, 256, PMD_SECT_DEF_CACHED);
@@ -64,11 +68,10 @@ static int pcm049_mmu_init(void)
 	arm_create_section(0x90000000, 0x80000000, 256, PMD_SECT_DEF_UNCACHED);
 
 	mmu_enable();
-
+#endif
 	return 0;
 }
-device_initcall(pcm049_mmu_init);
-#endif
+mem_initcall(pcm049_mem_init);
 
 static struct gpmc_config net_cfg = {
 	.cfg = {
@@ -93,9 +96,6 @@ static void pcm049_network_init(void)
 
 static int pcm049_devices_init(void)
 {
-	arm_add_mem_device("ram0", 0x80000000, SZ_512M);
-	add_mem_device("ram0", 0x40300000, 48 * 1024,
-				   IORESOURCE_MEM_WRITEABLE);
 	add_generic_device("omap-hsmmc", -1, NULL, 0x4809C100, SZ_4K,
 			   IORESOURCE_MEM, NULL);
 
diff --git a/arch/arm/boards/phycard-i.MX27/pca100.c b/arch/arm/boards/phycard-i.MX27/pca100.c
index 68f972a..3c2a0e4 100644
--- a/arch/arm/boards/phycard-i.MX27/pca100.c
+++ b/arch/arm/boards/phycard-i.MX27/pca100.c
@@ -69,9 +69,11 @@ static void pca100_usb_register(void)
 }
 #endif
 
-#ifdef CONFIG_MMU
-static void pca100_mmu_init(void)
+static int pca100_mem_init(void)
 {
+	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
+
+#ifdef CONFIG_MMU
 	mmu_init();
 
 	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
@@ -80,12 +82,10 @@ static void pca100_mmu_init(void)
 	setup_dma_coherent(0x10000000);
 
 	mmu_enable();
-}
-#else
-static void pca100_mmu_init(void)
-{
-}
 #endif
+	return 0;
+}
+mem_initcall(pca100_mem_init);
 
 static void pca100_usb_init(void)
 {
@@ -197,7 +197,6 @@ static int pca100_devices_init(void)
 		imx_gpio_mode(mode[i]);
 
 	imx27_add_nand(&nand_info);
-	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 	imx27_add_fec(&fec_info);
 	imx27_add_mmc0(NULL);
 
@@ -224,7 +223,6 @@ device_initcall(pca100_devices_init);
 
 static int pca100_console_init(void)
 {
-	pca100_mmu_init();
 	imx27_add_uart0();
 	return 0;
 }
diff --git a/arch/arm/boards/pm9261/init.c b/arch/arm/boards/pm9261/init.c
index 783a404..efc5dcc 100644
--- a/arch/arm/boards/pm9261/init.c
+++ b/arch/arm/boards/pm9261/init.c
@@ -126,9 +126,16 @@ static void __init pm_add_device_dm9000(void)
 static void __init ek_add_device_dm9000(void) {}
 #endif /* CONFIG_DRIVER_NET_DM9000 */
 
-static int pm9261_devices_init(void)
+static int pm9261_mem_init(void)
 {
 	at91_add_device_sdram(64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(pm9261_mem_init);
+
+static int pm9261_devices_init(void)
+{
 	pm_add_device_nand();
 	pm_add_device_dm9000();
 	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 4 * 1024 * 1024, 0);
diff --git a/arch/arm/boards/pm9263/init.c b/arch/arm/boards/pm9263/init.c
index 418b804..aeca4e7 100644
--- a/arch/arm/boards/pm9263/init.c
+++ b/arch/arm/boards/pm9263/init.c
@@ -91,6 +91,14 @@ static struct at91_ether_platform_data macb_pdata = {
 	.phy_addr = 0,
 };
 
+static int pm9263_mem_init(void)
+{
+	at91_add_device_sdram(64 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(pm9263_mem_init);
+
 static int pm9263_devices_init(void)
 {
 	/*
@@ -101,7 +109,6 @@ static int pm9263_devices_init(void)
 	at91_set_gpio_output(AT91_PIN_PB27, 1);
 	at91_set_gpio_value(AT91_PIN_PB27, 1); /* 1- enable, 0 - disable */
 
-	at91_add_device_sdram(64 * 1024 * 1024);
 	pm_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
 	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 4 * 1024 * 1024, 0);
diff --git a/arch/arm/boards/pm9g45/init.c b/arch/arm/boards/pm9g45/init.c
index 8031ce5..35c9ce9 100644
--- a/arch/arm/boards/pm9g45/init.c
+++ b/arch/arm/boards/pm9g45/init.c
@@ -82,9 +82,16 @@ static struct at91_ether_platform_data macb_pdata = {
 	.phy_addr = 0,
 };
 
-static int pm9g45_devices_init(void)
+static int pm9g45_mem_init(void)
 {
 	at91_add_device_sdram(128 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(pm9g45_mem_init);
+
+static int pm9g45_devices_init(void)
+{
 	pm_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
 
diff --git a/arch/arm/boards/scb9328/scb9328.c b/arch/arm/boards/scb9328/scb9328.c
index 68a39bf..e90417f 100644
--- a/arch/arm/boards/scb9328/scb9328.c
+++ b/arch/arm/boards/scb9328/scb9328.c
@@ -50,6 +50,14 @@ struct gpio_led leds[] = {
 	},
 };
 
+static int scb9328_mem_init(void)
+{
+	arm_add_mem_device("ram0", 0x08000000, 16 * 1024 * 1024);
+
+	return 0;
+}
+mem_initcall(scb9328_mem_init);
+
 static int scb9328_devices_init(void)
 {
 	int i;
@@ -81,7 +89,6 @@ static int scb9328_devices_init(void)
 	CS5L = 0x00000D03;
 
 	add_cfi_flash_device(-1, 0x10000000, 16 * 1024 * 1024, 0);
-	arm_add_mem_device("ram0", 0x08000000, 16 * 1024 * 1024);
 	add_dm9000_device(-1, 0x16000000, 0x16000004,
 			  IORESOURCE_MEM_16BIT, &dm9000_data);
 
diff --git a/arch/arm/boards/versatile/versatilepb.c b/arch/arm/boards/versatile/versatilepb.c
index fdd77e5..4e09de3 100644
--- a/arch/arm/boards/versatile/versatilepb.c
+++ b/arch/arm/boards/versatile/versatilepb.c
@@ -40,10 +40,16 @@ static int vpb_console_init(void)
 }
 console_initcall(vpb_console_init);
 
-static int vpb_devices_init(void)
+static int vpb_mem_init(void)
 {
 	versatile_add_sdram(64 * 1024 *1024);
 
+	return 0;
+}
+mem_initcall(vpb_mem_init);
+
+static int vpb_devices_init(void)
+{
 	add_cfi_flash_device(-1, VERSATILE_FLASH_BASE, VERSATILE_FLASH_SIZE, 0);
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self");
 	devfs_add_partition("nor0", 0x40000, 0x20000, PARTITION_FIXED, "env0");
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 8/9] ARM: rework MMU support
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 preceding siblings ...)
  2011-08-01 13:29 ` [PATCH 7/9 v2] ARM boards: move sdram setup before mmu setup Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 13:29 ` [PATCH 9/9 v2] ARM boards: remove now unnecessary mmu calls Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 15:54 ` rework MMU support Sascha Hauer
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

In barebox we used 1MiB sections to map our SDRAM cachable. This
has the drawback that we have to map our sdram twice: cached for
normal sdram and uncached for DMA operations. As address space gets
sparse on newer systems we are sometines unable to find a suitably
big enough area for the dma coherent space.

This patch changes the MMU code to use second level page tables.
With it we can implement dma_alloc_coherent as normal malloc, we
just have to remap the allocated area uncached afterwards and map
it cached again after free().

This makes arm_create_section(), setup_dma_coherent() and mmu_enable()
noops.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/mmu.c         |  175 ++++++++++++++++++++++++++++++++++++--------
 arch/arm/include/asm/mmu.h |   20 ++++-
 include/common.h           |    1 +
 3 files changed, 161 insertions(+), 35 deletions(-)

diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index bb067e3..53ba51a 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -1,10 +1,13 @@
 #include <common.h>
 #include <init.h>
 #include <asm/mmu.h>
+#include <errno.h>
+#include <sizes.h>
+#include <asm/memory.h>
 
 static unsigned long *ttb;
 
-void arm_create_section(unsigned long virt, unsigned long phys, int size_m,
+static void create_section(unsigned long virt, unsigned long phys, int size_m,
 		unsigned int flags)
 {
 	int i;
@@ -24,6 +27,23 @@ void arm_create_section(unsigned long virt, unsigned long phys, int size_m,
 }
 
 /*
+ * Do it the simple way for now and invalidate the entire
+ * tlb
+ */
+static inline void tlb_invalidate(void)
+{
+	asm volatile (
+		"mov	r0, #0\n"
+		"mcr	p15, 0, r0, c7, c10, 4;	@ drain write buffer\n"
+		"mcr	p15, 0, r0, c8, c6, 0;  @ invalidate D TLBs\n"
+		"mcr	p15, 0, r0, c8, c5, 0;  @ invalidate I TLBs\n"
+		:
+		:
+		: "r0"
+	);
+}
+
+/*
  * Create a second level translation table for the given virtual address.
  * We initially create a flat uncached mapping on it.
  * Not yet exported, but may be later if someone finds use for it.
@@ -43,6 +63,84 @@ static u32 *arm_create_pte(unsigned long virt)
 	return table;
 }
 
+static void remap_range(void *_start, size_t size, uint32_t flags)
+{
+	u32 pteentry;
+	struct arm_memory *mem;
+	unsigned long start = (unsigned long)_start;
+	u32 *p;
+	int numentries, i;
+
+	for_each_sdram_bank(mem) {
+		if (start >= mem->start && start < mem->start + mem->size)
+			goto found;
+	}
+
+	BUG();
+	return;
+
+found:
+	pteentry = (start - mem->start) >> PAGE_SHIFT;
+
+	numentries = size >> PAGE_SHIFT;
+
+	p = mem->ptes + pteentry;
+
+	for (i = 0; i < numentries; i++) {
+		p[i] &= ~(PTE_BUFFERABLE | PTE_CACHEABLE);
+		p[i] |= flags;
+	}
+
+	dma_flush_range((unsigned long)p,
+			(unsigned long)p + numentries * sizeof(u32));
+
+	tlb_invalidate();
+}
+
+/*
+ * remap the memory bank described by mem cachable and
+ * bufferable
+ */
+static int arm_mmu_remap_sdram(struct arm_memory *mem)
+{
+	unsigned long phys = (unsigned long)mem->start;
+	unsigned long ttb_start = phys >> 20;
+	unsigned long ttb_end = (phys + mem->size) >> 20;
+	unsigned long num_ptes = mem->size >> 10;
+	int i, pte;
+
+	debug("remapping SDRAM from 0x%08lx (size 0x%08lx)\n",
+			phys, mem->size);
+
+	/*
+	 * We replace each 1MiB section in this range with second level page
+	 * tables, therefore we must have 1Mib aligment here.
+	 */
+	if ((phys & (SZ_1M - 1)) || (mem->size & (SZ_1M - 1)))
+		return -EINVAL;
+
+	mem->ptes = memalign(0x400, num_ptes * sizeof(u32));
+
+	debug("ptes: 0x%p ttb_start: 0x%08lx ttb_end: 0x%08lx\n",
+			mem->ptes, ttb_start, ttb_end);
+
+	for (i = 0; i < num_ptes; i++) {
+		mem->ptes[i] = (phys + i * 4096) | PTE_TYPE_SMALL |
+			PTE_SMALL_AP_URW_SRW | PTE_BUFFERABLE | PTE_CACHEABLE;
+	}
+
+	pte = 0;
+
+	for (i = ttb_start; i < ttb_end; i++) {
+		ttb[i] = (unsigned long)(&mem->ptes[pte]) | PMD_TYPE_TABLE |
+			(0 << 4);
+		pte += 256;
+	}
+
+	tlb_invalidate();
+
+	return 0;
+}
 /*
  * We have 8 exception vectors and the table consists of absolute
  * jumps, so we need 8 * 4 bytes for the instructions and another
@@ -70,15 +168,17 @@ static void vectors_init(void)
 }
 
 /*
- * Prepare MMU for usage and create a flat mapping. Board
- * code is responsible to remap the SDRAM cached
+ * Prepare MMU for usage enable it.
  */
-void mmu_init(void)
+int mmu_init(void)
 {
+	struct arm_memory *mem;
 	int i;
 
 	ttb = memalign(0x10000, 0x4000);
 
+	debug("ttb: 0x%p\n", ttb);
+
 	/* Set the ttb register */
 	asm volatile ("mcr  p15,0,%0,c2,c0,0" : : "r"(ttb) /*:*/);
 
@@ -86,23 +186,36 @@ void mmu_init(void)
 	i = 0x3;
 	asm volatile ("mcr  p15,0,%0,c3,c0,0" : : "r"(i) /*:*/);
 
-	/* create a flat mapping */
-	arm_create_section(0, 0, 4096, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT);
+	/* create a flat mapping using 1MiB sections */
+	create_section(0, 0, 4096, PMD_SECT_AP_WRITE | PMD_SECT_AP_READ |
+			PMD_TYPE_SECT);
 
 	vectors_init();
-}
 
-/*
- * enable the MMU. Should be called after mmu_init()
- */
-void mmu_enable(void)
-{
+	/*
+	 * First remap sdram cached using sections.
+	 * This is to speed up the generation of 2nd level page tables
+	 * below
+	 */
+	for_each_sdram_bank(mem)
+		create_section(mem->start, mem->start, mem->size >> 20,
+				PMD_SECT_DEF_CACHED);
+
 	asm volatile (
 		"bl __mmu_cache_on;"
 		:
 		:
 		: "r0", "r1", "r2", "r3", "r6", "r10", "r12", "cc", "memory"
         );
+
+	/*
+	 * Now that we have the MMU and caches on remap sdram again using
+	 * page tables
+	 */
+	for_each_sdram_bank(mem)
+		arm_mmu_remap_sdram(mem);
+
+	return 0;
 }
 
 struct outer_cache_fns outer_cache;
@@ -125,39 +238,41 @@ void mmu_disable(void)
 	);
 }
 
-/*
- * For boards which need coherent memory for DMA. The idea
- * is simple: Setup a uncached section containing your SDRAM
- * and call setup_dma_coherent() with the offset between the
- * cached and the uncached section. dma_alloc_coherent() then
- * works using normal malloc but returns the corresponding
- * pointer in the uncached area.
- */
-static unsigned long dma_coherent_offset;
-
-void setup_dma_coherent(unsigned long offset)
-{
-	dma_coherent_offset = offset;
-}
+#define PAGE_ALIGN(s) ((s) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1);
 
 void *dma_alloc_coherent(size_t size)
 {
-	return xmemalign(4096, size) + dma_coherent_offset;
+	void *ret;
+
+	size = PAGE_ALIGN(size);
+	ret = xmemalign(4096, size);
+
+#ifdef CONFIG_MMU
+	dma_inv_range((unsigned long)ret, (unsigned long)ret + size);
+
+	remap_range(ret, size, 0);
+#endif
+
+	return ret;
 }
 
 unsigned long virt_to_phys(void *virt)
 {
-	return (unsigned long)virt - dma_coherent_offset;
+	return (unsigned long)virt;
 }
 
 void *phys_to_virt(unsigned long phys)
 {
-	return (void *)(phys + dma_coherent_offset);
+	return (void *)phys;
 }
 
 void dma_free_coherent(void *mem, size_t size)
 {
-	free(mem - dma_coherent_offset);
+#ifdef CONFIG_MMU
+	remap_range(mem, size, PTE_BUFFERABLE | PTE_CACHEABLE);
+#endif
+
+	free(mem);
 }
 
 void dma_clean_range(unsigned long start, unsigned long end)
diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index 9ebc2cd..b1aa781 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -3,19 +3,29 @@
 
 #include <asm/pgtable.h>
 #include <malloc.h>
+#include <errno.h>
 
 #define PMD_SECT_DEF_UNCACHED (PMD_SECT_AP_WRITE | PMD_SECT_AP_READ | PMD_TYPE_SECT)
 #define PMD_SECT_DEF_CACHED (PMD_SECT_WB | PMD_SECT_DEF_UNCACHED)
 
-void mmu_init(void);
-void mmu_enable(void);
+struct arm_memory;
+
+static inline void mmu_enable(void)
+{
+}
 void mmu_disable(void);
-void arm_create_section(unsigned long virt, unsigned long phys, int size_m,
-		unsigned int flags);
+static inline void arm_create_section(unsigned long virt, unsigned long phys, int size_m,
+		unsigned int flags)
+{
+}
 
-void setup_dma_coherent(unsigned long offset);
+static inline void setup_dma_coherent(unsigned long offset)
+{
+}
 
 #ifdef CONFIG_MMU
+int mmu_init(void);
+
 void *dma_alloc_coherent(size_t size);
 void dma_free_coherent(void *mem, size_t size);
 
diff --git a/include/common.h b/include/common.h
index f3353c8..0ce4a70 100644
--- a/include/common.h
+++ b/include/common.h
@@ -221,6 +221,7 @@ int run_shell(void);
 #define ULLONG_MAX	(~0ULL)
 
 #define PAGE_SIZE	4096
+#define PAGE_SHIFT	12
 
 int memory_display(char *addr, ulong offs, ulong nbytes, int size);
 
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 9/9 v2] ARM boards: remove now unnecessary mmu calls
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 preceding siblings ...)
  2011-08-01 13:29 ` [PATCH 8/9] ARM: rework MMU support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 13:29 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 15:54 ` rework MMU support Sascha Hauer
  9 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 13:29 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/boards/chumby_falconwing/falconwing.c    |   10 ----
 arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c |   10 ----
 arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |   10 ----
 arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c |   20 +++-----
 arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c |   16 ------
 arch/arm/boards/freescale-mx51-pdk/board.c        |   10 ----
 arch/arm/boards/freescale-mx53-loco/board.c       |   12 -----
 arch/arm/boards/guf-cupid/board.c                 |   20 +++-----
 arch/arm/boards/guf-neso/board.c                  |   10 ----
 arch/arm/boards/karo-tx25/board.c                 |   12 -----
 arch/arm/boards/karo-tx28/tx28.c                  |   10 ----
 arch/arm/boards/panda/board.c                     |    8 ---
 arch/arm/boards/pcm037/pcm037.c                   |   20 +++-----
 arch/arm/boards/pcm038/pcm038.c                   |   10 ----
 arch/arm/boards/pcm043/pcm043.c                   |   21 +++-----
 arch/arm/boards/pcm049/board.c                    |    9 ---
 arch/arm/boards/phycard-i.MX27/pca100.c           |   10 ----
 arch/arm/boards/scb9328/env/config                |   56 +++++++++++++++++++++
 arch/arm/cpu/mmu.c                                |    3 +-
 arch/arm/include/asm/mmu.h                        |    7 ---
 20 files changed, 86 insertions(+), 198 deletions(-)
 create mode 100644 arch/arm/boards/scb9328/env/config

diff --git a/arch/arm/boards/chumby_falconwing/falconwing.c b/arch/arm/boards/chumby_falconwing/falconwing.c
index b20dd74..1c66eb2 100644
--- a/arch/arm/boards/chumby_falconwing/falconwing.c
+++ b/arch/arm/boards/chumby_falconwing/falconwing.c
@@ -265,16 +265,6 @@ static int falconwing_mem_init(void)
 {
 	arm_add_mem_device("ram0", IMX_MEMORY_BASE, 64 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x40000000, 0x40000000, 64, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x50000000, 0x40000000, 64, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(falconwing_mem_init);
diff --git a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
index 5c07597..1c54202 100644
--- a/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
+++ b/arch/arm/boards/eukrea_cpuimx25/eukrea_cpuimx25.c
@@ -160,16 +160,6 @@ static int eukrea_cpuimx25_mem_init(void)
 {
 	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 64 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x90000000, 0x80000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(eukrea_cpuimx25_mem_init);
diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
index ac886fa..a5aadac 100644
--- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
+++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
@@ -92,16 +92,6 @@ static int eukrea_cpuimx27_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0xa0000000, SDRAM0 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0xb0000000, 0xa0000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(eukrea_cpuimx27_mem_init);
diff --git a/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c b/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
index 02df444..426445f 100644
--- a/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
+++ b/arch/arm/boards/eukrea_cpuimx35/eukrea_cpuimx35.c
@@ -130,23 +130,17 @@ static int eukrea_cpuimx35_mem_init(void)
 {
 	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x90000000, 0x80000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
+	return 0;
+}
+mem_initcall(eukrea_cpuimx35_mem_init);
 
-#ifdef CONFIG_CACHE_L2X0
+static int eukrea_cpuimx35_mmu_init(void)
+{
 	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
-#endif
-#endif
+
 	return 0;
 }
-mem_initcall(eukrea_cpuimx35_mem_init);
+postmmu_initcall(eukrea_cpuimx35_mmu_init);
 
 static int eukrea_cpuimx35_devices_init(void)
 {
diff --git a/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c b/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
index b6fce93..727db29 100644
--- a/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
+++ b/arch/arm/boards/eukrea_cpuimx51/eukrea_cpuimx51.c
@@ -97,22 +97,6 @@ static int eukrea_cpuimx51_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0x90000000, 256 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x90000000, 0x90000000, 256, PMD_SECT_DEF_CACHED);
-	arm_create_section(0xa0000000, 0x90000000, 256, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-#if TEXT_BASE & (0x100000 - 1)
-#warning cannot create vector section. Adjust TEXT_BASE to a 1M boundary
-#else
-	arm_create_section(0x0,        TEXT_BASE,   1, PMD_SECT_DEF_UNCACHED);
-#endif
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(eukrea_cpuimx51_mem_init);
diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index f347657..d6472df 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -77,16 +77,6 @@ static int babbage_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0x90000000, 512 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x90000000, 0x90000000, 512, PMD_SECT_DEF_CACHED);
-	arm_create_section(0xb0000000, 0x90000000, 512, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x20000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(babbage_mem_init);
diff --git a/arch/arm/boards/freescale-mx53-loco/board.c b/arch/arm/boards/freescale-mx53-loco/board.c
index 92cff01..b5240f4 100644
--- a/arch/arm/boards/freescale-mx53-loco/board.c
+++ b/arch/arm/boards/freescale-mx53-loco/board.c
@@ -78,18 +78,6 @@ static int loco_mem_init(void)
 	arm_add_mem_device("ram0", 0x70000000, SZ_512M);
 	arm_add_mem_device("ram1", 0xb0000000, SZ_512M);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x70000000, 0x70000000, 512, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x90000000, 0x70000000, 512, PMD_SECT_DEF_UNCACHED);
-	arm_create_section(0xb0000000, 0xb0000000, 512, PMD_SECT_DEF_CACHED);
-	arm_create_section(0xd0000000, 0xb0000000, 512, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x20000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(loco_mem_init);
diff --git a/arch/arm/boards/guf-cupid/board.c b/arch/arm/boards/guf-cupid/board.c
index 134f377..706707d 100644
--- a/arch/arm/boards/guf-cupid/board.c
+++ b/arch/arm/boards/guf-cupid/board.c
@@ -100,23 +100,17 @@ static int cupid_mem_init(void)
 {
 	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x90000000, 0x80000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
+	return 0;
+}
+mem_initcall(cupid_mem_init);
 
-#ifdef CONFIG_CACHE_L2X0
+static int cupid_mmu_init(void)
+{
 	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
-#endif
-#endif
+
 	return 0;
 }
-mem_initcall(cupid_mem_init);
+postmmu_initcall(cupid_mmu_init);
 
 static int cupid_devices_init(void)
 {
diff --git a/arch/arm/boards/guf-neso/board.c b/arch/arm/boards/guf-neso/board.c
index 3517a5d..446b333 100644
--- a/arch/arm/boards/guf-neso/board.c
+++ b/arch/arm/boards/guf-neso/board.c
@@ -140,16 +140,6 @@ static int neso_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0xb0000000, 0xa0000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(neso_mem_init);
diff --git a/arch/arm/boards/karo-tx25/board.c b/arch/arm/boards/karo-tx25/board.c
index a01fa3c..22bc27a 100644
--- a/arch/arm/boards/karo-tx25/board.c
+++ b/arch/arm/boards/karo-tx25/board.c
@@ -59,18 +59,6 @@ static int tx25_mem_init(void)
 	add_mem_device("ram0", 0x78000000, 128 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 32, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x82000000, 0x80000000, 32, PMD_SECT_DEF_UNCACHED);
-	arm_create_section(0x90000000, 0x90000000, 32, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x92000000, 0x90000000, 32, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x02000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(tx25_mem_init);
diff --git a/arch/arm/boards/karo-tx28/tx28.c b/arch/arm/boards/karo-tx28/tx28.c
index d6e3f9c..def388a 100644
--- a/arch/arm/boards/karo-tx28/tx28.c
+++ b/arch/arm/boards/karo-tx28/tx28.c
@@ -74,16 +74,6 @@ static int tx28_mem_init(void)
 {
 	arm_add_mem_device("ram0", IMX_MEMORY_BASE, 128 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x40000000, 0x40000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x50000000, 0x40000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(tx28_mem_init);
diff --git a/arch/arm/boards/panda/board.c b/arch/arm/boards/panda/board.c
index 696d44a..1303c47 100644
--- a/arch/arm/boards/panda/board.c
+++ b/arch/arm/boards/panda/board.c
@@ -48,14 +48,6 @@ static int panda_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0x80000000, SZ_1G);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 256, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x90000000, 0x80000000, 256, PMD_SECT_DEF_UNCACHED);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(panda_mem_init);
diff --git a/arch/arm/boards/pcm037/pcm037.c b/arch/arm/boards/pcm037/pcm037.c
index a026f23..85f004f 100644
--- a/arch/arm/boards/pcm037/pcm037.c
+++ b/arch/arm/boards/pcm037/pcm037.c
@@ -153,23 +153,17 @@ static int pcm037_mem_init(void)
 	arm_add_mem_device("ram1", IMX_SDRAM_CS1, SDRAM1 * 1024 * 1024);
 #endif
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x90000000, 0x80000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
+	return 0;
+}
+mem_initcall(pcm037_mem_init);
 
-#ifdef CONFIG_CACHE_L2X0
+static int pcm037_mmu_init(void)
+{
 	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
-#endif
-#endif
+
 	return 0;
 }
-mem_initcall(pcm037_mem_init);
+postmmu_initcall(pcm037_mmu_init);
 
 static int imx31_devices_init(void)
 {
diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 9588b9b..4db50fe 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -135,16 +135,6 @@ static int pcm038_mem_init(void)
 
 	add_mem_device("ram0", 0xc8000000, 512 * 1024, /* Can be up to 2MiB */
 				   IORESOURCE_MEM_WRITEABLE);
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0xb0000000, 0xa0000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(pcm038_mem_init);
diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index 10d319f..966899a 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -103,24 +103,17 @@ static int pcm043_mem_init(void)
 {
 	arm_add_mem_device("ram0", IMX_SDRAM_CS0, 128 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0x90000000, 0x80000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-
-#ifdef CONFIG_CACHE_L2X0
-	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
-#endif
-#endif
 	return 0;
 }
 mem_initcall(pcm043_mem_init);
 
+static int pcm043_mmu_init(void)
+{
+	l2x0_init((void __iomem *)0x30000000, 0x00030024, 0x00000000);
+
+	return 0;
+}
+postmmu_initcall(pcm043_mmu_init);
 
 struct gpio_led led0 = {
 	.gpio = 1 * 32 + 6,
diff --git a/arch/arm/boards/pcm049/board.c b/arch/arm/boards/pcm049/board.c
index 83eb9be..502e121 100644
--- a/arch/arm/boards/pcm049/board.c
+++ b/arch/arm/boards/pcm049/board.c
@@ -60,15 +60,6 @@ static int pcm049_mem_init(void)
 
 	add_mem_device("sram0", 0x40300000, 48 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0x80000000, 0x80000000, 256, PMD_SECT_DEF_CACHED);
-	/* warning: This shadows the second half of our ram */
-	arm_create_section(0x90000000, 0x80000000, 256, PMD_SECT_DEF_UNCACHED);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(pcm049_mem_init);
diff --git a/arch/arm/boards/phycard-i.MX27/pca100.c b/arch/arm/boards/phycard-i.MX27/pca100.c
index 3c2a0e4..f285466 100644
--- a/arch/arm/boards/phycard-i.MX27/pca100.c
+++ b/arch/arm/boards/phycard-i.MX27/pca100.c
@@ -73,16 +73,6 @@ static int pca100_mem_init(void)
 {
 	arm_add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024);
 
-#ifdef CONFIG_MMU
-	mmu_init();
-
-	arm_create_section(0xa0000000, 0xa0000000, 128, PMD_SECT_DEF_CACHED);
-	arm_create_section(0xb0000000, 0xa0000000, 128, PMD_SECT_DEF_UNCACHED);
-
-	setup_dma_coherent(0x10000000);
-
-	mmu_enable();
-#endif
 	return 0;
 }
 mem_initcall(pca100_mem_init);
diff --git a/arch/arm/boards/scb9328/env/config b/arch/arm/boards/scb9328/env/config
new file mode 100644
index 0000000..d0f3f25
--- /dev/null
+++ b/arch/arm/boards/scb9328/env/config
@@ -0,0 +1,56 @@
+#!/bin/sh
+
+machine=scb9328
+eth0.serverip=
+user=
+
+# use 'dhcp' to do dhcp in barebox and in kernel
+# use 'none' if you want to skip kernel ip autoconfiguration
+ip=dhcp
+
+# or set your networking parameters here
+#eth0.ipaddr=a.b.c.d
+#eth0.netmask=a.b.c.d
+#eth0.gateway=a.b.c.d
+#eth0.serverip=a.b.c.d
+
+# can be either 'net', 'nor' or 'nand'
+kernel_loc=net
+# can be either 'net', 'nor', 'nand' or 'initrd'
+rootfs_loc=net
+
+# can be either 'jffs2' or 'ubifs'
+rootfs_type=ubifs
+rootfsimage=root-$machine.$rootfs_type
+
+# The image type of the kernel. Can be uimage, zimage, raw, or raw_lzo
+kernelimage_type=zimage
+kernelimage=zImage-$machine
+#kernelimage_type=uimage
+#kernelimage=uImage-$machine
+#kernelimage_type=raw
+#kernelimage=Image-$machine
+#kernelimage_type=raw_lzo
+#kernelimage=Image-$machine.lzo
+
+if [ -n $user ]; then
+	kernelimage="$user"-"$kernelimage"
+	nfsroot="$eth0.serverip:/home/$user/nfsroot/$machine"
+	rootfsimage="$user"-"$rootfsimage"
+else
+	nfsroot="$eth0.serverip:/path/to/nfs/root"
+fi
+
+autoboot_timeout=3
+
+bootargs="console=ttymxc0,115200"
+
+nor_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nor=3
+
+nand_parts="256k(barebox)ro,128k(bareboxenv),2M(kernel),-(root)"
+rootfs_mtdblock_nand=7
+
+# set a fancy prompt (if support is compiled in)
+PS1="\e[1;32mbarebox@\e[1;31m\h:\w\e[0m "
+
diff --git a/arch/arm/cpu/mmu.c b/arch/arm/cpu/mmu.c
index 53ba51a..ad63358 100644
--- a/arch/arm/cpu/mmu.c
+++ b/arch/arm/cpu/mmu.c
@@ -170,7 +170,7 @@ static void vectors_init(void)
 /*
  * Prepare MMU for usage enable it.
  */
-int mmu_init(void)
+static int mmu_init(void)
 {
 	struct arm_memory *mem;
 	int i;
@@ -217,6 +217,7 @@ int mmu_init(void)
 
 	return 0;
 }
+mmu_initcall(mmu_init);
 
 struct outer_cache_fns outer_cache;
 
diff --git a/arch/arm/include/asm/mmu.h b/arch/arm/include/asm/mmu.h
index b1aa781..9ca5e2a 100644
--- a/arch/arm/include/asm/mmu.h
+++ b/arch/arm/include/asm/mmu.h
@@ -24,8 +24,6 @@ static inline void setup_dma_coherent(unsigned long offset)
 }
 
 #ifdef CONFIG_MMU
-int mmu_init(void);
-
 void *dma_alloc_coherent(size_t size);
 void dma_free_coherent(void *mem, size_t size);
 
@@ -36,11 +34,6 @@ unsigned long virt_to_phys(void *virt);
 void *phys_to_virt(unsigned long phys);
 
 #else
-static inline int mmu_init(void)
-{
-	return -EINVAL;
-}
-
 static inline void *dma_alloc_coherent(size_t size)
 {
 	return xmemalign(4096, size);
-- 
1.7.5.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: rework MMU support
  2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 preceding siblings ...)
  2011-08-01 13:29 ` [PATCH 9/9 v2] ARM boards: remove now unnecessary mmu calls Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 15:54 ` Sascha Hauer
  2011-08-01 16:12   ` Jean-Christophe PLAGNIOL-VILLARD
  9 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2011-08-01 15:54 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Aug 01, 2011 at 03:26:43PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Hi,
> 
> 	This series reworks the barebox MMU support. We now use second
> 	level page tables which allows us to remap the dma coherent area
> 	dynamically. We don't have to map our sdram twice anymore which
> 	helps us on newer systems with big memory.
> 
> 	As a bonus there is no board specific MMU code anymore. All a board
> 	has to do to enable MMU support via Kconfig is to register its SDRAM banks
> 	at mem_initcall
> 
> The following changes since commit b821d73607cc6387b1ee588af97a44e8eb2b4fe2:
> 
>   Merge branch 'resource' of git://uboot.jcrosoft.org/barebox into next (2011-08-01 14:10:38 +0200)
> 
> are available in the git repository at:
> 
>   git://uboot.jcrosoft.org/barebox.git mmu
> 
> Jean-Christophe PLAGNIOL-VILLARD (2):
>       arm: introduce arm_add_mem_device to register dram device
>       init: introduce mem, mmu and postmmu initcall
> 
> Sascha Hauer (7):
>       ARM cache l2x0: depend on MMU
>       ARM: move armlinux_add_dram to location which is always compiled
>       ARM l2x0: make init function static inline if l2 is not available
>       ARM: pass size to dma_free_coherent
>       ARM boards: move sdram setup before mmu setup
>       ARM: rework MMU support
>       ARM boards: remove now unnecessary mmu calls

merged up to 7/9. The MMU rework needs some changes to v1 which I
haven't posted yet. It does not work correctly on armv7 as these
processors need slightly different second level page table entries.

Also, I added the appropriate KEEP directives to
include/asm-generic/barebox.lds.h to make this branch work. Would be
good if you could give your patches at least *some* testing.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: rework MMU support
  2011-08-01 15:54 ` rework MMU support Sascha Hauer
@ 2011-08-01 16:12   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-08-01 16:32     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 16:12 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 17:54 Mon 01 Aug     , Sascha Hauer wrote:
> On Mon, Aug 01, 2011 at 03:26:43PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > Hi,
> > 
> > 	This series reworks the barebox MMU support. We now use second
> > 	level page tables which allows us to remap the dma coherent area
> > 	dynamically. We don't have to map our sdram twice anymore which
> > 	helps us on newer systems with big memory.
> > 
> > 	As a bonus there is no board specific MMU code anymore. All a board
> > 	has to do to enable MMU support via Kconfig is to register its SDRAM banks
> > 	at mem_initcall
> > 
> > The following changes since commit b821d73607cc6387b1ee588af97a44e8eb2b4fe2:
> > 
> >   Merge branch 'resource' of git://uboot.jcrosoft.org/barebox into next (2011-08-01 14:10:38 +0200)
> > 
> > are available in the git repository at:
> > 
> >   git://uboot.jcrosoft.org/barebox.git mmu
> > 
> > Jean-Christophe PLAGNIOL-VILLARD (2):
> >       arm: introduce arm_add_mem_device to register dram device
> >       init: introduce mem, mmu and postmmu initcall
> > 
> > Sascha Hauer (7):
> >       ARM cache l2x0: depend on MMU
> >       ARM: move armlinux_add_dram to location which is always compiled
> >       ARM l2x0: make init function static inline if l2 is not available
> >       ARM: pass size to dma_free_coherent
> >       ARM boards: move sdram setup before mmu setup
> >       ARM: rework MMU support
> >       ARM boards: remove now unnecessary mmu calls
> 
> merged up to 7/9. The MMU rework needs some changes to v1 which I
> haven't posted yet. It does not work correctly on armv7 as these
> processors need slightly different second level page table entries.
> 
> Also, I added the appropriate KEEP directives to
> include/asm-generic/barebox.lds.h to make this branch work. Would be
> good if you could give your patches at least *some* testing.
I've no armv7 availlable work fine

I test it on at91 and s3c and versatile work fine

but no mmu yet
 and I compiled all ARM

 Best Regards,
 J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: rework MMU support
  2011-08-01 16:12   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-08-01 16:32     ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 13+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-08-01 16:32 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 18:12 Mon 01 Aug     , Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 17:54 Mon 01 Aug     , Sascha Hauer wrote:
> > On Mon, Aug 01, 2011 at 03:26:43PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > > Hi,
> > > 
> > > 	This series reworks the barebox MMU support. We now use second
> > > 	level page tables which allows us to remap the dma coherent area
> > > 	dynamically. We don't have to map our sdram twice anymore which
> > > 	helps us on newer systems with big memory.
> > > 
> > > 	As a bonus there is no board specific MMU code anymore. All a board
> > > 	has to do to enable MMU support via Kconfig is to register its SDRAM banks
> > > 	at mem_initcall
> > > 
> > > The following changes since commit b821d73607cc6387b1ee588af97a44e8eb2b4fe2:
> > > 
> > >   Merge branch 'resource' of git://uboot.jcrosoft.org/barebox into next (2011-08-01 14:10:38 +0200)
> > > 
> > > are available in the git repository at:
> > > 
> > >   git://uboot.jcrosoft.org/barebox.git mmu
> > > 
> > > Jean-Christophe PLAGNIOL-VILLARD (2):
> > >       arm: introduce arm_add_mem_device to register dram device
> > >       init: introduce mem, mmu and postmmu initcall
> > > 
> > > Sascha Hauer (7):
> > >       ARM cache l2x0: depend on MMU
> > >       ARM: move armlinux_add_dram to location which is always compiled
> > >       ARM l2x0: make init function static inline if l2 is not available
> > >       ARM: pass size to dma_free_coherent
> > >       ARM boards: move sdram setup before mmu setup
> > >       ARM: rework MMU support
> > >       ARM boards: remove now unnecessary mmu calls
> > 
> > merged up to 7/9. The MMU rework needs some changes to v1 which I
> > haven't posted yet. It does not work correctly on armv7 as these
> > processors need slightly different second level page table entries.
> > 
> > Also, I added the appropriate KEEP directives to
> > include/asm-generic/barebox.lds.h to make this branch work. Would be
> > good if you could give your patches at least *some* testing.
> I've no armv7 availlable work fine
> 
> I test it on at91 and s3c and versatile work fine
> 
> but no mmu yet
>  and I compiled all ARM
> 
did'nt see the missing KEEP as I'm working on a really small version of
barebox with nothing inside to go done to less than 26K

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2011-08-01 16:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-01 13:26 rework MMU support Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 1/9 v2] arm: introduce arm_add_mem_device to register dram device Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 2/9] ARM cache l2x0: depend on MMU Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 3/9] ARM: move armlinux_add_dram to location which is always compiled Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 4/9] ARM l2x0: make init function static inline if l2 is not available Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 5/9] ARM: pass size to dma_free_coherent Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 6/9] init: introduce mem, mmu and postmmu initcall Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 7/9 v2] ARM boards: move sdram setup before mmu setup Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 8/9] ARM: rework MMU support Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 13:29 ` [PATCH 9/9 v2] ARM boards: remove now unnecessary mmu calls Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 15:54 ` rework MMU support Sascha Hauer
2011-08-01 16:12   ` Jean-Christophe PLAGNIOL-VILLARD
2011-08-01 16:32     ` Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox