win-pvdrivers

changeset 268:f28ce60f3fa7 wdm

closer to having xenvbd up and running. Non-512 byte aligned buffers are a pain though.
author James Harper <james.harper@bendigoit.com.au>
date Tue May 13 00:02:24 2008 +1000 (2008-05-13)
parents f157f82e0293
children 6128d5c1e7a8
files xenvbd/xenvbd.c xenvbd/xenvbd.h
line diff
     1.1 --- a/xenvbd/xenvbd.c	Mon May 12 00:20:02 2008 +1000
     1.2 +++ b/xenvbd/xenvbd.c	Tue May 13 00:02:24 2008 +1000
     1.3 @@ -68,52 +68,61 @@ XenVbd_Pnp(PDEVICE_OBJECT device_object,
     1.4  
     1.5    stack = IoGetCurrentIrpStackLocation(irp);
     1.6  
     1.7 +  // check if the Irp is meant for us... maybe the stack->DeviceObject field?
     1.8 +  
     1.9    switch (stack->MinorFunction)
    1.10    {
    1.11    case IRP_MN_START_DEVICE:
    1.12 -    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE\n"));
    1.13 -    mdl = AllocatePage();
    1.14 +    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE - DeviceObject = %p\n", stack->DeviceObject));
    1.15      old_crl = stack->Parameters.StartDevice.AllocatedResourcesTranslated;
    1.16 -    old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
    1.17 -      FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
    1.18 -      FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
    1.19 -      sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
    1.20 -    new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
    1.21 -    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENVBD_POOL_TAG);
    1.22 -    memcpy(new_crl, old_crl, old_length);
    1.23 -    prl = &new_crl->List[0].PartialResourceList;
    1.24 -    prd = &prl->PartialDescriptors[prl->Count++];
    1.25 -    prd->Type = CmResourceTypeMemory;
    1.26 -    prd->ShareDisposition = CmResourceShareDeviceExclusive;
    1.27 -    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
    1.28 -    prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
    1.29 -    prd->u.Memory.Length = PAGE_SIZE;
    1.30 -    KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
    1.31 -    ptr = start = MmGetMdlVirtualAddress(mdl);
    1.32 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "ring-ref", NULL);
    1.33 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
    1.34 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_FRONT, "device-type", NULL);
    1.35 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sectors", NULL);
    1.36 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sector-size", NULL);
    1.37 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
    1.38 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, UlongToPtr(GRANT_ENTRIES), NULL);
    1.39 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
    1.40 -    
    1.41 -    stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
    1.42 +    if (old_crl != NULL)
    1.43 +    {
    1.44 +      mdl = AllocatePage();
    1.45 +      old_length = FIELD_OFFSET(CM_RESOURCE_LIST, List) + 
    1.46 +        FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) +
    1.47 +        FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) +
    1.48 +        sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * old_crl->List[0].PartialResourceList.Count;
    1.49 +      new_length = old_length + sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * 1;
    1.50 +      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENVBD_POOL_TAG);
    1.51 +      memcpy(new_crl, old_crl, old_length);
    1.52 +      prl = &new_crl->List[0].PartialResourceList;
    1.53 +      prd = &prl->PartialDescriptors[prl->Count++];
    1.54 +      prd->Type = CmResourceTypeMemory;
    1.55 +      prd->ShareDisposition = CmResourceShareDeviceExclusive;
    1.56 +      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
    1.57 +      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
    1.58 +      prd->u.Memory.Length = PAGE_SIZE;
    1.59 +      KdPrint((__DRIVER_NAME "     Start = %08x, Length = %d\n", prd->u.Memory.Start.LowPart, prd->u.Memory.Length));
    1.60 +      ptr = start = MmGetMdlVirtualAddress(mdl);
    1.61 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_RING, "ring-ref", NULL);
    1.62 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_EVENT_CHANNEL_IRQ, "event-channel", NULL);
    1.63 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_FRONT, "device-type", NULL);
    1.64 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sectors", NULL);
    1.65 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sector-size", NULL);
    1.66 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_VECTORS, NULL, NULL);
    1.67 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, UlongToPtr(GRANT_ENTRIES), NULL);
    1.68 +      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);
    1.69 +      
    1.70 +      stack->Parameters.StartDevice.AllocatedResourcesTranslated = new_crl;
    1.71  
    1.72 -    old_crl = stack->Parameters.StartDevice.AllocatedResources;
    1.73 -    new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENVBD_POOL_TAG);
    1.74 -    memcpy(new_crl, old_crl, old_length);
    1.75 -    prl = &new_crl->List[0].PartialResourceList;
    1.76 -    prd = &prl->PartialDescriptors[prl->Count++];
    1.77 -    prd->Type = CmResourceTypeMemory;
    1.78 -    prd->ShareDisposition = CmResourceShareDeviceExclusive;
    1.79 -    prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
    1.80 -    prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
    1.81 -    prd->u.Memory.Length = PAGE_SIZE;
    1.82 -    stack->Parameters.StartDevice.AllocatedResources = new_crl;
    1.83 +      old_crl = stack->Parameters.StartDevice.AllocatedResources;
    1.84 +      new_crl = ExAllocatePoolWithTag(PagedPool, new_length, XENVBD_POOL_TAG);
    1.85 +      memcpy(new_crl, old_crl, old_length);
    1.86 +      prl = &new_crl->List[0].PartialResourceList;
    1.87 +      prd = &prl->PartialDescriptors[prl->Count++];
    1.88 +      prd->Type = CmResourceTypeMemory;
    1.89 +      prd->ShareDisposition = CmResourceShareDeviceExclusive;
    1.90 +      prd->Flags = CM_RESOURCE_MEMORY_READ_WRITE|CM_RESOURCE_MEMORY_PREFETCHABLE|CM_RESOURCE_MEMORY_CACHEABLE;
    1.91 +      prd->u.Memory.Start.QuadPart = MmGetMdlPfnArray(mdl)[0] << PAGE_SHIFT;
    1.92 +      prd->u.Memory.Length = PAGE_SIZE;
    1.93 +      stack->Parameters.StartDevice.AllocatedResources = new_crl;
    1.94  
    1.95 -    IoCopyCurrentIrpStackLocationToNext(irp);
    1.96 +      IoCopyCurrentIrpStackLocationToNext(irp);
    1.97 +    }
    1.98 +    else
    1.99 +    {
   1.100 +      KdPrint((__DRIVER_NAME "     AllocatedResource == NULL\n"));
   1.101 +    }
   1.102      status = XenVbd_Pnp_Original(device_object, irp);
   1.103  
   1.104      break;
     2.1 --- a/xenvbd/xenvbd.h	Mon May 12 00:20:02 2008 +1000
     2.2 +++ b/xenvbd/xenvbd.h	Tue May 13 00:02:24 2008 +1000
     2.3 @@ -97,8 +97,7 @@ struct
     2.4    USHORT shadow_free_list[SHADOW_ENTRIES];
     2.5    USHORT shadow_free;
     2.6  
     2.7 -  grant_entry_t grants[GRANT_ENTRIES];
     2.8 -  USHORT grant_free_list[GRANT_ENTRIES];
     2.9 +  grant_ref_t grant_free_list[GRANT_ENTRIES];
    2.10    USHORT grant_free;
    2.11  
    2.12    evtchn_port_t event_channel;