Commit | Line | Data |
---|---|---|
3e7ee490 | 1 | /* |
3e7ee490 HJ |
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 | */ | |
a0086dc5 GKH |
22 | #include <linux/kernel.h> |
23 | #include <linux/mm.h> | |
5a0e3ad6 | 24 | #include <linux/slab.h> |
b7c947f0 | 25 | #include <linux/vmalloc.h> |
4983b39a | 26 | #include "osd.h" |
645954c5 | 27 | #include "logging.h" |
3e7ee490 HJ |
28 | #include "VmbusPrivate.h" |
29 | ||
454f18a9 | 30 | /* The one and only */ |
af248e1f GKH |
31 | struct hv_context gHvContext = { |
32 | .SynICInitialized = false, | |
33 | .HypercallPage = NULL, | |
34 | .SignalEventParam = NULL, | |
35 | .SignalEventBuffer = NULL, | |
3e7ee490 HJ |
36 | }; |
37 | ||
0831ad04 GKH |
38 | /** |
39 | * HvQueryHypervisorPresence - Query the cpuid for presense of windows hypervisor | |
40 | */ | |
41 | static int HvQueryHypervisorPresence(void) | |
3e7ee490 | 42 | { |
0831ad04 GKH |
43 | unsigned int eax; |
44 | unsigned int ebx; | |
45 | unsigned int ecx; | |
46 | unsigned int edx; | |
47 | unsigned int op; | |
3e7ee490 | 48 | |
454f18a9 BP |
49 | eax = 0; |
50 | ebx = 0; | |
51 | ecx = 0; | |
52 | edx = 0; | |
0831ad04 | 53 | op = HvCpuIdFunctionVersionAndFeatures; |
f931a70c | 54 | cpuid(op, &eax, &ebx, &ecx, &edx); |
0831ad04 GKH |
55 | |
56 | return ecx & HV_PRESENT_BIT; | |
3e7ee490 HJ |
57 | } |
58 | ||
0831ad04 GKH |
59 | /** |
60 | * HvQueryHypervisorInfo - Get version info of the windows hypervisor | |
61 | */ | |
62 | static int HvQueryHypervisorInfo(void) | |
63 | { | |
64 | unsigned int eax; | |
65 | unsigned int ebx; | |
66 | unsigned int ecx; | |
67 | unsigned int edx; | |
68 | unsigned int maxLeaf; | |
69 | unsigned int op; | |
3e7ee490 | 70 | |
0831ad04 GKH |
71 | /* |
72 | * Its assumed that this is called after confirming that Viridian | |
73 | * is present. Query id and revision. | |
74 | */ | |
75 | eax = 0; | |
76 | ebx = 0; | |
77 | ecx = 0; | |
78 | edx = 0; | |
79 | op = HvCpuIdFunctionHvVendorAndMaxFunction; | |
80 | cpuid(op, &eax, &ebx, &ecx, &edx); | |
3e7ee490 | 81 | |
0831ad04 GKH |
82 | DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", |
83 | (ebx & 0xFF), | |
84 | ((ebx >> 8) & 0xFF), | |
85 | ((ebx >> 16) & 0xFF), | |
86 | ((ebx >> 24) & 0xFF), | |
87 | (ecx & 0xFF), | |
88 | ((ecx >> 8) & 0xFF), | |
89 | ((ecx >> 16) & 0xFF), | |
90 | ((ecx >> 24) & 0xFF), | |
91 | (edx & 0xFF), | |
92 | ((edx >> 8) & 0xFF), | |
93 | ((edx >> 16) & 0xFF), | |
94 | ((edx >> 24) & 0xFF)); | |
95 | ||
96 | maxLeaf = eax; | |
97 | eax = 0; | |
98 | ebx = 0; | |
99 | ecx = 0; | |
100 | edx = 0; | |
101 | op = HvCpuIdFunctionHvInterface; | |
102 | cpuid(op, &eax, &ebx, &ecx, &edx); | |
3e7ee490 | 103 | |
0831ad04 GKH |
104 | DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c", |
105 | (eax & 0xFF), | |
106 | ((eax >> 8) & 0xFF), | |
107 | ((eax >> 16) & 0xFF), | |
108 | ((eax >> 24) & 0xFF)); | |
109 | ||
110 | if (maxLeaf >= HvCpuIdFunctionMsHvVersion) { | |
111 | eax = 0; | |
112 | ebx = 0; | |
113 | ecx = 0; | |
114 | edx = 0; | |
115 | op = HvCpuIdFunctionMsHvVersion; | |
116 | cpuid(op, &eax, &ebx, &ecx, &edx); | |
117 | DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",\ | |
118 | eax, | |
119 | ebx >> 16, | |
120 | ebx & 0xFFFF, | |
121 | ecx, | |
122 | edx >> 24, | |
123 | edx & 0xFFFFFF); | |
124 | } | |
125 | return maxLeaf; | |
126 | } | |
3e7ee490 | 127 | |
0831ad04 GKH |
128 | /** |
129 | * HvDoHypercall - Invoke the specified hypercall | |
130 | */ | |
131 | static u64 HvDoHypercall(u64 Control, void *Input, void *Output) | |
3e7ee490 | 132 | { |
530cf207 | 133 | #ifdef CONFIG_X86_64 |
0831ad04 GKH |
134 | u64 hvStatus = 0; |
135 | u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; | |
136 | u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; | |
137 | volatile void *hypercallPage = gHvContext.HypercallPage; | |
3e7ee490 | 138 | |
0831ad04 GKH |
139 | DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p " |
140 | "output phys %llx virt %p hypercall %p>", | |
141 | Control, inputAddress, Input, | |
142 | outputAddress, Output, hypercallPage); | |
3e7ee490 | 143 | |
0831ad04 GKH |
144 | __asm__ __volatile__("mov %0, %%r8" : : "r" (outputAddress) : "r8"); |
145 | __asm__ __volatile__("call *%3" : "=a" (hvStatus) : | |
146 | "c" (Control), "d" (inputAddress), | |
147 | "m" (hypercallPage)); | |
3e7ee490 | 148 | |
0831ad04 | 149 | DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hvStatus); |
3e7ee490 | 150 | |
0831ad04 | 151 | return hvStatus; |
3e7ee490 HJ |
152 | |
153 | #else | |
154 | ||
0831ad04 GKH |
155 | u32 controlHi = Control >> 32; |
156 | u32 controlLo = Control & 0xFFFFFFFF; | |
157 | u32 hvStatusHi = 1; | |
158 | u32 hvStatusLo = 1; | |
159 | u64 inputAddress = (Input) ? virt_to_phys(Input) : 0; | |
160 | u32 inputAddressHi = inputAddress >> 32; | |
161 | u32 inputAddressLo = inputAddress & 0xFFFFFFFF; | |
fa56d361 | 162 | u64 outputAddress = (Output) ? virt_to_phys(Output) : 0; |
0831ad04 GKH |
163 | u32 outputAddressHi = outputAddress >> 32; |
164 | u32 outputAddressLo = outputAddress & 0xFFFFFFFF; | |
165 | volatile void *hypercallPage = gHvContext.HypercallPage; | |
3e7ee490 | 166 | |
0831ad04 GKH |
167 | DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>", |
168 | Control, Input, Output); | |
3e7ee490 | 169 | |
0831ad04 GKH |
170 | __asm__ __volatile__ ("call *%8" : "=d"(hvStatusHi), |
171 | "=a"(hvStatusLo) : "d" (controlHi), | |
172 | "a" (controlLo), "b" (inputAddressHi), | |
173 | "c" (inputAddressLo), "D"(outputAddressHi), | |
174 | "S"(outputAddressLo), "m" (hypercallPage)); | |
3e7ee490 | 175 | |
0831ad04 GKH |
176 | DPRINT_DBG(VMBUS, "Hypercall <return %llx>", |
177 | hvStatusLo | ((u64)hvStatusHi << 32)); | |
3e7ee490 | 178 | |
0831ad04 GKH |
179 | return hvStatusLo | ((u64)hvStatusHi << 32); |
180 | #endif /* !x86_64 */ | |
3e7ee490 HJ |
181 | } |
182 | ||
0831ad04 GKH |
183 | /** |
184 | * HvInit - Main initialization routine. | |
185 | * | |
186 | * This routine must be called before any other routines in here are called | |
187 | */ | |
188 | int HvInit(void) | |
3e7ee490 | 189 | { |
0831ad04 GKH |
190 | int ret = 0; |
191 | int maxLeaf; | |
f80b3d51 | 192 | union hv_x64_msr_hypercall_contents hypercallMsr; |
949cadaa | 193 | void *virtAddr = NULL; |
3e7ee490 HJ |
194 | |
195 | DPRINT_ENTER(VMBUS); | |
196 | ||
44f357f8 BP |
197 | memset(gHvContext.synICEventPage, 0, sizeof(void *) * MAX_NUM_CPUS); |
198 | memset(gHvContext.synICMessagePage, 0, sizeof(void *) * MAX_NUM_CPUS); | |
3e7ee490 | 199 | |
0831ad04 | 200 | if (!HvQueryHypervisorPresence()) { |
3e7ee490 HJ |
201 | DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!"); |
202 | goto Cleanup; | |
203 | } | |
204 | ||
0831ad04 GKH |
205 | DPRINT_INFO(VMBUS, |
206 | "Windows hypervisor detected! Retrieving more info..."); | |
3e7ee490 | 207 | |
0831ad04 GKH |
208 | maxLeaf = HvQueryHypervisorInfo(); |
209 | /* HvQueryHypervisorFeatures(maxLeaf); */ | |
3e7ee490 | 210 | |
0831ad04 | 211 | /* |
a73e6b7c | 212 | * We only support running on top of Hyper-V |
0831ad04 | 213 | */ |
a51ed7d6 | 214 | rdmsrl(HV_X64_MSR_GUEST_OS_ID, gHvContext.GuestId); |
a73e6b7c HJ |
215 | |
216 | if (gHvContext.GuestId != 0) { | |
217 | DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", | |
218 | gHvContext.GuestId); | |
219 | goto Cleanup; | |
3e7ee490 HJ |
220 | } |
221 | ||
a73e6b7c HJ |
222 | /* Write our OS info */ |
223 | wrmsrl(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID); | |
224 | gHvContext.GuestId = HV_LINUX_GUEST_ID; | |
225 | ||
454f18a9 | 226 | /* See if the hypercall page is already set */ |
a51ed7d6 | 227 | rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); |
3e7ee490 | 228 | |
a73e6b7c HJ |
229 | /* |
230 | * Allocate the hypercall page memory | |
231 | * virtAddr = osd_PageAlloc(1); | |
232 | */ | |
233 | virtAddr = osd_VirtualAllocExec(PAGE_SIZE); | |
3e7ee490 | 234 | |
a73e6b7c HJ |
235 | if (!virtAddr) { |
236 | DPRINT_ERR(VMBUS, | |
237 | "unable to allocate hypercall page!!"); | |
238 | goto Cleanup; | |
239 | } | |
3e7ee490 | 240 | |
a73e6b7c HJ |
241 | hypercallMsr.Enable = 1; |
242 | ||
243 | hypercallMsr.GuestPhysicalAddress = vmalloc_to_pfn(virtAddr); | |
244 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); | |
245 | ||
246 | /* Confirm that hypercall page did get setup. */ | |
247 | hypercallMsr.AsUINT64 = 0; | |
248 | rdmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); | |
249 | ||
250 | if (!hypercallMsr.Enable) { | |
251 | DPRINT_ERR(VMBUS, "unable to set hypercall page!!"); | |
3e7ee490 HJ |
252 | goto Cleanup; |
253 | } | |
254 | ||
a73e6b7c HJ |
255 | gHvContext.HypercallPage = virtAddr; |
256 | ||
2701f686 GKH |
257 | DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx", |
258 | gHvContext.HypercallPage, | |
259 | (u64)hypercallMsr.GuestPhysicalAddress << PAGE_SHIFT); | |
3e7ee490 | 260 | |
454f18a9 | 261 | /* Setup the global signal event param for the signal event hypercall */ |
0831ad04 GKH |
262 | gHvContext.SignalEventBuffer = |
263 | kmalloc(sizeof(struct hv_input_signal_event_buffer), | |
264 | GFP_KERNEL); | |
3e7ee490 | 265 | if (!gHvContext.SignalEventBuffer) |
3e7ee490 | 266 | goto Cleanup; |
3e7ee490 | 267 | |
0831ad04 GKH |
268 | gHvContext.SignalEventParam = |
269 | (struct hv_input_signal_event *) | |
270 | (ALIGN_UP((unsigned long)gHvContext.SignalEventBuffer, | |
271 | HV_HYPERCALL_PARAM_ALIGN)); | |
4d643114 | 272 | gHvContext.SignalEventParam->ConnectionId.Asu32 = 0; |
0831ad04 GKH |
273 | gHvContext.SignalEventParam->ConnectionId.u.Id = |
274 | VMBUS_EVENT_CONNECTION_ID; | |
3e7ee490 HJ |
275 | gHvContext.SignalEventParam->FlagNumber = 0; |
276 | gHvContext.SignalEventParam->RsvdZ = 0; | |
277 | ||
3e7ee490 HJ |
278 | DPRINT_EXIT(VMBUS); |
279 | ||
0831ad04 | 280 | return ret; |
3e7ee490 HJ |
281 | |
282 | Cleanup: | |
0831ad04 GKH |
283 | if (virtAddr) { |
284 | if (hypercallMsr.Enable) { | |
3e7ee490 | 285 | hypercallMsr.AsUINT64 = 0; |
a51ed7d6 | 286 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); |
3e7ee490 HJ |
287 | } |
288 | ||
b7c947f0 | 289 | vfree(virtAddr); |
3e7ee490 HJ |
290 | } |
291 | ret = -1; | |
292 | DPRINT_EXIT(VMBUS); | |
293 | ||
294 | return ret; | |
295 | } | |
296 | ||
0831ad04 GKH |
297 | /** |
298 | * HvCleanup - Cleanup routine. | |
299 | * | |
300 | * This routine is called normally during driver unloading or exiting. | |
301 | */ | |
302 | void HvCleanup(void) | |
3e7ee490 | 303 | { |
f80b3d51 | 304 | union hv_x64_msr_hypercall_contents hypercallMsr; |
3e7ee490 HJ |
305 | |
306 | DPRINT_ENTER(VMBUS); | |
307 | ||
0831ad04 | 308 | if (gHvContext.SignalEventBuffer) { |
3e7ee490 HJ |
309 | gHvContext.SignalEventBuffer = NULL; |
310 | gHvContext.SignalEventParam = NULL; | |
0831ad04 | 311 | kfree(gHvContext.SignalEventBuffer); |
3e7ee490 HJ |
312 | } |
313 | ||
a73e6b7c HJ |
314 | if (gHvContext.HypercallPage) { |
315 | hypercallMsr.AsUINT64 = 0; | |
316 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercallMsr.AsUINT64); | |
317 | vfree(gHvContext.HypercallPage); | |
318 | gHvContext.HypercallPage = NULL; | |
3e7ee490 HJ |
319 | } |
320 | ||
321 | DPRINT_EXIT(VMBUS); | |
3e7ee490 HJ |
322 | } |
323 | ||
0831ad04 GKH |
324 | /** |
325 | * HvPostMessage - Post a message using the hypervisor message IPC. | |
326 | * | |
327 | * This involves a hypercall. | |
328 | */ | |
034469e6 GKH |
329 | u16 HvPostMessage(union hv_connection_id connectionId, |
330 | enum hv_message_type messageType, | |
331 | void *payload, size_t payloadSize) | |
3e7ee490 HJ |
332 | { |
333 | struct alignedInput { | |
0831ad04 | 334 | u64 alignment8; |
cba4decd | 335 | struct hv_input_post_message msg; |
3e7ee490 HJ |
336 | }; |
337 | ||
cba4decd | 338 | struct hv_input_post_message *alignedMsg; |
034469e6 | 339 | u16 status; |
c4b0bc94 | 340 | unsigned long addr; |
3e7ee490 HJ |
341 | |
342 | if (payloadSize > HV_MESSAGE_PAYLOAD_BYTE_COUNT) | |
3e7ee490 | 343 | return -1; |
3e7ee490 | 344 | |
0a72f3cf | 345 | addr = (unsigned long)kmalloc(sizeof(struct alignedInput), GFP_ATOMIC); |
3e7ee490 | 346 | if (!addr) |
3e7ee490 | 347 | return -1; |
3e7ee490 | 348 | |
0831ad04 GKH |
349 | alignedMsg = (struct hv_input_post_message *) |
350 | (ALIGN_UP(addr, HV_HYPERCALL_PARAM_ALIGN)); | |
3e7ee490 HJ |
351 | |
352 | alignedMsg->ConnectionId = connectionId; | |
353 | alignedMsg->MessageType = messageType; | |
354 | alignedMsg->PayloadSize = payloadSize; | |
0831ad04 | 355 | memcpy((void *)alignedMsg->Payload, payload, payloadSize); |
3e7ee490 | 356 | |
949cadaa | 357 | status = HvDoHypercall(HvCallPostMessage, alignedMsg, NULL) & 0xFFFF; |
3e7ee490 | 358 | |
0831ad04 | 359 | kfree((void *)addr); |
3e7ee490 HJ |
360 | |
361 | return status; | |
362 | } | |
363 | ||
364 | ||
0831ad04 GKH |
365 | /** |
366 | * HvSignalEvent - Signal an event on the specified connection using the hypervisor event IPC. | |
367 | * | |
368 | * This involves a hypercall. | |
369 | */ | |
034469e6 | 370 | u16 HvSignalEvent(void) |
3e7ee490 | 371 | { |
034469e6 | 372 | u16 status; |
3e7ee490 | 373 | |
0831ad04 GKH |
374 | status = HvDoHypercall(HvCallSignalEvent, gHvContext.SignalEventParam, |
375 | NULL) & 0xFFFF; | |
3e7ee490 HJ |
376 | return status; |
377 | } | |
378 | ||
0831ad04 GKH |
379 | /** |
380 | * HvSynicInit - Initialize the Synthethic Interrupt Controller. | |
381 | * | |
382 | * If it is already initialized by another entity (ie x2v shim), we need to | |
383 | * retrieve the initialized message and event pages. Otherwise, we create and | |
384 | * initialize the message and event pages. | |
385 | */ | |
7692fd4d | 386 | void HvSynicInit(void *irqarg) |
3e7ee490 | 387 | { |
0831ad04 | 388 | u64 version; |
eacb1b4d GKH |
389 | union hv_synic_simp simp; |
390 | union hv_synic_siefp siefp; | |
391 | union hv_synic_sint sharedSint; | |
392 | union hv_synic_scontrol sctrl; | |
a73e6b7c | 393 | |
7692fd4d GKH |
394 | u32 irqVector = *((u32 *)(irqarg)); |
395 | int cpu = smp_processor_id(); | |
3e7ee490 HJ |
396 | |
397 | DPRINT_ENTER(VMBUS); | |
398 | ||
0831ad04 | 399 | if (!gHvContext.HypercallPage) { |
3e7ee490 | 400 | DPRINT_EXIT(VMBUS); |
7692fd4d | 401 | return; |
3e7ee490 HJ |
402 | } |
403 | ||
454f18a9 | 404 | /* Check the version */ |
a51ed7d6 | 405 | rdmsrl(HV_X64_MSR_SVERSION, version); |
3e7ee490 HJ |
406 | |
407 | DPRINT_INFO(VMBUS, "SynIC version: %llx", version); | |
408 | ||
a73e6b7c | 409 | gHvContext.synICMessagePage[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); |
3e7ee490 | 410 | |
a73e6b7c HJ |
411 | if (gHvContext.synICMessagePage[cpu] == NULL) { |
412 | DPRINT_ERR(VMBUS, | |
413 | "unable to allocate SYNIC message page!!"); | |
414 | goto Cleanup; | |
415 | } | |
3e7ee490 | 416 | |
a73e6b7c | 417 | gHvContext.synICEventPage[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); |
3e7ee490 | 418 | |
a73e6b7c HJ |
419 | if (gHvContext.synICEventPage[cpu] == NULL) { |
420 | DPRINT_ERR(VMBUS, | |
421 | "unable to allocate SYNIC event page!!"); | |
422 | goto Cleanup; | |
423 | } | |
3e7ee490 | 424 | |
a73e6b7c HJ |
425 | /* Setup the Synic's message page */ |
426 | rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); | |
427 | simp.SimpEnabled = 1; | |
428 | simp.BaseSimpGpa = virt_to_phys(gHvContext.synICMessagePage[cpu]) | |
429 | >> PAGE_SHIFT; | |
3e7ee490 | 430 | |
a73e6b7c | 431 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.AsUINT64); |
3e7ee490 | 432 | |
a73e6b7c | 433 | wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
3e7ee490 | 434 | |
a73e6b7c HJ |
435 | /* Setup the Synic's event page */ |
436 | rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); | |
437 | siefp.SiefpEnabled = 1; | |
438 | siefp.BaseSiefpGpa = virt_to_phys(gHvContext.synICEventPage[cpu]) | |
439 | >> PAGE_SHIFT; | |
440 | ||
441 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.AsUINT64); | |
442 | ||
443 | wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); | |
0831ad04 GKH |
444 | |
445 | /* Setup the interception SINT. */ | |
a51ed7d6 | 446 | /* wrmsrl((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX), */ |
0831ad04 | 447 | /* interceptionSint.AsUINT64); */ |
454f18a9 | 448 | |
0831ad04 | 449 | /* Setup the shared SINT. */ |
a51ed7d6 | 450 | rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
3e7ee490 HJ |
451 | |
452 | sharedSint.AsUINT64 = 0; | |
454f18a9 BP |
453 | sharedSint.Vector = irqVector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ |
454 | sharedSint.Masked = false; | |
455 | sharedSint.AutoEoi = true; | |
3e7ee490 | 456 | |
0831ad04 GKH |
457 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", |
458 | sharedSint.AsUINT64); | |
3e7ee490 | 459 | |
a51ed7d6 | 460 | wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
3e7ee490 | 461 | |
454f18a9 | 462 | /* Enable the global synic bit */ |
a51ed7d6 | 463 | rdmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); |
3e7ee490 HJ |
464 | sctrl.Enable = 1; |
465 | ||
a51ed7d6 | 466 | wrmsrl(HV_X64_MSR_SCONTROL, sctrl.AsUINT64); |
3e7ee490 | 467 | |
0e727613 | 468 | gHvContext.SynICInitialized = true; |
3e7ee490 HJ |
469 | |
470 | DPRINT_EXIT(VMBUS); | |
471 | ||
7692fd4d | 472 | return; |
3e7ee490 HJ |
473 | |
474 | Cleanup: | |
a73e6b7c HJ |
475 | if (gHvContext.synICEventPage[cpu]) |
476 | osd_PageFree(gHvContext.synICEventPage[cpu], 1); | |
3e7ee490 | 477 | |
a73e6b7c HJ |
478 | if (gHvContext.synICMessagePage[cpu]) |
479 | osd_PageFree(gHvContext.synICMessagePage[cpu], 1); | |
3e7ee490 HJ |
480 | |
481 | DPRINT_EXIT(VMBUS); | |
7692fd4d | 482 | return; |
3e7ee490 HJ |
483 | } |
484 | ||
0831ad04 GKH |
485 | /** |
486 | * HvSynicCleanup - Cleanup routine for HvSynicInit(). | |
487 | */ | |
7692fd4d | 488 | void HvSynicCleanup(void *arg) |
3e7ee490 | 489 | { |
eacb1b4d GKH |
490 | union hv_synic_sint sharedSint; |
491 | union hv_synic_simp simp; | |
492 | union hv_synic_siefp siefp; | |
7692fd4d | 493 | int cpu = smp_processor_id(); |
3e7ee490 HJ |
494 | |
495 | DPRINT_ENTER(VMBUS); | |
496 | ||
0831ad04 | 497 | if (!gHvContext.SynICInitialized) { |
3e7ee490 HJ |
498 | DPRINT_EXIT(VMBUS); |
499 | return; | |
500 | } | |
501 | ||
a51ed7d6 | 502 | rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
3e7ee490 HJ |
503 | |
504 | sharedSint.Masked = 1; | |
505 | ||
7692fd4d | 506 | /* Need to correctly cleanup in the case of SMP!!! */ |
454f18a9 | 507 | /* Disable the interrupt */ |
a51ed7d6 | 508 | wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, sharedSint.AsUINT64); |
3e7ee490 | 509 | |
a73e6b7c HJ |
510 | rdmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
511 | simp.SimpEnabled = 0; | |
512 | simp.BaseSimpGpa = 0; | |
3e7ee490 | 513 | |
a73e6b7c | 514 | wrmsrl(HV_X64_MSR_SIMP, simp.AsUINT64); |
3e7ee490 | 515 | |
a73e6b7c HJ |
516 | rdmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); |
517 | siefp.SiefpEnabled = 0; | |
518 | siefp.BaseSiefpGpa = 0; | |
3e7ee490 | 519 | |
a73e6b7c | 520 | wrmsrl(HV_X64_MSR_SIEFP, siefp.AsUINT64); |
3e7ee490 | 521 | |
a73e6b7c HJ |
522 | osd_PageFree(gHvContext.synICMessagePage[cpu], 1); |
523 | osd_PageFree(gHvContext.synICEventPage[cpu], 1); | |
3e7ee490 HJ |
524 | |
525 | DPRINT_EXIT(VMBUS); | |
526 | } |