xref: /qemu/include/hw/hyperv/hyperv-proto.h (revision 4c33c097f3a8a8093bcbaf097c3a178051e51b3e)
1 /*
2  * Definitions for Hyper-V guest/hypervisor interaction
3  *
4  * Copyright (c) 2017-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_PROTO_H
11 #define HW_HYPERV_HYPERV_PROTO_H
12 
13 #include "qemu/bitmap.h"
14 
15 /*
16  * Hypercall status code
17  */
18 #define HV_STATUS_SUCCESS                     0
19 #define HV_STATUS_INVALID_HYPERCALL_CODE      2
20 #define HV_STATUS_INVALID_HYPERCALL_INPUT     3
21 #define HV_STATUS_INVALID_ALIGNMENT           4
22 #define HV_STATUS_INVALID_PARAMETER           5
23 #define HV_STATUS_INSUFFICIENT_MEMORY         11
24 #define HV_STATUS_INVALID_PORT_ID             17
25 #define HV_STATUS_INVALID_CONNECTION_ID       18
26 #define HV_STATUS_INSUFFICIENT_BUFFERS        19
27 #define HV_STATUS_NOT_ACKNOWLEDGED            20
28 #define HV_STATUS_NO_DATA                     27
29 
30 /*
31  * Hypercall numbers
32  */
33 #define HV_POST_MESSAGE                       0x005c
34 #define HV_SIGNAL_EVENT                       0x005d
35 #define HV_POST_DEBUG_DATA                    0x0069
36 #define HV_RETRIEVE_DEBUG_DATA                0x006a
37 #define HV_RESET_DEBUG_SESSION                0x006b
38 #define HV_HYPERCALL_FAST                     (1u << 16)
39 
40 /*
41  * Message size
42  */
43 #define HV_MESSAGE_PAYLOAD_SIZE               240
44 
45 /*
46  * Message types
47  */
48 #define HV_MESSAGE_NONE                       0x00000000
49 #define HV_MESSAGE_VMBUS                      0x00000001
50 #define HV_MESSAGE_UNMAPPED_GPA               0x80000000
51 #define HV_MESSAGE_GPA_INTERCEPT              0x80000001
52 #define HV_MESSAGE_TIMER_EXPIRED              0x80000010
53 #define HV_MESSAGE_INVALID_VP_REGISTER_VALUE  0x80000020
54 #define HV_MESSAGE_UNRECOVERABLE_EXCEPTION    0x80000021
55 #define HV_MESSAGE_UNSUPPORTED_FEATURE        0x80000022
56 #define HV_MESSAGE_EVENTLOG_BUFFERCOMPLETE    0x80000040
57 #define HV_MESSAGE_X64_IOPORT_INTERCEPT       0x80010000
58 #define HV_MESSAGE_X64_MSR_INTERCEPT          0x80010001
59 #define HV_MESSAGE_X64_CPUID_INTERCEPT        0x80010002
60 #define HV_MESSAGE_X64_EXCEPTION_INTERCEPT    0x80010003
61 #define HV_MESSAGE_X64_APIC_EOI               0x80010004
62 #define HV_MESSAGE_X64_LEGACY_FP_ERROR        0x80010005
63 
64 /*
65  * Hyper-V Synthetic debug options MSR
66  */
67 #define HV_X64_MSR_SYNDBG_CONTROL               0x400000F1
68 #define HV_X64_MSR_SYNDBG_STATUS                0x400000F2
69 #define HV_X64_MSR_SYNDBG_SEND_BUFFER           0x400000F3
70 #define HV_X64_MSR_SYNDBG_RECV_BUFFER           0x400000F4
71 #define HV_X64_MSR_SYNDBG_PENDING_BUFFER        0x400000F5
72 #define HV_X64_MSR_SYNDBG_OPTIONS               0x400000FF
73 
74 #define HV_X64_SYNDBG_OPTION_USE_HCALLS         BIT(2)
75 
76 /*
77  * Message flags
78  */
79 #define HV_MESSAGE_FLAG_PENDING               0x1
80 
81 /*
82  * Number of synthetic interrupts
83  */
84 #define HV_SINT_COUNT                         16
85 
86 /*
87  * Event flags number per SINT
88  */
89 #define HV_EVENT_FLAGS_COUNT                  (256 * 8)
90 
91 /*
92  * Connection id valid bits
93  */
94 #define HV_CONNECTION_ID_MASK                 0x00ffffff
95 
96 /*
97  * Input structure for POST_MESSAGE hypercall
98  */
99 struct hyperv_post_message_input {
100     uint32_t connection_id;
101     uint32_t _reserved;
102     uint32_t message_type;
103     uint32_t payload_size;
104     uint8_t  payload[HV_MESSAGE_PAYLOAD_SIZE];
105 };
106 
107 /*
108  * Input structure for SIGNAL_EVENT hypercall
109  */
110 struct hyperv_signal_event_input {
111     uint32_t connection_id;
112     uint16_t flag_number;
113     uint16_t _reserved_zero;
114 };
115 
116 /*
117  * SynIC message structures
118  */
119 struct hyperv_message_header {
120     uint32_t message_type;
121     uint8_t  payload_size;
122     uint8_t  message_flags; /* HV_MESSAGE_FLAG_XX */
123     uint8_t  _reserved[2];
124     uint64_t sender;
125 };
126 
127 struct hyperv_message {
128     struct hyperv_message_header header;
129     uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE];
130 };
131 
132 struct hyperv_message_page {
133     struct hyperv_message slot[HV_SINT_COUNT];
134 };
135 
136 /*
137  * SynIC event flags structures
138  */
139 struct hyperv_event_flags {
140     DECLARE_BITMAP(flags, HV_EVENT_FLAGS_COUNT);
141 };
142 
143 struct hyperv_event_flags_page {
144     struct hyperv_event_flags slot[HV_SINT_COUNT];
145 };
146 
147 /*
148  * Kernel debugger structures
149  */
150 
151 /* Options flags for hyperv_reset_debug_session */
152 #define HV_DEBUG_PURGE_INCOMING_DATA        0x00000001
153 #define HV_DEBUG_PURGE_OUTGOING_DATA        0x00000002
154 struct hyperv_reset_debug_session_input {
155     uint32_t options;
156 } __attribute__ ((__packed__));
157 
158 struct hyperv_reset_debug_session_output {
159     uint32_t host_ip;
160     uint32_t target_ip;
161     uint16_t host_port;
162     uint16_t target_port;
163     uint8_t host_mac[6];
164     uint8_t target_mac[6];
165 } __attribute__ ((__packed__));
166 
167 /* Options for hyperv_post_debug_data */
168 #define HV_DEBUG_POST_LOOP                  0x00000001
169 
170 struct hyperv_post_debug_data_input {
171     uint32_t count;
172     uint32_t options;
173     /*uint8_t data[HV_HYP_PAGE_SIZE - 2 * sizeof(uint32_t)];*/
174 } __attribute__ ((__packed__));
175 
176 struct hyperv_post_debug_data_output {
177     uint32_t pending_count;
178 } __attribute__ ((__packed__));
179 
180 /* Options for hyperv_retrieve_debug_data */
181 #define HV_DEBUG_RETRIEVE_LOOP              0x00000001
182 #define HV_DEBUG_RETRIEVE_TEST_ACTIVITY     0x00000002
183 
184 struct hyperv_retrieve_debug_data_input {
185     uint32_t count;
186     uint32_t options;
187     uint64_t timeout;
188 } __attribute__ ((__packed__));
189 
190 struct hyperv_retrieve_debug_data_output {
191     uint32_t retrieved_count;
192     uint32_t remaining_count;
193 } __attribute__ ((__packed__));
194 #endif
195