win-pvdrivers

changeset 617:1478103c6ef5

Added DPC call in config page and Reconfiguring callback
author James Harper <james.harper@bendigoit.com.au>
date Sun Jul 26 23:06:45 2009 +1000 (2009-07-26)
parents fd445db0c603
children a344955897dd
files xenpci/xenpci_pdo.c
line diff
     1.1 --- a/xenpci/xenpci_pdo.c	Sun Jul 26 23:06:09 2009 +1000
     1.2 +++ b/xenpci/xenpci_pdo.c	Sun Jul 26 23:06:45 2009 +1000
     1.3 @@ -1151,6 +1151,21 @@ XenPci_ReadBackendState(PXENPCI_PDO_DEVI
     1.4    }
     1.5  }
     1.6  
     1.7 +static NTSTATUS
     1.8 +XenPciPdo_ReconfigureCompletionRoutine(
     1.9 +  PDEVICE_OBJECT device_object,
    1.10 +  PIRP irp,
    1.11 +  PVOID context)
    1.12 +{
    1.13 +  UNREFERENCED_PARAMETER(device_object);
    1.14 +  
    1.15 +  if (irp->PendingReturned)
    1.16 +  {
    1.17 +    KeSetEvent ((PKEVENT)context, IO_NO_INCREMENT, FALSE);
    1.18 +  }
    1.19 +  return STATUS_MORE_PROCESSING_REQUIRED;
    1.20 +}
    1.21 +
    1.22  static VOID
    1.23  XenPci_BackEndStateHandler(char *path, PVOID context)
    1.24  {
    1.25 @@ -1158,6 +1173,7 @@ XenPci_BackEndStateHandler(char *path, P
    1.26    PXENPCI_PDO_DEVICE_DATA xppdd = GetXppdd(device);
    1.27    PXENPCI_DEVICE_DATA xpdd = GetXpdd(xppdd->wdf_device_bus_fdo);
    1.28    ULONG new_backend_state;
    1.29 +  CHAR tmp_path[128];
    1.30  
    1.31  #if !DBG
    1.32    UNREFERENCED_PARAMETER(path);
    1.33 @@ -1220,6 +1236,58 @@ XenPci_BackEndStateHandler(char *path, P
    1.34      KdPrint((__DRIVER_NAME "     Backend State Changed to Closed (%s)\n", path));  
    1.35      break;
    1.36  
    1.37 +  case XenbusStateReconfiguring:
    1.38 +    KdPrint((__DRIVER_NAME "     Backend State Changed to Reconfiguring (%s)\n", path));  
    1.39 +    RtlStringCbPrintfA(tmp_path, ARRAY_SIZE(tmp_path), "%s/state", xppdd->path);
    1.40 +    KdPrint((__DRIVER_NAME "     Setting %s to %d\n", tmp_path, XenbusStateReconfiguring));
    1.41 +    XenBus_Printf(xpdd, XBT_NIL, tmp_path, "%d", XenbusStateReconfiguring);
    1.42 +    break;
    1.43 +
    1.44 +  case XenbusStateReconfigured:
    1.45 +    KdPrint((__DRIVER_NAME "     Backend State Changed to Reconfigured (%s)\n", path));
    1.46 +  {
    1.47 +    PDEVICE_OBJECT fdo;
    1.48 +    PIRP irp;
    1.49 +    PIO_STACK_LOCATION stack;
    1.50 +    NTSTATUS status;
    1.51 +    KEVENT irp_complete_event;
    1.52 +    
    1.53 +    fdo = IoGetAttachedDeviceReference(WdfDeviceWdmGetDeviceObject(device));
    1.54 +    KeInitializeEvent(&irp_complete_event, NotificationEvent, FALSE);
    1.55 +    irp = IoAllocateIrp(fdo->StackSize, FALSE);
    1.56 +    stack = IoGetNextIrpStackLocation(irp);
    1.57 +    stack->MajorFunction = IRP_MJ_INTERNAL_DEVICE_CONTROL;
    1.58 +    stack->Parameters.DeviceIoControl.IoControlCode = (ULONG)IOCTL_XEN_RECONFIGURE;
    1.59 +    IoSetCompletionRoutine(irp, XenPciPdo_ReconfigureCompletionRoutine, &irp_complete_event, TRUE, TRUE, TRUE);
    1.60 +    status = IoCallDriver(fdo, irp);
    1.61 +    if (status == STATUS_PENDING)
    1.62 +    {
    1.63 +      KdPrint((__DRIVER_NAME "     Waiting for completion\n"));
    1.64 +      status = KeWaitForSingleObject(&irp_complete_event, Executive, KernelMode, FALSE, NULL);
    1.65 +      status = irp->IoStatus.Status;                     
    1.66 +    }
    1.67 +    KdPrint((__DRIVER_NAME "     IOCTL_XEN_RECONFIGURE status = %08x\n", status));
    1.68 +    ObDereferenceObject(fdo);
    1.69 +#if 0
    1.70 +    WDFREQUEST request;
    1.71 +    WDF_REQUEST_SEND_OPTIONS options;
    1.72 +    WDFIOTARGET target;
    1.73 +    DEVICE_OBJECT fdo;
    1.74 +    
    1.75 +    WDF_REQUEST_SEND_OPTIONS_INIT(&options, WDF_REQUEST_SEND_OPTION_SEND_AND_FORGET);
    1.76 +    fdo = IoGetAttachedDevice(WdfDeviceWdmGetDeviceObject(device));
    1.77 +    
    1.78 +    target = WdfDeviceGetIoTarget(xppdd->wdf_device);
    1.79 +    WdfRequestCreate(WDF_NO_OBJECT_ATTRIBUTES, target, &request);
    1.80 +    WdfIoTargetFormatRequestForInternalIoctl(target, request, IOCTL_XEN_RECONFIGURE, NULL, NULL, NULL, NULL);
    1.81 +    WdfRequestSend(request, target, &options);
    1.82 +#endif
    1.83 +    RtlStringCbPrintfA(tmp_path, ARRAY_SIZE(tmp_path), "%s/state", xppdd->path);
    1.84 +    KdPrint((__DRIVER_NAME "     Setting %s to %d\n", tmp_path, XenbusStateConnected));
    1.85 +    XenBus_Printf(xpdd, XBT_NIL, tmp_path, "%d", XenbusStateConnected);
    1.86 +    break;
    1.87 +  }
    1.88 +  
    1.89    default:
    1.90      KdPrint((__DRIVER_NAME "     Backend State Changed to Undefined = %d (%s)\n", xppdd->backend_state, path));
    1.91      break;
    1.92 @@ -1616,6 +1684,7 @@ XenPci_XenShutdownDevice(PVOID context)
    1.93          FreePages(value);
    1.94          break;
    1.95        case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
    1.96 +      case XEN_INIT_TYPE_EVENT_CHANNEL_DPC: /* frontend event channel bound to dpc */
    1.97        case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
    1.98          EvtChn_Unbind(xpdd, PtrToUlong(value));
    1.99          EvtChn_Close(xpdd, PtrToUlong(value));
   1.100 @@ -1829,10 +1898,11 @@ XenPci_XenConfigDeviceSpecifyBuffers(WDF
   1.101        }
   1.102        break;
   1.103      case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
   1.104 +    case XEN_INIT_TYPE_EVENT_CHANNEL_DPC: /* frontend event channel bound to dpc */
   1.105      case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
   1.106        if ((event_channel = EvtChn_AllocUnbound(xpdd, 0)) != 0)
   1.107        {
   1.108 -        //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, event_channel));
   1.109 +        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_EVENT_CHANNEL - %s = %d\n", setting, event_channel));
   1.110          RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/%s", xppdd->path, setting);
   1.111          XenBus_Printf(xpdd, XBT_NIL, path, "%d", event_channel);
   1.112          ADD_XEN_INIT_RSP(&out_ptr, type, setting, UlongToPtr(event_channel), NULL);
   1.113 @@ -1841,6 +1911,11 @@ XenPci_XenConfigDeviceSpecifyBuffers(WDF
   1.114          {
   1.115            EvtChn_BindIrq(xpdd, event_channel, xppdd->irq_vector, path);
   1.116          }
   1.117 +        else if (type == XEN_INIT_TYPE_EVENT_CHANNEL_DPC)
   1.118 +        {
   1.119 +          #pragma warning(suppress:4055)
   1.120 +          EvtChn_BindDpc(xpdd, event_channel, (PXEN_EVTCHN_SERVICE_ROUTINE)value, value2);
   1.121 +        }
   1.122          else
   1.123          {
   1.124            #pragma warning(suppress:4055)
   1.125 @@ -1884,9 +1959,9 @@ XenPci_XenConfigDeviceSpecifyBuffers(WDF
   1.126        res = XenBus_Read(xpdd, XBT_NIL, path, &value);
   1.127        if (res)
   1.128        {
   1.129 -        //KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = <failed>\n", setting));
   1.130 +        KdPrint((__DRIVER_NAME "     XEN_INIT_TYPE_READ_STRING - %s = <failed>\n", setting));
   1.131          XenPci_FreeMem(res);
   1.132 -        ADD_XEN_INIT_RSP(&out_ptr, type, setting, NULL, NULL);
   1.133 +        ADD_XEN_INIT_RSP(&out_ptr, type, setting, "", "");
   1.134        }
   1.135        else
   1.136        {
   1.137 @@ -2211,7 +2286,7 @@ XenPciPdo_EvtDeviceD0Exit(WDFDEVICE devi
   1.138      KdPrint((__DRIVER_NAME "     Unknown WdfPowerDevice state %d\n", target_state));
   1.139      break;  
   1.140    }
   1.141 -  
   1.142 +
   1.143    if (target_state == WdfPowerDevicePrepareForHibernation
   1.144        || (target_state == WdfPowerDeviceD3 && xppdd->hiber_usage_kludge))
   1.145    {
   1.146 @@ -2504,6 +2579,7 @@ XenPci_Pdo_Suspend(WDFDEVICE device)
   1.147          switch (type)
   1.148          {
   1.149          case XEN_INIT_TYPE_EVENT_CHANNEL: /* frontend event channel */
   1.150 +        case XEN_INIT_TYPE_EVENT_CHANNEL_DPC: /* frontend event channel bound to dpc */
   1.151          case XEN_INIT_TYPE_EVENT_CHANNEL_IRQ: /* frontend event channel bound to irq */
   1.152            EvtChn_Unbind(xpdd, PtrToUlong(value));
   1.153            EvtChn_Close(xpdd, PtrToUlong(value));