win-pvdrivers

changeset 508:c8824436c717

xenbus userspace channel starting to get somewhere...
author James Harper <james.harper@bendigoit.com.au>
date Tue Dec 23 14:28:02 2008 +1100 (2008-12-23)
parents 69b067a93d0e
children 87aba6fc3a82
files xenpci/xenbus.c xenpci/xenbus_device_interface.c xenpci/xenpci.h xenpci/xenpci_fdo.c
line diff
     1.1 --- a/xenpci/xenbus.c	Tue Dec 23 14:27:42 2008 +1100
     1.2 +++ b/xenpci/xenbus.c	Tue Dec 23 14:28:02 2008 +1100
     1.3 @@ -138,7 +138,7 @@ xenbus_format_msg_reply(
     1.4    msg.tx_id = trans_id;
     1.5    msg.len = 0;
     1.6    for (i = 0; i < nr_reqs; i++)
     1.7 -    msg.len += (size_t)req[i].len;
     1.8 +    msg.len = msg.len + (size_t)req[i].len;
     1.9  
    1.10    ExAcquireFastMutex(&xpdd->xb_request_mutex);
    1.11    xb_write(xpdd, &msg, sizeof(msg));
     2.1 --- a/xenpci/xenbus_device_interface.c	Tue Dec 23 14:27:42 2008 +1100
     2.2 +++ b/xenpci/xenbus_device_interface.c	Tue Dec 23 14:28:02 2008 +1100
     2.3 @@ -27,6 +27,8 @@ XenPci_Irp_Create_XenBus(PDEVICE_OBJECT 
     2.4    PFILE_OBJECT file;
     2.5    device_interface_xenbus_context_t *dixc;
     2.6    
     2.7 +  FUNCTION_ENTER();
     2.8 +  
     2.9    UNREFERENCED_PARAMETER(device_object);
    2.10    stack = IoGetCurrentIrpStackLocation(irp);
    2.11    file = stack->FileObject;
    2.12 @@ -37,8 +39,12 @@ XenPci_Irp_Create_XenBus(PDEVICE_OBJECT 
    2.13    dixc->len = 0;
    2.14    file->FsContext = dixc;
    2.15    status = STATUS_SUCCESS;    
    2.16 +  dixc->pending_read_irp = NULL;
    2.17    irp->IoStatus.Status = status;
    2.18    IoCompleteRequest(irp, IO_NO_INCREMENT);
    2.19 +  
    2.20 +  FUNCTION_EXIT();
    2.21 +  
    2.22    return status;
    2.23  }
    2.24  
    2.25 @@ -74,15 +80,23 @@ XenPci_Irp_Read_XenBus_Complete(device_i
    2.26    xenbus_read_queue_item_t *list_entry;
    2.27    PIO_STACK_LOCATION stack;
    2.28    NTSTATUS status;
    2.29 +
    2.30 +  FUNCTION_ENTER();
    2.31    
    2.32 -  dixc->pending_read_irp = NULL;
    2.33 +KdPrint((__DRIVER_NAME "     A - dixc = %p, irp = %p\n", dixc, irp));
    2.34    stack = IoGetCurrentIrpStackLocation(irp);
    2.35 +KdPrint((__DRIVER_NAME "     Aa\n"));
    2.36    dst_length = stack->Parameters.Read.Length;
    2.37 +KdPrint((__DRIVER_NAME "     B - dst_length = %d\n", dst_length));
    2.38    dst_offset = 0;
    2.39 +KdPrint((__DRIVER_NAME "     C\n"));
    2.40    KeAcquireSpinLock(&dixc->lock, &old_irql);
    2.41 +KdPrint((__DRIVER_NAME "     D"));
    2.42    while(dst_offset < dst_length && (list_entry = (xenbus_read_queue_item_t *)RemoveHeadList(&dixc->read_list_head)) != (xenbus_read_queue_item_t *)&dixc->read_list_head)
    2.43    {
    2.44 +KdPrint((__DRIVER_NAME "     E\n"));
    2.45      copy_length = min(list_entry->length - list_entry->offset, dst_length - dst_offset);
    2.46 +    KdPrint((__DRIVER_NAME "     copying %d bytes\n", copy_length));
    2.47      memcpy((PUCHAR)irp->AssociatedIrp.SystemBuffer + dst_offset, (PUCHAR)list_entry->data + list_entry->offset, copy_length);
    2.48      list_entry->offset += copy_length;
    2.49      dst_offset += copy_length;
    2.50 @@ -97,22 +111,58 @@ XenPci_Irp_Read_XenBus_Complete(device_i
    2.51      }      
    2.52    }
    2.53    KeReleaseSpinLock(&dixc->lock, old_irql);
    2.54 -    
    2.55 +KdPrint((__DRIVER_NAME "     F\n"));
    2.56 +  
    2.57    if (dst_offset > 0)
    2.58    {
    2.59 +    KdPrint((__DRIVER_NAME "     completing request\n"));
    2.60      status = STATUS_SUCCESS;
    2.61      irp->IoStatus.Status = status;
    2.62      irp->IoStatus.Information = dst_offset;
    2.63 -    //IoSetCancelRoutine(irp, NULL);
    2.64 +    IoSetCancelRoutine(irp, NULL);
    2.65      IoCompleteRequest(irp, IO_NO_INCREMENT);
    2.66    }
    2.67    else
    2.68    {
    2.69 +    KdPrint((__DRIVER_NAME "     pending request\n"));
    2.70      status = STATUS_PENDING;
    2.71    }
    2.72 +
    2.73 +  FUNCTION_EXIT();
    2.74 +
    2.75    return status;
    2.76  }
    2.77  
    2.78 +static VOID
    2.79 +XenPci_Irp_Read_Cancel(PDEVICE_OBJECT device_object, PIRP irp)
    2.80 +{
    2.81 +  PIO_STACK_LOCATION stack;
    2.82 +  PFILE_OBJECT file;
    2.83 +  device_interface_xenbus_context_t *dixc;
    2.84 +  KIRQL old_irql;
    2.85 +
    2.86 +  FUNCTION_ENTER();
    2.87 +
    2.88 +  UNREFERENCED_PARAMETER(device_object);
    2.89 +
    2.90 +  stack = IoGetCurrentIrpStackLocation(irp);
    2.91 +  file = stack->FileObject;
    2.92 +  dixc = file->FsContext;
    2.93 +  IoReleaseCancelSpinLock(irp->CancelIrql);
    2.94 +  KeAcquireSpinLock(&dixc->lock, &old_irql);
    2.95 +  if (irp != dixc->pending_read_irp)
    2.96 +  {
    2.97 +    KdPrint((__DRIVER_NAME "     Not the current irp???\n"));
    2.98 +  }
    2.99 +  dixc->pending_read_irp = NULL;
   2.100 +  irp->IoStatus.Status = STATUS_CANCELLED;
   2.101 +  irp->IoStatus.Information = 0;
   2.102 +  KeReleaseSpinLock(&dixc->lock, old_irql);
   2.103 +  IoCompleteRequest(irp, IO_NO_INCREMENT);
   2.104 +
   2.105 +  FUNCTION_EXIT();
   2.106 +}
   2.107 +
   2.108  NTSTATUS
   2.109  XenPci_Irp_Read_XenBus(PDEVICE_OBJECT device_object, PIRP irp)
   2.110  {
   2.111 @@ -128,7 +178,7 @@ XenPci_Irp_Read_XenBus(PDEVICE_OBJECT de
   2.112    file = stack->FileObject;
   2.113    dixc = file->FsContext;
   2.114  
   2.115 -  ASSERT(dixc->pending_read_irp);
   2.116 +  ASSERT(!dixc->pending_read_irp);
   2.117    
   2.118    if (stack->Parameters.Read.Length == 0)
   2.119    {
   2.120 @@ -145,8 +195,8 @@ XenPci_Irp_Read_XenBus(PDEVICE_OBJECT de
   2.121        IoMarkIrpPending(irp);
   2.122        KeAcquireSpinLock(&dixc->lock, &old_irql);
   2.123        dixc->pending_read_irp = irp;
   2.124 -      //IoSetCancelRoutine(irp, XenBus_ShutdownIoCancel);
   2.125        KeReleaseSpinLock(&dixc->lock, old_irql);
   2.126 +      IoSetCancelRoutine(irp, XenPci_Irp_Read_Cancel);
   2.127      }
   2.128    }
   2.129    return status;
   2.130 @@ -170,11 +220,15 @@ XenPci_Irp_Write_XenBus(PDEVICE_OBJECT d
   2.131    PIRP read_irp;
   2.132    NTSTATUS read_status;
   2.133    
   2.134 +  FUNCTION_ENTER();
   2.135 +  
   2.136    xpdd = device_object->DeviceExtension;
   2.137    stack = IoGetCurrentIrpStackLocation(irp);
   2.138    file = stack->FileObject;
   2.139    dixc = file->FsContext;
   2.140    
   2.141 +  KdPrint((__DRIVER_NAME "     write length = %d\n", stack->Parameters.Write.Length));
   2.142 +  
   2.143    src_ptr = (PUCHAR)irp->AssociatedIrp.SystemBuffer;
   2.144    src_len = stack->Parameters.Write.Length;
   2.145    dst_ptr = dixc->u.buffer + dixc->len;
   2.146 @@ -232,7 +286,13 @@ XenPci_Irp_Write_XenBus(PDEVICE_OBJECT d
   2.147    status = STATUS_SUCCESS;    
   2.148    irp->IoStatus.Status = status;
   2.149    irp->IoStatus.Information = stack->Parameters.Write.Length;
   2.150 +
   2.151 +  KdPrint((__DRIVER_NAME "     Information = %d\n", irp->IoStatus.Information));
   2.152 +
   2.153    IoCompleteRequest(irp, IO_NO_INCREMENT);
   2.154 +
   2.155 +  FUNCTION_EXIT();
   2.156 +
   2.157    return status;
   2.158  }
   2.159  
     3.1 --- a/xenpci/xenpci.h	Tue Dec 23 14:27:42 2008 +1100
     3.2 +++ b/xenpci/xenpci.h	Tue Dec 23 14:28:02 2008 +1100
     3.3 @@ -279,11 +279,13 @@ typedef struct
     3.4    PXENPCI_PDO_DEVICE_DATA context;
     3.5  } XEN_CHILD, *PXEN_CHILD;
     3.6  
     3.7 +#define XEN_INTERFACE_VERSION 1
     3.8 +
     3.9  #define DEVICE_INTERFACE_TYPE_LEGACY 0
    3.10  #define DEVICE_INTERFACE_TYPE_XENBUS 1
    3.11  
    3.12  typedef struct {
    3.13 -  ULONG type;
    3.14 +  ULONG type; /* must be the first member */
    3.15    KSPIN_LOCK lock;
    3.16    ULONG len;
    3.17    union {
     4.1 --- a/xenpci/xenpci_fdo.c	Tue Dec 23 14:27:42 2008 +1100
     4.2 +++ b/xenpci/xenpci_fdo.c	Tue Dec 23 14:28:02 2008 +1100
     4.3 @@ -1333,10 +1333,13 @@ XenPci_Irp_Create_Fdo(PDEVICE_OBJECT dev
     4.4      // legacy interface
     4.5      xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
     4.6      file->FsContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(ULONG), XENPCI_POOL_TAG);
     4.7 +    *(PULONG)file->FsContext = DEVICE_INTERFACE_TYPE_LEGACY;
     4.8      status = STATUS_SUCCESS;    
     4.9      irp->IoStatus.Status = status;
    4.10      IoCompleteRequest(irp, IO_NO_INCREMENT);
    4.11    }
    4.12 +  KdPrint((__DRIVER_NAME "     context = %p\n", file->FsContext));
    4.13 +  KdPrint((__DRIVER_NAME "     type = %d\n", *(PULONG)file->FsContext));
    4.14    FUNCTION_EXIT();
    4.15  
    4.16    return status;
    4.17 @@ -1431,13 +1434,16 @@ XenPci_Irp_Write_Fdo(PDEVICE_OBJECT devi
    4.18    
    4.19    stack = IoGetCurrentIrpStackLocation(irp);
    4.20    file = stack->FileObject;
    4.21 +  
    4.22 +  KdPrint((__DRIVER_NAME "     context = %p\n", file->FsContext));
    4.23 +  KdPrint((__DRIVER_NAME "     type = %d\n", *(PULONG)file->FsContext));
    4.24  
    4.25    xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
    4.26    stack = IoGetCurrentIrpStackLocation(irp);
    4.27  
    4.28    if (*(PULONG)file->FsContext == DEVICE_INTERFACE_TYPE_XENBUS)
    4.29    {
    4.30 -    status = XenPci_Irp_Close_XenBus(device_object, irp);
    4.31 +    status = XenPci_Irp_Write_XenBus(device_object, irp);
    4.32    }
    4.33    else
    4.34    {
    4.35 @@ -1467,7 +1473,7 @@ XenPci_Irp_Cleanup_Fdo(PDEVICE_OBJECT de
    4.36    
    4.37    if (*(PULONG)file->FsContext == DEVICE_INTERFACE_TYPE_XENBUS)
    4.38    {
    4.39 -    status = XenPci_Irp_Close_XenBus(device_object, irp);
    4.40 +    status = XenPci_Irp_Cleanup_XenBus(device_object, irp);
    4.41    }
    4.42    else
    4.43    {