SPM: Optimize stateless service logic

- Rename the variables to make more sense.
- Do not chain stateless services as they are never looked up.
- Fine-tune the bit definition of service flags.

Change-Id: Ie242ceefa0a9b43581d12963a92e59c6da3fa3af
Signed-off-by: Ken Liu <Ken.Liu@arm.com>
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.c b/secure_fw/spm/cmsis_psa/spm_ipc.c
index e812d2c..ed3fe0d 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.c
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.c
@@ -37,7 +37,8 @@
 #include "load/spm_load_api.h"
 
 extern struct spm_partition_db_t g_spm_partition_db;
-static struct service_t *all_services;
+static struct service_t *connection_services_listhead;
+struct service_t *stateless_services_ref_tbl[STATIC_HANDLE_NUM_LIMIT];
 
 /* Pools */
 TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct tfm_conn_handle_t),
@@ -343,12 +344,12 @@
 
 struct service_t *tfm_spm_get_service_by_sid(uint32_t sid)
 {
-    struct service_t *p_serv = all_services;
+    struct service_t *p_serv = connection_services_listhead;
 
     while (p_serv && p_serv->p_ldinf->sid != sid) {
         p_serv = TO_CONTAINER(BI_LIST_NEXT_NODE(&p_serv->list),
                               struct service_t, list);
-        if (p_serv == all_services)
+        if (p_serv == connection_services_listhead)
             return NULL;
     }
 
@@ -390,12 +391,12 @@
     TFM_CORE_ASSERT(service);
 
     switch (SERVICE_GET_VERSION_POLICY(service->p_ldinf->flags)) {
-    case TFM_VERSION_POLICY_RELAXED:
+    case SERVICE_VERSION_POLICY_RELAXED:
         if (version > service->p_ldinf->version) {
             return SPM_ERROR_VERSION;
         }
         break;
-    case TFM_VERSION_POLICY_STRICT:
+    case SERVICE_VERSION_POLICY_STRICT:
         if (version != service->p_ldinf->version) {
             return SPM_ERROR_VERSION;
         }
@@ -663,7 +664,9 @@
             break;
         }
 
-        load_services_assuredly(partition, &all_services);
+        load_services_assuredly(partition, &connection_services_listhead,
+                                           stateless_services_ref_tbl,
+                                           sizeof(stateless_services_ref_tbl));
 
         p_cmninf = partition->p_ldinf;