| 
sl@0
 | 
     1  | 
// Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
  | 
| 
sl@0
 | 
     2  | 
// All rights reserved.
  | 
| 
sl@0
 | 
     3  | 
// This component and the accompanying materials are made available
  | 
| 
sl@0
 | 
     4  | 
// under the terms of the License "Eclipse Public License v1.0"
  | 
| 
sl@0
 | 
     5  | 
// which accompanies this distribution, and is available
  | 
| 
sl@0
 | 
     6  | 
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
  | 
| 
sl@0
 | 
     7  | 
//
  | 
| 
sl@0
 | 
     8  | 
// Initial Contributors:
  | 
| 
sl@0
 | 
     9  | 
// Nokia Corporation - initial contribution.
  | 
| 
sl@0
 | 
    10  | 
//
  | 
| 
sl@0
 | 
    11  | 
// Contributors:
  | 
| 
sl@0
 | 
    12  | 
//
  | 
| 
sl@0
 | 
    13  | 
// Description:
  | 
| 
sl@0
 | 
    14  | 
// e32\drivers\pbus\pccard\socket.cpp
  | 
| 
sl@0
 | 
    15  | 
// 
  | 
| 
sl@0
 | 
    16  | 
//
  | 
| 
sl@0
 | 
    17  | 
  | 
| 
sl@0
 | 
    18  | 
#include <pccard.h>
  | 
| 
sl@0
 | 
    19  | 
#include "cis.h"
  | 
| 
sl@0
 | 
    20  | 
  | 
| 
sl@0
 | 
    21  | 
const TInt KFuncGranularity=(KMaxFuncPerCard+1);
  | 
| 
sl@0
 | 
    22  | 
const TInt KMemGranularity=2;
  | 
| 
sl@0
 | 
    23  | 
  | 
| 
sl@0
 | 
    24  | 
TPccdFuncType FuncType(TUint aFuncCode)
  | 
| 
sl@0
 | 
    25  | 
	{
 | 
| 
sl@0
 | 
    26  | 
  | 
| 
sl@0
 | 
    27  | 
	if (aFuncCode<=KCisTplFuncIdScsi)
  | 
| 
sl@0
 | 
    28  | 
		return((TPccdFuncType)(aFuncCode+1));
  | 
| 
sl@0
 | 
    29  | 
	else if (aFuncCode==KCisTplFuncIdVendorSpecific)
  | 
| 
sl@0
 | 
    30  | 
		return(EVendorSpecificCard);
  | 
| 
sl@0
 | 
    31  | 
	else
  | 
| 
sl@0
 | 
    32  | 
		return(EUnknownCard);
  | 
| 
sl@0
 | 
    33  | 
	}
  | 
| 
sl@0
 | 
    34  | 
  | 
| 
sl@0
 | 
    35  | 
/********************************************
  | 
| 
sl@0
 | 
    36  | 
 * PC card power supply
  | 
| 
sl@0
 | 
    37  | 
 ********************************************/
  | 
| 
sl@0
 | 
    38  | 
DPcCardVcc::DPcCardVcc(TInt aPsuNum, TInt aMediaChangeNum)
  | 
| 
sl@0
 | 
    39  | 
	:	DPBusPsuBase(aPsuNum, aMediaChangeNum)
  | 
| 
sl@0
 | 
    40  | 
	{
 | 
| 
sl@0
 | 
    41  | 
	}
  | 
| 
sl@0
 | 
    42  | 
  | 
| 
sl@0
 | 
    43  | 
TInt DPcCardVcc::SocketVccToMilliVolts(TPccdSocketVcc aVcc)
  | 
| 
sl@0
 | 
    44  | 
//
  | 
| 
sl@0
 | 
    45  | 
// Converts a TPccdSocketVcc into a integer value - units mV.
  | 
| 
sl@0
 | 
    46  | 
//
  | 
| 
sl@0
 | 
    47  | 
	{
 | 
| 
sl@0
 | 
    48  | 
	switch (aVcc)
  | 
| 
sl@0
 | 
    49  | 
		{
 | 
| 
sl@0
 | 
    50  | 
		case EPccdSocket_5V0: return(5000);
  | 
| 
sl@0
 | 
    51  | 
		case EPccdSocket_3V3: return(3300);
  | 
| 
sl@0
 | 
    52  | 
		default: return(0);
  | 
| 
sl@0
 | 
    53  | 
		}
  | 
| 
sl@0
 | 
    54  | 
	}
  | 
| 
sl@0
 | 
    55  | 
  | 
| 
sl@0
 | 
    56  | 
TBool DPcCardVcc::IsLocked()
  | 
| 
sl@0
 | 
    57  | 
	{
 | 
| 
sl@0
 | 
    58  | 
/*	TInt i;
  | 
| 
sl@0
 | 
    59  | 
	Kern::EnterCS();
  | 
| 
sl@0
 | 
    60  | 
	for (i=0; i<KMaxPccdSockets; i++)
  | 
| 
sl@0
 | 
    61  | 
		{
 | 
| 
sl@0
 | 
    62  | 
		DPcCardSocket* pS=(DPcCardSocket*)TheSockets[i];
  | 
| 
sl@0
 | 
    63  | 
		if (pS && pS->iVcc==this)
  | 
| 
sl@0
 | 
    64  | 
			{
 | 
| 
sl@0
 | 
    65  | 
			if (pS->iClientWindows || pS->iActiveConfigs)
  | 
| 
sl@0
 | 
    66  | 
				break;
  | 
| 
sl@0
 | 
    67  | 
			}
  | 
| 
sl@0
 | 
    68  | 
		}
  | 
| 
sl@0
 | 
    69  | 
	Kern::LeaveCS();
  | 
| 
sl@0
 | 
    70  | 
	return (i<KMaxPccdSockets);
  | 
| 
sl@0
 | 
    71  | 
*/
  | 
| 
sl@0
 | 
    72  | 
	DPcCardSocket* pS=(DPcCardSocket*)iSocket;
  | 
| 
sl@0
 | 
    73  | 
	return (pS->iClientWindows || pS->iActiveConfigs);
  | 
| 
sl@0
 | 
    74  | 
	}
  | 
| 
sl@0
 | 
    75  | 
  | 
| 
sl@0
 | 
    76  | 
void DPcCardVcc::ReceiveVoltageCheckResult(TInt anError)
  | 
| 
sl@0
 | 
    77  | 
	{
 | 
| 
sl@0
 | 
    78  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("DPcCardVcc(%d)::ReceiveVoltageCheckResult(%d)",iPsuNum,anError));
 | 
| 
sl@0
 | 
    79  | 
	DPcCardSocket* pS=(DPcCardSocket*)iSocket;
  | 
| 
sl@0
 | 
    80  | 
	TInt s=pS->iCardPowerUpState;
  | 
| 
sl@0
 | 
    81  | 
	if (s==DPcCardSocket::EWaitForVccReading)
  | 
| 
sl@0
 | 
    82  | 
		{
 | 
| 
sl@0
 | 
    83  | 
		if (anError==KErrNone)
  | 
| 
sl@0
 | 
    84  | 
			{
 | 
| 
sl@0
 | 
    85  | 
			SetState(EPsuOnFull);
  | 
| 
sl@0
 | 
    86  | 
			pS->iCardPowerUpState=DPcCardSocket::EWaitForReady;
  | 
| 
sl@0
 | 
    87  | 
			}
  | 
| 
sl@0
 | 
    88  | 
		else
  | 
| 
sl@0
 | 
    89  | 
			pS->TerminatePowerUpSequence(KErrCorrupt);
  | 
| 
sl@0
 | 
    90  | 
		}
  | 
| 
sl@0
 | 
    91  | 
	else if (s!=DPcCardSocket::EInit && s!=DPcCardSocket::EApplyingReset && s!=DPcCardSocket::ECheckVcc)
  | 
| 
sl@0
 | 
    92  | 
		DPBusPsuBase::ReceiveVoltageCheckResult(anError);
  | 
| 
sl@0
 | 
    93  | 
	}
  | 
| 
sl@0
 | 
    94  | 
  | 
| 
sl@0
 | 
    95  | 
/********************************************
  | 
| 
sl@0
 | 
    96  | 
 * PC card media change
  | 
| 
sl@0
 | 
    97  | 
 ********************************************/
  | 
| 
sl@0
 | 
    98  | 
DPcCardMediaChange::DPcCardMediaChange(TInt aMediaChangeNum)
  | 
| 
sl@0
 | 
    99  | 
	: DMediaChangeBase(aMediaChangeNum)
  | 
| 
sl@0
 | 
   100  | 
	{
 | 
| 
sl@0
 | 
   101  | 
	}
  | 
| 
sl@0
 | 
   102  | 
  | 
| 
sl@0
 | 
   103  | 
TInt DPcCardMediaChange::Create()
  | 
| 
sl@0
 | 
   104  | 
	{
 | 
| 
sl@0
 | 
   105  | 
	return DMediaChangeBase::Create();
  | 
| 
sl@0
 | 
   106  | 
	}
  | 
| 
sl@0
 | 
   107  | 
  | 
| 
sl@0
 | 
   108  | 
/********************************************
  | 
| 
sl@0
 | 
   109  | 
 * PC card socket
  | 
| 
sl@0
 | 
   110  | 
 ********************************************/
  | 
| 
sl@0
 | 
   111  | 
void cardPowerUpTick(TAny* aPtr)
  | 
| 
sl@0
 | 
   112  | 
	{
 | 
| 
sl@0
 | 
   113  | 
	((DPcCardSocket*)aPtr)->iCardPowerUpDfc.Enque();
  | 
| 
sl@0
 | 
   114  | 
	}
  | 
| 
sl@0
 | 
   115  | 
  | 
| 
sl@0
 | 
   116  | 
void cardPowerUpDfc(TAny* aPtr)
  | 
| 
sl@0
 | 
   117  | 
	{
 | 
| 
sl@0
 | 
   118  | 
	((DPcCardSocket*)aPtr)->CardPowerUpTick();
  | 
| 
sl@0
 | 
   119  | 
	}
  | 
| 
sl@0
 | 
   120  | 
  | 
| 
sl@0
 | 
   121  | 
DPcCardSocket::DPcCardSocket(TSocket aSocketNum)
  | 
| 
sl@0
 | 
   122  | 
//
  | 
| 
sl@0
 | 
   123  | 
// Constructor.
  | 
| 
sl@0
 | 
   124  | 
//
  | 
| 
sl@0
 | 
   125  | 
	:	DPBusSocket(aSocketNum),
  | 
| 
sl@0
 | 
   126  | 
		iCardFuncArray(KFuncGranularity),
  | 
| 
sl@0
 | 
   127  | 
		iMemChunks(KMemGranularity),
  | 
| 
sl@0
 | 
   128  | 
		iCardPowerUpDfc(cardPowerUpDfc, this, 1)
  | 
