Author: hpoussin
Date: Sun Apr 16 11:17:34 2006
New Revision: 21599
URL:
http://svn.reactos.ru/svn/reactos?rev=21599&view=rev
Log:
kbdclass and mouclass:
- Better synchronization of code between kbdclass and mouclass
- Better cleanup in ClassAddDevice in case of error
- Better support of legacy devices
kbdclass only:
- Send IOCTLs to lower device
Modified:
trunk/reactos/drivers/input/kbdclass/kbdclass.c
trunk/reactos/drivers/input/kbdclass/kbdclass.h
trunk/reactos/drivers/input/mouclass/mouclass.c
trunk/reactos/drivers/input/mouclass/mouclass.h
Modified: trunk/reactos/drivers/input/kbdclass/kbdclass.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/drivers/input/kbdclass/kbdc…
==============================================================================
--- trunk/reactos/drivers/input/kbdclass/kbdclass.c (original)
+++ trunk/reactos/drivers/input/kbdclass/kbdclass.c Sun Apr 16 11:17:34 2006
@@ -107,7 +107,6 @@
switch (IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode)
{
-#if 0
case IOCTL_KEYBOARD_QUERY_ATTRIBUTES:
case IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION:
case IOCTL_KEYBOARD_QUERY_INDICATORS:
@@ -146,10 +145,10 @@
}
break;
}
-#endif
default:
DPRINT1("IRP_MJ_DEVICE_CONTROL / unknown I/O control code 0x%lx\n",
IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode);
+ ASSERT(FALSE);
break;
}
@@ -536,8 +535,8 @@
IN PDEVICE_OBJECT Pdo)
{
PCLASS_DRIVER_EXTENSION DriverExtension;
- PDEVICE_OBJECT Fdo;
- PPORT_DEVICE_EXTENSION DeviceExtension;
+ PDEVICE_OBJECT Fdo = NULL;
+ PPORT_DEVICE_EXTENSION DeviceExtension = NULL;
NTSTATUS Status;
DPRINT("ClassAddDevice called. Pdo = 0x%p\n", Pdo);
@@ -561,7 +560,7 @@
if (!NT_SUCCESS(Status))
{
DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
- return Status;
+ goto cleanup;
}
DeviceExtension = (PPORT_DEVICE_EXTENSION)Fdo->DeviceExtension;
@@ -573,8 +572,7 @@
if (!NT_SUCCESS(Status))
{
DPRINT("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n",
Status);
- IoDeleteDevice(Fdo);
- return Status;
+ goto cleanup;
}
if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
Fdo->Flags |= DO_POWER_PAGABLE;
@@ -582,16 +580,25 @@
Fdo->Flags |= DO_BUFFERED_IO;
if (DriverExtension->ConnectMultiplePorts)
- Status = ConnectPortDriver(Fdo, DriverExtension->MainClassDeviceObject);
+ DeviceExtension->ClassDO = DriverExtension->MainClassDeviceObject;
else
- Status = ConnectPortDriver(Fdo, Fdo);
+ {
+ /* We need a new class device object for this Fdo */
+ Status = CreateClassDeviceObject(
+ DriverObject,
+ &DeviceExtension->ClassDO);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
+ goto cleanup;
+ }
+ }
+ Status = ConnectPortDriver(Fdo, DeviceExtension->ClassDO);
if (!NT_SUCCESS(Status))
{
DPRINT("ConnectPortDriver() failed with status 0x%08lx\n", Status);
- IoDetachDevice(DeviceExtension->LowerDevice);
ObDereferenceObject(Fdo);
- IoDeleteDevice(Fdo);
- return Status;
+ goto cleanup;
}
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
@@ -601,13 +608,35 @@
&GUID_DEVINTERFACE_KEYBOARD,
NULL,
&DeviceExtension->InterfaceName);
- if (!NT_SUCCESS(Status))
+ if (Status == STATUS_INVALID_PARAMETER_1)
+ {
+ /* The Pdo was a strange one ; maybe it is a legacy device.
+ * Ignore the error. */
+ return STATUS_SUCCESS;
+ }
+ else if (!NT_SUCCESS(Status))
{
DPRINT("IoRegisterDeviceInterface() failed with status 0x%08lx\n", Status);
- return Status;
+ goto cleanup;
}
return STATUS_SUCCESS;
+
+cleanup:
+ if (DeviceExtension)
+ {
+ if (DeviceExtension->LowerDevice)
+ IoDetachDevice(DeviceExtension->LowerDevice);
+ if (DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO)
+ {
+ PCLASS_DEVICE_EXTENSION ClassDeviceExtension;
+ ClassDeviceExtension =
(PCLASS_DEVICE_EXTENSION)DeviceExtension->ClassDO->DeviceExtension;
+ ExFreePool(ClassDeviceExtension->PortData);
+ }
+ }
+ if (Fdo)
+ IoDeleteDevice(Fdo);
+ return Status;
}
static VOID NTAPI
@@ -748,34 +777,13 @@
DPRINT("IoGetDeviceObjectPointer(%wZ) failed with status 0x%08lx\n",
Status);
continue;
}
-
- /* Connect the port device object */
- if (DriverExtension->ConnectMultiplePorts)
- {
- Status = ConnectPortDriver(PortDeviceObject,
DriverExtension->MainClassDeviceObject);
- if (!NT_SUCCESS(Status))
- {
- /* FIXME: Log the error */
- DPRINT("ConnectPortDriver() failed with status 0x%08lx\n", Status);
- }
- }
- else
- {
- PDEVICE_OBJECT ClassDO;
- Status = CreateClassDeviceObject(DriverObject, &ClassDO);
- if (!NT_SUCCESS(Status))
- {
- /* FIXME: Log the error */
- DPRINT("CreatePointerClassDeviceObject() failed with status 0x%08lx\n",
Status);
- continue;
- }
- Status = ConnectPortDriver(PortDeviceObject, ClassDO);
- if (!NT_SUCCESS(Status))
- {
- /* FIXME: Log the error */
- DPRINT("ConnectPortDriver() failed with status 0x%08lx\n", Status);
- IoDeleteDevice(ClassDO);
- }
+ DPRINT("Legacy driver found: %wZ\n",
&PortDeviceObject->DriverObject->DriverName);
+
+ Status = ClassAddDevice(DriverObject, PortDeviceObject);
+ if (!NT_SUCCESS(Status))
+ {
+ /* FIXME: Log the error */
+ DPRINT("ClassAddDevice() failed with status 0x%08lx\n", Status);
}
}
if (Status == STATUS_NO_MORE_ENTRIES)
Modified: trunk/reactos/drivers/input/kbdclass/kbdclass.h
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/drivers/input/kbdclass/kbdc…
==============================================================================
--- trunk/reactos/drivers/input/kbdclass/kbdclass.h (original)
+++ trunk/reactos/drivers/input/kbdclass/kbdclass.h Sun Apr 16 11:17:34 2006
@@ -39,6 +39,7 @@
PDEVICE_OBJECT DeviceObject;
PORT_DEVICE_STATE PnpState;
PDEVICE_OBJECT LowerDevice;
+ PDEVICE_OBJECT ClassDO;
UNICODE_STRING InterfaceName;
} PORT_DEVICE_EXTENSION, *PPORT_DEVICE_EXTENSION;
Modified: trunk/reactos/drivers/input/mouclass/mouclass.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/drivers/input/mouclass/mouc…
==============================================================================
--- trunk/reactos/drivers/input/mouclass/mouclass.c (original)
+++ trunk/reactos/drivers/input/mouclass/mouclass.c Sun Apr 16 11:17:34 2006
@@ -125,6 +125,7 @@
default:
DPRINT1("IRP_MJ_DEVICE_CONTROL / unknown I/O control code 0x%lx\n",
IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode);
+ ASSERT(FALSE);
break;
}
@@ -506,8 +507,8 @@
IN PDEVICE_OBJECT Pdo)
{
PCLASS_DRIVER_EXTENSION DriverExtension;
- PDEVICE_OBJECT Fdo;
- PPORT_DEVICE_EXTENSION DeviceExtension;
+ PDEVICE_OBJECT Fdo = NULL;
+ PPORT_DEVICE_EXTENSION DeviceExtension = NULL;
NTSTATUS Status;
DPRINT("ClassAddDevice called. Pdo = 0x%p\n", Pdo);
@@ -531,7 +532,7 @@
if (!NT_SUCCESS(Status))
{
DPRINT("IoCreateDevice() failed with status 0x%08lx\n", Status);
- return Status;
+ goto cleanup;
}
DeviceExtension = (PPORT_DEVICE_EXTENSION)Fdo->DeviceExtension;
@@ -543,8 +544,7 @@
if (!NT_SUCCESS(Status))
{
DPRINT("IoAttachDeviceToDeviceStackSafe() failed with status 0x%08lx\n",
Status);
- IoDeleteDevice(Fdo);
- return Status;
+ goto cleanup;
}
if (DeviceExtension->LowerDevice->Flags & DO_POWER_PAGABLE)
Fdo->Flags |= DO_POWER_PAGABLE;
@@ -552,16 +552,25 @@
Fdo->Flags |= DO_BUFFERED_IO;
if (DriverExtension->ConnectMultiplePorts)
- Status = ConnectPortDriver(Fdo, DriverExtension->MainClassDeviceObject);
+ DeviceExtension->ClassDO = DriverExtension->MainClassDeviceObject;
else
- Status = ConnectPortDriver(Fdo, Fdo);
+ {
+ /* We need a new class device object for this Fdo */
+ Status = CreateClassDeviceObject(
+ DriverObject,
+ &DeviceExtension->ClassDO);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("CreateClassDeviceObject() failed with status 0x%08lx\n", Status);
+ goto cleanup;
+ }
+ }
+ Status = ConnectPortDriver(Fdo, DeviceExtension->ClassDO);
if (!NT_SUCCESS(Status))
{
DPRINT("ConnectPortDriver() failed with status 0x%08lx\n", Status);
- IoDetachDevice(DeviceExtension->LowerDevice);
ObDereferenceObject(Fdo);
- IoDeleteDevice(Fdo);
- return Status;
+ goto cleanup;
}
Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
@@ -571,13 +580,35 @@
&GUID_DEVINTERFACE_MOUSE,
NULL,
&DeviceExtension->InterfaceName);
- if (!NT_SUCCESS(Status))
+ if (Status == STATUS_INVALID_PARAMETER_1)
+ {
+ /* The Pdo was a strange one ; maybe it is a legacy device.
+ * Ignore the error. */
+ return STATUS_SUCCESS;
+ }
+ else if (!NT_SUCCESS(Status))
{
DPRINT("IoRegisterDeviceInterface() failed with status 0x%08lx\n", Status);
- return Status;
+ goto cleanup;
}
return STATUS_SUCCESS;
+
+cleanup:
+ if (DeviceExtension)
+ {
+ if (DeviceExtension->LowerDevice)
+ IoDetachDevice(DeviceExtension->LowerDevice);
+ if (DriverExtension->ConnectMultiplePorts && DeviceExtension->ClassDO)
+ {
+ PCLASS_DEVICE_EXTENSION ClassDeviceExtension;
+ ClassDeviceExtension =
(PCLASS_DEVICE_EXTENSION)DeviceExtension->ClassDO->DeviceExtension;
+ ExFreePool(ClassDeviceExtension->PortData);
+ }
+ }
+ if (Fdo)
+ IoDeleteDevice(Fdo);
+ return Status;
}
static VOID NTAPI
@@ -718,6 +749,7 @@
DPRINT("IoGetDeviceObjectPointer(%wZ) failed with status 0x%08lx\n",
Status);
continue;
}
+ DPRINT("Legacy driver found: %wZ\n",
&PortDeviceObject->DriverObject->DriverName);
Status = ClassAddDevice(DriverObject, PortDeviceObject);
if (!NT_SUCCESS(Status))
Modified: trunk/reactos/drivers/input/mouclass/mouclass.h
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/drivers/input/mouclass/mouc…
==============================================================================
--- trunk/reactos/drivers/input/mouclass/mouclass.h (original)
+++ trunk/reactos/drivers/input/mouclass/mouclass.h Sun Apr 16 11:17:34 2006
@@ -39,6 +39,7 @@
PDEVICE_OBJECT DeviceObject;
PORT_DEVICE_STATE PnpState;
PDEVICE_OBJECT LowerDevice;
+ PDEVICE_OBJECT ClassDO;
UNICODE_STRING InterfaceName;
} PORT_DEVICE_EXTENSION, *PPORT_DEVICE_EXTENSION;