Minimize differences between UHCI and OHCI
[reactos.git] / reactos / drivers / usb / miniport / usbuhci / uhci.c
1 /*
2 ReactOS specific functions for UHCI module
3 by Aleksey Bragin (aleksey@reactos.com)
4 and Hervé Poussineau (hpoussin@reactos.org)
5 Some parts of code are inspired (or even just copied) from ReactOS Videoport driver
6 */
7 #define NDEBUG
8 #include "uhci.h"
9
10 extern struct pci_driver uhci_pci_driver;
11 extern struct pci_device_id uhci_pci_ids[];
12 struct pci_device_id* pci_ids = &uhci_pci_ids[0];
13
14 NTSTATUS
15 InitLinuxWrapper(PDEVICE_OBJECT DeviceObject)
16 {
17 NTSTATUS Status;
18 PUSBMP_DEVICE_EXTENSION DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
19
20 /* Create generic linux structure */
21 struct pci_dev *dev;
22 dev = ExAllocatePoolWithTag(PagedPool, sizeof(struct pci_dev), USB_UHCI_TAG);
23 DeviceExtension->pdev = dev;
24
25 /* Initialize generic linux structure */
26 dev->irq = DeviceExtension->InterruptVector;
27 dev->dev_ext = (PVOID)DeviceExtension;
28 dev->dev.dev_ext = DeviceObject;
29 dev->slot_name = ExAllocatePoolWithTag(NonPagedPool, 128, USB_UHCI_TAG); // 128 max len for slot name
30
31 /* Init wrapper */
32 init_wrapper(dev);
33
34 strcpy(dev->dev.name, "UnivHCI PCI-USB Controller");
35 strcpy(dev->slot_name, "UHCD PCI Slot");
36
37 /* Init the HCD. Probe will be called automatically, but will fail because id=NULL */
38 Status = uhci_hcd_init();
39 if (!NT_SUCCESS(Status))
40 {
41 DPRINT("UHCI: uhci_hcd_init() failed with status 0x%08lx\n", Status);
42 /* FIXME: deinitialize linux wrapper */
43 ExFreePoolWithTag(dev, USB_UHCI_TAG);
44 return Status;
45 }
46
47 /* Init core usb */
48 usb_init();
49
50 /* Probe device with real id now */
51 uhci_pci_driver.probe(dev, uhci_pci_ids);
52
53 return STATUS_SUCCESS;
54 }
55
56 VOID STDCALL
57 DriverUnload(PDRIVER_OBJECT DriverObject)
58 {
59 PUSBMP_DEVICE_EXTENSION DeviceExtension;
60 PDEVICE_OBJECT DeviceObject;
61 struct pci_dev *dev;
62
63 DeviceObject = DriverObject->DeviceObject;
64 DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
65
66 dev = DeviceExtension->pdev;
67
68 DPRINT1("UHCI: DriverUnload()\n");
69
70 // Exit usb device
71 usb_exit();
72
73 // Remove device (uhci_pci_driver.remove)
74 uhci_pci_driver.remove(dev);
75
76 ExFreePool(dev->slot_name);
77 ExFreePool(dev);
78
79 // Perform some cleanup
80 uhci_hcd_cleanup();
81 }