Make OHCI+Core drivers really working, they are basically working now.
Next thing to do is to make them working better (e.g. having a thread
infinitely looping to serve irqs/other stuff isn't a good solution for
multitasking OS) - add interrupt handler, spinlocks wrappers, waits etc.
Modified: trunk/reactos/drivers/usb/cromwell/core/hcd-pci.c
Modified: trunk/reactos/drivers/usb/cromwell/core/hub.c
Modified: trunk/reactos/drivers/usb/cromwell/core/makefile
Modified: trunk/reactos/drivers/usb/cromwell/core/usb.c
Modified: trunk/reactos/drivers/usb/cromwell/core/usbcore.c
Modified: trunk/reactos/drivers/usb/cromwell/core/usbcore.def
Modified: trunk/reactos/drivers/usb/cromwell/host/makefile
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci-hcd.c
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci-pci.c
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci.h
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci_main.c
Added: trunk/reactos/drivers/usb/cromwell/host/ohci_main.h
Modified: trunk/reactos/drivers/usb/cromwell/linux/linux_wrapper.h
Modified: trunk/reactos/drivers/usb/cromwell/linux/pci_hal.c
Modified: trunk/reactos/drivers/usb/cromwell/linux/pci_ids.h
Modified: trunk/reactos/drivers/usb/cromwell/sys/linuxwrapper.c
_____
Modified: trunk/reactos/drivers/usb/cromwell/core/hcd-pci.c
--- trunk/reactos/drivers/usb/cromwell/core/hcd-pci.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/core/hcd-pci.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -62,13 +62,16 @@
int STDCALL usb_hcd_pci_probe (struct pci_dev *dev, const struct
pci_device_id *id)
{
struct hc_driver *driver;
- unsigned long resource, len;
+ PHYSICAL_ADDRESS resource;
+ unsigned long len;
void *base;
struct usb_hcd *hcd;
int retval, region;
char buf [8];
//char *bufp = buf;
+ printk("usbcore: usb_hcd_pci_probe() called\n");
+
if (usb_disabled())
return -ENODEV;
@@ -103,7 +106,8 @@
}
} else { // UHCI
- resource = len = 0;
+ //resource = 0;
+ len = 0;
for (region = 0; region < PCI_ROM_RESOURCE; region++) {
if (!(pci_resource_flags (dev, region) &
IORESOURCE_IO))
continue;
@@ -118,7 +122,7 @@
dbg ("no i/o regions available");
return -EBUSY;
}
- base = (void *) resource;
+ base = NULL; //(void *) resource; // this isn't possible
}
// driver->start(), later on, will transfer device from
@@ -165,7 +169,7 @@
if (request_irq (dev->irq, usb_hcd_irq, SA_SHIRQ,
hcd->description, hcd)
!= 0) {
dev_err (hcd->controller,
- "request interrupt %s failed\n", bufp);
+ "request interrupt %s failed\n", buf);
retval = -EBUSY;
goto clean_3;
}
@@ -173,7 +177,7 @@
hcd->regs = base;
hcd->region = region;
- dev_info (hcd->controller, "irq %s, %s %p\n", bufp,
+ dev_info (hcd->controller, "irq %s, %s %p\n", buf,
(driver->flags & HCD_MEMORY) ? "pci mem" : "io base",
base);
_____
Modified: trunk/reactos/drivers/usb/cromwell/core/hub.c
--- trunk/reactos/drivers/usb/cromwell/core/hub.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/core/hub.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -1148,8 +1148,13 @@
do {
hub_events();
- wait_event_interruptible(khubd_wait,
!list_empty(&hub_event_list));
+ //FIXME: Correct this
+ //wait_event_interruptible(khubd_wait,
!list_empty(&hub_event_list)); // interruptable_sleep_on analog - below
+ /*while (!list_empty(&hub_event_list)) {
+ interruptible_sleep_on(&khubd_wait);
+ }*/
+
if (current->flags & PF_FREEZE)
refrigerator(PF_IOTHREAD);
_____
Modified: trunk/reactos/drivers/usb/cromwell/core/makefile
--- trunk/reactos/drivers/usb/cromwell/core/makefile 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/core/makefile 2005-02-19
23:12:32 UTC (rev 13660)
@@ -6,7 +6,7 @@
TARGET_DDKLIBS = ntoskrnl.a
-TARGET_CFLAGS = -Wall -I$(PATH_TO_TOP)/ntoskrnl/include
+TARGET_CFLAGS = -Wall -I$(PATH_TO_TOP)/ntoskrnl/include -DDEBUG_MODE
TARGET_OBJECTS = \
message.o hcd.o hcd-pci.o hub.o usb.o config.o urb.o \
_____
Modified: trunk/reactos/drivers/usb/cromwell/core/usb.c
--- trunk/reactos/drivers/usb/cromwell/core/usb.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/core/usb.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -1042,7 +1042,7 @@
"USB device %04x:%04x (%s)",
vendor_id, product_id, mfgr_str);
}
- //usbprintk("USB connected: %s\n",dev->dev.name);
+ usbprintk("USB connected: %s\n",dev->dev.name);
kfree(buf);
}
@@ -1227,6 +1227,7 @@
"usb-%s-%s interface %d",
dev->bus->bus_name, dev->devpath,
desc->bInterfaceNumber);
+ DPRINT1("usb_new_device: %s\n",
interface->dev.name);
}
dev_dbg (&dev->dev, "%s - registering interface %s\n",
__FUNCTION__, interface->dev.bus_id);
device_add (&interface->dev);
@@ -1510,7 +1511,7 @@
/*
* Init
*/
-static int __init usb_init(void)
+int STDCALL __init usb_init(void)
{
if (nousb) {
info("USB support disabled\n");
@@ -1530,7 +1531,7 @@
/*
* Cleanup
*/
-static void __exit usb_exit(void)
+void STDCALL __exit usb_exit(void)
{
/* This will matter if shutdown/reboot does exitcalls. */
if (nousb)
_____
Modified: trunk/reactos/drivers/usb/cromwell/core/usbcore.c
--- trunk/reactos/drivers/usb/cromwell/core/usbcore.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/core/usbcore.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -4,13 +4,60 @@
*/
#include <ddk/ntddk.h>
+#include <debug.h>
+NTSTATUS AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT pdo)
+{
+ DbgPrint("usbcore: AddDevice called\n");
+
+ /* we need to do kind of this stuff here (as usual)
+ PDEVICE_OBJECT fdo;
+ IoCreateDevice(..., &fdo);
+ pdx->LowerDeviceObject =
+ IoAttachDeviceToDeviceStack(fdo, pdo);*/
+ return STATUS_SUCCESS;
+}
+
+VOID DriverUnload(PDRIVER_OBJECT DriverObject)
+{
+ // nothing to do here yet
+}
+
+// Dispatch PNP
+NTSTATUS DispatchPnp(PDEVICE_OBJECT fdo, PIRP Irp)
+{
+ ULONG fcn;
+ PIO_STACK_LOCATION stack;
+
+ stack = IoGetCurrentIrpStackLocation(Irp);
+ fcn = stack->MinorFunction;
+ DbgPrint("IRP_MJ_PNP, fcn=%d\n", fcn);
+
+ if (fcn == IRP_MN_REMOVE_DEVICE)
+ {
+ IoDeleteDevice(fdo);
+ }
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS DispatchPower(PDEVICE_OBJECT fido, PIRP Irp)
+{
+ DbgPrint("IRP_MJ_POWER dispatch\n");
+ return STATUS_SUCCESS;
+}
+
/*
* Standard DriverEntry method.
*/
NTSTATUS STDCALL
-DriverEntry(IN PVOID Context1, IN PVOID Context2)
+DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegPath)
{
+ DriverObject->DriverUnload = DriverUnload;
+ DriverObject->DriverExtension->AddDevice = AddDevice;
+ DriverObject->MajorFunction[IRP_MJ_PNP] = DispatchPnp;
+ DriverObject->MajorFunction[IRP_MJ_POWER] = DispatchPower;
+
return STATUS_SUCCESS;
}
_____
Modified: trunk/reactos/drivers/usb/cromwell/core/usbcore.def
--- trunk/reactos/drivers/usb/cromwell/core/usbcore.def 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/core/usbcore.def 2005-02-19
23:12:32 UTC (rev 13660)
@@ -2,6 +2,8 @@
; Exports definition file for usbcore.sys
;
EXPORTS
+usb_init@0
+usb_exit@0
usb_init_urb@4
usb_alloc_urb@8
usb_free_urb@4
_____
Modified: trunk/reactos/drivers/usb/cromwell/host/makefile
--- trunk/reactos/drivers/usb/cromwell/host/makefile 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/host/makefile 2005-02-19
23:12:32 UTC (rev 13660)
@@ -6,7 +6,7 @@
TARGET_DDKLIBS = ntoskrnl.a usbcore.a
-TARGET_CFLAGS = -Wall -I$(PATH_TO_TOP)/ntoskrnl/include
+TARGET_CFLAGS = -Wall -I$(PATH_TO_TOP)/ntoskrnl/include -DDEBUG_MODE
TARGET_OBJECTS = \
ohci-hcd.o ohci_main.o ../sys/ros_wrapper.o ../sys/linuxwrapper.o
_____
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci-hcd.c
--- trunk/reactos/drivers/usb/cromwell/host/ohci-hcd.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/host/ohci-hcd.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -471,7 +471,7 @@
/* a reset clears this */
writel ((u32) ohci->hcca_dma, &ohci->regs->hcca);
-// usbprintk("HCCA: %p \n",ohci->regs->hcca);
+ usbprintk("HCCA: %p \n",ohci->regs->hcca);
/* force default fmInterval (we won't adjust it); init
thresholds
* for last FS and LS packets, reserve 90% for periodic.
_____
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci-pci.c
--- trunk/reactos/drivers/usb/cromwell/host/ohci-pci.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/host/ohci-pci.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -38,6 +38,8 @@
struct ohci_hcd *ohci = hcd_to_ohci (hcd);
int ret;
+ DPRINT("ohci_pci_start()\n");
+
if (hcd->pdev) {
ohci->hcca = pci_alloc_consistent (hcd->pdev,
sizeof *ohci->hcca, &ohci->hcca_dma);
@@ -86,23 +88,27 @@
}
- memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
+ memset (ohci->hcca, 0, sizeof (struct ohci_hcca));
if ((ret = ohci_mem_init (ohci)) < 0) {
ohci_stop (hcd);
return ret;
}
ohci->regs = hcd->regs;
+ DPRINT("Controller memory init done\n");
+
if (hc_reset (ohci) < 0) {
ohci_stop (hcd);
return -ENODEV;
}
+ DPRINT("Controller reset done\n");
if (hc_start (ohci) < 0) {
ohci_err (ohci, "can't start\n");
ohci_stop (hcd);
return -EBUSY;
}
+ DPRINT("Controller start done\n");
#ifdef DEBUG
ohci_dump (ohci, 1);
@@ -352,7 +358,7 @@
/*----------------------------------------------------------------------
---*/
-static const struct pci_device_id __devinitdata pci_ids [] = { {
+const struct pci_device_id __devinitdata pci_ids [] = { {
/* handle any USB OHCI controller */
.class = (PCI_CLASS_SERIAL_USB << 8) | 0x10,
@@ -370,7 +376,7 @@
MODULE_DEVICE_TABLE (pci, pci_ids);
/* pci driver glue; this is a "new style" PCI driver module */
-static struct pci_driver ohci_pci_driver = {
+struct pci_driver ohci_pci_driver = {
.name = (char *) hcd_name,
.id_table = pci_ids,
@@ -384,22 +390,23 @@
};
-static int __init ohci_hcd_pci_init (void)
+int ohci_hcd_pci_init (void)
{
printk (KERN_DEBUG "%s: " DRIVER_INFO " (PCI)\n", hcd_name);
if (usb_disabled())
return -ENODEV;
- printk (KERN_DEBUG "%s: block sizes: ed %Zd td %Zd\n", hcd_name,
- sizeof (struct ed), sizeof (struct td));
+ // causes page fault in reactos
+ //printk (KERN_DEBUG "%s: block sizes: ed %Zd td %Zd\n",
hcd_name,
+ // sizeof (struct ed), sizeof (struct td));
return pci_module_init (&ohci_pci_driver);
}
-module_init (ohci_hcd_pci_init);
+/*module_init (ohci_hcd_pci_init);*/
/*----------------------------------------------------------------------
---*/
-static void __exit ohci_hcd_pci_cleanup (void)
+void ohci_hcd_pci_cleanup (void)
{
pci_unregister_driver (&ohci_pci_driver);
}
-module_exit (ohci_hcd_pci_cleanup);
+/*module_exit (ohci_hcd_pci_cleanup);*/
_____
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci.h
--- trunk/reactos/drivers/usb/cromwell/host/ohci.h 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/host/ohci.h 2005-02-19
23:12:32 UTC (rev 13660)
@@ -240,11 +240,23 @@
#define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
/* pre-shifted values for HCFS */
-# define OHCI_USB_RESET (0 << 6)
-# define OHCI_USB_RESUME (1 << 6)
-# define OHCI_USB_OPER (2 << 6)
-# define OHCI_USB_SUSPEND (3 << 6)
+#define OHCI_USB_RESET (0 << 6)
+#define OHCI_USB_RESUME (1 << 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
*/
_____
Modified: trunk/reactos/drivers/usb/cromwell/host/ohci_main.c
--- trunk/reactos/drivers/usb/cromwell/host/ohci_main.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/host/ohci_main.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -1,61 +1,295 @@
/*
- ReactOS specific functions for ohci module
+ ReactOS specific functions for OHCI module
by Aleksey Bragin (aleksey(a)reactos.com)
+ Some parts of code are inspired (or even just copied) from ReactOS
Videoport driver
*/
#include <ddk/ntddk.h>
#include <debug.h>
+#include "../linux/linux_wrapper.h"
+#include "ohci_main.h"
-NTSTATUS AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT pdo)
+// 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;
+
+
+#define USB_OHCI_TAG TAG('u','s','b','o')
+
+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;
- DbgPrint("ohci: AddDevice called\n");
+ DPRINT1("ohci: AddDevice called\n");
+
+ // 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. */
- swprintf(DeviceBuffer, L"\\Device\\usbohci");
+ // 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);
- Status = IoCreateDevice(DriverObject, 0, &DeviceName,
FILE_DEVICE_VIDEO, 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)pdo->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");
return STATUS_SUCCESS;
}
-VOID DriverUnload(PDRIVER_OBJECT DriverObject)
+VOID STDCALL DriverUnload(PDRIVER_OBJECT DriverObject)
{
- // nothing to do here yet
+ 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();
}
-// Dispatch PNP
-NTSTATUS DispatchPnp(PDEVICE_OBJECT fdo, PIRP Irp)
+NTSTATUS InitLinuxWrapper(PDEVICE_OBJECT DeviceObject)
{
- ULONG fcn;
- PIO_STACK_LOCATION stack;
+ NTSTATUS Status;
+ POHCI_DEVICE_EXTENSION DeviceExtension =
(POHCI_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
+
+ // Fill generic linux structs
+ dev = ExAllocatePoolWithTag(PagedPool, sizeof(struct pci_dev),
USB_OHCI_TAG);
- stack = IoGetCurrentIrpStackLocation(Irp);
- fcn = stack->MinorFunction;
- DbgPrint("IRP_MJ_PNP, fcn=%d\n", fcn);
+ init_wrapper(dev);
+ dev->irq = DeviceExtension->InterruptLevel;
+ dev->dev_ext = (PVOID)DeviceExtension;
+ dev->slot_name = ExAllocatePoolWithTag(NonPagedPool, 128,
USB_OHCI_TAG); // 128 max len for slot name
- if (fcn == IRP_MN_REMOVE_DEVICE)
- {
- IoDeleteDevice(fdo);
- }
+ 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);
+
+ DPRINT("InitLinuxWrapper() done\n");
+
return STATUS_SUCCESS;
}
-NTSTATUS DispatchPower(PDEVICE_OBJECT fido, PIRP Irp)
+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;
+
+ /*
+ * 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);
+}
+
+// Dispatch PNP
+NTSTATUS STDCALL DispatchPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
+{
+ PIO_STACK_LOCATION IrpSp;
+ NTSTATUS Status;
+
+ IrpSp = IoGetCurrentIrpStackLocation(Irp);
+
+ switch (IrpSp->MinorFunction)
+ {
+ case IRP_MN_START_DEVICE:
+ //Status = IntVideoPortForwardIrpAndWait(DeviceObject, Irp);
+ //if (NT_SUCCESS(Status) && NT_SUCCESS(Irp->IoStatus.Status))
+
+ Status = OHCD_PnPStartDevice(DeviceObject, Irp);
+ Irp->IoStatus.Status = Status;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ break;
+
+
+ case IRP_MN_REMOVE_DEVICE:
+ case IRP_MN_QUERY_REMOVE_DEVICE:
+ case IRP_MN_CANCEL_REMOVE_DEVICE:
+ case IRP_MN_SURPRISE_REMOVAL:
+
+ case IRP_MN_STOP_DEVICE:
+ //Status = IntVideoPortForwardIrpAndWait(DeviceObject, Irp);
+ //if (NT_SUCCESS(Status) && NT_SUCCESS(Irp->IoStatus.Status))
+ Status = STATUS_SUCCESS;
+ Irp->IoStatus.Status = Status;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+
+ IoDeleteDevice(DeviceObject); // just delete device for
now
+ break;
+
+ case IRP_MN_QUERY_STOP_DEVICE:
+ case IRP_MN_CANCEL_STOP_DEVICE:
+ Status = STATUS_SUCCESS;
+ Irp->IoStatus.Status = STATUS_SUCCESS;
+ Irp->IoStatus.Information = 0;
+ IoCompleteRequest(Irp, IO_NO_INCREMENT);
+ break;
+
+ default:
+ return STATUS_NOT_IMPLEMENTED;
+ break;
+ }
+
+ return Status;
+}
+
+NTSTATUS STDCALL DispatchPower(PDEVICE_OBJECT fido, PIRP Irp)
+{
DbgPrint("IRP_MJ_POWER dispatch\n");
return STATUS_SUCCESS;
}
_____
Added: trunk/reactos/drivers/usb/cromwell/host/ohci_main.h
--- trunk/reactos/drivers/usb/cromwell/host/ohci_main.h 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/host/ohci_main.h 2005-02-19
23:12:32 UTC (rev 13660)
@@ -0,0 +1,46 @@
+/*
+ * OHCI WDM/PNP driver
+ *
+ * Copyright (C) 2005 ReactOS Team
+ *
+ * Author: Aleksey Bragin (aleksey(a)reactos.com)
+ *
+ */
+
+#ifndef OHCI_MAIN_H
+#define OHCI_MAIN_H
+
+typedef struct _OHCI_DRIVER_EXTENSION
+{
+ //OHCI_HW_INITIALIZATION_DATA InitializationData;
+ PVOID HwContext;
+ //UNICODE_STRING RegistryPath;
+} OHCI_DRIVER_EXTENSION, *POHCI_DRIVER_EXTENSION;
+
+typedef struct _OHCI_DEVICE_EXTENSTION
+{
+ ULONG DeviceNumber;
+ PDEVICE_OBJECT PhysicalDeviceObject;
+ PDEVICE_OBJECT FunctionalDeviceObject;
+ PDEVICE_OBJECT NextDeviceObject;
+ //UNICODE_STRING RegistryPath;
+ PKINTERRUPT InterruptObject;
+ KSPIN_LOCK InterruptSpinLock;
+ PCM_RESOURCE_LIST AllocatedResources;
+ ULONG InterruptVector;
+ ULONG InterruptLevel;
+ PHYSICAL_ADDRESS BaseAddress;
+ ULONG BaseAddrLength;
+ ULONG AdapterInterfaceType;
+ ULONG SystemIoBusNumber;
+ ULONG SystemIoSlotNumber;
+ LIST_ENTRY AddressMappingListHead;
+ //KDPC DpcObject;
+ OHCI_DRIVER_EXTENSION *DriverExtension;
+ ULONG DeviceOpened;
+ //KMUTEX DeviceLock;
+ //CHAR MiniPortDeviceExtension[1];
+} OHCI_DEVICE_EXTENSION, *POHCI_DEVICE_EXTENSION;
+
+
+#endif
_____
Modified: trunk/reactos/drivers/usb/cromwell/linux/linux_wrapper.h
--- trunk/reactos/drivers/usb/cromwell/linux/linux_wrapper.h
2005-02-19 23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/linux/linux_wrapper.h
2005-02-19 23:12:32 UTC (rev 13660)
@@ -205,6 +205,7 @@
int base[4];
int flags[4];
void * data;
+ void * dev_ext; // link to Windows DeviceExtension
};
struct pci_bus {
@@ -475,12 +476,19 @@
#define daemonize(a) do {} while(0)
#define allow_signal(a) do {} while(0)
#define wait_event_interruptible(x,y) do {} while(0)
+
+#define interruptible_sleep_on(a) my_interruptible_sleep_on(a)
+void my_interruptible_sleep_on(int a);
+
#define flush_scheduled_work() do {} while(0)
#define refrigerator(x) do {} while(0)
#define signal_pending(x) 1 // fall through threads
#define complete_and_exit(a,b) return 0
-#define kill_proc(a,b,c) 0
+//#define kill_proc(a,b,c) 0
+#define kill_proc(a,b,c) my_kill_proc(a, b, c);
+int my_kill_proc(int pid, int signal, int unk);
+
#define yield() do {} while(0)
#define cpu_relax() do {} while(0)
@@ -528,7 +536,7 @@
/*----------------------------------------------------------------------
--*/
#ifdef DEBUG_MODE
#define dev_printk(lvl,x,f,arg...) printk(f, ## arg)
-#define dev_dbg(x,f,arg...) do {} while (0) //printk(f, ## arg)
+#define dev_dbg(x,f,arg...) printk(f, ## arg)
#define dev_info(x,f,arg...) printk(f,## arg)
#define dev_warn(x,f,arg...) printk(f,## arg)
#define dev_err(x,f,arg...) printk(f,## arg)
@@ -681,7 +689,7 @@
}
#define kernel_thread(a,b,c) my_kernel_thread(a,b,c)
-int my_kernel_thread(int (*handler)(void*), void* parm, int flags);
+int my_kernel_thread(int STDCALL (*handler)(void*), void* parm, int
flags);
/*----------------------------------------------------------------------
--*/
/* PCI, simple and inlined... */
@@ -714,7 +722,7 @@
void handle_irqs(int irq);
void inc_jiffies(int);
-void init_wrapper(void);
+void init_wrapper(struct pci_dev *pci_dev);
void do_all_timers(void);
#define __KERNEL_DS 0x18
_____
Modified: trunk/reactos/drivers/usb/cromwell/linux/pci_hal.c
--- trunk/reactos/drivers/usb/cromwell/linux/pci_hal.c 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/linux/pci_hal.c 2005-02-19
23:12:32 UTC (rev 13660)
@@ -1,29 +1,45 @@
// PCI -> HAL interface
// this file is part of linux_wrapper.h
+//FIXME: Move this file, make its definitions more general
+#include "../host/ohci_main.h"
+
/*
Initialize device before it's used by a driver. Ask low-level code to
enable I/O and memory.
Wake up the device if it was suspended. Beware, this function can
fail.
*/
static int __inline__ pci_enable_device(struct pci_dev *dev)
{
+ DPRINT1("pci_enable_device() called...\n");
return 0;
}
// Get physical address where resource x resides
-static unsigned long __inline__ pci_resource_start (struct pci_dev
*dev, int x)
+static PHYSICAL_ADDRESS __inline__ pci_resource_start (struct pci_dev
*dev, int x)
{
- // HalGetBusData...
- // HalAssignSlotResources ?
- return dev->base[x];
+ POHCI_DEVICE_EXTENSION dev_ext =
(POHCI_DEVICE_EXTENSION)dev->dev_ext;
+ DPRINT1("pci_resource_start() called, x=0x%x\n", x);
+
+ //FIXME: Take x into account
+ return dev_ext->BaseAddress;
+ //return dev->base[x];
}
// ???
-static unsigned long __inline__ pci_resource_len (struct pci_dev *dev,
int x){return 0;}
+static unsigned long __inline__ pci_resource_len (struct pci_dev *dev,
int x)
+{
+ POHCI_DEVICE_EXTENSION ext =
(POHCI_DEVICE_EXTENSION)dev->dev_ext;
+ DPRINT1("pci_resource_len() called, x=0x%x\n", x);
+
+ //FIXME: Take x into account
+ return ext->BaseAddrLength;
+}
+
// ???
static int __inline__ pci_resource_flags(struct pci_dev *dev, int x)
{
+ DPRINT1("pci_resource_flags() called, x=0x%x\n");
return dev->flags[x];
}
@@ -35,6 +51,7 @@
// Store pointer to data for this device
static int __inline__ pci_set_drvdata(struct pci_dev *dev, void* d)
{
+ DPRINT1("pci_set_drvdata() called...\n");
dev->data=(void*)d;
return 0;
}
@@ -42,6 +59,7 @@
// Get pointer to previously saved data
static void __inline__ *pci_get_drvdata(struct pci_dev *dev)
{
+ DPRINT1("pci_get_drvdata() called...\n");
return dev->data;
}
@@ -59,16 +77,25 @@
n length of region
name name of requester
*/
-static int __inline__ request_region(unsigned long addr, unsigned long
len, const char * d){return 0;}
+static int __inline__ request_region(PHYSICAL_ADDRESS addr, unsigned
long len, const char * d)
+{
+ DPRINT1("request_region(): addr=0x%x, len=0x%x\n", addr, len);
+ return 0;
+}
/*
Unmap I/O memory from kernel address space.
Parameters:
addr virtual start address
+
*/
static int __inline__ iounmap(void* p)
{
+ DPRINT1("iounmap(): p=0x%x. FIXME - how to obtain len of mapped
region?\n", p);
+
+ //MmUnnapIoSpace(p);
+
return 0;
}
@@ -79,7 +106,11 @@
start begin of region
n length of region
*/
-static int __inline__ release_region(unsigned long addr, unsigned long
len){return 0;}
+static int __inline__ release_region(PHYSICAL_ADDRESS addr, unsigned
long len)
+{
+ DPRINT1("release_region(): addr=0x%x, len=0x%x\n", addr, len);
+ return 0;
+}
/*
Allocate I/O memory region.
@@ -89,8 +120,9 @@
n length of region
name name of requester
*/
-static int __inline__ request_mem_region(unsigned long addr, unsigned
long len, const char * d)
+static int __inline__ request_mem_region(PHYSICAL_ADDRESS addr,
unsigned long len, const char * d)
{
+ DPRINT1("request_mem_region(): addr=0x%x, len=0x%x\n", addr,
len);
return 1;
}
@@ -104,10 +136,12 @@
Returns:
virtual start address of mapped range
*/
-static void __inline__ *ioremap_nocache(unsigned long addr, unsigned
long len)
+static void __inline__ *ioremap_nocache(PHYSICAL_ADDRESS addr, unsigned
long len)
{
- // MmMapIoSpace ?
- return (void*)addr;
+ // MmMapIoSpace with NoCache param
+ DPRINT1("ioremap_nocache(): addr=0x%x, len=0x%x\n", addr, len);
+
+ return MmMapIoSpace(addr, len, MmNonCached);
}
/*
@@ -117,7 +151,8 @@
start begin of region
n length of region
*/
-static int __inline__ release_mem_region(unsigned long addr, unsigned
long len)
+static int __inline__ release_mem_region(PHYSICAL_ADDRESS addr,
unsigned long len)
{
+ DPRINT1("release_mem_region(): addr=0x%x, len=0x%x\n", addr,
len);
return 0;
}
_____
Modified: trunk/reactos/drivers/usb/cromwell/linux/pci_ids.h
--- trunk/reactos/drivers/usb/cromwell/linux/pci_ids.h 2005-02-19
23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/linux/pci_ids.h 2005-02-19
23:12:32 UTC (rev 13660)
@@ -8,4 +8,4 @@
#define PCI_CLASS_SERIAL_USB (PCI_CLASS_SERIAL_BUS_CTLR << 8 +
PCI_SUBCLASS_SB_USB)
-#endif
\ No newline at end of file
+#endif
_____
Modified: trunk/reactos/drivers/usb/cromwell/sys/linuxwrapper.c
--- trunk/reactos/drivers/usb/cromwell/sys/linuxwrapper.c
2005-02-19 23:08:28 UTC (rev 13659)
+++ trunk/reactos/drivers/usb/cromwell/sys/linuxwrapper.c
2005-02-19 23:12:32 UTC (rev 13660)
@@ -47,7 +47,7 @@
* Helper functions for top-level system
*/
/*----------------------------------------------------------------------
--*/
-void init_wrapper(void)
+void init_wrapper(struct pci_dev *probe_dev)
{
int n;
for(n=0;n<MAX_TIMERS;n++)
@@ -58,7 +58,7 @@
my_jiffies=0;
num_irqs=0;
my_current=&act_cur;
- pci_probe_dev=NULL;
+ pci_probe_dev=probe_dev;
for(n=0;n<MAX_IRQS;n++)
{
@@ -108,12 +108,38 @@
}
/*----------------------------------------------------------------------
--*/
// Purpose: Remember thread procedure and data in global var
-int my_kernel_thread(int (*handler)(void*), void* parm, int flags)
+// ReactOS Purpose: Create real kernel thread
+int my_kernel_thread(int STDCALL (*handler)(void*), void* parm, int
flags)
{
- thread_handler=handler;
- thread_parm=parm;
- return 42; // PID :-)
+ HANDLE hThread;
+ //thread_handler=handler;
+ //thread_parm=parm;
+ //return 42; // PID :-)
+
+ ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);
+
+ PsCreateSystemThread(&hThread,
+ THREAD_ALL_ACCESS,
+ NULL,
+ NULL,
+ NULL,
+ (PKSTART_ROUTINE)handler,
+ parm);
+
+ return (int)hThread; // FIXME: Correct?
}
+
+// Kill the process
[truncated at 1000 lines; 20 more skipped]