os/boardsupport/haitest/bspsvs/suite/bsp/mmc/ldd/src/d_mmcsdif.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
#include <kernel.h>
sl@0
    19
#include <mmc.h>
sl@0
    20
#include <locmedia.h>
sl@0
    21
sl@0
    22
#include "mmcldd.h"
sl@0
    23
#include "d_mmcsdif.h"
sl@0
    24
sl@0
    25
sl@0
    26
sl@0
    27
const TInt KMajorVersionNumber=1;
sl@0
    28
const TInt KMinorVersionNumber=0;
sl@0
    29
const TInt KBuildVersionNumber=0;
sl@0
    30
sl@0
    31
// global Dfc Que
sl@0
    32
TDynamicDfcQue* gDfcQ;
sl@0
    33
sl@0
    34
sl@0
    35
sl@0
    36
DECLARE_STANDARD_LDD()
sl@0
    37
	{
sl@0
    38
	return new DLddFactoryMmcCntrlInterface;
sl@0
    39
	}
sl@0
    40
sl@0
    41
/**
sl@0
    42
 * DLddFactoryMmcCntrlInterface constructor
sl@0
    43
 *
sl@0
    44
 * @return N/A
sl@0
    45
 *
sl@0
    46
 * @leave N/A
sl@0
    47
 */
sl@0
    48
DLddFactoryMmcCntrlInterface::DLddFactoryMmcCntrlInterface()
sl@0
    49
	{
sl@0
    50
    iParseMask=KDeviceAllowUnit;  // Pass stack number as unit
sl@0
    51
	iUnitsMask=0xffffffff;
sl@0
    52
	iVersion=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
    53
	}
sl@0
    54
sl@0
    55
/**
sl@0
    56
 * Create logical channel
sl@0
    57
 *
sl@0
    58
 * @param DLogicalChannelBase*& aChannel - logical channel
sl@0
    59
 *
sl@0
    60
 * @return TInt the error code
sl@0
    61
 *
sl@0
    62
 * @leave N/A
sl@0
    63
 */
sl@0
    64
TInt DLddFactoryMmcCntrlInterface::Create(DLogicalChannelBase*& aChannel)
sl@0
    65
	{
sl@0
    66
	aChannel = new DLddMmcCntrlInterface;
sl@0
    67
	return aChannel ? KErrNone : KErrNoMemory;
sl@0
    68
	}
sl@0
    69
sl@0
    70
const TInt KDMmcThreadPriority = 27;
sl@0
    71
_LIT(KDMmcThread,"DMMCSDThread");
sl@0
    72
sl@0
    73
sl@0
    74
/**
sl@0
    75
 * Install driver
sl@0
    76
 *
sl@0
    77
 * @return TInt the error code
sl@0
    78
 *
sl@0
    79
 * @leave N/A
sl@0
    80
 */
sl@0
    81
TInt DLddFactoryMmcCntrlInterface::Install()
sl@0
    82
	{
sl@0
    83
	// Allocate a kernel thread to run the DFC
sl@0
    84
	TInt r = Kern::DynamicDfcQCreate(gDfcQ, KDMmcThreadPriority, KDMmcThread);
sl@0
    85
sl@0
    86
	if (r != KErrNone)
sl@0
    87
		return r;
sl@0
    88
	__KTRACE_OPT(KHARDWARE,MMCSDLOG("installing driver name from factory"));
sl@0
    89
	return SetName(&KLddName);
sl@0
    90
    }
sl@0
    91
sl@0
    92
/**
sl@0
    93
 * Get the Pc Card Contoller Interface ldd's version info
sl@0
    94
 *
sl@0
    95
 * @param TDes8 &aDes - Buffer to contain version info
sl@0
    96
 *
sl@0
    97
 * @return N/A
sl@0
    98
 *
sl@0
    99
 * @leave N/A
sl@0
   100
 */
sl@0
   101
void DLddFactoryMmcCntrlInterface::GetCaps(TDes8 &aDes) const
sl@0
   102
	{
sl@0
   103
    TCapsMmcIfV01 b;
sl@0
   104
	b.version=TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber);
sl@0
   105
	aDes.FillZ(aDes.MaxLength());
sl@0
   106
	aDes.Copy((TUint8 *)&b,Min(aDes.MaxLength(),sizeof(b)));
sl@0
   107
	}
sl@0
   108
sl@0
   109
/**
sl@0
   110
 * Destructor
sl@0
   111
 *
sl@0
   112
 * @return N/A
sl@0
   113
 *
sl@0
   114
 * @leave N/A
sl@0
   115
 */
sl@0
   116
