win-pvdrivers

changeset 307:6b85686a16c0 wdm

really merged with default now i think
author James Harper <james.harper@bendigoit.com.au>
date Wed Jun 11 20:27:30 2008 +1000 (2008-06-11)
parents b4f7d75fbe24 5a7bfc1827a7
children 094537c517f5
files xenpci/xenpci.h
line diff
     1.1 --- a/common/include/public/arch-x86/xen.h	Wed Jun 11 20:18:33 2008 +1000
     1.2 +++ b/common/include/public/arch-x86/xen.h	Wed Jun 11 20:27:30 2008 +1000
     1.3 @@ -209,4 +209,5 @@ typedef struct arch_shared_info arch_sha
     1.4   * tab-width: 4
     1.5   * indent-tabs-mode: nil
     1.6   * End:
     1.7 - */
     1.8 \ No newline at end of file
     1.9 + */
    1.10 +
     2.1 --- a/common/include/xen_public.h	Wed Jun 11 20:18:33 2008 +1000
     2.2 +++ b/common/include/xen_public.h	Wed Jun 11 20:27:30 2008 +1000
     2.3 @@ -199,7 +199,9 @@ static __inline VOID
     2.4  __ADD_XEN_INIT_STRING(PUCHAR *ptr, PCHAR val)
     2.5  {
     2.6  //  KdPrint((__DRIVER_NAME "     ADD_XEN_INIT_STRING *ptr = %p, val = %s\n", *ptr, val));
     2.7 -  RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
     2.8 +  //RtlStringCbCopyA((PCHAR)*ptr, PAGE_SIZE - (PtrToUlong(*ptr) & (PAGE_SIZE - 1)), val);
     2.9 +  // using strcpy instead of above needed for mingw32
    2.10 +  strcpy((char *)ptr, val);
    2.11    *ptr += strlen(val) + 1;
    2.12  }
    2.13  
     3.1 --- a/common/include/xen_windows.h	Wed Jun 11 20:18:33 2008 +1000
     3.2 +++ b/common/include/xen_windows.h	Wed Jun 11 20:27:30 2008 +1000
     3.3 @@ -9,12 +9,23 @@
     3.4    #define __x86_64__
     3.5  #elif defined(_IA64_)
     3.6    #define __ia64__
     3.7 +#elif defined(__MINGW32__)
     3.8 +  /* __i386__ already defined */
     3.9  #elif defined(_X86_)
    3.10    #define __i386__
    3.11  #else
    3.12    #error Unknown architecture
    3.13  #endif
    3.14  
    3.15 +#ifdef __MINGW32__
    3.16 +typedef signed char int8_t;
    3.17 +typedef unsigned char uint8_t;
    3.18 +typedef signed short int16_t;
    3.19 +typedef unsigned short uint16_t;
    3.20 +typedef signed int int32_t;
    3.21 +typedef unsigned int uint32_t;
    3.22 +typedef unsigned long long uint64_t;
    3.23 +#else
    3.24  typedef INT8 int8_t;
    3.25  typedef UINT8 uint8_t;
    3.26  typedef INT16 int16_t;
    3.27 @@ -22,6 +33,7 @@ typedef UINT16 uint16_t;
    3.28  typedef INT32 int32_t;
    3.29  typedef UINT32 uint32_t;
    3.30  typedef UINT64 uint64_t;
    3.31 +#endif
    3.32  
    3.33  #include <xen.h>
    3.34  
     4.1 --- a/xenhide/xenhide.c	Wed Jun 11 20:18:33 2008 +1000
     4.2 +++ b/xenhide/xenhide.c	Wed Jun 11 20:27:30 2008 +1000
     4.3 @@ -51,7 +51,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
     4.4    ULONG BufLen = 200;
     4.5    PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
     4.6    int State = 0;
     4.7 -  int StartPos = 0;
     4.8 +  size_t StartPos = 0;
     4.9    WCHAR *SystemStartOptions;
    4.10    size_t SystemStartOptionsLen;
    4.11    size_t i;
     5.1 --- a/xennet/xennet_common.c	Wed Jun 11 20:18:33 2008 +1000
     5.2 +++ b/xennet/xennet_common.c	Wed Jun 11 20:27:30 2008 +1000
     5.3 @@ -200,13 +200,15 @@ PMDL
     5.4  XenFreelist_GetPage(freelist_t *fl)
     5.5  {
     5.6    PMDL mdl;
     5.7 +  PFN_NUMBER pfn;
     5.8  
     5.9    if (fl->page_free == 0)
    5.10    {
    5.11      mdl = AllocatePagesExtra(1, sizeof(grant_ref_t));
    5.12 +    pfn = *MmGetMdlPfnArray(mdl);
    5.13      *(grant_ref_t *)(((UCHAR *)mdl) + MmSizeOfMdl(0, PAGE_SIZE)) = fl->xi->vectors.GntTbl_GrantAccess(
    5.14        fl->xi->vectors.context, 0,
    5.15 -      (ULONG)*MmGetMdlPfnArray(mdl), FALSE, 0);
    5.16 +      (uint32_t)pfn, FALSE, 0);
    5.17    }
    5.18    else
    5.19    {
     6.1 --- a/xennet/xennet_rx.c	Wed Jun 11 20:18:33 2008 +1000
     6.2 +++ b/xennet/xennet_rx.c	Wed Jun 11 20:27:30 2008 +1000
     6.3 @@ -29,7 +29,9 @@ XenNet_RxBufferAlloc(struct xennet_info 
     6.4    int i, batch_target, notify;
     6.5    RING_IDX req_prod = xi->rx.req_prod_pvt;
     6.6    netif_rx_request_t *req;
     6.7 +#if DBG
     6.8    int cycles = 0;
     6.9 +#endif
    6.10  #if defined(XEN_PROFILE)
    6.11    LARGE_INTEGER tsc, dummy;
    6.12  #endif
    6.13 @@ -363,7 +365,9 @@ XenNet_RxBufferCheck(struct xennet_info 
    6.14    struct netif_rx_response *rxrsp = NULL;
    6.15    struct netif_extra_info *ei;
    6.16    USHORT id;
    6.17 +#if DBG
    6.18    int cycles = 0;
    6.19 +#endif
    6.20  #if defined(XEN_PROFILE)
    6.21    LARGE_INTEGER tsc, dummy;
    6.22  #endif
    6.23 @@ -497,7 +501,9 @@ XenNet_ReturnPacket(
    6.24  {
    6.25    struct xennet_info *xi = MiniportAdapterContext;
    6.26    PMDL mdl;
    6.27 +#if DBG
    6.28    int cycles = 0;
    6.29 +#endif
    6.30  #if defined(XEN_PROFILE)
    6.31    LARGE_INTEGER tsc, dummy;
    6.32  #endif
     7.1 --- a/xennet/xennet_tx.c	Wed Jun 11 20:18:33 2008 +1000
     7.2 +++ b/xennet/xennet_tx.c	Wed Jun 11 20:27:30 2008 +1000
     7.3 @@ -251,8 +251,10 @@ XenNet_SendQueuedPackets(struct xennet_i
     7.4  #if defined(XEN_PROFILE)
     7.5    LARGE_INTEGER tsc, dummy;
     7.6  #endif
     7.7 -  
     7.8 +
     7.9 +#if DBG
    7.10    int cycles = 0;
    7.11 +#endif
    7.12    BOOLEAN success;
    7.13  
    7.14  #if defined(XEN_PROFILE)
    7.15 @@ -297,7 +299,9 @@ XenNet_TxBufferGC(struct xennet_info *xi
    7.16    ULONG packet_count = 0;
    7.17    int moretodo;
    7.18    ULONG i;
    7.19 +#if DBG
    7.20    int cycles = 0;
    7.21 +#endif
    7.22  #if defined(XEN_PROFILE)
    7.23    LARGE_INTEGER tsc, dummy;
    7.24  #endif
     8.1 --- a/xenpci/evtchn.c	Wed Jun 11 20:18:33 2008 +1000
     8.2 +++ b/xenpci/evtchn.c	Wed Jun 11 20:27:30 2008 +1000
     8.3 @@ -19,7 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     8.4  
     8.5  #include "xenpci.h"
     8.6  
     8.7 -#if defined(_X86_)
     8.8 +#if defined(_WIN32)
     8.9    #define xchg(p1, p2) _InterlockedExchange(p1, p2)
    8.10    #define synch_clear_bit(p1, p2) _interlockedbittestandreset(p2, p1)
    8.11    #define synch_set_bit(p1, p2) _interlockedbittestandset(p2, p1)
     9.1 --- a/xenpci/gnttbl.c	Wed Jun 11 20:18:33 2008 +1000
     9.2 +++ b/xenpci/gnttbl.c	Wed Jun 11 20:27:30 2008 +1000
     9.3 @@ -74,7 +74,7 @@ grant_ref_t
     9.4  GntTbl_GrantAccess(
     9.5    PVOID Context,
     9.6    domid_t domid,
     9.7 -  uint32_t frame,
     9.8 +  uint32_t frame, // xen api limits pfn to 32bit, so no guests over 8TB
     9.9    int readonly,
    9.10    grant_ref_t ref)
    9.11  {
    10.1 --- a/xenpci/hypercall.h	Wed Jun 11 20:18:33 2008 +1000
    10.2 +++ b/xenpci/hypercall.h	Wed Jun 11 20:27:30 2008 +1000
    10.3 @@ -17,8 +17,12 @@ along with this program; if not, write t
    10.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    10.5  */
    10.6  
    10.7 -#if defined(_X86_)
    10.8 -  #include "hypercall_x86.h"
    10.9 +#if defined(_X86_)
   10.10 +  #if defined(__MINGW32__)
   10.11 +    #include "hypercall_x86_mingw.h"
   10.12 +  #else
   10.13 +    #include "hypercall_x86.h"
   10.14 +  #endif
   10.15  #else
   10.16    #if defined(_AMD64_)
   10.17      #include "hypercall_amd64.h"
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/xenpci/hypercall_x86_mingw.h	Wed Jun 11 20:27:30 2008 +1000
    11.3 @@ -0,0 +1,139 @@
    11.4 +/*
    11.5 +PV Drivers for Windows Xen HVM Domains
    11.6 +Copyright (C) 2007 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 +#define __STR(x) #x
   11.24 +#define STR(x) __STR(x)
   11.25 +
   11.26 +#define HYPERCALL_STR(name)					\
   11.27 +	"mov $xpdd->hypercall_stubs,%%eax; "				\
   11.28 +	"add $("STR(__HYPERVISOR_##name)" * 32),%%eax; "	\
   11.29 +	"call *%%eax"
   11.30 +
   11.31 +#define _hypercall2(type, name, a1, a2)                         \
   11.32 +({                                                              \
   11.33 +        long __res, __ign1, __ign2;                             \
   11.34 +        asm volatile (                                          \
   11.35 +                HYPERCALL_STR(name)                             \
   11.36 +                : "=a" (__res), "=b" (__ign1), "=c" (__ign2)    \
   11.37 +                : "1" ((long)(a1)), "2" ((long)(a2))            \
   11.38 +                : "memory" );                                   \
   11.39 +        (type)__res;                                            \
   11.40 +})
   11.41 +
   11.42 +#define _hypercall3(type, name, a1, a2, a3)			\
   11.43 +({								\
   11.44 +	long __res, __ign1, __ign2, __ign3;			\
   11.45 +	asm volatile (						\
   11.46 +		HYPERCALL_STR(name)				\
   11.47 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2), 	\
   11.48 +		"=d" (__ign3)					\
   11.49 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
   11.50 +		"3" ((long)(a3))				\
   11.51 +		: "memory" );					\
   11.52 +	(type)__res;						\
   11.53 +})
   11.54 +
   11.55 +#define _hypercall4(type, name, a1, a2, a3, a4)			\
   11.56 +({								\
   11.57 +	long __res, __ign1, __ign2, __ign3, __ign4;		\
   11.58 +	asm volatile (						\
   11.59 +		HYPERCALL_STR(name)				\
   11.60 +		: "=a" (__res), "=b" (__ign1), "=c" (__ign2),	\
   11.61 +		"=d" (__ign3), "=S" (__ign4)			\
   11.62 +		: "1" ((long)(a1)), "2" ((long)(a2)),		\
   11.63 +		"3" ((long)(a3)), "4" ((long)(a4))		\
   11.64 +		: "memory" );					\
   11.65 +	(type)__res;						\
   11.66 +})
   11.67 +
   11.68 +static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
   11.69 +                         unsigned int *ecx, unsigned int *edx)
   11.70 +{
   11.71 +  __asm__("cpuid"
   11.72 +          : "=a" (*eax),
   11.73 +            "=b" (*ebx),
   11.74 +            "=c" (*ecx),
   11.75 +            "=d" (*edx)
   11.76 +          : "0" (op));
   11.77 +}
   11.78 +
   11.79 +static __inline void __cpuid(uint32_t output[4], uint32_t op)
   11.80 +{
   11.81 +  cpuid(op, &output[0], &output[1], &output[2], &output[3]);
   11.82 +}
   11.83 +
   11.84 +static __inline void __writemsr(uint32_t msr, uint64_t value)
   11.85 +{
   11.86 +  uint32_t hi, lo;
   11.87 +  hi = value >> 32;
   11.88 +  lo = value & 0xFFFFFFFF;
   11.89 +
   11.90 +  __asm__ __volatile__("wrmsr" \
   11.91 +                       : /* no outputs */ \
   11.92 +                       : "c" (msr), "a" (lo), "d" (hi));
   11.93 +}
   11.94 +
   11.95 +static __inline int
   11.96 +HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
   11.97 +{
   11.98 +  return _hypercall2(int, memory_op, cmd, arg);
   11.99 +}
  11.100 +
  11.101 +static __inline int
  11.102 +HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
  11.103 +{
  11.104 +  return _hypercall2(int, sched_op, cmd, arg);
  11.105 +}
  11.106 +
  11.107 +static __inline int
  11.108 +HYPERVISOR_xen_version(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
  11.109 +{
  11.110 +  return _hypercall2(int, xen_version, cmd, arg);
  11.111 +}
  11.112 +
  11.113 +static __inline int
  11.114 +HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
  11.115 +{
  11.116 +	return _hypercall3(int, grant_table_op, cmd, uop, count);
  11.117 +}
  11.118 +
  11.119 +static __inline int
  11.120 +HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
  11.121 +{
  11.122 +	return _hypercall4(int, mmu_update, req, count, success_count, domid);
  11.123 +}
  11.124 +
  11.125 +static __inline int
  11.126 +HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
  11.127 +{
  11.128 +	return _hypercall3(int, console_io, cmd, count, string);
  11.129 +}
  11.130 +
  11.131 +static __inline int
  11.132 +HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xpdd, int op, struct xen_hvm_param *arg)
  11.133 +{
  11.134 +  return _hypercall2(unsigned long, hvm_op, op, arg);
  11.135 +}
  11.136 +
  11.137 +static __inline int
  11.138 +HYPERVISOR_event_channel_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
  11.139 +{
  11.140 +	return _hypercall2(int, event_channel_op, cmd, arg);
  11.141 +}
  11.142 +
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/xenpci/makefile.mingw	Wed Jun 11 20:27:30 2008 +1000
    12.3 @@ -0,0 +1,9 @@
    12.4 +CFLAGS = -Wall -I/usr/i586-mingw32msvc/include/ddk/ -I../common/include -I../common/include/public
    12.5 +
    12.6 +xenpci.sys: xenpci.c 
    12.7 +	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s -shared -Wl,--entry,_load@8 -nostdlib $^ -lntoskrnl -lhal
    12.8 +
    12.9 +test.exe: test.c kexec.h
   12.10 +	i586-mingw32msvc-gcc $(CFLAGS) -o $@ -s $^ -lkernel32
   12.11 +
   12.12 +all: xenpci.sys
    13.1 --- a/xenpci/xenpci.h	Wed Jun 11 20:18:33 2008 +1000
    13.2 +++ b/xenpci/xenpci.h	Wed Jun 11 20:27:30 2008 +1000
    13.3 @@ -24,14 +24,16 @@ Foundation, Inc., 51 Franklin Street, Fi
    13.4  #define EISCONN 127
    13.5  
    13.6  #include <ntddk.h>
    13.7 +
    13.8 +#ifndef __MINGW32__
    13.9  #include <wdm.h>
   13.10  //#include <wdf.h>
   13.11  #include <initguid.h>
   13.12  #include <wdmguid.h>
   13.13  #include <errno.h>
   13.14 -
   13.15  #define NTSTRSAFE_LIB
   13.16  #include <ntstrsafe.h>
   13.17 +#endif
   13.18  
   13.19  #define __DRIVER_NAME "XenPCI"
   13.20  
   13.21 @@ -133,19 +135,19 @@ typedef struct
   13.22    ULONG device_usage_hibernation;
   13.23  } XENPCI_COMMON, *PXENPCI_COMMON;
   13.24  
   13.25 -static __inline INIT_PNP_STATE(PXENPCI_COMMON common)
   13.26 +static __inline void INIT_PNP_STATE(PXENPCI_COMMON common)
   13.27  {
   13.28    common->current_pnp_state = NotStarted;
   13.29    common->previous_pnp_state = NotStarted;
   13.30  }
   13.31  
   13.32 -static __inline SET_PNP_STATE(PXENPCI_COMMON common, DEVICE_PNP_STATE state)
   13.33 +static __inline void SET_PNP_STATE(PXENPCI_COMMON common, DEVICE_PNP_STATE state)
   13.34  {
   13.35    common->previous_pnp_state = common->current_pnp_state;
   13.36    common->current_pnp_state = state;
   13.37  }
   13.38  
   13.39 -static __inline REVERT_PNP_STATE(PXENPCI_COMMON common)
   13.40 +static __inline void REVERT_PNP_STATE(PXENPCI_COMMON common)
   13.41  {
   13.42    common->current_pnp_state = common->previous_pnp_state;
   13.43  }
   13.44 @@ -200,7 +202,7 @@ typedef struct {
   13.45    KSPIN_LOCK WatchLock;
   13.46    KSPIN_LOCK grant_lock;
   13.47  
   13.48 -  KGUARDED_MUTEX WatchHandlerMutex;
   13.49 +  //KGUARDED_MUTEX WatchHandlerMutex;
   13.50  
   13.51    LIST_ENTRY child_list;
   13.52    
   13.53 @@ -237,7 +239,6 @@ typedef struct {
   13.54    grant_ref_t grant_refs[MAX_RESOURCES];
   13.55    PMDL mdls[MAX_RESOURCES];
   13.56    evtchn_port_t event_channels[MAX_RESOURCES];
   13.57 -  PMDL config_mdl;
   13.58  } XENPCI_PDO_DEVICE_DATA, *PXENPCI_PDO_DEVICE_DATA;
   13.59  
   13.60  typedef struct
   13.61 @@ -292,7 +293,7 @@ sw_interrupt(UCHAR intno)
   13.62      KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000002, (ULONG)intno, 0x00000000, 0x00000000);
   13.63      break;
   13.64    }
   13.65 -}    
   13.66 +}
   13.67  #else
   13.68  VOID _sw_interrupt(UCHAR);
   13.69