SPM: Prevent simultaneous blocking calls

Blocking calls can only succeed if the target Secure Partition is idle.

Change-Id: Iabeaa0b8d3e653fd8581fa086758936abfc1c772
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/services/std_svc/spm/spm_private.h b/services/std_svc/spm/spm_private.h
index a8234c3..a7bd760 100644
--- a/services/std_svc/spm/spm_private.h
+++ b/services/std_svc/spm/spm_private.h
@@ -58,6 +58,9 @@
 	sp_state_t state;
 	spinlock_t state_lock;
 
+	unsigned int request_count;
+	spinlock_t request_count_lock;
+
 	/* Base and size of the shared SPM<->SP buffer */
 	uintptr_t spm_sp_buffer_base;
 	size_t spm_sp_buffer_size;
@@ -80,6 +83,11 @@
 void sp_state_wait_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to);
 int sp_state_try_switch(sp_context_t *sp_ptr, sp_state_t from, sp_state_t to);
 
+/* Functions to keep track of the number of active requests per SP */
+void spm_sp_request_increase(sp_context_t *sp_ctx);
+void spm_sp_request_decrease(sp_context_t *sp_ctx);
+int spm_sp_request_increase_if_zero(sp_context_t *sp_ctx);
+
 /* Functions related to the translation tables management */
 xlat_ctx_t *spm_sp_xlat_context_alloc(void);
 void sp_map_memory_regions(sp_context_t *sp_ctx);