SPM: Adjust fundamental headers - lists and bits

Fundamental headers contain preprocessors, the headers do not belong
to a specific module.

- Move lists.h into common SPM 'include' root.
- Move bit operations from 'utilities.h' to a dedicated header file,
  and put this new header under SPM 'include' root.

Change-Id: Icb6627f7172721b651632cb94f1546a34368cb3b
Signed-off-by: Ken Liu <Ken.Liu@arm.com>
diff --git a/secure_fw/spm/cmsis_func/spm_func.c b/secure_fw/spm/cmsis_func/spm_func.c
index 72ec0ff..da107f3 100644
--- a/secure_fw/spm/cmsis_func/spm_func.c
+++ b/secure_fw/spm/cmsis_func/spm_func.c
@@ -8,6 +8,7 @@
 #include <stdint.h>
 #include <stdbool.h>
 #include <arm_cmse.h>
+#include "bitops.h"
 #include "tfm_nspm.h"
 #include "tfm_api.h"
 #include "tfm_arch.h"
@@ -1087,7 +1088,7 @@
 {
     size_t i;
 
-    if (!tfm_is_one_bit_set(signal)) {
+    if (!IS_ONLY_ONE_BIT_IN_UINT32(signal)) {
         return -1;
     }
 
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.c b/secure_fw/spm/cmsis_psa/spm_ipc.c
index 836f838..d2067c1 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.c
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.c
@@ -7,6 +7,7 @@
 
 #include <inttypes.h>
 #include <stdbool.h>
+#include "bitops.h"
 #include "psa/client.h"
 #include "psa/service.h"
 #include "tfm_thread.h"
@@ -24,7 +25,7 @@
 #include "tfm_core_utils.h"
 #include "tfm_rpc.h"
 #include "tfm_core_trustzone.h"
-#include "ffm/lists.h"
+#include "lists.h"
 #include "tfm_pools.h"
 #include "region.h"
 #include "region_defs.h"
@@ -879,7 +880,7 @@
 {
     size_t i;
 
-    if (!tfm_is_one_bit_set(signal)) {
+    if (!IS_ONLY_ONE_BIT_IN_UINT32(signal)) {
         return -1;
     }
 
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.h b/secure_fw/spm/cmsis_psa/spm_ipc.h
index 41c506f..ed04f05 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.h
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.h
@@ -11,7 +11,7 @@
 #include <stdint.h>
 #include "spm_partition_defs.h"
 #include "tfm_arch.h"
-#include "ffm/lists.h"
+#include "lists.h"
 #include "tfm_wait.h"
 #include "tfm_secure_api.h"
 #include "tfm_thread.h"
diff --git a/secure_fw/spm/cmsis_psa/tfm_pools.c b/secure_fw/spm/cmsis_psa/tfm_pools.c
index 8045f08..835674f 100644
--- a/secure_fw/spm/cmsis_psa/tfm_pools.c
+++ b/secure_fw/spm/cmsis_psa/tfm_pools.c
@@ -14,7 +14,7 @@
 #include "internal_errors.h"
 #include "cmsis_compiler.h"
 #include "utilities.h"
-#include "ffm/lists.h"
+#include "lists.h"
 #include "tfm_pools.h"
 #include "tfm_memory_utils.h"
 #include "tfm_core_utils.h"
diff --git a/secure_fw/spm/cmsis_psa/tfm_pools.h b/secure_fw/spm/cmsis_psa/tfm_pools.h
index a71aa8c..e9c19dc 100644
--- a/secure_fw/spm/cmsis_psa/tfm_pools.h
+++ b/secure_fw/spm/cmsis_psa/tfm_pools.h
@@ -9,7 +9,7 @@
 
 #include <stdbool.h>
 
-#include "ffm/lists.h"
+#include "lists.h"
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/secure_fw/spm/ffm/psa_client_service_apis.c b/secure_fw/spm/ffm/psa_client_service_apis.c
index 9fba6ee..235ee8b 100644
--- a/secure_fw/spm/ffm/psa_client_service_apis.c
+++ b/secure_fw/spm/ffm/psa_client_service_apis.c
@@ -6,6 +6,7 @@
  */
 
 #include <stdint.h>
+#include "bitops.h"
 #include "spm_psa_client_call.h"
 #include "psa/lifecycle.h"
 #ifdef TFM_PSA_API
@@ -183,7 +184,7 @@
      * Only one message could be retrieved every time for psa_get(). It is a
      * fatal error if the input signal has more than a signal bit set.
      */
-    if (!tfm_is_one_bit_set(signal)) {
+    if (!IS_ONLY_ONE_BIT_IN_UINT32(signal)) {
         tfm_core_panic();
     }
 
diff --git a/secure_fw/spm/ffm/utilities.c b/secure_fw/spm/ffm/utilities.c
index 2aab6d9..98a3e19 100644
--- a/secure_fw/spm/ffm/utilities.c
+++ b/secure_fw/spm/ffm/utilities.c
@@ -20,8 +20,3 @@
      */
     tfm_hal_system_reset();
 }
-
-bool tfm_is_one_bit_set(uint32_t n)
-{
-    return ((n && !(n & (n-1))) ? true : false);
-}
diff --git a/secure_fw/spm/include/bitops.h b/secure_fw/spm/include/bitops.h
new file mode 100644
index 0000000..ed3ddd9
--- /dev/null
+++ b/secure_fw/spm/include/bitops.h
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+#ifndef __BITOPS_H__
+#define __BITOPS_H__
+
+#include <stdint.h>
+
+/* Check if there is only one bit availiable in a 32bit number */
+#define IS_ONLY_ONE_BIT_IN_UINT32(n)                          \
+                  ((uint32_t)(n) && !((uint32_t)(n) & ((uint32_t)(n)-1)))
+#endif /* __BITOPS_H__ */
diff --git a/secure_fw/spm/include/ffm/lists.h b/secure_fw/spm/include/lists.h
similarity index 100%
rename from secure_fw/spm/include/ffm/lists.h
rename to secure_fw/spm/include/lists.h
diff --git a/secure_fw/spm/include/utilities.h b/secure_fw/spm/include/utilities.h
index f191ff6..76c9128 100644
--- a/secure_fw/spm/include/utilities.h
+++ b/secure_fw/spm/include/utilities.h
@@ -35,6 +35,4 @@
 
 #define ERROR_MSG(msg)
 
-bool tfm_is_one_bit_set(uint32_t n);
-
 #endif /* __TFM_UTILS_H__ */