win-pvdrivers

changeset 363:097ab7d19ea2

Merge bug fixer from WDF to WDM.
author Wayne Gong <wayne.gong@oracle.com>
date Mon Jul 07 14:03:39 2008 +0800 (2008-07-07)
parents f7a5c1889c36
children 2ff96a909c28
files xenhide/xenhide.c xenpci/gnttbl.c xenpci/xenpci.h xenvbd/scsiport.c xenvbd/xenvbd.h xenvbd/xenvbd.inx
line diff
     1.1 --- a/xenhide/xenhide.c	Mon Jul 07 20:45:27 2008 +1000
     1.2 +++ b/xenhide/xenhide.c	Mon Jul 07 14:03:39 2008 +0800
     1.3 @@ -60,8 +60,8 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
     1.4    UNICODE_STRING RegValueName;
     1.5    HANDLE RegHandle;
     1.6    OBJECT_ATTRIBUTES RegObjectAttributes;
     1.7 -  char Buf[200];
     1.8 -  ULONG BufLen = 200;
     1.9 +  char Buf[300];// Sometimes bigger then 200 if system reboot from crash
    1.10 +  ULONG BufLen = 300;
    1.11    PKEY_VALUE_PARTIAL_INFORMATION KeyPartialValue;
    1.12    int State = 0;
    1.13    size_t StartPos = 0;
    1.14 @@ -249,8 +249,9 @@ XenHide_AddDevice(
    1.15    if (gplpv)
    1.16    {
    1.17      /* hide only specific devices */
    1.18 -    if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_8086&DEV_7010")
    1.19 -      || XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_10EC&DEV_8139"))
    1.20 +    if (XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_8086&DEV_7010") // Qemu IDE
    1.21 +      || XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_10EC&DEV_8139") // Qemu Network
    1.22 +      || XenHide_IdSuffixMatches(PhysicalDeviceObject, L"VEN_1000&DEV_0012"))// Qemu SCSI
    1.23      {
    1.24        hide_type = XENHIDE_TYPE_DEVICE;
    1.25      }
     2.1 --- a/xenpci/gnttbl.c	Mon Jul 07 20:45:27 2008 +1000
     2.2 +++ b/xenpci/gnttbl.c	Mon Jul 07 14:03:39 2008 +0800
     2.3 @@ -149,28 +149,59 @@ 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 +  struct gnttab_query_size query;
    2.12 +  int rc;
    2.13 +
    2.14 +  query.dom = DOMID_SELF;
    2.15 +
    2.16 +  rc = HYPERVISOR_grant_table_op(xpdd,GNTTABOP_query_size, &query, 1);
    2.17 +  if ((rc < 0) || (query.status != GNTST_okay))
    2.18 +  {
    2.19 +    KdPrint((__DRIVER_NAME "     ***CANNOT QUERY MAX GRANT FRAME***\n"));
    2.20 +    return 4; /* Legacy max supported number of frames */
    2.21 +  }
    2.22 +  return query.max_nr_frames;
    2.23 +}
    2.24 +#endif
    2.25 +
    2.26  VOID
    2.27  GntTbl_Init(PXENPCI_DEVICE_DATA xpdd)
    2.28  {
    2.29    int i;
    2.30 -
    2.31 +  int max_grant_frames = NR_GRANT_FRAMES;
    2.32 +  int max_grant_entries = NR_GRANT_ENTRIES;
    2.33    //KdPrint((__DRIVER_NAME " --> GntTbl_Init\n"));
    2.34    
    2.35    KeInitializeSpinLock(&xpdd->grant_lock);
    2.36  
    2.37 -  for (i = NR_RESERVED_ENTRIES; i < NR_GRANT_ENTRIES; i++)
    2.38 +#if defined(_X86_)
    2.39 +  max_grant_frames = GntTbl_QueryMaxFrames(xpdd);
    2.40 +  max_grant_entries = min(NR_GRANT_ENTRIES,(max_grant_frames * PAGE_SIZE / sizeof(grant_entry_t)));
    2.41 +  KdPrint((__DRIVER_NAME "     max_grant_entries : %d\n",max_grant_entries));
    2.42 +#else
    2.43 +  #if defined(_AMD64_)
    2.44 +    KdPrint((__DRIVER_NAME "     AMD64 cannot support HYPERVISOR_grant_table_op now\n"));
    2.45 +  #endif
    2.46 +#endif
    2.47 +
    2.48 +  xpdd->gnttab_list = ExAllocatePoolWithTag(NonPagedPool, sizeof(grant_ref_t) * max_grant_entries, XENPCI_POOL_TAG);// Where to free?
    2.49 +  for (i = NR_RESERVED_ENTRIES; i < max_grant_entries; i++)
    2.50      GntTbl_PutRef(xpdd, i);
    2.51  
    2.52    xpdd->gnttab_table_physical = XenPci_AllocMMIO(xpdd,
    2.53 -    PAGE_SIZE * NR_GRANT_FRAMES);
    2.54 +    PAGE_SIZE * max_grant_frames);
    2.55    xpdd->gnttab_table = MmMapIoSpace(xpdd->gnttab_table_physical,
    2.56 -    PAGE_SIZE * NR_GRANT_FRAMES, MmNonCached);
    2.57 +    PAGE_SIZE * max_grant_frames, MmNonCached);
    2.58    if (!xpdd->gnttab_table)
    2.59    {
    2.60      KdPrint((__DRIVER_NAME "     Error Mapping Grant Table Shared Memory\n"));
    2.61      return;
    2.62    }
    2.63 -  GntTbl_Map(xpdd, 0, NR_GRANT_FRAMES - 1);
    2.64 +  GntTbl_Map(xpdd, 0, max_grant_frames - 1);
    2.65  
    2.66    //KdPrint((__DRIVER_NAME " <-- GntTbl_Init table mapped at %p\n", gnttab_table));
    2.67  }
     3.1 --- a/xenpci/xenpci.h	Mon Jul 07 20:45:27 2008 +1000
     3.2 +++ b/xenpci/xenpci.h	Mon Jul 07 14:03:39 2008 +0800
     3.3 @@ -57,7 +57,7 @@ DEFINE_GUID( GUID_XENPCI_DEVCLASS, 0xC82
     3.4  #define XENPCI_POOL_TAG (ULONG) 'XenP'
     3.5  
     3.6  #define NR_RESERVED_ENTRIES 8
     3.7 -#define NR_GRANT_FRAMES 4
     3.8 +#define NR_GRANT_FRAMES 32
     3.9  #define NR_GRANT_ENTRIES (NR_GRANT_FRAMES * PAGE_SIZE / sizeof(grant_entry_t))
    3.10  
    3.11  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
    3.12 @@ -184,7 +184,7 @@ typedef struct {
    3.13  
    3.14    grant_entry_t *gnttab_table;
    3.15    PHYSICAL_ADDRESS gnttab_table_physical;
    3.16 -  grant_ref_t gnttab_list[NR_GRANT_ENTRIES];
    3.17 +  grant_ref_t *gnttab_list;
    3.18  
    3.19    ev_action_t ev_actions[NR_EVENTS];
    3.20  //  unsigned long bound_ports[NR_EVENTS/(8*sizeof(unsigned long))];
     4.1 --- a/xenvbd/scsiport.c	Mon Jul 07 20:45:27 2008 +1000
     4.2 +++ b/xenvbd/scsiport.c	Mon Jul 07 14:03:39 2008 +0800
     4.3 @@ -180,6 +180,24 @@ XenVbd_InitFromConfig(PXENVBD_DEVICE_DAT
     4.4            xvdd->device_type = XENVBD_DEVICETYPE_UNKNOWN;
     4.5          }
     4.6        }
     4.7 +      else if (strcmp(setting, "mode") == 0)
     4.8 +      {
     4.9 +        if (strncmp(value, "r", 1) == 0)
    4.10 +        {
    4.11 +          KdPrint((__DRIVER_NAME "     mode = r\n"));    
    4.12 +          xvdd->device_mode = XENVBD_DEVICEMODE_READ;
    4.13 +        }
    4.14 +        else if (strncmp(value, "w", 1) == 0)
    4.15 +        {
    4.16 +          KdPrint((__DRIVER_NAME "     mode = w\n"));    
    4.17 +          xvdd->device_mode = XENVBD_DEVICEMODE_WRITE;
    4.18 +        }
    4.19 +        else
    4.20 +        {
    4.21 +          KdPrint((__DRIVER_NAME "     mode = unknown\n"));
    4.22 +          xvdd->device_mode = XENVBD_DEVICEMODE_UNKNOWN;
    4.23 +        }
    4.24 +      }
    4.25        break;
    4.26      case XEN_INIT_TYPE_VECTORS:
    4.27        //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_VECTORS\n"));
    4.28 @@ -544,6 +562,12 @@ XenVbd_FillModePage(PXENVBD_DEVICE_DATA 
    4.29    parameter_header->BlockDescriptorLength = 0;
    4.30    offset += sizeof(MODE_PARAMETER_HEADER);
    4.31    
    4.32 +  if (xvdd->device_mode == XENVBD_DEVICEMODE_READ)
    4.33 +  {
    4.34 +    KdPrint((__DRIVER_NAME " Mode sense to a read only disk.\n"));
    4.35 +    parameter_header->DeviceSpecificParameter|=MODE_DSP_WRITE_PROTECT; 
    4.36 +  }
    4.37 +  
    4.38    if (!cdb->MODE_SENSE.Dbd)
    4.39    {
    4.40      parameter_header->BlockDescriptorLength += sizeof(MODE_PARAMETER_BLOCK);
     5.1 --- a/xenvbd/xenvbd.h	Mon Jul 07 20:45:27 2008 +1000
     5.2 +++ b/xenvbd/xenvbd.h	Mon Jul 07 14:03:39 2008 +0800
     5.3 @@ -90,6 +90,12 @@ typedef enum {
     5.4    XENVBD_DEVICETYPE_CONTROLLER // Not yet used
     5.5  } XENVBD_DEVICETYPE;
     5.6  
     5.7 +typedef enum {
     5.8 +  XENVBD_DEVICEMODE_UNKNOWN,
     5.9 +  XENVBD_DEVICEMODE_READ,
    5.10 +  XENVBD_DEVICEMODE_WRITE
    5.11 +} XENVBD_DEVICEMODE;
    5.12 +
    5.13  struct
    5.14  {
    5.15    blkif_shadow_t shadows[SHADOW_ENTRIES];
    5.16 @@ -115,6 +121,7 @@ struct
    5.17    UCHAR last_additional_sense_code;
    5.18    blkif_response_t tmp_rep;
    5.19    XENVBD_DEVICETYPE device_type;
    5.20 +  XENVBD_DEVICEMODE device_mode;
    5.21    DISK_GEOMETRY Geometry;
    5.22    ULONG bytes_per_sector;
    5.23    ULONGLONG total_sectors;
     6.1 --- a/xenvbd/xenvbd.inx	Mon Jul 07 20:45:27 2008 +1000
     6.2 +++ b/xenvbd/xenvbd.inx	Mon Jul 07 14:03:39 2008 +0800
     6.3 @@ -62,6 +62,7 @@ AddReg = XenVbd_XenConfig_AddReg, XenVbd
     6.4  HKR,"XenConfig\ring-ref", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_RING%
     6.5  HKR,"XenConfig\event-channel", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_EVENT_CHANNEL_IRQ%
     6.6  HKR,"XenConfig\device-type", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_FRONT%
     6.7 +HKR,"XenConfig\mode", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
     6.8  HKR,"XenConfig\sectors", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
     6.9  HKR,"XenConfig\sector-size", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_READ_STRING_BACK%
    6.10  HKR,"XenConfig\vectors", "type", %FLG_ADDREG_TYPE_DWORD%, %XEN_INIT_TYPE_VECTORS%