diff --git a/reactos/drivers/usb/cromwell/core/hcd-pci.c b/reactos/drivers/usb/cromwell/core/hcd-pci.c index ca7182c0b2a..e65c436cced 100644 --- a/reactos/drivers/usb/cromwell/core/hcd-pci.c +++ b/reactos/drivers/usb/cromwell/core/hcd-pci.c @@ -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 @@ clean_1: } } 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 @@ clean_1: 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 @@ clean_3: 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 @@ clean_3: 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); diff --git a/reactos/drivers/usb/cromwell/core/hub.c b/reactos/drivers/usb/cromwell/core/hub.c index 744ec729b87..b60aa8d9de6 100644 --- a/reactos/drivers/usb/cromwell/core/hub.c +++ b/reactos/drivers/usb/cromwell/core/hub.c @@ -1148,7 +1148,12 @@ static int hub_thread(void *__hub) 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); diff --git a/reactos/drivers/usb/cromwell/core/makefile b/reactos/drivers/usb/cromwell/core/makefile index eeba46f94d7..27d2ff92be6 100644 --- a/reactos/drivers/usb/cromwell/core/makefile +++ b/reactos/drivers/usb/cromwell/core/makefile @@ -6,7 +6,7 @@ TARGET_NAME = usbcore 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 \ diff --git a/reactos/drivers/usb/cromwell/core/usb.c b/reactos/drivers/usb/cromwell/core/usb.c index 4206935def1..be494fb39a4 100644 --- a/reactos/drivers/usb/cromwell/core/usb.c +++ b/reactos/drivers/usb/cromwell/core/usb.c @@ -1042,7 +1042,7 @@ static void set_device_description (struct usb_device *dev) "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 @@ int usb_new_device(struct usb_device *dev, struct device *parent) "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 @@ int STDCALL usb_disabled(void) /* * Init */ -static int __init usb_init(void) +int STDCALL __init usb_init(void) { if (nousb) { info("USB support disabled\n"); @@ -1530,7 +1531,7 @@ static int __init usb_init(void) /* * Cleanup */ -static void __exit usb_exit(void) +void STDCALL __exit usb_exit(void) { /* This will matter if shutdown/reboot does exitcalls. */ if (nousb) diff --git a/reactos/drivers/usb/cromwell/core/usbcore.c b/reactos/drivers/usb/cromwell/core/usbcore.c index 0c8e0c50a9a..34df7e4b021 100644 --- a/reactos/drivers/usb/cromwell/core/usbcore.c +++ b/reactos/drivers/usb/cromwell/core/usbcore.c @@ -4,13 +4,60 @@ */ #include +#include +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; } diff --git a/reactos/drivers/usb/cromwell/core/usbcore.def b/reactos/drivers/usb/cromwell/core/usbcore.def index cc6e7687e2d..ae73cc2a560 100644 --- a/reactos/drivers/usb/cromwell/core/usbcore.def +++ b/reactos/drivers/usb/cromwell/core/usbcore.def @@ -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 diff --git a/reactos/drivers/usb/cromwell/host/makefile b/reactos/drivers/usb/cromwell/host/makefile index 0cc14867050..fa4c7e652ec 100644 --- a/reactos/drivers/usb/cromwell/host/makefile +++ b/reactos/drivers/usb/cromwell/host/makefile @@ -6,7 +6,7 @@ TARGET_NAME = ohci 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 diff --git a/reactos/drivers/usb/cromwell/host/ohci-hcd.c b/reactos/drivers/usb/cromwell/host/ohci-hcd.c index fec58a01b5a..3470fa9e825 100644 --- a/reactos/drivers/usb/cromwell/host/ohci-hcd.c +++ b/reactos/drivers/usb/cromwell/host/ohci-hcd.c @@ -471,7 +471,7 @@ static int hc_start (struct ohci_hcd *ohci) /* 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. diff --git a/reactos/drivers/usb/cromwell/host/ohci-pci.c b/reactos/drivers/usb/cromwell/host/ohci-pci.c index 1e7fd945f21..0ce7123c541 100644 --- a/reactos/drivers/usb/cromwell/host/ohci-pci.c +++ b/reactos/drivers/usb/cromwell/host/ohci-pci.c @@ -38,6 +38,8 @@ ohci_pci_start (struct usb_hcd *hcd) 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 @@ ohci_pci_start (struct usb_hcd *hcd) } - 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 hc_driver ohci_pci_hc_driver = { /*-------------------------------------------------------------------------*/ -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 @@ static const struct pci_device_id __devinitdata pci_ids [] = { { 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 struct pci_driver ohci_pci_driver = { }; -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);*/ diff --git a/reactos/drivers/usb/cromwell/host/ohci.h b/reactos/drivers/usb/cromwell/host/ohci.h index 400b505e65a..632382e88ba 100644 --- a/reactos/drivers/usb/cromwell/host/ohci.h +++ b/reactos/drivers/usb/cromwell/host/ohci.h @@ -240,10 +240,22 @@ struct ohci_regs { #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 diff --git a/reactos/drivers/usb/cromwell/host/ohci_main.c b/reactos/drivers/usb/cromwell/host/ohci_main.c index dd52a066739..aba234a8082 100644 --- a/reactos/drivers/usb/cromwell/host/ohci_main.c +++ b/reactos/drivers/usb/cromwell/host/ohci_main.c @@ -1,26 +1,73 @@ /* - ReactOS specific functions for ohci module + 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 #include +#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, 0, &DeviceName, FILE_DEVICE_VIDEO, 0, FALSE,&fdo); + Status = IoCreateDevice(DriverObject, + sizeof(OHCI_DEVICE_EXTENSION)/* + DriverExtension->InitializationData.HwDeviceExtensionSize*/, + &DeviceName, + FILE_DEVICE_CONTROLLER, + 0, + FALSE, + &fdo); if (!NT_SUCCESS(Status)) { @@ -28,33 +75,220 @@ NTSTATUS AddDevice(PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT pdo) 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(); +} + +NTSTATUS InitLinuxWrapper(PDEVICE_OBJECT DeviceObject) +{ + 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); + + 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 + + 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 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 DispatchPnp(PDEVICE_OBJECT fdo, PIRP Irp) +NTSTATUS STDCALL DispatchPnp(PDEVICE_OBJECT DeviceObject, PIRP Irp) { - ULONG fcn; - PIO_STACK_LOCATION stack; - - stack = IoGetCurrentIrpStackLocation(Irp); - fcn = stack->MinorFunction; - DbgPrint("IRP_MJ_PNP, fcn=%d\n", fcn); + PIO_STACK_LOCATION IrpSp; + NTSTATUS Status; - if (fcn == IRP_MN_REMOVE_DEVICE) - { - IoDeleteDevice(fdo); - } + IrpSp = IoGetCurrentIrpStackLocation(Irp); - return STATUS_SUCCESS; + 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 DispatchPower(PDEVICE_OBJECT fido, PIRP Irp) +NTSTATUS STDCALL DispatchPower(PDEVICE_OBJECT fido, PIRP Irp) { DbgPrint("IRP_MJ_POWER dispatch\n"); return STATUS_SUCCESS; diff --git a/reactos/drivers/usb/cromwell/host/ohci_main.h b/reactos/drivers/usb/cromwell/host/ohci_main.h new file mode 100644 index 00000000000..1324d1ba165 --- /dev/null +++ b/reactos/drivers/usb/cromwell/host/ohci_main.h @@ -0,0 +1,46 @@ +/* + * OHCI WDM/PNP driver + * + * Copyright (C) 2005 ReactOS Team + * + * Author: Aleksey Bragin (aleksey@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 diff --git a/reactos/drivers/usb/cromwell/linux/linux_wrapper.h b/reactos/drivers/usb/cromwell/linux/linux_wrapper.h index bcb1987b98b..89308c722aa 100644 --- a/reactos/drivers/usb/cromwell/linux/linux_wrapper.h +++ b/reactos/drivers/usb/cromwell/linux/linux_wrapper.h @@ -205,6 +205,7 @@ struct pci_dev { int base[4]; int flags[4]; void * data; + void * dev_ext; // link to Windows DeviceExtension }; struct pci_bus { @@ -475,12 +476,19 @@ void my_wait_for_completion(struct completion*); #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 @@ void my_wait_for_completion(struct completion*); /*------------------------------------------------------------------------*/ #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 @@ static void __inline__ complete(struct completion *p) } #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 @@ struct my_irqs { 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 diff --git a/reactos/drivers/usb/cromwell/linux/pci_hal.c b/reactos/drivers/usb/cromwell/linux/pci_hal.c index 4008b8412ff..1fed7ddb4f4 100644 --- a/reactos/drivers/usb/cromwell/linux/pci_hal.c +++ b/reactos/drivers/usb/cromwell/linux/pci_hal.c @@ -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 @@ static int __inline__ pci_set_master(struct pci_dev *dev) {return 0;} // 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 @@ static int __inline__ pci_set_drvdata(struct pci_dev *dev, void* d) // 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 @@ start begin of region 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 @@ Parameters: 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 @@ start begin of region 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 @@ size size of physical address range 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 @@ Parameters: 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; } diff --git a/reactos/drivers/usb/cromwell/linux/pci_ids.h b/reactos/drivers/usb/cromwell/linux/pci_ids.h index 73c93372e04..538413658e9 100644 --- a/reactos/drivers/usb/cromwell/linux/pci_ids.h +++ b/reactos/drivers/usb/cromwell/linux/pci_ids.h @@ -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 diff --git a/reactos/drivers/usb/cromwell/sys/linuxwrapper.c b/reactos/drivers/usb/cromwell/sys/linuxwrapper.c index fce04d21250..e1170e9c828 100644 --- a/reactos/drivers/usb/cromwell/sys/linuxwrapper.c +++ b/reactos/drivers/usb/cromwell/sys/linuxwrapper.c @@ -47,7 +47,7 @@ static int drvs_num; * Helper functions for top-level system */ /*------------------------------------------------------------------------*/ -void init_wrapper(void) +void init_wrapper(struct pci_dev *probe_dev) { int n; for(n=0;n