- Make i8042Flush flush both output and input buffers.

- Make i8042Flush apply only KBD_OBF flag (applying MOU_OBF leads to an infinite loop trying to flush the buffer).
- Fix a bug in i8042Write, where instead of waiting by polling a PollingIterations times (~10000), it was using ResendIterations (=3), thus giving 8042 very small chance of processing the data.
- Make i8042BasicDetect resend CTRL_SELF_TEST sequence, if controller asks so. Maximum resend iterations are limited by ResendIterations variable.
- Reinsert debug-messages hack, since this is an early-loading driver, and it's not possible to break in to KDBG to change debug filter values.
- As a result, keyboard and mouse work on real hardware again.
See issue #3036 for more details.

svn path=/trunk/; revision=32153
This commit is contained in:
Aleksey Bragin 2008-02-06 09:46:38 +00:00
parent 75172afb72
commit dbc44341a9
3 changed files with 50 additions and 20 deletions

View file

@ -475,6 +475,17 @@ DriverEntry(
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. */
#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);
#endif
Status = IoAllocateDriverObjectExtension(
DriverObject,
DriverObject,

View file

@ -75,6 +75,7 @@ i8042BasicDetect(
IN PPORT_DEVICE_EXTENSION DeviceExtension)
{
NTSTATUS Status;
ULONG ResendIterations;
UCHAR Value = 0;
/* Don't enable keyboard and mouse interrupts, disable keyboard/mouse */
@ -83,23 +84,33 @@ i8042BasicDetect(
i8042Flush(DeviceExtension);
if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, CTRL_SELF_TEST))
ResendIterations = DeviceExtension->Settings.ResendIterations + 1;
while (ResendIterations--)
{
WARN_(I8042PRT, "Writing CTRL_SELF_TEST command failed\n");
return STATUS_IO_TIMEOUT;
}
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 != 0x55)
{
WARN_(I8042PRT, "Got 0x%02x instead of 0x55\n", Value);
return STATUS_IO_DEVICE_ERROR;
if (Value == KBD_RESEND)
{
TRACE_(I8042PRT, "Resending...\n", Value);
KeStallExecutionProcessor(50);
continue;
}
else if (Value != 0x55)
{
WARN_(I8042PRT, "Got 0x%02x instead of 0x55\n", Value);
return STATUS_IO_DEVICE_ERROR;
}
}
/*

View file

@ -21,8 +21,16 @@ i8042Flush(
{
UCHAR Ignore;
while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_OBF | MOU_OBF, &Ignore))) {
INFO_(I8042PRT, "Data flushed\n"); /* drop */
/* 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");
}
}
@ -189,20 +197,20 @@ i8042Write(
IN PUCHAR addr,
IN UCHAR data)
{
ULONG ResendIterations;
ULONG Counter;
ASSERT(addr);
ASSERT(DeviceExtension->ControlPort != NULL);
ResendIterations = DeviceExtension->Settings.ResendIterations;
Counter = DeviceExtension->Settings.PollingIterations;
while ((KBD_IBF & READ_PORT_UCHAR(DeviceExtension->ControlPort)) &&
(ResendIterations--))
(Counter--))
{
KeStallExecutionProcessor(50);
}
if (ResendIterations)
if (Counter)
{
WRITE_PORT_UCHAR(addr, data);
INFO_(I8042PRT, "Sent 0x%x to port %p\n", data, addr);