DLddFactoryMmcCntrlInterface::~DLddFactoryMmcCntrlInterface()
sl@0
   117
	{
sl@0
   118
	if (gDfcQ)
sl@0
   119
		gDfcQ->Destroy();
sl@0
   120
	}
sl@0
   121
sl@0
   122
/**
sl@0
   123
 * DLddMmcCntrlInterface constructor
sl@0
   124
 *
sl@0
   125
 * @return N/A
sl@0
   126
 *
sl@0
   127
 * @leave N/A
sl@0
   128
 */
sl@0
   129
DLddMmcCntrlInterface::DLddMmcCntrlInterface()
sl@0
   130
	{
sl@0
   131
	iClient = &Kern::CurrentThread();
sl@0
   132
	((DObject*)iClient)->Open();	// can't fail since thread is running
sl@0
   133
    }
sl@0
   134
sl@0
   135
/**
sl@0
   136
 * Destructor
sl@0
   137
 *
sl@0
   138
 * @return N/A
sl@0
   139
 *
sl@0
   140
 * @leave	N/A
sl@0
   141
 */
sl@0
   142
DLddMmcCntrlInterface::~DLddMmcCntrlInterface()
sl@0
   143
	{
sl@0
   144
	Kern::SafeClose((DObject*&)iClient,NULL);
sl@0
   145
	iAsyncList.ResetAndDestroy();
sl@0
   146
    }
sl@0
   147
sl@0
   148
/**
sl@0
   149
 * Create driver ojects
sl@0
   150
 *
sl@0
   151
 * @param TInt aUnit - Socket ID
sl@0
   152
 * @param const TDesC8* aInfo - Buffer for logging
sl@0
   153
 * @param const TVersion& aVer - Current version
sl@0
   154
 *
sl@0
   155
 * @return TInt the error code
sl@0
   156
 *
sl@0
   157
 * @leave N/A
sl@0
   158
 */
sl@0
   159
TInt DLddMmcCntrlInterface::DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer)
sl@0
   160
	{
sl@0
   161
	if (!Kern::QueryVersionSupported(TVersion(KMajorVersionNumber,KMinorVersionNumber,KBuildVersionNumber),aVer))
sl@0
   162
		return(KErrNotSupported);
sl@0
   163
sl@0
   164
	MMCSDLOG2("DLddMmcCntrlInterface::DoCreate called aInfo(%S)", aInfo);
sl@0
   165
sl@0
   166
	// create the socket - there is only a DMMCSocket
sl@0
   167
	iSocket = static_cast<DMMCSocket*>(DPBusSocket::SocketFromId(aUnit));
sl@0
   168
	if(!iSocket)
sl@0
   169
		return(KErrNoMemory);
sl@0
   170
sl@0
   171
	//Obtain the appropriate card from the stack
sl@0
   172
	iStack = static_cast<DMMCStack*>(iSocket->Stack(KStackNo));
sl@0
   173
	if(iStack == NULL)
sl@0
   174
		return(KErrNoMemory);
sl@0
   175
sl@0
   176
	//Obtain the appropriate card power supply
sl@0
   177
	iPsu=static_cast<DMMCPsu*>(iSocket->iVcc);
sl@0
   178
	if (iPsu==NULL)
sl@0
   179
		return(KErrNoMemory);
sl@0
   180
sl@0
   181
	//Obtain the appropriate card  Media change
sl@0
   182
	iMediaChange=static_cast<DMMCMediaChange*>(iSocket->iMediaChange);
sl@0
   183
	if (iMediaChange==NULL)
sl@0
   184
		return(KErrNoMemory);
sl@0
   185
sl@0
   186
	SetDfcQ(gDfcQ);
sl@0
   187
	iMsgQ.Receive();
sl@0
   188
sl@0
   189
	iUnit = aUnit;  // save the unit - needed for regitering callbacks for subsequent bus events
sl@0
   190
sl@0
   191
    return(KErrNone);
sl@0
   192
	}
sl@0
   193
sl@0
   194
/**
sl@0
   195
 * Request cancelled callback
sl@0
   196
 *
sl@0
   197
 * @param TInt sReqNo - Request Number
sl@0
   198
 *
sl@0
   199
 * @return N/A
sl@0
   200
 *
sl@0
   201
 * @leave N/A
sl@0
   202
 */
sl@0
   203
void DLddMmcCntrlInterface::DoCancel(TInt /*aReqNo*/)
sl@0
   204
	{
sl@0
   205
	}
sl@0
   206
sl@0
   207
/**
sl@0
   208
 * Handle kernel side message
sl@0
   209
 *
sl@0
   210
 * @param TMessageBase* aMsg - The kernel side message
sl@0
   211
 *
sl@0
   212
 * @return N/A
sl@0
   213
 *
sl@0
   214
 * @leave N/A
sl@0
   215
 */
