9c3c3d7e5fef9d2f6d608740fd9807c27f105e94
[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 = STATUS_SUCCESS;
18
19 PUSBMP_DEVICE_EXTENSION DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
20
21 /* Create generic linux structure */
22 struct pci_dev *dev;
23 dev = ExAllocatePoolWithTag(PagedPool, sizeof(struct pci_dev), USB_UHCI_TAG);
24 DeviceExtension->pdev = dev;
25
26 /* Initialize generic linux structure */
27 dev->irq = DeviceExtension->InterruptVector;
28 dev->dev_ext = (PVOID)DeviceExtension;
29 dev->dev.dev_ext = (PVOID)DeviceExtension;
30 dev->slot_name = ExAllocatePoolWithTag(NonPagedPool, 128, USB_UHCI_TAG); // 128 max len for slot name
31 init_wrapper(dev);
32
33 strcpy(dev->dev.name, "UnivHCI PCI-USB Controller");
34 strcpy(dev->slot_name, "UHCD PCI Slot");
35
36 /* Init the HCD. Probe will be called automatically, but will fail because id=NULL */
37 Status = uhci_hcd_init();
38 if (!NT_SUCCESS(Status))
39 {
40 DPRINT("UHCI: uhci_hcd_init() failed with status 0x%08lx\n", Status);
41 /* FIXME: deinitialize linux wrapper */
42 ExFreePoolWithTag(dev, USB_UHCI_TAG);
43 return Status;
44 }
45
46 /* Init core usb */
47 usb_init();
48
49 /* Probe device with real id now */
50 uhci_pci_driver.probe(dev, uhci_pci_ids);
51
52 return Status;
53 }
54
55 VOID STDCALL
56 DriverUnload(PDRIVER_OBJECT DriverObject)
57 {
58 PUSBMP_DEVICE_EXTENSION DeviceExtension;
59 PDEVICE_OBJECT DeviceObject;
60 struct pci_dev *dev;
61
62 DeviceObject = DriverObject->DeviceObject;
63 DeviceExtension = (PUSBMP_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
64
65 dev = DeviceExtension->pdev;
66
67 DPRINT1("UHCI: DriverUnload()\n");
68
69 // Exit usb device
70 usb_exit();
71
72 // Remove device (uhci_pci_driver.remove)
73 uhci_pci_driver.remove(dev);
74
75 ExFreePool(dev->slot_name);
76 ExFreePool(dev);
77
78 // Perform some cleanup
79 uhci_hcd_cleanup();
80 }