Author: janderwald
Date: Mon Jan 5 23:33:34 2009
New Revision: 38598
URL:
http://svn.reactos.org/svn/reactos?rev=38598&view=rev
Log:
- Remove dma_master.c as it is unused
- Implement PcNewDmaChannel
- partly implement IDmaChannel / IDmaChannelSlave
Removed:
trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_master.c
Modified:
trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.c
trunk/reactos/drivers/wdm/audio/backpln/portcls/port_wavepci.c
trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild
trunk/reactos/drivers/wdm/audio/backpln/portcls/private.h
trunk/reactos/drivers/wdm/audio/backpln/portcls/stubs.c
Removed: trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_master.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_master.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_master.c (removed)
@@ -1,198 +1,0 @@
-#include "private.h"
-
-
-typedef struct
-{
- IDmaChannelSlaveVtbl *lpVtbl;
-
- LONG ref;
- ULONG BufferSize;
- PHYSICAL_ADDRESS Address;
-
-}IDmaChannelImpl;
-
-
-/*
- Basic IUnknown methods
-*/
-
- NTSTATUS
- STDMETHODCALLTYPE
- IDmaChannel_fnQueryInterface(
- IDmaChannel* iface,
- IN REFIID refiid,
- OUT PVOID* Output)
- {
- /* TODO */
- return STATUS_UNSUCCESSFUL;
- }
-
-ULONG
-STDMETHODCALLTYPE
-IDmaChannel_fnAddRef(
- IDmaChannel* iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_AddRef: This %p\n", This);
-
- return _InterlockedIncrement(&This->ref);
-}
-
-ULONG
-STDMETHODCALLTYPE
-IDmaChannel_fnRelease(
- IDmaChannel* iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- _InterlockedDecrement(&This->ref);
-
- DPRINT("IDmaChannel_Release: This %p new ref %u\n", This, This->ref);
-
- if (This->ref == 0)
- {
- ExFreePoolWithTag(This, TAG_PORTCLASS);
- return 0;
- }
- /* Return new reference count */
- return This->ref;
-}
-
-
-
-NTSTATUS
-NTAPI
-IDmaChannel_fnAllocateBuffer(
- IN IDmaChannel * iface,
- IN ULONG BufferSize,
- IN PPHYSICAL_ADDRESS PhysicalAddressConstraint OPTIONAL)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_AllocateBuffer: This %p BufferSize %u\n", This,
BufferSize);
-
- /* Did the caller already allocate a buffer ?*/
- if (This->BufferSize) return STATUS_UNSUCCESSFUL;
-
- /* FIXME */
- //This->BufferSize = BufferSize;
-
- return STATUS_UNSUCCESSFUL;
-}
-
-ULONG
-NTAPI
-IDmaChannel_fnAllocatedBufferSize(
- IN IDmaChannel * iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_AllocatedBufferSize: This %p BufferSize %u\n", This,
This->BufferSize);
- return This->BufferSize;
-}
-
-VOID
-NTAPI
-IDmaChannel_fnCopyFrom(
- IN IDmaChannel * iface,
- IN PVOID Destination,
- IN PVOID Source,
- IN ULONG ByteCount
- )
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_CopyFrom: This %p Destination %p Source %p ByteCount
%u\n", This, Destination, Source, ByteCount);
-}
-
-VOID
-NTAPI
-IDmaChannel_fnCopyTo(
- IN IDmaChannel * iface,
- IN PVOID Destination,
- IN PVOID Source,
- IN ULONG ByteCount
- )
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_CopyTo: This %p Destination %p Source %p ByteCount
%u\n", This, Destination, Source, ByteCount);
-}
-
-VOID
-NTAPI
-IDmaChannel_fnFreeBuffer(
- IN IDmaChannel * iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_FreeBuffer: This %p\n", This);
-}
-
-PADAPTER_OBJECT
-NTAPI
-IDmaChannel_fnGetAdapterObject(
- IN IDmaChannel * iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_GetAdapterObject: This %p\n", This);
- return NULL;
-}
-
-ULONG
-NTAPI
-IDmaChannel_fnMaximumBufferSize(
- IN IDmaChannel * iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_MaximumBufferSize: This %p\n", This);
- return 0;
-}
-
-PHYSICAL_ADDRESS
-NTAPI
-IDmaChannel_fnPhysicalAdress(
- IN IDmaChannel * iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_PhysicalAdress: This %p\n", This);
- return This->Address;
-}
-
-VOID
-NTAPI
-IDmaChannel_fnSetBufferSize(
- IN IDmaChannel * iface,
- IN ULONG BufferSize)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_SetBufferSize: This %p\n", This);
-
-}
-
-PVOID
-NTAPI
-IDmaChannel_fnSystemAddress(
- IN IDmaChannel * iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_SystemAddress: This %p\n", This);
- return NULL;
-}
-
-ULONG
-NTAPI
-IDmaChannel_fnTransferCount(
- IN IDmaChannel * iface)
-{
- IDmaChannelImpl * This = (IDmaChannelImpl*)iface;
-
- DPRINT("IDmaChannel_TransferCount: This %p\n", This);
- return 0;
-}
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/dma_slave.c [iso-8859-1] Mon Jan 5
23:33:34 2009
@@ -7,15 +7,30 @@
LONG ref;
+
+ PDEVICE_OBJECT pDeviceObject;
+ PDMA_ADAPTER pAdapter;
+
+ BOOL DmaStarted;
+
+ ULONG MapSize;
+ PVOID MapRegisterBase;
+
+ ULONG LastTransferCount;
+
+ ULONG MaximumBufferSize;
ULONG MaxMapRegisters;
ULONG AllocatedBufferSize;
ULONG BufferSize;
- PDMA_ADAPTER pAdapter;
+
PHYSICAL_ADDRESS Address;
PVOID Buffer;
PMDL Mdl;
+ BOOLEAN WriteToDevice;
}IDmaChannelSlaveImpl;
+
+const GUID IID_IDmaChannel;
//---------------------------------------------------------------
@@ -30,7 +45,17 @@
IN REFIID refiid,
OUT PVOID* Output)
{
- /* TODO */
+ IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
+
+ if (IsEqualGUIDAligned(refiid, &IID_IUnknown) ||
+ IsEqualGUIDAligned(refiid, &IID_IDmaChannel) ||
+ IsEqualGUIDAligned(refiid, &IID_IDmaChannelSlave))
+ {
+ *Output = &This->lpVtbl;
+ InterlockedIncrement(&This->ref);
+ return STATUS_SUCCESS;
+ }
+
return STATUS_UNSUCCESSFUL;
}
@@ -81,8 +106,6 @@
{
IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
- DPRINT("IDmaChannelSlave_AllocateBuffer: This %p BufferSize %u\n", This,
BufferSize);
-
/* Did the caller already allocate a buffer ?*/
if (This->Buffer)
{
@@ -90,16 +113,15 @@
return STATUS_UNSUCCESSFUL;
}
+ //FIXME
+ // retry with different size on failure
+
This->Buffer =
This->pAdapter->DmaOperations->AllocateCommonBuffer(This->pAdapter,
BufferSize, &This->Address, TRUE);
if (!This->Buffer)
{
DPRINT1("IDmaChannelSlave_AllocateBuffer fAllocateCommonBuffer failed
\n");
return STATUS_UNSUCCESSFUL;
}
-
- This->Mdl = IoAllocateMdl(This->Buffer, BufferSize, FALSE, FALSE, NULL);
- if (This->Mdl)
- MmBuildMdlForNonPagedPool(This->Mdl);
This->BufferSize = BufferSize;
This->AllocatedBufferSize = BufferSize;
@@ -129,6 +151,8 @@
IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
DPRINT("IDmaChannelSlave_CopyFrom: This %p Destination %p Source %p ByteCount
%u\n", This, Destination, Source, ByteCount);
+
+ iface->lpVtbl->CopyTo(iface, Destination, Source, ByteCount);
}
VOID
@@ -143,8 +167,9 @@
IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
DPRINT("IDmaChannelSlave_CopyTo: This %p Destination %p Source %p ByteCount
%u\n", This, Destination, Source, ByteCount);
-}
-
+ RtlCopyMemory(Destination, Source, ByteCount);
+}
+
VOID
NTAPI
IDmaChannelSlave_fnFreeBuffer(
@@ -163,6 +188,13 @@
This->pAdapter->DmaOperations->FreeCommonBuffer(This->pAdapter,
This->AllocatedBufferSize, This->Address, This->Buffer, TRUE);
This->Buffer = NULL;
This->AllocatedBufferSize = 0;
+ This->Address.QuadPart = 0LL;
+
+ if (This->Mdl)
+ {
+ IoFreeMdl(This->Mdl);
+ This->Mdl = NULL;
+ }
}
PADAPTER_OBJECT
@@ -184,7 +216,7 @@
IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
DPRINT("IDmaChannelSlave_MaximumBufferSize: This %p\n", This);
- return 0;
+ return This->MaximumBufferSize;
}
PHYSICAL_ADDRESS
@@ -241,7 +273,7 @@
IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
DPRINT("IDmaChannelSlave_TransferCount: This %p\n", This);
- return 0;
+ return This->LastTransferCount;
}
ULONG
@@ -249,11 +281,44 @@
IDmaChannelSlave_fnReadCounter(
IN IDmaChannelSlave * iface)
{
- IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
-
- DPRINT("IDmaChannelSlave_ReadCounter: This %p\n", This);
-
- return 0;
+ ULONG Counter;
+ IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
+
+ Counter = This->pAdapter->DmaOperations->ReadDmaCounter(This->pAdapter);
+
+ if (!This->DmaStarted || Counter >= This->LastTransferCount) //FIXME
+ Counter = 0;
+
+ return Counter;
+}
+
+IO_ALLOCATION_ACTION
+NTAPI
+AdapterControl(
+ IN PDEVICE_OBJECT DeviceObject,
+ IN PIRP Irp,
+ IN PVOID MapRegisterBase,
+ IN PVOID Context)
+{
+ ULONG Length;
+ IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)Context;
+
+ Length = This->MapSize;
+ This->MapRegisterBase = MapRegisterBase;
+
+ This->pAdapter->DmaOperations->MapTransfer(This->pAdapter,
+ This->Mdl,
+ MapRegisterBase,
+
(PVOID)((ULONG_PTR)This->Mdl->StartVa + This->Mdl->ByteOffset),
+ &Length,
+ This->WriteToDevice);
+
+ if (Length == This->BufferSize)
+ {
+ This->DmaStarted = TRUE;
+ }
+
+ return KeepObject;
}
NTSTATUS
@@ -263,10 +328,43 @@
ULONG MapSize,
BOOLEAN WriteToDevice)
{
+ NTSTATUS Status;
+ ULONG MapRegisters;
+ KIRQL OldIrql;
IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
DPRINT("IDmaChannelSlave_Start: This %p\n", This);
- return 0;
+
+ if (This->DmaStarted)
+ return STATUS_UNSUCCESSFUL;
+
+ if (!This->Mdl)
+ {
+ This->Mdl = IoAllocateMdl(&This->Buffer, This->MaximumBufferSize,
FALSE, FALSE, NULL);
+ if (!This->Mdl)
+ {
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+ MmBuildMdlForNonPagedPool(This->Mdl);
+ }
+
+ This->MapSize = MapSize;
+ This->WriteToDevice = WriteToDevice;
+ This->LastTransferCount = MapSize;
+
+ //FIXME
+ // synchronize access
+ //
+ KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+
+ MapRegisters = ADDRESS_AND_SIZE_TO_SPAN_PAGES(This->Buffer, MapSize);
+ Status =
This->pAdapter->DmaOperations->AllocateAdapterChannel(This->pAdapter,
This->pDeviceObject, MapRegisters, AdapterControl, (PVOID)This);
+ KeLowerIrql(OldIrql);
+
+ if(!NT_SUCCESS(Status))
+ This->LastTransferCount = 0;
+
+ return Status;
}
NTSTATUS
@@ -274,9 +372,29 @@
IDmaChannelSlave_fnStop(
IN IDmaChannelSlave * iface)
{
+ KIRQL OldIrql;
IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
DPRINT("IDmaChannelSlave_fnStop: This %p\n", This);
+
+ if (!This->DmaStarted)
+ return STATUS_SUCCESS;
+
+ This->pAdapter->DmaOperations->FlushAdapterBuffers(This->pAdapter,
+ This->Mdl,
+ This->MapRegisterBase,
+
(PVOID)((ULONG_PTR)This->Mdl->StartVa + This->Mdl->ByteOffset),
+ This->MapSize,
+ This->WriteToDevice);
+
+ KeRaiseIrql(DISPATCH_LEVEL, &OldIrql);
+
+ This->pAdapter->DmaOperations->FreeAdapterChannel(This->pAdapter);
+
+ KeLowerIrql(OldIrql);
+
+ This->DmaStarted = FALSE;
+
return 0;
}
@@ -286,10 +404,40 @@
IN IDmaChannelSlave * iface,
ULONG Timeout)
{
- IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
-
- DPRINT("IDmaChannelSlave_WaitForTC: This %p\n", This);
- return 0;
+ ULONG RetryCount;
+ ULONG BytesRemaining;
+ ULONG PrevBytesRemaining;
+
+ IDmaChannelSlaveImpl * This = (IDmaChannelSlaveImpl*)iface;
+
+ BytesRemaining =
This->pAdapter->DmaOperations->ReadDmaCounter(This->pAdapter);
+ if (!BytesRemaining)
+ {
+ return STATUS_SUCCESS;
+ }
+
+ RetryCount = Timeout / 10;
+ PrevBytesRemaining = 0xFFFFFFFF;
+ do
+ {
+ BytesRemaining =
This->pAdapter->DmaOperations->ReadDmaCounter(This->pAdapter);
+
+ if (!BytesRemaining)
+ break;
+
+ if (PrevBytesRemaining == BytesRemaining)
+ break;
+
+ KeStallExecutionProcessor(10);
+ PrevBytesRemaining = BytesRemaining;
+
+ }while(RetryCount-- >= 1);
+
+ //FIXME
+ // return error code on timeout
+ //
+
+ return STATUS_SUCCESS;
}
@@ -320,29 +468,56 @@
};
-NTSTATUS NewDmaChannelSlave(
- IN PDEVICE_DESCRIPTION DeviceDesc,
- IN PDMA_ADAPTER Adapter,
- IN ULONG MapRegisters,
- OUT PDMACHANNELSLAVE* DmaChannel)
-{
+/*
+ * @unimplemented
+ */
+NTSTATUS NTAPI
+PcNewDmaChannel(
+ OUT PDMACHANNEL* OutDmaChannel,
+ IN PUNKNOWN OuterUnknown OPTIONAL,
+ IN POOL_TYPE PoolType,
+ IN PDEVICE_DESCRIPTION DeviceDescription,
+ IN PDEVICE_OBJECT DeviceObject)
+{
+ NTSTATUS Status;
+ PDMA_ADAPTER Adapter;
+ ULONG MapRegisters;
+ INTERFACE_TYPE BusType;
+ ULONG ResultLength;
+
IDmaChannelSlaveImpl * This;
- This = ExAllocatePoolWithTag(NonPagedPool, sizeof(IDmaChannelSlaveImpl),
TAG_PORTCLASS);
+ This = ExAllocatePoolWithTag(PoolType, sizeof(IDmaChannelSlaveImpl), TAG_PORTCLASS);
if (!This)
{
- Adapter->DmaOperations->PutDmaAdapter(Adapter);
return STATUS_INSUFFICIENT_RESOURCES;
}
+
+ Status = IoGetDeviceProperty(DeviceObject, DevicePropertyLegacyBusType,
sizeof(BusType), (PVOID)&BusType, &ResultLength);
+ if (NT_SUCCESS(Status))
+ {
+ DeviceDescription->InterfaceType = BusType;
+ }
+
+ Adapter = IoGetDmaAdapter(DeviceObject, DeviceDescription, &MapRegisters);
+ if (!Adapter)
+ {
+ ExFreePoolWithTag(This, TAG_PORTCLASS);
+ return STATUS_DEVICE_CONFIGURATION_ERROR;
+ }
+
RtlZeroMemory(This, sizeof(IDmaChannelSlaveImpl));
+
This->ref = 1;
This->lpVtbl = &vt_IDmaChannelSlaveVtbl;
This->pAdapter = Adapter;
+ This->pDeviceObject = DeviceObject;
+ This->MaximumBufferSize = DeviceDescription->MaximumLength;
This->MaxMapRegisters = MapRegisters;
- *DmaChannel = (PVOID)(&This->lpVtbl);
+
+ *OutDmaChannel = (PVOID)(&This->lpVtbl);
return STATUS_SUCCESS;
}
-
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/port_wavepci.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/port_wavepci.c [iso-8859-1]
(original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/port_wavepci.c [iso-8859-1] Mon Jan 5
23:33:34 2009
@@ -7,7 +7,6 @@
#if 0
IUnregisterSubdevice *lpVtblUnregisterSubDevice;
- IPortClsVersionVtbl *lpVtblPortClsVersion;
#endif
LONG ref;
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild [iso-8859-1]
(original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/portcls.rbuild [iso-8859-1] Mon Jan 5
23:33:34 2009
@@ -9,9 +9,9 @@
<library>ks</library>
<library>drmk</library>
<library>rtl</library>
+ <library>hal</library>
<file>api.c</file>
<file>dll.c</file>
- <file>dma_master.c</file>
<file>dma_slave.c</file>
<file>drm_port.c</file>
<file>adapter.c</file>
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/private.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/private.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/private.h [iso-8859-1] Mon Jan 5
23:33:34 2009
@@ -71,12 +71,6 @@
NTSTATUS NewPortWavePci(
OUT PPORT* OutPort);
-NTSTATUS NewDmaChannelSlave(
- IN PDEVICE_DESCRIPTION DeviceDesc,
- IN PDMA_ADAPTER Adapter,
- IN ULONG MapRegisters,
- OUT PDMACHANNELSLAVE* DmaChannel);
-
NTSTATUS NewIDrmPort(
OUT PDRMPORT2 *OutPort);
Modified: trunk/reactos/drivers/wdm/audio/backpln/portcls/stubs.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/wdm/audio/backpln/…
==============================================================================
--- trunk/reactos/drivers/wdm/audio/backpln/portcls/stubs.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/wdm/audio/backpln/portcls/stubs.c [iso-8859-1] Mon Jan 5
23:33:34 2009
@@ -16,17 +16,7 @@
Factory Stubs
*/
-NTSTATUS NTAPI
-PcNewDmaChannel(
- OUT PDMACHANNEL* OutDmaChannel,
- IN PUNKNOWN OuterUnknown OPTIONAL,
- IN POOL_TYPE PoolType,
- IN PDEVICE_DESCRIPTION DeviceDescription,
- IN PDEVICE_OBJECT DeviceObject)
-{
- UNIMPLEMENTED;
- return STATUS_UNSUCCESSFUL;
-}
+
/* ===============================================================
Power Management