xref: /qemu/include/hw/hyperv/hyperv-proto.h (revision a976a99a)
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  * Message flags
66  */
67 #define HV_MESSAGE_FLAG_PENDING               0x1
68 
69 /*
70  * Number of synthetic interrupts
71  */
72 #define HV_SINT_COUNT                         16
73 
74 /*
75  * Event flags number per SINT
76  */
77 #define HV_EVENT_FLAGS_COUNT                  (256 * 8)
78 
79 /*
80  * Connection id valid bits
81  */
82 #define HV_CONNECTION_ID_MASK                 0x00ffffff
83 
84 /*
85  * Input structure for POST_MESSAGE hypercall
86  */
87 struct hyperv_post_message_input {
88     uint32_t connection_id;
89     uint32_t _reserved;
90     uint32_t message_type;
91     uint32_t payload_size;
92     uint8_t  payload[HV_MESSAGE_PAYLOAD_SIZE];
93 };
94 
95 /*
96  * Input structure for SIGNAL_EVENT hypercall
97  */
98 struct hyperv_signal_event_input {
99     uint32_t connection_id;
100     uint16_t flag_number;
101     uint16_t _reserved_zero;
102 };
103 
104 /*
105  * SynIC message structures
106  */
107 struct hyperv_message_header {
108     uint32_t message_type;
109     uint8_t  payload_size;
110     uint8_t  message_flags; /* HV_MESSAGE_FLAG_XX */
111     uint8_t  _reserved[2];
112     uint64_t sender;
113 };
114 
115 struct hyperv_message {
116     struct hyperv_message_header header;
117     uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE];
118 };
119 
120 struct hyperv_message_page {
121     struct hyperv_message slot[HV_SINT_COUNT];
122 };
123 
124 /*
125  * SynIC event flags structures
126  */
127 struct hyperv_event_flags {
128     DECLARE_BITMAP(flags, HV_EVENT_FLAGS_COUNT);
129 };
130 
131 struct hyperv_event_flags_page {
132     struct hyperv_event_flags slot[HV_SINT_COUNT];
133 };
134 
135 /*
136  * Kernel debugger structures
137  */
138 
139 /* Options flags for hyperv_reset_debug_session */
140 #define HV_DEBUG_PURGE_INCOMING_DATA        0x00000001
141 #define HV_DEBUG_PURGE_OUTGOING_DATA        0x00000002
142 struct hyperv_reset_debug_session_input {
143     uint32_t options;
144 } __attribute__ ((__packed__));
145 
146 struct hyperv_reset_debug_session_output {
147     uint32_t host_ip;
148     uint32_t target_ip;
149     uint16_t host_port;
150     uint16_t target_port;
151     uint8_t host_mac[6];
152     uint8_t target_mac[6];
153 } __attribute__ ((__packed__));
154 
155 /* Options for hyperv_post_debug_data */
156 #define HV_DEBUG_POST_LOOP                  0x00000001
157 
158 struct hyperv_post_debug_data_input {
159     uint32_t count;
160     uint32_t options;
161     /*uint8_t data[HV_HYP_PAGE_SIZE - 2 * sizeof(uint32_t)];*/
162 } __attribute__ ((__packed__));
163 
164 struct hyperv_post_debug_data_output {
165     uint32_t pending_count;
166 } __attribute__ ((__packed__));
167 
168 /* Options for hyperv_retrieve_debug_data */
169 #define HV_DEBUG_RETRIEVE_LOOP              0x00000001
170 #define HV_DEBUG_RETRIEVE_TEST_ACTIVITY     0x00000002
171 
172 struct hyperv_retrieve_debug_data_input {
173     uint32_t count;
174     uint32_t options;
175     uint64_t timeout;
176 } __attribute__ ((__packed__));
177 
178 struct hyperv_retrieve_debug_data_output {
179     uint32_t retrieved_count;
180     uint32_t remaining_count;
181 } __attribute__ ((__packed__));
182 #endif
183