sl@0
   216
void DLddMmcCntrlInterface::HandleMsg(TMessageBase* aMsg)
sl@0
   217
    {
sl@0
   218
    TThreadMessage& m=*(TThreadMessage*)aMsg;
sl@0
   219
    TInt id=m.iValue;
sl@0
   220
sl@0
   221
	if (id==(TInt)ECloseMsg)
sl@0
   222
		{
sl@0
   223
		m.Complete(KErrNone, EFalse);
sl@0
   224
		return;
sl@0
   225
		}
sl@0
   226
    else if (id==KMaxTInt)
sl@0
   227
		{
sl@0
   228
		// DoCancel
sl@0
   229
		m.Complete(KErrNone,ETrue);
sl@0
   230
		return;
sl@0
   231
		}
sl@0
   232
sl@0
   233
    if (id<0)
sl@0
   234
		{
sl@0
   235
		// DoRequest
sl@0
   236
		TRequestStatus* pS=(TRequestStatus*)m.Ptr0();
sl@0
   237
		TInt r=DoRequest(~id, pS, m.Ptr1(), m.Ptr2());
sl@0
   238
		if (r!=KErrNone)
sl@0
   239
	    	Kern::RequestComplete(iClient, pS, r);
sl@0
   240
		m.Complete(KErrNone,ETrue);
sl@0
   241
		}
sl@0
   242
    else
sl@0
   243
		{
sl@0
   244
		// DoControl
sl@0
   245
		TInt r=DoControl(id,m.Ptr0(),m.Ptr1());
sl@0
   246
		if(r != KErrCompletion)
sl@0
   247
			{
sl@0
   248
			m.Complete(r,ETrue);
sl@0
   249
			}
sl@0
   250
		}
sl@0
   251
	}
sl@0
   252
sl@0
   253
/**
sl@0
   254
 * Do a kernel side request
sl@0
   255
 *
sl@0
   256
 * @param TInt aFunction - Request Function ID
sl@0
   257
 * @param TRequestStatus* aStatus - Request Status
sl@0
   258
 * @param TAny* a1 - Given parameter
sl@0
   259
 * @param TAny* a2 - Given parameter
sl@0
   260
 *
sl@0
   261
 * @return TInt the error code
sl@0
   262
 *
sl@0
   263
 * @leave N/A
sl@0
   264
 */
sl@0
   265
