K. Y. Srinivasan | 8730046 | 2017-01-18 16:45:02 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * X86 specific Hyper-V initialization code. |
| 3 | * |
| 4 | * Copyright (C) 2016, Microsoft, Inc. |
| 5 | * |
| 6 | * Author : K. Y. Srinivasan <kys@microsoft.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License version 2 as published |
| 10 | * by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or |
| 15 | * NON INFRINGEMENT. See the GNU General Public License for more |
| 16 | * details. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #include <linux/types.h> |
| 21 | #include <asm/hypervisor.h> |
| 22 | #include <asm/hyperv.h> |
| 23 | #include <asm/mshyperv.h> |
| 24 | #include <linux/version.h> |
| 25 | #include <linux/vmalloc.h> |
| 26 | #include <linux/mm.h> |
| 27 | |
| 28 | void *hv_hypercall_pg; |
| 29 | /* |
| 30 | * This function is to be invoked early in the boot sequence after the |
| 31 | * hypervisor has been detected. |
| 32 | * |
| 33 | * 1. Setup the hypercall page. |
| 34 | */ |
| 35 | void hyperv_init(void) |
| 36 | { |
| 37 | u64 guest_id; |
| 38 | union hv_x64_msr_hypercall_contents hypercall_msr; |
| 39 | |
| 40 | if (x86_hyper != &x86_hyper_ms_hyperv) |
| 41 | return; |
| 42 | |
| 43 | /* |
| 44 | * Setup the hypercall page and enable hypercalls. |
| 45 | * 1. Register the guest ID |
| 46 | * 2. Enable the hypercall and register the hypercall page |
| 47 | */ |
| 48 | guest_id = generate_guest_id(0, LINUX_VERSION_CODE, 0); |
| 49 | wrmsrl(HV_X64_MSR_GUEST_OS_ID, guest_id); |
| 50 | |
| 51 | hv_hypercall_pg = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC); |
| 52 | if (hv_hypercall_pg == NULL) { |
| 53 | wrmsrl(HV_X64_MSR_GUEST_OS_ID, 0); |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); |
| 58 | hypercall_msr.enable = 1; |
| 59 | hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); |
| 60 | wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); |
| 61 | } |
| 62 | EXPORT_SYMBOL_GPL(hv_hypercall_pg); |