| 
sl@0
 | 
   129  | 
	{
 | 
| 
sl@0
 | 
   130  | 
  | 
| 
sl@0
 | 
   131  | 
	iType=EPBusTypePcCard;
  | 
| 
sl@0
 | 
   132  | 
//	iCardPowerUpState=EIdle;
  | 
| 
sl@0
 | 
   133  | 
//	iClientWindows=0;
  | 
| 
sl@0
 | 
   134  | 
//	iActiveConfigs=0;
  | 
| 
sl@0
 | 
   135  | 
	}
  | 
| 
sl@0
 | 
   136  | 
  | 
| 
sl@0
 | 
   137  | 
TInt DPcCardSocket::Create(const TDesC* aName)
  | 
| 
sl@0
 | 
   138  | 
//
  | 
| 
sl@0
 | 
   139  | 
// Create a new Socket. Only created once on kernel initialization so don't
  | 
| 
sl@0
 | 
   140  | 
// worry about cleanup if it fails.
  | 
| 
sl@0
 | 
   141  | 
//
  | 
| 
sl@0
 | 
   142  | 
	{
 | 
| 
sl@0
 | 
   143  | 
  | 
| 
sl@0
 | 
   144  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Skt(%d):Create(%lS)",iSocketNumber,aName));
 | 
| 
sl@0
 | 
   145  | 
  | 
| 
sl@0
 | 
   146  | 
	TInt r=DPBusSocket::Create(aName);
  | 
| 
sl@0
 | 
   147  | 
	if (r!=KErrNone)
  | 
| 
sl@0
 | 
   148  | 
		return r;
  | 
| 
sl@0
 | 
   149  | 
	iCardPowerUpDfc.SetDfcQ(&iDfcQ);
  | 
| 
sl@0
 | 
   150  | 
  | 
| 
sl@0
 | 
   151  | 
	// Create card function array - add and remove a dummy function to pre-allocate array memory.
  | 
| 
sl@0
 | 
   152  | 
	// This way, adding new functions to array never causes any memory allocation.
  | 
| 
sl@0
 | 
   153  | 
	r=AddNewFunc(0,EPccdAttribMem);				// Add dummy function
  | 
| 
sl@0
 | 
   154  | 
	if (r!=KErrNone)
  | 
| 
sl@0
 | 
   155  | 
		return r;
  | 
| 
sl@0
 | 
   156  | 
	delete iCardFuncArray[0];					// Destroy dummy function
  | 
| 
sl@0
 | 
   157  | 
	iCardFuncArray.Remove(0);					// Remove pointer to dummy from array
  | 
| 
sl@0
 | 
   158  | 
  | 
| 
sl@0
 | 
   159  | 
	// Now allocate the permanent attribute memory chunk. Don't bother about what
  | 
| 
sl@0
 | 
   160  | 
	// access speed we asign, it gets set each time we subsequently access the chunk.
  | 
| 
sl@0
 | 
   161  | 
	TPccdChnk chnk(EPccdAttribMem,0,KDefaultAttribMemSize);
  | 
| 
sl@0
 | 
   162  | 
	r=iAttribWin.Create(this,chnk,EAcSpeed300nS,KPccdChunkPermanent|KPccdChunkShared|KPccdChunkSystemOwned);
  | 
| 
sl@0
 | 
   163  | 
	return r;
  | 
| 
sl@0
 | 
   164  | 
	}
  | 
| 
sl@0
 | 
   165  | 
  | 
| 
sl@0
 | 
   166  | 
void DPcCardSocket::ResetPowerUpState()
  | 
| 
sl@0
 | 
   167  | 
	{
 | 
| 
sl@0
 | 
   168  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Skt(%d):ResetPowerUpState",iSocketNumber));
 | 
| 
sl@0
 | 
   169  | 
	if (iCardPowerUpState!=EIdle)
  | 
| 
sl@0
 | 
   170  | 
		{
 | 
| 
sl@0
 | 
   171  | 
		iCardPowerUpTimer.Cancel();
  | 
| 
sl@0
 | 
   172  | 
		iCardPowerUpDfc.Cancel();
  | 
| 
sl@0
 | 
   173  | 
		iCardPowerUpState=EIdle;
  | 
| 
sl@0
 | 
   174  | 
		}
  | 
| 
sl@0
 | 
   175  | 
	}
  | 
| 
sl@0
 | 
   176  | 
  | 
| 
sl@0
 | 
   177  | 
void DPcCardSocket::Reset1()
  | 
| 
sl@0
 | 
   178  | 
	{
 | 
| 
sl@0
 | 
   179  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Skt(%d):Reset1",iSocketNumber));
 | 
| 
sl@0
 | 
   180  | 
	ResetPowerUpState();
  | 
| 
sl@0
 | 
   181  | 
	}
  | 
| 
sl@0
 | 
   182  | 
  | 
| 
sl@0
 | 
   183  | 
void DPcCardSocket::Reset2()
  | 
| 
sl@0
 | 
   184  | 
//
  | 
| 
sl@0
 | 
   185  | 
// Reset the socket (called to remove any allocated memory following a
  | 
| 
sl@0
 | 
   186  | 
// media change event).
  | 
| 
sl@0
 | 
   187  | 
//
  | 
| 
sl@0
 | 
   188  | 
	{
 | 
| 
sl@0
 | 
   189  | 
  | 
| 
sl@0
 | 
   190  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Skt(%d):Rst2",iSocketNumber));
 | 
| 
sl@0
 | 
   191  | 
	// Destroy all the function objects
  | 
| 
sl@0
 | 
   192  | 
	TInt i;
  | 
| 
sl@0
 | 
   193  | 
	for (i=CardFuncCount()-1;i>=0;i--)
  | 
| 
sl@0
 | 
   194  | 
		{
 | 
| 
sl@0
 | 
   195  | 
		delete iCardFuncArray[i];
  | 
| 
sl@0
 | 
   196  | 
		iCardFuncArray.Remove(i);		// Now remove from array (doesn't cause memory dealloc).
  | 
| 
sl@0
 | 
   197  | 
		}
  | 
| 
sl@0
 | 
   198  | 
	iActiveConfigs=0;
  | 
| 
sl@0
 | 
   199  | 
  | 
| 
sl@0
 | 
   200  | 
	// Destroy all the non-permanent Pc Card chunks
  | 
| 
sl@0
 | 
   201  | 
	for (i=(iMemChunks.Count()-1);i>=0;i--)
  | 
| 
sl@0
 | 
   202  | 
		{
 | 
| 
sl@0
 | 
   203  | 
		if ( iMemChunks[i]->IsRemovable() )
  | 
| 
sl@0
 | 
   204  | 
			iMemChunks[i]->Close();
  | 
| 
sl@0
 | 
   205  | 
		}
  | 
| 
sl@0
 | 
   206  | 
	iMemChunks.Compress();
  | 
| 
sl@0
 | 
   207  | 
	}
  | 
| 
sl@0
 | 
   208  | 
  | 
| 
sl@0
 | 
   209  | 
void DPcCardSocket::Restore()
  | 
| 
sl@0
 | 
   210  | 
//
  | 
| 
sl@0
 | 
   211  | 
// Restore the socket. Normally called when restoring a socket after it has been powered 
  | 
| 
sl@0
 | 
   212  | 
// down due to inactivity (but not media change)
  | 
| 
sl@0
 | 
   213  | 
//
  | 
| 
sl@0
 | 
   214  | 
	{	
 | 
| 
sl@0
 | 
   215  | 
	TInt i;
  | 
| 
sl@0
 | 
   216  | 
	TPcCardFunction *cf;
  | 
| 
sl@0
 | 
   217  | 
	for (i=CardFuncCount()-1;i>=0;i--)
  | 
| 
sl@0
 | 
   218  | 
		{
 | 
| 
sl@0
 | 
   219  | 
		cf=iCardFuncArray[i];
  | 
| 
sl@0
 | 
   220  | 
  | 
| 
sl@0
 | 
   221  | 
		TUint8 index;
  | 
| 
sl@0
 | 
   222  | 
		if ((index=(TUint8)cf->ConfigOption())!=KInvalidConfOpt && cf->IsRestorableConfig())
  | 
| 
sl@0
 | 
   223  | 
			WriteConfigReg(i,KConfigOptionReg,index);
  | 
| 
sl@0
 | 
   224  | 
		}
  | 
| 
sl@0
 | 
   225  | 
	}
  | 
| 
sl@0
 | 
   226  | 
  | 
| 
sl@0
 | 
   227  | 
void DPcCardSocket::RemoveChunk(DPccdChunkBase *aChunk)
  | 
| 
sl@0
 | 
   228  | 
//
  | 
| 
sl@0
 | 
   229  | 
// Remove a chunk from this socket. 
  | 
| 
sl@0
 | 
   230  | 
//	
  | 
| 
sl@0
 | 
   231  | 
	{
 | 
| 
sl@0
 | 
   232  | 
	TInt i;
  | 
| 
sl@0
 | 
   233  | 
	for (i=0;i<iMemChunks.Count();i++)
  | 
| 
sl@0
 | 
   234  | 
		{
 | 
| 
sl@0
 | 
   235  | 
		if (iMemChunks[i]==aChunk)
  | 
| 
sl@0
 | 
   236  | 
			{
 | 
| 
sl@0
 | 
   237  | 
			iMemChunks.Remove(i);
  | 
| 
sl@0
 | 
   238  | 
			iMemChunks.Compress();
  | 
| 
sl@0
 | 
   239  | 
			return;
  | 
| 
sl@0
 | 
   240  | 
			}
  | 
| 
sl@0
 | 
   241  | 
		}
  | 
| 
sl@0
 | 
   242  | 
	}
  | 
| 
sl@0
 | 
   243  | 
  | 
| 
sl@0
 | 
   244  | 
EXPORT_C TInt DPcCardSocket::RequestConfig(TInt aCardFunc,DBase *aClientID,TPcCardConfig &anInfo,TUint aFlag)
  | 
| 
sl@0
 | 
   245  | 
//
  | 
| 
sl@0
 | 
   246  | 
// Configure the card.
  | 
| 
sl@0
 | 
   247  | 
//
  | 
| 
sl@0
 | 
   248  | 
	{
 | 
| 
sl@0
 | 
   249  | 
  | 
| 
sl@0
 | 
   250  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Skt(%d):RequestConfig(F:%d O:%xH B:%xH L:%xH)",iSocketNumber,aCardFunc,\
 | 
| 
sl@0
 | 
   251  | 
										   anInfo.iConfigOption,anInfo.iConfigBaseAddr,anInfo.iRegPresent));
  | 
| 
sl@0
 | 
   252  | 
	if (!IsValidCardFunc(aCardFunc))
  | 
| 
sl@0
 | 
   253  | 
		return(KErrArgument);
  | 
| 
sl@0
 | 
   254  | 
	// Check that this function isn't configured already
  | 
| 
sl@0
 | 
   255  | 
	TPcCardFunction *cf=iCardFuncArray[aCardFunc];
  | 
| 
sl@0
 | 
   256  | 
	if (cf->IsConfigured())
  | 
| 
sl@0
 | 
   257  | 
		return(KErrInUse);	   // Its already configured.
  | 