TInt DLddMmcCntrlInterface::DoRequest(TInt aFunction, TRequestStatus* aStatus, TAny* a1, TAny *a2)
sl@0
   266
	{
sl@0
   267
sl@0
   268
	TTCFunctionId fid = TTCFunctionId(aFunction);
sl@0
   269
	switch(fid.TestType())
sl@0
   270
		{
sl@0
   271
		case EMmcTestSocket:
sl@0
   272
			return SocketDoRequest(aStatus, a1, a2, aFunction);
sl@0
   273
sl@0
   274
		case EMmcTestStack:
sl@0
   275
		case EMmcTestPsu:
sl@0
   276
		case EMmcTestMediaChange:
sl@0
   277
	  	case EMmcGeneralTest:
sl@0
   278
		default:
sl@0
   279
			break;
sl@0
   280
		};
sl@0
   281
sl@0
   282
    switch(fid.FunctionId())
sl@0
   283
		{
sl@0
   284
        case RMMCSDTestControllerInterface::EReadSector:
sl@0
   285
            {
sl@0
   286
            // read sector a1 is block number, a2 is client descriptor
sl@0
   287
            // data will be written back to upon completion
sl@0
   288
			MMCSDLOG3("RMMCSDTestControllerInterface::EReadSector a1(%d) a2(%x)", (TUint32)a1, a2);
sl@0
   289
			if(!iCard)
sl@0
   290
				{
sl@0
   291
				MMCSDLOG("RMMCSDTestControllerInterface::EReadSector NULL card\n");
sl@0
   292
				return KErrNotReady;
sl@0
   293
				}
sl@0
   294
sl@0
   295
			DMmcSessionAsyncRequest* request = CreateAsyncSessionRequest(EMmcSesReadBlk, aStatus);
sl@0
   296
sl@0
   297
			TUint32 srcAddr=((TUint32)a1)<<KSectorSizeShift;
sl@0
   298
			TUint readBlLen = 1 << iCard->MaxReadBlLen();
sl@0
   299
			TUint readBlMask=(readBlLen-1);
sl@0
   300
			request->iBlkOffet=srcAddr-(srcAddr&(~readBlMask));
sl@0
   301
			request->iClientDesPtr = a2;
sl@0
   302
			srcAddr &= (~readBlMask);
sl@0
   303
sl@0
   304
			MMCSDLOG("RMMCSDTestControllerInterface::EReadSector #2");
sl@0
   305
			TMMCArgument da(srcAddr);
sl@0
   306
sl@0
   307
			request->Session().SetupCIMReadBlock(da,readBlLen,&(request->iBuf[0]));
sl@0
   308
			request->Session().Engage();
sl@0
   309
sl@0
   310
			MMCSDLOG("RMMCSDTestControllerInterface::EReadSector #3");
sl@0
   311
			break;
sl@0
   312
            }
sl@0
   313
        case RMMCSDTestControllerInterface::EWriteSector:
sl@0
   314
            {
sl@0
   315
			MMCSDLOG3("RMMCSDTestControllerInterface::EWriteSector a1(%d) a2(%x) #1", (TUint32)a1, a2);
sl@0
   316
			if(!iCard)
sl@0
   317
				{
sl@0
   318
				MMCSDLOG("RMMCSDTestControllerInterface::EWriteSector NULL card\n");
sl@0
   319
				return KErrNotReady;
sl@0
   320
				}
sl@0
   321
sl@0
   322
			TUint32 destAddr=((TUint32)a1)<<KSectorSizeShift;
sl@0
   323
			TUint writeBlLen=1 << iCard->MaxWriteBlLen();
sl@0
   324
			
sl@0
   325
			DMmcSessionAsyncRequest* request = CreateAsyncSessionRequest(EMmcSesWriteBlk, aStatus);
sl@0
   326
			
sl@0
   327
			TUint writeBlMask=(writeBlLen-1);
sl@0
   328
			request->iBlkOffet=destAddr-(destAddr&(~writeBlMask));
sl@0
   329
			TPtr8* srcDes = (TPtr8*)a2;
sl@0
   330
			TPtr8 ptr(&(request->iBuf[request->iBlkOffet]),KSectorSizeInBytes,KSectorSizeInBytes);
sl@0
   331
			TInt r = Kern::ThreadDesRead(iClient, srcDes, ptr, 0, KChunkShiftBy0);
sl@0
   332
			if(r != KErrNone)
sl@0
   333
				{
sl@0
   334
				return(r);
sl@0
   335
				}
sl@0
   336
sl@0
   337
			destAddr&=(~writeBlMask);
sl@0
   338
			request->Session().SetupCIMWriteBlock(TMMCArgument(destAddr),writeBlLen,&(request->iBuf[0]));
sl@0
   339
			request->Session().Engage();
sl@0
   340
sl@0
   341
			MMCSDLOG("RMMCSDTestControllerInterface::EWriteSector #4");
sl@0
   342
			break;
sl@0
   343
			}
sl@0
   344
        }
sl@0
   345
	return(KErrNone);
sl@0
   346
	}
sl@0
   347
sl@0
   348
/**
sl@0
   349
 * Do a kernel side control
sl@0
   350
 *
sl@0
   351
 * @param TInt aFunction - Request Function ID
sl@0
   352
 * @param TAny* a1 - Given parameter
sl@0
   353
 * @param TAny* a2 - Given parameter
sl@0
   354
 *
sl@0
   355
 * @return TInt the error code
sl@0
   356
 *
sl@0
   357
 * @leave N/A
sl@0
   358
 */
sl@0
   359
