baseport/syborg/soundsc/virtio_queue.h
changeset 45 01c1ffcc4fca
equal deleted inserted replaced
44:72a7468afdd4 45:01c1ffcc4fca
       
     1 /*
       
     2 * This component and the accompanying materials are made available
       
     3 * under the terms of the License "Eclipse Public License v1.0"
       
     4 * which accompanies this distribution, and is available
       
     5 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     6 *
       
     7 * Initial Contributors:
       
     8 * Accenture Ltd
       
     9 *
       
    10 * Contributors:
       
    11 *
       
    12 * Description: This file is a part of sound driver for Syborg adaptation.
       
    13 *
       
    14 */
       
    15 
       
    16 #ifndef VIRTIO_QUEUE_H
       
    17 #define VIRTIO_QUEUE_H
       
    18 
       
    19 #include "virtio.h"
       
    20 #include <e32def.h>
       
    21 
       
    22 namespace VirtIo
       
    23 {
       
    24 
       
    25 /// @brief implements VirtIo Queue.
       
    26 /// 
       
    27 ///
       
    28 /// @note functions are not enclosed with any synchronisation primitives.
       
    29 /// However, implementation is believed to split operations in 3 groups with the following concurrency constraints:
       
    30 /// <li> A GetBuf, DetachBuf
       
    31 /// <li> B AddBuf
       
    32 /// <li> C Processing, Completed, Sync
       
    33 /// Group C can be executed concurrently with any other functions.
       
    34 /// Group A can be executed concurrently with a group B function.
       
    35 /// Group A or B function cannot be executed concurrently with function from the same group.
       
    36 ///
       
    37 /// Memory barries would have to be introduced for SMP.
       
    38 ///
       
    39 class DQueue : public DBase, public MQueue
       
    40 	{
       
    41 	typedef TUint16 TIdx;
       
    42 
       
    43 	struct TTransactionInfo
       
    44 		{
       
    45 		Token iToken;
       
    46 		TUint iTotalLen;
       
    47 		};
       
    48 	
       
    49 	static const TUint KFreeDescriptorMarker = 0xFFFF;
       
    50 	
       
    51 public:
       
    52 
       
    53 	/// @brief Creates a VirtIo Queue with a MIo object, Queue Id,
       
    54 	/// and descriptor count/ring lenght.
       
    55 	DQueue( MIo& aVirtIo, TUint aId, TUint aCount );
       
    56 	
       
    57 	/// Allocates resources
       
    58 	TInt Construct();
       
    59 		
       
    60 	virtual ~DQueue();
       
    61 	
       
    62 public: // implementation of MQueue
       
    63 	
       
    64 	virtual TInt AddBuf( const TAddrLen aScatterList[], TUint32 aOutNum, TUint32 aInNum, Token aToken);
       
    65 	
       
    66 	virtual TInt DetachBuf( Token aToken );
       
    67 	
       
    68 	virtual Token GetBuf( TUint& aLen );
       
    69 	
       
    70 	virtual void Sync();
       
    71 	
       
    72 	virtual TUint Id() 
       
    73 		{ return iId; }
       
    74 	
       
    75 	virtual TBool Restart()
       
    76 		{ return ETrue;	}
       
    77 	
       
    78 	virtual TInt Processing();
       
    79 			
       
    80 	virtual TInt Completed();	
       
    81 	
       
    82 public:	// Debug functions 
       
    83 	void DumpUsedPending();
       
    84 	
       
    85 	void DumpUsed(TUint usedSlot);
       
    86 	void DumpAvailPending();
       
    87 	
       
    88 	void DumpAvail(TUint availSlot);
       
    89 	void DumpDescs(TUint descId );
       
    90 	
       
    91 	virtual void DumpAll();
       
    92 		
       
    93 private:
       
    94 	void Wipe();
       
    95 
       
    96 	TUint Slot( TUint i )
       
    97 		{ return i & (iCount - 1); }
       
    98 				
       
    99 	void FreeDescs( TUint firstDescIdx );
       
   100 	
       
   101 	TUint8* AllocMem( TUint aSize );
       
   102 	
       
   103 	TInt AllocQueue();
       
   104 	
       
   105 	void PreInitQueue();
       
   106 	
       
   107 	void PostInitQueue();
       
   108 	
       
   109 private:
       
   110 	MIo& iVirtIo;
       
   111 	const TUint iId;
       
   112 	const TUint iCount;
       
   113 	volatile TUint iNextUsedToRead;
       
   114 	TUint iFirstEverToRead;
       
   115 	volatile TUint iNextAvailToSync;
       
   116 	TUint iFirstEverToSync;
       
   117 
       
   118 	TUint iDescSize;
       
   119 	TUint iAvailSize;
       
   120 	TUint iTokenSize;
       
   121 	TUint iUsedSize;
       
   122 	
       
   123 	TRingDesc* iDesc;
       
   124 	TRingAvail* iAvail;
       
   125 	volatile TRingUsed* iUsed;
       
   126 	TTransactionInfo* iToken;
       
   127 	
       
   128 	// managed
       
   129 	TUint8* iMem;
       
   130 	TPhysAddr iPhysAddr;
       
   131 	TBool iPhysMemReallyAllocated;
       
   132 	DPlatChunkHw* iChunk;
       
   133 	
       
   134 	};
       
   135 
       
   136 
       
   137 } // namespace VirtIo
       
   138 
       
   139 #endif