kernel/eka/drivers/medmmc/medmmc.cpp
changeset 293 0659d0e1a03c
parent 287 ddfd5aa0d58f
child 300 1d28c8722707
equal deleted inserted replaced
291:206a6eaaeb71 293:0659d0e1a03c
    38 
    38 
    39 #ifndef BTRACE_PAGING_MEDIA
    39 #ifndef BTRACE_PAGING_MEDIA
    40 	#undef BTraceContext8
    40 	#undef BTraceContext8
    41 	#define BTraceContext8(aCategory,aSubCategory,a1,a2) 
    41 	#define BTraceContext8(aCategory,aSubCategory,a1,a2) 
    42 #endif	// BTRACE_PAGING_MEDIA
    42 #endif	// BTRACE_PAGING_MEDIA
       
    43 
       
    44 // Enables reliable writes for system drives
       
    45 #define _ENABLE_EMMC_RELIABLE_WRITE_
    43 
    46 
    44 // Enable this macro to debug cache: 
    47 // Enable this macro to debug cache: 
    45 // NB The greater the number of blocks, the slower this is...
    48 // NB The greater the number of blocks, the slower this is...
    46 //#define _DEBUG_CACHE
    49 //#define _DEBUG_CACHE
    47 #ifdef _DEBUG_CACHE
    50 #ifdef _DEBUG_CACHE
  1271 			if (iCard->ExtendedCSD().ExtendedCSDRev() >= 3)
  1274 			if (iCard->ExtendedCSD().ExtendedCSDRev() >= 3)
  1272 				{
  1275 				{
  1273 				// One request, i.e. not end of previous DB request 
  1276 				// One request, i.e. not end of previous DB request 
  1274 				// 512 Bytes long when sector aligned
  1277 				// 512 Bytes long when sector aligned
  1275 				if ( ( I64LOW(iPhysEnd - iPhysStart) == iBlkLen) && ((iReqStart & ~iBlkMsk) == iPhysStart) )
  1278 				if ( ( I64LOW(iPhysEnd - iPhysStart) == iBlkLen) && ((iReqStart & ~iBlkMsk) == iPhysStart) )
  1276 					{
  1279                     {
  1277 					__KTRACE_OPT(KPBUSDRV, Kern::Printf("mmd:lw:AtomicWrite"));
  1280 				    // Reliable write will only be issued on non-removable drives (i.e. System drives)
  1278 					iSession->Command().iFlags|= KMMCCmdFlagReliableWrite;
  1281                     if (!isRemovableDrive( *( iCurrentReq->Drive() ) ) )
  1279 					}
  1282                         {                                            
       
  1283                         __KTRACE_OPT(KPBUSDRV, Kern::Printf("mmd:lw:AtomicWrite"));
       
  1284                         iSession->Command().iFlags|= KMMCCmdFlagReliableWrite;
       
  1285                         }
       
  1286 			        }
  1280 				}
  1287 				}
  1281 #endif //_ENABLE_EMMC_RELIABLE_WRITE_			
  1288 #endif //_ENABLE_EMMC_RELIABLE_WRITE_			
  1282 		
  1289 		
  1283 			// Engage the data transfer session...
  1290 			// Engage the data transfer session...
  1284 			r = EngageAndSetWriteRequest(aMedReq);
  1291 			r = EngageAndSetWriteRequest(aMedReq);
  2677 	// is a synchronous version of the function
  2684 	// is a synchronous version of the function
  2678 	OstTraceFunctionExitExt( DMMCMEDIADRIVERFLASH_CAPS_EXIT2, this, KErrCompletion );
  2685 	OstTraceFunctionExitExt( DMMCMEDIADRIVERFLASH_CAPS_EXIT2, this, KErrCompletion );
  2679 	return KErrCompletion;
  2686 	return KErrCompletion;
  2680 	}
  2687 	}
  2681 
  2688 
       
  2689 // 
       
  2690 // returns True if the specified drive is removable either physically or logically
       
  2691 //
       
  2692 TBool DMmcMediaDriverFlash::isRemovableDrive(TLocDrv& aDrive)
       
  2693     {    
       
  2694     if (iInternalSlot && iMmcPartitionInfo)
       
  2695         {        
       
  2696         TBuf8<sizeof(TLocalDriveCapsV6)> capsBuf;
       
  2697         capsBuf.SetMax();
       
  2698         capsBuf.FillZ();
       
  2699         iMmcPartitionInfo->PartitionCaps(aDrive,capsBuf);
       
  2700         TLocalDriveCapsV6& CapsInfo = *(TLocalDriveCapsV6*)capsBuf.Ptr(); 
       
  2701         
       
  2702         if (CapsInfo.iDriveAtt & (KDriveAttRemovable|KDriveAttLogicallyRemovable) )
       
  2703             {            
       
  2704             return ETrue;
       
  2705             }
       
  2706         else
       
  2707             {
       
  2708             return EFalse;
       
  2709             }
       
  2710         }
       
  2711     return ETrue;
       
  2712     }
  2682 
  2713 
  2683 // ---- cache ----
  2714 // ---- cache ----
  2684 
  2715 
  2685 TInt DMmcMediaDriverFlash::ReadDataUntilCacheExhausted(TBool* aAllDone)
  2716 TInt DMmcMediaDriverFlash::ReadDataUntilCacheExhausted(TBool* aAllDone)
  2686 //
  2717 //
  3431 	iSessionEndDfc.Cancel();
  3462 	iSessionEndDfc.Cancel();
  3432 	iDataTransferCallBackDfc.Cancel();
  3463 	iDataTransferCallBackDfc.Cancel();
  3433 
  3464 
  3434 	EndInCritical();
  3465 	EndInCritical();
  3435 
  3466 
       
  3467 	if (iMedReq == EMReqRead || iMedReq == EMReqWrite)
       
  3468         {
       
  3469         // Powerdown during a read or write operation,
       
  3470 	    // invalidate Cache to ensure Cache consistency 
       
  3471 	    InvalidateCache();
       
  3472         }
       
  3473 	
  3436 	// need to cancel the session as the stack doesn't take too kindly to having the same session engaged more than once.
  3474 	// need to cancel the session as the stack doesn't take too kindly to having the same session engaged more than once.
  3437 	if (iSession)
  3475 	if (iSession)
  3438 		iStack->CancelSession(iSession);
  3476 		iStack->CancelSession(iSession);
  3439 
  3477 	
  3440 	CompleteRequest(KErrNotReady);
  3478 	CompleteRequest(KErrNotReady);	
  3441 	iMedReq = EMReqIdle;
       
  3442 	OstTraceFunctionExit0( DMMCMEDIADRIVERFLASH_NOTIFYPOWERDOWN_EXIT );
  3479 	OstTraceFunctionExit0( DMMCMEDIADRIVERFLASH_NOTIFYPOWERDOWN_EXIT );
  3443 	}
  3480 	}
  3444 
  3481 
  3445 void DMmcMediaDriverFlash::NotifyEmergencyPowerDown()
  3482 void DMmcMediaDriverFlash::NotifyEmergencyPowerDown()
  3446 	{
  3483 	{
  3447 	OstTraceFunctionEntry0( DMMCMEDIADRIVERFLASH_NOTIFYEMERGENCYPOWERDOWN_ENTRY );
  3484 	OstTraceFunctionEntry0( DMMCMEDIADRIVERFLASH_NOTIFYEMERGENCYPOWERDOWN_ENTRY );
  3448 	__KTRACE_OPT(KPBUSDRV,Kern::Printf(">Ata:NotifyEmergencyPowerDown"));
  3485 	__KTRACE_OPT(KPBUSDRV,Kern::Printf(">mmc:NotifyEmergencyPowerDown"));
  3449 
  3486 
  3450 	iSessionEndDfc.Cancel();
  3487 	iSessionEndDfc.Cancel();
  3451 	iDataTransferCallBackDfc.Cancel();
  3488 	iDataTransferCallBackDfc.Cancel();
  3452 
  3489 
  3453 	TInt r=KErrNotReady;
  3490 	TInt r=KErrNotReady;
  3454 	if (iCritical)
  3491 	if (iCritical)
  3455 		r=KErrAbort;
  3492 		r=KErrAbort;
  3456 	EndInCritical();
  3493 	EndInCritical();
  3457 
  3494 
       
  3495 	if (iMedReq == EMReqRead || iMedReq == EMReqWrite)
       
  3496         {
       
  3497         // Powerdown during a read or write operation,
       
  3498         // invalidate Cache to ensure Cache consistency
       
  3499         InvalidateCache();
       
  3500         }
       
  3501 	
  3458 	// need to cancel the session as the stack doesn't take too kindly to having the same session engaged more than once.
  3502 	// need to cancel the session as the stack doesn't take too kindly to having the same session engaged more than once.
  3459 	if (iSession)
  3503 	if (iSession)
  3460 		iStack->CancelSession(iSession);
  3504 		iStack->CancelSession(iSession);
  3461 
  3505 
  3462 	CompleteRequest(r);
  3506 	CompleteRequest(r);	
  3463 	iMedReq = EMReqIdle;
       
  3464 	OstTraceFunctionExit0( DMMCMEDIADRIVERFLASH_NOTIFYEMERGENCYPOWERDOWN_EXIT );
  3507 	OstTraceFunctionExit0( DMMCMEDIADRIVERFLASH_NOTIFYEMERGENCYPOWERDOWN_EXIT );
  3465 	}
  3508 	}
  3466 
  3509 
  3467 TInt DMmcMediaDriverFlash::Request(TLocDrvRequest& aRequest)
  3510 TInt DMmcMediaDriverFlash::Request(TLocDrvRequest& aRequest)
  3468 	{
  3511 	{