| 
sl@0
 | 
   258  | 
  | 
| 
sl@0
 | 
   259  | 
	// If configuration registers are within attribute chunk then configure the
  | 
| 
sl@0
 | 
   260  | 
	// card (rather than use the registers present info, assume all registers are
  | 
| 
sl@0
 | 
   261  | 
	// present - ie size of mask).
  | 
| 
sl@0
 | 
   262  | 
	if (anInfo.iConfigBaseAddr+(sizeof(anInfo.iRegPresent)<<1)>KDefaultAttribMemSize)
  | 
| 
sl@0
 | 
   263  | 
		return(KErrNotSupported);
  | 
| 
sl@0
 | 
   264  | 
	anInfo.iConfigOption&=(KConfOptLevIReqM|KConfOptConfM); // Mustn't allow msb - KInvalidConfOpt
  | 
| 
sl@0
 | 
   265  | 
	TPccdAccessSpeed sp=(VccSetting()==EPccdSocket_3V3)?EAcSpeed600nS:EAcSpeed300nS;
  | 
| 
sl@0
 | 
   266  | 
	iAttribWin.SetAccessSpeed(sp);
  | 
| 
sl@0
 | 
   267  | 
	iAttribWin.SetupChunkHw();
  | 
| 
sl@0
 | 
   268  | 
	iAttribWin.Write(anInfo.iConfigBaseAddr,(TUint8*)&anInfo.iConfigOption,1);
  | 
| 
sl@0
 | 
   269  | 
  | 
| 
sl@0
 | 
   270  | 
	cf->SetConfigRegMask(anInfo.iRegPresent);
  | 
| 
sl@0
 | 
   271  | 
	cf->SetConfigBaseAddr(anInfo.iConfigBaseAddr);
  | 
| 
sl@0
 | 
   272  | 
	cf->SetConfigOption(anInfo.iConfigOption,aClientID,aFlag);
  | 
| 
sl@0
 | 
   273  | 
	__e32_atomic_add_ord32(&iActiveConfigs, 1);
  | 
| 
sl@0
 | 
   274  | 
	return(KErrNone);
  | 
| 
sl@0
 | 
   275  | 
	}
  | 
| 
sl@0
 | 
   276  | 
  | 
| 
sl@0
 | 
   277  | 
EXPORT_C void DPcCardSocket::ReleaseConfig(TInt aCardFunc,DBase *aClientID)
  | 
| 
sl@0
 | 
   278  | 
//
  | 
| 
sl@0
 | 
   279  | 
// Return card to memory only config.
  | 
| 
sl@0
 | 
   280  | 
//
  | 
| 
sl@0
 | 
   281  | 
	{
 | 
| 
sl@0
 | 
   282  | 
  | 
| 
sl@0
 | 
   283  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Skt(%d):ReleaseConfig(F:%d)",iSocketNumber,aCardFunc));
 | 
| 
sl@0
 | 
   284  | 
	if (IsValidCardFunc(aCardFunc))
  | 
| 
sl@0
 | 
   285  | 
		{
 | 
| 
sl@0
 | 
   286  | 
		TPcCardFunction *cf=iCardFuncArray[aCardFunc];
  | 
| 
sl@0
 | 
   287  | 
		if (cf->IsConfiguredByClient(aClientID))
  | 
| 
sl@0
 | 
   288  | 
			{
 | 
| 
sl@0
 | 
   289  | 
			if (iState==EPBusOn && Kern::PowerGood())
  | 
| 
sl@0
 | 
   290  | 
				WriteConfigReg(aCardFunc,KConfigOptionReg,0); // Restore Config. Option register
  | 
| 
sl@0
 | 
   291  | 
  | 
| 
sl@0
 | 
   292  | 
			cf->SetConfigRegMask(0);
  | 
| 
sl@0
 | 
   293  | 
			cf->SetConfigBaseAddr(0);	
  | 
| 
sl@0
 | 
   294  | 
			cf->SetConfigOption(KInvalidConfOpt,NULL,0);
  | 
| 
sl@0
 | 
   295  | 
			__e32_atomic_add_ord32(&iActiveConfigs, TUint32(-1));
  | 
| 
sl@0
 | 
   296  | 
			}
  | 
| 
sl@0
 | 
   297  | 
		}
  | 
| 
sl@0
 | 
   298  | 
	}
  | 
| 
sl@0
 | 
   299  | 
  | 
| 
sl@0
 | 
   300  | 
EXPORT_C TInt DPcCardSocket::ReadConfigReg(TInt aCardFunc,TInt aRegOffset,TUint8 &aVal)
  | 
| 
sl@0
 | 
   301  | 
//
  | 
| 
sl@0
 | 
   302  | 
// Read from a specified configuration register. (We return an error if the RegPres mask
  | 
| 
sl@0
 | 
   303  | 
// indicates the register isn't present but still attempt the read).
  | 
| 
sl@0
 | 
   304  | 
//
  | 
| 
sl@0
 | 
   305  | 
	{
 | 
| 
sl@0
 | 
   306  | 
	TInt offset, err;
  | 
| 
sl@0
 | 
   307  | 
	if (!IsValidCardFunc(aCardFunc)|| iState!=EPBusOn || !Kern::PowerGood())
  | 
| 
sl@0
 | 
   308  | 
		err=KErrArgument;
  | 
| 
sl@0
 | 
   309  | 
	else
  | 
| 
sl@0
 | 
   310  | 
		{
 | 
| 
sl@0
 | 
   311  | 
		if ((err=iCardFuncArray[aCardFunc]->ConfigRegAddress(aRegOffset,offset))==KErrNone||err==KErrNotSupported)
  | 
| 
sl@0
 | 
   312  | 
			{
 | 
| 
sl@0
 | 
   313  | 
			TPccdAccessSpeed sp=(VccSetting()==EPccdSocket_3V3)?EAcSpeed600nS:EAcSpeed300nS;
  | 
| 
sl@0
 | 
   314  | 
			iAttribWin.SetAccessSpeed(sp);
  | 
| 
sl@0
 | 
   315  | 
			iAttribWin.SetupChunkHw();
  | 
| 
sl@0
 | 
   316  | 
			iAttribWin.Read(offset,&aVal,1);
  | 
| 
sl@0
 | 
   317  | 
			}
  | 
| 
sl@0
 | 
   318  | 
		}
  | 
| 
sl@0
 | 
   319  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("<Skt(%d):ReadConfigReg-%d",iSocketNumber,err));
 | 
| 
sl@0
 | 
   320  | 
	return(err);
  | 
| 
sl@0
 | 
   321  | 
	}
  | 
| 
sl@0
 | 
   322  | 
  | 
| 
sl@0
 | 
   323  | 
EXPORT_C TInt DPcCardSocket::WriteConfigReg(TInt aCardFunc,TInt aRegOffset,const TUint8 aVal)
  | 
| 
sl@0
 | 
   324  | 
//
  | 
| 
sl@0
 | 
   325  | 
// Write to a specified configuration register. (We return an error if the RegPres mask
  | 
| 
sl@0
 | 
   326  | 
// indicates the register isn't present but still attempt the write).
  | 
| 
sl@0
 | 
   327  | 
//
  | 
| 
sl@0
 | 
   328  | 
	{
 | 
| 
sl@0
 | 
   329  | 
	TInt offset, err;
  | 
| 
sl@0
 | 
   330  | 
	if (!IsValidCardFunc(aCardFunc)|| iState!=EPBusOn || !Kern::PowerGood())
  | 
| 
sl@0
 | 
   331  | 
		err=KErrArgument;
  | 
| 
sl@0
 | 
   332  | 
	else
  | 
| 
sl@0
 | 
   333  | 
		{
 | 
| 
sl@0
 | 
   334  | 
		if ((err=iCardFuncArray[aCardFunc]->ConfigRegAddress(aRegOffset,offset))==KErrNone||err==KErrNotSupported)
  | 
| 
sl@0
 | 
   335  | 
			{
 | 
| 
sl@0
 | 
   336  | 
			TPccdAccessSpeed sp=(VccSetting()==EPccdSocket_3V3)?EAcSpeed600nS:EAcSpeed300nS;
  | 
| 
sl@0
 | 
   337  | 
			iAttribWin.SetAccessSpeed(sp);
  | 
| 
sl@0
 | 
   338  | 
			iAttribWin.SetupChunkHw();
  | 
| 
sl@0
 | 
   339  | 
			iAttribWin.Write(offset,&aVal,1);
  | 
| 
sl@0
 | 
   340  | 
			}
  | 
| 
sl@0
 | 
   341  | 
		}
  | 
| 
sl@0
 | 
   342  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("<Skt(%d):WriteConfigReg-%d",iSocketNumber,err));
 | 
| 
sl@0
 | 
   343  | 
	return(err);
  | 
| 
sl@0
 | 
   344  | 
	}
  | 
| 
sl@0
 | 
   345  | 
  | 
| 
sl@0
 | 
   346  | 
const TInt KReadCisBufferSize=0x80;   // 128 Bytes
  | 
| 
sl@0
 | 
   347  | 
TInt DPcCardSocket::ReadCis(TPccdMemType aMemType,TInt aPos,TDes8 &aDes,TInt aLen)
  | 
| 
sl@0
 | 
   348  | 
//
  | 
| 
sl@0
 | 
   349  | 
// Read from CIS 
  | 
| 
sl@0
 | 
   350  | 
//
  | 
