]>
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> |
e3fe0bb6 | 26 | #include "hv_api.h" |
645954c5 | 27 | #include "logging.h" |
72daf320 | 28 | #include "vmbus_private.h" |
3e7ee490 | 29 | |
454f18a9 | 30 | /* The one and only */ |
6a0aaa18 HZ |
31 | struct hv_context hv_context = { |
32 | .synic_initialized = false, | |
33 | .hypercall_page = NULL, | |
34 | .signal_event_param = NULL, | |
35 | .signal_event_buffer = NULL, | |
3e7ee490 HJ |
36 | }; |
37 | ||
3e189519 | 38 | /* |
d44890c8 | 39 | * query_hypervisor_presence |
25985edc | 40 | * - Query the cpuid for presence of windows hypervisor |
0831ad04 | 41 | */ |
d44890c8 | 42 | static int query_hypervisor_presence(void) |
3e7ee490 | 43 | { |
0831ad04 GKH |
44 | unsigned int eax; |
45 | unsigned int ebx; | |
46 | unsigned int ecx; | |
47 | unsigned int edx; | |
48 | unsigned int op; | |
3e7ee490 | 49 | |
454f18a9 BP |
50 | eax = 0; |
51 | ebx = 0; | |
52 | ecx = 0; | |
53 | edx = 0; | |
f6feebe0 | 54 | op = HVCPUID_VERSION_FEATURES; |
f931a70c | 55 | cpuid(op, &eax, &ebx, &ecx, &edx); |
0831ad04 GKH |
56 | |
57 | return ecx & HV_PRESENT_BIT; | |
3e7ee490 HJ |
58 | } |
59 | ||
3e189519 | 60 | /* |
d44890c8 | 61 | * query_hypervisor_info - Get version info of the windows hypervisor |
0831ad04 | 62 | */ |
d44890c8 | 63 | static int query_hypervisor_info(void) |
0831ad04 GKH |
64 | { |
65 | unsigned int eax; | |
66 | unsigned int ebx; | |
67 | unsigned int ecx; | |
68 | unsigned int edx; | |
b8dfb264 | 69 | unsigned int max_leaf; |
0831ad04 | 70 | unsigned int op; |
3e7ee490 | 71 | |
0831ad04 GKH |
72 | /* |
73 | * Its assumed that this is called after confirming that Viridian | |
74 | * is present. Query id and revision. | |
75 | */ | |
76 | eax = 0; | |
77 | ebx = 0; | |
78 | ecx = 0; | |
79 | edx = 0; | |
f6feebe0 | 80 | op = HVCPUID_VENDOR_MAXFUNCTION; |
0831ad04 | 81 | cpuid(op, &eax, &ebx, &ecx, &edx); |
3e7ee490 | 82 | |
0831ad04 GKH |
83 | DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", |
84 | (ebx & 0xFF), | |
85 | ((ebx >> 8) & 0xFF), | |
86 | ((ebx >> 16) & 0xFF), | |
87 | ((ebx >> 24) & 0xFF), | |
88 | (ecx & 0xFF), | |
89 | ((ecx >> 8) & 0xFF), | |
90 | ((ecx >> 16) & 0xFF), | |
91 | ((ecx >> 24) & 0xFF), | |
92 | (edx & 0xFF), | |
93 | ((edx >> 8) & 0xFF), | |
94 | ((edx >> 16) & 0xFF), | |
95 | ((edx >> 24) & 0xFF)); | |
96 | ||
b8dfb264 | 97 | max_leaf = eax; |
0831ad04 GKH |
98 | eax = 0; |
99 | ebx = 0; | |
100 | ecx = 0; | |
101 | edx = 0; | |
f6feebe0 | 102 | op = HVCPUID_INTERFACE; |
0831ad04 | 103 | cpuid(op, &eax, &ebx, &ecx, &edx); |
3e7ee490 | 104 | |
0831ad04 GKH |
105 | DPRINT_INFO(VMBUS, "Interface ID: %c%c%c%c", |
106 | (eax & 0xFF), | |
107 | ((eax >> 8) & 0xFF), | |
108 | ((eax >> 16) & 0xFF), | |
109 | ((eax >> 24) & 0xFF)); | |
110 | ||
b8dfb264 | 111 | if (max_leaf >= HVCPUID_VERSION) { |
0831ad04 GKH |
112 | eax = 0; |
113 | ebx = 0; | |
114 | ecx = 0; | |
115 | edx = 0; | |
f6feebe0 | 116 | op = HVCPUID_VERSION; |
0831ad04 GKH |
117 | cpuid(op, &eax, &ebx, &ecx, &edx); |
118 | DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",\ | |
119 | eax, | |
120 | ebx >> 16, | |
121 | ebx & 0xFFFF, | |
122 | ecx, | |
123 | edx >> 24, | |
124 | edx & 0xFFFFFF); | |
125 | } | |
b8dfb264 | 126 | return max_leaf; |
0831ad04 | 127 | } |
3e7ee490 | 128 | |
3e189519 | 129 | /* |
d44890c8 | 130 | * do_hypercall- Invoke the specified hypercall |
0831ad04 | 131 | */ |
d44890c8 | 132 | static u64 do_hypercall(u64 control, void *input, void *output) |
3e7ee490 | 133 | { |
530cf207 | 134 | #ifdef CONFIG_X86_64 |
b8dfb264 HZ |
135 | u64 hv_status = 0; |
136 | u64 input_address = (input) ? virt_to_phys(input) : 0; | |
137 | u64 output_address = (output) ? virt_to_phys(output) : 0; | |
138 | volatile void *hypercall_page = hv_context.hypercall_page; | |
3e7ee490 | 139 | |
0831ad04 GKH |
140 | DPRINT_DBG(VMBUS, "Hypercall <control %llx input phys %llx virt %p " |
141 | "output phys %llx virt %p hypercall %p>", | |
b8dfb264 HZ |
142 | control, input_address, input, |
143 | output_address, output, hypercall_page); | |
3e7ee490 | 144 | |
b8dfb264 HZ |
145 | __asm__ __volatile__("mov %0, %%r8" : : "r" (output_address) : "r8"); |
146 | __asm__ __volatile__("call *%3" : "=a" (hv_status) : | |
147 | "c" (control), "d" (input_address), | |
148 | "m" (hypercall_page)); | |
3e7ee490 | 149 | |
b8dfb264 | 150 | DPRINT_DBG(VMBUS, "Hypercall <return %llx>", hv_status); |
3e7ee490 | 151 | |
b8dfb264 | 152 | return hv_status; |
3e7ee490 HJ |
153 | |
154 | #else | |
155 | ||
b8dfb264 HZ |
156 | u32 control_hi = control >> 32; |
157 | u32 control_lo = control & 0xFFFFFFFF; | |
158 | u32 hv_status_hi = 1; | |
159 | u32 hv_status_lo = 1; | |
160 | u64 input_address = (input) ? virt_to_phys(input) : 0; | |
161 | u32 input_address_hi = input_address >> 32; | |
162 | u32 input_address_lo = input_address & 0xFFFFFFFF; | |
163 | u64 output_address = (output) ? virt_to_phys(output) : 0; | |
164 | u32 output_address_hi = output_address >> 32; | |
165 | u32 output_address_lo = output_address & 0xFFFFFFFF; | |
166 | volatile void *hypercall_page = hv_context.hypercall_page; | |
3e7ee490 | 167 | |
0831ad04 | 168 | DPRINT_DBG(VMBUS, "Hypercall <control %llx input %p output %p>", |
b8dfb264 | 169 | control, input, output); |
3e7ee490 | 170 | |
b8dfb264 HZ |
171 | __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi), |
172 | "=a"(hv_status_lo) : "d" (control_hi), | |
173 | "a" (control_lo), "b" (input_address_hi), | |
174 | "c" (input_address_lo), "D"(output_address_hi), | |
175 | "S"(output_address_lo), "m" (hypercall_page)); | |
3e7ee490 | 176 | |
0831ad04 | 177 | DPRINT_DBG(VMBUS, "Hypercall <return %llx>", |
b8dfb264 | 178 | hv_status_lo | ((u64)hv_status_hi << 32)); |
3e7ee490 | 179 | |
b8dfb264 | 180 | return hv_status_lo | ((u64)hv_status_hi << 32); |
0831ad04 | 181 | #endif /* !x86_64 */ |
3e7ee490 HJ |
182 | } |
183 | ||
3e189519 | 184 | /* |
d44890c8 | 185 | * hv_init - Main initialization routine. |
0831ad04 GKH |
186 | * |
187 | * This routine must be called before any other routines in here are called | |
188 | */ | |
d44890c8 | 189 | int hv_init(void) |
3e7ee490 | 190 | { |
0831ad04 | 191 | int ret = 0; |
b8dfb264 HZ |
192 | int max_leaf; |
193 | union hv_x64_msr_hypercall_contents hypercall_msr; | |
194 | void *virtaddr = NULL; | |
3e7ee490 | 195 | |
6a0aaa18 HZ |
196 | memset(hv_context.synic_event_page, 0, sizeof(void *) * MAX_NUM_CPUS); |
197 | memset(hv_context.synic_message_page, 0, | |
198 | sizeof(void *) * MAX_NUM_CPUS); | |
3e7ee490 | 199 | |
d44890c8 | 200 | if (!query_hypervisor_presence()) { |
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 | |
d44890c8 | 208 | max_leaf = query_hypervisor_info(); |
0831ad04 | 209 | /* HvQueryHypervisorFeatures(maxLeaf); */ |
3e7ee490 | 210 | |
0831ad04 | 211 | /* |
a73e6b7c | 212 | * We only support running on top of Hyper-V |
0831ad04 | 213 | */ |
6a0aaa18 | 214 | rdmsrl(HV_X64_MSR_GUEST_OS_ID, hv_context.guestid); |
a73e6b7c | 215 | |
6a0aaa18 | 216 | if (hv_context.guestid != 0) { |
a73e6b7c | 217 | DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", |
6a0aaa18 | 218 | hv_context.guestid); |
a73e6b7c | 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); | |
6a0aaa18 | 224 | hv_context.guestid = HV_LINUX_GUEST_ID; |
a73e6b7c | 225 | |
454f18a9 | 226 | /* See if the hypercall page is already set */ |
b8dfb264 | 227 | rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); |
3e7ee490 | 228 | |
a73e6b7c HJ |
229 | /* |
230 | * Allocate the hypercall page memory | |
203df82d | 231 | * virtaddr = osd_page_alloc(1); |
a73e6b7c | 232 | */ |
df3493e0 | 233 | virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC); |
3e7ee490 | 234 | |
b8dfb264 | 235 | if (!virtaddr) { |
a73e6b7c HJ |
236 | DPRINT_ERR(VMBUS, |
237 | "unable to allocate hypercall page!!"); | |
238 | goto Cleanup; | |
239 | } | |
3e7ee490 | 240 | |
b8dfb264 | 241 | hypercall_msr.enable = 1; |
a73e6b7c | 242 | |
b8dfb264 HZ |
243 | hypercall_msr.guest_physical_address = vmalloc_to_pfn(virtaddr); |
244 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); | |
a73e6b7c HJ |
245 | |
246 | /* Confirm that hypercall page did get setup. */ | |
b8dfb264 HZ |
247 | hypercall_msr.as_uint64 = 0; |
248 | rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); | |
a73e6b7c | 249 | |
b8dfb264 | 250 | if (!hypercall_msr.enable) { |
a73e6b7c | 251 | DPRINT_ERR(VMBUS, "unable to set hypercall page!!"); |
3e7ee490 HJ |
252 | goto Cleanup; |
253 | } | |
254 | ||
b8dfb264 | 255 | hv_context.hypercall_page = virtaddr; |
a73e6b7c | 256 | |
2701f686 | 257 | DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx", |
6a0aaa18 | 258 | hv_context.hypercall_page, |
b8dfb264 | 259 | (u64)hypercall_msr.guest_physical_address << PAGE_SHIFT); |
3e7ee490 | 260 | |
454f18a9 | 261 | /* Setup the global signal event param for the signal event hypercall */ |
6a0aaa18 | 262 | hv_context.signal_event_buffer = |
0831ad04 GKH |
263 | kmalloc(sizeof(struct hv_input_signal_event_buffer), |
264 | GFP_KERNEL); | |
6a0aaa18 | 265 | if (!hv_context.signal_event_buffer) |
3e7ee490 | 266 | goto Cleanup; |
3e7ee490 | 267 | |
6a0aaa18 | 268 | hv_context.signal_event_param = |
0831ad04 | 269 | (struct hv_input_signal_event *) |
73509681 | 270 | (ALIGN((unsigned long) |
6a0aaa18 | 271 | hv_context.signal_event_buffer, |
0831ad04 | 272 | HV_HYPERCALL_PARAM_ALIGN)); |
6a0aaa18 HZ |
273 | hv_context.signal_event_param->connectionid.asu32 = 0; |
274 | hv_context.signal_event_param->connectionid.u.id = | |
0831ad04 | 275 | VMBUS_EVENT_CONNECTION_ID; |
6a0aaa18 HZ |
276 | hv_context.signal_event_param->flag_number = 0; |
277 | hv_context.signal_event_param->rsvdz = 0; | |
3e7ee490 | 278 | |
0831ad04 | 279 | return ret; |
3e7ee490 HJ |
280 | |
281 | Cleanup: | |
b8dfb264 HZ |
282 | if (virtaddr) { |
283 | if (hypercall_msr.enable) { | |
284 | hypercall_msr.as_uint64 = 0; | |
285 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); | |
3e7ee490 HJ |
286 | } |
287 | ||
b8dfb264 | 288 | vfree(virtaddr); |
3e7ee490 HJ |
289 | } |
290 | ret = -1; | |
3e7ee490 HJ |
291 | return ret; |
292 | } | |
293 | ||
3e189519 | 294 | /* |
d44890c8 | 295 | * hv_cleanup - Cleanup routine. |
0831ad04 GKH |
296 | * |
297 | * This routine is called normally during driver unloading or exiting. | |
298 | */ | |
d44890c8 | 299 | void hv_cleanup(void) |
3e7ee490 | 300 | { |
b8dfb264 | 301 | union hv_x64_msr_hypercall_contents hypercall_msr; |
3e7ee490 | 302 | |
6a0aaa18 HZ |
303 | kfree(hv_context.signal_event_buffer); |
304 | hv_context.signal_event_buffer = NULL; | |
305 | hv_context.signal_event_param = NULL; | |
3e7ee490 | 306 | |
6a0aaa18 | 307 | if (hv_context.hypercall_page) { |
b8dfb264 HZ |
308 | hypercall_msr.as_uint64 = 0; |
309 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); | |
6a0aaa18 HZ |
310 | vfree(hv_context.hypercall_page); |
311 | hv_context.hypercall_page = NULL; | |
3e7ee490 | 312 | } |
3e7ee490 HJ |
313 | } |
314 | ||
3e189519 | 315 | /* |
d44890c8 | 316 | * hv_post_message - Post a message using the hypervisor message IPC. |
0831ad04 GKH |
317 | * |
318 | * This involves a hypercall. | |
319 | */ | |
d44890c8 | 320 | u16 hv_post_message(union hv_connection_id connection_id, |
b8dfb264 HZ |
321 | enum hv_message_type message_type, |
322 | void *payload, size_t payload_size) | |
3e7ee490 | 323 | { |
b8dfb264 | 324 | struct aligned_input { |
0831ad04 | 325 | u64 alignment8; |
cba4decd | 326 | struct hv_input_post_message msg; |
3e7ee490 HJ |
327 | }; |
328 | ||
b8dfb264 | 329 | struct hv_input_post_message *aligned_msg; |
034469e6 | 330 | u16 status; |
c4b0bc94 | 331 | unsigned long addr; |
3e7ee490 | 332 | |
b8dfb264 | 333 | if (payload_size > HV_MESSAGE_PAYLOAD_BYTE_COUNT) |
3e7ee490 | 334 | return -1; |
3e7ee490 | 335 | |
b8dfb264 | 336 | addr = (unsigned long)kmalloc(sizeof(struct aligned_input), GFP_ATOMIC); |
3e7ee490 | 337 | if (!addr) |
3e7ee490 | 338 | return -1; |
3e7ee490 | 339 | |
b8dfb264 | 340 | aligned_msg = (struct hv_input_post_message *) |
73509681 | 341 | (ALIGN(addr, HV_HYPERCALL_PARAM_ALIGN)); |
3e7ee490 | 342 | |
b8dfb264 HZ |
343 | aligned_msg->connectionid = connection_id; |
344 | aligned_msg->message_type = message_type; | |
345 | aligned_msg->payload_size = payload_size; | |
346 | memcpy((void *)aligned_msg->payload, payload, payload_size); | |
3e7ee490 | 347 | |
d44890c8 HZ |
348 | status = do_hypercall(HVCALL_POST_MESSAGE, aligned_msg, NULL) |
349 | & 0xFFFF; | |
3e7ee490 | 350 | |
0831ad04 | 351 | kfree((void *)addr); |
3e7ee490 HJ |
352 | |
353 | return status; | |
354 | } | |
355 | ||
356 | ||
3e189519 | 357 | /* |
d44890c8 HZ |
358 | * hv_signal_event - |
359 | * Signal an event on the specified connection using the hypervisor event IPC. | |
0831ad04 GKH |
360 | * |
361 | * This involves a hypercall. | |
362 | */ | |
d44890c8 | 363 | u16 hv_signal_event(void) |
3e7ee490 | 364 | { |
034469e6 | 365 | u16 status; |
3e7ee490 | 366 | |
d44890c8 | 367 | status = do_hypercall(HVCALL_SIGNAL_EVENT, |
6a0aaa18 | 368 | hv_context.signal_event_param, |
0831ad04 | 369 | NULL) & 0xFFFF; |
3e7ee490 HJ |
370 | return status; |
371 | } | |
372 | ||
3e189519 | 373 | /* |
d44890c8 | 374 | * hv_synic_init - Initialize the Synthethic Interrupt Controller. |
0831ad04 GKH |
375 | * |
376 | * If it is already initialized by another entity (ie x2v shim), we need to | |
377 | * retrieve the initialized message and event pages. Otherwise, we create and | |
378 | * initialize the message and event pages. | |
379 | */ | |
d44890c8 | 380 | void hv_synic_init(void *irqarg) |
3e7ee490 | 381 | { |
0831ad04 | 382 | u64 version; |
eacb1b4d GKH |
383 | union hv_synic_simp simp; |
384 | union hv_synic_siefp siefp; | |
b8dfb264 | 385 | union hv_synic_sint shared_sint; |
eacb1b4d | 386 | union hv_synic_scontrol sctrl; |
a73e6b7c | 387 | |
b8dfb264 | 388 | u32 irq_vector = *((u32 *)(irqarg)); |
7692fd4d | 389 | int cpu = smp_processor_id(); |
3e7ee490 | 390 | |
6a0aaa18 | 391 | if (!hv_context.hypercall_page) |
7692fd4d | 392 | return; |
3e7ee490 | 393 | |
454f18a9 | 394 | /* Check the version */ |
a51ed7d6 | 395 | rdmsrl(HV_X64_MSR_SVERSION, version); |
3e7ee490 HJ |
396 | |
397 | DPRINT_INFO(VMBUS, "SynIC version: %llx", version); | |
398 | ||
6a0aaa18 HZ |
399 | hv_context.synic_message_page[cpu] = |
400 | (void *)get_zeroed_page(GFP_ATOMIC); | |
3e7ee490 | 401 | |
6a0aaa18 | 402 | if (hv_context.synic_message_page[cpu] == NULL) { |
a73e6b7c HJ |
403 | DPRINT_ERR(VMBUS, |
404 | "unable to allocate SYNIC message page!!"); | |
405 | goto Cleanup; | |
406 | } | |
3e7ee490 | 407 | |
6a0aaa18 HZ |
408 | hv_context.synic_event_page[cpu] = |
409 | (void *)get_zeroed_page(GFP_ATOMIC); | |
3e7ee490 | 410 | |
6a0aaa18 | 411 | if (hv_context.synic_event_page[cpu] == NULL) { |
a73e6b7c HJ |
412 | DPRINT_ERR(VMBUS, |
413 | "unable to allocate SYNIC event page!!"); | |
414 | goto Cleanup; | |
415 | } | |
3e7ee490 | 416 | |
a73e6b7c | 417 | /* Setup the Synic's message page */ |
f6feebe0 HZ |
418 | rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64); |
419 | simp.simp_enabled = 1; | |
6a0aaa18 | 420 | simp.base_simp_gpa = virt_to_phys(hv_context.synic_message_page[cpu]) |
a73e6b7c | 421 | >> PAGE_SHIFT; |
3e7ee490 | 422 | |
f6feebe0 | 423 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.as_uint64); |
3e7ee490 | 424 | |
f6feebe0 | 425 | wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64); |
3e7ee490 | 426 | |
a73e6b7c | 427 | /* Setup the Synic's event page */ |
f6feebe0 HZ |
428 | rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); |
429 | siefp.siefp_enabled = 1; | |
6a0aaa18 | 430 | siefp.base_siefp_gpa = virt_to_phys(hv_context.synic_event_page[cpu]) |
a73e6b7c HJ |
431 | >> PAGE_SHIFT; |
432 | ||
f6feebe0 | 433 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.as_uint64); |
a73e6b7c | 434 | |
f6feebe0 | 435 | wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); |
0831ad04 GKH |
436 | |
437 | /* Setup the interception SINT. */ | |
a51ed7d6 | 438 | /* wrmsrl((HV_X64_MSR_SINT0 + HV_SYNIC_INTERCEPTION_SINT_INDEX), */ |
f6feebe0 | 439 | /* interceptionSint.as_uint64); */ |
454f18a9 | 440 | |
0831ad04 | 441 | /* Setup the shared SINT. */ |
b8dfb264 | 442 | rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
3e7ee490 | 443 | |
b8dfb264 HZ |
444 | shared_sint.as_uint64 = 0; |
445 | shared_sint.vector = irq_vector; /* HV_SHARED_SINT_IDT_VECTOR + 0x20; */ | |
446 | shared_sint.masked = false; | |
447 | shared_sint.auto_eoi = true; | |
3e7ee490 | 448 | |
0831ad04 | 449 | DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", |
b8dfb264 | 450 | shared_sint.as_uint64); |
3e7ee490 | 451 | |
b8dfb264 | 452 | wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
3e7ee490 | 453 | |
454f18a9 | 454 | /* Enable the global synic bit */ |
f6feebe0 HZ |
455 | rdmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); |
456 | sctrl.enable = 1; | |
3e7ee490 | 457 | |
f6feebe0 | 458 | wrmsrl(HV_X64_MSR_SCONTROL, sctrl.as_uint64); |
3e7ee490 | 459 | |
6a0aaa18 | 460 | hv_context.synic_initialized = true; |
7692fd4d | 461 | return; |
3e7ee490 HJ |
462 | |
463 | Cleanup: | |
6a0aaa18 | 464 | if (hv_context.synic_event_page[cpu]) |
df3493e0 | 465 | free_page((unsigned long)hv_context.synic_event_page[cpu]); |
3e7ee490 | 466 | |
6a0aaa18 | 467 | if (hv_context.synic_message_page[cpu]) |
df3493e0 | 468 | free_page((unsigned long)hv_context.synic_message_page[cpu]); |
7692fd4d | 469 | return; |
3e7ee490 HJ |
470 | } |
471 | ||
3e189519 | 472 | /* |
d44890c8 | 473 | * hv_synic_cleanup - Cleanup routine for hv_synic_init(). |
0831ad04 | 474 | */ |
d44890c8 | 475 | void hv_synic_cleanup(void *arg) |
3e7ee490 | 476 | { |
b8dfb264 | 477 | union hv_synic_sint shared_sint; |
eacb1b4d GKH |
478 | union hv_synic_simp simp; |
479 | union hv_synic_siefp siefp; | |
7692fd4d | 480 | int cpu = smp_processor_id(); |
3e7ee490 | 481 | |
6a0aaa18 | 482 | if (!hv_context.synic_initialized) |
3e7ee490 | 483 | return; |
3e7ee490 | 484 | |
b8dfb264 | 485 | rdmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
3e7ee490 | 486 | |
b8dfb264 | 487 | shared_sint.masked = 1; |
3e7ee490 | 488 | |
7692fd4d | 489 | /* Need to correctly cleanup in the case of SMP!!! */ |
454f18a9 | 490 | /* Disable the interrupt */ |
b8dfb264 | 491 | wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); |
3e7ee490 | 492 | |
f6feebe0 HZ |
493 | rdmsrl(HV_X64_MSR_SIMP, simp.as_uint64); |
494 | simp.simp_enabled = 0; | |
495 | simp.base_simp_gpa = 0; | |
3e7ee490 | 496 | |
f6feebe0 | 497 | wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64); |
3e7ee490 | 498 | |
f6feebe0 HZ |
499 | rdmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); |
500 | siefp.siefp_enabled = 0; | |
501 | siefp.base_siefp_gpa = 0; | |
3e7ee490 | 502 | |
f6feebe0 | 503 | wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); |
3e7ee490 | 504 | |
df3493e0 S |
505 | free_page((unsigned long)hv_context.synic_message_page[cpu]); |
506 | free_page((unsigned long)hv_context.synic_event_page[cpu]); | |
3e7ee490 | 507 | } |