fix(rcar3): disable stack protector for functions in SRAM

Disable the BL31 stack protector for all functions placed in SRAM,
because the canary value in __stack_chk_guard in DRAM can not be
read when running Suspend To RAM code from SRAM. The SSP functions
in DRAM can also not be called from that code. Make sure the code
in SRAM is self-contained by marking rcar_pwrc_go_suspend_to_ram()
as noinline. To assure the stack protector is active otherwise,
use no_stack_protector function attribute for the select functions
which are placed in SRAM.

Change-Id: Idc43e70fd5217ea130a48c46f227a37c568dc8bd
Fixes: cfa466ab733f ("feat(rcar3): enable the stack protection")
Signed-off-by: Toshiyuki Ogasahara <toshiyuki.ogasahara.bo@hitachi.com>
Signed-off-by: Yoshifumi Hosoya <yoshifumi.hosoya.wj@renesas.com>
Signed-off-by: Dien Pham <dien.pham.ry@renesas.com>
Signed-off-by: Hieu Nguyen <hieu.nguyen.dn@renesas.com>
Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
diff --git a/drivers/renesas/common/common.c b/drivers/renesas/common/common.c
index a0aa480..07d7ea3 100644
--- a/drivers/renesas/common/common.c
+++ b/drivers/renesas/common/common.c
@@ -10,7 +10,8 @@
 #include "rcar_private.h"
 
 #if IMAGE_BL31
-void __attribute__ ((section(".system_ram"))) cpg_write(uintptr_t regadr, uint32_t regval)
+void __attribute__ ((section(".system_ram"), no_stack_protector))
+	cpg_write(uintptr_t regadr, uint32_t regval)
 #else
 void cpg_write(uintptr_t regadr, uint32_t regval)
 #endif
@@ -22,8 +23,8 @@
 }
 
 #if IMAGE_BL31
-void __attribute__ ((section(".system_ram"))) mstpcr_write(uint32_t mstpcr, uint32_t mstpsr,
-							   uint32_t target_bit)
+void __attribute__ ((section(".system_ram"), no_stack_protector))
+	mstpcr_write(uint32_t mstpcr, uint32_t mstpsr, uint32_t target_bit)
 #else
 void mstpcr_write(uint32_t mstpcr, uint32_t mstpsr, uint32_t target_bit)
 #endif
diff --git a/drivers/renesas/common/delay/micro_delay.c b/drivers/renesas/common/delay/micro_delay.c
index a5e2a69..a0a41d2 100644
--- a/drivers/renesas/common/delay/micro_delay.c
+++ b/drivers/renesas/common/delay/micro_delay.c
@@ -13,7 +13,7 @@
 
 void
 #if IMAGE_BL31
-	__attribute__ ((section(".system_ram")))
+	__attribute__ ((section(".system_ram"), no_stack_protector))
 #endif
 	rcar_micro_delay(uint64_t micro_sec)
 {
diff --git a/drivers/renesas/common/iic_dvfs/iic_dvfs.c b/drivers/renesas/common/iic_dvfs/iic_dvfs.c
index bf80697..4dd3872 100644
--- a/drivers/renesas/common/iic_dvfs/iic_dvfs.c
+++ b/drivers/renesas/common/iic_dvfs/iic_dvfs.c
@@ -79,11 +79,11 @@
 
 #if IMAGE_BL31
 #define IIC_DVFS_FUNC(__name, ...)					\
-static int32_t	__attribute__ ((section(".system_ram")))		\
+static int32_t	__attribute__ ((section(".system_ram"), no_stack_protector)) \
 dvfs_ ##__name(__VA_ARGS__)
 
 #define RCAR_DVFS_API(__name, ...)					\
-int32_t __attribute__ ((section(".system_ram")))			\
+int32_t __attribute__ ((section(".system_ram"), no_stack_protector))	\
 rcar_iic_dvfs_ ##__name(__VA_ARGS__)
 
 #else
diff --git a/drivers/renesas/common/pwrc/pwrc.c b/drivers/renesas/common/pwrc/pwrc.c
index 9e765af..35fba44 100644
--- a/drivers/renesas/common/pwrc/pwrc.c
+++ b/drivers/renesas/common/pwrc/pwrc.c
@@ -427,7 +427,7 @@
 } while (!(mmio_read_32(DBSC4_REG_DBCAM##__bit##STAT0) & DBSC4_BIT_DBCAMxSTAT0))
 
 
-static void __attribute__ ((section(".system_ram")))
+static void __attribute__ ((section(".system_ram"), no_stack_protector))
 	rcar_pwrc_set_self_refresh(void)
 {
 	uint32_t reg = mmio_read_32(RCAR_PRR);
@@ -519,7 +519,7 @@
 	mmio_write_32(DBSC4_REG_DBSYSCNT0, DBSC4_SET_DBSYSCNT0_WRITE_DISABLE);
 }
 
-static void __attribute__ ((section(".system_ram")))
+static void __attribute__ ((section(".system_ram"), no_stack_protector))
 rcar_pwrc_set_self_refresh_e3(void)
 {
 	uint32_t ddr_md;
@@ -650,7 +650,7 @@
 	mmio_write_32(DBSC4_REG_DBSYSCNT0, DBSC4_SET_DBSYSCNT0_WRITE_DISABLE);
 }
 
-void __attribute__ ((section(".system_ram"))) __attribute__ ((noinline))
+static void __attribute__ ((section(".system_ram"), noinline, no_stack_protector))
 rcar_pwrc_go_suspend_to_ram(void)
 {
 #if PMIC_ROHM_BD9571
diff --git a/drivers/renesas/common/pwrc/pwrc.h b/drivers/renesas/common/pwrc/pwrc.h
index 3b0f1dd..74fa4b2 100644
--- a/drivers/renesas/common/pwrc/pwrc.h
+++ b/drivers/renesas/common/pwrc/pwrc.h
@@ -64,7 +64,6 @@
 #endif
 
 #if RCAR_SYSTEM_SUSPEND
-void rcar_pwrc_go_suspend_to_ram(void);
 void rcar_pwrc_set_suspend_to_ram(void);
 void rcar_pwrc_init_suspend_to_ram(void);
 void rcar_pwrc_suspend_to_ram(void);
diff --git a/drivers/renesas/rcar_gen4/pwrc/pwrc.c b/drivers/renesas/rcar_gen4/pwrc/pwrc.c
index c42da8c..101b93a 100644
--- a/drivers/renesas/rcar_gen4/pwrc/pwrc.c
+++ b/drivers/renesas/rcar_gen4/pwrc/pwrc.c
@@ -312,7 +312,8 @@
 	return count;
 }
 
-static void __section(".system_ram") rcar_pwrc_set_self_refresh(void)
+static void __attribute__ ((section(".system_ram"), no_stack_protector))
+	rcar_pwrc_set_self_refresh(void)
 {
 	uint64_t base_count, freq, get_count, wait_time;
 	uint32_t reg;
@@ -410,7 +411,7 @@
 	mmio_write_32(DBSC4_REG_DBSYSCNT0, DBSC4_SET_DBSYSCNT0_WRITE_DISABLE);
 }
 
-static void __section(".system_ram") __attribute__ ((noinline))
+static void __attribute__ ((section(".system_ram"), no_stack_protector))
 		rcar_pwrc_go_suspend_to_ram(void)
 {
 	rcar_pwrc_set_self_refresh();