From 0560eef6ec5479a9b730715ddb65781b20f1d8bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Poussineau?= Date: Wed, 11 Feb 2009 17:21:10 +0000 Subject: [PATCH] Revert r39517, as there is no reason for such a change: files are consistently formatted, don't belong to ntoskrnl, use tabs only for indenting and not for formatting, and formatting revisions complicate svn blame feature usage. svn path=/trunk/; revision=39553 --- reactos/drivers/input/i8042prt/createclose.c | 45 +- reactos/drivers/input/i8042prt/i8042prt.c | 820 +++++----- reactos/drivers/input/i8042prt/i8042prt.h | 392 ++--- reactos/drivers/input/i8042prt/keyboard.c | 1377 ++++++++-------- reactos/drivers/input/i8042prt/misc.c | 95 +- reactos/drivers/input/i8042prt/mouse.c | 1480 +++++++++--------- reactos/drivers/input/i8042prt/pnp.c | 1178 +++++++------- reactos/drivers/input/i8042prt/ps2pp.c | 215 +-- reactos/drivers/input/i8042prt/readwrite.c | 282 ++-- reactos/drivers/input/i8042prt/registry.c | 369 ++--- reactos/drivers/input/i8042prt/setup.c | 422 ++--- 11 files changed, 3380 insertions(+), 3295 deletions(-) diff --git a/reactos/drivers/input/i8042prt/createclose.c b/reactos/drivers/input/i8042prt/createclose.c index 6429291c702..3a896d0ffcc 100644 --- a/reactos/drivers/input/i8042prt/createclose.c +++ b/reactos/drivers/input/i8042prt/createclose.c @@ -13,37 +13,40 @@ /* FUNCTIONS *****************************************************************/ NTSTATUS NTAPI -i8042Create(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042Create( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - TRACE_(I8042PRT, "IRP_MJ_CREATE\n"); + TRACE_(I8042PRT, "IRP_MJ_CREATE\n"); - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = 0; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return STATUS_SUCCESS; + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = 0; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return STATUS_SUCCESS; } NTSTATUS NTAPI -i8042Cleanup(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042Cleanup( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - TRACE_(I8042PRT, "IRP_MJ_CLEANUP\n"); + TRACE_(I8042PRT, "IRP_MJ_CLEANUP\n"); - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = 0; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return STATUS_SUCCESS; + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = 0; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return STATUS_SUCCESS; } NTSTATUS NTAPI -i8042Close(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042Close( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - TRACE_(I8042PRT, "IRP_MJ_CLOSE\n"); + TRACE_(I8042PRT, "IRP_MJ_CLOSE\n"); - Irp->IoStatus.Status = STATUS_SUCCESS; - Irp->IoStatus.Information = 0; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return STATUS_SUCCESS; + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = 0; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return STATUS_SUCCESS; } diff --git a/reactos/drivers/input/i8042prt/i8042prt.c b/reactos/drivers/input/i8042prt/i8042prt.c index cdbcb294c9b..45890ac1e83 100644 --- a/reactos/drivers/input/i8042prt/i8042prt.c +++ b/reactos/drivers/input/i8042prt/i8042prt.c @@ -23,506 +23,516 @@ static DRIVER_DISPATCH i8042InternalDeviceControl; DRIVER_INITIALIZE DriverEntry; NTSTATUS NTAPI -i8042AddDevice(IN PDRIVER_OBJECT DriverObject, - IN PDEVICE_OBJECT Pdo) +i8042AddDevice( + IN PDRIVER_OBJECT DriverObject, + IN PDEVICE_OBJECT Pdo) { - PI8042_DRIVER_EXTENSION DriverExtension; - PFDO_DEVICE_EXTENSION DeviceExtension = NULL; - PDEVICE_OBJECT Fdo = NULL; - ULONG DeviceExtensionSize; - NTSTATUS Status; + PI8042_DRIVER_EXTENSION DriverExtension; + PFDO_DEVICE_EXTENSION DeviceExtension = NULL; + PDEVICE_OBJECT Fdo = NULL; + ULONG DeviceExtensionSize; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042AddDevice(%p %p)\n", DriverObject, Pdo); + TRACE_(I8042PRT, "i8042AddDevice(%p %p)\n", DriverObject, Pdo); - DriverExtension = (PI8042_DRIVER_EXTENSION)IoGetDriverObjectExtension(DriverObject, DriverObject); + DriverExtension = (PI8042_DRIVER_EXTENSION)IoGetDriverObjectExtension(DriverObject, DriverObject); - if (Pdo == NULL) - { - /* We're getting a NULL Pdo at the first call as - * we are a legacy driver. Ignore it */ - return STATUS_SUCCESS; - } + if (Pdo == NULL) + { + /* We're getting a NULL Pdo at the first call as + * we are a legacy driver. Ignore it */ + return STATUS_SUCCESS; + } - /* Create new device object. As we don't know if the device would be a keyboard - * or a mouse, we have to allocate the biggest device extension. */ - DeviceExtensionSize = MAX(sizeof(I8042_KEYBOARD_EXTENSION), sizeof(I8042_MOUSE_EXTENSION)); - Status = IoCreateDevice( - DriverObject, - DeviceExtensionSize, - NULL, - Pdo->DeviceType, - FILE_DEVICE_SECURE_OPEN, - TRUE, - &Fdo); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoCreateDevice() failed with status 0x%08lx\n", Status); - goto cleanup; - } + /* Create new device object. As we don't know if the device would be a keyboard + * or a mouse, we have to allocate the biggest device extension. */ + DeviceExtensionSize = MAX(sizeof(I8042_KEYBOARD_EXTENSION), sizeof(I8042_MOUSE_EXTENSION)); + Status = IoCreateDevice( + DriverObject, + DeviceExtensionSize, + NULL, + Pdo->DeviceType, + FILE_DEVICE_SECURE_OPEN, + TRUE, + &Fdo); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoCreateDevice() failed with status 0x%08lx\n", Status); + goto cleanup; + } - DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension; - RtlZeroMemory(DeviceExtension, DeviceExtensionSize); - DeviceExtension->Type = Unknown; - DeviceExtension->Fdo = Fdo; - DeviceExtension->Pdo = Pdo; - DeviceExtension->PortDeviceExtension = &DriverExtension->Port; - Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status); - goto cleanup; - } + DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension; + RtlZeroMemory(DeviceExtension, DeviceExtensionSize); + DeviceExtension->Type = Unknown; + DeviceExtension->Fdo = Fdo; + DeviceExtension->Pdo = Pdo; + DeviceExtension->PortDeviceExtension = &DriverExtension->Port; + Status = IoAttachDeviceToDeviceStackSafe(Fdo, Pdo, &DeviceExtension->LowerDevice); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n", Status); + goto cleanup; + } - ExInterlockedInsertTailList( - &DriverExtension->DeviceListHead, - &DeviceExtension->ListEntry, - &DriverExtension->DeviceListLock); + ExInterlockedInsertTailList( + &DriverExtension->DeviceListHead, + &DeviceExtension->ListEntry, + &DriverExtension->DeviceListLock); - Fdo->Flags &= ~DO_DEVICE_INITIALIZING; - return STATUS_SUCCESS; + Fdo->Flags &= ~DO_DEVICE_INITIALIZING; + return STATUS_SUCCESS; cleanup: - if (DeviceExtension && DeviceExtension->LowerDevice) - IoDetachDevice(DeviceExtension->LowerDevice); - if (Fdo) - IoDeleteDevice(Fdo); - return Status; + if (DeviceExtension && DeviceExtension->LowerDevice) + IoDetachDevice(DeviceExtension->LowerDevice); + if (Fdo) + IoDeleteDevice(Fdo); + return Status; } VOID NTAPI -i8042SendHookWorkItem(IN PDEVICE_OBJECT DeviceObject, - IN PVOID Context) +i8042SendHookWorkItem( + IN PDEVICE_OBJECT DeviceObject, + IN PVOID Context) { - PI8042_HOOK_WORKITEM WorkItemData; - PFDO_DEVICE_EXTENSION FdoDeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; - PDEVICE_OBJECT TopOfStack = NULL; - ULONG IoControlCode; - PVOID InputBuffer; - ULONG InputBufferLength; - IO_STATUS_BLOCK IoStatus; - KEVENT Event; - PIRP NewIrp; - NTSTATUS Status; + PI8042_HOOK_WORKITEM WorkItemData; + PFDO_DEVICE_EXTENSION FdoDeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + PDEVICE_OBJECT TopOfStack = NULL; + ULONG IoControlCode; + PVOID InputBuffer; + ULONG InputBufferLength; + IO_STATUS_BLOCK IoStatus; + KEVENT Event; + PIRP NewIrp; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042SendHookWorkItem(%p %p)\n", DeviceObject, Context); + TRACE_(I8042PRT, "i8042SendHookWorkItem(%p %p)\n", DeviceObject, Context); - WorkItemData = (PI8042_HOOK_WORKITEM)Context; - FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - PortDeviceExtension = FdoDeviceExtension->PortDeviceExtension; + WorkItemData = (PI8042_HOOK_WORKITEM)Context; + FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + PortDeviceExtension = FdoDeviceExtension->PortDeviceExtension; - switch (FdoDeviceExtension->Type) - { - case Keyboard: - { - PI8042_KEYBOARD_EXTENSION DeviceExtension; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension; - IoControlCode = IOCTL_INTERNAL_I8042_HOOK_KEYBOARD; - InputBuffer = &DeviceExtension->KeyboardHook; - InputBufferLength = sizeof(INTERNAL_I8042_HOOK_KEYBOARD); - break; - } - case Mouse: - { - PI8042_MOUSE_EXTENSION DeviceExtension; - DeviceExtension = (PI8042_MOUSE_EXTENSION)FdoDeviceExtension; - IoControlCode = IOCTL_INTERNAL_I8042_HOOK_MOUSE; - InputBuffer = &DeviceExtension->MouseHook; - InputBufferLength = sizeof(INTERNAL_I8042_HOOK_MOUSE); - break; - } - default: - { - ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type); - ASSERT(FALSE); - WorkItemData->Irp->IoStatus.Status = STATUS_INTERNAL_ERROR; - goto cleanup; - } - } + switch (FdoDeviceExtension->Type) + { + case Keyboard: + { + PI8042_KEYBOARD_EXTENSION DeviceExtension; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension; + IoControlCode = IOCTL_INTERNAL_I8042_HOOK_KEYBOARD; + InputBuffer = &DeviceExtension->KeyboardHook; + InputBufferLength = sizeof(INTERNAL_I8042_HOOK_KEYBOARD); + break; + } + case Mouse: + { + PI8042_MOUSE_EXTENSION DeviceExtension; + DeviceExtension = (PI8042_MOUSE_EXTENSION)FdoDeviceExtension; + IoControlCode = IOCTL_INTERNAL_I8042_HOOK_MOUSE; + InputBuffer = &DeviceExtension->MouseHook; + InputBufferLength = sizeof(INTERNAL_I8042_HOOK_MOUSE); + break; + } + default: + { + ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type); + ASSERT(FALSE); + WorkItemData->Irp->IoStatus.Status = STATUS_INTERNAL_ERROR; + goto cleanup; + } + } - KeInitializeEvent(&Event, NotificationEvent, FALSE); - TopOfStack = IoGetAttachedDeviceReference(DeviceObject); + KeInitializeEvent(&Event, NotificationEvent, FALSE); + TopOfStack = IoGetAttachedDeviceReference(DeviceObject); - NewIrp = IoBuildDeviceIoControlRequest( - IoControlCode, - TopOfStack, - InputBuffer, - InputBufferLength, - NULL, - 0, - TRUE, - &Event, - &IoStatus); + NewIrp = IoBuildDeviceIoControlRequest( + IoControlCode, + TopOfStack, + InputBuffer, + InputBufferLength, + NULL, + 0, + TRUE, + &Event, + &IoStatus); - if (!NewIrp) - { - WARN_(I8042PRT, "IoBuildDeviceIoControlRequest() failed\n"); - WorkItemData->Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; - goto cleanup; - } + if (!NewIrp) + { + WARN_(I8042PRT, "IoBuildDeviceIoControlRequest() failed\n"); + WorkItemData->Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } - Status = IoCallDriver(TopOfStack, NewIrp); - if (Status == STATUS_PENDING) - { - KeWaitForSingleObject( - &Event, - Executive, - KernelMode, - FALSE, - NULL); - Status = IoStatus.Status; - } - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoCallDriver() failed with status 0x%08lx\n", Status); - goto cleanup; - } + Status = IoCallDriver(TopOfStack, NewIrp); + if (Status == STATUS_PENDING) + { + KeWaitForSingleObject( + &Event, + Executive, + KernelMode, + FALSE, + NULL); + Status = IoStatus.Status; + } + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoCallDriver() failed with status 0x%08lx\n", Status); + goto cleanup; + } - if (FdoDeviceExtension->Type == Keyboard) - { - PI8042_KEYBOARD_EXTENSION DeviceExtension; + if (FdoDeviceExtension->Type == Keyboard) + { + PI8042_KEYBOARD_EXTENSION DeviceExtension; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension; - /* Call the hooked initialization if it exists */ - if (DeviceExtension->KeyboardHook.InitializationRoutine) - { - Status = DeviceExtension->KeyboardHook.InitializationRoutine( - DeviceExtension->KeyboardHook.Context, - PortDeviceExtension, - i8042SynchReadPort, - i8042SynchWritePortKbd, - FALSE); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "KeyboardHook.InitializationRoutine() failed with status 0x%08lx\n", Status); - WorkItemData->Irp->IoStatus.Status = Status; - goto cleanup; - } - } - } + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)FdoDeviceExtension; + /* Call the hooked initialization if it exists */ + if (DeviceExtension->KeyboardHook.InitializationRoutine) + { + Status = DeviceExtension->KeyboardHook.InitializationRoutine( + DeviceExtension->KeyboardHook.Context, + PortDeviceExtension, + i8042SynchReadPort, + i8042SynchWritePortKbd, + FALSE); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "KeyboardHook.InitializationRoutine() failed with status 0x%08lx\n", Status); + WorkItemData->Irp->IoStatus.Status = Status; + goto cleanup; + } + } + } - WorkItemData->Irp->IoStatus.Status = STATUS_SUCCESS; + WorkItemData->Irp->IoStatus.Status = STATUS_SUCCESS; cleanup: - if (TopOfStack != NULL) - ObDereferenceObject(TopOfStack); - WorkItemData->Irp->IoStatus.Information = 0; - IoCompleteRequest(WorkItemData->Irp, IO_NO_INCREMENT); + if (TopOfStack != NULL) + ObDereferenceObject(TopOfStack); + WorkItemData->Irp->IoStatus.Information = 0; + IoCompleteRequest(WorkItemData->Irp, IO_NO_INCREMENT); - IoFreeWorkItem(WorkItemData->WorkItem); - ExFreePoolWithTag(WorkItemData, I8042PRT_TAG); + IoFreeWorkItem(WorkItemData->WorkItem); + ExFreePoolWithTag(WorkItemData, I8042PRT_TAG); } static VOID NTAPI -i8042StartIo(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042StartIo( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PFDO_DEVICE_EXTENSION DeviceExtension; + PFDO_DEVICE_EXTENSION DeviceExtension; - DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - switch (DeviceExtension->Type) - { - case Keyboard: - i8042KbdStartIo(DeviceObject, Irp); - break; - default: - ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type); - ASSERT(FALSE); - break; - } + DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + switch (DeviceExtension->Type) + { + case Keyboard: + i8042KbdStartIo(DeviceObject, Irp); + break; + default: + ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type); + ASSERT(FALSE); + break; + } } /* Write the current byte of the packet. Returns FALSE in case -* of problems. -*/ + * of problems. + */ static BOOLEAN -i8042PacketWrite(IN PPORT_DEVICE_EXTENSION DeviceExtension) +i8042PacketWrite( + IN PPORT_DEVICE_EXTENSION DeviceExtension) { - UCHAR Port = DeviceExtension->PacketPort; + UCHAR Port = DeviceExtension->PacketPort; - if (Port) - { - if (!i8042Write(DeviceExtension, - DeviceExtension->ControlPort, - Port)) - { - /* something is really wrong! */ - WARN_(I8042PRT, "Failed to send packet byte!\n"); - return FALSE; - } - } + if (Port) + { + if (!i8042Write(DeviceExtension, + DeviceExtension->ControlPort, + Port)) + { + /* something is really wrong! */ + WARN_(I8042PRT, "Failed to send packet byte!\n"); + return FALSE; + } + } - return i8042Write(DeviceExtension, - DeviceExtension->DataPort, - DeviceExtension->Packet.Bytes[DeviceExtension->Packet.CurrentByte]); + return i8042Write(DeviceExtension, + DeviceExtension->DataPort, + DeviceExtension->Packet.Bytes[DeviceExtension->Packet.CurrentByte]); } BOOLEAN -i8042PacketIsr(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR Output) +i8042PacketIsr( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR Output) { - if (DeviceExtension->Packet.State == Idle) - return FALSE; + if (DeviceExtension->Packet.State == Idle) + return FALSE; - switch (Output) - { - case KBD_RESEND: - DeviceExtension->PacketResends++; - if (DeviceExtension->PacketResends > DeviceExtension->Settings.ResendIterations) - { - DeviceExtension->Packet.State = Idle; - DeviceExtension->PacketComplete = TRUE; - DeviceExtension->PacketResult = STATUS_IO_TIMEOUT; - DeviceExtension->PacketResends = 0; - return TRUE; - } - DeviceExtension->Packet.CurrentByte--; - break; + switch (Output) + { + case KBD_RESEND: + DeviceExtension->PacketResends++; + if (DeviceExtension->PacketResends > DeviceExtension->Settings.ResendIterations) + { + DeviceExtension->Packet.State = Idle; + DeviceExtension->PacketComplete = TRUE; + DeviceExtension->PacketResult = STATUS_IO_TIMEOUT; + DeviceExtension->PacketResends = 0; + return TRUE; + } + DeviceExtension->Packet.CurrentByte--; + break; - case KBD_NACK: - DeviceExtension->Packet.State = Idle; - DeviceExtension->PacketComplete = TRUE; - DeviceExtension->PacketResult = STATUS_UNEXPECTED_IO_ERROR; - DeviceExtension->PacketResends = 0; - return TRUE; + case KBD_NACK: + DeviceExtension->Packet.State = Idle; + DeviceExtension->PacketComplete = TRUE; + DeviceExtension->PacketResult = STATUS_UNEXPECTED_IO_ERROR; + DeviceExtension->PacketResends = 0; + return TRUE; - default: - DeviceExtension->PacketResends = 0; - } + default: + DeviceExtension->PacketResends = 0; + } - if (DeviceExtension->Packet.CurrentByte >= DeviceExtension->Packet.ByteCount) - { - DeviceExtension->Packet.State = Idle; - DeviceExtension->PacketComplete = TRUE; - DeviceExtension->PacketResult = STATUS_SUCCESS; - return TRUE; - } + if (DeviceExtension->Packet.CurrentByte >= DeviceExtension->Packet.ByteCount) + { + DeviceExtension->Packet.State = Idle; + DeviceExtension->PacketComplete = TRUE; + DeviceExtension->PacketResult = STATUS_SUCCESS; + return TRUE; + } - if (!i8042PacketWrite(DeviceExtension)) - { - DeviceExtension->Packet.State = Idle; - DeviceExtension->PacketComplete = TRUE; - DeviceExtension->PacketResult = STATUS_IO_TIMEOUT; - return TRUE; - } - DeviceExtension->Packet.CurrentByte++; + if (!i8042PacketWrite(DeviceExtension)) + { + DeviceExtension->Packet.State = Idle; + DeviceExtension->PacketComplete = TRUE; + DeviceExtension->PacketResult = STATUS_IO_TIMEOUT; + return TRUE; + } + DeviceExtension->Packet.CurrentByte++; - return TRUE; + return TRUE; } /* -* This function starts a packet. It must be called with the -* correct DIRQL. -*/ + * This function starts a packet. It must be called with the + * correct DIRQL. + */ NTSTATUS -i8042StartPacket(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, - IN PUCHAR Bytes, - IN ULONG ByteCount, - IN PIRP Irp) +i8042StartPacket( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, + IN PUCHAR Bytes, + IN ULONG ByteCount, + IN PIRP Irp) { - KIRQL Irql; - NTSTATUS Status; + KIRQL Irql; + NTSTATUS Status; - Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt); + Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt); - if (DeviceExtension->Packet.State != Idle) - { - Status = STATUS_DEVICE_BUSY; - goto done; - } + if (DeviceExtension->Packet.State != Idle) + { + Status = STATUS_DEVICE_BUSY; + goto done; + } - switch (FdoDeviceExtension->Type) - { - case Keyboard: DeviceExtension->PacketPort = 0; break; - case Mouse: DeviceExtension->PacketPort = CTRL_WRITE_MOUSE; break; - default: - ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type); - ASSERT(FALSE); - Status = STATUS_INTERNAL_ERROR; - goto done; - } + switch (FdoDeviceExtension->Type) + { + case Keyboard: DeviceExtension->PacketPort = 0; break; + case Mouse: DeviceExtension->PacketPort = CTRL_WRITE_MOUSE; break; + default: + ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type); + ASSERT(FALSE); + Status = STATUS_INTERNAL_ERROR; + goto done; + } - DeviceExtension->Packet.Bytes = Bytes; - DeviceExtension->Packet.CurrentByte = 0; - DeviceExtension->Packet.ByteCount = ByteCount; - DeviceExtension->Packet.State = SendingBytes; - DeviceExtension->PacketResult = Status = STATUS_PENDING; - DeviceExtension->CurrentIrp = Irp; - DeviceExtension->CurrentIrpDevice = FdoDeviceExtension->Fdo; + DeviceExtension->Packet.Bytes = Bytes; + DeviceExtension->Packet.CurrentByte = 0; + DeviceExtension->Packet.ByteCount = ByteCount; + DeviceExtension->Packet.State = SendingBytes; + DeviceExtension->PacketResult = Status = STATUS_PENDING; + DeviceExtension->CurrentIrp = Irp; + DeviceExtension->CurrentIrpDevice = FdoDeviceExtension->Fdo; - if (!i8042PacketWrite(DeviceExtension)) - { - Status = STATUS_IO_TIMEOUT; - DeviceExtension->Packet.State = Idle; - DeviceExtension->PacketResult = STATUS_ABANDONED; - goto done; - } + if (!i8042PacketWrite(DeviceExtension)) + { + Status = STATUS_IO_TIMEOUT; + DeviceExtension->Packet.State = Idle; + DeviceExtension->PacketResult = STATUS_ABANDONED; + goto done; + } - DeviceExtension->Packet.CurrentByte++; + DeviceExtension->Packet.CurrentByte++; done: - KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql); + KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql); - if (Status != STATUS_PENDING) - { - DeviceExtension->CurrentIrp = NULL; - DeviceExtension->CurrentIrpDevice = NULL; - Irp->IoStatus.Status = Status; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - } - return Status; + if (Status != STATUS_PENDING) + { + DeviceExtension->CurrentIrp = NULL; + DeviceExtension->CurrentIrpDevice = NULL; + Irp->IoStatus.Status = Status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + } + return Status; } static NTSTATUS NTAPI -IrpStub(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +IrpStub( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - NTSTATUS Status = Irp->IoStatus.Status; + NTSTATUS Status = Irp->IoStatus.Status; - /* Do nothing */ - ASSERT(FALSE); - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return Status; + /* Do nothing */ + ASSERT(FALSE); + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return Status; } static NTSTATUS NTAPI -i8042DeviceControl(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042DeviceControl( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PFDO_DEVICE_EXTENSION DeviceExtension; - NTSTATUS Status; + PFDO_DEVICE_EXTENSION DeviceExtension; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042DeviceControl(%p %p)\n", DeviceObject, Irp); - DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + TRACE_(I8042PRT, "i8042DeviceControl(%p %p)\n", DeviceObject, Irp); + DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - switch (DeviceExtension->Type) - { - case Keyboard: - return i8042KbdDeviceControl(DeviceObject, Irp); - break; - default: - return IrpStub(DeviceObject, Irp); - } + switch (DeviceExtension->Type) + { + case Keyboard: + return i8042KbdDeviceControl(DeviceObject, Irp); + break; + default: + return IrpStub(DeviceObject, Irp); + } - return Status; + return Status; } static NTSTATUS NTAPI -i8042InternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042InternalDeviceControl( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PFDO_DEVICE_EXTENSION DeviceExtension; - ULONG ControlCode; - NTSTATUS Status; + PFDO_DEVICE_EXTENSION DeviceExtension; + ULONG ControlCode; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042InternalDeviceControl(%p %p)\n", DeviceObject, Irp); - DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + TRACE_(I8042PRT, "i8042InternalDeviceControl(%p %p)\n", DeviceObject, Irp); + DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - switch (DeviceExtension->Type) - { - case Unknown: - { - ControlCode = IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode; - switch (ControlCode) - { - case IOCTL_INTERNAL_KEYBOARD_CONNECT: - Status = i8042KbdInternalDeviceControl(DeviceObject, Irp); - break; - case IOCTL_INTERNAL_MOUSE_CONNECT: - Status = i8042MouInternalDeviceControl(DeviceObject, Irp); - break; - default: - ERR_(I8042PRT, "Unknown IO control code 0x%lx\n", ControlCode); - ASSERT(FALSE); - Status = STATUS_INVALID_DEVICE_REQUEST; - break; - } - break; - } - case Keyboard: - Status = i8042KbdInternalDeviceControl(DeviceObject, Irp); - break; - case Mouse: - Status = i8042MouInternalDeviceControl(DeviceObject, Irp); - break; - default: - ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type); - ASSERT(FALSE); - Status = STATUS_INTERNAL_ERROR; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - break; - } + switch (DeviceExtension->Type) + { + case Unknown: + { + ControlCode = IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode; + switch (ControlCode) + { + case IOCTL_INTERNAL_KEYBOARD_CONNECT: + Status = i8042KbdInternalDeviceControl(DeviceObject, Irp); + break; + case IOCTL_INTERNAL_MOUSE_CONNECT: + Status = i8042MouInternalDeviceControl(DeviceObject, Irp); + break; + default: + ERR_(I8042PRT, "Unknown IO control code 0x%lx\n", ControlCode); + ASSERT(FALSE); + Status = STATUS_INVALID_DEVICE_REQUEST; + break; + } + break; + } + case Keyboard: + Status = i8042KbdInternalDeviceControl(DeviceObject, Irp); + break; + case Mouse: + Status = i8042MouInternalDeviceControl(DeviceObject, Irp); + break; + default: + ERR_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type); + ASSERT(FALSE); + Status = STATUS_INTERNAL_ERROR; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + break; + } - return Status; + return Status; } NTSTATUS NTAPI -DriverEntry(IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath) +DriverEntry( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath) { - PI8042_DRIVER_EXTENSION DriverExtension; - ULONG i; - NTSTATUS Status; + PI8042_DRIVER_EXTENSION DriverExtension; + ULONG i; + NTSTATUS Status; - /* ROS Hack: ideally, we shouldn't have to initialize debug level this way, - but since the only way is to change it via KDBG, it's better to leave - it here too. */ + /* ROS Hack: ideally, we shouldn't have to initialize debug level this way, + but since the only way is to change it via KDBG, it's better to leave + it here too. */ #if 0 - DbgSetDebugFilterState( - DPFLTR_I8042PRT_ID, - (1 << DPFLTR_ERROR_LEVEL) | (1 << DPFLTR_WARNING_LEVEL) | - (1 << DPFLTR_TRACE_LEVEL) /*| (1 << DPFLTR_INFO_LEVEL)*/ | DPFLTR_MASK, - TRUE); + DbgSetDebugFilterState( + DPFLTR_I8042PRT_ID, + (1 << DPFLTR_ERROR_LEVEL) | (1 << DPFLTR_WARNING_LEVEL) | + (1 << DPFLTR_TRACE_LEVEL) /*| (1 << DPFLTR_INFO_LEVEL)*/ | DPFLTR_MASK, + TRUE); #endif - Status = IoAllocateDriverObjectExtension( - DriverObject, - DriverObject, - sizeof(I8042_DRIVER_EXTENSION), - (PVOID*)&DriverExtension); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status); - return Status; - } - RtlZeroMemory(DriverExtension, sizeof(I8042_DRIVER_EXTENSION)); - KeInitializeSpinLock(&DriverExtension->Port.SpinLock); - InitializeListHead(&DriverExtension->DeviceListHead); - KeInitializeSpinLock(&DriverExtension->DeviceListLock); + Status = IoAllocateDriverObjectExtension( + DriverObject, + DriverObject, + sizeof(I8042_DRIVER_EXTENSION), + (PVOID*)&DriverExtension); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoAllocateDriverObjectExtension() failed with status 0x%08lx\n", Status); + return Status; + } + RtlZeroMemory(DriverExtension, sizeof(I8042_DRIVER_EXTENSION)); + KeInitializeSpinLock(&DriverExtension->Port.SpinLock); + InitializeListHead(&DriverExtension->DeviceListHead); + KeInitializeSpinLock(&DriverExtension->DeviceListLock); - Status = DuplicateUnicodeString( - RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, - RegistryPath, - &DriverExtension->RegistryPath); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status); - return Status; - } + Status = DuplicateUnicodeString( + RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, + RegistryPath, + &DriverExtension->RegistryPath); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "DuplicateUnicodeString() failed with status 0x%08lx\n", Status); + return Status; + } - Status = ReadRegistryEntries(RegistryPath, &DriverExtension->Port.Settings); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "ReadRegistryEntries() failed with status 0x%08lx\n", Status); - return Status; - } + Status = ReadRegistryEntries(RegistryPath, &DriverExtension->Port.Settings); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "ReadRegistryEntries() failed with status 0x%08lx\n", Status); + return Status; + } - DriverObject->DriverExtension->AddDevice = i8042AddDevice; - DriverObject->DriverStartIo = i8042StartIo; + DriverObject->DriverExtension->AddDevice = i8042AddDevice; + DriverObject->DriverStartIo = i8042StartIo; - for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) - DriverObject->MajorFunction[i] = IrpStub; + for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) + DriverObject->MajorFunction[i] = IrpStub; - DriverObject->MajorFunction[IRP_MJ_CREATE] = i8042Create; - DriverObject->MajorFunction[IRP_MJ_CLEANUP] = i8042Cleanup; - DriverObject->MajorFunction[IRP_MJ_CLOSE] = i8042Close; - DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = i8042DeviceControl; - DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = i8042InternalDeviceControl; - DriverObject->MajorFunction[IRP_MJ_PNP] = i8042Pnp; + DriverObject->MajorFunction[IRP_MJ_CREATE] = i8042Create; + DriverObject->MajorFunction[IRP_MJ_CLEANUP] = i8042Cleanup; + DriverObject->MajorFunction[IRP_MJ_CLOSE] = i8042Close; + DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = i8042DeviceControl; + DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = i8042InternalDeviceControl; + DriverObject->MajorFunction[IRP_MJ_PNP] = i8042Pnp; - if (IsFirstStageSetup()) - return i8042AddLegacyKeyboard(DriverObject, RegistryPath); + if (IsFirstStageSetup()) + return i8042AddLegacyKeyboard(DriverObject, RegistryPath); - return STATUS_SUCCESS; + return STATUS_SUCCESS; } diff --git a/reactos/drivers/input/i8042prt/i8042prt.h b/reactos/drivers/input/i8042prt/i8042prt.h index 28844ef0207..58201803e24 100644 --- a/reactos/drivers/input/i8042prt/i8042prt.h +++ b/reactos/drivers/input/i8042prt/i8042prt.h @@ -11,56 +11,56 @@ #include /*----------------------------------------------------- -* Structures -* --------------------------------------------------*/ + * Structures + * --------------------------------------------------*/ #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24)) #define I8042PRT_TAG TAG('8', '0', '4', '2') typedef enum { - dsStopped, - dsStarted, - dsPaused, - dsRemoved, - dsSurpriseRemoved + dsStopped, + dsStarted, + dsPaused, + dsRemoved, + dsSurpriseRemoved } DEVICE_STATE; typedef struct _I8042_SETTINGS { - /* Registry settings */ - ULONG KeyboardDataQueueSize; /* done */ - UNICODE_STRING KeyboardDeviceBaseName; - ULONG MouseDataQueueSize; /* done */ - ULONG MouseResolution; - ULONG MouseSynchIn100ns; - ULONG NumberOfButtons; - UNICODE_STRING PointerDeviceBaseName; - ULONG PollStatusIterations; /* done */ - ULONG OverrideKeyboardType; - ULONG OverrideKeyboardSubtype; - ULONG PollingIterations; /* done */ - ULONG PollingIterationsMaximum; - ULONG ResendIterations; /* done */ - ULONG SampleRate; - ULONG CrashOnCtrlScroll; /* done */ + /* Registry settings */ + ULONG KeyboardDataQueueSize; /* done */ + UNICODE_STRING KeyboardDeviceBaseName; + ULONG MouseDataQueueSize; /* done */ + ULONG MouseResolution; + ULONG MouseSynchIn100ns; + ULONG NumberOfButtons; + UNICODE_STRING PointerDeviceBaseName; + ULONG PollStatusIterations; /* done */ + ULONG OverrideKeyboardType; + ULONG OverrideKeyboardSubtype; + ULONG PollingIterations; /* done */ + ULONG PollingIterationsMaximum; + ULONG ResendIterations; /* done */ + ULONG SampleRate; + ULONG CrashOnCtrlScroll; /* done */ } I8042_SETTINGS, *PI8042_SETTINGS; typedef enum _MOUSE_TIMEOUT_STATE { - NoChange, - TimeoutStart, - TimeoutCancel + NoChange, + TimeoutStart, + TimeoutCancel } MOUSE_TIMEOUT_STATE, *PMOUSE_TIMEOUT_STATE; typedef struct _INTERRUPT_DATA { - PKINTERRUPT Object; - ULONG Vector; - KIRQL Dirql; - KINTERRUPT_MODE InterruptMode; - BOOLEAN ShareInterrupt; - KAFFINITY Affinity; + PKINTERRUPT Object; + ULONG Vector; + KIRQL Dirql; + KINTERRUPT_MODE InterruptMode; + BOOLEAN ShareInterrupt; + KAFFINITY Affinity; } INTERRUPT_DATA, *PINTERRUPT_DATA; #define WHEEL_DELTA 120 @@ -82,135 +82,135 @@ typedef struct _I8042_MOUSE_EXTENSION *PI8042_MOUSE_EXTENSION; typedef struct _PORT_DEVICE_EXTENSION { - PUCHAR DataPort; /* Usually 0x60 */ - PUCHAR ControlPort; /* Usually 0x64 */ - I8042_SETTINGS Settings; - ULONG Flags; + PUCHAR DataPort; /* Usually 0x60 */ + PUCHAR ControlPort; /* Usually 0x64 */ + I8042_SETTINGS Settings; + ULONG Flags; - PI8042_KEYBOARD_EXTENSION KeyboardExtension; - INTERRUPT_DATA KeyboardInterrupt; - PI8042_MOUSE_EXTENSION MouseExtension; - INTERRUPT_DATA MouseInterrupt; - PKINTERRUPT HighestDIRQLInterrupt; - KSPIN_LOCK SpinLock; - KIRQL HighestDirql; + PI8042_KEYBOARD_EXTENSION KeyboardExtension; + INTERRUPT_DATA KeyboardInterrupt; + PI8042_MOUSE_EXTENSION MouseExtension; + INTERRUPT_DATA MouseInterrupt; + PKINTERRUPT HighestDIRQLInterrupt; + KSPIN_LOCK SpinLock; + KIRQL HighestDirql; - OUTPUT_PACKET Packet; - ULONG PacketResends; - BOOLEAN PacketComplete; - NTSTATUS PacketResult; - UCHAR PacketBuffer[16]; - UCHAR PacketPort; + OUTPUT_PACKET Packet; + ULONG PacketResends; + BOOLEAN PacketComplete; + NTSTATUS PacketResult; + UCHAR PacketBuffer[16]; + UCHAR PacketPort; - PIRP CurrentIrp; - PDEVICE_OBJECT CurrentIrpDevice; + PIRP CurrentIrp; + PDEVICE_OBJECT CurrentIrpDevice; } PORT_DEVICE_EXTENSION, *PPORT_DEVICE_EXTENSION; typedef struct _I8042_DRIVER_EXTENSION { - UNICODE_STRING RegistryPath; + UNICODE_STRING RegistryPath; - PORT_DEVICE_EXTENSION Port; - LIST_ENTRY DeviceListHead; - KSPIN_LOCK DeviceListLock; + PORT_DEVICE_EXTENSION Port; + LIST_ENTRY DeviceListHead; + KSPIN_LOCK DeviceListLock; } I8042_DRIVER_EXTENSION, *PI8042_DRIVER_EXTENSION; typedef enum _I8042_DEVICE_TYPE { - Unknown, - Keyboard, - Mouse, - PhysicalDeviceObject + Unknown, + Keyboard, + Mouse, + PhysicalDeviceObject } I8042_DEVICE_TYPE, *PI8042_DEVICE_TYPE; typedef struct _FDO_DEVICE_EXTENSION { - I8042_DEVICE_TYPE Type; - // Linkage in I8042_DRIVER_EXTENSION.DeviceListHead - LIST_ENTRY ListEntry; - // Associated device object (FDO) - PDEVICE_OBJECT Fdo; - // Associated device object (PDO) - PDEVICE_OBJECT Pdo; - // Lower device object - PDEVICE_OBJECT LowerDevice; - // Current state of the driver - DEVICE_STATE PnpState; + I8042_DEVICE_TYPE Type; + // Linkage in I8042_DRIVER_EXTENSION.DeviceListHead + LIST_ENTRY ListEntry; + // Associated device object (FDO) + PDEVICE_OBJECT Fdo; + // Associated device object (PDO) + PDEVICE_OBJECT Pdo; + // Lower device object + PDEVICE_OBJECT LowerDevice; + // Current state of the driver + DEVICE_STATE PnpState; - PPORT_DEVICE_EXTENSION PortDeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION; typedef struct _I8042_KEYBOARD_EXTENSION { - FDO_DEVICE_EXTENSION Common; - CONNECT_DATA KeyboardData; - INTERNAL_I8042_HOOK_KEYBOARD KeyboardHook; /* FIXME: IsrWritePort ignored */ - KDPC DpcKeyboard; + FDO_DEVICE_EXTENSION Common; + CONNECT_DATA KeyboardData; + INTERNAL_I8042_HOOK_KEYBOARD KeyboardHook; /* FIXME: IsrWritePort ignored */ + KDPC DpcKeyboard; - KEYBOARD_INDICATOR_PARAMETERS KeyboardIndicators; + KEYBOARD_INDICATOR_PARAMETERS KeyboardIndicators; - KEYBOARD_SCAN_STATE KeyboardScanState; - BOOLEAN KeyComplete; - PKEYBOARD_INPUT_DATA KeyboardBuffer; - ULONG KeysInBuffer; + KEYBOARD_SCAN_STATE KeyboardScanState; + BOOLEAN KeyComplete; + PKEYBOARD_INPUT_DATA KeyboardBuffer; + ULONG KeysInBuffer; - /* Power keys items */ - ULONG ReportedCaps; - ULONG NewCaps; - ULONG LastPowerKey; - UNICODE_STRING PowerInterfaceName; - PIO_WORKITEM PowerWorkItem; - PIRP PowerIrp; + /* Power keys items */ + ULONG ReportedCaps; + ULONG NewCaps; + ULONG LastPowerKey; + UNICODE_STRING PowerInterfaceName; + PIO_WORKITEM PowerWorkItem; + PIRP PowerIrp; - /* Debug items */ - ULONG ComboPosition; - PIO_WORKITEM DebugWorkItem; - BOOLEAN TabPressed; + /* Debug items */ + ULONG ComboPosition; + PIO_WORKITEM DebugWorkItem; + BOOLEAN TabPressed; } I8042_KEYBOARD_EXTENSION; typedef enum _I8042_MOUSE_TYPE { - GenericPS2, - Intellimouse, - IntellimouseExplorer, - Ps2pp + GenericPS2, + Intellimouse, + IntellimouseExplorer, + Ps2pp } I8042_MOUSE_TYPE, *PI8042_MOUSE_TYPE; typedef struct _I8042_MOUSE_EXTENSION { - FDO_DEVICE_EXTENSION Common; - CONNECT_DATA MouseData; - INTERNAL_I8042_HOOK_MOUSE MouseHook; - KDPC DpcMouse; + FDO_DEVICE_EXTENSION Common; + CONNECT_DATA MouseData; + INTERNAL_I8042_HOOK_MOUSE MouseHook; + KDPC DpcMouse; - MOUSE_ATTRIBUTES MouseAttributes; + MOUSE_ATTRIBUTES MouseAttributes; - MOUSE_STATE MouseState; - BOOLEAN MouseComplete; - MOUSE_RESET_SUBSTATE MouseResetState; - PMOUSE_INPUT_DATA MouseBuffer; - ULONG MouseInBuffer; - USHORT MouseButtonState; - ULARGE_INTEGER MousePacketStartTime; + MOUSE_STATE MouseState; + BOOLEAN MouseComplete; + MOUSE_RESET_SUBSTATE MouseResetState; + PMOUSE_INPUT_DATA MouseBuffer; + ULONG MouseInBuffer; + USHORT MouseButtonState; + ULARGE_INTEGER MousePacketStartTime; - KTIMER TimerMouseTimeout; - KDPC DpcMouseTimeout; - MOUSE_TIMEOUT_STATE MouseTimeoutState; - BOOLEAN MouseTimeoutActive; + KTIMER TimerMouseTimeout; + KDPC DpcMouseTimeout; + MOUSE_TIMEOUT_STATE MouseTimeoutState; + BOOLEAN MouseTimeoutActive; - UCHAR MouseLogiBuffer[3]; - I8042_MOUSE_TYPE MouseType; + UCHAR MouseLogiBuffer[3]; + I8042_MOUSE_TYPE MouseType; } I8042_MOUSE_EXTENSION; typedef struct _I8042_HOOK_WORKITEM { - PIO_WORKITEM WorkItem; - PIRP Irp; + PIO_WORKITEM WorkItem; + PIRP Irp; } I8042_HOOK_WORKITEM, *PI8042_HOOK_WORKITEM; /*----------------------------------------------------- -* Some defines -* --------------------------------------------------*/ + * Some defines + * --------------------------------------------------*/ #define MAX(a, b) ((a) >= (b) ? (a) : (b)) @@ -219,8 +219,8 @@ typedef struct _I8042_HOOK_WORKITEM #define KEYBOARD_WAKE_CODE 0x63 /*----------------------------------------------------- -* Controller commands -* --------------------------------------------------*/ + * Controller commands + * --------------------------------------------------*/ #define KBD_READ_MODE 0x20 #define KBD_WRITE_MODE 0x60 @@ -230,15 +230,15 @@ typedef struct _I8042_HOOK_WORKITEM #define CTRL_WRITE_MOUSE 0xD4 /*----------------------------------------------------- -* Keyboard commands -* --------------------------------------------------*/ + * Keyboard commands + * --------------------------------------------------*/ #define KBD_CMD_SET_LEDS 0xED #define KBD_CMD_GET_ID 0xF2 /*----------------------------------------------------- -* Keyboard responses -* --------------------------------------------------*/ + * Keyboard responses + * --------------------------------------------------*/ #define KBD_SELF_TEST_OK 0x55 #define KBD_ACK 0xFA @@ -246,8 +246,8 @@ typedef struct _I8042_HOOK_WORKITEM #define KBD_RESEND 0xFE /*----------------------------------------------------- -* Controller status register bits -* --------------------------------------------------*/ + * Controller status register bits + * --------------------------------------------------*/ #define KBD_OBF 0x01 #define KBD_IBF 0x02 @@ -255,8 +255,8 @@ typedef struct _I8042_HOOK_WORKITEM #define KBD_PERR 0x80 /*----------------------------------------------------- -* Controller command byte bits -* --------------------------------------------------*/ + * Controller command byte bits + * --------------------------------------------------*/ #define CCB_KBD_INT_ENAB 0x01 #define CCB_MOUSE_INT_ENAB 0x02 @@ -266,31 +266,31 @@ typedef struct _I8042_HOOK_WORKITEM #define CCB_TRANSLATE 0x40 /*----------------------------------------------------- -* LED bits -* --------------------------------------------------*/ + * LED bits + * --------------------------------------------------*/ #define KBD_LED_SCROLL 0x01 #define KBD_LED_NUM 0x02 #define KBD_LED_CAPS 0x04 /*----------------------------------------------------- -* Mouse commands -* --------------------------------------------------*/ + * Mouse commands + * --------------------------------------------------*/ #define MOU_ENAB 0xF4 #define MOU_CMD_RESET 0xFF /*----------------------------------------------------- -* Mouse responses -* --------------------------------------------------*/ + * Mouse responses + * --------------------------------------------------*/ #define MOUSE_ACK 0xFA #define MOUSE_ERROR 0xFC #define MOUSE_NACK 0xFE /*----------------------------------------------------- -* Prototypes -* --------------------------------------------------*/ + * Prototypes + * --------------------------------------------------*/ /* createclose.c */ @@ -305,9 +305,10 @@ DRIVER_DISPATCH i8042Close; /* keyboard.c */ NTSTATUS NTAPI -i8042SynchWritePortKbd(IN PVOID Context, - IN UCHAR Value, - IN BOOLEAN WaitForAck); +i8042SynchWritePortKbd( + IN PVOID Context, + IN UCHAR Value, + IN BOOLEAN WaitForAck); DRIVER_STARTIO i8042KbdStartIo; @@ -322,15 +323,17 @@ KSERVICE_ROUTINE i8042KbdInterruptService; DRIVER_ADD_DEVICE i8042AddDevice; BOOLEAN -i8042PacketIsr(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR Output); +i8042PacketIsr( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR Output); NTSTATUS -i8042StartPacket(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, - IN PUCHAR Bytes, - IN ULONG ByteCount, - IN PIRP Irp); +i8042StartPacket( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, + IN PUCHAR Bytes, + IN ULONG ByteCount, + IN PIRP Irp); /* misc.c */ @@ -339,22 +342,26 @@ DRIVER_DISPATCH ForwardIrpAndForget; DRIVER_DISPATCH ForwardIrpAndWait; NTSTATUS -DuplicateUnicodeString(IN ULONG Flags, - IN PCUNICODE_STRING SourceString, - OUT PUNICODE_STRING DestinationString); +DuplicateUnicodeString( + IN ULONG Flags, + IN PCUNICODE_STRING SourceString, + OUT PUNICODE_STRING DestinationString); /* mouse.c */ VOID -i8042MouHandle(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN UCHAR Output); +i8042MouHandle( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN UCHAR Output); VOID -i8042MouHandleButtons(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN USHORT Mask); +i8042MouHandleButtons( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN USHORT Mask); NTSTATUS -i8042MouInitialize(IN PI8042_MOUSE_EXTENSION DeviceExtension); +i8042MouInitialize( + IN PI8042_MOUSE_EXTENSION DeviceExtension); DRIVER_DISPATCH i8042MouInternalDeviceControl; @@ -363,73 +370,86 @@ KSERVICE_ROUTINE i8042MouInterruptService; /* pnp.c */ BOOLEAN -i8042ChangeMode(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR FlagsToDisable, - IN UCHAR FlagsToEnable); +i8042ChangeMode( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR FlagsToDisable, + IN UCHAR FlagsToEnable); DRIVER_DISPATCH i8042Pnp; /* ps2pp.c */ VOID -i8042MouHandlePs2pp(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN UCHAR Input); +i8042MouHandlePs2pp( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN UCHAR Input); /* readwrite.c */ VOID -i8042Flush(IN PPORT_DEVICE_EXTENSION DeviceExtension); +i8042Flush( + IN PPORT_DEVICE_EXTENSION DeviceExtension); BOOLEAN -i8042IsrWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR Value, - IN UCHAR SelectCmd OPTIONAL); +i8042IsrWritePort( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR Value, + IN UCHAR SelectCmd OPTIONAL); NTSTATUS -i8042ReadData(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR StatusFlags, - OUT PUCHAR Data); +i8042ReadData( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR StatusFlags, + OUT PUCHAR Data); #define i8042ReadKeyboardData(DeviceExtension, Data) \ - i8042ReadData(DeviceExtension, KBD_OBF, Data) + i8042ReadData(DeviceExtension, KBD_OBF, Data) #define i8042ReadMouseData(DeviceExtension, Data) \ - i8042ReadData(DeviceExtension, MOU_OBF, Data) + i8042ReadData(DeviceExtension, MOU_OBF, Data) NTSTATUS -i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, - OUT PUCHAR Data); +i8042ReadDataWait( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + OUT PUCHAR Data); NTSTATUS -i8042ReadStatus(IN PPORT_DEVICE_EXTENSION DeviceExtension, - OUT PUCHAR Status); +i8042ReadStatus( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + OUT PUCHAR Status); NTSTATUS NTAPI -i8042SynchReadPort(IN PVOID Context, - OUT PUCHAR Value, - IN BOOLEAN WaitForAck); +i8042SynchReadPort( + IN PVOID Context, + OUT PUCHAR Value, + IN BOOLEAN WaitForAck); NTSTATUS NTAPI -i8042SynchWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR Port, - IN UCHAR Value, - IN BOOLEAN WaitForAck); +i8042SynchWritePort( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR Port, + IN UCHAR Value, + IN BOOLEAN WaitForAck); BOOLEAN -i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN PUCHAR addr, - IN UCHAR data); +i8042Write( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN PUCHAR addr, + IN UCHAR data); /* registry.c */ NTSTATUS -ReadRegistryEntries(IN PUNICODE_STRING RegistryPath, - OUT PI8042_SETTINGS Settings); +ReadRegistryEntries( + IN PUNICODE_STRING RegistryPath, + OUT PI8042_SETTINGS Settings); /* setup.c */ BOOLEAN -IsFirstStageSetup(VOID); +IsFirstStageSetup( + VOID); NTSTATUS -i8042AddLegacyKeyboard(IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath); +i8042AddLegacyKeyboard( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath); #endif // _I8042PRT_H_ diff --git a/reactos/drivers/input/i8042prt/keyboard.c b/reactos/drivers/input/i8042prt/keyboard.c index 0523e85c946..0b1c3d13e5d 100644 --- a/reactos/drivers/input/i8042prt/keyboard.c +++ b/reactos/drivers/input/i8042prt/keyboard.c @@ -20,14 +20,14 @@ static IO_WORKITEM_ROUTINE i8042PowerWorkItem; /* This structure starts with the same layout as KEYBOARD_INDICATOR_TRANSLATION */ typedef struct _LOCAL_KEYBOARD_INDICATOR_TRANSLATION { - USHORT NumberOfIndicatorKeys; - INDICATOR_LIST IndicatorList[3]; + USHORT NumberOfIndicatorKeys; + INDICATOR_LIST IndicatorList[3]; } LOCAL_KEYBOARD_INDICATOR_TRANSLATION, *PLOCAL_KEYBOARD_INDICATOR_TRANSLATION; static LOCAL_KEYBOARD_INDICATOR_TRANSLATION IndicatorTranslation = { 3, { - {0x3A, KEYBOARD_CAPS_LOCK_ON}, - {0x45, KEYBOARD_NUM_LOCK_ON}, - {0x46, KEYBOARD_SCROLL_LOCK_ON}}}; + {0x3A, KEYBOARD_CAPS_LOCK_ON}, + {0x45, KEYBOARD_NUM_LOCK_ON}, + {0x46, KEYBOARD_SCROLL_LOCK_ON}}}; /* FUNCTIONS *****************************************************************/ @@ -35,814 +35,827 @@ static LOCAL_KEYBOARD_INDICATOR_TRANSLATION IndicatorTranslation = { 3, { #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24)) static VOID NTAPI -i8042DebugWorkItem(IN PDEVICE_OBJECT DeviceObject, - IN PVOID Key) +i8042DebugWorkItem( + IN PDEVICE_OBJECT DeviceObject, + IN PVOID Key) { - INFO_(I8042PRT, "Debug key: p\n", Key); + INFO_(I8042PRT, "Debug key: p\n", Key); - if (!Key) - return; + if (!Key) + return; - /* We hope kernel would understand this. If - * that's not the case, nothing would happen. - */ - KdSystemDebugControl(TAG('R', 'o', 's', ' '), Key, 0, NULL, 0, NULL, KernelMode); + /* We hope kernel would understand this. If + * that's not the case, nothing would happen. + */ + KdSystemDebugControl(TAG('R', 'o', 's', ' '), Key, 0, NULL, 0, NULL, KernelMode); } /* -* These functions are callbacks for filter driver custom interrupt -* service routines. -*/ + * These functions are callbacks for filter driver custom interrupt + * service routines. + */ /*static VOID NTAPI i8042KbdIsrWritePort( -IN PVOID Context, -IN UCHAR Value) + IN PVOID Context, + IN UCHAR Value) { -PI8042_KEYBOARD_EXTENSION DeviceExtension; + PI8042_KEYBOARD_EXTENSION DeviceExtension; -DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; -if (DeviceExtension->KeyboardHook.IsrWritePort) -{ -DeviceExtension->KeyboardHook.IsrWritePort( -DeviceExtension->KeyboardHook.CallContext, -Value); -} -else -i8042IsrWritePort(Context, Value, 0); + if (DeviceExtension->KeyboardHook.IsrWritePort) + { + DeviceExtension->KeyboardHook.IsrWritePort( + DeviceExtension->KeyboardHook.CallContext, + Value); + } + else + i8042IsrWritePort(Context, Value, 0); }*/ static VOID NTAPI -i8042KbdQueuePacket(IN PVOID Context) +i8042KbdQueuePacket( + IN PVOID Context) { - PI8042_KEYBOARD_EXTENSION DeviceExtension; + PI8042_KEYBOARD_EXTENSION DeviceExtension; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; - DeviceExtension->KeyComplete = TRUE; - DeviceExtension->KeysInBuffer++; - if (DeviceExtension->KeysInBuffer > DeviceExtension->Common.PortDeviceExtension->Settings.KeyboardDataQueueSize) - { - WARN_(I8042PRT, "Keyboard buffer overflow\n"); - DeviceExtension->KeysInBuffer--; - } + DeviceExtension->KeyComplete = TRUE; + DeviceExtension->KeysInBuffer++; + if (DeviceExtension->KeysInBuffer > DeviceExtension->Common.PortDeviceExtension->Settings.KeyboardDataQueueSize) + { + WARN_(I8042PRT, "Keyboard buffer overflow\n"); + DeviceExtension->KeysInBuffer--; + } - TRACE_(I8042PRT, "Irq completes key\n"); - KeInsertQueueDpc(&DeviceExtension->DpcKeyboard, NULL, NULL); + TRACE_(I8042PRT, "Irq completes key\n"); + KeInsertQueueDpc(&DeviceExtension->DpcKeyboard, NULL, NULL); } /* -* These functions are callbacks for filter driver custom -* initialization routines. -*/ + * These functions are callbacks for filter driver custom + * initialization routines. + */ NTSTATUS NTAPI -i8042SynchWritePortKbd(IN PVOID Context, - IN UCHAR Value, - IN BOOLEAN WaitForAck) +i8042SynchWritePortKbd( + IN PVOID Context, + IN UCHAR Value, + IN BOOLEAN WaitForAck) { - return i8042SynchWritePort((PPORT_DEVICE_EXTENSION)Context, - 0, - Value, - WaitForAck); + return i8042SynchWritePort( + (PPORT_DEVICE_EXTENSION)Context, + 0, + Value, + WaitForAck); } /* -* Process the keyboard internal device requests -*/ + * Process the keyboard internal device requests + */ VOID NTAPI -i8042KbdStartIo(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042KbdStartIo( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PIO_STACK_LOCATION Stack; - PI8042_KEYBOARD_EXTENSION DeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; + PIO_STACK_LOCATION Stack; + PI8042_KEYBOARD_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; - Stack = IoGetCurrentIrpStackLocation(Irp); - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + Stack = IoGetCurrentIrpStackLocation(Irp); + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension; + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - switch (Stack->Parameters.DeviceIoControl.IoControlCode) - { - case IOCTL_KEYBOARD_SET_INDICATORS: - { - TRACE_(I8042PRT, "IOCTL_KEYBOARD_SET_INDICATORS\n"); - INFO_(I8042PRT, "Leds: {%s%s%s }\n", - DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_CAPS_LOCK_ON ? " CAPSLOCK" : "", - DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_NUM_LOCK_ON ? " NUMLOCK" : "", - DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_SCROLL_LOCK_ON ? " SCROLLLOCK" : ""); + switch (Stack->Parameters.DeviceIoControl.IoControlCode) + { + case IOCTL_KEYBOARD_SET_INDICATORS: + { + TRACE_(I8042PRT, "IOCTL_KEYBOARD_SET_INDICATORS\n"); + INFO_(I8042PRT, "Leds: {%s%s%s }\n", + DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_CAPS_LOCK_ON ? " CAPSLOCK" : "", + DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_NUM_LOCK_ON ? " NUMLOCK" : "", + DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_SCROLL_LOCK_ON ? " SCROLLLOCK" : ""); - PortDeviceExtension->PacketBuffer[0] = KBD_CMD_SET_LEDS; - PortDeviceExtension->PacketBuffer[1] = 0; - if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_CAPS_LOCK_ON) - PortDeviceExtension->PacketBuffer[1] |= KBD_LED_CAPS; + PortDeviceExtension->PacketBuffer[0] = KBD_CMD_SET_LEDS; + PortDeviceExtension->PacketBuffer[1] = 0; + if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_CAPS_LOCK_ON) + PortDeviceExtension->PacketBuffer[1] |= KBD_LED_CAPS; - if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_NUM_LOCK_ON) - PortDeviceExtension->PacketBuffer[1] |= KBD_LED_NUM; + if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_NUM_LOCK_ON) + PortDeviceExtension->PacketBuffer[1] |= KBD_LED_NUM; - if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_SCROLL_LOCK_ON) - PortDeviceExtension->PacketBuffer[1] |= KBD_LED_SCROLL; + if (DeviceExtension->KeyboardIndicators.LedFlags & KEYBOARD_SCROLL_LOCK_ON) + PortDeviceExtension->PacketBuffer[1] |= KBD_LED_SCROLL; - i8042StartPacket( - PortDeviceExtension, - &DeviceExtension->Common, - PortDeviceExtension->PacketBuffer, - 2, - Irp); - break; - } - default: - { - ERR_(I8042PRT, "Unknown ioctl code 0x%lx\n", - Stack->Parameters.DeviceIoControl.IoControlCode); - ASSERT(FALSE); - } - } + i8042StartPacket( + PortDeviceExtension, + &DeviceExtension->Common, + PortDeviceExtension->PacketBuffer, + 2, + Irp); + break; + } + default: + { + ERR_(I8042PRT, "Unknown ioctl code 0x%lx\n", + Stack->Parameters.DeviceIoControl.IoControlCode); + ASSERT(FALSE); + } + } } static VOID -i8042PacketDpc(IN PPORT_DEVICE_EXTENSION DeviceExtension) +i8042PacketDpc( + IN PPORT_DEVICE_EXTENSION DeviceExtension) { - BOOLEAN FinishIrp = FALSE; - KIRQL Irql; - NTSTATUS Result = STATUS_INTERNAL_ERROR; /* Shouldn't happen */ + BOOLEAN FinishIrp = FALSE; + KIRQL Irql; + NTSTATUS Result = STATUS_INTERNAL_ERROR; /* Shouldn't happen */ - /* If the interrupt happens before this is setup, the key - * was already in the buffer. Too bad! */ - if (!DeviceExtension->HighestDIRQLInterrupt) - return; + /* If the interrupt happens before this is setup, the key + * was already in the buffer. Too bad! */ + if (!DeviceExtension->HighestDIRQLInterrupt) + return; - Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt); + Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt); - if (DeviceExtension->Packet.State == Idle - && DeviceExtension->PacketComplete) - { - FinishIrp = TRUE; - Result = DeviceExtension->PacketResult; - DeviceExtension->PacketComplete = FALSE; - } + if (DeviceExtension->Packet.State == Idle + && DeviceExtension->PacketComplete) + { + FinishIrp = TRUE; + Result = DeviceExtension->PacketResult; + DeviceExtension->PacketComplete = FALSE; + } - KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql); + KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql); - if (!FinishIrp) - return; + if (!FinishIrp) + return; - if (DeviceExtension->CurrentIrp) - { - DeviceExtension->CurrentIrp->IoStatus.Status = Result; - IoCompleteRequest(DeviceExtension->CurrentIrp, IO_NO_INCREMENT); - IoStartNextPacket(DeviceExtension->CurrentIrpDevice, FALSE); - DeviceExtension->CurrentIrp = NULL; - DeviceExtension->CurrentIrpDevice = NULL; - } + if (DeviceExtension->CurrentIrp) + { + DeviceExtension->CurrentIrp->IoStatus.Status = Result; + IoCompleteRequest(DeviceExtension->CurrentIrp, IO_NO_INCREMENT); + IoStartNextPacket(DeviceExtension->CurrentIrpDevice, FALSE); + DeviceExtension->CurrentIrp = NULL; + DeviceExtension->CurrentIrpDevice = NULL; + } } static VOID NTAPI -i8042PowerWorkItem(IN PDEVICE_OBJECT DeviceObject, - IN PVOID Context) +i8042PowerWorkItem( + IN PDEVICE_OBJECT DeviceObject, + IN PVOID Context) { - PI8042_KEYBOARD_EXTENSION DeviceExtension; - PIRP WaitingIrp; - NTSTATUS Status; + PI8042_KEYBOARD_EXTENSION DeviceExtension; + PIRP WaitingIrp; + NTSTATUS Status; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; - /* See http://blogs.msdn.com/doronh/archive/2006/09/08/746961.aspx */ + /* See http://blogs.msdn.com/doronh/archive/2006/09/08/746961.aspx */ - /* Register GUID_DEVICE_SYS_BUTTON interface and report capability */ - if (DeviceExtension->NewCaps != DeviceExtension->ReportedCaps) - { - WaitingIrp = InterlockedExchangePointer(&DeviceExtension->PowerIrp, NULL); - if (WaitingIrp) - { - /* Cancel the current power irp, as capability changed */ - WaitingIrp->IoStatus.Status = STATUS_UNSUCCESSFUL; - WaitingIrp->IoStatus.Information = sizeof(ULONG); - IoCompleteRequest(WaitingIrp, IO_NO_INCREMENT); - } + /* Register GUID_DEVICE_SYS_BUTTON interface and report capability */ + if (DeviceExtension->NewCaps != DeviceExtension->ReportedCaps) + { + WaitingIrp = InterlockedExchangePointer(&DeviceExtension->PowerIrp, NULL); + if (WaitingIrp) + { + /* Cancel the current power irp, as capability changed */ + WaitingIrp->IoStatus.Status = STATUS_UNSUCCESSFUL; + WaitingIrp->IoStatus.Information = sizeof(ULONG); + IoCompleteRequest(WaitingIrp, IO_NO_INCREMENT); + } - if (DeviceExtension->PowerInterfaceName.MaximumLength == 0) - { - /* We have never registred this interface ; do it */ - Status = IoRegisterDeviceInterface( - DeviceExtension->Common.Pdo, - &GUID_DEVICE_SYS_BUTTON, - NULL, - &DeviceExtension->PowerInterfaceName); - if (!NT_SUCCESS(Status)) - { - /* We can't do more yet, ignore the keypress... */ - WARN_(I8042PRT, "IoRegisterDeviceInterface(GUID_DEVICE_SYS_BUTTON) failed with status 0x%08lx\n", - Status); - DeviceExtension->PowerInterfaceName.MaximumLength = 0; - return; - } - } - else - { - /* Disable the interface. Once activated again, capabilities would be asked again */ - Status = IoSetDeviceInterfaceState( - &DeviceExtension->PowerInterfaceName, - FALSE); - if (!NT_SUCCESS(Status)) - { - /* Ignore the key press... */ - WARN_(I8042PRT, "Disabling interface %wZ failed with status 0x%08lx\n", - &DeviceExtension->PowerInterfaceName, Status); - return; - } - } - /* Enable the interface. This leads to receving a IOCTL_GET_SYS_BUTTON_CAPS, - * so we can report new capability */ - Status = IoSetDeviceInterfaceState( - &DeviceExtension->PowerInterfaceName, - TRUE); - if (!NT_SUCCESS(Status)) - { - /* Ignore the key press... */ - WARN_(I8042PRT, "Enabling interface %wZ failed with status 0x%08lx\n", - &DeviceExtension->PowerInterfaceName, Status); - return; - } - } + if (DeviceExtension->PowerInterfaceName.MaximumLength == 0) + { + /* We have never registred this interface ; do it */ + Status = IoRegisterDeviceInterface( + DeviceExtension->Common.Pdo, + &GUID_DEVICE_SYS_BUTTON, + NULL, + &DeviceExtension->PowerInterfaceName); + if (!NT_SUCCESS(Status)) + { + /* We can't do more yet, ignore the keypress... */ + WARN_(I8042PRT, "IoRegisterDeviceInterface(GUID_DEVICE_SYS_BUTTON) failed with status 0x%08lx\n", + Status); + DeviceExtension->PowerInterfaceName.MaximumLength = 0; + return; + } + } + else + { + /* Disable the interface. Once activated again, capabilities would be asked again */ + Status = IoSetDeviceInterfaceState( + &DeviceExtension->PowerInterfaceName, + FALSE); + if (!NT_SUCCESS(Status)) + { + /* Ignore the key press... */ + WARN_(I8042PRT, "Disabling interface %wZ failed with status 0x%08lx\n", + &DeviceExtension->PowerInterfaceName, Status); + return; + } + } + /* Enable the interface. This leads to receving a IOCTL_GET_SYS_BUTTON_CAPS, + * so we can report new capability */ + Status = IoSetDeviceInterfaceState( + &DeviceExtension->PowerInterfaceName, + TRUE); + if (!NT_SUCCESS(Status)) + { + /* Ignore the key press... */ + WARN_(I8042PRT, "Enabling interface %wZ failed with status 0x%08lx\n", + &DeviceExtension->PowerInterfaceName, Status); + return; + } + } - /* Directly complete the IOCTL_GET_SYS_BUTTON_EVENT Irp (if any) */ - WaitingIrp = InterlockedExchangePointer(&DeviceExtension->PowerIrp, NULL); - if (WaitingIrp) - { - PULONG pEvent = (PULONG)WaitingIrp->AssociatedIrp.SystemBuffer; + /* Directly complete the IOCTL_GET_SYS_BUTTON_EVENT Irp (if any) */ + WaitingIrp = InterlockedExchangePointer(&DeviceExtension->PowerIrp, NULL); + if (WaitingIrp) + { + PULONG pEvent = (PULONG)WaitingIrp->AssociatedIrp.SystemBuffer; - WaitingIrp->IoStatus.Status = STATUS_SUCCESS; - WaitingIrp->IoStatus.Information = sizeof(ULONG); - *pEvent = InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, 0); - IoCompleteRequest(WaitingIrp, IO_NO_INCREMENT); - } + WaitingIrp->IoStatus.Status = STATUS_SUCCESS; + WaitingIrp->IoStatus.Information = sizeof(ULONG); + *pEvent = InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, 0); + IoCompleteRequest(WaitingIrp, IO_NO_INCREMENT); + } } /* Return TRUE if it was a power key */ static BOOLEAN -HandlePowerKeys(IN PI8042_KEYBOARD_EXTENSION DeviceExtension) +HandlePowerKeys( + IN PI8042_KEYBOARD_EXTENSION DeviceExtension) { - PKEYBOARD_INPUT_DATA InputData; - ULONG KeyPress; + PKEYBOARD_INPUT_DATA InputData; + ULONG KeyPress; - InputData = DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer - 1; - if (!(InputData->Flags & KEY_E0)) - return FALSE; + InputData = DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer - 1; + if (!(InputData->Flags & KEY_E0)) + return FALSE; - if (InputData->Flags & KEY_BREAK) - /* We already took care of the key press */ - return TRUE; + if (InputData->Flags & KEY_BREAK) + /* We already took care of the key press */ + return TRUE; - switch (InputData->MakeCode) - { - case KEYBOARD_POWER_CODE: - KeyPress = SYS_BUTTON_POWER; - break; - case KEYBOARD_SLEEP_CODE: - KeyPress = SYS_BUTTON_SLEEP; - break; - case KEYBOARD_WAKE_CODE: - KeyPress = SYS_BUTTON_WAKE; - break; - default: - return FALSE; - } + switch (InputData->MakeCode) + { + case KEYBOARD_POWER_CODE: + KeyPress = SYS_BUTTON_POWER; + break; + case KEYBOARD_SLEEP_CODE: + KeyPress = SYS_BUTTON_SLEEP; + break; + case KEYBOARD_WAKE_CODE: + KeyPress = SYS_BUTTON_WAKE; + break; + default: + return FALSE; + } - /* Our work can only be done at passive level, so use a workitem */ - DeviceExtension->NewCaps |= KeyPress; - InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, KeyPress); - IoQueueWorkItem( - DeviceExtension->PowerWorkItem, - &i8042PowerWorkItem, - DelayedWorkQueue, - DeviceExtension); - return TRUE; + /* Our work can only be done at passive level, so use a workitem */ + DeviceExtension->NewCaps |= KeyPress; + InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, KeyPress); + IoQueueWorkItem( + DeviceExtension->PowerWorkItem, + &i8042PowerWorkItem, + DelayedWorkQueue, + DeviceExtension); + return TRUE; } static VOID NTAPI -i8042KbdDpcRoutine(IN PKDPC Dpc, - IN PVOID DeferredContext, - IN PVOID SystemArgument1, - IN PVOID SystemArgument2) +i8042KbdDpcRoutine( + IN PKDPC Dpc, + IN PVOID DeferredContext, + IN PVOID SystemArgument1, + IN PVOID SystemArgument2) { - PI8042_KEYBOARD_EXTENSION DeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; - ULONG KeysTransferred = 0; - ULONG KeysInBufferCopy; - KIRQL Irql; + PI8042_KEYBOARD_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + ULONG KeysTransferred = 0; + ULONG KeysInBufferCopy; + KIRQL Irql; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeferredContext; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeferredContext; + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - if (HandlePowerKeys(DeviceExtension)) - { - DeviceExtension->KeyComplete = FALSE; - return; - } + if (HandlePowerKeys(DeviceExtension)) + { + DeviceExtension->KeyComplete = FALSE; + return; + } - i8042PacketDpc(PortDeviceExtension); - if (!DeviceExtension->KeyComplete) - return; - /* We got the interrupt as it was being enabled, too bad */ - if (!PortDeviceExtension->HighestDIRQLInterrupt) - return; + i8042PacketDpc(PortDeviceExtension); + if (!DeviceExtension->KeyComplete) + return; + /* We got the interrupt as it was being enabled, too bad */ + if (!PortDeviceExtension->HighestDIRQLInterrupt) + return; - Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); + Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); - DeviceExtension->KeyComplete = FALSE; - KeysInBufferCopy = DeviceExtension->KeysInBuffer; + DeviceExtension->KeyComplete = FALSE; + KeysInBufferCopy = DeviceExtension->KeysInBuffer; - KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); + KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); - if (PortDeviceExtension->Settings.CrashOnCtrlScroll) - { - PKEYBOARD_INPUT_DATA InputData; - InputData = DeviceExtension->KeyboardBuffer + KeysInBufferCopy - 1; + if (PortDeviceExtension->Settings.CrashOnCtrlScroll) + { + PKEYBOARD_INPUT_DATA InputData; + InputData = DeviceExtension->KeyboardBuffer + KeysInBufferCopy - 1; - /* Test for TAB + key combination */ - if (InputData->MakeCode == 0x0F) - DeviceExtension->TabPressed = !(InputData->Flags & KEY_BREAK); - else if (DeviceExtension->TabPressed) - { - DeviceExtension->TabPressed = FALSE; + /* Test for TAB + key combination */ + if (InputData->MakeCode == 0x0F) + DeviceExtension->TabPressed = !(InputData->Flags & KEY_BREAK); + else if (DeviceExtension->TabPressed) + { + DeviceExtension->TabPressed = FALSE; - IoQueueWorkItem( - DeviceExtension->DebugWorkItem, - &i8042DebugWorkItem, - DelayedWorkQueue, - (PVOID)(ULONG_PTR)InputData->MakeCode); - } - } + IoQueueWorkItem( + DeviceExtension->DebugWorkItem, + &i8042DebugWorkItem, + DelayedWorkQueue, + (PVOID)(ULONG_PTR)InputData->MakeCode); + } + } - TRACE_(I8042PRT, "Send a key\n"); + TRACE_(I8042PRT, "Send a key\n"); - if (!DeviceExtension->KeyboardData.ClassService) - return; + if (!DeviceExtension->KeyboardData.ClassService) + return; - INFO_(I8042PRT, "Sending %lu key(s)\n", KeysInBufferCopy); - (*(PSERVICE_CALLBACK_ROUTINE)DeviceExtension->KeyboardData.ClassService)( - DeviceExtension->KeyboardData.ClassDeviceObject, - DeviceExtension->KeyboardBuffer, - DeviceExtension->KeyboardBuffer + KeysInBufferCopy, - &KeysTransferred); + INFO_(I8042PRT, "Sending %lu key(s)\n", KeysInBufferCopy); + (*(PSERVICE_CALLBACK_ROUTINE)DeviceExtension->KeyboardData.ClassService)( + DeviceExtension->KeyboardData.ClassDeviceObject, + DeviceExtension->KeyboardBuffer, + DeviceExtension->KeyboardBuffer + KeysInBufferCopy, + &KeysTransferred); - KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); - DeviceExtension->KeysInBuffer -= KeysTransferred; - KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); + KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); + DeviceExtension->KeysInBuffer -= KeysTransferred; + KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); } /* -* Runs the keyboard IOCTL dispatch. -*/ + * Runs the keyboard IOCTL dispatch. + */ NTSTATUS NTAPI -i8042KbdDeviceControl(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042KbdDeviceControl( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PIO_STACK_LOCATION Stack; - PI8042_KEYBOARD_EXTENSION DeviceExtension; - NTSTATUS Status; + PIO_STACK_LOCATION Stack; + PI8042_KEYBOARD_EXTENSION DeviceExtension; + NTSTATUS Status; - Stack = IoGetCurrentIrpStackLocation(Irp); - Irp->IoStatus.Information = 0; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension; + Stack = IoGetCurrentIrpStackLocation(Irp); + Irp->IoStatus.Information = 0; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension; - switch (Stack->Parameters.DeviceIoControl.IoControlCode) - { - case IOCTL_GET_SYS_BUTTON_CAPS: - { - /* Part of GUID_DEVICE_SYS_BUTTON interface */ - PULONG pCaps; - TRACE_(I8042PRT, "IOCTL_GET_SYS_BUTTON_CAPS\n"); + switch (Stack->Parameters.DeviceIoControl.IoControlCode) + { + case IOCTL_GET_SYS_BUTTON_CAPS: + { + /* Part of GUID_DEVICE_SYS_BUTTON interface */ + PULONG pCaps; + TRACE_(I8042PRT, "IOCTL_GET_SYS_BUTTON_CAPS\n"); - if (Stack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG)) - Status = STATUS_INVALID_PARAMETER; - else - { - pCaps = (PULONG)Irp->AssociatedIrp.SystemBuffer; - *pCaps = DeviceExtension->NewCaps; - DeviceExtension->ReportedCaps = DeviceExtension->NewCaps; - Irp->IoStatus.Information = sizeof(ULONG); - Status = STATUS_SUCCESS; - } - break; - } - case IOCTL_GET_SYS_BUTTON_EVENT: - { - /* Part of GUID_DEVICE_SYS_BUTTON interface */ - PIRP WaitingIrp; - TRACE_(I8042PRT, "IOCTL_GET_SYS_BUTTON_EVENT\n"); + if (Stack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG)) + Status = STATUS_INVALID_PARAMETER; + else + { + pCaps = (PULONG)Irp->AssociatedIrp.SystemBuffer; + *pCaps = DeviceExtension->NewCaps; + DeviceExtension->ReportedCaps = DeviceExtension->NewCaps; + Irp->IoStatus.Information = sizeof(ULONG); + Status = STATUS_SUCCESS; + } + break; + } + case IOCTL_GET_SYS_BUTTON_EVENT: + { + /* Part of GUID_DEVICE_SYS_BUTTON interface */ + PIRP WaitingIrp; + TRACE_(I8042PRT, "IOCTL_GET_SYS_BUTTON_EVENT\n"); - if (Stack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG)) - Status = STATUS_INVALID_PARAMETER; - else - { - WaitingIrp = InterlockedCompareExchangePointer( - &DeviceExtension->PowerIrp, - Irp, - NULL); - /* Check if an Irp is already pending */ - if (WaitingIrp) - { - /* Unable to have a 2nd pending IRP for this IOCTL */ - WARN_(I8042PRT, "Unable to pend a second IRP for IOCTL_GET_SYS_BUTTON_EVENT\n"); - Status = STATUS_INVALID_PARAMETER; - Irp->IoStatus.Status = Status; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - } - else - { - ULONG PowerKey; - PowerKey = InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, 0); - if (PowerKey != 0) - { - (VOID)InterlockedCompareExchangePointer(&DeviceExtension->PowerIrp, NULL, Irp); - *(PULONG)Irp->AssociatedIrp.SystemBuffer = PowerKey; - Status = STATUS_SUCCESS; - Irp->IoStatus.Status = Status; - Irp->IoStatus.Information = sizeof(ULONG); - IoCompleteRequest(Irp, IO_NO_INCREMENT); - } - else - { - TRACE_(I8042PRT, "Pending IOCTL_GET_SYS_BUTTON_EVENT\n"); - Status = STATUS_PENDING; - Irp->IoStatus.Status = Status; - IoMarkIrpPending(Irp); - } - } - return Status; - } - break; - } - default: - { - ERR_(I8042PRT, "IRP_MJ_DEVICE_CONTROL / unknown ioctl code 0x%lx\n", - Stack->Parameters.DeviceIoControl.IoControlCode); - ASSERT(FALSE); - return ForwardIrpAndForget(DeviceObject, Irp); - } - } + if (Stack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(ULONG)) + Status = STATUS_INVALID_PARAMETER; + else + { + WaitingIrp = InterlockedCompareExchangePointer( + &DeviceExtension->PowerIrp, + Irp, + NULL); + /* Check if an Irp is already pending */ + if (WaitingIrp) + { + /* Unable to have a 2nd pending IRP for this IOCTL */ + WARN_(I8042PRT, "Unable to pend a second IRP for IOCTL_GET_SYS_BUTTON_EVENT\n"); + Status = STATUS_INVALID_PARAMETER; + Irp->IoStatus.Status = Status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + } + else + { + ULONG PowerKey; + PowerKey = InterlockedExchange((PLONG)&DeviceExtension->LastPowerKey, 0); + if (PowerKey != 0) + { + (VOID)InterlockedCompareExchangePointer(&DeviceExtension->PowerIrp, NULL, Irp); + *(PULONG)Irp->AssociatedIrp.SystemBuffer = PowerKey; + Status = STATUS_SUCCESS; + Irp->IoStatus.Status = Status; + Irp->IoStatus.Information = sizeof(ULONG); + IoCompleteRequest(Irp, IO_NO_INCREMENT); + } + else + { + TRACE_(I8042PRT, "Pending IOCTL_GET_SYS_BUTTON_EVENT\n"); + Status = STATUS_PENDING; + Irp->IoStatus.Status = Status; + IoMarkIrpPending(Irp); + } + } + return Status; + } + break; + } + default: + { + ERR_(I8042PRT, "IRP_MJ_DEVICE_CONTROL / unknown ioctl code 0x%lx\n", + Stack->Parameters.DeviceIoControl.IoControlCode); + ASSERT(FALSE); + return ForwardIrpAndForget(DeviceObject, Irp); + } + } - Irp->IoStatus.Status = Status; - if (Status == STATUS_PENDING) - IoMarkIrpPending(Irp); - else - IoCompleteRequest(Irp, IO_NO_INCREMENT); + Irp->IoStatus.Status = Status; + if (Status == STATUS_PENDING) + IoMarkIrpPending(Irp); + else + IoCompleteRequest(Irp, IO_NO_INCREMENT); - return Status; + return Status; } /* -* Runs the keyboard IOCTL_INTERNAL dispatch. -*/ + * Runs the keyboard IOCTL_INTERNAL dispatch. + */ NTSTATUS NTAPI -i8042KbdInternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042KbdInternalDeviceControl( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PIO_STACK_LOCATION Stack; - PI8042_KEYBOARD_EXTENSION DeviceExtension; - NTSTATUS Status; + PIO_STACK_LOCATION Stack; + PI8042_KEYBOARD_EXTENSION DeviceExtension; + NTSTATUS Status; - Stack = IoGetCurrentIrpStackLocation(Irp); - Irp->IoStatus.Information = 0; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension; + Stack = IoGetCurrentIrpStackLocation(Irp); + Irp->IoStatus.Information = 0; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)DeviceObject->DeviceExtension; - switch (Stack->Parameters.DeviceIoControl.IoControlCode) - { - case IOCTL_INTERNAL_KEYBOARD_CONNECT: - { - SIZE_T Size; - PIO_WORKITEM WorkItem = NULL; - PI8042_HOOK_WORKITEM WorkItemData = NULL; + switch (Stack->Parameters.DeviceIoControl.IoControlCode) + { + case IOCTL_INTERNAL_KEYBOARD_CONNECT: + { + SIZE_T Size; + PIO_WORKITEM WorkItem = NULL; + PI8042_HOOK_WORKITEM WorkItemData = NULL; - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_CONNECT\n"); - if (Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(CONNECT_DATA)) - { - Status = STATUS_INVALID_PARAMETER; - goto cleanup; - } + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_CONNECT\n"); + if (Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(CONNECT_DATA)) + { + Status = STATUS_INVALID_PARAMETER; + goto cleanup; + } - DeviceExtension->KeyboardData = - *((PCONNECT_DATA)Stack->Parameters.DeviceIoControl.Type3InputBuffer); + DeviceExtension->KeyboardData = + *((PCONNECT_DATA)Stack->Parameters.DeviceIoControl.Type3InputBuffer); - /* Send IOCTL_INTERNAL_I8042_HOOK_KEYBOARD to device stack */ - WorkItem = IoAllocateWorkItem(DeviceObject); - if (!WorkItem) - { - WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); - Status = STATUS_INSUFFICIENT_RESOURCES; - goto cleanup; - } - WorkItemData = ExAllocatePoolWithTag( - NonPagedPool, - sizeof(I8042_HOOK_WORKITEM), - I8042PRT_TAG); - if (!WorkItemData) - { - WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - WorkItemData->WorkItem = WorkItem; - WorkItemData->Irp = Irp; + /* Send IOCTL_INTERNAL_I8042_HOOK_KEYBOARD to device stack */ + WorkItem = IoAllocateWorkItem(DeviceObject); + if (!WorkItem) + { + WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } + WorkItemData = ExAllocatePoolWithTag( + NonPagedPool, + sizeof(I8042_HOOK_WORKITEM), + I8042PRT_TAG); + if (!WorkItemData) + { + WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + WorkItemData->WorkItem = WorkItem; + WorkItemData->Irp = Irp; - /* Initialize extension */ - DeviceExtension->Common.Type = Keyboard; - Size = DeviceExtension->Common.PortDeviceExtension->Settings.KeyboardDataQueueSize * sizeof(KEYBOARD_INPUT_DATA); - DeviceExtension->KeyboardBuffer = ExAllocatePoolWithTag( - NonPagedPool, - Size, - I8042PRT_TAG); - if (!DeviceExtension->KeyboardBuffer) - { - WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - RtlZeroMemory(DeviceExtension->KeyboardBuffer, Size); - KeInitializeDpc( - &DeviceExtension->DpcKeyboard, - i8042KbdDpcRoutine, - DeviceExtension); - DeviceExtension->PowerWorkItem = IoAllocateWorkItem(DeviceObject); - if (!DeviceExtension->PowerWorkItem) - { - WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); - Status = STATUS_INSUFFICIENT_RESOURCES; - goto cleanup; - } - DeviceExtension->DebugWorkItem = IoAllocateWorkItem(DeviceObject); - if (!DeviceExtension->DebugWorkItem) - { - WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); - Status = STATUS_INSUFFICIENT_RESOURCES; - goto cleanup; - } - DeviceExtension->Common.PortDeviceExtension->KeyboardExtension = DeviceExtension; - DeviceExtension->Common.PortDeviceExtension->Flags |= KEYBOARD_CONNECTED; + /* Initialize extension */ + DeviceExtension->Common.Type = Keyboard; + Size = DeviceExtension->Common.PortDeviceExtension->Settings.KeyboardDataQueueSize * sizeof(KEYBOARD_INPUT_DATA); + DeviceExtension->KeyboardBuffer = ExAllocatePoolWithTag( + NonPagedPool, + Size, + I8042PRT_TAG); + if (!DeviceExtension->KeyboardBuffer) + { + WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + RtlZeroMemory(DeviceExtension->KeyboardBuffer, Size); + KeInitializeDpc( + &DeviceExtension->DpcKeyboard, + i8042KbdDpcRoutine, + DeviceExtension); + DeviceExtension->PowerWorkItem = IoAllocateWorkItem(DeviceObject); + if (!DeviceExtension->PowerWorkItem) + { + WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } + DeviceExtension->DebugWorkItem = IoAllocateWorkItem(DeviceObject); + if (!DeviceExtension->DebugWorkItem) + { + WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } + DeviceExtension->Common.PortDeviceExtension->KeyboardExtension = DeviceExtension; + DeviceExtension->Common.PortDeviceExtension->Flags |= KEYBOARD_CONNECTED; - IoMarkIrpPending(Irp); - /* FIXME: DeviceExtension->KeyboardHook.IsrWritePort = ; */ - DeviceExtension->KeyboardHook.QueueKeyboardPacket = i8042KbdQueuePacket; - DeviceExtension->KeyboardHook.CallContext = DeviceExtension; - IoQueueWorkItem(WorkItem, - i8042SendHookWorkItem, - DelayedWorkQueue, - WorkItemData); - Status = STATUS_PENDING; - break; + IoMarkIrpPending(Irp); + /* FIXME: DeviceExtension->KeyboardHook.IsrWritePort = ; */ + DeviceExtension->KeyboardHook.QueueKeyboardPacket = i8042KbdQueuePacket; + DeviceExtension->KeyboardHook.CallContext = DeviceExtension; + IoQueueWorkItem(WorkItem, + i8042SendHookWorkItem, + DelayedWorkQueue, + WorkItemData); + Status = STATUS_PENDING; + break; cleanup: - if (DeviceExtension->KeyboardBuffer) - ExFreePoolWithTag(DeviceExtension->KeyboardBuffer, I8042PRT_TAG); - if (DeviceExtension->PowerWorkItem) - IoFreeWorkItem(DeviceExtension->PowerWorkItem); - if (DeviceExtension->DebugWorkItem) - IoFreeWorkItem(DeviceExtension->DebugWorkItem); - if (WorkItem) - IoFreeWorkItem(WorkItem); - if (WorkItemData) - ExFreePoolWithTag(WorkItemData, I8042PRT_TAG); - break; - } - case IOCTL_INTERNAL_KEYBOARD_DISCONNECT: - { - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_DISCONNECT\n"); - /* MSDN says that operation is to implemented. - * To implement it, we just have to do: - * DeviceExtension->KeyboardData.ClassService = NULL; - */ - Status = STATUS_NOT_IMPLEMENTED; - break; - } - case IOCTL_INTERNAL_I8042_HOOK_KEYBOARD: - { - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_I8042_HOOK_KEYBOARD\n"); - /* Nothing to do here */ - Status = STATUS_SUCCESS; - break; - } - case IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION: - { - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION\n"); + if (DeviceExtension->KeyboardBuffer) + ExFreePoolWithTag(DeviceExtension->KeyboardBuffer, I8042PRT_TAG); + if (DeviceExtension->PowerWorkItem) + IoFreeWorkItem(DeviceExtension->PowerWorkItem); + if (DeviceExtension->DebugWorkItem) + IoFreeWorkItem(DeviceExtension->DebugWorkItem); + if (WorkItem) + IoFreeWorkItem(WorkItem); + if (WorkItemData) + ExFreePoolWithTag(WorkItemData, I8042PRT_TAG); + break; + } + case IOCTL_INTERNAL_KEYBOARD_DISCONNECT: + { + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_KEYBOARD_DISCONNECT\n"); + /* MSDN says that operation is to implemented. + * To implement it, we just have to do: + * DeviceExtension->KeyboardData.ClassService = NULL; + */ + Status = STATUS_NOT_IMPLEMENTED; + break; + } + case IOCTL_INTERNAL_I8042_HOOK_KEYBOARD: + { + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_I8042_HOOK_KEYBOARD\n"); + /* Nothing to do here */ + Status = STATUS_SUCCESS; + break; + } + case IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION: + { + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION\n"); - /* We should check the UnitID, but it's kind of pointless as - * all keyboards are supposed to have the same one - */ - if (Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION)) - { - Status = STATUS_BUFFER_TOO_SMALL; - } - else - { - RtlCopyMemory( - Irp->AssociatedIrp.SystemBuffer, - &IndicatorTranslation, - sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION)); - Irp->IoStatus.Information = sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION); - Status = STATUS_SUCCESS; - } - break; - } - case IOCTL_KEYBOARD_QUERY_INDICATORS: - { - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATORS\n"); + /* We should check the UnitID, but it's kind of pointless as + * all keyboards are supposed to have the same one + */ + if (Stack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION)) + { + Status = STATUS_BUFFER_TOO_SMALL; + } + else + { + RtlCopyMemory( + Irp->AssociatedIrp.SystemBuffer, + &IndicatorTranslation, + sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION)); + Irp->IoStatus.Information = sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION); + Status = STATUS_SUCCESS; + } + break; + } + case IOCTL_KEYBOARD_QUERY_INDICATORS: + { + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_QUERY_INDICATORS\n"); - if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS)) - { - Status = STATUS_BUFFER_TOO_SMALL; - } - else - { - RtlCopyMemory( - Irp->AssociatedIrp.SystemBuffer, - &DeviceExtension->KeyboardIndicators, - sizeof(KEYBOARD_INDICATOR_PARAMETERS)); - Irp->IoStatus.Information = sizeof(KEYBOARD_INDICATOR_PARAMETERS); - Status = STATUS_SUCCESS; - } - break; - } - case IOCTL_KEYBOARD_SET_INDICATORS: - { - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_SET_INDICATORS\n"); + if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS)) + { + Status = STATUS_BUFFER_TOO_SMALL; + } + else + { + RtlCopyMemory( + Irp->AssociatedIrp.SystemBuffer, + &DeviceExtension->KeyboardIndicators, + sizeof(KEYBOARD_INDICATOR_PARAMETERS)); + Irp->IoStatus.Information = sizeof(KEYBOARD_INDICATOR_PARAMETERS); + Status = STATUS_SUCCESS; + } + break; + } + case IOCTL_KEYBOARD_SET_INDICATORS: + { + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_KEYBOARD_SET_INDICATORS\n"); - if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS)) - { - Status = STATUS_BUFFER_TOO_SMALL; - } - else - { - RtlCopyMemory( - &DeviceExtension->KeyboardIndicators, - Irp->AssociatedIrp.SystemBuffer, - sizeof(KEYBOARD_INDICATOR_PARAMETERS)); - Status = STATUS_PENDING; - IoMarkIrpPending(Irp); - IoStartPacket(DeviceObject, Irp, NULL, NULL); - } - break; - } - default: - { - ERR_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / unknown ioctl code 0x%lx\n", - Stack->Parameters.DeviceIoControl.IoControlCode); - ASSERT(FALSE); - return ForwardIrpAndForget(DeviceObject, Irp); - } - } + if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(KEYBOARD_INDICATOR_PARAMETERS)) + { + Status = STATUS_BUFFER_TOO_SMALL; + } + else + { + RtlCopyMemory( + &DeviceExtension->KeyboardIndicators, + Irp->AssociatedIrp.SystemBuffer, + sizeof(KEYBOARD_INDICATOR_PARAMETERS)); + Status = STATUS_PENDING; + IoMarkIrpPending(Irp); + IoStartPacket(DeviceObject, Irp, NULL, NULL); + } + break; + } + default: + { + ERR_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / unknown ioctl code 0x%lx\n", + Stack->Parameters.DeviceIoControl.IoControlCode); + ASSERT(FALSE); + return ForwardIrpAndForget(DeviceObject, Irp); + } + } - Irp->IoStatus.Status = Status; - if (Status != STATUS_PENDING) - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return Status; + Irp->IoStatus.Status = Status; + if (Status != STATUS_PENDING) + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return Status; } /* -* Call the customization hook. The ToReturn parameter is about wether -* we should go on with the interrupt. The return value is what -* we should return (indicating to the system wether someone else -* should try to handle the interrupt) -*/ + * Call the customization hook. The ToReturn parameter is about wether + * we should go on with the interrupt. The return value is what + * we should return (indicating to the system wether someone else + * should try to handle the interrupt) + */ static BOOLEAN -i8042KbdCallIsrHook(IN PI8042_KEYBOARD_EXTENSION DeviceExtension, - IN UCHAR Status, - IN UCHAR Input, - OUT PBOOLEAN ToReturn) +i8042KbdCallIsrHook( + IN PI8042_KEYBOARD_EXTENSION DeviceExtension, + IN UCHAR Status, + IN UCHAR Input, + OUT PBOOLEAN ToReturn) { - BOOLEAN HookReturn, HookContinue; + BOOLEAN HookReturn, HookContinue; - HookContinue = FALSE; + HookContinue = FALSE; - if (DeviceExtension->KeyboardHook.IsrRoutine) - { - HookReturn = DeviceExtension->KeyboardHook.IsrRoutine( - DeviceExtension->KeyboardHook.Context, - DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer, - &DeviceExtension->Common.PortDeviceExtension->Packet, - Status, - &Input, - &HookContinue, - &DeviceExtension->KeyboardScanState); + if (DeviceExtension->KeyboardHook.IsrRoutine) + { + HookReturn = DeviceExtension->KeyboardHook.IsrRoutine( + DeviceExtension->KeyboardHook.Context, + DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer, + &DeviceExtension->Common.PortDeviceExtension->Packet, + Status, + &Input, + &HookContinue, + &DeviceExtension->KeyboardScanState); - if (!HookContinue) - { - *ToReturn = HookReturn; - return TRUE; - } - } - return FALSE; + if (!HookContinue) + { + *ToReturn = HookReturn; + return TRUE; + } + } + return FALSE; } BOOLEAN NTAPI -i8042KbdInterruptService(IN PKINTERRUPT Interrupt, - PVOID Context) +i8042KbdInterruptService( + IN PKINTERRUPT Interrupt, + PVOID Context) { - PI8042_KEYBOARD_EXTENSION DeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; - PKEYBOARD_INPUT_DATA InputData; - ULONG Counter; - UCHAR PortStatus, Output; - BOOLEAN ToReturn = FALSE; - NTSTATUS Status; + PI8042_KEYBOARD_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + PKEYBOARD_INPUT_DATA InputData; + ULONG Counter; + UCHAR PortStatus, Output; + BOOLEAN ToReturn = FALSE; + NTSTATUS Status; - DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - InputData = DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer; - Counter = PortDeviceExtension->Settings.PollStatusIterations; + DeviceExtension = (PI8042_KEYBOARD_EXTENSION)Context; + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + InputData = DeviceExtension->KeyboardBuffer + DeviceExtension->KeysInBuffer; + Counter = PortDeviceExtension->Settings.PollStatusIterations; - while (Counter) - { - Status = i8042ReadStatus(PortDeviceExtension, &PortStatus); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "i8042ReadStatus() failed with status 0x%08lx\n", Status); - return FALSE; - } - Status = i8042ReadKeyboardData(PortDeviceExtension, &Output); - if (NT_SUCCESS(Status)) - break; - KeStallExecutionProcessor(1); - Counter--; - } - if (Counter == 0) - { - WARN_(I8042PRT, "Spurious i8042 keyboard interrupt\n"); - return FALSE; - } + while (Counter) + { + Status = i8042ReadStatus(PortDeviceExtension, &PortStatus); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "i8042ReadStatus() failed with status 0x%08lx\n", Status); + return FALSE; + } + Status = i8042ReadKeyboardData(PortDeviceExtension, &Output); + if (NT_SUCCESS(Status)) + break; + KeStallExecutionProcessor(1); + Counter--; + } + if (Counter == 0) + { + WARN_(I8042PRT, "Spurious i8042 keyboard interrupt\n"); + return FALSE; + } - INFO_(I8042PRT, "Got: 0x%02x\n", Output); + INFO_(I8042PRT, "Got: 0x%02x\n", Output); - if (PortDeviceExtension->Settings.CrashOnCtrlScroll) - { - /* Test for CTRL + SCROLL LOCK twice */ - static const UCHAR ScanCodes[] = { 0xe0, 0x1d, 0x46, 0xc6, 0x46, 0 }; + if (PortDeviceExtension->Settings.CrashOnCtrlScroll) + { + /* Test for CTRL + SCROLL LOCK twice */ + static const UCHAR ScanCodes[] = { 0xe0, 0x1d, 0x46, 0xc6, 0x46, 0 }; - if (Output == ScanCodes[DeviceExtension->ComboPosition]) - { - DeviceExtension->ComboPosition++; - if (ScanCodes[DeviceExtension->ComboPosition] == 0) - KeBugCheck(MANUALLY_INITIATED_CRASH); - } - else if (Output == ScanCodes[0]) - DeviceExtension->ComboPosition = 1; - else - DeviceExtension->ComboPosition = 0; - } + if (Output == ScanCodes[DeviceExtension->ComboPosition]) + { + DeviceExtension->ComboPosition++; + if (ScanCodes[DeviceExtension->ComboPosition] == 0) + KeBugCheck(MANUALLY_INITIATED_CRASH); + } + else if (Output == ScanCodes[0]) + DeviceExtension->ComboPosition = 1; + else + DeviceExtension->ComboPosition = 0; + } - if (i8042KbdCallIsrHook(DeviceExtension, PortStatus, Output, &ToReturn)) - return ToReturn; + if (i8042KbdCallIsrHook(DeviceExtension, PortStatus, Output, &ToReturn)) + return ToReturn; - if (i8042PacketIsr(PortDeviceExtension, Output)) - { - if (PortDeviceExtension->PacketComplete) - { - TRACE_(I8042PRT, "Packet complete\n"); - KeInsertQueueDpc(&DeviceExtension->DpcKeyboard, NULL, NULL); - } - TRACE_(I8042PRT, "Irq eaten by packet\n"); - return TRUE; - } + if (i8042PacketIsr(PortDeviceExtension, Output)) + { + if (PortDeviceExtension->PacketComplete) + { + TRACE_(I8042PRT, "Packet complete\n"); + KeInsertQueueDpc(&DeviceExtension->DpcKeyboard, NULL, NULL); + } + TRACE_(I8042PRT, "Irq eaten by packet\n"); + return TRUE; + } - TRACE_(I8042PRT, "Irq is keyboard input\n"); + TRACE_(I8042PRT, "Irq is keyboard input\n"); - if (DeviceExtension->KeyboardScanState == Normal) - { - switch (Output) - { - case 0xe0: - DeviceExtension->KeyboardScanState = GotE0; - return TRUE; - case 0xe1: - DeviceExtension->KeyboardScanState = GotE1; - return TRUE; - default: - break; - } - } + if (DeviceExtension->KeyboardScanState == Normal) + { + switch (Output) + { + case 0xe0: + DeviceExtension->KeyboardScanState = GotE0; + return TRUE; + case 0xe1: + DeviceExtension->KeyboardScanState = GotE1; + return TRUE; + default: + break; + } + } - /* Update InputData */ - InputData->Flags = 0; - switch (DeviceExtension->KeyboardScanState) - { - case GotE0: - InputData->Flags |= KEY_E0; - break; - case GotE1: - InputData->Flags |= KEY_E1; - break; - default: - break; - } - DeviceExtension->KeyboardScanState = Normal; - if (Output & 0x80) - InputData->Flags |= KEY_BREAK; - else - InputData->Flags |= KEY_MAKE; - InputData->MakeCode = Output & 0x7f; - InputData->Reserved = 0; + /* Update InputData */ + InputData->Flags = 0; + switch (DeviceExtension->KeyboardScanState) + { + case GotE0: + InputData->Flags |= KEY_E0; + break; + case GotE1: + InputData->Flags |= KEY_E1; + break; + default: + break; + } + DeviceExtension->KeyboardScanState = Normal; + if (Output & 0x80) + InputData->Flags |= KEY_BREAK; + else + InputData->Flags |= KEY_MAKE; + InputData->MakeCode = Output & 0x7f; + InputData->Reserved = 0; - DeviceExtension->KeyboardHook.QueueKeyboardPacket(DeviceExtension->KeyboardHook.CallContext); + DeviceExtension->KeyboardHook.QueueKeyboardPacket(DeviceExtension->KeyboardHook.CallContext); - return TRUE; + return TRUE; } diff --git a/reactos/drivers/input/i8042prt/misc.c b/reactos/drivers/input/i8042prt/misc.c index 698003dcfc4..102dd1dc121 100644 --- a/reactos/drivers/input/i8042prt/misc.c +++ b/reactos/drivers/input/i8042prt/misc.c @@ -13,71 +13,74 @@ /* FUNCTIONS *****************************************************************/ NTSTATUS NTAPI -ForwardIrpAndWait(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +ForwardIrpAndWait( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PDEVICE_OBJECT LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; + PDEVICE_OBJECT LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; - ASSERT(LowerDevice); + ASSERT(LowerDevice); - if (!IoForwardIrpSynchronously(LowerDevice, Irp)) - return STATUS_UNSUCCESSFUL; + if (!IoForwardIrpSynchronously(LowerDevice, Irp)) + return STATUS_UNSUCCESSFUL; - return Irp->IoStatus.Status; + return Irp->IoStatus.Status; } NTSTATUS NTAPI -ForwardIrpAndForget(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +ForwardIrpAndForget( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PDEVICE_OBJECT LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; + PDEVICE_OBJECT LowerDevice = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->LowerDevice; - ASSERT(LowerDevice); + ASSERT(LowerDevice); - IoSkipCurrentIrpStackLocation(Irp); - return IoCallDriver(LowerDevice, Irp); + IoSkipCurrentIrpStackLocation(Irp); + return IoCallDriver(LowerDevice, Irp); } NTSTATUS -DuplicateUnicodeString(IN ULONG Flags, - IN PCUNICODE_STRING SourceString, - OUT PUNICODE_STRING DestinationString) +DuplicateUnicodeString( + IN ULONG Flags, + IN PCUNICODE_STRING SourceString, + OUT PUNICODE_STRING DestinationString) { - if (SourceString == NULL || DestinationString == NULL - || SourceString->Length > SourceString->MaximumLength - || (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL) - || Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4) - { - return STATUS_INVALID_PARAMETER; - } + if (SourceString == NULL || DestinationString == NULL + || SourceString->Length > SourceString->MaximumLength + || (SourceString->Length == 0 && SourceString->MaximumLength > 0 && SourceString->Buffer == NULL) + || Flags == RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING || Flags >= 4) + { + return STATUS_INVALID_PARAMETER; + } - if ((SourceString->Length == 0) - && (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | - RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING))) - { - DestinationString->Length = 0; - DestinationString->MaximumLength = 0; - DestinationString->Buffer = NULL; - } - else - { - USHORT DestMaxLength = SourceString->Length; + if ((SourceString->Length == 0) + && (Flags != (RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE | + RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING))) + { + DestinationString->Length = 0; + DestinationString->MaximumLength = 0; + DestinationString->Buffer = NULL; + } + else + { + USHORT DestMaxLength = SourceString->Length; - if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) - DestMaxLength += sizeof(UNICODE_NULL); + if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) + DestMaxLength += sizeof(UNICODE_NULL); - DestinationString->Buffer = ExAllocatePoolWithTag(PagedPool, DestMaxLength, I8042PRT_TAG); - if (DestinationString->Buffer == NULL) - return STATUS_NO_MEMORY; + DestinationString->Buffer = ExAllocatePoolWithTag(PagedPool, DestMaxLength, I8042PRT_TAG); + if (DestinationString->Buffer == NULL) + return STATUS_NO_MEMORY; - RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length); - DestinationString->Length = SourceString->Length; - DestinationString->MaximumLength = DestMaxLength; + RtlCopyMemory(DestinationString->Buffer, SourceString->Buffer, SourceString->Length); + DestinationString->Length = SourceString->Length; + DestinationString->MaximumLength = DestMaxLength; - if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) - DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0; - } + if (Flags & RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE) + DestinationString->Buffer[DestinationString->Length / sizeof(WCHAR)] = 0; + } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } diff --git a/reactos/drivers/input/i8042prt/mouse.c b/reactos/drivers/input/i8042prt/mouse.c index 51375c0317b..a53d5b74898 100644 --- a/reactos/drivers/input/i8042prt/mouse.c +++ b/reactos/drivers/input/i8042prt/mouse.c @@ -17,869 +17,881 @@ /* FUNCTIONS *****************************************************************/ /* -* These functions are callbacks for filter driver custom interrupt -* service routines. -*/ + * These functions are callbacks for filter driver custom interrupt + * service routines. + */ static VOID NTAPI -i8042MouIsrWritePort(IN PVOID Context, - IN UCHAR Value) +i8042MouIsrWritePort( + IN PVOID Context, + IN UCHAR Value) { - PI8042_MOUSE_EXTENSION DeviceExtension; + PI8042_MOUSE_EXTENSION DeviceExtension; - DeviceExtension = (PI8042_MOUSE_EXTENSION)Context; + DeviceExtension = (PI8042_MOUSE_EXTENSION)Context; - if (DeviceExtension->MouseHook.IsrWritePort != i8042MouIsrWritePort) - { - DeviceExtension->MouseHook.IsrWritePort( - DeviceExtension->MouseHook.CallContext, - Value); - } - else - i8042IsrWritePort(DeviceExtension->Common.PortDeviceExtension, Value, CTRL_WRITE_MOUSE); + if (DeviceExtension->MouseHook.IsrWritePort != i8042MouIsrWritePort) + { + DeviceExtension->MouseHook.IsrWritePort( + DeviceExtension->MouseHook.CallContext, + Value); + } + else + i8042IsrWritePort(DeviceExtension->Common.PortDeviceExtension, Value, CTRL_WRITE_MOUSE); } static VOID NTAPI -i8042MouQueuePacket(IN PVOID Context) +i8042MouQueuePacket( + IN PVOID Context) { - PI8042_MOUSE_EXTENSION DeviceExtension; + PI8042_MOUSE_EXTENSION DeviceExtension; - DeviceExtension = (PI8042_MOUSE_EXTENSION)Context; + DeviceExtension = (PI8042_MOUSE_EXTENSION)Context; - DeviceExtension->MouseComplete = TRUE; - DeviceExtension->MouseInBuffer++; - if (DeviceExtension->MouseInBuffer > DeviceExtension->Common.PortDeviceExtension->Settings.MouseDataQueueSize) - { - WARN_(I8042PRT, "Mouse buffer overflow\n"); - DeviceExtension->MouseInBuffer--; - } + DeviceExtension->MouseComplete = TRUE; + DeviceExtension->MouseInBuffer++; + if (DeviceExtension->MouseInBuffer > DeviceExtension->Common.PortDeviceExtension->Settings.MouseDataQueueSize) + { + WARN_(I8042PRT, "Mouse buffer overflow\n"); + DeviceExtension->MouseInBuffer--; + } - TRACE_(I8042PRT, "Irq completes mouse packet\n"); - KeInsertQueueDpc(&DeviceExtension->DpcMouse, NULL, NULL); + TRACE_(I8042PRT, "Irq completes mouse packet\n"); + KeInsertQueueDpc(&DeviceExtension->DpcMouse, NULL, NULL); } VOID -i8042MouHandle(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN UCHAR Output) +i8042MouHandle( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN UCHAR Output) { - PMOUSE_INPUT_DATA MouseInput; - CHAR Scroll; + PMOUSE_INPUT_DATA MouseInput; + CHAR Scroll; - MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer; + MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer; - switch (DeviceExtension->MouseState) - { - case MouseIdle: - /* This bit should be 1, if not drop the packet, we - * might be lucky and get in sync again - */ - if (!(Output & 8)) { - WARN_(I8042PRT, "Bad input, dropping..\n"); - return; - } + switch (DeviceExtension->MouseState) + { + case MouseIdle: + /* This bit should be 1, if not drop the packet, we + * might be lucky and get in sync again + */ + if (!(Output & 8)) { + WARN_(I8042PRT, "Bad input, dropping..\n"); + return; + } - MouseInput->Buttons = 0; - MouseInput->RawButtons = 0; - MouseInput->Flags = MOUSE_MOVE_RELATIVE; + MouseInput->Buttons = 0; + MouseInput->RawButtons = 0; + MouseInput->Flags = MOUSE_MOVE_RELATIVE; - /* Note how we ignore the overflow bits, like Windows - * is said to do. There's no reasonable thing to do - * anyway. - */ + /* Note how we ignore the overflow bits, like Windows + * is said to do. There's no reasonable thing to do + * anyway. + */ - if (Output & 16) - MouseInput->LastX = 1; - else - MouseInput->LastX = 0; - if (Output & 32) - MouseInput->LastY = 1; - else - MouseInput->LastY = 0; + if (Output & 16) + MouseInput->LastX = 1; + else + MouseInput->LastX = 0; + if (Output & 32) + MouseInput->LastY = 1; + else + MouseInput->LastY = 0; - if (Output & 1) - MouseInput->RawButtons |= MOUSE_LEFT_BUTTON_DOWN; - if (Output & 2) - MouseInput->RawButtons |= MOUSE_RIGHT_BUTTON_DOWN; - if (Output & 4) - MouseInput->RawButtons |= MOUSE_MIDDLE_BUTTON_DOWN; + if (Output & 1) + MouseInput->RawButtons |= MOUSE_LEFT_BUTTON_DOWN; + if (Output & 2) + MouseInput->RawButtons |= MOUSE_RIGHT_BUTTON_DOWN; + if (Output & 4) + MouseInput->RawButtons |= MOUSE_MIDDLE_BUTTON_DOWN; - DeviceExtension->MouseState = XMovement; - break; + DeviceExtension->MouseState = XMovement; + break; - case XMovement: - if (MouseInput->LastX) - MouseInput->LastX = (LONG) Output - 256; - else - MouseInput->LastX = Output; + case XMovement: + if (MouseInput->LastX) + MouseInput->LastX = (LONG) Output - 256; + else + MouseInput->LastX = Output; - DeviceExtension->MouseState = YMovement; - break; + DeviceExtension->MouseState = YMovement; + break; - case YMovement: - if (MouseInput->LastY) - MouseInput->LastY = (LONG)Output - 256; - else - MouseInput->LastY = (LONG)Output; + case YMovement: + if (MouseInput->LastY) + MouseInput->LastY = (LONG)Output - 256; + else + MouseInput->LastY = (LONG)Output; - /* Windows wants it the other way around */ - MouseInput->LastY = -MouseInput->LastY; + /* Windows wants it the other way around */ + MouseInput->LastY = -MouseInput->LastY; - if (DeviceExtension->MouseType == GenericPS2 || - DeviceExtension->MouseType == Ps2pp) - { - i8042MouHandleButtons( - DeviceExtension, - MOUSE_LEFT_BUTTON_DOWN | - MOUSE_RIGHT_BUTTON_DOWN | - MOUSE_MIDDLE_BUTTON_DOWN); - DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext); - DeviceExtension->MouseState = MouseIdle; - } - else - { - DeviceExtension->MouseState = ZMovement; - } - break; + if (DeviceExtension->MouseType == GenericPS2 || + DeviceExtension->MouseType == Ps2pp) + { + i8042MouHandleButtons( + DeviceExtension, + MOUSE_LEFT_BUTTON_DOWN | + MOUSE_RIGHT_BUTTON_DOWN | + MOUSE_MIDDLE_BUTTON_DOWN); + DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext); + DeviceExtension->MouseState = MouseIdle; + } + else + { + DeviceExtension->MouseState = ZMovement; + } + break; - case ZMovement: - Scroll = Output & 0x0f; - if (Scroll & 8) - Scroll |= 0xf0; + case ZMovement: + Scroll = Output & 0x0f; + if (Scroll & 8) + Scroll |= 0xf0; - if (Scroll) - { - MouseInput->RawButtons |= MOUSE_WHEEL; - MouseInput->ButtonData = (USHORT)(Scroll * -WHEEL_DELTA); - } + if (Scroll) + { + MouseInput->RawButtons |= MOUSE_WHEEL; + MouseInput->ButtonData = (USHORT)(Scroll * -WHEEL_DELTA); + } - if (DeviceExtension->MouseType == IntellimouseExplorer) - { - if (Output & 16) - MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN; - if (Output & 32) - MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN; - } - i8042MouHandleButtons( - DeviceExtension, - MOUSE_LEFT_BUTTON_DOWN | - MOUSE_RIGHT_BUTTON_DOWN | - MOUSE_MIDDLE_BUTTON_DOWN | - MOUSE_BUTTON_4_DOWN | - MOUSE_BUTTON_5_DOWN); - DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext); - DeviceExtension->MouseState = MouseIdle; - break; + if (DeviceExtension->MouseType == IntellimouseExplorer) + { + if (Output & 16) + MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN; + if (Output & 32) + MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN; + } + i8042MouHandleButtons( + DeviceExtension, + MOUSE_LEFT_BUTTON_DOWN | + MOUSE_RIGHT_BUTTON_DOWN | + MOUSE_MIDDLE_BUTTON_DOWN | + MOUSE_BUTTON_4_DOWN | + MOUSE_BUTTON_5_DOWN); + DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext); + DeviceExtension->MouseState = MouseIdle; + break; - default: - ERR_(I8042PRT, "Unexpected state 0x%u!\n", DeviceExtension->MouseState); - ASSERT(FALSE); - } + default: + ERR_(I8042PRT, "Unexpected state 0x%u!\n", DeviceExtension->MouseState); + ASSERT(FALSE); + } } /* -* Updates ButtonFlags according to RawButtons and a saved state; -* Only takes in account the bits that are set in Mask -*/ + * Updates ButtonFlags according to RawButtons and a saved state; + * Only takes in account the bits that are set in Mask + */ VOID -i8042MouHandleButtons(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN USHORT Mask) +i8042MouHandleButtons( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN USHORT Mask) { - PMOUSE_INPUT_DATA MouseInput; - USHORT NewButtonData; - USHORT ButtonDiff; + PMOUSE_INPUT_DATA MouseInput; + USHORT NewButtonData; + USHORT ButtonDiff; - MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer; - NewButtonData = (USHORT)(MouseInput->RawButtons & Mask); - ButtonDiff = (NewButtonData ^ DeviceExtension->MouseButtonState) & Mask; + MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer; + NewButtonData = (USHORT)(MouseInput->RawButtons & Mask); + ButtonDiff = (NewButtonData ^ DeviceExtension->MouseButtonState) & Mask; - /* Note that the defines are such: - * MOUSE_LEFT_BUTTON_DOWN 1 - * MOUSE_LEFT_BUTTON_UP 2 - */ - MouseInput->ButtonFlags |= (NewButtonData & ButtonDiff) | - (((~(NewButtonData)) << 1) & (ButtonDiff << 1)) | - (MouseInput->RawButtons & 0xfc00); + /* Note that the defines are such: + * MOUSE_LEFT_BUTTON_DOWN 1 + * MOUSE_LEFT_BUTTON_UP 2 + */ + MouseInput->ButtonFlags |= (NewButtonData & ButtonDiff) | + (((~(NewButtonData)) << 1) & (ButtonDiff << 1)) | + (MouseInput->RawButtons & 0xfc00); - INFO_(I8042PRT, "Left raw/up/down: %u/%u/%u\n", - MouseInput->RawButtons & MOUSE_LEFT_BUTTON_DOWN, - MouseInput->ButtonFlags & MOUSE_LEFT_BUTTON_DOWN, - MouseInput->ButtonFlags & MOUSE_LEFT_BUTTON_UP); + INFO_(I8042PRT, "Left raw/up/down: %u/%u/%u\n", + MouseInput->RawButtons & MOUSE_LEFT_BUTTON_DOWN, + MouseInput->ButtonFlags & MOUSE_LEFT_BUTTON_DOWN, + MouseInput->ButtonFlags & MOUSE_LEFT_BUTTON_UP); - DeviceExtension->MouseButtonState = - (DeviceExtension->MouseButtonState & ~Mask) | (NewButtonData & Mask); + DeviceExtension->MouseButtonState = + (DeviceExtension->MouseButtonState & ~Mask) | (NewButtonData & Mask); } /* Does lastest initializations for the mouse. This method -* is called just before connecting the interrupt. -*/ + * is called just before connecting the interrupt. + */ NTSTATUS -i8042MouInitialize(IN PI8042_MOUSE_EXTENSION DeviceExtension) +i8042MouInitialize( + IN PI8042_MOUSE_EXTENSION DeviceExtension) { - NTSTATUS Status; - UCHAR Value; + NTSTATUS Status; + UCHAR Value; - /* Enable the PS/2 mouse port */ - i8042Write(DeviceExtension->Common.PortDeviceExtension, DeviceExtension->Common.PortDeviceExtension->ControlPort, MOUSE_ENAB); + /* Enable the PS/2 mouse port */ + i8042Write(DeviceExtension->Common.PortDeviceExtension, DeviceExtension->Common.PortDeviceExtension->ControlPort, MOUSE_ENAB); - /* Enable the mouse */ - if(!i8042IsrWritePort(DeviceExtension->Common.PortDeviceExtension, MOU_ENAB, CTRL_WRITE_MOUSE)) - { - WARN_(I8042PRT, "Failed to enable mouse!\n"); - return STATUS_IO_DEVICE_ERROR; - } + /* Enable the mouse */ + if(!i8042IsrWritePort(DeviceExtension->Common.PortDeviceExtension, MOU_ENAB, CTRL_WRITE_MOUSE)) + { + WARN_(I8042PRT, "Failed to enable mouse!\n"); + return STATUS_IO_DEVICE_ERROR; + } - Status = i8042ReadDataWait(DeviceExtension->Common.PortDeviceExtension, &Value); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "Failed to read the response of MOU_ENAB, status 0x%08lx\n", Status); - return Status; - } + Status = i8042ReadDataWait(DeviceExtension->Common.PortDeviceExtension, &Value); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "Failed to read the response of MOU_ENAB, status 0x%08lx\n", Status); + return Status; + } - if(Value == MOUSE_ACK) - { - INFO_(I8042PRT, "Mouse was enabled successfully!\n"); - return STATUS_SUCCESS; - } + if(Value == MOUSE_ACK) + { + INFO_(I8042PRT, "Mouse was enabled successfully!\n"); + return STATUS_SUCCESS; + } - WARN_(I8042PRT, "Got 0x%02x instead of 0xFA\n", Value); - return STATUS_IO_DEVICE_ERROR; + WARN_(I8042PRT, "Got 0x%02x instead of 0xFA\n", Value); + return STATUS_IO_DEVICE_ERROR; } static VOID NTAPI -i8042MouDpcRoutine(IN PKDPC Dpc, - IN PVOID DeferredContext, - IN PVOID SystemArgument1, - IN PVOID SystemArgument2) +i8042MouDpcRoutine( + IN PKDPC Dpc, + IN PVOID DeferredContext, + IN PVOID SystemArgument1, + IN PVOID SystemArgument2) { - PI8042_MOUSE_EXTENSION DeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; - ULONG MouseTransferred = 0; - ULONG MouseInBufferCopy; - KIRQL Irql; - LARGE_INTEGER Timeout; + PI8042_MOUSE_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + ULONG MouseTransferred = 0; + ULONG MouseInBufferCopy; + KIRQL Irql; + LARGE_INTEGER Timeout; - DeviceExtension = (PI8042_MOUSE_EXTENSION)DeferredContext; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + DeviceExtension = (PI8042_MOUSE_EXTENSION)DeferredContext; + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - switch (DeviceExtension->MouseTimeoutState) - { - case TimeoutStart: - { - DeviceExtension->MouseTimeoutState = NoChange; - if (DeviceExtension->MouseTimeoutActive && - !KeCancelTimer(&DeviceExtension->TimerMouseTimeout)) - { - /* The timer fired already, give up */ - DeviceExtension->MouseTimeoutActive = FALSE; - return; - } + switch (DeviceExtension->MouseTimeoutState) + { + case TimeoutStart: + { + DeviceExtension->MouseTimeoutState = NoChange; + if (DeviceExtension->MouseTimeoutActive && + !KeCancelTimer(&DeviceExtension->TimerMouseTimeout)) + { + /* The timer fired already, give up */ + DeviceExtension->MouseTimeoutActive = FALSE; + return; + } - Timeout.QuadPart = -15000000; /* 1.5 seconds, should be enough */ + Timeout.QuadPart = -15000000; /* 1.5 seconds, should be enough */ - KeSetTimer( - &DeviceExtension->TimerMouseTimeout, - Timeout, - &DeviceExtension->DpcMouseTimeout); - DeviceExtension->MouseTimeoutActive = TRUE; - return; - } + KeSetTimer( + &DeviceExtension->TimerMouseTimeout, + Timeout, + &DeviceExtension->DpcMouseTimeout); + DeviceExtension->MouseTimeoutActive = TRUE; + return; + } - case TimeoutCancel: - { - DeviceExtension->MouseTimeoutState = NoChange; - KeCancelTimer(&DeviceExtension->TimerMouseTimeout); - DeviceExtension->MouseTimeoutActive = FALSE; - } + case TimeoutCancel: + { + DeviceExtension->MouseTimeoutState = NoChange; + KeCancelTimer(&DeviceExtension->TimerMouseTimeout); + DeviceExtension->MouseTimeoutActive = FALSE; + } - default: - ;/* nothing, don't want a warning */ - } + default: + ;/* nothing, don't want a warning */ + } - /* Should be unlikely */ - if (!DeviceExtension->MouseComplete) - return; + /* Should be unlikely */ + if (!DeviceExtension->MouseComplete) + return; - Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); + Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); - DeviceExtension->MouseComplete = FALSE; - MouseInBufferCopy = DeviceExtension->MouseInBuffer; + DeviceExtension->MouseComplete = FALSE; + MouseInBufferCopy = DeviceExtension->MouseInBuffer; - KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); + KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); - TRACE_(I8042PRT, "Send a mouse packet\n"); + TRACE_(I8042PRT, "Send a mouse packet\n"); - if (!DeviceExtension->MouseData.ClassService) - return; + if (!DeviceExtension->MouseData.ClassService) + return; - INFO_(I8042PRT, "Sending %lu mouse move(s)\n", MouseInBufferCopy); - (*(PSERVICE_CALLBACK_ROUTINE)DeviceExtension->MouseData.ClassService)( - DeviceExtension->MouseData.ClassDeviceObject, - DeviceExtension->MouseBuffer, - DeviceExtension->MouseBuffer + MouseInBufferCopy, - &MouseTransferred); + INFO_(I8042PRT, "Sending %lu mouse move(s)\n", MouseInBufferCopy); + (*(PSERVICE_CALLBACK_ROUTINE)DeviceExtension->MouseData.ClassService)( + DeviceExtension->MouseData.ClassDeviceObject, + DeviceExtension->MouseBuffer, + DeviceExtension->MouseBuffer + MouseInBufferCopy, + &MouseTransferred); - Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); - DeviceExtension->MouseInBuffer -= MouseTransferred; - if (DeviceExtension->MouseInBuffer) - RtlMoveMemory( - DeviceExtension->MouseBuffer, - DeviceExtension->MouseBuffer + MouseTransferred, - DeviceExtension->MouseInBuffer * sizeof(MOUSE_INPUT_DATA)); - KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); + Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); + DeviceExtension->MouseInBuffer -= MouseTransferred; + if (DeviceExtension->MouseInBuffer) + RtlMoveMemory( + DeviceExtension->MouseBuffer, + DeviceExtension->MouseBuffer + MouseTransferred, + DeviceExtension->MouseInBuffer * sizeof(MOUSE_INPUT_DATA)); + KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); } /* This timer DPC will be called when the mouse reset times out. -* I'll just send the 'disable mouse port' command to the controller -* and say the mouse doesn't exist. -*/ + * I'll just send the 'disable mouse port' command to the controller + * and say the mouse doesn't exist. + */ static VOID NTAPI -i8042DpcRoutineMouseTimeout(IN PKDPC Dpc, - IN PVOID DeferredContext, - IN PVOID SystemArgument1, - IN PVOID SystemArgument2) +i8042DpcRoutineMouseTimeout( + IN PKDPC Dpc, + IN PVOID DeferredContext, + IN PVOID SystemArgument1, + IN PVOID SystemArgument2) { - PI8042_MOUSE_EXTENSION DeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; - KIRQL Irql; + PI8042_MOUSE_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + KIRQL Irql; - DeviceExtension = (PI8042_MOUSE_EXTENSION)DeferredContext; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + DeviceExtension = (PI8042_MOUSE_EXTENSION)DeferredContext; + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); + Irql = KeAcquireInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt); - WARN_(I8042PRT, "Mouse initialization timeout! (substate %x). Disabling mouse.\n", - DeviceExtension->MouseResetState); + WARN_(I8042PRT, "Mouse initialization timeout! (substate %x). Disabling mouse.\n", + DeviceExtension->MouseResetState); - i8042Flush(PortDeviceExtension); - i8042ChangeMode(PortDeviceExtension, CCB_MOUSE_INT_ENAB, CCB_MOUSE_DISAB); - i8042Flush(PortDeviceExtension); + i8042Flush(PortDeviceExtension); + i8042ChangeMode(PortDeviceExtension, CCB_MOUSE_INT_ENAB, CCB_MOUSE_DISAB); + i8042Flush(PortDeviceExtension); - PortDeviceExtension->Flags &= ~MOUSE_PRESENT; + PortDeviceExtension->Flags &= ~MOUSE_PRESENT; - KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); + KeReleaseInterruptSpinLock(PortDeviceExtension->HighestDIRQLInterrupt, Irql); } /* -* Runs the mouse IOCTL_INTERNAL dispatch. -*/ + * Runs the mouse IOCTL_INTERNAL dispatch. + */ NTSTATUS NTAPI -i8042MouInternalDeviceControl(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042MouInternalDeviceControl( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PIO_STACK_LOCATION Stack; - PI8042_MOUSE_EXTENSION DeviceExtension; - NTSTATUS Status; + PIO_STACK_LOCATION Stack; + PI8042_MOUSE_EXTENSION DeviceExtension; + NTSTATUS Status; - Stack = IoGetCurrentIrpStackLocation(Irp); - Irp->IoStatus.Information = 0; - DeviceExtension = (PI8042_MOUSE_EXTENSION)DeviceObject->DeviceExtension; + Stack = IoGetCurrentIrpStackLocation(Irp); + Irp->IoStatus.Information = 0; + DeviceExtension = (PI8042_MOUSE_EXTENSION)DeviceObject->DeviceExtension; - switch (Stack->Parameters.DeviceIoControl.IoControlCode) - { - case IOCTL_INTERNAL_MOUSE_CONNECT: - { - SIZE_T Size; - PIO_WORKITEM WorkItem = NULL; - PI8042_HOOK_WORKITEM WorkItemData = NULL; + switch (Stack->Parameters.DeviceIoControl.IoControlCode) + { + case IOCTL_INTERNAL_MOUSE_CONNECT: + { + SIZE_T Size; + PIO_WORKITEM WorkItem = NULL; + PI8042_HOOK_WORKITEM WorkItemData = NULL; - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_MOUSE_CONNECT\n"); - if (Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(CONNECT_DATA)) - { - Status = STATUS_INVALID_PARAMETER; - goto cleanup; - } + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_MOUSE_CONNECT\n"); + if (Stack->Parameters.DeviceIoControl.InputBufferLength != sizeof(CONNECT_DATA)) + { + Status = STATUS_INVALID_PARAMETER; + goto cleanup; + } - DeviceExtension->MouseData = - *((PCONNECT_DATA)Stack->Parameters.DeviceIoControl.Type3InputBuffer); + DeviceExtension->MouseData = + *((PCONNECT_DATA)Stack->Parameters.DeviceIoControl.Type3InputBuffer); - /* Send IOCTL_INTERNAL_I8042_HOOK_MOUSE to device stack */ - WorkItem = IoAllocateWorkItem(DeviceObject); - if (!WorkItem) - { - WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); - Status = STATUS_INSUFFICIENT_RESOURCES; - goto cleanup; - } - WorkItemData = ExAllocatePoolWithTag( - NonPagedPool, - sizeof(I8042_HOOK_WORKITEM), - I8042PRT_TAG); - if (!WorkItemData) - { - WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - WorkItemData->WorkItem = WorkItem; - WorkItemData->Irp = Irp; + /* Send IOCTL_INTERNAL_I8042_HOOK_MOUSE to device stack */ + WorkItem = IoAllocateWorkItem(DeviceObject); + if (!WorkItem) + { + WARN_(I8042PRT, "IoAllocateWorkItem() failed\n"); + Status = STATUS_INSUFFICIENT_RESOURCES; + goto cleanup; + } + WorkItemData = ExAllocatePoolWithTag( + NonPagedPool, + sizeof(I8042_HOOK_WORKITEM), + I8042PRT_TAG); + if (!WorkItemData) + { + WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + WorkItemData->WorkItem = WorkItem; + WorkItemData->Irp = Irp; - /* Initialize extension */ - DeviceExtension->Common.Type = Mouse; - Size = DeviceExtension->Common.PortDeviceExtension->Settings.MouseDataQueueSize * sizeof(MOUSE_INPUT_DATA); - DeviceExtension->MouseBuffer = ExAllocatePoolWithTag( - NonPagedPool, - Size, - I8042PRT_TAG); - if (!DeviceExtension->MouseBuffer) - { - WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - RtlZeroMemory(DeviceExtension->MouseBuffer, Size); - DeviceExtension->MouseAttributes.InputDataQueueLength = - DeviceExtension->Common.PortDeviceExtension->Settings.MouseDataQueueSize; - KeInitializeDpc( - &DeviceExtension->DpcMouse, - i8042MouDpcRoutine, - DeviceExtension); - KeInitializeDpc( - &DeviceExtension->DpcMouseTimeout, - i8042DpcRoutineMouseTimeout, - DeviceExtension); - KeInitializeTimer(&DeviceExtension->TimerMouseTimeout); - DeviceExtension->Common.PortDeviceExtension->MouseExtension = DeviceExtension; - DeviceExtension->Common.PortDeviceExtension->Flags |= MOUSE_CONNECTED; + /* Initialize extension */ + DeviceExtension->Common.Type = Mouse; + Size = DeviceExtension->Common.PortDeviceExtension->Settings.MouseDataQueueSize * sizeof(MOUSE_INPUT_DATA); + DeviceExtension->MouseBuffer = ExAllocatePoolWithTag( + NonPagedPool, + Size, + I8042PRT_TAG); + if (!DeviceExtension->MouseBuffer) + { + WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + RtlZeroMemory(DeviceExtension->MouseBuffer, Size); + DeviceExtension->MouseAttributes.InputDataQueueLength = + DeviceExtension->Common.PortDeviceExtension->Settings.MouseDataQueueSize; + KeInitializeDpc( + &DeviceExtension->DpcMouse, + i8042MouDpcRoutine, + DeviceExtension); + KeInitializeDpc( + &DeviceExtension->DpcMouseTimeout, + i8042DpcRoutineMouseTimeout, + DeviceExtension); + KeInitializeTimer(&DeviceExtension->TimerMouseTimeout); + DeviceExtension->Common.PortDeviceExtension->MouseExtension = DeviceExtension; + DeviceExtension->Common.PortDeviceExtension->Flags |= MOUSE_CONNECTED; - IoMarkIrpPending(Irp); - DeviceExtension->MouseState = MouseResetting; - DeviceExtension->MouseResetState = 1100; - DeviceExtension->MouseHook.IsrWritePort = i8042MouIsrWritePort; - DeviceExtension->MouseHook.QueueMousePacket = i8042MouQueuePacket; - DeviceExtension->MouseHook.CallContext = DeviceExtension; - IoQueueWorkItem(WorkItem, - i8042SendHookWorkItem, - DelayedWorkQueue, - WorkItemData); - Status = STATUS_PENDING; - break; + IoMarkIrpPending(Irp); + DeviceExtension->MouseState = MouseResetting; + DeviceExtension->MouseResetState = 1100; + DeviceExtension->MouseHook.IsrWritePort = i8042MouIsrWritePort; + DeviceExtension->MouseHook.QueueMousePacket = i8042MouQueuePacket; + DeviceExtension->MouseHook.CallContext = DeviceExtension; + IoQueueWorkItem(WorkItem, + i8042SendHookWorkItem, + DelayedWorkQueue, + WorkItemData); + Status = STATUS_PENDING; + break; cleanup: - if (DeviceExtension->MouseBuffer) - ExFreePoolWithTag(DeviceExtension->MouseBuffer, I8042PRT_TAG); - if (WorkItem) - IoFreeWorkItem(WorkItem); - if (WorkItemData) - ExFreePoolWithTag(WorkItemData, I8042PRT_TAG); - break; - } - case IOCTL_INTERNAL_MOUSE_DISCONNECT: - { - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_MOUSE_DISCONNECT\n"); - /* MSDN says that operation is to implemented. - * To implement it, we just have to do: - * DeviceExtension->MouseData.ClassService = NULL; - */ - Status = STATUS_NOT_IMPLEMENTED; - break; - } - case IOCTL_INTERNAL_I8042_HOOK_MOUSE: - { - TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_I8042_HOOK_MOUSE\n"); - /* Nothing to do here */ - Status = STATUS_SUCCESS; - break; - } - default: - { - ERR_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / unknown ioctl code 0x%lx\n", - Stack->Parameters.DeviceIoControl.IoControlCode); - ASSERT(FALSE); - return ForwardIrpAndForget(DeviceObject, Irp); - } - } + if (DeviceExtension->MouseBuffer) + ExFreePoolWithTag(DeviceExtension->MouseBuffer, I8042PRT_TAG); + if (WorkItem) + IoFreeWorkItem(WorkItem); + if (WorkItemData) + ExFreePoolWithTag(WorkItemData, I8042PRT_TAG); + break; + } + case IOCTL_INTERNAL_MOUSE_DISCONNECT: + { + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_MOUSE_DISCONNECT\n"); + /* MSDN says that operation is to implemented. + * To implement it, we just have to do: + * DeviceExtension->MouseData.ClassService = NULL; + */ + Status = STATUS_NOT_IMPLEMENTED; + break; + } + case IOCTL_INTERNAL_I8042_HOOK_MOUSE: + { + TRACE_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / IOCTL_INTERNAL_I8042_HOOK_MOUSE\n"); + /* Nothing to do here */ + Status = STATUS_SUCCESS; + break; + } + default: + { + ERR_(I8042PRT, "IRP_MJ_INTERNAL_DEVICE_CONTROL / unknown ioctl code 0x%lx\n", + Stack->Parameters.DeviceIoControl.IoControlCode); + ASSERT(FALSE); + return ForwardIrpAndForget(DeviceObject, Irp); + } + } - Irp->IoStatus.Status = Status; - if (Status != STATUS_PENDING) - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return Status; + Irp->IoStatus.Status = Status; + if (Status != STATUS_PENDING) + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return Status; } /* Test if packets are taking too long to come in. If they do, we -* might have gotten out of sync and should just drop what we have. -* -* If we want to be totally right, we'd also have to keep a count of -* errors, and totally reset the mouse after too much of them (can -* happen if the user is using a KVM switch and an OS on another port -* resets the mouse, or if the user hotplugs the mouse, or if we're just -* generally unlucky). Also note the input parsing routine where we -* drop invalid input packets. -*/ + * might have gotten out of sync and should just drop what we have. + * + * If we want to be totally right, we'd also have to keep a count of + * errors, and totally reset the mouse after too much of them (can + * happen if the user is using a KVM switch and an OS on another port + * resets the mouse, or if the user hotplugs the mouse, or if we're just + * generally unlucky). Also note the input parsing routine where we + * drop invalid input packets. + */ static VOID -i8042MouInputTestTimeout(IN PI8042_MOUSE_EXTENSION DeviceExtension) +i8042MouInputTestTimeout( + IN PI8042_MOUSE_EXTENSION DeviceExtension) { - ULARGE_INTEGER Now; + ULARGE_INTEGER Now; - if (DeviceExtension->MouseState == MouseExpectingACK || - DeviceExtension->MouseState == MouseResetting) - return; + if (DeviceExtension->MouseState == MouseExpectingACK || + DeviceExtension->MouseState == MouseResetting) + return; - Now.QuadPart = KeQueryInterruptTime(); + Now.QuadPart = KeQueryInterruptTime(); - if (DeviceExtension->MouseState != MouseIdle) { - /* Check if the last byte came too long ago */ - if (Now.QuadPart - DeviceExtension->MousePacketStartTime.QuadPart > - DeviceExtension->Common.PortDeviceExtension->Settings.MouseSynchIn100ns) - { - WARN_(I8042PRT, "Mouse input packet timeout\n"); - DeviceExtension->MouseState = MouseIdle; - } - } + if (DeviceExtension->MouseState != MouseIdle) { + /* Check if the last byte came too long ago */ + if (Now.QuadPart - DeviceExtension->MousePacketStartTime.QuadPart > + DeviceExtension->Common.PortDeviceExtension->Settings.MouseSynchIn100ns) + { + WARN_(I8042PRT, "Mouse input packet timeout\n"); + DeviceExtension->MouseState = MouseIdle; + } + } - if (DeviceExtension->MouseState == MouseIdle) - DeviceExtension->MousePacketStartTime.QuadPart = Now.QuadPart; + if (DeviceExtension->MouseState == MouseIdle) + DeviceExtension->MousePacketStartTime.QuadPart = Now.QuadPart; } /* -* Call the customization hook. The ToReturn parameter is about wether -* we should go on with the interrupt. The return value is what -* we should return (indicating to the system wether someone else -* should try to handle the interrupt) -*/ + * Call the customization hook. The ToReturn parameter is about wether + * we should go on with the interrupt. The return value is what + * we should return (indicating to the system wether someone else + * should try to handle the interrupt) + */ static BOOLEAN -i8042MouCallIsrHook(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN UCHAR Status, - IN UCHAR Input, - OUT PBOOLEAN ToReturn) +i8042MouCallIsrHook( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN UCHAR Status, + IN UCHAR Input, + OUT PBOOLEAN ToReturn) { - BOOLEAN HookReturn, HookContinue; + BOOLEAN HookReturn, HookContinue; - HookContinue = FALSE; + HookContinue = FALSE; - if (DeviceExtension->MouseHook.IsrRoutine) - { - HookReturn = DeviceExtension->MouseHook.IsrRoutine( - DeviceExtension->MouseHook.Context, - DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer, - &DeviceExtension->Common.PortDeviceExtension->Packet, - Status, - &Input, - &HookContinue, - &DeviceExtension->MouseState, - &DeviceExtension->MouseResetState); + if (DeviceExtension->MouseHook.IsrRoutine) + { + HookReturn = DeviceExtension->MouseHook.IsrRoutine( + DeviceExtension->MouseHook.Context, + DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer, + &DeviceExtension->Common.PortDeviceExtension->Packet, + Status, + &Input, + &HookContinue, + &DeviceExtension->MouseState, + &DeviceExtension->MouseResetState); - if (!HookContinue) - { - *ToReturn = HookReturn; - return TRUE; - } - } - return FALSE; + if (!HookContinue) + { + *ToReturn = HookReturn; + return TRUE; + } + } + return FALSE; } static BOOLEAN -i8042MouResetIsr(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN UCHAR Status, - IN UCHAR Value) +i8042MouResetIsr( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN UCHAR Status, + IN UCHAR Value) { - PPORT_DEVICE_EXTENSION PortDeviceExtension; - BOOLEAN ToReturn = FALSE; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + BOOLEAN ToReturn = FALSE; - if (i8042MouCallIsrHook(DeviceExtension, Status, Value, &ToReturn)) - return ToReturn; + if (i8042MouCallIsrHook(DeviceExtension, Status, Value, &ToReturn)) + return ToReturn; - if (MouseResetting != DeviceExtension->MouseState) - return FALSE; - DeviceExtension->MouseTimeoutState = TimeoutStart; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + if (MouseResetting != DeviceExtension->MouseState) + return FALSE; + DeviceExtension->MouseTimeoutState = TimeoutStart; + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - switch (DeviceExtension->MouseResetState) - { - case 1100: /* the first ack, drop it. */ - DeviceExtension->MouseResetState = ExpectingReset; - return TRUE; - case ExpectingReset: - /* First, 0xFF is sent. The mouse is supposed to say AA00 if ok, FC00 if not. */ - if (0xAA == Value) - { - DeviceExtension->MouseResetState++; - } - else - { - PortDeviceExtension->Flags &= ~MOUSE_PRESENT; - DeviceExtension->MouseState = MouseIdle; - WARN_(I8042PRT, "Mouse returned bad reset reply: %x (expected aa)\n", Value); - } - return TRUE; - case ExpectingResetId: - if (0x00 == Value) - { - DeviceExtension->MouseResetState++; - DeviceExtension->MouseType = GenericPS2; - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF2); - } - else - { - PortDeviceExtension->Flags &= ~MOUSE_PRESENT; - DeviceExtension->MouseState = MouseIdle; - WARN_(I8042PRT, "Mouse returned bad reset reply part two: %x (expected 0)\n", Value); - } - return TRUE; - case ExpectingGetDeviceIdACK: - if (MOUSE_ACK == Value) - { - DeviceExtension->MouseResetState++; - } - else if (MOUSE_NACK == Value || MOUSE_ERROR == Value) - { - DeviceExtension->MouseResetState++; - /* Act as if 00 (normal mouse) was received */ - WARN_(I8042PRT, "Mouse doesn't support 0xd2, (returns %x, expected %x), faking\n", Value, MOUSE_ACK); - i8042MouResetIsr(DeviceExtension, Status, 0); - } - return TRUE; - case ExpectingGetDeviceIdValue: - switch (Value) - { - case 0x02: - DeviceExtension->MouseAttributes.MouseIdentifier = - BALLPOINT_I8042_HARDWARE; - break; - case 0x03: - case 0x04: - DeviceExtension->MouseAttributes.MouseIdentifier = - WHEELMOUSE_I8042_HARDWARE; - break; - default: - DeviceExtension->MouseAttributes.MouseIdentifier = - MOUSE_I8042_HARDWARE; - } - DeviceExtension->MouseResetState++; - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE8); - return TRUE; - case ExpectingSetResolutionDefaultACK: - DeviceExtension->MouseResetState++; - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x00); - return TRUE; - case ExpectingSetResolutionDefaultValueACK: - DeviceExtension->MouseResetState = ExpectingSetScaling1to1ACK; - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE6); - return TRUE; - case ExpectingSetScaling1to1ACK: - case ExpectingSetScaling1to1ACK2: - DeviceExtension->MouseResetState++; - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE6); - return TRUE; - case ExpectingSetScaling1to1ACK3: - DeviceExtension->MouseResetState++; - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE9); - return TRUE; - case ExpectingReadMouseStatusACK: - DeviceExtension->MouseResetState++; - return TRUE; - case ExpectingReadMouseStatusByte1: - DeviceExtension->MouseLogiBuffer[0] = Value; - DeviceExtension->MouseResetState++; - return TRUE; - case ExpectingReadMouseStatusByte2: - DeviceExtension->MouseLogiBuffer[1] = Value; - DeviceExtension->MouseResetState++; - return TRUE; - case ExpectingReadMouseStatusByte3: - DeviceExtension->MouseLogiBuffer[2] = Value; - /* Now MouseLogiBuffer is a set of info. If the second - * byte is 0, the mouse didn't understand the magic - * code. Otherwise, it it a Logitech and the second byte - * is the number of buttons, bit 7 of the first byte tells - * if it understands special E7 commands, the rest is an ID. - */ - if (DeviceExtension->MouseLogiBuffer[1]) - { - DeviceExtension->MouseAttributes.NumberOfButtons = - DeviceExtension->MouseLogiBuffer[1]; - DeviceExtension->MouseType = Ps2pp; - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); - DeviceExtension->MouseResetState = ExpectingSetSamplingRateACK; - /* TODO: Go through EnableWheel and Enable5Buttons */ - return TRUE; - } - DeviceExtension->MouseResetState = EnableWheel; - i8042MouResetIsr(DeviceExtension, Status, Value); - return TRUE; - case EnableWheel: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); - DeviceExtension->MouseResetState = 1001; - return TRUE; - case 1001: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xC8); - DeviceExtension->MouseResetState++; - return TRUE; - case 1002: - case 1004: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); - DeviceExtension->MouseResetState++; - return TRUE; - case 1003: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x64); - DeviceExtension->MouseResetState++; - return TRUE; - case 1005: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x50); - DeviceExtension->MouseResetState++; - return TRUE; - case 1006: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF2); - DeviceExtension->MouseResetState++; - return TRUE; - case 1007: - /* Ignore ACK */ - DeviceExtension->MouseResetState++; - return TRUE; - case 1008: - if (0x03 == Value) { - /* It's either an Intellimouse or Intellimouse Explorer. */ - DeviceExtension->MouseAttributes.NumberOfButtons = 3; - DeviceExtension->MouseAttributes.MouseIdentifier = - WHEELMOUSE_I8042_HARDWARE; - DeviceExtension->MouseType = Intellimouse; - DeviceExtension->MouseResetState = Enable5Buttons; - i8042MouResetIsr(DeviceExtension, Status, Value); - } - else - { - /* Just set the default settings and be done */ - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); - DeviceExtension->MouseResetState = ExpectingSetSamplingRateACK; - } - return TRUE; - case Enable5Buttons: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); - DeviceExtension->MouseResetState = 1021; - return TRUE; - case 1022: - case 1024: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); - DeviceExtension->MouseResetState++; - return TRUE; - case 1021: - case 1023: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xC8); - DeviceExtension->MouseResetState++; - return TRUE; - case 1025: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x50); - DeviceExtension->MouseResetState++; - return TRUE; - case 1026: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF2); - DeviceExtension->MouseResetState++; - return TRUE; - case 1027: - if (0x04 == Value) - { - DeviceExtension->MouseAttributes.NumberOfButtons = 5; - DeviceExtension->MouseAttributes.MouseIdentifier = - WHEELMOUSE_I8042_HARDWARE; - DeviceExtension->MouseType = IntellimouseExplorer; - } - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); - DeviceExtension->MouseResetState = ExpectingSetSamplingRateACK; - return TRUE; - case ExpectingSetSamplingRateACK: - DeviceExtension->MouseHook.IsrWritePort( - DeviceExtension->MouseHook.CallContext, - (UCHAR)DeviceExtension->MouseAttributes.SampleRate); - DeviceExtension->MouseResetState++; - return TRUE; - case ExpectingSetSamplingRateValueACK: - if (MOUSE_NACK == Value) - { - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x3C); - DeviceExtension->MouseAttributes.SampleRate = (USHORT)PortDeviceExtension->Settings.SampleRate; - DeviceExtension->MouseResetState = 1040; - return TRUE; - } - case 1040: /* Fallthrough */ - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE8); - DeviceExtension->MouseResetState = ExpectingFinalResolutionACK; - return TRUE; - case ExpectingFinalResolutionACK: - DeviceExtension->MouseHook.IsrWritePort( - DeviceExtension->MouseHook.CallContext, - (UCHAR)(PortDeviceExtension->Settings.MouseResolution & 0xff)); - INFO_(I8042PRT, "Mouse resolution %lu\n", - PortDeviceExtension->Settings.MouseResolution); - DeviceExtension->MouseResetState = ExpectingFinalResolutionValueACK; - return TRUE; - case ExpectingFinalResolutionValueACK: - DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF4); - DeviceExtension->MouseResetState = ExpectingEnableACK; - return TRUE; - case ExpectingEnableACK: - DeviceExtension->MouseState = MouseIdle; - DeviceExtension->MouseTimeoutState = TimeoutCancel; - INFO_(I8042PRT, "Mouse type = %u\n", DeviceExtension->MouseType); - return TRUE; - default: - if (DeviceExtension->MouseResetState < 100 || DeviceExtension->MouseResetState > 999) - ERR_(I8042PRT, "MouseResetState went out of range: %lu\n", DeviceExtension->MouseResetState); - return FALSE; - } + switch (DeviceExtension->MouseResetState) + { + case 1100: /* the first ack, drop it. */ + DeviceExtension->MouseResetState = ExpectingReset; + return TRUE; + case ExpectingReset: + /* First, 0xFF is sent. The mouse is supposed to say AA00 if ok, FC00 if not. */ + if (0xAA == Value) + { + DeviceExtension->MouseResetState++; + } + else + { + PortDeviceExtension->Flags &= ~MOUSE_PRESENT; + DeviceExtension->MouseState = MouseIdle; + WARN_(I8042PRT, "Mouse returned bad reset reply: %x (expected aa)\n", Value); + } + return TRUE; + case ExpectingResetId: + if (0x00 == Value) + { + DeviceExtension->MouseResetState++; + DeviceExtension->MouseType = GenericPS2; + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF2); + } + else + { + PortDeviceExtension->Flags &= ~MOUSE_PRESENT; + DeviceExtension->MouseState = MouseIdle; + WARN_(I8042PRT, "Mouse returned bad reset reply part two: %x (expected 0)\n", Value); + } + return TRUE; + case ExpectingGetDeviceIdACK: + if (MOUSE_ACK == Value) + { + DeviceExtension->MouseResetState++; + } + else if (MOUSE_NACK == Value || MOUSE_ERROR == Value) + { + DeviceExtension->MouseResetState++; + /* Act as if 00 (normal mouse) was received */ + WARN_(I8042PRT, "Mouse doesn't support 0xd2, (returns %x, expected %x), faking\n", Value, MOUSE_ACK); + i8042MouResetIsr(DeviceExtension, Status, 0); + } + return TRUE; + case ExpectingGetDeviceIdValue: + switch (Value) + { + case 0x02: + DeviceExtension->MouseAttributes.MouseIdentifier = + BALLPOINT_I8042_HARDWARE; + break; + case 0x03: + case 0x04: + DeviceExtension->MouseAttributes.MouseIdentifier = + WHEELMOUSE_I8042_HARDWARE; + break; + default: + DeviceExtension->MouseAttributes.MouseIdentifier = + MOUSE_I8042_HARDWARE; + } + DeviceExtension->MouseResetState++; + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE8); + return TRUE; + case ExpectingSetResolutionDefaultACK: + DeviceExtension->MouseResetState++; + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x00); + return TRUE; + case ExpectingSetResolutionDefaultValueACK: + DeviceExtension->MouseResetState = ExpectingSetScaling1to1ACK; + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE6); + return TRUE; + case ExpectingSetScaling1to1ACK: + case ExpectingSetScaling1to1ACK2: + DeviceExtension->MouseResetState++; + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE6); + return TRUE; + case ExpectingSetScaling1to1ACK3: + DeviceExtension->MouseResetState++; + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE9); + return TRUE; + case ExpectingReadMouseStatusACK: + DeviceExtension->MouseResetState++; + return TRUE; + case ExpectingReadMouseStatusByte1: + DeviceExtension->MouseLogiBuffer[0] = Value; + DeviceExtension->MouseResetState++; + return TRUE; + case ExpectingReadMouseStatusByte2: + DeviceExtension->MouseLogiBuffer[1] = Value; + DeviceExtension->MouseResetState++; + return TRUE; + case ExpectingReadMouseStatusByte3: + DeviceExtension->MouseLogiBuffer[2] = Value; + /* Now MouseLogiBuffer is a set of info. If the second + * byte is 0, the mouse didn't understand the magic + * code. Otherwise, it it a Logitech and the second byte + * is the number of buttons, bit 7 of the first byte tells + * if it understands special E7 commands, the rest is an ID. + */ + if (DeviceExtension->MouseLogiBuffer[1]) + { + DeviceExtension->MouseAttributes.NumberOfButtons = + DeviceExtension->MouseLogiBuffer[1]; + DeviceExtension->MouseType = Ps2pp; + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); + DeviceExtension->MouseResetState = ExpectingSetSamplingRateACK; + /* TODO: Go through EnableWheel and Enable5Buttons */ + return TRUE; + } + DeviceExtension->MouseResetState = EnableWheel; + i8042MouResetIsr(DeviceExtension, Status, Value); + return TRUE; + case EnableWheel: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); + DeviceExtension->MouseResetState = 1001; + return TRUE; + case 1001: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xC8); + DeviceExtension->MouseResetState++; + return TRUE; + case 1002: + case 1004: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); + DeviceExtension->MouseResetState++; + return TRUE; + case 1003: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x64); + DeviceExtension->MouseResetState++; + return TRUE; + case 1005: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x50); + DeviceExtension->MouseResetState++; + return TRUE; + case 1006: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF2); + DeviceExtension->MouseResetState++; + return TRUE; + case 1007: + /* Ignore ACK */ + DeviceExtension->MouseResetState++; + return TRUE; + case 1008: + if (0x03 == Value) { + /* It's either an Intellimouse or Intellimouse Explorer. */ + DeviceExtension->MouseAttributes.NumberOfButtons = 3; + DeviceExtension->MouseAttributes.MouseIdentifier = + WHEELMOUSE_I8042_HARDWARE; + DeviceExtension->MouseType = Intellimouse; + DeviceExtension->MouseResetState = Enable5Buttons; + i8042MouResetIsr(DeviceExtension, Status, Value); + } + else + { + /* Just set the default settings and be done */ + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); + DeviceExtension->MouseResetState = ExpectingSetSamplingRateACK; + } + return TRUE; + case Enable5Buttons: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); + DeviceExtension->MouseResetState = 1021; + return TRUE; + case 1022: + case 1024: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); + DeviceExtension->MouseResetState++; + return TRUE; + case 1021: + case 1023: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xC8); + DeviceExtension->MouseResetState++; + return TRUE; + case 1025: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x50); + DeviceExtension->MouseResetState++; + return TRUE; + case 1026: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF2); + DeviceExtension->MouseResetState++; + return TRUE; + case 1027: + if (0x04 == Value) + { + DeviceExtension->MouseAttributes.NumberOfButtons = 5; + DeviceExtension->MouseAttributes.MouseIdentifier = + WHEELMOUSE_I8042_HARDWARE; + DeviceExtension->MouseType = IntellimouseExplorer; + } + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF3); + DeviceExtension->MouseResetState = ExpectingSetSamplingRateACK; + return TRUE; + case ExpectingSetSamplingRateACK: + DeviceExtension->MouseHook.IsrWritePort( + DeviceExtension->MouseHook.CallContext, + (UCHAR)DeviceExtension->MouseAttributes.SampleRate); + DeviceExtension->MouseResetState++; + return TRUE; + case ExpectingSetSamplingRateValueACK: + if (MOUSE_NACK == Value) + { + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0x3C); + DeviceExtension->MouseAttributes.SampleRate = (USHORT)PortDeviceExtension->Settings.SampleRate; + DeviceExtension->MouseResetState = 1040; + return TRUE; + } + case 1040: /* Fallthrough */ + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xE8); + DeviceExtension->MouseResetState = ExpectingFinalResolutionACK; + return TRUE; + case ExpectingFinalResolutionACK: + DeviceExtension->MouseHook.IsrWritePort( + DeviceExtension->MouseHook.CallContext, + (UCHAR)(PortDeviceExtension->Settings.MouseResolution & 0xff)); + INFO_(I8042PRT, "Mouse resolution %lu\n", + PortDeviceExtension->Settings.MouseResolution); + DeviceExtension->MouseResetState = ExpectingFinalResolutionValueACK; + return TRUE; + case ExpectingFinalResolutionValueACK: + DeviceExtension->MouseHook.IsrWritePort(DeviceExtension->MouseHook.CallContext, 0xF4); + DeviceExtension->MouseResetState = ExpectingEnableACK; + return TRUE; + case ExpectingEnableACK: + DeviceExtension->MouseState = MouseIdle; + DeviceExtension->MouseTimeoutState = TimeoutCancel; + INFO_(I8042PRT, "Mouse type = %u\n", DeviceExtension->MouseType); + return TRUE; + default: + if (DeviceExtension->MouseResetState < 100 || DeviceExtension->MouseResetState > 999) + ERR_(I8042PRT, "MouseResetState went out of range: %lu\n", DeviceExtension->MouseResetState); + return FALSE; + } } BOOLEAN NTAPI -i8042MouInterruptService(IN PKINTERRUPT Interrupt, - PVOID Context) +i8042MouInterruptService( + IN PKINTERRUPT Interrupt, + PVOID Context) { - PI8042_MOUSE_EXTENSION DeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; - ULONG Counter; - UCHAR Output, PortStatus; - NTSTATUS Status; + PI8042_MOUSE_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + ULONG Counter; + UCHAR Output, PortStatus; + NTSTATUS Status; - DeviceExtension = (PI8042_MOUSE_EXTENSION)Context; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - Counter = PortDeviceExtension->Settings.PollStatusIterations; + DeviceExtension = (PI8042_MOUSE_EXTENSION)Context; + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + Counter = PortDeviceExtension->Settings.PollStatusIterations; - while (Counter) - { - Status = i8042ReadStatus(PortDeviceExtension, &PortStatus); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "i8042ReadStatus() failed with status 0x%08lx\n", Status); - return FALSE; - } - Status = i8042ReadMouseData(PortDeviceExtension, &Output); - if (NT_SUCCESS(Status)) - break; - KeStallExecutionProcessor(1); - Counter--; - } - if (Counter == 0) - { - WARN_(I8042PRT, "Spurious i8042 mouse interrupt\n"); - return FALSE; - } + while (Counter) + { + Status = i8042ReadStatus(PortDeviceExtension, &PortStatus); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "i8042ReadStatus() failed with status 0x%08lx\n", Status); + return FALSE; + } + Status = i8042ReadMouseData(PortDeviceExtension, &Output); + if (NT_SUCCESS(Status)) + break; + KeStallExecutionProcessor(1); + Counter--; + } + if (Counter == 0) + { + WARN_(I8042PRT, "Spurious i8042 mouse interrupt\n"); + return FALSE; + } - INFO_(I8042PRT, "Got: 0x%02x\n", Output); + INFO_(I8042PRT, "Got: 0x%02x\n", Output); - if (i8042PacketIsr(PortDeviceExtension, Output)) - { - if (PortDeviceExtension->PacketComplete) - { - TRACE_(I8042PRT, "Packet complete\n"); - KeInsertQueueDpc(&DeviceExtension->DpcMouse, NULL, NULL); - } - TRACE_(I8042PRT, "Irq eaten by packet\n"); - return TRUE; - } + if (i8042PacketIsr(PortDeviceExtension, Output)) + { + if (PortDeviceExtension->PacketComplete) + { + TRACE_(I8042PRT, "Packet complete\n"); + KeInsertQueueDpc(&DeviceExtension->DpcMouse, NULL, NULL); + } + TRACE_(I8042PRT, "Irq eaten by packet\n"); + return TRUE; + } - TRACE_(I8042PRT, "Irq is mouse input\n"); + TRACE_(I8042PRT, "Irq is mouse input\n"); - i8042MouInputTestTimeout(DeviceExtension); + i8042MouInputTestTimeout(DeviceExtension); - if (i8042MouResetIsr(DeviceExtension, PortStatus, Output)) - { - TRACE_(I8042PRT, "Handled by ResetIsr or hooked Isr\n"); - if (NoChange != DeviceExtension->MouseTimeoutState) { - KeInsertQueueDpc(&DeviceExtension->DpcMouse, NULL, NULL); - } - return TRUE; - } + if (i8042MouResetIsr(DeviceExtension, PortStatus, Output)) + { + TRACE_(I8042PRT, "Handled by ResetIsr or hooked Isr\n"); + if (NoChange != DeviceExtension->MouseTimeoutState) { + KeInsertQueueDpc(&DeviceExtension->DpcMouse, NULL, NULL); + } + return TRUE; + } - if (DeviceExtension->MouseType == Ps2pp) - i8042MouHandlePs2pp(DeviceExtension, Output); - else - i8042MouHandle(DeviceExtension, Output); + if (DeviceExtension->MouseType == Ps2pp) + i8042MouHandlePs2pp(DeviceExtension, Output); + else + i8042MouHandle(DeviceExtension, Output); - return TRUE; + return TRUE; } diff --git a/reactos/drivers/input/i8042prt/pnp.c b/reactos/drivers/input/i8042prt/pnp.c index 89a39c25ad3..ef0d6a7f747 100644 --- a/reactos/drivers/input/i8042prt/pnp.c +++ b/reactos/drivers/input/i8042prt/pnp.c @@ -14,697 +14,707 @@ /* FUNCTIONS *****************************************************************/ /* This is all pretty confusing. There's more than one way to -* disable/enable the keyboard. You can send KBD_ENABLE to the -* keyboard, and it will start scanning keys. Sending KBD_DISABLE -* will disable the key scanning but also reset the parameters to -* defaults. -* -* You can also send 0xAE to the controller for enabling the -* keyboard clock line and 0xAD for disabling it. Then it'll -* automatically get turned on at the next command. The last -* way is by modifying the bit that drives the clock line in the -* 'command byte' of the controller. This is almost, but not quite, -* the same as the AE/AD thing. The difference can be used to detect -* some really old broken keyboard controllers which I hope won't be -* necessary. -* -* We change the command byte, sending KBD_ENABLE/DISABLE seems to confuse -* some kvm switches. -*/ + * disable/enable the keyboard. You can send KBD_ENABLE to the + * keyboard, and it will start scanning keys. Sending KBD_DISABLE + * will disable the key scanning but also reset the parameters to + * defaults. + * + * You can also send 0xAE to the controller for enabling the + * keyboard clock line and 0xAD for disabling it. Then it'll + * automatically get turned on at the next command. The last + * way is by modifying the bit that drives the clock line in the + * 'command byte' of the controller. This is almost, but not quite, + * the same as the AE/AD thing. The difference can be used to detect + * some really old broken keyboard controllers which I hope won't be + * necessary. + * + * We change the command byte, sending KBD_ENABLE/DISABLE seems to confuse + * some kvm switches. + */ BOOLEAN -i8042ChangeMode(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR FlagsToDisable, - IN UCHAR FlagsToEnable) +i8042ChangeMode( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR FlagsToDisable, + IN UCHAR FlagsToEnable) { - UCHAR Value; - NTSTATUS Status; + UCHAR Value; + NTSTATUS Status; - if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_READ_MODE)) - { - WARN_(I8042PRT, "Can't read i8042 mode\n"); - return FALSE; - } + if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_READ_MODE)) + { + WARN_(I8042PRT, "Can't read i8042 mode\n"); + return FALSE; + } - Status = i8042ReadDataWait(DeviceExtension, &Value); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "No response after read i8042 mode\n"); - return FALSE; - } + Status = i8042ReadDataWait(DeviceExtension, &Value); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "No response after read i8042 mode\n"); + return FALSE; + } - Value &= ~FlagsToDisable; - Value |= FlagsToEnable; + Value &= ~FlagsToDisable; + Value |= FlagsToEnable; - if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_WRITE_MODE)) - { - WARN_(I8042PRT, "Can't set i8042 mode\n"); - return FALSE; - } + if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_WRITE_MODE)) + { + WARN_(I8042PRT, "Can't set i8042 mode\n"); + return FALSE; + } - if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value)) - { - WARN_(I8042PRT, "Can't send i8042 mode\n"); - return FALSE; - } + if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value)) + { + WARN_(I8042PRT, "Can't send i8042 mode\n"); + return FALSE; + } - return TRUE; + return TRUE; } static NTSTATUS -i8042BasicDetect(IN PPORT_DEVICE_EXTENSION DeviceExtension) +i8042BasicDetect( + IN PPORT_DEVICE_EXTENSION DeviceExtension) { - NTSTATUS Status; - ULONG ResendIterations; - UCHAR Value = 0; + NTSTATUS Status; + ULONG ResendIterations; + UCHAR Value = 0; - /* Don't enable keyboard and mouse interrupts, disable keyboard/mouse */ - i8042Flush(DeviceExtension); - if (!i8042ChangeMode(DeviceExtension, CCB_KBD_INT_ENAB | CCB_MOUSE_INT_ENAB, CCB_KBD_DISAB | CCB_MOUSE_DISAB)) - return STATUS_IO_DEVICE_ERROR; + /* Don't enable keyboard and mouse interrupts, disable keyboard/mouse */ + i8042Flush(DeviceExtension); + if (!i8042ChangeMode(DeviceExtension, CCB_KBD_INT_ENAB | CCB_MOUSE_INT_ENAB, CCB_KBD_DISAB | CCB_MOUSE_DISAB)) + return STATUS_IO_DEVICE_ERROR; - i8042Flush(DeviceExtension); + i8042Flush(DeviceExtension); - /* Issue a CTRL_SELF_TEST command to check if this is really an i8042 controller */ - ResendIterations = DeviceExtension->Settings.ResendIterations + 1; - while (ResendIterations--) - { - if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, CTRL_SELF_TEST)) - { - WARN_(I8042PRT, "Writing CTRL_SELF_TEST command failed\n"); - return STATUS_IO_TIMEOUT; - } + /* Issue a CTRL_SELF_TEST command to check if this is really an i8042 controller */ + ResendIterations = DeviceExtension->Settings.ResendIterations + 1; + while (ResendIterations--) + { + if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, CTRL_SELF_TEST)) + { + WARN_(I8042PRT, "Writing CTRL_SELF_TEST command failed\n"); + return STATUS_IO_TIMEOUT; + } - Status = i8042ReadDataWait(DeviceExtension, &Value); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "Failed to read CTRL_SELF_TEST response, status 0x%08lx\n", Status); - return Status; - } + Status = i8042ReadDataWait(DeviceExtension, &Value); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "Failed to read CTRL_SELF_TEST response, status 0x%08lx\n", Status); + return Status; + } - if (Value == KBD_SELF_TEST_OK) - { - INFO_(I8042PRT, "CTRL_SELF_TEST completed successfully!\n"); - break; - } - else if (Value == KBD_RESEND) - { - TRACE_(I8042PRT, "Resending...\n", Value); - KeStallExecutionProcessor(50); - } - else - { - WARN_(I8042PRT, "Got 0x%02x instead of 0x55\n", Value); - return STATUS_IO_DEVICE_ERROR; - } - } + if (Value == KBD_SELF_TEST_OK) + { + INFO_(I8042PRT, "CTRL_SELF_TEST completed successfully!\n"); + break; + } + else if (Value == KBD_RESEND) + { + TRACE_(I8042PRT, "Resending...\n", Value); + KeStallExecutionProcessor(50); + } + else + { + WARN_(I8042PRT, "Got 0x%02x instead of 0x55\n", Value); + return STATUS_IO_DEVICE_ERROR; + } + } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } static VOID -i8042DetectKeyboard(IN PPORT_DEVICE_EXTENSION DeviceExtension) +i8042DetectKeyboard( + IN PPORT_DEVICE_EXTENSION DeviceExtension) { - NTSTATUS Status; + NTSTATUS Status; - /* Set LEDs (that is not fatal if some error occurs) */ - Status = i8042SynchWritePort(DeviceExtension, 0, KBD_CMD_SET_LEDS, TRUE); - if (NT_SUCCESS(Status)) - { - Status = i8042SynchWritePort(DeviceExtension, 0, 0, TRUE); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "Can't finish SET_LEDS (0x%08lx)\n", Status); - return; - } - } - else - { - WARN_(I8042PRT, "Warning: can't write SET_LEDS (0x%08lx)\n", Status); - } + /* Set LEDs (that is not fatal if some error occurs) */ + Status = i8042SynchWritePort(DeviceExtension, 0, KBD_CMD_SET_LEDS, TRUE); + if (NT_SUCCESS(Status)) + { + Status = i8042SynchWritePort(DeviceExtension, 0, 0, TRUE); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "Can't finish SET_LEDS (0x%08lx)\n", Status); + return; + } + } + else + { + WARN_(I8042PRT, "Warning: can't write SET_LEDS (0x%08lx)\n", Status); + } - /* Turn on translation and SF (Some machines don't reboot if SF is not set, see ReactOS bug #1842) */ - if (!i8042ChangeMode(DeviceExtension, 0, CCB_TRANSLATE | CCB_SYSTEM_FLAG)) - return; + /* Turn on translation and SF (Some machines don't reboot if SF is not set, see ReactOS bug #1842) */ + if (!i8042ChangeMode(DeviceExtension, 0, CCB_TRANSLATE | CCB_SYSTEM_FLAG)) + return; - /* - * We used to send a KBD_LINE_TEST (0xAB) command, but on at least HP - * Pavilion notebooks the response to that command was incorrect. - * So now we just assume that a keyboard is attached. - */ - DeviceExtension->Flags |= KEYBOARD_PRESENT; + /* + * We used to send a KBD_LINE_TEST (0xAB) command, but on at least HP + * Pavilion notebooks the response to that command was incorrect. + * So now we just assume that a keyboard is attached. + */ + DeviceExtension->Flags |= KEYBOARD_PRESENT; - INFO_(I8042PRT, "Keyboard detected\n"); + INFO_(I8042PRT, "Keyboard detected\n"); } static VOID -i8042DetectMouse(IN PPORT_DEVICE_EXTENSION DeviceExtension) +i8042DetectMouse( + IN PPORT_DEVICE_EXTENSION DeviceExtension) { - NTSTATUS Status; - UCHAR Value; - UCHAR ExpectedReply[] = { MOUSE_ACK, 0xAA }; - UCHAR ReplyByte; + NTSTATUS Status; + UCHAR Value; + UCHAR ExpectedReply[] = { MOUSE_ACK, 0xAA }; + UCHAR ReplyByte; - /* First do a mouse line test */ - if (i8042Write(DeviceExtension, DeviceExtension->ControlPort, MOUSE_LINE_TEST)) - { - Status = i8042ReadDataWait(DeviceExtension, &Value); + /* First do a mouse line test */ + if (i8042Write(DeviceExtension, DeviceExtension->ControlPort, MOUSE_LINE_TEST)) + { + Status = i8042ReadDataWait(DeviceExtension, &Value); - if (!NT_SUCCESS(Status) || Value != 0) - { - WARN_(I8042PRT, "Mouse line test failed\n"); - goto failure; - } - } + if (!NT_SUCCESS(Status) || Value != 0) + { + WARN_(I8042PRT, "Mouse line test failed\n"); + goto failure; + } + } - /* Now reset the mouse */ - i8042Flush(DeviceExtension); + /* Now reset the mouse */ + i8042Flush(DeviceExtension); - if(!i8042IsrWritePort(DeviceExtension, MOU_CMD_RESET, CTRL_WRITE_MOUSE)) - { - WARN_(I8042PRT, "Failed to write reset command to mouse\n"); - goto failure; - } + if(!i8042IsrWritePort(DeviceExtension, MOU_CMD_RESET, CTRL_WRITE_MOUSE)) + { + WARN_(I8042PRT, "Failed to write reset command to mouse\n"); + goto failure; + } - /* The implementation of the "Mouse Reset" command differs much from chip to chip. + /* The implementation of the "Mouse Reset" command differs much from chip to chip. - By default, the first byte is an ACK, when the mouse is plugged in and working and NACK when it's not. - On success, the next bytes are 0xAA and 0x00. + By default, the first byte is an ACK, when the mouse is plugged in and working and NACK when it's not. + On success, the next bytes are 0xAA and 0x00. - But on some systems (like ECS K7S5A Pro, SiS 735 chipset), we always get an ACK and 0xAA. - Only the last byte indicates, whether a mouse is plugged in. - It is either sent or not, so there is no byte, which indicates a failure here. + But on some systems (like ECS K7S5A Pro, SiS 735 chipset), we always get an ACK and 0xAA. + Only the last byte indicates, whether a mouse is plugged in. + It is either sent or not, so there is no byte, which indicates a failure here. - After the Mouse Reset command was issued, it usually takes some time until we get a response. - So get the first two bytes in a loop. */ - for (ReplyByte = 0; - ReplyByte < sizeof(ExpectedReply) / sizeof(ExpectedReply[0]); - ReplyByte++) - { - ULONG Counter = 500; + After the Mouse Reset command was issued, it usually takes some time until we get a response. + So get the first two bytes in a loop. */ + for (ReplyByte = 0; + ReplyByte < sizeof(ExpectedReply) / sizeof(ExpectedReply[0]); + ReplyByte++) + { + ULONG Counter = 500; - do - { - Status = i8042ReadDataWait(DeviceExtension, &Value); + do + { + Status = i8042ReadDataWait(DeviceExtension, &Value); - if(!NT_SUCCESS(Status)) - { - /* Wait some time before trying again */ - KeStallExecutionProcessor(50); - } - } while (Status == STATUS_IO_TIMEOUT && Counter--); + if(!NT_SUCCESS(Status)) + { + /* Wait some time before trying again */ + KeStallExecutionProcessor(50); + } + } while (Status == STATUS_IO_TIMEOUT && Counter--); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "No ACK after mouse reset, status 0x%08lx\n", Status); - goto failure; - } - else if (Value != ExpectedReply[ReplyByte]) - { - WARN_(I8042PRT, "Unexpected reply: 0x%02x (expected 0x%02x)\n", Value, ExpectedReply[ReplyByte]); - goto failure; - } - } + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "No ACK after mouse reset, status 0x%08lx\n", Status); + goto failure; + } + else if (Value != ExpectedReply[ReplyByte]) + { + WARN_(I8042PRT, "Unexpected reply: 0x%02x (expected 0x%02x)\n", Value, ExpectedReply[ReplyByte]); + goto failure; + } + } - /* Finally get the third byte, but only try it one time (see above). - Otherwise this takes around 45 seconds on a K7S5A Pro, when no mouse is plugged in. */ - Status = i8042ReadDataWait(DeviceExtension, &Value); + /* Finally get the third byte, but only try it one time (see above). + Otherwise this takes around 45 seconds on a K7S5A Pro, when no mouse is plugged in. */ + Status = i8042ReadDataWait(DeviceExtension, &Value); - if(!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "Last byte was not transmitted after mouse reset, status 0x%08lx\n", Status); - goto failure; - } - else if(Value != 0x00) - { - WARN_(I8042PRT, "Last byte after mouse reset was not 0x00, but 0x%02x\n", Value); - goto failure; - } + if(!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "Last byte was not transmitted after mouse reset, status 0x%08lx\n", Status); + goto failure; + } + else if(Value != 0x00) + { + WARN_(I8042PRT, "Last byte after mouse reset was not 0x00, but 0x%02x\n", Value); + goto failure; + } - DeviceExtension->Flags |= MOUSE_PRESENT; - INFO_(I8042PRT, "Mouse detected\n"); - return; + DeviceExtension->Flags |= MOUSE_PRESENT; + INFO_(I8042PRT, "Mouse detected\n"); + return; failure: - /* There is probably no mouse present. On some systems, - the probe locks the entire keyboard controller. Let's - try to get access to the keyboard again by sending a - reset */ - i8042Flush(DeviceExtension); - i8042Write(DeviceExtension, DeviceExtension->ControlPort, CTRL_SELF_TEST); - i8042ReadDataWait(DeviceExtension, &Value); - i8042Flush(DeviceExtension); + /* There is probably no mouse present. On some systems, + the probe locks the entire keyboard controller. Let's + try to get access to the keyboard again by sending a + reset */ + i8042Flush(DeviceExtension); + i8042Write(DeviceExtension, DeviceExtension->ControlPort, CTRL_SELF_TEST); + i8042ReadDataWait(DeviceExtension, &Value); + i8042Flush(DeviceExtension); - INFO_(I8042PRT, "Mouse not detected\n"); + INFO_(I8042PRT, "Mouse not detected\n"); } static NTSTATUS -i8042ConnectKeyboardInterrupt(IN PI8042_KEYBOARD_EXTENSION DeviceExtension) +i8042ConnectKeyboardInterrupt( + IN PI8042_KEYBOARD_EXTENSION DeviceExtension) { - PPORT_DEVICE_EXTENSION PortDeviceExtension; - KIRQL DirqlMax; - NTSTATUS Status; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + KIRQL DirqlMax; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042ConnectKeyboardInterrupt()\n"); + TRACE_(I8042PRT, "i8042ConnectKeyboardInterrupt()\n"); - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - DirqlMax = MAX( - PortDeviceExtension->KeyboardInterrupt.Dirql, - PortDeviceExtension->MouseInterrupt.Dirql); + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + DirqlMax = MAX( + PortDeviceExtension->KeyboardInterrupt.Dirql, + PortDeviceExtension->MouseInterrupt.Dirql); - INFO_(I8042PRT, "KeyboardInterrupt.Vector %lu\n", - PortDeviceExtension->KeyboardInterrupt.Vector); - INFO_(I8042PRT, "KeyboardInterrupt.Dirql %lu\n", - PortDeviceExtension->KeyboardInterrupt.Dirql); - INFO_(I8042PRT, "KeyboardInterrupt.DirqlMax %lu\n", - DirqlMax); - INFO_(I8042PRT, "KeyboardInterrupt.InterruptMode %s\n", - PortDeviceExtension->KeyboardInterrupt.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched"); - INFO_(I8042PRT, "KeyboardInterrupt.ShareInterrupt %s\n", - PortDeviceExtension->KeyboardInterrupt.ShareInterrupt ? "yes" : "no"); - INFO_(I8042PRT, "KeyboardInterrupt.Affinity 0x%lx\n", - PortDeviceExtension->KeyboardInterrupt.Affinity); - Status = IoConnectInterrupt( - &PortDeviceExtension->KeyboardInterrupt.Object, - i8042KbdInterruptService, - DeviceExtension, &PortDeviceExtension->SpinLock, - PortDeviceExtension->KeyboardInterrupt.Vector, PortDeviceExtension->KeyboardInterrupt.Dirql, DirqlMax, - PortDeviceExtension->KeyboardInterrupt.InterruptMode, PortDeviceExtension->KeyboardInterrupt.ShareInterrupt, - PortDeviceExtension->KeyboardInterrupt.Affinity, FALSE); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoConnectInterrupt() failed with status 0x%08x\n", Status); - return Status; - } + INFO_(I8042PRT, "KeyboardInterrupt.Vector %lu\n", + PortDeviceExtension->KeyboardInterrupt.Vector); + INFO_(I8042PRT, "KeyboardInterrupt.Dirql %lu\n", + PortDeviceExtension->KeyboardInterrupt.Dirql); + INFO_(I8042PRT, "KeyboardInterrupt.DirqlMax %lu\n", + DirqlMax); + INFO_(I8042PRT, "KeyboardInterrupt.InterruptMode %s\n", + PortDeviceExtension->KeyboardInterrupt.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched"); + INFO_(I8042PRT, "KeyboardInterrupt.ShareInterrupt %s\n", + PortDeviceExtension->KeyboardInterrupt.ShareInterrupt ? "yes" : "no"); + INFO_(I8042PRT, "KeyboardInterrupt.Affinity 0x%lx\n", + PortDeviceExtension->KeyboardInterrupt.Affinity); + Status = IoConnectInterrupt( + &PortDeviceExtension->KeyboardInterrupt.Object, + i8042KbdInterruptService, + DeviceExtension, &PortDeviceExtension->SpinLock, + PortDeviceExtension->KeyboardInterrupt.Vector, PortDeviceExtension->KeyboardInterrupt.Dirql, DirqlMax, + PortDeviceExtension->KeyboardInterrupt.InterruptMode, PortDeviceExtension->KeyboardInterrupt.ShareInterrupt, + PortDeviceExtension->KeyboardInterrupt.Affinity, FALSE); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoConnectInterrupt() failed with status 0x%08x\n", Status); + return Status; + } - if (DirqlMax == PortDeviceExtension->KeyboardInterrupt.Dirql) - PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->KeyboardInterrupt.Object; - PortDeviceExtension->Flags |= KEYBOARD_INITIALIZED; - return STATUS_SUCCESS; + if (DirqlMax == PortDeviceExtension->KeyboardInterrupt.Dirql) + PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->KeyboardInterrupt.Object; + PortDeviceExtension->Flags |= KEYBOARD_INITIALIZED; + return STATUS_SUCCESS; } static NTSTATUS -i8042ConnectMouseInterrupt(IN PI8042_MOUSE_EXTENSION DeviceExtension) +i8042ConnectMouseInterrupt( + IN PI8042_MOUSE_EXTENSION DeviceExtension) { - PPORT_DEVICE_EXTENSION PortDeviceExtension; - KIRQL DirqlMax; - NTSTATUS Status; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + KIRQL DirqlMax; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042ConnectMouseInterrupt()\n"); + TRACE_(I8042PRT, "i8042ConnectMouseInterrupt()\n"); - Status = i8042MouInitialize(DeviceExtension); - if (!NT_SUCCESS(Status)) - return Status; + Status = i8042MouInitialize(DeviceExtension); + if (!NT_SUCCESS(Status)) + return Status; - PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; - DirqlMax = MAX( - PortDeviceExtension->KeyboardInterrupt.Dirql, - PortDeviceExtension->MouseInterrupt.Dirql); + PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension; + DirqlMax = MAX( + PortDeviceExtension->KeyboardInterrupt.Dirql, + PortDeviceExtension->MouseInterrupt.Dirql); - INFO_(I8042PRT, "MouseInterrupt.Vector %lu\n", - PortDeviceExtension->MouseInterrupt.Vector); - INFO_(I8042PRT, "MouseInterrupt.Dirql %lu\n", - PortDeviceExtension->MouseInterrupt.Dirql); - INFO_(I8042PRT, "MouseInterrupt.DirqlMax %lu\n", - DirqlMax); - INFO_(I8042PRT, "MouseInterrupt.InterruptMode %s\n", - PortDeviceExtension->MouseInterrupt.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched"); - INFO_(I8042PRT, "MouseInterrupt.ShareInterrupt %s\n", - PortDeviceExtension->MouseInterrupt.ShareInterrupt ? "yes" : "no"); - INFO_(I8042PRT, "MouseInterrupt.Affinity 0x%lx\n", - PortDeviceExtension->MouseInterrupt.Affinity); - Status = IoConnectInterrupt( - &PortDeviceExtension->MouseInterrupt.Object, - i8042MouInterruptService, - DeviceExtension, &PortDeviceExtension->SpinLock, - PortDeviceExtension->MouseInterrupt.Vector, PortDeviceExtension->MouseInterrupt.Dirql, DirqlMax, - PortDeviceExtension->MouseInterrupt.InterruptMode, PortDeviceExtension->MouseInterrupt.ShareInterrupt, - PortDeviceExtension->MouseInterrupt.Affinity, FALSE); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoConnectInterrupt() failed with status 0x%08x\n", Status); - goto cleanup; - } + INFO_(I8042PRT, "MouseInterrupt.Vector %lu\n", + PortDeviceExtension->MouseInterrupt.Vector); + INFO_(I8042PRT, "MouseInterrupt.Dirql %lu\n", + PortDeviceExtension->MouseInterrupt.Dirql); + INFO_(I8042PRT, "MouseInterrupt.DirqlMax %lu\n", + DirqlMax); + INFO_(I8042PRT, "MouseInterrupt.InterruptMode %s\n", + PortDeviceExtension->MouseInterrupt.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched"); + INFO_(I8042PRT, "MouseInterrupt.ShareInterrupt %s\n", + PortDeviceExtension->MouseInterrupt.ShareInterrupt ? "yes" : "no"); + INFO_(I8042PRT, "MouseInterrupt.Affinity 0x%lx\n", + PortDeviceExtension->MouseInterrupt.Affinity); + Status = IoConnectInterrupt( + &PortDeviceExtension->MouseInterrupt.Object, + i8042MouInterruptService, + DeviceExtension, &PortDeviceExtension->SpinLock, + PortDeviceExtension->MouseInterrupt.Vector, PortDeviceExtension->MouseInterrupt.Dirql, DirqlMax, + PortDeviceExtension->MouseInterrupt.InterruptMode, PortDeviceExtension->MouseInterrupt.ShareInterrupt, + PortDeviceExtension->MouseInterrupt.Affinity, FALSE); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoConnectInterrupt() failed with status 0x%08x\n", Status); + goto cleanup; + } - if (DirqlMax == PortDeviceExtension->MouseInterrupt.Dirql) - PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->MouseInterrupt.Object; + if (DirqlMax == PortDeviceExtension->MouseInterrupt.Dirql) + PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->MouseInterrupt.Object; - PortDeviceExtension->Flags |= MOUSE_INITIALIZED; - Status = STATUS_SUCCESS; + PortDeviceExtension->Flags |= MOUSE_INITIALIZED; + Status = STATUS_SUCCESS; cleanup: - if (!NT_SUCCESS(Status)) - { - PortDeviceExtension->Flags &= ~MOUSE_INITIALIZED; - if (PortDeviceExtension->MouseInterrupt.Object) - { - IoDisconnectInterrupt(PortDeviceExtension->MouseInterrupt.Object); - PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->KeyboardInterrupt.Object; - } - } - return Status; + if (!NT_SUCCESS(Status)) + { + PortDeviceExtension->Flags &= ~MOUSE_INITIALIZED; + if (PortDeviceExtension->MouseInterrupt.Object) + { + IoDisconnectInterrupt(PortDeviceExtension->MouseInterrupt.Object); + PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->KeyboardInterrupt.Object; + } + } + return Status; } static NTSTATUS -EnableInterrupts(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR FlagsToDisable, - IN UCHAR FlagsToEnable) +EnableInterrupts( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR FlagsToDisable, + IN UCHAR FlagsToEnable) { - i8042Flush(DeviceExtension); + i8042Flush(DeviceExtension); - if (!i8042ChangeMode(DeviceExtension, FlagsToDisable, FlagsToEnable)) - return STATUS_UNSUCCESSFUL; + if (!i8042ChangeMode(DeviceExtension, FlagsToDisable, FlagsToEnable)) + return STATUS_UNSUCCESSFUL; - /* Reset the mouse (if any) to start the detection */ - if (DeviceExtension->Flags & MOUSE_PRESENT) - { - KIRQL Irql; + /* Reset the mouse (if any) to start the detection */ + if (DeviceExtension->Flags & MOUSE_PRESENT) + { + KIRQL Irql; - Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt); - i8042IsrWritePort(DeviceExtension, MOU_CMD_RESET, CTRL_WRITE_MOUSE); - KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql); - } + Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt); + i8042IsrWritePort(DeviceExtension, MOU_CMD_RESET, CTRL_WRITE_MOUSE); + KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql); + } - return STATUS_SUCCESS; + return STATUS_SUCCESS; } static NTSTATUS -StartProcedure(IN PPORT_DEVICE_EXTENSION DeviceExtension) +StartProcedure( + IN PPORT_DEVICE_EXTENSION DeviceExtension) { - NTSTATUS Status; - UCHAR FlagsToDisable = 0; - UCHAR FlagsToEnable = 0; + NTSTATUS Status; + UCHAR FlagsToDisable = 0; + UCHAR FlagsToEnable = 0; - if (DeviceExtension->DataPort == 0) - { - /* Unable to do something at the moment */ - return STATUS_SUCCESS; - } + if (DeviceExtension->DataPort == 0) + { + /* Unable to do something at the moment */ + return STATUS_SUCCESS; + } - if (!(DeviceExtension->Flags & (KEYBOARD_PRESENT | MOUSE_PRESENT))) - { - /* Try to detect them */ - TRACE_(I8042PRT, "Check if the controller is really a i8042\n"); - Status = i8042BasicDetect(DeviceExtension); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "i8042BasicDetect() failed with status 0x%08lx\n", Status); - return STATUS_UNSUCCESSFUL; - } + if (!(DeviceExtension->Flags & (KEYBOARD_PRESENT | MOUSE_PRESENT))) + { + /* Try to detect them */ + TRACE_(I8042PRT, "Check if the controller is really a i8042\n"); + Status = i8042BasicDetect(DeviceExtension); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "i8042BasicDetect() failed with status 0x%08lx\n", Status); + return STATUS_UNSUCCESSFUL; + } - /* First detect the mouse and then the keyboard! - If we do it the other way round, some systems throw away settings like the keyboard translation, when detecting the mouse. + /* First detect the mouse and then the keyboard! + If we do it the other way round, some systems throw away settings like the keyboard translation, when detecting the mouse. + + Don't detect the mouse if we're in 1st stage setup! */ + if(!IsFirstStageSetup()) + { + TRACE_(I8042PRT, "Detecting mouse\n"); + i8042DetectMouse(DeviceExtension); + } - Don't detect the mouse if we're in 1st stage setup! */ - if(!IsFirstStageSetup()) - { - TRACE_(I8042PRT, "Detecting mouse\n"); - i8042DetectMouse(DeviceExtension); - } + TRACE_(I8042PRT, "Detecting keyboard\n"); + i8042DetectKeyboard(DeviceExtension); - TRACE_(I8042PRT, "Detecting keyboard\n"); - i8042DetectKeyboard(DeviceExtension); + INFO_(I8042PRT, "Keyboard present: %s\n", DeviceExtension->Flags & KEYBOARD_PRESENT ? "YES" : "NO"); + INFO_(I8042PRT, "Mouse present : %s\n", DeviceExtension->Flags & MOUSE_PRESENT ? "YES" : "NO"); + } - INFO_(I8042PRT, "Keyboard present: %s\n", DeviceExtension->Flags & KEYBOARD_PRESENT ? "YES" : "NO"); - INFO_(I8042PRT, "Mouse present : %s\n", DeviceExtension->Flags & MOUSE_PRESENT ? "YES" : "NO"); - } + /* Connect interrupts */ + if (DeviceExtension->Flags & KEYBOARD_PRESENT && + DeviceExtension->Flags & KEYBOARD_CONNECTED && + DeviceExtension->Flags & KEYBOARD_STARTED && + !(DeviceExtension->Flags & KEYBOARD_INITIALIZED)) + { + /* Keyboard is ready to be initialized */ + Status = i8042ConnectKeyboardInterrupt(DeviceExtension->KeyboardExtension); + if (NT_SUCCESS(Status)) + { + DeviceExtension->Flags |= KEYBOARD_INITIALIZED; + FlagsToDisable |= CCB_KBD_DISAB; + FlagsToEnable |= CCB_KBD_INT_ENAB; + } + } - /* Connect interrupts */ - if (DeviceExtension->Flags & KEYBOARD_PRESENT && - DeviceExtension->Flags & KEYBOARD_CONNECTED && - DeviceExtension->Flags & KEYBOARD_STARTED && - !(DeviceExtension->Flags & KEYBOARD_INITIALIZED)) - { - /* Keyboard is ready to be initialized */ - Status = i8042ConnectKeyboardInterrupt(DeviceExtension->KeyboardExtension); - if (NT_SUCCESS(Status)) - { - DeviceExtension->Flags |= KEYBOARD_INITIALIZED; - FlagsToDisable |= CCB_KBD_DISAB; - FlagsToEnable |= CCB_KBD_INT_ENAB; - } - } + if (DeviceExtension->Flags & MOUSE_PRESENT && + DeviceExtension->Flags & MOUSE_CONNECTED && + DeviceExtension->Flags & MOUSE_STARTED && + !(DeviceExtension->Flags & MOUSE_INITIALIZED)) + { + /* Mouse is ready to be initialized */ + Status = i8042ConnectMouseInterrupt(DeviceExtension->MouseExtension); + if (NT_SUCCESS(Status)) + { + DeviceExtension->Flags |= MOUSE_INITIALIZED; + FlagsToDisable |= CCB_MOUSE_DISAB; + FlagsToEnable |= CCB_MOUSE_INT_ENAB; + } + } - if (DeviceExtension->Flags & MOUSE_PRESENT && - DeviceExtension->Flags & MOUSE_CONNECTED && - DeviceExtension->Flags & MOUSE_STARTED && - !(DeviceExtension->Flags & MOUSE_INITIALIZED)) - { - /* Mouse is ready to be initialized */ - Status = i8042ConnectMouseInterrupt(DeviceExtension->MouseExtension); - if (NT_SUCCESS(Status)) - { - DeviceExtension->Flags |= MOUSE_INITIALIZED; - FlagsToDisable |= CCB_MOUSE_DISAB; - FlagsToEnable |= CCB_MOUSE_INT_ENAB; - } - } + if (FlagsToEnable) + Status = EnableInterrupts(DeviceExtension, FlagsToDisable, FlagsToEnable); + else + Status = STATUS_SUCCESS; - if (FlagsToEnable) - Status = EnableInterrupts(DeviceExtension, FlagsToDisable, FlagsToEnable); - else - Status = STATUS_SUCCESS; - - return Status; + return Status; } static NTSTATUS -i8042PnpStartDevice(IN PDEVICE_OBJECT DeviceObject, - IN PCM_RESOURCE_LIST AllocatedResources, - IN PCM_RESOURCE_LIST AllocatedResourcesTranslated) +i8042PnpStartDevice( + IN PDEVICE_OBJECT DeviceObject, + IN PCM_RESOURCE_LIST AllocatedResources, + IN PCM_RESOURCE_LIST AllocatedResourcesTranslated) { - PFDO_DEVICE_EXTENSION DeviceExtension; - PPORT_DEVICE_EXTENSION PortDeviceExtension; - PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor, ResourceDescriptorTranslated; - INTERRUPT_DATA InterruptData; - BOOLEAN FoundDataPort = FALSE; - BOOLEAN FoundControlPort = FALSE; - BOOLEAN FoundIrq = FALSE; - ULONG i; - NTSTATUS Status; + PFDO_DEVICE_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION PortDeviceExtension; + PCM_PARTIAL_RESOURCE_DESCRIPTOR ResourceDescriptor, ResourceDescriptorTranslated; + INTERRUPT_DATA InterruptData; + BOOLEAN FoundDataPort = FALSE; + BOOLEAN FoundControlPort = FALSE; + BOOLEAN FoundIrq = FALSE; + ULONG i; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042PnpStartDevice(%p)\n", DeviceObject); - DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; - PortDeviceExtension = DeviceExtension->PortDeviceExtension; + TRACE_(I8042PRT, "i8042PnpStartDevice(%p)\n", DeviceObject); + DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; + PortDeviceExtension = DeviceExtension->PortDeviceExtension; - ASSERT(DeviceExtension->PnpState == dsStopped); + ASSERT(DeviceExtension->PnpState == dsStopped); - if (!AllocatedResources) - { - WARN_(I8042PRT, "No allocated resources sent to driver\n"); - return STATUS_INSUFFICIENT_RESOURCES; - } - if (AllocatedResources->Count != 1) - { - WARN_(I8042PRT, "Wrong number of allocated resources sent to driver\n"); - return STATUS_INSUFFICIENT_RESOURCES; - } - if (AllocatedResources->List[0].PartialResourceList.Version != 1 - || AllocatedResources->List[0].PartialResourceList.Revision != 1 - || AllocatedResourcesTranslated->List[0].PartialResourceList.Version != 1 - || AllocatedResourcesTranslated->List[0].PartialResourceList.Revision != 1) - { - WARN_(I8042PRT, "Revision mismatch: %u.%u != 1.1 or %u.%u != 1.1\n", - AllocatedResources->List[0].PartialResourceList.Version, - AllocatedResources->List[0].PartialResourceList.Revision, - AllocatedResourcesTranslated->List[0].PartialResourceList.Version, - AllocatedResourcesTranslated->List[0].PartialResourceList.Revision); - return STATUS_REVISION_MISMATCH; - } + if (!AllocatedResources) + { + WARN_(I8042PRT, "No allocated resources sent to driver\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } + if (AllocatedResources->Count != 1) + { + WARN_(I8042PRT, "Wrong number of allocated resources sent to driver\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } + if (AllocatedResources->List[0].PartialResourceList.Version != 1 + || AllocatedResources->List[0].PartialResourceList.Revision != 1 + || AllocatedResourcesTranslated->List[0].PartialResourceList.Version != 1 + || AllocatedResourcesTranslated->List[0].PartialResourceList.Revision != 1) + { + WARN_(I8042PRT, "Revision mismatch: %u.%u != 1.1 or %u.%u != 1.1\n", + AllocatedResources->List[0].PartialResourceList.Version, + AllocatedResources->List[0].PartialResourceList.Revision, + AllocatedResourcesTranslated->List[0].PartialResourceList.Version, + AllocatedResourcesTranslated->List[0].PartialResourceList.Revision); + return STATUS_REVISION_MISMATCH; + } - /* Get Irq and optionally control port and data port */ - for (i = 0; i < AllocatedResources->List[0].PartialResourceList.Count; i++) - { - ResourceDescriptor = &AllocatedResources->List[0].PartialResourceList.PartialDescriptors[i]; - ResourceDescriptorTranslated = &AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[i]; - switch (ResourceDescriptor->Type) - { - case CmResourceTypePort: - { - if (ResourceDescriptor->u.Port.Length == 1) - { - /* We assume that the first ressource will - * be the control port and the second one - * will be the data port... - */ - if (!FoundDataPort) - { - PortDeviceExtension->DataPort = ULongToPtr(ResourceDescriptor->u.Port.Start.u.LowPart); - INFO_(I8042PRT, "Found data port: %p\n", PortDeviceExtension->DataPort); - FoundDataPort = TRUE; - } - else if (!FoundControlPort) - { - PortDeviceExtension->ControlPort = ULongToPtr(ResourceDescriptor->u.Port.Start.u.LowPart); - INFO_(I8042PRT, "Found control port: %p\n", PortDeviceExtension->ControlPort); - FoundControlPort = TRUE; - } - else - { - WARN_(I8042PRT, "Too much I/O ranges provided: 0x%lx\n", ResourceDescriptor->u.Port.Length); - return STATUS_INVALID_PARAMETER; - } - } - else - WARN_(I8042PRT, "Invalid I/O range length: 0x%lx\n", ResourceDescriptor->u.Port.Length); - break; - } - case CmResourceTypeInterrupt: - { - if (FoundIrq) - return STATUS_INVALID_PARAMETER; - InterruptData.Dirql = (KIRQL)ResourceDescriptorTranslated->u.Interrupt.Level; - InterruptData.Vector = ResourceDescriptorTranslated->u.Interrupt.Vector; - InterruptData.Affinity = ResourceDescriptorTranslated->u.Interrupt.Affinity; - if (ResourceDescriptorTranslated->Flags & CM_RESOURCE_INTERRUPT_LATCHED) - InterruptData.InterruptMode = Latched; - else - InterruptData.InterruptMode = LevelSensitive; - InterruptData.ShareInterrupt = (ResourceDescriptorTranslated->ShareDisposition == CmResourceShareShared); - INFO_(I8042PRT, "Found irq resource: %lu\n", ResourceDescriptor->u.Interrupt.Level); - FoundIrq = TRUE; - break; - } - default: - WARN_(I8042PRT, "Unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type); - } - } + /* Get Irq and optionally control port and data port */ + for (i = 0; i < AllocatedResources->List[0].PartialResourceList.Count; i++) + { + ResourceDescriptor = &AllocatedResources->List[0].PartialResourceList.PartialDescriptors[i]; + ResourceDescriptorTranslated = &AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[i]; + switch (ResourceDescriptor->Type) + { + case CmResourceTypePort: + { + if (ResourceDescriptor->u.Port.Length == 1) + { + /* We assume that the first ressource will + * be the control port and the second one + * will be the data port... + */ + if (!FoundDataPort) + { + PortDeviceExtension->DataPort = ULongToPtr(ResourceDescriptor->u.Port.Start.u.LowPart); + INFO_(I8042PRT, "Found data port: %p\n", PortDeviceExtension->DataPort); + FoundDataPort = TRUE; + } + else if (!FoundControlPort) + { + PortDeviceExtension->ControlPort = ULongToPtr(ResourceDescriptor->u.Port.Start.u.LowPart); + INFO_(I8042PRT, "Found control port: %p\n", PortDeviceExtension->ControlPort); + FoundControlPort = TRUE; + } + else + { + WARN_(I8042PRT, "Too much I/O ranges provided: 0x%lx\n", ResourceDescriptor->u.Port.Length); + return STATUS_INVALID_PARAMETER; + } + } + else + WARN_(I8042PRT, "Invalid I/O range length: 0x%lx\n", ResourceDescriptor->u.Port.Length); + break; + } + case CmResourceTypeInterrupt: + { + if (FoundIrq) + return STATUS_INVALID_PARAMETER; + InterruptData.Dirql = (KIRQL)ResourceDescriptorTranslated->u.Interrupt.Level; + InterruptData.Vector = ResourceDescriptorTranslated->u.Interrupt.Vector; + InterruptData.Affinity = ResourceDescriptorTranslated->u.Interrupt.Affinity; + if (ResourceDescriptorTranslated->Flags & CM_RESOURCE_INTERRUPT_LATCHED) + InterruptData.InterruptMode = Latched; + else + InterruptData.InterruptMode = LevelSensitive; + InterruptData.ShareInterrupt = (ResourceDescriptorTranslated->ShareDisposition == CmResourceShareShared); + INFO_(I8042PRT, "Found irq resource: %lu\n", ResourceDescriptor->u.Interrupt.Level); + FoundIrq = TRUE; + break; + } + default: + WARN_(I8042PRT, "Unknown resource descriptor type 0x%x\n", ResourceDescriptor->Type); + } + } - if (!FoundIrq) - { - WARN_(I8042PRT, "Interrupt resource was not found in allocated resources list\n"); - return STATUS_INSUFFICIENT_RESOURCES; - } - else if (DeviceExtension->Type == Keyboard && (!FoundDataPort || !FoundControlPort)) - { - WARN_(I8042PRT, "Some required resources were not found in allocated resources list\n"); - return STATUS_INSUFFICIENT_RESOURCES; - } - else if (DeviceExtension->Type == Mouse && (FoundDataPort || FoundControlPort)) - { - WARN_(I8042PRT, "Too much resources were provided in allocated resources list\n"); - return STATUS_INVALID_PARAMETER; - } + if (!FoundIrq) + { + WARN_(I8042PRT, "Interrupt resource was not found in allocated resources list\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } + else if (DeviceExtension->Type == Keyboard && (!FoundDataPort || !FoundControlPort)) + { + WARN_(I8042PRT, "Some required resources were not found in allocated resources list\n"); + return STATUS_INSUFFICIENT_RESOURCES; + } + else if (DeviceExtension->Type == Mouse && (FoundDataPort || FoundControlPort)) + { + WARN_(I8042PRT, "Too much resources were provided in allocated resources list\n"); + return STATUS_INVALID_PARAMETER; + } - switch (DeviceExtension->Type) - { - case Keyboard: - { - RtlCopyMemory( - &PortDeviceExtension->KeyboardInterrupt, - &InterruptData, - sizeof(INTERRUPT_DATA)); - PortDeviceExtension->Flags |= KEYBOARD_STARTED; - Status = StartProcedure(PortDeviceExtension); - break; - } - case Mouse: - { - RtlCopyMemory( - &PortDeviceExtension->MouseInterrupt, - &InterruptData, - sizeof(INTERRUPT_DATA)); - PortDeviceExtension->Flags |= MOUSE_STARTED; - Status = StartProcedure(PortDeviceExtension); - break; - } - default: - { - WARN_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type); - ASSERT(!(PortDeviceExtension->Flags & KEYBOARD_CONNECTED) || !(PortDeviceExtension->Flags & MOUSE_CONNECTED)); - Status = STATUS_INVALID_DEVICE_REQUEST; - } - } + switch (DeviceExtension->Type) + { + case Keyboard: + { + RtlCopyMemory( + &PortDeviceExtension->KeyboardInterrupt, + &InterruptData, + sizeof(INTERRUPT_DATA)); + PortDeviceExtension->Flags |= KEYBOARD_STARTED; + Status = StartProcedure(PortDeviceExtension); + break; + } + case Mouse: + { + RtlCopyMemory( + &PortDeviceExtension->MouseInterrupt, + &InterruptData, + sizeof(INTERRUPT_DATA)); + PortDeviceExtension->Flags |= MOUSE_STARTED; + Status = StartProcedure(PortDeviceExtension); + break; + } + default: + { + WARN_(I8042PRT, "Unknown FDO type %u\n", DeviceExtension->Type); + ASSERT(!(PortDeviceExtension->Flags & KEYBOARD_CONNECTED) || !(PortDeviceExtension->Flags & MOUSE_CONNECTED)); + Status = STATUS_INVALID_DEVICE_REQUEST; + } + } - if (NT_SUCCESS(Status)) - DeviceExtension->PnpState = dsStarted; + if (NT_SUCCESS(Status)) + DeviceExtension->PnpState = dsStarted; - return Status; + return Status; } NTSTATUS NTAPI -i8042Pnp(IN PDEVICE_OBJECT DeviceObject, - IN PIRP Irp) +i8042Pnp( + IN PDEVICE_OBJECT DeviceObject, + IN PIRP Irp) { - PIO_STACK_LOCATION Stack; - ULONG MinorFunction; - I8042_DEVICE_TYPE DeviceType; - ULONG_PTR Information = 0; - NTSTATUS Status; + PIO_STACK_LOCATION Stack; + ULONG MinorFunction; + I8042_DEVICE_TYPE DeviceType; + ULONG_PTR Information = 0; + NTSTATUS Status; - Stack = IoGetCurrentIrpStackLocation(Irp); - MinorFunction = Stack->MinorFunction; - DeviceType = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Type; + Stack = IoGetCurrentIrpStackLocation(Irp); + MinorFunction = Stack->MinorFunction; + DeviceType = ((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Type; - switch (MinorFunction) - { - case IRP_MN_START_DEVICE: /* 0x00 */ - { - TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n"); + switch (MinorFunction) + { + case IRP_MN_START_DEVICE: /* 0x00 */ + { + TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_START_DEVICE\n"); - /* Call lower driver (if any) */ - if (DeviceType != PhysicalDeviceObject) - { - Status = ForwardIrpAndWait(DeviceObject, Irp); - if (NT_SUCCESS(Status)) - Status = i8042PnpStartDevice( - DeviceObject, - Stack->Parameters.StartDevice.AllocatedResources, - Stack->Parameters.StartDevice.AllocatedResourcesTranslated); - } - else - Status = STATUS_SUCCESS; - break; - } - case IRP_MN_QUERY_DEVICE_RELATIONS: /* (optional) 0x07 */ - { - switch (Stack->Parameters.QueryDeviceRelations.Type) - { - case BusRelations: - { - PDEVICE_RELATIONS DeviceRelations; + /* Call lower driver (if any) */ + if (DeviceType != PhysicalDeviceObject) + { + Status = ForwardIrpAndWait(DeviceObject, Irp); + if (NT_SUCCESS(Status)) + Status = i8042PnpStartDevice( + DeviceObject, + Stack->Parameters.StartDevice.AllocatedResources, + Stack->Parameters.StartDevice.AllocatedResourcesTranslated); + } + else + Status = STATUS_SUCCESS; + break; + } + case IRP_MN_QUERY_DEVICE_RELATIONS: /* (optional) 0x07 */ + { + switch (Stack->Parameters.QueryDeviceRelations.Type) + { + case BusRelations: + { + PDEVICE_RELATIONS DeviceRelations; - TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n"); - DeviceRelations = ExAllocatePool(PagedPool, sizeof(DEVICE_RELATIONS)); - if (DeviceRelations) - { - DeviceRelations->Count = 0; - Information = (ULONG_PTR)DeviceRelations; - Status = STATUS_SUCCESS; - } - else - Status = STATUS_INSUFFICIENT_RESOURCES; - break; - } - case RemovalRelations: - { - TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations\n"); - return ForwardIrpAndForget(DeviceObject, Irp); - } - default: - ERR_(I8042PRT, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n", - Stack->Parameters.QueryDeviceRelations.Type); - ASSERT(FALSE); - return ForwardIrpAndForget(DeviceObject, Irp); - } - break; - } - case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* (optional) 0x0d */ - { - TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"); - /* Nothing to do */ - Status = Irp->IoStatus.Status; - break; - } - default: - { - ERR_(I8042PRT, "IRP_MJ_PNP / unknown minor function 0x%x\n", MinorFunction); - ASSERT(FALSE); - return ForwardIrpAndForget(DeviceObject, Irp); - } - } + TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n"); + DeviceRelations = ExAllocatePool(PagedPool, sizeof(DEVICE_RELATIONS)); + if (DeviceRelations) + { + DeviceRelations->Count = 0; + Information = (ULONG_PTR)DeviceRelations; + Status = STATUS_SUCCESS; + } + else + Status = STATUS_INSUFFICIENT_RESOURCES; + break; + } + case RemovalRelations: + { + TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations\n"); + return ForwardIrpAndForget(DeviceObject, Irp); + } + default: + ERR_(I8042PRT, "IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n", + Stack->Parameters.QueryDeviceRelations.Type); + ASSERT(FALSE); + return ForwardIrpAndForget(DeviceObject, Irp); + } + break; + } + case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* (optional) 0x0d */ + { + TRACE_(I8042PRT, "IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n"); + /* Nothing to do */ + Status = Irp->IoStatus.Status; + break; + } + default: + { + ERR_(I8042PRT, "IRP_MJ_PNP / unknown minor function 0x%x\n", MinorFunction); + ASSERT(FALSE); + return ForwardIrpAndForget(DeviceObject, Irp); + } + } - Irp->IoStatus.Information = Information; - Irp->IoStatus.Status = Status; - IoCompleteRequest(Irp, IO_NO_INCREMENT); - return Status; + Irp->IoStatus.Information = Information; + Irp->IoStatus.Status = Status; + IoCompleteRequest(Irp, IO_NO_INCREMENT); + return Status; } diff --git a/reactos/drivers/input/i8042prt/ps2pp.c b/reactos/drivers/input/i8042prt/ps2pp.c index a6634e20878..3b3ffc679c1 100644 --- a/reactos/drivers/input/i8042prt/ps2pp.c +++ b/reactos/drivers/input/i8042prt/ps2pp.c @@ -14,124 +14,125 @@ /* FUNCTIONS *****************************************************************/ VOID -i8042MouHandlePs2pp(IN PI8042_MOUSE_EXTENSION DeviceExtension, - IN UCHAR Input) +i8042MouHandlePs2pp( + IN PI8042_MOUSE_EXTENSION DeviceExtension, + IN UCHAR Input) { - UCHAR PktType; - PMOUSE_INPUT_DATA MouseInput; + UCHAR PktType; + PMOUSE_INPUT_DATA MouseInput; - MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer; + MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer; - /* First, collect 3 bytes for a packet - * We can detect out-of-sync only by checking - * the whole packet anyway. - * - * If bit 7 and 8 of the first byte are 0, its - * a normal packet. - * - * Otherwise, the packet is different, like this: - * 1: E 1 b3 b2 x x x x - * 2: x x b1 b0 x1 x0 1 0 - * 3: x x x x x x x1 x0 - * - * b3-0 form a code that specifies the packet type: - * - * 0 Device Type - * 1 Rollers and buttons - * 2 Reserved - * 3 Reserved - * 4 Device ID - * 5 Channel & Battery - * 6 Wireless notifications - * 7 Reserved - * 8 ShortID LSB (ShortID is a number that is supposed to differentiate - * 9 ShortID MSB between your mouse and your neighbours') - * 10 Reserved - * 11 Mouse capabilities - * 12 Remote control LSB - * 13 Remote control MSB - * 14 Reserved - * 15 Extended packet - */ + /* First, collect 3 bytes for a packet + * We can detect out-of-sync only by checking + * the whole packet anyway. + * + * If bit 7 and 8 of the first byte are 0, its + * a normal packet. + * + * Otherwise, the packet is different, like this: + * 1: E 1 b3 b2 x x x x + * 2: x x b1 b0 x1 x0 1 0 + * 3: x x x x x x x1 x0 + * + * b3-0 form a code that specifies the packet type: + * + * 0 Device Type + * 1 Rollers and buttons + * 2 Reserved + * 3 Reserved + * 4 Device ID + * 5 Channel & Battery + * 6 Wireless notifications + * 7 Reserved + * 8 ShortID LSB (ShortID is a number that is supposed to differentiate + * 9 ShortID MSB between your mouse and your neighbours') + * 10 Reserved + * 11 Mouse capabilities + * 12 Remote control LSB + * 13 Remote control MSB + * 14 Reserved + * 15 Extended packet + */ - switch (DeviceExtension->MouseState) - { - case MouseIdle: - case XMovement: - DeviceExtension->MouseLogiBuffer[DeviceExtension->MouseState] = Input; - DeviceExtension->MouseState++; - break; + switch (DeviceExtension->MouseState) + { + case MouseIdle: + case XMovement: + DeviceExtension->MouseLogiBuffer[DeviceExtension->MouseState] = Input; + DeviceExtension->MouseState++; + break; - case YMovement: - DeviceExtension->MouseLogiBuffer[2] = Input; - DeviceExtension->MouseState = MouseIdle; + case YMovement: + DeviceExtension->MouseLogiBuffer[2] = Input; + DeviceExtension->MouseState = MouseIdle; - /* first check if it's a normal packet */ + /* first check if it's a normal packet */ - if (!(DeviceExtension->MouseLogiBuffer[0] & 0xC0)) - { - DeviceExtension->MouseState = MouseIdle; - i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[0]); - i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[1]); - i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[2]); - /* We could care about wether MouseState really - * advances, but we don't need to because we're - * only doing three bytes anyway, so the packet - * will never complete if it's broken. - */ - return; - } + if (!(DeviceExtension->MouseLogiBuffer[0] & 0xC0)) + { + DeviceExtension->MouseState = MouseIdle; + i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[0]); + i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[1]); + i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[2]); + /* We could care about wether MouseState really + * advances, but we don't need to because we're + * only doing three bytes anyway, so the packet + * will never complete if it's broken. + */ + return; + } - /* sanity check */ - if (((DeviceExtension->MouseLogiBuffer[0] & 0x48) != 0x48) || - (((DeviceExtension->MouseLogiBuffer[1] & 0x0C) >> 2) != - (DeviceExtension->MouseLogiBuffer[2] & 0x03))) - { - WARN_(I8042PRT, "Ps2pp packet fails sanity checks\n"); - return; - } + /* sanity check */ + if (((DeviceExtension->MouseLogiBuffer[0] & 0x48) != 0x48) || + (((DeviceExtension->MouseLogiBuffer[1] & 0x0C) >> 2) != + (DeviceExtension->MouseLogiBuffer[2] & 0x03))) + { + WARN_(I8042PRT, "Ps2pp packet fails sanity checks\n"); + return; + } - /* Now get the packet type */ - PktType = ((DeviceExtension->MouseLogiBuffer[0] & 0x30) >> 4) & - ((DeviceExtension->MouseLogiBuffer[1] & 0x30) >> 6); + /* Now get the packet type */ + PktType = ((DeviceExtension->MouseLogiBuffer[0] & 0x30) >> 4) & + ((DeviceExtension->MouseLogiBuffer[1] & 0x30) >> 6); - switch (PktType) - { - case 0: - /* The packet contains the device ID, but we - * already read that in the initialization - * sequence. Ignore it. - */ - return; - case 1: - RtlZeroMemory(MouseInput, sizeof(MOUSE_INPUT_DATA)); - if (DeviceExtension->MouseLogiBuffer[2] & 0x10) - MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN; + switch (PktType) + { + case 0: + /* The packet contains the device ID, but we + * already read that in the initialization + * sequence. Ignore it. + */ + return; + case 1: + RtlZeroMemory(MouseInput, sizeof(MOUSE_INPUT_DATA)); + if (DeviceExtension->MouseLogiBuffer[2] & 0x10) + MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN; - if (DeviceExtension->MouseLogiBuffer[2] & 0x20) - MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN; + if (DeviceExtension->MouseLogiBuffer[2] & 0x20) + MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN; - if (DeviceExtension->MouseLogiBuffer[2] & 0x0F) - { - MouseInput->ButtonFlags |= MOUSE_WHEEL; - if (DeviceExtension->MouseLogiBuffer[2] & 0x08) - MouseInput->ButtonData = (DeviceExtension->MouseLogiBuffer[2] & 0x07) - 8; - else - MouseInput->ButtonData = DeviceExtension->MouseLogiBuffer[2] & 0x07; - } - i8042MouHandleButtons( - DeviceExtension, - MOUSE_BUTTON_4_DOWN | MOUSE_BUTTON_5_DOWN); - DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext); - return; - default: - /* These are for things that would probably - * be handled by logitechs own driver. - */ - return; - } + if (DeviceExtension->MouseLogiBuffer[2] & 0x0F) + { + MouseInput->ButtonFlags |= MOUSE_WHEEL; + if (DeviceExtension->MouseLogiBuffer[2] & 0x08) + MouseInput->ButtonData = (DeviceExtension->MouseLogiBuffer[2] & 0x07) - 8; + else + MouseInput->ButtonData = DeviceExtension->MouseLogiBuffer[2] & 0x07; + } + i8042MouHandleButtons( + DeviceExtension, + MOUSE_BUTTON_4_DOWN | MOUSE_BUTTON_5_DOWN); + DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext); + return; + default: + /* These are for things that would probably + * be handled by logitechs own driver. + */ + return; + } - default: - WARN_(I8042PRT, "Unexpected input state for ps2pp!\n"); - } + default: + WARN_(I8042PRT, "Unexpected input state for ps2pp!\n"); + } } diff --git a/reactos/drivers/input/i8042prt/readwrite.c b/reactos/drivers/input/i8042prt/readwrite.c index 691f459d594..651f7138aa0 100644 --- a/reactos/drivers/input/i8042prt/readwrite.c +++ b/reactos/drivers/input/i8042prt/readwrite.c @@ -16,197 +16,205 @@ /* FUNCTIONS *****************************************************************/ VOID -i8042Flush(IN PPORT_DEVICE_EXTENSION DeviceExtension) +i8042Flush( + IN PPORT_DEVICE_EXTENSION DeviceExtension) { - UCHAR Ignore; + UCHAR Ignore; - /* Flush output buffer */ - while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_OBF /* | MOU_OBF*/, &Ignore))) { - KeStallExecutionProcessor(50); - TRACE_(I8042PRT, "Output data flushed\n"); - } + /* Flush output buffer */ + while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_OBF /* | MOU_OBF*/, &Ignore))) { + KeStallExecutionProcessor(50); + TRACE_(I8042PRT, "Output data flushed\n"); + } - /* Flush input buffer */ - while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_IBF, &Ignore))) { - KeStallExecutionProcessor(50); - TRACE_(I8042PRT, "Input data flushed\n"); - } + /* Flush input buffer */ + while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_IBF, &Ignore))) { + KeStallExecutionProcessor(50); + TRACE_(I8042PRT, "Input data flushed\n"); + } } BOOLEAN -i8042IsrWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR Value, - IN UCHAR SelectCmd OPTIONAL) +i8042IsrWritePort( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR Value, + IN UCHAR SelectCmd OPTIONAL) { - if (SelectCmd) - if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, SelectCmd)) - return FALSE; + if (SelectCmd) + if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, SelectCmd)) + return FALSE; - return i8042Write(DeviceExtension, DeviceExtension->DataPort, Value); + return i8042Write(DeviceExtension, DeviceExtension->DataPort, Value); } /* -* FUNCTION: Read data from port 0x60 -*/ + * FUNCTION: Read data from port 0x60 + */ NTSTATUS -i8042ReadData(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR StatusFlags, - OUT PUCHAR Data) +i8042ReadData( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR StatusFlags, + OUT PUCHAR Data) { - UCHAR PortStatus; - NTSTATUS Status; + UCHAR PortStatus; + NTSTATUS Status; - Status = i8042ReadStatus(DeviceExtension, &PortStatus); - if (!NT_SUCCESS(Status)) - return Status; + Status = i8042ReadStatus(DeviceExtension, &PortStatus); + if (!NT_SUCCESS(Status)) + return Status; - // If data is available - if (PortStatus & StatusFlags) - { - *Data = READ_PORT_UCHAR(DeviceExtension->DataPort); - INFO_(I8042PRT, "Read: 0x%02x (status: 0x%x)\n", Data[0], PortStatus); + // If data is available + if (PortStatus & StatusFlags) + { + *Data = READ_PORT_UCHAR(DeviceExtension->DataPort); + INFO_(I8042PRT, "Read: 0x%02x (status: 0x%x)\n", Data[0], PortStatus); - // If the data is valid (not timeout, not parity error) - if ((PortStatus & KBD_PERR) == 0) - return STATUS_SUCCESS; - } - return STATUS_UNSUCCESSFUL; + // If the data is valid (not timeout, not parity error) + if ((PortStatus & KBD_PERR) == 0) + return STATUS_SUCCESS; + } + return STATUS_UNSUCCESSFUL; } NTSTATUS -i8042ReadStatus(IN PPORT_DEVICE_EXTENSION DeviceExtension, - OUT PUCHAR Status) +i8042ReadStatus( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + OUT PUCHAR Status) { - ASSERT(DeviceExtension->ControlPort != NULL); - *Status = READ_PORT_UCHAR(DeviceExtension->ControlPort); - return STATUS_SUCCESS; + ASSERT(DeviceExtension->ControlPort != NULL); + *Status = READ_PORT_UCHAR(DeviceExtension->ControlPort); + return STATUS_SUCCESS; } /* -* FUNCTION: Read data from data port -*/ + * FUNCTION: Read data from data port + */ NTSTATUS -i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, - OUT PUCHAR Data) +i8042ReadDataWait( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + OUT PUCHAR Data) { - ULONG Counter; - NTSTATUS Status; + ULONG Counter; + NTSTATUS Status; - Counter = DeviceExtension->Settings.PollingIterations; + Counter = DeviceExtension->Settings.PollingIterations; - while (Counter--) - { - Status = i8042ReadKeyboardData(DeviceExtension, Data); + while (Counter--) + { + Status = i8042ReadKeyboardData(DeviceExtension, Data); - if (NT_SUCCESS(Status)) - return Status; + if (NT_SUCCESS(Status)) + return Status; - KeStallExecutionProcessor(50); - } + KeStallExecutionProcessor(50); + } - /* Timed out */ - return STATUS_IO_TIMEOUT; + /* Timed out */ + return STATUS_IO_TIMEOUT; } /* -* This one reads a value from the port; You don't have to specify -* which one, it'll always be from the one you talked to, so one function -* is enough this time. Note how MSDN specifies the -* WaitForAck parameter to be ignored. -*/ + * This one reads a value from the port; You don't have to specify + * which one, it'll always be from the one you talked to, so one function + * is enough this time. Note how MSDN specifies the + * WaitForAck parameter to be ignored. + */ NTSTATUS NTAPI -i8042SynchReadPort(IN PVOID Context, - OUT PUCHAR Value, - IN BOOLEAN WaitForAck) +i8042SynchReadPort( + IN PVOID Context, + OUT PUCHAR Value, + IN BOOLEAN WaitForAck) { - PPORT_DEVICE_EXTENSION DeviceExtension; + PPORT_DEVICE_EXTENSION DeviceExtension; - DeviceExtension = (PPORT_DEVICE_EXTENSION)Context; + DeviceExtension = (PPORT_DEVICE_EXTENSION)Context; - return i8042ReadDataWait(DeviceExtension, Value); + return i8042ReadDataWait(DeviceExtension, Value); } /* -* These functions are callbacks for filter driver custom -* initialization routines. -*/ + * These functions are callbacks for filter driver custom + * initialization routines. + */ NTSTATUS NTAPI -i8042SynchWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN UCHAR Port, - IN UCHAR Value, - IN BOOLEAN WaitForAck) +i8042SynchWritePort( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN UCHAR Port, + IN UCHAR Value, + IN BOOLEAN WaitForAck) { - NTSTATUS Status; - UCHAR Ack; - ULONG ResendIterations; + NTSTATUS Status; + UCHAR Ack; + ULONG ResendIterations; - ResendIterations = DeviceExtension->Settings.ResendIterations + 1; + ResendIterations = DeviceExtension->Settings.ResendIterations + 1; - do - { - if (Port) - if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Port)) - { - WARN_(I8042PRT, "Failed to write Port\n"); - return STATUS_IO_TIMEOUT; - } + do + { + if (Port) + if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Port)) + { + WARN_(I8042PRT, "Failed to write Port\n"); + return STATUS_IO_TIMEOUT; + } - if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value)) - { - WARN_(I8042PRT, "Failed to write Value\n"); - return STATUS_IO_TIMEOUT; - } + if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value)) + { + WARN_(I8042PRT, "Failed to write Value\n"); + return STATUS_IO_TIMEOUT; + } - if (WaitForAck) - { - Status = i8042ReadDataWait(DeviceExtension, &Ack); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "Failed to read Ack\n"); - return Status; - } - if (Ack == KBD_ACK) - return STATUS_SUCCESS; - else if (Ack == KBD_RESEND) - INFO_(I8042PRT, "i8042 asks for a data resend\n"); - } - else - { - return STATUS_SUCCESS; - } - TRACE_(I8042PRT, "Reiterating\n"); - ResendIterations--; - } while (ResendIterations); + if (WaitForAck) + { + Status = i8042ReadDataWait(DeviceExtension, &Ack); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "Failed to read Ack\n"); + return Status; + } + if (Ack == KBD_ACK) + return STATUS_SUCCESS; + else if (Ack == KBD_RESEND) + INFO_(I8042PRT, "i8042 asks for a data resend\n"); + } + else + { + return STATUS_SUCCESS; + } + TRACE_(I8042PRT, "Reiterating\n"); + ResendIterations--; + } while (ResendIterations); - return STATUS_IO_TIMEOUT; + return STATUS_IO_TIMEOUT; } /* -* FUNCTION: Write data to a port, waiting first for it to become ready -*/ + * FUNCTION: Write data to a port, waiting first for it to become ready + */ BOOLEAN -i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, - IN PUCHAR addr, - IN UCHAR data) +i8042Write( + IN PPORT_DEVICE_EXTENSION DeviceExtension, + IN PUCHAR addr, + IN UCHAR data) { - ULONG Counter; + ULONG Counter; - ASSERT(addr); - ASSERT(DeviceExtension->ControlPort != NULL); + ASSERT(addr); + ASSERT(DeviceExtension->ControlPort != NULL); - Counter = DeviceExtension->Settings.PollingIterations; + Counter = DeviceExtension->Settings.PollingIterations; - while ((KBD_IBF & READ_PORT_UCHAR(DeviceExtension->ControlPort)) && - (Counter--)) - { - KeStallExecutionProcessor(50); - } + while ((KBD_IBF & READ_PORT_UCHAR(DeviceExtension->ControlPort)) && + (Counter--)) + { + KeStallExecutionProcessor(50); + } - if (Counter) - { - WRITE_PORT_UCHAR(addr, data); - INFO_(I8042PRT, "Sent 0x%x to port %p\n", data, addr); - return TRUE; - } - return FALSE; + if (Counter) + { + WRITE_PORT_UCHAR(addr, data); + INFO_(I8042PRT, "Sent 0x%x to port %p\n", data, addr); + return TRUE; + } + return FALSE; } diff --git a/reactos/drivers/input/i8042prt/registry.c b/reactos/drivers/input/i8042prt/registry.c index 6baca89d3d4..24c74424f56 100644 --- a/reactos/drivers/input/i8042prt/registry.c +++ b/reactos/drivers/input/i8042prt/registry.c @@ -16,215 +16,216 @@ /* FUNCTIONS *****************************************************************/ NTSTATUS -ReadRegistryEntries(IN PUNICODE_STRING RegistryPath, - OUT PI8042_SETTINGS Settings) +ReadRegistryEntries( + IN PUNICODE_STRING RegistryPath, + OUT PI8042_SETTINGS Settings) { - RTL_QUERY_REGISTRY_TABLE Parameters[17]; - NTSTATUS Status; + RTL_QUERY_REGISTRY_TABLE Parameters[17]; + NTSTATUS Status; - ULONG DefaultKeyboardDataQueueSize = 0x64; - PCWSTR DefaultKeyboardDeviceBaseName = L"KeyboardPort"; - ULONG DefaultMouseDataQueueSize = 0x64; - ULONG DefaultMouseResolution = 3; - ULONG DefaultMouseSynchIn100ns = 20000000; - ULONG DefaultNumberOfButtons = 2; - PCWSTR DefaultPointerDeviceBaseName = L"PointerPort"; - ULONG DefaultPollStatusIterations = 1; - ULONG DefaultOverrideKeyboardType = 4; - ULONG DefaultOverrideKeyboardSubtype = 0; - ULONG DefaultPollingIterations = 12000; - ULONG DefaultPollingIterationsMaximum = 12000; - ULONG DefaultResendIterations = 0x3; - ULONG DefaultSampleRate = 60; - ULONG DefaultCrashOnCtrlScroll; + ULONG DefaultKeyboardDataQueueSize = 0x64; + PCWSTR DefaultKeyboardDeviceBaseName = L"KeyboardPort"; + ULONG DefaultMouseDataQueueSize = 0x64; + ULONG DefaultMouseResolution = 3; + ULONG DefaultMouseSynchIn100ns = 20000000; + ULONG DefaultNumberOfButtons = 2; + PCWSTR DefaultPointerDeviceBaseName = L"PointerPort"; + ULONG DefaultPollStatusIterations = 1; + ULONG DefaultOverrideKeyboardType = 4; + ULONG DefaultOverrideKeyboardSubtype = 0; + ULONG DefaultPollingIterations = 12000; + ULONG DefaultPollingIterationsMaximum = 12000; + ULONG DefaultResendIterations = 0x3; + ULONG DefaultSampleRate = 60; + ULONG DefaultCrashOnCtrlScroll; - /* Default value for CrashOnCtrlScroll depends if we're - * running a debug build or a normal build. - */ + /* Default value for CrashOnCtrlScroll depends if we're + * running a debug build or a normal build. + */ #ifdef DBG - DefaultCrashOnCtrlScroll = 1; + DefaultCrashOnCtrlScroll = 1; #else - DefaultCrashOnCtrlScroll = 0; + DefaultCrashOnCtrlScroll = 0; #endif - RtlZeroMemory(Parameters, sizeof(Parameters)); + RtlZeroMemory(Parameters, sizeof(Parameters)); - Parameters[0].Flags = RTL_QUERY_REGISTRY_SUBKEY; - Parameters[0].Name = L"Parameters"; + Parameters[0].Flags = RTL_QUERY_REGISTRY_SUBKEY; + Parameters[0].Name = L"Parameters"; - Parameters[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[1].Name = L"KeyboardDataQueueSize"; - Parameters[1].EntryContext = &Settings->KeyboardDataQueueSize; - Parameters[1].DefaultType = REG_DWORD; - Parameters[1].DefaultData = &DefaultKeyboardDataQueueSize; - Parameters[1].DefaultLength = sizeof(ULONG); + Parameters[1].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[1].Name = L"KeyboardDataQueueSize"; + Parameters[1].EntryContext = &Settings->KeyboardDataQueueSize; + Parameters[1].DefaultType = REG_DWORD; + Parameters[1].DefaultData = &DefaultKeyboardDataQueueSize; + Parameters[1].DefaultLength = sizeof(ULONG); - Parameters[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[2].Name = L"KeyboardDeviceBaseName"; - Parameters[2].EntryContext = &Settings->KeyboardDeviceBaseName; - Parameters[2].DefaultType = REG_SZ; - Parameters[2].DefaultData = (PVOID)DefaultKeyboardDeviceBaseName; - Parameters[2].DefaultLength = 0; + Parameters[2].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[2].Name = L"KeyboardDeviceBaseName"; + Parameters[2].EntryContext = &Settings->KeyboardDeviceBaseName; + Parameters[2].DefaultType = REG_SZ; + Parameters[2].DefaultData = (PVOID)DefaultKeyboardDeviceBaseName; + Parameters[2].DefaultLength = 0; - Parameters[3].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[3].Name = L"MouseDataQueueSize"; - Parameters[3].EntryContext = &Settings->MouseDataQueueSize; - Parameters[3].DefaultType = REG_DWORD; - Parameters[3].DefaultData = &DefaultMouseDataQueueSize; - Parameters[3].DefaultLength = sizeof(ULONG); + Parameters[3].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[3].Name = L"MouseDataQueueSize"; + Parameters[3].EntryContext = &Settings->MouseDataQueueSize; + Parameters[3].DefaultType = REG_DWORD; + Parameters[3].DefaultData = &DefaultMouseDataQueueSize; + Parameters[3].DefaultLength = sizeof(ULONG); - Parameters[4].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[4].Name = L"MouseResolution"; - Parameters[4].EntryContext = &Settings->MouseResolution; - Parameters[4].DefaultType = REG_DWORD; - Parameters[4].DefaultData = &DefaultMouseResolution; - Parameters[4].DefaultLength = sizeof(ULONG); + Parameters[4].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[4].Name = L"MouseResolution"; + Parameters[4].EntryContext = &Settings->MouseResolution; + Parameters[4].DefaultType = REG_DWORD; + Parameters[4].DefaultData = &DefaultMouseResolution; + Parameters[4].DefaultLength = sizeof(ULONG); - Parameters[5].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[5].Name = L"MouseSynchIn100ns"; - Parameters[5].EntryContext = &Settings->MouseSynchIn100ns; - Parameters[5].DefaultType = REG_DWORD; - Parameters[5].DefaultData = &DefaultMouseSynchIn100ns; - Parameters[5].DefaultLength = sizeof(ULONG); + Parameters[5].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[5].Name = L"MouseSynchIn100ns"; + Parameters[5].EntryContext = &Settings->MouseSynchIn100ns; + Parameters[5].DefaultType = REG_DWORD; + Parameters[5].DefaultData = &DefaultMouseSynchIn100ns; + Parameters[5].DefaultLength = sizeof(ULONG); - Parameters[6].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[6].Name = L"NumberOfButtons"; - Parameters[6].EntryContext = &Settings->NumberOfButtons; - Parameters[6].DefaultType = REG_DWORD; - Parameters[6].DefaultData = &DefaultNumberOfButtons; - Parameters[6].DefaultLength = sizeof(ULONG); + Parameters[6].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[6].Name = L"NumberOfButtons"; + Parameters[6].EntryContext = &Settings->NumberOfButtons; + Parameters[6].DefaultType = REG_DWORD; + Parameters[6].DefaultData = &DefaultNumberOfButtons; + Parameters[6].DefaultLength = sizeof(ULONG); - Parameters[7].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[7].Name = L"PointerDeviceBaseName"; - Parameters[7].EntryContext = &Settings->PointerDeviceBaseName; - Parameters[7].DefaultType = REG_SZ; - Parameters[7].DefaultData = (PVOID)DefaultPointerDeviceBaseName; - Parameters[7].DefaultLength = 0; + Parameters[7].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[7].Name = L"PointerDeviceBaseName"; + Parameters[7].EntryContext = &Settings->PointerDeviceBaseName; + Parameters[7].DefaultType = REG_SZ; + Parameters[7].DefaultData = (PVOID)DefaultPointerDeviceBaseName; + Parameters[7].DefaultLength = 0; - Parameters[8].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[8].Name = L"PollStatusIterations"; - Parameters[8].EntryContext = &Settings->PollStatusIterations; - Parameters[8].DefaultType = REG_DWORD; - Parameters[8].DefaultData = &DefaultPollStatusIterations; - Parameters[8].DefaultLength = sizeof(ULONG); + Parameters[8].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[8].Name = L"PollStatusIterations"; + Parameters[8].EntryContext = &Settings->PollStatusIterations; + Parameters[8].DefaultType = REG_DWORD; + Parameters[8].DefaultData = &DefaultPollStatusIterations; + Parameters[8].DefaultLength = sizeof(ULONG); - Parameters[9].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[9].Name = L"OverrideKeyboardType"; - Parameters[9].EntryContext = &Settings->OverrideKeyboardType; - Parameters[9].DefaultType = REG_DWORD; - Parameters[9].DefaultData = &DefaultOverrideKeyboardType; - Parameters[9].DefaultLength = sizeof(ULONG); + Parameters[9].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[9].Name = L"OverrideKeyboardType"; + Parameters[9].EntryContext = &Settings->OverrideKeyboardType; + Parameters[9].DefaultType = REG_DWORD; + Parameters[9].DefaultData = &DefaultOverrideKeyboardType; + Parameters[9].DefaultLength = sizeof(ULONG); - Parameters[10].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[10].Name = L"OverrideKeyboardSubtype"; - Parameters[10].EntryContext = &Settings->OverrideKeyboardSubtype; - Parameters[10].DefaultType = REG_DWORD; - Parameters[10].DefaultData = &DefaultOverrideKeyboardSubtype; - Parameters[10].DefaultLength = sizeof(ULONG); + Parameters[10].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[10].Name = L"OverrideKeyboardSubtype"; + Parameters[10].EntryContext = &Settings->OverrideKeyboardSubtype; + Parameters[10].DefaultType = REG_DWORD; + Parameters[10].DefaultData = &DefaultOverrideKeyboardSubtype; + Parameters[10].DefaultLength = sizeof(ULONG); - Parameters[11].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[11].Name = L"PollingIterations"; - Parameters[11].EntryContext = &Settings->PollingIterations; - Parameters[11].DefaultType = REG_DWORD; - Parameters[11].DefaultData = &DefaultPollingIterations; - Parameters[11].DefaultLength = sizeof(ULONG); + Parameters[11].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[11].Name = L"PollingIterations"; + Parameters[11].EntryContext = &Settings->PollingIterations; + Parameters[11].DefaultType = REG_DWORD; + Parameters[11].DefaultData = &DefaultPollingIterations; + Parameters[11].DefaultLength = sizeof(ULONG); - Parameters[12].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[12].Name = L"PollingIterationsMaximum"; - Parameters[12].EntryContext = &Settings->PollingIterationsMaximum; - Parameters[12].DefaultType = REG_DWORD; - Parameters[12].DefaultData = &DefaultPollingIterationsMaximum; - Parameters[12].DefaultLength = sizeof(ULONG); + Parameters[12].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[12].Name = L"PollingIterationsMaximum"; + Parameters[12].EntryContext = &Settings->PollingIterationsMaximum; + Parameters[12].DefaultType = REG_DWORD; + Parameters[12].DefaultData = &DefaultPollingIterationsMaximum; + Parameters[12].DefaultLength = sizeof(ULONG); - Parameters[13].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[13].Name = L"ResendIterations"; - Parameters[13].EntryContext = &Settings->ResendIterations; - Parameters[13].DefaultType = REG_DWORD; - Parameters[13].DefaultData = &DefaultResendIterations; - Parameters[13].DefaultLength = sizeof(ULONG); + Parameters[13].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[13].Name = L"ResendIterations"; + Parameters[13].EntryContext = &Settings->ResendIterations; + Parameters[13].DefaultType = REG_DWORD; + Parameters[13].DefaultData = &DefaultResendIterations; + Parameters[13].DefaultLength = sizeof(ULONG); - Parameters[14].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[14].Name = L"SampleRate"; - Parameters[14].EntryContext = &Settings->SampleRate; - Parameters[14].DefaultType = REG_DWORD; - Parameters[14].DefaultData = &DefaultSampleRate; - Parameters[14].DefaultLength = sizeof(ULONG); + Parameters[14].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[14].Name = L"SampleRate"; + Parameters[14].EntryContext = &Settings->SampleRate; + Parameters[14].DefaultType = REG_DWORD; + Parameters[14].DefaultData = &DefaultSampleRate; + Parameters[14].DefaultLength = sizeof(ULONG); - Parameters[15].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; - Parameters[15].Name = L"CrashOnCtrlScroll"; - Parameters[15].EntryContext = &Settings->CrashOnCtrlScroll; - Parameters[15].DefaultType = REG_DWORD; - Parameters[15].DefaultData = &DefaultCrashOnCtrlScroll; - Parameters[15].DefaultLength = sizeof(ULONG); + Parameters[15].Flags = RTL_QUERY_REGISTRY_DIRECT | RTL_REGISTRY_OPTIONAL; + Parameters[15].Name = L"CrashOnCtrlScroll"; + Parameters[15].EntryContext = &Settings->CrashOnCtrlScroll; + Parameters[15].DefaultType = REG_DWORD; + Parameters[15].DefaultData = &DefaultCrashOnCtrlScroll; + Parameters[15].DefaultLength = sizeof(ULONG); - Status = RtlQueryRegistryValues( - RTL_REGISTRY_ABSOLUTE, - RegistryPath->Buffer, - Parameters, - NULL, - NULL); + Status = RtlQueryRegistryValues( + RTL_REGISTRY_ABSOLUTE, + RegistryPath->Buffer, + Parameters, + NULL, + NULL); - if (NT_SUCCESS(Status)) - { - /* Check values */ - if (Settings->KeyboardDataQueueSize < 1) - Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize; - if (Settings->MouseDataQueueSize < 1) - Settings->MouseDataQueueSize = DefaultMouseDataQueueSize; - if (Settings->NumberOfButtons < 1) - Settings->NumberOfButtons = DefaultNumberOfButtons; - if (Settings->PollingIterations < 0x400) - Settings->PollingIterations = DefaultPollingIterations; - if (Settings->PollingIterationsMaximum < 0x400) - Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum; - if (Settings->ResendIterations < 1) - Settings->ResendIterations = DefaultResendIterations; - } - else if (Status == STATUS_OBJECT_NAME_NOT_FOUND) - { - /* Registry path doesn't exist. Set defaults */ - Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize; - Settings->MouseDataQueueSize = DefaultMouseDataQueueSize; - Settings->MouseResolution = DefaultMouseResolution; - Settings->MouseSynchIn100ns = DefaultMouseSynchIn100ns; - Settings->NumberOfButtons = DefaultNumberOfButtons; - Settings->PollStatusIterations = DefaultPollStatusIterations; - Settings->OverrideKeyboardType = DefaultOverrideKeyboardType; - Settings->OverrideKeyboardSubtype = DefaultOverrideKeyboardSubtype; - Settings->PollingIterations = DefaultPollingIterations; - Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum; - Settings->ResendIterations = DefaultResendIterations; - Settings->SampleRate = DefaultSampleRate; - Settings->CrashOnCtrlScroll = DefaultCrashOnCtrlScroll; - if (!RtlCreateUnicodeString(&Settings->KeyboardDeviceBaseName, DefaultKeyboardDeviceBaseName) - || !RtlCreateUnicodeString(&Settings->PointerDeviceBaseName, DefaultPointerDeviceBaseName)) - { - WARN_(I8042PRT, "RtlCreateUnicodeString() failed\n"); - Status = STATUS_NO_MEMORY; - } - else - { - Status = STATUS_SUCCESS; - } - } + if (NT_SUCCESS(Status)) + { + /* Check values */ + if (Settings->KeyboardDataQueueSize < 1) + Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize; + if (Settings->MouseDataQueueSize < 1) + Settings->MouseDataQueueSize = DefaultMouseDataQueueSize; + if (Settings->NumberOfButtons < 1) + Settings->NumberOfButtons = DefaultNumberOfButtons; + if (Settings->PollingIterations < 0x400) + Settings->PollingIterations = DefaultPollingIterations; + if (Settings->PollingIterationsMaximum < 0x400) + Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum; + if (Settings->ResendIterations < 1) + Settings->ResendIterations = DefaultResendIterations; + } + else if (Status == STATUS_OBJECT_NAME_NOT_FOUND) + { + /* Registry path doesn't exist. Set defaults */ + Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize; + Settings->MouseDataQueueSize = DefaultMouseDataQueueSize; + Settings->MouseResolution = DefaultMouseResolution; + Settings->MouseSynchIn100ns = DefaultMouseSynchIn100ns; + Settings->NumberOfButtons = DefaultNumberOfButtons; + Settings->PollStatusIterations = DefaultPollStatusIterations; + Settings->OverrideKeyboardType = DefaultOverrideKeyboardType; + Settings->OverrideKeyboardSubtype = DefaultOverrideKeyboardSubtype; + Settings->PollingIterations = DefaultPollingIterations; + Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum; + Settings->ResendIterations = DefaultResendIterations; + Settings->SampleRate = DefaultSampleRate; + Settings->CrashOnCtrlScroll = DefaultCrashOnCtrlScroll; + if (!RtlCreateUnicodeString(&Settings->KeyboardDeviceBaseName, DefaultKeyboardDeviceBaseName) + || !RtlCreateUnicodeString(&Settings->PointerDeviceBaseName, DefaultPointerDeviceBaseName)) + { + WARN_(I8042PRT, "RtlCreateUnicodeString() failed\n"); + Status = STATUS_NO_MEMORY; + } + else + { + Status = STATUS_SUCCESS; + } + } - if (NT_SUCCESS(Status)) - { - INFO_(I8042PRT, "KeyboardDataQueueSize : 0x%lx\n", Settings->KeyboardDataQueueSize); - INFO_(I8042PRT, "KeyboardDeviceBaseName : %wZ\n", &Settings->KeyboardDeviceBaseName); - INFO_(I8042PRT, "MouseDataQueueSize : 0x%lx\n", Settings->MouseDataQueueSize); - INFO_(I8042PRT, "MouseResolution : 0x%lx\n", Settings->MouseResolution); - INFO_(I8042PRT, "MouseSynchIn100ns : %lu\n", Settings->MouseSynchIn100ns); - INFO_(I8042PRT, "NumberOfButtons : 0x%lx\n", Settings->NumberOfButtons); - INFO_(I8042PRT, "PointerDeviceBaseName : %wZ\n", &Settings->PointerDeviceBaseName); - INFO_(I8042PRT, "PollStatusIterations : 0x%lx\n", Settings->PollStatusIterations); - INFO_(I8042PRT, "OverrideKeyboardType : 0x%lx\n", Settings->OverrideKeyboardType); - INFO_(I8042PRT, "OverrideKeyboardSubtype : 0x%lx\n", Settings->OverrideKeyboardSubtype); - INFO_(I8042PRT, "PollingIterations : 0x%lx\n", Settings->PollingIterations); - INFO_(I8042PRT, "PollingIterationsMaximum : %lu\n", Settings->PollingIterationsMaximum); - INFO_(I8042PRT, "ResendIterations : 0x%lx\n", Settings->ResendIterations); - INFO_(I8042PRT, "SampleRate : %lu\n", Settings->SampleRate); - } + if (NT_SUCCESS(Status)) + { + INFO_(I8042PRT, "KeyboardDataQueueSize : 0x%lx\n", Settings->KeyboardDataQueueSize); + INFO_(I8042PRT, "KeyboardDeviceBaseName : %wZ\n", &Settings->KeyboardDeviceBaseName); + INFO_(I8042PRT, "MouseDataQueueSize : 0x%lx\n", Settings->MouseDataQueueSize); + INFO_(I8042PRT, "MouseResolution : 0x%lx\n", Settings->MouseResolution); + INFO_(I8042PRT, "MouseSynchIn100ns : %lu\n", Settings->MouseSynchIn100ns); + INFO_(I8042PRT, "NumberOfButtons : 0x%lx\n", Settings->NumberOfButtons); + INFO_(I8042PRT, "PointerDeviceBaseName : %wZ\n", &Settings->PointerDeviceBaseName); + INFO_(I8042PRT, "PollStatusIterations : 0x%lx\n", Settings->PollStatusIterations); + INFO_(I8042PRT, "OverrideKeyboardType : 0x%lx\n", Settings->OverrideKeyboardType); + INFO_(I8042PRT, "OverrideKeyboardSubtype : 0x%lx\n", Settings->OverrideKeyboardSubtype); + INFO_(I8042PRT, "PollingIterations : 0x%lx\n", Settings->PollingIterations); + INFO_(I8042PRT, "PollingIterationsMaximum : %lu\n", Settings->PollingIterationsMaximum); + INFO_(I8042PRT, "ResendIterations : 0x%lx\n", Settings->ResendIterations); + INFO_(I8042PRT, "SampleRate : %lu\n", Settings->SampleRate); + } - return Status; + return Status; } diff --git a/reactos/drivers/input/i8042prt/setup.c b/reactos/drivers/input/i8042prt/setup.c index 4f6c08a5857..17d08468b7b 100644 --- a/reactos/drivers/input/i8042prt/setup.c +++ b/reactos/drivers/input/i8042prt/setup.c @@ -7,8 +7,8 @@ */ /* NOTE: -* All this file is a big hack and should be removed one day... -*/ + * All this file is a big hack and should be removed one day... + */ /* INCLUDES ******************************************************************/ @@ -23,247 +23,251 @@ /* FUNCTIONS *****************************************************************/ BOOLEAN -IsFirstStageSetup(VOID) +IsFirstStageSetup( + VOID) { - UNICODE_STRING PathU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\Setup"); - OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE hSetupKey = (HANDLE)NULL; - NTSTATUS Status; - BOOLEAN ret = TRUE; + UNICODE_STRING PathU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\SYSTEM\\Setup"); + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE hSetupKey = (HANDLE)NULL; + NTSTATUS Status; + BOOLEAN ret = TRUE; - InitializeObjectAttributes(&ObjectAttributes, &PathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = ZwOpenKey(&hSetupKey, KEY_QUERY_VALUE, &ObjectAttributes); + InitializeObjectAttributes(&ObjectAttributes, &PathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); + Status = ZwOpenKey(&hSetupKey, KEY_QUERY_VALUE, &ObjectAttributes); - if (Status == STATUS_OBJECT_NAME_NOT_FOUND) - ret = TRUE; - else - ret = FALSE; + if (Status == STATUS_OBJECT_NAME_NOT_FOUND) + ret = TRUE; + else + ret = FALSE; - if (hSetupKey != (HANDLE)NULL) - ZwClose(hSetupKey); - INFO_(I8042PRT, "IsFirstStageSetup() returns %s\n", ret ? "YES" : "NO"); - return ret; + if (hSetupKey != (HANDLE)NULL) + ZwClose(hSetupKey); + INFO_(I8042PRT, "IsFirstStageSetup() returns %s\n", ret ? "YES" : "NO"); + return ret; } static VOID NTAPI -SendStartDevice(IN PDRIVER_OBJECT DriverObject, - IN PVOID Context, - IN ULONG Count) +SendStartDevice( + IN PDRIVER_OBJECT DriverObject, + IN PVOID Context, + IN ULONG Count) { - PDEVICE_OBJECT Pdo; - PCM_RESOURCE_LIST AllocatedResources = NULL; - PCM_RESOURCE_LIST AllocatedResourcesTranslated = NULL; - PDEVICE_OBJECT TopDeviceObject = NULL; - KEVENT Event; - IO_STATUS_BLOCK IoStatusBlock; - PIRP Irp; - PIO_STACK_LOCATION Stack; - ULONG ResourceListSize; - NTSTATUS Status; + PDEVICE_OBJECT Pdo; + PCM_RESOURCE_LIST AllocatedResources = NULL; + PCM_RESOURCE_LIST AllocatedResourcesTranslated = NULL; + PDEVICE_OBJECT TopDeviceObject = NULL; + KEVENT Event; + IO_STATUS_BLOCK IoStatusBlock; + PIRP Irp; + PIO_STACK_LOCATION Stack; + ULONG ResourceListSize; + NTSTATUS Status; - Pdo = (PDEVICE_OBJECT)Context; - TRACE_(I8042PRT, "SendStartDevice(%p)\n", Pdo); + Pdo = (PDEVICE_OBJECT)Context; + TRACE_(I8042PRT, "SendStartDevice(%p)\n", Pdo); - /* Create default resource list */ - ResourceListSize = sizeof(CM_RESOURCE_LIST) + 3 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); - AllocatedResources = ExAllocatePoolWithTag(PagedPool, ResourceListSize, I8042PRT_TAG); - if (!AllocatedResources) - { - WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - AllocatedResources->Count = 1; - AllocatedResources->List[0].PartialResourceList.Version = 1; - AllocatedResources->List[0].PartialResourceList.Revision = 1; - AllocatedResources->List[0].PartialResourceList.Count = 3; - /* Data port */ - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Type = CmResourceTypePort; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDeviceExclusive; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Flags = 0; /* FIXME */ - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Start.u.HighPart = 0; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Start.u.LowPart = KEYBOARD_DATA_PORT; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Length = 1; - /* Control port */ - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].Type = CmResourceTypePort; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].ShareDisposition = CmResourceShareDeviceExclusive; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].Flags = 0; /* FIXME */ - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Port.Start.u.HighPart = 0; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Port.Start.u.LowPart = KEYBOARD_CONTROL_PORT; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Port.Length = 1; - /* Interrupt */ - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].Type = CmResourceTypeInterrupt; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].ShareDisposition = CmResourceShareDeviceExclusive; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].Flags = CM_RESOURCE_INTERRUPT_LATCHED; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Level = KEYBOARD_IRQ; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Vector = 0; - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Affinity = (KAFFINITY)-1; + /* Create default resource list */ + ResourceListSize = sizeof(CM_RESOURCE_LIST) + 3 * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR); + AllocatedResources = ExAllocatePoolWithTag(PagedPool, ResourceListSize, I8042PRT_TAG); + if (!AllocatedResources) + { + WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + AllocatedResources->Count = 1; + AllocatedResources->List[0].PartialResourceList.Version = 1; + AllocatedResources->List[0].PartialResourceList.Revision = 1; + AllocatedResources->List[0].PartialResourceList.Count = 3; + /* Data port */ + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Type = CmResourceTypePort; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].ShareDisposition = CmResourceShareDeviceExclusive; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].Flags = 0; /* FIXME */ + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Start.u.HighPart = 0; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Start.u.LowPart = KEYBOARD_DATA_PORT; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[0].u.Port.Length = 1; + /* Control port */ + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].Type = CmResourceTypePort; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].ShareDisposition = CmResourceShareDeviceExclusive; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].Flags = 0; /* FIXME */ + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Port.Start.u.HighPart = 0; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Port.Start.u.LowPart = KEYBOARD_CONTROL_PORT; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[1].u.Port.Length = 1; + /* Interrupt */ + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].Type = CmResourceTypeInterrupt; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].ShareDisposition = CmResourceShareDeviceExclusive; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].Flags = CM_RESOURCE_INTERRUPT_LATCHED; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Level = KEYBOARD_IRQ; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Vector = 0; + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Affinity = (KAFFINITY)-1; - /* Create default resource list translated */ - AllocatedResourcesTranslated = ExAllocatePoolWithTag(PagedPool, ResourceListSize, I8042PRT_TAG); - if (!AllocatedResourcesTranslated) - { - WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); - Status = STATUS_NO_MEMORY; - goto cleanup; - } - RtlCopyMemory(AllocatedResourcesTranslated, AllocatedResources, ResourceListSize); - AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Vector = HalGetInterruptVector( - Internal, 0, - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Level, - AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Vector, - (PKIRQL)&AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Level, - &AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Affinity); + /* Create default resource list translated */ + AllocatedResourcesTranslated = ExAllocatePoolWithTag(PagedPool, ResourceListSize, I8042PRT_TAG); + if (!AllocatedResourcesTranslated) + { + WARN_(I8042PRT, "ExAllocatePoolWithTag() failed\n"); + Status = STATUS_NO_MEMORY; + goto cleanup; + } + RtlCopyMemory(AllocatedResourcesTranslated, AllocatedResources, ResourceListSize); + AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Vector = HalGetInterruptVector( + Internal, 0, + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Level, + AllocatedResources->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Vector, + (PKIRQL)&AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Level, + &AllocatedResourcesTranslated->List[0].PartialResourceList.PartialDescriptors[2].u.Interrupt.Affinity); - /* Send IRP_MN_START_DEVICE */ - TopDeviceObject = IoGetAttachedDeviceReference(Pdo); - KeInitializeEvent( - &Event, - NotificationEvent, - FALSE); - Irp = IoBuildSynchronousFsdRequest( - IRP_MJ_PNP, - TopDeviceObject, - NULL, - 0, - NULL, - &Event, - &IoStatusBlock); - Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED; - Irp->IoStatus.Information = 0; - Stack = IoGetNextIrpStackLocation(Irp); - Stack->MinorFunction = IRP_MN_START_DEVICE; - Stack->Parameters.StartDevice.AllocatedResources = AllocatedResources; - Stack->Parameters.StartDevice.AllocatedResourcesTranslated = AllocatedResourcesTranslated; - Status = IoCallDriver(TopDeviceObject, Irp); - if (Status == STATUS_PENDING) - { - KeWaitForSingleObject( - &Event, - Executive, - KernelMode, - FALSE, - NULL); - Status = IoStatusBlock.Status; - } - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoCallDriver() failed with status 0x%08lx\n", Status); - goto cleanup; - } + /* Send IRP_MN_START_DEVICE */ + TopDeviceObject = IoGetAttachedDeviceReference(Pdo); + KeInitializeEvent( + &Event, + NotificationEvent, + FALSE); + Irp = IoBuildSynchronousFsdRequest( + IRP_MJ_PNP, + TopDeviceObject, + NULL, + 0, + NULL, + &Event, + &IoStatusBlock); + Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED; + Irp->IoStatus.Information = 0; + Stack = IoGetNextIrpStackLocation(Irp); + Stack->MinorFunction = IRP_MN_START_DEVICE; + Stack->Parameters.StartDevice.AllocatedResources = AllocatedResources; + Stack->Parameters.StartDevice.AllocatedResourcesTranslated = AllocatedResourcesTranslated; + Status = IoCallDriver(TopDeviceObject, Irp); + if (Status == STATUS_PENDING) + { + KeWaitForSingleObject( + &Event, + Executive, + KernelMode, + FALSE, + NULL); + Status = IoStatusBlock.Status; + } + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoCallDriver() failed with status 0x%08lx\n", Status); + goto cleanup; + } cleanup: - if (TopDeviceObject) - ObDereferenceObject(TopDeviceObject); - if (AllocatedResources) - ExFreePoolWithTag(AllocatedResources, I8042PRT_TAG); - if (AllocatedResourcesTranslated) - ExFreePoolWithTag(AllocatedResourcesTranslated, I8042PRT_TAG); + if (TopDeviceObject) + ObDereferenceObject(TopDeviceObject); + if (AllocatedResources) + ExFreePoolWithTag(AllocatedResources, I8042PRT_TAG); + if (AllocatedResourcesTranslated) + ExFreePoolWithTag(AllocatedResourcesTranslated, I8042PRT_TAG); } static NTSTATUS -AddRegistryEntry(IN PCWSTR PortTypeName, - IN PUNICODE_STRING DeviceName, - IN PCWSTR RegistryPath) +AddRegistryEntry( + IN PCWSTR PortTypeName, + IN PUNICODE_STRING DeviceName, + IN PCWSTR RegistryPath) { - UNICODE_STRING PathU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DEVICEMAP"); - OBJECT_ATTRIBUTES ObjectAttributes; - HANDLE hDeviceMapKey = (HANDLE)-1; - HANDLE hPortKey = (HANDLE)-1; - UNICODE_STRING PortTypeNameU; - NTSTATUS Status; + UNICODE_STRING PathU = RTL_CONSTANT_STRING(L"\\REGISTRY\\MACHINE\\HARDWARE\\DEVICEMAP"); + OBJECT_ATTRIBUTES ObjectAttributes; + HANDLE hDeviceMapKey = (HANDLE)-1; + HANDLE hPortKey = (HANDLE)-1; + UNICODE_STRING PortTypeNameU; + NTSTATUS Status; - InitializeObjectAttributes(&ObjectAttributes, &PathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); - Status = ZwOpenKey(&hDeviceMapKey, 0, &ObjectAttributes); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "ZwOpenKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } + InitializeObjectAttributes(&ObjectAttributes, &PathU, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE, NULL, NULL); + Status = ZwOpenKey(&hDeviceMapKey, 0, &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "ZwOpenKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } - RtlInitUnicodeString(&PortTypeNameU, PortTypeName); - InitializeObjectAttributes(&ObjectAttributes, &PortTypeNameU, OBJ_KERNEL_HANDLE, hDeviceMapKey, NULL); - Status = ZwCreateKey(&hPortKey, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "ZwCreateKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } + RtlInitUnicodeString(&PortTypeNameU, PortTypeName); + InitializeObjectAttributes(&ObjectAttributes, &PortTypeNameU, OBJ_KERNEL_HANDLE, hDeviceMapKey, NULL); + Status = ZwCreateKey(&hPortKey, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE, NULL); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "ZwCreateKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } - Status = ZwSetValueKey(hPortKey, DeviceName, 0, REG_SZ, (PVOID)RegistryPath, wcslen(RegistryPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL)); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "ZwSetValueKey() failed with status 0x%08lx\n", Status); - goto cleanup; - } + Status = ZwSetValueKey(hPortKey, DeviceName, 0, REG_SZ, (PVOID)RegistryPath, wcslen(RegistryPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL)); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "ZwSetValueKey() failed with status 0x%08lx\n", Status); + goto cleanup; + } - Status = STATUS_SUCCESS; + Status = STATUS_SUCCESS; cleanup: - if (hDeviceMapKey != (HANDLE)-1) - ZwClose(hDeviceMapKey); - if (hPortKey != (HANDLE)-1) - ZwClose(hPortKey); - return Status; + if (hDeviceMapKey != (HANDLE)-1) + ZwClose(hDeviceMapKey); + if (hPortKey != (HANDLE)-1) + ZwClose(hPortKey); + return Status; } NTSTATUS -i8042AddLegacyKeyboard(IN PDRIVER_OBJECT DriverObject, - IN PUNICODE_STRING RegistryPath) +i8042AddLegacyKeyboard( + IN PDRIVER_OBJECT DriverObject, + IN PUNICODE_STRING RegistryPath) { - UNICODE_STRING KeyboardName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardPort8042"); - PI8042_DEVICE_TYPE DeviceExtension = NULL; - PDEVICE_OBJECT Pdo = NULL; - NTSTATUS Status; + UNICODE_STRING KeyboardName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardPort8042"); + PI8042_DEVICE_TYPE DeviceExtension = NULL; + PDEVICE_OBJECT Pdo = NULL; + NTSTATUS Status; - TRACE_(I8042PRT, "i8042AddLegacyKeyboard()\n"); + TRACE_(I8042PRT, "i8042AddLegacyKeyboard()\n"); - /* Create a named PDO */ - Status = IoCreateDevice( - DriverObject, - sizeof(I8042_DEVICE_TYPE), - &KeyboardName, - FILE_DEVICE_8042_PORT, - FILE_DEVICE_SECURE_OPEN, - TRUE, - &Pdo); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "IoCreateDevice() failed with status 0x%08lx\n", Status); - goto cleanup; - } + /* Create a named PDO */ + Status = IoCreateDevice( + DriverObject, + sizeof(I8042_DEVICE_TYPE), + &KeyboardName, + FILE_DEVICE_8042_PORT, + FILE_DEVICE_SECURE_OPEN, + TRUE, + &Pdo); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "IoCreateDevice() failed with status 0x%08lx\n", Status); + goto cleanup; + } - /* Initialize device extension */ - DeviceExtension = (PI8042_DEVICE_TYPE)Pdo->DeviceExtension; - RtlZeroMemory(DeviceExtension, sizeof(I8042_DEVICE_TYPE)); - *DeviceExtension = PhysicalDeviceObject; - Pdo->Flags &= ~DO_DEVICE_INITIALIZING; + /* Initialize device extension */ + DeviceExtension = (PI8042_DEVICE_TYPE)Pdo->DeviceExtension; + RtlZeroMemory(DeviceExtension, sizeof(I8042_DEVICE_TYPE)); + *DeviceExtension = PhysicalDeviceObject; + Pdo->Flags &= ~DO_DEVICE_INITIALIZING; - /* Add FDO at the top of the PDO */ - Status = i8042AddDevice(DriverObject, Pdo); - if (!NT_SUCCESS(Status)) - { - WARN_(I8042PRT, "i8042AddDevice() failed with status 0x%08lx\n", Status); - goto cleanup; - } + /* Add FDO at the top of the PDO */ + Status = i8042AddDevice(DriverObject, Pdo); + if (!NT_SUCCESS(Status)) + { + WARN_(I8042PRT, "i8042AddDevice() failed with status 0x%08lx\n", Status); + goto cleanup; + } - /* We will send the IRP_MN_START_DEVICE later, once kbdclass is loaded */ - AddRegistryEntry(L"KeyboardPort", &KeyboardName, RegistryPath->Buffer); - IoRegisterBootDriverReinitialization( - DriverObject, - SendStartDevice, - Pdo); + /* We will send the IRP_MN_START_DEVICE later, once kbdclass is loaded */ + AddRegistryEntry(L"KeyboardPort", &KeyboardName, RegistryPath->Buffer); + IoRegisterBootDriverReinitialization( + DriverObject, + SendStartDevice, + Pdo); - Status = STATUS_SUCCESS; - /* Yes, completly forget the Pdo pointer, as we will never - * have to unload this driver during first stage setup. - */ + Status = STATUS_SUCCESS; + /* Yes, completly forget the Pdo pointer, as we will never + * have to unload this driver during first stage setup. + */ cleanup: - if (!NT_SUCCESS(Status)) - { - if (Pdo) - IoDeleteDevice(Pdo); - } - return Status; + if (!NT_SUCCESS(Status)) + { + if (Pdo) + IoDeleteDevice(Pdo); + } + return Status; }