Let OHCI miniport use shared code in drivers/usb/miniport/common/*, instead of duplicating it
Modified: trunk/reactos/drivers/usb/miniport/common/fdo.c
Modified: trunk/reactos/drivers/usb/miniport/common/main.c
Modified: trunk/reactos/drivers/usb/miniport/common/usbcommon.h
Modified: trunk/reactos/drivers/usb/miniport/usbohci/ohci-hcd.c
Modified: trunk/reactos/drivers/usb/miniport/usbohci/ohci-pci.c
Added: trunk/reactos/drivers/usb/miniport/usbohci/ohci.c
Deleted: trunk/reactos/drivers/usb/miniport/usbohci/ohci.def
Modified: trunk/reactos/drivers/usb/miniport/usbohci/ohci.h
Deleted: trunk/reactos/drivers/usb/miniport/usbohci/ohci_main.c
Deleted: trunk/reactos/drivers/usb/miniport/usbohci/ohci_main.h
Modified: trunk/reactos/drivers/usb/miniport/usbohci/usbohci.xml

Modified: trunk/reactos/drivers/usb/miniport/common/fdo.c
--- trunk/reactos/drivers/usb/miniport/common/fdo.c	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/common/fdo.c	2005-09-11 11:40:43 UTC (rev 17795)
@@ -59,6 +59,9 @@
 	PUSBMP_DEVICE_EXTENSION DeviceExtension;
 	PCM_RESOURCE_LIST AllocatedResources;
 
+	if (DeviceObject == KeyboardFdo || DeviceObject == MouseFdo)
+		return STATUS_SUCCESS;
+
 	/*
 	* Get the initialization data we saved in VideoPortInitialize.
 	*/
@@ -350,3 +353,218 @@
 	IoCompleteRequest(Irp, IO_NO_INCREMENT);
 	return Status;
 }