| 
sl@0
 | 
   351  | 
	{
 | 
| 
sl@0
 | 
   352  | 
  | 
| 
sl@0
 | 
   353  | 
	__KTRACE_OPT(KPBUS2,Kern::Printf(">Skt(%d):ReadCis(LE:%xH PO:%d TY:%d)",iSocketNumber,aLen,aPos,aMemType));
 | 
| 
sl@0
 | 
   354  | 
	RPccdWindow newWin;
  | 
| 
sl@0
 | 
   355  | 
	RPccdWindow* win=&newWin;
  | 
| 
sl@0
 | 
   356  | 
	TBool needNewChunk=ETrue;
  | 
| 
sl@0
 | 
   357  | 
	TInt cisE=(aPos+aLen);
  | 
| 
sl@0
 | 
   358  | 
	TInt incrm=1;
  | 
| 
sl@0
 | 
   359  | 
	if (aMemType==EPccdAttribMem)
  | 
| 
sl@0
 | 
   360  | 
		{
 | 
| 
sl@0
 | 
   361  | 
		incrm=2;		// Read every other byte
  | 
| 
sl@0
 | 
   362  | 
		cisE<<=1;		
  | 
| 
sl@0
 | 
   363  | 
		aPos<<=1;
  | 
| 
sl@0
 | 
   364  | 
		if (cisE<=(TInt)KDefaultAttribMemSize)
  | 
| 
sl@0
 | 
   365  | 
			{
 | 
| 
sl@0
 | 
   366  | 
			needNewChunk=EFalse;
  | 
| 
sl@0
 | 
   367  | 
			win=&iAttribWin;
  | 
| 
sl@0
 | 
   368  | 
			}
  | 
| 
sl@0
 | 
   369  | 
		}
  | 
| 
sl@0
 | 
   370  | 
  | 
| 
sl@0
 | 
   371  | 
	if (needNewChunk)
  | 
| 
sl@0
 | 
   372  | 
		{
 | 
| 
sl@0
 | 
   373  | 
		TPccdChnk chnk(aMemType,aPos,(cisE-aPos));
  | 
| 
sl@0
 | 
   374  | 
		TInt r=newWin.Create(this,chnk,EAcSpeed300nS,KPccdChunkShared|KPccdChunkSystemOwned);
  | 
| 
sl@0
 | 
   375  | 
		if (r!=KErrNone)
  | 
| 
sl@0
 | 
   376  | 
			return(r);
  | 
| 
sl@0
 | 
   377  | 
		cisE-=aPos;
  | 
| 
sl@0
 | 
   378  | 
		aPos=0;
  | 
| 
sl@0
 | 
   379  | 
		}
  | 
| 
sl@0
 | 
   380  | 
  | 
| 
sl@0
 | 
   381  | 
	TPccdAccessSpeed sp=(VccSetting()==EPccdSocket_3V3)?EAcSpeed600nS:EAcSpeed300nS;
  | 
| 
sl@0
 | 
   382  | 
	win->SetAccessSpeed(sp);
  | 
| 
sl@0
 | 
   383  | 
	win->SetupChunkHw();
  | 
| 
sl@0
 | 
   384  | 
	aDes.Zero();
  | 
| 
sl@0
 | 
   385  | 
	TText8 buf[KReadCisBufferSize];
  | 
| 
sl@0
 | 
   386  | 
	TInt s;
  | 
| 
sl@0
 | 
   387  | 
	for (;aPos<cisE;aPos+=s)
  | 
| 
sl@0
 | 
   388  | 
		{
 | 
| 
sl@0
 | 
   389  | 
		s=Min(KReadCisBufferSize,(cisE-aPos));
  | 
| 
sl@0
 | 
   390  | 
		win->Read(aPos,&buf[0],s);
  | 
| 
sl@0
 | 
   391  | 
		for (TInt i=0;i<s;i+=incrm)
  | 
| 
sl@0
 | 
   392  | 
			aDes.Append((TChar)buf[i]);   
  | 
| 
sl@0
 | 
   393  | 
		} 
  | 
| 
sl@0
 | 
   394  | 
  | 
| 
sl@0
 | 
   395  | 
	if (needNewChunk)
  | 
| 
sl@0
 | 
   396  | 
		newWin.Close();
  | 
| 
sl@0
 | 
   397  | 
	return(KErrNone);
  | 
| 
sl@0
 | 
   398  | 
	}
  | 
| 
sl@0
 | 
   399  | 
  | 
| 
sl@0
 | 
   400  | 
TInt DPcCardSocket::AddNewFunc(TUint32 anOffset,TPccdMemType aMemType)
  | 
| 
sl@0
 | 
   401  | 
//
  | 
| 
sl@0
 | 
   402  | 
// Create a new card function and append it to the function array
  | 
| 
sl@0
 | 
   403  | 
//
  | 
| 
sl@0
 | 
   404  | 
	{
 | 
| 
sl@0
 | 
   405  | 
  | 
| 
sl@0
 | 
   406  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Skt(%d):AddNewFunc(T:%d)",iSocketNumber,aMemType));
 | 
| 
sl@0
 | 
   407  | 
	TInt r=KErrNoMemory;
  | 
| 
sl@0
 | 
   408  | 
	TPcCardFunction* cf=new TPcCardFunction(anOffset,aMemType);
  | 
| 
sl@0
 | 
   409  | 
	if (cf)
  | 
| 
sl@0
 | 
   410  | 
		{
 | 
| 
sl@0
 | 
   411  | 
		r=iCardFuncArray.Append(cf);
  | 
| 
sl@0
 | 
   412  | 
		if (r!=KErrNone)
  | 
| 
sl@0
 | 
   413  | 
			delete cf;
  | 
| 
sl@0
 | 
   414  | 
		}
  | 
| 
sl@0
 | 
   415  | 
	return r;
  | 
| 
sl@0
 | 
   416  | 
	}
  | 
| 
sl@0
 | 
   417  | 
  | 
| 
sl@0
 | 
   418  | 
TPcCardFunction *DPcCardSocket::CardFunc(TInt aCardFunc)
  | 
| 
sl@0
 | 
   419  | 
// 
  | 
| 
sl@0
 | 
   420  | 
// Get a reference to a specific card function from the function array 
  | 
| 
sl@0
 | 
   421  | 
//
  | 
| 
sl@0
 | 
   422  | 
	{
 | 
| 
sl@0
 | 
   423  | 
												   
  | 
| 
sl@0
 | 
   424  | 
	__ASSERT_ALWAYS(IsValidCardFunc(aCardFunc),PcCardPanic(EPcCardBadFunctionNumber));
  | 
| 
sl@0
 | 
   425  | 
	return iCardFuncArray[aCardFunc];
  | 
| 
sl@0
 | 
   426  | 
	}
  | 
| 
sl@0
 | 
   427  | 
  | 
| 
sl@0
 | 
   428  | 
TBool DPcCardSocket::IsConfigLocked()
  | 
| 
sl@0
 | 
   429  | 
//
  | 
| 
sl@0
 | 
   430  | 
// Returns ETrue if this socket contains a card function which is currently configured.
  | 
| 
sl@0
 | 
   431  | 
//
  | 
| 
sl@0
 | 
   432  | 
	{
 | 
| 
sl@0
 | 
   433  | 
//	TInt i;
  | 
| 
sl@0
 | 
   434  | 
//	for (i=CardFuncCount()-1;i>=0;i--)
  | 
| 
sl@0
 | 
   435  | 
//		{
 | 
| 
sl@0
 | 
   436  | 
//		if (iCardFuncArray[i]->IsConfigured())
  | 
| 
sl@0
 | 
   437  | 
//			return(ETrue);
  | 
| 
sl@0
 | 
   438  | 
//		}
  | 
| 
sl@0
 | 
   439  | 
//	return(EFalse);
  | 
| 
sl@0
 | 
   440  | 
	return (iActiveConfigs!=0);
  | 
| 
sl@0
 | 
   441  | 
	}
  | 
| 
sl@0
 | 
   442  | 
  | 
| 
sl@0
 | 
   443  | 
TBool DPcCardSocket::IsMemoryLocked()
  | 
| 
sl@0
 | 
   444  | 
//
  | 
| 
sl@0
 | 
   445  | 
// Returns ETrue if any PC Card memory chunks are allocated on this socket.
  | 
| 
sl@0
 | 
   446  | 
//
  | 
| 
sl@0
 | 
   447  | 
	{
 | 
| 
sl@0
 | 
   448  | 
  | 
| 
sl@0
 | 
   449  | 
//	TInt i;
  | 
| 
sl@0
 | 
   450  | 
//	for (i=iMemChunks.Count()-1;i>=0;i--)
  | 
| 
sl@0
 | 
   451  | 
//		{
 | 
| 
sl@0
 | 
   452  | 
//		if ( iMemChunks[i]->IsLocked() )
  | 
| 
sl@0
 | 
   453  | 
//			return(ETrue);
  | 
| 
sl@0
 | 
   454  | 
//		}
  | 
| 
sl@0
 | 
   455  | 
//	return(EFalse);
  | 
| 
sl@0
 | 
   456  | 
	return (iClientWindows!=0);
  | 
| 
sl@0
 | 
   457  | 
	}
  | 
| 
sl@0
 | 
   458  | 
  | 
| 
sl@0
 | 
   459  | 
TPccdSocketVcc DPcCardSocket::VccSetting()
  | 
| 
sl@0
 | 
   460  | 
//
  | 
| 
sl@0
 | 
   461  | 
// Return voltage setting that this socket is currently set for
  | 
| 
sl@0
 | 
   462  | 
//
  | 
| 
sl@0
 | 
   463  | 
	{
 | 
| 
sl@0
 | 
   464  | 
  | 
| 
sl@0
 | 
   465  | 
	return ((DPcCardVcc*)iVcc)->VoltageSetting();
  | 
| 
sl@0
 | 
   466  | 
	}
  | 
| 
sl@0
 | 
   467  | 
  | 
| 
sl@0
 | 
   468  | 
EXPORT_C TInt DPcCardSocket::VerifyCard(TPccdType &aType)
  | 
| 
sl@0
 | 
   469  | 
//
  | 
| 
sl@0
 | 
   470  | 
// Return information about the type of card present 
  | 
| 
sl@0
 | 
   471  | 
//
  | 
| 
sl@0
 | 
   472  | 
	{
 | 
| 
sl@0
 | 
   473  | 
  | 
| 
sl@0
 | 
   474  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">Cntrl:VerifyCard(S:%d)",iSocketNumber));
 | 
| 
sl@0
 | 
   475  | 
	// The data we want is stored off-card, so it doesn't actually need to be
  | 
| 
sl@0
 | 
   476  | 
	// powered but we need to have read CIS format.
  | 
| 
sl@0
 | 
   477  | 
	TInt err=KErrNone;
  | 
| 
sl@0
 | 
   478  | 
    if (CardIsReadyAndVerified()==KErrNone)
  | 
| 
sl@0
 | 
   479  | 
		{
 | 
| 
sl@0
 | 
   480  | 
		aType.iFuncCount=CardFuncCount();
  | 
| 
sl@0
 | 
   481  | 
		for (TInt i=(aType.iFuncCount-1);i>=0;i--)
  | 
| 
sl@0
 | 
   482  | 
			aType.iFuncType[i]=CardFunc(i)->FuncType();
  | 
| 
sl@0
 | 
   483  | 
		}
  | 
| 
sl@0
 | 
   484  | 
	else
  | 
| 
sl@0
 | 
   485  | 
		err=KErrNotReady;
  | 
| 
sl@0
 | 
   486  | 
  | 
| 
sl@0
 | 
   487  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("<Cntrl:VerifyCard(S:%d T:%d)-%d",iSocketNumber,(TInt)aType.iFuncType[0],err));
 | 
| 
sl@0
 | 
   488  | 
	return(err);
  | 
| 
sl@0
 | 
   489  | 
	}
  | 
| 
sl@0
 | 
   490  | 
  | 
| 
sl@0
 | 
   491  | 
TInt DPcCardSocket::CardIsReadyAndVerified()
  | 
| 
sl@0
 | 
   492  | 
//
  | 
| 
sl@0
 | 
   493  | 
// Returns KErrNone when specified card is powered and ready (ie has had h/w reset) and
  | 
| 
sl@0
 | 
   494  | 
// a basic parsing of CIS has been performed (card functions detected).
  | 
| 
sl@0
 | 
   495  | 
//
  | 
