Author: cgutman
Date: Sun Jan 22 21:58:06 2012
New Revision: 55080
URL:
http://svn.reactos.org/svn/reactos?rev=55080&view=rev
Log:
[USB-BRINGUP-TRUNK]
- Implement device disconnect indication for usbehci and usbohci
- Implement device removal for FDOs and PDOs in usbstor and usbhub
Modified:
branches/usb-bringup-trunk/drivers/usb/usbehci_new/hardware.cpp
branches/usb-bringup-trunk/drivers/usb/usbhub_new/fdo.c
branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c
branches/usb-bringup-trunk/drivers/usb/usbohci/hardware.cpp
branches/usb-bringup-trunk/drivers/usb/usbstor/fdo.c
branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c
Modified: branches/usb-bringup-trunk/drivers/usb/usbehci_new/hardware.cpp
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/u…
==============================================================================
--- branches/usb-bringup-trunk/drivers/usb/usbehci_new/hardware.cpp [iso-8859-1]
(original)
+++ branches/usb-bringup-trunk/drivers/usb/usbehci_new/hardware.cpp [iso-8859-1] Sun Jan
22 21:58:06 2012
@@ -1131,21 +1131,28 @@
This->m_PortStatus[i].PortStatus |= USB_PORT_STATUS_HIGH_SPEED;
This->m_PortStatus[i].PortStatus |= USB_PORT_STATUS_CONNECT;
This->m_PortStatus[i].PortChange |= USB_PORT_STATUS_CONNECT;
-
- //
- // is there a status change callback
- //
- if (This->m_SCECallBack != NULL)
- {
- //
- // queue work item for processing
- //
- ExQueueWorkItem(&This->m_StatusChangeWorkItem,
DelayedWorkQueue);
- }
}
else
{
DPRINT1("Device disconnected on port %d\n", i);
+
+ //
+ // update port status flags
+ //
+ This->m_PortStatus[i].PortStatus &=
~USB_PORT_STATUS_HIGH_SPEED;
+ This->m_PortStatus[i].PortStatus &= ~USB_PORT_STATUS_CONNECT;
+ This->m_PortStatus[i].PortChange |= USB_PORT_STATUS_CONNECT;
+ }
+
+ //
+ // is there a status change callback
+ //
+ if (This->m_SCECallBack != NULL)
+ {
+ //
+ // queue work item for processing
+ //
+ ExQueueWorkItem(&This->m_StatusChangeWorkItem,
DelayedWorkQueue);
}
//
Modified: branches/usb-bringup-trunk/drivers/usb/usbhub_new/fdo.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/u…
==============================================================================
--- branches/usb-bringup-trunk/drivers/usb/usbhub_new/fdo.c [iso-8859-1] (original)
+++ branches/usb-bringup-trunk/drivers/usb/usbhub_new/fdo.c [iso-8859-1] Sun Jan 22
21:58:06 2012
@@ -20,6 +20,11 @@
IN PDEVICE_OBJECT UsbHubDeviceObject,
IN LONG PortId,
OUT PDEVICE_OBJECT *UsbChildDeviceObject);
+
+NTSTATUS
+DestroyUsbChildDeviceObject(
+ IN PDEVICE_OBJECT UsbHubDeviceObject,
+ IN LONG PortId);
NTSTATUS
SubmitRequestToRootHub(
@@ -304,9 +309,11 @@
{
DPRINT1("Device disconnected from port %d\n", PortId);
- //
- // FIXME: Remove the device, and deallocate memory
- //
+ Status = DestroyUsbChildDeviceObject(DeviceObject, PortId);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Failed to delete child device object after
disconnect\n");
+ }
}
else
{
@@ -997,6 +1004,51 @@
ExFreePool(UsbChildExtension->usInstanceId.Buffer);
return Status;
+}
+
+NTSTATUS
+DestroyUsbChildDeviceObject(
+ IN PDEVICE_OBJECT UsbHubDeviceObject,
+ IN LONG PortId)
+{
+ PHUB_DEVICE_EXTENSION HubDeviceExtension =
(PHUB_DEVICE_EXTENSION)UsbHubDeviceObject->DeviceExtension;
+ PHUB_CHILDDEVICE_EXTENSION UsbChildExtension = NULL;
+ PDEVICE_OBJECT ChildDeviceObject = NULL;
+ ULONG Index = 0;
+
+ DPRINT1("Removing device on port %d (Child index: %d)\n", PortId, Index);
+
+ for (Index = 0; Index < USB_MAXCHILDREN; Index++)
+ {
+ if (HubDeviceExtension->ChildDeviceObject[Index])
+ {
+ UsbChildExtension =
(PHUB_CHILDDEVICE_EXTENSION)HubDeviceExtension->ChildDeviceObject[Index]->DeviceExtension;
+
+ /* Check if it matches the port ID */
+ if (UsbChildExtension->PortNumber == PortId)
+ {
+ /* We found it */
+ ChildDeviceObject = HubDeviceExtension->ChildDeviceObject[Index];
+ break;
+ }
+ }
+ }
+
+ /* Fail the request if the device doesn't exist */
+ if (!ChildDeviceObject)
+ {
+ DPRINT1("Removal request for non-existant device!\n");
+ return STATUS_UNSUCCESSFUL;
+ }
+
+ /* Remove the device from the table */
+ HubDeviceExtension->ChildDeviceObject[Index] = NULL;
+
+ /* Invalidate device relations for the root hub */
+ IoInvalidateDeviceRelations(HubDeviceExtension->RootHubPhysicalDeviceObject,
BusRelations);
+
+ /* The rest of the removal process takes place in IRP_MN_REMOVE_DEVICE handling for
the PDO */
+ return STATUS_SUCCESS;
}
NTSTATUS
Modified: branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/u…
==============================================================================
--- branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c [iso-8859-1] (original)
+++ branches/usb-bringup-trunk/drivers/usb/usbhub_new/pdo.c [iso-8859-1] Sun Jan 22
21:58:06 2012
@@ -582,11 +582,21 @@
}
case IRP_MN_REMOVE_DEVICE:
{
- //
- // FIXME
- //
- Status = STATUS_SUCCESS;
- break;
+ PHUB_DEVICE_EXTENSION HubDeviceExtension =
(PHUB_DEVICE_EXTENSION)UsbChildExtension->ParentDeviceObject->DeviceExtension;
+ PUSB_BUS_INTERFACE_HUB_V5 HubInterface =
&HubDeviceExtension->HubInterface;
+
+ DPRINT1("IRP_MJ_PNP / IRP_MN_REMOVE_DEVICE\n");
+
+ /* Remove the device */
+
HubInterface->RemoveUsbDevice(HubDeviceExtension->UsbDInterface.BusContext,
UsbChildExtension->UsbDeviceHandle, 0);
+
+ /* Complete the IRP */
+ Irp->IoStatus.Status = STATUS_SUCCESS;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+ /* Delete the device object */
+ IoDeleteDevice(DeviceObject);
+ return STATUS_SUCCESS;
}
default:
{
Modified: branches/usb-bringup-trunk/drivers/usb/usbohci/hardware.cpp
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/u…
==============================================================================
--- branches/usb-bringup-trunk/drivers/usb/usbohci/hardware.cpp [iso-8859-1] (original)
+++ branches/usb-bringup-trunk/drivers/usb/usbohci/hardware.cpp [iso-8859-1] Sun Jan 22
21:58:06 2012
@@ -1447,17 +1447,6 @@
//
This->m_PortStatus[Index].PortStatus |=
USB_PORT_STATUS_LOW_SPEED;
}
-
- //
- // is there a status change callback
- //
- if (This->m_SCECallBack != NULL)
- {
- //
- // queue work item for processing
- //
- ExQueueWorkItem(&This->m_StatusChangeWorkItem,
DelayedWorkQueue);
- }
}
else
{
@@ -1465,6 +1454,24 @@
// device disconnected
//
DPRINT1("Device disconnected at Port %x\n", Index);
+
+ //
+ // update port status flags
+ //
+ This->m_PortStatus[Index].PortStatus &=
~USB_PORT_STATUS_LOW_SPEED;
+ This->m_PortStatus[Index].PortStatus &=
~USB_PORT_STATUS_CONNECT;
+ This->m_PortStatus[Index].PortChange |= USB_PORT_STATUS_CONNECT;
+ }
+
+ //
+ // is there a status change callback
+ //
+ if (This->m_SCECallBack != NULL)
+ {
+ //
+ // queue work item for processing
+ //
+ ExQueueWorkItem(&This->m_StatusChangeWorkItem,
DelayedWorkQueue);
}
}
}
Modified: branches/usb-bringup-trunk/drivers/usb/usbstor/fdo.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/u…
==============================================================================
--- branches/usb-bringup-trunk/drivers/usb/usbstor/fdo.c [iso-8859-1] (original)
+++ branches/usb-bringup-trunk/drivers/usb/usbstor/fdo.c [iso-8859-1] Sun Jan 22 21:58:06
2012
@@ -119,6 +119,31 @@
}
NTSTATUS
+USBSTOR_FdoHandleRemoveDevice(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PFDO_DEVICE_EXTENSION DeviceExtension,
+ IN OUT PIRP Irp)
+{
+ NTSTATUS Status;
+
+ DPRINT1("Handling FDO removal\n");
+
+ /* We don't need to request removal of our children here */
+
+ /* Send the IRP down the stack */
+ IoSkipCurrentIrpStackLocation(Irp);
+ Status = IoCallDriver(DeviceExtension->LowerDeviceObject, Irp);
+
+ /* Detach from the device stack */
+ /* IoDetachDevice(DeviceExtension->LowerDeviceObject); */ //This crashes for some
reason during unload
+
+ /* Delete the device object */
+ IoDeleteDevice(DeviceObject);
+
+ return Status;
+}
+
+NTSTATUS
USBSTOR_FdoHandleStartDevice(
IN PDEVICE_OBJECT DeviceObject,
IN PFDO_DEVICE_EXTENSION DeviceExtension,
@@ -302,9 +327,11 @@
Status = STATUS_NOT_SUPPORTED;
break;
case IRP_MN_REMOVE_DEVICE:
- DPRINT1("USBSTOR_FdoHandlePnp: IRP_MN_REMOVE_DEVICE
unimplemented\n");
- Status = STATUS_NOT_SUPPORTED;
- break;
+ {
+ DPRINT1("IRP_MN_REMOVE_DEVICE\n");
+
+ return USBSTOR_FdoHandleRemoveDevice(DeviceObject, DeviceExtension, Irp);
+ }
case IRP_MN_QUERY_CAPABILITIES:
{
//
Modified: branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c
URL:
http://svn.reactos.org/svn/reactos/branches/usb-bringup-trunk/drivers/usb/u…
==============================================================================
--- branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c [iso-8859-1] (original)
+++ branches/usb-bringup-trunk/drivers/usb/usbstor/pdo.c [iso-8859-1] Sun Jan 22 21:58:06
2012
@@ -842,9 +842,18 @@
break;
}
case IRP_MN_REMOVE_DEVICE:
- DPRINT1("USBSTOR_PdoHandlePnp: IRP_MN_REMOVE_DEVICE
unimplemented\n");
- Status = STATUS_SUCCESS;
- break;
+ {
+ DPRINT1("IRP_MN_REMOVE_DEVICE\n");
+
+ /* Complete the IRP */
+ Irp->IoStatus.Status = STATUS_SUCCESS;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+ /* Delete the device object */
+ IoDeleteDevice(DeviceObject);
+
+ return STATUS_SUCCESS;
+ }
case IRP_MN_QUERY_CAPABILITIES:
{
//