+
+NTSTATUS
+UsbMpInternalDeviceControlFdo(
+	IN PDEVICE_OBJECT DeviceObject,
+	IN PIRP Irp)
+{
+	NTSTATUS Status = STATUS_INVALID_DEVICE_REQUEST;
+
+	DPRINT("USBMP: UsbMpDeviceInternalControlFdo(DO %p, code 0x%lx) called\n",
+		DeviceObject,
+		IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.IoControlCode);
+
+	if (DeviceObject == KeyboardFdo)
+	{
+		// it's keyboard's IOCTL
+		PIO_STACK_LOCATION Stk;
+
+		Irp->IoStatus.Information = 0;
+		Stk = IoGetCurrentIrpStackLocation(Irp);
+
+		switch (Stk->Parameters.DeviceIoControl.IoControlCode)
+		{
+			case IOCTL_INTERNAL_KEYBOARD_CONNECT:
+				DPRINT("USBMP: IOCTL_INTERNAL_KEYBOARD_CONNECT\n");
+				if (Stk->Parameters.DeviceIoControl.InputBufferLength <	sizeof(CONNECT_DATA)) {
+					DPRINT1("USBMP: Keyboard IOCTL_INTERNAL_KEYBOARD_CONNECT "
+							"invalid buffer size\n");
+					Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
+					goto intcontfailure;
+				}
+
+				RtlCopyMemory(&KbdClassInformation,
+					Stk->Parameters.DeviceIoControl.Type3InputBuffer,
+					sizeof(CONNECT_DATA));
+	
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+
+		case IOCTL_INTERNAL_I8042_KEYBOARD_WRITE_BUFFER:
+			DPRINT("USBMP: IOCTL_INTERNAL_I8042_KEYBOARD_WRITE_BUFFER\n");
+			if (Stk->Parameters.DeviceIoControl.InputBufferLength <	1) {
+				Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
+				goto intcontfailure;
+			}
+/*			if (!DevExt->KeyboardInterruptObject) {
+				Irp->IoStatus.Status = STATUS_DEVICE_NOT_READY;
+				goto intcontfailure;
+			}*/
+
+			Irp->IoStatus.Status = STATUS_SUCCESS;
+			break;
+		case IOCTL_KEYBOARD_QUERY_ATTRIBUTES:
+			DPRINT("USBMP: IOCTL_KEYBOARD_QUERY_ATTRIBUTES\n");
+			if (Stk->Parameters.DeviceIoControl.OutputBufferLength <
+				sizeof(KEYBOARD_ATTRIBUTES)) {
+					DPRINT("USBMP: Keyboard IOCTL_KEYBOARD_QUERY_ATTRIBUTES "
+						"invalid buffer size\n");
+					Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
+					goto intcontfailure;
+				}
+				/*RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
+					&DevExt->KeyboardAttributes,
+					sizeof(KEYBOARD_ATTRIBUTES));*/
+
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+		case IOCTL_KEYBOARD_QUERY_INDICATORS:
+			DPRINT("USBMP: IOCTL_KEYBOARD_QUERY_INDICATORS\n");
+			if (Stk->Parameters.DeviceIoControl.OutputBufferLength <
+				sizeof(KEYBOARD_INDICATOR_PARAMETERS)) {
+					DPRINT("USBMP: Keyboard IOCTL_KEYBOARD_QUERY_INDICATORS "
+						"invalid buffer size\n");
+					Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
+					goto intcontfailure;
+				}
+				/*RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
+					&DevExt->KeyboardIndicators,
+					sizeof(KEYBOARD_INDICATOR_PARAMETERS));*/
+
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+		case IOCTL_KEYBOARD_QUERY_TYPEMATIC:
+			DPRINT("USBMP: IOCTL_KEYBOARD_QUERY_TYPEMATIC\n");
+			if (Stk->Parameters.DeviceIoControl.OutputBufferLength <
+				sizeof(KEYBOARD_TYPEMATIC_PARAMETERS)) {
+					DPRINT("USBMP: Keyboard IOCTL_KEYBOARD_QUERY_TYPEMATIC	"
+						"invalid buffer size\n");
+					Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
+					goto intcontfailure;
+				}
+				/*RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
+					&DevExt->KeyboardTypematic,
+					sizeof(KEYBOARD_TYPEMATIC_PARAMETERS));*/
+
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+		case IOCTL_KEYBOARD_SET_INDICATORS:
+			DPRINT("USBMP: IOCTL_KEYBOARD_SET_INDICATORS\n");
+			if (Stk->Parameters.DeviceIoControl.InputBufferLength <
+				sizeof(KEYBOARD_INDICATOR_PARAMETERS)) {
+					DPRINT("USBMP: Keyboard IOCTL_KEYBOARD_SET_INDICTATORS	"
+						"invalid buffer size\n");
+					Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
+					goto intcontfailure;
+				}
+
+				/*RtlCopyMemory(&DevExt->KeyboardIndicators,
+					Irp->AssociatedIrp.SystemBuffer,
+					sizeof(KEYBOARD_INDICATOR_PARAMETERS));*/
+
+				//DPRINT("%x\n", DevExt->KeyboardIndicators.LedFlags);
+
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+		case IOCTL_KEYBOARD_SET_TYPEMATIC:
+			DPRINT("USBMP: IOCTL_KEYBOARD_SET_TYPEMATIC\n");
+			if (Stk->Parameters.DeviceIoControl.InputBufferLength <
+				sizeof(KEYBOARD_TYPEMATIC_PARAMETERS)) {
+					DPRINT("USBMP: Keyboard IOCTL_KEYBOARD_SET_TYPEMATIC "
+						"invalid buffer size\n");
+					Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
+					goto intcontfailure;
+				}
+
+				/*RtlCopyMemory(&DevExt->KeyboardTypematic,
+					Irp->AssociatedIrp.SystemBuffer,
+					sizeof(KEYBOARD_TYPEMATIC_PARAMETERS));*/
+
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+		case IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION:
+			/* We should check the UnitID, but it's	kind of	pointless as
+			* all keyboards are supposed to have the same one
+			*/
+#if 0
+			DPRINT("USBMP: IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION\n");
+			if (Stk->Parameters.DeviceIoControl.OutputBufferLength <
+				sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION)) {
+					DPRINT("USBMP: IOCTL_KEYBOARD_QUERY_INDICATOR_TRANSLATION:	"
+						"invalid buffer size (expected)\n");
+					/* It's to query the buffer size */
+					Irp->IoStatus.Status = STATUS_BUFFER_TOO_SMALL;
+					goto intcontfailure;
+				}
+				Irp->IoStatus.Information =
+					sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION);
+#endif
+				/*RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer,
+					&IndicatorTranslation,
+					sizeof(LOCAL_KEYBOARD_INDICATOR_TRANSLATION));*/
+
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+		case IOCTL_INTERNAL_I8042_HOOK_KEYBOARD:
+			/* Nothing to do here */
+			Irp->IoStatus.Status = STATUS_SUCCESS;
+			break;
+		default:
+			Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
+			break;
+		}
+
+	intcontfailure:
+			Status = Irp->IoStatus.Status;
+	}
+	else if (DeviceObject == MouseFdo)
+	{
+		// it's mouse's IOCTL
+		PIO_STACK_LOCATION Stk;
+
+		Irp->IoStatus.Information = 0;
+		Stk = IoGetCurrentIrpStackLocation(Irp);
+
+		switch (Stk->Parameters.DeviceIoControl.IoControlCode)
+		{
+			case IOCTL_INTERNAL_MOUSE_CONNECT:
+				DPRINT("USBMP: IOCTL_INTERNAL_MOUSE_CONNECT\n");
+				if (Stk->Parameters.DeviceIoControl.InputBufferLength <	sizeof(CONNECT_DATA)) {
+					DPRINT1("USBMP: IOCTL_INTERNAL_MOUSE_CONNECT "
+							"invalid buffer size\n");
+					Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
+					goto intcontfailure2;
+				}
+
+				RtlCopyMemory(&MouseClassInformation,
+					Stk->Parameters.DeviceIoControl.Type3InputBuffer,
+					sizeof(CONNECT_DATA));
+	
+				Irp->IoStatus.Status = STATUS_SUCCESS;
+				break;
+
+		default:
+			Irp->IoStatus.Status = STATUS_SUCCESS;//STATUS_INVALID_DEVICE_REQUEST;
+			break;
+		}
+	intcontfailure2:
+		Status = Irp->IoStatus.Status;
+	}
+	else
+	{
+		DPRINT("USBMP: We got IOCTL for UsbCore\n");
+		IoCompleteRequest(Irp, IO_NO_INCREMENT);
+		return STATUS_SUCCESS;
+	}
+
+
+	if (Status == STATUS_INVALID_DEVICE_REQUEST) {
+		DPRINT1("USBMP: Invalid internal device request!\n");
+	}
+
+	if (Status != STATUS_PENDING)
+		IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+	return Status;
+}

