kernel/eka/drivers/pbus/pbusmedia.cpp
changeset 47 46fffbe7b5a7
parent 43 96e5fb8b040d
child 62 4a8fed1c0ef6
equal deleted inserted replaced
46:0bf4040442f9 47:46fffbe7b5a7
    14 // e32\drivers\pbus\pbusmedia.cpp
    14 // e32\drivers\pbus\pbusmedia.cpp
    15 // 
    15 // 
    16 //
    16 //
    17 
    17 
    18 #include <drivers/pbusmedia.h>
    18 #include <drivers/pbusmedia.h>
       
    19 #include "OstTraceDefinitions.h"
       
    20 #ifdef OST_TRACE_COMPILER_IN_USE
       
    21 #include "locmedia_ost.h"
       
    22 #ifdef __VC32__
       
    23 #pragma warning(disable: 4127) // disabling warning "conditional expression is constant"
       
    24 #endif
       
    25 #include "pbusmediaTraces.h"
       
    26 #endif
    19 
    27 
    20 void mediaCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2)
    28 void mediaCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2)
    21 	{
    29 	{
       
    30 	OstTraceFunctionEntry0( MEDIACALLBACK_ENTRY );
    22 	DPBusPrimaryMedia* pM=(DPBusPrimaryMedia*)aPtr;
    31 	DPBusPrimaryMedia* pM=(DPBusPrimaryMedia*)aPtr;
    23 	__KTRACE_OPT(KLOCDRV,Kern::Printf("mediaCallBack media %d, reason %d, a1=0x%x, a2=0x%x",pM->iMediaId,aReason,a1,a2));
    32 	__KTRACE_OPT(KLOCDRV,Kern::Printf("mediaCallBack media %d, reason %d, a1=0x%x, a2=0x%x",pM->iMediaId,aReason,a1,a2));
       
    33 	OstTraceExt4( TRACE_INTERNALS, MEDIACALLBACK, "aPtr=0x%x; aReason=%d; a1=0x%x; a2=0x%x", ( TUint )( aPtr ), aReason, ( TUint )( a1 ), ( TUint )( a2 ) );
       
    34 	
    24 	switch (aReason)
    35 	switch (aReason)
    25 		{
    36 		{
    26 		case TPBusCallBack::EPBusStateChange:
    37 		case TPBusCallBack::EPBusStateChange:
    27 			pM->PBusStateChange((TInt)a1,(TInt)a2);
    38 			pM->PBusStateChange((TInt)a1,(TInt)a2);
    28 			break;
    39 			break;
    29 		}
    40 		}
       
    41 	OstTraceFunctionExit0( MEDIACALLBACK_EXIT );
    30 	}
    42 	}
    31 
    43 
    32 /**
    44 /**
    33   Constructor for DPBusPrimaryMedia. Initializes the iSocket with aSocket.
    45   Constructor for DPBusPrimaryMedia. Initializes the iSocket with aSocket.
    34   @param aSocket	Pointer to DPBusSocket object
    46   @param aSocket	Pointer to DPBusSocket object
    36   */
    48   */
    37 
    49 
    38 DPBusPrimaryMedia::DPBusPrimaryMedia(DPBusSocket* aSocket)
    50 DPBusPrimaryMedia::DPBusPrimaryMedia(DPBusSocket* aSocket)
    39 	:	iSocket(aSocket)
    51 	:	iSocket(aSocket)
    40 	{
    52 	{
       
    53 	OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_DPBUSPRIMARYMEDIA_ENTRY, this );
    41 	}
    54 	}
    42 /**
    55 /**
    43   This function install a media call back for a removable media device.
    56   This function install a media call back for a removable media device.
    44   @param aDevice	Local media ID.
    57   @param aDevice	Local media ID.
    45   @param aMediaId	Media Id (unique for a media subsystem)
    58   @param aMediaId	Media Id (unique for a media subsystem)
    48           otherwise one of the other system wide error codes.
    61           otherwise one of the other system wide error codes.
    49   @see DPrimaryMediaBase::Create()
    62   @see DPrimaryMediaBase::Create()
    50   */
    63   */
    51 TInt DPBusPrimaryMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt aLastMediaId)
    64 TInt DPBusPrimaryMedia::Create(TMediaDevice aDevice, TInt aMediaId, TInt aLastMediaId)
    52 	{
    65 	{
       
    66 	OstTraceExt4(TRACE_FLOW, DPBUSPRIMARYMEDIA_CREATE_ENTRY ,"DPBusPrimaryMedia::Create;aDevice=%d;aMediaId=%d;aLastMediaId=%d;this=%x", (TInt) aDevice, aMediaId, aLastMediaId, (TUint) this);
       
    67 	
    53 	// Permanently install a media call back if for a removable media device
    68 	// Permanently install a media call back if for a removable media device
    54 	TInt r=KErrArgument;
    69 	TInt r=KErrArgument;
    55 	iPBusState=EPBusCardAbsent;
    70 	iPBusState=EPBusCardAbsent;
    56 	if (__IS_REMOVABLE(aDevice))
    71 	if (__IS_REMOVABLE(aDevice))
    57 		{
    72 		{
    65 			iBusCallBack.Add();
    80 			iBusCallBack.Add();
    66 			iPBusState=iSocket->State();
    81 			iPBusState=iSocket->State();
    67 			iMsgQ.Receive();
    82 			iMsgQ.Receive();
    68 			}
    83 			}
    69 		}
    84 		}
       
    85 	OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_CREATE_EXIT, this, r );
    70 	return r;
    86 	return r;
    71 	}
    87 	}
    72 
    88 
    73 /**
    89 /**
    74   Checks the PBUS state.
    90   Checks the PBUS state.
    76           KErrNotReady if card is absent.
    92           KErrNotReady if card is absent.
    77   @see TPBusState
    93   @see TPBusState
    78   */
    94   */
    79 TInt DPBusPrimaryMedia::QuickCheckStatus()
    95 TInt DPBusPrimaryMedia::QuickCheckStatus()
    80 	{
    96 	{
       
    97 	OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS_ENTRY, this );
    81 	TInt r=KErrNone;
    98 	TInt r=KErrNone;
    82 	if (iSocket && iSocket->State()==EPBusCardAbsent)
    99 	if (iSocket && iSocket->State()==EPBusCardAbsent)
    83 		r=KErrNotReady;
   100 		r=KErrNotReady;
    84 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia::QuickCheckStatus media %d returns %d",iMediaId,r));
   101 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia::QuickCheckStatus media %d returns %d",iMediaId,r));
       
   102 	OstTraceExt2(TRACE_INTERNALS, DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS, "iMediaId=%d; retval=%d",iMediaId,r);
       
   103 	OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_QUICKCHECKSTATUS_EXIT, this );
    85 	return r;
   104 	return r;
    86 	}
   105 	}
    87 
   106 
    88 /**
   107 /**
    89   This function is called by the local media device driver to force a remount of the media device.
   108   This function is called by the local media device driver to force a remount of the media device.
    92 		  otherwise one of the other system wide error codes. 
   111 		  otherwise one of the other system wide error codes. 
    93   @see TForceMediaChangeFlags
   112   @see TForceMediaChangeFlags
    94   */
   113   */
    95 TInt DPBusPrimaryMedia::ForceMediaChange(TInt aFlags)
   114 TInt DPBusPrimaryMedia::ForceMediaChange(TInt aFlags)
    96 	{
   115 	{
       
   116 	OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_ENTRY, this );
    97 	if ((aFlags != KMediaRemountForceMediaChange) || (iPBusState == EPBusCardAbsent))
   117 	if ((aFlags != KMediaRemountForceMediaChange) || (iPBusState == EPBusCardAbsent))
    98 		{
   118 		{
    99 		TInt pbusState = iPBusState;
   119 		TInt pbusState = iPBusState;
   100 		
   120 		
   101 		// This should ensure NotifyMediaChange() is called for ALL primary media attached to this socket
   121 		// This should ensure NotifyMediaChange() is called for ALL primary media attached to this socket
   105 		// unusable state which might cause the next request to fail, so power down the socket to be safe
   125 		// unusable state which might cause the next request to fail, so power down the socket to be safe
   106 		iSocket->ResetSocket(EFalse);
   126 		iSocket->ResetSocket(EFalse);
   107 
   127 
   108 		iSocket->ChangeState(pbusState == EPBusCardAbsent ? EPBusCardAbsent : EPBusOff, KErrNotReady);
   128 		iSocket->ChangeState(pbusState == EPBusCardAbsent ? EPBusCardAbsent : EPBusOff, KErrNotReady);
   109 
   129 
       
   130 		OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_EXIT1, this, KErrCompletion );
   110 		return KErrCompletion;
   131 		return KErrCompletion;
   111 		}
   132 		}
   112 	
   133 	
   113 	iSocket->ForceMediaChange();
   134 	iSocket->ForceMediaChange();
       
   135 	OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_FORCEMEDIACHANGE_EXIT2, this, KErrNone );
   114 	return KErrNone;
   136 	return KErrNone;
   115 	}
   137 	}
   116 
   138 
   117 /**
   139 /**
   118   Called by clients to power up the PBUS.
   140   Called by clients to power up the PBUS.
   120   		  otherwise one of the other system wide error codes.
   142   		  otherwise one of the other system wide error codes.
   121   @see  DPBusSocket::PowerUp()
   143   @see  DPBusSocket::PowerUp()
   122   */
   144   */
   123 TInt DPBusPrimaryMedia::InitiatePowerUp()
   145 TInt DPBusPrimaryMedia::InitiatePowerUp()
   124 	{
   146 	{
   125 	return iSocket->PowerUp();
   147 	OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_INITIATEPOWERUP_ENTRY, this );
       
   148 	TInt r = iSocket->PowerUp();  
       
   149 	OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_INITIATEPOWERUP_EXIT, this, r );
       
   150 	return r;
   126 	}
   151 	}
   127 
   152 
   128 /**
   153 /**
   129   Flags the media driver as entering a critical part of its processing.
   154   Flags the media driver as entering a critical part of its processing.
   130   @return KErrNone if successful,
   155   @return KErrNone if successful,
   131   		  otherwise one of the other system wide error codes.
   156   		  otherwise one of the other system wide error codes.
   132   @see DPBusSocket::InCritical()
   157   @see DPBusSocket::InCritical()
   133   */
   158   */
   134 TInt DPBusPrimaryMedia::DoInCritical()
   159 TInt DPBusPrimaryMedia::DoInCritical()
   135 	{
   160 	{
   136 	return iSocket->InCritical();
   161 	OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DOINCRITICAL_ENTRY, this );
       
   162 	TInt r = iSocket->InCritical(); 
       
   163 	OstTraceFunctionExitExt( DPBUSPRIMARYMEDIA_DOINCRITICAL_EXIT, this, r );
       
   164 	return r;
   137 	}
   165 	}
   138 
   166 
   139 /**
   167 /**
   140   Flags the media driver as leaving a critical part of its processing.
   168   Flags the media driver as leaving a critical part of its processing.
   141   @return KErrNone if successful, 
   169   @return KErrNone if successful, 
   142   		  otherwise one of the other system wide error codes.
   170   		  otherwise one of the other system wide error codes.
   143   @see DPBusSocket::EndInCritical()
   171   @see DPBusSocket::EndInCritical()
   144   */
   172   */
   145 void DPBusPrimaryMedia::DoEndInCritical()
   173 void DPBusPrimaryMedia::DoEndInCritical()
   146 	{
   174 	{
       
   175 	OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DOENDINCRITICAL_ENTRY, this );
   147 	iSocket->EndInCritical();
   176 	iSocket->EndInCritical();
       
   177 	OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DOENDINCRITICAL_EXIT, this );
   148 	}
   178 	}
   149 
   179 
   150 /**
   180 /**
   151   Sets the incremental value of current consumption to aCurrent.
   181   Sets the incremental value of current consumption to aCurrent.
   152   @param aCurrent Delta Current in Milliamps.
   182   @param aCurrent Delta Current in Milliamps.
   153   @see DPBusSocket::DeltaCurrentConsumption()
   183   @see DPBusSocket::DeltaCurrentConsumption()
   154   */
   184   */
   155 void DPBusPrimaryMedia::DeltaCurrentConsumption(TInt aCurrent)
   185 void DPBusPrimaryMedia::DeltaCurrentConsumption(TInt aCurrent)
   156 	{
   186 	{
       
   187 	OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_DELTACURRENTCONSUMPTION_ENTRY, this );
   157 	iSocket->DeltaCurrentConsumption(aCurrent);
   188 	iSocket->DeltaCurrentConsumption(aCurrent);
       
   189 	OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DELTACURRENTCONSUMPTION_EXIT, this );
   158 	}
   190 	}
   159 
   191 
   160 /**
   192 /**
   161   Gets the default drive capability/attributes.
   193   Gets the default drive capability/attributes.
   162   @param aCaps	A reference to a client-supplied TLocalDriveCapsV2 class to be filled by this function.
   194   @param aCaps	A reference to a client-supplied TLocalDriveCapsV2 class to be filled by this function.
   163   @see TLocalDriveCapsV2
   195   @see TLocalDriveCapsV2
   164   @see TMediaType
   196   @see TMediaType
   165   */
   197   */
   166 void DPBusPrimaryMedia::DefaultDriveCaps(TLocalDriveCapsV2& aCaps)
   198 void DPBusPrimaryMedia::DefaultDriveCaps(TLocalDriveCapsV2& aCaps)
   167 	{
   199 	{
       
   200 	OstTraceFunctionEntry1( DPBUSPRIMARYMEDIA_DEFAULTDRIVECAPS_ENTRY, this );
   168 	// aCaps is zeroed beforehand
   201 	// aCaps is zeroed beforehand
   169 	aCaps.iType = EMediaNotPresent;
   202 	aCaps.iType = EMediaNotPresent;
   170 	aCaps.iDriveAtt = KDriveAttLocal|KDriveAttRemovable;
   203 	aCaps.iDriveAtt = KDriveAttLocal|KDriveAttRemovable;
       
   204 	OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_DEFAULTDRIVECAPS_EXIT, this );
   171 	}
   205 	}
   172 
   206 
   173 /**
   207 /**
   174   Checks whether it is a removable media device or not.
   208   Checks whether it is a removable media device or not.
   175   @param aSocketNum	This will be updated with socket number
   209   @param aSocketNum	This will be updated with socket number
   176   @return ETrue if Removable Device, EFalse if the device is Non-Removable.
   210   @return ETrue if Removable Device, EFalse if the device is Non-Removable.
   177   */
   211   */
   178 TBool DPBusPrimaryMedia::IsRemovableDevice(TInt& aSocketNum)
   212 TBool DPBusPrimaryMedia::IsRemovableDevice(TInt& aSocketNum)
   179 	{
   213 	{
       
   214 	OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_ISREMOVABLEDEVICE_ENTRY, this );
   180 	aSocketNum=iSocket->iSocketNumber;
   215 	aSocketNum=iSocket->iSocketNumber;
       
   216 	OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_ISREMOVABLEDEVICE_EXIT, this );
   181 	return(ETrue);
   217 	return(ETrue);
   182 	}
   218 	}
   183 	
   219 	
   184 void DPBusPrimaryMedia::PBusStateChange(TInt aState, TInt anError)
   220 void DPBusPrimaryMedia::PBusStateChange(TInt aState, TInt anError)
   185 	{
   221 	{
       
   222 	OstTraceFunctionEntryExt( DPBUSPRIMARYMEDIA_PBUSSTATECHANGE_ENTRY, this );
   186 	// receive power down and media change notifications
   223 	// receive power down and media change notifications
   187 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia(%d)::PBusStateChange state %d, err %d",iMediaId,aState,anError));
   224 	__KTRACE_OPT(KLOCDRV,Kern::Printf("DPBusPrimaryMedia(%d)::PBusStateChange state %d, err %d",iMediaId,aState,anError));
       
   225 	OstTraceExt3(TRACE_INTERNALS, DPBUSPRIMARYMEDIA_PBUSSTATECHANGE, "iMediaId=%d; aState=%d; anError=%d", iMediaId,aState,anError);
   188 	if (aState!=iPBusState)
   226 	if (aState!=iPBusState)
   189 		{
   227 		{
   190 		TInt oldState = iPBusState;
   228 		TInt oldState = iPBusState;
   191 		iPBusState=aState;
   229 		iPBusState=aState;
   192 		switch (aState)
   230 		switch (aState)
   241 				break;
   279 				break;
   242 			default:
   280 			default:
   243 				break;
   281 				break;
   244 			}
   282 			}
   245 		}
   283 		}
   246 	}
   284 	OstTraceFunctionExit1( DPBUSPRIMARYMEDIA_PBUSSTATECHANGE_EXIT, this );
   247 
   285 	}
       
   286