Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 1 | /* |
Andrew Walbran | 692b325 | 2019-03-07 15:51:31 +0000 | [diff] [blame] | 2 | * Copyright 2018 The Hafnium Authors. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 3 | * |
Andrew Walbran | e959ec1 | 2020-06-17 15:01:09 +0100 | [diff] [blame] | 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. |
Andrew Scull | 1883487 | 2018-10-12 11:48:09 +0100 | [diff] [blame] | 7 | */ |
| 8 | |
Andrew Scull | fbc938a | 2018-08-20 14:09:28 +0100 | [diff] [blame] | 9 | #pragma once |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 10 | |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 11 | #include <stdatomic.h> |
| 12 | |
Olivier Deprez | febf9e6 | 2023-03-02 15:44:35 +0100 | [diff] [blame] | 13 | #include "hf/arch/vm/vm.h" |
Andrew Walbran | 1f32e72 | 2019-06-07 17:57:26 +0100 | [diff] [blame] | 14 | |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 15 | #include "hf/cpu.h" |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 16 | #include "hf/ffa_partition_manifest.h" |
Madhukar Pappireddy | 464f246 | 2021-08-03 11:23:07 -0500 | [diff] [blame] | 17 | #include "hf/interrupt_desc.h" |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 18 | #include "hf/list.h" |
Andrew Scull | 18c78fc | 2018-08-20 12:57:41 +0100 | [diff] [blame] | 19 | #include "hf/mm.h" |
Wedson Almeida Filho | 22d5eaa | 2018-12-16 00:38:49 +0000 | [diff] [blame] | 20 | #include "hf/mpool.h" |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 21 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 22 | #include "vmapi/hf/ffa.h" |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 23 | |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 24 | #define MAX_SMCS 32 |
Madhukar Pappireddy | 464f246 | 2021-08-03 11:23:07 -0500 | [diff] [blame] | 25 | #define VM_MANIFEST_MAX_INTERRUPTS 32 |
Andrew Walbran | c1ad4ce | 2019-05-09 11:41:39 +0100 | [diff] [blame] | 26 | |
Madhukar Pappireddy | 5c04a38 | 2022-12-28 11:29:26 -0600 | [diff] [blame] | 27 | /** Action for Other-Secure interrupts by SPMC. */ |
| 28 | #define OTHER_S_INT_ACTION_QUEUED 0 |
| 29 | #define OTHER_S_INT_ACTION_SIGNALED 1 |
| 30 | |
Andrew Walbran | a36f759 | 2019-12-13 18:43:38 +0000 | [diff] [blame] | 31 | /** |
Olivier Deprez | 2013775 | 2023-02-07 10:55:35 +0100 | [diff] [blame] | 32 | * Power management bifields stating which messages a VM is willing to be |
| 33 | * notified about. |
| 34 | */ |
| 35 | #define VM_POWER_MANAGEMENT_CPU_OFF_SHIFT (0) |
| 36 | #define VM_POWER_MANAGEMENT_CPU_ON_SHIFT (3) |
| 37 | |
| 38 | /** |
J-Alves | e8c8c2b | 2022-12-16 15:34:48 +0000 | [diff] [blame] | 39 | * The state of an RX buffer, as defined by FF-A v1.1 EAC0 specification. |
| 40 | * It is used to implement ownership rules, as defined in the section 6.2.2.4.2. |
Andrew Walbran | a36f759 | 2019-12-13 18:43:38 +0000 | [diff] [blame] | 41 | * |
J-Alves | e8c8c2b | 2022-12-16 15:34:48 +0000 | [diff] [blame] | 42 | * EMPTY is the initial state. It is set by default to the endpoints at the |
| 43 | * virtual instance. |
| 44 | * The follow state transitions are possible: |
| 45 | * * EMPTY => FULL: message sent to a partition. Ownership given to the |
| 46 | * partition. |
| 47 | * * EMPTY => OTHER_WORLD_OWNED: This state transition only applies to NWd VMs. |
| 48 | * Used by the SPMC or Hypervisor to track that ownership of the RX buffer |
| 49 | * belong to the other world: |
| 50 | * - The Hypervisor does this state transition after forwarding |
| 51 | * FFA_RXTX_MAP call to the SPMC, for it to map a VM's RXTX buffers into SPMC's |
| 52 | * translation regime. |
| 53 | * - SPMC was previously given ownership of the VM's RX buffer, after the |
| 54 | * FFA_RXTX_MAP interface has been successfully forwarded to it. The SPMC does |
| 55 | * this state transition, when handling a successful FFA_RX_ACQUIRE, assigning |
| 56 | * ownership to the hypervisor. |
| 57 | * * FULL => EMPTY: Partition received an RX buffer full notification, consumed |
| 58 | * the content of buffers, and called FFA_RX_RELEASE or FFA_MSG_WAIT. SPMC or |
| 59 | * Hypervisor's ownership reestablished. |
| 60 | * * OTHER_WORLD_OWNED => EMPTY: VM called FFA_RX_RELEASE, the hypervisor |
| 61 | * forwarded it to the SPMC, which reestablishes ownership of the VM's buffer. |
| 62 | * SPs should never have their buffers state set to OTHER_WORLD_OWNED. |
Andrew Walbran | a36f759 | 2019-12-13 18:43:38 +0000 | [diff] [blame] | 63 | */ |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 64 | enum mailbox_state { |
Andrew Walbran | c3910f7 | 2018-11-27 14:24:36 +0000 | [diff] [blame] | 65 | /** There is no message in the mailbox. */ |
Andrew Scull | d6ee110 | 2019-04-05 22:12:42 +0100 | [diff] [blame] | 66 | MAILBOX_STATE_EMPTY, |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 67 | |
Andrew Walbran | c3910f7 | 2018-11-27 14:24:36 +0000 | [diff] [blame] | 68 | /** There is a message in the mailbox that is waiting for a reader. */ |
J-Alves | e8c8c2b | 2022-12-16 15:34:48 +0000 | [diff] [blame] | 69 | MAILBOX_STATE_FULL, |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 70 | |
J-Alves | e8c8c2b | 2022-12-16 15:34:48 +0000 | [diff] [blame] | 71 | /** |
| 72 | * In the SPMC, it means the Hypervisor/OS Kernel owns the RX buffer. |
| 73 | * In the Hypervisor, it means the SPMC owns the Rx buffer. |
| 74 | */ |
| 75 | MAILBOX_STATE_OTHER_WORLD_OWNED, |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 78 | struct mailbox { |
| 79 | enum mailbox_state state; |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 80 | void *recv; |
| 81 | const void *send; |
| 82 | |
| 83 | /** The ID of the VM which sent the message currently in `recv`. */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 84 | ffa_id_t recv_sender; |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 85 | |
| 86 | /** The size of the message currently in `recv`. */ |
| 87 | uint32_t recv_size; |
| 88 | |
Andrew Walbran | e7ad3c0 | 2019-12-24 17:03:04 +0000 | [diff] [blame] | 89 | /** |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 90 | * The FF-A function ID to use to deliver the message currently in |
Andrew Walbran | e7ad3c0 | 2019-12-24 17:03:04 +0000 | [diff] [blame] | 91 | * `recv`. |
| 92 | */ |
| 93 | uint32_t recv_func; |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 94 | }; |
| 95 | |
J-Alves | 4ef6e84 | 2021-03-18 12:47:01 +0000 | [diff] [blame] | 96 | struct notifications_state { |
| 97 | /** |
| 98 | * To keep track of the notifications pending. |
| 99 | * Set on call to FFA_NOTIFICATION_SET, and cleared on call to |
| 100 | * FFA_NOTIFICATION_GET. |
| 101 | */ |
| 102 | ffa_notifications_bitmap_t pending; |
| 103 | |
| 104 | /** |
| 105 | * Set on FFA_NOTIFICATION_INFO_GET to keep track of the notifications |
| 106 | * whose information has been retrieved by the referred ABI. |
| 107 | * Cleared on call to FFA_NOTIFICATION_GET. |
| 108 | */ |
| 109 | ffa_notifications_bitmap_t info_get_retrieved; |
| 110 | }; |
| 111 | |
| 112 | struct notifications { |
| 113 | /** |
| 114 | * The following array maps the notifications to the bound FF-A |
| 115 | * endpoint. |
| 116 | * The index in the bindings array relates to the notification |
| 117 | * ID, and bit position in 'ffa_notifications_bitmap_t'. |
| 118 | */ |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 119 | ffa_id_t bindings_sender_id[MAX_FFA_NOTIFICATIONS]; |
J-Alves | 4ef6e84 | 2021-03-18 12:47:01 +0000 | [diff] [blame] | 120 | ffa_notifications_bitmap_t bindings_per_vcpu; |
| 121 | |
Raghu Krishnamurthy | f5fec20 | 2022-09-30 07:25:10 -0700 | [diff] [blame] | 122 | /* The index of the array below relates to the ID of the VCPU. |
| 123 | * This is a dynamically allocated array of struct |
| 124 | * notifications_state and has as many entries as vcpu_count. |
| 125 | */ |
| 126 | struct notifications_state *per_vcpu; |
J-Alves | 4ef6e84 | 2021-03-18 12:47:01 +0000 | [diff] [blame] | 127 | struct notifications_state global; |
| 128 | }; |
| 129 | |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 130 | /** |
| 131 | * The following enum relates to a state machine to guide the insertion of |
| 132 | * IDs in the respective list as a result of a FFA_NOTIFICATION_INFO_GET call. |
| 133 | * As per the FF-A v1.1 specification, the return of the interface |
| 134 | * FFA_NOTIFICATION_INFO_GET, is a list of 16-bit values, regarding the VM ID |
| 135 | * and VCPU IDs of those with pending notifications. |
| 136 | * The overall list, is composed of "sub-lists", that starts with the VM ID, and |
| 137 | * can follow with up to 3 more VCPU IDs. A VM can have multiple 'sub-lists'. |
| 138 | * The states are traversed on a per VM basis, and should help with filling the |
| 139 | * list of IDs. |
| 140 | * |
| 141 | * INIT is the initial state. The following state transitions are possible: |
| 142 | * * INIT => INSERTING: no list has been created for the VM prior. There are |
| 143 | * notifications pending and VM ID should be inserted first. If it regards to |
| 144 | * a per VCPU notification the VCPU ID should follow. Only VCPU IDs should be |
| 145 | * inserted from this point, until reaching "sub-list" size limit. |
| 146 | * * INIT => FULL: There is no space in the ID list to insert IDs. |
| 147 | * * INSERTING => STARTING_NEW: list has been created. Adding only VCPU IDs, |
| 148 | * however "sub-list" limit has been reached. If there are more pending per VCPU |
| 149 | * notifications pending for the VM, a new list should be created starting with |
| 150 | * VM ID. |
| 151 | * * INSERTING => FULL: There is no space in the ID list to insert IDs. |
| 152 | * * STARTING_NEW => INSERTING: Started a new 'sub-list' for the given VM, for |
| 153 | * the remaining pending per VCPU notifications, only the VCPU ID should be |
| 154 | * inserted. |
| 155 | * * STARTING_NEW => FULL: There is no space in the ID list to insert IDs. |
| 156 | */ |
| 157 | enum notifications_info_get_state { |
| 158 | INIT, |
| 159 | INSERTING, |
| 160 | STARTING_NEW, |
| 161 | FULL, |
| 162 | }; |
| 163 | |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 164 | struct smc_whitelist { |
| 165 | uint32_t smcs[MAX_SMCS]; |
| 166 | uint16_t smc_count; |
| 167 | bool permissive; |
| 168 | }; |
| 169 | |
Karl Meakin | 2ad6b66 | 2024-07-29 20:45:40 +0100 | [diff] [blame] | 170 | /* NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) */ |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 171 | struct vm { |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 172 | ffa_id_t id; |
Kathleen Capella | 422b10b | 2023-06-30 18:28:27 -0400 | [diff] [blame] | 173 | struct ffa_uuid uuids[PARTITION_MAX_UUIDS]; |
Karl Meakin | 0e617d9 | 2024-04-05 12:55:22 +0100 | [diff] [blame] | 174 | enum ffa_version ffa_version; |
Karl Meakin | 6eeec8e | 2024-03-07 18:07:20 +0000 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * Whether this FF-A instance has negotiated an FF-A version through a |
| 178 | * call to FFA_VERSION. Once the version has been negotiated, it is an |
| 179 | * error to attempt to change it through another call to FFA_VERSION. |
| 180 | */ |
| 181 | bool ffa_version_negotiated; |
| 182 | |
Andrew Scull | ae9962e | 2019-10-03 16:51:16 +0100 | [diff] [blame] | 183 | struct smc_whitelist smc_whitelist; |
| 184 | |
Andrew Walbran | 0d7a068 | 2018-12-06 16:48:47 +0000 | [diff] [blame] | 185 | /** See api.c for the partial ordering on locks. */ |
Wedson Almeida Filho | 2f94ec1 | 2018-07-26 16:00:48 +0100 | [diff] [blame] | 186 | struct spinlock lock; |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 187 | ffa_vcpu_count_t vcpu_count; |
Raghu Krishnamurthy | 30aabd6 | 2022-09-17 21:41:00 -0700 | [diff] [blame] | 188 | struct vcpu *vcpus; |
Andrew Scull | 89a7524 | 2018-08-06 17:04:55 +0100 | [diff] [blame] | 189 | struct mm_ptable ptable; |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * Set of page tables used for defining the peripheral's secure |
| 193 | * IPA space, in the context of SPMC. |
| 194 | */ |
| 195 | struct mm_ptable iommu_ptables[PARTITION_MAX_DMA_DEVICES]; |
| 196 | /** Count of DMA devices assigned to this VM. */ |
| 197 | uint8_t dma_device_count; |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 198 | struct mailbox mailbox; |
J-Alves | 4ef6e84 | 2021-03-18 12:47:01 +0000 | [diff] [blame] | 199 | |
| 200 | struct { |
| 201 | /** |
| 202 | * State structures for notifications coming from VMs or coming |
| 203 | * from SPs. Both fields are maintained by the SPMC. |
| 204 | * The hypervisor ignores the 'from_sp' field, given VM |
| 205 | * notifications from SPs are managed by the SPMC. |
| 206 | */ |
| 207 | struct notifications from_vm; |
| 208 | struct notifications from_sp; |
J-Alves | 52578f8 | 2022-03-25 12:30:47 +0000 | [diff] [blame] | 209 | struct notifications_state framework; |
J-Alves | 4ef6e84 | 2021-03-18 12:47:01 +0000 | [diff] [blame] | 210 | bool enabled; |
J-Alves | 6e2abc6 | 2021-12-02 14:58:56 +0000 | [diff] [blame] | 211 | bool npi_injected; |
J-Alves | 4ef6e84 | 2021-03-18 12:47:01 +0000 | [diff] [blame] | 212 | } notifications; |
| 213 | |
Karl Meakin | a603e08 | 2024-08-02 17:57:27 +0100 | [diff] [blame] | 214 | /** |
| 215 | * Whether this partition is subscribed to receiving VM created/VM |
| 216 | * destroyed messages. |
| 217 | */ |
| 218 | struct { |
| 219 | bool vm_created; |
| 220 | bool vm_destroyed; |
| 221 | } vm_availability_messages; |
| 222 | |
Andrew Scull | 9726c25 | 2019-01-23 13:44:19 +0000 | [diff] [blame] | 223 | atomic_bool aborting; |
Andrew Walbran | 1f32e72 | 2019-06-07 17:57:26 +0100 | [diff] [blame] | 224 | |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 225 | /** |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 226 | * Booting parameters (FF-A SP partitions). |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 227 | */ |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 228 | uint16_t boot_order; |
J-Alves | 7d38f7b | 2022-04-13 13:22:30 +0100 | [diff] [blame] | 229 | |
| 230 | /** Entries to pass boot data to the VM. */ |
| 231 | struct { |
| 232 | uint32_t gp_register_num; |
| 233 | ipaddr_t blob_addr; |
| 234 | } boot_info; |
| 235 | |
Kathleen Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 236 | uint16_t messaging_method; |
Madhukar Pappireddy | 8415405 | 2022-06-21 18:30:25 -0500 | [diff] [blame] | 237 | |
| 238 | /** |
| 239 | * Action specified by a Partition through the manifest in response to |
| 240 | * non secure interrupt. |
| 241 | */ |
| 242 | uint8_t ns_interrupts_action; |
Madhukar Pappireddy | 5c04a38 | 2022-12-28 11:29:26 -0600 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * Action specified by a Partition through the manifest in response to |
| 246 | * Other-S-Int. |
| 247 | */ |
| 248 | uint8_t other_s_interrupts_action; |
Madhukar Pappireddy | 046dad0 | 2022-06-21 18:43:33 -0500 | [diff] [blame] | 249 | bool me_signal_virq; |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 250 | |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 251 | /** |
Olivier Deprez | a15f235 | 2022-09-26 09:17:24 +0200 | [diff] [blame] | 252 | * Bitmask reporting the power management events that a partition |
| 253 | * requests to the signaled about. |
| 254 | */ |
| 255 | uint32_t power_management; |
| 256 | |
| 257 | /** |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 258 | * Secondary entry point supplied by FFA_SECONDARY_EP_REGISTER used |
| 259 | * for cold and warm boot of SP execution contexts. |
| 260 | */ |
| 261 | ipaddr_t secondary_ep; |
| 262 | |
Andrew Walbran | 1f32e72 | 2019-06-07 17:57:26 +0100 | [diff] [blame] | 263 | /** Arch-specific VM information. */ |
| 264 | struct arch_vm arch; |
Raghu Krishnamurthy | cd1eceb | 2021-01-04 12:20:48 -0800 | [diff] [blame] | 265 | bool el0_partition; |
Madhukar Pappireddy | 464f246 | 2021-08-03 11:23:07 -0500 | [diff] [blame] | 266 | |
| 267 | /** Interrupt descriptor */ |
| 268 | struct interrupt_descriptor interrupt_desc[VM_MANIFEST_MAX_INTERRUPTS]; |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 269 | |
| 270 | /* List entry pointing to the next VM in the boot order list. */ |
| 271 | struct list_entry boot_list_node; |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | /** Encapsulates a VM whose lock is held. */ |
| 275 | struct vm_locked { |
| 276 | struct vm *vm; |
Wedson Almeida Filho | 987c0ff | 2018-06-20 16:34:38 +0100 | [diff] [blame] | 277 | }; |
| 278 | |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 279 | /** Container for two vm_locked structures */ |
| 280 | struct two_vm_locked { |
| 281 | struct vm_locked vm1; |
| 282 | struct vm_locked vm2; |
| 283 | }; |
| 284 | |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 285 | struct vm *vm_init(ffa_id_t id, ffa_vcpu_count_t vcpu_count, |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 286 | struct mpool *ppool, bool el0_partition, |
| 287 | uint8_t dma_device_count); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 288 | bool vm_init_next(ffa_vcpu_count_t vcpu_count, struct mpool *ppool, |
Madhukar Pappireddy | 070f49e | 2024-01-12 13:02:27 -0600 | [diff] [blame] | 289 | struct vm **new_vm, bool el0_partition, |
| 290 | uint8_t dma_device_count); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 291 | ffa_vm_count_t vm_get_count(void); |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 292 | struct vm *vm_find(ffa_id_t id); |
| 293 | struct vm_locked vm_find_locked(ffa_id_t id); |
Fuad Tabba | e4efcc3 | 2020-07-16 15:37:27 +0100 | [diff] [blame] | 294 | struct vm *vm_find_index(uint16_t index); |
Andrew Walbran | 7e932bd | 2019-04-29 16:47:06 +0100 | [diff] [blame] | 295 | struct vm_locked vm_lock(struct vm *vm); |
Jose Marinho | 75509b4 | 2019-04-09 09:34:59 +0100 | [diff] [blame] | 296 | struct two_vm_locked vm_lock_both(struct vm *vm1, struct vm *vm2); |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 297 | void vm_unlock(struct vm_locked *locked); |
Karl Meakin | e143080 | 2024-03-06 14:08:11 +0000 | [diff] [blame] | 298 | struct two_vm_locked vm_lock_both_in_order(struct vm_locked vm1, |
| 299 | struct vm *vm2); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 300 | struct vcpu *vm_get_vcpu(struct vm *vm, ffa_vcpu_index_t vcpu_index); |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 301 | bool vm_id_is_current_world(ffa_id_t vm_id); |
J-Alves | 122f1a1 | 2022-12-12 15:55:42 +0000 | [diff] [blame] | 302 | bool vm_is_mailbox_busy(struct vm_locked to); |
J-Alves | e8c8c2b | 2022-12-16 15:34:48 +0000 | [diff] [blame] | 303 | bool vm_is_mailbox_other_world_owned(struct vm_locked to); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 304 | bool vm_identity_map(struct vm_locked vm_locked, paddr_t begin, paddr_t end, |
| 305 | uint32_t mode, struct mpool *ppool, ipaddr_t *ipa); |
| 306 | bool vm_identity_prepare(struct vm_locked vm_locked, paddr_t begin, paddr_t end, |
| 307 | uint32_t mode, struct mpool *ppool); |
| 308 | void vm_identity_commit(struct vm_locked vm_locked, paddr_t begin, paddr_t end, |
| 309 | uint32_t mode, struct mpool *ppool, ipaddr_t *ipa); |
| 310 | bool vm_unmap(struct vm_locked vm_locked, paddr_t begin, paddr_t end, |
| 311 | struct mpool *ppool); |
Raghu Krishnamurthy | 7ad3d14 | 2021-03-28 00:47:35 -0700 | [diff] [blame] | 312 | void vm_ptable_defrag(struct vm_locked vm_locked, struct mpool *ppool); |
Andrew Scull | 3c25745 | 2019-11-26 13:32:50 +0000 | [diff] [blame] | 313 | bool vm_unmap_hypervisor(struct vm_locked vm_locked, struct mpool *ppool); |
J-Alves | b37fd08 | 2020-10-22 12:29:21 +0100 | [diff] [blame] | 314 | |
Raghu Krishnamurthy | ea195fa | 2021-02-12 23:29:00 -0800 | [diff] [blame] | 315 | bool vm_mem_get_mode(struct vm_locked vm_locked, ipaddr_t begin, ipaddr_t end, |
| 316 | uint32_t *mode); |
Madhukar Pappireddy | 0e57d3d | 2023-10-11 15:49:05 -0500 | [diff] [blame] | 317 | bool vm_iommu_mm_identity_map(struct vm_locked vm_locked, paddr_t begin, |
| 318 | paddr_t end, uint32_t mode, struct mpool *ppool, |
| 319 | ipaddr_t *ipa, uint8_t dma_device_id); |
| 320 | |
Raghu Krishnamurthy | f5fec20 | 2022-09-30 07:25:10 -0700 | [diff] [blame] | 321 | void vm_notifications_init(struct vm *vm, ffa_vcpu_count_t vcpu_count, |
| 322 | struct mpool *ppool); |
J-Alves | 6665225 | 2022-07-06 09:49:51 +0100 | [diff] [blame] | 323 | bool vm_mailbox_state_busy(struct vm_locked vm_locked); |
J-Alves | a0f317d | 2021-06-09 13:31:59 +0100 | [diff] [blame] | 324 | bool vm_are_notifications_pending(struct vm_locked vm_locked, bool from_vm, |
| 325 | ffa_notifications_bitmap_t notifications); |
J-Alves | e8c8c2b | 2022-12-16 15:34:48 +0000 | [diff] [blame] | 326 | bool vm_are_fwk_notifications_pending(struct vm_locked vm_locked); |
J-Alves | 7461ef2 | 2021-10-18 17:21:33 +0100 | [diff] [blame] | 327 | bool vm_are_global_notifications_pending(struct vm_locked vm_locked); |
| 328 | bool vm_are_per_vcpu_notifications_pending(struct vm_locked vm_locked, |
| 329 | ffa_vcpu_index_t vcpu_id); |
J-Alves | 09ff9d8 | 2021-11-02 11:55:20 +0000 | [diff] [blame] | 330 | bool vm_are_notifications_enabled(struct vm *vm); |
| 331 | bool vm_locked_are_notifications_enabled(struct vm_locked vm_locked); |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 332 | bool vm_notifications_validate_per_vcpu(struct vm_locked vm_locked, |
| 333 | bool is_from_vm, bool is_per_vcpu, |
| 334 | ffa_notifications_bitmap_t notif); |
| 335 | bool vm_notifications_validate_bound_sender( |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 336 | struct vm_locked vm_locked, bool is_from_vm, ffa_id_t sender_id, |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 337 | ffa_notifications_bitmap_t notifications); |
| 338 | bool vm_notifications_validate_binding(struct vm_locked vm_locked, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 339 | bool is_from_vm, ffa_id_t sender_id, |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 340 | ffa_notifications_bitmap_t notifications, |
| 341 | bool is_per_vcpu); |
| 342 | void vm_notifications_update_bindings(struct vm_locked vm_locked, |
J-Alves | 19e20cf | 2023-08-02 12:48:55 +0100 | [diff] [blame] | 343 | bool is_from_vm, ffa_id_t sender_id, |
J-Alves | c003a7a | 2021-03-18 13:06:53 +0000 | [diff] [blame] | 344 | ffa_notifications_bitmap_t notifications, |
| 345 | bool is_per_vcpu); |
J-Alves | 5a16c96 | 2022-03-25 12:32:51 +0000 | [diff] [blame] | 346 | void vm_notifications_partition_set_pending( |
| 347 | struct vm_locked vm_locked, bool is_from_vm, |
| 348 | ffa_notifications_bitmap_t notifications, ffa_vcpu_index_t vcpu_id, |
| 349 | bool is_per_vcpu); |
J-Alves | 5136dda | 2022-03-25 12:26:38 +0000 | [diff] [blame] | 350 | ffa_notifications_bitmap_t vm_notifications_partition_get_pending( |
| 351 | struct vm_locked vm_locked, bool is_from_vm, ffa_vcpu_index_t vcpu_id); |
J-Alves | 14163a7 | 2022-03-25 14:01:34 +0000 | [diff] [blame] | 352 | void vm_notifications_framework_set_pending( |
| 353 | struct vm_locked vm_locked, ffa_notifications_bitmap_t notifications); |
J-Alves | 663682a | 2022-03-25 13:56:51 +0000 | [diff] [blame] | 354 | ffa_notifications_bitmap_t vm_notifications_framework_get_pending( |
| 355 | struct vm_locked vm_locked); |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 356 | void vm_notifications_info_get_pending( |
| 357 | struct vm_locked vm_locked, bool is_from_vm, uint16_t *ids, |
| 358 | uint32_t *ids_count, uint32_t *lists_sizes, uint32_t *lists_count, |
Karl Meakin | 2ad6b66 | 2024-07-29 20:45:40 +0100 | [diff] [blame] | 359 | uint32_t ids_max_count, |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 360 | enum notifications_info_get_state *info_get_state); |
J-Alves | fe23ebe | 2021-10-13 16:07:07 +0100 | [diff] [blame] | 361 | bool vm_notifications_pending_not_retrieved_by_scheduler(void); |
| 362 | bool vm_is_notifications_pending_count_zero(void); |
J-Alves | c8e8a22 | 2021-06-08 17:33:52 +0100 | [diff] [blame] | 363 | bool vm_notifications_info_get(struct vm_locked vm_locked, uint16_t *ids, |
| 364 | uint32_t *ids_count, uint32_t *lists_sizes, |
Karl Meakin | 2ad6b66 | 2024-07-29 20:45:40 +0100 | [diff] [blame] | 365 | uint32_t *lists_count, uint32_t ids_max_count); |
Kathleen Capella | f71dee4 | 2023-08-08 16:24:14 -0400 | [diff] [blame] | 366 | bool vm_supports_messaging_method(struct vm *vm, uint16_t messaging_method); |
J-Alves | 6e2abc6 | 2021-12-02 14:58:56 +0000 | [diff] [blame] | 367 | void vm_notifications_set_npi_injected(struct vm_locked vm_locked, |
| 368 | bool npi_injected); |
| 369 | bool vm_notifications_is_npi_injected(struct vm_locked vm_locked); |
J-Alves | 7d38f7b | 2022-04-13 13:22:30 +0100 | [diff] [blame] | 370 | void vm_set_boot_info_gp_reg(struct vm *vm, struct vcpu *vcpu); |
Olivier Deprez | 2013775 | 2023-02-07 10:55:35 +0100 | [diff] [blame] | 371 | |
| 372 | /** |
| 373 | * Returns true if the VM requested to receive cpu on power management |
| 374 | * events. |
| 375 | */ |
| 376 | static inline bool vm_power_management_cpu_on_requested(struct vm *vm) |
| 377 | { |
| 378 | return (vm->power_management & |
| 379 | (UINT32_C(1) << VM_POWER_MANAGEMENT_CPU_ON_SHIFT)) != 0; |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Returns true if the VM requested to receive cpu off power management |
| 384 | * events. |
| 385 | */ |
| 386 | static inline bool vm_power_management_cpu_off_requested(struct vm *vm) |
| 387 | { |
| 388 | return (vm->power_management & |
| 389 | (UINT32_C(1) << VM_POWER_MANAGEMENT_CPU_OFF_SHIFT)) != 0; |
| 390 | } |
Madhukar Pappireddy | 18c6eb7 | 2023-08-21 12:16:18 -0500 | [diff] [blame] | 391 | |
Karl Meakin | 8204182 | 2024-05-20 11:14:34 +0100 | [diff] [blame] | 392 | /* Return true if `vm` is a UP. */ |
| 393 | static inline bool vm_is_up(const struct vm *vm) |
| 394 | { |
| 395 | return vm->vcpu_count == 1; |
| 396 | } |
| 397 | |
| 398 | /* Return true if `vm` is a MP. */ |
| 399 | static inline bool vm_is_mp(const struct vm *vm) |
| 400 | { |
| 401 | return vm->vcpu_count > 1; |
| 402 | } |
| 403 | |
Karl Meakin | 5e99699 | 2024-05-20 11:27:07 +0100 | [diff] [blame] | 404 | /* Return true if `vm` is the primary VM. */ |
| 405 | static inline bool vm_is_primary(const struct vm *vm) |
| 406 | { |
| 407 | return vm->id == HF_PRIMARY_VM_ID; |
| 408 | } |
| 409 | |
Daniel Boulby | f3cf28c | 2024-08-22 10:46:23 +0100 | [diff] [blame] | 410 | /** |
| 411 | * Convert a CPU ID for a secondary VM to the corresponding vCPU index. |
| 412 | */ |
| 413 | static inline ffa_vcpu_index_t vcpu_id_to_index(cpu_id_t vcpu_id) |
| 414 | { |
| 415 | /* For now we use indices as IDs. */ |
| 416 | return vcpu_id; |
| 417 | } |
| 418 | |
Madhukar Pappireddy | 18c6eb7 | 2023-08-21 12:16:18 -0500 | [diff] [blame] | 419 | struct interrupt_descriptor *vm_interrupt_set_target_mpidr( |
| 420 | struct vm_locked vm_locked, uint32_t id, uint32_t target_mpidr); |
| 421 | struct interrupt_descriptor *vm_interrupt_set_sec_state( |
| 422 | struct vm_locked vm_locked, uint32_t id, uint32_t sec_state); |
Madhukar Pappireddy | 938faaf | 2023-07-31 17:56:55 -0500 | [diff] [blame] | 423 | struct interrupt_descriptor *vm_interrupt_set_enable(struct vm_locked vm_locked, |
| 424 | uint32_t id, bool enable); |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 425 | |
| 426 | void vm_update_boot(struct vm *vm); |
| 427 | struct vm *vm_get_boot_vm(void); |
Madhukar Pappireddy | a81f541 | 2024-11-25 09:46:48 -0600 | [diff] [blame^] | 428 | struct vm *vm_get_boot_vm_secondary_core(void); |
Madhukar Pappireddy | a49ba16 | 2024-11-25 09:40:45 -0600 | [diff] [blame] | 429 | struct vm *vm_get_next_boot(struct vm *vm); |
Madhukar Pappireddy | a81f541 | 2024-11-25 09:46:48 -0600 | [diff] [blame^] | 430 | struct vm *vm_get_next_boot_secondary_core(struct vm *vm); |