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
14 IN PVOID DeviceObject
,
15 IN DEVICE_REGISTRY_PROPERTY DeviceProperty
,
16 IN ULONG BufferLength
,
17 OUT PVOID PropertyBuffer
,
18 OUT PULONG ResultLength
)
20 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
22 PC_ASSERT_IRQL_EQUAL(PASSIVE_LEVEL
);
24 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)((PDEVICE_OBJECT
)DeviceObject
)->DeviceExtension
;
26 return IoGetDeviceProperty(DeviceExtension
->PhysicalDeviceObject
, DeviceProperty
, BufferLength
, PropertyBuffer
, ResultLength
);
34 LARGE_INTEGER CurrentTime
;
36 KeQuerySystemTime(&CurrentTime
);
38 return (CurrentTime
.QuadPart
- Since
);
44 IN PDEVICE_OBJECT DeviceObject
,
47 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
49 PLIST_ENTRY ListEntry
;
50 PTIMER_CONTEXT CurContext
;
52 if (!DeviceObject
|| !DeviceObject
->DeviceExtension
)
55 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
57 KeAcquireSpinLock(&DeviceExtension
->TimerListLock
, &OldIrql
);
59 ListEntry
= DeviceExtension
->TimerList
.Flink
;
60 while(ListEntry
!= &DeviceExtension
->TimerList
)
62 CurContext
= (PTIMER_CONTEXT
)CONTAINING_RECORD(ListEntry
, TIMER_CONTEXT
, Entry
);
64 CurContext
->pTimerRoutine(DeviceObject
, CurContext
->Context
);
65 ListEntry
= ListEntry
->Flink
;
68 KeReleaseSpinLock(&DeviceExtension
->TimerListLock
, OldIrql
);
74 IN PDEVICE_OBJECT pDeviceObject
,
75 IN PIO_TIMER_ROUTINE pTimerRoutine
,
78 NTSTATUS Status
= STATUS_SUCCESS
;
79 PTIMER_CONTEXT TimerContext
, CurContext
;
81 PLIST_ENTRY ListEntry
;
83 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
85 PC_ASSERT_IRQL_EQUAL(PASSIVE_LEVEL
);
87 if (!pDeviceObject
|| !pDeviceObject
->DeviceExtension
)
88 return STATUS_INVALID_PARAMETER
;
90 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)pDeviceObject
->DeviceExtension
;
92 TimerContext
= (PTIMER_CONTEXT
)AllocateItem(NonPagedPool
, sizeof(TIMER_CONTEXT
), TAG_PORTCLASS
);
95 DPRINT1("Failed to allocate memory\n");
96 return STATUS_INSUFFICIENT_RESOURCES
;
99 KeAcquireSpinLock(&DeviceExtension
->TimerListLock
, &OldIrql
);
101 ListEntry
= DeviceExtension
->TimerList
.Flink
;
103 while(ListEntry
!= &DeviceExtension
->TimerList
)
105 CurContext
= (PTIMER_CONTEXT
)CONTAINING_RECORD(ListEntry
, TIMER_CONTEXT
, Entry
);
107 if (CurContext
->Context
== pContext
&& CurContext
->pTimerRoutine
== pTimerRoutine
)
110 Status
= STATUS_UNSUCCESSFUL
;
111 ExFreePool(TimerContext
);
114 ListEntry
= ListEntry
->Flink
;
119 TimerContext
->Context
= pContext
;
120 TimerContext
->pTimerRoutine
= pTimerRoutine
;
121 InsertTailList(&DeviceExtension
->TimerList
, &TimerContext
->Entry
);
124 KeReleaseSpinLock(&DeviceExtension
->TimerListLock
, OldIrql
);
131 PcUnregisterIoTimeout(
132 IN PDEVICE_OBJECT pDeviceObject
,
133 IN PIO_TIMER_ROUTINE pTimerRoutine
,
136 PTIMER_CONTEXT CurContext
;
138 PLIST_ENTRY ListEntry
;
140 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
142 PC_ASSERT_IRQL_EQUAL(PASSIVE_LEVEL
);
144 if (!pDeviceObject
|| !pDeviceObject
->DeviceExtension
)
145 return STATUS_INVALID_PARAMETER
;
148 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)pDeviceObject
->DeviceExtension
;
151 KeAcquireSpinLock(&DeviceExtension
->TimerListLock
, &OldIrql
);
153 ListEntry
= DeviceExtension
->TimerList
.Flink
;
156 while(ListEntry
!= &DeviceExtension
->TimerList
)
158 CurContext
= (PTIMER_CONTEXT
)CONTAINING_RECORD(ListEntry
, TIMER_CONTEXT
, Entry
);
160 if (CurContext
->Context
== pContext
&& CurContext
->pTimerRoutine
== pTimerRoutine
)
163 RemoveEntryList(&CurContext
->Entry
);
164 ExFreePool(CurContext
);
167 ListEntry
= ListEntry
->Flink
;
170 KeReleaseSpinLock(&DeviceExtension
->TimerListLock
, OldIrql
);
173 return STATUS_SUCCESS
;
175 return STATUS_NOT_FOUND
;
182 PcCompletePendingPropertyRequest(
183 IN PPCPROPERTY_REQUEST PropertyRequest
,
184 IN NTSTATUS NtStatus
)
187 PC_ASSERT_IRQL(DISPATCH_LEVEL
);
189 if (!PropertyRequest
|| !PropertyRequest
->Irp
|| NtStatus
== STATUS_PENDING
)
190 return STATUS_INVALID_PARAMETER
;
192 // set the final status code
193 PropertyRequest
->Irp
->IoStatus
.Status
= NtStatus
;
196 IoCompleteRequest(PropertyRequest
->Irp
, IO_SOUND_INCREMENT
);
198 // free the property request
199 ExFreePool(PropertyRequest
);
202 return STATUS_SUCCESS
;
207 PcDmaMasterDescription(
208 IN PRESOURCELIST ResourceList OPTIONAL
,
209 IN BOOLEAN ScatterGather
,
210 IN BOOLEAN Dma32BitAddresses
,
211 IN BOOLEAN IgnoreCount
,
212 IN BOOLEAN Dma64BitAddresses
,
213 IN DMA_WIDTH DmaWidth
,
214 IN DMA_SPEED DmaSpeed
,
215 IN ULONG MaximumLength
,
217 OUT PDEVICE_DESCRIPTION DeviceDescription
)
220 RtlZeroMemory(DeviceDescription
, sizeof(DEVICE_DESCRIPTION
));
222 DeviceDescription
->Master
= TRUE
;
223 DeviceDescription
->Version
= DEVICE_DESCRIPTION_VERSION1
;
224 DeviceDescription
->ScatterGather
= ScatterGather
;
225 DeviceDescription
->Dma32BitAddresses
= Dma32BitAddresses
;
226 DeviceDescription
->IgnoreCount
= IgnoreCount
;
227 DeviceDescription
->Dma64BitAddresses
= Dma64BitAddresses
;
228 DeviceDescription
->DmaWidth
= DmaWidth
;
229 DeviceDescription
->DmaSpeed
= DmaSpeed
;
230 DeviceDescription
->MaximumLength
= MaximumLength
;
231 DeviceDescription
->DmaPort
= DmaPort
;
233 return STATUS_SUCCESS
;
238 PcDmaSlaveDescription(
239 IN PRESOURCELIST ResourceList OPTIONAL
,
242 IN ULONG AutoInitialize
,
243 IN DMA_SPEED DmaSpeed
,
244 IN ULONG MaximumLength
,
246 OUT PDEVICE_DESCRIPTION DeviceDescription
)
249 RtlZeroMemory(DeviceDescription
, sizeof(DEVICE_DESCRIPTION
));
251 DeviceDescription
->Version
= DEVICE_DESCRIPTION_VERSION1
;
252 DeviceDescription
->DemandMode
= DemandMode
;
253 DeviceDescription
->AutoInitialize
= AutoInitialize
;
254 DeviceDescription
->DmaSpeed
= DmaSpeed
;
255 DeviceDescription
->MaximumLength
= MaximumLength
;
256 DeviceDescription
->DmaPort
= DmaPort
;
258 return STATUS_SUCCESS
;