| 
sl@0
 | 
   496  | 
	{
 | 
| 
sl@0
 | 
   497  | 
  | 
| 
sl@0
 | 
   498  | 
	TInt r=KErrNotReady;
  | 
| 
sl@0
 | 
   499  | 
	if (CardIsReady())
  | 
| 
sl@0
 | 
   500  | 
		{
 | 
| 
sl@0
 | 
   501  | 
		r=KErrNone;
  | 
| 
sl@0
 | 
   502  | 
		// Check if card function(s) have been determined (there is always at
  | 
| 
sl@0
 | 
   503  | 
		// least a global function record if basic parsing performed).
  | 
| 
sl@0
 | 
   504  | 
		if (!IsVerified())
  | 
| 
sl@0
 | 
   505  | 
			r=GetCisFormat();
  | 
| 
sl@0
 | 
   506  | 
		}
  | 
| 
sl@0
 | 
   507  | 
  | 
| 
sl@0
 | 
   508  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("<Cntrl:CardRdyAndVerif(S:%d)-%xH",iSocketNumber,r));
 | 
| 
sl@0
 | 
   509  | 
	return r;
  | 
| 
sl@0
 | 
   510  | 
	}
  | 
| 
sl@0
 | 
   511  | 
  | 
| 
sl@0
 | 
   512  | 
TBool DPcCardSocket::CardIsReady()
  | 
| 
sl@0
 | 
   513  | 
	{
 | 
| 
sl@0
 | 
   514  | 
	TBool r=(iState==EPBusOn && Kern::PowerGood());
  | 
| 
sl@0
 | 
   515  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("CardIsReady: %d",r));
 | 
| 
sl@0
 | 
   516  | 
	return r;
  | 
| 
sl@0
 | 
   517  | 
	}
  | 
| 
sl@0
 | 
   518  | 
  | 
| 
sl@0
 | 
   519  | 
TBool DPcCardSocket::CardIsPowered()
  | 
| 
sl@0
 | 
   520  | 
	{
 | 
| 
sl@0
 | 
   521  | 
	return !iVcc->IsOff();
  | 
| 
sl@0
 | 
   522  | 
	}
  | 
| 
sl@0
 | 
   523  | 
  | 
| 
sl@0
 | 
   524  | 
TInt DPcCardSocket::GetCisFormat()
  | 
| 
sl@0
 | 
   525  | 
//
  | 
| 
sl@0
 | 
   526  | 
// Determine the type of card present by parsing the entire CIS. If a 
  | 
| 
sl@0
 | 
   527  | 
// Multi-function card is present then parse each CIS.
  | 
| 
sl@0
 | 
   528  | 
//
  | 
| 
sl@0
 | 
   529  | 
	{
 | 
| 
sl@0
 | 
   530  | 
  | 
| 
sl@0
 | 
   531  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">GetCisFormat (S:%d)",iSocketNumber));
 | 
| 
sl@0
 | 
   532  | 
  | 
| 
sl@0
 | 
   533  | 
	TInt r=AddNewFunc(0,EPccdAttribMem);		// We always have 1st CIS
  | 
| 
sl@0
 | 
   534  | 
	if (r!=KErrNone)
  | 
| 
sl@0
 | 
   535  | 
		return r;
  | 
| 
sl@0
 | 
   536  | 
	if (ValidateCis(0)!=KErrNone)				// Can't use this until func added
  | 
| 
sl@0
 | 
   537  | 
		return KErrCorrupt;
  | 
| 
sl@0
 | 
   538  | 
	TCisReader cisRd;
  | 
| 
sl@0
 | 
   539  | 
	cisRd.iSocket=this;
  | 
| 
sl@0
 | 
   540  | 
	cisRd.DoSelectCis(0);
  | 
| 
sl@0
 | 
   541  | 
	TPccdFuncType firstFuncType;
  | 
| 
sl@0
 | 
   542  | 
	// Check for a multi-function card, search the global CIS (attribute 
  | 
| 
sl@0
 | 
   543  | 
	// memory - addr 0) for a KCisTplLongLinkMfc tuple.
  | 
| 
sl@0
 | 
   544  | 
	TBuf8<KLargeTplBufSize> tpl;
  | 
| 
sl@0
 | 
   545  | 
	if (cisRd.DoFindReadTuple(KCisTplLongLinkMfc,tpl,KPccdReturnLinkTpl)==KErrNone)
  | 
| 
sl@0
 | 
   546  | 
		{
 | 
| 
sl@0
 | 
   547  | 
		// Multi-Function card 
  | 
| 
sl@0
 | 
   548  | 
		firstFuncType=EGlobalCard;
  | 
| 
sl@0
 | 
   549  | 
		const TUint8 *tplPtr=tpl.Ptr()+2; // First tuple after link
  | 
| 
sl@0
 | 
   550  | 
		TInt funcCount=*tplPtr++;
  | 
| 
sl@0
 | 
   551  | 
  | 
| 
sl@0
 | 
   552  | 
		// Add a card function object to the socket for each entry in KCisTplLongLinkMfc tuple
  | 
| 
sl@0
 | 
   553  | 
		TPccdMemType memType;
  | 
| 
sl@0
 | 
   554  | 
		TUint32 lnkAdr;
  | 
| 
sl@0
 | 
   555  | 
		TInt i;
  | 
| 
sl@0
 | 
   556  | 
		for (i=0;i<funcCount;i++)
  | 
| 
sl@0
 | 
   557  | 
			{
 | 
| 
sl@0
 | 
   558  | 
			memType=(*tplPtr++)?EPccdCommon8Mem:EPccdAttribMem;
  | 
| 
sl@0
 | 
   559  | 
			TInt j;
  | 
| 
sl@0
 | 
   560  | 
			for (lnkAdr=0,j=0;j<4;j++)		// Convert link address from string to unsigned long
  | 
| 
sl@0
 | 
   561  | 
				lnkAdr += (*tplPtr++) << (8*j);
  | 
| 
sl@0
 | 
   562  | 
			r=AddNewFunc(lnkAdr,memType);
  | 
| 
sl@0
 | 
   563  | 
			if (r!=KErrNone)
  | 
| 
sl@0
 | 
   564  | 
				return r;
  | 
| 
sl@0
 | 
   565  | 
			if (ValidateCis(i+1)!=KErrNone) // Can't use this until func added
  | 
| 
sl@0
 | 
   566  | 
				return KErrCorrupt;
  | 
| 
sl@0
 | 
   567  | 
			}
  | 
| 
sl@0
 | 
   568  | 
		// Parse the CIS of each card function looking for a KCisTplFuncId tuple
  | 
| 
sl@0
 | 
   569  | 
		for (i=1;i<=funcCount;i++)
  | 
| 
sl@0
 | 
   570  | 
			{
 | 
| 
sl@0
 | 
   571  | 
			cisRd.DoSelectCis(i);
  | 
| 
sl@0
 | 
   572  | 
			TPccdFuncType ft;
  | 
| 
sl@0
 | 
   573  | 
			if (cisRd.DoFindReadTuple(KCisTplFuncId,tpl,0)==KErrNone)
  | 
| 
sl@0
 | 
   574  | 
				ft=FuncType(tpl[2]);
  | 
| 
sl@0
 | 
   575  | 
			else
  | 
| 
sl@0
 | 
   576  | 
				ft=EUnknownCard;
  | 
| 
sl@0
 | 
   577  | 
			CardFunc(i)->SetFuncType(ft);
  | 
| 
sl@0
 | 
   578  | 
			}
  | 
| 
sl@0
 | 
   579  | 
		}
  | 
| 
sl@0
 | 
   580  | 
	else
  | 
| 
sl@0
 | 
   581  | 
		{
 | 
| 
sl@0
 | 
   582  | 
		// Single Function card 
  | 
| 
sl@0
 | 
   583  | 
		cisRd.Restart();
  | 
| 
sl@0
 | 
   584  | 
		if (cisRd.DoFindReadTuple(KCisTplFuncId,tpl,0)==KErrNone)
  | 
| 
sl@0
 | 
   585  | 
			firstFuncType=FuncType(tpl[2]); 
  | 
| 
sl@0
 | 
   586  | 
		else
  | 
| 
sl@0
 | 
   587  | 
			firstFuncType=EUnknownCard; 
  | 
| 
sl@0
 | 
   588  | 
		}
  | 
| 
sl@0
 | 
   589  | 
  | 
| 
sl@0
 | 
   590  | 
	CardFunc(0)->SetFuncType(firstFuncType);
  | 
| 
sl@0
 | 
   591  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("<GetCisFormat(T:%d)",firstFuncType));
 | 
| 
sl@0
 | 
   592  | 
	return KErrNone;
  | 
| 
sl@0
 | 
   593  | 
	}
  | 
| 
sl@0
 | 
   594  | 
  | 
| 
sl@0
 | 
   595  | 
TInt DPcCardSocket::ValidateCis(TInt aCardFunc)
  | 
| 
sl@0
 | 
   596  | 
//
  | 
| 
sl@0
 | 
   597  | 
// Attempt to walk though entire CIS.
  | 
| 
sl@0
 | 
   598  | 
//
  | 
| 
sl@0
 | 
   599  | 
	{
 | 
| 
sl@0
 | 
   600  | 
  | 
| 
sl@0
 | 
   601  | 
	TCisReader cisRd;
  | 
| 
sl@0
 | 
   602  | 
	cisRd.iSocket=this;
  | 
| 
sl@0
 | 
   603  | 
	TBuf8<KLargeTplBufSize> tpl;
  | 
| 
sl@0
 | 
   604  | 
	TInt j=0,err;
  | 
| 
sl@0
 | 
   605  | 
	if ((err=cisRd.DoSelectCis(aCardFunc))==KErrNone)
  | 
| 
sl@0
 | 
   606  | 
		{
 | 
| 
sl@0
 | 
   607  | 
		for (j=0;j<KMaxTuplesPerCis;j++)
  | 
| 
sl@0
 | 
   608  | 
			{
 | 
| 
sl@0
 | 
   609  | 
			err=cisRd.DoFindReadTuple(KPccdNonSpecificTpl,tpl,(KPccdFindOnly|KPccdReturnLinkTpl|KPccdReportErrors));
  | 
| 
sl@0
 | 
   610  | 
			if (err!=KErrNone)
  | 
| 
sl@0
 | 
   611  | 
				break;
  | 
| 
sl@0
 | 
   612  | 
			}
  | 
| 
sl@0
 | 
   613  | 
		if (j>=KMaxTuplesPerCis)
  | 
| 
sl@0
 | 
   614  | 
			err=KErrCorrupt;
  | 
| 
sl@0
 | 
   615  | 
		if (err==KErrNotFound)
  | 
| 
sl@0
 | 
   616  | 
			err=KErrNone;
  | 
| 
sl@0
 | 
   617  | 
		}
  | 
| 
sl@0
 | 
   618  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("<Skt:ValidateCis(S:%d F:%d Tuples:%d)-%d",iSocketNumber,aCardFunc,j,err));
 | 
| 
sl@0
 | 
   619  | 
	return(err);
  | 
| 
sl@0
 | 
   620  | 
	}
  | 
