win-pvdrivers

changeset 374:25814a68e426

Added grant table op to amd64
Updates to better support resume
author James Harper <james.harper@bendigoit.com.au>
date Wed Jul 09 22:04:57 2008 +1000 (2008-07-09)
parents 6b1c00d218e9
children 448011e246d3
files xenpci/amd64/hypercall.asm xenpci/gnttbl.c xenpci/hypercall_amd64.h xenpci/xenpci.h xenpci/xenpci_fdo.c
line diff
     1.1 --- a/xenpci/amd64/hypercall.asm	Wed Jul 09 20:17:22 2008 +1000
     1.2 +++ b/xenpci/amd64/hypercall.asm	Wed Jul 09 22:04:57 2008 +1000
     1.3 @@ -31,4 +31,17 @@
     1.4      pop rdi
     1.5      ret
     1.6  _hypercall2 endp
     1.7 +
     1.8 +_hypercall3 proc
     1.9 +    push rdi
    1.10 +    push rsi
    1.11 +    mov rdi, rdx
    1.12 +    mov rsi, r8
    1.13 +    mov rdx, r9
    1.14 +    mov rax, rcx
    1.15 +    call rax
    1.16 +    pop rsi
    1.17 +    pop rdi
    1.18 +    ret
    1.19 +_hypercall3 endp
    1.20  END
     2.1 --- a/xenpci/gnttbl.c	Wed Jul 09 20:17:22 2008 +1000
     2.2 +++ b/xenpci/gnttbl.c	Wed Jul 09 22:04:57 2008 +1000
     2.3 @@ -149,7 +149,6 @@ GntTbl_EndAccess(
     2.4    return TRUE;
     2.5  }
     2.6  
     2.7 -#if defined(_X86_)
     2.8  static unsigned int 
     2.9  GntTbl_QueryMaxFrames(PXENPCI_DEVICE_DATA xpdd)
    2.10  {
    2.11 @@ -166,42 +165,58 @@ GntTbl_QueryMaxFrames(PXENPCI_DEVICE_DAT
    2.12    }
    2.13    return query.max_nr_frames;
    2.14  }
    2.15 -#endif
    2.16 +
    2.17 +VOID
    2.18 +GntTbl_InitMap(PXENPCI_DEVICE_DATA xpdd)
    2.19 +{
    2.20 +  int i;
    2.21 +  ULONG grant_frames;
    2.22 +  int grant_entries;
    2.23 +  //KdPrint((__DRIVER_NAME " --> GntTbl_Init\n"));
    2.24 +
    2.25 +  grant_frames = GntTbl_QueryMaxFrames(xpdd);
    2.26 +  grant_entries = min(NR_GRANT_ENTRIES, (grant_frames * PAGE_SIZE / sizeof(grant_entry_t)));
    2.27 +  KdPrint((__DRIVER_NAME "     grant_entries : %d\n", grant_entries));
    2.28 +
    2.29 +  if (xpdd->gnttab_list)
    2.30 +  {
    2.31 +    if (grant_frames > xpdd->max_grant_frames)
    2.32 +    {
    2.33 +      ExFreePoolWithTag(xpdd->gnttab_list, XENPCI_POOL_TAG);
    2.34 +      MmUnmapIoSpace(xpdd->gnttab_table, PAGE_SIZE * xpdd->max_grant_frames);
    2.35 +      xpdd->gnttab_list = NULL;
    2.36 +    }
    2.37 +  }
    2.38 +  
    2.39 +  if (!xpdd->gnttab_list)
    2.40 +  {  
    2.41 +    xpdd->gnttab_list = ExAllocatePoolWithTag(NonPagedPool, sizeof(grant_ref_t) * grant_entries, XENPCI_POOL_TAG);
    2.42 +    xpdd->gnttab_table_physical = XenPci_AllocMMIO(xpdd,
    2.43 +      PAGE_SIZE * grant_frames);
    2.44 +    xpdd->gnttab_table = MmMapIoSpace(xpdd->gnttab_table_physical,
    2.45 +      PAGE_SIZE * grant_frames, MmNonCached);
    2.46 +    if (!xpdd->gnttab_table)
    2.47 +    {
    2.48 +      KdPrint((__DRIVER_NAME "     Error Mapping Grant Table Shared Memory\n"));
    2.49 +      // this should be a show stopper...
    2.50 +      return;
    2.51 +    }
    2.52 +    xpdd->max_grant_frames = grant_frames;
    2.53 +  }
    2.54 +  RtlZeroMemory(xpdd->gnttab_list, sizeof(grant_ref_t) * grant_entries);
    2.55 +  for (i = NR_RESERVED_ENTRIES; i < grant_entries; i++)
    2.56 +    GntTbl_PutRef(xpdd, i);
    2.57 +  
    2.58 +  GntTbl_Map(xpdd, 0, grant_frames - 1);
    2.59 +}
    2.60  
    2.61  VOID
    2.62  GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    2.63  {
    2.64 -  int i;
    2.65 -  int max_grant_frames = NR_GRANT_FRAMES;
    2.66 -  int max_grant_entries = NR_GRANT_ENTRIES;
    2.67    //KdPrint((__DRIVER_NAME " --> GntTbl_Init\n"));
    2.68    
    2.69    KeInitializeSpinLock(&xpdd->grant_lock);
    2.70 -
    2.71 -#if defined(_X86_)
    2.72 -  max_grant_frames = GntTbl_QueryMaxFrames(xpdd);
    2.73 -  max_grant_entries = min(NR_GRANT_ENTRIES,(max_grant_frames * PAGE_SIZE / sizeof(grant_entry_t)));
    2.74 -  KdPrint((__DRIVER_NAME "     max_grant_entries : %d\n",max_grant_entries));
    2.75 -#else
    2.76 -  #if defined(_AMD64_)
    2.77 -    KdPrint((__DRIVER_NAME "     AMD64 cannot support HYPERVISOR_grant_table_op now\n"));
    2.78 -  #endif
    2.79 -#endif
    2.80 -
    2.81 -  xpdd->gnttab_list = ExAllocatePoolWithTag(NonPagedPool, sizeof(grant_ref_t) * max_grant_entries, XENPCI_POOL_TAG);// Where to free?
    2.82 -  for (i = NR_RESERVED_ENTRIES; i < max_grant_entries; i++)
    2.83 -    GntTbl_PutRef(xpdd, i);
    2.84 -
    2.85 -  xpdd->gnttab_table_physical = XenPci_AllocMMIO(xpdd,
    2.86 -    PAGE_SIZE * max_grant_frames);
    2.87 -  xpdd->gnttab_table = MmMapIoSpace(xpdd->gnttab_table_physical,
    2.88 -    PAGE_SIZE * max_grant_frames, MmNonCached);
    2.89 -  if (!xpdd->gnttab_table)
    2.90 -  {
    2.91 -    KdPrint((__DRIVER_NAME "     Error Mapping Grant Table Shared Memory\n"));
    2.92 -    return;
    2.93 -  }
    2.94 -  GntTbl_Map(xpdd, 0, max_grant_frames - 1);
    2.95 -
    2.96 +  GntTbl_InitMap(xpdd);
    2.97 +  
    2.98    //KdPrint((__DRIVER_NAME " <-- GntTbl_Init table mapped at %p\n", gnttab_table));
    2.99  }
     3.1 --- a/xenpci/hypercall_amd64.h	Wed Jul 09 20:17:22 2008 +1000
     3.2 +++ b/xenpci/hypercall_amd64.h	Wed Jul 09 22:04:57 2008 +1000
     3.3 @@ -17,14 +17,15 @@ along with this program; if not, write t
     3.4  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     3.5  */
     3.6  
     3.7 -extern int _hypercall2(VOID *address, int cmd, void *arg);
     3.8 +extern int _hypercall2(VOID *address, xen_ulong_t a1, xen_ulong_t a2);
     3.9 +extern int _hypercall3(VOID *address, xen_ulong_t a1, xen_ulong_t a2, xen_ulong_t a3);
    3.10  
    3.11  static __inline int
    3.12  HYPERVISOR_memory_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *arg)
    3.13  {
    3.14    PCHAR memory_op_func = xpdd->hypercall_stubs;
    3.15    memory_op_func += __HYPERVISOR_memory_op * 32;
    3.16 -  return _hypercall2(memory_op_func, cmd, arg);
    3.17 +  return _hypercall2(memory_op_func, (xen_ulong_t)cmd, (xen_ulong_t)arg);
    3.18  }
    3.19  
    3.20  static __inline int
    3.21 @@ -32,31 +33,18 @@ HYPERVISOR_xen_version(PXENPCI_DEVICE_DA
    3.22  {
    3.23    PCHAR xen_version_func = xpdd->hypercall_stubs;
    3.24    xen_version_func += __HYPERVISOR_xen_version * 32;
    3.25 -  return _hypercall2(xen_version_func, cmd, arg);
    3.26 +  return _hypercall2(xen_version_func, (xen_ulong_t)cmd, (xen_ulong_t)arg);
    3.27  }
    3.28  
    3.29 -#if 0
    3.30  static __inline int
    3.31  HYPERVISOR_grant_table_op(PXENPCI_DEVICE_DATA xpdd, int cmd, void *uop, unsigned int count)
    3.32  {
    3.33 -  ASSERTMSG("grant_table_op not yet supported under AMD64", FALSE);
    3.34 -/*
    3.35 -  char *hypercall_stubs = xpdd->hypercall_stubs;
    3.36 -  long __res;
    3.37 -  __asm {
    3.38 -    mov ebx, cmd
    3.39 -    mov ecx, uop
    3.40 -    mov edx, count
    3.41 -    mov eax, hypercall_stubs
    3.42 -    add eax, (__HYPERVISOR_grant_table_op * 32)
    3.43 -    call eax
    3.44 -    mov [__res], eax
    3.45 -  }
    3.46 -  return __res;
    3.47 -*/
    3.48 -  return -1;
    3.49 +  PCHAR grant_table_op_func = xpdd->hypercall_stubs;
    3.50 +  grant_table_op_func += __HYPERVISOR_grant_table_op * 32;
    3.51 +  return _hypercall3(grant_table_op_func, (xen_ulong_t)cmd, (xen_ulong_t)uop, (xen_ulong_t)count);
    3.52  }
    3.53  
    3.54 +#if 0
    3.55  static __inline int
    3.56  HYPERVISOR_mmu_update(PXENPCI_DEVICE_DATA xpdd, mmu_update_t *req, int count, int *success_count, domid_t domid)
    3.57  {
    3.58 @@ -79,27 +67,6 @@ HYPERVISOR_mmu_update(PXENPCI_DEVICE_DAT
    3.59  */
    3.60    return -1;
    3.61  }
    3.62 -
    3.63 -static __inline int
    3.64 -HYPERVISOR_console_io(PXENPCI_DEVICE_DATA xpdd, int cmd, int count, char *string)
    3.65 -{
    3.66 -  ASSERTMSG("console_io not yet supported under AMD64", FALSE);
    3.67 -/*
    3.68 -  char *hypercall_stubs = xpdd->hypercall_stubs;
    3.69 -  long __res;
    3.70 -  __asm {
    3.71 -    mov ebx, cmd
    3.72 -    mov ecx, count
    3.73 -    mov edx, string
    3.74 -    mov eax, hypercall_stubs
    3.75 -    add eax, (__HYPERVISOR_console_io * 32)
    3.76 -    call eax
    3.77 -    mov [__res], eax
    3.78 -  }
    3.79 -  return __res;
    3.80 -*/
    3.81 -  return -1;
    3.82 -}
    3.83  #endif
    3.84  
    3.85  static __inline int
    3.86 @@ -107,7 +74,7 @@ HYPERVISOR_hvm_op(PXENPCI_DEVICE_DATA xp
    3.87  {
    3.88    PCHAR hvm_op_func = xpdd->hypercall_stubs;
    3.89    hvm_op_func += __HYPERVISOR_hvm_op * 32;
    3.90 -  return _hypercall2(hvm_op_func, op, arg);
    3.91 +  return _hypercall2(hvm_op_func, (xen_ulong_t)op, (xen_ulong_t)arg);
    3.92  }
    3.93  
    3.94  static __inline int
    3.95 @@ -115,7 +82,7 @@ HYPERVISOR_event_channel_op(PXENPCI_DEVI
    3.96  {
    3.97    PCHAR event_channel_op_func = xpdd->hypercall_stubs;
    3.98    event_channel_op_func += __HYPERVISOR_event_channel_op * 32;
    3.99 -  return _hypercall2(event_channel_op_func, cmd, op);
   3.100 +  return _hypercall2(event_channel_op_func, (xen_ulong_t)cmd, (xen_ulong_t)op);
   3.101  }
   3.102  
   3.103  static __inline int
   3.104 @@ -123,7 +90,7 @@ HYPERVISOR_sched_op(PXENPCI_DEVICE_DATA 
   3.105  {
   3.106    PCHAR sched_op_func = xpdd->hypercall_stubs;
   3.107    sched_op_func += __HYPERVISOR_sched_op * 32;
   3.108 -  return _hypercall2(sched_op_func, cmd, arg);
   3.109 +  return _hypercall2(sched_op_func, (xen_ulong_t)cmd, (xen_ulong_t)arg);
   3.110  }
   3.111  
   3.112  static __inline int
     4.1 --- a/xenpci/xenpci.h	Wed Jul 09 20:17:22 2008 +1000
     4.2 +++ b/xenpci/xenpci.h	Wed Jul 09 22:04:57 2008 +1000
     4.3 @@ -185,6 +185,9 @@ typedef struct {
     4.4    grant_entry_t *gnttab_table;
     4.5    PHYSICAL_ADDRESS gnttab_table_physical;
     4.6    grant_ref_t *gnttab_list;
     4.7 +  /* this is the maximum number of grant frames we have memory allocated for */
     4.8 +  /* after a resume it may not be the actual number of grant frames we have though */
     4.9 +  ULONG max_grant_frames;
    4.10  
    4.11    ev_action_t ev_actions[NR_EVENTS];
    4.12  //  unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
    4.13 @@ -418,7 +421,8 @@ EvtChn_AllocUnbound(PVOID Context, domid
    4.14  
    4.15  VOID
    4.16  GntTbl_Init(PXENPCI_DEVICE_DATA xpdd);
    4.17 -
    4.18 +VOID
    4.19 +GntTbl_InitMap(PXENPCI_DEVICE_DATA xpdd);
    4.20  grant_ref_t
    4.21  GntTbl_GrantAccess(PVOID Context, domid_t domid, uint32_t, int readonly, grant_ref_t ref);
    4.22  BOOLEAN
     5.1 --- a/xenpci/xenpci_fdo.c	Wed Jul 09 20:17:22 2008 +1000
     5.2 +++ b/xenpci/xenpci_fdo.c	Wed Jul 09 22:04:57 2008 +1000
     5.3 @@ -384,9 +384,6 @@ XenPci_Suspend(
     5.4    }
     5.5    KdPrint((__DRIVER_NAME "     all other processors are spinning\n"));
     5.6  
     5.7 -  // make a backup of the grant table - we are going to keep it instead of throwing it away
     5.8 -  //memcpy(gnttbl_backup, xpdd->gnttab_table, PAGE_SIZE * NR_GRANT_FRAMES);
     5.9 -
    5.10    KdPrint((__DRIVER_NAME "     calling suspend\n"));
    5.11    cancelled = hvm_shutdown(Context, SHUTDOWN_suspend);
    5.12    KdPrint((__DRIVER_NAME "     back from suspend, cancelled = %d\n", cancelled));
    5.13 @@ -398,8 +395,6 @@ XenPci_Suspend(
    5.14    /* this enabled interrupts again too */  
    5.15    EvtChn_Init(xpdd);
    5.16  
    5.17 -  //memcpy(xpdd->gnttab_table, gnttbl_backup, PAGE_SIZE * NR_GRANT_FRAMES);
    5.18 -
    5.19    for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
    5.20    {
    5.21      child->context->device_state.resume_state = RESUME_STATE_BACKEND_RESUME;