win-pvdrivers

changeset 599:f118fcbe5ca8

Fixed up hot-add code (xm xxx-attach)
Removed legacy code
author James Harper <james.harper@bendigoit.com.au>
date Thu Jul 02 21:12:33 2009 +1000 (2009-07-02)
parents cf954aa0a8b1
children bfcba5547b8e
files xenpci/xenpci.c xenpci/xenpci_fdo.c
line diff
     1.1 --- a/xenpci/xenpci.c	Thu Jul 02 21:10:57 2009 +1000
     1.2 +++ b/xenpci/xenpci.c	Thu Jul 02 21:12:33 2009 +1000
     1.3 @@ -116,6 +116,7 @@ XenPci_EvtDeviceAdd_XenPci(WDFDRIVER dri
     1.4    }
     1.5  
     1.6    xpdd = GetXpdd(device);
     1.7 +  xpdd->child_list = WdfFdoGetDefaultChildList(device);
     1.8  
     1.9    WdfCollectionCreate(WDF_NO_OBJECT_ATTRIBUTES, &xpdd->veto_devices);
    1.10    status = WdfDriverOpenParametersRegistryKey(driver, KEY_QUERY_VALUE, WDF_NO_OBJECT_ATTRIBUTES, &param_key);
     2.1 --- a/xenpci/xenpci_fdo.c	Thu Jul 02 21:10:57 2009 +1000
     2.2 +++ b/xenpci/xenpci_fdo.c	Thu Jul 02 21:12:33 2009 +1000
     2.3 @@ -502,8 +502,8 @@ XenPci_DeviceWatchHandler(char *path, PV
     2.4      {
     2.5        XenPci_FreeMem(value);
     2.6        /* we probably have to be a bit smarter here and do nothing if xenpci isn't running yet */
     2.7 -      KdPrint((__DRIVER_NAME "     Invalidating Device Relations\n"));
     2.8 -      //IoInvalidateDeviceRelations(xpdd->common.pdo, BusRelations);
     2.9 +      KdPrint((__DRIVER_NAME "     Rescanning child list\n"));
    2.10 +      XenPci_EvtChildListScanForChildren(xpdd->child_list);
    2.11      }
    2.12    }
    2.13    FreeSplitString(bits, count);
    2.14 @@ -882,1418 +882,3 @@ XenPci_EvtChildListScanForChildren(WDFCH
    2.15    
    2.16    FUNCTION_EXIT();
    2.17  }
    2.18 -
    2.19 -#if 0
    2.20 -#if 0
    2.21 -static VOID
    2.22 -XenBus_BalloonHandler(char *Path, PVOID Data);
    2.23 -#endif
    2.24 -
    2.25 -#pragma warning(disable : 4200) // zero-sized array
    2.26 -
    2.27 -NTSTATUS
    2.28 -XenPci_Power_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
    2.29 -{
    2.30 -  NTSTATUS status;
    2.31 -  PIO_STACK_LOCATION stack;
    2.32 -  POWER_STATE_TYPE power_type;
    2.33 -  POWER_STATE power_state;
    2.34 -  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
    2.35 -
    2.36 -  UNREFERENCED_PARAMETER(device_object);
    2.37 -  
    2.38 -  FUNCTION_ENTER();
    2.39 -
    2.40 -  stack = IoGetCurrentIrpStackLocation(irp);
    2.41 -  power_type = stack->Parameters.Power.Type;
    2.42 -  power_state = stack->Parameters.Power.State;
    2.43 -
    2.44 -  switch (stack->MinorFunction)
    2.45 -  {
    2.46 -  case IRP_MN_POWER_SEQUENCE:
    2.47 -    //irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
    2.48 -    KdPrint((__DRIVER_NAME "     IRP_MN_POWER_SEQUENCE\n"));
    2.49 -    break;
    2.50 -  case IRP_MN_QUERY_POWER:
    2.51 -    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_POWER\n"));
    2.52 -    break;
    2.53 -  case IRP_MN_SET_POWER:
    2.54 -    KdPrint((__DRIVER_NAME "     IRP_MN_SET_POWER\n"));
    2.55 -    switch (power_type) {
    2.56 -    case DevicePowerState:
    2.57 -      KdPrint((__DRIVER_NAME "     DevicePowerState\n"));
    2.58 -      break;
    2.59 -    case SystemPowerState:
    2.60 -      KdPrint((__DRIVER_NAME "     SystemPowerState\n"));
    2.61 -      break;
    2.62 -    default:
    2.63 -      KdPrint((__DRIVER_NAME "     %d\n", power_type));
    2.64 -    }    
    2.65 -    break;
    2.66 -  case IRP_MN_WAIT_WAKE:
    2.67 -    KdPrint((__DRIVER_NAME "     IRP_MN_WAIT_WAKE\n"));
    2.68 -    break;
    2.69 -  default:
    2.70 -    KdPrint((__DRIVER_NAME "     IRP_MN_%d\n", stack->MinorFunction));
    2.71 -    break;  
    2.72 -  }
    2.73 -  PoStartNextPowerIrp(irp);
    2.74 -  IoSkipCurrentIrpStackLocation(irp);
    2.75 -  status = PoCallDriver(xpdd->common.lower_do, irp);
    2.76 -  
    2.77 -  FUNCTION_EXIT();
    2.78 -
    2.79 -  return status;
    2.80 -}
    2.81 -
    2.82 -NTSTATUS
    2.83 -XenPci_Dummy_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
    2.84 -{
    2.85 -  NTSTATUS status;
    2.86 -  PIO_STACK_LOCATION stack;
    2.87 -  PXENPCI_DEVICE_DATA xpdd;
    2.88 -
    2.89 -  FUNCTION_ENTER();
    2.90 -
    2.91 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
    2.92 -  stack = IoGetCurrentIrpStackLocation(irp);
    2.93 -  IoSkipCurrentIrpStackLocation(irp);
    2.94 -  status = IoCallDriver(xpdd->common.lower_do, irp);
    2.95 -
    2.96 -  FUNCTION_EXIT();
    2.97 -
    2.98 -  return status;
    2.99 -}
   2.100 -
   2.101 -static NTSTATUS
   2.102 -XenPci_Pnp_IoCompletion(PDEVICE_OBJECT device_object, PIRP irp, PVOID context)
   2.103 -{
   2.104 -  PKEVENT event = (PKEVENT)context;
   2.105 -
   2.106 -  UNREFERENCED_PARAMETER(device_object);
   2.107 -
   2.108 -  FUNCTION_ENTER();
   2.109 -
   2.110 -  if (irp->PendingReturned)
   2.111 -  {
   2.112 -    KeSetEvent(event, IO_NO_INCREMENT, FALSE);
   2.113 -  }
   2.114 -
   2.115 -  FUNCTION_EXIT();
   2.116 -
   2.117 -  return STATUS_MORE_PROCESSING_REQUIRED;
   2.118 -}
   2.119 -
   2.120 -static NTSTATUS
   2.121 -XenPci_QueueWorkItem(PDEVICE_OBJECT device_object, PIO_WORKITEM_ROUTINE routine, PVOID context)
   2.122 -{
   2.123 -  PIO_WORKITEM work_item;
   2.124 -  NTSTATUS status = STATUS_SUCCESS;
   2.125 -
   2.126 -	work_item = IoAllocateWorkItem(device_object);
   2.127 -	IoQueueWorkItem(work_item, routine, DelayedWorkQueue, context);
   2.128 -	
   2.129 -  return status;
   2.130 -}
   2.131 -
   2.132 -static NTSTATUS
   2.133 -XenPci_SendAndWaitForIrp(PDEVICE_OBJECT device_object, PIRP irp)
   2.134 -{
   2.135 -  NTSTATUS status;
   2.136 -  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.137 -  KEVENT event;
   2.138 -
   2.139 -  UNREFERENCED_PARAMETER(device_object);
   2.140 -
   2.141 -  FUNCTION_ENTER();
   2.142 -
   2.143 -  KeInitializeEvent(&event, NotificationEvent, FALSE);
   2.144 -
   2.145 -  IoCopyCurrentIrpStackLocationToNext(irp);
   2.146 -  IoSetCompletionRoutine(irp, XenPci_Pnp_IoCompletion, &event, TRUE, TRUE, TRUE);
   2.147 -
   2.148 -  status = IoCallDriver(xpdd->common.lower_do, irp);
   2.149 -
   2.150 -  if (status == STATUS_PENDING)
   2.151 -  {
   2.152 -    KdPrint((__DRIVER_NAME "     waiting ...\n"));
   2.153 -    KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
   2.154 -    KdPrint((__DRIVER_NAME "     ... done\n"));
   2.155 -    status = irp->IoStatus.Status;
   2.156 -  }
   2.157 -
   2.158 -  FUNCTION_EXIT();
   2.159 -
   2.160 -  return status;
   2.161 -}
   2.162 -
   2.163 -static NTSTATUS
   2.164 -XenPci_ProcessShutdownIrp(PXENPCI_DEVICE_DATA xpdd)
   2.165 -{
   2.166 -  PIO_STACK_LOCATION stack;
   2.167 -  NTSTATUS status;
   2.168 -  PIRP irp;
   2.169 -  KIRQL old_irql;
   2.170 -  ULONG length;
   2.171 -
   2.172 -  FUNCTION_ENTER();
   2.173 -
   2.174 -  KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
   2.175 -  if (xpdd->shutdown_irp)
   2.176 -  {
   2.177 -    irp = xpdd->shutdown_irp;
   2.178 -    stack = IoGetCurrentIrpStackLocation(irp);
   2.179 -    KdPrint((__DRIVER_NAME "     stack = %p\n", stack));
   2.180 -    KdPrint((__DRIVER_NAME "     length = %d, buffer = %p\n", stack->Parameters.Read.Length, irp->AssociatedIrp.SystemBuffer));
   2.181 -    length = min(xpdd->shutdown_prod - xpdd->shutdown_cons, stack->Parameters.Read.Length);
   2.182 -    KdPrint((__DRIVER_NAME "     length = %d\n", length));
   2.183 -    if (length > 0)
   2.184 -    {
   2.185 -      memcpy(irp->AssociatedIrp.SystemBuffer, &xpdd->shutdown_ring[xpdd->shutdown_cons & (SHUTDOWN_RING_SIZE - 1)], length);
   2.186 -      xpdd->shutdown_cons += length;
   2.187 -      if (xpdd->shutdown_cons > SHUTDOWN_RING_SIZE)
   2.188 -      {
   2.189 -        xpdd->shutdown_cons -= SHUTDOWN_RING_SIZE;
   2.190 -        xpdd->shutdown_prod -= SHUTDOWN_RING_SIZE;
   2.191 -        xpdd->shutdown_start -= SHUTDOWN_RING_SIZE;
   2.192 -      }
   2.193 -      xpdd->shutdown_irp = NULL;
   2.194 -      KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
   2.195 -      status = STATUS_SUCCESS;    
   2.196 -      irp->IoStatus.Status = status;
   2.197 -      irp->IoStatus.Information = length;
   2.198 -      IoSetCancelRoutine(irp, NULL);
   2.199 -      IoCompleteRequest(irp, IO_NO_INCREMENT);
   2.200 -    }
   2.201 -    else
   2.202 -    {
   2.203 -      KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
   2.204 -      KdPrint((__DRIVER_NAME "     nothing to read... pending\n"));
   2.205 -      IoMarkIrpPending(irp);
   2.206 -      status = STATUS_PENDING;
   2.207 -    }
   2.208 -  }
   2.209 -  else
   2.210 -  {
   2.211 -    KdPrint((__DRIVER_NAME "     no pending irp\n"));
   2.212 -    KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
   2.213 -    status = STATUS_SUCCESS;
   2.214 -  }  
   2.215 -
   2.216 -  FUNCTION_EXIT();
   2.217 -
   2.218 -  return status;
   2.219 -}
   2.220 -
   2.221 -static VOID
   2.222 -XenBus_ShutdownIoCancel(PDEVICE_OBJECT device_object, PIRP irp)
   2.223 -{
   2.224 -  PXENPCI_DEVICE_DATA xpdd;
   2.225 -  KIRQL old_irql;
   2.226 -
   2.227 -  FUNCTION_ENTER();
   2.228 -
   2.229 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.230 -  IoReleaseCancelSpinLock(irp->CancelIrql);
   2.231 -  KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
   2.232 -  if (irp == xpdd->shutdown_irp)
   2.233 -  {
   2.234 -    KdPrint((__DRIVER_NAME "     Not the current irp???\n"));
   2.235 -    xpdd->shutdown_irp = NULL;
   2.236 -  }
   2.237 -  irp->IoStatus.Status = STATUS_CANCELLED;
   2.238 -  irp->IoStatus.Information = 0;
   2.239 -  KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
   2.240 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
   2.241 -
   2.242 -  FUNCTION_EXIT();
   2.243 -}
   2.244 -
   2.245 -struct {
   2.246 -  volatile ULONG do_spin;
   2.247 -  volatile ULONG abort_spin;
   2.248 -  volatile LONG nr_spinning;
   2.249 -  KDPC dpcs[MAX_VIRT_CPUS];
   2.250 -  KEVENT spin_event;
   2.251 -  KEVENT resume_event;
   2.252 -} typedef SUSPEND_INFO, *PSUSPEND_INFO;
   2.253 -
   2.254 -/* runs at PASSIVE_LEVEL */
   2.255 -static DDKAPI VOID
   2.256 -XenPci_CompleteResume(PDEVICE_OBJECT device_object, PVOID context)
   2.257 -{
   2.258 -  PSUSPEND_INFO suspend_info = context;
   2.259 -  PXENPCI_DEVICE_DATA xpdd;
   2.260 -  PXEN_CHILD child;
   2.261 -
   2.262 -  UNREFERENCED_PARAMETER(context);
   2.263 -  FUNCTION_ENTER();
   2.264 -
   2.265 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.266 -
   2.267 -  while (suspend_info->nr_spinning)
   2.268 -  {
   2.269 -    KdPrint((__DRIVER_NAME "     %d processors are still spinning\n", suspend_info->nr_spinning));
   2.270 -    KeWaitForSingleObject(&suspend_info->spin_event, Executive, KernelMode, FALSE, NULL);
   2.271 -  }
   2.272 -  KdPrint((__DRIVER_NAME "     all other processors have stopped spinning\n"));
   2.273 -
   2.274 -  XenBus_Resume(xpdd);
   2.275 -
   2.276 -  for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
   2.277 -  {
   2.278 -    XenPci_Pdo_Resume(child->context->common.pdo);
   2.279 -  }
   2.280 -
   2.281 -  xpdd->suspend_state = SUSPEND_STATE_NONE;
   2.282 -
   2.283 -  FUNCTION_EXIT();
   2.284 -}
   2.285 -
   2.286 -/* Called at DISPATCH_LEVEL */
   2.287 -static DDKAPI VOID
   2.288 -XenPci_Suspend(
   2.289 -  PRKDPC Dpc,
   2.290 -  PVOID Context,
   2.291 -  PVOID SystemArgument1,
   2.292 -  PVOID SystemArgument2)
   2.293 -{
   2.294 -  PXENPCI_DEVICE_DATA xpdd = Context;
   2.295 -  PSUSPEND_INFO suspend_info = SystemArgument1;
   2.296 -  ULONG ActiveProcessorCount;
   2.297 -  KIRQL old_irql;
   2.298 -  int cancelled = 0;
   2.299 -  PXEN_CHILD child;
   2.300 -  
   2.301 -  //PUCHAR gnttbl_backup[PAGE_SIZE * NR_GRANT_FRAMES];
   2.302 -
   2.303 -  UNREFERENCED_PARAMETER(Dpc);
   2.304 -  UNREFERENCED_PARAMETER(SystemArgument2);
   2.305 -
   2.306 -  FUNCTION_ENTER();
   2.307 -  FUNCTION_MSG("(CPU = %d)\n", KeGetCurrentProcessorNumber());
   2.308 -
   2.309 -  if (KeGetCurrentProcessorNumber() != 0)
   2.310 -  {
   2.311 -    KdPrint((__DRIVER_NAME "     CPU %d spinning...\n", KeGetCurrentProcessorNumber()));
   2.312 -    KeRaiseIrql(HIGH_LEVEL, &old_irql);
   2.313 -    InterlockedIncrement(&suspend_info->nr_spinning);
   2.314 -    while(suspend_info->do_spin && !suspend_info->abort_spin)
   2.315 -    {
   2.316 -      KeStallExecutionProcessor(1);
   2.317 -      KeMemoryBarrier();
   2.318 -    }
   2.319 -    if (suspend_info->abort_spin)
   2.320 -    {
   2.321 -      KdPrint((__DRIVER_NAME "     CPU %d spin aborted\n", KeGetCurrentProcessorNumber()));
   2.322 -KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000003, 0x00000001, 0x00000000, 0x00000000);
   2.323 -      return;
   2.324 -    }
   2.325 -    KeLowerIrql(old_irql);
   2.326 -    InterlockedDecrement(&suspend_info->nr_spinning);
   2.327 -    KeSetEvent(&suspend_info->spin_event, IO_NO_INCREMENT, FALSE);
   2.328 -    FUNCTION_EXIT();
   2.329 -    return;
   2.330 -  }
   2.331 -  ActiveProcessorCount = (ULONG)KeNumberProcessors;
   2.332 -
   2.333 -  KeRaiseIrql(HIGH_LEVEL, &old_irql);
   2.334 -  xpdd->suspend_state = SUSPEND_STATE_HIGH_IRQL;
   2.335 -  while (suspend_info->nr_spinning < (LONG)ActiveProcessorCount - 1 && !suspend_info->abort_spin)
   2.336 -  {
   2.337 -    KeStallExecutionProcessor(1);
   2.338 -    //HYPERVISOR_yield(xpdd);
   2.339 -    KeMemoryBarrier();
   2.340 -  }
   2.341 -  if (suspend_info->abort_spin)
   2.342 -  {
   2.343 -    KdPrint((__DRIVER_NAME "     CPU %d spin aborted\n", KeGetCurrentProcessorNumber()));
   2.344 -KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000003, 0x00000003, 0x00000000, 0x00000000);
   2.345 -    return;
   2.346 -  }
   2.347 -  cancelled = hvm_shutdown(Context, SHUTDOWN_suspend);
   2.348 -  KdPrint((__DRIVER_NAME "     back from suspend, cancelled = %d\n", cancelled));
   2.349 -  
   2.350 -  XenPci_Init(xpdd);
   2.351 -  
   2.352 -  GntTbl_InitMap(Context);
   2.353 -
   2.354 -  /* this enables interrupts again too */  
   2.355 -  EvtChn_Init(xpdd);
   2.356 -
   2.357 -  for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
   2.358 -  {
   2.359 -    child->context->device_state.resume_state = RESUME_STATE_BACKEND_RESUME;
   2.360 -  }
   2.361 -  KeLowerIrql(old_irql);
   2.362 -  xpdd->suspend_state = SUSPEND_STATE_RESUMING;
   2.363 -  suspend_info->do_spin = FALSE;
   2.364 -  KeMemoryBarrier();  
   2.365 -  KeSetEvent(&suspend_info->resume_event, IO_NO_INCREMENT, FALSE);
   2.366 -  FUNCTION_EXIT();
   2.367 -}
   2.368 -
   2.369 -/* Called at PASSIVE_LEVEL */
   2.370 -static VOID DDKAPI
   2.371 -XenPci_BeginSuspend(PDEVICE_OBJECT device_object, PVOID context)
   2.372 -{
   2.373 -  //KAFFINITY ActiveProcessorMask = 0; // this is for Vista+
   2.374 -  PXENPCI_DEVICE_DATA xpdd = device_object->DeviceExtension;
   2.375 -  ULONG ActiveProcessorCount;
   2.376 -  ULONG i;
   2.377 -  PSUSPEND_INFO suspend_info;
   2.378 -  //PKDPC Dpc;
   2.379 -  KIRQL OldIrql;
   2.380 -  PXEN_CHILD child;
   2.381 -
   2.382 -  UNREFERENCED_PARAMETER(context);
   2.383 -  FUNCTION_ENTER();
   2.384 -
   2.385 -  if (xpdd->suspend_state == SUSPEND_STATE_NONE)
   2.386 -  {
   2.387 -    xpdd->suspend_state = SUSPEND_STATE_SCHEDULED;
   2.388 -    KeMemoryBarrier();
   2.389 -
   2.390 -    suspend_info = ExAllocatePoolWithTag(NonPagedPool, sizeof(SUSPEND_INFO), XENPCI_POOL_TAG);
   2.391 -    RtlZeroMemory(suspend_info, sizeof(SUSPEND_INFO));
   2.392 -    KeInitializeEvent(&suspend_info->spin_event, SynchronizationEvent, FALSE);
   2.393 -    KeInitializeEvent(&suspend_info->resume_event, SynchronizationEvent, FALSE);
   2.394 -    
   2.395 -    for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
   2.396 -    {
   2.397 -      XenPci_Pdo_Suspend(child->context->common.pdo);
   2.398 -    }
   2.399 -
   2.400 -    XenBus_Suspend(xpdd);
   2.401 -
   2.402 -    EvtChn_Shutdown(xpdd);
   2.403 -
   2.404 -    //ActiveProcessorCount = KeQueryActiveProcessorCount(&ActiveProcessorMask); // this is for Vista+
   2.405 -    ActiveProcessorCount = (ULONG)KeNumberProcessors;
   2.406 -    /* Go to HIGH_LEVEL to prevent any races with Dpc's on the current processor */
   2.407 -    KeRaiseIrql(HIGH_LEVEL, &OldIrql);
   2.408 -    suspend_info->do_spin = TRUE;
   2.409 -    for (i = 0; i < ActiveProcessorCount; i++)
   2.410 -    {
   2.411 -      //Dpc = ExAllocatePoolWithTag(NonPagedPool, sizeof(KDPC), XENPCI_POOL_TAG);
   2.412 -      KeInitializeDpc(&suspend_info->dpcs[i], XenPci_Suspend, xpdd);
   2.413 -      KeSetTargetProcessorDpc(&suspend_info->dpcs[i], (CCHAR)i);
   2.414 -      KeSetImportanceDpc(&suspend_info->dpcs[i], HighImportance);
   2.415 -      KdPrint((__DRIVER_NAME "     queuing Dpc for CPU %d\n", i));
   2.416 -      KeInsertQueueDpc(&suspend_info->dpcs[i], suspend_info, NULL);
   2.417 -    }
   2.418 -    KdPrint((__DRIVER_NAME "     All Dpc's queued\n"));
   2.419 -    KeMemoryBarrier();
   2.420 -    KeLowerIrql(OldIrql);
   2.421 -    KdPrint((__DRIVER_NAME "     Waiting for resume_event\n"));
   2.422 -    KeWaitForSingleObject(&suspend_info->resume_event, Executive, KernelMode, FALSE, NULL);
   2.423 -    KdPrint((__DRIVER_NAME "     Got resume_event\n"));
   2.424 -    //xpdd->log_interrupts = TRUE;
   2.425 -    XenPci_CompleteResume(device_object, suspend_info);
   2.426 -  }
   2.427 -  FUNCTION_EXIT();
   2.428 -}
   2.429 -
   2.430 -static void
   2.431 -XenPci_ShutdownHandler(char *path, PVOID context)
   2.432 -{
   2.433 -  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)context;
   2.434 -  char *res;
   2.435 -  char *value;
   2.436 -  KIRQL old_irql;
   2.437 -  PIO_WORKITEM work_item;
   2.438 -
   2.439 -  UNREFERENCED_PARAMETER(path);
   2.440 -
   2.441 -  FUNCTION_ENTER();
   2.442 -
   2.443 -  res = XenBus_Read(xpdd, XBT_NIL, SHUTDOWN_PATH, &value);
   2.444 -  if (res)
   2.445 -  {
   2.446 -    KdPrint(("Error reading shutdown path - %s\n", res));
   2.447 -    XenPci_FreeMem(res);
   2.448 -    return;
   2.449 -  }
   2.450 -
   2.451 -  KdPrint((__DRIVER_NAME "     Shutdown value = %s\n", value));
   2.452 -
   2.453 -  if (strlen(value) != 0)
   2.454 -  {
   2.455 -    if (strcmp(value, "suspend") == 0)
   2.456 -    {
   2.457 -      KdPrint((__DRIVER_NAME "     Suspend detected\n"));
   2.458 -      /* we have to queue this as a work item as we stop the xenbus thread, which we are currently running in! */
   2.459 -    	work_item = IoAllocateWorkItem(xpdd->common.fdo);
   2.460 -      IoQueueWorkItem(work_item, XenPci_BeginSuspend, DelayedWorkQueue, NULL);
   2.461 -      //XenPci_BeginSuspend(xpdd);
   2.462 -    }
   2.463 -    else
   2.464 -    {
   2.465 -      KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
   2.466 -      if (xpdd->shutdown_start >= xpdd->shutdown_cons)
   2.467 -        xpdd->shutdown_prod = xpdd->shutdown_start;
   2.468 -      else
   2.469 -        xpdd->shutdown_start = xpdd->shutdown_prod;
   2.470 -      memcpy(&xpdd->shutdown_ring[xpdd->shutdown_prod], value, strlen(value));
   2.471 -      xpdd->shutdown_prod += (ULONG)strlen(value);
   2.472 -      xpdd->shutdown_ring[xpdd->shutdown_prod++] = '\r';
   2.473 -      xpdd->shutdown_ring[xpdd->shutdown_prod++] = '\n';
   2.474 -      KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
   2.475 -      XenPci_ProcessShutdownIrp(xpdd);
   2.476 -    }
   2.477 -  }
   2.478 -
   2.479 -  //XenPci_FreeMem(value);
   2.480 -
   2.481 -  FUNCTION_EXIT();
   2.482 -}
   2.483 -
   2.484 -static VOID 
   2.485 -XenPci_DumpPdoConfigs(PXENPCI_DEVICE_DATA xpdd)
   2.486 -{
   2.487 -  PXEN_CHILD child;
   2.488 -
   2.489 -  for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
   2.490 -  {
   2.491 -    XenPci_DumpPdoConfig(child->context->common.pdo);
   2.492 -  }  
   2.493 -}
   2.494 -
   2.495 -static VOID
   2.496 -XenPci_SysrqHandler(char *path, PVOID context)
   2.497 -{
   2.498 -  PXENPCI_DEVICE_DATA xpdd = context;
   2.499 -  char *value;
   2.500 -  char letter;
   2.501 -  char *res;
   2.502 -
   2.503 -  UNREFERENCED_PARAMETER(path);
   2.504 -
   2.505 -  FUNCTION_ENTER();
   2.506 -
   2.507 -  XenBus_Read(xpdd, XBT_NIL, SYSRQ_PATH, &value);
   2.508 -
   2.509 -  KdPrint((__DRIVER_NAME "     SysRq Value = %s\n", value));
   2.510 -
   2.511 -  if (value != NULL && strlen(value) != 0)
   2.512 -  {
   2.513 -    letter = *value;
   2.514 -    res = XenBus_Write(xpdd, XBT_NIL, SYSRQ_PATH, "");
   2.515 -    if (res)
   2.516 -    {
   2.517 -      KdPrint(("Error writing sysrq path\n"));
   2.518 -      XenPci_FreeMem(res);
   2.519 -      return;
   2.520 -    }
   2.521 -  }
   2.522 -  else
   2.523 -  {
   2.524 -    letter = 0;
   2.525 -  }
   2.526 -
   2.527 -  if (value != NULL)
   2.528 -  {
   2.529 -    XenPci_FreeMem(value);
   2.530 -  }
   2.531 -
   2.532 -  switch (letter)
   2.533 -  {
   2.534 -  case 0:
   2.535 -    break;
   2.536 -  case 'B': /* cause a bug check */
   2.537 -    KeBugCheckEx(('X' << 16)|('E' << 8)|('N'), 0x00000001, 0x00000000, 0x00000000, 0x00000000);
   2.538 -    break;
   2.539 -  case 'X': /* stop delivering events */
   2.540 -  	xpdd->interrupts_masked = TRUE;
   2.541 -    break;    
   2.542 -  case 'C':
   2.543 -    /* show some debugging info */
   2.544 -  	XenPci_DumpPdoConfigs(xpdd);
   2.545 -    break;
   2.546 -  default:
   2.547 -    KdPrint(("     Unhandled sysrq letter %c\n", letter));
   2.548 -    break;
   2.549 -  }
   2.550 -
   2.551 -  FUNCTION_EXIT();
   2.552 -}
   2.553 -
   2.554 -static DDKAPI VOID
   2.555 -XenPci_Pnp_StartDeviceCallback(PDEVICE_OBJECT device_object, PVOID context)
   2.556 -{
   2.557 -  NTSTATUS status = STATUS_SUCCESS;
   2.558 -  PXENPCI_DEVICE_DATA xpdd = device_object->DeviceExtension;
   2.559 -  PIRP irp = context;
   2.560 -  char *response;
   2.561 -
   2.562 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
   2.563 -  
   2.564 -  XenPci_Init(xpdd);
   2.565 -
   2.566 -  GntTbl_Init(xpdd);
   2.567 -
   2.568 -  EvtChn_Init(xpdd);
   2.569 -  EvtChn_ConnectInterrupt(xpdd);
   2.570 -  XenBus_Init(xpdd);
   2.571 -
   2.572 -  response = XenBus_AddWatch(xpdd, XBT_NIL, SYSRQ_PATH, XenPci_SysrqHandler, xpdd);
   2.573 -  KdPrint((__DRIVER_NAME "     sysrqwatch response = '%s'\n", response));
   2.574 -  
   2.575 -#if 0
   2.576 -  response = XenBus_AddWatch(xpdd, XBT_NIL, SHUTDOWN_PATH, XenPci_ShutdownHandler, xpdd);
   2.577 -  KdPrint((__DRIVER_NAME "     shutdown watch response = '%s'\n", response));
   2.578 -#endif
   2.579 -
   2.580 -  response = XenBus_AddWatch(xpdd, XBT_NIL, "device", XenPci_DeviceWatchHandler, xpdd);
   2.581 -  KdPrint((__DRIVER_NAME "     device watch response = '%s'\n", response));
   2.582 -
   2.583 -#if 0
   2.584 -  response = XenBus_AddWatch(xpdd, XBT_NIL, BALLOON_PATH, XenPci_BalloonHandler, Device);
   2.585 -  KdPrint((__DRIVER_NAME "     balloon watch response = '%s'\n", response));
   2.586 -#endif
   2.587 -
   2.588 -  status = IoSetDeviceInterfaceState(&xpdd->legacy_interface_name, TRUE);
   2.589 -  if (!NT_SUCCESS(status))
   2.590 -  {
   2.591 -    KdPrint((__DRIVER_NAME "     IoSetDeviceInterfaceState (legacy) failed with status 0x%08x\n", status));
   2.592 -  }
   2.593 -
   2.594 -  status = IoSetDeviceInterfaceState(&xpdd->interface_name, TRUE);
   2.595 -  if (!NT_SUCCESS(status))
   2.596 -  {
   2.597 -    KdPrint((__DRIVER_NAME "     IoSetDeviceInterfaceState failed with status 0x%08x\n", status));
   2.598 -  }
   2.599 -
   2.600 -  irp->IoStatus.Status = status;
   2.601 -  
   2.602 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
   2.603 -
   2.604 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__ "\n"));
   2.605 -}
   2.606 -
   2.607 -static NTSTATUS
   2.608 -XenPci_Pnp_StartDevice(PDEVICE_OBJECT device_object, PIRP irp)
   2.609 -{
   2.610 -  NTSTATUS status;
   2.611 -  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.612 -  PIO_STACK_LOCATION stack;
   2.613 -  PCM_PARTIAL_RESOURCE_LIST res_list;
   2.614 -  PCM_PARTIAL_RESOURCE_DESCRIPTOR res_descriptor;
   2.615 -  ULONG i;
   2.616 -
   2.617 -  UNREFERENCED_PARAMETER(device_object);
   2.618 -
   2.619 -  FUNCTION_ENTER();
   2.620 -
   2.621 -  stack = IoGetCurrentIrpStackLocation(irp);
   2.622 -
   2.623 -  IoMarkIrpPending(irp);
   2.624 -
   2.625 -  status = XenPci_SendAndWaitForIrp(device_object, irp);
   2.626 -
   2.627 -  res_list = &stack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList;
   2.628 -  
   2.629 -  for (i = 0; i < res_list->Count; i++)
   2.630 -  {
   2.631 -    res_descriptor = &res_list->PartialDescriptors[i];
   2.632 -    switch (res_descriptor->Type)
   2.633 -    {
   2.634 -    case CmResourceTypeInterrupt:
   2.635 -      KdPrint((__DRIVER_NAME "     irq_number = %03x\n", res_descriptor->u.Interrupt.Vector));
   2.636 -      xpdd->irq_number = res_descriptor->u.Interrupt.Vector;
   2.637 -      //memcpy(&InterruptRaw, res_descriptor, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
   2.638 -      break;
   2.639 -    }
   2.640 -  }
   2.641 -
   2.642 -  res_list = &stack->Parameters.StartDevice.AllocatedResourcesTranslated->List[0].PartialResourceList;
   2.643 -  
   2.644 -  for (i = 0; i < res_list->Count; i++)
   2.645 -  {
   2.646 -    res_descriptor = &res_list->PartialDescriptors[i];
   2.647 -    switch (res_descriptor->Type) {
   2.648 -    case CmResourceTypePort:
   2.649 -      KdPrint((__DRIVER_NAME "     IoPort Address(%x) Length: %d\n", res_descriptor->u.Port.Start.LowPart, res_descriptor->u.Port.Length));
   2.650 -      xpdd->platform_ioport_addr = res_descriptor->u.Port.Start.LowPart;
   2.651 -      xpdd->platform_ioport_len = res_descriptor->u.Port.Length;
   2.652 -      break;
   2.653 -    case CmResourceTypeMemory:
   2.654 -      KdPrint((__DRIVER_NAME "     Memory mapped CSR:(%x:%x) Length:(%d)\n", res_descriptor->u.Memory.Start.LowPart, res_descriptor->u.Memory.Start.HighPart, res_descriptor->u.Memory.Length));
   2.655 -      KdPrint((__DRIVER_NAME "     Memory flags = %04X\n", res_descriptor->Flags));
   2.656 -      xpdd->platform_mmio_addr = res_descriptor->u.Memory.Start;
   2.657 -      xpdd->platform_mmio_len = res_descriptor->u.Memory.Length;
   2.658 -      xpdd->platform_mmio_alloc = 0;
   2.659 -      xpdd->platform_mmio_flags = res_descriptor->Flags;
   2.660 -      break;
   2.661 -    case CmResourceTypeInterrupt:
   2.662 -      KdPrint((__DRIVER_NAME "     irq_vector = %03x\n", res_descriptor->u.Interrupt.Vector));
   2.663 -      KdPrint((__DRIVER_NAME "     irq_level = %03x\n", res_descriptor->u.Interrupt.Level));
   2.664 -	    xpdd->irq_level = (KIRQL)res_descriptor->u.Interrupt.Level;
   2.665 -  	  xpdd->irq_vector = res_descriptor->u.Interrupt.Vector;
   2.666 -	    xpdd->irq_affinity = res_descriptor->u.Interrupt.Affinity;
   2.667 -      
   2.668 -      xpdd->irq_mode = (res_descriptor->Flags & CM_RESOURCE_INTERRUPT_LATCHED)?Latched:LevelSensitive;
   2.669 -      KdPrint((__DRIVER_NAME "     irq_mode = %s\n", (xpdd->irq_mode == Latched)?"Latched":"LevelSensitive"));
   2.670 -      switch(res_descriptor->ShareDisposition)
   2.671 -      {
   2.672 -      case CmResourceShareDeviceExclusive:
   2.673 -        KdPrint((__DRIVER_NAME "     ShareDisposition = CmResourceShareDeviceExclusive\n"));
   2.674 -        break;
   2.675 -      case CmResourceShareDriverExclusive:
   2.676 -        KdPrint((__DRIVER_NAME "     ShareDisposition = CmResourceShareDriverExclusive\n"));
   2.677 -        break;
   2.678 -      case CmResourceShareShared:
   2.679 -        KdPrint((__DRIVER_NAME "     ShareDisposition = CmResourceShareShared\n"));
   2.680 -        break;
   2.681 -      default:
   2.682 -        KdPrint((__DRIVER_NAME "     ShareDisposition = %d\n", res_descriptor->ShareDisposition));
   2.683 -        break;
   2.684 -      }
   2.685 -      break;
   2.686 -    case CmResourceTypeDevicePrivate:
   2.687 -      KdPrint((__DRIVER_NAME "     Private Data: 0x%02x 0x%02x 0x%02x\n", res_descriptor->u.DevicePrivate.Data[0], res_descriptor->u.DevicePrivate.Data[1], res_descriptor->u.DevicePrivate.Data[2]));
   2.688 -      break;
   2.689 -    default:
   2.690 -      KdPrint((__DRIVER_NAME "     Unhandled resource type (0x%x)\n", res_descriptor->Type));
   2.691 -      break;
   2.692 -    }
   2.693 -  }
   2.694 -
   2.695 -  XenPci_QueueWorkItem(device_object, XenPci_Pnp_StartDeviceCallback, irp);
   2.696 -
   2.697 -  FUNCTION_EXIT();
   2.698 -  
   2.699 -  return STATUS_PENDING;
   2.700 -}
   2.701 -
   2.702 -static NTSTATUS
   2.703 -XenPci_Pnp_StopDevice(PDEVICE_OBJECT device_object, PIRP irp, PVOID context)
   2.704 -{
   2.705 -  NTSTATUS status = STATUS_SUCCESS;
   2.706 -
   2.707 -  UNREFERENCED_PARAMETER(device_object);
   2.708 -  UNREFERENCED_PARAMETER(context);
   2.709 -
   2.710 -  FUNCTION_ENTER();
   2.711 -
   2.712 -  irp->IoStatus.Status = status;
   2.713 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
   2.714 -
   2.715 -  FUNCTION_EXIT();
   2.716 -
   2.717 -  return irp->IoStatus.Status;
   2.718 -}
   2.719 -
   2.720 -static NTSTATUS
   2.721 -XenPci_Pnp_QueryStopRemoveDevice(PDEVICE_OBJECT device_object, PIRP irp)
   2.722 -{
   2.723 -  NTSTATUS status;
   2.724 -  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.725 -
   2.726 -  UNREFERENCED_PARAMETER(device_object);
   2.727 -
   2.728 -  FUNCTION_ENTER();
   2.729 -
   2.730 -  if (xpdd->common.device_usage_paging
   2.731 -    || xpdd->common.device_usage_dump
   2.732 -    || xpdd->common.device_usage_hibernation)
   2.733 -  {
   2.734 -    /* We are in the paging or hibernation path - can't remove */
   2.735 -    status = irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
   2.736 -    IoCompleteRequest(irp, IO_NO_INCREMENT);
   2.737 -  }
   2.738 -  else
   2.739 -  {
   2.740 -    IoSkipCurrentIrpStackLocation(irp);
   2.741 -    status = IoCallDriver(xpdd->common.lower_do, irp);
   2.742 -  }
   2.743 -  
   2.744 -  FUNCTION_EXIT();
   2.745 -
   2.746 -  return status;
   2.747 -}
   2.748 -
   2.749 -static NTSTATUS
   2.750 -XenPci_Pnp_RemoveDevice(PDEVICE_OBJECT device_object, PIRP irp)
   2.751 -{
   2.752 -  NTSTATUS status;
   2.753 -  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.754 -
   2.755 -  UNREFERENCED_PARAMETER(device_object);
   2.756 -
   2.757 -  FUNCTION_ENTER();
   2.758 -
   2.759 -  irp->IoStatus.Status = STATUS_SUCCESS;
   2.760 -  IoSkipCurrentIrpStackLocation(irp);
   2.761 -  status = IoCallDriver(xpdd->common.lower_do, irp);
   2.762 -  IoDetachDevice(xpdd->common.lower_do);
   2.763 -
   2.764 -  FUNCTION_EXIT();
   2.765 -
   2.766 -  return status;
   2.767 -}
   2.768 -
   2.769 -static DDKAPI VOID
   2.770 -XenPci_Pnp_QueryBusRelationsCallback(PDEVICE_OBJECT device_object, PVOID context)
   2.771 -{
   2.772 -  NTSTATUS status = STATUS_SUCCESS;
   2.773 -  PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.774 -  PXENPCI_PDO_DEVICE_DATA xppdd;
   2.775 -  PIRP irp = context;
   2.776 -  int device_count = 0;
   2.777 -  PDEVICE_RELATIONS dev_relations;
   2.778 -  PXEN_CHILD child, old_child;
   2.779 -  //char *response;
   2.780 -  char *msg;
   2.781 -  char **devices;
   2.782 -  char **instances;
   2.783 -  int i, j;
   2.784 -  CHAR path[128];
   2.785 -  PDEVICE_OBJECT pdo;
   2.786 -  PDEVICE_RELATIONS oldRelations;
   2.787 -  int prevcount, length;
   2.788 -
   2.789 -  FUNCTION_ENTER();
   2.790 -
   2.791 -  msg = XenBus_List(xpdd, XBT_NIL, "device", &devices);
   2.792 -  if (!msg)
   2.793 -  {
   2.794 -    for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
   2.795 -    {
   2.796 -      if (child->state == CHILD_STATE_DELETED)
   2.797 -      {
   2.798 -        KdPrint((__DRIVER_NAME "     Found deleted child - this shouldn't happen\n" ));
   2.799 -      }
   2.800 -      child->state = CHILD_STATE_DELETED;
   2.801 -    }
   2.802 -
   2.803 -    for (i = 0; devices[i]; i++)
   2.804 -    {
   2.805 -      RtlStringCbPrintfA(path, ARRAY_SIZE(path), "device/%s", devices[i]);
   2.806 -      msg = XenBus_List(xpdd, XBT_NIL, path, &instances);
   2.807 -      if (!msg)
   2.808 -      {
   2.809 -        for (j = 0; instances[j]; j++)
   2.810 -        {
   2.811 -          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "device/%s/%s", devices[i], instances[j]);
   2.812 -
   2.813 -          for (child = (PXEN_CHILD)xpdd->child_list.Flink; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
   2.814 -          {
   2.815 -            if (strcmp(child->context->path, path) == 0)
   2.816 -            {
   2.817 -              KdPrint((__DRIVER_NAME "     Existing device %s\n", path));
   2.818 -              ASSERT(child->state == CHILD_STATE_DELETED);
   2.819 -              child->state = CHILD_STATE_ADDED;
   2.820 -              device_count++;
   2.821 -              break;
   2.822 -            }
   2.823 -          }
   2.824 -        
   2.825 -          if (child == (PXEN_CHILD)&xpdd->child_list)
   2.826 -          {
   2.827 -            KdPrint((__DRIVER_NAME "     New device %s\n", path));
   2.828 -            child = ExAllocatePoolWithTag(NonPagedPool, sizeof(XEN_CHILD), XENPCI_POOL_TAG);
   2.829 -            child->state = CHILD_STATE_ADDED;
   2.830 -            status = IoCreateDevice(
   2.831 -              xpdd->common.fdo->DriverObject,
   2.832 -              sizeof(XENPCI_PDO_DEVICE_DATA),
   2.833 -              NULL,
   2.834 -              FILE_DEVICE_UNKNOWN,
   2.835 -              FILE_AUTOGENERATED_DEVICE_NAME | FILE_DEVICE_SECURE_OPEN,
   2.836 -              FALSE,
   2.837 -              &pdo);
   2.838 -            if (!NT_SUCCESS(status))
   2.839 -            {
   2.840 -              KdPrint((__DRIVER_NAME "     IoCreateDevice status = %08X\n", status));
   2.841 -            }
   2.842 -            RtlZeroMemory(pdo->DeviceExtension, sizeof(XENPCI_PDO_DEVICE_DATA));
   2.843 -            child->context = xppdd = pdo->DeviceExtension;
   2.844 -            xppdd->common.fdo = NULL;
   2.845 -            xppdd->common.pdo = pdo;
   2.846 -            ObReferenceObject(pdo);
   2.847 -            xppdd->common.lower_do = NULL;
   2.848 -            INIT_PNP_STATE(&xppdd->common);
   2.849 -            xppdd->common.device_usage_paging = 0;
   2.850 -            xppdd->common.device_usage_dump = 0;
   2.851 -            xppdd->common.device_usage_hibernation = 0;
   2.852 -            xppdd->bus_fdo = xpdd->common.fdo;
   2.853 -            xppdd->bus_pdo = xpdd->common.pdo;
   2.854 -            RtlStringCbCopyA(xppdd->path, ARRAY_SIZE(xppdd->path), path);
   2.855 -            RtlStringCbCopyA(xppdd->device, ARRAY_SIZE(xppdd->device), devices[i]);
   2.856 -            xppdd->index = atoi(instances[j]);
   2.857 -            KeInitializeEvent(&xppdd->backend_state_event, SynchronizationEvent, FALSE);
   2.858 -            xppdd->backend_state = XenbusStateUnknown;
   2.859 -            xppdd->backend_path[0] = '\0';
   2.860 -            InsertTailList(&xpdd->child_list, (PLIST_ENTRY)child);
   2.861 -            device_count++;
   2.862 -          }
   2.863 -          XenPci_FreeMem(instances[j]);
   2.864 -        }
   2.865 -        XenPci_FreeMem(instances);
   2.866 -      }
   2.867 -      XenPci_FreeMem(devices[i]);
   2.868 -    }
   2.869 -    XenPci_FreeMem(devices);
   2.870 -
   2.871 -    //
   2.872 -    // Keep track of old relations structure
   2.873 -    //
   2.874 -    oldRelations = (PDEVICE_RELATIONS) irp->IoStatus.Information;
   2.875 -    if (oldRelations)
   2.876 -    {
   2.877 -      prevcount = oldRelations->Count;
   2.878 -    }
   2.879 -    else
   2.880 -    {
   2.881 -      prevcount = 0;
   2.882 -    }
   2.883 -
   2.884 -    //
   2.885 -    // Need to allocate a new relations structure and add our
   2.886 -    // PDOs to it.
   2.887 -    //
   2.888 -
   2.889 -    length = sizeof(DEVICE_RELATIONS) + ((device_count + prevcount) * sizeof (PDEVICE_OBJECT)) -1;
   2.890 -
   2.891 -    dev_relations = (PDEVICE_RELATIONS) ExAllocatePoolWithTag (PagedPool, length, XENPCI_POOL_TAG);
   2.892 -    if (!dev_relations)
   2.893 -    {
   2.894 -      KdPrint((__DRIVER_NAME "**** Failed to allocate a new buffer for query device relations\n"));
   2.895 -      //
   2.896 -      // Fail the IRP
   2.897 -      //
   2.898 -      irp->IoStatus.Status = status = STATUS_INSUFFICIENT_RESOURCES;
   2.899 -      IoCompleteRequest (irp, IO_NO_INCREMENT);
   2.900 -      return;
   2.901 -    }
   2.902 -
   2.903 -    //
   2.904 -    // Copy in the device objects so far
   2.905 -    //
   2.906 -    if (prevcount)
   2.907 -    {
   2.908 -      RtlCopyMemory (dev_relations->Objects, oldRelations->Objects, prevcount * sizeof (PDEVICE_OBJECT));
   2.909 -    }
   2.910 -
   2.911 -    for (child = (PXEN_CHILD)xpdd->child_list.Flink, device_count = 0; child != (PXEN_CHILD)&xpdd->child_list; child = (PXEN_CHILD)child->entry.Flink)
   2.912 -    {
   2.913 -      if (child->state == CHILD_STATE_ADDED)
   2.914 -      {
   2.915 -        ObReferenceObject(child->context->common.pdo);
   2.916 -        dev_relations->Objects[prevcount++] = child->context->common.pdo;
   2.917 -      }
   2.918 -    }
   2.919 -
   2.920 -    dev_relations->Count = prevcount + device_count;
   2.921 -
   2.922 -    child = (PXEN_CHILD)xpdd->child_list.Flink;
   2.923 -    while (child != (PXEN_CHILD)&xpdd->child_list)
   2.924 -    {
   2.925 -      if (child->state == CHILD_STATE_DELETED)
   2.926 -      {
   2.927 -        KdPrint((__DRIVER_NAME "     Removing deleted child from device list\n"));
   2.928 -        old_child = child;
   2.929 -        child = (PXEN_CHILD)child->entry.Flink;
   2.930 -        RemoveEntryList((PLIST_ENTRY)old_child);
   2.931 -        xppdd = old_child->context;
   2.932 -        xppdd->reported_missing = TRUE;
   2.933 -        ObDereferenceObject(xppdd->common.pdo);
   2.934 -        ExFreePoolWithTag(old_child, XENPCI_POOL_TAG);
   2.935 -      }
   2.936 -      else
   2.937 -      {
   2.938 -        child = (PXEN_CHILD)child->entry.Flink;
   2.939 -      }
   2.940 -    }
   2.941 -    
   2.942 -    status = STATUS_SUCCESS;
   2.943 -  }
   2.944 -  else
   2.945 -  {
   2.946 -    //
   2.947 -    // Fail the IRP
   2.948 -    //
   2.949 -    irp->IoStatus.Status = status = STATUS_INSUFFICIENT_RESOURCES;
   2.950 -    IoCompleteRequest (irp, IO_NO_INCREMENT);
   2.951 -    return;
   2.952 -  }
   2.953 -
   2.954 -  irp->IoStatus.Status = status;
   2.955 -  //
   2.956 -  // Replace the relations structure in the IRP with the new
   2.957 -  // one.
   2.958 -  //
   2.959 -  if (oldRelations)
   2.960 -  {
   2.961 -      ExFreePool (oldRelations);
   2.962 -  }
   2.963 -  irp->IoStatus.Information = (ULONG_PTR)dev_relations;
   2.964 -
   2.965 -  IoCompleteRequest (irp, IO_NO_INCREMENT);
   2.966 -
   2.967 -  FUNCTION_EXIT();
   2.968 -}
   2.969 -
   2.970 -static NTSTATUS
   2.971 -XenPci_Pnp_QueryBusRelations(PDEVICE_OBJECT device_object, PIRP irp)
   2.972 -{
   2.973 -  NTSTATUS status;
   2.974 -
   2.975 -  UNREFERENCED_PARAMETER(device_object);
   2.976 -
   2.977 -  FUNCTION_ENTER();
   2.978 -
   2.979 -  IoMarkIrpPending(irp);
   2.980 -
   2.981 -  status = XenPci_SendAndWaitForIrp(device_object, irp);
   2.982 -
   2.983 -  XenPci_QueueWorkItem(device_object, XenPci_Pnp_QueryBusRelationsCallback, irp);
   2.984 -
   2.985 -  FUNCTION_EXIT();
   2.986 -
   2.987 -  return STATUS_PENDING;
   2.988 -}
   2.989 -
   2.990 -static DDKAPI VOID
   2.991 -XenPci_Pnp_FilterResourceRequirementsCallback(PDEVICE_OBJECT device_object, PVOID context)
   2.992 -{
   2.993 -  NTSTATUS status = STATUS_SUCCESS;
   2.994 -  //PXENPCI_DEVICE_DATA xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
   2.995 -  PIRP irp = context;
   2.996 -
   2.997 -  UNREFERENCED_PARAMETER(device_object);
   2.998 -
   2.999 -  FUNCTION_ENTER();
  2.1000 -  irp->IoStatus.Status = status;
  2.1001 -  IoCompleteRequest (irp, IO_NO_INCREMENT);
  2.1002 -  
  2.1003 -  FUNCTION_EXIT();
  2.1004 -}
  2.1005 -
  2.1006 -static NTSTATUS
  2.1007 -XenPci_Pnp_FilterResourceRequirements(PDEVICE_OBJECT device_object, PIRP irp)
  2.1008 -{
  2.1009 -  NTSTATUS status;
  2.1010 -
  2.1011 -  UNREFERENCED_PARAMETER(device_object);
  2.1012 -
  2.1013 -  FUNCTION_ENTER();
  2.1014 -
  2.1015 -  IoMarkIrpPending(irp);
  2.1016 -
  2.1017 -  status = XenPci_SendAndWaitForIrp(device_object, irp);
  2.1018 -
  2.1019 -  XenPci_QueueWorkItem(device_object, XenPci_Pnp_FilterResourceRequirementsCallback, irp);
  2.1020 -
  2.1021 -  FUNCTION_EXIT();
  2.1022 -
  2.1023 -  return STATUS_PENDING;
  2.1024 -}
  2.1025 -
  2.1026 -static NTSTATUS
  2.1027 -XenPci_Pnp_DeviceUsageNotification(PDEVICE_OBJECT device_object, PIRP irp, PVOID context)
  2.1028 -{
  2.1029 -  NTSTATUS status;
  2.1030 -  PXENPCI_DEVICE_DATA xpdd;
  2.1031 -  PIO_STACK_LOCATION stack;
  2.1032 -  
  2.1033 -  UNREFERENCED_PARAMETER(context);
  2.1034 -
  2.1035 -  FUNCTION_ENTER();
  2.1036 -
  2.1037 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  2.1038 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1039 -  status = irp->IoStatus.Status;
  2.1040 -
  2.1041 -  /* fail if we are in a stop or remove pending state */  
  2.1042 -  if (!NT_SUCCESS(irp->IoStatus.Status))
  2.1043 -  {
  2.1044 -    switch (stack->Parameters.UsageNotification.Type)
  2.1045 -    {
  2.1046 -    case DeviceUsageTypePaging:
  2.1047 -      if (stack->Parameters.UsageNotification.InPath)
  2.1048 -        xpdd->common.device_usage_paging--;
  2.1049 -      else
  2.1050 -        xpdd->common.device_usage_paging++;      
  2.1051 -      break;
  2.1052 -    case DeviceUsageTypeDumpFile:
  2.1053 -      if (stack->Parameters.UsageNotification.InPath)
  2.1054 -        xpdd->common.device_usage_dump--;
  2.1055 -      else
  2.1056 -        xpdd->common.device_usage_dump++;      
  2.1057 -      break;
  2.1058 -    case DeviceUsageTypeHibernation:
  2.1059 -      if (stack->Parameters.UsageNotification.InPath)
  2.1060 -        xpdd->common.device_usage_hibernation--;
  2.1061 -      else
  2.1062 -        xpdd->common.device_usage_hibernation++;      
  2.1063 -      break;
  2.1064 -    default:
  2.1065 -      KdPrint((__DRIVER_NAME " Unknown usage type %x\n",
  2.1066 -        stack->Parameters.UsageNotification.Type));
  2.1067 -      break;
  2.1068 -    }
  2.1069 -    if (xpdd->common.device_usage_paging
  2.1070 -      || xpdd->common.device_usage_dump
  2.1071 -      || xpdd->common.device_usage_hibernation)
  2.1072 -    {
  2.1073 -      xpdd->common.fdo->Flags &= ~DO_POWER_PAGABLE;
  2.1074 -    }
  2.1075 -    IoInvalidateDeviceState(xpdd->common.pdo);
  2.1076 -  }
  2.1077 -  IoCompleteRequest(irp, IO_NO_INCREMENT);
  2.1078 -
  2.1079 -  FUNCTION_EXIT();
  2.1080 -  
  2.1081 -  return status;
  2.1082 -}
  2.1083 -
  2.1084 -
  2.1085 -NTSTATUS
  2.1086 -XenPci_Pnp_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  2.1087 -{
  2.1088 -  NTSTATUS status;
  2.1089 -  PIO_STACK_LOCATION stack;
  2.1090 -  PXENPCI_DEVICE_DATA xpdd = device_object->DeviceExtension;;
  2.1091 -
  2.1092 -  KdPrint((__DRIVER_NAME " --> " __FUNCTION__ "\n"));
  2.1093 -
  2.1094 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1095 -
  2.1096 -  switch (stack->MinorFunction)
  2.1097 -  {
  2.1098 -  case IRP_MN_START_DEVICE:
  2.1099 -    KdPrint((__DRIVER_NAME "     IRP_MN_START_DEVICE\n"));
  2.1100 -    return XenPci_Pnp_StartDevice(device_object, irp);
  2.1101 -
  2.1102 -  case IRP_MN_QUERY_STOP_DEVICE:
  2.1103 -    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_STOP_DEVICE\n"));
  2.1104 -    status = XenPci_Pnp_QueryStopRemoveDevice(device_object, irp);
  2.1105 -    if (NT_SUCCESS(status))
  2.1106 -      SET_PNP_STATE(&xpdd->common, RemovePending);
  2.1107 -    return status;
  2.1108 -
  2.1109 -  case IRP_MN_STOP_DEVICE:
  2.1110 -    KdPrint((__DRIVER_NAME "     IRP_MN_STOP_DEVICE\n"));
  2.1111 -    IoCopyCurrentIrpStackLocationToNext(irp);
  2.1112 -    IoSetCompletionRoutine(irp, XenPci_Pnp_StopDevice, NULL, TRUE, TRUE, TRUE);
  2.1113 -    break;
  2.1114 -
  2.1115 -  case IRP_MN_CANCEL_STOP_DEVICE:
  2.1116 -    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_STOP_DEVICE\n"));
  2.1117 -    IoSkipCurrentIrpStackLocation(irp);
  2.1118 -    REVERT_PNP_STATE(&xpdd->common);
  2.1119 -    irp->IoStatus.Status = STATUS_SUCCESS;
  2.1120 -    break;
  2.1121 -
  2.1122 -  case IRP_MN_QUERY_REMOVE_DEVICE:
  2.1123 -    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_REMOVE_DEVICE\n"));
  2.1124 -    status = XenPci_Pnp_QueryStopRemoveDevice(device_object, irp);
  2.1125 -    if (NT_SUCCESS(status))
  2.1126 -      SET_PNP_STATE(&xpdd->common, RemovePending);
  2.1127 -    return status;
  2.1128 -
  2.1129 -  case IRP_MN_REMOVE_DEVICE:
  2.1130 -    KdPrint((__DRIVER_NAME "     IRP_MN_REMOVE_DEVICE\n"));
  2.1131 -    return XenPci_Pnp_RemoveDevice(device_object, irp);
  2.1132 -    break;
  2.1133 -
  2.1134 -  case IRP_MN_CANCEL_REMOVE_DEVICE:
  2.1135 -    KdPrint((__DRIVER_NAME "     IRP_MN_CANCEL_REMOVE_DEVICE\n"));
  2.1136 -    IoSkipCurrentIrpStackLocation(irp);
  2.1137 -    REVERT_PNP_STATE(&xpdd->common);
  2.1138 -    irp->IoStatus.Status = STATUS_SUCCESS;
  2.1139 -    break;
  2.1140 -
  2.1141 -  case IRP_MN_SURPRISE_REMOVAL:
  2.1142 -    KdPrint((__DRIVER_NAME "     IRP_MN_SURPRISE_REMOVAL\n"));
  2.1143 -    IoSkipCurrentIrpStackLocation(irp);
  2.1144 -    irp->IoStatus.Status = STATUS_SUCCESS;
  2.1145 -    break;
  2.1146 -
  2.1147 -  case IRP_MN_DEVICE_USAGE_NOTIFICATION:
  2.1148 -    KdPrint((__DRIVER_NAME "     IRP_MN_DEVICE_USAGE_NOTIFICATION\n"));
  2.1149 -    switch (stack->Parameters.UsageNotification.Type)
  2.1150 -    {
  2.1151 -    case DeviceUsageTypePaging:
  2.1152 -      KdPrint((__DRIVER_NAME "     type = DeviceUsageTypePaging = %d\n", stack->Parameters.UsageNotification.InPath));
  2.1153 -      if (stack->Parameters.UsageNotification.InPath)
  2.1154 -        xpdd->common.device_usage_paging++;
  2.1155 -      else
  2.1156 -        xpdd->common.device_usage_paging--;      
  2.1157 -      irp->IoStatus.Status = STATUS_SUCCESS;
  2.1158 -      break;
  2.1159 -    case DeviceUsageTypeDumpFile:
  2.1160 -      KdPrint((__DRIVER_NAME "     type = DeviceUsageTypeDumpFile = %d\n", stack->Parameters.UsageNotification.InPath));
  2.1161 -      if (stack->Parameters.UsageNotification.InPath)
  2.1162 -        xpdd->common.device_usage_dump++;
  2.1163 -      else
  2.1164 -        xpdd->common.device_usage_dump--;      
  2.1165 -      irp->IoStatus.Status = STATUS_SUCCESS;
  2.1166 -      break;
  2.1167 -    case DeviceUsageTypeHibernation:
  2.1168 -      KdPrint((__DRIVER_NAME "     type = DeviceUsageTypeHibernation = %d\n", stack->Parameters.UsageNotification.InPath));
  2.1169 -      if (stack->Parameters.UsageNotification.InPath)
  2.1170 -        xpdd->common.device_usage_hibernation++;
  2.1171 -      else
  2.1172 -        xpdd->common.device_usage_hibernation--;      
  2.1173 -      irp->IoStatus.Status = STATUS_SUCCESS;
  2.1174 -      break;
  2.1175 -    default:
  2.1176 -      KdPrint((__DRIVER_NAME "     type = unsupported (%d)\n", stack->Parameters.UsageNotification.Type));
  2.1177 -      irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
  2.1178 -      IoCompleteRequest(irp, IO_NO_INCREMENT);
  2.1179 -      return STATUS_NOT_SUPPORTED;
  2.1180 -    }
  2.1181 -    if (!xpdd->common.device_usage_paging
  2.1182 -      && !xpdd->common.device_usage_dump
  2.1183 -      && !xpdd->common.device_usage_hibernation)
  2.1184 -    {
  2.1185 -      xpdd->common.fdo->Flags |= DO_POWER_PAGABLE;
  2.1186 -    }
  2.1187 -    IoInvalidateDeviceState(xpdd->common.pdo);
  2.1188 -    IoCopyCurrentIrpStackLocationToNext(irp);
  2.1189 -    IoSetCompletionRoutine(irp, XenPci_Pnp_DeviceUsageNotification, NULL, TRUE, TRUE, TRUE);
  2.1190 -    break;
  2.1191 -
  2.1192 -  case IRP_MN_QUERY_DEVICE_RELATIONS:
  2.1193 -    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_DEVICE_RELATIONS\n"));
  2.1194 -    switch (stack->Parameters.QueryDeviceRelations.Type)
  2.1195 -    {
  2.1196 -    case BusRelations:
  2.1197 -      KdPrint((__DRIVER_NAME "     BusRelations\n"));
  2.1198 -      return XenPci_Pnp_QueryBusRelations(device_object, irp);
  2.1199 -      break;  
  2.1200 -    default:
  2.1201 -      IoSkipCurrentIrpStackLocation(irp);
  2.1202 -      break;  
  2.1203 -    }
  2.1204 -    break;
  2.1205 -
  2.1206 -  case IRP_MN_FILTER_RESOURCE_REQUIREMENTS:
  2.1207 -    KdPrint((__DRIVER_NAME "     IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"));
  2.1208 -    return XenPci_Pnp_FilterResourceRequirements(device_object, irp);
  2.1209 -
  2.1210 -  case IRP_MN_QUERY_PNP_DEVICE_STATE:
  2.1211 -    KdPrint((__DRIVER_NAME "     IRP_MN_QUERY_PNP_DEVICE_STATE\n"));
  2.1212 -    irp->IoStatus.Status = STATUS_SUCCESS;
  2.1213 -    if (xpdd->common.device_usage_paging
  2.1214 -      || xpdd->common.device_usage_dump
  2.1215 -      || xpdd->common.device_usage_hibernation)
  2.1216 -    {
  2.1217 -      irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
  2.1218 -    }
  2.1219 -    IoSkipCurrentIrpStackLocation(irp);
  2.1220 -    break;
  2.1221 -    
  2.1222 -  default:
  2.1223 -    KdPrint((__DRIVER_NAME "     Unhandled Minor = %d\n", stack->MinorFunction));
  2.1224 -    IoSkipCurrentIrpStackLocation(irp);
  2.1225 -    break;
  2.1226 -  }
  2.1227 -
  2.1228 -  status = IoCallDriver(xpdd->common.lower_do, irp);
  2.1229 -
  2.1230 -  KdPrint((__DRIVER_NAME " <-- " __FUNCTION__"\n"));
  2.1231 -
  2.1232 -  return status;
  2.1233 -}
  2.1234 -
  2.1235 -NTSTATUS
  2.1236 -XenPci_Irp_Create_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  2.1237 -{
  2.1238 -  PXENPCI_DEVICE_DATA xpdd;
  2.1239 -  NTSTATUS status;
  2.1240 -  PIO_STACK_LOCATION stack;
  2.1241 -  PFILE_OBJECT file;
  2.1242 -
  2.1243 -  FUNCTION_ENTER();
  2.1244 -  
  2.1245 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1246 -  file = stack->FileObject;
  2.1247 -  
  2.1248 -  KdPrint((__DRIVER_NAME "     filename = %wZ\n", &file->FileName));
  2.1249 -  if (wcscmp(L"\\xenbus", file->FileName.Buffer) == 0)
  2.1250 -  {
  2.1251 -    status = XenPci_Irp_Create_XenBus(device_object, irp);
  2.1252 -  }
  2.1253 -  else
  2.1254 -  {
  2.1255 -    // legacy interface
  2.1256 -    xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  2.1257 -    file->FsContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(ULONG), XENPCI_POOL_TAG);
  2.1258 -    *(PULONG)file->FsContext = DEVICE_INTERFACE_TYPE_LEGACY;
  2.1259 -    status = STATUS_SUCCESS;    
  2.1260 -    irp->IoStatus.Status = status;
  2.1261 -    IoCompleteRequest(irp, IO_NO_INCREMENT);
  2.1262 -  }
  2.1263 -  KdPrint((__DRIVER_NAME "     context = %p\n", file->FsContext));
  2.1264 -  KdPrint((__DRIVER_NAME "     type = %d\n", *(PULONG)file->FsContext));
  2.1265 -  FUNCTION_EXIT();
  2.1266 -
  2.1267 -  return status;
  2.1268 -}
  2.1269 -
  2.1270 -NTSTATUS
  2.1271 -XenPci_Irp_Close_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  2.1272 -{
  2.1273 -  PXENPCI_DEVICE_DATA xpdd;
  2.1274 -  NTSTATUS status;
  2.1275 -  PIO_STACK_LOCATION stack;
  2.1276 -  PFILE_OBJECT file;
  2.1277 -
  2.1278 -  FUNCTION_ENTER();
  2.1279 -  
  2.1280 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1281 -  file = stack->FileObject;
  2.1282 -
  2.1283 -  if (*(PULONG)file->FsContext == DEVICE_INTERFACE_TYPE_XENBUS)
  2.1284 -  {
  2.1285 -    status = XenPci_Irp_Close_XenBus(device_object, irp);
  2.1286 -  }
  2.1287 -  else
  2.1288 -  {
  2.1289 -    // wait until pending irp's 
  2.1290 -    xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  2.1291 -    status = STATUS_SUCCESS;    
  2.1292 -    irp->IoStatus.Status = status;
  2.1293 -    IoCompleteRequest(irp, IO_NO_INCREMENT);
  2.1294 -  }
  2.1295 -  
  2.1296 -  FUNCTION_EXIT();
  2.1297 -
  2.1298 -  return status;
  2.1299 -}
  2.1300 -
  2.1301 -NTSTATUS
  2.1302 -XenPci_Irp_Read_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  2.1303 -{
  2.1304 -  PXENPCI_DEVICE_DATA xpdd;
  2.1305 -  NTSTATUS status;
  2.1306 -  PIO_STACK_LOCATION stack;
  2.1307 -  KIRQL old_irql;
  2.1308 -  PFILE_OBJECT file;
  2.1309 -
  2.1310 -  FUNCTION_ENTER();
  2.1311 -  
  2.1312 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1313 -  file = stack->FileObject;
  2.1314 -
  2.1315 -  if (*(PULONG)file->FsContext == DEVICE_INTERFACE_TYPE_XENBUS)
  2.1316 -  {
  2.1317 -    status = XenPci_Irp_Read_XenBus(device_object, irp);
  2.1318 -  }
  2.1319 -  else
  2.1320 -  {
  2.1321 -    xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  2.1322 -    stack = IoGetCurrentIrpStackLocation(irp);
  2.1323 -    if (stack->Parameters.Read.Length == 0)
  2.1324 -    {
  2.1325 -      irp->IoStatus.Information = 0;
  2.1326 -      status = STATUS_SUCCESS;    
  2.1327 -      irp->IoStatus.Status = status;
  2.1328 -      IoCompleteRequest(irp, IO_NO_INCREMENT);
  2.1329 -    }
  2.1330 -    else 
  2.1331 -    {
  2.1332 -      KdPrint((__DRIVER_NAME "     stack = %p\n", stack));
  2.1333 -      KdPrint((__DRIVER_NAME "     length = %d, buffer = %p\n", stack->Parameters.Read.Length, irp->AssociatedIrp.SystemBuffer));
  2.1334 -      
  2.1335 -      KeAcquireSpinLock(&xpdd->shutdown_ring_lock, &old_irql);
  2.1336 -      xpdd->shutdown_irp = irp;
  2.1337 -      IoSetCancelRoutine(irp, XenBus_ShutdownIoCancel);
  2.1338 -      KeReleaseSpinLock(&xpdd->shutdown_ring_lock, old_irql);
  2.1339 -      status = XenPci_ProcessShutdownIrp(xpdd);
  2.1340 -    }
  2.1341 -  }
  2.1342 -  FUNCTION_EXIT();
  2.1343 -
  2.1344 -  return status;
  2.1345 -}
  2.1346 -
  2.1347 -NTSTATUS
  2.1348 -XenPci_Irp_Write_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  2.1349 -{
  2.1350 -  PXENPCI_DEVICE_DATA xpdd;
  2.1351 -  NTSTATUS status;
  2.1352 -  PIO_STACK_LOCATION stack;
  2.1353 -  PFILE_OBJECT file;
  2.1354 -
  2.1355 -  FUNCTION_ENTER();
  2.1356 -  
  2.1357 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1358 -  file = stack->FileObject;
  2.1359 -  
  2.1360 -  KdPrint((__DRIVER_NAME "     context = %p\n", file->FsContext));
  2.1361 -  KdPrint((__DRIVER_NAME "     type = %d\n", *(PULONG)file->FsContext));
  2.1362 -
  2.1363 -  xpdd = (PXENPCI_DEVICE_DATA)device_object->DeviceExtension;
  2.1364 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1365 -
  2.1366 -  if (*(PULONG)file->FsContext == DEVICE_INTERFACE_TYPE_XENBUS)
  2.1367 -  {
  2.1368 -    status = XenPci_Irp_Write_XenBus(device_object, irp);
  2.1369 -  }
  2.1370 -  else
  2.1371 -  {
  2.1372 -    status = STATUS_UNSUCCESSFUL;
  2.1373 -    irp->IoStatus.Status = status;
  2.1374 -    IoCompleteRequest(irp, IO_NO_INCREMENT);
  2.1375 -  }    
  2.1376 -
  2.1377 -  FUNCTION_EXIT();
  2.1378 -
  2.1379 -  return status;
  2.1380 -}
  2.1381 -
  2.1382 -NTSTATUS
  2.1383 -XenPci_Irp_Cleanup_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  2.1384 -{
  2.1385 -  NTSTATUS status;
  2.1386 -  PIO_STACK_LOCATION stack;
  2.1387 -  PFILE_OBJECT file;
  2.1388 -
  2.1389 -  UNREFERENCED_PARAMETER(device_object);
  2.1390 -
  2.1391 -  FUNCTION_ENTER();
  2.1392 -  
  2.1393 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1394 -  file = stack->FileObject;
  2.1395 -  
  2.1396 -  if (*(PULONG)file->FsContext == DEVICE_INTERFACE_TYPE_XENBUS)
  2.1397 -  {
  2.1398 -    status = XenPci_Irp_Cleanup_XenBus(device_object, irp);
  2.1399 -  }
  2.1400 -  else
  2.1401 -  {
  2.1402 -    status = STATUS_SUCCESS;
  2.1403 -    irp->IoStatus.Status = status;
  2.1404 -    IoCompleteRequest(irp, IO_NO_INCREMENT);
  2.1405 -  }
  2.1406 -  FUNCTION_EXIT();
  2.1407 -
  2.1408 -  return status;
  2.1409 -}
  2.1410 -
  2.1411 -DDKAPI NTSTATUS
  2.1412 -XenPci_SystemControl_Fdo(PDEVICE_OBJECT device_object, PIRP irp)
  2.1413 -{
  2.1414 -  NTSTATUS status;
  2.1415 -  PIO_STACK_LOCATION stack;
  2.1416 -  PXENPCI_COMMON common = device_object->DeviceExtension;
  2.1417 -  
  2.1418 -  FUNCTION_ENTER();
  2.1419 -
  2.1420 -  UNREFERENCED_PARAMETER(device_object);
  2.1421 -
  2.1422 -  stack = IoGetCurrentIrpStackLocation(irp);
  2.1423 -  DbgPrint(__DRIVER_NAME "     Minor = %d\n", stack->MinorFunction);
  2.1424 -  IoSkipCurrentIrpStackLocation(irp);
  2.1425 -  status = IoCallDriver(common->lower_do, irp);
  2.1426 -
  2.1427 -  FUNCTION_EXIT();
  2.1428 -  
  2.1429 -  return status;
  2.1430 -}
  2.1431 -
  2.1432 -#endif