[U-Boot] [RFC ATF] Add SMCCC_RENESAS_MEMCONF SMC call

2018-06-15 Thread Ulrich Hecht
Returns the memory configuration for Renesas R8A7795 (R-Car H3) SoCs,
revision 3.0 and up.

Signed-off-by: Ulrich Hecht 
---
See "[RFC] ARM: rmobile: create DT memory nodes for R8A7795 3.0 and newer"
for an explanation of this.

CU
Uli


 include/services/arm_arch_svc.h|  1 +
 services/arm_arch_svc/arm_arch_svc_setup.c | 14 ++
 2 files changed, 15 insertions(+)

diff --git a/include/services/arm_arch_svc.h b/include/services/arm_arch_svc.h
index 2961601..9132336 100644
--- a/include/services/arm_arch_svc.h
+++ b/include/services/arm_arch_svc.h
@@ -10,5 +10,6 @@
 #define SMCCC_VERSION  U(0x8000)
 #define SMCCC_ARCH_FEATURESU(0x8001)
 #define SMCCC_ARCH_WORKAROUND_1U(0x80008000)
+#define SMCCC_RENESAS_MEMCONF  U(0x8200)
 
 #endif /* __ARM_ARCH_SVC_H__ */
diff --git a/services/arm_arch_svc/arm_arch_svc_setup.c 
b/services/arm_arch_svc/arm_arch_svc_setup.c
index eedac86..f836ae8 100644
--- a/services/arm_arch_svc/arm_arch_svc_setup.c
+++ b/services/arm_arch_svc/arm_arch_svc_setup.c
@@ -56,6 +56,20 @@ uintptr_t arm_arch_svc_smc_handler(uint32_t smc_fid,
 */
SMC_RET0(handle);
 #endif
+   case SMCCC_RENESAS_MEMCONF:
+#if (RCAR_DRAM_LPDDR4_MEMCONF == 0)
+   /* 4GB(1GBx4) */
+   SMC_RET1(handle, 1);
+#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 5) && \
+   (RCAR_DRAM_SPLIT == 2)
+   /* 4GB(2GBx2 2ch split) */
+   SMC_RET1(handle, 2);
+#elif (RCAR_DRAM_LPDDR4_MEMCONF == 1) && (RCAR_DRAM_CHANNEL == 15)
+   /* 8GB(2GBx4: default) */
+   SMC_RET1(handle, 3);
+#else
+   SMC_RET1(handle, 0);
+#endif /* RCAR_DRAM_LPDDR4_MEMCONF == 0 */
default:
WARN("Unimplemented Arm Architecture Service Call: 0x%x \n",
smc_fid);
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [RFC] ARM: rmobile: create DT memory nodes for R8A7795 3.0 and newer

2018-06-15 Thread Ulrich Hecht
On Fri, Jun 15, 2018 at 12:09 PM, Marek Vasut  wrote:
>> + arm_smccc_smc(ARM_SMCCC_RENESAS_MEMCONF,
>> +   0, 0, 0, 0, 0, 0, 0, );
>
> Will this call work on platforms without patched ATF ?
> (I think not, don't you need to handle return value?)

I have not actually tested that, but if I understand the ATF code
correctly, unimplemented calls return
SMC_UNK (0x), which should be handled by the default case (NOP) below.

>
>> + switch (res.a0) {
>> + case 1:
>> + base[0] = 0x04800ULL;
>> + size[0] = 0x03800ULL;
>> + base[1] = 0x5ULL;
>> + size[1] = 0x04000ULL;
>> + base[2] = 0x6ULL;
>> + size[2] = 0x04000ULL;
>> + base[3] = 0x7ULL;
>> + size[3] = 0x04000ULL;
>> + fdt_fixup_memory_banks(blob, base, size, 4);
>> + break;
>> + case 2:
>> + base[0] = 0x04800ULL;
>> + size[0] = 0x07800ULL;
>> + base[1] = 0x5ULL;
>> + size[1] = 0x08000ULL;
>> + fdt_fixup_memory_banks(blob, base, size, 2);
>> + break;
>> + case 3:
>> + base[0] = 0x04800ULL;
>> + size[0] = 0x07800ULL;
>> + base[1] = 0x5ULL;
>> + size[1] = 0x08000ULL;
>> + base[2] = 0x6ULL;
>> + size[2] = 0x08000ULL;
>> + base[3] = 0x7ULL;
>> + size[3] = 0x08000ULL;
>> + fdt_fixup_memory_banks(blob, base, size, 4);
>> + break;
>
> Obvious design question is -- since you're adding new SMC call anyway,
> can't the call just return the memory layout table itself, so that it
> won't be duplicated both in U-Boot and ATF ?

My gut feeling was to go with the smallest interface possible.

CU
Uli
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


[U-Boot] [RFC] ARM: rmobile: create DT memory nodes for R8A7795 3.0 and newer

2018-06-15 Thread Ulrich Hecht
Uses an SMC call to the ATF to determine the memory configuration, then
creates appropriate DT memory nodes.

Signed-off-by: Ulrich Hecht 
---
This is an attempt to avoid having to have a ton of different device trees
for Renesas R8A7795 H3 SoCs from revision 3.0, which come in a number of
different memory configurations.

The specific configuration is statically baked into the ARM Trusted Firmware
binary, so this solution adds an SMC "SiP Service Call" to the ATF returning
the memory configuration, and then has u-boot build appropriate memory nodes.

This has not been tested in the flesh successfully, as I only have a revision
1.0 board. I'd like to get some feedback on whether this approach is sound,
though. Thanks.

Depends on "[RFC ATF] Add SMCCC_RENESAS_MEMCONF SMC call".

CU
Uli



 board/renesas/salvator-x/salvator-x.c | 51 +++
 configs/r8a7795_salvator-x_defconfig  |  2 ++
 2 files changed, 53 insertions(+)

diff --git a/board/renesas/salvator-x/salvator-x.c 
b/board/renesas/salvator-x/salvator-x.c
index 651877c..307cb64 100644
--- a/board/renesas/salvator-x/salvator-x.c
+++ b/board/renesas/salvator-x/salvator-x.c
@@ -24,6 +24,7 @@
 #include 
 #include 
 #include 
+#include 
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -136,3 +137,53 @@ void reset_cpu(ulong addr)
writel(RST_CODE, RST_CA57RESCNT);
 #endif
 }
+
+#define ARM_SMCCC_RENESAS_MEMCONF  0x8200UL
+int ft_board_setup(void *blob, bd_t *bd)
+{
+   if (rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7795 &&
+   rmobile_get_cpu_rev_integer() >= 3) {
+   u64 base[CONFIG_NR_DRAM_BANKS];
+   u64 size[CONFIG_NR_DRAM_BANKS];
+   struct arm_smccc_res res;
+
+   arm_smccc_smc(ARM_SMCCC_RENESAS_MEMCONF,
+ 0, 0, 0, 0, 0, 0, 0, );
+
+   switch (res.a0) {
+   case 1:
+   base[0] = 0x04800ULL;
+   size[0] = 0x03800ULL;
+   base[1] = 0x5ULL;
+   size[1] = 0x04000ULL;
+   base[2] = 0x6ULL;
+   size[2] = 0x04000ULL;
+   base[3] = 0x7ULL;
+   size[3] = 0x04000ULL;
+   fdt_fixup_memory_banks(blob, base, size, 4);
+   break;
+   case 2:
+   base[0] = 0x04800ULL;
+   size[0] = 0x07800ULL;
+   base[1] = 0x5ULL;
+   size[1] = 0x08000ULL;
+   fdt_fixup_memory_banks(blob, base, size, 2);
+   break;
+   case 3:
+   base[0] = 0x04800ULL;
+   size[0] = 0x07800ULL;
+   base[1] = 0x5ULL;
+   size[1] = 0x08000ULL;
+   base[2] = 0x6ULL;
+   size[2] = 0x08000ULL;
+   base[3] = 0x7ULL;
+   size[3] = 0x08000ULL;
+   fdt_fixup_memory_banks(blob, base, size, 4);
+   break;
+   default:
+   break;
+   }
+   }
+
+   return 0;
+}
diff --git a/configs/r8a7795_salvator-x_defconfig 
b/configs/r8a7795_salvator-x_defconfig
index fdfa41c..cd2bb59 100644
--- a/configs/r8a7795_salvator-x_defconfig
+++ b/configs/r8a7795_salvator-x_defconfig
@@ -61,3 +61,5 @@ CONFIG_USB_EHCI_GENERIC=y
 CONFIG_USB_STORAGE=y
 CONFIG_OF_LIBFDT_OVERLAY=y
 CONFIG_SMBIOS_MANUFACTURER=""
+CONFIG_OF_BOARD_SETUP=y
+CONFIG_ARM_SMCCC=y
-- 
2.7.4

___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot