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