1 /*- SPDX-License-Identifier: BSD-2-Clause-FreeBSD 2 * Copyright (c) 2009-2012,2016-2017, 2022 Microsoft Corp. 3 * Copyright (c) 2012 NetApp Inc. 4 * Copyright (c) 2012 Citrix Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice unmodified, this list of conditions, and the following 12 * disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * Implements low-level interactions with Hyper-V/Azure 31 */ 32 33 #include <sys/cdefs.h> 34 __FBSDID("$FreeBSD$"); 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/kernel.h> 39 #include <sys/malloc.h> 40 #include <sys/timetc.h> 41 42 #include <vm/vm.h> 43 #include <vm/pmap.h> 44 #include <vm/vm_extern.h> 45 #include <vm/vm_kern.h> 46 47 #include <dev/hyperv/include/hyperv.h> 48 #include <dev/hyperv/include/hyperv_busdma.h> 49 #include <dev/hyperv/vmbus/aarch64/hyperv_machdep.h> 50 #include <dev/hyperv/vmbus/aarch64/hyperv_reg.h> 51 #include <dev/hyperv/vmbus/hyperv_var.h> 52 #include <dev/hyperv/vmbus/hyperv_common_reg.h> 53 54 void hyperv_init_tc(void); 55 int hypercall_page_setup(vm_paddr_t); 56 void hypercall_disable(void); 57 bool hyperv_identify_features(void); 58 59 u_int hyperv_ver_major; 60 u_int hyperv_features; 61 u_int hyperv_recommends; 62 63 hyperv_tc64_t hyperv_tc64; 64 65 void 66 hyperv_init_tc(void) 67 { 68 hyperv_tc64 = NULL; 69 } 70 71 int 72 hypercall_page_setup(vm_paddr_t hc) 73 { 74 return (0); 75 } 76 77 void 78 hypercall_disable(void) 79 { 80 return; 81 } 82 83 bool 84 hyperv_identify_features(void) 85 { 86 struct hv_get_vp_registers_output result; 87 vm_guest = VM_GUEST_HV; 88 89 hv_get_vpreg_128(CPUID_LEAF_HV_FEATURES, &result); 90 hyperv_features = result.as32.a; 91 hv_get_vpreg_128(CPUID_LEAF_HV_IDENTITY, &result); 92 hyperv_ver_major = result.as32.b >> 16; 93 hv_get_vpreg_128(CPUID_LEAF_HV_RECOMMENDS, &result); 94 hyperv_recommends = result.as32.a; 95 return (true); 96 } 97