[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 07/14] Expose console interface from Pdo
From: Owen Smith <owen.smith@xxxxxxxxxx> Pdo registers the xencons interface guid and implements boilerplate responses to IOCTLs and read/write IRPs Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx> --- src/xencons/pdo.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/src/xencons/pdo.c b/src/xencons/pdo.c index 7a9c1e6..cc0dc4e 100755 --- a/src/xencons/pdo.c +++ b/src/xencons/pdo.c @@ -36,6 +36,8 @@ #include <ntstrsafe.h> #include <stdlib.h> +#include <xencons_device.h> + #include "names.h" #include "fdo.h" #include "pdo.h" @@ -436,6 +438,9 @@ PdoD3ToD0( KeLowerIrql(Irql); +#pragma prefast(suppress:28123) + (VOID) IoSetDeviceInterfaceState(&Pdo->Dx->Link, TRUE); + return STATUS_SUCCESS; fail3: @@ -466,6 +471,9 @@ PdoD0ToD3( ASSERT3U(KeGetCurrentIrql(), == , PASSIVE_LEVEL); +#pragma prefast(suppress:28123) + (VOID) IoSetDeviceInterfaceState(&Pdo->Dx->Link, FALSE); + KeRaiseIrql(DISPATCH_LEVEL, &Irql); XENBUS_SUSPEND(Deregister, @@ -518,8 +526,20 @@ PdoStartDevice( IN PIRP Irp ) { + PXENCONS_DX Dx = Pdo->Dx; NTSTATUS status; + if (Dx->Link.Length != 0) + goto done; + + status = IoRegisterDeviceInterface(__PdoGetDeviceObject(Pdo), + &GUID_XENCONS_DEVICE, + NULL, + &Dx->Link); + if (!NT_SUCCESS(status)) + goto fail1; + +done: status = PdoD3ToD0(Pdo); if (!NT_SUCCESS(status)) goto fail1; @@ -1562,6 +1582,163 @@ PdoDispatchPower( } static DECLSPEC_NOINLINE NTSTATUS +PdoDispatchCreate( + IN PXENCONS_PDO Pdo, + IN PIRP Irp + ) +{ + NTSTATUS status; + + UNREFERENCED_PARAMETER(Pdo); + + status = STATUS_SUCCESS; + + Irp->IoStatus.Status = status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return status; +} + +static DECLSPEC_NOINLINE NTSTATUS +PdoDispatchCleanup( + IN PXENCONS_PDO Pdo, + IN PIRP Irp + ) +{ + NTSTATUS status; + + UNREFERENCED_PARAMETER(Pdo); + + status = STATUS_SUCCESS; + + Irp->IoStatus.Status = status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return status; +} + +static DECLSPEC_NOINLINE NTSTATUS +PdoDispatchClose( + IN PXENCONS_PDO Pdo, + IN PIRP Irp + ) +{ + NTSTATUS status; + + UNREFERENCED_PARAMETER(Pdo); + + status = STATUS_SUCCESS; + + Irp->IoStatus.Status = status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return status; +} + +static DECLSPEC_NOINLINE NTSTATUS +PdoDispatchReadWrite( + IN PXENCONS_PDO Pdo, + IN PIRP Irp + ) +{ + NTSTATUS status; + + IoMarkIrpPending(Irp); + + status = STATUS_DEVICE_NOT_READY; + if (!NT_SUCCESS(status)) + goto fail1; + + return STATUS_PENDING; + +fail1: + Error("fail1 (%08x)\n", status); + + Irp->IoStatus.Status = status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return status; +} + +static DECLSPEC_NOINLINE NTSTATUS +PdoDispatchControl( + IN PXENCONS_PDO Pdo, + IN PIRP Irp + ) +{ + PIO_STACK_LOCATION StackLocation; + ULONG IoControlCode; + ULONG InputBufferLength; + ULONG OutputBufferLength; + PVOID Buffer; + PCHAR Value; + ULONG Length; + NTSTATUS status; + + UNREFERENCED_PARAMETER(Pdo); + + StackLocation = IoGetCurrentIrpStackLocation(Irp); + IoControlCode = StackLocation->Parameters.DeviceIoControl.IoControlCode; + InputBufferLength = StackLocation->Parameters.DeviceIoControl.InputBufferLength; + OutputBufferLength = StackLocation->Parameters.DeviceIoControl.OutputBufferLength; + Buffer = Irp->AssociatedIrp.SystemBuffer; + + switch (IoControlCode) { + case IOCTL_XENCONS_GET_INSTANCE: + Value = __PdoGetName(Pdo); + break; + case IOCTL_XENCONS_GET_NAME: + Value = "non-default"; // use xenstore value + break; + case IOCTL_XENCONS_GET_PROTOCOL: + Value = "vt100"; // use xenstore value + break; + default: + status = STATUS_NOT_SUPPORTED; + goto fail1; + } + Length = (ULONG)strlen(Value); + + status = STATUS_INVALID_PARAMETER; + if (InputBufferLength != 0) + goto fail2; + + Irp->IoStatus.Information = Length; + + status = STATUS_INVALID_BUFFER_SIZE; + if (OutputBufferLength == 0) + goto done; + + RtlZeroMemory(Buffer, OutputBufferLength); + + if (OutputBufferLength < Length) + goto fail3; + + RtlCopyMemory(Buffer, Value, Length); + status = STATUS_SUCCESS; + +done: + Irp->IoStatus.Status = status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return status; + +fail3: + Error("fail3\n"); + +fail2: + Error("fail2\n"); + +fail1: + Error("fail1 (%08x)\n", status); + + Irp->IoStatus.Status = status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + + return status; +} + +static DECLSPEC_NOINLINE NTSTATUS PdoDispatchDefault( IN PXENCONS_PDO Pdo, IN PIRP Irp @@ -1597,6 +1774,27 @@ PdoDispatch( status = PdoDispatchPower(Pdo, Irp); break; + case IRP_MJ_CREATE: + status = PdoDispatchCreate(Pdo, Irp); + break; + + case IRP_MJ_CLEANUP: + status = PdoDispatchCleanup(Pdo, Irp); + break; + + case IRP_MJ_CLOSE: + status = PdoDispatchClose(Pdo, Irp); + break; + + case IRP_MJ_READ: + case IRP_MJ_WRITE: + status = PdoDispatchReadWrite(Pdo, Irp); + break; + + case IRP_MJ_DEVICE_CONTROL: + status = PdoDispatchControl(Pdo, Irp); + break; + default: status = PdoDispatchDefault(Pdo, Irp); break; @@ -1763,6 +1961,7 @@ PdoDestroy( (VOID)__PdoClearEjectRequested(Pdo); + RtlFreeUnicodeString(&Dx->Link); Dx->Pdo = NULL; RtlZeroMemory(&Pdo->SuspendInterface, -- 2.8.3 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |