win-pvdrivers

changeset 534:1d13cbc9a3b0

Changed to use sg. crash dump doesn't appear to work anymore.
author James Harper <james.harper@bendigoit.com.au>
date Tue Jan 27 00:46:33 2009 +1100 (2009-01-27)
parents 82f26efb764f
children 285d80861ecf
files xenvbd/xenvbd.c xenvbd/xenvbd.h
line diff
     1.1 --- a/xenvbd/xenvbd.c	Tue Jan 27 00:46:08 2009 +1100
     1.2 +++ b/xenvbd/xenvbd.c	Tue Jan 27 00:46:33 2009 +1100
     1.3 @@ -41,6 +41,8 @@ DRIVER_INITIALIZE DriverEntry;
     1.4    #define GET_PAGE_ALIGNED(ptr) UlongToPtr((PtrToUlong(ptr) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
     1.5  #endif
     1.6  
     1.7 +#define LongLongToPtr(x) ((PVOID)(ULONG)(x))
     1.8 +
     1.9  static BOOLEAN dump_mode = FALSE;
    1.10  
    1.11  ULONGLONG parse_numeric_string(PCHAR string)
    1.12 @@ -76,25 +78,6 @@ put_shadow_on_freelist(PXENVBD_DEVICE_DA
    1.13    xvdd->shadow_free++;
    1.14  }
    1.15  
    1.16 -static grant_ref_t
    1.17 -get_grant_from_freelist(PXENVBD_DEVICE_DATA xvdd)
    1.18 -{
    1.19 -  if (xvdd->grant_free == 0)
    1.20 -  {
    1.21 -    KdPrint((__DRIVER_NAME "     No more grant refs\n"));    
    1.22 -    return (grant_ref_t)0x0FFFFFFF;
    1.23 -  }
    1.24 -  xvdd->grant_free--;
    1.25 -  return xvdd->grant_free_list[xvdd->grant_free];
    1.26 -}
    1.27 -
    1.28 -static VOID
    1.29 -put_grant_on_freelist(PXENVBD_DEVICE_DATA xvdd, grant_ref_t grant)
    1.30 -{
    1.31 -  xvdd->grant_free_list[xvdd->grant_free] = grant;
    1.32 -  xvdd->grant_free++;
    1.33 -}
    1.34 -
    1.35  static blkif_response_t *
    1.36  XenVbd_GetResponse(PXENVBD_DEVICE_DATA xvdd, int i)
    1.37  {
    1.38 @@ -240,29 +223,6 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
    1.39        else
    1.40          memcpy(&xvdd->vectors, value, sizeof(XENPCI_VECTORS));
    1.41        break;
    1.42 -    case XEN_INIT_TYPE_GRANT_ENTRIES:
    1.43 -      KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_GRANT_ENTRIES - %d\n", PtrToUlong(setting)));
    1.44 -      xvdd->grant_entries = (USHORT)PtrToUlong(setting);
    1.45 -      if (dump_mode)
    1.46 -      {
    1.47 -        /* check each grant entry first to make sure it isn't in use already */
    1.48 -        grant_ref_t *gref = (grant_ref_t *)value;
    1.49 -        xvdd->grant_free = 0;
    1.50 -        for (i = 0; i < xvdd->grant_entries; i++)
    1.51 -        {
    1.52 -          if (xvdd->vectors.GntTbl_EndAccess(xvdd->vectors.context, *gref, TRUE))
    1.53 -          {
    1.54 -            put_grant_on_freelist(xvdd, *gref);
    1.55 -          }
    1.56 -          gref++;
    1.57 -        }
    1.58 -      }
    1.59 -      else
    1.60 -      {
    1.61 -        memcpy(&xvdd->grant_free_list, value, sizeof(grant_ref_t) * xvdd->grant_entries);
    1.62 -        xvdd->grant_free = xvdd->grant_entries;
    1.63 -      }
    1.64 -      break;
    1.65      case XEN_INIT_TYPE_STATE_PTR:
    1.66        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_DEVICE_STATE - %p\n", PtrToUlong(value)));
    1.67        xvdd->device_state = (PXENPCI_DEVICE_STATE)value;
    1.68 @@ -386,39 +346,21 @@ decode_cdb_is_read(PSCSI_REQUEST_BLOCK s
    1.69  }
    1.70  
    1.71  static VOID
    1.72 -XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb, ULONG srb_offset)
    1.73 +XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA xvdd, PSCSI_REQUEST_BLOCK srb)
    1.74  {
    1.75 -  ULONG block_count, transfer_length;
    1.76 +  ULONG block_count;
    1.77    blkif_shadow_t *shadow;
    1.78 -  PHYSICAL_ADDRESS physical_address;
    1.79 -  ULONG pfn;
    1.80    ULONG remaining, offset, length;
    1.81    PUCHAR ptr;
    1.82    int notify;
    1.83  
    1.84 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
    1.85 +  //FUNCTION_ENTER();
    1.86  
    1.87 -  //ASSERT(!(srb_offset == 0 && xvdd->split_request_in_progress));
    1.88 +  ptr = srb->DataBuffer;
    1.89 +
    1.90    block_count = decode_cdb_length(srb);;
    1.91    block_count *= xvdd->bytes_per_sector / 512;
    1.92 -  if (PtrToUlong(srb->DataBuffer) & 511) /* use SrbExtension intead of DataBuffer if DataBuffer is not aligned to sector size */
    1.93 -  {
    1.94 -    ptr = GET_PAGE_ALIGNED(srb->SrbExtension);
    1.95 -    transfer_length = min(block_count * 512 - srb_offset, UNALIGNED_DOUBLE_BUFFER_SIZE);
    1.96 -  }
    1.97 -  else
    1.98 -  {
    1.99 -    ptr = srb->DataBuffer;
   1.100 -    transfer_length = block_count * 512;
   1.101 -  }
   1.102 -
   1.103 -  if (xvdd->grant_free <= ADDRESS_AND_SIZE_TO_SPAN_PAGES(ptr, transfer_length))
   1.104 -  {
   1.105 -    ASSERT(!xvdd->pending_srb);
   1.106 -    KdPrint((__DRIVER_NAME "     No enough grants - deferring\n"));
   1.107 -    xvdd->pending_srb = srb;
   1.108 -    return;
   1.109 -  }
   1.110 +  remaining = block_count * 512;
   1.111  
   1.112    shadow = get_shadow_from_freelist(xvdd);
   1.113    ASSERT(shadow);
   1.114 @@ -427,42 +369,26 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.115    shadow->req.handle = 0;
   1.116    shadow->req.operation = decode_cdb_is_read(srb)?BLKIF_OP_READ:BLKIF_OP_WRITE;
   1.117    shadow->req.nr_segments = 0;
   1.118 -  shadow->offset = srb_offset;
   1.119 -  shadow->length = transfer_length;
   1.120    shadow->srb = srb;
   1.121  
   1.122    //KdPrint((__DRIVER_NAME "     sector_number = %d, block_count = %d\n", (ULONG)shadow->req.sector_number, block_count));
   1.123    //KdPrint((__DRIVER_NAME "     SrbExtension = %p\n", srb->SrbExtension));
   1.124    //KdPrint((__DRIVER_NAME "     DataBuffer   = %p\n", srb->DataBuffer));
   1.125  
   1.126 -  if (PtrToUlong(srb->DataBuffer) & 511) /* use SrbExtension intead of DataBuffer if DataBuffer is not aligned to sector size */
   1.127 -  {
   1.128 -    shadow->req.sector_number += srb_offset / 512; //xvdd->bytes_per_sector;
   1.129 -    //KdPrint((__DRIVER_NAME "     Using unaligned buffer - DataBuffer = %p, SrbExtension = %p, total length = %d, offset = %d, length = %d, sector = %d\n", srb->DataBuffer, srb->SrbExtension, block_count * 512, shadow->offset, shadow->length, (ULONG)shadow->req.sector_number));
   1.130 -    if (!decode_cdb_is_read(srb))
   1.131 -    {
   1.132 -      memcpy(ptr, ((PUCHAR)srb->DataBuffer) + srb_offset, shadow->length);
   1.133 -    }
   1.134 -  }
   1.135 -  else
   1.136 -  {
   1.137 -    ptr = srb->DataBuffer;
   1.138 -  }
   1.139    //KdPrint((__DRIVER_NAME "     sector_number = %d\n", (ULONG)shadow->req.sector_number));
   1.140    //KdPrint((__DRIVER_NAME "     handle = %d\n", shadow->req.handle));
   1.141    //KdPrint((__DRIVER_NAME "     operation = %d\n", shadow->req.operation));
   1.142      
   1.143 -  remaining = shadow->length;  
   1.144    while (remaining > 0)
   1.145    {
   1.146 -    physical_address = MmGetPhysicalAddress(ptr);
   1.147 -    pfn = (ULONG)(physical_address.QuadPart >> PAGE_SHIFT);
   1.148 -    shadow->req.seg[shadow->req.nr_segments].gref = get_grant_from_freelist(xvdd);
   1.149 -    ASSERT(shadow->req.seg[shadow->req.nr_segments].gref != INVALID_GRANT_REF);
   1.150 -    xvdd->vectors.GntTbl_GrantAccess(xvdd->vectors.context, 0, pfn, 0, shadow->req.seg[shadow->req.nr_segments].gref);
   1.151 -    offset = (ULONG)(physical_address.QuadPart & (PAGE_SIZE - 1));
   1.152 +    PHYSICAL_ADDRESS physical_address;
   1.153 +    physical_address = ScsiPortGetPhysicalAddress(xvdd, srb, ptr, &length);
   1.154 +    offset = physical_address.LowPart & (PAGE_SIZE - 1);
   1.155      ASSERT((offset & 511) == 0);
   1.156 -    length = min(PAGE_SIZE - offset, remaining);
   1.157 +    //length = min(PAGE_SIZE - offset, remaining);
   1.158 +    //KdPrint((__DRIVER_NAME "     length(a) = %d\n", length));
   1.159 +    shadow->req.seg[shadow->req.nr_segments].gref = (grant_ref_t)(physical_address.QuadPart >> PAGE_SHIFT);
   1.160 +    //KdPrint((__DRIVER_NAME "     length(b) = %d\n", length));
   1.161      shadow->req.seg[shadow->req.nr_segments].first_sect = (UCHAR)(offset >> 9);
   1.162      shadow->req.seg[shadow->req.nr_segments].last_sect = (UCHAR)(((offset + length) >> 9) - 1);
   1.163      remaining -= length;
   1.164 @@ -483,10 +409,10 @@ XenVbd_PutSrbOnRing(PXENVBD_DEVICE_DATA 
   1.165      xvdd->vectors.EvtChn_Notify(xvdd->vectors.context, xvdd->event_channel);
   1.166    }
   1.167  
   1.168 -  if (xvdd->shadow_free && srb_offset == 0)
   1.169 +  if (xvdd->shadow_free)
   1.170      ScsiPortNotification(NextLuRequest, xvdd, 0, 0, 0);
   1.171  
   1.172 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.173 +  //FUNCTION_EXIT();
   1.174  }
   1.175  
   1.176  typedef struct {
   1.177 @@ -513,7 +439,6 @@ XenVbd_Resume(PVOID DeviceExtension)
   1.178      if (xvdd->shadows[i].srb)
   1.179      {
   1.180        shadows[shadow_count].srb = xvdd->shadows[i].srb;
   1.181 -      shadows[shadow_count].offset = xvdd->shadows[i].offset;
   1.182        shadow_count++;
   1.183        xvdd->shadows[i].srb = NULL;
   1.184      }      
   1.185 @@ -525,7 +450,7 @@ KdPrint((__DRIVER_NAME "     Back from I
   1.186    for (i = 0; i < shadow_count; i++)
   1.187    {
   1.188  KdPrint((__DRIVER_NAME "     Putting on Shadow entry\n"));
   1.189 -    XenVbd_PutSrbOnRing(xvdd, shadows[i].srb, shadows[i].offset);
   1.190 +    XenVbd_PutSrbOnRing(xvdd, shadows[i].srb);
   1.191    }
   1.192  KdPrint((__DRIVER_NAME "     Shadows are back on the ring\n"));
   1.193    
   1.194 @@ -591,7 +516,7 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   1.195      return status;
   1.196    
   1.197    ConfigInfo->MaximumTransferLength = BLKIF_MAX_SEGMENTS_PER_REQUEST * PAGE_SIZE;
   1.198 -  ConfigInfo->NumberOfPhysicalBreaks = 0; //BLKIF_MAX_SEGMENTS_PER_REQUEST - 1;
   1.199 +  ConfigInfo->NumberOfPhysicalBreaks = BLKIF_MAX_SEGMENTS_PER_REQUEST - 1;
   1.200    ConfigInfo->ScatterGather = TRUE;
   1.201    ConfigInfo->AlignmentMask = 0;
   1.202    ConfigInfo->NumberOfBuses = 1;
   1.203 @@ -603,11 +528,13 @@ XenVbd_HwScsiFindAdapter(PVOID DeviceExt
   1.204    {
   1.205      ConfigInfo->Master = TRUE;
   1.206      ConfigInfo->Dma64BitAddresses = SCSI_DMA64_MINIPORT_SUPPORTED;
   1.207 +    ConfigInfo->Dma32BitAddresses = FALSE;
   1.208      KdPrint((__DRIVER_NAME "     Dma64BitAddresses supported\n"));
   1.209    }
   1.210    else
   1.211    {
   1.212 -    ConfigInfo->Master = FALSE;
   1.213 +    ConfigInfo->Master = TRUE; //FALSE;
   1.214 +    ConfigInfo->Dma32BitAddresses = TRUE;
   1.215      KdPrint((__DRIVER_NAME "     Dma64BitAddresses not supported\n"));
   1.216    }
   1.217  
   1.218 @@ -684,11 +611,14 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   1.219    BOOLEAN cdb_dbd;
   1.220    UCHAR cdb_page_code;
   1.221    USHORT cdb_allocation_length;
   1.222 +  PVOID data_buffer;
   1.223 +  ULONG data_buffer_length;
   1.224  
   1.225    UNREFERENCED_PARAMETER(xvdd);
   1.226  
   1.227    //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   1.228    
   1.229 +  data_buffer = LongLongToPtr(ScsiPortGetPhysicalAddress(xvdd, srb, srb->DataBuffer, &data_buffer_length).QuadPart);
   1.230    //cdb = (PCDB)srb->Cdb;
   1.231    switch (srb->Cdb[0])
   1.232    {
   1.233 @@ -713,7 +643,8 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   1.234      return FALSE;
   1.235    }
   1.236    offset = 0;
   1.237 -  RtlZeroMemory(srb->DataBuffer, srb->DataTransferLength);
   1.238 +  
   1.239 +  RtlZeroMemory(data_buffer, srb->DataTransferLength);
   1.240    RtlZeroMemory(buffer, ARRAY_SIZE(buffer));
   1.241  
   1.242    parameter_header = (PMODE_PARAMETER_HEADER)&buffer[offset];
   1.243 @@ -781,7 +712,7 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
   1.244      srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.245    srb->DataTransferLength = min(srb->DataTransferLength, offset);
   1.246    srb->ScsiStatus = 0;
   1.247 -  memcpy(srb->DataBuffer, buffer, srb->DataTransferLength);
   1.248 +  memcpy(data_buffer, buffer, srb->DataTransferLength);
   1.249    
   1.250    //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.251  
   1.252 @@ -821,18 +752,17 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
   1.253    PXENVBD_DEVICE_DATA xvdd = (PXENVBD_DEVICE_DATA)DeviceExtension;
   1.254    PSCSI_REQUEST_BLOCK srb;
   1.255    RING_IDX i, rp;
   1.256 -  int j;
   1.257    blkif_response_t *rep;
   1.258    int block_count;
   1.259    int more_to_do = TRUE;
   1.260    blkif_shadow_t *shadow;
   1.261 -  ULONG offset;
   1.262 -
   1.263 -  //KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   1.264  
   1.265    /* in dump mode I think we get called on a timer, not by an actual IRQ */
   1.266    if (!dump_mode && !xvdd->vectors.EvtChn_AckEvent(xvdd->vectors.context, xvdd->event_channel))
   1.267      return FALSE; /* interrupt was not for us */
   1.268 +
   1.269 +  //FUNCTION_ENTER();
   1.270 +
   1.271    if (xvdd->device_state->resume_state != xvdd->device_state->resume_state_ack)
   1.272    {
   1.273      FUNCTION_ENTER();
   1.274 @@ -920,47 +850,10 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
   1.275            xvdd->last_additional_sense_code = SCSI_ADSENSE_NO_SENSE;
   1.276            XenVbd_MakeAutoSense(xvdd, srb);
   1.277          }
   1.278 -        for (j = 0; j < shadow->req.nr_segments; j++)
   1.279 -        {
   1.280 -#if DBG
   1.281 -          BOOLEAN result = 
   1.282 -#endif
   1.283 -              xvdd->vectors.GntTbl_EndAccess(xvdd->vectors.context, shadow->req.seg[j].gref, TRUE);
   1.284 -#if DBG
   1.285 -          ASSERT(result);
   1.286 -#endif
   1.287 -          put_grant_on_freelist(xvdd, shadow->req.seg[j].gref);
   1.288 -        }
   1.289  
   1.290 -        if (PtrToUlong(srb->DataBuffer) & 511) /* use SrbExtension intead of DataBuffer if DataBuffer is not aligned to sector size */
   1.291 -        {
   1.292 -          if (decode_cdb_is_read(srb))
   1.293 -            memcpy(((PUCHAR)srb->DataBuffer) + shadow->offset, GET_PAGE_ALIGNED(srb->SrbExtension), shadow->length);
   1.294 -          offset = shadow->offset + shadow->length;
   1.295 -          put_shadow_on_freelist(xvdd, shadow);
   1.296 -          if (offset == (ULONG)block_count * 512)
   1.297 -          {
   1.298 -            ScsiPortNotification(RequestComplete, xvdd, srb);
   1.299 -            ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
   1.300 -          }
   1.301 -          else
   1.302 -          {
   1.303 -            XenVbd_PutSrbOnRing(xvdd, srb, offset);
   1.304 -          }
   1.305 -        }
   1.306 -        else
   1.307 -        {
   1.308 -          put_shadow_on_freelist(xvdd, shadow);
   1.309 -          ScsiPortNotification(RequestComplete, xvdd, srb);
   1.310 -          if (xvdd->pending_srb)
   1.311 -          {
   1.312 -            srb = xvdd->pending_srb;
   1.313 -            xvdd->pending_srb = NULL;
   1.314 -            XenVbd_PutSrbOnRing(xvdd, srb, 0);
   1.315 -          }
   1.316 -          else
   1.317 -            ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
   1.318 -        }
   1.319 +        put_shadow_on_freelist(xvdd, shadow);
   1.320 +        ScsiPortNotification(RequestComplete, xvdd, srb);
   1.321 +        ScsiPortNotification(NextLuRequest, DeviceExtension, 0, 0, 0);
   1.322          break;
   1.323        }
   1.324      }
   1.325 @@ -982,7 +875,7 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
   1.326    //KdPrint((__DRIVER_NAME "     ring.rsp_cons = %d\n", xvdd->ring.rsp_cons));
   1.327    //KdPrint((__DRIVER_NAME "     ring.req_prod_pvt = %d\n", xvdd->ring.req_prod_pvt));
   1.328  
   1.329 -  //KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   1.330 +  //FUNCTION_EXIT();
   1.331  
   1.332    return FALSE; /* always fall through to the next ISR... */
   1.333  }
   1.334 @@ -990,7 +883,8 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
   1.335  static BOOLEAN DDKAPI
   1.336  XenVbd_HwScsiStartIo(PVOID DeviceExtension, PSCSI_REQUEST_BLOCK Srb)
   1.337  {
   1.338 -  PUCHAR DataBuffer;
   1.339 +  PUCHAR data_buffer;
   1.340 +  ULONG data_buffer_length;
   1.341    PCDB cdb;
   1.342    PXENVBD_DEVICE_DATA xvdd = DeviceExtension;
   1.343  
   1.344 @@ -1049,15 +943,15 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.345  //      KdPrint((__DRIVER_NAME "     (LUN = %d, EVPD = %d, Page Code = %02X)\n", Srb->Cdb[1] >> 5, Srb->Cdb[1] & 1, Srb->Cdb[2]));
   1.346  //      KdPrint((__DRIVER_NAME "     (Length = %d)\n", Srb->DataTransferLength));
   1.347  //      KdPrint((__DRIVER_NAME "     (Srb->Databuffer = %08x)\n", Srb->DataBuffer));
   1.348 -      DataBuffer = Srb->DataBuffer;
   1.349 -      RtlZeroMemory(DataBuffer, Srb->DataTransferLength);
   1.350 +      data_buffer = LongLongToPtr(ScsiPortGetPhysicalAddress(xvdd, Srb, Srb->DataBuffer, &data_buffer_length).QuadPart);
   1.351 +      RtlZeroMemory(data_buffer, Srb->DataTransferLength);
   1.352        Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.353        switch (xvdd->device_type)
   1.354        {
   1.355        case XENVBD_DEVICETYPE_DISK:
   1.356          if ((Srb->Cdb[1] & 1) == 0)
   1.357          {
   1.358 -          PINQUIRYDATA id = (PINQUIRYDATA)DataBuffer;
   1.359 +          PINQUIRYDATA id = (PINQUIRYDATA)data_buffer;
   1.360            id->DeviceType = DIRECT_ACCESS_DEVICE;
   1.361            id->Versions = 3;
   1.362            id->ResponseDataFormat = 0;
   1.363 @@ -1072,19 +966,19 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.364            switch (Srb->Cdb[2])
   1.365            {
   1.366            case 0x00:
   1.367 -            DataBuffer[0] = DIRECT_ACCESS_DEVICE;
   1.368 -            DataBuffer[1] = 0x00;
   1.369 -            DataBuffer[2] = 0x00;
   1.370 -            DataBuffer[3] = 2;
   1.371 -            DataBuffer[4] = 0x00;
   1.372 -            DataBuffer[5] = 0x80;
   1.373 +            data_buffer[0] = DIRECT_ACCESS_DEVICE;
   1.374 +            data_buffer[1] = 0x00;
   1.375 +            data_buffer[2] = 0x00;
   1.376 +            data_buffer[3] = 2;
   1.377 +            data_buffer[4] = 0x00;
   1.378 +            data_buffer[5] = 0x80;
   1.379              break;
   1.380            case 0x80:
   1.381 -            DataBuffer[0] = DIRECT_ACCESS_DEVICE;
   1.382 -            DataBuffer[1] = 0x80;
   1.383 -            DataBuffer[2] = 0x00;
   1.384 -            DataBuffer[3] = 8;
   1.385 -            memset(&DataBuffer[4], ' ', 8);
   1.386 +            data_buffer[0] = DIRECT_ACCESS_DEVICE;
   1.387 +            data_buffer[1] = 0x80;
   1.388 +            data_buffer[2] = 0x00;
   1.389 +            data_buffer[3] = 8;
   1.390 +            memset(&data_buffer[4], ' ', 8);
   1.391              break;
   1.392            default:
   1.393              //KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", Srb->Cdb[2]));
   1.394 @@ -1096,7 +990,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.395        case XENVBD_DEVICETYPE_CDROM:
   1.396          if ((Srb->Cdb[1] & 1) == 0)
   1.397          {
   1.398 -          PINQUIRYDATA id = (PINQUIRYDATA)DataBuffer;
   1.399 +          PINQUIRYDATA id = (PINQUIRYDATA)data_buffer;
   1.400            id->DeviceType = READ_ONLY_DIRECT_ACCESS_DEVICE;
   1.401            id->RemovableMedia = 1;
   1.402            id->Versions = 3;
   1.403 @@ -1112,26 +1006,26 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.404            switch (Srb->Cdb[2])
   1.405            {
   1.406            case 0x00:
   1.407 -            DataBuffer[0] = READ_ONLY_DIRECT_ACCESS_DEVICE;
   1.408 -            DataBuffer[1] = 0x00;
   1.409 -            DataBuffer[2] = 0x00;
   1.410 -            DataBuffer[3] = 2;
   1.411 -            DataBuffer[4] = 0x00;
   1.412 -            DataBuffer[5] = 0x80;
   1.413 +            data_buffer[0] = READ_ONLY_DIRECT_ACCESS_DEVICE;
   1.414 +            data_buffer[1] = 0x00;
   1.415 +            data_buffer[2] = 0x00;
   1.416 +            data_buffer[3] = 2;
   1.417 +            data_buffer[4] = 0x00;
   1.418 +            data_buffer[5] = 0x80;
   1.419              break;
   1.420            case 0x80:
   1.421 -            DataBuffer[0] = READ_ONLY_DIRECT_ACCESS_DEVICE;
   1.422 -            DataBuffer[1] = 0x80;
   1.423 -            DataBuffer[2] = 0x00;
   1.424 -            DataBuffer[3] = 8;
   1.425 -            DataBuffer[4] = 0x31;
   1.426 -            DataBuffer[5] = 0x32;
   1.427 -            DataBuffer[6] = 0x33;
   1.428 -            DataBuffer[7] = 0x34;
   1.429 -            DataBuffer[8] = 0x35;
   1.430 -            DataBuffer[9] = 0x36;
   1.431 -            DataBuffer[10] = 0x37;
   1.432 -            DataBuffer[11] = 0x38;
   1.433 +            data_buffer[0] = READ_ONLY_DIRECT_ACCESS_DEVICE;
   1.434 +            data_buffer[1] = 0x80;
   1.435 +            data_buffer[2] = 0x00;
   1.436 +            data_buffer[3] = 8;
   1.437 +            data_buffer[4] = 0x31;
   1.438 +            data_buffer[5] = 0x32;
   1.439 +            data_buffer[6] = 0x33;
   1.440 +            data_buffer[7] = 0x34;
   1.441 +            data_buffer[8] = 0x35;
   1.442 +            data_buffer[9] = 0x36;
   1.443 +            data_buffer[10] = 0x37;
   1.444 +            data_buffer[11] = 0x38;
   1.445              break;
   1.446            default:
   1.447              //KdPrint((__DRIVER_NAME "     Unknown Page %02x requested\n", Srb->Cdb[2]));
   1.448 @@ -1151,26 +1045,26 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.449        //KdPrint((__DRIVER_NAME "       LUN = %d, RelAdr = %d\n", Srb->Cdb[1] >> 4, Srb->Cdb[1] & 1));
   1.450        //KdPrint((__DRIVER_NAME "       LBA = %02x%02x%02x%02x\n", Srb->Cdb[2], Srb->Cdb[3], Srb->Cdb[4], Srb->Cdb[5]));
   1.451        //KdPrint((__DRIVER_NAME "       PMI = %d\n", Srb->Cdb[8] & 1));
   1.452 -      DataBuffer = Srb->DataBuffer;
   1.453 -      RtlZeroMemory(DataBuffer, Srb->DataTransferLength);
   1.454 +      data_buffer = LongLongToPtr(ScsiPortGetPhysicalAddress(xvdd, Srb, Srb->DataBuffer, &data_buffer_length).QuadPart);
   1.455 +      RtlZeroMemory(data_buffer, Srb->DataTransferLength);
   1.456        if ((xvdd->total_sectors - 1) >> 32)
   1.457        {
   1.458 -        DataBuffer[0] = 0xff;
   1.459 -        DataBuffer[1] = 0xff;
   1.460 -        DataBuffer[2] = 0xff;
   1.461 -        DataBuffer[3] = 0xff;
   1.462 +        data_buffer[0] = 0xff;
   1.463 +        data_buffer[1] = 0xff;
   1.464 +        data_buffer[2] = 0xff;
   1.465 +        data_buffer[3] = 0xff;
   1.466        }
   1.467        else
   1.468        {
   1.469 -        DataBuffer[0] = (unsigned char)((xvdd->total_sectors - 1) >> 24) & 0xff;
   1.470 -        DataBuffer[1] = (unsigned char)((xvdd->total_sectors - 1) >> 16) & 0xff;
   1.471 -        DataBuffer[2] = (unsigned char)((xvdd->total_sectors - 1) >> 8) & 0xff;
   1.472 -        DataBuffer[3] = (unsigned char)((xvdd->total_sectors - 1) >> 0) & 0xff;
   1.473 +        data_buffer[0] = (unsigned char)((xvdd->total_sectors - 1) >> 24) & 0xff;
   1.474 +        data_buffer[1] = (unsigned char)((xvdd->total_sectors - 1) >> 16) & 0xff;
   1.475 +        data_buffer[2] = (unsigned char)((xvdd->total_sectors - 1) >> 8) & 0xff;
   1.476 +        data_buffer[3] = (unsigned char)((xvdd->total_sectors - 1) >> 0) & 0xff;
   1.477        }
   1.478 -      DataBuffer[4] = (unsigned char)(xvdd->bytes_per_sector >> 24) & 0xff;
   1.479 -      DataBuffer[5] = (unsigned char)(xvdd->bytes_per_sector >> 16) & 0xff;
   1.480 -      DataBuffer[6] = (unsigned char)(xvdd->bytes_per_sector >> 8) & 0xff;
   1.481 -      DataBuffer[7] = (unsigned char)(xvdd->bytes_per_sector >> 0) & 0xff;
   1.482 +      data_buffer[4] = (unsigned char)(xvdd->bytes_per_sector >> 24) & 0xff;
   1.483 +      data_buffer[5] = (unsigned char)(xvdd->bytes_per_sector >> 16) & 0xff;
   1.484 +      data_buffer[6] = (unsigned char)(xvdd->bytes_per_sector >> 8) & 0xff;
   1.485 +      data_buffer[7] = (unsigned char)(xvdd->bytes_per_sector >> 0) & 0xff;
   1.486        Srb->ScsiStatus = 0;
   1.487        Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.488        break;
   1.489 @@ -1179,20 +1073,20 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.490        //KdPrint((__DRIVER_NAME "       LUN = %d, RelAdr = %d\n", Srb->Cdb[1] >> 4, Srb->Cdb[1] & 1));
   1.491        //KdPrint((__DRIVER_NAME "       LBA = %02x%02x%02x%02x\n", Srb->Cdb[2], Srb->Cdb[3], Srb->Cdb[4], Srb->Cdb[5]));
   1.492        //KdPrint((__DRIVER_NAME "       PMI = %d\n", Srb->Cdb[8] & 1));
   1.493 -      DataBuffer = Srb->DataBuffer;
   1.494 -      RtlZeroMemory(DataBuffer, Srb->DataTransferLength);
   1.495 -      DataBuffer[0] = (unsigned char)((xvdd->total_sectors - 1) >> 56) & 0xff;
   1.496 -      DataBuffer[1] = (unsigned char)((xvdd->total_sectors - 1) >> 48) & 0xff;
   1.497 -      DataBuffer[2] = (unsigned char)((xvdd->total_sectors - 1) >> 40) & 0xff;
   1.498 -      DataBuffer[3] = (unsigned char)((xvdd->total_sectors - 1) >> 32) & 0xff;
   1.499 -      DataBuffer[4] = (unsigned char)((xvdd->total_sectors - 1) >> 24) & 0xff;
   1.500 -      DataBuffer[5] = (unsigned char)((xvdd->total_sectors - 1) >> 16) & 0xff;
   1.501 -      DataBuffer[6] = (unsigned char)((xvdd->total_sectors - 1) >> 8) & 0xff;
   1.502 -      DataBuffer[7] = (unsigned char)((xvdd->total_sectors - 1) >> 0) & 0xff;
   1.503 -      DataBuffer[8] = (unsigned char)(xvdd->bytes_per_sector >> 24) & 0xff;
   1.504 -      DataBuffer[9] = (unsigned char)(xvdd->bytes_per_sector >> 16) & 0xff;
   1.505 -      DataBuffer[10] = (unsigned char)(xvdd->bytes_per_sector >> 8) & 0xff;
   1.506 -      DataBuffer[11] = (unsigned char)(xvdd->bytes_per_sector >> 0) & 0xff;
   1.507 +      data_buffer = LongLongToPtr(ScsiPortGetPhysicalAddress(xvdd, Srb, Srb->DataBuffer, &data_buffer_length).QuadPart);
   1.508 +      RtlZeroMemory(data_buffer, Srb->DataTransferLength);
   1.509 +      data_buffer[0] = (unsigned char)((xvdd->total_sectors - 1) >> 56) & 0xff;
   1.510 +      data_buffer[1] = (unsigned char)((xvdd->total_sectors - 1) >> 48) & 0xff;
   1.511 +      data_buffer[2] = (unsigned char)((xvdd->total_sectors - 1) >> 40) & 0xff;
   1.512 +      data_buffer[3] = (unsigned char)((xvdd->total_sectors - 1) >> 32) & 0xff;
   1.513 +      data_buffer[4] = (unsigned char)((xvdd->total_sectors - 1) >> 24) & 0xff;
   1.514 +      data_buffer[5] = (unsigned char)((xvdd->total_sectors - 1) >> 16) & 0xff;
   1.515 +      data_buffer[6] = (unsigned char)((xvdd->total_sectors - 1) >> 8) & 0xff;
   1.516 +      data_buffer[7] = (unsigned char)((xvdd->total_sectors - 1) >> 0) & 0xff;
   1.517 +      data_buffer[8] = (unsigned char)(xvdd->bytes_per_sector >> 24) & 0xff;
   1.518 +      data_buffer[9] = (unsigned char)(xvdd->bytes_per_sector >> 16) & 0xff;
   1.519 +      data_buffer[10] = (unsigned char)(xvdd->bytes_per_sector >> 8) & 0xff;
   1.520 +      data_buffer[11] = (unsigned char)(xvdd->bytes_per_sector >> 0) & 0xff;
   1.521        Srb->ScsiStatus = 0;
   1.522        Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.523        break;
   1.524 @@ -1206,7 +1100,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.525      case SCSIOP_WRITE:
   1.526      case SCSIOP_WRITE16:
   1.527  //      KdPrint((__DRIVER_NAME "     Command = READ/WRITE\n"));
   1.528 -      XenVbd_PutSrbOnRing(xvdd, Srb, 0);
   1.529 +      XenVbd_PutSrbOnRing(xvdd, Srb);
   1.530        break;
   1.531      case SCSIOP_VERIFY:
   1.532        // Should we do more here?
   1.533 @@ -1223,7 +1117,7 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.534        Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.535        break;      
   1.536      case SCSIOP_READ_TOC:
   1.537 -      DataBuffer = Srb->DataBuffer;
   1.538 +      data_buffer = LongLongToPtr(ScsiPortGetPhysicalAddress(xvdd, Srb, Srb->DataBuffer, &data_buffer_length).QuadPart);
   1.539  //      DataBuffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, HighPagePriority);
   1.540  /*
   1.541  #define READ_TOC_FORMAT_TOC         0x00
   1.542 @@ -1243,18 +1137,18 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
   1.543        switch (cdb->READ_TOC.Format2)
   1.544        {
   1.545        case READ_TOC_FORMAT_TOC:
   1.546 -        DataBuffer[0] = 0; // length MSB
   1.547 -        DataBuffer[1] = 10; // length LSB
   1.548 -        DataBuffer[2] = 1; // First Track
   1.549 -        DataBuffer[3] = 1; // Last Track
   1.550 -        DataBuffer[4] = 0; // Reserved
   1.551 -        DataBuffer[5] = 0x14; // current position data + uninterrupted data
   1.552 -        DataBuffer[6] = 1; // last complete track
   1.553 -        DataBuffer[7] = 0; // reserved
   1.554 -        DataBuffer[8] = 0; // MSB Block
   1.555 -        DataBuffer[9] = 0;
   1.556 -        DataBuffer[10] = 0;
   1.557 -        DataBuffer[11] = 0; // LSB Block
   1.558 +        data_buffer[0] = 0; // length MSB
   1.559 +        data_buffer[1] = 10; // length LSB
   1.560 +        data_buffer[2] = 1; // First Track
   1.561 +        data_buffer[3] = 1; // Last Track
   1.562 +        data_buffer[4] = 0; // Reserved
   1.563 +        data_buffer[5] = 0x14; // current position data + uninterrupted data
   1.564 +        data_buffer[6] = 1; // last complete track
   1.565 +        data_buffer[7] = 0; // reserved
   1.566 +        data_buffer[8] = 0; // MSB Block
   1.567 +        data_buffer[9] = 0;
   1.568 +        data_buffer[10] = 0;
   1.569 +        data_buffer[11] = 0; // LSB Block
   1.570          Srb->SrbStatus = SRB_STATUS_SUCCESS;
   1.571          break;
   1.572        case READ_TOC_FORMAT_SESSION:
   1.573 @@ -1408,6 +1302,49 @@ XenVbd_HwScsiAdapterControl(PVOID Device
   1.574    return Status;
   1.575  }
   1.576  
   1.577 +PVOID init_driver_extension;
   1.578 +
   1.579 +static BOOLEAN
   1.580 +XenVbd_DmaNeedVirtualAddress(PIRP irp)
   1.581 +{
   1.582 +  PIO_STACK_LOCATION stack;
   1.583 +
   1.584 +  //FUNCTION_ENTER();
   1.585 +  
   1.586 +  stack = IoGetCurrentIrpStackLocation(irp);
   1.587 +  if (stack->MajorFunction != IRP_MJ_SCSI)
   1.588 +  {
   1.589 +    //KdPrint((__DRIVER_NAME "     Not IRP_MJ_SCSI\n"));
   1.590 +    //FUNCTION_EXIT();
   1.591 +    return FALSE; /* this actually shouldn't happen */
   1.592 +  }
   1.593 +  
   1.594 +  switch (stack->Parameters.Scsi.Srb->Cdb[0])
   1.595 +  {
   1.596 +  case SCSIOP_READ:
   1.597 +  case SCSIOP_READ16:
   1.598 +  case SCSIOP_WRITE:
   1.599 +  case SCSIOP_WRITE16:
   1.600 +    //KdPrint((__DRIVER_NAME "     read/write operation\n"));
   1.601 +    //FUNCTION_EXIT();
   1.602 +    return FALSE;
   1.603 +  default:
   1.604 +    //KdPrint((__DRIVER_NAME "     not a read/write operation\n"));
   1.605 +    //FUNCTION_EXIT();
   1.606 +    return TRUE;
   1.607 +  }
   1.608 +}
   1.609 +
   1.610 +static ULONG
   1.611 +XenVbd_DmaGetAlignment(PIRP irp)
   1.612 +{
   1.613 +  UNREFERENCED_PARAMETER(irp);
   1.614 +  
   1.615 +  return 512;
   1.616 +}
   1.617 +
   1.618 +dma_driver_extension_t *dma_driver_extension;
   1.619 +
   1.620  NTSTATUS
   1.621  DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
   1.622  {
   1.623 @@ -1437,8 +1374,11 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   1.624      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "mode", NULL);
   1.625      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sectors", NULL);
   1.626      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_READ_STRING_BACK, "sector-size", NULL);
   1.627 -    ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, NULL, UlongToPtr(144));
   1.628      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL);       
   1.629 +
   1.630 +    IoAllocateDriverObjectExtension(DriverObject, UlongToPtr(XEN_DMA_DRIVER_EXTENSION_MAGIC), sizeof(dma_driver_extension), &dma_driver_extension);  
   1.631 +    dma_driver_extension->need_virtual_address = XenVbd_DmaNeedVirtualAddress;
   1.632 +    dma_driver_extension->get_alignment = XenVbd_DmaGetAlignment;
   1.633    }
   1.634  
   1.635    RtlZeroMemory(&HwInitializationData, sizeof(HW_INITIALIZATION_DATA));
   1.636 @@ -1448,10 +1388,15 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
   1.637    HwInitializationData.DeviceExtensionSize = sizeof(XENVBD_DEVICE_DATA);
   1.638    HwInitializationData.SpecificLuExtensionSize = 0;
   1.639    /* SrbExtension is not always aligned to a page boundary, so we add PAGE_SIZE-1 to it to make sure we have at least UNALIGNED_DOUBLE_BUFFER_SIZE bytes of page aligned memory */
   1.640 -  HwInitializationData.SrbExtensionSize = UNALIGNED_DOUBLE_BUFFER_SIZE + PAGE_SIZE - 1;
   1.641 +  HwInitializationData.SrbExtensionSize = 0; //UNALIGNED_DOUBLE_BUFFER_SIZE + PAGE_SIZE - 1;
   1.642    HwInitializationData.NumberOfAccessRanges = 1;
   1.643 +#if 0
   1.644    HwInitializationData.MapBuffers = TRUE;
   1.645    HwInitializationData.NeedPhysicalAddresses = FALSE;
   1.646 +#else
   1.647 +  HwInitializationData.MapBuffers = FALSE;
   1.648 +  HwInitializationData.NeedPhysicalAddresses = TRUE;
   1.649 +#endif
   1.650    HwInitializationData.TaggedQueuing = FALSE;
   1.651    HwInitializationData.AutoRequestSense = TRUE;
   1.652    HwInitializationData.MultipleRequestPerLu = TRUE;
     2.1 --- a/xenvbd/xenvbd.h	Tue Jan 27 00:46:08 2009 +1100
     2.2 +++ b/xenvbd/xenvbd.h	Tue Jan 27 00:46:33 2009 +1100
     2.3 @@ -42,7 +42,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  
     2.5  #include <xen_windows.h>
     2.6  #include <memory.h>
     2.7 -#include <grant_table.h>
     2.8 +//#include <grant_table.h>
     2.9  #include <event_channel.h>
    2.10  #include <hvm/params.h>
    2.11  #include <hvm/hvm_op.h>
    2.12 @@ -52,7 +52,6 @@ Foundation, Inc., 51 Franklin Street, Fi
    2.13  
    2.14  #define XENVBD_POOL_TAG (ULONG) 'XVBD'
    2.15  
    2.16 -#define UNALIGNED_DOUBLE_BUFFER_SIZE (PAGE_SIZE * 1)
    2.17  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    2.18  #define BLK_RING_SIZE __RING_SIZE((blkif_sring_t *)0, PAGE_SIZE)
    2.19  #define BLK_OTHER_RING_SIZE __RING_SIZE((blkif_other_sring_t *)0, PAGE_SIZE)
    2.20 @@ -84,13 +83,10 @@ DEFINE_RING_TYPES(blkif_other, struct bl
    2.21  typedef struct {
    2.22    blkif_request_t req;
    2.23    PSCSI_REQUEST_BLOCK srb;
    2.24 -  ULONG offset;
    2.25 -  ULONG length;
    2.26  } blkif_shadow_t;
    2.27  
    2.28  #define MAX_SHADOW_ENTRIES 64
    2.29  #define SHADOW_ENTRIES min(MAX_SHADOW_ENTRIES, min(BLK_RING_SIZE, BLK_OTHER_RING_SIZE))
    2.30 -#define MAX_GRANT_ENTRIES 512
    2.31  
    2.32  typedef enum {
    2.33    XENVBD_DEVICETYPE_UNKNOWN,
    2.34 @@ -114,10 +110,6 @@ struct
    2.35    USHORT shadow_free;
    2.36    USHORT shadow_min_free;
    2.37  
    2.38 -  grant_ref_t grant_free_list[MAX_GRANT_ENTRIES];
    2.39 -  USHORT grant_free;
    2.40 -  USHORT grant_entries;
    2.41 -  
    2.42    PUCHAR device_base;
    2.43  
    2.44    blkif_sring_t *sring;
    2.45 @@ -147,7 +139,6 @@ struct
    2.46    ULONGLONG aligned_bytes;
    2.47    ULONGLONG unaligned_requests;
    2.48    ULONGLONG unaligned_bytes;
    2.49 -  ULONGLONG no_free_grant_requests;
    2.50  */
    2.51  } typedef XENVBD_DEVICE_DATA, *PXENVBD_DEVICE_DATA;
    2.52