Modified: trunk/reactos/drivers/usb/miniport/common/main.c
--- trunk/reactos/drivers/usb/miniport/common/main.c	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/common/main.c	2005-09-11 11:40:43 UTC (rev 17795)
@@ -17,7 +17,11 @@
 #define INITGUID
 #include "usbcommon.h"
 
-static ULONG DeviceNumber = 0; /* FIXME: what is that? */
+// data for embedded drivers
+CONNECT_DATA KbdClassInformation;
+CONNECT_DATA MouseClassInformation;
+PDEVICE_OBJECT KeyboardFdo = NULL;
+PDEVICE_OBJECT MouseFdo = NULL;
 
 static NTSTATUS
 CreateRootHubPdo(
@@ -61,6 +65,64 @@
 	return STATUS_SUCCESS;
 }
 
+static NTSTATUS
+AddDevice_Keyboard(
+	IN PDRIVER_OBJECT DriverObject,
+	IN PDEVICE_OBJECT Pdo)
+{
+	UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardClass0");
+	PDEVICE_OBJECT Fdo;
+	NTSTATUS Status;
+
+	Status = IoCreateDevice(DriverObject,
+		8, // debug
+		&DeviceName,
+		FILE_DEVICE_KEYBOARD,
+		FILE_DEVICE_SECURE_OPEN,
+		TRUE,
+		&Fdo);
+
+	if (!NT_SUCCESS(Status))
+	{
+		DPRINT1("USBMP: IoCreateDevice() for usb keyboard driver failed with status 0x%08lx\n", Status);
+		return Status;
+	}
+	KeyboardFdo = Fdo;
+	Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
+	DPRINT("USBMP: Created keyboard Fdo: %p\n", Fdo);
+
+	return STATUS_SUCCESS;
+}
+
+static NTSTATUS
+AddDevice_Mouse(
+	IN PDRIVER_OBJECT DriverObject,
+	IN PDEVICE_OBJECT Pdo)
+{
+	UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\PointerClass0");
+	PDEVICE_OBJECT Fdo;
+	NTSTATUS Status;
+
+	Status = IoCreateDevice(DriverObject,
+		8, // debug
+		&DeviceName,
+		FILE_DEVICE_MOUSE,
+		FILE_DEVICE_SECURE_OPEN,
+		TRUE,
+		&Fdo);
+
+	if (!NT_SUCCESS(Status))
+	{
+		DPRINT1("USBMP: IoCreateDevice() for usb mouse driver failed with status 0x%08lx\n", Status);
+		return Status;
+	}
+	MouseFdo = Fdo;
+	Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
+	DPRINT("USBMP: Created mouse Fdo: %p\n", Fdo);
+
+	return STATUS_SUCCESS;
+}
+
 NTSTATUS STDCALL
 AddDevice(
 	IN PDRIVER_OBJECT DriverObject,
@@ -74,8 +136,17 @@
 	UNICODE_STRING LinkDeviceName;
 	PUSBMP_DRIVER_EXTENSION DriverExtension;
 	PUSBMP_DEVICE_EXTENSION DeviceExtension;
+	ULONG DeviceNumber;
 
+	/* FIXME: actually, we prevent multiple USB controllers on a computer */
+	static BOOLEAN xbox_workaround = FALSE;
+
 	DPRINT("USBMP: AddDevice called\n");
+	
+	if (xbox_workaround)
+		// Fail for any other host controller than the first
+		return STATUS_INSUFFICIENT_RESOURCES;
+	xbox_workaround = TRUE;
 
 	// Allocate driver extension now
 	DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
@@ -142,8 +213,6 @@
 
 	DeviceExtension->NextDeviceObject = IoAttachDeviceToDeviceStack(fdo, pdo);
 
-	fdo->Flags &= ~DO_DEVICE_INITIALIZING;
-
 	// Initialize device extension
 	DeviceExtension->IsFDO = TRUE;
 	DeviceExtension->DeviceNumber = DeviceNumber;
@@ -151,6 +220,8 @@
 	DeviceExtension->FunctionalDeviceObject = fdo;
 	DeviceExtension->DriverExtension = DriverExtension;
 
+	fdo->Flags &= ~DO_DEVICE_INITIALIZING;
+	
 	/* FIXME: do a loop to find an available number */
 	swprintf(LinkDeviceBuffer, L"\\??\\HCD%lu", 0);
 
@@ -158,13 +229,19 @@
 
 	Status = IoCreateSymbolicLink(&LinkDeviceName, &DeviceName);
 
+	if (NT_SUCCESS(Status))
+		Status = AddDevice_Keyboard(DriverObject, pdo);
+	if (NT_SUCCESS(Status))
+		Status = AddDevice_Mouse(DriverObject, pdo);
+
 	if (!NT_SUCCESS(Status))
 	{
-		DPRINT("USBMP: IoCreateSymbolicLink call failed with status 0x%08x\n", Status);
+		DPRINT("USBMP: IoCreateSymbolicLink() call failed with status 0x%08x\n", Status);
 		IoDeleteDevice(DeviceExtension->RootHubPdo);
 		IoDeleteDevice(fdo);
 		return Status;
 	}
+	
 
 	return STATUS_SUCCESS;
 }
