ReactOS 0.4.16-dev-329-g9223134
api.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/backpln/portcls/api.cpp
5 * PURPOSE: Port api functions
6 * PROGRAMMER: Johannes Anderwald
7 */
8
9#include "private.hpp"
10
11#define NDEBUG
12#include <debug.h>
13
22{
23 PPCLASS_DEVICE_EXTENSION DeviceExtension;
24
26
27 DeviceExtension = (PPCLASS_DEVICE_EXTENSION)((PDEVICE_OBJECT)DeviceObject)->DeviceExtension;
28
30}
31
35 IN ULONGLONG Since)
36{
37 LARGE_INTEGER CurrentTime;
38
39 KeQuerySystemTime(&CurrentTime);
40
41 return (CurrentTime.QuadPart - Since);
42}
43
44VOID
49{
50 PPCLASS_DEVICE_EXTENSION DeviceExtension;
52 PLIST_ENTRY ListEntry;
53 PTIMER_CONTEXT CurContext;
54
55 if (!DeviceObject || !DeviceObject->DeviceExtension)
56 return;
57
58 DeviceExtension = (PPCLASS_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
59
60 KeAcquireSpinLock(&DeviceExtension->TimerListLock, &OldIrql);
61
62 ListEntry = DeviceExtension->TimerList.Flink;
63 while(ListEntry != &DeviceExtension->TimerList)
64 {
65 CurContext = (PTIMER_CONTEXT)CONTAINING_RECORD(ListEntry, TIMER_CONTEXT, Entry);
66
67 CurContext->pTimerRoutine(DeviceObject, CurContext->Context);
68 ListEntry = ListEntry->Flink;
69 }
70
71 KeReleaseSpinLock(&DeviceExtension->TimerListLock, OldIrql);
72}
73
78 IN PIO_TIMER_ROUTINE pTimerRoutine,
79 IN PVOID pContext)
80{
82 PTIMER_CONTEXT TimerContext, CurContext;
84 PLIST_ENTRY ListEntry;
85 BOOLEAN bFound;
86 PPCLASS_DEVICE_EXTENSION DeviceExtension;
87
89
90 if (!pDeviceObject || !pDeviceObject->DeviceExtension)
92
93 DeviceExtension = (PPCLASS_DEVICE_EXTENSION)pDeviceObject->DeviceExtension;
94
96 if (!TimerContext)
97 {
98 DPRINT("Failed to allocate memory\n");
100 }
101
102 KeAcquireSpinLock(&DeviceExtension->TimerListLock, &OldIrql);
103
104 ListEntry = DeviceExtension->TimerList.Flink;
105 bFound = FALSE;
106 while(ListEntry != &DeviceExtension->TimerList)
107 {
108 CurContext = (PTIMER_CONTEXT)CONTAINING_RECORD(ListEntry, TIMER_CONTEXT, Entry);
109
110 if (CurContext->Context == pContext && CurContext->pTimerRoutine == pTimerRoutine)
111 {
112 bFound = TRUE;
115 break;
116 }
117 ListEntry = ListEntry->Flink;
118 }
119
120 if (!bFound)
121 {
122 TimerContext->Context = pContext;
123 TimerContext->pTimerRoutine = pTimerRoutine;
124 InsertTailList(&DeviceExtension->TimerList, &TimerContext->Entry);
125 }
126
127 KeReleaseSpinLock(&DeviceExtension->TimerListLock, OldIrql);
128
129 return Status;
130}
131
133NTAPI
136 IN PIO_TIMER_ROUTINE pTimerRoutine,
137 IN PVOID pContext)
138{
139 PTIMER_CONTEXT CurContext;
141 PLIST_ENTRY ListEntry;
142 BOOLEAN bFound;
143 PPCLASS_DEVICE_EXTENSION DeviceExtension;
144
146
147 if (!pDeviceObject || !pDeviceObject->DeviceExtension)
149
150 DeviceExtension = (PPCLASS_DEVICE_EXTENSION)pDeviceObject->DeviceExtension;
151
152 KeAcquireSpinLock(&DeviceExtension->TimerListLock, &OldIrql);
153
154 ListEntry = DeviceExtension->TimerList.Flink;
155 bFound = FALSE;
156
157 while(ListEntry != &DeviceExtension->TimerList)
158 {
159 CurContext = (PTIMER_CONTEXT)CONTAINING_RECORD(ListEntry, TIMER_CONTEXT, Entry);
160
161 if (CurContext->Context == pContext && CurContext->pTimerRoutine == pTimerRoutine)
162 {
163 bFound = TRUE;
164 RemoveEntryList(&CurContext->Entry);
165 FreeItem(CurContext, TAG_PORTCLASS);
166 break;
167 }
168 ListEntry = ListEntry->Flink;
169 }
170
171 KeReleaseSpinLock(&DeviceExtension->TimerListLock, OldIrql);
172
173 if (bFound)
174 return STATUS_SUCCESS;
175 else
176 return STATUS_NOT_FOUND;
177}
178
180NTAPI
182 IN PPCPROPERTY_REQUEST PropertyRequest,
183 IN NTSTATUS NtStatus)
184{
185 // sanity checks
187
188 if (!PropertyRequest || !PropertyRequest->Irp || NtStatus == STATUS_PENDING)
190
191 // set the final status code
192 PropertyRequest->Irp->IoStatus.Status = NtStatus;
193
194 // complete the irp
195 IoCompleteRequest(PropertyRequest->Irp, IO_SOUND_INCREMENT);
196
197 // free the property request
198 FreeItem(PropertyRequest, TAG_PORTCLASS);
199
200 // return success
201 return STATUS_SUCCESS;
202}
203
205NTAPI
209 IN BOOLEAN Dma32BitAddresses,
210 IN BOOLEAN IgnoreCount,
212 IN DMA_WIDTH DmaWidth,
213 IN DMA_SPEED DmaSpeed,
215 IN ULONG DmaPort,
217{
218
220
221 DeviceDescription->Master = TRUE;
223 DeviceDescription->ScatterGather= ScatterGather;
224 DeviceDescription->Dma32BitAddresses = Dma32BitAddresses;
225 DeviceDescription->IgnoreCount = IgnoreCount;
226 DeviceDescription->Dma64BitAddresses = Dma64BitAddresses;
227 DeviceDescription->DmaWidth = DmaWidth;
228 DeviceDescription->DmaSpeed = DmaSpeed;
229 DeviceDescription->MaximumLength = MaximumLength;
230 DeviceDescription->DmaPort = DmaPort;
231
232 return STATUS_SUCCESS;
233}
234
236NTAPI
239 IN ULONG DmaIndex,
240 IN BOOLEAN DemandMode,
241 IN BOOLEAN AutoInitialize,
242 IN DMA_SPEED DmaSpeed,
244 IN ULONG DmaPort,
246{
247
249
251 DeviceDescription->DemandMode = DemandMode;
252 DeviceDescription->AutoInitialize = AutoInitialize;
253 DeviceDescription->DmaSpeed = DmaSpeed;
254 DeviceDescription->MaximumLength = MaximumLength;
255 DeviceDescription->DmaPort = DmaPort;
256
257 return STATUS_SUCCESS;
258}
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
NTSTATUS NTAPI PcGetDeviceProperty(IN PVOID DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: api.cpp:16
NTSTATUS NTAPI PcDmaSlaveDescription(IN PRESOURCELIST ResourceList OPTIONAL, IN ULONG DmaIndex, IN BOOLEAN DemandMode, IN BOOLEAN AutoInitialize, IN DMA_SPEED DmaSpeed, IN ULONG MaximumLength, IN ULONG DmaPort, OUT PDEVICE_DESCRIPTION DeviceDescription)
Definition: api.cpp:237
NTSTATUS NTAPI PcCompletePendingPropertyRequest(IN PPCPROPERTY_REQUEST PropertyRequest, IN NTSTATUS NtStatus)
Definition: api.cpp:181
ULONGLONG NTAPI PcGetTimeInterval(IN ULONGLONG Since)
Definition: api.cpp:34
NTSTATUS NTAPI PcDmaMasterDescription(IN PRESOURCELIST ResourceList OPTIONAL, IN BOOLEAN ScatterGather, IN BOOLEAN Dma32BitAddresses, IN BOOLEAN IgnoreCount, IN BOOLEAN Dma64BitAddresses, IN DMA_WIDTH DmaWidth, IN DMA_SPEED DmaSpeed, IN ULONG MaximumLength, IN ULONG DmaPort, OUT PDEVICE_DESCRIPTION DeviceDescription)
Definition: api.cpp:206
VOID NTAPI PcIoTimerRoutine(IN PDEVICE_OBJECT DeviceObject, IN PVOID Context)
Definition: api.cpp:46
NTSTATUS NTAPI PcRegisterIoTimeout(IN PDEVICE_OBJECT pDeviceObject, IN PIO_TIMER_ROUTINE pTimerRoutine, IN PVOID pContext)
Definition: api.cpp:76
NTSTATUS NTAPI PcUnregisterIoTimeout(IN PDEVICE_OBJECT pDeviceObject, IN PIO_TIMER_ROUTINE pTimerRoutine, IN PVOID pContext)
Definition: api.cpp:134
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define NonPagedPool
Definition: env_spec_w32.h:307
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
Status
Definition: gdiplustypes.h:25
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
_In_ PNDIS_STRING _In_ PNDIS_STRING _Out_ PDEVICE_OBJECT * pDeviceObject
Definition: ndis.h:4679
_In_ BOOLEAN Dma64BitAddresses
Definition: ndis.h:4652
#define IoCompleteRequest
Definition: irp.c:1240
NTSTATUS NTAPI IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject, IN DEVICE_REGISTRY_PROPERTY DeviceProperty, IN ULONG BufferLength, OUT PVOID PropertyBuffer, OUT PULONG ResultLength)
Definition: pnpmgr.c:1382
IResourceList * PRESOURCELIST
Definition: portcls.h:442
struct TIMER_CONTEXT * PTIMER_CONTEXT
#define PC_ASSERT_IRQL_EQUAL(x)
Definition: private.hpp:31
#define PC_ASSERT_IRQL(x)
Definition: private.hpp:30
struct PCLASS_DEVICE_EXTENSION * PPCLASS_DEVICE_EXTENSION
#define TAG_PORTCLASS
Definition: private.hpp:24
enum _DMA_SPEED DMA_SPEED
enum _DMA_WIDTH DMA_WIDTH
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define DPRINT
Definition: sndvol32.h:73
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
base of all file and directory entries
Definition: entries.h:83
PDEVICE_OBJECT PhysicalDeviceObject
Definition: private.hpp:402
KSPIN_LOCK TimerListLock
Definition: private.hpp:413
LIST_ENTRY Entry
Definition: private.hpp:430
PVOID Context
Definition: private.hpp:432
PIO_TIMER_ROUTINE pTimerRoutine
Definition: private.hpp:431
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3776
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ ULONG _Out_ PVOID PropertyBuffer
Definition: wdfdevice.h:4437
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY DeviceProperty
Definition: wdfdevice.h:3769
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_In_ WDFDMATRANSACTION _In_ size_t MaximumLength
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:432
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
#define IO_SOUND_INCREMENT
Definition: iotypes.h:608
#define DEVICE_DESCRIPTION_VERSION1
Definition: iotypes.h:2064
DEVICE_REGISTRY_PROPERTY
Definition: iotypes.h:1194
_In_ struct _IRP _In_ struct _SCATTER_GATHER_LIST * ScatterGather
Definition: iotypes.h:2375
IO_TIMER_ROUTINE * PIO_TIMER_ROUTINE
Definition: iotypes.h:2863
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
_In_ PLARGE_INTEGER _In_opt_ PTIMER_APC_ROUTINE _In_opt_ PVOID TimerContext
Definition: zwfuncs.h:430