Dualcpu: Simplify the lock of multi-thread test statistics

The variables in statistics are non-secure mailbox local ones.
Protect them with non-secure mailbox local locks, other than the
inter-core locks.

Change-Id: I73b034b7ea1b559fbed19d324300e3b933e96275
Signed-off-by: David Hu <david.hu@arm.com>
diff --git a/interface/src/tfm_ns_mailbox.c b/interface/src/tfm_ns_mailbox.c
index 0b96e65..21ee1d8 100644
--- a/interface/src/tfm_ns_mailbox.c
+++ b/interface/src/tfm_ns_mailbox.c
@@ -6,6 +6,8 @@
  */
 
 #include <string.h>
+
+#include "cmsis_compiler.h"
 #include "tfm_ns_mailbox.h"
 #include "tfm_plat_ns.h"
 
@@ -87,6 +89,20 @@
     }
 }
 
+/*
+ * When NSPE mailbox only covers a single non-secure core, spinlock is only
+ * required to disable IRQ.
+ */
+static inline void ns_mailbox_spin_lock(void)
+{
+    __disable_irq();
+}
+
+static inline void ns_mailbox_spin_unlock(void)
+{
+    __enable_irq();
+}
+
 static uint8_t acquire_empty_slot(const struct ns_mailbox_queue_t *queue)
 {
     uint8_t idx;
@@ -128,12 +144,8 @@
         return;
     }
 
-    tfm_ns_mailbox_hal_enter_critical();
-
     mailbox_queue_ptr->nr_tx = 0;
     mailbox_queue_ptr->nr_used_slots = 0;
-
-    tfm_ns_mailbox_hal_exit_critical();
 }
 
 static void mailbox_tx_stats_update(struct ns_mailbox_queue_t *ns_queue)
@@ -146,9 +158,6 @@
     }
 
     tfm_ns_mailbox_hal_enter_critical();
-
-    ns_queue->nr_tx++;
-
     /* Count the number of used slots when this tx arrives */
     empty_status = ns_queue->empty_slots;
     tfm_ns_mailbox_hal_exit_critical();
@@ -161,9 +170,10 @@
         }
     }
 
-    tfm_ns_mailbox_hal_enter_critical();
+    ns_mailbox_spin_lock();
     ns_queue->nr_used_slots += (NUM_MAILBOX_QUEUE_SLOT - nr_empty);
-    tfm_ns_mailbox_hal_exit_critical();
+    ns_queue->nr_tx++;
+    ns_mailbox_spin_unlock();
 }
 
 void tfm_ns_mailbox_stats_avg_slot(struct ns_mailbox_stats_res_t *stats_res)
@@ -174,10 +184,8 @@
         return;
     }
 
-    tfm_ns_mailbox_hal_enter_critical();
     nr_used_slots = mailbox_queue_ptr->nr_used_slots;
     nr_tx = mailbox_queue_ptr->nr_tx;
-    tfm_ns_mailbox_hal_exit_critical();
 
     stats_res->avg_nr_slots = nr_used_slots / nr_tx;
     nr_used_slots %= nr_tx;