| 
sl@0
 | 
   621  | 
  | 
| 
sl@0
 | 
   622  | 
void DPcCardSocket::InitiatePowerUpSequence()
  | 
| 
sl@0
 | 
   623  | 
	{
 | 
| 
sl@0
 | 
   624  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("DPcCardSocket(%d)::InitiatePowerUpSequence",iSocketNumber));
 | 
| 
sl@0
 | 
   625  | 
	// Check if battery is too low
  | 
| 
sl@0
 | 
   626  | 
//	TSupplyStatus ss=(TSupplyStatus)iMachineInfo.iDisableOnLowBattery;
  | 
| 
sl@0
 | 
   627  | 
//	if (ss!=EZero)
  | 
| 
sl@0
 | 
   628  | 
//		{
 | 
| 
sl@0
 | 
   629  | 
//		TSupplyInfoV1 info;
  | 
| 
sl@0
 | 
   630  | 
//		Hal::SupplyInfo(info); 
  | 
| 
sl@0
 | 
   631  | 
//		if (info.iMainBatteryStatus<ss && !info.iExternalPowerPresent)
  | 
| 
sl@0
 | 
   632  | 
//			{
 | 
| 
sl@0
 | 
   633  | 
//			iSocket[aSocket]->SetSocketStatus(ESocketBatTooLow);
  | 
| 
sl@0
 | 
   634  | 
//			rs=KErrBadPower;
  | 
| 
sl@0
 | 
   635  | 
//			break;
  | 
| 
sl@0
 | 
   636  | 
//			}
  | 
| 
sl@0
 | 
   637  | 
//		}
  | 
| 
sl@0
 | 
   638  | 
  | 
| 
sl@0
 | 
   639  | 
	// Check the state of the Voltage sense line
  | 
| 
sl@0
 | 
   640  | 
	TSocketIndicators ind;
  | 
| 
sl@0
 | 
   641  | 
	Indicators(ind);
  | 
| 
sl@0
 | 
   642  | 
	TUint v=(TUint)ind.iVoltSense & ((DPcCardVcc*)iVcc)->VoltageSupported();
  | 
| 
sl@0
 | 
   643  | 
	if (v==0)
  | 
| 
sl@0
 | 
   644  | 
		{
 | 
| 
sl@0
 | 
   645  | 
		__KTRACE_OPT(KPBUS1,Kern::Printf("InitiatePowerUpSequence(S:%d)-Voltage sense problem(%d)",iSocketNumber,ind.iVoltSense));
 | 
| 
sl@0
 | 
   646  | 
		iVcc->SetCurrLimited();   // Not totally true but has effect.
  | 
| 
sl@0
 | 
   647  | 
		PowerUpSequenceComplete(KErrCorrupt);
  | 
| 
sl@0
 | 
   648  | 
		return;
  | 
| 
sl@0
 | 
   649  | 
		}
  | 
| 
sl@0
 | 
   650  | 
	TPccdSocketVcc sVcc=(v&KPccdVcc_3V3)?EPccdSocket_3V3:EPccdSocket_5V0; // ??? What about xVx / yVy 
  | 
| 
sl@0
 | 
   651  | 
	((DPcCardVcc*)iVcc)->SetVoltage(sVcc);
  | 
| 
sl@0
 | 
   652  | 
  | 
| 
sl@0
 | 
   653  | 
	// Power up card (current limited).
  | 
| 
sl@0
 | 
   654  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("InitiatePowerUpSequence(S:%d)-Apply Vcc",iSocketNumber));
 | 
| 
sl@0
 | 
   655  | 
	if (iVcc->SetState(EPsuOnCurLimit) != KErrNone)
  | 
| 
sl@0
 | 
   656  | 
		{
 | 
| 
sl@0
 | 
   657  | 
		__KTRACE_OPT(KPBUS1,Kern::Printf("InitiatePowerUpSequence(S:%d)-Vcc problem",iSocketNumber));
 | 
| 
sl@0
 | 
   658  | 
		iVcc->SetState(EPsuOff);
  | 
| 
sl@0
 | 
   659  | 
		iVcc->SetCurrLimited();
  | 
| 
sl@0
 | 
   660  | 
		PowerUpSequenceComplete(KErrGeneral);
  | 
| 
sl@0
 | 
   661  | 
		return;
  | 
| 
sl@0
 | 
   662  | 
		}
  | 
| 
sl@0
 | 
   663  | 
	iCardPowerUpState=EInit;
  | 
| 
sl@0
 | 
   664  | 
	iCardPowerUpTickCount=0;
  | 
| 
sl@0
 | 
   665  | 
	iCardPowerUpResetLen=KResetOnDefaultLen;
  | 
| 
sl@0
 | 
   666  | 
	iCardPowerUpPauseLen=KResetOffDefaultLen;
  | 
| 
sl@0
 | 
   667  | 
	iCardPowerUpTimer.Periodic(KPccdPowerUpReqInterval,cardPowerUpTick,this);
  | 
| 
sl@0
 | 
   668  | 
	}
  | 
| 
sl@0
 | 
   669  | 
  | 
| 
sl@0
 | 
   670  | 
void DPcCardSocket::TerminatePowerUpSequence(TInt aResult)
  | 
| 
sl@0
 | 
   671  | 
	{
 | 
| 
sl@0
 | 
   672  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("DPcCardSocket(%d)::TerminatePowerUpSequence result %d",iSocketNumber,aResult));
 | 
| 
sl@0
 | 
   673  | 
	ResetPowerUpState();
  | 
| 
sl@0
 | 
   674  | 
	if (aResult==KErrNone)
  | 
| 
sl@0
 | 
   675  | 
		Restore();
  | 
| 
sl@0
 | 
   676  | 
	PowerUpSequenceComplete(aResult);
  | 
| 
sl@0
 | 
   677  | 
	}
  | 
| 
sl@0
 | 
   678  | 
  | 
| 
sl@0
 | 
   679  | 
void DPcCardSocket::CardPowerUpTick()
  | 
| 
sl@0
 | 
   680  | 
	{
 | 
| 
sl@0
 | 
   681  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("CardPowerUpTick S:%d Elapsed %d State %d",iSocketNumber,iCardPowerUpTickCount,iCardPowerUpState));
 | 
| 
sl@0
 | 
   682  | 
	if (++iCardPowerUpTickCount>KPwrUpTimeOut)
  | 
| 
sl@0
 | 
   683  | 
		{
 | 
| 
sl@0
 | 
   684  | 
		iVcc->SetState(EPsuOff);	// should leave this to timeout
  | 
| 
sl@0
 | 
   685  | 
		TerminatePowerUpSequence(KErrTimedOut);
  | 
| 
sl@0
 | 
   686  | 
		return;
  | 
| 
sl@0
 | 
   687  | 
		}
  | 
| 
sl@0
 | 
   688  | 
	switch (iCardPowerUpState)
  | 
| 
sl@0
 | 
   689  | 
		{
 | 
| 
sl@0
 | 
   690  | 
		case EInit:
  | 
| 
sl@0
 | 
   691  | 
			HwReset(ETrue);		// Apply reset - Turns on interface
  | 
| 
sl@0
 | 
   692  | 
			iCardPowerUpState=EApplyingReset;
  | 
| 
sl@0
 | 
   693  | 
			break;
  | 
| 
sl@0
 | 
   694  | 
		case EApplyingReset:
  | 
| 
sl@0
 | 
   695  | 
			if (iCardPowerUpTickCount>iCardPowerUpResetLen)
  | 
| 
sl@0
 | 
   696  | 
				{
 | 
| 
sl@0
 | 
   697  | 
				HwReset(EFalse);	// remove reset
  | 
| 
sl@0
 | 
   698  | 
				iCardPowerUpState=ECheckVcc;
  | 
| 
sl@0
 | 
   699  | 
				}
  | 
| 
sl@0
 | 
   700  | 
			break;
  | 
| 
sl@0
 | 
   701  | 
		case ECheckVcc:
  | 
| 
sl@0
 | 
   702  | 
			{
 | 
| 
sl@0
 | 
   703  | 
			iCardPowerUpState=EWaitForVccReading;
  | 
| 
sl@0
 | 
   704  | 
			TInt cv=iVcc->CheckVoltage(KPsuChkOnPwrUp);
  | 
| 
sl@0
 | 
   705  | 
			if (cv==KErrNotSupported)
  | 
| 
sl@0
 | 
   706  | 
				iCardPowerUpState=EWaitForReady;
  | 
| 
sl@0
 | 
   707  | 
			else if (cv!=KErrNone)
  | 
| 
sl@0
 | 
   708  | 
				TerminatePowerUpSequence(cv);
  | 
| 
sl@0
 | 
   709  | 
			break;
  | 
| 
sl@0
 | 
   710  | 
			}
  | 
| 
sl@0
 | 
   711  | 
		case EWaitForVccReading:
  | 
| 
sl@0
 | 
   712  | 
			break;
  | 
| 
sl@0
 | 
   713  | 
		case EWaitForReady:
  | 
| 
sl@0
 | 
   714  | 
			if (Ready())
  | 
| 
sl@0
 | 
   715  | 
				{
 | 
| 
sl@0
 | 
   716  | 
				iCardPowerUpState=EPauseAfterReady; // Card is ready
  | 
| 
sl@0
 | 
   717  | 
				// Its effectively powered up now so reset the elapsed time and use it 
  | 
| 
sl@0
 | 
   718  | 
				// to measure pause after reset (ie this is limited to KPwrUpTimeOut too).
  | 
| 
sl@0
 | 
   719  | 
				iCardPowerUpTickCount=0;
  | 
| 
sl@0
 | 
   720  | 
				}
  | 
| 
sl@0
 | 
   721  | 
			break;
  | 
| 
sl@0
 | 
   722  | 
		case EPauseAfterReady:
  | 
| 
sl@0
 | 
   723  | 
			if (iCardPowerUpTickCount>=iCardPowerUpPauseLen)
  | 
| 
sl@0
 | 
   724  | 
				{
 | 
| 
sl@0
 | 
   725  | 
				// power-up sequence is complete
  | 
| 
sl@0
 | 
   726  | 
				TerminatePowerUpSequence(KErrNone);
  | 
| 
sl@0
 | 
   727  | 
				}
  | 
| 
sl@0
 | 
   728  | 
			break;
  | 
| 
sl@0
 | 
   729  | 
		}
  | 
| 
sl@0
 | 
   730  | 
	}
  | 
| 
sl@0
 | 
   731  | 
  | 
| 
sl@0
 | 
   732  | 
/********************************************
  | 
| 
sl@0
 | 
   733  | 
 * PC card memory chunk
  | 
| 
sl@0
 | 
   734  | 
 ********************************************/
  | 
| 
sl@0
 | 
   735  | 
DPccdChunkBase::DPccdChunkBase()
  | 
| 
sl@0
 | 
   736  | 
//
  | 
| 
sl@0
 | 
   737  | 
// Constructor
  | 
| 
sl@0
 | 
   738  | 
//
  | 
