6338c48d121c7c6fe3dffe203669942f017cefbe
[reactos.git] / drivers / storage / port / storport / fdo.c
1 /*
2 * PROJECT: ReactOS Storport Driver
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Storport FDO code
5 * COPYRIGHT: Copyright 2017 Eric Kohl (eric.kohl@reactos.org)
6 */
7
8 /* INCLUDES *******************************************************************/
9
10 #include "precomp.h"
11
12 #define NDEBUG
13 #include <debug.h>
14
15
16 /* FUNCTIONS ******************************************************************/
17
18 static
19 NTSTATUS
20 PortFdoStartMiniport(
21 _In_ PFDO_DEVICE_EXTENSION DeviceExtension)
22 {
23 PHW_INITIALIZATION_DATA InitData;
24 INTERFACE_TYPE InterfaceType;
25 NTSTATUS Status;
26
27 DPRINT1("PortFdoStartDevice(%p)\n", DeviceExtension);
28
29 /* Get the interface type of the lower device */
30 InterfaceType = GetBusInterface(DeviceExtension->LowerDevice);
31 if (InterfaceType == InterfaceTypeUndefined)
32 return STATUS_NO_SUCH_DEVICE;
33
34 /* Get the driver init data for the given interface type */
35 InitData = PortGetDriverInitData(DeviceExtension->DriverExtension,
36 InterfaceType);
37 if (InitData == NULL)
38 return STATUS_NO_SUCH_DEVICE;
39
40 /* Initialize the miniport */
41 Status = MiniportInitialize(&DeviceExtension->Miniport,
42 DeviceExtension,
43 InitData);
44 if (!NT_SUCCESS(Status))
45 {
46 DPRINT1("MiniportInitialize() failed (Status 0x%08lx)\n", Status);
47 return Status;
48 }
49
50 /* Call the miniports FindAdapter function */
51 Status = MiniportFindAdapter(&DeviceExtension->Miniport);
52 if (!NT_SUCCESS(Status))
53 {
54 DPRINT1("MiniportFindAdapter() failed (Status 0x%08lx)\n", Status);
55 return Status;
56 }
57
58 /* Call the miniports HwInitialize function */
59 Status = MiniportHwInitialize(&DeviceExtension->Miniport);
60 if (!NT_SUCCESS(Status))
61 {
62 DPRINT1("MiniportHwInitialize() failed (Status 0x%08lx)\n", Status);
63 return Status;
64 }
65
66 return STATUS_SUCCESS;
67 }
68
69
70 static
71 NTSTATUS
72 NTAPI
73 PortFdoStartDevice(
74 _In_ PFDO_DEVICE_EXTENSION DeviceExtension,
75 _In_ PIRP Irp)
76 {
77 NTSTATUS Status;
78
79 DPRINT1("PortFdoStartDevice(%p %p)\n",
80 DeviceExtension, Irp);
81
82 ASSERT(DeviceExtension->ExtensionType == FdoExtension);
83
84 /* Start the lower device if the FDO is in 'stopped' state */
85 if (DeviceExtension->PnpState == dsStopped)
86 {
87 Status = ForwardIrpAndWait(DeviceExtension->LowerDevice, Irp);
88 if (!NT_SUCCESS(Status))
89 {
90 DPRINT1("ForwardIrpAndWait() failed (Status 0x%08lx)\n", Status);
91 return Status;
92 }
93 }
94
95 /* Change to the 'started' state */
96 DeviceExtension->PnpState = dsStarted;
97
98 /* Start the miniport (FindAdapter & Initialize) */
99 Status = PortFdoStartMiniport(DeviceExtension);
100 if (!NT_SUCCESS(Status))
101 {
102 DPRINT1("FdoStartMiniport() failed (Status 0x%08lx)\n", Status);
103 DeviceExtension->PnpState = dsStopped;
104 }
105
106 return Status;
107 }
108
109
110 static
111 NTSTATUS
112 PortFdoQueryBusRelations(
113 _In_ PFDO_DEVICE_EXTENSION DeviceExtension,
114 _Out_ PULONG_PTR Information)
115 {
116 NTSTATUS Status = STATUS_SUCCESS;;
117
118 DPRINT1("PortFdoQueryBusRelations(%p %p)\n",
119 DeviceExtension, Information);
120
121 *Information = 0;
122
123 return Status;
124 }
125
126
127 NTSTATUS
128 NTAPI
129 PortFdoPnp(
130 _In_ PDEVICE_OBJECT DeviceObject,
131 _In_ PIRP Irp)
132 {
133 PFDO_DEVICE_EXTENSION DeviceExtension;
134 PIO_STACK_LOCATION Stack;
135 ULONG_PTR Information = 0;
136 NTSTATUS Status = STATUS_NOT_SUPPORTED;
137
138 DPRINT1("PortFdoPnp(%p %p)\n",
139 DeviceObject, Irp);
140
141 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
142 ASSERT(DeviceExtension);
143 ASSERT(DeviceExtension->ExtensionType == FdoExtension);
144
145 Stack = IoGetCurrentIrpStackLocation(Irp);
146
147 switch (Stack->MinorFunction)
148 {
149 case IRP_MN_START_DEVICE: /* 0x00 */
150 DPRINT1("IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
151 Status = PortFdoStartDevice(DeviceExtension, Irp);
152 break;
153
154 case IRP_MN_QUERY_REMOVE_DEVICE: /* 0x01 */
155 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_REMOVE_DEVICE\n");
156 break;
157
158 case IRP_MN_REMOVE_DEVICE: /* 0x02 */
159 DPRINT1("IRP_MJ_PNP / IRP_MN_REMOVE_DEVICE\n");
160 break;
161
162 case IRP_MN_CANCEL_REMOVE_DEVICE: /* 0x03 */
163 DPRINT1("IRP_MJ_PNP / IRP_MN_CANCEL_REMOVE_DEVICE\n");
164 break;
165
166 case IRP_MN_STOP_DEVICE: /* 0x04 */
167 DPRINT1("IRP_MJ_PNP / IRP_MN_STOP_DEVICE\n");
168 break;
169
170 case IRP_MN_QUERY_STOP_DEVICE: /* 0x05 */
171 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_STOP_DEVICE\n");
172 break;
173
174 case IRP_MN_CANCEL_STOP_DEVICE: /* 0x06 */
175 DPRINT1("IRP_MJ_PNP / IRP_MN_CANCEL_STOP_DEVICE\n");
176 break;
177
178 case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x07 */
179 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS\n");
180 switch (Stack->Parameters.QueryDeviceRelations.Type)
181 {
182 case BusRelations:
183 DPRINT1(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
184 Status = PortFdoQueryBusRelations(DeviceExtension, &Information);
185 break;
186
187 case RemovalRelations:
188 DPRINT1(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations\n");
189 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
190
191 default:
192 DPRINT1(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
193 Stack->Parameters.QueryDeviceRelations.Type);
194 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
195 }
196 break;
197
198 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* 0x0d */
199 DPRINT1("IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
200 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
201
202 case IRP_MN_QUERY_PNP_DEVICE_STATE: /* 0x14 */
203 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_PNP_DEVICE_STATE\n");
204 break;
205
206 case IRP_MN_DEVICE_USAGE_NOTIFICATION: /* 0x16 */
207 DPRINT1("IRP_MJ_PNP / IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
208 break;
209
210 case IRP_MN_SURPRISE_REMOVAL: /* 0x17 */
211 DPRINT1("IRP_MJ_PNP / IRP_MN_SURPRISE_REMOVAL\n");
212 break;
213
214 default:
215 DPRINT1("IRP_MJ_PNP / Unknown IOCTL 0x%lx\n", Stack->MinorFunction);
216 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
217 }
218
219 Irp->IoStatus.Information = Information;
220 Irp->IoStatus.Status = Status;
221 IoCompleteRequest(Irp, IO_NO_INCREMENT);
222
223 return Status;
224 }
225
226 /* EOF */