Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 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. |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #pragma once |
| 10 | |
Olivier Deprez | c5203fb | 2022-09-29 13:49:24 +0200 | [diff] [blame] | 11 | #include "hf/arch/types.h" |
| 12 | |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 13 | #include "hf/addr.h" |
Daniel Boulby | 801f8ef | 2022-06-27 14:21:01 +0100 | [diff] [blame] | 14 | #include "hf/interrupt_desc.h" |
J-Alves | 67f5ba3 | 2024-09-27 18:07:11 +0100 | [diff] [blame^] | 15 | #include "hf/list.h" |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 16 | #include "hf/spinlock.h" |
| 17 | |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 18 | #include "vmapi/hf/ffa.h" |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 19 | |
Madhukar Pappireddy | 8415405 | 2022-06-21 18:30:25 -0500 | [diff] [blame] | 20 | /** Action for non secure interrupt by SPMC. */ |
| 21 | #define NS_ACTION_QUEUED 0 |
| 22 | #define NS_ACTION_ME 1 |
| 23 | #define NS_ACTION_SIGNALED 2 |
Madhukar Pappireddy | 8415405 | 2022-06-21 18:30:25 -0500 | [diff] [blame] | 24 | |
Madhukar Pappireddy | 32913cb | 2024-07-19 13:04:05 -0500 | [diff] [blame] | 25 | /** Maximum number of pending virtual interrupts in the queue per vCPU. */ |
| 26 | #define VINT_QUEUE_MAX 5 |
| 27 | |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 28 | enum vcpu_state { |
Fuad Tabba | b0ef2a4 | 2019-12-19 11:19:25 +0000 | [diff] [blame] | 29 | /** The vCPU is switched off. */ |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 30 | VCPU_STATE_OFF, |
| 31 | |
Fuad Tabba | b0ef2a4 | 2019-12-19 11:19:25 +0000 | [diff] [blame] | 32 | /** The vCPU is currently running. */ |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 33 | VCPU_STATE_RUNNING, |
| 34 | |
Madhukar Pappireddy | b11e0d1 | 2021-08-02 19:44:35 -0500 | [diff] [blame] | 35 | /** The vCPU is waiting to be allocated CPU cycles to do work. */ |
| 36 | VCPU_STATE_WAITING, |
| 37 | |
| 38 | /** |
| 39 | * The vCPU is blocked and waiting for some work to complete on |
| 40 | * its behalf. |
| 41 | */ |
| 42 | VCPU_STATE_BLOCKED, |
| 43 | |
| 44 | /** The vCPU has been preempted by an interrupt. */ |
| 45 | VCPU_STATE_PREEMPTED, |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 46 | |
Fuad Tabba | b0ef2a4 | 2019-12-19 11:19:25 +0000 | [diff] [blame] | 47 | /** The vCPU is waiting for an interrupt. */ |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 48 | VCPU_STATE_BLOCKED_INTERRUPT, |
| 49 | |
Fuad Tabba | b0ef2a4 | 2019-12-19 11:19:25 +0000 | [diff] [blame] | 50 | /** The vCPU has aborted. */ |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 51 | VCPU_STATE_ABORTED, |
| 52 | }; |
| 53 | |
Madhukar Pappireddy | fe297a3 | 2022-06-21 16:42:13 -0500 | [diff] [blame] | 54 | /** Refer to section 7 of the FF-A v1.1 EAC0 spec. */ |
| 55 | enum partition_runtime_model { |
| 56 | RTM_NONE, |
| 57 | /** Runtime model for FFA_RUN. */ |
| 58 | RTM_FFA_RUN, |
| 59 | /** Runtime model for FFA_MSG_SEND_DIRECT_REQUEST. */ |
| 60 | RTM_FFA_DIR_REQ, |
| 61 | /** Runtime model for Secure Interrupt handling. */ |
| 62 | RTM_SEC_INTERRUPT, |
| 63 | /** Runtime model for SP Initialization. */ |
| 64 | RTM_SP_INIT, |
| 65 | }; |
| 66 | |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 67 | /** Refer to section 8.2.3 of the FF-A EAC0 spec. */ |
| 68 | enum schedule_mode { |
| 69 | NONE, |
| 70 | /** Normal world scheduled mode. */ |
| 71 | NWD_MODE, |
| 72 | /** SPMC scheduled mode. */ |
| 73 | SPMC_MODE, |
| 74 | }; |
| 75 | |
Madhukar Pappireddy | 32913cb | 2024-07-19 13:04:05 -0500 | [diff] [blame] | 76 | /* |
| 77 | * This queue is implemented as a circular buffer. The entries are managed on |
| 78 | * a First In First Out basis. |
| 79 | */ |
| 80 | struct interrupt_queue { |
| 81 | uint32_t vint_buffer[VINT_QUEUE_MAX]; |
| 82 | uint16_t head; |
| 83 | uint16_t tail; |
| 84 | }; |
| 85 | |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 86 | struct interrupts { |
| 87 | /** Bitfield keeping track of which interrupts are enabled. */ |
Daniel Boulby | 4ca50f0 | 2022-07-29 18:29:34 +0100 | [diff] [blame] | 88 | struct interrupt_bitmap interrupt_enabled; |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 89 | /** Bitfield keeping track of which interrupts are pending. */ |
Daniel Boulby | 4ca50f0 | 2022-07-29 18:29:34 +0100 | [diff] [blame] | 90 | struct interrupt_bitmap interrupt_pending; |
Manish Pandey | 35e452f | 2021-02-18 21:36:34 +0000 | [diff] [blame] | 91 | /** Bitfield recording the interrupt pin configuration. */ |
Daniel Boulby | 4ca50f0 | 2022-07-29 18:29:34 +0100 | [diff] [blame] | 92 | struct interrupt_bitmap interrupt_type; |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 93 | /** |
| 94 | * The number of interrupts which are currently both enabled and |
Manish Pandey | 35e452f | 2021-02-18 21:36:34 +0000 | [diff] [blame] | 95 | * pending. Count independently virtual IRQ and FIQ interrupt types |
| 96 | * i.e. the sum of the two counters is the number of bits set in |
| 97 | * interrupt_enable & interrupt_pending. |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 98 | */ |
Manish Pandey | 35e452f | 2021-02-18 21:36:34 +0000 | [diff] [blame] | 99 | uint32_t enabled_and_pending_irq_count; |
| 100 | uint32_t enabled_and_pending_fiq_count; |
Madhukar Pappireddy | 32913cb | 2024-07-19 13:04:05 -0500 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Partition Manager maintains a queue of pending virtual interrupts. |
| 104 | */ |
| 105 | struct interrupt_queue vint_q; |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | struct vcpu_fault_info { |
| 109 | ipaddr_t ipaddr; |
| 110 | vaddr_t vaddr; |
| 111 | vaddr_t pc; |
| 112 | uint32_t mode; |
| 113 | }; |
| 114 | |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 115 | struct call_chain { |
| 116 | /** Previous node in the SP call chain. */ |
| 117 | struct vcpu *prev_node; |
| 118 | |
| 119 | /** Next node in the SP call chain. */ |
| 120 | struct vcpu *next_node; |
| 121 | }; |
| 122 | |
Karl Meakin | c5cebbc | 2024-06-17 11:30:27 +0100 | [diff] [blame] | 123 | #define LOG_BUFFER_SIZE 256 |
| 124 | |
| 125 | struct log_buffer { |
| 126 | char chars[LOG_BUFFER_SIZE]; |
| 127 | uint16_t len; |
| 128 | }; |
| 129 | |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 130 | struct vcpu { |
| 131 | struct spinlock lock; |
| 132 | |
| 133 | /* |
| 134 | * The state is only changed in the context of the vCPU being run. This |
| 135 | * ensures the scheduler can easily keep track of the vCPU state as |
| 136 | * transitions are indicated by the return code from the run call. |
| 137 | */ |
| 138 | enum vcpu_state state; |
| 139 | |
| 140 | struct cpu *cpu; |
| 141 | struct vm *vm; |
| 142 | struct arch_regs regs; |
| 143 | struct interrupts interrupts; |
| 144 | |
Karl Meakin | c5cebbc | 2024-06-17 11:30:27 +0100 | [diff] [blame] | 145 | struct log_buffer log_buffer; |
| 146 | |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 147 | /* |
| 148 | * Determine whether the 'regs' field is available for use. This is set |
| 149 | * to false when a vCPU is about to run on a physical CPU, and is set |
Olivier Deprez | 3caed1c | 2021-02-05 12:07:36 +0100 | [diff] [blame] | 150 | * back to true when it is descheduled. This is not relevant for the |
| 151 | * primary VM vCPUs in the normal world (or the "other world VM" vCPUs |
| 152 | * in the secure world) as they are pinned to physical CPUs and there |
| 153 | * is no contention to take care of. |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 154 | */ |
| 155 | bool regs_available; |
Olivier Deprez | ee9d6a9 | 2019-11-26 09:14:11 +0000 | [diff] [blame] | 156 | |
| 157 | /* |
| 158 | * If the current vCPU is executing as a consequence of a |
Kathleen Capella | e468c11 | 2023-12-13 17:56:28 -0500 | [diff] [blame] | 159 | * direct request invocation, then this member holds the |
Olivier Deprez | ee9d6a9 | 2019-11-26 09:14:11 +0000 | [diff] [blame] | 160 | * originating VM ID from which the call originated. |
| 161 | * The value HF_INVALID_VM_ID implies the vCPU is not executing as |
Kathleen Capella | e468c11 | 2023-12-13 17:56:28 -0500 | [diff] [blame] | 162 | * a result of a prior direct request invocation. |
Olivier Deprez | ee9d6a9 | 2019-11-26 09:14:11 +0000 | [diff] [blame] | 163 | */ |
Kathleen Capella | e468c11 | 2023-12-13 17:56:28 -0500 | [diff] [blame] | 164 | struct { |
| 165 | /** |
| 166 | * Indicate whether request is via FFA_MSG_SEND_DIRECT_REQ2. |
| 167 | */ |
| 168 | bool is_ffa_req2; |
| 169 | ffa_id_t vm_id; |
| 170 | } direct_request_origin; |
Manish Pandey | a5f39fb | 2020-09-11 09:47:11 +0100 | [diff] [blame] | 171 | |
Madhukar Pappireddy | b11e0d1 | 2021-08-02 19:44:35 -0500 | [diff] [blame] | 172 | /** Determine whether partition is currently handling managed exit. */ |
Manish Pandey | a5f39fb | 2020-09-11 09:47:11 +0100 | [diff] [blame] | 173 | bool processing_managed_exit; |
Madhukar Pappireddy | f675bb6 | 2021-08-03 12:57:10 -0500 | [diff] [blame] | 174 | |
| 175 | /** |
Madhukar Pappireddy | f675bb6 | 2021-08-03 12:57:10 -0500 | [diff] [blame] | 176 | * Track current vCPU which got pre-empted when secure interrupt |
| 177 | * triggered. |
| 178 | */ |
| 179 | struct vcpu *preempted_vcpu; |
Madhukar Pappireddy | dd6fdfb | 2021-12-14 12:30:36 -0600 | [diff] [blame] | 180 | |
| 181 | /** |
| 182 | * Current value of the Priority Mask register which is saved/restored |
| 183 | * during secure interrupt handling. |
| 184 | */ |
| 185 | uint8_t priority_mask; |
Madhukar Pappireddy | 0aaadbb | 2021-12-16 20:58:10 -0600 | [diff] [blame] | 186 | |
| 187 | /** |
| 188 | * Per FF-A v1.1-Beta0 spec section 8.3, an SP can use multiple |
| 189 | * mechanisms to signal completion of secure interrupt handling. SP |
| 190 | * can invoke explicit FF-A ABIs, namely FFA_MSG_WAIT and FFA_RUN, |
| 191 | * when in WAITING/BLOCKED state respectively, but has to perform |
| 192 | * implicit signal completion mechanism by dropping the priority |
| 193 | * of the virtual secure interrupt when SPMC signaled the virtual |
| 194 | * interrupt in PREEMPTED state(The vCPU was preempted by a Self S-Int |
| 195 | * while running). This variable helps SPMC to keep a track of such |
| 196 | * mechanism and perform appropriate bookkeeping. |
| 197 | */ |
J-Alves | ac94075 | 2024-08-07 14:02:51 +0100 | [diff] [blame] | 198 | bool requires_deactivate_call; |
Madhukar Pappireddy | fe297a3 | 2022-06-21 16:42:13 -0500 | [diff] [blame] | 199 | |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 200 | /** SP call chain. */ |
| 201 | struct call_chain call_chain; |
| 202 | |
| 203 | /** |
| 204 | * Indicates if the current vCPU is running in SPMC scheduled |
| 205 | * mode or Normal World scheduled mode. |
| 206 | */ |
| 207 | enum schedule_mode scheduling_mode; |
| 208 | |
Madhukar Pappireddy | 8415405 | 2022-06-21 18:30:25 -0500 | [diff] [blame] | 209 | /** |
Madhukar Pappireddy | 94da32d | 2023-02-22 16:04:10 -0600 | [diff] [blame] | 210 | * If the action in response to a non-secure or other-secure interrupt |
| 211 | * is to queue it, this field is used to save and restore the current |
| 212 | * priority mask. |
Madhukar Pappireddy | 8415405 | 2022-06-21 18:30:25 -0500 | [diff] [blame] | 213 | */ |
Madhukar Pappireddy | 94da32d | 2023-02-22 16:04:10 -0600 | [diff] [blame] | 214 | uint8_t prev_interrupt_priority; |
Madhukar Pappireddy | c40f55f | 2022-06-22 11:00:41 -0500 | [diff] [blame] | 215 | |
Madhukar Pappireddy | fe297a3 | 2022-06-21 16:42:13 -0500 | [diff] [blame] | 216 | /** Partition Runtime Model. */ |
| 217 | enum partition_runtime_model rt_model; |
Madhukar Pappireddy | 2f76e49 | 2022-09-06 15:21:59 -0500 | [diff] [blame] | 218 | |
| 219 | /** |
Madhukar Pappireddy | ba24885 | 2024-01-04 16:58:09 -0600 | [diff] [blame] | 220 | * Direct response message has been intercepted to signal virtual |
| 221 | * secure interrupt for an SP. |
Madhukar Pappireddy | 2f76e49 | 2022-09-06 15:21:59 -0500 | [diff] [blame] | 222 | */ |
| 223 | bool direct_resp_intercepted; |
| 224 | |
Madhukar Pappireddy | ba24885 | 2024-01-04 16:58:09 -0600 | [diff] [blame] | 225 | /** |
| 226 | * FFA_MSG_WAIT invocation has been intercepted to signal virtual |
| 227 | * secure interrupt for an SP. |
| 228 | */ |
| 229 | bool msg_wait_intercepted; |
| 230 | |
Madhukar Pappireddy | 2f76e49 | 2022-09-06 15:21:59 -0500 | [diff] [blame] | 231 | /** Save direct response message args to be resumed later. */ |
| 232 | struct ffa_value direct_resp_ffa_value; |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 233 | |
J-Alves | 67f5ba3 | 2024-09-27 18:07:11 +0100 | [diff] [blame^] | 234 | /* List entry pointing to the next vCPU in the boot order list. */ |
| 235 | struct list_entry boot_list_node; |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | /** Encapsulates a vCPU whose lock is held. */ |
| 239 | struct vcpu_locked { |
| 240 | struct vcpu *vcpu; |
| 241 | }; |
| 242 | |
Olivier Deprez | 0b6f10a | 2020-08-05 18:21:33 +0200 | [diff] [blame] | 243 | /** Container for two vcpu_locked structures. */ |
| 244 | struct two_vcpu_locked { |
| 245 | struct vcpu_locked vcpu1; |
| 246 | struct vcpu_locked vcpu2; |
| 247 | }; |
| 248 | |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 249 | struct vcpu_locked vcpu_lock(struct vcpu *vcpu); |
Olivier Deprez | 0b6f10a | 2020-08-05 18:21:33 +0200 | [diff] [blame] | 250 | struct two_vcpu_locked vcpu_lock_both(struct vcpu *vcpu1, struct vcpu *vcpu2); |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 251 | void vcpu_unlock(struct vcpu_locked *locked); |
| 252 | void vcpu_init(struct vcpu *vcpu, struct vm *vm); |
| 253 | void vcpu_on(struct vcpu_locked vcpu, ipaddr_t entry, uintreg_t arg); |
Andrew Walbran | b5ab43c | 2020-04-30 11:32:54 +0100 | [diff] [blame] | 254 | ffa_vcpu_index_t vcpu_index(const struct vcpu *vcpu); |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 255 | bool vcpu_is_off(struct vcpu_locked vcpu); |
Max Shvetsov | 40108e7 | 2020-08-27 12:39:50 +0100 | [diff] [blame] | 256 | bool vcpu_secondary_reset_and_start(struct vcpu_locked vcpu_locked, |
| 257 | ipaddr_t entry, uintreg_t arg); |
Fuad Tabba | 5c73843 | 2019-12-02 11:02:42 +0000 | [diff] [blame] | 258 | |
| 259 | bool vcpu_handle_page_fault(const struct vcpu *current, |
| 260 | struct vcpu_fault_info *f); |
Olivier Deprez | 2ebae3a | 2020-06-11 16:34:30 +0200 | [diff] [blame] | 261 | |
J-Alves | 7ac4905 | 2022-02-08 17:20:53 +0000 | [diff] [blame] | 262 | void vcpu_set_phys_core_idx(struct vcpu *vcpu); |
Olivier Deprez | 632249e | 2022-09-26 09:18:31 +0200 | [diff] [blame] | 263 | void vcpu_set_boot_info_gp_reg(struct vcpu *vcpu); |
| 264 | |
Olivier Deprez | 181074b | 2023-02-02 14:53:23 +0100 | [diff] [blame] | 265 | void vcpu_update_boot(struct vcpu *vcpu); |
| 266 | struct vcpu *vcpu_get_boot_vcpu(void); |
J-Alves | 67f5ba3 | 2024-09-27 18:07:11 +0100 | [diff] [blame^] | 267 | struct vcpu *vcpu_get_next_boot(struct vcpu *vcpu); |
J-Alves | 7ac4905 | 2022-02-08 17:20:53 +0000 | [diff] [blame] | 268 | |
Daniel Boulby | 4ca50f0 | 2022-07-29 18:29:34 +0100 | [diff] [blame] | 269 | static inline bool vcpu_is_virt_interrupt_enabled(struct interrupts *interrupts, |
| 270 | uint32_t intid) |
| 271 | { |
| 272 | return interrupt_bitmap_get_value(&interrupts->interrupt_enabled, |
| 273 | intid) == 1U; |
| 274 | } |
| 275 | |
| 276 | static inline void vcpu_virt_interrupt_set_enabled( |
| 277 | struct interrupts *interrupts, uint32_t intid) |
| 278 | { |
| 279 | interrupt_bitmap_set_value(&interrupts->interrupt_enabled, intid); |
| 280 | } |
| 281 | |
| 282 | static inline void vcpu_virt_interrupt_clear_enabled( |
| 283 | struct interrupts *interrupts, uint32_t intid) |
| 284 | { |
| 285 | interrupt_bitmap_clear_value(&interrupts->interrupt_enabled, intid); |
| 286 | } |
| 287 | |
| 288 | static inline bool vcpu_is_virt_interrupt_pending(struct interrupts *interrupts, |
| 289 | uint32_t intid) |
| 290 | { |
| 291 | return interrupt_bitmap_get_value(&interrupts->interrupt_pending, |
| 292 | intid) == 1U; |
| 293 | } |
| 294 | |
| 295 | static inline void vcpu_virt_interrupt_set_pending( |
| 296 | struct interrupts *interrupts, uint32_t intid) |
| 297 | { |
| 298 | interrupt_bitmap_set_value(&interrupts->interrupt_pending, intid); |
| 299 | } |
| 300 | |
| 301 | static inline void vcpu_virt_interrupt_clear_pending( |
| 302 | struct interrupts *interrupts, uint32_t intid) |
| 303 | { |
| 304 | interrupt_bitmap_clear_value(&interrupts->interrupt_pending, intid); |
| 305 | } |
| 306 | |
| 307 | static inline enum interrupt_type vcpu_virt_interrupt_get_type( |
| 308 | struct interrupts *interrupts, uint32_t intid) |
| 309 | { |
| 310 | return (enum interrupt_type)interrupt_bitmap_get_value( |
| 311 | &interrupts->interrupt_type, intid); |
| 312 | } |
| 313 | |
| 314 | static inline void vcpu_virt_interrupt_set_type(struct interrupts *interrupts, |
| 315 | uint32_t intid, |
| 316 | enum interrupt_type type) |
| 317 | { |
| 318 | if (type == INTERRUPT_TYPE_IRQ) { |
| 319 | interrupt_bitmap_clear_value(&interrupts->interrupt_type, |
| 320 | intid); |
| 321 | } else { |
| 322 | interrupt_bitmap_set_value(&interrupts->interrupt_type, intid); |
| 323 | } |
| 324 | } |
| 325 | |
Manish Pandey | 35e452f | 2021-02-18 21:36:34 +0000 | [diff] [blame] | 326 | static inline void vcpu_irq_count_increment(struct vcpu_locked vcpu_locked) |
| 327 | { |
| 328 | vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count++; |
| 329 | } |
| 330 | |
| 331 | static inline void vcpu_irq_count_decrement(struct vcpu_locked vcpu_locked) |
| 332 | { |
| 333 | vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count--; |
| 334 | } |
| 335 | |
| 336 | static inline void vcpu_fiq_count_increment(struct vcpu_locked vcpu_locked) |
| 337 | { |
| 338 | vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count++; |
| 339 | } |
| 340 | |
| 341 | static inline void vcpu_fiq_count_decrement(struct vcpu_locked vcpu_locked) |
| 342 | { |
| 343 | vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count--; |
| 344 | } |
| 345 | |
Daniel Boulby | 4ca50f0 | 2022-07-29 18:29:34 +0100 | [diff] [blame] | 346 | static inline void vcpu_interrupt_count_increment( |
| 347 | struct vcpu_locked vcpu_locked, struct interrupts *interrupts, |
| 348 | uint32_t intid) |
| 349 | { |
| 350 | if (vcpu_virt_interrupt_get_type(interrupts, intid) == |
| 351 | INTERRUPT_TYPE_IRQ) { |
| 352 | vcpu_irq_count_increment(vcpu_locked); |
| 353 | } else { |
| 354 | vcpu_fiq_count_increment(vcpu_locked); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | static inline void vcpu_interrupt_count_decrement( |
| 359 | struct vcpu_locked vcpu_locked, struct interrupts *interrupts, |
| 360 | uint32_t intid) |
| 361 | { |
| 362 | if (vcpu_virt_interrupt_get_type(interrupts, intid) == |
| 363 | INTERRUPT_TYPE_IRQ) { |
| 364 | vcpu_irq_count_decrement(vcpu_locked); |
| 365 | } else { |
| 366 | vcpu_fiq_count_decrement(vcpu_locked); |
| 367 | } |
| 368 | } |
| 369 | |
Manish Pandey | 35e452f | 2021-02-18 21:36:34 +0000 | [diff] [blame] | 370 | static inline uint32_t vcpu_interrupt_irq_count_get( |
| 371 | struct vcpu_locked vcpu_locked) |
| 372 | { |
| 373 | return vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count; |
| 374 | } |
| 375 | |
| 376 | static inline uint32_t vcpu_interrupt_fiq_count_get( |
| 377 | struct vcpu_locked vcpu_locked) |
| 378 | { |
| 379 | return vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count; |
| 380 | } |
| 381 | |
| 382 | static inline uint32_t vcpu_interrupt_count_get(struct vcpu_locked vcpu_locked) |
| 383 | { |
| 384 | return vcpu_locked.vcpu->interrupts.enabled_and_pending_irq_count + |
| 385 | vcpu_locked.vcpu->interrupts.enabled_and_pending_fiq_count; |
| 386 | } |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 387 | |
Madhukar Pappireddy | bd10e57 | 2023-03-06 16:39:49 -0600 | [diff] [blame] | 388 | static inline void vcpu_call_chain_extend(struct vcpu_locked vcpu1_locked, |
| 389 | struct vcpu_locked vcpu2_locked) |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 390 | { |
Madhukar Pappireddy | bd10e57 | 2023-03-06 16:39:49 -0600 | [diff] [blame] | 391 | vcpu1_locked.vcpu->call_chain.next_node = vcpu2_locked.vcpu; |
| 392 | vcpu2_locked.vcpu->call_chain.prev_node = vcpu1_locked.vcpu; |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 393 | } |
| 394 | |
Madhukar Pappireddy | bd10e57 | 2023-03-06 16:39:49 -0600 | [diff] [blame] | 395 | static inline void vcpu_call_chain_remove_node(struct vcpu_locked vcpu1_locked, |
| 396 | struct vcpu_locked vcpu2_locked) |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 397 | { |
Madhukar Pappireddy | bd10e57 | 2023-03-06 16:39:49 -0600 | [diff] [blame] | 398 | vcpu1_locked.vcpu->call_chain.prev_node = NULL; |
| 399 | vcpu2_locked.vcpu->call_chain.next_node = NULL; |
Madhukar Pappireddy | 5992fbc | 2022-06-21 17:15:16 -0500 | [diff] [blame] | 400 | } |
J-Alves | 12cedae | 2023-08-04 14:37:37 +0100 | [diff] [blame] | 401 | |
J-Alves | b8730e9 | 2024-08-07 18:28:55 +0100 | [diff] [blame] | 402 | void vcpu_interrupt_clear_decrement(struct vcpu_locked vcpu_locked, |
| 403 | uint32_t intid); |
| 404 | |
J-Alves | 0247fe6 | 2024-02-23 10:21:46 +0000 | [diff] [blame] | 405 | void vcpu_set_running(struct vcpu_locked target_locked, struct ffa_value *args); |
J-Alves | 12cedae | 2023-08-04 14:37:37 +0100 | [diff] [blame] | 406 | void vcpu_save_interrupt_priority(struct vcpu_locked vcpu_locked, |
| 407 | uint8_t priority); |
| 408 | void vcpu_interrupt_inject(struct vcpu_locked target_locked, uint32_t intid); |
J-Alves | 12cedae | 2023-08-04 14:37:37 +0100 | [diff] [blame] | 409 | void vcpu_enter_secure_interrupt_rtm(struct vcpu_locked vcpu_locked); |
J-Alves | 3b31f09 | 2024-08-07 13:26:29 +0100 | [diff] [blame] | 410 | |
Madhukar Pappireddy | 32913cb | 2024-07-19 13:04:05 -0500 | [diff] [blame] | 411 | bool vcpu_interrupt_queue_push(struct vcpu_locked vcpu_locked, |
| 412 | uint32_t vint_id); |
| 413 | bool vcpu_interrupt_queue_pop(struct vcpu_locked vcpu_locked, |
| 414 | uint32_t *vint_id); |
| 415 | bool vcpu_interrupt_queue_peek(struct vcpu_locked vcpu_locked, |
| 416 | uint32_t *vint_id); |
| 417 | bool vcpu_is_interrupt_in_queue(struct vcpu_locked vcpu_locked, |
| 418 | uint32_t vint_id); |
| 419 | bool vcpu_is_interrupt_queue_empty(struct vcpu_locked vcpu_locked); |
J-Alves | 3b31f09 | 2024-08-07 13:26:29 +0100 | [diff] [blame] | 420 | |
| 421 | void vcpu_secure_interrupt_complete(struct vcpu_locked vcpu_locked); |