2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Kernel Streaming
4 * FILE: drivers/wdm/audio/backpln/portcls/api.c
5 * PURPOSE: Port api functions
6 * PROGRAMMER: Johannes Anderwald
17 IN PVOID DeviceObject
,
18 IN DEVICE_REGISTRY_PROPERTY DeviceProperty
,
19 IN ULONG BufferLength
,
20 OUT PVOID PropertyBuffer
,
21 OUT PULONG ResultLength
)
23 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
25 ASSERT_IRQL_EQUAL(PASSIVE_LEVEL
);
27 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)((PDEVICE_OBJECT
)DeviceObject
)->DeviceExtension
;
29 return IoGetDeviceProperty(DeviceExtension
->PhysicalDeviceObject
, DeviceProperty
, BufferLength
, PropertyBuffer
, ResultLength
);
40 LARGE_INTEGER CurrentTime
;
42 KeQuerySystemTime(&CurrentTime
);
44 return (CurrentTime
.QuadPart
- Since
);
54 IN PDEVICE_OBJECT DeviceObject
,
57 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
59 PLIST_ENTRY ListEntry
;
60 PTIMER_CONTEXT CurContext
;
62 if (!DeviceObject
|| !DeviceObject
->DeviceExtension
)
65 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
67 KeAcquireSpinLock(&DeviceExtension
->TimerListLock
, &OldIrql
);
69 ListEntry
= DeviceExtension
->TimerList
.Flink
;
70 while(ListEntry
!= &DeviceExtension
->TimerList
)
72 CurContext
= (PTIMER_CONTEXT
)CONTAINING_RECORD(ListEntry
, TIMER_CONTEXT
, Entry
);
74 CurContext
->pTimerRoutine(DeviceObject
, CurContext
->Context
);
75 ListEntry
= ListEntry
->Flink
;
78 KeReleaseSpinLock(&DeviceExtension
->TimerListLock
, OldIrql
);
86 IN PDEVICE_OBJECT pDeviceObject
,
87 IN PIO_TIMER_ROUTINE pTimerRoutine
,
90 NTSTATUS Status
= STATUS_SUCCESS
;
91 PTIMER_CONTEXT TimerContext
, CurContext
;
93 PLIST_ENTRY ListEntry
;
95 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
97 ASSERT_IRQL_EQUAL(PASSIVE_LEVEL
);
99 if (!pDeviceObject
|| !pDeviceObject
->DeviceExtension
)
100 return STATUS_INVALID_PARAMETER
;
102 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)pDeviceObject
->DeviceExtension
;
104 TimerContext
= AllocateItem(NonPagedPool
, sizeof(TIMER_CONTEXT
), TAG_PORTCLASS
);
107 DPRINT1("Failed to allocate memory\n");
108 return STATUS_INSUFFICIENT_RESOURCES
;
111 KeAcquireSpinLock(&DeviceExtension
->TimerListLock
, &OldIrql
);
113 ListEntry
= DeviceExtension
->TimerList
.Flink
;
115 while(ListEntry
!= &DeviceExtension
->TimerList
)
117 CurContext
= (PTIMER_CONTEXT
)CONTAINING_RECORD(ListEntry
, TIMER_CONTEXT
, Entry
);
119 if (CurContext
->Context
== pContext
&& CurContext
->pTimerRoutine
== pTimerRoutine
)
122 Status
= STATUS_UNSUCCESSFUL
;
123 ExFreePool(TimerContext
);
126 ListEntry
= ListEntry
->Flink
;
131 TimerContext
->Context
= pContext
;
132 TimerContext
->pTimerRoutine
= pTimerRoutine
;
133 InsertTailList(&DeviceExtension
->TimerList
, &TimerContext
->Entry
);
136 KeReleaseSpinLock(&DeviceExtension
->TimerListLock
, OldIrql
);
146 PcUnregisterIoTimeout(
147 IN PDEVICE_OBJECT pDeviceObject
,
148 IN PIO_TIMER_ROUTINE pTimerRoutine
,
151 PTIMER_CONTEXT CurContext
;
153 PLIST_ENTRY ListEntry
;
155 PPCLASS_DEVICE_EXTENSION DeviceExtension
;
157 ASSERT_IRQL_EQUAL(PASSIVE_LEVEL
);
159 if (!pDeviceObject
|| !pDeviceObject
->DeviceExtension
)
160 return STATUS_INVALID_PARAMETER
;
163 DeviceExtension
= (PPCLASS_DEVICE_EXTENSION
)pDeviceObject
->DeviceExtension
;
166 KeAcquireSpinLock(&DeviceExtension
->TimerListLock
, &OldIrql
);
168 ListEntry
= DeviceExtension
->TimerList
.Flink
;
171 while(ListEntry
!= &DeviceExtension
->TimerList
)
173 CurContext
= (PTIMER_CONTEXT
)CONTAINING_RECORD(ListEntry
, TIMER_CONTEXT
, Entry
);
175 if (CurContext
->Context
== pContext
&& CurContext
->pTimerRoutine
== pTimerRoutine
)
178 RemoveEntryList(&CurContext
->Entry
);
179 ExFreePool(CurContext
);
182 ListEntry
= ListEntry
->Flink
;
185 KeReleaseSpinLock(&DeviceExtension
->TimerListLock
, OldIrql
);
188 return STATUS_SUCCESS
;
190 return STATUS_NOT_FOUND
;
199 PcCompletePendingPropertyRequest(
200 IN PPCPROPERTY_REQUEST PropertyRequest
,
201 IN NTSTATUS NtStatus
)
204 ASSERT_IRQL(DISPATCH_LEVEL
);
206 if (!PropertyRequest
)
207 return STATUS_INVALID_PARAMETER
;
209 ASSERT(PropertyRequest
->Irp
);
210 ASSERT(NtStatus
!= STATUS_PENDING
);
212 /* set the final status code */
213 PropertyRequest
->Irp
->IoStatus
.Status
= NtStatus
;
215 /* complete the irp */
216 IoCompleteRequest(PropertyRequest
->Irp
, IO_SOUND_INCREMENT
);
218 /* free the property request */
219 ExFreePool(PropertyRequest
);
222 return STATUS_SUCCESS
;
231 PcDmaMasterDescription(
232 IN PRESOURCELIST ResourceList OPTIONAL
,
233 IN BOOLEAN ScatterGather
,
234 IN BOOLEAN Dma32BitAddresses
,
235 IN BOOLEAN IgnoreCount
,
236 IN BOOLEAN Dma64BitAddresses
,
237 IN DMA_WIDTH DmaWidth
,
238 IN DMA_SPEED DmaSpeed
,
239 IN ULONG MaximumLength
,
241 OUT PDEVICE_DESCRIPTION DeviceDescription
)
244 RtlZeroMemory(DeviceDescription
, sizeof(DEVICE_DESCRIPTION
));
246 DeviceDescription
->Master
= TRUE
;
247 DeviceDescription
->Version
= DEVICE_DESCRIPTION_VERSION1
;
248 DeviceDescription
->ScatterGather
= ScatterGather
;
249 DeviceDescription
->Dma32BitAddresses
= Dma32BitAddresses
;
250 DeviceDescription
->IgnoreCount
= IgnoreCount
;
251 DeviceDescription
->Dma64BitAddresses
= Dma64BitAddresses
;
252 DeviceDescription
->DmaWidth
= DmaWidth
;
253 DeviceDescription
->DmaSpeed
= DmaSpeed
;
254 DeviceDescription
->MaximumLength
= MaximumLength
;
255 DeviceDescription
->DmaPort
= DmaPort
;
257 return STATUS_SUCCESS
;
264 PcDmaSlaveDescription(
265 IN PRESOURCELIST ResourceList OPTIONAL
,
268 IN ULONG AutoInitialize
,
269 IN DMA_SPEED DmaSpeed
,
270 IN ULONG MaximumLength
,
272 OUT PDEVICE_DESCRIPTION DeviceDescription
)
275 RtlZeroMemory(DeviceDescription
, sizeof(DEVICE_DESCRIPTION
));
277 DeviceDescription
->Version
= DEVICE_DESCRIPTION_VERSION1
;
278 DeviceDescription
->DemandMode
= DemandMode
;
279 DeviceDescription
->AutoInitialize
= AutoInitialize
;
280 DeviceDescription
->DmaSpeed
= DmaSpeed
;
281 DeviceDescription
->MaximumLength
= MaximumLength
;
282 DeviceDescription
->DmaPort
= DmaPort
;
284 return STATUS_SUCCESS
;