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