baseport/syborg/soundsc/virtio_defs.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_DEFS_H
       
    17 #define VIRTIO_DEFS_H
       
    18 
       
    19 #include <e32def.h>
       
    20 #include <kernel.h> // fot TPhysAddr
       
    21 
       
    22 /// @file virtio_defs.h
       
    23 /// most of definitions here come from VirtIo spec
       
    24 /// and was made compatible to the qemu backend (which means diverged from spec)
       
    25 
       
    26 namespace VirtIo
       
    27 {
       
    28 
       
    29 #define POW2ALIGN1(x) ((x)|((x)>>1))
       
    30 #define POW2ALIGN2(x) ((x)|((x)>>2))
       
    31 #define POW2ALIGN4(x) ((x)|((x)>>4))
       
    32 #define POW2ALIGN8(x) ((x)|((x)>>8))
       
    33 #define POW2ALIGN16(x) ((x)|((x)>>16))
       
    34 
       
    35 ///@brief Alignes \a x to the closest bigger or equal power2 value
       
    36 #define POW2ALIGN(x) (POW2ALIGN16(POW2ALIGN8(POW2ALIGN4(POW2ALIGN2(POW2ALIGN1((x)-1)))))+1)
       
    37 
       
    38 static const TUint KVirtIoAlignment = 0x1000;
       
    39 
       
    40 enum 
       
    41 	{
       
    42 	EStatusReset = 0,
       
    43 	EStatusAcknowledge = 1,
       
    44 	EStatusDriverFound = 2,
       
    45 	EStatusDriverInitialised = 4,
       
    46 	EStatusFailed = 0x80
       
    47 	};
       
    48 
       
    49 enum 
       
    50 	{
       
    51     EIoID             = 0,
       
    52     EIoDevType        = 1,
       
    53     EIoHostFeatures  = 2,
       
    54     EIoGuestFeatures = 3,
       
    55     EIoQueueBase     = 4,
       
    56     EIoQueueSize      = 5,
       
    57     EIoQueueSelect      = 6,
       
    58     EIoQueueNotify   = 7,
       
    59     EIoStatus	  	  = 8,
       
    60     EIoInterruptEnable     = 9,
       
    61     EIoInterruptStatus     = 10
       
    62 	};
       
    63 
       
    64 struct TRingDesc
       
    65 	{
       
    66 	enum 
       
    67 		{
       
    68 		EFlagNext = 1,
       
    69 		EFlagWrite = 2
       
    70 		};
       
    71 
       
    72 	TUint64 iAddr;	// physical address
       
    73 	TUint32 iLen;
       
    74 	TUint16 iFlags;
       
    75 	TUint16 iNext;
       
    76 	};
       
    77 
       
    78 struct TRingAvail
       
    79 	{
       
    80 	enum { EFlagInhibitNotifications = 1 };
       
    81 	TUint16 iFlags;
       
    82 	TUint16 iIdx;
       
    83 	TUint16 iRing[1];
       
    84 	};
       
    85 
       
    86 struct TRingUsed
       
    87 	{
       
    88 	enum { EFlagInhibitNotifications = 1 };
       
    89 	TUint16 iFlags;
       
    90 	TUint16 iIdx;
       
    91 		struct 
       
    92 		{
       
    93 		TUint32 iId;
       
    94 		TUint32 iLen;
       
    95 		} iRing[1];
       
    96 	};
       
    97 
       
    98 /// @brief Represents element of scatter gather list
       
    99 struct TAddrLen
       
   100 	{
       
   101 	TPhysAddr iAddr;
       
   102 	TUint32 iLen;
       
   103 	};
       
   104 
       
   105 /// Gives a pointer resulting with aliging \a v with \a a.
       
   106 /// @note \a a must be power of 2.
       
   107 template <typename T> T* Align( T* v, TUint a )
       
   108 	{ return (T*)( ((TUint8*)v) + ((-(TUint)v)&(a-1)) ); }
       
   109 	
       
   110 /// Gives a pointer resulting with aliging \a v with \a a.
       
   111 /// @note \a a must be power of 2.
       
   112 template <typename T> T Align( T v, TUint a )
       
   113 	{ return (v)+((-v)&(a-1)); }
       
   114 
       
   115 }
       
   116 
       
   117 #endif