baseport/syborg/soundsc/virtio_queue.cpp
author Maciej Jablonski <maciej.jablonski@accenture.com>
Thu, 04 Mar 2010 00:55:21 +0000
changeset 45 01c1ffcc4fca
child 72 d00bf4f57250
permissions -rw-r--r--
Audio driver for qemu simulator
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     1
/*
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     2
* This component and the accompanying materials are made available
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     3
* under the terms of the License "Eclipse Public License v1.0"
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     4
* which accompanies this distribution, and is available
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     5
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     6
*
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     7
* Initial Contributors:
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     8
* Accenture Ltd
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
     9
*
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    10
* Contributors:
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    11
*
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    12
* Description: This file is a part of sound driver for Syborg adaptation.
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    13
*
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    14
*/
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    15
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    16
#include "virtio_queue.h"
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    17
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    18
#define ENABLE_QEMU_AUDIO_MODEL_BUG_WORKAROUND
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    19
#define ENABLE_QEMU_VIRTIO_CLEANUP_BUG_WORKAROUND
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    20
#define PHYS_ADDR(x) Epoc::LinearToPhysical( reinterpret_cast<TUint32>(x))
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    21
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    22
namespace VirtIo
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    23
{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    24
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    25
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    26
DQueue::DQueue( MIo& aVirtIo, TUint aId, TUint aCount ) 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    27
	: iVirtIo( aVirtIo ), iId( aId ), iCount( aCount )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    28
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    29
	}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    30
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    31
TInt DQueue::Construct()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    32
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    33
	TInt r = AllocQueue();
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    34
	if (r!=KErrNone)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    35
		{ return r; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    36
	PreInitQueue();
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    37
	iVirtIo.SetQueueBase( iId, iDesc );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    38
	PostInitQueue();
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    39
	return KErrNone;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    40
	}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    41
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    42
void DQueue::Wipe()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    43
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    44
	if ( iChunk )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    45
		{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    46
		iChunk->Close( NULL );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    47
		iChunk = NULL;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    48
		}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    49
#ifndef ENABLE_QEMU_VIRTIO_CLEANUP_BUG_WORKAROUND		
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    50
	if ( iPhysAddr )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    51
		{ Epoc::FreePhysicalRam( iPhysAddr ); }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    52
