Update contrib.
1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\drivers\pbus\pccard\epoc\pccd_chunk.cpp
18 #include <pccd_chunk.h>
20 DPlatPccdChunk::DPlatPccdChunk()
30 DPlatPccdChunk::~DPlatPccdChunk()
32 // Destroy (base class destructor called after this)
35 __KTRACE_OPT(KPBUS1,Kern::Printf(">PlatChunk:~PlatChunk(P:%xH,C:%xH)",iChunk,this));
38 void DPlatPccdChunk::Close()
40 // Destroy (base class destructor called after this)
43 __KTRACE_OPT(KPBUS1,Kern::Printf(">PlatChunk:Close(P:%xH,C:%xH)",iChunk,this));
45 Kern::SafeClose((DObject*&)iChunk,NULL);
46 DPccdChunkBase::Close();
49 TInt DPlatPccdChunk::DoCreate(TPccdChnk aChunk, TUint aFlag)
51 // Create a chunk of Pc Card h/w. Base addresses are rounded down to a page size boundary and
52 // chunk sizes are rounded up in size to a whole page.
55 __KTRACE_OPT(KPBUS2,Kern::Printf(">PlatChunk::DoCreate"));
56 // Round base address down to page size boundary, then calculate physical addresss for this chunk.
57 TUint32 pageSize=Kern::RoundToPageSize(1);
58 iChnk.iMemBaseAddr&=~(pageSize-1); // Round it down.
59 TUint32 roundingOffset=aChunk.iMemBaseAddr-iChnk.iMemBaseAddr;
60 TUint32 physAddr=iChnk.iMemBaseAddr;
61 physAddr+=ThePccdCntrlInterface->MemPhysicalAddress(iSocket->iSocketNumber,iChnk.iMemType);
63 // Round size (plus anything gained in rounding base address) up to page size
64 iChnk.iMemLen=Kern::RoundToPageSize(iChnk.iMemLen+roundingOffset);
66 TInt attribs=EMapAttrSupRw;
68 attribs |= EMapAttrCachedMax;
70 __KTRACE_OPT(KPBUS1,Kern::Printf("PlatChunk:DoCreate(L:%xH PA:%xH)",iChnk.iMemLen,physAddr));
71 TInt r=DPlatChunkHw::New(iChunk, physAddr, iChnk.iMemLen, attribs);
77 __KTRACE_OPT(KPBUS2,Kern::Printf("PlatChunk(%xH):DoCreate(LA:%xH)",iChunk,iChunk->LinearAddress()));
82 TInt DPlatPccdChunk::SetupChunkHw(TPccdAccessSpeed aSpeed,TPccdMemType aMemType,TBool aWaitSig,TUint aFlag)
84 // Config h/w in preparation for accessing chunk
88 __KTRACE_OPT(KPBUS2,Kern::Printf("PlatChunk:SetupChunkHw(SP:%d CT:%d RT:%d W:%d F:%d)",aSpeed,iChnk.iMemType,aMemType,aWaitSig,aFlag));
89 if (ThePccdCntrlInterface->MemConfig(iSocket->iSocketNumber,aMemType,aSpeed,aWaitSig,aFlag)==KMemConfigByteAccess)
91 iFlag|=KPccdChunkByteAccessOnly;
92 __KTRACE_OPT(KPBUS2,Kern::Printf("Byte access only"));
97 TLinAddr DPlatPccdChunk::LinearAddress()
99 // Return linear address of window
102 TLinAddr a=iChunk->LinearAddress();
103 __KTRACE_OPT(KPBUS2,Kern::Printf("<PlatChunk(%xH):LinAddr(%xH)",iChunk,a));
107 TInt DPlatPccdChunk::Read(TInt aPos,TAny *aPtr,TInt aLength)
109 // Perform a read (length always in bytes)
113 __KTRACE_OPT(KPBUS2,Kern::Printf("PlatChunk(%xH):Read(%xH from %08xH)",iChunk,aLength,aPos));
115 volatile TUint8 *pData=(volatile TUint8*)(iChunk->LinearAddress()+aPos);
116 if (!(iFlag&KPccdChunkByteAccessOnly))
118 if (aLength==1) // Probably the ATA command.
119 *(TUint8*)aPtr=*pData;
121 memcpy(aPtr,(TAny*)pData,aLength);
126 TUint8 *pT=(TUint8*)aPtr;
127 TUint8 *pTE=pT+aLength;
135 TInt DPlatPccdChunk::Write(TInt aPos,const TAny *aPtr,TInt aLength)
137 // Perform a write (length always in bytes)
141 __KTRACE_OPT(KPBUS2,Kern::Printf("PlatChunk(%xH):Write(%xH to %08xH)",iChunk,aLength,aPos));
143 volatile TUint8 *pData=(volatile TUint8*)((iChunk->LinearAddress())+aPos);
144 if (!(iFlag&KPccdChunkByteAccessOnly))
146 if (aLength==1) // Probably the ATA command.
147 *pData=*(TUint8*)aPtr;
149 memcpy((TAny*)pData,aPtr,aLength);
154 TUint8 *pS=(TUint8*)aPtr;
155 TUint8 *pSE=pS+aLength;
163 TInt DPlatPccdChunk::ReadByteMultiple(TInt aPos,TAny *aPtr,TInt aCount)
165 // Perform a multiple read from a single byte (aCount in bytes)
169 __KTRACE_OPT(KPBUS2,Kern::Printf("PlatChunk(%xH):ReadByteMult(%xH from %08xH)",iChunk,aCount,aPos));
171 volatile TUint8 *pS=(volatile TUint8*)((iChunk->LinearAddress())+aPos);
172 TUint8 *pT=(TUint8*)aPtr;
173 TUint8 *pTE=pT+aCount;
180 TInt DPlatPccdChunk::WriteByteMultiple(TInt aPos,const TAny *aPtr,TInt aCount)
182 // Perform a multiple write to a single byte (aCount in bytes)
186 __KTRACE_OPT(KPBUS2,Kern::Printf("PlatChunk(%xH):WriteByteMult(%xH to %08xH)",iChunk,aCount,aPos));
188 volatile TUint8 *pT=(volatile TUint8*)((iChunk->LinearAddress())+aPos);
189 TUint8 *pS=(TUint8*)aPtr;
190 TUint8 *pSE=pS+aCount;
197 #ifndef __PCCD_MACHINE_CODED__
198 TInt DPlatPccdChunk::ReadHWordMultiple(TInt aPos,TAny *aPtr,TInt aCount)
200 // Perform a series of reads of 16bit halfwords from a single location in the chunk (aCount is in hwords).
204 __KTRACE_OPT(KPBUS2,Kern::Printf(">PlatChunk(%xH):ReadHWordMult(%xH from %08xH)",iChunk,aCount,aPos));
206 volatile TUint16 *pS=(volatile TUint16*)((iChunk->LinearAddress())+aPos);
207 TUint16 *pT=(TUint16*)aPtr;
208 TUint16 *pTE=pT+aCount;
212 __KTRACE_OPT(KPBUS2,Kern::Printf("<RHWM"));
216 TInt DPlatPccdChunk::WriteHWordMultiple(TInt aPos,const TAny *aPtr,TInt aCount)
218 // Perform a series of writes of 16bit halfwords to a single location in the chunk (aCount is in hwords).
222 __KTRACE_OPT(KPBUS2,Kern::Printf(">PlatChunk(%xH):WriteHWordMult(%xH to %08xH)",iChunk,aCount,aPos));
224 volatile TUint16 *pT=(volatile TUint16*)((iChunk->LinearAddress())+aPos);
225 TUint16 *pS=(TUint16*)aPtr;
226 TUint16 *pSE=(pS+aCount);
230 __KTRACE_OPT(KPBUS2,Kern::Printf("<WHWM"));
234 TUint DPlatPccdChunk::Read8(TInt aPos)
236 volatile TUint8 *pT=(volatile TUint8*)((iChunk->LinearAddress())+aPos);
240 void DPlatPccdChunk::Write8(TInt aPos, TUint aValue)
242 volatile TUint8 *pT=(volatile TUint8*)((iChunk->LinearAddress())+aPos);
247 TBool DPlatPccdChunk::IsTypeCompatible(TPccdMemType aMemType)
249 // Check if this chunk type is compatible with specified type
253 if (aMemType==iChnk.iMemType)
255 if ((aMemType==EPccdAttribMem||aMemType==EPccdCommon8Mem)&&(iChnk.iMemType==EPccdAttribMem||iChnk.iMemType==EPccdCommon8Mem))