@@ -239,6 +316,15 @@
 }
 
 static NTSTATUS STDCALL
+DispatchInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+{
+	if (((PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
+		return UsbMpInternalDeviceControlFdo(DeviceObject, Irp);
+	else
+		return IrpStub(DeviceObject, Irp);
+}
+
+static NTSTATUS STDCALL
 DispatchPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
 {
 	if (((PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->IsFDO)
@@ -263,6 +349,7 @@
 NTSTATUS STDCALL
 DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegPath)
 {
+	USBPORT_INTERFACE UsbPortInterface;
 	ULONG i;
 
 	DriverObject->DriverUnload = DriverUnload;
@@ -275,8 +362,20 @@
 	DriverObject->MajorFunction[IRP_MJ_CLOSE] = DispatchClose;
 	DriverObject->MajorFunction[IRP_MJ_CLEANUP] = DispatchCleanup;
 	DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchDeviceControl;
+	DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = DispatchInternalDeviceControl;
 	DriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnp;
 	DriverObject->MajorFunction[IRP_MJ_POWER] = DispatchPower;
 
+	// Register in usbcore.sys
+	UsbPortInterface.KbdConnectData = &KbdClassInformation;
+	UsbPortInterface.MouseConnectData = &MouseClassInformation;
+	
+	KbdClassInformation.ClassService = NULL;
+	KbdClassInformation.ClassDeviceObject = NULL;
+	MouseClassInformation.ClassService = NULL;
+	MouseClassInformation.ClassDeviceObject = NULL;
+	
+	RegisterPortDriver(DriverObject, &UsbPortInterface);
+
 	return STATUS_SUCCESS;
 }

Modified: trunk/reactos/drivers/usb/miniport/common/usbcommon.h
--- trunk/reactos/drivers/usb/miniport/common/usbcommon.h	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/common/usbcommon.h	2005-09-11 11:40:43 UTC (rev 17795)
@@ -7,6 +7,7 @@
 #include <usbdi.h>
 #include <usbiodef.h>
 #include <initguid.h>
+#include <ntdd8042.h>
 
 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
 #define USB_MINIPORT_TAG TAG('u','s','b','m')
@@ -14,6 +15,11 @@
 #include "../../usbport/hcd.h"
 #include "usbcommon_types.h"
 
+extern CONNECT_DATA KbdClassInformation;
+extern CONNECT_DATA MouseClassInformation;
+extern PDEVICE_OBJECT KeyboardFdo;
+extern PDEVICE_OBJECT MouseFdo;
+
 /* cleanup.c */
 NTSTATUS STDCALL
 UsbMpCleanup(
@@ -43,6 +49,11 @@
 	IN PDEVICE_OBJECT DeviceObject,
 	IN PIRP Irp);
 
+NTSTATUS
+UsbMpInternalDeviceControlFdo(
+	IN PDEVICE_OBJECT DeviceObject,
+	IN PIRP Irp);
+
 /* misc.c */
 NTSTATUS
 ForwardIrpAndWait(

Modified: trunk/reactos/drivers/usb/miniport/usbohci/ohci-hcd.c
--- trunk/reactos/drivers/usb/miniport/usbohci/ohci-hcd.c	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/usbohci/ohci-hcd.c	2005-09-11 11:40:43 UTC (rev 17795)
@@ -107,8 +107,7 @@
 #else
 #include "ohci_config.h"
 
-#include "../usb_wrapper.h"
-#include "hcd.h"
+#include "../../usbport/hcd.h"
 
 //#define OHCI_VERBOSE_DEBUG
 #endif
@@ -626,6 +625,18 @@
 
 /*-------------------------------------------------------------------------*/
 
+// HCFS itself
+static char *hcfs2string (int state)
+{
+	switch (state) {
+		case OHCI_USB_RESET: return "reset";
+		case OHCI_USB_RESUME: return "resume";
+		case OHCI_USB_OPER: return "operational";
+		case OHCI_USB_SUSPEND: return "suspend";
+	}
+	return "?";
+}
+
 static void ohci_stop (struct usb_hcd *hcd)
 {	
 	struct ohci_hcd		*ohci = hcd_to_ohci (hcd);

Modified: trunk/reactos/drivers/usb/miniport/usbohci/ohci-pci.c
--- trunk/reactos/drivers/usb/miniport/usbohci/ohci-pci.c	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/usbohci/ohci-pci.c	2005-09-11 11:40:43 UTC (rev 17795)
@@ -358,7 +358,7 @@
 
 /*-------------------------------------------------------------------------*/
 
-const struct pci_device_id __devinitdata pci_ids [] = { {
+const struct pci_device_id __devinitdata ohci_pci_ids [] = { {
 
 	/* handle any USB OHCI controller */
 	.class =	(PCI_CLASS_SERIAL_USB << 8) | 0x10,
@@ -373,12 +373,12 @@
 
 	}, { /* end: all zeroes */ }
 };
-MODULE_DEVICE_TABLE (pci, pci_ids);
+MODULE_DEVICE_TABLE (pci, ohci_pci_ids);
 
 /* pci driver glue; this is a "new style" PCI driver module */
 struct pci_driver ohci_pci_driver = {
 	.name =		(char *) hcd_name,
-	.id_table =	pci_ids,
+	.id_table =	ohci_pci_ids,
 
 	.probe =	usb_hcd_pci_probe,
 	.remove =	usb_hcd_pci_remove,

Added: trunk/reactos/drivers/usb/miniport/usbohci/ohci.c
--- trunk/reactos/drivers/usb/miniport/usbohci/ohci.c	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/usbohci/ohci.c	2005-09-11 11:40:43 UTC (rev 17795)
@@ -0,0 +1,76 @@
+#define NDEBUG
+#include <debug.h>
+
+#include "ohci.h"
+
+extern struct pci_driver ohci_pci_driver;
+extern struct pci_device_id ohci_pci_ids[];
+struct pci_device_id* pci_ids = &ohci_pci_ids[0];
+
+NTSTATUS
+InitLinuxWrapper(PDEVICE_OBJECT DeviceObject)
+{
+	NTSTATUS Status;
+	PUSBMP_DEVICE_EXTENSION DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+
+	/* Create generic linux structure */
+	struct pci_dev *dev;
+	dev = ExAllocatePoolWithTag(PagedPool, sizeof(struct pci_dev), USB_OHCI_TAG);
+	DeviceExtension->pdev = dev;
+	
+	/* Initialize generic linux structure */
+	dev->irq = DeviceExtension->InterruptVector;
+	dev->dev_ext = (PVOID)DeviceExtension;
+	dev->dev.dev_ext = (PVOID)DeviceExtension;
+	dev->slot_name = ExAllocatePoolWithTag(NonPagedPool, 128, USB_OHCI_TAG); // 128 max len for slot name
+
+	// Init wrapper
+	init_wrapper(dev);
+
+	strcpy(dev->dev.name, "OpenHCI PCI-USB Controller");
+	strcpy(dev->slot_name, "OHCD PCI Slot");
+
+	// Init the OHCI HCD. Probe will be called automatically, but will fail because id=NULL
+	Status = ohci_hcd_pci_init();
+	if (!NT_SUCCESS(Status))
+	{
+		DPRINT("OHCI: ohci_hcd_pci_init() failed with status 0x%08lx\n", Status);
+		/* FIXME: deinitialize linux wrapper */
+		ExFreePoolWithTag(dev, USB_OHCI_TAG);
+		return Status;
+	}
+
+	// Init core usb
+	usb_init();
+
+	// Probe device with real id now
+	ohci_pci_driver.probe(dev, ohci_pci_ids);
+
+	return STATUS_SUCCESS;
+}
+
+VOID STDCALL DriverUnload(PDRIVER_OBJECT DriverObject)
+{
+	PUSBMP_DEVICE_EXTENSION DeviceExtension;
+	PDEVICE_OBJECT DeviceObject;
+	struct pci_dev *dev;
+
+	DeviceObject = DriverObject->DeviceObject;
+	DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+
+	dev = DeviceExtension->pdev;
+
+	DPRINT1("DriverUnload()\n");
+
+	// Exit usb device
+	usb_exit();
+
+	// Remove device (ohci_pci_driver.remove)
+	ohci_pci_driver.remove(dev);
+
+	ExFreePool(dev->slot_name);
+	ExFreePool(dev);
+
+	// Perform some cleanup
+	ohci_hcd_pci_cleanup();
+}

Deleted: trunk/reactos/drivers/usb/miniport/usbohci/ohci.def
--- trunk/reactos/drivers/usb/miniport/usbohci/ohci.def	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/usbohci/ohci.def	2005-09-11 11:40:43 UTC (rev 17795)
@@ -1,2 +0,0 @@
-LIBRARY ohci.sys
-EXPORTS

Modified: trunk/reactos/drivers/usb/miniport/usbohci/ohci.h
--- trunk/reactos/drivers/usb/miniport/usbohci/ohci.h	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/usbohci/ohci.h	2005-09-11 11:40:43 UTC (rev 17795)
@@ -6,7 +6,16 @@
  * 
  * This file is licenced under the GPL.
  */
- 
+
+#include "usbcommon.h"
+#define USB_OHCI_TAG TAG('u','s','b','o')
+
+/* declare basic init functions and structures */
+int ohci_hcd_pci_init(void);
+void ohci_hcd_pci_cleanup(void);
+int STDCALL usb_init(void);
+void STDCALL usb_exit(void);
+
 /*
  * OHCI Endpoint Descriptor (ED) ... holds TD queue
  * See OHCI spec, section 4.2
@@ -245,18 +254,6 @@
 #define OHCI_USB_OPER	(2 << 6)
 #define OHCI_USB_SUSPEND (3 << 6)
 
-// HCFS itself
-static char *hcfs2string (int state)
-{
-	switch (state) {
-		case OHCI_USB_RESET: return "reset";
-		case OHCI_USB_RESUME: return "resume";
-		case OHCI_USB_OPER: return "operational";
-		case OHCI_USB_SUSPEND: return "suspend";
-	}
-	return "?";
-}
-
 /*
  * HcCommandStatus (cmdstatus) register masks
  */

Deleted: trunk/reactos/drivers/usb/miniport/usbohci/ohci_main.c
--- trunk/reactos/drivers/usb/miniport/usbohci/ohci_main.c	2005-09-11 09:23:16 UTC (rev 17794)
+++ trunk/reactos/drivers/usb/miniport/usbohci/ohci_main.c	2005-09-11 11:40:43 UTC (rev 17795)
@@ -1,666 +0,0 @@
-/*
-   ReactOS specific functions for OHCI module
-   by Aleksey Bragin (aleksey@reactos.com)
-   Some parts of code are inspired (or even just copied) from ReactOS Videoport driver
-*/
-
-#include <ddk/ntddk.h>
-#include <ddk/ntddkbd.h>
-#include <ddk/ntdd8042.h>
-
-#include <debug.h>
-#include "../usb_wrapper.h"
-#include "hcd.h"
-#include "ohci_main.h"
-
-// declare basic init funcs
-void init_wrapper(struct pci_dev *probe_dev);
-int ohci_hcd_pci_init (void);
-void ohci_hcd_pci_cleanup (void);
-int STDCALL usb_init(void);
-void STDCALL usb_exit(void);
-extern struct pci_driver ohci_pci_driver;
-extern const struct pci_device_id pci_ids[];
-
-
-// This should be removed, but for testing purposes it's here
-struct pci_dev *dev;
-//struct pci_device_id *dev_id;
-static bool xbox_workaround=false;
-
-// data for embedded drivers
-CONNECT_DATA KbdClassInformation;
-CONNECT_DATA MouseClassInformation;
-PDEVICE_OBJECT KeyboardFdo = NULL;
-PDEVICE_OBJECT MouseFdo = NULL;
-
-
-#define USB_OHCI_TAG TAG('u','s','b','o')
-
-NTSTATUS AddDevice_Keyboard(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT pdo)
-{
-	UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\KeyboardClass0");
-	PDEVICE_OBJECT fdo;
-	NTSTATUS Status;
-
-	Status = IoCreateDevice(DriverObject,
-	               8, // debug
-	               &DeviceName,
-	               FILE_DEVICE_KEYBOARD,
-	               FILE_DEVICE_SECURE_OPEN,
-	               TRUE,
-	               &fdo);
-
-	if (!NT_SUCCESS(Status))
-	{
-		DPRINT1("IoCreateDevice for usb keyboard driver failed\n");
-		return Status;
-	}
-	KeyboardFdo = fdo;
-	fdo->Flags &= ~DO_DEVICE_INITIALIZING;
-	DPRINT1("Created keyboard fdo: %p\n", fdo);
-
-	return STATUS_SUCCESS;
-}
-
-NTSTATUS AddDevice_Mouse(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT pdo)
-{
-	UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\PointerClass0");
-	PDEVICE_OBJECT fdo;
-	NTSTATUS Status;
-
-	Status = IoCreateDevice(DriverObject,
-	               8, // debug
-	               &DeviceName,
-	               FILE_DEVICE_MOUSE,
-	               FILE_DEVICE_SECURE_OPEN,
-	               TRUE,
-	               &fdo);
-
-	if (!NT_SUCCESS(Status))
-	{
-		DPRINT1("IoCreateDevice for usb mouse driver failed\n");
-		return Status;
-	}
-	MouseFdo = fdo;
-	fdo->Flags &= ~DO_DEVICE_INITIALIZING;
-
-	DPRINT1("Created mouse fdo: %p\n", fdo);
-
-	return STATUS_SUCCESS;
-}
-
-
-NTSTATUS STDCALL AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT pdo)
-{
-	PDEVICE_OBJECT fdo;
-	NTSTATUS Status;
-	WCHAR DeviceBuffer[20];
-	UNICODE_STRING DeviceName;
-	POHCI_DRIVER_EXTENSION DriverExtension;
-	POHCI_DEVICE_EXTENSION DeviceExtension;
-	ULONG Size, DeviceNumber;
-
-	DPRINT1("ohci: AddDevice called\n");
-
-	if (xbox_workaround)
-		return STATUS_INSUFFICIENT_RESOURCES; // Fail for any other host controller than the first
-	
-	xbox_workaround = true;
-
-	// Allocate driver extension now
-	DriverExtension = IoGetDriverObjectExtension(DriverObject, DriverObject);
-	if (DriverExtension == NULL)
-	{
-		Status = IoAllocateDriverObjectExtension(
-					DriverObject,
-					DriverObject,
-					sizeof(OHCI_DRIVER_EXTENSION),
-					(PVOID *)&DriverExtension);
-
-		if (!NT_SUCCESS(Status))
-		{
-			DPRINT1("Allocating DriverObjectExtension failed.\n");
-			return Status;
-		}
-	}
-   
-	// Create a unicode device name
-	DeviceNumber = 0; //TODO: Allocate new device number every time
-	swprintf(DeviceBuffer, L"\\Device\\USBFDO-%lu", DeviceNumber);
-	RtlInitUnicodeString(&DeviceName, DeviceBuffer);
-
-	Status = IoCreateDevice(DriverObject,
-		                    sizeof(OHCI_DEVICE_EXTENSION)/* + DriverExtension->InitializationData.HwDeviceExtensionSize*/,
-							&DeviceName,
-							FILE_DEVICE_CONTROLLER,
-							0,
-							FALSE,
-							&fdo);
-
-	if (!NT_SUCCESS(Status))
-	{
-		DPRINT("IoCreateDevice call failed with status 0x%08x\n", Status);
-		return Status;
-	}
-
-	// zerofill device extension
-	DeviceExtension = (POHCI_DEVICE_EXTENSION)fdo->DeviceExtension;
-	RtlZeroMemory(DeviceExtension, sizeof(OHCI_DEVICE_EXTENSION));
-	DeviceExtension->NextDeviceObject = IoAttachDeviceToDeviceStack(fdo, pdo);
-
-	fdo->Flags &= ~DO_DEVICE_INITIALIZING;
-
-	// Initialize device extension
-	DeviceExtension->DeviceNumber = DeviceNumber;
-	DeviceExtension->PhysicalDeviceObject = pdo;
-	DeviceExtension->FunctionalDeviceObject = fdo;
-	DeviceExtension->DriverExtension = DriverExtension;
-
-	/* Get bus number from the upper level bus driver. */
-	Size = sizeof(ULONG);
-	Status = IoGetDeviceProperty(
-				pdo,
-				DevicePropertyBusNumber,
-				Size,
-				&DeviceExtension->SystemIoBusNumber,
-				&Size);
-	
-	if (!NT_SUCCESS(Status))
-	{
-		DPRINT("Couldn't get an information from bus driver. Panic!!!\n");
-		return Status;
-	}
-
-	DPRINT("Done AddDevice\n");
-
-	// create embedded keyboard driver
-	Status = AddDevice_Keyboard(DriverObject, pdo);
-	Status = AddDevice_Mouse(DriverObject, pdo);
-
-	return Status;
-}
-
-
-VOID STDCALL DriverUnload(PDRIVER_OBJECT DriverObject)
-{
-	DPRINT1("DriverUnload()\n");
-
-	// Exit usb device
-	usb_exit();
-
-	// Remove device (ohci_pci_driver.remove)
-	ohci_pci_driver.remove(dev);
-
-	ExFreePool(dev->slot_name);
-	ExFreePool(dev);
-
-	// Perform some cleanup
-	ohci_hcd_pci_cleanup();
-}
-
-void RegisterISR(PDEVICE_OBJECT DeviceObject)
-{
-#if 0
-	NTSTATUS Status;
-	POHCI_DEVICE_EXTENSION DeviceExtension = (POHCI_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
-
-	/* Connect interrupt and enable them */
-	Status = IoConnectInterrupt(
-		&DeviceExtension->InterruptObject, SerialInterruptService,
-		DeviceObject, NULL,
-		Vector, Dirql, Dirql,
-		InterruptMode, ShareInterrupt,
-		Affinity, FALSE);
-	if (!NT_SUCCESS(Status))
-	{
-		DPRINT("hci: IoConnectInterrupt() failed with status 0x%08x\n", Status);
-		return 1;
-	}
-#endif
-}
-
-NTSTATUS
-InitLinuxWrapper(PDEVICE_OBJECT DeviceObject)
-{
-	NTSTATUS Status;
-	POHCI_DEVICE_EXTENSION DeviceExtension = (POHCI_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
-
-	// Allocate and fill generic linux structs
-	dev = ExAllocatePoolWithTag(PagedPool, sizeof(struct pci_dev), USB_OHCI_TAG);
-	dev->irq = DeviceExtension->InterruptVector;
-	dev->dev_ext = (PVOID)DeviceExtension;
-	dev->dev.dev_ext = (PVOID)DeviceExtension;
-	dev->slot_name = ExAllocatePoolWithTag(NonPagedPool, 128, USB_OHCI_TAG); // 128 max len for slot name
-
-	// Init wrapper
-	init_wrapper(dev);
-
-	strcpy(dev->dev.name, "OpenHCI PCI-USB Controller");
-	strcpy(dev->slot_name, "OHCD PCI Slot");
-
-	// Init the OHCI HCD. Probe will be called automatically, but will fail because id=NULL
-	Status = ohci_hcd_pci_init();
-	//FIXME: Check status returned value
-
-	// Init core usb
-	usb_init();
-
-	// Probe device with real id now
-	ohci_pci_driver.probe(dev, pci_ids);
-
-	// Register interrupt here
-	RegisterISR(DeviceObject);
-
-	DPRINT1("InitLinuxWrapper() done\n");
-
-	return STATUS_SUCCESS;
-}
-
-NTSTATUS STDCALL
-OHCD_PnPStartDevice(IN PDEVICE_OBJECT DeviceObject,
-					IN PIRP	Irp)
-{
-	PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
-	PDRIVER_OBJECT DriverObject;
-	POHCI_DRIVER_EXTENSION DriverExtension;
-	POHCI_DEVICE_EXTENSION DeviceExtension;
-	PCM_RESOURCE_LIST AllocatedResources;
-
-	NTSTATUS Status; // debug
-	//LONGLONG delay; // debug
-
-	if (DeviceObject == KeyboardFdo || DeviceObject == MouseFdo)
-		return STATUS_SUCCESS;
-
-	/*
-	* Get the initialization data we saved in VideoPortInitialize.
-	*/
-	DriverObject = DeviceObject->DriverObject;
-	DriverExtension	= IoGetDriverObjectExtension(DriverObject, DriverObject);
-	DeviceExtension	= (POHCI_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
-
-	/*
-	* Store	some resources in the DeviceExtension.
-	*/
-	AllocatedResources = Stack->Parameters.StartDevice.AllocatedResources;
-	if (AllocatedResources != NULL)
-	{
-		CM_FULL_RESOURCE_DESCRIPTOR	*FullList;
-		CM_PARTIAL_RESOURCE_DESCRIPTOR *Descriptor;
-		ULONG ResourceCount;
-		ULONG ResourceListSize;
-
-		/* Save	the	resource list */
-		ResourceCount =	AllocatedResources->List[0].PartialResourceList.Count;
-		ResourceListSize =
-			FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.
-			PartialDescriptors[ResourceCount]);
-		DeviceExtension->AllocatedResources	= ExAllocatePool(PagedPool,	ResourceListSize);
-		if (DeviceExtension->AllocatedResources	== NULL)
-		{
-			return STATUS_INSUFFICIENT_RESOURCES;
-		}
-
-		RtlCopyMemory(DeviceExtension->AllocatedResources,
-			AllocatedResources,
-			ResourceListSize);
-
-		/* Get the interrupt level/vector -	needed by HwFindAdapter	sometimes */
-		for	(FullList =	AllocatedResources->List;
-			FullList < AllocatedResources->List	+ AllocatedResources->Count;
-			FullList++)
-		{
-			/* FIXME: Is this ASSERT ok	for	resources from the PNP manager?	*/
-			/*ASSERT(FullList->InterfaceType == PCIBus &&
-				FullList->BusNumber	== DeviceExtension->SystemIoBusNumber &&
-				1 == FullList->PartialResourceList.Version &&
-				1 == FullList->PartialResourceList.Revision);*/
-			for	(Descriptor	= FullList->PartialResourceList.PartialDescriptors;
-				Descriptor < FullList->PartialResourceList.PartialDescriptors +	FullList->PartialResourceList.Count;
-				Descriptor++)
-			{
-				if (Descriptor->Type ==	CmResourceTypeInterrupt)
-				{
-					DeviceExtension->InterruptLevel	= Descriptor->u.Interrupt.Level;
-					DeviceExtension->InterruptVector = Descriptor->u.Interrupt.Vector;
-				}
-				else if (Descriptor->Type ==	CmResourceTypeMemory)
-				{
-					DeviceExtension->BaseAddress	= Descriptor->u.Memory.Start;
-					DeviceExtension->BaseAddrLength = Descriptor->u.Memory.Length;
-				}
-			}
-		}
-	}
-	DPRINT1("Interrupt level: 0x%x Interrupt	Vector:	0x%x\n",
-		DeviceExtension->InterruptLevel,
-		DeviceExtension->InterruptVector);
-
-	/*
-	* Init wrapper with this object
-	*/
-	//return InitLinuxWrapper(DeviceObject);
-
-	// debug wait
-	Status = InitLinuxWrapper(DeviceObject);
-
-	//delay = -10000000*30; // wait 30 secs
-	//KeDelayExecutionThread(KernelMode, FALSE, (LARGE_INTEGER *)&delay); //wait_us(1);
-
-	return Status;
-}
[truncated at 1000 lines; 408 more skipped]