guestrendering/guestvideodriver/ldd/src/virtualvideohwchannel.cpp
branchbug235_bringup_0
changeset 51 4f400a6ea71f
parent 49 3b4f7e9d873f
child 52 39e5f73667ba
equal deleted inserted replaced
49:3b4f7e9d873f 51:4f400a6ea71f
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Virtual Video Hardware Channel implementation
       
    15 
       
    16 #include <kernel/kernel.h>
       
    17 #include <assp.h>
       
    18 
       
    19 #include <graphics/virtualvideohwchannel.h>
       
    20 #include <graphics/virtualvideohwdeviceinterface.h>
       
    21 #include <graphics/guestvideodriverprotocol.h>
       
    22 #include <graphics/guestvideodrivercommon.h>
       
    23 #include <graphics/devicereqhandler.h>
       
    24 
       
    25 #include "serializedfunctioncall.h"
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // DVirtualVideoHwChannel::DVirtualVideoHwChannel
       
    29 // -----------------------------------------------------------------------------
       
    30 //
       
    31 DVirtualVideoHwChannel::DVirtualVideoHwChannel(
       
    32     MVirtualVideoHwDeviceInterface& aDeviceInterface,
       
    33     DVirtualVideoHwInterface& aHwInterface,
       
    34     DDeviceReqHandler& aDeviceReqHandler,
       
    35     TDfcQue* aQueue ) :
       
    36     iDeviceInterface( aDeviceInterface ),
       
    37     iHwInterface( aHwInterface ),
       
    38     iReqHandler( aDeviceReqHandler )
       
    39     {    
       
    40     SetDfcQ( aQueue );
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // DVirtualVideoHwChannel::~DVirtualVideoHwChannel
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 DVirtualVideoHwChannel::~DVirtualVideoHwChannel()
       
    48     {
       
    49     // Enter critical section
       
    50     NKern::ThreadEnterCS();
       
    51     iMsgQ.CompleteAll( KErrAbort );
       
    52     // Leave critical section
       
    53     NKern::ThreadLeaveCS();
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // DVirtualVideoHwChannel::Request
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 TInt DVirtualVideoHwChannel::Request( TInt aReqNo, TAny *a1, TAny *a2 )
       
    61     {
       
    62     TInt result = DLogicalChannel::Request( aReqNo, a1, a2 );
       
    63     return result;
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // DVirtualVideoHwChannel::HandleMsg
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 void DVirtualVideoHwChannel::HandleMsg( TMessageBase* aMsgRequest )
       
    71     {
       
    72     DThread* userThread = aMsgRequest->Client();
       
    73     TThreadMessage& msg = *(TThreadMessage*)aMsgRequest;
       
    74     // Default error condition
       
    75     TInt err = KErrNone; 
       
    76 
       
    77     if ( msg.iValue == ECloseMsg )
       
    78         {
       
    79         iReqHandler.HandleClientShutdown( userThread->iOwningProcess->iId, userThread->iId );
       
    80         msg.Complete( KErrNone, EFalse );
       
    81         return;
       
    82         }
       
    83     
       
    84     if ( msg.iValue < 0 )
       
    85         {
       
    86         TRequestStatus* status = (TRequestStatus*)msg.Ptr0();
       
    87         err = DoRequest( userThread, ~msg.iValue, status, msg.Ptr1(), msg.Ptr2() );
       
    88         if( err != KErrNone )
       
    89             {
       
    90             Kern::RequestComplete( userThread, status, err );
       
    91             }
       
    92         err = KErrNone;
       
    93         }
       
    94     else
       
    95         {
       
    96         err = DoControl( userThread, msg.iValue, msg.Ptr0(), msg.Ptr1() );
       
    97         }
       
    98 
       
    99     msg.Complete( err, ETrue );
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // DVirtualVideoHwChannel::DoCreate
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 TInt DVirtualVideoHwChannel::DoCreate( TInt /*aUnit*/, const TDesC* /*aInfo*/, const TVersion& aVer )
       
   107     {
       
   108     using namespace GuestVideoDriver;
       
   109     TInt err = KErrNone;
       
   110     
       
   111     if ( ! Kern::QueryVersionSupported(
       
   112             TVersion(
       
   113                     KMajorVer,
       
   114                     KMinorVer,
       
   115                     KBuildVer ),
       
   116             aVer ) )
       
   117         {
       
   118         return KErrNotSupported; 
       
   119         }
       
   120 
       
   121     iMsgQ.Receive();
       
   122     return err;
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // DVirtualVideoHwChannel::DoRequest
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 TInt DVirtualVideoHwChannel::DoRequest(
       
   130         DThread*& aUserThread,
       
   131         TInt aReqNo,
       
   132         TRequestStatus* aStatus,
       
   133         TAny* a1,
       
   134         TAny* a2 )
       
   135     {
       
   136     using namespace GuestVideoDriver;
       
   137 
       
   138     // Default error condition
       
   139     TInt err = KErrNone; 
       
   140 
       
   141     switch( aReqNo )
       
   142         {
       
   143         case ERequestExecuteCommand:
       
   144             {
       
   145             err = iReqHandler.HandleExecuteAsync(
       
   146                     aUserThread,
       
   147                     aStatus,
       
   148                     a1);
       
   149             break;
       
   150             }
       
   151         case ERequestLoadCommands:
       
   152             {
       
   153             err = iReqHandler.HandleLoadCommands(
       
   154                     aUserThread, 
       
   155                     aStatus,
       
   156                     a1 );
       
   157             break;
       
   158             }
       
   159         default:
       
   160             {
       
   161             // Other requests are not supported
       
   162             err = KErrNotSupported;
       
   163             }
       
   164             break;
       
   165         }
       
   166     return err;
       
   167     }
       
   168 
       
   169 
       
   170 
       
   171 #ifdef FAISALMEMON_S4_SGIMAGE
       
   172 TInt DVirtualVideoHwChannel::GetSgImageMetaData(TSgImageMetaData& aSgInfo, const TUint64 aId)
       
   173 	{
       
   174 	VVHW_TRACE("DVirtualVideoHwChannel::OpenSgImageMetaData 0x%lx", aId );
       
   175 	DSgResource* sgResource = NULL;
       
   176 	TInt metaDataErr = SgExtension::FindAndOpenResource( aId, sgResource );//Open the sgimage resource
       
   177 	
       
   178 	if ( metaDataErr == KErrNone )
       
   179 		{
       
   180 		TPckgBuf<TSgImageMetaData> metaDataPckg;
       
   181 		
       
   182 		metaDataErr = sgResource->GetMetaData( metaDataPckg );
       
   183 		if ( metaDataErr == KErrNone )
       
   184 			{
       
   185 			aSgInfo = metaDataPckg();
       
   186 			}
       
   187 
       
   188 		sgResource->Close();
       
   189 		}
       
   190 	return metaDataErr;
       
   191 	}
       
   192 #endif
       
   193 
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // DVirtualVideoHwChannel::DoControl
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 TInt DVirtualVideoHwChannel::DoControl(
       
   200         DThread*& aUserThread,
       
   201         TInt aFunction,
       
   202         TAny* a1,
       
   203         TAny* a2 )
       
   204     {
       
   205     using namespace GuestVideoDriver;
       
   206     
       
   207     // Default error condition
       
   208     TInt err = KErrNone; 
       
   209 
       
   210     switch( aFunction )
       
   211         {
       
   212         case ERequestMapAddress:
       
   213             {
       
   214             TPckgBuf<TInt> handle;
       
   215             err = Kern::ThreadDesRead( aUserThread, a1, handle, 0, 0 );
       
   216             if ( KErrNone == err )
       
   217                 {
       
   218                 DChunk* chunk = Kern::OpenSharedChunk( aUserThread, handle(), EFalse );
       
   219                 if ( chunk )
       
   220                     {
       
   221                     TLinAddr kernelAddress;
       
   222                     TUint32 mapAttr;
       
   223                     TUint32 physicalAddress( 0 );
       
   224                     TInt ret = Kern::ChunkPhysicalAddress( chunk, 0, chunk->Size(), 
       
   225                             kernelAddress, mapAttr, physicalAddress );
       
   226                     
       
   227                     TPckgC<TUint32> address( physicalAddress );
       
   228                     err = Kern::ThreadDesWrite( aUserThread, a2, address, 0, 0, aUserThread );
       
   229                     Kern::ChunkClose( chunk );
       
   230                     chunk = NULL;
       
   231                     }
       
   232                 else
       
   233                     {
       
   234                     err = KErrGeneral;
       
   235                     }
       
   236                 }
       
   237             break;
       
   238             }
       
   239         case ERequestSurfaceBufferBaseAddress:
       
   240             {
       
   241             TPhysAddr physicalAddress(0);
       
   242 			physicalAddress = iHwInterface.GetSurfaceBufferBase();
       
   243             TPckgC<TPhysAddr> address(physicalAddress);
       
   244             err = Kern::ThreadDesWrite(aUserThread, a1, address, 0, 0, aUserThread);
       
   245             break;
       
   246             }
       
   247 #ifdef FAISALMEMON_S4_SGIMAGE
       
   248         case ERequestSgHandles:
       
   249             {
       
   250             VVHW_TRACE("DVirtualVideoHwChannel::DoControl - ERequestSgHandles" );
       
   251             TPckgBuf<TUint64> sgId;
       
   252             err = Kern::ThreadDesRead( aUserThread, a1, sgId, 0, 0 );
       
   253             if( KErrNone == err )
       
   254                 {
       
   255 				TSgImageMetaData sgInfo;
       
   256 				err = GetSgImageMetaData( sgInfo, sgId());
       
   257 				if ( KErrNone == err )
       
   258 					{
       
   259 					// package the handles into 64-bit value, since there's only one parameter (a2) available
       
   260 					TUint64 sgHandles = (((TUint64)sgInfo.iPbufferHandle)&0xFFFFFFFF) + (((TUint64)sgInfo.iVGImageHandle)<<32);
       
   261 					TPckg<TUint64> handles(sgHandles);
       
   262 					err = Kern::ThreadDesWrite( aUserThread, a2, handles, 0, 0);
       
   263 					if(err)
       
   264 					    VVHW_TRACE("DVirtualVideoHwChannel::DoControl - ThreadDesWrite error=%d", err);
       
   265 					}
       
   266 				else
       
   267 					{
       
   268 					VVHW_TRACE("DVirtualVideoHwChannel::DoControl - OpenSgImageMetaData failed" );
       
   269 					}
       
   270                 }
       
   271             else
       
   272             	{
       
   273 				VVHW_TRACE("DVirtualVideoHwChannel::DoControl - ThreadDesRead err=%i", err );
       
   274                 }
       
   275             break;
       
   276             }
       
   277 #endif
       
   278         default:
       
   279             {
       
   280             // Other functions are not supported
       
   281             err = KErrNotSupported;
       
   282             }
       
   283             break;
       
   284         }
       
   285 
       
   286     return err;
       
   287     }
       
   288