xref: /openbmc/qemu/include/hw/hyperv/hyperv.h (revision 750541c4)
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 "cpu-qom.h"
14 #include "hw/hyperv/hyperv-proto.h"
15 
16 typedef struct HvSintRoute HvSintRoute;
17 
18 /*
19  * Callback executed in a bottom-half when the status of posting the message
20  * becomes known, before unblocking the connection for further messages
21  */
22 typedef void (*HvSintMsgCb)(void *data, int status);
23 
24 HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint,
25                                    HvSintMsgCb cb, void *cb_data);
26 void hyperv_sint_route_ref(HvSintRoute *sint_route);
27 void hyperv_sint_route_unref(HvSintRoute *sint_route);
28 
29 int hyperv_sint_route_set_sint(HvSintRoute *sint_route);
30 
31 /*
32  * Submit a message to be posted in vcpu context.  If the submission succeeds,
33  * the status of posting the message is reported via the callback associated
34  * with the @sint_route; until then no more messages are accepted.
35  */
36 int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg);
37 /*
38  * Set event flag @eventno, and signal the SINT if the flag has changed.
39  */
40 int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno);
41 
42 /*
43  * Handler for messages arriving from the guest via HV_POST_MESSAGE hypercall.
44  * Executed in vcpu context.
45  */
46 typedef uint16_t (*HvMsgHandler)(const struct hyperv_post_message_input *msg,
47                                  void *data);
48 /*
49  * Associate @handler with the message connection @conn_id, such that @handler
50  * is called with @data when the guest executes HV_POST_MESSAGE hypercall on
51  * @conn_id.  If @handler is NULL clear the association.
52  */
53 int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data);
54 /*
55  * Associate @notifier with the event connection @conn_id, such that @notifier
56  * is signaled when the guest executes HV_SIGNAL_EVENT hypercall on @conn_id.
57  * If @notifier is NULL clear the association.
58  */
59 int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier);
60 
61 /*
62  * Process HV_POST_MESSAGE hypercall: parse the data in the guest memory as
63  * specified in @param, and call the HvMsgHandler associated with the
64  * connection on the message contained therein.
65  */
66 uint16_t hyperv_hcall_post_message(uint64_t param, bool fast);
67 /*
68  * Process HV_SIGNAL_EVENT hypercall: signal the EventNotifier associated with
69  * the connection as specified in @param.
70  */
71 uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast);
72 
73 static inline uint32_t hyperv_vp_index(CPUState *cs)
74 {
75     return cs->cpu_index;
76 }
77 
78 void hyperv_synic_add(CPUState *cs);
79 void hyperv_synic_reset(CPUState *cs);
80 void hyperv_synic_update(CPUState *cs, bool enable,
81                          hwaddr msg_page_addr, hwaddr event_page_addr);
82 
83 #endif
84