J-Alves | 7ec9d6e | 2023-02-28 16:39:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2023 The Hafnium Authors. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style |
| 5 | * license that can be found in the LICENSE file or at |
| 6 | * https://opensource.org/licenses/BSD-3-Clause. |
| 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
| 11 | #include <stdint.h> |
| 12 | |
| 13 | #include "hf/addr.h" |
| 14 | #include "hf/memiter.h" |
| 15 | #include "hf/string.h" |
| 16 | |
| 17 | #include "vmapi/hf/ffa.h" |
| 18 | |
| 19 | #define MANIFEST_INVALID_ADDRESS UINT64_MAX |
| 20 | #define MANIFEST_INVALID_ID UINT32_MAX |
| 21 | |
| 22 | #define SP_RTX_BUF_NAME_SIZE 10 |
| 23 | |
| 24 | /** FF-A manifest memory and device regions attributes. */ |
| 25 | #define MANIFEST_REGION_ATTR_READ (UINT32_C(1) << 0) |
| 26 | #define MANIFEST_REGION_ATTR_WRITE (UINT32_C(1) << 1) |
| 27 | #define MANIFEST_REGION_ATTR_EXEC (UINT32_C(1) << 2) |
| 28 | #define MANIFEST_REGION_ATTR_SECURITY (UINT32_C(1) << 3) |
| 29 | |
| 30 | #define MANIFEST_REGION_ALL_ATTR_MASK \ |
| 31 | (MANIFEST_REGION_ATTR_READ | MANIFEST_REGION_ATTR_WRITE | \ |
| 32 | MANIFEST_REGION_ATTR_EXEC | MANIFEST_REGION_ATTR_SECURITY) |
| 33 | |
| 34 | #define MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED (UINT32_C(1) << 0) |
| 35 | #define MANIFEST_POWER_MANAGEMENT_CPU_ON_SUPPORTED (UINT32_C(1) << 3) |
| 36 | #define MANIFEST_POWER_MANAGEMENT_NONE_MASK (UINT32_C(0)) |
| 37 | #define MANIFEST_POWER_MANAGEMENT_ALL_MASK \ |
| 38 | (MANIFEST_POWER_MANAGEMENT_CPU_OFF_SUPPORTED | \ |
| 39 | MANIFEST_POWER_MANAGEMENT_CPU_ON_SUPPORTED) |
| 40 | |
| 41 | /* Highest possible value for the boot-order field. */ |
| 42 | #define DEFAULT_BOOT_ORDER 0xFFFF |
| 43 | #define DEFAULT_BOOT_GP_REGISTER UINT32_C(-1) |
| 44 | |
| 45 | enum run_time_el { |
| 46 | EL1 = 0, |
| 47 | S_EL0, |
| 48 | S_EL1, |
| 49 | SUPERVISOR_MODE, |
| 50 | SECURE_USER_MODE, |
| 51 | SECURE_SUPERVISOR_MODE |
| 52 | }; |
| 53 | |
| 54 | enum execution_state { AARCH64 = 0, AARCH32 }; |
| 55 | |
| 56 | enum xlat_granule { PAGE_4KB = 0, PAGE_16KB, PAGE_64KB }; |
| 57 | |
| 58 | /** |
| 59 | * Partition Memory region as described in FFA v1.0 spec, Table 10 |
| 60 | */ |
| 61 | struct memory_region { |
| 62 | struct string name; |
| 63 | /** |
| 64 | * Specify PA, VA for S-EL0 partitions or IPA |
| 65 | * for S-EL1 partitions - optional. |
| 66 | */ |
| 67 | uintptr_t base_address; |
| 68 | /** Page count - mandatory */ |
| 69 | uint32_t page_count; |
| 70 | /** Memory attributes - mandatory */ |
| 71 | uint32_t attributes; |
| 72 | }; |
| 73 | |
| 74 | struct interrupt_info { |
| 75 | uint32_t id; |
| 76 | uint32_t attributes; |
| 77 | bool mpidr_valid; |
| 78 | uint64_t mpidr; |
| 79 | }; |
| 80 | |
| 81 | /** |
| 82 | * Partition Device region as described in FFA v1.0 spec, Table 11 |
| 83 | */ |
| 84 | struct device_region { |
| 85 | /** Device base PA - mandatory */ |
| 86 | uintptr_t base_address; |
| 87 | /** Page count - mandatory */ |
| 88 | uint32_t page_count; |
| 89 | /** Memory attributes - mandatory */ |
| 90 | uint32_t attributes; |
| 91 | /** List of physical interrupt ID's and their attributes - optional */ |
| 92 | struct interrupt_info interrupts[PARTITION_MAX_INTERRUPTS_PER_DEVICE]; |
| 93 | /** Count of physical interrupts - optional */ |
| 94 | uint8_t interrupt_count; |
| 95 | /** SMMU ID - optional */ |
| 96 | uint32_t smmu_id; |
| 97 | /** Count of Stream IDs assigned to device - optional */ |
| 98 | uint8_t stream_count; |
| 99 | /** List of Stream IDs assigned to device - optional */ |
| 100 | uint32_t stream_ids[PARTITION_MAX_STREAMS_PER_DEVICE]; |
| 101 | /** Exclusive access to an endpoint - optional */ |
| 102 | bool exclusive_access; |
| 103 | /** Name of Device region - optional */ |
| 104 | struct string name; |
| 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * RX/TX buffer, reference to memory-region entries that describe RX/TX |
| 109 | * buffers in partition manifest. |
| 110 | */ |
| 111 | struct rx_tx { |
| 112 | bool available; |
| 113 | uint32_t rx_phandle; |
| 114 | uint32_t tx_phandle; |
| 115 | struct memory_region *rx_buffer; |
| 116 | struct memory_region *tx_buffer; |
| 117 | }; |
| 118 | |
| 119 | /** |
| 120 | * Partition manifest as described in FF-A v1.0 spec section 3.1 |
| 121 | */ |
| 122 | struct ffa_partition_manifest { |
| 123 | /** FF-A expected version - mandatory */ |
| 124 | uint32_t ffa_version; |
| 125 | /** UUID - mandatory */ |
| 126 | struct ffa_uuid uuid; |
| 127 | /** Partition id - optional */ |
| 128 | ffa_vm_id_t id; |
| 129 | /** Aux ids for mem transactions - optional */ |
| 130 | ffa_vm_id_t aux_id; |
| 131 | |
| 132 | /* NOTE: optional name field maps to VM debug_name field */ |
| 133 | |
| 134 | /** mandatory */ |
| 135 | ffa_vcpu_count_t execution_ctx_count; |
| 136 | /** EL1 or secure EL1, secure EL0 - mandatory */ |
| 137 | enum run_time_el run_time_el; |
| 138 | /** AArch32 / AArch64 - mandatory */ |
| 139 | enum execution_state execution_state; |
| 140 | /** optional */ |
| 141 | uintpaddr_t load_addr; |
| 142 | /** optional */ |
| 143 | size_t ep_offset; |
| 144 | /** 4/16/64KB - optional */ |
| 145 | enum xlat_granule xlat_granule; |
| 146 | /** Register id from w0/x0-w3/x3 - optional. */ |
| 147 | uint32_t gp_register_num; |
| 148 | /** |
| 149 | * Flags the presence of the optional IMPDEF node to define Partition's |
| 150 | * Boot Info. |
| 151 | */ |
| 152 | bool boot_info; |
| 153 | /** optional */ |
| 154 | uint16_t boot_order; |
| 155 | |
| 156 | /** Optional RX/TX buffers */ |
| 157 | struct rx_tx rxtx; |
| 158 | |
| 159 | /** mandatory - direct/indirect msg or both */ |
| 160 | uint8_t messaging_method; |
| 161 | /** mandatory - action in response to non secure interrupt */ |
| 162 | uint8_t ns_interrupts_action; |
| 163 | /** optional - managed exit signaled through vIRQ */ |
| 164 | bool me_signal_virq; |
| 165 | /** optional - receipt of notifications. */ |
| 166 | bool notification_support; |
| 167 | /** |
| 168 | * optional - power management messages bitfield. |
| 169 | * |
| 170 | * See [1] power-management-messages manifest field. |
| 171 | * |
| 172 | * The Hafnium supported combinations for a MP SP are: |
| 173 | * Bit 0 - relay PSCI cpu off message to the SP. |
| 174 | * Bit 3 - relay PSCI cpu on to the SP. |
| 175 | * |
| 176 | * [1] |
| 177 | * https://trustedfirmware-a.readthedocs.io/en/latest/components/ffa-manifest-binding.html#partition-properties |
| 178 | */ |
| 179 | uint32_t power_management; |
| 180 | /** optional */ |
| 181 | bool has_primary_scheduler; |
| 182 | /** optional - tuples SEPID/SMMUID/streamId */ |
| 183 | uint32_t stream_ep_ids[1]; |
| 184 | |
| 185 | /** Memory regions */ |
| 186 | uint16_t mem_region_count; |
| 187 | struct memory_region mem_regions[PARTITION_MAX_MEMORY_REGIONS]; |
| 188 | /** Device regions */ |
| 189 | uint16_t dev_region_count; |
| 190 | struct device_region dev_regions[PARTITION_MAX_DEVICE_REGIONS]; |
| 191 | /** optional - action in response to Other-Secure interrupt */ |
| 192 | uint8_t other_s_interrupts_action; |
| 193 | }; |