win-pvdrivers

changeset 563:c16b24b438aa

Allowed branding of disk names via registry.
Filter updates.
author James Harper <james.harper@bendigoit.com.au>
date Sun May 10 20:17:53 2009 +1000 (2009-05-10)
parents 8ab116a713f4
children 3ac377a8136c
files xenvbd/xenvbd.c xenvbd/xenvbd.inx
line diff
     1.1 --- a/xenvbd/xenvbd.c	Sun May 10 20:17:31 2009 +1000
     1.2 +++ b/xenvbd/xenvbd.c	Sun May 10 20:17:53 2009 +1000
     1.3 @@ -38,6 +38,10 @@ Foundation, Inc., 51 Franklin Street, Fi
     1.4  
     1.5  static BOOLEAN dump_mode = FALSE;
     1.6  
     1.7 +CHAR scsi_device_manufacturer[8];
     1.8 +CHAR scsi_disk_model[16];
     1.9 +CHAR scsi_cdrom_model[16];
    1.10 +
    1.11  ULONGLONG parse_numeric_string(PCHAR string)
    1.12  {
    1.13    ULONGLONG val = 0;
    1.14 @@ -748,9 +752,10 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
    1.15    int more_to_do = TRUE;
    1.16    blkif_shadow_t *shadow;
    1.17    ULONG suspend_resume_state_pdo;
    1.18 +  BOOLEAN last_interrupt = FALSE;
    1.19  
    1.20    /* in dump mode I think we get called on a timer, not by an actual IRQ */
    1.21 -  if (!dump_mode && !xvdd->vectors.EvtChn_AckEvent(xvdd->vectors.context, xvdd->event_channel))
    1.22 +  if (!dump_mode && !xvdd->vectors.EvtChn_AckEvent(xvdd->vectors.context, xvdd->event_channel, &last_interrupt))
    1.23      return FALSE; /* interrupt was not for us */
    1.24      
    1.25    suspend_resume_state_pdo = xvdd->device_state->suspend_resume_state_pdo;
    1.26 @@ -786,7 +791,7 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
    1.27  
    1.28    if (xvdd->device_state->suspend_resume_state_fdo != SR_STATE_RUNNING)
    1.29    {
    1.30 -    return FALSE;
    1.31 +    return !last_interrupt;
    1.32    }
    1.33  
    1.34    while (more_to_do)
    1.35 @@ -892,7 +897,7 @@ XenVbd_HwScsiInterrupt(PVOID DeviceExten
    1.36      FUNCTION_EXIT();
    1.37    }
    1.38  
    1.39 -  return FALSE; /* always fall through to the next ISR... */
    1.40 +  return !last_interrupt;
    1.41  }
    1.42  
    1.43  static BOOLEAN DDKAPI
    1.44 @@ -979,8 +984,8 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
    1.45            id->ResponseDataFormat = 0;
    1.46            id->AdditionalLength = FIELD_OFFSET(INQUIRYDATA, VendorSpecific) - FIELD_OFFSET(INQUIRYDATA, AdditionalLength);
    1.47            id->CommandQueue = 1;
    1.48 -          memcpy(id->VendorId, "XEN     ", 8); // vendor id
    1.49 -          memcpy(id->ProductId, "PV DISK         ", 16); // product id
    1.50 +          memcpy(id->VendorId, scsi_device_manufacturer, 8); // vendor id
    1.51 +          memcpy(id->ProductId, scsi_disk_model, 16); // product id
    1.52            memcpy(id->ProductRevisionLevel, "0000", 4); // product revision level
    1.53          }
    1.54          else
    1.55 @@ -1019,8 +1024,8 @@ XenVbd_HwScsiStartIo(PVOID DeviceExtensi
    1.56            id->ResponseDataFormat = 0;
    1.57            id->AdditionalLength = FIELD_OFFSET(INQUIRYDATA, VendorSpecific) - FIELD_OFFSET(INQUIRYDATA, AdditionalLength);
    1.58            id->CommandQueue = 1;
    1.59 -          memcpy(id->VendorId, "XEN     ", 8); // vendor id
    1.60 -          memcpy(id->ProductId, "PV CDROM        ", 16); // product id
    1.61 +          memcpy(id->VendorId, scsi_device_manufacturer, 8); // vendor id
    1.62 +          memcpy(id->ProductId, scsi_cdrom_model, 16); // product id
    1.63            memcpy(id->ProductRevisionLevel, "0000", 4); // product revision level
    1.64          }
    1.65          else
    1.66 @@ -1404,7 +1409,15 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    1.67    HW_INITIALIZATION_DATA HwInitializationData;
    1.68    PVOID driver_extension;
    1.69    PUCHAR ptr;
    1.70 -
    1.71 +  OBJECT_ATTRIBUTES oa;
    1.72 +  HANDLE service_handle;
    1.73 +  UNICODE_STRING param_name;
    1.74 +  HANDLE param_handle;
    1.75 +  UNICODE_STRING value_name;
    1.76 +  CHAR buf[256];
    1.77 +  ULONG buf_len;
    1.78 +  PKEY_VALUE_PARTIAL_INFORMATION kpv;
    1.79 +  
    1.80    FUNCTION_ENTER();
    1.81    KdPrint((__DRIVER_NAME "     IRQL = %d\n", KeGetCurrentIrql()));
    1.82    KdPrint((__DRIVER_NAME "     DriverObject = %p, RegistryPath = %p\n", DriverObject, RegistryPath));
    1.83 @@ -1430,11 +1443,66 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
    1.84      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_GRANT_ENTRIES, NULL, ULongToPtr(BLKIF_MAX_SEGMENTS_PER_REQUEST), NULL); /* for use in crash dump */
    1.85      ADD_XEN_INIT_REQ(&ptr, XEN_INIT_TYPE_END, NULL, NULL, NULL);
    1.86  
    1.87 -    IoAllocateDriverObjectExtension(DriverObject, UlongToPtr(XEN_DMA_DRIVER_EXTENSION_MAGIC), sizeof(dma_driver_extension), &dma_driver_extension);  
    1.88 +    IoAllocateDriverObjectExtension(DriverObject, UlongToPtr(XEN_DMA_DRIVER_EXTENSION_MAGIC), sizeof(dma_driver_extension_t), &dma_driver_extension);  
    1.89      dma_driver_extension->need_virtual_address = XenVbd_DmaNeedVirtualAddress;
    1.90      dma_driver_extension->get_alignment = XenVbd_DmaGetAlignment;
    1.91 +    dma_driver_extension->max_sg_elements = 0;
    1.92 +    
    1.93 +    // get registry service key handle
    1.94 +    // get parameters key handle
    1.95 +    // get disk value name
    1.96 +    // get cdrom value name
    1.97 +    
    1.98 +    InitializeObjectAttributes(&oa, RegistryPath, OBJ_CASE_INSENSITIVE, NULL, NULL);
    1.99 +    status = ZwOpenKey(&service_handle, KEY_READ, &oa);
   1.100 +    if(!NT_SUCCESS(status))
   1.101 +    {
   1.102 +      KdPrint((__DRIVER_NAME "     ZwOpenKey(Service) returned %08x\n", status));
   1.103 +    }
   1.104 +    else
   1.105 +    {
   1.106 +      RtlInitUnicodeString(&param_name, L"Parameters");
   1.107 +      InitializeObjectAttributes(&oa, &param_name, OBJ_CASE_INSENSITIVE, service_handle, NULL);
   1.108 +      status = ZwOpenKey(&param_handle, KEY_READ, &oa);
   1.109 +      if(!NT_SUCCESS(status))
   1.110 +      {
   1.111 +        KdPrint((__DRIVER_NAME "     ZwOpenKey(Parameters) returned %08x\n", status));
   1.112 +      }
   1.113 +      else
   1.114 +      {
   1.115 +        kpv = (PKEY_VALUE_PARTIAL_INFORMATION)buf;
   1.116 +        RtlFillMemory(scsi_device_manufacturer, 8, ' ');
   1.117 +        RtlFillMemory(scsi_disk_model, 16, ' ');
   1.118 +        RtlFillMemory(scsi_cdrom_model, 16, ' ');
   1.119 +
   1.120 +        RtlInitUnicodeString(&value_name, L"Manufacturer");
   1.121 +        buf_len = 256;
   1.122 +        status = ZwQueryValueKey(param_handle, &value_name, KeyValuePartialInformation, buf, buf_len, &buf_len);
   1.123 +        if(NT_SUCCESS(status))
   1.124 +          wcstombs(scsi_device_manufacturer, (PWCHAR)kpv->Data, min(kpv->DataLength, 8));
   1.125 +        else
   1.126 +          strncpy(scsi_device_manufacturer, "XEN     ", 8);
   1.127 +
   1.128 +        RtlInitUnicodeString(&value_name, L"Disk_Model");
   1.129 +        buf_len = 256;
   1.130 +        status = ZwQueryValueKey(param_handle, &value_name, KeyValuePartialInformation, buf, buf_len, &buf_len);
   1.131 +        if(NT_SUCCESS(status))
   1.132 +          wcstombs(scsi_disk_model, (PWCHAR)kpv->Data, min(kpv->DataLength, 16));
   1.133 +        else
   1.134 +          strncpy(scsi_disk_model, "PV DISK          ", 16);
   1.135 +
   1.136 +        RtlInitUnicodeString(&value_name, L"CDROM_Model");
   1.137 +        buf_len = 256;
   1.138 +        status = ZwQueryValueKey(param_handle, &value_name, KeyValuePartialInformation, buf, buf_len, &buf_len);
   1.139 +        if(NT_SUCCESS(status))
   1.140 +          wcstombs(scsi_cdrom_model, (PWCHAR)kpv->Data, min(kpv->DataLength, 16));
   1.141 +        else
   1.142 +          strncpy(scsi_cdrom_model, "PV CDROM        ", 16);
   1.143 +      }
   1.144 +      ZwClose(service_handle);
   1.145 +    }
   1.146    }
   1.147 -
   1.148 +  
   1.149    RtlZeroMemory(&HwInitializationData, sizeof(HW_INITIALIZATION_DATA));
   1.150  
   1.151    HwInitializationData.HwInitializationDataSize = sizeof(HW_INITIALIZATION_DATA);
     2.1 --- a/xenvbd/xenvbd.inx	Sun May 10 20:17:31 2009 +1000
     2.2 +++ b/xenvbd/xenvbd.inx	Sun May 10 20:17:53 2009 +1000
     2.3 @@ -37,10 +37,6 @@ AddReg = XenVbd_Service_AddReg
     2.4  
     2.5  [XenVbd_Service_AddReg]
     2.6  HKR,"Parameters\PnpInterface", "15", 0x00010001, 0x00000001
     2.7 -; Add XenHide as a filter to IDE Controllers
     2.8 -HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E96A-E325-11CE-BFC1-08002BE10318},UpperFilters,0x00010008,XenHide
     2.9 -; Add XenHide as a filter to SCSI Controllers
    2.10 -HKLM,SYSTEM\CurrentControlSet\Control\Class\{4D36E97B-E325-11CE-BFC1-08002BE10318},UpperFilters,0x00010008,XenHide
    2.11  
    2.12  [XenVbd_EventLog]
    2.13  AddReg = XenVbd_EventLog_AddReg