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     ULONG UnitCount;
116     LIST_ENTRY UnitListHead;
117 } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
118 
119 
120 typedef struct _PDO_DEVICE_EXTENSION
121 {
122     EXTENSION_TYPE ExtensionType;
123 
124     PDEVICE_OBJECT AttachedFdo;
125 
126     DEVICE_STATE PnpState;
127 
128 } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
129 
130 
131 /* fdo.c */
132 
133 NTSTATUS
134 NTAPI
135 PortFdoScsi(
136     _In_ PDEVICE_OBJECT DeviceObject,
137     _In_ PIRP Irp);
138 
139 NTSTATUS
140 NTAPI
141 PortFdoPnp(
142     _In_ PDEVICE_OBJECT DeviceObject,
143     _In_ PIRP Irp);
144 
145 
146 /* miniport.c */
147 
148 NTSTATUS
149 MiniportInitialize(
150     _In_ PMINIPORT Miniport,
151     _In_ PFDO_DEVICE_EXTENSION DeviceExtension,
152     _In_ PHW_INITIALIZATION_DATA HwInitializationData);
153 
154 NTSTATUS
155 MiniportFindAdapter(
156     _In_ PMINIPORT Miniport);
157 
158 NTSTATUS
159 MiniportHwInitialize(
160     _In_ PMINIPORT Miniport);
161 
162 BOOLEAN
163 MiniportHwInterrupt(
164     _In_ PMINIPORT Miniport);
165 
166 BOOLEAN
167 MiniportStartIo(
168     _In_ PMINIPORT Miniport,
169     _In_ PSCSI_REQUEST_BLOCK Srb);
170 
171 /* misc.c */
172 
173 NTSTATUS
174 ForwardIrpAndWait(
175     _In_ PDEVICE_OBJECT LowerDevice,
176     _In_ PIRP Irp);
177 
178 NTSTATUS
179 NTAPI
180 ForwardIrpAndForget(
181     _In_ PDEVICE_OBJECT LowerDevice,
182     _In_ PIRP Irp);
183 
184 INTERFACE_TYPE
185 GetBusInterface(
186     PDEVICE_OBJECT DeviceObject);
187 
188 PCM_RESOURCE_LIST
189 CopyResourceList(
190     POOL_TYPE PoolType,
191     PCM_RESOURCE_LIST Source);
192 
193 NTSTATUS
194 QueryBusInterface(
195     PDEVICE_OBJECT DeviceObject,
196     PGUID Guid,
197     USHORT Size,
198     USHORT Version,
199     PBUS_INTERFACE_STANDARD Interface,
200     PVOID InterfaceSpecificData);
201 
202 BOOLEAN
203 TranslateResourceListAddress(
204     PFDO_DEVICE_EXTENSION DeviceExtension,
205     INTERFACE_TYPE BusType,
206     ULONG SystemIoBusNumber,
207     STOR_PHYSICAL_ADDRESS IoAddress,
208     ULONG NumberOfBytes,
209     BOOLEAN InIoSpace,
210     PPHYSICAL_ADDRESS TranslatedAddress);
211 
212 NTSTATUS
213 GetResourceListInterrupt(
214     PFDO_DEVICE_EXTENSION DeviceExtension,
215     PULONG Vector,
216     PKIRQL Irql,
217     KINTERRUPT_MODE *InterruptMode,
218     PBOOLEAN ShareVector,
219     PKAFFINITY Affinity);
220 
221 NTSTATUS
222 AllocateAddressMapping(
223     PMAPPED_ADDRESS *MappedAddressList,
224     STOR_PHYSICAL_ADDRESS IoAddress,
225     PVOID MappedAddress,
226     ULONG NumberOfBytes,
227     ULONG BusNumber);
228 
229 /* pdo.c */
230 
231 NTSTATUS
232 NTAPI
233 PortPdoScsi(
234     _In_ PDEVICE_OBJECT DeviceObject,
235     _In_ PIRP Irp);
236 
237 NTSTATUS
238 NTAPI
239 PortPdoPnp(
240     _In_ PDEVICE_OBJECT DeviceObject,
241     _In_ PIRP Irp);
242 
243 
244 /* storport.c */
245 
246 PHW_INITIALIZATION_DATA
247 PortGetDriverInitData(
248     PDRIVER_OBJECT_EXTENSION DriverExtension,
249     INTERFACE_TYPE InterfaceType);
250 
251 NTSTATUS
252 NTAPI
253 DriverEntry(
254     _In_ PDRIVER_OBJECT DriverObject,
255     _In_ PUNICODE_STRING RegistryPath);
256 
257 #endif /* _STORPORT_PCH_ */
258