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