K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2011, 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 | * K. Y. Srinivasan <kys@microsoft.com> |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #ifndef _HYPERV_VMBUS_H |
| 26 | #define _HYPERV_VMBUS_H |
| 27 | |
K. Y. Srinivasan | 43c698b | 2011-05-12 19:34:33 -0700 | [diff] [blame] | 28 | #include <linux/list.h> |
| 29 | #include <asm/sync_bitops.h> |
| 30 | #include <linux/atomic.h> |
Greg Kroah-Hartman | 46a9719 | 2011-10-04 12:29:52 -0700 | [diff] [blame] | 31 | #include <linux/hyperv.h> |
K. Y. Srinivasan | 43c698b | 2011-05-12 19:34:33 -0700 | [diff] [blame] | 32 | |
K. Y. Srinivasan | afbdc4a | 2011-05-12 19:34:29 -0700 | [diff] [blame] | 33 | /* |
| 34 | * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent |
| 35 | * is set by CPUID(HVCPUID_VERSION_FEATURES). |
| 36 | */ |
| 37 | enum hv_cpuid_function { |
| 38 | HVCPUID_VERSION_FEATURES = 0x00000001, |
| 39 | HVCPUID_VENDOR_MAXFUNCTION = 0x40000000, |
| 40 | HVCPUID_INTERFACE = 0x40000001, |
| 41 | |
| 42 | /* |
| 43 | * The remaining functions depend on the value of |
| 44 | * HVCPUID_INTERFACE |
| 45 | */ |
| 46 | HVCPUID_VERSION = 0x40000002, |
| 47 | HVCPUID_FEATURES = 0x40000003, |
| 48 | HVCPUID_ENLIGHTENMENT_INFO = 0x40000004, |
| 49 | HVCPUID_IMPLEMENTATION_LIMITS = 0x40000005, |
| 50 | }; |
| 51 | |
| 52 | /* Define version of the synthetic interrupt controller. */ |
| 53 | #define HV_SYNIC_VERSION (1) |
| 54 | |
| 55 | /* Define the expected SynIC version. */ |
| 56 | #define HV_SYNIC_VERSION_1 (0x1) |
| 57 | |
| 58 | /* Define synthetic interrupt controller message constants. */ |
| 59 | #define HV_MESSAGE_SIZE (256) |
| 60 | #define HV_MESSAGE_PAYLOAD_BYTE_COUNT (240) |
| 61 | #define HV_MESSAGE_PAYLOAD_QWORD_COUNT (30) |
| 62 | #define HV_ANY_VP (0xFFFFFFFF) |
| 63 | |
| 64 | /* Define synthetic interrupt controller flag constants. */ |
| 65 | #define HV_EVENT_FLAGS_COUNT (256 * 8) |
| 66 | #define HV_EVENT_FLAGS_BYTE_COUNT (256) |
| 67 | #define HV_EVENT_FLAGS_DWORD_COUNT (256 / sizeof(u32)) |
| 68 | |
| 69 | /* Define hypervisor message types. */ |
| 70 | enum hv_message_type { |
| 71 | HVMSG_NONE = 0x00000000, |
| 72 | |
| 73 | /* Memory access messages. */ |
| 74 | HVMSG_UNMAPPED_GPA = 0x80000000, |
| 75 | HVMSG_GPA_INTERCEPT = 0x80000001, |
| 76 | |
| 77 | /* Timer notification messages. */ |
| 78 | HVMSG_TIMER_EXPIRED = 0x80000010, |
| 79 | |
| 80 | /* Error messages. */ |
| 81 | HVMSG_INVALID_VP_REGISTER_VALUE = 0x80000020, |
| 82 | HVMSG_UNRECOVERABLE_EXCEPTION = 0x80000021, |
| 83 | HVMSG_UNSUPPORTED_FEATURE = 0x80000022, |
| 84 | |
| 85 | /* Trace buffer complete messages. */ |
| 86 | HVMSG_EVENTLOG_BUFFERCOMPLETE = 0x80000040, |
| 87 | |
| 88 | /* Platform-specific processor intercept messages. */ |
| 89 | HVMSG_X64_IOPORT_INTERCEPT = 0x80010000, |
| 90 | HVMSG_X64_MSR_INTERCEPT = 0x80010001, |
| 91 | HVMSG_X64_CPUID_INTERCEPT = 0x80010002, |
| 92 | HVMSG_X64_EXCEPTION_INTERCEPT = 0x80010003, |
| 93 | HVMSG_X64_APIC_EOI = 0x80010004, |
| 94 | HVMSG_X64_LEGACY_FP_ERROR = 0x80010005 |
| 95 | }; |
| 96 | |
| 97 | /* Define the number of synthetic interrupt sources. */ |
| 98 | #define HV_SYNIC_SINT_COUNT (16) |
| 99 | #define HV_SYNIC_STIMER_COUNT (4) |
| 100 | |
| 101 | /* Define invalid partition identifier. */ |
| 102 | #define HV_PARTITION_ID_INVALID ((u64)0x0) |
| 103 | |
K. Y. Srinivasan | afbdc4a | 2011-05-12 19:34:29 -0700 | [diff] [blame] | 104 | /* Define port identifier type. */ |
| 105 | union hv_port_id { |
| 106 | u32 asu32; |
| 107 | struct { |
| 108 | u32 id:24; |
| 109 | u32 reserved:8; |
| 110 | } u ; |
| 111 | }; |
| 112 | |
| 113 | /* Define port type. */ |
| 114 | enum hv_port_type { |
| 115 | HVPORT_MSG = 1, |
| 116 | HVPORT_EVENT = 2, |
| 117 | HVPORT_MONITOR = 3 |
| 118 | }; |
| 119 | |
| 120 | /* Define port information structure. */ |
| 121 | struct hv_port_info { |
| 122 | enum hv_port_type port_type; |
| 123 | u32 padding; |
| 124 | union { |
| 125 | struct { |
| 126 | u32 target_sint; |
| 127 | u32 target_vp; |
| 128 | u64 rsvdz; |
| 129 | } message_port_info; |
| 130 | struct { |
| 131 | u32 target_sint; |
| 132 | u32 target_vp; |
| 133 | u16 base_flag_bumber; |
| 134 | u16 flag_count; |
| 135 | u32 rsvdz; |
| 136 | } event_port_info; |
| 137 | struct { |
| 138 | u64 monitor_address; |
| 139 | u64 rsvdz; |
| 140 | } monitor_port_info; |
| 141 | }; |
| 142 | }; |
| 143 | |
| 144 | struct hv_connection_info { |
| 145 | enum hv_port_type port_type; |
| 146 | u32 padding; |
| 147 | union { |
| 148 | struct { |
| 149 | u64 rsvdz; |
| 150 | } message_connection_info; |
| 151 | struct { |
| 152 | u64 rsvdz; |
| 153 | } event_connection_info; |
| 154 | struct { |
| 155 | u64 monitor_address; |
| 156 | } monitor_connection_info; |
| 157 | }; |
| 158 | }; |
| 159 | |
| 160 | /* Define synthetic interrupt controller message flags. */ |
| 161 | union hv_message_flags { |
| 162 | u8 asu8; |
| 163 | struct { |
| 164 | u8 msg_pending:1; |
| 165 | u8 reserved:7; |
| 166 | }; |
| 167 | }; |
| 168 | |
| 169 | /* Define synthetic interrupt controller message header. */ |
| 170 | struct hv_message_header { |
| 171 | enum hv_message_type message_type; |
| 172 | u8 payload_size; |
| 173 | union hv_message_flags message_flags; |
| 174 | u8 reserved[2]; |
| 175 | union { |
| 176 | u64 sender; |
| 177 | union hv_port_id port; |
| 178 | }; |
| 179 | }; |
| 180 | |
| 181 | /* Define timer message payload structure. */ |
| 182 | struct hv_timer_message_payload { |
| 183 | u32 timer_index; |
| 184 | u32 reserved; |
| 185 | u64 expiration_time; /* When the timer expired */ |
| 186 | u64 delivery_time; /* When the message was delivered */ |
| 187 | }; |
| 188 | |
| 189 | /* Define synthetic interrupt controller message format. */ |
| 190 | struct hv_message { |
| 191 | struct hv_message_header header; |
| 192 | union { |
| 193 | u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; |
| 194 | } u ; |
| 195 | }; |
| 196 | |
| 197 | /* Define the number of message buffers associated with each port. */ |
| 198 | #define HV_PORT_MESSAGE_BUFFER_COUNT (16) |
| 199 | |
| 200 | /* Define the synthetic interrupt message page layout. */ |
| 201 | struct hv_message_page { |
| 202 | struct hv_message sint_message[HV_SYNIC_SINT_COUNT]; |
| 203 | }; |
| 204 | |
| 205 | /* Define the synthetic interrupt controller event flags format. */ |
| 206 | union hv_synic_event_flags { |
| 207 | u8 flags8[HV_EVENT_FLAGS_BYTE_COUNT]; |
| 208 | u32 flags32[HV_EVENT_FLAGS_DWORD_COUNT]; |
| 209 | }; |
| 210 | |
| 211 | /* Define the synthetic interrupt flags page layout. */ |
| 212 | struct hv_synic_event_flags_page { |
| 213 | union hv_synic_event_flags sintevent_flags[HV_SYNIC_SINT_COUNT]; |
| 214 | }; |
| 215 | |
| 216 | /* Define SynIC control register. */ |
| 217 | union hv_synic_scontrol { |
| 218 | u64 as_uint64; |
| 219 | struct { |
| 220 | u64 enable:1; |
| 221 | u64 reserved:63; |
| 222 | }; |
| 223 | }; |
| 224 | |
| 225 | /* Define synthetic interrupt source. */ |
| 226 | union hv_synic_sint { |
| 227 | u64 as_uint64; |
| 228 | struct { |
| 229 | u64 vector:8; |
| 230 | u64 reserved1:8; |
| 231 | u64 masked:1; |
| 232 | u64 auto_eoi:1; |
| 233 | u64 reserved2:46; |
| 234 | }; |
| 235 | }; |
| 236 | |
| 237 | /* Define the format of the SIMP register */ |
| 238 | union hv_synic_simp { |
| 239 | u64 as_uint64; |
| 240 | struct { |
| 241 | u64 simp_enabled:1; |
| 242 | u64 preserved:11; |
| 243 | u64 base_simp_gpa:52; |
| 244 | }; |
| 245 | }; |
| 246 | |
| 247 | /* Define the format of the SIEFP register */ |
| 248 | union hv_synic_siefp { |
| 249 | u64 as_uint64; |
| 250 | struct { |
| 251 | u64 siefp_enabled:1; |
| 252 | u64 preserved:11; |
| 253 | u64 base_siefp_gpa:52; |
| 254 | }; |
| 255 | }; |
| 256 | |
| 257 | /* Definitions for the monitored notification facility */ |
| 258 | union hv_monitor_trigger_group { |
| 259 | u64 as_uint64; |
| 260 | struct { |
| 261 | u32 pending; |
| 262 | u32 armed; |
| 263 | }; |
| 264 | }; |
| 265 | |
| 266 | struct hv_monitor_parameter { |
| 267 | union hv_connection_id connectionid; |
| 268 | u16 flagnumber; |
| 269 | u16 rsvdz; |
| 270 | }; |
| 271 | |
| 272 | union hv_monitor_trigger_state { |
| 273 | u32 asu32; |
| 274 | |
| 275 | struct { |
| 276 | u32 group_enable:4; |
| 277 | u32 rsvdz:28; |
| 278 | }; |
| 279 | }; |
| 280 | |
| 281 | /* struct hv_monitor_page Layout */ |
| 282 | /* ------------------------------------------------------ */ |
| 283 | /* | 0 | TriggerState (4 bytes) | Rsvd1 (4 bytes) | */ |
| 284 | /* | 8 | TriggerGroup[0] | */ |
| 285 | /* | 10 | TriggerGroup[1] | */ |
| 286 | /* | 18 | TriggerGroup[2] | */ |
| 287 | /* | 20 | TriggerGroup[3] | */ |
| 288 | /* | 28 | Rsvd2[0] | */ |
| 289 | /* | 30 | Rsvd2[1] | */ |
| 290 | /* | 38 | Rsvd2[2] | */ |
| 291 | /* | 40 | NextCheckTime[0][0] | NextCheckTime[0][1] | */ |
| 292 | /* | ... | */ |
| 293 | /* | 240 | Latency[0][0..3] | */ |
| 294 | /* | 340 | Rsvz3[0] | */ |
| 295 | /* | 440 | Parameter[0][0] | */ |
| 296 | /* | 448 | Parameter[0][1] | */ |
| 297 | /* | ... | */ |
| 298 | /* | 840 | Rsvd4[0] | */ |
| 299 | /* ------------------------------------------------------ */ |
| 300 | struct hv_monitor_page { |
| 301 | union hv_monitor_trigger_state trigger_state; |
| 302 | u32 rsvdz1; |
| 303 | |
| 304 | union hv_monitor_trigger_group trigger_group[4]; |
| 305 | u64 rsvdz2[3]; |
| 306 | |
| 307 | s32 next_checktime[4][32]; |
| 308 | |
| 309 | u16 latency[4][32]; |
| 310 | u64 rsvdz3[32]; |
| 311 | |
| 312 | struct hv_monitor_parameter parameter[4][32]; |
| 313 | |
| 314 | u8 rsvdz4[1984]; |
| 315 | }; |
| 316 | |
| 317 | /* Declare the various hypercall operations. */ |
| 318 | enum hv_call_code { |
| 319 | HVCALL_POST_MESSAGE = 0x005c, |
| 320 | HVCALL_SIGNAL_EVENT = 0x005d, |
| 321 | }; |
| 322 | |
| 323 | /* Definition of the hv_post_message hypercall input structure. */ |
| 324 | struct hv_input_post_message { |
| 325 | union hv_connection_id connectionid; |
| 326 | u32 reserved; |
| 327 | enum hv_message_type message_type; |
| 328 | u32 payload_size; |
| 329 | u64 payload[HV_MESSAGE_PAYLOAD_QWORD_COUNT]; |
| 330 | }; |
| 331 | |
K. Y. Srinivasan | afbdc4a | 2011-05-12 19:34:29 -0700 | [diff] [blame] | 332 | /* |
| 333 | * Versioning definitions used for guests reporting themselves to the |
| 334 | * hypervisor, and visa versa. |
| 335 | */ |
| 336 | |
| 337 | /* Version info reported by guest OS's */ |
| 338 | enum hv_guest_os_vendor { |
| 339 | HVGUESTOS_VENDOR_MICROSOFT = 0x0001 |
| 340 | }; |
| 341 | |
| 342 | enum hv_guest_os_microsoft_ids { |
| 343 | HVGUESTOS_MICROSOFT_UNDEFINED = 0x00, |
| 344 | HVGUESTOS_MICROSOFT_MSDOS = 0x01, |
| 345 | HVGUESTOS_MICROSOFT_WINDOWS3X = 0x02, |
| 346 | HVGUESTOS_MICROSOFT_WINDOWS9X = 0x03, |
| 347 | HVGUESTOS_MICROSOFT_WINDOWSNT = 0x04, |
| 348 | HVGUESTOS_MICROSOFT_WINDOWSCE = 0x05 |
| 349 | }; |
| 350 | |
| 351 | /* |
| 352 | * Declare the MSR used to identify the guest OS. |
| 353 | */ |
| 354 | #define HV_X64_MSR_GUEST_OS_ID 0x40000000 |
| 355 | |
| 356 | union hv_x64_msr_guest_os_id_contents { |
| 357 | u64 as_uint64; |
| 358 | struct { |
| 359 | u64 build_number:16; |
| 360 | u64 service_version:8; /* Service Pack, etc. */ |
| 361 | u64 minor_version:8; |
| 362 | u64 major_version:8; |
| 363 | u64 os_id:8; /* enum hv_guest_os_microsoft_ids (if Vendor=MS) */ |
| 364 | u64 vendor_id:16; /* enum hv_guest_os_vendor */ |
| 365 | }; |
| 366 | }; |
| 367 | |
| 368 | /* |
| 369 | * Declare the MSR used to setup pages used to communicate with the hypervisor. |
| 370 | */ |
| 371 | #define HV_X64_MSR_HYPERCALL 0x40000001 |
| 372 | |
| 373 | union hv_x64_msr_hypercall_contents { |
| 374 | u64 as_uint64; |
| 375 | struct { |
| 376 | u64 enable:1; |
| 377 | u64 reserved:11; |
| 378 | u64 guest_physical_address:52; |
| 379 | }; |
| 380 | }; |
| 381 | |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 382 | |
| 383 | enum { |
| 384 | VMBUS_MESSAGE_CONNECTION_ID = 1, |
| 385 | VMBUS_MESSAGE_PORT_ID = 1, |
| 386 | VMBUS_EVENT_CONNECTION_ID = 2, |
| 387 | VMBUS_EVENT_PORT_ID = 2, |
| 388 | VMBUS_MONITOR_CONNECTION_ID = 3, |
| 389 | VMBUS_MONITOR_PORT_ID = 3, |
| 390 | VMBUS_MESSAGE_SINT = 2, |
| 391 | }; |
| 392 | |
| 393 | /* #defines */ |
| 394 | |
| 395 | #define HV_PRESENT_BIT 0x80000000 |
| 396 | |
K. Y. Srinivasan | 83ba0c4 | 2012-07-24 16:11:58 -0700 | [diff] [blame] | 397 | /* |
| 398 | * The guest OS needs to register the guest ID with the hypervisor. |
| 399 | * The guest ID is a 64 bit entity and the structure of this ID is |
| 400 | * specified in the Hyper-V specification: |
| 401 | * |
| 402 | * http://msdn.microsoft.com/en-us/library/windows/hardware/ff542653%28v=vs.85%29.aspx |
| 403 | * |
| 404 | * While the current guideline does not specify how Linux guest ID(s) |
| 405 | * need to be generated, our plan is to publish the guidelines for |
| 406 | * Linux and other guest operating systems that currently are hosted |
| 407 | * on Hyper-V. The implementation here conforms to this yet |
| 408 | * unpublished guidelines. |
| 409 | * |
| 410 | * |
| 411 | * Bit(s) |
| 412 | * 63 - Indicates if the OS is Open Source or not; 1 is Open Source |
| 413 | * 62:56 - Os Type; Linux is 0x100 |
| 414 | * 55:48 - Distro specific identification |
| 415 | * 47:16 - Linux kernel version number |
| 416 | * 15:0 - Distro specific identification |
| 417 | * |
| 418 | * |
| 419 | */ |
| 420 | |
| 421 | #define HV_LINUX_VENDOR_ID 0x8100 |
| 422 | |
| 423 | /* |
| 424 | * Generate the guest ID based on the guideline described above. |
| 425 | */ |
| 426 | |
| 427 | static inline __u64 generate_guest_id(__u8 d_info1, __u32 kernel_version, |
| 428 | __u16 d_info2) |
| 429 | { |
| 430 | __u64 guest_id = 0; |
| 431 | |
| 432 | guest_id = (((__u64)HV_LINUX_VENDOR_ID) << 48); |
| 433 | guest_id |= (((__u64)(d_info1)) << 48); |
| 434 | guest_id |= (((__u64)(kernel_version)) << 16); |
| 435 | guest_id |= ((__u64)(d_info2)); |
| 436 | |
| 437 | return guest_id; |
| 438 | } |
| 439 | |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 440 | |
| 441 | #define HV_CPU_POWER_MANAGEMENT (1 << 0) |
| 442 | #define HV_RECOMMENDATIONS_MAX 4 |
| 443 | |
| 444 | #define HV_X64_MAX 5 |
| 445 | #define HV_CAPS_MAX 8 |
| 446 | |
| 447 | |
| 448 | #define HV_HYPERCALL_PARAM_ALIGN sizeof(u64) |
| 449 | |
| 450 | |
| 451 | /* Service definitions */ |
| 452 | |
| 453 | #define HV_SERVICE_PARENT_PORT (0) |
| 454 | #define HV_SERVICE_PARENT_CONNECTION (0) |
| 455 | |
| 456 | #define HV_SERVICE_CONNECT_RESPONSE_SUCCESS (0) |
| 457 | #define HV_SERVICE_CONNECT_RESPONSE_INVALID_PARAMETER (1) |
| 458 | #define HV_SERVICE_CONNECT_RESPONSE_UNKNOWN_SERVICE (2) |
| 459 | #define HV_SERVICE_CONNECT_RESPONSE_CONNECTION_REJECTED (3) |
| 460 | |
| 461 | #define HV_SERVICE_CONNECT_REQUEST_MESSAGE_ID (1) |
| 462 | #define HV_SERVICE_CONNECT_RESPONSE_MESSAGE_ID (2) |
| 463 | #define HV_SERVICE_DISCONNECT_REQUEST_MESSAGE_ID (3) |
| 464 | #define HV_SERVICE_DISCONNECT_RESPONSE_MESSAGE_ID (4) |
| 465 | #define HV_SERVICE_MAX_MESSAGE_ID (4) |
| 466 | |
| 467 | #define HV_SERVICE_PROTOCOL_VERSION (0x0010) |
| 468 | #define HV_CONNECT_PAYLOAD_BYTE_COUNT 64 |
| 469 | |
| 470 | /* #define VMBUS_REVISION_NUMBER 6 */ |
| 471 | |
| 472 | /* Our local vmbus's port and connection id. Anything >0 is fine */ |
| 473 | /* #define VMBUS_PORT_ID 11 */ |
| 474 | |
| 475 | /* 628180B8-308D-4c5e-B7DB-1BEB62E62EF4 */ |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 476 | static const uuid_le VMBUS_SERVICE_ID = { |
| 477 | .b = { |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 478 | 0xb8, 0x80, 0x81, 0x62, 0x8d, 0x30, 0x5e, 0x4c, |
| 479 | 0xb7, 0xdb, 0x1b, 0xeb, 0x62, 0xe6, 0x2e, 0xf4 |
| 480 | }, |
| 481 | }; |
| 482 | |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 483 | |
| 484 | |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 485 | struct hv_context { |
| 486 | /* We only support running on top of Hyper-V |
| 487 | * So at this point this really can only contain the Hyper-V ID |
| 488 | */ |
| 489 | u64 guestid; |
| 490 | |
| 491 | void *hypercall_page; |
| 492 | |
| 493 | bool synic_initialized; |
| 494 | |
K. Y. Srinivasan | 14c1bf8 | 2012-02-02 16:56:51 -0800 | [diff] [blame] | 495 | void *synic_message_page[NR_CPUS]; |
| 496 | void *synic_event_page[NR_CPUS]; |
K. Y. Srinivasan | 917ea42 | 2012-12-01 06:46:47 -0800 | [diff] [blame] | 497 | /* |
| 498 | * Hypervisor's notion of virtual processor ID is different from |
| 499 | * Linux' notion of CPU ID. This information can only be retrieved |
| 500 | * in the context of the calling CPU. Setup a map for easy access |
| 501 | * to this information: |
| 502 | * |
| 503 | * vp_index[a] is the Hyper-V's processor ID corresponding to |
| 504 | * Linux cpuid 'a'. |
| 505 | */ |
| 506 | u32 vp_index[NR_CPUS]; |
K. Y. Srinivasan | db11f12 | 2012-12-01 06:46:53 -0800 | [diff] [blame] | 507 | /* |
| 508 | * Starting with win8, we can take channel interrupts on any CPU; |
| 509 | * we will manage the tasklet that handles events on a per CPU |
| 510 | * basis. |
| 511 | */ |
| 512 | struct tasklet_struct *event_dpc[NR_CPUS]; |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 513 | }; |
| 514 | |
| 515 | extern struct hv_context hv_context; |
| 516 | |
| 517 | |
| 518 | /* Hv Interface */ |
| 519 | |
| 520 | extern int hv_init(void); |
| 521 | |
| 522 | extern void hv_cleanup(void); |
| 523 | |
Dan Carpenter | 415f0a0 | 2012-03-28 09:58:07 +0300 | [diff] [blame] | 524 | extern int hv_post_message(union hv_connection_id connection_id, |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 525 | enum hv_message_type message_type, |
| 526 | void *payload, size_t payload_size); |
| 527 | |
K. Y. Srinivasan | 1f42248 | 2012-12-01 06:46:42 -0800 | [diff] [blame] | 528 | extern u16 hv_signal_event(void *con_id); |
K. Y. Srinivasan | 3645a91 | 2011-05-12 19:34:30 -0700 | [diff] [blame] | 529 | |
| 530 | extern void hv_synic_init(void *irqarg); |
| 531 | |
| 532 | extern void hv_synic_cleanup(void *arg); |
| 533 | |
K. Y. Srinivasan | 5fbebb2 | 2012-12-01 06:46:58 -0800 | [diff] [blame] | 534 | /* |
| 535 | * Host version information. |
| 536 | */ |
| 537 | extern unsigned int host_info_eax; |
| 538 | extern unsigned int host_info_ebx; |
| 539 | extern unsigned int host_info_ecx; |
| 540 | extern unsigned int host_info_edx; |
K. Y. Srinivasan | 940655c | 2011-05-12 19:34:31 -0700 | [diff] [blame] | 541 | |
| 542 | /* Interface */ |
| 543 | |
| 544 | |
| 545 | int hv_ringbuffer_init(struct hv_ring_buffer_info *ring_info, void *buffer, |
| 546 | u32 buflen); |
| 547 | |
| 548 | void hv_ringbuffer_cleanup(struct hv_ring_buffer_info *ring_info); |
| 549 | |
| 550 | int hv_ringbuffer_write(struct hv_ring_buffer_info *ring_info, |
| 551 | struct scatterlist *sglist, |
K. Y. Srinivasan | 98fa8cf | 2012-12-01 06:46:36 -0800 | [diff] [blame] | 552 | u32 sgcount, bool *signal); |
K. Y. Srinivasan | 940655c | 2011-05-12 19:34:31 -0700 | [diff] [blame] | 553 | |
| 554 | int hv_ringbuffer_peek(struct hv_ring_buffer_info *ring_info, void *buffer, |
| 555 | u32 buflen); |
| 556 | |
| 557 | int hv_ringbuffer_read(struct hv_ring_buffer_info *ring_info, |
| 558 | void *buffer, |
| 559 | u32 buflen, |
K. Y. Srinivasan | c2b8e52 | 2012-12-01 06:46:57 -0800 | [diff] [blame] | 560 | u32 offset, bool *signal); |
K. Y. Srinivasan | 940655c | 2011-05-12 19:34:31 -0700 | [diff] [blame] | 561 | |
K. Y. Srinivasan | 940655c | 2011-05-12 19:34:31 -0700 | [diff] [blame] | 562 | |
K. Y. Srinivasan | 940655c | 2011-05-12 19:34:31 -0700 | [diff] [blame] | 563 | void hv_ringbuffer_get_debuginfo(struct hv_ring_buffer_info *ring_info, |
| 564 | struct hv_ring_buffer_debug_info *debug_info); |
| 565 | |
K. Y. Srinivasan | 6fdf3b2 | 2012-12-01 06:46:32 -0800 | [diff] [blame] | 566 | void hv_begin_read(struct hv_ring_buffer_info *rbi); |
| 567 | |
| 568 | u32 hv_end_read(struct hv_ring_buffer_info *rbi); |
| 569 | |
K. Y. Srinivasan | 89b2ca4 | 2011-05-12 19:34:32 -0700 | [diff] [blame] | 570 | /* |
| 571 | * Maximum channels is determined by the size of the interrupt page |
| 572 | * which is PAGE_SIZE. 1/2 of PAGE_SIZE is for send endpoint interrupt |
| 573 | * and the other is receive endpoint interrupt |
| 574 | */ |
| 575 | #define MAX_NUM_CHANNELS ((PAGE_SIZE >> 1) << 3) /* 16348 channels */ |
| 576 | |
| 577 | /* The value here must be in multiple of 32 */ |
| 578 | /* TODO: Need to make this configurable */ |
| 579 | #define MAX_NUM_CHANNELS_SUPPORTED 256 |
| 580 | |
| 581 | |
| 582 | enum vmbus_connect_state { |
| 583 | DISCONNECTED, |
| 584 | CONNECTING, |
| 585 | CONNECTED, |
| 586 | DISCONNECTING |
| 587 | }; |
| 588 | |
| 589 | #define MAX_SIZE_CHANNEL_MESSAGE HV_MESSAGE_PAYLOAD_BYTE_COUNT |
| 590 | |
| 591 | struct vmbus_connection { |
| 592 | enum vmbus_connect_state conn_state; |
| 593 | |
| 594 | atomic_t next_gpadl_handle; |
| 595 | |
| 596 | /* |
| 597 | * Represents channel interrupts. Each bit position represents a |
| 598 | * channel. When a channel sends an interrupt via VMBUS, it finds its |
| 599 | * bit in the sendInterruptPage, set it and calls Hv to generate a port |
| 600 | * event. The other end receives the port event and parse the |
| 601 | * recvInterruptPage to see which bit is set |
| 602 | */ |
| 603 | void *int_page; |
| 604 | void *send_int_page; |
| 605 | void *recv_int_page; |
| 606 | |
| 607 | /* |
| 608 | * 2 pages - 1st page for parent->child notification and 2nd |
| 609 | * is child->parent notification |
| 610 | */ |
| 611 | void *monitor_pages; |
| 612 | struct list_head chn_msg_list; |
| 613 | spinlock_t channelmsg_lock; |
| 614 | |
| 615 | /* List of channels */ |
| 616 | struct list_head chn_list; |
| 617 | spinlock_t channel_lock; |
| 618 | |
| 619 | struct workqueue_struct *work_queue; |
| 620 | }; |
| 621 | |
| 622 | |
| 623 | struct vmbus_msginfo { |
| 624 | /* Bookkeeping stuff */ |
| 625 | struct list_head msglist_entry; |
| 626 | |
| 627 | /* The message itself */ |
| 628 | unsigned char msg[0]; |
| 629 | }; |
| 630 | |
| 631 | |
| 632 | extern struct vmbus_connection vmbus_connection; |
| 633 | |
| 634 | /* General vmbus interface */ |
| 635 | |
K. Y. Srinivasan | f2c7301 | 2011-09-08 07:24:12 -0700 | [diff] [blame] | 636 | struct hv_device *vmbus_device_create(uuid_le *type, |
K. Y. Srinivasan | 358d2ee | 2011-08-25 09:48:28 -0700 | [diff] [blame] | 637 | uuid_le *instance, |
K. Y. Srinivasan | 89b2ca4 | 2011-05-12 19:34:32 -0700 | [diff] [blame] | 638 | struct vmbus_channel *channel); |
| 639 | |
K. Y. Srinivasan | 22794281 | 2011-09-08 07:24:13 -0700 | [diff] [blame] | 640 | int vmbus_device_register(struct hv_device *child_device_obj); |
K. Y. Srinivasan | 696453b | 2011-09-08 07:24:14 -0700 | [diff] [blame] | 641 | void vmbus_device_unregister(struct hv_device *device_obj); |
K. Y. Srinivasan | 89b2ca4 | 2011-05-12 19:34:32 -0700 | [diff] [blame] | 642 | |
| 643 | /* static void */ |
| 644 | /* VmbusChildDeviceDestroy( */ |
| 645 | /* struct hv_device *); */ |
| 646 | |
| 647 | struct vmbus_channel *relid2channel(u32 relid); |
| 648 | |
K. Y. Srinivasan | 93e5bd0 | 2011-12-12 09:29:17 -0800 | [diff] [blame] | 649 | void vmbus_free_channels(void); |
K. Y. Srinivasan | 89b2ca4 | 2011-05-12 19:34:32 -0700 | [diff] [blame] | 650 | |
| 651 | /* Connection interface */ |
| 652 | |
| 653 | int vmbus_connect(void); |
| 654 | |
K. Y. Srinivasan | 89b2ca4 | 2011-05-12 19:34:32 -0700 | [diff] [blame] | 655 | int vmbus_post_msg(void *buffer, size_t buflen); |
| 656 | |
K. Y. Srinivasan | 21c3bef | 2012-12-01 06:46:43 -0800 | [diff] [blame] | 657 | int vmbus_set_event(struct vmbus_channel *channel); |
K. Y. Srinivasan | 89b2ca4 | 2011-05-12 19:34:32 -0700 | [diff] [blame] | 658 | |
| 659 | void vmbus_on_event(unsigned long data); |
| 660 | |
| 661 | |
K. Y. Srinivasan | 0f2a661 | 2011-05-12 19:34:28 -0700 | [diff] [blame] | 662 | #endif /* _HYPERV_VMBUS_H */ |