SPM: Allow secondary CPUs to use the Secure Partition

The Secure Partition should be able to be used from any CPU, not just
the lead one. This patch point the secure contexts of all secondary
CPUs to the same one used by the lead CPU for the Secure Partition. This
way, they can also use it.

In order to prevent more than one CPU from using the Secure Partition at
the same time, a lock has been added.

Change-Id: Ica76373127c3626498b06c558a4874ce72201ff7
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/services/std_svc/spm/spm_main.c b/services/std_svc/spm/spm_main.c
index e156106..979b9a8 100644
--- a/services/std_svc/spm/spm_main.c
+++ b/services/std_svc/spm/spm_main.c
@@ -125,6 +125,13 @@
 	secure_partition_setup();
 
 	/*
+	 * Make all CPUs use the same secure context.
+	 */
+	for (unsigned int i = 0; i < PLATFORM_CORE_COUNT; i++) {
+		cm_set_context_by_index(i, &sp_ctx.cpu_ctx, SECURE);
+	}
+
+	/*
 	 * Arrange for an entry into the secure partition.
 	 */
 	sp_ctx.sp_init_in_progress = 1;
@@ -369,6 +376,9 @@
 				assert(0);
 			}
 
+			/* Release the Secure Partition context */
+			spin_unlock(&sp_ctx.lock);
+
 			/*
 			 * This is the result from the Secure partition of an
 			 * earlier request. Copy the result into the non-secure
@@ -442,6 +452,9 @@
 			/* Save the Normal world context */
 			cm_el1_sysregs_context_save(NON_SECURE);
 
+			/* Lock the Secure Partition context. */
+			spin_lock(&sp_ctx.lock);
+
 			/*
 			 * Restore the secure world context and prepare for
 			 * entry in S-EL0