win-pvdrivers

changeset 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 013c44008e93
children a127b9bea695
files common/include/public/xen.h common/include/xen_windows.h xenpci/amd64/hypercall.asm xenpci/evtchn.c xenpci/gnttbl.c xenpci/hypercall.h xenpci/hypercall_amd64.h xenpci/hypercall_ia64.h xenpci/hypercall_x86.h xenpci/hypercall_x86_mingw.h xenpci/memory.c xenpci/sources xenpci/xenbus.c xenpci/xenpci.def xenpci/xenpci.h xenpci/xenpci_export.c xenpci/xenpci_fdo.c xenpci/xenpci_patch_kernel.c
line diff
     1.1 --- a/common/include/public/xen.h	Tue May 21 16:19:13 2013 +1000
     1.2 +++ b/common/include/public/xen.h	Sun Jun 02 16:37:21 2013 +1000
     1.3 @@ -80,6 +80,7 @@
     1.4  #define __HYPERVISOR_sysctl               35
     1.5  #define __HYPERVISOR_domctl               36
     1.6  #define __HYPERVISOR_kexec_op             37
     1.7 +#define __HYPERVISOR_tmem_op              38
     1.8  
     1.9  /* Architecture-specific hypercall definitions. */
    1.10  #define __HYPERVISOR_arch_0               48
    1.11 @@ -591,6 +592,28 @@ DEFINE_XEN_GUEST_HANDLE(uint64_t);
    1.12  
    1.13  #endif /* !__ASSEMBLY__ */
    1.14  
    1.15 +#define TMEM_SPEC_VERSION 1
    1.16 +
    1.17 +struct tmem_op {
    1.18 +	uint32_t cmd;
    1.19 +	int32_t pool_id;
    1.20 +	union {
    1.21 +		struct {  /* for cmd == TMEM_NEW_POOL */
    1.22 +			uint64_t uuid[2];
    1.23 +			uint32_t flags;
    1.24 +		} new;
    1.25 +		struct {
    1.26 +			uint64_t oid[3];
    1.27 +			uint32_t index;
    1.28 +			uint32_t tmem_offset;
    1.29 +			uint32_t pfn_offset;
    1.30 +			uint32_t len;
    1.31 +			XEN_GUEST_HANDLE(void) gmfn; /* guest machine page frame */
    1.32 +		} gen;
    1.33 +	} u;
    1.34 +};
    1.35 +
    1.36 +
    1.37  /* Default definitions for macros used by domctl/sysctl. */
    1.38  #if defined(__XEN__) || defined(__XEN_TOOLS__)
    1.39  #ifndef uint64_aligned_t
     2.1 --- a/common/include/xen_windows.h	Tue May 21 16:19:13 2013 +1000
     2.2 +++ b/common/include/xen_windows.h	Sun Jun 02 16:37:21 2013 +1000
     2.3 @@ -262,6 +262,9 @@ XnBindEvent(XN_HANDLE handle, evtchn_por
     2.4  NTSTATUS
     2.5  XnUnbindEvent(XN_HANDLE handle, evtchn_port_t port);
     2.6  
     2.7 +ULONG
     2.8 +XnTmemOp(struct tmem_op *tmem_op);
     2.9 +
    2.10  #ifndef XENPCI_POOL_TAG
    2.11  #define XENPCI_POOL_TAG (ULONG) 'XenP'
    2.12  #endif
     3.1 --- a/xenpci/amd64/hypercall.asm	Tue May 21 16:19:13 2013 +1000
     3.2 +++ b/xenpci/amd64/hypercall.asm	Sun Jun 02 16:37:21 2013 +1000
     3.3 @@ -20,6 +20,17 @@
     3.4  ; })
     3.5  
     3.6  .code
     3.7 +_hypercall1 proc
     3.8 +    push rdi
     3.9 +    push rsi
    3.10 +    mov rdi, rdx
    3.11 +    mov rax, rcx
    3.12 +    call rax
    3.13 +    pop rsi
    3.14 +    pop rdi
    3.15 +    ret
    3.16 +_hypercall1 endp
    3.17 +
    3.18  _hypercall2 proc
    3.19      push rdi
    3.20      push rsi
     4.1 --- a/xenpci/evtchn.c	Tue May 21 16:19:13 2013 +1000
     4.2 +++ b/xenpci/evtchn.c	Sun Jun 02 16:37:21 2013 +1000
     4.3 @@ -353,44 +353,46 @@ EvtChn_Unmask(PVOID context, evtchn_port
     4.4  }
     4.5  
     4.6  NTSTATUS
     4.7 -EvtChn_Notify(PVOID Context, evtchn_port_t port) {
     4.8 -  PXENPCI_DEVICE_DATA xpdd = Context;
     4.9 +EvtChn_Notify(PVOID context, evtchn_port_t port) {
    4.10    struct evtchn_send send;
    4.11  
    4.12 +  UNREFERENCED_PARAMETER(context);
    4.13    send.port = port;
    4.14 -  (void)HYPERVISOR_event_channel_op(xpdd, EVTCHNOP_send, &send);
    4.15 +  (void)HYPERVISOR_event_channel_op(EVTCHNOP_send, &send);
    4.16    return STATUS_SUCCESS;
    4.17  }
    4.18  
    4.19  evtchn_port_t
    4.20  EvtChn_AllocIpi(PVOID context, ULONG vcpu) {
    4.21 -  PXENPCI_DEVICE_DATA xpdd = context;
    4.22    evtchn_bind_ipi_t op;
    4.23    
    4.24 +  UNREFERENCED_PARAMETER(context);
    4.25    FUNCTION_ENTER();
    4.26    op.vcpu = vcpu;
    4.27    op.port = 0;
    4.28 -  HYPERVISOR_event_channel_op(xpdd, EVTCHNOP_bind_ipi, &op);
    4.29 +  HYPERVISOR_event_channel_op(EVTCHNOP_bind_ipi, &op);
    4.30    FUNCTION_EXIT();
    4.31    return op.port;
    4.32  }
    4.33  
    4.34  evtchn_port_t
    4.35 -EvtChn_AllocUnbound(PVOID Context, domid_t Domain) {
    4.36 -  PXENPCI_DEVICE_DATA xpdd = Context;
    4.37 +EvtChn_AllocUnbound(PVOID context, domid_t Domain) {
    4.38    evtchn_alloc_unbound_t op;
    4.39 +
    4.40 +  UNREFERENCED_PARAMETER(context);
    4.41    op.dom = DOMID_SELF;
    4.42    op.remote_dom = Domain;
    4.43 -  HYPERVISOR_event_channel_op(xpdd, EVTCHNOP_alloc_unbound, &op);
    4.44 +  HYPERVISOR_event_channel_op(EVTCHNOP_alloc_unbound, &op);
    4.45    return op.port;
    4.46  }
    4.47  
    4.48  VOID
    4.49 -EvtChn_Close(PVOID Context, evtchn_port_t port) {
    4.50 -  PXENPCI_DEVICE_DATA xpdd = Context;
    4.51 +EvtChn_Close(PVOID context, evtchn_port_t port) {
    4.52    evtchn_close_t op;
    4.53 +
    4.54 +  UNREFERENCED_PARAMETER(context);
    4.55    op.port = port;
    4.56 -  HYPERVISOR_event_channel_op(xpdd, EVTCHNOP_close, &op);
    4.57 +  HYPERVISOR_event_channel_op(EVTCHNOP_close, &op);
    4.58    return;
    4.59  }
    4.60  
    4.61 @@ -437,7 +439,7 @@ EvtChn_Init(PXENPCI_DEVICE_DATA xpdd)
    4.62  
    4.63    KeMemoryBarrier();
    4.64  
    4.65 -  result = hvm_set_parameter(xpdd, HVM_PARAM_CALLBACK_IRQ, xpdd->irq_number);
    4.66 +  result = hvm_set_parameter(HVM_PARAM_CALLBACK_IRQ, xpdd->irq_number);
    4.67    FUNCTION_MSG("hvm_set_parameter(HVM_PARAM_CALLBACK_IRQ, %d) = %d\n", xpdd->irq_number, (ULONG)result);
    4.68  
    4.69    for (i = 0; i < MAX_VIRT_CPUS; i++)
    4.70 @@ -467,7 +469,7 @@ EvtChn_Suspend(PXENPCI_DEVICE_DATA xpdd)
    4.71    for (i = 0; i < MAX_VIRT_CPUS; i++)
    4.72      xpdd->shared_info_area->vcpu_info[i].evtchn_upcall_mask = 1;
    4.73    KeMemoryBarrier();
    4.74 -  hvm_set_parameter(xpdd, HVM_PARAM_CALLBACK_IRQ, 0);
    4.75 +  hvm_set_parameter(HVM_PARAM_CALLBACK_IRQ, 0);
    4.76  
    4.77    for (i = 0; i < NR_EVENTS; i++) {
    4.78      if (xpdd->ev_actions[i].type == EVT_ACTION_TYPE_DPC) {
     5.1 --- a/xenpci/gnttbl.c	Tue May 21 16:19:13 2013 +1000
     5.2 +++ b/xenpci/gnttbl.c	Sun Jun 02 16:37:21 2013 +1000
     5.3 @@ -76,7 +76,7 @@ GntTbl_Map(PVOID Context, unsigned int s
     5.4      xatp.idx = i;
     5.5      xatp.space = XENMAPSPACE_grant_table;
     5.6      xatp.gpfn = (xen_pfn_t)MmGetMdlPfnArray(xpdd->gnttbl_mdl)[i];
     5.7 -    if (HYPERVISOR_memory_op(xpdd, XENMEM_add_to_physmap, &xatp))
     5.8 +    if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp))
     5.9      {
    5.10        FUNCTION_MSG("*** ERROR MAPPING FRAME %d ***\n", i);
    5.11      }
    5.12 @@ -154,14 +154,14 @@ GntTbl_EndAccess(
    5.13  }
    5.14  
    5.15  static unsigned int 
    5.16 -GntTbl_QueryMaxFrames(PXENPCI_DEVICE_DATA xpdd)
    5.17 -{
    5.18 +GntTbl_QueryMaxFrames(PXENPCI_DEVICE_DATA xpdd) {
    5.19    struct gnttab_query_size query;
    5.20    int rc;
    5.21  
    5.22 +  UNREFERENCED_PARAMETER(xpdd);
    5.23    query.dom = DOMID_SELF;
    5.24  
    5.25 -  rc = HYPERVISOR_grant_table_op(xpdd, GNTTABOP_query_size, &query, 1);
    5.26 +  rc = HYPERVISOR_grant_table_op(GNTTABOP_query_size, &query, 1);
    5.27    if ((rc < 0) || (query.status != GNTST_okay))
    5.28    {
    5.29      FUNCTION_MSG("***CANNOT QUERY MAX GRANT FRAME***\n");
    5.30 @@ -171,8 +171,7 @@ GntTbl_QueryMaxFrames(PXENPCI_DEVICE_DAT
    5.31  }
    5.32  
    5.33  VOID
    5.34 -GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    5.35 -{
    5.36 +GntTbl_Init(PXENPCI_DEVICE_DATA xpdd) {
    5.37    int i;
    5.38    int grant_entries;
    5.39  
    5.40 @@ -216,7 +215,7 @@ GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    5.41      set_xen_guest_handle(reservation.extent_start, &pfn);
    5.42      
    5.43      FUNCTION_MSG("Calling HYPERVISOR_memory_op - pfn = %x\n", (ULONG)pfn);
    5.44 -    ret = HYPERVISOR_memory_op(xpdd, XENMEM_decrease_reservation, &reservation);
    5.45 +    ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
    5.46      FUNCTION_MSG("decreased %d pages for grant table frame %d\n", ret, i);
    5.47    }
    5.48  
    5.49 @@ -324,7 +323,7 @@ GntTbl_Resume(PXENPCI_DEVICE_DATA xpdd)
    5.50      set_xen_guest_handle(reservation.extent_start, &pfn);
    5.51      
    5.52      FUNCTION_MSG("Calling HYPERVISOR_memory_op - pfn = %x\n", (ULONG)pfn);
    5.53 -    ret = HYPERVISOR_memory_op(xpdd, XENMEM_decrease_reservation, &reservation);
    5.54 +    ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
    5.55      FUNCTION_MSG("decreased %d pages for grant table frame %d\n", ret, i);
    5.56    }
    5.57  
     6.1 --- a/xenpci/hypercall.h	Tue May 21 16:19:13 2013 +1000
     6.2 +++ b/xenpci/hypercall.h	Sun Jun 02 16:37:21 2013 +1000
     6.3 @@ -17,64 +17,53 @@ along with this program; if not, write t
     6.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     6.5  */
     6.6  
     6.7 +#include "xenpci.h"
     6.8 +
     6.9  #if defined(_X86_)
    6.10 -  #if defined(__MINGW32__)
    6.11 -    #include "hypercall_x86_mingw.h"
    6.12 -  #else
    6.13 -    #include "hypercall_x86.h"
    6.14 -  #endif
    6.15 +  #include "hypercall_x86.h"
    6.16  #elif defined(_AMD64_)
    6.17    #include "hypercall_amd64.h"
    6.18 -#elif defined(__ia64__)
    6.19 -  #include "hypercall_ia64.h"
    6.20  #endif
    6.21  
    6.22  static __inline ULONGLONG
    6.23 -_hvm_get_parameter(PVOID hypercall_stubs, int hvm_param)
    6.24 +hvm_get_parameter(int hvm_param)
    6.25  {
    6.26    struct xen_hvm_param a;
    6.27    int retval;
    6.28  
    6.29 -  FUNCTION_ENTER();
    6.30    a.domid = DOMID_SELF;
    6.31    a.index = hvm_param;
    6.32 -  retval = _HYPERVISOR_hvm_op(hypercall_stubs, HVMOP_get_param, &a);
    6.33 -  KdPrint((__DRIVER_NAME " HYPERVISOR_hvm_op retval = %d\n", retval));
    6.34 -  FUNCTION_EXIT();
    6.35 +  retval = HYPERVISOR_hvm_op(HVMOP_get_param, &a);
    6.36    return a.value;
    6.37  }
    6.38  
    6.39  static __inline ULONGLONG
    6.40 -_hvm_set_parameter(PVOID hypercall_stubs, int hvm_param, ULONGLONG value)
    6.41 +hvm_set_parameter(int hvm_param, ULONGLONG value)
    6.42  {
    6.43    struct xen_hvm_param a;
    6.44    int retval;
    6.45  
    6.46 -  FUNCTION_ENTER();
    6.47    a.domid = DOMID_SELF;
    6.48    a.index = hvm_param;
    6.49    a.value = value;
    6.50 -  retval = _HYPERVISOR_hvm_op(hypercall_stubs, HVMOP_set_param, &a);
    6.51 -  KdPrint((__DRIVER_NAME " HYPERVISOR_hvm_op retval = %d\n", retval));
    6.52 -  FUNCTION_EXIT();
    6.53 +  retval = HYPERVISOR_hvm_op(HVMOP_set_param, &a);
    6.54    return retval;
    6.55  }
    6.56  
    6.57  static __inline int
    6.58 -_hvm_shutdown(PVOID hypercall_stubs, unsigned int reason)
    6.59 +hvm_shutdown(unsigned int reason)
    6.60  {
    6.61    struct sched_shutdown ss;
    6.62    int retval;
    6.63  
    6.64    FUNCTION_ENTER();
    6.65    ss.reason = reason;
    6.66 -  retval = _HYPERVISOR_sched_op(hypercall_stubs, SCHEDOP_shutdown, &ss);
    6.67 +  retval = HYPERVISOR_sched_op(SCHEDOP_shutdown, &ss);
    6.68    FUNCTION_EXIT();
    6.69    return retval;
    6.70  }
    6.71  
    6.72  static __inline VOID
    6.73 -_HYPERVISOR_yield(PVOID hypercall_stubs)
    6.74 -{
    6.75 -  _HYPERVISOR_sched_op(hypercall_stubs, SCHEDOP_yield, NULL);
    6.76 +HYPERVISOR_yield() {
    6.77 +  HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
    6.78  }
     7.1 --- a/xenpci/hypercall_amd64.h	Tue May 21 16:19:13 2013 +1000
     7.2 +++ b/xenpci/hypercall_amd64.h	Sun Jun 02 16:37:21 2013 +1000
     7.3 @@ -17,11 +17,12 @@ along with this program; if not, write t
     7.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     7.5  */
     7.6  
     7.7 +extern int _hypercall1(VOID *address, xen_ulong_t a1);
     7.8  extern int _hypercall2(VOID *address, xen_ulong_t a1, xen_ulong_t a2);
     7.9  extern int _hypercall3(VOID *address, xen_ulong_t a1, xen_ulong_t a2, xen_ulong_t a3);
    7.10  
    7.11  static __inline int
    7.12 -_HYPERVISOR_memory_op(PVOID hypercall_stubs, int cmd, void *arg)
    7.13 +HYPERVISOR_memory_op(int cmd, void *arg)
    7.14  {
    7.15    PCHAR memory_op_func = hypercall_stubs;
    7.16    memory_op_func += __HYPERVISOR_memory_op * 32;
    7.17 @@ -29,7 +30,7 @@ static __inline int
    7.18  }
    7.19  
    7.20  static __inline int
    7.21 -_HYPERVISOR_xen_version(PVOID hypercall_stubs, int cmd, void *arg)
    7.22 +HYPERVISOR_xen_version(int cmd, void *arg)
    7.23  {
    7.24    PCHAR xen_version_func = hypercall_stubs;
    7.25    xen_version_func += __HYPERVISOR_xen_version * 32;
    7.26 @@ -37,7 +38,7 @@ static __inline int
    7.27  }
    7.28  
    7.29  static __inline int
    7.30 -_HYPERVISOR_grant_table_op(PVOID hypercall_stubs, int cmd, void *uop, unsigned int count)
    7.31 +HYPERVISOR_grant_table_op(int cmd, void *uop, unsigned int count)
    7.32  {
    7.33    PCHAR grant_table_op_func = hypercall_stubs;
    7.34    grant_table_op_func += __HYPERVISOR_grant_table_op * 32;
    7.35 @@ -45,7 +46,7 @@ static __inline int
    7.36  }
    7.37  
    7.38  static __inline int
    7.39 -_HYPERVISOR_hvm_op(PVOID hypercall_stubs, int op, struct xen_hvm_param *arg)
    7.40 +HYPERVISOR_hvm_op(int op, struct xen_hvm_param *arg)
    7.41  {
    7.42    PCHAR hvm_op_func = hypercall_stubs;
    7.43    hvm_op_func += __HYPERVISOR_hvm_op * 32;
    7.44 @@ -53,7 +54,7 @@ static __inline int
    7.45  }
    7.46  
    7.47  static __inline int
    7.48 -_HYPERVISOR_event_channel_op(PVOID hypercall_stubs, int cmd, void *op)
    7.49 +HYPERVISOR_event_channel_op(int cmd, void *op)
    7.50  {
    7.51    PCHAR event_channel_op_func = hypercall_stubs;
    7.52    event_channel_op_func += __HYPERVISOR_event_channel_op * 32;
    7.53 @@ -61,7 +62,7 @@ static __inline int
    7.54  }
    7.55  
    7.56  static __inline int
    7.57 -_HYPERVISOR_sched_op(PVOID hypercall_stubs, int cmd, void *arg)
    7.58 +HYPERVISOR_sched_op(int cmd, void *arg)
    7.59  {
    7.60    PCHAR sched_op_func = hypercall_stubs;
    7.61    sched_op_func += __HYPERVISOR_sched_op * 32;
    7.62 @@ -69,17 +70,10 @@ static __inline int
    7.63  }
    7.64  
    7.65  static __inline int
    7.66 -_HYPERVISOR_shutdown(PVOID hypercall_stubs, unsigned int reason)
    7.67 +HYPERVISOR_tmem_op(void *op)
    7.68  {
    7.69 -  struct sched_shutdown ss;
    7.70 -  int retval;
    7.71 +  PCHAR event_channel_op_func = hypercall_stubs;
    7.72 +  event_channel_op_func += __HYPERVISOR_event_channel_op * 32;
    7.73 +  return _hypercall2(event_channel_op_func, (xen_ulong_t)op);
    7.74 +}
    7.75  
    7.76 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    7.77 -  
    7.78 -  ss.reason = reason;
    7.79 -  retval = _HYPERVISOR_sched_op(hypercall_stubs, SCHEDOP_shutdown, &ss);
    7.80 -  
    7.81 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    7.82 -
    7.83 -  return retval;
    7.84 -}
    7.85 \ No newline at end of file
     8.1 --- a/xenpci/hypercall_ia64.h	Tue May 21 16:19:13 2013 +1000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,88 +0,0 @@
     8.4 -/*
     8.5 -PV Drivers for Windows Xen HVM Domains
     8.6 -Copyright (C) 2007 James Harper
     8.7 -
     8.8 -This program is free software; you can redistribute it and/or
     8.9 -modify it under the terms of the GNU General Public License
    8.10 -as published by the Free Software Foundation; either version 2
    8.11 -of the License, or (at your option) any later version.
    8.12 -
    8.13 -This program is distributed in the hope that it will be useful,
    8.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.16 -GNU General Public License for more details.
    8.17 -
    8.18 -You should have received a copy of the GNU General Public License
    8.19 -along with this program; if not, write to the Free Software
    8.20 -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    8.21 -*/
    8.22 -
    8.23 -extern int _hypercall2(VOID *address, xen_ulong_t a1, xen_ulong_t a2);
    8.24 -extern int _hypercall3(VOID *address, xen_ulong_t a1, xen_ulong_t a2, xen_ulong_t a3);
    8.25 -
    8.26 -static __inline int
    8.27 -HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    8.28 -{
    8.29 -  PCHAR memory_op_func = xpdd->hypercall_stubs;
    8.30 -  memory_op_func += __HYPERVISOR_memory_op * 32;
    8.31 -  return _hypercall2(memory_op_func, (xen_ulong_t)cmd, (xen_ulong_t)arg);
    8.32 -}
    8.33 -
    8.34 -static __inline int
    8.35 -HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    8.36 -{
    8.37 -  PCHAR xen_version_func = xpdd->hypercall_stubs;
    8.38 -  xen_version_func += __HYPERVISOR_xen_version * 32;
    8.39 -  return _hypercall2(xen_version_func, (xen_ulong_t)cmd, (xen_ulong_t)arg);
    8.40 -}
    8.41 -
    8.42 -static __inline int
    8.43 -HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
    8.44 -{
    8.45 -  PCHAR grant_table_op_func = xpdd->hypercall_stubs;
    8.46 -  grant_table_op_func += __HYPERVISOR_grant_table_op * 32;
    8.47 -  return _hypercall3(grant_table_op_func, (xen_ulong_t)cmd, (xen_ulong_t)uop, (xen_ulong_t)count);
    8.48 -}
    8.49 -
    8.50 -static __inline int
    8.51 -HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
    8.52 -{
    8.53 -  PCHAR hvm_op_func = xpdd->hypercall_stubs;
    8.54 -  hvm_op_func += __HYPERVISOR_hvm_op * 32;
    8.55 -  return _hypercall2(hvm_op_func, (xen_ulong_t)op, (xen_ulong_t)arg);
    8.56 -}
    8.57 -
    8.58 -static __inline int
    8.59 -HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *op)
    8.60 -{
    8.61 -  PCHAR event_channel_op_func = xpdd->hypercall_stubs;
    8.62 -  event_channel_op_func += __HYPERVISOR_event_channel_op * 32;
    8.63 -  return _hypercall2(event_channel_op_func, (xen_ulong_t)cmd, (xen_ulong_t)op);
    8.64 -}
    8.65 -
    8.66 -static __inline int
    8.67 -HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    8.68 -{
    8.69 -  PCHAR sched_op_func = xpdd->hypercall_stubs;
    8.70 -  sched_op_func += __HYPERVISOR_sched_op * 32;
    8.71 -  return _hypercall2(sched_op_func, (xen_ulong_t)cmd, (xen_ulong_t)arg);
    8.72 -}
    8.73 -
    8.74 -static __inline int
    8.75 -HYPERVISOR_shutdown(PXENPCI_DEVICE_DATA xpdd, unsigned int reason)
    8.76 -{
    8.77 -  struct sched_shutdown ss;
    8.78 -  int retval;
    8.79 -
    8.80 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    8.81 -
    8.82 -  ss.reason = reason;
    8.83 -
    8.84 -  KdPrint((__DRIVER_NAME "     A\n"));
    8.85 -
    8.86 -  retval = HYPERVISOR_sched_op(xpdd, SCHEDOP_shutdown, &ss);
    8.87 -
    8.88 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
    8.89 -
    8.90 -  return retval;
    8.91 -}
     9.1 --- a/xenpci/hypercall_x86.h	Tue May 21 16:19:13 2013 +1000
     9.2 +++ b/xenpci/hypercall_x86.h	Sun Jun 02 16:37:21 2013 +1000
     9.3 @@ -20,8 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     9.4  */
     9.5  
     9.6  static __inline int
     9.7 -_HYPERVISOR_memory_op(PVOID hypercall_stubs, int cmd, void *arg)
     9.8 -{
     9.9 +HYPERVISOR_memory_op(int cmd, void *arg) {
    9.10    long __res;
    9.11    __asm {
    9.12      mov ebx, cmd
    9.13 @@ -35,8 +34,7 @@ static __inline int
    9.14  }
    9.15  
    9.16  static __inline int
    9.17 -_HYPERVISOR_sched_op(PVOID hypercall_stubs, int cmd, void *arg)
    9.18 -{
    9.19 +HYPERVISOR_sched_op(int cmd, void *arg) {
    9.20    long __res;
    9.21    __asm {
    9.22      mov ebx, cmd
    9.23 @@ -50,8 +48,7 @@ static __inline int
    9.24  }
    9.25  
    9.26  static __inline int
    9.27 -_HYPERVISOR_xen_version(PVOID hypercall_stubs, int cmd, void *arg)
    9.28 -{
    9.29 +HYPERVISOR_xen_version(int cmd, void *arg) {
    9.30    long __res;
    9.31    __asm {
    9.32      mov ebx, cmd
    9.33 @@ -65,8 +62,7 @@ static __inline int
    9.34  }
    9.35  
    9.36  static __inline int
    9.37 -_HYPERVISOR_grant_table_op(PVOID hypercall_stubs, int cmd, void *uop, unsigned int count)
    9.38 -{
    9.39 +HYPERVISOR_grant_table_op(int cmd, void *uop, unsigned int count) {
    9.40    long __res;
    9.41    __asm {
    9.42      mov ebx, cmd
    9.43 @@ -81,8 +77,7 @@ static __inline int
    9.44  }
    9.45  
    9.46  static __inline int
    9.47 -_HYPERVISOR_hvm_op(PVOID hypercall_stubs, int op, struct xen_hvm_param *arg)
    9.48 -{
    9.49 +HYPERVISOR_hvm_op(int op, struct xen_hvm_param *arg) {
    9.50    long __res;
    9.51    __asm {
    9.52      mov ebx, op
    9.53 @@ -96,8 +91,7 @@ static __inline int
    9.54  }
    9.55  
    9.56  static __inline int
    9.57 -_HYPERVISOR_event_channel_op(PVOID hypercall_stubs, int cmd, void *op)
    9.58 -{
    9.59 +HYPERVISOR_event_channel_op(int cmd, void *op) {
    9.60    long __res;
    9.61    __asm {
    9.62      mov ebx, cmd
    9.63 @@ -110,4 +104,17 @@ static __inline int
    9.64    return __res;
    9.65  }
    9.66  
    9.67 +static __inline int
    9.68 +HYPERVISOR_tmem_op(struct tmem_op *op) {
    9.69 +  long __res;
    9.70 +  __asm {
    9.71 +    mov ebx, op
    9.72 +    mov eax, hypercall_stubs
    9.73 +    add eax, (__HYPERVISOR_tmem_op * 32)
    9.74 +    call eax
    9.75 +    mov [__res], eax
    9.76 +  }
    9.77 +  return __res;
    9.78 +}
    9.79 +
    9.80  #endif
    10.1 --- a/xenpci/hypercall_x86_mingw.h	Tue May 21 16:19:13 2013 +1000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,108 +0,0 @@
    10.4 -/* Code/license from Xen's include/asm/hypercall.h: */
    10.5 -/*
    10.6 - * Copyright (c) 2002-2004, K A Fraser
    10.7 - * 
    10.8 - * This program is free software; you can redistribute it and/or
    10.9 - * modify it under the terms of the GNU General Public License version 2
   10.10 - * as published by the Free Software Foundation; or, when distributed
   10.11 - * separately from the Linux kernel or incorporated into other
   10.12 - * software packages, subject to the following license:
   10.13 - * 
   10.14 - * Permission is hereby granted, free of charge, to any person obtaining a copy
   10.15 - * of this source file (the "Software"), to deal in the Software without
   10.16 - * restriction, including without limitation the rights to use, copy, modify,
   10.17 - * merge, publish, distribute, sublicense, and/or sell copies of the Software,
   10.18 - * and to permit persons to whom the Software is furnished to do so, subject to
   10.19 - * the following conditions:
   10.20 - * 
   10.21 - * The above copyright notice and this permission notice shall be included in
   10.22 - * all copies or substantial portions of the Software.
   10.23 - */
   10.24 -/* Also Copyright (C) 2008 Andy Grover */
   10.25 -
   10.26 -#define __STR(x) #x
   10.27 -#define STR(x) __STR(x)
   10.28 -
   10.29 -#define _hypercall2(type, name, a1, a2)                         \
   10.30 -({                                                              \
   10.31 -  long __res, __ign1, __ign2;                                   \
   10.32 -  asm volatile (                                                \
   10.33 -	  "mov %3,%%eax; "                                            \
   10.34 -	  "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "            \
   10.35 -  	"call *%%eax"                                               \
   10.36 -    : "=a" (__res), "=b" (__ign1), "=c" (__ign2)                \
   10.37 -    : "1" ((long)(a1)), "2" ((long)(a2)), "r" (xpdd->hypercall_stubs) \
   10.38 -    : "memory" );                                               \
   10.39 -  (type)__res;                                                  \
   10.40 -})
   10.41 -
   10.42 -#define _hypercall3(type, name, a1, a2, a3)			                \
   10.43 -({								                                              \
   10.44 -	long __res, __ign1, __ign2, __ign3;			                      \
   10.45 -	asm volatile (						                                    \
   10.46 -	  "mov %4,%%eax; "                                            \
   10.47 -	  "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "            \
   10.48 -  	"call *%%eax"                                               \
   10.49 -		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	            \
   10.50 -		"=d" (__ign3)					                                      \
   10.51 -		: "1" ((long)(a1)), "2" ((long)(a2)),		                    \
   10.52 -		"3" ((long)(a3)), "r" (xpdd->hypercall_stubs)		            \
   10.53 -		: "memory" );					                                      \
   10.54 -	(type)__res;						                                      \
   10.55 -})
   10.56 -
   10.57 -
   10.58 -static __inline void __cpuid(uint32_t output[4], uint32_t op)
   10.59 -{
   10.60 -  __asm__("cpuid"
   10.61 -          : "=a" (output[0]),
   10.62 -            "=b" (output[1]),
   10.63 -            "=c" (output[2]),
   10.64 -            "=d" (output[3])
   10.65 -          : "0" (op));
   10.66 -}
   10.67 -
   10.68 -static __inline void __writemsr(uint32_t msr, uint64_t value)
   10.69 -{
   10.70 -  uint32_t hi, lo;
   10.71 -  hi = value >> 32;
   10.72 -  lo = value & 0xFFFFFFFF;
   10.73 -
   10.74 -  __asm__ __volatile__("wrmsr"
   10.75 -                       : /* no outputs */
   10.76 -                       : "c" (msr), "a" (lo), "d" (hi));
   10.77 -}
   10.78 -
   10.79 -static __inline int
   10.80 -HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   10.81 -{
   10.82 -  return _hypercall2(int, memory_op, cmd, arg);
   10.83 -}
   10.84 -
   10.85 -static __inline int
   10.86 -HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   10.87 -{
   10.88 -  return _hypercall2(int, sched_op, cmd, arg);
   10.89 -}
   10.90 -
   10.91 -static __inline int
   10.92 -HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
   10.93 -{
   10.94 -  return _hypercall2(unsigned long, hvm_op, op, arg);
   10.95 -}
   10.96 -
   10.97 -static __inline int
   10.98 -HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   10.99 -{
  10.100 -	return _hypercall2(int, event_channel_op, cmd, arg);
  10.101 -}
  10.102 -
  10.103 static inline int
  10.104 -HYPERVISOR_grant_table_op(
  10.105 -  PXENPCI_DEVICE_DATA xpdd,
  10.106 -  unsigned int cmd,
  10.107 -  void *uop,
  10.108 -  unsigned int count)
  10.109 -{
  10.110 -	return _hypercall3(int, grant_table_op, cmd, uop, count);
  10.111 -}
  10.112 -
    11.1 --- a/xenpci/memory.c	Tue May 21 16:19:13 2013 +1000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,85 +0,0 @@
    11.4 -/*
    11.5 -PV Drivers for Windows Xen HVM Domains
    11.6 -Copyright (C) 2011 James Harper
    11.7 -
    11.8 -This program is free software; you can redistribute it and/or
    11.9 -modify it under the terms of the GNU General Public License
   11.10 -as published by the Free Software Foundation; either version 2
   11.11 -of the License, or (at your option) any later version.
   11.12 -
   11.13 -This program is distributed in the hope that it will be useful,
   11.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.16 -GNU General Public License for more details.
   11.17 -
   11.18 -You should have received a copy of the GNU General Public License
   11.19 -along with this program; if not, write to the Free Software
   11.20 -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   11.21 -*/
   11.22 -
   11.23 -#include "xenpci.h"
   11.24 -
   11.25 -/* must be called at <= DISPATCH_LEVEL if hypercall_stubs == NULL */
   11.26 -
   11.27 -#define XEN_SIGNATURE_LOWER 0x40000000
   11.28 -#define XEN_SIGNATURE_UPPER 0x4000FFFF
   11.29 -
   11.30 -USHORT xen_version_major = (USHORT)-1;
   11.31 -USHORT xen_version_minor = (USHORT)-1;
   11.32 -
   11.33 -PVOID
   11.34 -hvm_get_hypercall_stubs()
   11.35 -{
   11.36 -  PVOID hypercall_stubs;
   11.37 -  ULONG base;
   11.38 -  DWORD32 cpuid_output[4];
   11.39 -  char xensig[13];
   11.40 -  ULONG i;
   11.41 -  ULONG pages;
   11.42 -  ULONG msr;
   11.43 -
   11.44 -  for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100)
   11.45 -  {
   11.46 -    __cpuid(cpuid_output, base);
   11.47 -    *(ULONG*)(xensig + 0) = cpuid_output[1];
   11.48 -    *(ULONG*)(xensig + 4) = cpuid_output[2];
   11.49 -    *(ULONG*)(xensig + 8) = cpuid_output[3];
   11.50 -    xensig[12] = '\0';
   11.51 -    FUNCTION_MSG("base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]);
   11.52 -    if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
   11.53 -      break;
   11.54 -  }
   11.55 -  if (base > XEN_SIGNATURE_UPPER)
   11.56 -  {
   11.57 -    FUNCTION_MSG("Cannot find Xen signature\n");
   11.58 -    return NULL;
   11.59 -  }
   11.60 -
   11.61 -  __cpuid(cpuid_output, base + 1);
   11.62 -  xen_version_major = (USHORT)(cpuid_output[0] >> 16);
   11.63 -  xen_version_minor = (USHORT)(cpuid_output[0] & 0xFFFF);
   11.64 -  FUNCTION_MSG("Xen Version %d.%d\n", xen_version_major, xen_version_minor);
   11.65 -
   11.66 -  __cpuid(cpuid_output, base + 2);
   11.67 -  pages = cpuid_output[0];
   11.68 -  msr = cpuid_output[1];
   11.69 -
   11.70 -  hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
   11.71 -  FUNCTION_MSG("Hypercall area at %p\n", hypercall_stubs);
   11.72 -
   11.73 -  if (!hypercall_stubs)
   11.74 -    return NULL;
   11.75 -  for (i = 0; i < pages; i++) {
   11.76 -    ULONGLONG pfn;
   11.77 -    pfn = (MmGetPhysicalAddress((PUCHAR)hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
   11.78 -    //KdPrint((__DRIVER_NAME "     pfn = %16lX\n", pfn));
   11.79 -    __writemsr(msr, (pfn << PAGE_SHIFT) + i);
   11.80 -  }
   11.81 -  return hypercall_stubs;
   11.82 -}
   11.83 -
   11.84 -VOID
   11.85 -hvm_free_hypercall_stubs(PVOID hypercall_stubs)
   11.86 -{
   11.87 -  ExFreePoolWithTag(hypercall_stubs, XENPCI_POOL_TAG);
   11.88 -}
    12.1 --- a/xenpci/sources	Tue May 21 16:19:13 2013 +1000
    12.2 +++ b/xenpci/sources	Sun Jun 02 16:37:21 2013 +1000
    12.3 @@ -19,6 +19,6 @@ I386_SOURCES=tpr_emulate.asm
    12.4  # dbgprint_hook.asm
    12.5  
    12.6  SOURCES=xenpci.rc xenpci.c xenpci_fdo.c xenpci_pdo.c xenpci_export.c \
    12.7 -        evtchn.c gnttbl.c xenbus.c memory.c xenpci_device_interface.c \
    12.8 +        evtchn.c gnttbl.c xenbus.c xenpci_device_interface.c \
    12.9          xenbus_device_interface.c xenpci_highsync.c xenpci_patch_kernel.c \
   12.10          xenpci_dbgprint.c
    13.1 --- a/xenpci/xenbus.c	Tue May 21 16:19:13 2013 +1000
    13.2 +++ b/xenpci/xenbus.c	Sun Jun 02 16:37:21 2013 +1000
    13.3 @@ -354,8 +354,8 @@ XenBus_Connect(PXENPCI_DEVICE_DATA xpdd)
    13.4    PHYSICAL_ADDRESS pa_xen_store_interface;
    13.5    xen_ulong_t xen_store_mfn;
    13.6  
    13.7 -  xpdd->xenbus_event = (evtchn_port_t)hvm_get_parameter(xpdd, HVM_PARAM_STORE_EVTCHN);
    13.8 -  xen_store_mfn = (xen_ulong_t)hvm_get_parameter(xpdd, HVM_PARAM_STORE_PFN);
    13.9 +  xpdd->xenbus_event = (evtchn_port_t)hvm_get_parameter(HVM_PARAM_STORE_EVTCHN);
   13.10 +  xen_store_mfn = (xen_ulong_t)hvm_get_parameter(HVM_PARAM_STORE_PFN);
   13.11    pa_xen_store_interface.QuadPart = (ULONGLONG)xen_store_mfn << PAGE_SHIFT;
   13.12    xpdd->xen_store_interface = MmMapIoSpace(pa_xen_store_interface, PAGE_SIZE, MmNonCached);
   13.13  
    14.1 --- a/xenpci/xenpci.def	Tue May 21 16:19:13 2013 +1000
    14.2 +++ b/xenpci/xenpci.def	Sun Jun 02 16:37:21 2013 +1000
    14.3 @@ -29,4 +29,6 @@ EXPORTS
    14.4   XnWriteInt64
    14.5  
    14.6   XnDebugPrint
    14.7 - XnPrintDump
    14.8 \ No newline at end of file
    14.9 + XnPrintDump
   14.10 +
   14.11 + XnTmemOp
    15.1 --- a/xenpci/xenpci.h	Tue May 21 16:19:13 2013 +1000
    15.2 +++ b/xenpci/xenpci.h	Sun Jun 02 16:37:21 2013 +1000
    15.3 @@ -75,6 +75,7 @@ DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC82
    15.4  #define BALLOON_UNITS_KB (1 * 1024) /* 1MB */
    15.5  #define BALLOON_UNIT_PAGES ((BALLOON_UNITS_KB << 10) >> PAGE_SHIFT)
    15.6  
    15.7 +extern PVOID hypercall_stubs;
    15.8  extern ULONG qemu_protocol_version;
    15.9  extern USHORT xen_version_major;
   15.10  extern USHORT xen_version_minor;
   15.11 @@ -160,8 +161,6 @@ typedef struct {
   15.12    ULONG platform_ioport_addr;
   15.13    ULONG platform_ioport_len;
   15.14  
   15.15 -  char *hypercall_stubs;
   15.16 -
   15.17    evtchn_port_t xenbus_event;
   15.18  
   15.19    /* grant related */
   15.20 @@ -330,6 +329,7 @@ EVT_WDF_FILE_CLOSE XenPci_EvtFileClose;
   15.21  EVT_WDF_FILE_CLEANUP XenPci_EvtFileCleanup;
   15.22  EVT_WDF_IO_QUEUE_IO_DEFAULT XenPci_EvtIoDefault;
   15.23  
   15.24 +#if 0
   15.25  #define HYPERVISOR_memory_op(xpdd, cmd, arg) _HYPERVISOR_memory_op(xpdd->hypercall_stubs, cmd, arg)
   15.26  #define HYPERVISOR_xen_version(xpdd, cmd, arg) _HYPERVISOR_xen_version(xpdd->hypercall_stubs, cmd, arg)
   15.27  #define HYPERVISOR_grant_table_op(xpdd, cmd, uop, count) _HYPERVISOR_grant_table_op(xpdd->hypercall_stubs, cmd, uop, count)
   15.28 @@ -342,13 +342,14 @@ EVT_WDF_IO_QUEUE_IO_DEFAULT XenPci_EvtIo
   15.29  #define hvm_set_parameter(xvdd, hvm_param, value) _hvm_set_parameter(xvdd->hypercall_stubs, hvm_param, value);
   15.30  #define hvm_shutdown(xvdd, reason) _hvm_shutdown(xvdd->hypercall_stubs, reason);
   15.31  #define HYPERVISOR_yield(xvdd) _HYPERVISOR_yield(xvdd->hypercall_stubs);
   15.32 +#endif
   15.33  
   15.34  #include "hypercall.h"
   15.35  
   15.36  #define XBT_NIL ((xenbus_transaction_t)0)
   15.37  
   15.38 -PVOID hvm_get_hypercall_stubs();
   15.39 -VOID hvm_free_hypercall_stubs(PVOID hypercall_stubs);
   15.40 +//VOID hvm_get_hypercall_stubs();
   15.41 +//VOID hvm_free_hypercall_stubs();
   15.42  
   15.43  EVT_WDF_DEVICE_PREPARE_HARDWARE XenPci_EvtDevicePrepareHardware;
   15.44  EVT_WDF_DEVICE_RELEASE_HARDWARE XenPci_EvtDeviceReleaseHardware;
    16.1 --- a/xenpci/xenpci_export.c	Tue May 21 16:19:13 2013 +1000
    16.2 +++ b/xenpci/xenpci_export.c	Sun Jun 02 16:37:21 2013 +1000
    16.3 @@ -425,3 +425,8 @@ XnPrintDump() {
    16.4      XnDebugPrint("Bug check 0x%08x (0x%p, 0x%p, 0x%p, 0x%p)\n", bugcheck_data.BugCheckCode, bugcheck_data.Parameter1, bugcheck_data.Parameter2, bugcheck_data.Parameter3, bugcheck_data.Parameter4);
    16.5    }
    16.6  }
    16.7 +
    16.8 +ULONG
    16.9 +XnTmemOp(struct tmem_op *tmem_op) {
   16.10 +  return HYPERVISOR_tmem_op(tmem_op);
   16.11 +}
   16.12 \ No newline at end of file
    17.1 --- a/xenpci/xenpci_fdo.c	Tue May 21 16:19:13 2013 +1000
    17.2 +++ b/xenpci/xenpci_fdo.c	Sun Jun 02 16:37:21 2013 +1000
    17.3 @@ -33,6 +33,69 @@ static EVT_WDF_WORKITEM XenPci_SuspendRe
    17.4  static KSTART_ROUTINE XenPci_BalloonThreadProc;
    17.5  #endif
    17.6  
    17.7 +#define XEN_SIGNATURE_LOWER 0x40000000
    17.8 +#define XEN_SIGNATURE_UPPER 0x4000FFFF
    17.9 +
   17.10 +USHORT xen_version_major = (USHORT)-1;
   17.11 +USHORT xen_version_minor = (USHORT)-1;
   17.12 +PVOID hypercall_stubs = NULL;
   17.13 +
   17.14 +static VOID
   17.15 +hvm_get_hypercall_stubs() {
   17.16 +  ULONG base;
   17.17 +  DWORD32 cpuid_output[4];
   17.18 +  char xensig[13];
   17.19 +  ULONG i;
   17.20 +  ULONG pages;
   17.21 +  ULONG msr;
   17.22 +
   17.23 +  if (hypercall_stubs) {
   17.24 +    FUNCTION_MSG("hypercall_stubs alread set\n");
   17.25 +    return;
   17.26 +  }
   17.27 +
   17.28 +  for (base = XEN_SIGNATURE_LOWER; base < XEN_SIGNATURE_UPPER; base += 0x100) {
   17.29 +    __cpuid(cpuid_output, base);
   17.30 +    *(ULONG*)(xensig + 0) = cpuid_output[1];
   17.31 +    *(ULONG*)(xensig + 4) = cpuid_output[2];
   17.32 +    *(ULONG*)(xensig + 8) = cpuid_output[3];
   17.33 +    xensig[12] = '\0';
   17.34 +    FUNCTION_MSG("base = 0x%08x, Xen Signature = %s, EAX = 0x%08x\n", base, xensig, cpuid_output[0]);
   17.35 +    if (!strncmp("XenVMMXenVMM", xensig, 12) && ((cpuid_output[0] - base) >= 2))
   17.36 +      break;
   17.37 +  }
   17.38 +  if (base == XEN_SIGNATURE_UPPER) {
   17.39 +    FUNCTION_MSG("Cannot find Xen signature\n");
   17.40 +    return;
   17.41 +  }
   17.42 +
   17.43 +  __cpuid(cpuid_output, base + 1);
   17.44 +  xen_version_major = (USHORT)(cpuid_output[0] >> 16);
   17.45 +  xen_version_minor = (USHORT)(cpuid_output[0] & 0xFFFF);
   17.46 +  FUNCTION_MSG("Xen Version %d.%d\n", xen_version_major, xen_version_minor);
   17.47 +
   17.48 +  __cpuid(cpuid_output, base + 2);
   17.49 +  pages = cpuid_output[0];
   17.50 +  msr = cpuid_output[1];
   17.51 +
   17.52 +  hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
   17.53 +  FUNCTION_MSG("Hypercall area at %p\n", hypercall_stubs);
   17.54 +
   17.55 +  if (!hypercall_stubs)
   17.56 +    return;
   17.57 +  for (i = 0; i < pages; i++) {
   17.58 +    ULONGLONG pfn;
   17.59 +    pfn = (MmGetPhysicalAddress((PUCHAR)hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
   17.60 +    __writemsr(msr, (pfn << PAGE_SHIFT) + i);
   17.61 +  }
   17.62 +}
   17.63 +
   17.64 +static VOID
   17.65 +hvm_free_hypercall_stubs() {
   17.66 +  ExFreePoolWithTag(hypercall_stubs, XENPCI_POOL_TAG);
   17.67 +  hypercall_stubs = NULL;
   17.68 +}
   17.69 +
   17.70  static VOID
   17.71  XenPci_MapHalThenPatchKernel(PXENPCI_DEVICE_DATA xpdd)
   17.72  {
   17.73 @@ -111,12 +174,12 @@ XenPci_Init(PXENPCI_DEVICE_DATA xpdd)
   17.74  
   17.75    FUNCTION_ENTER();
   17.76  
   17.77 -  if (!xpdd->hypercall_stubs)
   17.78 +  if (!hypercall_stubs)
   17.79    {
   17.80      XN_ASSERT(KeGetCurrentIrql() <= DISPATCH_LEVEL);
   17.81 -    xpdd->hypercall_stubs = hvm_get_hypercall_stubs();
   17.82 +    hvm_get_hypercall_stubs();
   17.83    }
   17.84 -  if (!xpdd->hypercall_stubs)
   17.85 +  if (!hypercall_stubs)
   17.86      return STATUS_UNSUCCESSFUL;
   17.87  
   17.88    if (!xpdd->shared_info_area)
   17.89 @@ -133,7 +196,7 @@ XenPci_Init(PXENPCI_DEVICE_DATA xpdd)
   17.90    xatp.space = XENMAPSPACE_shared_info;
   17.91    xatp.gpfn = (xen_pfn_t)(xpdd->shared_info_area_unmapped.QuadPart >> PAGE_SHIFT);
   17.92    FUNCTION_MSG("gpfn = %x\n", xatp.gpfn);
   17.93 -  ret = HYPERVISOR_memory_op(xpdd, XENMEM_add_to_physmap, &xatp);
   17.94 +  ret = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
   17.95    FUNCTION_MSG("hypervisor memory op (XENMAPSPACE_shared_info) ret = %d\n", ret);
   17.96  
   17.97    FUNCTION_EXIT();
   17.98 @@ -270,13 +333,13 @@ XenPci_BalloonThreadProc(PVOID StartCont
   17.99          set_xen_guest_handle(reservation.extent_start, pfns);
  17.100          
  17.101          //FUNCTION_MSG("Calling HYPERVISOR_memory_op(XENMEM_populate_physmap) - pfn_count = %d\n", pfn_count);
  17.102 -        ret = HYPERVISOR_memory_op(xpdd, XENMEM_populate_physmap, &reservation);
  17.103 +        ret = HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
  17.104          //FUNCTION_MSG("populated %d pages\n", ret);
  17.105          if (ret < (ULONG)pfn_count) {
  17.106            if (ret > 0) {
  17.107              /* We hit the Xen hard limit: reprobe. */
  17.108              reservation.nr_extents = ret;
  17.109 -            ret = HYPERVISOR_memory_op(xpdd, XENMEM_decrease_reservation, &reservation);
  17.110 +            ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
  17.111              FUNCTION_MSG("decreased %d pages (xen is out of pages)\n", ret);
  17.112            }
  17.113            ExFreePoolWithTag(pfns, XENPCI_POOL_TAG);
  17.114 @@ -335,7 +398,7 @@ XenPci_BalloonThreadProc(PVOID StartCont
  17.115            #pragma warning(disable: 4127) /* conditional expression is constant */
  17.116            set_xen_guest_handle(reservation.extent_start, pfns);
  17.117            
  17.118 -          ret = HYPERVISOR_memory_op(xpdd, XENMEM_decrease_reservation, &reservation);
  17.119 +          ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation, &reservation);
  17.120            ExFreePoolWithTag(pfns, XENPCI_POOL_TAG);
  17.121            if (head) {
  17.122              mdl->Next = head;
  17.123 @@ -396,7 +459,7 @@ XenPci_Suspend0(PVOID context)
  17.124    sysenter_esp = __readmsr(0x175);
  17.125    sysenter_eip = __readmsr(0x176);
  17.126    
  17.127 -  cancelled = hvm_shutdown(xpdd, SHUTDOWN_suspend);
  17.128 +  cancelled = hvm_shutdown(SHUTDOWN_suspend);
  17.129  
  17.130    /* this code was to fix a bug that existed in Xen for a short time... it is harmless but can probably be removed */
  17.131    if (__readmsr(0x174) != sysenter_cs) {
    18.1 --- a/xenpci/xenpci_patch_kernel.c	Tue May 21 16:19:13 2013 +1000
    18.2 +++ b/xenpci/xenpci_patch_kernel.c	Sun Jun 02 16:37:21 2013 +1000
    18.3 @@ -329,7 +329,7 @@ MapVlapic(PXENPCI_DEVICE_DATA xpdd)
    18.4      xatp.space = XENMAPSPACE_vlapic;
    18.5      xatp.gpfn = (xen_pfn_t)(lapic_page[i].QuadPart >> PAGE_SHIFT);
    18.6      KdPrint((__DRIVER_NAME "     gpfn = %x\n", xatp.gpfn));
    18.7 -    rc = HYPERVISOR_memory_op(xpdd, XENMEM_add_to_physmap, &xatp);
    18.8 +    rc = HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
    18.9      KdPrint((__DRIVER_NAME "     hypervisor memory op (XENMAPSPACE_vlapic_regs) ret = %d\n", rc));
   18.10      if (rc != 0)
   18.11      {