win-pvdrivers

changeset 126:b722a577ed90

More work on adding AMD64 support
author James Harper <james.harper@bendigoit.com.au>
date Wed Jan 16 23:58:02 2008 +1100 (2008-01-16)
parents 403f2c20466e
children 0b87815a2ee7
files xenpci/amd64/hypercall.asm xenpci/hypercall_amd64.h xenpci/i386/hypercall.asm xenpci/sources xenpci/xenpci.c xenpci/xenpci.h xenpci/xenpci.inx
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xenpci/amd64/hypercall.asm	Wed Jan 16 23:58:02 2008 +1100
     1.3 @@ -0,0 +1,34 @@
     1.4 +.data
     1.5 +
     1.6 +; look up 'fastcall' in the ddk help for the calling convention for amd64
     1.7 +
     1.8 +; called with
     1.9 +;  address of function in rcx
    1.10 +;  p1 in rdx
    1.11 +;  p2 in r8
    1.12 +
    1.13 +; linux code is
    1.14 +; #define _hypercall2(type, name, a1, a2)
    1.15 +; ({
    1.16 +;   long __res, __ign1, __ign2;
    1.17 +;   asm volatile (
    1.18 +;     "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
    1.19 +;     : "=a" (__res), "=D" (__ign1), "=S" (__ign2)
    1.20 +;     : "1" ((long)(a1)), "2" ((long)(a2))
    1.21 +;     : "memory" );
    1.22 +;   (type)__res;
    1.23 +; })
    1.24 +
    1.25 +.code
    1.26 +_hypercall2 proc
    1.27 +    push rdi
    1.28 +    push rsi
    1.29 +    mov rdi, rdx
    1.30 +    mov rsi, r8
    1.31 +    mov rax, rcx
    1.32 +    call rax
    1.33 +    pop rsi
    1.34 +    pop rdi
    1.35 +    ret
    1.36 +_hypercall2 endp
    1.37 +END
    1.38 \ No newline at end of file
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/xenpci/hypercall_amd64.h	Wed Jan 16 23:58:02 2008 +1100
     2.3 @@ -0,0 +1,178 @@
     2.4 +/*
     2.5 +PV Drivers for Windows Xen HVM Domains
     2.6 +Copyright (C) 2007 James Harper
     2.7 +
     2.8 +This program is free software; you can redistribute it and/or
     2.9 +modify it under the terms of the GNU General Public License
    2.10 +as published by the Free Software Foundation; either version 2
    2.11 +of the License, or (at your option) any later version.
    2.12 +
    2.13 +This program is distributed in the hope that it will be useful,
    2.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.16 +GNU General Public License for more details.
    2.17 +
    2.18 +You should have received a copy of the GNU General Public License
    2.19 +along with this program; if not, write to the Free Software
    2.20 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    2.21 +*/
    2.22 +
    2.23 +extern int _hypercall2(VOID *address, int cmd, void *arg);
    2.24 +
    2.25 +static __inline int
    2.26 +HYPERVISOR_memory_op(WDFDEVICE Device, int cmd, void *arg)
    2.27 +{
    2.28 +  PCHAR memory_op_func = GetDeviceData(Device)->hypercall_stubs;
    2.29 +  memory_op_func += __HYPERVISOR_memory_op * 32;
    2.30 +  return _hypercall2(memory_op_func, cmd, arg);
    2.31 +  
    2.32 +/*
    2.33 +  long __res;
    2.34 +  __asm {
    2.35 +    mov ebx, cmd
    2.36 +    mov ecx, arg
    2.37 +    mov eax, hypercall_stubs
    2.38 +    add eax, (__HYPERVISOR_memory_op * 32)
    2.39 +    call eax
    2.40 +    mov [__res], eax
    2.41 +  }
    2.42 +  return __res;
    2.43 +*/
    2.44 +}
    2.45 +
    2.46 +static __inline int
    2.47 +HYPERVISOR_xen_version(WDFDEVICE Device, int cmd, void *arg)
    2.48 +{
    2.49 +/*
    2.50 +  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.51 +  long __res;
    2.52 +  __asm {
    2.53 +    mov ebx, cmd
    2.54 +    mov ecx, arg
    2.55 +    mov eax, hypercall_stubs
    2.56 +    add eax, (__HYPERVISOR_xen_version * 32)
    2.57 +    call eax
    2.58 +    mov [__res], eax
    2.59 +  }
    2.60 +  return __res;
    2.61 +*/
    2.62 +  return -1;
    2.63 +}
    2.64 +
    2.65 +static __inline int
    2.66 +HYPERVISOR_grant_table_op(WDFDEVICE Device, int cmd, void *uop, unsigned int count)
    2.67 +{
    2.68 +/*
    2.69 +  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.70 +  long __res;
    2.71 +  __asm {
    2.72 +    mov ebx, cmd
    2.73 +    mov ecx, uop
    2.74 +    mov edx, count
    2.75 +    mov eax, hypercall_stubs
    2.76 +    add eax, (__HYPERVISOR_grant_table_op * 32)
    2.77 +    call eax
    2.78 +    mov [__res], eax
    2.79 +  }
    2.80 +  return __res;
    2.81 +*/
    2.82 +  return -1;
    2.83 +}
    2.84 +
    2.85 +static __inline int
    2.86 +HYPERVISOR_mmu_update(WDFDEVICE Device, mmu_update_t *req, int count, int *success_count, domid_t domid)
    2.87 +{
    2.88 +/*
    2.89 +  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.90 +  long __res;
    2.91 +  long _domid = (long)domid;
    2.92 +  __asm {
    2.93 +    mov ebx, req
    2.94 +    mov ecx, count
    2.95 +    mov edx, success_count
    2.96 +    mov edi, _domid
    2.97 +    mov eax, hypercall_stubs
    2.98 +    add eax, (__HYPERVISOR_mmu_update * 32)
    2.99 +    call eax
   2.100 +    mov [__res], eax
   2.101 +  }
   2.102 +  return __res;
   2.103 +*/
   2.104 +  return -1;
   2.105 +}
   2.106 +
   2.107 +static __inline int
   2.108 +HYPERVISOR_console_io(WDFDEVICE Device, int cmd, int count, char *string)
   2.109 +{
   2.110 +/*
   2.111 +  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
   2.112 +  long __res;
   2.113 +  __asm {
   2.114 +    mov ebx, cmd
   2.115 +    mov ecx, count
   2.116 +    mov edx, string
   2.117 +    mov eax, hypercall_stubs
   2.118 +    add eax, (__HYPERVISOR_console_io * 32)
   2.119 +    call eax
   2.120 +    mov [__res], eax
   2.121 +  }
   2.122 +  return __res;
   2.123 +*/
   2.124 +  return -1;
   2.125 +}
   2.126 +
   2.127 +static __inline int
   2.128 +HYPERVISOR_hvm_op(WDFDEVICE Device, int op, struct xen_hvm_param *arg)
   2.129 +{
   2.130 +  PCHAR hvm_op_func = GetDeviceData(Device)->hypercall_stubs;
   2.131 +  hvm_op_func += __HYPERVISOR_memory_op * 32;
   2.132 +  return _hypercall2(hvm_op_func, op, arg);
   2.133 +/*
   2.134 +  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
   2.135 +  long __res;
   2.136 +  __asm {
   2.137 +    mov ebx, op
   2.138 +    mov ecx, arg
   2.139 +    mov eax, hypercall_stubs
   2.140 +    add eax, (__HYPERVISOR_hvm_op * 32)
   2.141 +    call eax
   2.142 +    mov [__res], eax
   2.143 +  }
   2.144 +  return __res;
   2.145 +*/
   2.146 +}
   2.147 +
   2.148 +static __inline int
   2.149 +HYPERVISOR_event_channel_op(WDFDEVICE Device, int cmd, void *op)
   2.150 +{
   2.151 +/*
   2.152 +  char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
   2.153 +  long __res;
   2.154 +  __asm {
   2.155 +    mov ebx, cmd
   2.156 +    mov ecx, op
   2.157 +    mov eax, hypercall_stubs
   2.158 +    add eax, (__HYPERVISOR_event_channel_op * 32)
   2.159 +    call eax
   2.160 +    mov [__res], eax
   2.161 +  }
   2.162 +  return __res;
   2.163 +*/
   2.164 +  return -1;
   2.165 +}
   2.166 +
   2.167 +static __inline ULONGLONG
   2.168 +hvm_get_parameter(WDFDEVICE Device, int hvm_param)
   2.169 +{
   2.170 +  struct xen_hvm_param a;
   2.171 +  int retval;
   2.172 +
   2.173 +  KdPrint((__DRIVER_NAME " --> hvm_get_parameter\n"));
   2.174 +  a.domid = DOMID_SELF;
   2.175 +  a.index = hvm_param;
   2.176 +  //a.value = via;
   2.177 +  retval = HYPERVISOR_hvm_op(Device, HVMOP_get_param, &a);
   2.178 +  KdPrint((__DRIVER_NAME " hvm_get_parameter retval = %d\n", retval));
   2.179 +  KdPrint((__DRIVER_NAME " <-- hvm_get_parameter\n"));
   2.180 +  return a.value;
   2.181 +}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/xenpci/i386/hypercall.asm	Wed Jan 16 23:58:02 2008 +1100
     3.3 @@ -0,0 +1,2 @@
     3.4 +;nothing to do here for x86
     3.5 +END
     3.6 \ No newline at end of file
     4.1 --- a/xenpci/sources	Wed Jan 16 21:55:48 2008 +1100
     4.2 +++ b/xenpci/sources	Wed Jan 16 23:58:02 2008 +1100
     4.3 @@ -1,7 +1,7 @@
     4.4  TARGETNAME=XENPCI
     4.5  TARGETTYPE=DRIVER
     4.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     4.7 -VERSION=0.5.0.24
     4.8 +VERSION=0.5.0.27
     4.9  KMDF_VERSION=1
    4.10  MSC_WARNING_LEVEL=/W4
    4.11  INF_NAME=xenpci
    4.12 @@ -9,4 +9,4 @@ INCLUDES = ..\common\include;..\common\i
    4.13  TARGETLIBS=$(DDK_LIB_PATH)\ntstrsafe.lib
    4.14  MISCFILES=$(TARGETPATH)\$(INF_NAME).inf
    4.15  NTTARGETFILES=
    4.16 -SOURCES=xenpci.c xenbus.c gnttbl.c evtchn.c
    4.17 +SOURCES=xenpci.c xenbus.c gnttbl.c evtchn.c hypercall.asm
     5.1 --- a/xenpci/xenpci.c	Wed Jan 16 21:55:48 2008 +1100
     5.2 +++ b/xenpci/xenpci.c	Wed Jan 16 23:58:02 2008 +1100
     5.3 @@ -300,7 +300,7 @@ init_xen_info(WDFDEVICE Device)
     5.4    xatp.space = XENMAPSPACE_shared_info;
     5.5    xatp.gpfn = (xen_pfn_t)(shared_info_area_unmapped.QuadPart >> PAGE_SHIFT);
     5.6    ret = HYPERVISOR_memory_op(Device, XENMEM_add_to_physmap, &xatp);
     5.7 -  //KdPrint((__DRIVER_NAME " ret = %d\n", ret));
     5.8 +  KdPrint((__DRIVER_NAME " hypervisor memory op ret = %d\n", ret));
     5.9  
    5.10    xpdd->shared_info_area = MmMapIoSpace(shared_info_area_unmapped,
    5.11      PAGE_SIZE, MmNonCached);
    5.12 @@ -314,13 +314,13 @@ set_callback_irq(WDFDEVICE Device, ULONG
    5.13    struct xen_hvm_param a;
    5.14    int retval;
    5.15  
    5.16 -  //KdPrint((__DRIVER_NAME " --> set_callback_irq\n"));
    5.17 +  KdPrint((__DRIVER_NAME " --> set_callback_irq\n"));
    5.18    a.domid = DOMID_SELF;
    5.19    a.index = HVM_PARAM_CALLBACK_IRQ;
    5.20    a.value = irq;
    5.21    retval = HYPERVISOR_hvm_op(Device, HVMOP_set_param, &a);
    5.22 -  //KdPrint((__DRIVER_NAME " HYPERVISOR_hvm_op retval = %d\n", retval));
    5.23 -  //KdPrint((__DRIVER_NAME " <-- set_callback_irq\n"));
    5.24 +  KdPrint((__DRIVER_NAME " HYPERVISOR_hvm_op retval = %d\n", retval));
    5.25 +  KdPrint((__DRIVER_NAME " <-- set_callback_irq\n"));
    5.26    return retval;
    5.27  }
    5.28  
     6.1 --- a/xenpci/xenpci.h	Wed Jan 16 21:55:48 2008 +1100
     6.2 +++ b/xenpci/xenpci.h	Wed Jan 16 23:58:02 2008 +1100
     6.3 @@ -143,7 +143,13 @@ typedef struct {
     6.4  
     6.5  WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(XENPCI_DEVICE_DATA, GetDeviceData);
     6.6  
     6.7 -#include "hypercall_x86.h"
     6.8 +#if defined(_X86_)
     6.9 +  #include "hypercall_x86.h"
    6.10 +#else
    6.11 +  #if defined(_AMD64_)
    6.12 +    #include "hypercall_amd64.h"
    6.13 +  #endif
    6.14 +#endif
    6.15  
    6.16  typedef unsigned long xenbus_transaction_t;
    6.17  typedef uint32_t XENSTORE_RING_IDX;
     7.1 --- a/xenpci/xenpci.inx	Wed Jan 16 21:55:48 2008 +1100
     7.2 +++ b/xenpci/xenpci.inx	Wed Jan 16 23:58:02 2008 +1100
     7.3 @@ -14,7 +14,8 @@ CoInstaller_CopyFiles = 11
     7.4  ExcludeFromSelect=*
     7.5  
     7.6  [Manufacturer]
     7.7 -%JAMESHARPER%=JAMESHARPER,NT$ARCH$
     7.8 +%JAMESHARPER%=JAMESHARPER,NTx86
     7.9 +%JAMESHARPER%=JAMESHARPER,NTAMD64
    7.10  
    7.11  ; For Win2K
    7.12  ;[JAMESHARPER]
    7.13 @@ -22,7 +23,10 @@ ExcludeFromSelect=*
    7.14  ; -----------       	 -------           --------
    7.15  ;%XenPCI.DRVDESC%=XenPCI_Inst, PCI\VEN_5853&DEV_0001
    7.16  
    7.17 -[JAMESHARPER.NT$ARCH$]
    7.18 +[JAMESHARPER.NTx86]
    7.19 +%XenPCI.DRVDESC%=XenPCI_Inst, PCI\VEN_5853&DEV_0001
    7.20 +
    7.21 +[JAMESHARPER.NTAMD64]
    7.22  %XenPCI.DRVDESC%=XenPCI_Inst, PCI\VEN_5853&DEV_0001
    7.23  
    7.24  [XenPCI_Inst.NT]
    7.25 @@ -35,9 +39,11 @@ xenpci.sys
    7.26  xenpci.sys=1
    7.27  WdfCoinstaller01005.dll=1,,
    7.28  
    7.29 -[SourceDisksNames]
    7.30 +[SourceDisksNames.x86]
    7.31  1 = %DISK_NAME%,,,\i386
    7.32 -;1 = %DISK_NAME%,,,\i386
    7.33 +
    7.34 +[SourceDisksNames.amd64]
    7.35 +1 = %DISK_NAME%,,,\amd64
    7.36  
    7.37  [XenPCI_Inst.NT.Services]
    7.38  AddService=XenPCI,2,XenPCI_Service