blob: f34d61c89696409472c2be8caafef7da56fe9bab [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
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010010
Andrew Scull18c78fc2018-08-20 12:57:41 +010011#include "hf/cpu.h"
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000012#include "hf/mpool.h"
Karl Meakin6f1f1212024-07-16 10:18:16 +010013#include "hf/vcpu.h"
Andrew Scull18c78fc2018-08-20 12:57:41 +010014#include "hf/vm.h"
Wedson Almeida Filho3fcbcff2018-07-10 23:53:39 +010015
Andrew Scull6d2db332018-10-10 15:28:17 +010016#include "vmapi/hf/call.h"
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010017#include "vmapi/hf/ffa.h"
Andrew Scull6d2db332018-10-10 15:28:17 +010018
J-Alvesbd32c972024-02-02 16:20:04 +000019static inline struct ffa_value api_ffa_interrupt_return(uint32_t id)
20{
21 return (struct ffa_value){.func = FFA_INTERRUPT_32, .arg2 = id};
22}
23
Wedson Almeida Filho22d5eaa2018-12-16 00:38:49 +000024void api_init(struct mpool *ppool);
Madhukar Pappireddyb11e0d12021-08-02 19:44:35 -050025struct vcpu *api_ffa_get_vm_vcpu(struct vm *vm, struct vcpu *current);
Andrew Walbran1f8d4872018-12-20 11:21:32 +000026void api_regs_state_saved(struct vcpu *vcpu);
Wedson Almeida Filhoea62e2e2019-01-09 19:14:59 +000027int64_t api_mailbox_writable_get(const struct vcpu *current);
J-Alves19e20cf2023-08-02 12:48:55 +010028int64_t api_mailbox_waiter_get(ffa_id_t vm_id, const struct vcpu *current);
Madhukar Pappireddybd10e572023-03-06 16:39:49 -060029struct vcpu *api_switch_to_vm(struct vcpu_locked current_locked,
30 struct ffa_value to_ret,
J-Alves19e20cf2023-08-02 12:48:55 +010031 enum vcpu_state vcpu_state, ffa_id_t to_id);
Madhukar Pappireddybd10e572023-03-06 16:39:49 -060032struct vcpu *api_switch_to_primary(struct vcpu_locked current_locked,
J-Alves27b71962022-12-12 15:29:58 +000033 struct ffa_value primary_ret,
34 enum vcpu_state secondary_state);
35
Andrew Scull33fecd32019-01-08 14:48:27 +000036struct vcpu *api_preempt(struct vcpu *current);
Andrew Scull33fecd32019-01-08 14:48:27 +000037struct vcpu *api_wait_for_interrupt(struct vcpu *current);
Andrew Walbran33645652019-04-15 12:29:31 +010038struct vcpu *api_vcpu_off(struct vcpu *current);
Andrew Scull9726c252019-01-23 13:44:19 +000039struct vcpu *api_abort(struct vcpu *current);
Andrew Walbran33645652019-04-15 12:29:31 +010040struct vcpu *api_wake_up(struct vcpu *current, struct vcpu *target_vcpu);
Andrew Walbran318f5732018-11-20 16:23:42 +000041
Manish Pandey35e452f2021-02-18 21:36:34 +000042int64_t api_interrupt_enable(uint32_t intid, bool enable,
43 enum interrupt_type type, struct vcpu *current);
Madhukar Pappireddyc64d0642024-08-07 16:55:46 -050044uint32_t api_interrupt_get(struct vcpu_locked current_locked);
J-Alves19e20cf2023-08-02 12:48:55 +010045int64_t api_interrupt_inject(ffa_id_t target_vm_id,
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010046 ffa_vcpu_index_t target_vcpu_idx, uint32_t intid,
Andrew Walbran42347a92019-05-09 13:59:03 +010047 struct vcpu *current, struct vcpu **next);
Manish Pandeya5f39fb2020-09-11 09:47:11 +010048int64_t api_interrupt_inject_locked(struct vcpu_locked target_locked,
Madhukar Pappireddybd10e572023-03-06 16:39:49 -060049 uint32_t intid,
50 struct vcpu_locked current_locked,
Manish Pandeya5f39fb2020-09-11 09:47:11 +010051 struct vcpu **next);
J-Alves13394022021-06-30 13:48:49 +010052void api_sri_send_if_delayed(struct vcpu *current);
Jose Marinhoa1dfeda2019-02-27 16:46:03 +000053
J-Alves19e20cf2023-08-02 12:48:55 +010054struct ffa_value api_ffa_msg_send(ffa_id_t sender_vm_id,
55 ffa_id_t receiver_vm_id, uint32_t size,
Federico Recanati86f6cde2022-04-28 19:44:49 +020056 struct vcpu *current, struct vcpu **next);
J-Alves19e20cf2023-08-02 12:48:55 +010057struct ffa_value api_ffa_msg_send2(ffa_id_t sender_vm_id, uint32_t flags,
Federico Recanati25053ee2022-03-14 15:01:53 +010058 struct vcpu *current);
J-Alves19e20cf2023-08-02 12:48:55 +010059struct ffa_value api_ffa_rx_release(ffa_id_t receiver_id, struct vcpu *current);
60struct ffa_value api_ffa_rx_acquire(ffa_id_t receiver_id, struct vcpu *current);
Manish Pandeyd34f8892020-06-19 17:41:07 +010061struct ffa_value api_vm_configure_pages(
62 struct mm_stage1_locked mm_stage1_locked, struct vm_locked vm_locked,
63 ipaddr_t send, ipaddr_t recv, uint32_t page_count,
64 struct mpool *local_page_pool);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010065struct ffa_value api_ffa_rxtx_map(ipaddr_t send, ipaddr_t recv,
Federico Recanati9f1b6532022-04-14 13:15:28 +020066 uint32_t page_count, struct vcpu *current);
J-Alves19e20cf2023-08-02 12:48:55 +010067struct ffa_value api_ffa_rxtx_unmap(ffa_id_t allocator_id,
Daniel Boulby9e420ca2021-07-07 15:03:49 +010068 struct vcpu *current);
Madhukar Pappireddy184501c2023-05-23 17:24:06 -050069struct ffa_value api_yield(struct vcpu *current, struct vcpu **next,
70 struct ffa_value *args);
Daniel Boulbybaeaf2e2021-12-09 11:42:36 +000071struct ffa_value api_ffa_version(struct vcpu *current,
72 uint32_t requested_version);
Fuad Tabbae4efcc32020-07-16 15:37:27 +010073struct ffa_value api_ffa_partition_info_get(struct vcpu *current,
Daniel Boulbyb46cad12021-12-13 17:47:21 +000074 const struct ffa_uuid *uuid,
Karl Meakin2ad6b662024-07-29 20:45:40 +010075 uint32_t flags);
Raghu Krishnamurthy2d2b0f42023-04-23 09:54:45 -070076bool api_ffa_fill_partition_info_from_regs(
77 struct ffa_value ret, uint16_t start_index,
78 struct ffa_partition_info *partitions, uint16_t partitions_len,
79 ffa_vm_count_t *ret_count);
Raghu Krishnamurthy7592bcb2022-12-25 13:09:00 -080080struct ffa_value api_ffa_partition_info_get_regs(struct vcpu *current,
81 const struct ffa_uuid *uuid,
Karl Meakin2ad6b662024-07-29 20:45:40 +010082 uint16_t start_index,
83 uint16_t tag);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010084struct ffa_value api_ffa_id_get(const struct vcpu *current);
Daniel Boulbyb2fb80e2021-02-03 15:09:23 +000085struct ffa_value api_ffa_spm_id_get(void);
J-Alves6f72ca82021-11-01 12:34:58 +000086struct ffa_value api_ffa_feature_success(uint32_t arg2);
Karl Meakin49ec1e42024-05-10 13:08:24 +010087struct ffa_value api_ffa_features(uint32_t function_or_feature_id,
Karl Meakinf1ed5f12024-02-22 15:57:36 +000088 uint32_t input_property,
89 struct vcpu *current);
Madhukar Pappireddy5522c672021-12-17 16:35:51 -060090struct ffa_value api_ffa_msg_wait(struct vcpu *current, struct vcpu **next,
91 struct ffa_value *args);
J-Alves19e20cf2023-08-02 12:48:55 +010092struct ffa_value api_ffa_run(ffa_id_t vm_id, ffa_vcpu_index_t vcpu_idx,
Madhukar Pappireddyb11e0d12021-08-02 19:44:35 -050093 struct vcpu *current, struct vcpu **next);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010094struct ffa_value api_ffa_mem_send(uint32_t share_func, uint32_t length,
95 uint32_t fragment_length, ipaddr_t address,
Andrew Walbran1a86aa92020-05-15 17:22:28 +010096 uint32_t page_count, struct vcpu *current);
Andrew Walbranb5ab43c2020-04-30 11:32:54 +010097struct ffa_value api_ffa_mem_retrieve_req(uint32_t length,
98 uint32_t fragment_length,
99 ipaddr_t address, uint32_t page_count,
100 struct vcpu *current);
101struct ffa_value api_ffa_mem_relinquish(struct vcpu *current);
102struct ffa_value api_ffa_mem_reclaim(ffa_memory_handle_t handle,
103 ffa_memory_region_flags_t flags,
104 struct vcpu *current);
Andrew Walbranca808b12020-05-15 17:22:28 +0100105struct ffa_value api_ffa_mem_frag_rx(ffa_memory_handle_t handle,
106 uint32_t fragment_offset,
J-Alves19e20cf2023-08-02 12:48:55 +0100107 ffa_id_t sender_vm_id,
Andrew Walbranca808b12020-05-15 17:22:28 +0100108 struct vcpu *current);
109struct ffa_value api_ffa_mem_frag_tx(ffa_memory_handle_t handle,
110 uint32_t fragment_length,
J-Alves19e20cf2023-08-02 12:48:55 +0100111 ffa_id_t sender_vm_id,
Andrew Walbranca808b12020-05-15 17:22:28 +0100112 struct vcpu *current);
J-Alves19e20cf2023-08-02 12:48:55 +0100113struct ffa_value api_ffa_msg_send_direct_req(ffa_id_t sender_vm_id,
114 ffa_id_t receiver_vm_id,
Olivier Deprezee9d6a92019-11-26 09:14:11 +0000115 struct ffa_value args,
116 struct vcpu *current,
117 struct vcpu **next);
Kathleen Capella41fea932023-06-23 17:39:28 -0400118struct ffa_value api_ffa_msg_send_direct_req2(ffa_id_t sender_vm_id,
119 ffa_id_t receiver_vm_id,
120 struct ffa_value args,
121 struct vcpu *current,
122 struct vcpu **next);
J-Alves19e20cf2023-08-02 12:48:55 +0100123struct ffa_value api_ffa_msg_send_direct_resp(ffa_id_t sender_vm_id,
124 ffa_id_t receiver_vm_id,
Olivier Deprezee9d6a92019-11-26 09:14:11 +0000125 struct ffa_value args,
126 struct vcpu *current,
127 struct vcpu **next);
Kathleen Capella087e5022023-09-07 18:04:15 -0400128struct ffa_value api_ffa_msg_send_direct_resp2(ffa_id_t sender_vm_id,
129 ffa_id_t receiver_vm_id,
130 struct ffa_value args,
131 struct vcpu *current,
132 struct vcpu **next);
Max Shvetsov40108e72020-08-27 12:39:50 +0100133struct ffa_value api_ffa_secondary_ep_register(ipaddr_t entry_point,
134 struct vcpu *current);
Madhukar Pappireddybd10e572023-03-06 16:39:49 -0600135struct vcpu *api_switch_to_other_world(struct vcpu_locked current_locked,
Manish Pandeya5f39fb2020-09-11 09:47:11 +0100136 struct ffa_value other_world_ret,
137 enum vcpu_state vcpu_state);
J-Alves19e20cf2023-08-02 12:48:55 +0100138struct ffa_value api_ffa_notification_bitmap_create(ffa_id_t vm_id,
J-Alvesa0f317d2021-06-09 13:31:59 +0100139 ffa_vcpu_count_t vcpu_count,
140 struct vcpu *current);
J-Alves19e20cf2023-08-02 12:48:55 +0100141struct ffa_value api_ffa_notification_bitmap_destroy(ffa_id_t vm_id,
J-Alvesa0f317d2021-06-09 13:31:59 +0100142 struct vcpu *current);
J-Alvesc003a7a2021-03-18 13:06:53 +0000143
144struct ffa_value api_ffa_notification_update_bindings(
J-Alves19e20cf2023-08-02 12:48:55 +0100145 ffa_id_t sender_vm_id, ffa_id_t receiver_vm_id, uint32_t flags,
J-Alvesc003a7a2021-03-18 13:06:53 +0000146 ffa_notifications_bitmap_t notifications, bool is_bind,
147 struct vcpu *current);
J-Alvesaa79c012021-07-09 14:29:45 +0100148
149struct ffa_value api_ffa_notification_set(
J-Alves19e20cf2023-08-02 12:48:55 +0100150 ffa_id_t sender_vm_id, ffa_id_t receiver_vm_id, uint32_t flags,
J-Alvesaa79c012021-07-09 14:29:45 +0100151 ffa_notifications_bitmap_t notifications, struct vcpu *current);
152
J-Alves19e20cf2023-08-02 12:48:55 +0100153struct ffa_value api_ffa_notification_get(ffa_id_t receiver_vm_id,
J-Alvesaa79c012021-07-09 14:29:45 +0100154 uint16_t vcpu_id, uint32_t flags,
155 struct vcpu *current);
J-Alvesc8e8a222021-06-08 17:33:52 +0100156
157struct ffa_value api_ffa_notification_info_get(struct vcpu *current);
Raghu Krishnamurthyea6d25f2021-09-14 15:27:06 -0700158
159struct ffa_value api_ffa_mem_perm_get(vaddr_t base_addr, struct vcpu *current);
160struct ffa_value api_ffa_mem_perm_set(vaddr_t base_addr, uint32_t page_count,
161 uint32_t mem_perm, struct vcpu *current);
Maksims Svecovs71b76702022-05-20 15:32:58 +0100162
Karl Meakin6f1f1212024-07-16 10:18:16 +0100163void api_flush_log_buffer(struct vcpu_locked *vcpu_locked);
Karl Meakin2ad6b662024-07-29 20:45:40 +0100164struct ffa_value api_ffa_console_log(struct ffa_value args,
Maksims Svecovs71b76702022-05-20 15:32:58 +0100165 struct vcpu *current);
Madhukar Pappireddy2f76e492022-09-06 15:21:59 -0500166
Madhukar Pappireddybd10e572023-03-06 16:39:49 -0600167void api_ffa_resume_direct_resp_target(struct vcpu_locked current_locked,
168 struct vcpu **next,
J-Alves19e20cf2023-08-02 12:48:55 +0100169 ffa_id_t receiver_vm_id,
Madhukar Pappireddy2f76e492022-09-06 15:21:59 -0500170 struct ffa_value to_ret,
171 bool is_nwd_call_chain);
Kathleen Capella036cc592023-11-30 18:26:15 -0500172
173bool api_extended_args_are_zero(struct ffa_value *args);