Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 1 | /* |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 2 | * Copyright (c) 2009, Microsoft Corporation. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms and conditions of the GNU General Public License, |
| 6 | * version 2, as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 11 | * more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along with |
| 14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
| 15 | * Place - Suite 330, Boston, MA 02111-1307 USA. |
| 16 | * |
| 17 | * Authors: |
| 18 | * Haiyang Zhang <haiyangz@microsoft.com> |
| 19 | * Hank Janssen <hjanssen@microsoft.com> |
| 20 | * |
| 21 | */ |
Greg Kroah-Hartman | a0086dc | 2009-08-17 17:22:08 -0700 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/mm.h> |
Bill Pemberton | b7c947f | 2009-07-29 17:00:13 -0400 | [diff] [blame] | 24 | #include <linux/vmalloc.h> |
Greg Kroah-Hartman | 4983b39 | 2009-08-19 16:14:47 -0700 | [diff] [blame] | 25 | #include "osd.h" |
Greg Kroah-Hartman | 645954c | 2009-08-28 16:22:59 -0700 | [diff] [blame] | 26 | #include "logging.h" |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 27 | #include "VmbusPrivate.h" |
| 28 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 29 | /* The one and only */ |
Greg Kroah-Hartman | af248e1 | 2009-08-18 15:20:34 -0700 | [diff] [blame] | 30 | struct hv_context gHvContext = { |
| 31 | .SynICInitialized = false, |
| 32 | .HypercallPage = NULL, |
| 33 | .SignalEventParam = NULL, |
| 34 | .SignalEventBuffer = NULL, |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 35 | }; |
| 36 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 37 | /** |
| 38 | * HvQueryHypervisorPresence - Query the cpuid for presense of windows hypervisor |
| 39 | */ |
| 40 | static int HvQueryHypervisorPresence(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 41 | { |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 42 | unsigned int eax; |
| 43 | unsigned int ebx; |
| 44 | unsigned int ecx; |
| 45 | unsigned int edx; |
| 46 | unsigned int op; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 47 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 48 | eax = 0; |
| 49 | ebx = 0; |
| 50 | ecx = 0; |
| 51 | edx = 0; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 52 | op = HvCpuIdFunctionVersionAndFeatures; |
Greg Kroah-Hartman | f931a70 | 2009-07-29 15:37:12 -0700 | [diff] [blame] | 53 | cpuid(op, &eax, &ebx, &ecx, &edx); |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 54 | |
| 55 | return ecx & HV_PRESENT_BIT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 58 | /** |
| 59 | * HvQueryHypervisorInfo - Get version info of the windows hypervisor |
| 60 | */ |
| 61 | static int HvQueryHypervisorInfo(void) |
| 62 | { |
| 63 | unsigned int eax; |
| 64 | unsigned int ebx; |
| 65 | unsigned int ecx; |
| 66 | unsigned int edx; |
| 67 | unsigned int maxLeaf; |
| 68 | unsigned int op; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 69 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 70 | /* |
| 71 | * Its assumed that this is called after confirming that Viridian |
| 72 | * is present. Query id and revision. |
| 73 | */ |
| 74 | eax = 0; |
| 75 | ebx = 0; |
| 76 | ecx = 0; |
| 77 | edx = 0; |
| 78 | op = HvCpuIdFunctionHvVendorAndMaxFunction; |
| 79 | cpuid(op, &eax, &ebx, &ecx, &edx); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 80 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 81 | DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", |
| 82 | (ebx & 0xFF), |
| 83 | ((ebx >> 8) & 0xFF), |
| 84 | ((ebx >> 16) & 0xFF), |
| 85 | ((ebx >> 24) & 0xFF), |
| 86 | (ecx & 0xFF), |
| 87 | ((ecx >> 8) & 0xFF), |
| 88 | ((ecx >> 16) & 0xFF), |
| 89 | ((ecx >> 24) & 0xFF), |
| 90 | (edx & 0xFF), |
| 91 | ((edx >> 8) & 0xFF), |
| 92 | ((edx >> 16) & 0xFF), |
| 93 | ((edx >> 24) & 0xFF)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 94 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 95 | maxLeaf = eax; |
| 96 | eax = 0; |
| 97 | ebx = 0; |
| 98 | ecx = 0; |
| 99 | edx = 0; |
| 100 | op = HvCpuIdFunctionHvInterface; |
| 101 | cpuid(op, &eax, &ebx, &ecx, &edx); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 102 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 103 | DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c", |
| 104 | (eax & 0xFF), |
| 105 | ((eax >> 8) & 0xFF), |
| 106 | ((eax >> 16) & 0xFF), |
| 107 | ((eax >> 24) & 0xFF)); |
| 108 | |
| 109 | if (maxLeaf >= HvCpuIdFunctionMsHvVersion) { |
| 110 | eax = 0; |
| 111 | ebx = 0; |
| 112 | ecx = 0; |
| 113 | edx = 0; |
| 114 | op = HvCpuIdFunctionMsHvVersion; |
| 115 | cpuid(op, &eax, &ebx, &ecx, &edx); |
| 116 | DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",\ |
| 117 | eax, |
| 118 | ebx >> 16, |
| 119 | ebx & 0xFFFF, |
| 120 | ecx, |
| 121 | edx >> 24, |
| 122 | edx & 0xFFFFFF); |
| 123 | } |
| 124 | return maxLeaf; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * HvDoHypercall - Invoke the specified hypercall |
| 129 | */ |
| 130 | static u64 HvDoHypercall(u64 Control, void *Input, void *Output) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 131 | { |
Greg Kroah-Hartman | 530cf20 | 2009-07-16 22:31:15 -0700 | [diff] [blame] | 132 | #ifdef CONFIG_X86_64 |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 133 | u64 hvStatus = 0; |
| 134 | u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; |
| 135 | u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; |
| 136 | volatile void *hypercallPage = gHvContext.HypercallPage; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 137 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 138 | DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p " |
| 139 | "output phys %llx virt %p hypercall %p>", |
| 140 | Control, inputAddress, Input, |
| 141 | outputAddress, Output, hypercallPage); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 142 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 143 | __asm__ __volatile__("mov %0, %%r8" : : "r" (outputAddress) : "r8"); |
| 144 | __asm__ __volatile__("call *%3" : "=a" (hvStatus) : |
| 145 | "c" (Control), "d" (inputAddress), |
| 146 | "m" (hypercallPage)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 147 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 148 | DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hvStatus); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 149 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 150 | return hvStatus; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 151 | |
| 152 | #else |
| 153 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 154 | u32 controlHi = Control >> 32; |
| 155 | u32 controlLo = Control & 0xFFFFFFFF; |
| 156 | u32 hvStatusHi = 1; |
| 157 | u32 hvStatusLo = 1; |
| 158 | u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; |
| 159 | u32 inputAddressHi = inputAddress >> 32; |
| 160 | u32 inputAddressLo = inputAddress & 0xFFFFFFFF; |
Greg Kroah-Hartman | fa56d36 | 2009-07-29 15:39:27 -0700 | [diff] [blame] | 161 | u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 162 | u32 outputAddressHi = outputAddress >> 32; |
| 163 | u32 outputAddressLo = outputAddress & 0xFFFFFFFF; |
| 164 | volatile void *hypercallPage = gHvContext.HypercallPage; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 165 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 166 | DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>", |
| 167 | Control, Input, Output); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 168 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 169 | __asm__ __volatile__ ("call *%8" : "=d"(hvStatusHi), |
| 170 | "=a"(hvStatusLo) : "d" (controlHi), |
| 171 | "a" (controlLo), "b" (inputAddressHi), |
| 172 | "c" (inputAddressLo), "D"(outputAddressHi), |
| 173 | "S"(outputAddressLo), "m" (hypercallPage)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 174 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 175 | DPRINT_DBG(VMBUS, "Hypercall <return %llx>", |
| 176 | hvStatusLo | ((u64)hvStatusHi << 32)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 177 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 178 | return hvStatusLo | ((u64)hvStatusHi << 32); |
| 179 | #endif /* !x86_64 */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 182 | /** |
| 183 | * HvInit - Main initialization routine. |
| 184 | * |
| 185 | * This routine must be called before any other routines in here are called |
| 186 | */ |
| 187 | int HvInit(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 188 | { |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 189 | int ret = 0; |
| 190 | int maxLeaf; |
Greg Kroah-Hartman | f80b3d5 | 2009-08-20 12:09:34 -0700 | [diff] [blame] | 191 | union hv_x64_msr_hypercall_contents hypercallMsr; |
Greg Kroah-Hartman | 949cada | 2009-07-29 09:06:51 -0700 | [diff] [blame] | 192 | void *virtAddr = NULL; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 193 | |
| 194 | DPRINT_ENTER(VMBUS); |
| 195 | |
Bill Pemberton | 44f357f | 2009-07-28 13:46:26 -0400 | [diff] [blame] | 196 | memset(gHvContext.synICEventPage, 0, sizeof(void *) * MAX_NUM_CPUS); |
| 197 | memset(gHvContext.synICMessagePage, 0, sizeof(void *) * MAX_NUM_CPUS); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 198 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 199 | if (!HvQueryHypervisorPresence()) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 200 | DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!"); |
| 201 | goto Cleanup; |
| 202 | } |
| 203 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 204 | DPRINT_INFO(VMBUS, |
| 205 | "Windows hypervisor detected! Retrieving more info..."); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 206 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 207 | maxLeaf = HvQueryHypervisorInfo(); |
| 208 | /* HvQueryHypervisorFeatures(maxLeaf); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 209 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 210 | /* |
| 211 | * Determine if we are running on xenlinux (ie x2v shim) or native |
| 212 | * linux |
| 213 | */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 214 | rdmsrl(HV_X64_MSR_GUEST_OS_ID, gHvContext.GuestId); |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 215 | if (gHvContext.GuestId == 0) { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 216 | /* Write our OS info */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 217 | wrmsrl(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 218 | gHvContext.GuestId = HV_LINUX_GUEST_ID; |
| 219 | } |
| 220 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 221 | /* See if the hypercall page is already set */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 222 | rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 223 | if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 224 | /* Allocate the hypercall page memory */ |
Greg Kroah-Hartman | bfc30aae | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 225 | /* virtAddr = osd_PageAlloc(1); */ |
| 226 | virtAddr = osd_VirtualAllocExec(PAGE_SIZE); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 227 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 228 | if (!virtAddr) { |
| 229 | DPRINT_ERR(VMBUS, |
| 230 | "unable to allocate hypercall page!!"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 231 | goto Cleanup; |
| 232 | } |
| 233 | |
| 234 | hypercallMsr.Enable = 1; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 235 | /* hypercallMsr.GuestPhysicalAddress = |
| 236 | * virt_to_phys(virtAddr) >> PAGE_SHIFT; */ |
Greg Kroah-Hartman | fa56d36 | 2009-07-29 15:39:27 -0700 | [diff] [blame] | 237 | hypercallMsr.GuestPhysicalAddress = vmalloc_to_pfn(virtAddr); |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 238 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 239 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 240 | /* Confirm that hypercall page did get setup. */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 241 | hypercallMsr.AsUINT64 = 0; |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 242 | rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 243 | if (!hypercallMsr.Enable) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 244 | DPRINT_ERR(VMBUS, "unable to set hypercall page!!"); |
| 245 | goto Cleanup; |
| 246 | } |
| 247 | |
| 248 | gHvContext.HypercallPage = virtAddr; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 249 | } else { |
| 250 | DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", |
| 251 | gHvContext.GuestId); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 252 | goto Cleanup; |
| 253 | } |
| 254 | |
Greg Kroah-Hartman | 2701f68 | 2009-07-16 12:36:37 -0700 | [diff] [blame] | 255 | DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx", |
| 256 | gHvContext.HypercallPage, |
| 257 | (u64)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 258 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 259 | /* Setup the global signal event param for the signal event hypercall */ |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 260 | gHvContext.SignalEventBuffer = |
| 261 | kmalloc(sizeof(struct hv_input_signal_event_buffer), |
| 262 | GFP_KERNEL); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 263 | if (!gHvContext.SignalEventBuffer) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 264 | goto Cleanup; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 265 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 266 | gHvContext.SignalEventParam = |
| 267 | (struct hv_input_signal_event *) |
| 268 | (ALIGN_UP((unsigned long)gHvContext.SignalEventBuffer, |
| 269 | HV_HYPERCALL_PARAM_ALIGN)); |
Greg Kroah-Hartman | 4d64311 | 2009-07-14 15:09:36 -0700 | [diff] [blame] | 270 | gHvContext.SignalEventParam->ConnectionId.Asu32 = 0; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 271 | gHvContext.SignalEventParam->ConnectionId.u.Id = |
| 272 | VMBUS_EVENT_CONNECTION_ID; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 273 | gHvContext.SignalEventParam->FlagNumber = 0; |
| 274 | gHvContext.SignalEventParam->RsvdZ = 0; |
| 275 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 276 | /* DPRINT_DBG(VMBUS, "My id %llu", HvGetCurrentPartitionId()); */ |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 277 | |
| 278 | DPRINT_EXIT(VMBUS); |
| 279 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 280 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 281 | |
| 282 | Cleanup: |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 283 | if (virtAddr) { |
| 284 | if (hypercallMsr.Enable) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 285 | hypercallMsr.AsUINT64 = 0; |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 286 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Bill Pemberton | b7c947f | 2009-07-29 17:00:13 -0400 | [diff] [blame] | 289 | vfree(virtAddr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 290 | } |
| 291 | ret = -1; |
| 292 | DPRINT_EXIT(VMBUS); |
| 293 | |
| 294 | return ret; |
| 295 | } |
| 296 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 297 | /** |
| 298 | * HvCleanup - Cleanup routine. |
| 299 | * |
| 300 | * This routine is called normally during driver unloading or exiting. |
| 301 | */ |
| 302 | void HvCleanup(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 303 | { |
Greg Kroah-Hartman | f80b3d5 | 2009-08-20 12:09:34 -0700 | [diff] [blame] | 304 | union hv_x64_msr_hypercall_contents hypercallMsr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 305 | |
| 306 | DPRINT_ENTER(VMBUS); |
| 307 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 308 | if (gHvContext.SignalEventBuffer) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 309 | gHvContext.SignalEventBuffer = NULL; |
| 310 | gHvContext.SignalEventParam = NULL; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 311 | kfree(gHvContext.SignalEventBuffer); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 314 | if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { |
| 315 | if (gHvContext.HypercallPage) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 316 | hypercallMsr.AsUINT64 = 0; |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 317 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); |
Bill Pemberton | b7c947f | 2009-07-29 17:00:13 -0400 | [diff] [blame] | 318 | vfree(gHvContext.HypercallPage); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 319 | gHvContext.HypercallPage = NULL; |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | DPRINT_EXIT(VMBUS); |
| 324 | |
| 325 | } |
| 326 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 327 | /** |
| 328 | * HvPostMessage - Post a message using the hypervisor message IPC. |
| 329 | * |
| 330 | * This involves a hypercall. |
| 331 | */ |
Greg Kroah-Hartman | 034469e | 2009-08-20 12:14:11 -0700 | [diff] [blame] | 332 | u16 HvPostMessage(union hv_connection_id connectionId, |
| 333 | enum hv_message_type messageType, |
| 334 | void *payload, size_t payloadSize) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 335 | { |
| 336 | struct alignedInput { |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 337 | u64 alignment8; |
Greg Kroah-Hartman | cba4dec | 2009-08-19 16:21:28 -0700 | [diff] [blame] | 338 | struct hv_input_post_message msg; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 339 | }; |
| 340 | |
Greg Kroah-Hartman | cba4dec | 2009-08-19 16:21:28 -0700 | [diff] [blame] | 341 | struct hv_input_post_message *alignedMsg; |
Greg Kroah-Hartman | 034469e | 2009-08-20 12:14:11 -0700 | [diff] [blame] | 342 | u16 status; |
Greg Kroah-Hartman | c4b0bc9 | 2009-07-14 15:12:46 -0700 | [diff] [blame] | 343 | unsigned long addr; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 344 | |
| 345 | if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 346 | return -1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 347 | |
Greg Kroah-Hartman | 0a72f3c | 2009-07-15 12:48:01 -0700 | [diff] [blame] | 348 | addr = (unsigned long)kmalloc(sizeof(struct alignedInput), GFP_ATOMIC); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 349 | if (!addr) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 350 | return -1; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 351 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 352 | alignedMsg = (struct hv_input_post_message *) |
| 353 | (ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 354 | |
| 355 | alignedMsg->ConnectionId = connectionId; |
| 356 | alignedMsg->MessageType = messageType; |
| 357 | alignedMsg->PayloadSize = payloadSize; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 358 | memcpy((void *)alignedMsg->Payload, payload, payloadSize); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 359 | |
Greg Kroah-Hartman | 949cada | 2009-07-29 09:06:51 -0700 | [diff] [blame] | 360 | status = HvDoHypercall(HvCallPostMessage, alignedMsg, NULL) & 0xFFFF; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 361 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 362 | kfree((void *)addr); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 363 | |
| 364 | return status; |
| 365 | } |
| 366 | |
| 367 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 368 | /** |
| 369 | * HvSignalEvent - Signal an event on the specified connection using the hypervisor event IPC. |
| 370 | * |
| 371 | * This involves a hypercall. |
| 372 | */ |
Greg Kroah-Hartman | 034469e | 2009-08-20 12:14:11 -0700 | [diff] [blame] | 373 | u16 HvSignalEvent(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 374 | { |
Greg Kroah-Hartman | 034469e | 2009-08-20 12:14:11 -0700 | [diff] [blame] | 375 | u16 status; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 376 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 377 | status = HvDoHypercall(HvCallSignalEvent, gHvContext.SignalEventParam, |
| 378 | NULL) & 0xFFFF; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 379 | return status; |
| 380 | } |
| 381 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 382 | /** |
| 383 | * HvSynicInit - Initialize the Synthethic Interrupt Controller. |
| 384 | * |
| 385 | * If it is already initialized by another entity (ie x2v shim), we need to |
| 386 | * retrieve the initialized message and event pages. Otherwise, we create and |
| 387 | * initialize the message and event pages. |
| 388 | */ |
| 389 | int HvSynicInit(u32 irqVector) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 390 | { |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 391 | u64 version; |
Greg Kroah-Hartman | eacb1b4 | 2009-08-20 12:11:26 -0700 | [diff] [blame] | 392 | union hv_synic_simp simp; |
| 393 | union hv_synic_siefp siefp; |
| 394 | union hv_synic_sint sharedSint; |
| 395 | union hv_synic_scontrol sctrl; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 396 | u64 guestID; |
| 397 | int ret = 0; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 398 | |
| 399 | DPRINT_ENTER(VMBUS); |
| 400 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 401 | if (!gHvContext.HypercallPage) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 402 | DPRINT_EXIT(VMBUS); |
| 403 | return ret; |
| 404 | } |
| 405 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 406 | /* Check the version */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 407 | rdmsrl(HV_X64_MSR_SVERSION, version); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 408 | |
| 409 | DPRINT_INFO(VMBUS, "SynIC version: %llx", version); |
| 410 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 411 | /* TODO: Handle SMP */ |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 412 | if (gHvContext.GuestId == HV_XENLINUX_GUEST_ID) { |
| 413 | DPRINT_INFO(VMBUS, "Skipping SIMP and SIEFP setup since " |
| 414 | "it is already set."); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 415 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 416 | rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
| 417 | rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 418 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 419 | DPRINT_DBG(VMBUS, "Simp: %llx, Sifep: %llx", |
| 420 | simp.AsUINT64, siefp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 421 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 422 | /* |
| 423 | * Determine if we are running on xenlinux (ie x2v shim) or |
| 424 | * native linux |
| 425 | */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 426 | rdmsrl(HV_X64_MSR_GUEST_OS_ID, guestID); |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 427 | if (guestID == HV_LINUX_GUEST_ID) { |
| 428 | gHvContext.synICMessagePage[0] = |
| 429 | phys_to_virt(simp.BaseSimpGpa << PAGE_SHIFT); |
| 430 | gHvContext.synICEventPage[0] = |
| 431 | phys_to_virt(siefp.BaseSiefpGpa << PAGE_SHIFT); |
| 432 | } else { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 433 | DPRINT_ERR(VMBUS, "unknown guest id!!"); |
| 434 | goto Cleanup; |
| 435 | } |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 436 | DPRINT_DBG(VMBUS, "MAPPED: Simp: %p, Sifep: %p", |
| 437 | gHvContext.synICMessagePage[0], |
| 438 | gHvContext.synICEventPage[0]); |
| 439 | } else { |
Greg Kroah-Hartman | bfc30aae | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 440 | gHvContext.synICMessagePage[0] = osd_PageAlloc(1); |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 441 | if (gHvContext.synICMessagePage[0] == NULL) { |
| 442 | DPRINT_ERR(VMBUS, |
| 443 | "unable to allocate SYNIC message page!!"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 444 | goto Cleanup; |
| 445 | } |
| 446 | |
Greg Kroah-Hartman | bfc30aae | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 447 | gHvContext.synICEventPage[0] = osd_PageAlloc(1); |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 448 | if (gHvContext.synICEventPage[0] == NULL) { |
| 449 | DPRINT_ERR(VMBUS, |
| 450 | "unable to allocate SYNIC event page!!"); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 451 | goto Cleanup; |
| 452 | } |
| 453 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 454 | /* Setup the Synic's message page */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 455 | rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 456 | simp.SimpEnabled = 1; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 457 | simp.BaseSimpGpa = virt_to_phys(gHvContext.synICMessagePage[0]) |
| 458 | >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 459 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 460 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", |
| 461 | simp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 462 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 463 | wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 464 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 465 | /* Setup the Synic's event page */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 466 | rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 467 | siefp.SiefpEnabled = 1; |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 468 | siefp.BaseSiefpGpa = virt_to_phys(gHvContext.synICEventPage[0]) |
| 469 | >> PAGE_SHIFT; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 470 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 471 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", |
| 472 | siefp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 473 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 474 | wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 475 | } |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 476 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 477 | /* Setup the interception SINT. */ |
| 478 | /* wrmsrl((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX), */ |
| 479 | /* interceptionSint.AsUINT64); */ |
| 480 | |
| 481 | /* Setup the shared SINT. */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 482 | rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 483 | |
| 484 | sharedSint.AsUINT64 = 0; |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 485 | sharedSint.Vector = irqVector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ |
| 486 | sharedSint.Masked = false; |
| 487 | sharedSint.AutoEoi = true; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 488 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 489 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", |
| 490 | sharedSint.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 491 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 492 | wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 493 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 494 | /* Enable the global synic bit */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 495 | rdmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 496 | sctrl.Enable = 1; |
| 497 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 498 | wrmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 499 | |
Greg Kroah-Hartman | 0e72761 | 2009-07-15 12:46:44 -0700 | [diff] [blame] | 500 | gHvContext.SynICInitialized = true; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 501 | |
| 502 | DPRINT_EXIT(VMBUS); |
| 503 | |
| 504 | return ret; |
| 505 | |
| 506 | Cleanup: |
| 507 | ret = -1; |
| 508 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 509 | if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 510 | if (gHvContext.synICEventPage[0]) |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 511 | osd_PageFree(gHvContext.synICEventPage[0], 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 512 | |
| 513 | if (gHvContext.synICMessagePage[0]) |
Greg Kroah-Hartman | bfc30aae | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 514 | osd_PageFree(gHvContext.synICMessagePage[0], 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | DPRINT_EXIT(VMBUS); |
| 518 | |
| 519 | return ret; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 522 | /** |
| 523 | * HvSynicCleanup - Cleanup routine for HvSynicInit(). |
| 524 | */ |
Greg Kroah-Hartman | 98d9fac | 2009-08-17 17:20:55 -0700 | [diff] [blame] | 525 | void HvSynicCleanup(void) |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 526 | { |
Greg Kroah-Hartman | eacb1b4 | 2009-08-20 12:11:26 -0700 | [diff] [blame] | 527 | union hv_synic_sint sharedSint; |
| 528 | union hv_synic_simp simp; |
| 529 | union hv_synic_siefp siefp; |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 530 | |
| 531 | DPRINT_ENTER(VMBUS); |
| 532 | |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 533 | if (!gHvContext.SynICInitialized) { |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 534 | DPRINT_EXIT(VMBUS); |
| 535 | return; |
| 536 | } |
| 537 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 538 | rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 539 | |
| 540 | sharedSint.Masked = 1; |
| 541 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 542 | /* Disable the interrupt */ |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 543 | wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 544 | |
Bill Pemberton | 454f18a | 2009-07-27 16:47:24 -0400 | [diff] [blame] | 545 | /* |
| 546 | * Disable and free the resources only if we are running as |
| 547 | * native linux since in xenlinux, we are sharing the |
| 548 | * resources with the x2v shim |
| 549 | */ |
Greg Kroah-Hartman | 0831ad0 | 2009-08-31 20:23:33 -0700 | [diff] [blame] | 550 | if (gHvContext.GuestId == HV_LINUX_GUEST_ID) { |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 551 | rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 552 | simp.SimpEnabled = 0; |
| 553 | simp.BaseSimpGpa = 0; |
| 554 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 555 | wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 556 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 557 | rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 558 | siefp.SiefpEnabled = 0; |
| 559 | siefp.BaseSiefpGpa = 0; |
| 560 | |
Greg Kroah-Hartman | a51ed7d | 2009-08-17 17:20:02 -0700 | [diff] [blame] | 561 | wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 562 | |
Greg Kroah-Hartman | bfc30aae | 2009-07-29 15:40:18 -0700 | [diff] [blame] | 563 | osd_PageFree(gHvContext.synICMessagePage[0], 1); |
| 564 | osd_PageFree(gHvContext.synICEventPage[0], 1); |
Hank Janssen | 3e7ee49 | 2009-07-13 16:02:34 -0700 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | DPRINT_EXIT(VMBUS); |
| 568 | } |