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 
33 typedef enum
34 {
35     dsStopped,
36     dsStarted,
37     dsPaused,
38     dsRemoved,
39     dsSurpriseRemoved
40 } DEVICE_STATE;
41 
42 typedef enum
43 {
44     InvalidExtension = 0,
45     DriverExtension,
46     FdoExtension,
47     PdoExtension
48 } EXTENSION_TYPE;
49 
50 typedef struct _DRIVER_INIT_DATA
51 {
52     LIST_ENTRY Entry;
53     HW_INITIALIZATION_DATA HwInitData;
54 } DRIVER_INIT_DATA, *PDRIVER_INIT_DATA;
55 
56 typedef struct _DRIVER_OBJECT_EXTENSION
57 {
58     EXTENSION_TYPE ExtensionType;
59     PDRIVER_OBJECT DriverObject;
60 
61     KSPIN_LOCK AdapterListLock;
62     LIST_ENTRY AdapterListHead;
63     ULONG AdapterCount;
64 
65     LIST_ENTRY InitDataListHead;
66 } DRIVER_OBJECT_EXTENSION, *PDRIVER_OBJECT_EXTENSION;
67 
68 typedef struct _MINIPORT_DEVICE_EXTENSION
69 {
70     struct _MINIPORT *Miniport;
71     UCHAR HwDeviceExtension[0];
72 } MINIPORT_DEVICE_EXTENSION, *PMINIPORT_DEVICE_EXTENSION;
73 
74 typedef struct _MINIPORT
75 {
76     struct _FDO_DEVICE_EXTENSION *DeviceExtension;
77     PHW_INITIALIZATION_DATA InitData;
78     PORT_CONFIGURATION_INFORMATION PortConfig;
79     PMINIPORT_DEVICE_EXTENSION MiniportExtension;
80 } MINIPORT, *PMINIPORT;
81 
82 typedef struct _FDO_DEVICE_EXTENSION
83 {
84     EXTENSION_TYPE ExtensionType;
85 
86     PDEVICE_OBJECT Device;
87     PDEVICE_OBJECT LowerDevice;
88     PDEVICE_OBJECT PhysicalDevice;
89     PDRIVER_OBJECT_EXTENSION DriverExtension;
90     DEVICE_STATE PnpState;
91     LIST_ENTRY AdapterListEntry;
92     MINIPORT Miniport;
93     ULONG BusNumber;
94     ULONG SlotNumber;
95     PCM_RESOURCE_LIST AllocatedResources;
96     PCM_RESOURCE_LIST TranslatedResources;
97     BUS_INTERFACE_STANDARD BusInterface;
98     BOOLEAN BusInitialized;
99     PMAPPED_ADDRESS MappedAddressList;
100     PVOID UncachedExtensionVirtualBase;
101     PHYSICAL_ADDRESS UncachedExtensionPhysicalBase;
102     ULONG UncachedExtensionSize;
103     PHW_PASSIVE_INITIALIZE_ROUTINE HwPassiveInitRoutine;
104     PKINTERRUPT Interrupt;
105     ULONG InterruptIrql;
106 } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
107 
108 
109 typedef struct _PDO_DEVICE_EXTENSION
110 {
111     EXTENSION_TYPE ExtensionType;
112 
113     PDEVICE_OBJECT AttachedFdo;
114 
115     DEVICE_STATE PnpState;
116 
117 } PDO_DEVICE_EXTENSION, *PPDO_DEVICE_EXTENSION;
118 
119 
120 /* fdo.c */
121 
122 NTSTATUS
123 NTAPI
124 PortFdoPnp(
125     _In_ PDEVICE_OBJECT DeviceObject,
126     _In_ PIRP Irp);
127 
128 
129 /* miniport.c */
130 
131 NTSTATUS
132 MiniportInitialize(
133     _In_ PMINIPORT Miniport,
134     _In_ PFDO_DEVICE_EXTENSION DeviceExtension,
135     _In_ PHW_INITIALIZATION_DATA HwInitializationData);
136 
137 NTSTATUS
138 MiniportFindAdapter(
139     _In_ PMINIPORT Miniport);
140 
141 NTSTATUS
142 MiniportHwInitialize(
143     _In_ PMINIPORT Miniport);
144 
145 BOOLEAN
146 MiniportHwInterrupt(
147     _In_ PMINIPORT Miniport);
148 
149 /* misc.c */
150 
151 NTSTATUS
152 ForwardIrpAndWait(
153     _In_ PDEVICE_OBJECT LowerDevice,
154     _In_ PIRP Irp);
155 
156 NTSTATUS
157 NTAPI
158 ForwardIrpAndForget(
159     _In_ PDEVICE_OBJECT LowerDevice,
160     _In_ PIRP Irp);
161 
162 INTERFACE_TYPE
163 GetBusInterface(
164     PDEVICE_OBJECT DeviceObject);
165 
166 PCM_RESOURCE_LIST
167 CopyResourceList(
168     POOL_TYPE PoolType,
169     PCM_RESOURCE_LIST Source);
170 
171 NTSTATUS
172 QueryBusInterface(
173     PDEVICE_OBJECT DeviceObject,
174     PGUID Guid,
175     USHORT Size,
176     USHORT Version,
177     PBUS_INTERFACE_STANDARD Interface,
178     PVOID InterfaceSpecificData);
179 
180 BOOLEAN
181 TranslateResourceListAddress(
182     PFDO_DEVICE_EXTENSION DeviceExtension,
183     INTERFACE_TYPE BusType,
184     ULONG SystemIoBusNumber,
185     STOR_PHYSICAL_ADDRESS IoAddress,
186     ULONG NumberOfBytes,
187     BOOLEAN InIoSpace,
188     PPHYSICAL_ADDRESS TranslatedAddress);
189 
190 NTSTATUS
191 GetResourceListInterrupt(
192     PFDO_DEVICE_EXTENSION DeviceExtension,
193     PULONG Vector,
194     PKIRQL Irql,
195     KINTERRUPT_MODE *InterruptMode,
196     PBOOLEAN ShareVector,
197     PKAFFINITY Affinity);
198 
199 NTSTATUS
200 AllocateAddressMapping(
201     PMAPPED_ADDRESS *MappedAddressList,
202     STOR_PHYSICAL_ADDRESS IoAddress,
203     PVOID MappedAddress,
204     ULONG NumberOfBytes,
205     ULONG BusNumber);
206 
207 /* pdo.c */
208 
209 NTSTATUS
210 NTAPI
211 PortPdoPnp(
212     _In_ PDEVICE_OBJECT DeviceObject,
213     _In_ PIRP Irp);
214 
215 
216 /* storport.c */
217 
218 PHW_INITIALIZATION_DATA
219 PortGetDriverInitData(
220     PDRIVER_OBJECT_EXTENSION DriverExtension,
221     INTERFACE_TYPE InterfaceType);
222 
223 NTSTATUS
224 NTAPI
225 DriverEntry(
226     _In_ PDRIVER_OBJECT DriverObject,
227     _In_ PUNICODE_STRING RegistryPath);
228 
229 #endif /* _STORPORT_PCH_ */
230