guestrendering/guestvideodriver/ldd/src/virtualvideohwinterface.cpp
branchbug235_bringup_0
changeset 1 d8d95053303a
child 2 e8ccf068ac7f
equal deleted inserted replaced
0:013716db5021 1:d8d95053303a
       
     1 /*
       
     2  * =============================================================================
       
     3  *  Name        : virtualvideohwinterface.cpp
       
     4  *  Part of     : 
       
     5  *  Description : Implementation file for the class DVirtualVideoHwInterface.
       
     6  *  Version     : %version:3 %
       
     7  *
       
     8  *  Copyright © 2002-2009 Nokia. All rights reserved.
       
     9  *  This material, including documentation and any related
       
    10  *  computer programs, is protected by copyright controlled by
       
    11  *  Nokia. All rights are reserved. Copying, including
       
    12  *  reproducing, storing, adapting or translating, any
       
    13  *  or all of this material requires the prior written consent of
       
    14  *  Nokia. This material also contains confidential
       
    15  *  information which may not be disclosed to others without the
       
    16  *  prior written consent of Nokia.
       
    17  * =============================================================================
       
    18  */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <platform.h>
       
    23 #include <kern_priv.h>
       
    24 
       
    25 #include "virtualvideointerfaceconstants.h"
       
    26 #include "virtualvideohwinterface.h"
       
    27 #include "virtualvideotracing.h"
       
    28 
       
    29 
       
    30 // CONSTANTS
       
    31 
       
    32 _LIT( KVirtualVideoHwInterfacePanic, "DVirtualVideoHwInterface" );
       
    33 
       
    34 // ============================ LOCAL DATA TYPES ===============================
       
    35 
       
    36 // Register offsets for playback and recording channels
       
    37 // Note: The orders of these must match the order of enumarations
       
    38 const TLinAddr KRegisterOffsets[] =
       
    39     {
       
    40     VVI_R_ID,
       
    41     VVI_R_IRQ_ENABLE,
       
    42     VVI_R_IRQ_STATUS,
       
    43     VVI_R_COMMAND,
       
    44     VVI_R_PARAMETER_LOAD,
       
    45     VVI_R_ERROR,
       
    46     VVI_R_INPUT_BUFFER_TAIL,
       
    47     VVI_R_INPUT_BUFFER_HEAD,
       
    48     VVI_R_INPUT_BUFFER_READ_COUNT,
       
    49     VVI_R_INPUT_BUFFER_WRITE_COUNT,
       
    50     VVI_R_INPUT_BUFFER_MAX_TAIL,
       
    51     VVI_R_REQUEST_ID
       
    52     };
       
    53 #define ASSERT_PANIC(c,p) __ASSERT_DEBUG(c,Kern::PanicCurrentThread(KVirtualVideoHwInterfacePanic,p));
       
    54 
       
    55 // ============================ LOCAL FUNCTIONS ================================
       
    56 
       
    57 // Get register offset for certain register range and register
       
    58 inline TLinAddr RegisterOffset( DVirtualVideoHwInterface::TRegister aRegister )
       
    59     {
       
    60     return KRegisterOffsets[aRegister];
       
    61     }
       
    62 
       
    63 // ============================ MEMBER FUNCTIONS ===============================
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // DVirtualVideoHwInterface::DVirtualVideoHwInterface
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 DVirtualVideoHwInterface::DVirtualVideoHwInterface()
       
    70     {
       
    71     iInputParametersMemoryChunk = NULL;
       
    72     iOutputParametersMemoryChunk = NULL;
       
    73     iRegisterMemoryChunk = NULL;
       
    74     }
       
    75 
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // DVirtualVideoHwInterface::~DVirtualVideoHwInterface
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 DVirtualVideoHwInterface::~DVirtualVideoHwInterface()
       
    82     {
       
    83     // Enter critical section
       
    84     NKern::ThreadEnterCS();
       
    85 
       
    86     if ( iInputParametersMemoryChunk )
       
    87         {
       
    88         Kern::ChunkClose( iInputParametersMemoryChunk );
       
    89         }
       
    90 
       
    91     if ( iOutputParametersMemoryChunk )
       
    92         {
       
    93         Kern::ChunkClose( iOutputParametersMemoryChunk );
       
    94         }
       
    95 
       
    96     if ( iRegisterMemoryChunk )
       
    97         {
       
    98         Kern::ChunkClose( iRegisterMemoryChunk );
       
    99         }
       
   100 
       
   101     iInputParametersMemoryChunk = NULL;
       
   102     iOutputParametersMemoryChunk = NULL;
       
   103     iRegisterMemoryChunk = NULL;
       
   104 
       
   105     // Leave critical section
       
   106     NKern::ThreadLeaveCS();
       
   107     }
       
   108 
       
   109 TInt DVirtualVideoHwInterface::InitParametersInputMemory()
       
   110     {
       
   111     return InitPhysicalMemory( VVI_PARAMETERS_INPUT_BASE_ADDRESS, 
       
   112             VVI_PARAMETERS_INPUT_MEMORY_SIZE, iInputParametersMemoryChunk, 
       
   113             iInputParametersChunkKernelAddress );    
       
   114     }
       
   115 
       
   116 TInt DVirtualVideoHwInterface::InitParametersOutputMemory()
       
   117     {
       
   118     return InitPhysicalMemory( VVI_PARAMETERS_OUTPUT_BASE_ADDRESS, 
       
   119             VVI_PARAMETERS_OUTPUT_MEMORY_SIZE, iOutputParametersMemoryChunk, 
       
   120             iOutputParametersChunkKernelAddress );    
       
   121     }
       
   122 
       
   123 TInt DVirtualVideoHwInterface::InitRegisterMemory()
       
   124     {
       
   125     return InitPhysicalMemory( VVI_REGISTERS_BASE_ADDRESS, 
       
   126             VVI_REGISTERS_MEMORY_SIZE, iRegisterMemoryChunk, 
       
   127             iRegisterChunkKernelAddress );        
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // DVirtualVideoHwInterface::InitPhysicalMemory
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TInt DVirtualVideoHwInterface::InitPhysicalMemory( TUint32 aPhysicalAddress, 
       
   135         TInt aMaxSize, DChunk*& aChunk, TLinAddr& aLinAddr )
       
   136     {
       
   137     TInt error = KErrNoMemory;
       
   138     TChunkCreateInfo info;
       
   139     info.iType = TChunkCreateInfo::ESharedKernelSingle;
       
   140     info.iMaxSize = aMaxSize;
       
   141 	info.iMapAttr = EMapAttrFullyBlocking;
       
   142     info.iOwnsMemory = EFalse;
       
   143     info.iDestroyedDfc = NULL;
       
   144     DChunk* chunk = NULL;
       
   145     TUint32 mapAttr = 0;
       
   146     TLinAddr chunkKernelAddress = 0;
       
   147     
       
   148     // Enter critical section while creating the chunk and commiting memory
       
   149     NKern::ThreadEnterCS();
       
   150 
       
   151     error = Kern::ChunkCreate( info, chunk, chunkKernelAddress, mapAttr );
       
   152     if ( !error )
       
   153         {
       
   154         error = Kern::ChunkCommitPhysical(
       
   155             chunk, 0, aMaxSize, aPhysicalAddress );
       
   156         if ( error )
       
   157             {
       
   158             Kern::ChunkClose( chunk );
       
   159             }
       
   160         else
       
   161             {
       
   162             // Physical memory has been successfully committed to chunk
       
   163             aChunk = chunk; 
       
   164             aLinAddr = chunkKernelAddress;
       
   165             }
       
   166         }
       
   167     chunk = NULL;
       
   168 
       
   169     // Leave critical section
       
   170     NKern::ThreadLeaveCS();
       
   171     
       
   172     VVHW_TRACE("DVirtualVideoHwInterface::InitPhysicalMemory return %d", error);
       
   173     return error;
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // -----------------------------------------------------------------------------
       
   178 // DVirtualVideoHwInterface::EnableInterrupts
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void DVirtualVideoHwInterface::EnableInterrupts( TUint32 aInterruptBitField )
       
   182     {
       
   183     SetRegisterValue( ERegIrqEnable, aInterruptBitField );
       
   184     }
       
   185 
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // DVirtualVideoHwInterface::GetInterruptEnabledState
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 void DVirtualVideoHwInterface::GetInterruptEnabledState( TUint32& aInterruptBitField )
       
   192     {
       
   193     GetRegisterValue( ERegIrqEnable, aInterruptBitField );
       
   194     }
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // DVirtualVideoHwInterface::GetInterruptStatus
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 void DVirtualVideoHwInterface::GetInterruptStatus( TUint32& aInterruptBitField )
       
   202     {
       
   203     GetRegisterValue( ERegIrqStatus, aInterruptBitField );
       
   204     }
       
   205 
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // DVirtualVideoHwInterface::ResetInterruptStatus
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void DVirtualVideoHwInterface::ResetInterruptStatus( TUint32 aInterruptBitField )
       
   212     {
       
   213     SetRegisterValue( ERegIrqStatus, aInterruptBitField );
       
   214     }
       
   215 
       
   216 
       
   217 // DVirtualVideoHwInterface::IssueCommand
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void DVirtualVideoHwInterface::IssueCommand( TUint32 aCommand )
       
   221     {
       
   222     SetRegisterValue( ERegCommand, aCommand );
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // DVirtualVideoHwInterface::GetRegisterValue
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 void DVirtualVideoHwInterface::GetRegisterValue(
       
   230     TRegister aRegister,
       
   231     TUint32& aValue )
       
   232     {
       
   233     if ( iRegisterMemoryChunk )
       
   234         {
       
   235         TLinAddr offset = RegisterOffset( aRegister );
       
   236         TUint32* ptr = reinterpret_cast<TUint32*>( iRegisterChunkKernelAddress + offset );
       
   237         aValue = *ptr;
       
   238         }
       
   239     else
       
   240         {
       
   241         Kern::PanicCurrentThread( KVirtualVideoHwInterfacePanic, KErrNotReady );
       
   242         }
       
   243     }
       
   244 
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // DVirtualVideoHwInterface::SetRegisterValue
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void DVirtualVideoHwInterface::SetRegisterValue(
       
   251     TRegister aRegister,
       
   252     TUint32 aValue )
       
   253     {
       
   254     if ( iRegisterMemoryChunk )
       
   255         {
       
   256         TLinAddr offset = RegisterOffset( aRegister );
       
   257         TUint32* ptr = reinterpret_cast<TUint32*>( iRegisterChunkKernelAddress + offset );
       
   258         *ptr = aValue;
       
   259         }
       
   260     else
       
   261         {
       
   262         Kern::PanicCurrentThread( KVirtualVideoHwInterfacePanic, KErrNotReady );
       
   263         }
       
   264     }
       
   265 
       
   266 
       
   267 // End of file