Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | 6658be6 | 2009-08-20 12:13:27 -0700 | [diff] [blame] | 28 | #include "hv_api.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 29 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 30 | enum { |
| 31 | VMBUS_MESSAGE_CONNECTION_ID = 1, |
| 32 | VMBUS_MESSAGE_PORT_ID = 1, |
| 33 | VMBUS_EVENT_CONNECTION_ID = 2, |
| 34 | VMBUS_EVENT_PORT_ID = 2, |
| 35 | VMBUS_MONITOR_CONNECTION_ID = 3, |
| 36 | VMBUS_MONITOR_PORT_ID = 3, |
| 37 | VMBUS_MESSAGE_SINT = 2, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 38 | }; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 39 | |
| 40 | /* #defines */ |
| 41 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 42 | #define HV_PRESENT_BIT 0x80000000 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 43 | |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 44 | #define HV_LINUX_GUEST_ID_LO 0x00000000 |
| 45 | #define HV_LINUX_GUEST_ID_HI 0xB16B00B5 |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 46 | #define HV_LINUX_GUEST_ID (((u64)HV_LINUX_GUEST_ID_HI << 32) | \ |
| 47 | HV_LINUX_GUEST_ID_LO) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 48 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 49 | #define HV_CPU_POWER_MANAGEMENT (1 << 0) |
| 50 | #define HV_RECOMMENDATIONS_MAX 4 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 51 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 52 | #define HV_X64_MAX 5 |
| 53 | #define HV_CAPS_MAX 8 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 54 | |
| 55 | |
Greg Kroah-Hartman | 5947143 | 2009-07-14 15:10:26 -0700 | [diff] [blame] | 56 | #define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 57 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 58 | |
| 59 | /* Service definitions */ |
| 60 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 61 | #define HV_SERVICE_PARENT_PORT (0) |
| 62 | #define HV_SERVICE_PARENT_CONNECTION (0) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 63 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 64 | #define HV_SERVICE_CONNECT_RESPONSE_SUCCESS (0) |
| 65 | #define HV_SERVICE_CONNECT_RESPONSE_INVALID_PARAMETER (1) |
| 66 | #define HV_SERVICE_CONNECT_RESPONSE_UNKNOWN_SERVICE (2) |
| 67 | #define HV_SERVICE_CONNECT_RESPONSE_CONNECTION_REJECTED (3) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 68 | |
| 69 | #define HV_SERVICE_CONNECT_REQUEST_MESSAGE_ID (1) |
| 70 | #define HV_SERVICE_CONNECT_RESPONSE_MESSAGE_ID (2) |
| 71 | #define HV_SERVICE_DISCONNECT_REQUEST_MESSAGE_ID (3) |
| 72 | #define HV_SERVICE_DISCONNECT_RESPONSE_MESSAGE_ID (4) |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 73 | #define HV_SERVICE_MAX_MESSAGE_ID (4) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 74 | |
| 75 | #define HV_SERVICE_PROTOCOL_VERSION (0x0010) |
| 76 | #define HV_CONNECT_PAYLOAD_BYTE_COUNT 64 |
| 77 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 78 | /* #define VMBUS_REVISION_NUMBER 6 */ |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 79 | |
| 80 | /* Our local vmbus's port and connection id. Anything >0 is fine */ |
| 81 | /* #define VMBUS_PORT_ID 11 */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 82 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 83 | /* 628180B8-308D-4c5e-B7DB-1BEB62E62EF4 */ |
Greg Kroah-Hartman | caf26a3 | 2009-08-19 16:17:03 -0700 | [diff] [blame] | 84 | static const struct hv_guid VMBUS_SERVICE_ID = { |
| 85 | .data = { |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 86 | 0xb8, 0x80, 0x81, 0x62, 0x8d, 0x30, 0x5e, 0x4c, |
| 87 | 0xb7, 0xdb, 0x1b, 0xeb, 0x62, 0xe6, 0x2e, 0xf4 |
| 88 | }, |
| 89 | }; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 90 | |
Greg Kroah-Hartman | 7692fd4 | 2010-01-08 09:06:40 -0800 | [diff] [blame] | 91 | #define MAX_NUM_CPUS 32 |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 92 | |
| 93 | |
Greg Kroah-Hartman | af248e1 | 2009-08-18 15:20:34 -0700 | [diff] [blame] | 94 | struct hv_input_signal_event_buffer { |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 95 | u64 Align8; |
Greg Kroah-Hartman | cba4dec | 2009-08-19 16:21:28 -0700 | [diff] [blame] | 96 | struct hv_input_signal_event Event; |
Greg Kroah-Hartman | af248e1 | 2009-08-18 15:20:34 -0700 | [diff] [blame] | 97 | }; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 98 | |
Greg Kroah-Hartman | af248e1 | 2009-08-18 15:20:34 -0700 | [diff] [blame] | 99 | struct hv_context { |
Hank Janssen | a73e6b7 | 2010-01-22 19:17:50 +0000 | [diff] [blame] | 100 | /* We only support running on top of Hyper-V |
| 101 | * So at this point this really can only contain the Hyper-V ID |
| 102 | */ |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 103 | u64 GuestId; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 104 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 105 | void *HypercallPage; |
| 106 | |
| 107 | bool SynICInitialized; |
| 108 | |
| 109 | /* |
| 110 | * This is used as an input param to HvCallSignalEvent hypercall. The |
| 111 | * input param is immutable in our usage and must be dynamic mem (vs |
| 112 | * stack or global). */ |
Greg Kroah-Hartman | af248e1 | 2009-08-18 15:20:34 -0700 | [diff] [blame] | 113 | struct hv_input_signal_event_buffer *SignalEventBuffer; |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 114 | /* 8-bytes aligned of the buffer above */ |
Greg Kroah-Hartman | cba4dec | 2009-08-19 16:21:28 -0700 | [diff] [blame] | 115 | struct hv_input_signal_event *SignalEventParam; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 116 | |
Bill Pemberton | 44f357f | 2009-07-28 13:46:26 -0400 | [diff] [blame] | 117 | void *synICMessagePage[MAX_NUM_CPUS]; |
| 118 | void *synICEventPage[MAX_NUM_CPUS]; |
Greg Kroah-Hartman | af248e1 | 2009-08-18 15:20:34 -0700 | [diff] [blame] | 119 | }; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 120 | |
Greg Kroah-Hartman | af248e1 | 2009-08-18 15:20:34 -0700 | [diff] [blame] | 121 | extern struct hv_context gHvContext; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 122 | |
| 123 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 124 | /* Hv Interface */ |
| 125 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 126 | extern int HvInit(void); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 127 | |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 128 | extern void HvCleanup(void); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 129 | |
Greg Kroah-Hartman | 034469e | 2009-08-20 12:14:11 -0700 | [diff] [blame] | 130 | extern u16 HvPostMessage(union hv_connection_id connectionId, |
| 131 | enum hv_message_type messageType, |
| 132 | void *payload, size_t payloadSize); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 133 | |
Greg Kroah-Hartman | 034469e | 2009-08-20 12:14:11 -0700 | [diff] [blame] | 134 | extern u16 HvSignalEvent(void); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 135 | |
Greg Kroah-Hartman | 7692fd4 | 2010-01-08 09:06:40 -0800 | [diff] [blame] | 136 | extern void HvSynicInit(void *irqarg); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 137 | |
Greg Kroah-Hartman | 7692fd4 | 2010-01-08 09:06:40 -0800 | [diff] [blame] | 138 | extern void HvSynicCleanup(void *arg); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 139 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 140 | #endif /* __HV_H__ */ |