win-pvdrivers

diff xenpci/xenpci_fdo.c @ 1054:471c94d04d8a

Refactoring to support xencache (tmem)
author James Harper <james.harper@bendigoit.com.au>
date Sun Jun 02 16:37:21 2013 +1000 (2013-06-02)
parents 37c0c84a42e8
children 5be1f70687ad
line diff
     1.1 --- a/xenpci/xenpci_fdo.c	Tue May 21 16:19:13 2013 +1000
     1.2 +++ b/xenpci/xenpci_fdo.c	Sun Jun 02 16:37:21 2013 +1000
     1.3 @@ -33,6 +33,69 @@ static EVT_WDF_WORKITEM XenPci_SuspendRe
     1.4  static KSTART_ROUTINE XenPci_BalloonThreadProc;
     1.5  #endif
     1.6  
     1.7 +#define XEN_SIGNATURE_LOWER 0x40000000
     1.8 +#define XEN_SIGNATURE_UPPER 0x4000FFFF
     1.9 +
    1.10 +USHORT xen_version_major = (USHORT)-1;
    1.11 +USHORT xen_version_minor = (USHORT)-1;
    1.12 +PVOID hypercall_stubs = NULL;
    1.13 +
    1.14 +static VOID
    1.15 +hvm_get_hypercall_stubs() {
    1.16 +  ULONG base;
    1.17 +  DWORD32 cpuid_output[4];
    1.18 +  char xensig[13];
    1.19 +  ULONG i;
    1.20 +  ULONG pages;
    1.21 +  ULONG msr;
    1.22 +
    1.23 +  if (hypercall_stubs) {
    1.24 +    FUNCTION_MSG("hypercall_stubs alread set\n");
    1.25 +    return;
    1.26 +  }
    1.27 +
    1.28 +  for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100) {
    1.29 +    __cpuid(cpuid_output, base);
    1.30 +    *(ULONG*)(xensig + 0) = cpuid_output[1];
    1.31 +    *(ULONG*)(xensig + 4) = cpuid_output[2];
    1.32 +    *(ULONG*)(xensig + 8) = cpuid_output[3];
    1.33 +    xensig[12] = '\0';
    1.34 +    FUNCTION_MSG("base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]);
    1.35 +    if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
    1.36 +      break;
    1.37 +  }
    1.38 +  if (base == XEN_SIGNATURE_UPPER) {
    1.39 +    FUNCTION_MSG("Cannot find Xen signature\n");
    1.40 +    return;
    1.41 +  }
    1.42 +
    1.43 +  __cpuid(cpuid_output, base + 1);
    1.44 +  xen_version_major = (USHORT)(cpuid_output[0] >> 16);
    1.45 +  xen_version_minor = (USHORT)(cpuid_output[0] & 0xFFFF);
    1.46 +  FUNCTION_MSG("Xen Version %d.%d\n", xen_version_major, xen_version_minor);
    1.47 +
    1.48 +  __cpuid(cpuid_output, base + 2);
    1.49 +  pages = cpuid_output[0];
    1.50 +  msr = cpuid_output[1];
    1.51 +
    1.52 +  hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
    1.53 +  FUNCTION_MSG("Hypercall area at %p\n", hypercall_stubs);
    1.54 +
    1.55 +  if (!hypercall_stubs)
    1.56 +    return;
    1.57 +  for (i = 0; i < pages; i++) {
    1.58 +    ULONGLONG pfn;
    1.59 +    pfn = (MmGetPhysicalAddress((PUCHAR)hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
    1.60 +    __writemsr(msr, (pfn << PAGE_SHIFT) + i);
    1.61 +  }
    1.62 +}
    1.63 +
    1.64 +static VOID
    1.65 +hvm_free_hypercall_stubs() {
    1.66 +  ExFreePoolWithTag(hypercall_stubs, XENPCI_POOL_TAG);
    1.67 +  hypercall_stubs = NULL;
    1.68 +}
    1.69 +
    1.70  static VOID
    1.71  XenPci_MapHalThenPatchKernel(PXENPCI_DEVICE_DATA xpdd)
    1.72  {
    1.73 @@ -111,12 +174,12 @@ XenPci_Init(PXENPCI_DEVICE_DATA xpdd)
    1.74  
    1.75    FUNCTION_ENTER();
    1.76  
    1.77 -  if (!xpdd->hypercall_stubs)
    1.78 +  if (!hypercall_stubs)
    1.79    {
    1.80      XN_ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
    1.81 -    xpdd->hypercall_stubs = hvm_get_hypercall_stubs();
    1.82 +    hvm_get_hypercall_stubs();
    1.83    }
    1.84 -  if (!xpdd->hypercall_stubs)
    1.85 +  if (!hypercall_stubs)
    1.86      return STATUS_UNSUCCESSFUL;
    1.87  
    1.88    if (!xpdd->shared_info_area)
    1.89 @@ -133,7 +196,7 @@ XenPci_Init(PXENPCI_DEVICE_DATA xpdd)
    1.90    xatp.space = XENMAPSPACE_shared_info;
    1.91    xatp.gpfn = (xen_pfn_t)(xpdd->shared_info_area_unmapped.QuadPart >> PAGE_SHIFT);
    1.92    FUNCTION_MSG("gpfn = %x\n", xatp.gpfn);
    1.93 -  ret = HYPERVISOR_memory_op(xpdd, XENMEM_add_to_physmap, &xatp);
    1.94 +  ret = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
    1.95    FUNCTION_MSG("hypervisor memory op (XENMAPSPACE_shared_info) ret = %d\n", ret);
    1.96  
    1.97    FUNCTION_EXIT();
    1.98 @@ -270,13 +333,13 @@ XenPci_BalloonThreadProc(PVOID StartCont
    1.99          set_xen_guest_handle(reservation.extent_start, pfns);
   1.100          
   1.101          //FUNCTION_MSG("Calling HYPERVISOR_memory_op(XENMEM_populate_physmap) - pfn_count = %d\n", pfn_count);
   1.102 -        ret = HYPERVISOR_memory_op(xpdd, XENMEM_populate_physmap, &reservation);
   1.103 +        ret = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
   1.104          //FUNCTION_MSG("populated %d pages\n", ret);
   1.105          if (ret < (ULONG)pfn_count) {
   1.106            if (ret > 0) {
   1.107              /* We hit the Xen hard limit: reprobe. */
   1.108              reservation.nr_extents = ret;
   1.109 -            ret = HYPERVISOR_memory_op(xpdd, XENMEM_decrease_reservation, &reservation);
   1.110 +            ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
   1.111              FUNCTION_MSG("decreased %d pages (xen is out of pages)\n", ret);
   1.112            }
   1.113            ExFreePoolWithTag(pfns, XENPCI_POOL_TAG);
   1.114 @@ -335,7 +398,7 @@ XenPci_BalloonThreadProc(PVOID StartCont
   1.115            #pragma warning(disable: 4127) /* conditional expression is constant */
   1.116            set_xen_guest_handle(reservation.extent_start, pfns);
   1.117            
   1.118 -          ret = HYPERVISOR_memory_op(xpdd, XENMEM_decrease_reservation, &reservation);
   1.119 +          ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
   1.120            ExFreePoolWithTag(pfns, XENPCI_POOL_TAG);
   1.121            if (head) {
   1.122              mdl->Next = head;
   1.123 @@ -396,7 +459,7 @@ XenPci_Suspend0(PVOID context)
   1.124    sysenter_esp = __readmsr(0x175);
   1.125    sysenter_eip = __readmsr(0x176);
   1.126    
   1.127 -  cancelled = hvm_shutdown(xpdd, SHUTDOWN_suspend);
   1.128 +  cancelled = hvm_shutdown(SHUTDOWN_suspend);
   1.129  
   1.130    /* this code was to fix a bug that existed in Xen for a short time... it is harmless but can probably be removed */
   1.131    if (__readmsr(0x174) != sysenter_cs) {