[STORPORT] Initialize the port configuration and pass it to the HwFindAdapter routine.
[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 static
128 NTSTATUS
129 PortFdoFilterRequirements(
130 PFDO_DEVICE_EXTENSION DeviceExtension,
131 PIRP Irp)
132 {
133 PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList;
134
135 DPRINT1("PortFdoFilterRequirements(%p %p)\n", DeviceExtension, Irp);
136
137 /* Get the bus number and the slot number */
138 RequirementsList =(PIO_RESOURCE_REQUIREMENTS_LIST)Irp->IoStatus.Information;
139 if (RequirementsList != NULL)
140 {
141 DeviceExtension->BusNumber = RequirementsList->BusNumber;
142 DeviceExtension->SlotNumber = RequirementsList->SlotNumber;
143 }
144
145 return STATUS_SUCCESS;
146 }
147
148
149 NTSTATUS
150 NTAPI
151 PortFdoPnp(
152 _In_ PDEVICE_OBJECT DeviceObject,
153 _In_ PIRP Irp)
154 {
155 PFDO_DEVICE_EXTENSION DeviceExtension;
156 PIO_STACK_LOCATION Stack;
157 ULONG_PTR Information = 0;
158 NTSTATUS Status = STATUS_NOT_SUPPORTED;
159
160 DPRINT1("PortFdoPnp(%p %p)\n",
161 DeviceObject, Irp);
162
163 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
164 ASSERT(DeviceExtension);
165 ASSERT(DeviceExtension->ExtensionType == FdoExtension);
166
167 Stack = IoGetCurrentIrpStackLocation(Irp);
168
169 switch (Stack->MinorFunction)
170 {
171 case IRP_MN_START_DEVICE: /* 0x00 */
172 DPRINT1("IRP_MJ_PNP / IRP_MN_START_DEVICE\n");
173 Status = PortFdoStartDevice(DeviceExtension, Irp);
174 break;
175
176 case IRP_MN_QUERY_REMOVE_DEVICE: /* 0x01 */
177 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_REMOVE_DEVICE\n");
178 break;
179
180 case IRP_MN_REMOVE_DEVICE: /* 0x02 */
181 DPRINT1("IRP_MJ_PNP / IRP_MN_REMOVE_DEVICE\n");
182 break;
183
184 case IRP_MN_CANCEL_REMOVE_DEVICE: /* 0x03 */
185 DPRINT1("IRP_MJ_PNP / IRP_MN_CANCEL_REMOVE_DEVICE\n");
186 break;
187
188 case IRP_MN_STOP_DEVICE: /* 0x04 */
189 DPRINT1("IRP_MJ_PNP / IRP_MN_STOP_DEVICE\n");
190 break;
191
192 case IRP_MN_QUERY_STOP_DEVICE: /* 0x05 */
193 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_STOP_DEVICE\n");
194 break;
195
196 case IRP_MN_CANCEL_STOP_DEVICE: /* 0x06 */
197 DPRINT1("IRP_MJ_PNP / IRP_MN_CANCEL_STOP_DEVICE\n");
198 break;
199
200 case IRP_MN_QUERY_DEVICE_RELATIONS: /* 0x07 */
201 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS\n");
202 switch (Stack->Parameters.QueryDeviceRelations.Type)
203 {
204 case BusRelations:
205 DPRINT1(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations\n");
206 Status = PortFdoQueryBusRelations(DeviceExtension, &Information);
207 break;
208
209 case RemovalRelations:
210 DPRINT1(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / RemovalRelations\n");
211 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
212
213 default:
214 DPRINT1(" IRP_MJ_PNP / IRP_MN_QUERY_DEVICE_RELATIONS / Unknown type 0x%lx\n",
215 Stack->Parameters.QueryDeviceRelations.Type);
216 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
217 }
218 break;
219
220 case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: /* 0x0d */
221 DPRINT1("IRP_MJ_PNP / IRP_MN_FILTER_RESOURCE_REQUIREMENTS\n");
222 PortFdoFilterRequirements(DeviceExtension, Irp);
223 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
224
225 case IRP_MN_QUERY_PNP_DEVICE_STATE: /* 0x14 */
226 DPRINT1("IRP_MJ_PNP / IRP_MN_QUERY_PNP_DEVICE_STATE\n");
227 break;
228
229 case IRP_MN_DEVICE_USAGE_NOTIFICATION: /* 0x16 */
230 DPRINT1("IRP_MJ_PNP / IRP_MN_DEVICE_USAGE_NOTIFICATION\n");
231 break;
232
233 case IRP_MN_SURPRISE_REMOVAL: /* 0x17 */
234 DPRINT1("IRP_MJ_PNP / IRP_MN_SURPRISE_REMOVAL\n");
235 break;
236
237 default:
238 DPRINT1("IRP_MJ_PNP / Unknown IOCTL 0x%lx\n", Stack->MinorFunction);
239 return ForwardIrpAndForget(DeviceExtension->LowerDevice, Irp);
240 }
241
242 Irp->IoStatus.Information = Information;
243 Irp->IoStatus.Status = Status;
244 IoCompleteRequest(Irp, IO_NO_INCREMENT);
245
246 return Status;
247 }
248
249 /* EOF */