TInt DLddMmcCntrlInterface::DoControl(TInt aFunction,TAny* a1,TAny* a2)
sl@0
   360
	{
sl@0
   361
	TInt r = KErrNotSupported;
sl@0
   362
	TTCFunctionId fid = TTCFunctionId(aFunction);
sl@0
   363
	MMCSDLOG4("DLddMmcCntrlInterface::DoControl aFunction(%d) \
sl@0
   364
			fid.FunctionId()(%d) fid.TestType(%d)"
sl@0
   365
			, aFunction, fid.FunctionId(), fid.TestType());
sl@0
   366
sl@0
   367
	switch(fid.TestType())
sl@0
   368
		{
sl@0
   369
		case EMmcTestStack:
sl@0
   370
			return StackDoControl(aFunction, a1, a2);
sl@0
   371
		case EMmcTestSocket:
sl@0
   372
			return SocketDoControl(aFunction, a1, a2);
sl@0
   373
      	case EMmcTestPsu:
sl@0
   374
			return PsuDoControl(aFunction, a1, a2);
sl@0
   375
		case EMmcTestMediaChange:
sl@0
   376
			return MediaChangeDoControl(aFunction, a1, a2);
sl@0
   377
		case EMmcGeneralTest:
sl@0
   378
		default:
sl@0
   379
			break;
sl@0
   380
		};
sl@0
   381
sl@0
   382
	switch (fid.FunctionId())
sl@0
   383
		{
sl@0
   384
      	case RMMCSDTestControllerInterface::EReadCSD:
sl@0
   385
      		{
sl@0
   386
			iCSD = iCard->CSD();
sl@0
   387
				{				
sl@0
   388
				TCSDInfo csdInfo(iCSD);
sl@0
   389
	    		r = Kern::ThreadRawWrite(iClient, a1, &csdInfo, sizeof(csdInfo));
sl@0
   390
				}
sl@0
   391
      		}
sl@0
   392
	  		break;
sl@0
   393
	  		  		
sl@0
   394
      	case RMMCSDTestControllerInterface::EReadExtCSD:
sl@0
   395
      		{
sl@0
   396
			iExtendedCSD = iCard->ExtendedCSD();
sl@0
   397
			TExtendedCSDInfo extendedCSDInfo(iExtendedCSD);
sl@0
   398
    		r = Kern::ThreadRawWrite(iClient, a1, &extendedCSDInfo, sizeof(extendedCSDInfo));
sl@0
   399
      		}
sl@0
   400
	  		break;
sl@0
   401
	  		
sl@0
   402
		case RMMCSDTestControllerInterface::ECardInfo:
sl@0
   403
			{
sl@0
   404
			TMMCCardInfo cardInfo;
sl@0
   405
			cardInfo.SetCardInfo(*iCard);
sl@0
   406
			r = Kern::ThreadRawWrite(iClient, a1, &cardInfo, sizeof(cardInfo));
sl@0
   407
			}
sl@0
   408
			break;
sl@0
   409
			
sl@0
   410
		case RMMCSDTestControllerInterface::ECard:
sl@0
   411
      		{
sl@0
   412
			r = Kern::ThreadRawWrite(iClient, a1, &iCard, sizeof(iCard));
sl@0
   413
      		}
sl@0
   414
	  		break;
sl@0
   415
		  		
sl@0
   416
		case RMMCSDTestControllerInterface::ECardIsPresent:
sl@0
   417
			{
sl@0
   418
			TBool isPresent = iCard->IsPresent();
sl@0
   419
			r = Kern::ThreadRawWrite(iClient, a1, &isPresent, sizeof(isPresent));
sl@0
   420
			}
sl@0
   421
			break;
sl@0
   422
		  		
sl@0
   423
		case RMMCSDTestControllerInterface::ECardIsReady:
sl@0
   424
			{
sl@0
   425
			TBool isReady = iCard->IsReady();
sl@0
   426
			r = Kern::ThreadRawWrite(iClient, a1, &isReady, sizeof(isReady));
sl@0
   427
			}
sl@0
   428
			break;
sl@0
   429
		  		
sl@0
   430
		case RMMCSDTestControllerInterface::ECardIsLocked:
sl@0
   431
			{
sl@0
   432
			TBool isLocked = iCard->IsLocked();
sl@0
   433
			r = Kern::ThreadRawWrite(iClient, a1, &isLocked, sizeof(isLocked));
sl@0
   434
			}
sl@0
   435
			break;
sl@0
   436
		  		
sl@0
   437
       default:
sl@0
   438
        	{
sl@0
   439
        	MMCSDLOG2("DLddMmcCntrlInterface::DoControl - Invalid FunctionId()(%d)", fid.FunctionId());        	
sl@0
   440
        	}
sl@0
   441
			break;
sl@0
   442
		}
sl@0
   443
		
sl@0
   444
		
sl@0
   445
	return (r);
sl@0
   446
	}
sl@0
   447
sl@0
   448
/**
sl@0
   449
 * Check if a request status exists
sl@0
   450
 *
sl@0
   451
 * @param TRequestStatus* aStatus - Request Status
sl@0
   452
 *
sl@0
   453
 * @return TBool A request status exists
sl@0
   454
 *
sl@0
   455
 * @leave N/A
sl@0
   456
 */
sl@0
   457
TBool DLddMmcCntrlInterface::RequestStatusExists(TRequestStatus* aStatus)
sl@0
   458
	{
sl@0
   459
sl@0
   460
	// check whether this request status already exists in the async request list
sl@0
   461
	for(int i=0;i<iAsyncList.Count();i++)
sl@0
   462
		{
sl@0
   463
		MMCSDLOG3("Checking index(%d) iAsyncList[i]->Status(%x)", i, iAsyncList[i]->Status());
sl@0
   464
sl@0
   465
		if(iAsyncList[i]->Status() == aStatus)
sl@0
   466
			{
sl@0
   467
			MMCSDLOG3("WaRNING - adding duplicate TRequestStatus index[%d] aStatus(%x)", i, aStatus);
sl@0
   468
			return ETrue;
sl@0
   469
			}
sl@0
   470
		}
sl@0
   471
sl@0
   472
	return EFalse;
sl@0
   473
	}
