0c7f2811b6140fb41a9e2bbd52297753c51519b4
[reactos.git] / reactos / drivers / usb / miniport / usbohci / ohci.c
1 #define NDEBUG
2 #include <debug.h>
3
4 #include "ohci.h"
5
6 extern struct pci_driver ohci_pci_driver;
7 extern struct pci_device_id ohci_pci_ids[];
8 struct pci_device_id* pci_ids = &ohci_pci_ids[0];
9
10 NTSTATUS
11 InitLinuxWrapper(PDEVICE_OBJECT DeviceObject)
12 {
13 NTSTATUS Status;
14 PUSBMP_DEVICE_EXTENSION DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
15
16 /* Create generic linux structure */
17 struct pci_dev *dev;
18 dev = ExAllocatePoolWithTag(PagedPool, sizeof(struct pci_dev), USB_OHCI_TAG);
19 DeviceExtension->pdev = dev;
20
21 /* Initialize generic linux structure */
22 dev->irq = DeviceExtension->InterruptVector;
23 dev->dev_ext = (PVOID)DeviceExtension;
24 dev->dev.dev_ext = (PVOID)DeviceExtension;
25 dev->slot_name = ExAllocatePoolWithTag(NonPagedPool, 128, USB_OHCI_TAG); // 128 max len for slot name
26
27 // Init wrapper
28 init_wrapper(dev);
29
30 strcpy(dev->dev.name, "OpenHCI PCI-USB Controller");
31 strcpy(dev->slot_name, "OHCD PCI Slot");
32
33 // Init the OHCI HCD. Probe will be called automatically, but will fail because id=NULL
34 Status = ohci_hcd_pci_init();
35 if (!NT_SUCCESS(Status))
36 {
37 DPRINT("OHCI: ohci_hcd_pci_init() failed with status 0x%08lx\n", Status);
38 /* FIXME: deinitialize linux wrapper */
39 ExFreePoolWithTag(dev, USB_OHCI_TAG);
40 return Status;
41 }
42
43 // Init core usb
44 usb_init();
45
46 // Probe device with real id now
47 ohci_pci_driver.probe(dev, ohci_pci_ids);
48
49 return STATUS_SUCCESS;
50 }
51
52 VOID STDCALL DriverUnload(PDRIVER_OBJECT DriverObject)
53 {
54 PUSBMP_DEVICE_EXTENSION DeviceExtension;
55 PDEVICE_OBJECT DeviceObject;
56 struct pci_dev *dev;
57
58 DeviceObject = DriverObject->DeviceObject;
59 DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
60
61 dev = DeviceExtension->pdev;
62
63 DPRINT1("DriverUnload()\n");
64
65 // Exit usb device
66 usb_exit();
67
68 // Remove device (ohci_pci_driver.remove)
69 ohci_pci_driver.remove(dev);
70
71 ExFreePool(dev->slot_name);
72 ExFreePool(dev);
73
74 // Perform some cleanup
75 ohci_hcd_pci_cleanup();
76 }