[U-Boot] [PATCH v4 1/5] linux/const.h: import from kernel

Combine the uapi/linux/const.h header into the kernel linux/const.h. The next commit will use the _AC macro this header instead of the common.h definition.
Based on Linux kernel version 4.19.
Signed-off-by: Baruch Siach baruch@tkos.co.il --- v4: Mention kernel version in commit log
v3: New patch in this series --- include/linux/const.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 include/linux/const.h
diff --git a/include/linux/const.h b/include/linux/const.h new file mode 100644 index 000000000000..379c88923269 --- /dev/null +++ b/include/linux/const.h @@ -0,0 +1,34 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _LINUX_CONST_H +#define _LINUX_CONST_H + +/* const.h: Macros for dealing with constants. */ + +/* Some constant macros are used in both assembler and + * C code. Therefore we cannot annotate them always with + * 'UL' and other type specifiers unilaterally. We + * use the following macros to deal with this. + * + * Similarly, _AT() will cast an expression with a type in C, but + * leave it unchanged in asm. + */ + +#ifdef __ASSEMBLY__ +#define _AC(X,Y) X +#define _AT(T,X) X +#else +#define __AC(X,Y) (X##Y) +#define _AC(X,Y) __AC(X,Y) +#define _AT(T,X) ((T)(X)) +#endif + +#define _UL(x) (_AC(x, UL)) +#define _ULL(x) (_AC(x, ULL)) + +#define _BITUL(x) (_UL(1) << (x)) +#define _BITULL(x) (_ULL(1) << (x)) + +#define UL(x) (_UL(x)) +#define ULL(x) (_ULL(x)) + +#endif /* _LINUX_CONST_H */

Drop the _AC and UL macros from common.h. Linux headers is the original source of this macro, so keep its definition in the same header.
Update existing users of these macros to include const.h directly.
Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Rick Chen rick@andestech.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Rick Chen rick@andestech.com Signed-off-by: Baruch Siach baruch@tkos.co.il --- v4: Squash the spaces.h change in to this commit
v3: New patch in this series --- arch/arm/include/asm/armv8/mmu.h | 2 ++ arch/mips/include/asm/mach-generic/spaces.h | 2 +- arch/riscv/include/asm/csr.h | 2 ++ include/common.h | 9 --------- 4 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/arch/arm/include/asm/armv8/mmu.h b/arch/arm/include/asm/armv8/mmu.h index 62d00d15c26d..4a573208dfd0 100644 --- a/arch/arm/include/asm/armv8/mmu.h +++ b/arch/arm/include/asm/armv8/mmu.h @@ -7,6 +7,8 @@ #ifndef _ASM_ARMV8_MMU_H_ #define _ASM_ARMV8_MMU_H_
+#include <linux/const.h> + /* * block/section address mask and size definitions. */ diff --git a/arch/mips/include/asm/mach-generic/spaces.h b/arch/mips/include/asm/mach-generic/spaces.h index b7eac323cd67..539d0a566d52 100644 --- a/arch/mips/include/asm/mach-generic/spaces.h +++ b/arch/mips/include/asm/mach-generic/spaces.h @@ -7,7 +7,7 @@ #ifndef _ASM_MACH_GENERIC_SPACES_H #define _ASM_MACH_GENERIC_SPACES_H
-#include <asm/const.h> +#include <linux/const.h>
/* * This gives the physical RAM offset. diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index 50fccea5c8f9..29624fdbb555 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -8,6 +8,8 @@ #ifndef _ASM_RISCV_CSR_H #define _ASM_RISCV_CSR_H
+#include <linux/const.h> + /* Status register flags */ #define SR_SIE _AC(0x00000002, UL) /* Supervisor Interrupt Enable */ #define SR_SPIE _AC(0x00000020, UL) /* Previous Supervisor IE */ diff --git a/include/common.h b/include/common.h index 83b3bdc58dfa..f3c1de9f1fa2 100644 --- a/include/common.h +++ b/include/common.h @@ -14,9 +14,6 @@ typedef volatile unsigned long vu_long; typedef volatile unsigned short vu_short; typedef volatile unsigned char vu_char;
-/* Allow sharing constants with type modifiers between C and assembly. */ -#define _AC(X, Y) (X##Y) - #include <config.h> #include <errno.h> #include <time.h> @@ -542,16 +539,10 @@ int cpu_release(u32 nr, int argc, char * const argv[]);
#else /* __ASSEMBLY__ */
-/* Drop a C type modifier (like in 3UL) for constants used in assembly. */ -#define _AC(X, Y) X - #endif /* __ASSEMBLY__ */
/* Put only stuff here that the assembler can digest */
-/* Declare an unsigned long constant digestable both by C and an assembler. */ -#define UL(x) _AC(x, UL) - #ifdef CONFIG_POST #define CONFIG_HAS_POST #ifndef CONFIG_POST_ALT_LIST

Am So., 11. Nov. 2018 um 11:33 Uhr schrieb Baruch Siach baruch@tkos.co.il:
Drop the _AC and UL macros from common.h. Linux headers is the original source of this macro, so keep its definition in the same header.
Update existing users of these macros to include const.h directly.
Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Cc: Rick Chen rick@andestech.com Reviewed-by: Tom Rini trini@konsulko.com Reviewed-by: Rick Chen rick@andestech.com Signed-off-by: Baruch Siach baruch@tkos.co.il
v4: Squash the spaces.h change in to this commit
v3: New patch in this series
arch/arm/include/asm/armv8/mmu.h | 2 ++ arch/mips/include/asm/mach-generic/spaces.h | 2 +- arch/riscv/include/asm/csr.h | 2 ++ include/common.h | 9 --------- 4 files changed, 5 insertions(+), 10 deletions(-)
Reviewed-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com

Commit 86f21c96f467368 (mips: Use common _AC macro now.) removed the _AC definition from const.h. All other macros defined in const.h are not used anywhere, and there is now no user of this header. Remove this header.
Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Signed-off-by: Baruch Siach baruch@tkos.co.il --- v4: Drop the spaces.h change from this patch
v3: New patch in this series --- arch/mips/include/asm/const.h | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 arch/mips/include/asm/const.h
diff --git a/arch/mips/include/asm/const.h b/arch/mips/include/asm/const.h deleted file mode 100644 index ed43b5d534ac..000000000000 --- a/arch/mips/include/asm/const.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* - * const.h: Macros for dealing with constants. - */ - -#ifndef _LINUX_CONST_H -#define _LINUX_CONST_H - -/* Some constant macros are used in both assembler and - * C code. Therefore we cannot annotate them always with - * 'UL' and other type specifiers unilaterally. We - * use the following macros to deal with this. - * - * Similarly, _AT() will cast an expression with a type in C, but - * leave it unchanged in asm. - */ - -#ifdef __ASSEMBLY__ -#define _AT(T,X) X -#else -#define _AT(T,X) ((T)(X)) -#endif - -#define _BITUL(x) (_AC(1,UL) << (x)) -#define _BITULL(x) (_AC(1,ULL) << (x)) - -#endif /* !(_LINUX_CONST_H) */

On Sun, Nov 11, 2018 at 12:31:02PM +0200, Baruch Siach wrote:
Commit 86f21c96f467368 (mips: Use common _AC macro now.) removed the _AC definition from const.h. All other macros defined in const.h are not used anywhere, and there is now no user of this header. Remove this header.
Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Signed-off-by: Baruch Siach baruch@tkos.co.il
Reviewed-by: Tom Rini trini@konsulko.com

Am So., 11. Nov. 2018 um 11:33 Uhr schrieb Baruch Siach baruch@tkos.co.il:
Commit 86f21c96f467368 (mips: Use common _AC macro now.) removed the _AC definition from const.h. All other macros defined in const.h are not used anywhere, and there is now no user of this header. Remove this header.
Cc: Daniel Schwierzeck daniel.schwierzeck@gmail.com Signed-off-by: Baruch Siach baruch@tkos.co.il
v4: Drop the spaces.h change from this patch
v3: New patch in this series
arch/mips/include/asm/const.h | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 arch/mips/include/asm/const.h
Reviewed-by: Daniel Schwierzeck daniel.schwierzeck@gmail.com

The kernel added SZ_4G macro in commit f2b9ba871b (arm64/kernel: kaslr: reduce module randomization range to 4 GB).
Include linux/const.h for the _AC macro.
Drop a local SZ_4G definition in tegra code.
Cc: Tom Warren twarren@nvidia.com Reviewed-by: Tom Rini trini@konsulko.com Signed-off-by: Baruch Siach baruch@tkos.co.il --- v4: No change; add review tag
v3: Use linux/const.h
v2: No change --- arch/arm/mach-tegra/tegra186/nvtboot_mem.c | 3 +-- include/linux/sizes.h | 4 ++++ 2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/arch/arm/mach-tegra/tegra186/nvtboot_mem.c b/arch/arm/mach-tegra/tegra186/nvtboot_mem.c index 5c9467bfe8be..62142821a595 100644 --- a/arch/arm/mach-tegra/tegra186/nvtboot_mem.c +++ b/arch/arm/mach-tegra/tegra186/nvtboot_mem.c @@ -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.) diff --git a/include/linux/sizes.h b/include/linux/sizes.h index ce3e8150c174..fbde0bc7e882 100644 --- a/include/linux/sizes.h +++ b/include/linux/sizes.h @@ -8,6 +8,8 @@ #ifndef __LINUX_SIZES_H__ #define __LINUX_SIZES_H__
+#include <linux/const.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__ */

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.
The ATF maps the lower 3G of RAM starting at address 0. Higher RAM is mapped at 4G. This leaves a 1G hole between 3G and 4G for IO peripherals. Use a second bi_dram[] entry to describe the higher RAM area. As a result, CONFIG_NR_DRAM_BANKS must be set to 2 to use more than 3GB RAM.
This code in this commit is mostly taken from downstream Marvell U-Boot code by Grzegorz Jaszczyk.
Cc: Grzegorz Jaszczyk jaz@semihalf.com Signed-off-by: Baruch Siach baruch@tkos.co.il --- v4: No change
v3: No change
v2: Expand memory layout description in code comment and the commit log (Stefan) --- arch/arm/mach-mvebu/arm64-common.c | 50 +++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-mvebu/arm64-common.c b/arch/arm/mach-mvebu/arm64-common.c index f47273fde9c6..47bbf69944ec 100644 --- a/arch/arm/mach-mvebu/arm64-common.c +++ b/arch/arm/mach-mvebu/arm64-common.c @@ -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,62 @@ 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) +{ + /* + * The firmware (ATF) leaves a 1G whole above the 3G mark for IO + * devices. Higher RAM is mapped at 4G. + * + * 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;

On Sun, Nov 11, 2018 at 12:31:00PM +0200, Baruch Siach wrote:
Combine the uapi/linux/const.h header into the kernel linux/const.h. The next commit will use the _AC macro this header instead of the common.h definition.
Based on Linux kernel version 4.19.
Signed-off-by: Baruch Siach baruch@tkos.co.il
Reviewed-by: Tom Rini trini@konsulko.com

On 11.11.18 11:31, Baruch Siach wrote:
Combine the uapi/linux/const.h header into the kernel linux/const.h. The next commit will use the _AC macro this header instead of the common.h definition.
Based on Linux kernel version 4.19.
Signed-off-by: Baruch Siach baruch@tkos.co.il
v4: Mention kernel version in commit log
v3: New patch in this series
Whole series applied to u-boot-marvell/master
Thanks, Stefan
participants (4)
-
Baruch Siach
-
Daniel Schwierzeck
-
Stefan Roese
-
Tom Rini