sl@0
   474
sl@0
   475
/**
sl@0
   476
 * Create Asynchronous Session Request
sl@0
   477
 *
sl@0
   478
 * @param TMmcAsyncCmd aFunctionId - Request Function ID
sl@0
   479
 * @param TRequestStatus* aStatus - Request Status
sl@0
   480
 *
sl@0
   481
 * @return DMmcSessionAsyncRequest* Poniter to the created session request object
sl@0
   482
 *
sl@0
   483
 * @leave N/A
sl@0
   484
 */
sl@0
   485
DMmcSessionAsyncRequest* DLddMmcCntrlInterface::CreateAsyncSessionRequest(TMmcAsyncCmd aFunctionId, TRequestStatus* aStatus)
sl@0
   486
	{
sl@0
   487
sl@0
   488
	MMCSDLOG3("DLddMmcCntrlInterface::CreateAsyncRequest aStatus(%x) num requests in list (%d)",
sl@0
   489
			aStatus, iAsyncList.Count());
sl@0
   490
	
sl@0
   491
	// create an async request & append to async request list	
sl@0
   492
	DMmcSessionAsyncRequest* request = new  DMmcSessionAsyncRequest(aFunctionId, aStatus, *this, gDfcQ, *iStack, *iCard);	
sl@0
   493
	iAsyncList.Append(request);		
sl@0
   494
	MMCSDLOG4("DLddMmcCntrlInterface::CreateAsyncSessionRequest created OK Status(%x) functionID(%d) aFunctionId(%d)",
sl@0
   495
			request->Status(), request->FunctionId(), aFunctionId);
sl@0
   496
	return request;
sl@0
   497
	}
sl@0
   498
sl@0
   499
/**
sl@0
   500
 * Create Asynchronous Bus Event Request
sl@0
   501
 *
sl@0
   502
 * @param TMmcAsyncCmd aFunctionId - Request Function ID
sl@0
   503
 * @param TRequestStatus* aStatus - Request Status
sl@0
   504
 * @param TInt aUnit - Socket ID
sl@0
   505
 *
sl@0
   506
 * @return DBusEventRequest* Poniter to the created bus event request object
sl@0
   507
 *
sl@0
   508
 * @leave N/A
sl@0
   509
 */
sl@0
   510
DBusEventRequest* DLddMmcCntrlInterface::CreateAsyncBusEventRequest(TMmcAsyncCmd aFunctionId, TRequestStatus* aStatus, TInt aUnit)
sl@0
   511
	{
sl@0
   512
	MMCSDLOG3("DLddMmcCntrlInterface::CreateAsyncBusEventRequest aStatus(%x) num requests in list (%d)",
sl@0
   513
			aStatus, iAsyncList.Count());
sl@0
   514
	
sl@0
   515
	MMCSDLOG4("gDfcQ(%x), iStack(%x), iCard(%x)", gDfcQ, iStack, iCard);
sl@0
   516
sl@0
   517
	// create an async request & append toS async request list
sl@0
   518
	DBusEventRequest* request = new  DBusEventRequest(aFunctionId, aStatus, *this, aUnit, gDfcQ, *iStack, *iCard);
sl@0
   519
	iAsyncList.Append(request);
sl@0
   520
	MMCSDLOG4("DLddMmcCntrlInterface::CreateAsyncBusEventRequest created OK Status(%x) functionID(%d) aFunctionId(%d)",
sl@0
   521
			request->Status(), request->FunctionId(), aFunctionId);
sl@0
   522
	return request;
sl@0
   523
sl@0
   524
	}
sl@0
   525
sl@0
   526
/**
sl@0
   527
 * Clears an asynchronous Request from list
sl@0
   528
 *
sl@0
   529
 * @param DLddAsyncRequest* aRequest - Pointer to the request
sl@0
   530
 *
sl@0
   531
 * @return N/A
sl@0
   532
 *
sl@0
   533
 * @leave N/A
sl@0
   534
 */
sl@0
   535
