xref: /qemu/include/hw/hyperv/hyperv-proto.h (revision 5116122af70357d895ecc61c0211dbf786226081)
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_CONNECTION_ID       18
25 #define HV_STATUS_INSUFFICIENT_BUFFERS        19
26 
27 /*
28  * Hypercall numbers
29  */
30 #define HV_POST_MESSAGE                       0x005c
31 #define HV_SIGNAL_EVENT                       0x005d
32 #define HV_HYPERCALL_FAST                     (1u << 16)
33 
34 /*
35  * Message size
36  */
37 #define HV_MESSAGE_PAYLOAD_SIZE               240
38 
39 /*
40  * Message types
41  */
42 #define HV_MESSAGE_NONE                       0x00000000
43 #define HV_MESSAGE_VMBUS                      0x00000001
44 #define HV_MESSAGE_UNMAPPED_GPA               0x80000000
45 #define HV_MESSAGE_GPA_INTERCEPT              0x80000001
46 #define HV_MESSAGE_TIMER_EXPIRED              0x80000010
47 #define HV_MESSAGE_INVALID_VP_REGISTER_VALUE  0x80000020
48 #define HV_MESSAGE_UNRECOVERABLE_EXCEPTION    0x80000021
49 #define HV_MESSAGE_UNSUPPORTED_FEATURE        0x80000022
50 #define HV_MESSAGE_EVENTLOG_BUFFERCOMPLETE    0x80000040
51 #define HV_MESSAGE_X64_IOPORT_INTERCEPT       0x80010000
52 #define HV_MESSAGE_X64_MSR_INTERCEPT          0x80010001
53 #define HV_MESSAGE_X64_CPUID_INTERCEPT        0x80010002
54 #define HV_MESSAGE_X64_EXCEPTION_INTERCEPT    0x80010003
55 #define HV_MESSAGE_X64_APIC_EOI               0x80010004
56 #define HV_MESSAGE_X64_LEGACY_FP_ERROR        0x80010005
57 
58 /*
59  * Message flags
60  */
61 #define HV_MESSAGE_FLAG_PENDING               0x1
62 
63 /*
64  * Number of synthetic interrupts
65  */
66 #define HV_SINT_COUNT                         16
67 
68 /*
69  * Event flags number per SINT
70  */
71 #define HV_EVENT_FLAGS_COUNT                  (256 * 8)
72 
73 /*
74  * Connection id valid bits
75  */
76 #define HV_CONNECTION_ID_MASK                 0x00ffffff
77 
78 /*
79  * Input structure for POST_MESSAGE hypercall
80  */
81 struct hyperv_post_message_input {
82     uint32_t connection_id;
83     uint32_t _reserved;
84     uint32_t message_type;
85     uint32_t payload_size;
86     uint8_t  payload[HV_MESSAGE_PAYLOAD_SIZE];
87 };
88 
89 /*
90  * Input structure for SIGNAL_EVENT hypercall
91  */
92 struct hyperv_signal_event_input {
93     uint32_t connection_id;
94     uint16_t flag_number;
95     uint16_t _reserved_zero;
96 };
97 
98 /*
99  * SynIC message structures
100  */
101 struct hyperv_message_header {
102     uint32_t message_type;
103     uint8_t  payload_size;
104     uint8_t  message_flags; /* HV_MESSAGE_FLAG_XX */
105     uint8_t  _reserved[2];
106     uint64_t sender;
107 };
108 
109 struct hyperv_message {
110     struct hyperv_message_header header;
111     uint8_t payload[HV_MESSAGE_PAYLOAD_SIZE];
112 };
113 
114 struct hyperv_message_page {
115     struct hyperv_message slot[HV_SINT_COUNT];
116 };
117 
118 /*
119  * SynIC event flags structures
120  */
121 struct hyperv_event_flags {
122     DECLARE_BITMAP(flags, HV_EVENT_FLAGS_COUNT);
123 };
124 
125 struct hyperv_event_flags_page {
126     struct hyperv_event_flags slot[HV_SINT_COUNT];
127 };
128 
129 #endif
130