[USB]
[reactos.git] / reactos / drivers / usb / usbehci / usbehci.cpp
1 /*
2 * PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/usbehci/usbehci.cpp
5 * PURPOSE: USB EHCI device driver.
6 * PROGRAMMERS:
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
9 */
10
11 #include "usbehci.h"
12
13 //
14 // driver verifier
15 //
16 DRIVER_ADD_DEVICE EHCI_AddDevice;
17
18 NTSTATUS
19 NTAPI
20 EHCI_AddDevice(
21 PDRIVER_OBJECT DriverObject,
22 PDEVICE_OBJECT PhysicalDeviceObject)
23 {
24 NTSTATUS Status;
25 PHCDCONTROLLER HcdController;
26
27 DPRINT1("EHCI_AddDevice\n");
28
29 /* first create the controller object */
30 Status = CreateHCDController(&HcdController);
31 if (!NT_SUCCESS(Status))
32 {
33 /* failed to create hcd */
34 DPRINT1("AddDevice: Failed to create hcd with %x\n", Status);
35 return Status;
36 }
37
38 /* initialize the hcd */
39 Status = HcdController->Initialize(NULL, // FIXME
40 DriverObject,
41 PhysicalDeviceObject);
42
43 /* check for success */
44 if (!NT_SUCCESS(Status))
45 {
46 /* failed to initialize device */
47 DPRINT1("AddDevice: failed to initialize\n");
48
49 /* release object */
50 HcdController->Release();
51 }
52
53 return Status;
54
55 }
56
57 NTSTATUS
58 NTAPI
59 EHCI_Dispatch(
60 PDEVICE_OBJECT DeviceObject,
61 PIRP Irp)
62 {
63 PCOMMON_DEVICE_EXTENSION DeviceExtension;
64 PIO_STACK_LOCATION IoStack;
65 NTSTATUS Status;
66
67 //
68 // get common device extension
69 //
70 DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
71
72 //
73 // get current stack location
74 //
75 IoStack = IoGetCurrentIrpStackLocation(Irp);
76
77 //
78 // sanity checks
79 //
80 PC_ASSERT(DeviceExtension->Dispatcher);
81
82 switch(IoStack->MajorFunction)
83 {
84 case IRP_MJ_PNP:
85 {
86 //
87 // dispatch pnp
88 //
89 return DeviceExtension->Dispatcher->HandlePnp(DeviceObject, Irp);
90 }
91
92 case IRP_MJ_POWER:
93 {
94 //
95 // dispatch pnp
96 //
97 return DeviceExtension->Dispatcher->HandlePower(DeviceObject, Irp);
98 }
99 case IRP_MJ_INTERNAL_DEVICE_CONTROL:
100 case IRP_MJ_DEVICE_CONTROL:
101 {
102 //
103 // dispatch pnp
104 //
105 return DeviceExtension->Dispatcher->HandleDeviceControl(DeviceObject, Irp);
106 }
107 default:
108 {
109 DPRINT1("EHCI_Dispatch> Major %lu Minor %lu unhandeled\n", IoStack->MajorFunction, IoStack->MinorFunction);
110 Status = STATUS_SUCCESS;
111 }
112 }
113
114 //
115 // complete request
116 //
117 Irp->IoStatus.Information = 0;
118 Irp->IoStatus.Status = Status;
119 IoCompleteRequest(Irp, IO_NO_INCREMENT);
120
121 return Status;
122 }
123
124 extern
125 "C"
126 NTSTATUS
127 NTAPI
128 DriverEntry(
129 PDRIVER_OBJECT DriverObject,
130 PUNICODE_STRING RegistryPath)
131 {
132
133 /* initialize driver object*/
134 DriverObject->DriverExtension->AddDevice = EHCI_AddDevice;
135
136 DriverObject->MajorFunction[IRP_MJ_CREATE] = EHCI_Dispatch;
137 DriverObject->MajorFunction[IRP_MJ_CLOSE] = EHCI_Dispatch;
138 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = EHCI_Dispatch;
139 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = EHCI_Dispatch;
140 DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = EHCI_Dispatch;
141 DriverObject->MajorFunction[IRP_MJ_PNP] = EHCI_Dispatch;
142
143 return STATUS_SUCCESS;
144 }