| 
sl@0
 | 
   739  | 
	{
 | 
| 
sl@0
 | 
   740  | 
//	iSocket=NULL;
  | 
| 
sl@0
 | 
   741  | 
//	iCacheable=EFalse;
  | 
| 
sl@0
 | 
   742  | 
	}
  | 
| 
sl@0
 | 
   743  | 
  | 
| 
sl@0
 | 
   744  | 
TInt DPccdChunkBase::Create(DPcCardSocket* aSocket, TPccdChnk aChunk, TUint aFlag)
  | 
| 
sl@0
 | 
   745  | 
//
  | 
| 
sl@0
 | 
   746  | 
// Create a chunk of Pc Card h/w.
  | 
| 
sl@0
 | 
   747  | 
//
  | 
| 
sl@0
 | 
   748  | 
	{
 | 
| 
sl@0
 | 
   749  | 
	iSocket=aSocket;
  | 
| 
sl@0
 | 
   750  | 
	iChnk=aChunk;
  | 
| 
sl@0
 | 
   751  | 
	iCacheable=(aFlag&KPccdChunkCacheable);
  | 
| 
sl@0
 | 
   752  | 
	return DoCreate(aChunk,aFlag);
  | 
| 
sl@0
 | 
   753  | 
	}
  | 
| 
sl@0
 | 
   754  | 
  | 
| 
sl@0
 | 
   755  | 
DPccdChunkBase::~DPccdChunkBase()
  | 
| 
sl@0
 | 
   756  | 
//
  | 
| 
sl@0
 | 
   757  | 
// Destructor
  | 
| 
sl@0
 | 
   758  | 
//
  | 
| 
sl@0
 | 
   759  | 
	{
 | 
| 
sl@0
 | 
   760  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPccdChunkBase destruct %08x",this));
 | 
| 
sl@0
 | 
   761  | 
	}
  | 
| 
sl@0
 | 
   762  | 
  | 
| 
sl@0
 | 
   763  | 
void DPccdChunkBase::Close()
  | 
| 
sl@0
 | 
   764  | 
//
  | 
| 
sl@0
 | 
   765  | 
// Destructor
  | 
| 
sl@0
 | 
   766  | 
//
  | 
| 
sl@0
 | 
   767  | 
	{
 | 
| 
sl@0
 | 
   768  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf(">DPccdChunkBase::Close() %08x",this));
 | 
| 
sl@0
 | 
   769  | 
  | 
| 
sl@0
 | 
   770  | 
	// Disconnect all the Pc Card windows and then delete chunk
  | 
| 
sl@0
 | 
   771  | 
	SDblQueLink* pW=iWindowQ.iA.iNext;
  | 
| 
sl@0
 | 
   772  | 
	while (pW!=&iWindowQ.iA)
  | 
| 
sl@0
 | 
   773  | 
		{
 | 
| 
sl@0
 | 
   774  | 
		RPccdWindow& w=*(RPccdWindow*)pW;
  | 
| 
sl@0
 | 
   775  | 
		pW=pW->iNext;
  | 
| 
sl@0
 | 
   776  | 
		w.Close();	// closing last window deletes chunk
  | 
| 
sl@0
 | 
   777  | 
		}
  | 
| 
sl@0
 | 
   778  | 
	__KTRACE_OPT(KPBUS1,Kern::Printf("<DPccdChunkBase::Close() %08x",this));
 | 
| 
sl@0
 | 
   779  | 
	}
  | 
| 
sl@0
 | 
   780  | 
  | 
| 
sl@0
 | 
   781  | 
TBool DPccdChunkBase::IsRemovable()
  | 
| 
sl@0
 | 
   782  | 
//
  | 
| 
sl@0
 | 
   783  | 
// Check if this chunk has any permanent windows.
  | 
| 
sl@0
 | 
   784  | 
//
  | 
| 
sl@0
 | 
   785  | 
	{
 | 
| 
sl@0
 | 
   786  | 
	return (iPermanentWindows==0);
  | 
| 
sl@0
 | 
   787  | 
	}
  | 
| 
sl@0
 | 
   788  | 
  | 
| 
sl@0
 | 
   789  | 
TBool DPccdChunkBase::IsLocked()
  | 
| 
sl@0
 | 
   790  | 
//
  | 
| 
sl@0
 | 
   791  | 
// Check if this chunk has any windows which are allocated to clients of the PC Card
  | 
| 
sl@0
 | 
   792  | 
// Controller (as opposed to the Controller itself).
  | 
| 
sl@0
 | 
   793  | 
//
  | 
| 
sl@0
 | 
   794  | 
	{
 | 
| 
sl@0
 | 
   795  | 
	return (iWindows>iSystemWindows);
  | 
| 
sl@0
 | 
   796  | 
	}
  | 
| 
sl@0
 | 
   797  | 
  | 
| 
sl@0
 | 
   798  | 
TInt DPccdChunkBase::AllocateWinCheck(TPccdChnk aWin,TUint aFlag)
  | 
| 
sl@0
 | 
   799  | 
//
  | 
| 
sl@0
 | 
   800  | 
// Check if it is possible to create the specified window from this chunk.
  | 
| 
sl@0
 | 
   801  | 
//
  | 
| 
sl@0
 | 
   802  | 
	{
 | 
| 
sl@0
 | 
   803  | 
	// Check if they are of compatible type
  | 
| 
sl@0
 | 
   804  | 
	if (!IsTypeCompatible(aWin.iMemType))
  | 
| 
sl@0
 | 
   805  | 
		return(KErrNotFound);
  | 
| 
sl@0
 | 
   806  | 
  | 
| 
sl@0
 | 
   807  | 
	// For a success, the requested window must lie entirely within this chunk.
  | 
| 
sl@0
 | 
   808  | 
	TUint32 chnkEnd=(iChnk.iMemBaseAddr+iChnk.iMemLen-1);
  | 
| 
sl@0
 | 
   809  | 
	TUint32 winEnd=(aWin.iMemBaseAddr+aWin.iMemLen-1);
  | 
| 
sl@0
 | 
   810  | 
	TBool startIsInChnk=(aWin.iMemBaseAddr>=iChnk.iMemBaseAddr && aWin.iMemBaseAddr<=chnkEnd);
  | 
| 
sl@0
 | 
   811  | 
	TBool endIsInChnk=(winEnd>=iChnk.iMemBaseAddr && winEnd<=chnkEnd);
  | 
| 
sl@0
 | 
   812  | 
	if (startIsInChnk&&endIsInChnk)
  | 
| 
sl@0
 | 
   813  | 
		{
 | 
| 
sl@0
 | 
   814  | 
		// Possible success - first check the cache options are compatible
  | 
| 
sl@0
 | 
   815  | 
		if (!(aFlag|KPccdChunkCacheable)&&iCacheable)
  | 
| 
sl@0
 | 
   816  | 
			return(KErrAccessDenied);
  | 
| 
sl@0
 | 
   817  | 
  | 
| 
sl@0
 | 
   818  | 
		// Now check that the requested window isn't already allocated
  | 
| 
sl@0
 | 
   819  | 
		SDblQueLink* pW=iWindowQ.iA.iNext;
  | 
| 
sl@0
 | 
   820  | 
		while (pW!=&iWindowQ.iA)
  | 
| 
sl@0
 | 
   821  | 
			{
 | 
| 
sl@0
 | 
   822  | 
			RPccdWindow& w=*(RPccdWindow*)pW;
  | 
| 
sl@0
 | 
   823  | 
			pW=pW->iNext;
  | 
| 
sl@0
 | 
   824  | 
			if (w.Overlap(aWin.iMemBaseAddr-iChnk.iMemBaseAddr,aWin.iMemLen) )
  | 
| 
sl@0
 | 
   825  | 
				return(KErrAccessDenied);
  | 
| 
sl@0
 | 
   826  | 
			}
  | 
| 
sl@0
 | 
   827  | 
		return(KErrNone);
  | 
| 
sl@0
 | 
   828  | 
		}
  | 
| 
sl@0
 | 
   829  | 
	if (startIsInChnk||endIsInChnk)
  | 
| 
sl@0
 | 
   830  | 
		return(KErrAccessDenied);	// Requested window is partly in this chunk.
  | 
| 
sl@0
 | 
   831  | 
	return(KErrNotFound);
  | 
| 
sl@0
 | 
   832  | 
	}
  | 
| 
sl@0
 | 
   833  | 
  | 
| 
sl@0
 | 
   834  | 
void DPccdChunkBase::AddWindow(RPccdWindow *aWindow)
  | 
| 
sl@0
 | 
   835  | 
//
  | 
| 
sl@0
 | 
   836  | 
// Add a window to this chunk.
  | 
| 
sl@0
 | 
   837  | 
//
  | 
| 
sl@0
 | 
   838  | 
	{
 | 
| 
sl@0
 | 
   839  | 
	iWindowQ.Add(aWindow);
  | 
| 
sl@0
 | 
   840  | 
//	Kern::EnterCS();		Not needed since a single thread is used
  | 
| 
sl@0
 | 
   841  | 
	iWindows++;
  | 
| 
sl@0
 | 
   842  | 
	if (aWindow->IsPermanent())
  | 
| 
sl@0
 | 
   843  | 
		iPermanentWindows++;
  | 
| 
sl@0
 | 
   844  | 
	if (aWindow->IsShareable())
  | 
| 
sl@0
 | 
   845  | 
		iShareableWindows++;
  | 
| 
sl@0
 | 
   846  | 
	if (aWindow->IsSystemOwned())
  | 
| 
sl@0
 | 
   847  | 
		iSystemWindows++;
  | 
| 
sl@0
 | 
   848  | 
	else
  | 
| 
sl@0
 | 
   849  | 
		iSocket->iClientWindows++;
  | 
| 
sl@0
 | 
   850  | 
//	Kern::LeaveCS();
  | 
| 
sl@0
 | 
   851  | 
	aWindow->iChunk=this;
  | 
| 
sl@0
 | 
   852  | 
	}
  | 
| 
sl@0
 | 
   853  | 
  | 
| 
sl@0
 | 
   854  | 
void DPccdChunkBase::RemoveWindow(RPccdWindow *aWindow)
  | 
| 
sl@0
 | 
   855  | 
//
  | 
| 
sl@0
 | 
   856  | 
// Remove a window from this chunk (even if it's permanent). 
  | 
| 
sl@0
 | 
   857  | 
//	
  | 
