[HEADERS]
[reactos.git] / reactos / include / ddk / strmini.h
1 #ifndef _STREAM_H
2 #define _STREAM_H
3
4 #include <ntddk.h>
5 #include <windef.h>
6 #include <ks.h>
7
8 /* Helper macro to enable gcc's extension. */
9 #ifndef __GNU_EXTENSION
10 #ifdef __GNUC__
11 #define __GNU_EXTENSION __extension__
12 #else
13 #define __GNU_EXTENSION
14 #endif
15 #endif
16
17 #define STREAMAPI __stdcall
18 #define STREAM_SYSTEM_TIME_MASK ((STREAM_SYSTEM_TIME)0x00000001FFFFFFFF)
19
20 typedef enum
21 {
22 DebugLevelFatal = 0,
23 DebugLevelError,
24 DebugLevelWarning,
25 DebugLevelInfo,
26 DebugLevelTrace,
27 DebugLevelVerbose,
28 DebugLevelMaximum
29 }STREAM_DEBUG_LEVEL;
30
31
32 #if DBG
33
34 #define DebugPrint(x) StreamClassDebugPrint x
35 #define DEBUG_BREAKPOINT() DbgBreakPoint()
36 #define DEBUG_ASSERT(exp) \
37 if ( !(exp) ) { \
38 StreamClassDebugAssert( __FILE__, __LINE__, #exp, exp); \
39 }
40 #else
41
42 #define DebugPrint(x)
43 #define DEBUG_BREAKPOINT()
44 #define DEBUG_ASSERT(exp)
45
46 #endif
47
48 typedef PHYSICAL_ADDRESS STREAM_PHYSICAL_ADDRESS, *PSTREAM_PHYSICAL_ADDRESS;
49 __GNU_EXTENSION typedef unsigned __int64 STREAM_SYSTEM_TIME, *PSTREAM_SYSTEM_TIME;
50 __GNU_EXTENSION typedef unsigned __int64 STREAM_TIMESTAMP, *PSTREAM_TIMESTAMP;
51
52 typedef enum
53 {
54 TIME_GET_STREAM_TIME,
55 TIME_READ_ONBOARD_CLOCK,
56 TIME_SET_ONBOARD_CLOCK
57 }TIME_FUNCTION;
58
59 typedef struct _HW_TIME_CONTEXT
60 {
61 struct _HW_DEVICE_EXTENSION *HwDeviceExtension;
62 struct _HW_STREAM_OBJECT *HwStreamObject;
63 TIME_FUNCTION Function;
64 ULONGLONG Time;
65 ULONGLONG SystemTime;
66 }HW_TIME_CONTEXT, *PHW_TIME_CONTEXT;
67
68 typedef struct _HW_EVENT_DESCRIPTOR
69 {
70 BOOLEAN Enable;
71 PKSEVENT_ENTRY EventEntry;
72 PKSEVENTDATA EventData;
73 __GNU_EXTENSION union
74 {
75 struct _HW_STREAM_OBJECT * StreamObject;
76 struct _HW_DEVICE_EXTENSION *DeviceExtension;
77 };
78 ULONG EnableEventSetIndex;
79 PVOID HwInstanceExtension;
80 ULONG Reserved;
81 } HW_EVENT_DESCRIPTOR, *PHW_EVENT_DESCRIPTOR;
82
83 struct _HW_STREAM_REQUEST_BLOCK;
84
85 typedef VOID (STREAMAPI * PHW_RECEIVE_STREAM_DATA_SRB) (IN struct _HW_STREAM_REQUEST_BLOCK * SRB);
86 typedef VOID (STREAMAPI * PHW_RECEIVE_STREAM_CONTROL_SRB) (IN struct _HW_STREAM_REQUEST_BLOCK * SRB);
87 typedef NTSTATUS (STREAMAPI * PHW_EVENT_ROUTINE) (IN PHW_EVENT_DESCRIPTOR EventDescriptor);
88 typedef VOID (STREAMAPI * PHW_CLOCK_FUNCTION) (IN PHW_TIME_CONTEXT HwTimeContext);
89
90 typedef struct _HW_CLOCK_OBJECT
91 {
92 PHW_CLOCK_FUNCTION HwClockFunction;
93 ULONG ClockSupportFlags;
94 ULONG Reserved[2];
95 } HW_CLOCK_OBJECT, *PHW_CLOCK_OBJECT;
96
97 #define CLOCK_SUPPORT_CAN_SET_ONBOARD_CLOCK 0x1
98 #define CLOCK_SUPPORT_CAN_READ_ONBOARD_CLOCK 0x2
99 #define CLOCK_SUPPORT_CAN_RETURN_STREAM_TIME 0x4
100
101 typedef struct _HW_STREAM_OBJECT
102 {
103 ULONG SizeOfThisPacket;
104 ULONG StreamNumber;
105 PVOID HwStreamExtension;
106 PHW_RECEIVE_STREAM_DATA_SRB ReceiveDataPacket;
107 PHW_RECEIVE_STREAM_CONTROL_SRB ReceiveControlPacket;
108 HW_CLOCK_OBJECT HwClockObject;
109 BOOLEAN Dma;
110 BOOLEAN Pio;
111 PVOID HwDeviceExtension;
112 ULONG StreamHeaderMediaSpecific;
113 ULONG StreamHeaderWorkspace;
114 BOOLEAN Allocator;
115 PHW_EVENT_ROUTINE HwEventRoutine;
116 ULONG Reserved[2];
117 } HW_STREAM_OBJECT, *PHW_STREAM_OBJECT;
118
119 typedef struct _HW_STREAM_HEADER
120 {
121 ULONG NumberOfStreams;
122 ULONG SizeOfHwStreamInformation;
123 ULONG NumDevPropArrayEntries;
124 PKSPROPERTY_SET DevicePropertiesArray;
125 ULONG NumDevEventArrayEntries;
126 PKSEVENT_SET DeviceEventsArray;
127 PKSTOPOLOGY Topology;
128 PHW_EVENT_ROUTINE DeviceEventRoutine;
129 LONG NumDevMethodArrayEntries;
130 PKSMETHOD_SET DeviceMethodsArray;
131 }HW_STREAM_HEADER, *PHW_STREAM_HEADER;
132
133 typedef struct _HW_STREAM_INFORMATION
134 {
135 ULONG NumberOfPossibleInstances;
136 KSPIN_DATAFLOW DataFlow;
137 BOOLEAN DataAccessible;
138 ULONG NumberOfFormatArrayEntries;
139 PKSDATAFORMAT* StreamFormatsArray;
140 PVOID ClassReserved[4];
141 ULONG NumStreamPropArrayEntries;
142 PKSPROPERTY_SET StreamPropertiesArray;
143 ULONG NumStreamEventArrayEntries;
144 PKSEVENT_SET StreamEventsArray;
145 GUID* Category;
146 GUID* Name;
147 ULONG MediumsCount;
148 const KSPIN_MEDIUM* Mediums;
149 BOOLEAN BridgeStream;
150 ULONG Reserved[2];
151 }HW_STREAM_INFORMATION, *PHW_STREAM_INFORMATION;
152
153
154 typedef struct _HW_STREAM_DESCRIPTOR
155 {
156 HW_STREAM_HEADER StreamHeader;
157 HW_STREAM_INFORMATION StreamInfo;
158 } HW_STREAM_DESCRIPTOR, *PHW_STREAM_DESCRIPTOR;
159
160 typedef struct _STREAM_TIME_REFERENCE
161 {
162 STREAM_TIMESTAMP CurrentOnboardClockValue;
163 LARGE_INTEGER OnboardClockFrequency;
164 LARGE_INTEGER CurrentSystemTime;
165 ULONG Reserved[2];
166 }STREAM_TIME_REFERENCE, *PSTREAM_TIME_REFERENCE;
167
168 typedef struct _STREAM_DATA_INTERSECT_INFO
169 {
170 ULONG StreamNumber;
171 PKSDATARANGE DataRange;
172 PVOID DataFormatBuffer;
173 ULONG SizeOfDataFormatBuffer;
174
175 }STREAM_DATA_INTERSECT_INFO, *PSTREAM_DATA_INTERSECT_INFO;
176
177 typedef struct _STREAM_PROPERTY_DESCRIPTOR
178 {
179 PKSPROPERTY Property;
180 ULONG PropertySetID;
181 PVOID PropertyInfo;
182 ULONG PropertyInputSize;
183 ULONG PropertyOutputSize;
184 }STREAM_PROPERTY_DESCRIPTOR, *PSTREAM_PROPERTY_DESCRIPTOR;
185
186 typedef struct _STREAM_METHOD_DESCRIPTOR
187 {
188 ULONG MethodSetID;
189 PKSMETHOD Method;
190 PVOID MethodInfo;
191 LONG MethodInputSize;
192 LONG MethodOutputSize;
193 } STREAM_METHOD_DESCRIPTOR, *PSTREAM_METHOD_DESCRIPTOR;
194
195 #define STREAM_REQUEST_BLOCK_SIZE sizeof(STREAM_REQUEST_BLOCK)
196
197 typedef enum _SRB_COMMAND
198 {
199 SRB_READ_DATA,
200 SRB_WRITE_DATA,
201 SRB_GET_STREAM_STATE,
202 SRB_SET_STREAM_STATE,
203 SRB_SET_STREAM_PROPERTY,
204 SRB_GET_STREAM_PROPERTY,
205 SRB_OPEN_MASTER_CLOCK,
206
207 SRB_INDICATE_MASTER_CLOCK,
208 SRB_UNKNOWN_STREAM_COMMAND,
209 SRB_SET_STREAM_RATE,
210 SRB_PROPOSE_DATA_FORMAT,
211 SRB_CLOSE_MASTER_CLOCK,
212 SRB_PROPOSE_STREAM_RATE,
213 SRB_SET_DATA_FORMAT,
214 SRB_GET_DATA_FORMAT,
215 SRB_BEGIN_FLUSH,
216 SRB_END_FLUSH,
217
218 SRB_GET_STREAM_INFO = 0x100,
219 SRB_OPEN_STREAM,
220 SRB_CLOSE_STREAM,
221 SRB_OPEN_DEVICE_INSTANCE,
222 SRB_CLOSE_DEVICE_INSTANCE,
223 SRB_GET_DEVICE_PROPERTY,
224 SRB_SET_DEVICE_PROPERTY,
225 SRB_INITIALIZE_DEVICE,
226 SRB_CHANGE_POWER_STATE,
227 SRB_UNINITIALIZE_DEVICE,
228 SRB_UNKNOWN_DEVICE_COMMAND,
229 SRB_PAGING_OUT_DRIVER,
230 SRB_GET_DATA_INTERSECTION,
231 SRB_INITIALIZATION_COMPLETE,
232 SRB_SURPRISE_REMOVAL
233
234 #if (NTDDI_VERSION >= NTDDI_WINXP)
235
236 ,SRB_DEVICE_METHOD
237 ,SRB_STREAM_METHOD
238
239 #if ( (NTDDI_VERSION >= NTDDI_WINXPSP2) && (NTDDI_VERSION < NTDDI_WS03) ) || (NTDDI_VERSION >= NTDDI_WS03SP1)
240
241 ,SRB_NOTIFY_IDLE_STATE
242
243 #endif
244
245 #endif
246
247 }SRB_COMMAND;
248
249 typedef struct
250 {
251 PHYSICAL_ADDRESS PhysicalAddress;
252 ULONG Length;
253 } KSSCATTER_GATHER, *PKSSCATTER_GATHER;
254
255
256 typedef struct _HW_STREAM_REQUEST_BLOCK
257 {
258 ULONG SizeOfThisPacket;
259 SRB_COMMAND Command;
260 NTSTATUS Status;
261 PHW_STREAM_OBJECT StreamObject;
262 PVOID HwDeviceExtension;
263 PVOID SRBExtension;
264
265 union _CommandData
266 {
267 PKSSTREAM_HEADER DataBufferArray;
268 PHW_STREAM_DESCRIPTOR StreamBuffer;
269 KSSTATE StreamState;
270 PSTREAM_TIME_REFERENCE TimeReference;
271 PSTREAM_PROPERTY_DESCRIPTOR PropertyInfo;
272 PKSDATAFORMAT OpenFormat;
273 struct _PORT_CONFIGURATION_INFORMATION *ConfigInfo;
274 HANDLE MasterClockHandle;
275 DEVICE_POWER_STATE DeviceState;
276 PSTREAM_DATA_INTERSECT_INFO IntersectInfo;
277
278 #if (NTDDI_VERSION >= NTDDI_WINXP)
279 PVOID MethodInfo;
280 LONG FilterTypeIndex;
281 #if ( (NTDDI_VERSION >= NTDDI_WINXPSP2) && (NTDDI_VERSION < NTDDI_WS03) ) || (NTDDI_VERSION >= NTDDI_WS03SP1)
282 BOOLEAN Idle;
283 #endif
284 #endif
285
286 }CommandData;
287
288 ULONG NumberOfBuffers;
289 ULONG TimeoutCounter;
290 ULONG TimeoutOriginal;
291 struct _HW_STREAM_REQUEST_BLOCK *NextSRB;
292
293 PIRP Irp;
294 ULONG Flags;
295 PVOID HwInstanceExtension;
296
297 __GNU_EXTENSION union
298 {
299 ULONG NumberOfBytesToTransfer;
300 ULONG ActualBytesTransferred;
301 };
302
303 PKSSCATTER_GATHER ScatterGatherBuffer;
304 ULONG NumberOfPhysicalPages;
305 ULONG NumberOfScatterGatherElements;
306 ULONG Reserved[1];
307
308 }HW_STREAM_REQUEST_BLOCK, *PHW_STREAM_REQUEST_BLOCK;
309
310 #define SRB_HW_FLAGS_DATA_TRANSFER 0x01
311 #define SRB_HW_FLAGS_STREAM_REQUEST 0x2
312
313 typedef enum
314 {
315 PerRequestExtension,
316 DmaBuffer,
317 SRBDataBuffer
318 }STREAM_BUFFER_TYPE;
319
320 typedef struct _ACCESS_RANGE
321 {
322 STREAM_PHYSICAL_ADDRESS RangeStart;
323 ULONG RangeLength;
324 BOOLEAN RangeInMemory;
325 ULONG Reserved;
326 }ACCESS_RANGE, *PACCESS_RANGE;
327
328 typedef struct _PORT_CONFIGURATION_INFORMATION
329 {
330 ULONG SizeOfThisPacket;
331 PVOID HwDeviceExtension;
332 PDEVICE_OBJECT ClassDeviceObject;
333 PDEVICE_OBJECT PhysicalDeviceObject;
334 ULONG SystemIoBusNumber;
335 INTERFACE_TYPE AdapterInterfaceType;
336 ULONG BusInterruptLevel;
337 ULONG BusInterruptVector;
338 KINTERRUPT_MODE InterruptMode;
339 ULONG DmaChannel;
340 ULONG NumberOfAccessRanges;
341 PACCESS_RANGE AccessRanges;
342 ULONG StreamDescriptorSize;
343 PIRP Irp;
344 PKINTERRUPT InterruptObject;
345 PADAPTER_OBJECT DmaAdapterObject;
346 PDEVICE_OBJECT RealPhysicalDeviceObject;
347 ULONG Reserved[1];
348 }PORT_CONFIGURATION_INFORMATION, *PPORT_CONFIGURATION_INFORMATION;
349
350 typedef VOID (STREAMAPI * PHW_RECEIVE_DEVICE_SRB) (IN PHW_STREAM_REQUEST_BLOCK SRB);
351 typedef VOID (STREAMAPI * PHW_CANCEL_SRB) (IN PHW_STREAM_REQUEST_BLOCK SRB);
352 typedef VOID (STREAMAPI * PHW_REQUEST_TIMEOUT_HANDLER) (IN PHW_STREAM_REQUEST_BLOCK SRB);
353 typedef BOOLEAN (STREAMAPI * PHW_INTERRUPT) (IN PVOID DeviceExtension);
354 typedef VOID (STREAMAPI * PHW_TIMER_ROUTINE) (IN PVOID Context);
355 typedef VOID (STREAMAPI * PHW_PRIORITY_ROUTINE) (IN PVOID Context);
356 typedef VOID (STREAMAPI * PHW_QUERY_CLOCK_ROUTINE) (IN PHW_TIME_CONTEXT TimeContext);
357 typedef BOOLEAN (STREAMAPI * PHW_RESET_ADAPTER) (IN PVOID DeviceExtension);
358
359 typedef enum _STREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE
360 {
361 ReadyForNextStreamDataRequest,
362 ReadyForNextStreamControlRequest,
363 HardwareStarved,
364 StreamRequestComplete,
365 SignalMultipleStreamEvents,
366 SignalStreamEvent,
367 DeleteStreamEvent,
368 StreamNotificationMaximum
369 }STREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE, *PSTREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE;
370
371 typedef enum _STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE
372 {
373 ReadyForNextDeviceRequest,
374 DeviceRequestComplete,
375 SignalMultipleDeviceEvents,
376 SignalDeviceEvent,
377 DeleteDeviceEvent,
378 #if (NTDDI_VERSION >= NTDDI_WINXP)
379 SignalMultipleDeviceInstanceEvents,
380 #endif
381 DeviceNotificationMaximum
382 } STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE, *PSTREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE;
383
384 #define STREAM_CLASS_VERSION_20 0x0200
385
386 typedef struct _HW_INITIALIZATION_DATA {
387 #if (NTDDI_VERSION >= NTDDI_WINXP)
388 __GNU_EXTENSION union
389 {
390 ULONG HwInitializationDataSize;
391 __GNU_EXTENSION struct
392 {
393 USHORT SizeOfThisPacket;
394 USHORT StreamClassVersion;
395 };
396 };
397 #else
398 ULONG HwInitializationDataSize;
399 #endif
400
401 PHW_INTERRUPT HwInterrupt;
402 PHW_RECEIVE_DEVICE_SRB HwReceivePacket;
403 PHW_CANCEL_SRB HwCancelPacket;
404 PHW_REQUEST_TIMEOUT_HANDLER HwRequestTimeoutHandler;
405 ULONG DeviceExtensionSize;
406 ULONG PerRequestExtensionSize;
407 ULONG PerStreamExtensionSize;
408 ULONG FilterInstanceExtensionSize;
409 BOOLEAN BusMasterDMA;
410 BOOLEAN Dma24BitAddresses;
411 ULONG BufferAlignment;
412 BOOLEAN TurnOffSynchronization;
413 ULONG DmaBufferSize;
414
415 #if (NTDDI_VERSION >= NTDDI_WINXP)
416 ULONG NumNameExtensions;
417 PWCHAR *NameExtensionArray;
418 #else
419 ULONG Reserved[2];
420 #endif
421 } HW_INITIALIZATION_DATA, *PHW_INITIALIZATION_DATA;
422
423 typedef enum _STREAM_PRIORITY
424 {
425 High,
426 Dispatch,
427 Low,
428 LowToHigh
429 }STREAM_PRIORITY, *PSTREAM_PRIORITY;
430
431
432 VOID
433 StreamClassAbortOutstandingRequests(
434 IN PVOID HwDeviceExtension,
435 IN PHW_STREAM_OBJECT HwStreamObject,
436 IN NTSTATUS Status
437 );
438
439 VOID
440 STREAMAPI
441 StreamClassCallAtNewPriority(
442 IN PHW_STREAM_OBJECT StreamObject,
443 IN PVOID HwDeviceExtension,
444 IN STREAM_PRIORITY Priority,
445 IN PHW_PRIORITY_ROUTINE PriorityRoutine,
446 IN PVOID Context
447 );
448
449 VOID
450 STREAMAPI
451 StreamClassCompleteRequestAndMarkQueueReady(
452 IN PHW_STREAM_REQUEST_BLOCK Srb
453 );
454
455 VOID
456 STREAMAPI
457 StreamClassDebugAssert(
458 IN PCHAR File,
459 IN ULONG Line,
460 IN PCHAR AssertText,
461 IN ULONG AssertValue
462 );
463
464 VOID
465 __cdecl
466 StreamClassDebugPrint(
467 IN STREAM_DEBUG_LEVEL DebugPrintLevel,
468 IN PCCHAR DebugMessage,
469 ...
470 );
471
472 VOID
473 __cdecl
474 StreamClassDeviceNotification(
475 IN STREAM_MINIDRIVER_DEVICE_NOTIFICATION_TYPE NotificationType,
476 IN PVOID HwDeviceExtension,
477 IN PHW_STREAM_REQUEST_BLOCK pSrb,
478 IN PKSEVENT_ENTRY EventEntry,
479 IN GUID *EventSet,
480 IN ULONG EventId
481 );
482
483 VOID
484 STREAMAPI
485 StreamClassFilterReenumerateStreams(
486 IN PVOID HwInstanceExtension,
487 IN ULONG StreamDescriptorSize
488 );
489
490 PVOID
491 STREAMAPI
492 StreamClassGetDmaBuffer(
493 IN PVOID HwDeviceExtension
494 );
495
496
497 PKSEVENT_ENTRY
498 StreamClassGetNextEvent(
499 IN PVOID HwInstanceExtension_OR_HwDeviceExtension,
500 IN PHW_STREAM_OBJECT HwStreamObject,
501 IN GUID * EventGuid,
502 IN ULONG EventItem,
503 IN PKSEVENT_ENTRY CurrentEvent
504 );
505
506 STREAM_PHYSICAL_ADDRESS
507 STREAMAPI
508 StreamClassGetPhysicalAddress(
509 IN PVOID HwDeviceExtension,
510 IN PHW_STREAM_REQUEST_BLOCK HwSRB,
511 IN PVOID VirtualAddress,
512 IN STREAM_BUFFER_TYPE Type,
513 IN ULONG * Length
514 );
515
516 VOID
517 StreamClassQueryMasterClock(
518 IN PHW_STREAM_OBJECT HwStreamObject,
519 IN HANDLE MasterClockHandle,
520 IN TIME_FUNCTION TimeFunction,
521 IN PHW_QUERY_CLOCK_ROUTINE ClockCallbackRoutine
522 );
523
524 VOID
525 STREAMAPI
526 StreamClassQueryMasterClockSync(
527 IN HANDLE MasterClockHandle,
528 IN PHW_TIME_CONTEXT TimeContext
529 );
530
531 BOOLEAN
532 STREAMAPI
533 StreamClassReadWriteConfig(
534 IN PVOID HwDeviceExtension,
535 IN BOOLEAN Read,
536 IN PVOID Buffer,
537 IN ULONG Offset,
538 IN ULONG Length
539 );
540
541 VOID
542 STREAMAPI
543 StreamClassReenumerateStreams(
544 IN PVOID HwDeviceExtension,
545 IN ULONG StreamDescriptorSize
546 );
547
548 NTSTATUS
549 STREAMAPI
550 StreamClassRegisterAdapter(
551 IN PVOID Argument1,
552 IN PVOID Argument2,
553 IN PHW_INITIALIZATION_DATA HwInitializationData
554 );
555
556 #define StreamClassRegisterMinidriver StreamClassRegisterAdapter
557
558 NTSTATUS
559 StreamClassRegisterFilterWithNoKSPins(
560 IN PDEVICE_OBJECT DeviceObject,
561 IN const GUID * InterfaceClassGUID,
562 IN ULONG PinCount,
563 IN BOOLEAN * PinDirection,
564 IN KSPIN_MEDIUM * MediumList,
565 IN GUID * CategoryList
566 );
567
568 VOID
569 STREAMAPI
570 StreamClassScheduleTimer(
571 IN PHW_STREAM_OBJECT StreamObject,
572 IN PVOID HwDeviceExtension,
573 IN ULONG NumberOfMicroseconds,
574 IN PHW_TIMER_ROUTINE TimerRoutine,
575 IN PVOID Context
576 );
577
578 VOID
579 __cdecl
580 StreamClassStreamNotification(
581 IN STREAM_MINIDRIVER_STREAM_NOTIFICATION_TYPE NotificationType,
582 IN PHW_STREAM_OBJECT StreamObject,
583 IN ...
584 );
585
586 #endif