#endif
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    53
	iPhysAddr = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    54
	}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    55
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    56
DQueue::~DQueue()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    57
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    58
	Wipe();
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    59
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    60
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    61
//
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    62
// Implementation here is that descs are allocated from the one starting with lowest index, 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    63
TInt DQueue::AddBuf( const TAddrLen aScatterList[], TUint32 aOutNum, TUint32 aInNum, Token aToken)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    64
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    65
	SYBORG_VIRTIO_DEBUG("AddBuf Q%x %x l%x %x,%x %x",
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    66
		iId, aScatterList[0].iAddr, aScatterList[0].iLen, aOutNum, aInNum, aToken );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    67
	TUint outLeft = aOutNum;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    68
	TUint inLeft = aInNum;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    69
	TInt first = -1;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    70
	TInt last = -1;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    71
	TUint totalLen = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    72
	// @TODO maintain freedescs counter to know if the below is going to success from the outset.
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    73
	// alloc and initialise descs
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    74
	for ( TUint i = 0, j = 0; (i < iCount) && (outLeft+inLeft); ++i )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    75
		{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    76
		if (iDesc[i].iFlags == KFreeDescriptorMarker)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    77
			{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    78
			if (first<0)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    79
				{ first = i; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    80
			iDesc[i].iFlags = ((outLeft)? 0 : TRingDesc::EFlagWrite);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    81
			iDesc[i].iNext = KFreeDescriptorMarker;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    82
			iDesc[i].iAddr = aScatterList[j].iAddr;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    83
			iDesc[i].iLen = aScatterList[j].iLen;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    84
			totalLen += aScatterList[j].iLen;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    85
			iToken[i].iToken = aToken;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    86
			iToken[i].iTotalLen = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    87
			if ( last >=0 )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    88
				{ 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    89
				iDesc[last].iNext = i; 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    90
				iDesc[last].iFlags |= TRingDesc::EFlagNext;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    91
				}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    92
			last = i;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    93
			if (outLeft) 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    94
				{ --outLeft; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    95
			else 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    96
				{ --inLeft; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    97
			j++;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    98
			}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
    99
		}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   100
	if (outLeft+inLeft) // rollback descs if not all could have been claimed
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   101
		{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   102
		if (first>=0)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   103
			{ FreeDescs(first); }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   104
		return KErrNotReady;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   105
		}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   106
	iToken[first].iTotalLen = totalLen;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   107
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   108
	// fill a slot in avail ring
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   109
	iAvail->iRing[Slot(iAvail->iIdx)] = first;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   110
	++iAvail->iIdx;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   111
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   112
	return KErrNone;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   113
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   114
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   115
// bases on the assumption that the lowest desc index with given aToken value is used (see addBuf)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   116
// @todo make sure the buffer is not yet posted	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   117
TInt DQueue::DetachBuf( Token aToken )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   118
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   119
	TUint myDescId = KFreeDescriptorMarker;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   120
	for ( TIdx i = iNextAvailToSync; i != iAvail->iIdx ; ++i )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   121
		{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   122
		TUint availSlot = Slot( i );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   123
		TUint descId = iAvail->iRing[availSlot];
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   124
		if ( descId < iCount )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   125
			{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   126
			if (iToken[descId].iToken == aToken)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   127
				{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   128
				myDescId = descId;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   129
				break;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   130
				}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   131
			}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   132
		}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   133
	if ( myDescId != KFreeDescriptorMarker )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   134
		{ return KErrNotFound; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   135
	FreeDescs( myDescId );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   136
	return KErrNone;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   137
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   138
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   139
Token DQueue::GetBuf( TUint& aLen )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   140
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   141
	TIdx usedIdx = iUsed->iIdx;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   142
	ASSERT( ((TIdx)iNextUsedToRead) <= usedIdx );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   143
	if (usedIdx == ((TIdx)iNextUsedToRead))
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   144
		{ return 0; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   145
	TUint nextUsedSlot = Slot(iNextUsedToRead);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   146
	TUint len = iUsed->iRing[nextUsedSlot].iLen;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   147
	TUint descId = iUsed->iRing[nextUsedSlot].iId;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   148
	ASSERT(descId<iCount);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   149
	Token token = iToken[descId].iToken;	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   150
	TUint orderedLen = iToken[descId].iTotalLen;	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   151
	SYBORG_VIRTIO_DEBUG( "GetBuf Q%x %x ..%x t%x D%x L%x OL%x", iId, iNextUsedToRead, usedIdx, token, descId, len, orderedLen );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   152
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   153
	++iNextUsedToRead;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   154
	FreeDescs( descId );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   155
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   156
#ifdef ENABLE_QEMU_AUDIO_MODEL_BUG_WORKAROUND	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   157
	aLen = len?len:orderedLen; // @TODO kind of a hack to solve virtio-audio's failure to report len by syborg on the side of qemu
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   158
#endif
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   159
	return token;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   160
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   161
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   162
TInt DQueue::Processing()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   163
	{ return  ((TIdx)(iAvail->iIdx - iFirstEverToSync)) 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   164
		- ((TIdx)(iUsed->iIdx - iFirstEverToRead)); }	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   165
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   166
TInt DQueue::Completed()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   167
	{ return  ((TIdx)(iUsed->iIdx - iNextUsedToRead)); }		
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   168
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   169
void DQueue::Sync()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   170
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   171
	SYBORG_VIRTIO_DEBUG("Sync Q%d, %x..%x",
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   172
		iId, iNextAvailToSync, iAvail->iIdx );	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   173
	if ( ((TIdx)iNextAvailToSync) == iAvail->iIdx)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   174
		{ return; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   175
	DumpAvailPending();
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   176
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   177
	iNextAvailToSync = iAvail->iIdx;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   178
	iVirtIo.PostQueue( iId );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   179
	}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   180
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   181
void DQueue::DumpUsedPending()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   182
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   183
	for (TIdx i = iNextUsedToRead; i != iUsed->iIdx; ++i )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   184
		{ DumpUsed( Slot(i) ); }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   185
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   186
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   187
void DQueue::DumpUsed(TUint usedSlot)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   188
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   189
	SYBORG_VIRTIO_DEBUG("Usedslot = %x, aLen = %x, descId=%x", usedSlot, (TUint32) iUsed->iRing[usedSlot].iLen, iUsed->iRing[usedSlot].iId);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   190
	TUint descId = iUsed->iRing[usedSlot].iId;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   191
	DumpDescs( descId );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   192
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   193
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   194
void DQueue::DumpAvailPending()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   195
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   196
	for (TIdx i = iNextAvailToSync; i != iAvail->iIdx; ++i )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   197
		{ DumpAvail( Slot(i) ); }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   198
	}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   199
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   200
void DQueue::DumpAvail(TUint availSlot)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   201
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   202
	SYBORG_VIRTIO_DEBUG("Q%d, availslot = %x", iId, availSlot);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   203
	TUint descId = iAvail->iRing[availSlot];
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   204
	DumpDescs( descId );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   205
	}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   206
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   207
void DQueue::DumpDescs(TUint descId )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   208
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   209
	do {
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   210
		TRingDesc& d = iDesc[descId];
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   211
		SYBORG_VIRTIO_DEBUG(" Desc %x,addr %x, len %x, flags %x, next %x",
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   212
			(TUint32)descId, (TUint32)d.iAddr, (TUint32)d.iLen, (TUint32)d.iFlags, (TUint32)d.iNext );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   213
		if ((d.iFlags&TRingDesc::EFlagNext)==0)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   214
			{ break; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   215
		descId = d.iNext;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   216
		} while (ETrue);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   217
	}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   218
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   219
void DQueue::DumpAll()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   220
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   221
	DumpAvailPending();
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   222
	DumpUsedPending();
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   223
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   224
		
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   225
void DQueue::FreeDescs( TUint firstDescIdx )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   226
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   227
	TInt i = firstDescIdx;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   228
	Token token = iToken[firstDescIdx].iToken;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   229
	while (i>=0)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   230
		{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   231
		ASSERT( ( ((TUint)i) < iCount ) );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   232
		TUint flags = iDesc[i].iFlags;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   233
		ASSERT( flags != KFreeDescriptorMarker );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   234
		iDesc[i].iFlags = KFreeDescriptorMarker;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   235
		ASSERT( iToken[i].iToken == token );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   236
		iToken[i].iToken = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   237
		iToken[i].iTotalLen = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   238
		i = (flags&TRingDesc::EFlagNext)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   239
			? iDesc[i].iNext : -1;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   240
		}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   241
	}		
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   242
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   243
TUint8* DQueue::AllocMem( TUint aSize )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   244
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   245
	TInt r = KErrNone;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   246
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   247
#ifdef ENABLE_QEMU_VIRTIO_CLEANUP_BUG_WORKAROUND		
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   248
	// note this is second part of workaround that deals
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   249
	// with the issue that memory once assigned to queuebase cannot be 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   250
	// changed,
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   251
	// if queuebase != 0 this is because it was set when the driver
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   252
	// was loaded previous time
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   253
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   254
	iPhysAddr = (TUint32) iVirtIo.GetQueueBase( iId );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   255
	iPhysMemReallyAllocated = (iPhysAddr == 0);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   256
	if (iPhysMemReallyAllocated)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   257
		{ r = Epoc::AllocPhysicalRam(aSize, iPhysAddr, 0 ); }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   258
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   259
#endif
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   260
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   261
	if (r!=KErrNone ) 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   262
		{ return NULL; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   263
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   264
	r = DPlatChunkHw::New( iChunk, iPhysAddr, aSize, 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   265
		EMapAttrSupRw | EMapAttrL2Uncached | EMapAttrL1Uncached );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   266
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   267
	if (r!=KErrNone ) 
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   268
		{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   269
		if ( iPhysMemReallyAllocated )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   270
			{ Epoc::FreePhysicalRam( iPhysAddr, aSize ); }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   271
		iChunk->Close( NULL );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   272
		return NULL;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   273
		}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   274
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   275
	ASSERT( r == KErrNone );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   276
	return reinterpret_cast<TUint8*>( iChunk->LinearAddress() );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   277
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   278
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   279
TInt DQueue::AllocQueue()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   280
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   281
	iDescSize = iCount * sizeof(TRingDesc);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   282
	iAvailSize = sizeof(TRingAvail) + (iCount-1) * sizeof(((TRingAvail*)0)->iRing[0]);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   283
	iTokenSize = iCount * sizeof(TTransactionInfo);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   284
	TUint usedOffset = Align( iDescSize +  iAvailSize, KVirtIoAlignment );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   285
	TUint iUsedSize = sizeof(TRingUsed) + (iCount-1) * sizeof(((TRingUsed*)0)->iRing[0]);
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   286
	TUint size = usedOffset + iUsedSize;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   287
	TUint8* iMemAligned;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   288
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   289
	iMemAligned = AllocMem( size );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   290
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   291
	if (!iMemAligned)
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   292
		{ return KErrNoMemory; }
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   293
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   294
	iDesc = reinterpret_cast<TRingDesc*>( iMemAligned );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   295
	iAvail = reinterpret_cast<TRingAvail*>( iMemAligned + iDescSize );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   296
	iUsed = reinterpret_cast<TRingUsed*>( iMemAligned + usedOffset );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   297
	iToken = reinterpret_cast<TTransactionInfo*>( Kern::Alloc( iTokenSize ) );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   298
	SYBORG_VIRTIO_DEBUG("DQueue %d, Virt iDesc=%x,iAvail=%x,iToken=%x,iUsed=%x",
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   299
		iId, iDesc, iAvail, iToken, iUsed );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   300
	SYBORG_VIRTIO_DEBUG("DQueue %d, Phys iDesc=%x, iUsed=%x",
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   301
		iId, PHYS_ADDR(iDesc), PHYS_ADDR(iUsed) );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   302
	ASSERT( ((PHYS_ADDR(iUsed)-PHYS_ADDR(iDesc))) == ((TUint32)((TUint8*)iUsed-(TUint8*)iDesc)) );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   303
	return KErrNone;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   304
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   305
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   306
void DQueue::PreInitQueue()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   307
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   308
	memset(iDesc, -1, iDescSize );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   309
	memset( ((TUint8*) iAvail) + 4, -1, iDescSize - 4 );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   310
	memset( ((TUint8*) iUsed) + 4, -1, iDescSize - 4 );
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   311
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   312
	iAvail->iFlags = 0; // no notifications from control queue
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   313
	iUsed->iFlags = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   314
	if ( iPhysMemReallyAllocated )
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   315
		{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   316
		iAvail->iIdx = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   317
		iUsed->iIdx = 0;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   318
		}
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   319
	}	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   320
	
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   321
void DQueue::PostInitQueue()
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   322
	{
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   323
	iFirstEverToSync = iNextAvailToSync = iAvail->iIdx;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   324
	iFirstEverToRead = iNextUsedToRead = iUsed->iIdx;
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   325
	}		
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   326
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   327
01c1ffcc4fca Audio driver for qemu simulator
Maciej Jablonski <maciej.jablonski@accenture.com>
parents:
diff changeset
   328
} // namespace VirtIo