1 /*
2  * Copyright (c) 2021, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __SERVICE_DEFS_H__
9 #define __SERVICE_DEFS_H__
10 
11 #include <stdint.h>
12 #include "config_impl.h"
13 #include "psa/service.h"
14 
15 /*
16  * Service load data - flags
17  * bit 7-0: stateless handle index
18  * bit 8: 1 - NS accessible, 0 - NS not accessible
19  * bit 9: 1 - stateless, 0 - connection-based
20  * bit 10: 1 - strict version policy, 0 - relaxed version policy
21  * bit 11: 1 - MM-IOVEC enabled, 0 - MM-IOVEC disabled
22  */
23 #define SERVICE_FLAG_STATELESS_HINDEX_MASK      (0xFF)
24 #define SERVICE_FLAG_NS_ACCESSIBLE              (1U << 8)
25 #define SERVICE_FLAG_STATELESS                  (1U << 9)
26 
27 #define SERVICE_FLAG_VERSION_POLICY_BIT         (1U << 10)
28 #define SERVICE_VERSION_POLICY_RELAXED          (0U << 10)
29 #define SERVICE_VERSION_POLICY_STRICT           (1U << 10)
30 #define SERVICE_FLAG_MM_IOVEC                   (1U << 11)
31 
32 #define SERVICE_GET_STATELESS_HINDEX(flag)      \
33     ((flag) & SERVICE_FLAG_STATELESS_HINDEX_MASK)
34 #define SERVICE_IS_NS_ACCESSIBLE(flag)          \
35     ((flag) & SERVICE_FLAG_NS_ACCESSIBLE)
36 #define SERVICE_IS_STATELESS(flag)              \
37     ((flag) & SERVICE_FLAG_STATELESS)
38 #define SERVICE_GET_VERSION_POLICY(flag)        \
39     ((flag) & SERVICE_FLAG_VERSION_POLICY_BIT)
40 #define SERVICE_ENABLED_MM_IOVEC(flag)          \
41     ((flag) & SERVICE_FLAG_MM_IOVEC)
42 
43 #define STRID_TO_STRING_PTR(strid)              (const char *)(strid)
44 #define STRING_PTR_TO_STRID(str)                (uintptr_t)(str)
45 
46 /* Common service structure type */
47 struct service_load_info_t {
48     uintptr_t       name_strid;         /* String ID for name               */
49     uint32_t        sid;                /* Service ID                       */
50     uint32_t        flags;              /* Flags                            */
51     uint32_t        version;            /* Service version                  */
52     uintptr_t       sfn;                /* Secure Function                  */
53 #if CONFIG_TFM_SPM_BACKEND_IPC == 1
54     psa_signal_t    signal;             /* Service signal                   */
55 #endif
56 } __attribute__((aligned(4)));
57 
58 #endif /* __SERVICE_DEFS_H__ */
59