Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 1 | #ifndef _VMAPI_HF_HVC_H |
| 2 | #define _VMAPI_HF_HVC_H |
| 3 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 4 | #if defined(__linux__) && defined(__KERNEL__) |
| 5 | |
| 6 | #include <linux/types.h> |
| 7 | |
| 8 | typedef phys_addr_t hf_ipaddr_t; |
| 9 | |
| 10 | #else |
| 11 | |
| 12 | #include <stdbool.h> |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 13 | #include <stddef.h> |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 14 | #include <stdint.h> |
| 15 | |
| 16 | typedef uintptr_t hf_ipaddr_t; |
| 17 | |
| 18 | #endif |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 19 | |
| 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 Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 41 | /** |
| 42 | * This function must be implemented to trigger the architecture specific |
| 43 | * mechanism to call to the hypervisor. |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 44 | */ |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 45 | size_t hf_call(size_t arg0, size_t arg1, size_t arg2, size_t arg3); |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 46 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 47 | /** |
| 48 | * Runs the given vcpu of the given vm. |
| 49 | */ |
| 50 | static 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 Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 56 | * Returns the number of secondary VMs. |
| 57 | */ |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 58 | static inline int32_t hf_vm_get_count(void) |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 59 | { |
| 60 | return hf_call(HF_VM_GET_COUNT, 0, 0, 0); |
| 61 | } |
| 62 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 63 | /** |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 64 | * Returns the number of VCPUs configured in the given secondary VM. |
| 65 | */ |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 66 | static inline int32_t hf_vcpu_get_count(uint32_t vm_idx) |
Andrew Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 67 | { |
| 68 | return hf_call(HF_VCPU_GET_COUNT, vm_idx, 0, 0); |
| 69 | } |
| 70 | |
Andrew Scull | 5ac05f0 | 2018-08-10 17:23:22 +0100 | [diff] [blame] | 71 | /** |
| 72 | * Configures the pages to send/receive data through. The pages must not be |
| 73 | * shared. |
| 74 | */ |
| 75 | static 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 | */ |
| 84 | static 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 | */ |
| 98 | static 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 | */ |
| 108 | static 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 | */ |
| 119 | static 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 Scull | f35a5c9 | 2018-08-07 18:09:46 +0100 | [diff] [blame] | 124 | #endif /* _VMAPI_HF_HVC_H */ |