xref: /qemu/include/hw/hyperv/hyperv.h (revision ec7e5a90fea996f04ea24e81b680a87bc975354a)
1 /*
2  * Hyper-V guest/hypervisor interaction
3  *
4  * Copyright (c) 2015-2018 Virtuozzo International GmbH.
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  */
9 
10 #ifndef HW_HYPERV_HYPERV_H
11 #define HW_HYPERV_HYPERV_H
12 
13 #include "exec/hwaddr.h"
14 #include "hw/core/cpu.h"
15 #include "hw/hyperv/hyperv-proto.h"
16 
17 typedef struct HvSintRoute HvSintRoute;
18 
19 /*
20  * Callback executed in a bottom-half when the status of posting the message
21  * becomes known, before unblocking the connection for further messages
22  */
23 typedef void (*HvSintMsgCb)(void *data, int status);
24 
25 HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
26                                    HvSintMsgCb cb, void *cb_data);
27 void hyperv_sint_route_ref(HvSintRoute *sint_route);
28 void hyperv_sint_route_unref(HvSintRoute *sint_route);
29 
30 int hyperv_sint_route_set_sint(HvSintRoute *sint_route);
31 
32 /*
33  * Submit a message to be posted in vcpu context.  If the submission succeeds,
34  * the status of posting the message is reported via the callback associated
35  * with the @sint_route; until then no more messages are accepted.
36  */
37 int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg);
38 /*
39  * Set event flag @eventno, and signal the SINT if the flag has changed.
40  */
41 int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno);
42 
43 /*
44  * Handler for messages arriving from the guest via HV_POST_MESSAGE hypercall.
45  * Executed in vcpu context.
46  */
47 typedef uint16_t (*HvMsgHandler)(const struct hyperv_post_message_input *msg,
48                                  void *data);
49 /*
50  * Associate @handler with the message connection @conn_id, such that @handler
51  * is called with @data when the guest executes HV_POST_MESSAGE hypercall on
52  * @conn_id.  If @handler is NULL clear the association.
53  */
54 int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data);
55 /*
56  * Associate @notifier with the event connection @conn_id, such that @notifier
57  * is signaled when the guest executes HV_SIGNAL_EVENT hypercall on @conn_id.
58  * If @notifier is NULL clear the association.
59  */
60 int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier);
61 
62 /*
63  * Process HV_POST_MESSAGE hypercall: parse the data in the guest memory as
64  * specified in @param, and call the HvMsgHandler associated with the
65  * connection on the message contained therein.
66  */
67 uint16_t hyperv_hcall_post_message(uint64_t param, bool fast);
68 /*
69  * Process HV_SIGNAL_EVENT hypercall: signal the EventNotifier associated with
70  * the connection as specified in @param.
71  */
72 uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast);
73 
74 static inline uint32_t hyperv_vp_index(CPUState *cs)
75 {
76     return cs->cpu_index;
77 }
78 
79 void hyperv_synic_add(CPUState *cs);
80 void hyperv_synic_reset(CPUState *cs);
81 void hyperv_synic_update(CPUState *cs, bool enable,
82                          hwaddr msg_page_addr, hwaddr event_page_addr);
83 bool hyperv_is_synic_enabled(void);
84 
85 /*
86  * Process HVCALL_RESET_DEBUG_SESSION hypercall.
87  */
88 uint16_t hyperv_hcall_reset_dbg_session(uint64_t outgpa);
89 /*
90  * Process HVCALL_RETREIVE_DEBUG_DATA hypercall.
91  */
92 uint16_t hyperv_hcall_retreive_dbg_data(uint64_t ingpa, uint64_t outgpa,
93                                         bool fast);
94 /*
95  * Process HVCALL_POST_DEBUG_DATA hypercall.
96  */
97 uint16_t hyperv_hcall_post_dbg_data(uint64_t ingpa, uint64_t outgpa, bool fast);
98 
99 uint32_t hyperv_syndbg_send(uint64_t ingpa, uint32_t count);
100 uint32_t hyperv_syndbg_recv(uint64_t ingpa, uint32_t count);
101 void hyperv_syndbg_set_pending_page(uint64_t ingpa);
102 uint64_t hyperv_syndbg_query_options(void);
103 
104 typedef enum HvSynthDbgMsgType {
105     HV_SYNDBG_MSG_CONNECTION_INFO,
106     HV_SYNDBG_MSG_SEND,
107     HV_SYNDBG_MSG_RECV,
108     HV_SYNDBG_MSG_SET_PENDING_PAGE,
109     HV_SYNDBG_MSG_QUERY_OPTIONS
110 } HvDbgSynthMsgType;
111 
112 typedef struct HvSynDbgMsg {
113     HvDbgSynthMsgType type;
114     union {
115         struct {
116             uint32_t host_ip;
117             uint16_t host_port;
118         } connection_info;
119         struct {
120             uint64_t buf_gpa;
121             uint32_t count;
122             uint32_t pending_count;
123             bool is_raw;
124         } send;
125         struct {
126             uint64_t buf_gpa;
127             uint32_t count;
128             uint32_t options;
129             uint64_t timeout;
130             uint32_t retrieved_count;
131             bool is_raw;
132         } recv;
133         struct {
134             uint64_t buf_gpa;
135         } pending_page;
136         struct {
137             uint64_t options;
138         } query_options;
139     } u;
140 } HvSynDbgMsg;
141 typedef uint16_t (*HvSynDbgHandler)(void *context, HvSynDbgMsg *msg);
142 void hyperv_set_syndbg_handler(HvSynDbgHandler handler, void *context);
143 
144 bool hyperv_are_vmbus_recommended_features_enabled(void);
145 void hyperv_set_vmbus_recommended_features_enabled(void);
146 
147 #endif
148