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 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Andrew Scull | fbc938a | 2018-08-20 14:09:28 +0100 | [diff] [blame] | 17 | #pragma once |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 18 | |
Andrew Scull | 6d2db33 | 2018-10-10 15:28:17 +0100 | [diff] [blame] | 19 | #include "hf/abi.h" |
Jose Marinho | a1dfeda | 2019-02-27 16:46:03 +0000 | [diff] [blame] | 20 | #include "hf/spci.h" |
Andrew Scull | 6d2db33 | 2018-10-10 15:28:17 +0100 | [diff] [blame] | 21 | #include "hf/types.h" |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 22 | |
| 23 | /* Keep macro alignment */ |
| 24 | /* clang-format off */ |
| 25 | |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 26 | /* TODO: Define constants below according to spec. */ |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 27 | #define HF_VM_GET_ID 0xff00 |
| 28 | #define HF_VM_GET_COUNT 0xff01 |
| 29 | #define HF_VCPU_GET_COUNT 0xff02 |
| 30 | #define HF_VCPU_RUN 0xff03 |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 31 | #define HF_VM_CONFIGURE 0xff05 |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 32 | #define HF_MAILBOX_CLEAR 0xff08 |
| 33 | #define HF_MAILBOX_WRITABLE_GET 0xff09 |
| 34 | #define HF_MAILBOX_WAITER_GET 0xff0a |
| 35 | #define HF_INTERRUPT_ENABLE 0xff0b |
| 36 | #define HF_INTERRUPT_GET 0xff0c |
| 37 | #define HF_INTERRUPT_INJECT 0xff0d |
Andrew Scull | 6386f25 | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 38 | #define HF_SHARE_MEMORY 0xff0e |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 39 | |
Andrew Walbran | c1ad4ce | 2019-05-09 11:41:39 +0100 | [diff] [blame] | 40 | /* This matches what Trusty and its ATF module currently use. */ |
| 41 | #define HF_DEBUG_LOG 0xbd000000 |
| 42 | |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 43 | /* clang-format on */ |
| 44 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 45 | /** |
| 46 | * This function must be implemented to trigger the architecture specific |
| 47 | * mechanism to call to the hypervisor. |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 48 | */ |
Andrew Walbran | 4e6bcc7 | 2019-09-11 13:57:22 +0100 | [diff] [blame] | 49 | int64_t hf_call(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3); |
Andrew Walbran | 7f920af | 2019-09-03 17:09:30 +0100 | [diff] [blame] | 50 | struct spci_value spci_call(struct spci_value args); |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 51 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 52 | /** |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 53 | * Returns the VM's own ID. |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 54 | */ |
Andrew Walbran | 9553492 | 2019-06-19 11:32:54 +0100 | [diff] [blame] | 55 | static inline spci_vm_id_t hf_vm_get_id(void) |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 56 | { |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 57 | return hf_call(HF_VM_GET_ID, 0, 0, 0); |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | /** |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 61 | * Returns the number of secondary VMs. |
| 62 | */ |
Andrew Walbran | 52d9967 | 2019-06-25 15:51:11 +0100 | [diff] [blame] | 63 | static inline spci_vm_count_t hf_vm_get_count(void) |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 64 | { |
| 65 | return hf_call(HF_VM_GET_COUNT, 0, 0, 0); |
| 66 | } |
| 67 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 68 | /** |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 69 | * Returns the number of VCPUs configured in the given secondary VM. |
| 70 | */ |
Andrew Walbran | c6d23c4 | 2019-06-26 13:30:42 +0100 | [diff] [blame] | 71 | static inline spci_vcpu_count_t hf_vcpu_get_count(spci_vm_id_t vm_id) |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 72 | { |
Andrew Scull | 1950326 | 2018-09-20 14:48:39 +0100 | [diff] [blame] | 73 | return hf_call(HF_VCPU_GET_COUNT, vm_id, 0, 0); |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 76 | /** |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 77 | * Runs the given vcpu of the given vm. |
| 78 | * |
| 79 | * Returns an hf_vcpu_run_return struct telling the scheduler what to do next. |
| 80 | */ |
Andrew Walbran | 9553492 | 2019-06-19 11:32:54 +0100 | [diff] [blame] | 81 | static inline struct hf_vcpu_run_return hf_vcpu_run(spci_vm_id_t vm_id, |
Andrew Walbran | b037d5b | 2019-06-25 17:19:41 +0100 | [diff] [blame] | 82 | spci_vcpu_index_t vcpu_idx) |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 83 | { |
| 84 | return hf_vcpu_run_return_decode( |
| 85 | hf_call(HF_VCPU_RUN, vm_id, vcpu_idx, 0)); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Hints that the vcpu is willing to yield its current use of the physical CPU. |
Jose Marinho | 135dff3 | 2019-02-28 10:25:57 +0000 | [diff] [blame] | 90 | * This call always returns SPCI_SUCCESS. |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 91 | */ |
Andrew Walbran | 16075b6 | 2019-09-03 17:11:07 +0100 | [diff] [blame] | 92 | static inline struct spci_value spci_yield(void) |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 93 | { |
Andrew Walbran | 16075b6 | 2019-09-03 17:11:07 +0100 | [diff] [blame] | 94 | return spci_call((struct spci_value){.func = SPCI_YIELD_32}); |
Andrew Scull | 55c4d8b | 2018-12-18 18:50:18 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 98 | * Configures the pages to send/receive data through. The pages must not be |
| 99 | * shared. |
Andrew Walbran | 54afb50 | 2018-11-26 16:01:11 +0000 | [diff] [blame] | 100 | * |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 101 | * Returns: |
| 102 | * - -1 on failure. |
| 103 | * - 0 on success if no further action is needed. |
| 104 | * - 1 if it was called by the primary VM and the primary VM now needs to wake |
| 105 | * up or kick waiters. |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 106 | */ |
Andrew Scull | c0e569a | 2018-10-02 18:05:21 +0100 | [diff] [blame] | 107 | static inline int64_t hf_vm_configure(hf_ipaddr_t send, hf_ipaddr_t recv) |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 108 | { |
| 109 | return hf_call(HF_VM_CONFIGURE, send, recv, 0); |
| 110 | } |
| 111 | |
| 112 | /** |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 113 | * Copies data from the sender's send buffer to the recipient's receive buffer. |
Andrew Walbran | 54afb50 | 2018-11-26 16:01:11 +0000 | [diff] [blame] | 114 | * |
Wedson Almeida Filho | 17c997f | 2019-01-09 18:50:09 +0000 | [diff] [blame] | 115 | * If the recipient's receive buffer is busy, it can optionally register the |
| 116 | * caller to be notified when the recipient's receive buffer becomes available. |
| 117 | * |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 118 | * Attributes may include: |
| 119 | * - SPCI_MSG_SEND_NOTIFY, to notify the caller when it should try again. |
| 120 | * - SPCI_MSG_SEND_LEGACY_MEMORY, to send a legacy architected memory sharing |
| 121 | * message. |
| 122 | * |
| 123 | * Returns SPCI_SUCCESS if the message is sent, or an error code otherwise: |
| 124 | * - INVALID_PARAMETERS: one or more of the parameters do not conform. |
Jose Marinho | a1dfeda | 2019-02-27 16:46:03 +0000 | [diff] [blame] | 125 | * - BUSY: the message could not be delivered either because the mailbox |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 126 | * was full or the target VM is not yet set up. |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 127 | */ |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 128 | static inline struct spci_value spci_msg_send(spci_vm_id_t sender_vm_id, |
| 129 | spci_vm_id_t target_vm_id, |
| 130 | uint32_t size, |
| 131 | uint32_t attributes) |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 132 | { |
Andrew Walbran | 70bc862 | 2019-10-07 14:15:58 +0100 | [diff] [blame] | 133 | return spci_call((struct spci_value){ |
| 134 | .func = SPCI_MSG_SEND_32, |
| 135 | .arg1 = ((uint64_t)sender_vm_id << 16) | target_vm_id, |
| 136 | .arg3 = size, |
| 137 | .arg4 = attributes}); |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | /** |
Andrew Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 141 | * Called by secondary VMs to receive a message. This will block until a message |
| 142 | * is received. |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 143 | * |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 144 | * The mailbox must be cleared before a new message can be received. |
Andrew Walbran | 9311c9a | 2019-03-12 16:59:04 +0000 | [diff] [blame] | 145 | * |
Andrew Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 146 | * If no message is immediately available and there are no enabled and pending |
| 147 | * interrupts (irrespective of whether interrupts are enabled globally), then |
| 148 | * this will block until a message is available or an enabled interrupt becomes |
| 149 | * pending. This matches the behaviour of the WFI instruction on aarch64, except |
| 150 | * that a message becoming available is also treated like a wake-up event. |
Andrew Walbran | c850081 | 2019-06-26 10:36:48 +0100 | [diff] [blame] | 151 | * |
| 152 | * Returns: |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 153 | * - SPCI_MSG_SEND if a message is successfully received. |
| 154 | * - SPCI_ERROR SPCI_NOT_SUPPORTED if called from the primary VM. |
| 155 | * - SPCI_ERROR SPCI_INTERRUPTED if an interrupt happened during the call. |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 156 | */ |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 157 | static inline struct spci_value spci_msg_wait(void) |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 158 | { |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 159 | return spci_call((struct spci_value){.func = SPCI_MSG_WAIT_32}); |
Andrew Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Called by secondary VMs to receive a message. The call will return whether or |
| 164 | * not a message is available. |
| 165 | * |
| 166 | * The mailbox must be cleared before a new message can be received. |
| 167 | * |
| 168 | * Returns: |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 169 | * - SPCI_MSG_SEND if a message is successfully received. |
| 170 | * - SPCI_ERROR SPCI_NOT_SUPPORTED if called from the primary VM. |
| 171 | * - SPCI_ERROR SPCI_INTERRUPTED if an interrupt happened during the call. |
| 172 | * - SPCI_ERROR SPCI_RETRY if there was no pending message. |
Andrew Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 173 | */ |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 174 | static inline struct spci_value spci_msg_poll(void) |
Andrew Walbran | 0de4f16 | 2019-09-03 16:44:20 +0100 | [diff] [blame] | 175 | { |
Andrew Walbran | d4d2fa1 | 2019-10-01 16:47:25 +0100 | [diff] [blame] | 176 | return spci_call((struct spci_value){.func = SPCI_MSG_POLL_32}); |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** |
Andrew Walbran | 54afb50 | 2018-11-26 16:01:11 +0000 | [diff] [blame] | 180 | * Clears the caller's mailbox so a new message can be received. |
| 181 | * |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 182 | * Returns: |
Andrew Scull | aa7db8e | 2019-02-01 14:12:19 +0000 | [diff] [blame] | 183 | * - -1 on failure, if the mailbox hasn't been read. |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 184 | * - 0 on success if no further action is needed. |
| 185 | * - 1 if it was called by the primary VM and the primary VM now needs to wake |
| 186 | * up or kick waiters. Waiters should be retrieved by calling |
| 187 | * hf_mailbox_waiter_get. |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 188 | */ |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 189 | static inline int64_t hf_mailbox_clear(void) |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 190 | { |
Andrew Scull | aa039b3 | 2018-10-04 15:02:26 +0100 | [diff] [blame] | 191 | return hf_call(HF_MAILBOX_CLEAR, 0, 0, 0); |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 192 | } |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 193 | |
| 194 | /** |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 195 | * Retrieves the next VM whose mailbox became writable. For a VM to be notified |
| 196 | * by this function, the caller must have called api_mailbox_send before with |
| 197 | * the notify argument set to true, and this call must have failed because the |
| 198 | * mailbox was not available. |
| 199 | * |
Wedson Almeida Filho | b790f65 | 2019-01-22 23:41:56 +0000 | [diff] [blame] | 200 | * It should be called repeatedly to retrieve a list of VMs. |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 201 | * |
| 202 | * Returns -1 if no VM became writable, or the id of the VM whose mailbox |
| 203 | * became writable. |
| 204 | */ |
| 205 | static inline int64_t hf_mailbox_writable_get(void) |
| 206 | { |
| 207 | return hf_call(HF_MAILBOX_WRITABLE_GET, 0, 0, 0); |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * Retrieves the next VM waiting to be notified that the mailbox of the |
| 212 | * specified VM became writable. Only primary VMs are allowed to call this. |
| 213 | * |
Wedson Almeida Filho | b790f65 | 2019-01-22 23:41:56 +0000 | [diff] [blame] | 214 | * Returns -1 on failure or if there are no waiters; the VM id of the next |
| 215 | * waiter otherwise. |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 216 | */ |
Andrew Walbran | 9553492 | 2019-06-19 11:32:54 +0100 | [diff] [blame] | 217 | static inline int64_t hf_mailbox_waiter_get(spci_vm_id_t vm_id) |
Wedson Almeida Filho | ea62e2e | 2019-01-09 19:14:59 +0000 | [diff] [blame] | 218 | { |
| 219 | return hf_call(HF_MAILBOX_WAITER_GET, vm_id, 0, 0); |
| 220 | } |
| 221 | |
| 222 | /** |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 223 | * Enables or disables a given interrupt ID. |
| 224 | * |
| 225 | * Returns 0 on success, or -1 if the intid is invalid. |
| 226 | */ |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 227 | static inline int64_t hf_interrupt_enable(uint32_t intid, bool enable) |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 228 | { |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 229 | return hf_call(HF_INTERRUPT_ENABLE, intid, enable, 0); |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Gets the ID of the pending interrupt (if any) and acknowledge it. |
| 234 | * |
| 235 | * Returns HF_INVALID_INTID if there are no pending interrupts. |
| 236 | */ |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 237 | static inline uint32_t hf_interrupt_get(void) |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 238 | { |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 239 | return hf_call(HF_INTERRUPT_GET, 0, 0, 0); |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Injects a virtual interrupt of the given ID into the given target vCPU. |
| 244 | * This doesn't cause the vCPU to actually be run immediately; it will be taken |
| 245 | * when the vCPU is next run, which is up to the scheduler. |
| 246 | * |
Andrew Walbran | 3d84a26 | 2018-12-13 14:41:19 +0000 | [diff] [blame] | 247 | * Returns: |
| 248 | * - -1 on failure because the target VM or vCPU doesn't exist, the interrupt |
| 249 | * ID is invalid, or the current VM is not allowed to inject interrupts to |
| 250 | * the target VM. |
| 251 | * - 0 on success if no further action is needed. |
| 252 | * - 1 if it was called by the primary VM and the primary VM now needs to wake |
| 253 | * up or kick the target vCPU. |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 254 | */ |
Andrew Walbran | 9553492 | 2019-06-19 11:32:54 +0100 | [diff] [blame] | 255 | static inline int64_t hf_interrupt_inject(spci_vm_id_t target_vm_id, |
Andrew Walbran | b037d5b | 2019-06-25 17:19:41 +0100 | [diff] [blame] | 256 | spci_vcpu_index_t target_vcpu_idx, |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 257 | uint32_t intid) |
| 258 | { |
Wedson Almeida Filho | c559d13 | 2019-01-09 19:33:40 +0000 | [diff] [blame] | 259 | return hf_call(HF_INTERRUPT_INJECT, target_vm_id, target_vcpu_idx, |
Andrew Walbran | 318f573 | 2018-11-20 16:23:42 +0000 | [diff] [blame] | 260 | intid); |
| 261 | } |
Andrew Scull | 6386f25 | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * Shares a region of memory with another VM. |
| 265 | * |
| 266 | * Returns 0 on success or -1 if the sharing was not allowed or failed. |
| 267 | * |
| 268 | * TODO: replace this with a better API once we have decided what that should |
| 269 | * look like. |
| 270 | */ |
Andrew Walbran | 9553492 | 2019-06-19 11:32:54 +0100 | [diff] [blame] | 271 | static inline int64_t hf_share_memory(spci_vm_id_t vm_id, hf_ipaddr_t addr, |
Andrew Scull | 6386f25 | 2018-12-06 13:29:10 +0000 | [diff] [blame] | 272 | size_t size, enum hf_share share) |
| 273 | { |
| 274 | return hf_call(HF_SHARE_MEMORY, (((uint64_t)vm_id) << 32) | share, addr, |
| 275 | size); |
| 276 | } |
Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 277 | |
Andrew Walbran | c1ad4ce | 2019-05-09 11:41:39 +0100 | [diff] [blame] | 278 | /** |
| 279 | * Sends a character to the debug log for the VM. |
| 280 | * |
| 281 | * Returns 0 on success, or -1 if it failed for some reason. |
| 282 | */ |
| 283 | static inline int64_t hf_debug_log(char c) |
| 284 | { |
| 285 | return hf_call(HF_DEBUG_LOG, c, 0, 0); |
| 286 | } |
| 287 | |
Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 288 | /** Obtains the Hafnium's version of the implemented SPCI specification. */ |
Andrew Walbran | 7f920af | 2019-09-03 17:09:30 +0100 | [diff] [blame] | 289 | static inline struct spci_value spci_version(void) |
Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 290 | { |
Andrew Walbran | 7f920af | 2019-09-03 17:09:30 +0100 | [diff] [blame] | 291 | return spci_call((struct spci_value){.func = SPCI_VERSION_32}); |
Jose Marinho | fc0b2b6 | 2019-06-06 11:18:45 +0100 | [diff] [blame] | 292 | } |