win-pvdrivers

changeset 1019:df03fde445b8

tidyup xenpci
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 12 20:45:25 2013 +1100 (2013-02-12)
parents 9c6af8d0bdb6
children 2cbbfed14af4
files xenpci/xenbus.c xenpci/xenpci_pdo.c
line diff
     1.1 --- a/xenpci/xenbus.c	Tue Feb 12 20:45:08 2013 +1100
     1.2 +++ b/xenpci/xenbus.c	Tue Feb 12 20:45:25 2013 +1100
     1.3 @@ -636,12 +636,11 @@ XenBus_AddWatch(
     1.4  
     1.5  char *
     1.6  XenBus_RemWatch(
     1.7 -  PVOID Context,
     1.8 -  xenbus_transaction_t xbt,
     1.9 -  char *Path,
    1.10 -  PXN_WATCH_CALLBACK ServiceRoutine,
    1.11 -  PVOID ServiceContext)
    1.12 -{
    1.13 +    PVOID Context,
    1.14 +    xenbus_transaction_t xbt,
    1.15 +    char *Path,
    1.16 +    PXN_WATCH_CALLBACK ServiceRoutine,
    1.17 +    PVOID ServiceContext) {
    1.18    PXENPCI_DEVICE_DATA xpdd = Context;
    1.19    char *msg;
    1.20    int i;
    1.21 @@ -652,20 +651,17 @@ XenBus_RemWatch(
    1.22  
    1.23    // check that Path < 128 chars
    1.24  
    1.25 -  for (i = 0; i < MAX_WATCH_ENTRIES; i++)
    1.26 -  {
    1.27 +  for (i = 0; i < MAX_WATCH_ENTRIES; i++) {
    1.28      if (xpdd->XenBus_WatchEntries[i].Active
    1.29 -      && !strcmp(xpdd->XenBus_WatchEntries[i].Path, Path)
    1.30 -      && xpdd->XenBus_WatchEntries[i].ServiceRoutine == ServiceRoutine
    1.31 -      && xpdd->XenBus_WatchEntries[i].ServiceContext == ServiceContext)
    1.32 -    {
    1.33 +        && !strcmp(xpdd->XenBus_WatchEntries[i].Path, Path)
    1.34 +        && xpdd->XenBus_WatchEntries[i].ServiceRoutine == ServiceRoutine
    1.35 +        && xpdd->XenBus_WatchEntries[i].ServiceContext == ServiceContext) {
    1.36        KdPrint((__DRIVER_NAME "     Match\n"));
    1.37        break;
    1.38      }
    1.39    }
    1.40  
    1.41 -  if (i == MAX_WATCH_ENTRIES)
    1.42 -  {
    1.43 +  if (i == MAX_WATCH_ENTRIES) {
    1.44      ExReleaseFastMutex(&xpdd->xb_watch_mutex);
    1.45      KdPrint((__DRIVER_NAME "     Watch not set for %s - can't remove\n", Path));
    1.46      return NULL;
     2.1 --- a/xenpci/xenpci_pdo.c	Tue Feb 12 20:45:08 2013 +1100
     2.2 +++ b/xenpci/xenpci_pdo.c	Tue Feb 12 20:45:25 2013 +1100
     2.3 @@ -28,11 +28,7 @@ Foundation, Inc., 51 Franklin Street, Fi
     2.4  static EVT_WDF_INTERRUPT_SYNCHRONIZE XenPci_EvtChn_Sync_Routine;
     2.5  static EVT_WDF_DEVICE_D0_ENTRY XenPciPdo_EvtDeviceD0Entry;
     2.6  static EVT_WDF_DEVICE_D0_EXIT XenPciPdo_EvtDeviceD0Exit;
     2.7 -static EVT_WDF_DEVICE_PREPARE_HARDWARE XenPciPdo_EvtDevicePrepareHardware;
     2.8 -static EVT_WDF_DEVICE_RELEASE_HARDWARE XenPciPdo_EvtDeviceReleaseHardware;
     2.9  static EVT_WDF_DEVICE_USAGE_NOTIFICATION XenPciPdo_EvtDeviceUsageNotification;
    2.10 -//static EVT_WDFDEVICE_WDM_IRP_PREPROCESS XenPciPdo_EvtDeviceWdmIrpPreprocess_START_DEVICE;
    2.11 -//static EVT_WDF_DEVICE_RESOURCE_REQUIREMENTS_QUERY XenPciPdo_EvtDeviceResourceRequirementsQuery;
    2.12  static EVT_WDF_DEVICE_PNP_STATE_CHANGE_NOTIFICATION XenPci_EvtDevicePnpStateChange;
    2.13  
    2.14  
    2.15 @@ -65,99 +61,6 @@ XenPci_ReadBackendState(PXENPCI_PDO_DEVI
    2.16    }
    2.17  }
    2.18  
    2.19 -static VOID
    2.20 -XenPci_UpdateBackendState(PVOID context)
    2.21 -{
    2.22 -  WDFDEVICE device = context;
    2.23 -  PXENPCI_PDO_DEVICE_DATA xppdd = GetXppdd(device);
    2.24 -  PXENPCI_DEVICE_DATA xpdd = GetXpdd(xppdd->wdf_device_bus_fdo);
    2.25 -  ULONG new_backend_state;
    2.26 -
    2.27 -  FUNCTION_ENTER();
    2.28 -
    2.29 -  ExAcquireFastMutex(&xppdd->backend_state_mutex);
    2.30 -
    2.31 -  new_backend_state = XenPci_ReadBackendState(xppdd);
    2.32 -  if (new_backend_state == XenbusStateUnknown)
    2.33 -  {
    2.34 -    if (xpdd->suspend_state != SUSPEND_STATE_NONE)
    2.35 -    {
    2.36 -      ExReleaseFastMutex(&xppdd->backend_state_mutex);
    2.37 -      return;
    2.38 -    }
    2.39 -    KdPrint(("Failed to read path, assuming closed\n"));
    2.40 -    new_backend_state = XenbusStateClosed;
    2.41 -  }
    2.42 -
    2.43 -  if (xppdd->backend_state == new_backend_state)
    2.44 -  {
    2.45 -    KdPrint((__DRIVER_NAME "     state unchanged\n"));
    2.46 -    ExReleaseFastMutex(&xppdd->backend_state_mutex);
    2.47 -    return;
    2.48 -  }
    2.49 -  
    2.50 -  xppdd->backend_state = new_backend_state;
    2.51 -
    2.52 -  switch (xppdd->backend_state)
    2.53 -  {
    2.54 -  case XenbusStateUnknown:
    2.55 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Unknown\n"));
    2.56 -    break;
    2.57 -
    2.58 -  case XenbusStateInitialising:
    2.59 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialising\n"));
    2.60 -    break;
    2.61 -
    2.62 -  case XenbusStateInitWait:
    2.63 -    KdPrint((__DRIVER_NAME "     Backend State Changed to InitWait\n"));
    2.64 -    break;
    2.65 -
    2.66 -  case XenbusStateInitialised:
    2.67 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Initialised\n"));
    2.68 -    break;
    2.69 -
    2.70 -  case XenbusStateConnected:
    2.71 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Connected\n"));  
    2.72 -    break;
    2.73 -
    2.74 -  case XenbusStateClosing:
    2.75 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closing\n"));
    2.76 -    if (xppdd->frontend_state != XenbusStateClosing)
    2.77 -    {
    2.78 -      xppdd->backend_initiated_remove = TRUE;
    2.79 -      KdPrint((__DRIVER_NAME "     Requesting eject\n"));
    2.80 -      WdfPdoRequestEject(device);
    2.81 -    }
    2.82 -    break;
    2.83 -
    2.84 -  case XenbusStateClosed:
    2.85 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Closed\n"));
    2.86 -    break;
    2.87 -  
    2.88 -  default:
    2.89 -    KdPrint((__DRIVER_NAME "     Backend State Changed to Undefined = %d\n", xppdd->backend_state));
    2.90 -    break;
    2.91 -  }
    2.92 -
    2.93 -  KeSetEvent(&xppdd->backend_state_event, 1, FALSE);
    2.94 -
    2.95 -  ExReleaseFastMutex(&xppdd->backend_state_mutex);
    2.96 -  FUNCTION_EXIT();
    2.97 -
    2.98 -  return;
    2.99 -}
   2.100 -
   2.101 -static VOID
   2.102 -XenPci_BackendStateHandler(char *path, PVOID context)
   2.103 -{
   2.104 -  UNREFERENCED_PARAMETER(path);
   2.105 -
   2.106 -  /* check that path == device/id/state */
   2.107 -  //RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->path);
   2.108 -
   2.109 -  XenPci_UpdateBackendState(context);
   2.110 -}
   2.111 -
   2.112  static NTSTATUS
   2.113  XenPci_GetBackendDetails(WDFDEVICE device)
   2.114  {
   2.115 @@ -242,18 +145,16 @@ XenPci_ResumePdo(WDFDEVICE device) {
   2.116  }
   2.117  
   2.118  NTSTATUS
   2.119 -XenPciPdo_EvtDeviceD0Entry(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state)
   2.120 -{
   2.121 +XenPciPdo_EvtDeviceD0Entry(WDFDEVICE device, WDF_POWER_DEVICE_STATE previous_state) {
   2.122    NTSTATUS status = STATUS_SUCCESS;
   2.123    PXENPCI_PDO_DEVICE_DATA xppdd = GetXppdd(device);
   2.124 -  PXENPCI_DEVICE_DATA xpdd = GetXpdd(xppdd->wdf_device_bus_fdo);
   2.125 +  //PXENPCI_DEVICE_DATA xpdd = GetXpdd(xppdd->wdf_device_bus_fdo);
   2.126    CHAR path[128];
   2.127    
   2.128    FUNCTION_ENTER();
   2.129    KdPrint((__DRIVER_NAME "     path = %s\n", xppdd->path));
   2.130  
   2.131 -  switch (previous_state)
   2.132 -  {
   2.133 +  switch (previous_state) {
   2.134    case WdfPowerDeviceD0:
   2.135      KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   2.136      break;
   2.137 @@ -265,8 +166,7 @@ XenPciPdo_EvtDeviceD0Entry(WDFDEVICE dev
   2.138      break;
   2.139    case WdfPowerDeviceD3:
   2.140      KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   2.141 -    if (xppdd->hiber_usage_kludge)
   2.142 -    {
   2.143 +    if (xppdd->hiber_usage_kludge) {
   2.144        KdPrint((__DRIVER_NAME "     (but really WdfPowerDevicePrepareForHibernation)\n"));
   2.145        previous_state = WdfPowerDevicePrepareForHibernation;
   2.146      }
   2.147 @@ -283,45 +183,15 @@ XenPciPdo_EvtDeviceD0Entry(WDFDEVICE dev
   2.148    }
   2.149  
   2.150    status = XenPci_GetBackendDetails(device);
   2.151 -  if (!NT_SUCCESS(status))
   2.152 -  {
   2.153 +  if (!NT_SUCCESS(status)) {
   2.154      WdfDeviceSetFailed(device, WdfDeviceFailedNoRestart);
   2.155      FUNCTION_EXIT_STATUS(status);
   2.156      return status;
   2.157    }
   2.158  
   2.159 -  if (previous_state == WdfPowerDeviceD3 || previous_state == WdfPowerDeviceD3Final)
   2.160 -  {
   2.161 -#if 0
   2.162 -    xppdd->requested_resources_ptr = xppdd->requested_resources_start;
   2.163 -    xppdd->assigned_resources_start = xppdd->assigned_resources_ptr = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
   2.164 -    XenConfig_InitConfigPage(device);
   2.165 -    status = XenPci_XenConfigDevice(device);
   2.166 -#endif
   2.167 -  }
   2.168 -  else if (previous_state == WdfPowerDevicePrepareForHibernation)
   2.169 -  {
   2.170 -#if 0
   2.171 -    PVOID src, dst;
   2.172 -    
   2.173 -    ADD_XEN_INIT_REQ(&xppdd->requested_resources_ptr, XEN_INIT_TYPE_END, NULL, NULL, NULL);
   2.174 -    src = xppdd->requested_resources_start;
   2.175 -    xppdd->requested_resources_ptr = xppdd->requested_resources_start = ExAllocatePoolWithTag(NonPagedPool, PAGE_SIZE, XENPCI_POOL_TAG);
   2.176 -    xppdd->assigned_resources_ptr = xppdd->assigned_resources_start;
   2.177 -
   2.178 -    dst = MmMapIoSpace(xppdd->config_page_phys, xppdd->config_page_length, MmNonCached);
   2.179 -
   2.180 -    status = XenPci_XenConfigDeviceSpecifyBuffers(device, src, dst);
   2.181 -
   2.182 -    MmUnmapIoSpace(dst, xppdd->config_page_length);
   2.183 -    ExFreePoolWithTag(src, XENPCI_POOL_TAG);
   2.184 -#endif
   2.185 -  }
   2.186 -
   2.187 -  if (!NT_SUCCESS(status))
   2.188 -  {
   2.189 +  if (!NT_SUCCESS(status)) {
   2.190      RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
   2.191 -    XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackendStateHandler, device);
   2.192 +    //XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackendStateHandler, device);
   2.193      WdfDeviceSetFailed(device, WdfDeviceFailedNoRestart);
   2.194      FUNCTION_EXIT_STATUS(status);
   2.195      return status;
   2.196 @@ -333,11 +203,10 @@ XenPciPdo_EvtDeviceD0Entry(WDFDEVICE dev
   2.197  }
   2.198  
   2.199  NTSTATUS
   2.200 -XenPciPdo_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state)
   2.201 -{
   2.202 +XenPciPdo_EvtDeviceD0Exit(WDFDEVICE device, WDF_POWER_DEVICE_STATE target_state) {
   2.203    NTSTATUS status = STATUS_SUCCESS;
   2.204    PXENPCI_PDO_DEVICE_DATA xppdd = GetXppdd(device);
   2.205 -  PXENPCI_DEVICE_DATA xpdd = GetXpdd(xppdd->wdf_device_bus_fdo);
   2.206 +  //PXENPCI_DEVICE_DATA xpdd = GetXpdd(xppdd->wdf_device_bus_fdo);
   2.207    char path[128];
   2.208    
   2.209    UNREFERENCED_PARAMETER(device);
   2.210 @@ -346,8 +215,7 @@ XenPciPdo_EvtDeviceD0Exit(WDFDEVICE devi
   2.211    FUNCTION_ENTER();
   2.212    KdPrint((__DRIVER_NAME "     path = %s\n", xppdd->path));
   2.213    
   2.214 -  switch (target_state)
   2.215 -  {
   2.216 +  switch (target_state) {
   2.217    case WdfPowerDeviceD0:
   2.218      KdPrint((__DRIVER_NAME "     WdfPowerDeviceD1\n"));
   2.219      break;
   2.220 @@ -359,8 +227,7 @@ XenPciPdo_EvtDeviceD0Exit(WDFDEVICE devi
   2.221      break;
   2.222    case WdfPowerDeviceD3:
   2.223      KdPrint((__DRIVER_NAME "     WdfPowerDeviceD3\n"));
   2.224 -    if (xppdd->hiber_usage_kludge)
   2.225 -    {
   2.226 +    if (xppdd->hiber_usage_kludge) {
   2.227        KdPrint((__DRIVER_NAME "     (but really WdfPowerDevicePrepareForHibernation)\n"));
   2.228        target_state = WdfPowerDevicePrepareForHibernation;
   2.229      }
   2.230 @@ -381,46 +248,11 @@ XenPciPdo_EvtDeviceD0Exit(WDFDEVICE devi
   2.231      KdPrint((__DRIVER_NAME "     not powering down as we are hibernating\n"));
   2.232      // should we set the backend state here so it's correct on resume???
   2.233    }
   2.234 -  else
   2.235 -  {
   2.236 -#if 0
   2.237 -    status = XenPci_XenShutdownDevice(device);
   2.238 -#endif
   2.239 -  }
   2.240    
   2.241    /* Remove watch on backend state */
   2.242    RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/state", xppdd->backend_path);
   2.243 -  XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackendStateHandler, device);
   2.244 -  
   2.245 -  FUNCTION_EXIT();
   2.246 +  //XenBus_RemWatch(xpdd, XBT_NIL, path, XenPci_BackendStateHandler, device);
   2.247    
   2.248 -  return status;
   2.249 -}
   2.250 -
   2.251 -NTSTATUS
   2.252 -XenPciPdo_EvtDevicePrepareHardware(WDFDEVICE device, WDFCMRESLIST resources_raw, WDFCMRESLIST resources_translated)
   2.253 -{
   2.254 -  NTSTATUS status = STATUS_SUCCESS;
   2.255 -
   2.256 -  UNREFERENCED_PARAMETER(device);
   2.257 -  UNREFERENCED_PARAMETER(resources_raw);
   2.258 -  UNREFERENCED_PARAMETER(resources_translated);
   2.259 -  
   2.260 -  FUNCTION_ENTER();
   2.261 -  FUNCTION_EXIT();
   2.262 -  
   2.263 -  return status;
   2.264 -}
   2.265 -
   2.266 -NTSTATUS
   2.267 -XenPciPdo_EvtDeviceReleaseHardware(WDFDEVICE device, WDFCMRESLIST resources_translated)
   2.268 -{
   2.269 -  NTSTATUS status = STATUS_SUCCESS;
   2.270 -  
   2.271 -  UNREFERENCED_PARAMETER(device);
   2.272 -  UNREFERENCED_PARAMETER(resources_translated);
   2.273 -  
   2.274 -  FUNCTION_ENTER();
   2.275    FUNCTION_EXIT();
   2.276    
   2.277    return status;
   2.278 @@ -502,11 +334,7 @@ XenPci_EvtChildListCreateDevice(WDFCHILD
   2.279    
   2.280    WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&child_pnp_power_callbacks);
   2.281    child_pnp_power_callbacks.EvtDeviceD0Entry = XenPciPdo_EvtDeviceD0Entry;
   2.282 -  //child_pnp_power_callbacks.EvtDeviceD0EntryPostInterruptsEnabled = XenPciPdo_EvtDeviceD0EntryPostInterruptsEnabled;
   2.283    child_pnp_power_callbacks.EvtDeviceD0Exit = XenPciPdo_EvtDeviceD0Exit;
   2.284 -  //child_pnp_power_callbacks.EvtDeviceD0ExitPreInterruptsDisabled = XenPciPdo_EvtDeviceD0ExitPreInterruptsDisabled;
   2.285 -  child_pnp_power_callbacks.EvtDevicePrepareHardware = XenPciPdo_EvtDevicePrepareHardware;
   2.286 -  child_pnp_power_callbacks.EvtDeviceReleaseHardware = XenPciPdo_EvtDeviceReleaseHardware;
   2.287    child_pnp_power_callbacks.EvtDeviceUsageNotification = XenPciPdo_EvtDeviceUsageNotification;
   2.288    WdfDeviceInitSetPnpPowerEventCallbacks(child_init, &child_pnp_power_callbacks);
   2.289