1 /*
2  * Copyright 2018 The Hafnium Authors.
3  *
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.
7  */
8 
9 #pragma once
10 
11 #include "hf/cpu.h"
12 #include "hf/mpool.h"
13 #include "hf/vm.h"
14 
15 #include "vmapi/hf/call.h"
16 #include "vmapi/hf/ffa.h"
17 
18 void api_init(struct mpool *ppool);
19 struct vcpu *api_ffa_get_vm_vcpu(struct vm *vm, struct vcpu *current);
20 void api_regs_state_saved(struct vcpu *vcpu);
21 int64_t api_mailbox_writable_get(const struct vcpu *current);
22 int64_t api_mailbox_waiter_get(ffa_vm_id_t vm_id, const struct vcpu *current);
23 int64_t api_debug_log(char c, struct vcpu *current);
24 
25 struct vcpu *api_preempt(struct vcpu *current);
26 struct vcpu *api_wait_for_interrupt(struct vcpu *current);
27 struct vcpu *api_vcpu_off(struct vcpu *current);
28 struct vcpu *api_abort(struct vcpu *current);
29 struct vcpu *api_wake_up(struct vcpu *current, struct vcpu *target_vcpu);
30 
31 int64_t api_interrupt_enable(uint32_t intid, bool enable,
32 			     enum interrupt_type type, struct vcpu *current);
33 uint32_t api_interrupt_get(struct vcpu *current);
34 int64_t api_interrupt_inject(ffa_vm_id_t target_vm_id,
35 			     ffa_vcpu_index_t target_vcpu_idx, uint32_t intid,
36 			     struct vcpu *current, struct vcpu **next);
37 int64_t api_interrupt_inject_locked(struct vcpu_locked target_locked,
38 				    uint32_t intid, struct vcpu *current,
39 				    struct vcpu **next);
40 void api_sri_send_if_delayed(struct vcpu *current);
41 
42 struct ffa_value api_ffa_msg_send(ffa_vm_id_t sender_vm_id,
43 				  ffa_vm_id_t receiver_vm_id, uint32_t size,
44 				  struct vcpu *current, struct vcpu **next);
45 struct ffa_value api_ffa_msg_send2(ffa_vm_id_t sender_vm_id, uint32_t flags,
46 				   struct vcpu *current);
47 struct ffa_value api_ffa_msg_recv(bool block, struct vcpu *current,
48 				  struct vcpu **next);
49 struct ffa_value api_ffa_rx_release(ffa_vm_id_t receiver_id,
50 				    struct vcpu *current, struct vcpu **next);
51 struct ffa_value api_ffa_rx_acquire(ffa_vm_id_t receiver_id,
52 				    struct vcpu *current);
53 struct ffa_value api_vm_configure_pages(
54 	struct mm_stage1_locked mm_stage1_locked, struct vm_locked vm_locked,
55 	ipaddr_t send, ipaddr_t recv, uint32_t page_count,
56 	struct mpool *local_page_pool);
57 struct ffa_value api_ffa_rxtx_map(ipaddr_t send, ipaddr_t recv,
58 				  uint32_t page_count, struct vcpu *current);
59 struct ffa_value api_ffa_rxtx_unmap(ffa_vm_id_t allocator_id,
60 				    struct vcpu *current);
61 struct ffa_value api_yield(struct vcpu *current, struct vcpu **next);
62 struct ffa_value api_ffa_version(struct vcpu *current,
63 				 uint32_t requested_version);
64 struct ffa_value api_ffa_partition_info_get(struct vcpu *current,
65 					    const struct ffa_uuid *uuid,
66 					    const uint32_t flags);
67 struct ffa_value api_ffa_id_get(const struct vcpu *current);
68 struct ffa_value api_ffa_spm_id_get(void);
69 struct ffa_value api_ffa_feature_success(uint32_t arg2);
70 struct ffa_value api_ffa_features(uint32_t function_id);
71 struct ffa_value api_ffa_msg_wait(struct vcpu *current, struct vcpu **next,
72 				  struct ffa_value *args);
73 struct ffa_value api_ffa_run(ffa_vm_id_t vm_id, ffa_vcpu_index_t vcpu_idx,
74 			     struct vcpu *current, struct vcpu **next);
75 struct ffa_value api_ffa_mem_send(uint32_t share_func, uint32_t length,
76 				  uint32_t fragment_length, ipaddr_t address,
77 				  uint32_t page_count, struct vcpu *current);
78 struct ffa_value api_ffa_mem_retrieve_req(uint32_t length,
79 					  uint32_t fragment_length,
80 					  ipaddr_t address, uint32_t page_count,
81 					  struct vcpu *current);
82 struct ffa_value api_ffa_mem_relinquish(struct vcpu *current);
83 struct ffa_value api_ffa_mem_reclaim(ffa_memory_handle_t handle,
84 				     ffa_memory_region_flags_t flags,
85 				     struct vcpu *current);
86 struct ffa_value api_ffa_mem_frag_rx(ffa_memory_handle_t handle,
87 				     uint32_t fragment_offset,
88 				     ffa_vm_id_t sender_vm_id,
89 				     struct vcpu *current);
90 struct ffa_value api_ffa_mem_frag_tx(ffa_memory_handle_t handle,
91 				     uint32_t fragment_length,
92 				     ffa_vm_id_t sender_vm_id,
93 				     struct vcpu *current);
94 struct ffa_value api_ffa_msg_send_direct_req(ffa_vm_id_t sender_vm_id,
95 					     ffa_vm_id_t receiver_vm_id,
96 					     struct ffa_value args,
97 					     struct vcpu *current,
98 					     struct vcpu **next);
99 struct ffa_value api_ffa_msg_send_direct_resp(ffa_vm_id_t sender_vm_id,
100 					      ffa_vm_id_t receiver_vm_id,
101 					      struct ffa_value args,
102 					      struct vcpu *current,
103 					      struct vcpu **next);
104 struct ffa_value api_ffa_secondary_ep_register(ipaddr_t entry_point,
105 					       struct vcpu *current);
106 struct vcpu *api_switch_to_other_world(struct vcpu *current,
107 				       struct ffa_value other_world_ret,
108 				       enum vcpu_state vcpu_state);
109 struct ffa_value api_ffa_notification_bitmap_create(ffa_vm_id_t vm_id,
110 						    ffa_vcpu_count_t vcpu_count,
111 						    struct vcpu *current);
112 struct ffa_value api_ffa_notification_bitmap_destroy(ffa_vm_id_t vm_id,
113 						     struct vcpu *current);
114 
115 struct ffa_value api_ffa_notification_update_bindings(
116 	ffa_vm_id_t sender_vm_id, ffa_vm_id_t receiver_vm_id, uint32_t flags,
117 	ffa_notifications_bitmap_t notifications, bool is_bind,
118 	struct vcpu *current);
119 
120 struct ffa_value api_ffa_notification_set(
121 	ffa_vm_id_t sender_vm_id, ffa_vm_id_t receiver_vm_id, uint32_t flags,
122 	ffa_notifications_bitmap_t notifications, struct vcpu *current);
123 
124 struct ffa_value api_ffa_notification_get(ffa_vm_id_t receiver_vm_id,
125 					  uint16_t vcpu_id, uint32_t flags,
126 					  struct vcpu *current);
127 
128 struct ffa_value api_ffa_notification_info_get(struct vcpu *current);
129 
130 struct ffa_value api_ffa_mem_perm_get(vaddr_t base_addr, struct vcpu *current);
131 struct ffa_value api_ffa_mem_perm_set(vaddr_t base_addr, uint32_t page_count,
132 				      uint32_t mem_perm, struct vcpu *current);
133 
134 struct ffa_value api_ffa_console_log(const struct ffa_value args,
135 				     struct vcpu *current);
136