void DLddMmcCntrlInterface::ClearRequest(DLddAsyncRequest* aRequest)
sl@0
   536
	{
sl@0
   537
	if(!aRequest)
sl@0
   538
		{
sl@0
   539
		MMCSDLOG("ERROR IN DLddMmcCntrlInterface::ClearRequest NULL request");
sl@0
   540
		return;
sl@0
   541
		}
sl@0
   542
sl@0
   543
	TInt i = iAsyncList.Find(aRequest);
sl@0
   544
	if(i >= 0)
sl@0
   545
		{
sl@0
   546
		iAsyncList.Remove(i);
sl@0
   547
		}
sl@0
   548
	else
sl@0
   549
		{
sl@0
   550
		MMCSDLOG2("ERROR IN DLddMmcCntrlInterface::ClearRequest err(%d)", i);
sl@0
   551
		}
sl@0
   552
sl@0
   553
	delete aRequest;
sl@0
   554
sl@0
   555
	}
sl@0
   556
sl@0
   557
/**
sl@0
   558
 * Callback when request has completed
sl@0
   559
 *
sl@0
   560
 * @param DLddAsyncRequest& aRequest - The completed request
sl@0
   561
 *
sl@0
   562
 * @return N/A
sl@0
   563
 *
sl@0
   564
 * @leave N/A
sl@0
   565
 */
sl@0
   566
void DLddMmcCntrlInterface::Notify(DLddAsyncRequest& aRequest)  // callback from DLddAsyncRequest
sl@0
   567
	{
sl@0
   568
	MMCSDLOG("DLddMmcCntrlInterface::Notify called");
sl@0
   569
	TRequestStatus* status =  aRequest.Status();
sl@0
   570
	switch (aRequest.FunctionId())
sl@0
   571
		{
sl@0
   572
		case DLddMmcCntrlInterface::EMmcSesReadBlk:
sl@0
   573
			{
sl@0
   574
			DMmcSessionAsyncRequest& request = (DMmcSessionAsyncRequest&) aRequest;
sl@0
   575
			MMCSDLOG("DLddMmcCntrlInterface::ReadBlockComplete");
sl@0
   576
			TInt r = KErrNone;
sl@0
   577
			if (request.iClientDesPtr) // have we supplied descriptor to hold returned data
sl@0
   578
				{
sl@0
   579
				TPtr8 ptr(&(request.iBuf[request.iBlkOffet]), KSectorSizeInBytes, KSectorSizeInBytes);
sl@0
   580
				TPtrC8* srcDes = (TPtrC8*)request.iClientDesPtr;
sl@0
   581
				r = Kern::ThreadDesWrite(iClient, srcDes, ptr, 0, iClient);
sl@0
   582
				if(r != KErrNone)
sl@0
   583
					{
sl@0
   584
					MMCSDLOG2("ERROR DLddMmcCntrlInterface::ReadBlockComplete Kern::ThreadDesWrite returned r(%d)", r);
sl@0
   585
					}
sl@0
   586
				}
sl@0
   587
			else
sl@0
   588
				{
sl@0
   589
				MMCSDLOG("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete - No pointer provided to hold returned data");
sl@0
   590
				Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);				
sl@0
   591
				}
sl@0
   592
			Kern::RequestComplete(iClient, status, (r == KErrNone) ? aRequest.Error() : r);
sl@0
   593
			}
sl@0
   594
			break;
sl@0
   595
sl@0
   596
		case DLddMmcCntrlInterface::EMmcSesWriteBlk:
sl@0
   597
			{
sl@0
   598
			MMCSDLOG("DLddMmcCntrlInterface::WriteBlockComplete)");
sl@0
   599
			TRequestStatus* status =  aRequest.Status();
sl@0
   600
			Kern::RequestComplete(iClient, status, aRequest.Error());
sl@0
   601
			}
sl@0
   602
			break;
sl@0
   603
sl@0
   604
		case DLddMmcCntrlInterface::EMmcSesReadCSD:
sl@0
   605
			{
sl@0
   606
			DMmcSessionAsyncRequest& request = (DMmcSessionAsyncRequest&) aRequest;
sl@0
   607
			MMCSDLOG("DLddMmcCntrlInterface::ReadCSDComplete");
sl@0
   608
			TInt r = KErrNone;
sl@0
   609
			if (request.iClientDesPtr) // have we supplied pointer to hold returned data
sl@0
   610
				{
sl@0
   611
					{
sl@0
   612
					TCSDInfo csdInfo(iCSD);
sl@0
   613
		    		r = Kern::ThreadRawWrite(iClient, request.iClientDesPtr, &csdInfo, sizeof(csdInfo));
sl@0
   614
					}
sl@0
   615
				if(r != KErrNone)
sl@0
   616
					{
sl@0
   617
					MMCSDLOG2("ERROR DLddMmcCntrlInterface::ReadCSDComplete Kern::ThreadRawWrite returned r(%d)", r);
sl@0
   618
					}
sl@0
   619
				}
sl@0
   620
			else
sl@0
   621
				{
sl@0
   622
				MMCSDLOG("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete - No pointer provided to hold returned data");
sl@0
   623
				Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);				
sl@0
   624
				}
sl@0
   625
			Kern::RequestComplete(iClient, status, (r == KErrNone) ? aRequest.Error() : r);
sl@0
   626
			}
