blob: e8391f6c75f539078ac9fb93de80fd4975719175 [file] [log] [blame]
Andrew Scullfbc938a2018-08-20 14:09:28 +01001#pragma once
Andrew Scullf35a5c92018-08-07 18:09:46 +01002
Andrew Scull5ac05f02018-08-10 17:23:22 +01003#if defined(__linux__) && defined(__KERNEL__)
4
5#include <linux/types.h>
6
7typedef phys_addr_t hf_ipaddr_t;
8
9#else
10
11#include <stdbool.h>
Andrew Scullf35a5c92018-08-07 18:09:46 +010012#include <stddef.h>
Andrew Scull5ac05f02018-08-10 17:23:22 +010013#include <stdint.h>
14
15typedef uintptr_t hf_ipaddr_t;
16
17#endif
Andrew Scullf35a5c92018-08-07 18:09:46 +010018
19/* Keep macro alignment */
20/* clang-format off */
21
22/* Return values for vcpu_run() hypervisor call. */
23#define HF_VCPU_YIELD 0x00
24#define HF_VCPU_WAIT_FOR_INTERRUPT 0x01
25#define HF_VCPU_WAKE_UP 0x02
26#define HF_VCPU_RESPONSE_READY 0x03
27
28/* TODO: Define constants below according to spec. */
29#define HF_VCPU_RUN 0xff00
30#define HF_VM_GET_COUNT 0xff01
31#define HF_VCPU_GET_COUNT 0xff02
32#define HF_VM_CONFIGURE 0xff03
33#define HF_RPC_REQUEST 0xff04
34#define HF_RPC_READ_REQUEST 0xff05
35#define HF_RPC_ACK 0xff06
36#define HF_RPC_REPLY 0xff07
37
38/* clang-format on */
39
Andrew Scull5ac05f02018-08-10 17:23:22 +010040/**
41 * This function must be implemented to trigger the architecture specific
42 * mechanism to call to the hypervisor.
Andrew Scullf35a5c92018-08-07 18:09:46 +010043 */
Andrew Scull5ac05f02018-08-10 17:23:22 +010044size_t hf_call(size_t arg0, size_t arg1, size_t arg2, size_t arg3);
Andrew Scullf35a5c92018-08-07 18:09:46 +010045
Andrew Scull5ac05f02018-08-10 17:23:22 +010046/**
47 * Runs the given vcpu of the given vm.
48 */
49static inline int32_t hf_vcpu_run(uint32_t vm_idx, uint32_t vcpu_idx)
50{
51 return hf_call(HF_VCPU_RUN, vm_idx, vcpu_idx, 0);
52}
53
54/**
Andrew Scullf35a5c92018-08-07 18:09:46 +010055 * Returns the number of secondary VMs.
56 */
Andrew Scull5ac05f02018-08-10 17:23:22 +010057static inline int32_t hf_vm_get_count(void)
Andrew Scullf35a5c92018-08-07 18:09:46 +010058{
59 return hf_call(HF_VM_GET_COUNT, 0, 0, 0);
60}
61
Andrew Scull5ac05f02018-08-10 17:23:22 +010062/**
Andrew Scullf35a5c92018-08-07 18:09:46 +010063 * Returns the number of VCPUs configured in the given secondary VM.
64 */
Andrew Scull5ac05f02018-08-10 17:23:22 +010065static inline int32_t hf_vcpu_get_count(uint32_t vm_idx)
Andrew Scullf35a5c92018-08-07 18:09:46 +010066{
67 return hf_call(HF_VCPU_GET_COUNT, vm_idx, 0, 0);
68}
69
Andrew Scull5ac05f02018-08-10 17:23:22 +010070/**
71 * Configures the pages to send/receive data through. The pages must not be
72 * shared.
73 */
74static inline int32_t hf_vm_configure(hf_ipaddr_t send, hf_ipaddr_t recv)
75{
76 return hf_call(HF_VM_CONFIGURE, send, recv, 0);
77}
78
79/**
80 * Called by the primary VM to send an RPC request to a secondary VM. Data is
81 * copied from the caller's send buffer to the destination's receive buffer.
82 */
83static inline int32_t hf_rpc_request(uint32_t vm_idx, size_t size)
84{
85 return hf_call(HF_RPC_REQUEST, vm_idx, size, 0);
86}
87
88/**
89 * Called by the primary VM to read a request sent from a previous call to
90 * api_rpc_request. If one isn't available, this function can optionally block
91 * the caller until one becomes available.
92 *
93 * Once the caller has completed handling a request, it must indicate it by
94 * either calling api_rpc_reply or api_rpc_ack. No new requests can be accepted
95 * until the current one is acknowledged.
96 */
97static inline int32_t hf_rpc_read_request(bool block)
98{
99 return hf_call(HF_RPC_READ_REQUEST, block, 0, 0);
100}
101
102/**
103 * Acknowledges that either a request or a reply has been received and handled.
104 * After this call completes, the caller will be able to receive additional
105 * requests or replies.
106 */
107static inline int32_t hf_rpc_ack(void)
108{
109 return hf_call(HF_RPC_ACK, 0, 0, 0);
110}
111
112/**
113 * Called by a secondary VM to send a reply to the primary VM. Data is copied
114 * from the caller's send buffer to the destination's receive buffer.
115 *
116 * It can optionally acknowledge the pending request.
117 */
118static inline int32_t hf_rpc_reply(size_t size, bool ack)
119{
120 return hf_call(HF_RPC_REPLY, size, ack, 0);
121}