Commit | Line | Data |
---|---|---|
3e7ee490 HJ |
1 | /* |
2 | * | |
3 | * Copyright (c) 2009, Microsoft Corporation. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify it | |
6 | * under the terms and conditions of the GNU General Public License, | |
7 | * version 2, as published by the Free Software Foundation. | |
8 | * | |
9 | * This program is distributed in the hope it will be useful, but WITHOUT | |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | * more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along with | |
15 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple | |
16 | * Place - Suite 330, Boston, MA 02111-1307 USA. | |
17 | * | |
18 | * Authors: | |
19 | * Haiyang Zhang <haiyangz@microsoft.com> | |
20 | * Hank Janssen <hjanssen@microsoft.com> | |
21 | * | |
22 | */ | |
23 | ||
24 | ||
25 | #ifndef __HV_H__ | |
26 | #define __HV_H__ | |
27 | ||
09d50ff8 | 28 | #include "include/osd.h" |
3e7ee490 | 29 | |
09d50ff8 GKH |
30 | #include "include/HvTypes.h" |
31 | #include "include/HvStatus.h" | |
454f18a9 BP |
32 | /* #include "HvVmApi.h" */ |
33 | /* #include "HvKeApi.h" */ | |
34 | /* #include "HvMmApi.h" */ | |
35 | /* #include "HvCpuApi.h" */ | |
09d50ff8 GKH |
36 | #include "include/HvHalApi.h" |
37 | #include "include/HvVpApi.h" | |
454f18a9 | 38 | /* #include "HvTrApi.h" */ |
09d50ff8 | 39 | #include "include/HvSynicApi.h" |
454f18a9 BP |
40 | /* #include "HvAmApi.h" */ |
41 | /* #include "HvHkApi.h" */ | |
42 | /* #include "HvValApi.h" */ | |
09d50ff8 GKH |
43 | #include "include/HvHcApi.h" |
44 | #include "include/HvPtApi.h" | |
3e7ee490 HJ |
45 | |
46 | enum | |
47 | { | |
48 | VMBUS_MESSAGE_CONNECTION_ID = 1, | |
49 | VMBUS_MESSAGE_PORT_ID = 1, | |
50 | VMBUS_EVENT_CONNECTION_ID = 2, | |
51 | VMBUS_EVENT_PORT_ID = 2, | |
52 | VMBUS_MONITOR_CONNECTION_ID = 3, | |
53 | VMBUS_MONITOR_PORT_ID = 3, | |
54 | VMBUS_MESSAGE_SINT = 2 | |
55 | }; | |
454f18a9 BP |
56 | |
57 | /* #defines */ | |
58 | ||
3e7ee490 HJ |
59 | #define HV_PRESENT_BIT 0x80000000 |
60 | ||
61 | #define HV_XENLINUX_GUEST_ID_LO 0x00000000 | |
62 | #define HV_XENLINUX_GUEST_ID_HI 0x0B00B135 | |
59471438 | 63 | #define HV_XENLINUX_GUEST_ID (((u64)HV_XENLINUX_GUEST_ID_HI << 32) | HV_XENLINUX_GUEST_ID_LO) |
3e7ee490 HJ |
64 | |
65 | #define HV_LINUX_GUEST_ID_LO 0x00000000 | |
66 | #define HV_LINUX_GUEST_ID_HI 0xB16B00B5 | |
59471438 | 67 | #define HV_LINUX_GUEST_ID (((u64)HV_LINUX_GUEST_ID_HI << 32) | HV_LINUX_GUEST_ID_LO) |
3e7ee490 HJ |
68 | |
69 | #define HV_CPU_POWER_MANAGEMENT (1 << 0) | |
70 | #define HV_RECOMMENDATIONS_MAX 4 | |
71 | ||
72 | #define HV_X64_MAX 5 | |
73 | #define HV_CAPS_MAX 8 | |
74 | ||
75 | ||
59471438 | 76 | #define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) |
3e7ee490 | 77 | |
454f18a9 BP |
78 | |
79 | /* Service definitions */ | |
80 | ||
3e7ee490 HJ |
81 | #define HV_SERVICE_PARENT_PORT (0) |
82 | #define HV_SERVICE_PARENT_CONNECTION (0) | |
83 | ||
84 | #define HV_SERVICE_CONNECT_RESPONSE_SUCCESS (0) | |
85 | #define HV_SERVICE_CONNECT_RESPONSE_INVALID_PARAMETER (1) | |
86 | #define HV_SERVICE_CONNECT_RESPONSE_UNKNOWN_SERVICE (2) | |
87 | #define HV_SERVICE_CONNECT_RESPONSE_CONNECTION_REJECTED (3) | |
88 | ||
89 | #define HV_SERVICE_CONNECT_REQUEST_MESSAGE_ID (1) | |
90 | #define HV_SERVICE_CONNECT_RESPONSE_MESSAGE_ID (2) | |
91 | #define HV_SERVICE_DISCONNECT_REQUEST_MESSAGE_ID (3) | |
92 | #define HV_SERVICE_DISCONNECT_RESPONSE_MESSAGE_ID (4) | |
93 | #define HV_SERVICE_MAX_MESSAGE_ID (4) | |
94 | ||
95 | #define HV_SERVICE_PROTOCOL_VERSION (0x0010) | |
96 | #define HV_CONNECT_PAYLOAD_BYTE_COUNT 64 | |
97 | ||
454f18a9 BP |
98 | /* #define VMBUS_REVISION_NUMBER 6 */ |
99 | /* #define VMBUS_PORT_ID 11 // Our local vmbus's port and connection id. Anything >0 is fine */ | |
3e7ee490 | 100 | |
454f18a9 | 101 | /* 628180B8-308D-4c5e-B7DB-1BEB62E62EF4 */ |
3e7ee490 HJ |
102 | static const GUID VMBUS_SERVICE_ID = {.Data = {0xb8, 0x80, 0x81, 0x62, 0x8d, 0x30, 0x5e, 0x4c, 0xb7, 0xdb, 0x1b, 0xeb, 0x62, 0xe6, 0x2e, 0xf4} }; |
103 | ||
104 | #define MAX_NUM_CPUS 1 | |
105 | ||
106 | ||
107 | typedef struct { | |
59471438 | 108 | u64 Align8; |
3e7ee490 HJ |
109 | HV_INPUT_SIGNAL_EVENT Event; |
110 | } HV_INPUT_SIGNAL_EVENT_BUFFER; | |
111 | ||
112 | typedef struct { | |
454f18a9 | 113 | u64 GuestId; /* XenLinux or native Linux. If XenLinux, the hypercall and synic pages has already been initialized */ |
3e7ee490 HJ |
114 | void* HypercallPage; |
115 | ||
27274e5d | 116 | bool SynICInitialized; |
454f18a9 BP |
117 | /* This is used as an input param to HvCallSignalEvent hypercall. The input param is immutable */ |
118 | /* in our usage and must be dynamic mem (vs stack or global). */ | |
3e7ee490 | 119 | HV_INPUT_SIGNAL_EVENT_BUFFER *SignalEventBuffer; |
454f18a9 | 120 | HV_INPUT_SIGNAL_EVENT *SignalEventParam; /* 8-bytes aligned of the buffer above */ |
3e7ee490 HJ |
121 | |
122 | HANDLE synICMessagePage[MAX_NUM_CPUS]; | |
123 | HANDLE synICEventPage[MAX_NUM_CPUS]; | |
124 | } HV_CONTEXT; | |
125 | ||
126 | extern HV_CONTEXT gHvContext; | |
127 | ||
128 | ||
454f18a9 BP |
129 | |
130 | /* Inline routines */ | |
131 | ||
3e7ee490 HJ |
132 | static inline unsigned long long ReadMsr(int msr) |
133 | { | |
134 | unsigned long long val; | |
135 | ||
136 | RDMSR(msr, val); | |
137 | ||
138 | return val; | |
139 | } | |
140 | ||
59471438 | 141 | static inline void WriteMsr(int msr, u64 val) |
3e7ee490 HJ |
142 | { |
143 | WRMSR(msr, val); | |
144 | ||
145 | return; | |
146 | } | |
147 | ||
454f18a9 BP |
148 | |
149 | /* Hv Interface */ | |
150 | ||
2be1301b | 151 | static int |
3e7ee490 | 152 | HvInit( |
e20f683b | 153 | void |
3e7ee490 HJ |
154 | ); |
155 | ||
e20f683b | 156 | static void |
3e7ee490 | 157 | HvCleanup( |
e20f683b | 158 | void |
3e7ee490 HJ |
159 | ); |
160 | ||
2be1301b | 161 | static HV_STATUS |
3e7ee490 HJ |
162 | HvPostMessage( |
163 | HV_CONNECTION_ID connectionId, | |
164 | HV_MESSAGE_TYPE messageType, | |
8282c400 | 165 | void * payload, |
45635d97 | 166 | size_t payloadSize |
3e7ee490 HJ |
167 | ); |
168 | ||
2be1301b | 169 | static HV_STATUS |
3e7ee490 | 170 | HvSignalEvent( |
e20f683b | 171 | void |
3e7ee490 HJ |
172 | ); |
173 | ||
2be1301b | 174 | static int |
3e7ee490 | 175 | HvSynicInit( |
4d643114 | 176 | u32 irqVector |
3e7ee490 HJ |
177 | ); |
178 | ||
e20f683b | 179 | static void |
3e7ee490 | 180 | HvSynicCleanup( |
e20f683b | 181 | void |
3e7ee490 HJ |
182 | ); |
183 | ||
454f18a9 | 184 | #endif /* __HV_H__ */ |