1e8f3d23cSVitaly Kuznetsov // SPDX-License-Identifier: GPL-2.0-only
2e8f3d23cSVitaly Kuznetsov /*
3e8f3d23cSVitaly Kuznetsov * Hyper-V specific functions.
4e8f3d23cSVitaly Kuznetsov *
5e8f3d23cSVitaly Kuznetsov * Copyright (C) 2021, Red Hat Inc.
6e8f3d23cSVitaly Kuznetsov */
7e8f3d23cSVitaly Kuznetsov #include <stdint.h>
8e8f3d23cSVitaly Kuznetsov #include "processor.h"
9e8f3d23cSVitaly Kuznetsov #include "hyperv.h"
10e8f3d23cSVitaly Kuznetsov
vcpu_alloc_hyperv_test_pages(struct kvm_vm * vm,vm_vaddr_t * p_hv_pages_gva)112dc458b8SVitaly Kuznetsov struct hyperv_test_pages *vcpu_alloc_hyperv_test_pages(struct kvm_vm *vm,
122dc458b8SVitaly Kuznetsov vm_vaddr_t *p_hv_pages_gva)
132dc458b8SVitaly Kuznetsov {
142dc458b8SVitaly Kuznetsov vm_vaddr_t hv_pages_gva = vm_vaddr_alloc_page(vm);
152dc458b8SVitaly Kuznetsov struct hyperv_test_pages *hv = addr_gva2hva(vm, hv_pages_gva);
162dc458b8SVitaly Kuznetsov
172dc458b8SVitaly Kuznetsov /* Setup of a region of guest memory for the VP Assist page. */
182dc458b8SVitaly Kuznetsov hv->vp_assist = (void *)vm_vaddr_alloc_page(vm);
192dc458b8SVitaly Kuznetsov hv->vp_assist_hva = addr_gva2hva(vm, (uintptr_t)hv->vp_assist);
202dc458b8SVitaly Kuznetsov hv->vp_assist_gpa = addr_gva2gpa(vm, (uintptr_t)hv->vp_assist);
212dc458b8SVitaly Kuznetsov
22*6c15c3c4SVitaly Kuznetsov /* Setup of a region of guest memory for the partition assist page. */
23*6c15c3c4SVitaly Kuznetsov hv->partition_assist = (void *)vm_vaddr_alloc_page(vm);
24*6c15c3c4SVitaly Kuznetsov hv->partition_assist_hva = addr_gva2hva(vm, (uintptr_t)hv->partition_assist);
25*6c15c3c4SVitaly Kuznetsov hv->partition_assist_gpa = addr_gva2gpa(vm, (uintptr_t)hv->partition_assist);
26*6c15c3c4SVitaly Kuznetsov
272dc458b8SVitaly Kuznetsov /* Setup of a region of guest memory for the enlightened VMCS. */
282dc458b8SVitaly Kuznetsov hv->enlightened_vmcs = (void *)vm_vaddr_alloc_page(vm);
292dc458b8SVitaly Kuznetsov hv->enlightened_vmcs_hva = addr_gva2hva(vm, (uintptr_t)hv->enlightened_vmcs);
302dc458b8SVitaly Kuznetsov hv->enlightened_vmcs_gpa = addr_gva2gpa(vm, (uintptr_t)hv->enlightened_vmcs);
312dc458b8SVitaly Kuznetsov
322dc458b8SVitaly Kuznetsov *p_hv_pages_gva = hv_pages_gva;
332dc458b8SVitaly Kuznetsov return hv;
342dc458b8SVitaly Kuznetsov }
352dc458b8SVitaly Kuznetsov
enable_vp_assist(uint64_t vp_assist_pa,void * vp_assist)36e8f3d23cSVitaly Kuznetsov int enable_vp_assist(uint64_t vp_assist_pa, void *vp_assist)
37e8f3d23cSVitaly Kuznetsov {
38e8f3d23cSVitaly Kuznetsov uint64_t val = (vp_assist_pa & HV_X64_MSR_VP_ASSIST_PAGE_ADDRESS_MASK) |
39e8f3d23cSVitaly Kuznetsov HV_X64_MSR_VP_ASSIST_PAGE_ENABLE;
40e8f3d23cSVitaly Kuznetsov
41e8f3d23cSVitaly Kuznetsov wrmsr(HV_X64_MSR_VP_ASSIST_PAGE, val);
42e8f3d23cSVitaly Kuznetsov
43e8f3d23cSVitaly Kuznetsov current_vp_assist = vp_assist;
44e8f3d23cSVitaly Kuznetsov
45e8f3d23cSVitaly Kuznetsov return 0;
46e8f3d23cSVitaly Kuznetsov }
47