| 
sl@0
 | 
   858  | 
	{
 | 
| 
sl@0
 | 
   859  | 
  | 
| 
sl@0
 | 
   860  | 
	if (aWindow->iNext && aWindow->iChunk==this)
  | 
| 
sl@0
 | 
   861  | 
		{
 | 
| 
sl@0
 | 
   862  | 
		aWindow->Deque();
  | 
| 
sl@0
 | 
   863  | 
		aWindow->iNext=NULL;
  | 
| 
sl@0
 | 
   864  | 
//		Kern::EnterCS();	Not needed since a single thread is used
  | 
| 
sl@0
 | 
   865  | 
		iWindows--;
  | 
| 
sl@0
 | 
   866  | 
		if (aWindow->IsPermanent())
  | 
| 
sl@0
 | 
   867  | 
			iPermanentWindows--;
  | 
| 
sl@0
 | 
   868  | 
		if (aWindow->IsShareable())
  | 
| 
sl@0
 | 
   869  | 
			iShareableWindows--;
  | 
| 
sl@0
 | 
   870  | 
		if (aWindow->IsSystemOwned())
  | 
| 
sl@0
 | 
   871  | 
			iSystemWindows--;
  | 
| 
sl@0
 | 
   872  | 
		else
  | 
| 
sl@0
 | 
   873  | 
			iSocket->iClientWindows--;
  | 
| 
sl@0
 | 
   874  | 
//		Kern::LeaveCS();
  | 
| 
sl@0
 | 
   875  | 
		if (iWindows==0)
  | 
| 
sl@0
 | 
   876  | 
			{
 | 
| 
sl@0
 | 
   877  | 
			iSocket->RemoveChunk(this);
  | 
| 
sl@0
 | 
   878  | 
			delete this;
  | 
| 
sl@0
 | 
   879  | 
			}
  | 
| 
sl@0
 | 
   880  | 
		}
  | 
| 
sl@0
 | 
   881  | 
	}
  | 
| 
sl@0
 | 
   882  | 
  | 
| 
sl@0
 | 
   883  | 
/********************************************
  | 
| 
sl@0
 | 
   884  | 
 * PC card memory window
  | 
| 
sl@0
 | 
   885  | 
 ********************************************/
  | 
| 
sl@0
 | 
   886  | 
EXPORT_C RPccdWindow::RPccdWindow()
  | 
| 
sl@0
 | 
   887  | 
//
  | 
| 
sl@0
 | 
   888  | 
// Constructor
  | 
| 
sl@0
 | 
   889  | 
//
  | 
| 
sl@0
 | 
   890  | 
	: iAccessSpeed(EAcSpeedInValid),iMemType(EPccdAttribMem),iOffset(0),iLen(0),iType(0)
  | 
| 
sl@0
 | 
   891  | 
	{
 | 
| 
sl@0
 | 
   892  | 
	iNext=NULL;
  | 
| 
sl@0
 | 
   893  | 
	iChunk=NULL;
  | 
| 
sl@0
 | 
   894  | 
	}
  | 
| 
sl@0
 | 
   895  | 
  | 
| 
sl@0
 | 
   896  | 
EXPORT_C TInt RPccdWindow::Create(DPcCardSocket* aSocket, TPccdChnk aChnk, TPccdAccessSpeed aSpeed, TUint aFlag)
  | 
| 
sl@0
 | 
   897  | 
//
  | 
| 
sl@0
 | 
   898  | 
// Create a block of memory (IO, Common or Attribute memory).
  | 
| 
sl@0
 | 
   899  | 
//
  | 
| 
sl@0
 | 
   900  | 
	{
 | 
| 
sl@0
 | 
   901  | 
  | 
| 
sl@0
 | 
   902  | 
	DPccdChunkBase *chunk=NULL;
  | 
| 
sl@0
 | 
   903  | 
	TBool chunkExists=EFalse;
  | 
| 
sl@0
 | 
   904  | 
	TInt r;
  | 
| 
sl@0
 | 
   905  | 
  | 
| 
sl@0
 | 
   906  | 
	// See if requested window is actually part of a chunk already created
  | 
| 
sl@0
 | 
   907  | 
	TInt i;
  | 
| 
sl@0
 | 
   908  | 
	for (i=0;i<aSocket->iMemChunks.Count();i++)
  | 
| 
sl@0
 | 
   909  | 
		{
 | 
| 
sl@0
 | 
   910  | 
		if ((r=aSocket->iMemChunks[i]->AllocateWinCheck(aChnk,aFlag))==KErrNone)
  | 
| 
sl@0
 | 
   911  | 
			{
 | 
| 
sl@0
 | 
   912  | 
			chunk=aSocket->iMemChunks[i];
  | 
| 
sl@0
 | 
   913  | 
			chunkExists=ETrue;
  | 
| 
sl@0
 | 
   914  | 
			break;
  | 
| 
sl@0
 | 
   915  | 
			}
  | 
| 
sl@0
 | 
   916  | 
		if (r==KErrAccessDenied)
  | 
| 
sl@0
 | 
   917  | 
			return r;
  | 
| 
sl@0
 | 
   918  | 
		}
  | 
| 
sl@0
 | 
   919  | 
  | 
| 
sl@0
 | 
   920  | 
	// If necesary, create a chunk
  | 
| 
sl@0
 | 
   921  | 
	if (!chunkExists)
  | 
| 
sl@0
 | 
   922  | 
		{
 | 
| 
sl@0
 | 
   923  | 
		// Create the memory chunk
  | 
| 
sl@0
 | 
   924  | 
		chunk=aSocket->NewPccdChunk(aChnk.iMemType);
  | 
| 
sl@0
 | 
   925  | 
		if (!chunk)
  | 
| 
sl@0
 | 
   926  | 
			return KErrNoMemory;
  | 
| 
sl@0
 | 
   927  | 
		TInt r=chunk->Create(aSocket, aChnk, aFlag);
  | 
| 
sl@0
 | 
   928  | 
		if (r==KErrNone)
  | 
| 
sl@0
 | 
   929  | 
			r=aSocket->iMemChunks.Append(chunk);
  | 
| 
sl@0
 | 
   930  | 
		if (r!=KErrNone)
  | 
| 
sl@0
 | 
   931  | 
			{
 | 
| 
sl@0
 | 
   932  | 
			delete chunk;
  | 
| 
sl@0
 | 
   933  | 
			return r;
  | 
| 
sl@0
 | 
   934  | 
			}
  | 
| 
sl@0
 | 
   935  | 
		}
  | 
| 
sl@0
 | 
   936  | 
	__KTRACE_OPT(KPBUS2,Kern::Printf("Skt:CreateMemWindowL-got chunk(existing-%d)",chunkExists));
 | 
| 
sl@0
 | 
   937  | 
  | 
| 
sl@0
 | 
   938  | 
	// Create the memory window
  | 
| 
sl@0
 | 
   939  | 
	iOffset=aChnk.iMemBaseAddr-chunk->BaseAddr();
  | 
| 
sl@0
 | 
   940  | 
	iLen=aChnk.iMemLen;
  | 
| 
sl@0
 | 
   941  | 
	iAccessSpeed=aSpeed;
  | 
| 
sl@0
 | 
   942  | 
	iMemType=aChnk.iMemType;
  | 
| 
sl@0
 | 
   943  | 
	iWaitSig=(aFlag&KPccdRequestWait);
  | 
| 
sl@0
 | 
   944  | 
	iType=aFlag&(KPccdChunkShared|KPccdChunkPermanent|KPccdChunkSystemOwned); // Save flag settings
  | 
| 
sl@0
 | 
   945  | 
	chunk->AddWindow(this);
  | 
| 
sl@0
 | 
   946  | 
	__KTRACE_OPT(KPBUS2,Kern::Printf("Skt:CreateMemWindowL-created window"));
 | 
| 
sl@0
 | 
   947  | 
	return KErrNone;
  | 
| 
sl@0
 | 
   948  | 
	}
  | 
| 
sl@0
 | 
   949  | 
  | 
| 
sl@0
 | 
   950  | 
EXPORT_C void RPccdWindow::Close()
  | 
| 
sl@0
 | 
   951  | 
	{
 | 
| 
sl@0
 | 
   952  | 
	if (iNext && iChunk)
  | 
| 
sl@0
 | 
   953  | 
		iChunk->RemoveWindow(this);
  | 
| 
sl@0
 | 
   954  | 
	}
  | 
| 
sl@0
 | 
   955  | 
  | 
| 
sl@0
 | 
   956  | 
EXPORT_C TInt RPccdWindow::SetupChunkHw(TUint aFlag)
  | 
| 
sl@0
 | 
   957  | 
//
  | 
| 
sl@0
 | 
   958  | 
// Config h/w in preparation for accessing window. Flag is for platform dependant info.
  | 
| 
sl@0
 | 
   959  | 
//
  | 
| 
sl@0
 | 
   960  | 
	{
 | 
| 
sl@0
 | 
   961  | 
  | 
| 
sl@0
 | 
   962  | 
	if (!iChunk)
  | 
| 
sl@0
 | 
   963  | 
		return(KErrNotReady);
  | 
| 
sl@0
 | 
   964  | 
	iChunk->SetupChunkHw(iAccessSpeed,iMemType,iWaitSig,aFlag);
  | 
| 
sl@0
 | 
   965  | 
//	iVcc->ResetInactivityTimer();
  | 
| 
sl@0
 | 
   966  | 
	return(KErrNone);
  | 
| 
sl@0
 | 
   967  | 
	}
  | 
| 
sl@0
 | 
   968  | 
  | 
| 
sl@0
 | 
   969  | 
EXPORT_C TLinAddr RPccdWindow::LinearAddress()
  | 
| 
sl@0
 | 
   970  | 
//
  | 
| 
sl@0
 | 
   971  | 
// Return linear address of window
  | 
| 
sl@0
 | 
   972  | 
//
  | 
| 
sl@0
 | 
   973  | 
	{
 | 
| 
sl@0
 | 
   974  | 
	return iChunk->LinearAddress()+iOffset;
  | 
| 
sl@0
 | 
   975  | 
	}
  | 
| 
sl@0
 | 
   976  | 
  | 
| 
sl@0
 | 
   977  | 
TBool RPccdWindow::Overlap(TUint32 anOffset,TUint aLen)
  | 
| 
sl@0
 | 
   978  | 
//
  | 
| 
sl@0
 | 
   979  | 
//
  | 
| 
sl@0
 | 
   980  | 
//
  | 
| 
sl@0
 | 
   981  | 
	{
 | 
| 
sl@0
 | 
   982  | 
	// If this window is sharable then it doesn't matter if they overlap or not.
  | 
| 
sl@0
 | 
   983  | 
	if (IsShareable())
  | 
| 
sl@0
 | 
   984  | 
		return(EFalse);
  | 
| 
sl@0
 | 
   985  | 
  | 
| 
sl@0
 | 
   986  | 
	TUint32 winEnd=(anOffset+aLen-1);
  | 
| 
sl@0
 | 
   987  | 
	TUint32 thisEnd=(iOffset+iLen-1);
  | 
| 
sl@0
 | 
   988  | 
	if ((anOffset>=iOffset && anOffset<=thisEnd) ||
  | 
| 
sl@0
 | 
   989  | 
		(winEnd>=iOffset && winEnd<=thisEnd) )
  | 
| 
sl@0
 | 
   990  | 
		return(ETrue);
  | 
| 
sl@0
 | 
   991  | 
  | 
| 
sl@0
 | 
   992  | 
	return(EFalse);
  | 
| 
sl@0
 | 
   993  | 
	}
  | 
| 
sl@0
 | 
   994  | 
  |