os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/d_mmcsdif.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/d_mmcsdif.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,703 @@
     1.4 +/*
     1.5 +* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +#include <kernel.h>
    1.22 +#include <mmc.h>
    1.23 +#include <locmedia.h>
    1.24 +
    1.25 +#include "mmcldd.h"
    1.26 +#include "d_mmcsdif.h"
    1.27 +
    1.28 +
    1.29 +
    1.30 +const TInt KMajorVersionNumber=1;
    1.31 +const TInt KMinorVersionNumber=0;
    1.32 +const TInt KBuildVersionNumber=0;
    1.33 +
    1.34 +// global Dfc Que
    1.35 +TDynamicDfcQue* gDfcQ;
    1.36 +
    1.37 +
    1.38 +
    1.39 +DECLARE_STANDARD_LDD()
    1.40 +	{
    1.41 +	return new DLddFactoryMmcCntrlInterface;
    1.42 +	}
    1.43 +
    1.44 +/**
    1.45 + * DLddFactoryMmcCntrlInterface constructor
    1.46 + *
    1.47 + * @return N/A
    1.48 + *
    1.49 + * @leave N/A
    1.50 + */
    1.51 +DLddFactoryMmcCntrlInterface::DLddFactoryMmcCntrlInterface()
    1.52 +	{
    1.53 +    iParseMask=KDeviceAllowUnit;  // Pass stack number as unit
    1.54 +	iUnitsMask=0xffffffff;
    1.55 +	iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
    1.56 +	}
    1.57 +
    1.58 +/**
    1.59 + * Create logical channel
    1.60 + *
    1.61 + * @param DLogicalChannelBase*& aChannel - logical channel
    1.62 + *
    1.63 + * @return TInt the error code
    1.64 + *
    1.65 + * @leave N/A
    1.66 + */
    1.67 +TInt DLddFactoryMmcCntrlInterface::Create(DLogicalChannelBase*& aChannel)
    1.68 +	{
    1.69 +	aChannel = new DLddMmcCntrlInterface;
    1.70 +	return aChannel ? KErrNone : KErrNoMemory;
    1.71 +	}
    1.72 +
    1.73 +const TInt KDMmcThreadPriority = 27;
    1.74 +_LIT(KDMmcThread,"DMMCSDThread");
    1.75 +
    1.76 +
    1.77 +/**
    1.78 + * Install driver
    1.79 + *
    1.80 + * @return TInt the error code
    1.81 + *
    1.82 + * @leave N/A
    1.83 + */
    1.84 +TInt DLddFactoryMmcCntrlInterface::Install()
    1.85 +	{
    1.86 +	// Allocate a kernel thread to run the DFC
    1.87 +	TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDMmcThreadPriority, KDMmcThread);
    1.88 +
    1.89 +	if (r != KErrNone)
    1.90 +		return r;
    1.91 +	__KTRACE_OPT(KHARDWARE,MMCSDLOG("installing driver name from factory"));
    1.92 +	return SetName(&KLddName);
    1.93 +    }
    1.94 +
    1.95 +/**
    1.96 + * Get the Pc Card Contoller Interface ldd's version info
    1.97 + *
    1.98 + * @param TDes8 &aDes - Buffer to contain version info
    1.99 + *
   1.100 + * @return N/A
   1.101 + *
   1.102 + * @leave N/A
   1.103 + */
   1.104 +void DLddFactoryMmcCntrlInterface::GetCaps(TDes8 &aDes) const
   1.105 +	{
   1.106 +    TCapsMmcIfV01 b;
   1.107 +	b.version=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
   1.108 +	aDes.FillZ(aDes.MaxLength());
   1.109 +	aDes.Copy((TUint8 *)&b,Min(aDes.MaxLength(),sizeof(b)));
   1.110 +	}
   1.111 +
   1.112 +/**
   1.113 + * Destructor
   1.114 + *
   1.115 + * @return N/A
   1.116 + *
   1.117 + * @leave N/A
   1.118 + */
   1.119 +DLddFactoryMmcCntrlInterface::~DLddFactoryMmcCntrlInterface()
   1.120 +	{
   1.121 +	if (gDfcQ)
   1.122 +		gDfcQ->Destroy();
   1.123 +	}
   1.124 +
   1.125 +/**
   1.126 + * DLddMmcCntrlInterface constructor
   1.127 + *
   1.128 + * @return N/A
   1.129 + *
   1.130 + * @leave N/A
   1.131 + */
   1.132 +DLddMmcCntrlInterface::DLddMmcCntrlInterface()
   1.133 +	{
   1.134 +	iClient = &Kern::CurrentThread();
   1.135 +	((DObject*)iClient)->Open();	// can't fail since thread is running
   1.136 +    }
   1.137 +
   1.138 +/**
   1.139 + * Destructor
   1.140 + *
   1.141 + * @return N/A
   1.142 + *
   1.143 + * @leave	N/A
   1.144 + */
   1.145 +DLddMmcCntrlInterface::~DLddMmcCntrlInterface()
   1.146 +	{
   1.147 +	Kern::SafeClose((DObject*&)iClient,NULL);
   1.148 +	iAsyncList.ResetAndDestroy();
   1.149 +    }
   1.150 +
   1.151 +/**
   1.152 + * Create driver ojects
   1.153 + *
   1.154 + * @param TInt aUnit - Socket ID
   1.155 + * @param const TDesC8* aInfo - Buffer for logging
   1.156 + * @param const TVersion& aVer - Current version
   1.157 + *
   1.158 + * @return TInt the error code
   1.159 + *
   1.160 + * @leave N/A
   1.161 + */
   1.162 +TInt DLddMmcCntrlInterface::DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer)
   1.163 +	{
   1.164 +	if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
   1.165 +		return(KErrNotSupported);
   1.166 +
   1.167 +	MMCSDLOG2("DLddMmcCntrlInterface::DoCreate called aInfo(%S)", aInfo);
   1.168 +
   1.169 +	// create the socket - there is only a DMMCSocket
   1.170 +	iSocket = static_cast<DMMCSocket*>(DPBusSocket::SocketFromId(aUnit));
   1.171 +	if(!iSocket)
   1.172 +		return(KErrNoMemory);
   1.173 +
   1.174 +	//Obtain the appropriate card from the stack
   1.175 +	iStack = static_cast<DMMCStack*>(iSocket->Stack(KStackNo));
   1.176 +	if(iStack == NULL)
   1.177 +		return(KErrNoMemory);
   1.178 +
   1.179 +	//Obtain the appropriate card power supply
   1.180 +	iPsu=static_cast<DMMCPsu*>(iSocket->iVcc);
   1.181 +	if (iPsu==NULL)
   1.182 +		return(KErrNoMemory);
   1.183 +
   1.184 +	//Obtain the appropriate card  Media change
   1.185 +	iMediaChange=static_cast<DMMCMediaChange*>(iSocket->iMediaChange);
   1.186 +	if (iMediaChange==NULL)
   1.187 +		return(KErrNoMemory);
   1.188 +
   1.189 +	SetDfcQ(gDfcQ);
   1.190 +	iMsgQ.Receive();
   1.191 +
   1.192 +	iUnit = aUnit;  // save the unit - needed for regitering callbacks for subsequent bus events
   1.193 +
   1.194 +    return(KErrNone);
   1.195 +	}
   1.196 +
   1.197 +/**
   1.198 + * Request cancelled callback
   1.199 + *
   1.200 + * @param TInt sReqNo - Request Number
   1.201 + *
   1.202 + * @return N/A
   1.203 + *
   1.204 + * @leave N/A
   1.205 + */
   1.206 +void DLddMmcCntrlInterface::DoCancel(TInt /*aReqNo*/)
   1.207 +	{
   1.208 +	}
   1.209 +
   1.210 +/**
   1.211 + * Handle kernel side message
   1.212 + *
   1.213 + * @param TMessageBase* aMsg - The kernel side message
   1.214 + *
   1.215 + * @return N/A
   1.216 + *
   1.217 + * @leave N/A
   1.218 + */
   1.219 +void DLddMmcCntrlInterface::HandleMsg(TMessageBase* aMsg)
   1.220 +    {
   1.221 +    TThreadMessage& m=*(TThreadMessage*)aMsg;
   1.222 +    TInt id=m.iValue;
   1.223 +
   1.224 +	if (id==(TInt)ECloseMsg)
   1.225 +		{
   1.226 +		m.Complete(KErrNone, EFalse);
   1.227 +		return;
   1.228 +		}
   1.229 +    else if (id==KMaxTInt)
   1.230 +		{
   1.231 +		// DoCancel
   1.232 +		m.Complete(KErrNone,ETrue);
   1.233 +		return;
   1.234 +		}
   1.235 +
   1.236 +    if (id<0)
   1.237 +		{
   1.238 +		// DoRequest
   1.239 +		TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
   1.240 +		TInt r=DoRequest(~id, pS, m.Ptr1(), m.Ptr2());
   1.241 +		if (r!=KErrNone)
   1.242 +	    	Kern::RequestComplete(iClient, pS, r);
   1.243 +		m.Complete(KErrNone,ETrue);
   1.244 +		}
   1.245 +    else
   1.246 +		{
   1.247 +		// DoControl
   1.248 +		TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
   1.249 +		if(r != KErrCompletion)
   1.250 +			{
   1.251 +			m.Complete(r,ETrue);
   1.252 +			}
   1.253 +		}
   1.254 +	}
   1.255 +
   1.256 +/**
   1.257 + * Do a kernel side request
   1.258 + *
   1.259 + * @param TInt aFunction - Request Function ID
   1.260 + * @param TRequestStatus* aStatus - Request Status
   1.261 + * @param TAny* a1 - Given parameter
   1.262 + * @param TAny* a2 - Given parameter
   1.263 + *
   1.264 + * @return TInt the error code
   1.265 + *
   1.266 + * @leave N/A
   1.267 + */
   1.268 +TInt DLddMmcCntrlInterface::DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny *a2)
   1.269 +	{
   1.270 +
   1.271 +	TTCFunctionId fid = TTCFunctionId(aFunction);
   1.272 +	switch(fid.TestType())
   1.273 +		{
   1.274 +		case EMmcTestSocket:
   1.275 +			return SocketDoRequest(aStatus, a1, a2, aFunction);
   1.276 +
   1.277 +		case EMmcTestStack:
   1.278 +		case EMmcTestPsu:
   1.279 +		case EMmcTestMediaChange:
   1.280 +	  	case EMmcGeneralTest:
   1.281 +		default:
   1.282 +			break;
   1.283 +		};
   1.284 +
   1.285 +    switch(fid.FunctionId())
   1.286 +		{
   1.287 +        case RMMCSDTestControllerInterface::EReadSector:
   1.288 +            {
   1.289 +            // read sector a1 is block number, a2 is client descriptor
   1.290 +            // data will be written back to upon completion
   1.291 +			MMCSDLOG3("RMMCSDTestControllerInterface::EReadSector a1(%d) a2(%x)", (TUint32)a1, a2);
   1.292 +			if(!iCard)
   1.293 +				{
   1.294 +				MMCSDLOG("RMMCSDTestControllerInterface::EReadSector NULL card\n");
   1.295 +				return KErrNotReady;
   1.296 +				}
   1.297 +
   1.298 +			DMmcSessionAsyncRequest* request = CreateAsyncSessionRequest(EMmcSesReadBlk, aStatus);
   1.299 +
   1.300 +			TUint32 srcAddr=((TUint32)a1)<<KSectorSizeShift;
   1.301 +			TUint readBlLen = 1 << iCard->MaxReadBlLen();
   1.302 +			TUint readBlMask=(readBlLen-1);
   1.303 +			request->iBlkOffet=srcAddr-(srcAddr&(~readBlMask));
   1.304 +			request->iClientDesPtr = a2;
   1.305 +			srcAddr &= (~readBlMask);
   1.306 +
   1.307 +			MMCSDLOG("RMMCSDTestControllerInterface::EReadSector #2");
   1.308 +			TMMCArgument da(srcAddr);
   1.309 +
   1.310 +			request->Session().SetupCIMReadBlock(da,readBlLen,&(request->iBuf[0]));
   1.311 +			request->Session().Engage();
   1.312 +
   1.313 +			MMCSDLOG("RMMCSDTestControllerInterface::EReadSector #3");
   1.314 +			break;
   1.315 +            }
   1.316 +        case RMMCSDTestControllerInterface::EWriteSector:
   1.317 +            {
   1.318 +			MMCSDLOG3("RMMCSDTestControllerInterface::EWriteSector a1(%d) a2(%x) #1", (TUint32)a1, a2);
   1.319 +			if(!iCard)
   1.320 +				{
   1.321 +				MMCSDLOG("RMMCSDTestControllerInterface::EWriteSector NULL card\n");
   1.322 +				return KErrNotReady;
   1.323 +				}
   1.324 +
   1.325 +			TUint32 destAddr=((TUint32)a1)<<KSectorSizeShift;
   1.326 +			TUint writeBlLen=1 << iCard->MaxWriteBlLen();
   1.327 +			
   1.328 +			DMmcSessionAsyncRequest* request = CreateAsyncSessionRequest(EMmcSesWriteBlk, aStatus);
   1.329 +			
   1.330 +			TUint writeBlMask=(writeBlLen-1);
   1.331 +			request->iBlkOffet=destAddr-(destAddr&(~writeBlMask));
   1.332 +			TPtr8* srcDes = (TPtr8*)a2;
   1.333 +			TPtr8 ptr(&(request->iBuf[request->iBlkOffet]),KSectorSizeInBytes,KSectorSizeInBytes);
   1.334 +			TInt r = Kern::ThreadDesRead(iClient, srcDes, ptr, 0, KChunkShiftBy0);
   1.335 +			if(r != KErrNone)
   1.336 +				{
   1.337 +				return(r);
   1.338 +				}
   1.339 +
   1.340 +			destAddr&=(~writeBlMask);
   1.341 +			request->Session().SetupCIMWriteBlock(TMMCArgument(destAddr),writeBlLen,&(request->iBuf[0]));
   1.342 +			request->Session().Engage();
   1.343 +
   1.344 +			MMCSDLOG("RMMCSDTestControllerInterface::EWriteSector #4");
   1.345 +			break;
   1.346 +			}
   1.347 +        }
   1.348 +	return(KErrNone);
   1.349 +	}
   1.350 +
   1.351 +/**
   1.352 + * Do a kernel side control
   1.353 + *
   1.354 + * @param TInt aFunction - Request Function ID
   1.355 + * @param TAny* a1 - Given parameter
   1.356 + * @param TAny* a2 - Given parameter
   1.357 + *
   1.358 + * @return TInt the error code
   1.359 + *
   1.360 + * @leave N/A
   1.361 + */
   1.362 +TInt DLddMmcCntrlInterface::DoControl(TInt aFunction,TAny* a1,TAny* a2)
   1.363 +	{
   1.364 +	TInt r = KErrNotSupported;
   1.365 +	TTCFunctionId fid = TTCFunctionId(aFunction);
   1.366 +	MMCSDLOG4("DLddMmcCntrlInterface::DoControl aFunction(%d) \
   1.367 +			fid.FunctionId()(%d) fid.TestType(%d)"
   1.368 +			, aFunction, fid.FunctionId(), fid.TestType());
   1.369 +
   1.370 +	switch(fid.TestType())
   1.371 +		{
   1.372 +		case EMmcTestStack:
   1.373 +			return StackDoControl(aFunction, a1, a2);
   1.374 +		case EMmcTestSocket:
   1.375 +			return SocketDoControl(aFunction, a1, a2);
   1.376 +      	case EMmcTestPsu:
   1.377 +			return PsuDoControl(aFunction, a1, a2);
   1.378 +		case EMmcTestMediaChange:
   1.379 +			return MediaChangeDoControl(aFunction, a1, a2);
   1.380 +		case EMmcGeneralTest:
   1.381 +		default:
   1.382 +			break;
   1.383 +		};
   1.384 +
   1.385 +	switch (fid.FunctionId())
   1.386 +		{
   1.387 +      	case RMMCSDTestControllerInterface::EReadCSD:
   1.388 +      		{
   1.389 +			iCSD = iCard->CSD();
   1.390 +				{				
   1.391 +				TCSDInfo csdInfo(iCSD);
   1.392 +	    		r = Kern::ThreadRawWrite(iClient, a1, &csdInfo, sizeof(csdInfo));
   1.393 +				}
   1.394 +      		}
   1.395 +	  		break;
   1.396 +	  		  		
   1.397 +      	case RMMCSDTestControllerInterface::EReadExtCSD:
   1.398 +      		{
   1.399 +			iExtendedCSD = iCard->ExtendedCSD();
   1.400 +			TExtendedCSDInfo extendedCSDInfo(iExtendedCSD);
   1.401 +    		r = Kern::ThreadRawWrite(iClient, a1, &extendedCSDInfo, sizeof(extendedCSDInfo));
   1.402 +      		}
   1.403 +	  		break;
   1.404 +	  		
   1.405 +		case RMMCSDTestControllerInterface::ECardInfo:
   1.406 +			{
   1.407 +			TMMCCardInfo cardInfo;
   1.408 +			cardInfo.SetCardInfo(*iCard);
   1.409 +			r = Kern::ThreadRawWrite(iClient, a1, &cardInfo, sizeof(cardInfo));
   1.410 +			}
   1.411 +			break;
   1.412 +			
   1.413 +		case RMMCSDTestControllerInterface::ECard:
   1.414 +      		{
   1.415 +			r = Kern::ThreadRawWrite(iClient, a1, &iCard, sizeof(iCard));
   1.416 +      		}
   1.417 +	  		break;
   1.418 +		  		
   1.419 +		case RMMCSDTestControllerInterface::ECardIsPresent:
   1.420 +			{
   1.421 +			TBool isPresent = iCard->IsPresent();
   1.422 +			r = Kern::ThreadRawWrite(iClient, a1, &isPresent, sizeof(isPresent));
   1.423 +			}
   1.424 +			break;
   1.425 +		  		
   1.426 +		case RMMCSDTestControllerInterface::ECardIsReady:
   1.427 +			{
   1.428 +			TBool isReady = iCard->IsReady();
   1.429 +			r = Kern::ThreadRawWrite(iClient, a1, &isReady, sizeof(isReady));
   1.430 +			}
   1.431 +			break;
   1.432 +		  		
   1.433 +		case RMMCSDTestControllerInterface::ECardIsLocked:
   1.434 +			{
   1.435 +			TBool isLocked = iCard->IsLocked();
   1.436 +			r = Kern::ThreadRawWrite(iClient, a1, &isLocked, sizeof(isLocked));
   1.437 +			}
   1.438 +			break;
   1.439 +		  		
   1.440 +       default:
   1.441 +        	{
   1.442 +        	MMCSDLOG2("DLddMmcCntrlInterface::DoControl - Invalid FunctionId()(%d)", fid.FunctionId());        	
   1.443 +        	}
   1.444 +			break;
   1.445 +		}
   1.446 +		
   1.447 +		
   1.448 +	return (r);
   1.449 +	}
   1.450 +
   1.451 +/**
   1.452 + * Check if a request status exists
   1.453 + *
   1.454 + * @param TRequestStatus* aStatus - Request Status
   1.455 + *
   1.456 + * @return TBool A request status exists
   1.457 + *
   1.458 + * @leave N/A
   1.459 + */
   1.460 +TBool DLddMmcCntrlInterface::RequestStatusExists(TRequestStatus* aStatus)
   1.461 +	{
   1.462 +
   1.463 +	// check whether this request status already exists in the async request list
   1.464 +	for(int i=0;i<iAsyncList.Count();i++)
   1.465 +		{
   1.466 +		MMCSDLOG3("Checking index(%d) iAsyncList[i]->Status(%x)", i, iAsyncList[i]->Status());
   1.467 +
   1.468 +		if(iAsyncList[i]->Status() == aStatus)
   1.469 +			{
   1.470 +			MMCSDLOG3("WaRNING - adding duplicate TRequestStatus index[%d] aStatus(%x)", i, aStatus);
   1.471 +			return ETrue;
   1.472 +			}
   1.473 +		}
   1.474 +
   1.475 +	return EFalse;
   1.476 +	}
   1.477 +
   1.478 +/**
   1.479 + * Create Asynchronous Session Request
   1.480 + *
   1.481 + * @param TMmcAsyncCmd aFunctionId - Request Function ID
   1.482 + * @param TRequestStatus* aStatus - Request Status
   1.483 + *
   1.484 + * @return DMmcSessionAsyncRequest* Poniter to the created session request object
   1.485 + *
   1.486 + * @leave N/A
   1.487 + */
   1.488 +DMmcSessionAsyncRequest* DLddMmcCntrlInterface::CreateAsyncSessionRequest(TMmcAsyncCmd aFunctionId, TRequestStatus* aStatus)
   1.489 +	{
   1.490 +
   1.491 +	MMCSDLOG3("DLddMmcCntrlInterface::CreateAsyncRequest aStatus(%x) num requests in list (%d)",
   1.492 +			aStatus, iAsyncList.Count());
   1.493 +	
   1.494 +	// create an async request & append to async request list	
   1.495 +	DMmcSessionAsyncRequest* request = new  DMmcSessionAsyncRequest(aFunctionId, aStatus, *this, gDfcQ, *iStack, *iCard);	
   1.496 +	iAsyncList.Append(request);		
   1.497 +	MMCSDLOG4("DLddMmcCntrlInterface::CreateAsyncSessionRequest created OK Status(%x) functionID(%d) aFunctionId(%d)",
   1.498 +			request->Status(), request->FunctionId(), aFunctionId);
   1.499 +	return request;
   1.500 +	}
   1.501 +
   1.502 +/**
   1.503 + * Create Asynchronous Bus Event Request
   1.504 + *
   1.505 + * @param TMmcAsyncCmd aFunctionId - Request Function ID
   1.506 + * @param TRequestStatus* aStatus - Request Status
   1.507 + * @param TInt aUnit - Socket ID
   1.508 + *
   1.509 + * @return DBusEventRequest* Poniter to the created bus event request object
   1.510 + *
   1.511 + * @leave N/A
   1.512 + */
   1.513 +DBusEventRequest* DLddMmcCntrlInterface::CreateAsyncBusEventRequest(TMmcAsyncCmd aFunctionId, TRequestStatus* aStatus, TInt aUnit)
   1.514 +	{
   1.515 +	MMCSDLOG3("DLddMmcCntrlInterface::CreateAsyncBusEventRequest aStatus(%x) num requests in list (%d)",
   1.516 +			aStatus, iAsyncList.Count());
   1.517 +	
   1.518 +	MMCSDLOG4("gDfcQ(%x), iStack(%x), iCard(%x)", gDfcQ, iStack, iCard);
   1.519 +
   1.520 +	// create an async request & append toS async request list
   1.521 +	DBusEventRequest* request = new  DBusEventRequest(aFunctionId, aStatus, *this, aUnit, gDfcQ, *iStack, *iCard);
   1.522 +	iAsyncList.Append(request);
   1.523 +	MMCSDLOG4("DLddMmcCntrlInterface::CreateAsyncBusEventRequest created OK Status(%x) functionID(%d) aFunctionId(%d)",
   1.524 +			request->Status(), request->FunctionId(), aFunctionId);
   1.525 +	return request;
   1.526 +
   1.527 +	}
   1.528 +
   1.529 +/**
   1.530 + * Clears an asynchronous Request from list
   1.531 + *
   1.532 + * @param DLddAsyncRequest* aRequest - Pointer to the request
   1.533 + *
   1.534 + * @return N/A
   1.535 + *
   1.536 + * @leave N/A
   1.537 + */
   1.538 +void DLddMmcCntrlInterface::ClearRequest(DLddAsyncRequest* aRequest)
   1.539 +	{
   1.540 +	if(!aRequest)
   1.541 +		{
   1.542 +		MMCSDLOG("ERROR IN DLddMmcCntrlInterface::ClearRequest NULL request");
   1.543 +		return;
   1.544 +		}
   1.545 +
   1.546 +	TInt i = iAsyncList.Find(aRequest);
   1.547 +	if(i >= 0)
   1.548 +		{
   1.549 +		iAsyncList.Remove(i);
   1.550 +		}
   1.551 +	else
   1.552 +		{
   1.553 +		MMCSDLOG2("ERROR IN DLddMmcCntrlInterface::ClearRequest err(%d)", i);
   1.554 +		}
   1.555 +
   1.556 +	delete aRequest;
   1.557 +
   1.558 +	}
   1.559 +
   1.560 +/**
   1.561 + * Callback when request has completed
   1.562 + *
   1.563 + * @param DLddAsyncRequest& aRequest - The completed request
   1.564 + *
   1.565 + * @return N/A
   1.566 + *
   1.567 + * @leave N/A
   1.568 + */
   1.569 +void DLddMmcCntrlInterface::Notify(DLddAsyncRequest& aRequest)  // callback from DLddAsyncRequest
   1.570 +	{
   1.571 +	MMCSDLOG("DLddMmcCntrlInterface::Notify called");
   1.572 +	TRequestStatus* status =  aRequest.Status();
   1.573 +	switch (aRequest.FunctionId())
   1.574 +		{
   1.575 +		case DLddMmcCntrlInterface::EMmcSesReadBlk:
   1.576 +			{
   1.577 +			DMmcSessionAsyncRequest& request = (DMmcSessionAsyncRequest&) aRequest;
   1.578 +			MMCSDLOG("DLddMmcCntrlInterface::ReadBlockComplete");
   1.579 +			TInt r = KErrNone;
   1.580 +			if (request.iClientDesPtr) // have we supplied descriptor to hold returned data
   1.581 +				{
   1.582 +				TPtr8 ptr(&(request.iBuf[request.iBlkOffet]), KSectorSizeInBytes, KSectorSizeInBytes);
   1.583 +				TPtrC8* srcDes = (TPtrC8*)request.iClientDesPtr;
   1.584 +				r = Kern::ThreadDesWrite(iClient, srcDes, ptr, 0, iClient);
   1.585 +				if(r != KErrNone)
   1.586 +					{
   1.587 +					MMCSDLOG2("ERROR DLddMmcCntrlInterface::ReadBlockComplete Kern::ThreadDesWrite returned r(%d)", r);
   1.588 +					}
   1.589 +				}
   1.590 +			else
   1.591 +				{
   1.592 +				MMCSDLOG("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete - No pointer provided to hold returned data");
   1.593 +				Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);				
   1.594 +				}
   1.595 +			Kern::RequestComplete(iClient, status, (r == KErrNone) ? aRequest.Error() : r);
   1.596 +			}
   1.597 +			break;
   1.598 +
   1.599 +		case DLddMmcCntrlInterface::EMmcSesWriteBlk:
   1.600 +			{
   1.601 +			MMCSDLOG("DLddMmcCntrlInterface::WriteBlockComplete)");
   1.602 +			TRequestStatus* status =  aRequest.Status();
   1.603 +			Kern::RequestComplete(iClient, status, aRequest.Error());
   1.604 +			}
   1.605 +			break;
   1.606 +
   1.607 +		case DLddMmcCntrlInterface::EMmcSesReadCSD:
   1.608 +			{
   1.609 +			DMmcSessionAsyncRequest& request = (DMmcSessionAsyncRequest&) aRequest;
   1.610 +			MMCSDLOG("DLddMmcCntrlInterface::ReadCSDComplete");
   1.611 +			TInt r = KErrNone;
   1.612 +			if (request.iClientDesPtr) // have we supplied pointer to hold returned data
   1.613 +				{
   1.614 +					{
   1.615 +					TCSDInfo csdInfo(iCSD);
   1.616 +		    		r = Kern::ThreadRawWrite(iClient, request.iClientDesPtr, &csdInfo, sizeof(csdInfo));
   1.617 +					}
   1.618 +				if(r != KErrNone)
   1.619 +					{
   1.620 +					MMCSDLOG2("ERROR DLddMmcCntrlInterface::ReadCSDComplete Kern::ThreadRawWrite returned r(%d)", r);
   1.621 +					}
   1.622 +				}
   1.623 +			else
   1.624 +				{
   1.625 +				MMCSDLOG("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete - No pointer provided to hold returned data");
   1.626 +				Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);				
   1.627 +				}
   1.628 +			Kern::RequestComplete(iClient, status, (r == KErrNone) ? aRequest.Error() : r);
   1.629 +			}
   1.630 +			break;
   1.631 +
   1.632 +		case DLddMmcCntrlInterface::EMmcSesReadExtCSD:
   1.633 +			{
   1.634 +			DMmcSessionAsyncRequest& request = (DMmcSessionAsyncRequest&) aRequest;
   1.635 +			MMCSDLOG("DLddMmcCntrlInterface::ReadExtCSDComplete");
   1.636 +			TInt r = KErrNone;
   1.637 +			if (request.iClientDesPtr) // have we supplied pointer to hold returned data
   1.638 +				{
   1.639 +				TExtendedCSDInfo extendedCSDInfo(iExtendedCSD);
   1.640 +	    		r = Kern::ThreadRawWrite(iClient, request.iClientDesPtr, &extendedCSDInfo, sizeof(extendedCSDInfo));
   1.641 +				if(r != KErrNone)
   1.642 +					{
   1.643 +					MMCSDLOG2("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete Kern::ThreadRawWrite returned r(%d)", r);
   1.644 +					}
   1.645 +				}
   1.646 +			else
   1.647 +				{
   1.648 +				MMCSDLOG("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete - No pointer provided to hold returned data");
   1.649 +				Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);				
   1.650 +				}
   1.651 +			Kern::RequestComplete(iClient, status, (r == KErrNone) ? aRequest.Error() : r);
   1.652 +			}
   1.653 +			break;
   1.654 +			
   1.655 +		case DLddMmcCntrlInterface::EMMcSocketPowerUp:
   1.656 +			{
   1.657 +			DBusEventRequest& request = (DBusEventRequest&) aRequest;
   1.658 +			TInt retCode = KErrNone;
   1.659 +			
   1.660 +			MMCSDLOG2("DLddMmcCntrlInterface::EMMcSocketPowerUp ret code = %d", aRequest.Error());
   1.661 +			MMCSDLOG2("DLddMmcCntrlInterface::EMMcSocketPowerUp request.BusState() = %d", request.BusState());
   1.662 +			MMCSDLOG2("DLddMmcCntrlInterface::EMMcSocketPowerUp request.BusError() = %d", request.BusError());
   1.663 +			
   1.664 +			switch(aRequest.Error())
   1.665 +				{
   1.666 +				case TPBusCallBack::EPBusStateChange:
   1.667 +					{
   1.668 +					TPBusState newState = request.BusState();
   1.669 +					retCode = request.BusError();
   1.670 +
   1.671 +					if (retCode == KErrNone)
   1.672 +						{
   1.673 +						switch(newState)
   1.674 +							{
   1.675 +							case EPBusCardAbsent:	retCode = KErrNotFound;		break;			
   1.676 +							case EPBusPsuFault:		retCode = KErrBadPower;		break;
   1.677 +							case EPBusOff:
   1.678 +							case EPBusOn:
   1.679 +							case EPBusPowerUpPending:
   1.680 +							case EPBusPoweringUp:
   1.681 +							default:	
   1.682 +								break;
   1.683 +							}
   1.684 +						}
   1.685 +
   1.686 +					break;
   1.687 +					}
   1.688 +				}
   1.689 +			
   1.690 +	   		Kern::RequestComplete(iClient, status, retCode);
   1.691 +			}
   1.692 +			break;
   1.693 +
   1.694 +		default:
   1.695 +			MMCSDLOG("#######################################################################");
   1.696 +			MMCSDLOG("## UNHANDLED END DFC DLddAsyncRequest DLddMmcCntrlInterface::Notify  ##");
   1.697 +			MMCSDLOG2("## aRequest.FunctionId(%d)  ##", aRequest.FunctionId());
   1.698 +			MMCSDLOG("#######################################################################");
   1.699 +			Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);
   1.700 +			break;
   1.701 +		};
   1.702 +
   1.703 +	ClearRequest(&aRequest);
   1.704 +
   1.705 +	}
   1.706 +