Use constant stack size with RECLAIM_INIT_CODE

Currently, when RECLAIM_INIT_CODE is set, the
stacks are scaled to ensure that the entirety
of the init section can be reclaimed as stack.

This causes an issue in lib/psci/aarch64/psci_helpers.S,
where the stack size is used for cache operations in
psci_do_pwrdown_cache_maintenance(). If the stacks
are scaled, then the PSCI code may fail to invalidate
some of the stack memory before power down.

Resizing stacks is also not good for stability in general,
since code that works with a small number of cores may
overflow the stack when the number of cores is increased.

Change to make every stack be PLATFORM_STACK_SIZE big,
and allow the total stack to be smaller than the
init section.

Any pages of the init section not reclaimed as
stack will be set to read-only and execute-never,
for security.

Change-Id: I10b3884981006431f2fcbec3864c81d4a8c246e8
Signed-off-by: David Horstmann <david.horstmann@arm.com>
diff --git a/include/plat/arm/common/arm_reclaim_init.ld.S b/include/plat/arm/common/arm_reclaim_init.ld.S
index e4d4f12..717f65e 100644
--- a/include/plat/arm/common/arm_reclaim_init.ld.S
+++ b/include/plat/arm/common/arm_reclaim_init.ld.S
@@ -14,54 +14,30 @@
             __INIT_CODE_START__ = .;
 	    *(*text.init*);
             __INIT_CODE_END__ = .;
+            INIT_CODE_END_ALIGNED = ALIGN(PAGE_SIZE);
         } >RAM
 
 #ifdef BL31_PROGBITS_LIMIT
     ASSERT(__INIT_CODE_END__ <= BL31_PROGBITS_LIMIT,
             "BL31 init has exceeded progbits limit.")
 #endif
-
-    ASSERT(__INIT_CODE_END__ <= __STACKS_END__,
-        "Init code ends past the end of the stacks")
-
 }
 
-#undef	MIN
 #define	ABS		ABSOLUTE
-#define	COUNT		PLATFORM_CORE_COUNT
-#define	ALIGN_MASK	~(CACHE_WRITEBACK_GRANULE - 1)
 
-#define PRIMARY_STACK							\
-	__STACKS_START__ = .;						\
-	*(tzfw_normal_stacks)						\
-	OFFSET = ABS(SIZEOF(.init) - (. - __STACKS_START__));		\
-	/* Offset sign */						\
-	SIGN = ABS(OFFSET) & (1 << 63);					\
-	/* Offset mask */						\
-	MASK = ABS(SIGN >> 63) - 1;					\
-	. +=  ABS(OFFSET) & ABS(MASK);					\
-	.  = ALIGN(PAGE_SIZE);						\
-	__STACKS_END__ = .;						\
-	/* Total stack size */						\
-	SIZE = ABS(. - __STACKS_START__);				\
-	/* Maximum primary CPU stack */					\
-	STACK = ABS(__STACKS_START__ + SIZE / COUNT) & ALIGN_MASK;	\
-	/* Primary CPU stack */						\
-	__PRIMARY_STACK__ = MIN(STACK, ABS(__INIT_CODE_START__));
-
-#if (COUNT > 1)
-#define	SECONDARY_STACK					\
-	/* Size of the secondary CPUs' stack */		\
-	REST = ABS(__STACKS_END__ - __PRIMARY_STACK__);	\
-	/* Secondary per-CPU stack size */		\
-	__STACK_SIZE__ = ABS(REST / (COUNT - 1));
-#else
-#define	SECONDARY_STACK
-#endif
-
-#define STACK_SECTION		\
-	stacks (NOLOAD) : {	\
-		PRIMARY_STACK	\
-		SECONDARY_STACK	\
+#define STACK_SECTION							\
+	stacks (NOLOAD) : {						\
+		__STACKS_START__ = .;					\
+		*(tzfw_normal_stacks)					\
+		__STACKS_END__ = .;					\
+		/* Allow room for the init section where necessary. */	\
+		OFFSET = ABS(SIZEOF(.init) - (. - __STACKS_START__));	\
+		/* Offset sign */					\
+		SIGN = ABS(OFFSET) & (1 << 63);				\
+		/* Offset mask */					\
+		MASK = ABS(SIGN >> 63) - 1;				\
+		. +=  ABS(OFFSET) & ABS(MASK);				\
+		.  = ALIGN(PAGE_SIZE);					\
 	}
+
 #endif /* ARM_RECLAIM_INIT_LD_S */