Skip to contentSkip to conversation

linux/sizes.h: sync from kernel

PATCH Superseded Baruch Siach 2 participants 5 messages Oct 28, 2018 – Nov 5, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 linux/sizes.h: sync from kernel

The kernel added SZ_4G macro in commit f2b9ba871b (arm64/kernel: kaslr:
reduce module randomization range to 4 GB).

Include common.h for _AC() instead of the kernel linux/const.h header.

Drop a local SZ_4G definition in tegra code.

---
 arch/arm/mach-tegra/tegra186/nvtboot_mem.c | 3 +--
 include/linux/sizes.h                      | 4 ++++
 2 files changed, 5 insertions(+), 2 deletions(-)
arch/arm/mach-tegra/tegra186/nvtboot_mem.c +1 -2
index 5c9467bfe8be..62142821a595 100644
@@ -6,11 +6,10 @@
 #include <common.h>
 #include <fdt_support.h>
 #include <fdtdec.h>
+#include <linux/sizes.h>
 #include <asm/arch/tegra.h>
 #include <asm/armv8/mmu.h>
 
-#define SZ_4G 0x100000000ULL
-
 /*
  * Size of a region that's large enough to hold the relocated U-Boot and all
  * other allocations made around it (stack, heap, page tables, etc.)
include/linux/sizes.h +4 -0
index ce3e8150c174..9f3c13ee459b 100644
@@ -8,6 +8,8 @@
 #ifndef __LINUX_SIZES_H__
 #define __LINUX_SIZES_H__
 
+#include <common.h>
+
 #define SZ_1				0x00000001
 #define SZ_2				0x00000002
 #define SZ_4				0x00000004
@@ -44,4 +46,6 @@
 #define SZ_1G				0x40000000
 #define SZ_2G				0x80000000
 
+#define SZ_4G				_AC(0x100000000, ULL)
+
 #endif /* __LINUX_SIZES_H__ */
Signature · 1 line
2.19.1
#1 lore raw

PATCH 2/2 arm64: mvebu: a8k: autodetect RAM size

Some Armada 8K boards like Macchiatobin and Clearfog GT-8K use RAM from external DIMM. Hard coding the RAM size in the device-tree is not convenient. Fortunately, the ATF that initializes the RAM knows the size of RAM, and U-Boot can query the ATF using a SMC call.

This code in this commit is mostly taken from downstream Marvell U-Boot code by Grzegorz Jaszczyk.

CONFIG_NR_DRAM_BANKS must be set to 2 to use more than 3GB RAM.

Cc Grzegorz Jaszczyk <[email protected]>
---
 arch/arm/mach-mvebu/arm64-common.c | 47 +++++++++++++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/arm64-common.c +46 -1
index f47273fde9c6..7ba7301c7a8c 100644
@@ -7,6 +7,7 @@
 #include <dm.h>
 #include <fdtdec.h>
 #include <linux/libfdt.h>
+#include <linux/sizes.h>
 #include <pci.h>
 #include <asm/io.h>
 #include <asm/system.h>
@@ -45,15 +46,59 @@ const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
 
 /* DRAM init code ... */
 
+#define MV_SIP_DRAM_SIZE	0x82000010
+
+static u64 a8k_dram_scan_ap_sz(void)
+{
+	struct pt_regs pregs;
+
+	pregs.regs[0] = MV_SIP_DRAM_SIZE;
+	pregs.regs[1] = SOC_REGS_PHY_BASE;
+	smc_call(&pregs);
+
+	return pregs.regs[0];
+}
+
+static void a8k_dram_init_banksize(void)
+{
+	/*
+	 * Config 2 DRAM banks:
+	 * Bank 0 - max size 4G - 1G
+	 * Bank 1 - ram size - 4G + 1G
+	 */
+	phys_size_t max_bank0_size = SZ_4G - SZ_1G;
+
+	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
+	if (gd->ram_size <= max_bank0_size) {
+		gd->bd->bi_dram[0].size = gd->ram_size;
+		return;
+	}
+
+	gd->bd->bi_dram[0].size = max_bank0_size;
+	if (CONFIG_NR_DRAM_BANKS > 1) {
+		gd->bd->bi_dram[1].start = SZ_4G;
+		gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
+	}
+}
+
 int dram_init_banksize(void)
 {
-	fdtdec_setup_memory_banksize();
+	if (CONFIG_IS_ENABLED(ARMADA_8K))
+		a8k_dram_init_banksize();
+	else
+		fdtdec_setup_memory_banksize();
 
 	return 0;
 }
 
 int dram_init(void)
 {
+	if (CONFIG_IS_ENABLED(ARMADA_8K)) {
+		gd->ram_size = a8k_dram_scan_ap_sz();
+		if (gd->ram_size != 0)
+			return 0;
+	}
+
 	if (fdtdec_setup_mem_size_base() != 0)
 		return -EINVAL;
 
Signature · 1 line
2.19.1
#2 lore raw

PATCH 2/2 arm64: mvebu: a8k: autodetect RAM size

Quoted 55 lines · Baruch Siach

Some Armada 8K boards like Macchiatobin and Clearfog GT-8K use RAM from external DIMM. Hard coding the RAM size in the device-tree is not convenient. Fortunately, the ATF that initializes the RAM knows the size of RAM, and U-Boot can query the ATF using a SMC call.

This code in this commit is mostly taken from downstream Marvell U-Boot code by Grzegorz Jaszczyk.

CONFIG_NR_DRAM_BANKS must be set to 2 to use more than 3GB RAM.

Cc Grzegorz Jaszczyk <[email protected]>
---
  arch/arm/mach-mvebu/arm64-common.c | 47 +++++++++++++++++++++++++++++-
  1 file changed, 46 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/arm64-common.c +24 -0
index f47273fde9c6..7ba7301c7a8c 100644
@@ -7,6 +7,7 @@
  #include <dm.h>
  #include <fdtdec.h>
  #include <linux/libfdt.h>
+#include <linux/sizes.h>
  #include <pci.h>
  #include <asm/io.h>
  #include <asm/system.h>
@@ -45,15 +46,59 @@ const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
 
  /* DRAM init code ... */
 
+#define MV_SIP_DRAM_SIZE	0x82000010
+
+static u64 a8k_dram_scan_ap_sz(void)
+{
+	struct pt_regs pregs;
+
+	pregs.regs[0] = MV_SIP_DRAM_SIZE;
+	pregs.regs[1] = SOC_REGS_PHY_BASE;
+	smc_call(&pregs);
+
+	return pregs.regs[0];
+}
+
+static void a8k_dram_init_banksize(void)
+{
+	/*
+	 * Config 2 DRAM banks:
+	 * Bank 0 - max size 4G - 1G
+	 * Bank 1 - ram size - 4G + 1G
+	 */
+	phys_size_t max_bank0_size = SZ_4G - SZ_1G;
+
+	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;

arch/arm/mach-mvebu/arm64-common.c const struct mbus_dram_target_info *mvebu_mbus_dram_info(void) · line 81

Quoted 10 lines
arch/arm/mach-mvebu/arm64-common.c +10 -0
+	if (gd->ram_size <= max_bank0_size) {
+		gd->bd->bi_dram[0].size = gd->ram_size;
+		return;
+	}
+
+	gd->bd->bi_dram[0].size = max_bank0_size;
+	if (CONFIG_NR_DRAM_BANKS > 1) {
+		gd->bd->bi_dram[1].start = SZ_4G;
+		gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
+	}

Is CONFIG_NR_DRAM_BANKS > 2 possible on one of these platforms?

Also I find the splitting of the available RAM size (detected via ATF) onto the multiple banks not intuitive. Could you please explain the 1GiB hole in the bi_dram[x] struct? I suspect that this might have something to do with the internal register address space. But I fail to see, if this should be reflected in these bi_dram[x] values.

Thanks,
Stefan

#3 lore raw

PATCH 2/2 arm64: mvebu: a8k: autodetect RAM size

Hi Stefan,

Quoted 58 lines · Stefan Roese
Quoted 57 lines · Baruch Siach

Some Armada 8K boards like Macchiatobin and Clearfog GT-8K use RAM from external DIMM. Hard coding the RAM size in the device-tree is not convenient. Fortunately, the ATF that initializes the RAM knows the size of RAM, and U-Boot can query the ATF using a SMC call.

This code in this commit is mostly taken from downstream Marvell U-Boot code by Grzegorz Jaszczyk.

CONFIG_NR_DRAM_BANKS must be set to 2 to use more than 3GB RAM.

Cc Grzegorz Jaszczyk <[email protected]>
---
  arch/arm/mach-mvebu/arm64-common.c | 47 +++++++++++++++++++++++++++++-
  1 file changed, 46 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/arm64-common.c +28 -0
index f47273fde9c6..7ba7301c7a8c 100644
@@ -7,6 +7,7 @@
  #include <dm.h>
  #include <fdtdec.h>
  #include <linux/libfdt.h>
+#include <linux/sizes.h>
  #include <pci.h>
  #include <asm/io.h>
  #include <asm/system.h>
@@ -45,15 +46,59 @@ const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
  /* DRAM init code ... */
+#define MV_SIP_DRAM_SIZE	0x82000010
+
+static u64 a8k_dram_scan_ap_sz(void)
+{
+	struct pt_regs pregs;
+
+	pregs.regs[0] = MV_SIP_DRAM_SIZE;
+	pregs.regs[1] = SOC_REGS_PHY_BASE;
+	smc_call(&pregs);
+
+	return pregs.regs[0];
+}
+
+static void a8k_dram_init_banksize(void)
+{
+	/*
+	 * Config 2 DRAM banks:
+	 * Bank 0 - max size 4G - 1G
+	 * Bank 1 - ram size - 4G + 1G
+	 */
+	phys_size_t max_bank0_size = SZ_4G - SZ_1G;
+
+	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
+	if (gd->ram_size <= max_bank0_size) {
+		gd->bd->bi_dram[0].size = gd->ram_size;
+		return;
+	}
Quoted 8 lines

arch/arm/mach-mvebu/arm64-common.c const struct mbus_dram_target_info *mvebu_mbus_dram_info(void) · line 81

Quoted 6 lines
arch/arm/mach-mvebu/arm64-common.c +6 -0
+
+	gd->bd->bi_dram[0].size = max_bank0_size;
+	if (CONFIG_NR_DRAM_BANKS > 1) {
+		gd->bd->bi_dram[1].start = SZ_4G;
+		gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
+	}

Is CONFIG_NR_DRAM_BANKS > 2 possible on one of these platforms?

I tested with a 16GB SO-DIMM on Clearfog GT-8K. Before this change only 2GB were visible to Linux. With this change, and with CONFIG_NR_DRAM_BANKS=2, I am able to lock 15.5GB of RAM for write/read using the memtester utility.

I didn't test on Macchaitobin because I don't have a >3GB DIMM handy.

Quoted 5 lines

Also I find the splitting of the available RAM size (detected via ATF) onto the multiple banks not intuitive. Could you please explain the 1GiB hole in the bi_dram[x] struct? I suspect that this might have something to do with the internal register address space. But I fail to see, if this should be reflected in these bi_dram[x] values.

As I understand, that is how the ATF code configures the hardware address space. Peripheral devices registers are in the 0xFxxxxxxx area, as you can see in the Armada 8040 components .dtsi.

Is there any other way to transfer this information to the kernel?

baruch

Signature · 3 lines
     http://baruch.siach.name/blog/                  ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#4 lore raw

PATCH 2/2 arm64: mvebu: a8k: autodetect RAM size

Hi Baruch,

Quoted 82 lines · Baruch Siach

Hi Stefan,

Quoted 58 lines · Stefan Roese
Quoted 57 lines · Baruch Siach

Some Armada 8K boards like Macchiatobin and Clearfog GT-8K use RAM from external DIMM. Hard coding the RAM size in the device-tree is not convenient. Fortunately, the ATF that initializes the RAM knows the size of RAM, and U-Boot can query the ATF using a SMC call.

This code in this commit is mostly taken from downstream Marvell U-Boot code by Grzegorz Jaszczyk.

CONFIG_NR_DRAM_BANKS must be set to 2 to use more than 3GB RAM.

Cc Grzegorz Jaszczyk <[email protected]>
---
   arch/arm/mach-mvebu/arm64-common.c | 47 +++++++++++++++++++++++++++++-
   1 file changed, 46 insertions(+), 1 deletion(-)
arch/arm/mach-mvebu/arm64-common.c +28 -0
index f47273fde9c6..7ba7301c7a8c 100644
@@ -7,6 +7,7 @@
   #include <dm.h>
   #include <fdtdec.h>
   #include <linux/libfdt.h>
+#include <linux/sizes.h>
   #include <pci.h>
   #include <asm/io.h>
   #include <asm/system.h>
@@ -45,15 +46,59 @@ const struct mbus_dram_target_info *mvebu_mbus_dram_info(void)
   /* DRAM init code ... */
+#define MV_SIP_DRAM_SIZE	0x82000010
+
+static u64 a8k_dram_scan_ap_sz(void)
+{
+	struct pt_regs pregs;
+
+	pregs.regs[0] = MV_SIP_DRAM_SIZE;
+	pregs.regs[1] = SOC_REGS_PHY_BASE;
+	smc_call(&pregs);
+
+	return pregs.regs[0];
+}
+
+static void a8k_dram_init_banksize(void)
+{
+	/*
+	 * Config 2 DRAM banks:
+	 * Bank 0 - max size 4G - 1G
+	 * Bank 1 - ram size - 4G + 1G
+	 */
+	phys_size_t max_bank0_size = SZ_4G - SZ_1G;
+
+	gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
+	if (gd->ram_size <= max_bank0_size) {
+		gd->bd->bi_dram[0].size = gd->ram_size;
+		return;
+	}
Quoted 8 lines

arch/arm/mach-mvebu/arm64-common.c const struct mbus_dram_target_info *mvebu_mbus_dram_info(void) · line 81

Quoted 6 lines
arch/arm/mach-mvebu/arm64-common.c +6 -0
+
+	gd->bd->bi_dram[0].size = max_bank0_size;
+	if (CONFIG_NR_DRAM_BANKS > 1) {
+		gd->bd->bi_dram[1].start = SZ_4G;
+		gd->bd->bi_dram[1].size = gd->ram_size - max_bank0_size;
+	}

Is CONFIG_NR_DRAM_BANKS > 2 possible on one of these platforms?

I tested with a 16GB SO-DIMM on Clearfog GT-8K. Before this change only 2GB were visible to Linux. With this change, and with CONFIG_NR_DRAM_BANKS=2, I am able to lock 15.5GB of RAM for write/read using the memtester utility.

I didn't test on Macchaitobin because I don't have a >3GB DIMM handy.

Quoted 5 lines

Also I find the splitting of the available RAM size (detected via ATF) onto the multiple banks not intuitive. Could you please explain the 1GiB hole in the bi_dram[x] struct? I suspect that this might have something to do with the internal register address space. But I fail to see, if this should be reflected in these bi_dram[x] values.

Quoted 5 lines

As I understand, that is how the ATF code configures the hardware address space. Peripheral devices registers are in the 0xFxxxxxxx area, as you can see in the Armada 8040 components .dtsi.

Is there any other way to transfer this information to the kernel?

It seems that I was wrong with my assumption that the DT blob fixup in U-Boot is made on the base of gd->ram_size. The changes to bi_dram[] are necessary for this DT fixup.

It would be great though, if you could add a comment mentioning the reason for the necessary gap in the memory layout in the commit text and the comment in the code though.

Thanks,
Stefan