win-pvdrivers

changeset 145:e1ec2bacd4b0

Trying to get AMD64 working. sizeof(long) != sizeof(void *) under AMD64
author James Harper <james.harper@bendigoit.com.au>
date Wed Jan 23 13:00:43 2008 +1100 (2008-01-23)
parents af3f6972fe54
children b474e898b409
files xenpci/amd64/hypercall.asm xenpci/hypercall_amd64.h xenpci/sources xenpci/xenbus.c xenpci/xenpci.c xenpci/xenpci.h
line diff
     1.1 --- a/xenpci/amd64/hypercall.asm	Tue Jan 22 20:02:17 2008 +1100
     1.2 +++ b/xenpci/amd64/hypercall.asm	Wed Jan 23 13:00:43 2008 +1100
     1.3 @@ -31,4 +31,4 @@
     1.4      pop rdi
     1.5      ret
     1.6  _hypercall2 endp
     1.7 -END
     1.8 \ No newline at end of file
     1.9 +END
     2.1 --- a/xenpci/hypercall_amd64.h	Tue Jan 22 20:02:17 2008 +1100
     2.2 +++ b/xenpci/hypercall_amd64.h	Wed Jan 23 13:00:43 2008 +1100
     2.3 @@ -43,6 +43,9 @@ HYPERVISOR_memory_op(WDFDEVICE Device, i
     2.4  static __inline int
     2.5  HYPERVISOR_xen_version(WDFDEVICE Device, int cmd, void *arg)
     2.6  {
     2.7 +  PCHAR xen_version_func = GetDeviceData(Device)->hypercall_stubs;
     2.8 +  xen_version_func += __HYPERVISOR_xen_version * 32;
     2.9 +  return _hypercall2(xen_version_func, cmd, arg);
    2.10  /*
    2.11    char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.12    long __res;
    2.13 @@ -56,12 +59,12 @@ HYPERVISOR_xen_version(WDFDEVICE Device,
    2.14    }
    2.15    return __res;
    2.16  */
    2.17 -  return -1;
    2.18  }
    2.19  
    2.20  static __inline int
    2.21  HYPERVISOR_grant_table_op(WDFDEVICE Device, int cmd, void *uop, unsigned int count)
    2.22  {
    2.23 +  ASSERTMSG("grant_table_op not yet supported under AMD64", FALSE);
    2.24  /*
    2.25    char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.26    long __res;
    2.27 @@ -82,6 +85,7 @@ HYPERVISOR_grant_table_op(WDFDEVICE Devi
    2.28  static __inline int
    2.29  HYPERVISOR_mmu_update(WDFDEVICE Device, mmu_update_t *req, int count, int *success_count, domid_t domid)
    2.30  {
    2.31 +  ASSERTMSG("mmu_update not yet supported under AMD64", FALSE);
    2.32  /*
    2.33    char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.34    long __res;
    2.35 @@ -104,6 +108,7 @@ HYPERVISOR_mmu_update(WDFDEVICE Device, 
    2.36  static __inline int
    2.37  HYPERVISOR_console_io(WDFDEVICE Device, int cmd, int count, char *string)
    2.38  {
    2.39 +  ASSERTMSG("consoile_io not yet supported under AMD64", FALSE);
    2.40  /*
    2.41    char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.42    long __res;
    2.43 @@ -145,6 +150,9 @@ HYPERVISOR_hvm_op(WDFDEVICE Device, int 
    2.44  static __inline int
    2.45  HYPERVISOR_event_channel_op(WDFDEVICE Device, int cmd, void *op)
    2.46  {
    2.47 +  PCHAR event_channel_op_func = GetDeviceData(Device)->hypercall_stubs;
    2.48 +  event_channel_op_func += __HYPERVISOR_event_channel_op * 32;
    2.49 +  return _hypercall2(event_channel_op_func, cmd, op);
    2.50  /*
    2.51    char *hypercall_stubs = GetDeviceData(Device)->hypercall_stubs;
    2.52    long __res;
    2.53 @@ -158,7 +166,6 @@ HYPERVISOR_event_channel_op(WDFDEVICE De
    2.54    }
    2.55    return __res;
    2.56  */
    2.57 -  return -1;
    2.58  }
    2.59  
    2.60  static __inline ULONGLONG
    2.61 @@ -170,7 +177,6 @@ hvm_get_parameter(WDFDEVICE Device, int 
    2.62    KdPrint((__DRIVER_NAME " --> hvm_get_parameter\n"));
    2.63    a.domid = DOMID_SELF;
    2.64    a.index = hvm_param;
    2.65 -  //a.value = via;
    2.66    retval = HYPERVISOR_hvm_op(Device, HVMOP_get_param, &a);
    2.67    KdPrint((__DRIVER_NAME " hvm_get_parameter retval = %d\n", retval));
    2.68    KdPrint((__DRIVER_NAME " <-- hvm_get_parameter\n"));
     3.1 --- a/xenpci/sources	Tue Jan 22 20:02:17 2008 +1100
     3.2 +++ b/xenpci/sources	Wed Jan 23 13:00:43 2008 +1100
     3.3 @@ -1,7 +1,7 @@
     3.4  TARGETNAME=XENPCI
     3.5  TARGETTYPE=DRIVER
     3.6  TARGETPATH=..\Target\$(DDK_TARGET_OS)
     3.7 -VERSION=0.6.0.0
     3.8 +VERSION=0.6.0.5	
     3.9  KMDF_VERSION=1
    3.10  MSC_WARNING_LEVEL=/W4
    3.11  INF_NAME=xenpci
     4.1 --- a/xenpci/xenbus.c	Tue Jan 22 20:02:17 2008 +1100
     4.2 +++ b/xenpci/xenbus.c	Wed Jan 23 13:00:43 2008 +1100
     4.3 @@ -143,8 +143,8 @@ static void xb_write(
     4.4  //  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
     4.5  
     4.6    for (r = 0; r < nr_reqs; r++)
     4.7 -    len += req[r].len;
     4.8 -  m.len = len;
     4.9 +    len += (size_t)req[r].len;
    4.10 +  m.len = (ULONG)len;
    4.11    len += sizeof(m);
    4.12  
    4.13    cur_req = &header_req;
    4.14 @@ -175,7 +175,7 @@ static void xb_write(
    4.15    {
    4.16      this_chunk = min(cur_req->len - req_off,XENSTORE_RING_SIZE - MASK_XENSTORE_IDX(prod));
    4.17      memcpy((char *)xpdd->xen_store_interface->req + MASK_XENSTORE_IDX(prod), (char *)cur_req->data + req_off, this_chunk);
    4.18 -    prod += this_chunk;
    4.19 +    prod += (XENSTORE_RING_IDX)this_chunk;
    4.20      req_off += this_chunk;
    4.21      total_off += this_chunk;
    4.22      if (req_off == cur_req->len)
    4.23 @@ -198,7 +198,7 @@ static void xb_write(
    4.24    //_WriteBarrier();
    4.25    KeMemoryBarrier();
    4.26  
    4.27 -  xpdd->xen_store_interface->req_prod += len;
    4.28 +  xpdd->xen_store_interface->req_prod += (XENSTORE_RING_IDX)len;
    4.29  
    4.30    //KdPrint((__DRIVER_NAME " prod = %08x\n", xen_store_interface->req_prod));
    4.31  
    4.32 @@ -242,7 +242,7 @@ XenBus_Read(
    4.33    char **value)
    4.34  {
    4.35    WDFDEVICE Device = Context;
    4.36 -  struct write_req req[] = { {path, strlen(path) + 1} };
    4.37 +  struct write_req req[] = { {path, (ULONG)strlen(path) + 1} };
    4.38    struct xsd_sockmsg *rep;
    4.39    char *res;
    4.40    char *msg;
    4.41 @@ -275,8 +275,8 @@ XenBus_Write(
    4.42  {
    4.43    WDFDEVICE Device = Context;
    4.44    struct write_req req[] = {
    4.45 -    {path, strlen(path) + 1},
    4.46 -    {value, strlen(value) + 1},
    4.47 +    {path, (ULONG)strlen(path) + 1},
    4.48 +    {value, (ULONG)strlen(value) + 1},
    4.49    };
    4.50    struct xsd_sockmsg *rep;
    4.51    char *msg;
    4.52 @@ -413,7 +413,7 @@ XenBus_List(
    4.53  {
    4.54    WDFDEVICE Device = Context;
    4.55    struct xsd_sockmsg *reply, *repmsg;
    4.56 -  struct write_req req[] = { { pre, strlen(pre)+1 } };
    4.57 +  struct write_req req[] = { { pre, (ULONG)strlen(pre)+1 } };
    4.58    ULONG nr_elems, x, i;
    4.59    char **res;
    4.60    char *msg;
    4.61 @@ -437,7 +437,7 @@ XenBus_List(
    4.62      XENPCI_POOL_TAG);
    4.63    for (x = i = 0; i < nr_elems; i++)
    4.64    {
    4.65 -    int l = strlen((char *)reply + x);
    4.66 +    int l = (int)strlen((char *)reply + x);
    4.67      res[i] = ExAllocatePoolWithTag(NonPagedPool, l + 1, XENPCI_POOL_TAG);
    4.68      memcpy(res[i], (char *)reply + x, l + 1);
    4.69      x += l + 1;
    4.70 @@ -623,11 +623,11 @@ XenBus_AddWatch(
    4.71    KeReleaseSpinLock(&xpdd->WatchLock, OldIrql);
    4.72  
    4.73    req[0].data = Path;
    4.74 -  req[0].len = strlen(Path) + 1;
    4.75 +  req[0].len = (ULONG)strlen(Path) + 1;
    4.76  
    4.77    RtlStringCbPrintfA(Token, ARRAY_SIZE(Token), "%d", i);
    4.78    req[1].data = Token;
    4.79 -  req[1].len = strlen(Token) + 1;
    4.80 +  req[1].len = (ULONG)strlen(Token) + 1;
    4.81  
    4.82    rep = xenbus_msg_reply(Device, XS_WATCH, xbt, req, ARRAY_SIZE(req));
    4.83  
    4.84 @@ -703,11 +703,11 @@ XenBus_RemWatch(
    4.85    KeReleaseSpinLock(&xpdd->WatchLock, OldIrql);
    4.86  
    4.87    req[0].data = Path;
    4.88 -  req[0].len = strlen(Path) + 1;
    4.89 +  req[0].len = (ULONG)strlen(Path) + 1;
    4.90  
    4.91    RtlStringCbPrintfA(Token, ARRAY_SIZE(Token), "%d", i);
    4.92    req[1].data = Token;
    4.93 -  req[1].len = strlen(Token) + 1;
    4.94 +  req[1].len = (ULONG)strlen(Token) + 1;
    4.95  
    4.96    rep = xenbus_msg_reply(Device, XS_UNWATCH, xbt, req, ARRAY_SIZE(req));
    4.97  
     5.1 --- a/xenpci/xenpci.c	Tue Jan 22 20:02:17 2008 +1100
     5.2 +++ b/xenpci/xenpci.c	Wed Jan 23 13:00:43 2008 +1100
     5.3 @@ -24,6 +24,11 @@ Foundation, Inc., 51 Franklin Street, Fi
     5.4  #define SHUTDOWN_PATH "control/shutdown"
     5.5  #define BALLOON_PATH "memory/target"
     5.6  
     5.7 +#if sizeof(long) < sizeof(void *)
     5.8 + #define x 1
     5.9 +#else
    5.10 + #define x 2
    5.11 +#endif
    5.12  DRIVER_INITIALIZE DriverEntry;
    5.13  static NTSTATUS
    5.14  XenPCI_AddDevice(WDFDRIVER Driver, PWDFDEVICE_INIT DeviceInit);
    5.15 @@ -145,7 +150,7 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    5.16      case 0:
    5.17        if (SystemStartOptions[i] == L'G')
    5.18        {
    5.19 -        StartPos = i;
    5.20 +        StartPos = (int)i;
    5.21          State = 2;
    5.22        } else if (SystemStartOptions[i] != L' ')
    5.23        {
    5.24 @@ -240,15 +245,14 @@ get_hypercall_stubs(WDFDEVICE Device)
    5.25    //KdPrint((__DRIVER_NAME " Hypercall area is %u pages.\n", pages));
    5.26  
    5.27    xpdd->hypercall_stubs = ExAllocatePoolWithTag(NonPagedPool, pages * PAGE_SIZE, XENPCI_POOL_TAG);
    5.28 -  //KdPrint((__DRIVER_NAME " Hypercall area at %08x\n", hypercall_stubs));
    5.29 +  KdPrint((__DRIVER_NAME " Hypercall area at %p\n", xpdd->hypercall_stubs));
    5.30  
    5.31    if (!xpdd->hypercall_stubs)
    5.32      return 1;
    5.33    for (i = 0; i < pages; i++) {
    5.34      ULONGLONG pfn;
    5.35 -    //pfn = vmalloc_to_pfn((char *)hypercall_stubs + i * PAGE_SIZE);
    5.36      pfn = (MmGetPhysicalAddress(xpdd->hypercall_stubs + i * PAGE_SIZE).QuadPart >> PAGE_SHIFT);
    5.37 -    KdPrint((__DRIVER_NAME " pfn = %10lX\n", pfn));
    5.38 +    KdPrint((__DRIVER_NAME " pfn = %16lX\n", pfn));
    5.39      __writemsr(msr, (pfn << PAGE_SHIFT) + i);
    5.40    }
    5.41    return STATUS_SUCCESS;
    5.42 @@ -294,18 +298,27 @@ init_xen_info(WDFDEVICE Device)
    5.43    PHYSICAL_ADDRESS shared_info_area_unmapped;
    5.44  
    5.45    shared_info_area_unmapped = XenPCI_AllocMMIO(Device, PAGE_SIZE);
    5.46 +  KdPrint((__DRIVER_NAME " shared_info_area_unmapped.QuadPart = %lx\n", shared_info_area_unmapped.QuadPart));
    5.47    xatp.domid = DOMID_SELF;
    5.48    xatp.idx = 0;
    5.49    xatp.space = XENMAPSPACE_shared_info;
    5.50    xatp.gpfn = (xen_pfn_t)(shared_info_area_unmapped.QuadPart >> PAGE_SHIFT);
    5.51 +  KdPrint((__DRIVER_NAME " gpfn = %d\n", xatp.gpfn));
    5.52    ret = HYPERVISOR_memory_op(Device, XENMEM_add_to_physmap, &xatp);
    5.53    KdPrint((__DRIVER_NAME " hypervisor memory op ret = %d\n", ret));
    5.54  
    5.55 +  KdPrint((__DRIVER_NAME " %d %d %d", sizeof(short), sizeof(int), sizeof(long)));
    5.56 +  KdPrint((__DRIVER_NAME " sizeof(xen_add_to_physmap) = %d\n", sizeof(struct xen_add_to_physmap)));
    5.57 +  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, domid) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, domid)));
    5.58 +  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, idx) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, idx)));
    5.59 +  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, space) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, space)));
    5.60 +  KdPrint((__DRIVER_NAME " FIELD_OFFSET(xen_add_to_physmap, gpfn) = %d\n", FIELD_OFFSET(struct xen_add_to_physmap, gpfn)));
    5.61 +
    5.62    xpdd->shared_info_area = MmMapIoSpace(shared_info_area_unmapped,
    5.63 -    PAGE_SIZE, MmNonCached);
    5.64 +    PAGE_SIZE, MmCached);
    5.65  
    5.66 -  return 0;
    5.67 -}
    5.68 +  return 1;
    5.69 +} 
    5.70  
    5.71  static int
    5.72  set_callback_irq(WDFDEVICE Device, ULONGLONG irq)
    5.73 @@ -534,7 +547,8 @@ XenPCI_PrepareHardware(
    5.74  
    5.75    get_hypercall_stubs(Device);
    5.76  
    5.77 -  init_xen_info(Device);
    5.78 +  if (init_xen_info(Device))
    5.79 +    return STATUS_ACCESS_DENIED;
    5.80  
    5.81    GntTbl_Init(Device);
    5.82  
    5.83 @@ -684,8 +698,8 @@ static VOID
    5.84  XenPCI_IoRead(WDFQUEUE Queue, WDFREQUEST Request, size_t Length)
    5.85  {
    5.86    PSHUTDOWN_MSG_ENTRY Entry;
    5.87 -  ULONG Remaining;
    5.88 -  ULONG CopyLen;
    5.89 +  size_t Remaining;
    5.90 +  size_t CopyLen;
    5.91    PCHAR Buffer;
    5.92    size_t BufLen;
    5.93    KIRQL OldIrql;
    5.94 @@ -721,7 +735,7 @@ XenPCI_IoRead(WDFQUEUE Queue, WDFREQUEST
    5.95    else
    5.96    {    
    5.97      KdPrint((__DRIVER_NAME "     More to do...\n"));
    5.98 -    Entry->Ptr += CopyLen;
    5.99 +    Entry->Ptr += (ULONG)CopyLen;
   5.100      InsertHeadList(&ShutdownMsgList, &Entry->ListEntry);
   5.101    }
   5.102  
     6.1 --- a/xenpci/xenpci.h	Tue Jan 22 20:02:17 2008 +1100
     6.2 +++ b/xenpci/xenpci.h	Wed Jan 23 13:00:43 2008 +1100
     6.3 @@ -66,8 +66,6 @@ typedef struct _ev_action_t {
     6.4  
     6.5  typedef struct {
     6.6    ev_action_t *Action;
     6.7 -//  shared_info_t *shared_info_area;
     6.8 -//  ULONG port;
     6.9  } EVTCHN_DEVICE_DATA, *PEVTCHN_DEVICE_DATA;
    6.10  WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(EVTCHN_DEVICE_DATA, GetEvtChnDeviceData);
    6.11