sl@0
   627
			break;
sl@0
   628
sl@0
   629
		case DLddMmcCntrlInterface::EMmcSesReadExtCSD:
sl@0
   630
			{
sl@0
   631
			DMmcSessionAsyncRequest& request = (DMmcSessionAsyncRequest&) aRequest;
sl@0
   632
			MMCSDLOG("DLddMmcCntrlInterface::ReadExtCSDComplete");
sl@0
   633
			TInt r = KErrNone;
sl@0
   634
			if (request.iClientDesPtr) // have we supplied pointer to hold returned data
sl@0
   635
				{
sl@0
   636
				TExtendedCSDInfo extendedCSDInfo(iExtendedCSD);
sl@0
   637
	    		r = Kern::ThreadRawWrite(iClient, request.iClientDesPtr, &extendedCSDInfo, sizeof(extendedCSDInfo));
sl@0
   638
				if(r != KErrNone)
sl@0
   639
					{
sl@0
   640
					MMCSDLOG2("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete Kern::ThreadRawWrite returned r(%d)", r);
sl@0
   641
					}
sl@0
   642
				}
sl@0
   643
			else
sl@0
   644
				{
sl@0
   645
				MMCSDLOG("ERROR DLddMmcCntrlInterface::ReadExtCSDComplete - No pointer provided to hold returned data");
sl@0
   646
				Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);				
sl@0
   647
				}
sl@0
   648
			Kern::RequestComplete(iClient, status, (r == KErrNone) ? aRequest.Error() : r);
sl@0
   649
			}
sl@0
   650
			break;
sl@0
   651
			
sl@0
   652
		case DLddMmcCntrlInterface::EMMcSocketPowerUp:
sl@0
   653
			{
sl@0
   654
			DBusEventRequest& request = (DBusEventRequest&) aRequest;
sl@0
   655
			TInt retCode = KErrNone;
sl@0
   656
			
sl@0
   657
			MMCSDLOG2("DLddMmcCntrlInterface::EMMcSocketPowerUp ret code = %d", aRequest.Error());
sl@0
   658
			MMCSDLOG2("DLddMmcCntrlInterface::EMMcSocketPowerUp request.BusState() = %d", request.BusState());
sl@0
   659
			MMCSDLOG2("DLddMmcCntrlInterface::EMMcSocketPowerUp request.BusError() = %d", request.BusError());
sl@0
   660
			
sl@0
   661
			switch(aRequest.Error())
sl@0
   662
				{
sl@0
   663
				case TPBusCallBack::EPBusStateChange:
sl@0
   664
					{
sl@0
   665
					TPBusState newState = request.BusState();
sl@0
   666
					retCode = request.BusError();
sl@0
   667
sl@0
   668
					if (retCode == KErrNone)
sl@0
   669
						{
sl@0
   670
						switch(newState)
sl@0
   671
							{
sl@0
   672
							case EPBusCardAbsent:	retCode = KErrNotFound;		break;			
sl@0
   673
							case EPBusPsuFault:		retCode = KErrBadPower;		break;
sl@0
   674
							case EPBusOff:
sl@0
   675
							case EPBusOn:
sl@0
   676
							case EPBusPowerUpPending:
sl@0
   677
							case EPBusPoweringUp:
sl@0
   678
							default:	
sl@0
   679
								break;
sl@0
   680
							}
sl@0
   681
						}
sl@0
   682
sl@0
   683
					break;
sl@0
   684
					}
sl@0
   685
				}
sl@0
   686
			
sl@0
   687
	   		Kern::RequestComplete(iClient, status, retCode);
sl@0
   688
			}
sl@0
   689
			break;
sl@0
   690
sl@0
   691
		default:
sl@0
   692
			MMCSDLOG("#######################################################################");
sl@0
   693
			MMCSDLOG("## UNHANDLED END DFC DLddAsyncRequest DLddMmcCntrlInterface::Notify  ##");
sl@0
   694
			MMCSDLOG2("## aRequest.FunctionId(%d)  ##", aRequest.FunctionId());
sl@0
   695
			MMCSDLOG("#######################################################################");
sl@0
   696
			Kern::PanicCurrentThread(_L("PBUS-MMC"), 0);
sl@0
   697
			break;
sl@0
   698
		};
sl@0
   699
sl@0
   700
	ClearRequest(&aRequest);
sl@0
   701
sl@0
   702
	}
sl@0
   703