1 /*
2  * PROJECT:     ReactOS Storport Driver
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Storport driver common header file
5  * COPYRIGHT:   Copyright 2017 Eric Kohl (eric.kohl@reactos.org)
6  */
7 
8 #ifndef _STORPORT_PCH_
9 #define _STORPORT_PCH_
10 
11 #include <wdm.h>
12 #include <ntddk.h>
13 #include <stdio.h>
14 #include <memory.h>
15 
16 /* Declare STORPORT_API functions as exports rather than imports */
17 #define _STORPORT_
18 #include <storport.h>
19 
20 #include <ntddscsi.h>
21 #include <ntdddisk.h>
22 #include <mountdev.h>
23 #include <wdmguid.h>
24 
25 /* Memory Tags */
26 #define TAG_GLOBAL_DATA     'DGtS'
27 #define TAG_INIT_DATA       'DItS'
28 #define TAG_MINIPORT_DATA   'DMtS'
29 #define TAG_ACCRESS_RANGE   'RAtS'
30 #define TAG_RESOURCE_LIST   'LRtS'
31 #define TAG_ADDRESS_MAPPING 'MAtS'
32 #define TAG_INQUIRY_DATA    'QItS'
33 #define TAG_SENSE_DATA      'NStS'
34 
35 typedef enum
36 {
37     dsStopped,
38     dsStarted,
39     dsPaused,
40     dsRemoved,
41     dsSurpriseRemoved
42 } DEVICE_STATE;
43 
44 typedef enum
45 {
46     InvalidExtension = 0,
47     DriverExtension,
48     FdoExtension,
49     PdoExtension
50 } EXTENSION_TYPE;
51 
52 typedef struct _DRIVER_INIT_DATA
53 {
54     LIST_ENTRY Entry;
55     HW_INITIALIZATION_DATA HwInitData;
56 } DRIVER_INIT_DATA, *PDRIVER_INIT_DATA;
57 
58 typedef struct _DRIVER_OBJECT_EXTENSION
59 {
60     EXTENSION_TYPE ExtensionType;
61     PDRIVER_OBJECT DriverObject;
62 
63     KSPIN_LOCK AdapterListLock;
64     LIST_ENTRY AdapterListHead;
65     ULONG AdapterCount;
66 
67     LIST_ENTRY InitDataListHead;
68 } DRIVER_OBJECT_EXTENSION, *PDRIVER_OBJECT_EXTENSION;
69 
70 typedef struct _MINIPORT_DEVICE_EXTENSION
71 {
72     struct _MINIPORT *Miniport;
73     UCHAR HwDeviceExtension[0];
74 } MINIPORT_DEVICE_EXTENSION, *PMINIPORT_DEVICE_EXTENSION;
75 
76 typedef struct _MINIPORT
77 {
78     struct _FDO_DEVICE_EXTENSION *DeviceExtension;
79     PHW_INITIALIZATION_DATA InitData;
80     PORT_CONFIGURATION_INFORMATION PortConfig;
81     PMINIPORT_DEVICE_EXTENSION MiniportExtension;
82 } MINIPORT, *PMINIPORT;
83 
84 typedef struct _UNIT_DATA
85 {
86     LIST_ENTRY ListEntry;
87     INQUIRYDATA InquiryData;
88 } UNIT_DATA, *PUNIT_DATA;
89 
90 typedef struct _FDO_DEVICE_EXTENSION
91 {
92     EXTENSION_TYPE ExtensionType;
93 
94     PDEVICE_OBJECT Device;
95     PDEVICE_OBJECT LowerDevice;
96     PDEVICE_OBJECT PhysicalDevice;
97     PDRIVER_OBJECT_EXTENSION DriverExtension;
98     DEVICE_STATE PnpState;
99     LIST_ENTRY AdapterListEntry;
100     MINIPORT Miniport;
101     ULONG BusNumber;
102     ULONG SlotNumber;
103     PCM_RESOURCE_LIST AllocatedResources;
104     PCM_RESOURCE_LIST TranslatedResources;
105     BUS_INTERFACE_STANDARD BusInterface;
106     BOOLEAN BusInitialized;
107     PMAPPED_ADDRESS MappedAddressList;
108     PVOID UncachedExtensionVirtualBase;
109     PHYSICAL_ADDRESS UncachedExtensionPhysicalBase;
110     ULONG UncachedExtensionSize;
111     PHW_PASSIVE_INITIALIZE_ROUTINE HwPassiveInitRoutine;
112     PKINTERRUPT Interrupt;
113     ULONG InterruptIrql;
114 
115     KSPIN_LOCK PdoListLock;
116     LIST_ENTRY PdoListHead;
117     ULONG PdoCount;
118 } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
119 
120 
121 typedef struct _PDO_DEVICE_EXTENSION
122 {
123     EXTENSION_TYPE ExtensionType;
124 
125     PDEVICE_OBJECT Device;
126     PFDO_DEVICE_EXTENSION FdoExtension;
127     DEVICE_STATE PnpState;
128     LIST_ENTRY PdoListEntry;
129 
130     ULONG Bus;
131     ULONG Target;
132     ULONG Lun;
133     PINQUIRYDATA InquiryBuffer;
134 
135 
136 } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
137 
138 
139 /* fdo.c */
140 
141 NTSTATUS
142 NTAPI
143 PortFdoScsi(
144     _In_ PDEVICE_OBJECT DeviceObject,
145     _In_ PIRP Irp);
146 
147 NTSTATUS
148 NTAPI
149 PortFdoPnp(
150     _In_ PDEVICE_OBJECT DeviceObject,
151     _In_ PIRP Irp);
152 
153 
154 /* miniport.c */
155 
156 NTSTATUS
157 MiniportInitialize(
158     _In_ PMINIPORT Miniport,
159     _In_ PFDO_DEVICE_EXTENSION DeviceExtension,
160     _In_ PHW_INITIALIZATION_DATA HwInitializationData);
161 
162 NTSTATUS
163 MiniportFindAdapter(
164     _In_ PMINIPORT Miniport);
165 
166 NTSTATUS
167 MiniportHwInitialize(
168     _In_ PMINIPORT Miniport);
169 
170 BOOLEAN
171 MiniportHwInterrupt(
172     _In_ PMINIPORT Miniport);
173 
174 BOOLEAN
175 MiniportStartIo(
176     _In_ PMINIPORT Miniport,
177     _In_ PSCSI_REQUEST_BLOCK Srb);
178 
179 /* misc.c */
180 
181 NTSTATUS
182 NTAPI
183 ForwardIrpAndForget(
184     _In_ PDEVICE_OBJECT LowerDevice,
185     _In_ PIRP Irp);
186 
187 INTERFACE_TYPE
188 GetBusInterface(
189     PDEVICE_OBJECT DeviceObject);
190 
191 PCM_RESOURCE_LIST
192 CopyResourceList(
193     POOL_TYPE PoolType,
194     PCM_RESOURCE_LIST Source);
195 
196 NTSTATUS
197 QueryBusInterface(
198     PDEVICE_OBJECT DeviceObject,
199     PGUID Guid,
200     USHORT Size,
201     USHORT Version,
202     PBUS_INTERFACE_STANDARD Interface,
203     PVOID InterfaceSpecificData);
204 
205 BOOLEAN
206 TranslateResourceListAddress(
207     PFDO_DEVICE_EXTENSION DeviceExtension,
208     INTERFACE_TYPE BusType,
209     ULONG SystemIoBusNumber,
210     STOR_PHYSICAL_ADDRESS IoAddress,
211     ULONG NumberOfBytes,
212     BOOLEAN InIoSpace,
213     PPHYSICAL_ADDRESS TranslatedAddress);
214 
215 NTSTATUS
216 GetResourceListInterrupt(
217     PFDO_DEVICE_EXTENSION DeviceExtension,
218     PULONG Vector,
219     PKIRQL Irql,
220     KINTERRUPT_MODE *InterruptMode,
221     PBOOLEAN ShareVector,
222     PKAFFINITY Affinity);
223 
224 NTSTATUS
225 AllocateAddressMapping(
226     PMAPPED_ADDRESS *MappedAddressList,
227     STOR_PHYSICAL_ADDRESS IoAddress,
228     PVOID MappedAddress,
229     ULONG NumberOfBytes,
230     ULONG BusNumber);
231 
232 /* pdo.c */
233 
234 NTSTATUS
235 PortCreatePdo(
236     _In_ PFDO_DEVICE_EXTENSION FdoExtension,
237     _In_ ULONG Bus,
238     _In_ ULONG Target,
239     _In_ ULONG Lun,
240     _Out_ PPDO_DEVICE_EXTENSION *PdoExtension);
241 
242 NTSTATUS
243 PortDeletePdo(
244     _In_ PPDO_DEVICE_EXTENSION PdoExtension);
245 
246 NTSTATUS
247 NTAPI
248 PortPdoScsi(
249     _In_ PDEVICE_OBJECT DeviceObject,
250     _In_ PIRP Irp);
251 
252 NTSTATUS
253 NTAPI
254 PortPdoPnp(
255     _In_ PDEVICE_OBJECT DeviceObject,
256     _In_ PIRP Irp);
257 
258 
259 /* storport.c */
260 
261 PHW_INITIALIZATION_DATA
262 PortGetDriverInitData(
263     PDRIVER_OBJECT_EXTENSION DriverExtension,
264     INTERFACE_TYPE InterfaceType);
265 
266 NTSTATUS
267 NTAPI
268 DriverEntry(
269     _In_ PDRIVER_OBJECT DriverObject,
270     _In_ PUNICODE_STRING RegistryPath);
271 
272 #endif /* _STORPORT_PCH_ */
273