psci: fix error due to a non zero context id

In the previous psci implementation, the psci_afflvl_power_on_finish()
function would run into an error condition if the value of the context
id parameter in the cpu_on and cpu_suspend psci calls was != 0. The
parameter was being restored as the return value of the affinity level
0 finisher function. A non zero context id would be treated as an
error condition. This would prevent successful wake up of the cpu from
a power down state. Also, the contents of the general purpose
registers were not being cleared upon return to the non-secure world
after a cpu power up. This could potentially allow the non-secure
world to view secure data.

This patch ensures that all general purpose registers are set to ~0
prior to the final eret that drops the execution to the non-secure
world. The context id is used to initialize the general purpose
register x0 prior to re-entry into the non-secure world and is no
longer restored as a function return value. A platform helper
(platform_get_stack()) has been introduced to facilitate this change.

Change-Id: I2454911ffd75705d6aa8609a5d250d9b26fa097c
diff --git a/plat/common/aarch64/platform_helpers.S b/plat/common/aarch64/platform_helpers.S
index 8a6f493..770c1e2 100644
--- a/plat/common/aarch64/platform_helpers.S
+++ b/plat/common/aarch64/platform_helpers.S
@@ -35,6 +35,7 @@
 	.globl	pcpu_dv_mem_stack
 	.weak	platform_get_core_pos
 	.weak	platform_set_stack
+	.weak	platform_get_stack
 	.weak	platform_is_primary_cpu
 	.weak	platform_set_coherent_stack
 	.weak	platform_check_mpidr
@@ -95,19 +96,28 @@
 	cset	x0, eq
 	ret
 
-
 	/* -----------------------------------------------------
-	 * void platform_set_stack (int mpidr)
+	 * void platform_get_stack (unsigned long mpidr)
 	 * -----------------------------------------------------
 	 */
-platform_set_stack:; .type platform_set_stack, %function
-	mov	x9, x30 // lr
+platform_get_stack:; .type platform_get_stack, %function
+	mov	x10, x30 // lr
 	bl	platform_get_core_pos
 	add	x0, x0, #1
 	mov	x1, #PLATFORM_STACK_SIZE
 	mul	x0, x0, x1
 	ldr	x1, =platform_normal_stacks
-	add	sp, x1, x0
+	add	x0, x1, x0
+	ret	x10
+
+	/* -----------------------------------------------------
+	 * void platform_set_stack (unsigned long mpidr)
+	 * -----------------------------------------------------
+	 */
+platform_set_stack:; .type platform_set_stack, %function
+	mov	x9, x30 // lr
+	bl	platform_get_stack
+	mov	sp, x0
 	ret	x9
 
 	/* -----------------------------------------------------