blob: 44aaf396f5e470bcbe91e11bbfce927b22fed2fc [file] [log] [blame]
Andrew Scull18834872018-10-12 11:48:09 +01001/*
Andrew Walbran692b3252019-03-07 15:51:31 +00002 * Copyright 2018 The Hafnium Authors.
Andrew Scull18834872018-10-12 11:48:09 +01003 *
Andrew Walbrane959ec12020-06-17 15:01:09 +01004 * 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 Scull18834872018-10-12 11:48:09 +01007 */
8
Andrew Scullfbc938a2018-08-20 14:09:28 +01009#pragma once
Andrew Scullf35a5c92018-08-07 18:09:46 +010010
Andrew Scull6d2db332018-10-10 15:28:17 +010011#include "hf/abi.h"
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010012#include "hf/ffa.h"
Andrew Scull6d2db332018-10-10 15:28:17 +010013#include "hf/types.h"
Andrew Scullf35a5c92018-08-07 18:09:46 +010014
Andrew Scull5ac05f02018-08-10 17:23:22 +010015/**
Fuad Tabba77a4b012019-11-15 12:13:08 +000016 * This function must be implemented to trigger the architecture-specific
Andrew Scull5ac05f02018-08-10 17:23:22 +010017 * mechanism to call to the hypervisor.
Andrew Scullf35a5c92018-08-07 18:09:46 +010018 */
Andrew Walbran4e6bcc72019-09-11 13:57:22 +010019int64_t hf_call(uint64_t arg0, uint64_t arg1, uint64_t arg2, uint64_t arg3);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010020struct ffa_value ffa_call(struct ffa_value args);
Andrew Scullf35a5c92018-08-07 18:09:46 +010021
Andrew Scull5ac05f02018-08-10 17:23:22 +010022/**
Andrew Scull55c4d8b2018-12-18 18:50:18 +000023 * Returns the VM's own ID.
Andrew Scull5ac05f02018-08-10 17:23:22 +010024 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010025static inline struct ffa_value ffa_id_get(void)
Andrew Walbrand230f662019-10-07 18:03:36 +010026{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010027 return ffa_call((struct ffa_value){.func = FFA_ID_GET_32});
Andrew Walbrand230f662019-10-07 18:03:36 +010028}
29
30/**
Olivier Deprez421677d2021-06-18 12:18:53 +020031 * Returns the SPMC FF-A ID at NS virtual/physical and secure virtual
32 * FF-A instances.
33 * DEN0077A FF-A v1.1 Beta0 section 13.9 FFA_SPM_ID_GET.
34 */
35static inline struct ffa_value ffa_spm_id_get(void)
36{
37 return ffa_call((struct ffa_value){.func = FFA_SPM_ID_GET_32});
38}
39
40/**
Fuad Tabbae4efcc32020-07-16 15:37:27 +010041 * Requests information for partitions instantiated in the system. The
42 * information is returned in the RX buffer of the caller as an array of
43 * partition information descriptors (struct ffa_partition_info).
44 *
45 * A Null UUID (UUID that is all zeros) returns information for all partitions,
46 * whereas a non-Null UUID returns information only for partitions that match.
47 *
48 * Returns:
49 * - FFA_SUCCESS on success. The count of partition information descriptors
50 * populated in the RX buffer is returned in arg2 (register w2).
51 * - FFA_BUSY if the caller's RX buffer is not free.
52 * - FFA_NO_MEMORY if the results do not fit in the callers RX buffer.
53 * - FFA_INVALID_PARAMETERS for an unrecognized UUID.
54 */
55static inline struct ffa_value ffa_partition_info_get(
56 const struct ffa_uuid *uuid)
57{
58 return ffa_call((struct ffa_value){.func = FFA_PARTITION_INFO_GET_32,
59 .arg1 = uuid->uuid[0],
60 .arg2 = uuid->uuid[1],
61 .arg3 = uuid->uuid[2],
62 .arg4 = uuid->uuid[3]});
63}
64
65/**
Andrew Walbrand230f662019-10-07 18:03:36 +010066 * Returns the VM's own ID.
67 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010068static inline ffa_vm_id_t hf_vm_get_id(void)
Andrew Scull5ac05f02018-08-10 17:23:22 +010069{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010070 return ffa_id_get().arg2;
Andrew Scull5ac05f02018-08-10 17:23:22 +010071}
72
73/**
Andrew Walbran27faff32019-10-02 18:20:57 +010074 * Runs the given vCPU of the given VM.
75 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010076static inline struct ffa_value ffa_run(ffa_vm_id_t vm_id,
77 ffa_vcpu_index_t vcpu_idx)
Andrew Walbran27faff32019-10-02 18:20:57 +010078{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010079 return ffa_call((struct ffa_value){.func = FFA_RUN_32,
80 ffa_vm_vcpu(vm_id, vcpu_idx)});
Andrew Walbran27faff32019-10-02 18:20:57 +010081}
82
83/**
Fuad Tabbab0ef2a42019-12-19 11:19:25 +000084 * Hints that the vCPU is willing to yield its current use of the physical CPU.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010085 * This call always returns FFA_SUCCESS.
Andrew Scull55c4d8b2018-12-18 18:50:18 +000086 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010087static inline struct ffa_value ffa_yield(void)
Andrew Scull55c4d8b2018-12-18 18:50:18 +000088{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010089 return ffa_call((struct ffa_value){.func = FFA_YIELD_32});
Andrew Scull55c4d8b2018-12-18 18:50:18 +000090}
91
92/**
Andrew Scull5ac05f02018-08-10 17:23:22 +010093 * Configures the pages to send/receive data through. The pages must not be
94 * shared.
Andrew Walbran54afb502018-11-26 16:01:11 +000095 *
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +000096 * Returns:
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010097 * - FFA_ERROR FFA_INVALID_PARAMETERS if the given addresses are not properly
Andrew Walbranbfffb0f2019-11-05 14:02:34 +000098 * aligned or are the same.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010099 * - FFA_ERROR FFA_NO_MEMORY if the hypervisor was unable to map the buffers
Fuad Tabba9dc276f2020-07-16 09:29:32 +0100100 * due to insufficient page table memory.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100101 * - FFA_ERROR FFA_DENIED if the pages are already mapped or are not owned by
Andrew Walbranbfffb0f2019-11-05 14:02:34 +0000102 * the caller.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100103 * - FFA_SUCCESS on success if no further action is needed.
104 * - FFA_RX_RELEASE if it was called by the primary VM and the primary VM now
Andrew Walbranbfffb0f2019-11-05 14:02:34 +0000105 * needs to wake up or kick waiters.
Andrew Scull5ac05f02018-08-10 17:23:22 +0100106 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100107static inline struct ffa_value ffa_rxtx_map(hf_ipaddr_t send, hf_ipaddr_t recv)
Andrew Scull5ac05f02018-08-10 17:23:22 +0100108{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100109 return ffa_call(
110 (struct ffa_value){.func = FFA_RXTX_MAP_64,
111 .arg1 = send,
112 .arg2 = recv,
113 .arg3 = HF_MAILBOX_SIZE / FFA_PAGE_SIZE});
Andrew Scull5ac05f02018-08-10 17:23:22 +0100114}
115
116/**
Daniel Boulby9e420ca2021-07-07 15:03:49 +0100117 * Unmaps the RX/TX buffer pair of an endpoint or Hypervisor from the
118 * translation regime of the callee.
119 *
120 * Returns:
121 * - FFA_ERROR FFA_INVALID_PARAMETERS if there is no buffer pair registered on
122 * behalf of the caller.
123 * - FFA_SUCCESS on success if no further action is needed.
124 */
125static inline struct ffa_value ffa_rxtx_unmap(void)
126{
127 /* Note that allocator ID MBZ at virtual instance. */
128 return ffa_call((struct ffa_value){.func = FFA_RXTX_UNMAP_32});
129}
130
131/**
Andrew Scullaa039b32018-10-04 15:02:26 +0100132 * Copies data from the sender's send buffer to the recipient's receive buffer.
Andrew Walbran54afb502018-11-26 16:01:11 +0000133 *
Wedson Almeida Filho17c997f2019-01-09 18:50:09 +0000134 * If the recipient's receive buffer is busy, it can optionally register the
135 * caller to be notified when the recipient's receive buffer becomes available.
136 *
Andrew Walbran70bc8622019-10-07 14:15:58 +0100137 * Attributes may include:
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100138 * - FFA_MSG_SEND_NOTIFY, to notify the caller when it should try again.
139 * - FFA_MSG_SEND_LEGACY_MEMORY_*, to send a legacy architected memory sharing
Andrew Walbran70bc8622019-10-07 14:15:58 +0100140 * message.
141 *
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100142 * Returns FFA_SUCCESS if the message is sent, or an error code otherwise:
Andrew Walbran70bc8622019-10-07 14:15:58 +0100143 * - INVALID_PARAMETERS: one or more of the parameters do not conform.
Jose Marinhoa1dfeda2019-02-27 16:46:03 +0000144 * - BUSY: the message could not be delivered either because the mailbox
Andrew Walbran70bc8622019-10-07 14:15:58 +0100145 * was full or the target VM is not yet set up.
Andrew Scull5ac05f02018-08-10 17:23:22 +0100146 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100147static inline struct ffa_value ffa_msg_send(ffa_vm_id_t sender_vm_id,
148 ffa_vm_id_t target_vm_id,
149 uint32_t size, uint32_t attributes)
Andrew Scull5ac05f02018-08-10 17:23:22 +0100150{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100151 return ffa_call((struct ffa_value){
152 .func = FFA_MSG_SEND_32,
Andrew Walbran70bc8622019-10-07 14:15:58 +0100153 .arg1 = ((uint64_t)sender_vm_id << 16) | target_vm_id,
154 .arg3 = size,
155 .arg4 = attributes});
Andrew Scull5ac05f02018-08-10 17:23:22 +0100156}
157
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100158static inline struct ffa_value ffa_mem_donate(uint32_t length,
Andrew Walbrana65a1322020-04-06 19:32:32 +0100159 uint32_t fragment_length)
Andrew Walbrane908c4a2019-12-02 17:13:47 +0000160{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100161 return ffa_call((struct ffa_value){.func = FFA_MEM_DONATE_32,
162 .arg1 = length,
163 .arg2 = fragment_length});
Andrew Walbrane908c4a2019-12-02 17:13:47 +0000164}
165
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100166static inline struct ffa_value ffa_mem_lend(uint32_t length,
167 uint32_t fragment_length)
Andrew Walbrane908c4a2019-12-02 17:13:47 +0000168{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100169 return ffa_call((struct ffa_value){.func = FFA_MEM_LEND_32,
170 .arg1 = length,
171 .arg2 = fragment_length});
Andrew Walbrane908c4a2019-12-02 17:13:47 +0000172}
173
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100174static inline struct ffa_value ffa_mem_share(uint32_t length,
175 uint32_t fragment_length)
Andrew Walbran82d6d152019-12-24 15:02:06 +0000176{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100177 return ffa_call((struct ffa_value){.func = FFA_MEM_SHARE_32,
178 .arg1 = length,
179 .arg2 = fragment_length});
Andrew Walbran82d6d152019-12-24 15:02:06 +0000180}
181
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100182static inline struct ffa_value ffa_mem_retrieve_req(uint32_t length,
183 uint32_t fragment_length)
Andrew Walbran5de9c3d2020-02-10 13:35:29 +0000184{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100185 return ffa_call((struct ffa_value){.func = FFA_MEM_RETRIEVE_REQ_32,
186 .arg1 = length,
187 .arg2 = fragment_length});
Andrew Walbran5de9c3d2020-02-10 13:35:29 +0000188}
189
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100190static inline struct ffa_value ffa_mem_relinquish(void)
Andrew Walbran5de9c3d2020-02-10 13:35:29 +0000191{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100192 return ffa_call((struct ffa_value){.func = FFA_MEM_RELINQUISH_32});
193}
194
195static inline struct ffa_value ffa_mem_reclaim(ffa_memory_handle_t handle,
196 ffa_memory_region_flags_t flags)
197{
198 return ffa_call((struct ffa_value){.func = FFA_MEM_RECLAIM_32,
199 .arg1 = (uint32_t)handle,
200 .arg2 = (uint32_t)(handle >> 32),
201 .arg3 = flags});
Andrew Walbran5de9c3d2020-02-10 13:35:29 +0000202}
203
Andrew Walbranca808b12020-05-15 17:22:28 +0100204static inline struct ffa_value ffa_mem_frag_rx(ffa_memory_handle_t handle,
205 uint32_t fragment_offset)
206{
207 /* Note that sender MBZ at virtual instance. */
208 return ffa_call((struct ffa_value){.func = FFA_MEM_FRAG_RX_32,
209 .arg1 = (uint32_t)handle,
210 .arg2 = (uint32_t)(handle >> 32),
211 .arg3 = fragment_offset});
212}
213
214static inline struct ffa_value ffa_mem_frag_tx(ffa_memory_handle_t handle,
215 uint32_t fragment_length)
216{
217 /* Note that sender MBZ at virtual instance. */
218 return ffa_call((struct ffa_value){.func = FFA_MEM_FRAG_TX_32,
219 .arg1 = (uint32_t)handle,
220 .arg2 = (uint32_t)(handle >> 32),
221 .arg3 = fragment_length});
222}
223
Andrew Scull5ac05f02018-08-10 17:23:22 +0100224/**
Andrew Walbran0de4f162019-09-03 16:44:20 +0100225 * Called by secondary VMs to receive a message. This will block until a message
226 * is received.
Andrew Scull5ac05f02018-08-10 17:23:22 +0100227 *
Andrew Scullaa039b32018-10-04 15:02:26 +0100228 * The mailbox must be cleared before a new message can be received.
Andrew Walbran9311c9a2019-03-12 16:59:04 +0000229 *
Andrew Walbran0de4f162019-09-03 16:44:20 +0100230 * If no message is immediately available and there are no enabled and pending
231 * interrupts (irrespective of whether interrupts are enabled globally), then
232 * this will block until a message is available or an enabled interrupt becomes
Fuad Tabbab0ef2a42019-12-19 11:19:25 +0000233 * pending. This matches the behaviour of the WFI instruction on AArch64, except
Andrew Walbran0de4f162019-09-03 16:44:20 +0100234 * that a message becoming available is also treated like a wake-up event.
Andrew Walbranc8500812019-06-26 10:36:48 +0100235 *
236 * Returns:
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100237 * - FFA_MSG_SEND if a message is successfully received.
238 * - FFA_ERROR FFA_NOT_SUPPORTED if called from the primary VM.
239 * - FFA_ERROR FFA_INTERRUPTED if an interrupt happened during the call.
Andrew Scull5ac05f02018-08-10 17:23:22 +0100240 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100241static inline struct ffa_value ffa_msg_wait(void)
Andrew Scull5ac05f02018-08-10 17:23:22 +0100242{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100243 return ffa_call((struct ffa_value){.func = FFA_MSG_WAIT_32});
Andrew Walbran0de4f162019-09-03 16:44:20 +0100244}
245
246/**
247 * Called by secondary VMs to receive a message. The call will return whether or
248 * not a message is available.
249 *
250 * The mailbox must be cleared before a new message can be received.
251 *
252 * Returns:
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100253 * - FFA_MSG_SEND if a message is successfully received.
254 * - FFA_ERROR FFA_NOT_SUPPORTED if called from the primary VM.
255 * - FFA_ERROR FFA_INTERRUPTED if an interrupt happened during the call.
256 * - FFA_ERROR FFA_RETRY if there was no pending message.
Andrew Walbran0de4f162019-09-03 16:44:20 +0100257 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100258static inline struct ffa_value ffa_msg_poll(void)
Andrew Walbran0de4f162019-09-03 16:44:20 +0100259{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100260 return ffa_call((struct ffa_value){.func = FFA_MSG_POLL_32});
Andrew Scull5ac05f02018-08-10 17:23:22 +0100261}
262
263/**
Andrew Walbran8a0f5ca2019-11-05 13:12:23 +0000264 * Releases the caller's mailbox so that a new message can be received. The
265 * caller must have copied out all data they wish to preserve as new messages
266 * will overwrite the old and will arrive asynchronously.
Andrew Walbran54afb502018-11-26 16:01:11 +0000267 *
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000268 * Returns:
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100269 * - FFA_ERROR FFA_DENIED on failure, if the mailbox hasn't been read.
270 * - FFA_SUCCESS on success if no further action is needed.
271 * - FFA_RX_RELEASE if it was called by the primary VM and the primary VM now
Andrew Walbran8a0f5ca2019-11-05 13:12:23 +0000272 * needs to wake up or kick waiters. Waiters should be retrieved by calling
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000273 * hf_mailbox_waiter_get.
Andrew Scull5ac05f02018-08-10 17:23:22 +0100274 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100275static inline struct ffa_value ffa_rx_release(void)
Andrew Scull5ac05f02018-08-10 17:23:22 +0100276{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100277 return ffa_call((struct ffa_value){.func = FFA_RX_RELEASE_32});
Andrew Scull5ac05f02018-08-10 17:23:22 +0100278}
Andrew Walbran318f5732018-11-20 16:23:42 +0000279
280/**
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000281 * Retrieves the next VM whose mailbox became writable. For a VM to be notified
282 * by this function, the caller must have called api_mailbox_send before with
283 * the notify argument set to true, and this call must have failed because the
284 * mailbox was not available.
285 *
Wedson Almeida Filhob790f652019-01-22 23:41:56 +0000286 * It should be called repeatedly to retrieve a list of VMs.
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000287 *
288 * Returns -1 if no VM became writable, or the id of the VM whose mailbox
289 * became writable.
290 */
291static inline int64_t hf_mailbox_writable_get(void)
292{
293 return hf_call(HF_MAILBOX_WRITABLE_GET, 0, 0, 0);
294}
295
296/**
297 * Retrieves the next VM waiting to be notified that the mailbox of the
298 * specified VM became writable. Only primary VMs are allowed to call this.
299 *
Wedson Almeida Filhob790f652019-01-22 23:41:56 +0000300 * Returns -1 on failure or if there are no waiters; the VM id of the next
301 * waiter otherwise.
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000302 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100303static inline int64_t hf_mailbox_waiter_get(ffa_vm_id_t vm_id)
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +0000304{
305 return hf_call(HF_MAILBOX_WAITER_GET, vm_id, 0, 0);
306}
307
308/**
Andrew Walbran318f5732018-11-20 16:23:42 +0000309 * Enables or disables a given interrupt ID.
310 *
311 * Returns 0 on success, or -1 if the intid is invalid.
312 */
Manish Pandey35e452f2021-02-18 21:36:34 +0000313static inline int64_t hf_interrupt_enable(uint32_t intid, bool enable,
314 enum interrupt_type type)
Andrew Walbran318f5732018-11-20 16:23:42 +0000315{
Manish Pandey35e452f2021-02-18 21:36:34 +0000316 return hf_call(HF_INTERRUPT_ENABLE, intid, enable, type);
Andrew Walbran318f5732018-11-20 16:23:42 +0000317}
318
319/**
320 * Gets the ID of the pending interrupt (if any) and acknowledge it.
321 *
322 * Returns HF_INVALID_INTID if there are no pending interrupts.
323 */
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000324static inline uint32_t hf_interrupt_get(void)
Andrew Walbran318f5732018-11-20 16:23:42 +0000325{
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000326 return hf_call(HF_INTERRUPT_GET, 0, 0, 0);
Andrew Walbran318f5732018-11-20 16:23:42 +0000327}
328
329/**
330 * Injects a virtual interrupt of the given ID into the given target vCPU.
331 * This doesn't cause the vCPU to actually be run immediately; it will be taken
332 * when the vCPU is next run, which is up to the scheduler.
333 *
Andrew Walbran3d84a262018-12-13 14:41:19 +0000334 * Returns:
335 * - -1 on failure because the target VM or vCPU doesn't exist, the interrupt
336 * ID is invalid, or the current VM is not allowed to inject interrupts to
337 * the target VM.
338 * - 0 on success if no further action is needed.
339 * - 1 if it was called by the primary VM and the primary VM now needs to wake
340 * up or kick the target vCPU.
Andrew Walbran318f5732018-11-20 16:23:42 +0000341 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100342static inline int64_t hf_interrupt_inject(ffa_vm_id_t target_vm_id,
343 ffa_vcpu_index_t target_vcpu_idx,
Andrew Walbran318f5732018-11-20 16:23:42 +0000344 uint32_t intid)
345{
Wedson Almeida Filhoc559d132019-01-09 19:33:40 +0000346 return hf_call(HF_INTERRUPT_INJECT, target_vm_id, target_vcpu_idx,
Andrew Walbran318f5732018-11-20 16:23:42 +0000347 intid);
348}
Andrew Scull6386f252018-12-06 13:29:10 +0000349
350/**
Andrew Walbranc1ad4ce2019-05-09 11:41:39 +0100351 * Sends a character to the debug log for the VM.
352 *
353 * Returns 0 on success, or -1 if it failed for some reason.
354 */
355static inline int64_t hf_debug_log(char c)
356{
357 return hf_call(HF_DEBUG_LOG, c, 0, 0);
358}
359
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100360/** Obtains the Hafnium's version of the implemented FF-A specification. */
361static inline int32_t ffa_version(uint32_t requested_version)
Jose Marinhofc0b2b62019-06-06 11:18:45 +0100362{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100363 return ffa_call((struct ffa_value){.func = FFA_VERSION_32,
364 .arg1 = requested_version})
Andrew Walbran9fd29072020-04-22 12:12:14 +0100365 .func;
Jose Marinhofc0b2b62019-06-06 11:18:45 +0100366}
Jose Marinhoc0f4ff22019-10-09 10:37:42 +0100367
368/**
369 * Discovery function returning information about the implementation of optional
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100370 * FF-A interfaces.
Jose Marinhoc0f4ff22019-10-09 10:37:42 +0100371 *
372 * Returns:
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100373 * - FFA_SUCCESS in .func if the optional interface with function_id is
Jose Marinhoc0f4ff22019-10-09 10:37:42 +0100374 * implemented.
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100375 * - FFA_ERROR in .func if the optional interface with function_id is not
Jose Marinhoc0f4ff22019-10-09 10:37:42 +0100376 * implemented.
377 */
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100378static inline struct ffa_value ffa_features(uint32_t function_id)
Jose Marinhoc0f4ff22019-10-09 10:37:42 +0100379{
Andrew Walbranb5ab43c2020-04-30 11:32:54 +0100380 return ffa_call((struct ffa_value){.func = FFA_FEATURES_32,
381 .arg1 = function_id});
Jose Marinhoc0f4ff22019-10-09 10:37:42 +0100382}
Olivier Deprezee9d6a92019-11-26 09:14:11 +0000383
384static inline struct ffa_value ffa_msg_send_direct_req(
385 ffa_vm_id_t sender_vm_id, ffa_vm_id_t target_vm_id, uint32_t arg3,
386 uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7)
387{
388 return ffa_call((struct ffa_value){
389 .func = FFA_MSG_SEND_DIRECT_REQ_32,
390 .arg1 = ((uint64_t)sender_vm_id << 16) | target_vm_id,
391 .arg3 = arg3,
392 .arg4 = arg4,
393 .arg5 = arg5,
394 .arg6 = arg6,
395 .arg7 = arg7,
396 });
397}
398
399static inline struct ffa_value ffa_msg_send_direct_resp(
400 ffa_vm_id_t sender_vm_id, ffa_vm_id_t target_vm_id, uint32_t arg3,
401 uint32_t arg4, uint32_t arg5, uint32_t arg6, uint32_t arg7)
402{
403 return ffa_call((struct ffa_value){
404 .func = FFA_MSG_SEND_DIRECT_RESP_32,
405 .arg1 = ((uint64_t)sender_vm_id << 16) | target_vm_id,
406 .arg3 = arg3,
407 .arg4 = arg4,
408 .arg5 = arg5,
409 .arg6 = arg6,
410 .arg7 = arg7,
411 });
412}
J-Alvesef69ac92021-08-26 09:21:27 +0100413
414static inline struct ffa_value ffa_notification_bind(
415 ffa_vm_id_t sender_vm_id, ffa_vm_id_t receiver_vm_id, uint32_t flags,
416 ffa_notifications_bitmap_t bitmap)
417{
418 return ffa_call((struct ffa_value){
419 .func = FFA_NOTIFICATION_BIND_32,
420 .arg1 = (sender_vm_id << 16) | (receiver_vm_id),
421 .arg2 = flags,
422 .arg3 = (uint32_t)(bitmap),
423 .arg4 = (uint32_t)(bitmap >> 32),
424 });
425}
426
427static inline struct ffa_value ffa_notification_unbind(
428 ffa_vm_id_t sender_vm_id, ffa_vm_id_t receiver_vm_id,
429 ffa_notifications_bitmap_t bitmap)
430{
431 return ffa_call((struct ffa_value){
432 .func = FFA_NOTIFICATION_UNBIND_32,
433 .arg1 = (sender_vm_id << 16) | (receiver_vm_id),
434 .arg3 = (uint32_t)(bitmap),
435 .arg4 = (uint32_t)(bitmap >> 32),
436 });
437}
438
439static inline struct ffa_value ffa_notification_set(
440 ffa_vm_id_t sender_vm_id, ffa_vm_id_t receiver_vm_id, uint32_t flags,
441 ffa_notifications_bitmap_t bitmap)
442{
443 return ffa_call((struct ffa_value){
444 .func = FFA_NOTIFICATION_SET_32,
445 .arg1 = (sender_vm_id << 16) | (receiver_vm_id),
446 .arg2 = flags,
447 .arg3 = (uint32_t)(bitmap),
448 .arg4 = (uint32_t)(bitmap >> 32),
449 });
450}
451
452static inline struct ffa_value ffa_notification_get(ffa_vm_id_t receiver_vm_id,
453 ffa_vcpu_index_t vcpu_id,
454 uint32_t flags)
455{
456 return ffa_call((struct ffa_value){
457 .func = FFA_NOTIFICATION_GET_32,
J-Alvesbe6e3032021-11-30 14:54:12 +0000458 .arg1 = (vcpu_id << 16) | (receiver_vm_id),
J-Alvesef69ac92021-08-26 09:21:27 +0100459 .arg2 = flags,
460 });
461}
462
463static inline struct ffa_value ffa_notification_info_get(void)
464{
465 return ffa_call((struct ffa_value){
466 .func = FFA_NOTIFICATION_INFO_GET_64,
467 });
468}
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700469
470static inline struct ffa_value ffa_mem_perm_get(uint64_t base_va)
471{
472 return ffa_call((struct ffa_value){.func = FFA_MEM_PERM_GET_32,
473 .arg1 = base_va});
474}
475
476static inline struct ffa_value ffa_mem_perm_set(uint64_t base_va,
477 uint32_t page_count,
478 uint32_t mem_perm)
479{
480 return ffa_call((struct ffa_value){.func = FFA_MEM_PERM_SET_32,
481 .arg1 = base_va,
482 .arg2 = page_count,
483 .arg3 = mem_perm});
484}