[USBEHCI_NEW]
[reactos.git] / drivers / usb / usbehci_new / 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 DPRINT1("EHCI_Dispatch\n");
68
69 //
70 // get common device extension
71 //
72 DeviceExtension = (PCOMMON_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
73
74 //
75 // get current stack location
76 //
77 IoStack = IoGetCurrentIrpStackLocation(Irp);
78
79 //
80 // sanity checks
81 //
82 PC_ASSERT(DeviceExtension->HcdController);
83
84 //
85 // FIXME: support bus device
86 //
87 PC_ASSERT(DeviceExtension->IsHub == FALSE);
88
89 switch(IoStack->MajorFunction)
90 {
91 case IRP_MJ_PNP:
92 {
93 //
94 // dispatch pnp
95 //
96 return DeviceExtension->HcdController->HandlePnp(DeviceObject, Irp);
97 }
98
99 case IRP_MJ_POWER:
100 {
101 //
102 // dispatch pnp
103 //
104 return DeviceExtension->HcdController->HandlePower(DeviceObject, Irp);
105 }
106 case IRP_MJ_SYSTEM_CONTROL:
107 case IRP_MJ_DEVICE_CONTROL:
108 {
109 //
110 // dispatch pnp
111 //
112 return DeviceExtension->HcdController->HandleDeviceControl(DeviceObject, Irp);
113 }
114 case IRP_MJ_CREATE:
115 {
116 //
117 // dispatch create request
118 //
119 Status = STATUS_SUCCESS;
120
121 break;
122 }
123 default:
124 {
125 DPRINT1("EHCI_Dispatch> Major %lu Minor %lu not supported\n", IoStack->MajorFunction, IoStack->MinorFunction);
126 Status = STATUS_NOT_SUPPORTED;
127 }
128 }
129
130 //
131 // complete request
132 //
133 Irp->IoStatus.Information = 0;
134 Irp->IoStatus.Status = Status;
135 IoCompleteRequest(Irp, IO_NO_INCREMENT);
136
137
138 return Status;
139 }
140
141 extern
142 "C"
143 NTSTATUS
144 NTAPI
145 DriverEntry(
146 PDRIVER_OBJECT DriverObject,
147 PUNICODE_STRING RegistryPath)
148 {
149
150 /* initialize driver object*/
151 DriverObject->DriverExtension->AddDevice = EHCI_AddDevice;
152
153 DriverObject->MajorFunction[IRP_MJ_CREATE] = EHCI_Dispatch;
154 DriverObject->MajorFunction[IRP_MJ_CLOSE] = EHCI_Dispatch;
155 DriverObject->MajorFunction[IRP_MJ_CLEANUP] = EHCI_Dispatch;
156 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = EHCI_Dispatch;
157 DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = EHCI_Dispatch;
158 DriverObject->MajorFunction[IRP_MJ_PNP] = EHCI_Dispatch;
159
160 return STATUS_SUCCESS;
161 }