1 /*
2  * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3  * Copyright (c) 2022-2023 Cypress Semiconductor Corporation (an Infineon
4  * company) or an affiliate of Cypress Semiconductor Corporation. All rights
5  * reserved.
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  *
9  */
10 
11 #ifndef __PARTITION_DEFS_H__
12 #define __PARTITION_DEFS_H__
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 /* TF-M internal partition ID */
18 #define TFM_SP_IDLE_ID                          (1)
19 #define INVALID_PARTITION_ID                    (~0U)
20 
21 /* Encode a magic number into version for validating partition info */
22 #define PARTITION_INFO_VERSION_MASK             (0x0000FFFF)
23 #define PARTITION_INFO_MAGIC_MASK               (0xFFFF0000)
24 #define PARTITION_INFO_MAGIC                    (0x5F5F0000)
25 
26 /*
27  * Partition flag start
28  *
29  * 31      12 11 10  9   8  7         0
30  * +---------+--+--+---+---+----------+
31  * | RES[20] |TZ|MB|I/S|A/P| Priority |
32  * +---------+--+--+---+---+----------+
33  *
34  * Field                Desc                        Value
35  * Priority, bits[7:0]:  Partition Priority          Lowest, low, normal, high, hightest
36  * A/P, bit[8]:          ARoT or PRoT domain         1: PRoT              0: ARoT
37  * I/S, bit[9]:          IPC or SFN typed partition  1: IPC               0: SFN
38  * MB,  bit[10]:         NS Agent Mailbox or not     1: NS Agent mailbox  0: Not
39  * TZ,  bit[11]:         NS Agent TZ or not          1: NS Agent TZ       0: Not
40  * RES, bits[31:12]:     20 bits reserved            0
41  */
42 #define PARTITION_PRI_HIGHEST                   (0x0)
43 #define PARTITION_PRI_HIGH                      (0xF)
44 #define PARTITION_PRI_NORMAL                    (0x1F)
45 #define PARTITION_PRI_LOW                       (0x7F)
46 #define PARTITION_PRI_LOWEST                    (0xFF)
47 #define PARTITION_PRI_MASK                      (0xFF)
48 
49 #define PARTITION_MODEL_PSA_ROT                 (1UL << 8)
50 #define PARTITION_MODEL_IPC                     (1UL << 9)
51 
52 #define PARTITION_NS_AGENT_MB                   (1UL << 10)
53 #define PARTITION_NS_AGENT_TZ                   (1UL << 11)
54 
55 #define PARTITION_PRIORITY(flag)                ((flag) & PARTITION_PRI_MASK)
56 #define TO_THREAD_PRIORITY(x)                   (x)
57 
58 #define ENTRY_TO_POSITION(x)                    (uintptr_t)(x)
59 #define POSITION_TO_ENTRY(x, t)                 (t)(x)
60 
61 #define PTR_TO_REFERENCE(x)                     (uintptr_t)(x)
62 #define REFERENCE_TO_PTR(x, t)                  (t)(x)
63 
64 #define IS_PSA_ROT(pldi)                        (!!((pldi)->flags \
65                                                      & PARTITION_MODEL_PSA_ROT))
66 #define IS_IPC_MODEL(pldi)                      (!!((pldi)->flags \
67                                                      & PARTITION_MODEL_IPC))
68 #define IS_NS_AGENT(pldi)                       (!!((pldi)->flags \
69                                                      & (PARTITION_NS_AGENT_MB | PARTITION_NS_AGENT_TZ)))
70 #ifdef CONFIG_TFM_USE_TRUSTZONE
71 #define IS_NS_AGENT_TZ(pldi)                    (!!((pldi)->flags & PARTITION_NS_AGENT_TZ))
72 #else
73 #define IS_NS_AGENT_TZ(pldi)                    false
74 #endif
75 #ifdef TFM_PARTITION_NS_AGENT_MAILBOX
76 #define IS_NS_AGENT_MAILBOX(pldi)               (!!((pldi)->flags & PARTITION_NS_AGENT_MB))
77 #else
78 #define IS_NS_AGENT_MAILBOX(pldi)               false
79 #endif
80 
81 #define PARTITION_TYPE_TO_INDEX(type)           (!!((type) & PARTITION_NS_AGENT_TZ))
82 
83 /* Partition flag end */
84 
85 /*
86  * Common partition structure type, the extendable data is right after it.
87  * Extendable data has different size for each partition, and must be 4-byte
88  * aligned. It includes: stack and heap position, dependencies, services and
89  * assets data.
90  */
91 struct partition_load_info_t {
92     uint32_t        psa_ff_ver;         /* Encode the version with magic    */
93     int32_t         pid;                /* Partition ID                     */
94     uint32_t        flags;              /* ARoT/PRoT, SFN/IPC, priority     */
95     uintptr_t       entry;              /* Entry point                      */
96     size_t          stack_size;         /* Stack size                       */
97     size_t          heap_size;          /* Heap size                        */
98     uint32_t        ndeps;              /* Dependency number                */
99     uint32_t        nservices;          /* Service number                   */
100     uint32_t        nassets;            /* Asset numbers                    */
101     uint32_t        nirqs;              /* Number of IRQ owned by Partition */
102 } __attribute__((aligned(4)));
103 
104 #endif /* __PARTITION_DEFS_H__ */
105