sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // e32\include\drivers\dmasupport.h sl@0: // sl@0: // sl@0: sl@0: #ifndef DMASUPPORT_H sl@0: #define DMASUPPORT_H sl@0: sl@0: #include "plat_priv.h" sl@0: #include sl@0: sl@0: sl@0: class TLocDrvRequest; sl@0: sl@0: /** sl@0: @internalTechnology sl@0: @prototype sl@0: sl@0: Class used for read / write requests to the local media subsystem to gain access sl@0: to physical memory address to make use of DMA without the need of an intermediate buffer. sl@0: */ sl@0: class DDmaHelper : public DBase sl@0: { sl@0: public: sl@0: sl@0: enum TMemoryType sl@0: { sl@0: EUnknown, sl@0: EFileServerChunk, sl@0: ESharedChunk, sl@0: }; sl@0: sl@0: /** sl@0: Class used to describe a number of contiguous physical pages sl@0: */ sl@0: class TPageList sl@0: { sl@0: public: sl@0: TPhysAddr iAddress; // address of page sl@0: TInt iLength; sl@0: }; sl@0: sl@0: public: sl@0: DDmaHelper(); sl@0: ~DDmaHelper(); sl@0: sl@0: TInt Construct(TInt aLength, TInt aMediaBlockSize, TInt aDmaAlignment); sl@0: sl@0: TInt SendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress); sl@0: TInt GetPhysicalAddress(TPhysAddr& aAddr, TInt& aLen); sl@0: sl@0: #ifdef __DEMAND_PAGING__ sl@0: static TInt GetPhysicalAddress(TLocDrvRequest& aReq, TPhysAddr& aAddr, TInt& aLen); sl@0: #endif sl@0: inline TInt PageSize() const { return iPageSize; } sl@0: sl@0: private: sl@0: sl@0: static inline TInt PageSizeLog2(); sl@0: static inline TBool IsPageAligned(TLinAddr aAddr); sl@0: static inline TLinAddr PageAlign(TLinAddr aAddr); sl@0: static inline TLinAddr PageOffset(TLinAddr aAddr); sl@0: sl@0: inline TInt MaxFragLength() const; sl@0: inline void SetFragLength(TInt aLength); sl@0: inline TInt FragLength() const; sl@0: inline TInt LengthRemaining() const; sl@0: inline TUint32 LengthConsumed() const; sl@0: sl@0: inline TBool IsDmaAligned(TLinAddr aAddr); sl@0: inline TBool IsBlockAligned(TInt64 aPos); sl@0: inline TInt64 BlockAlign(TInt64 aPos); sl@0: inline TInt BlockOffset(TInt64 aPos); sl@0: sl@0: inline TLinAddr LinAddress() const; sl@0: sl@0: void ResetPageLists(); sl@0: sl@0: TInt UpdateRemoteDescriptorLength(TInt aLength); sl@0: sl@0: TInt RequestStart(); sl@0: void RequestEnd(); sl@0: void BuildPageList(); sl@0: void ReleasePages(TLinAddr aAddr); sl@0: sl@0: private: sl@0: TInt iMediaBlockSize; // Minimum transfer size (bytes) for the media. sl@0: TInt64 iMediaBlockSizeMask; // iMediaBlockSize - 1 sl@0: TInt iDmaAlignment; // DMA Alignment req for media's DMA controller i.e. word alignment sl@0: sl@0: static TInt iPageSize; // Memory page size in bytes (e.g. 4096 Bytes) sl@0: static TInt iPageSizeLog2; // Log2 of page size (e.g. 4096 -> 12) sl@0: static TInt iPageSizeMsk; // Mask of page size (e.g. 4096-1 -> 4095) sl@0: TInt iMaxPages; // Maximum number of pages that can be stored by this object sl@0: sl@0: DThread* iRemoteThread; // sl@0: DThread* iCurrentThread; // sl@0: DThread* iOwningThread; // Thread owning remote descriptor, either iRemoteThread or iCurrentThread sl@0: sl@0: TLocDrvRequest* iReq; // Current TLocDrvRequest sl@0: sl@0: // The following attributes are copied from the current TLocDrvRequest sl@0: TInt iReqId; sl@0: TInt iReqRemoteDesOffset; sl@0: TInt iReqFlags; // sl@0: TInt iReqLenClient; // length of data requested by client (unmodified) sl@0: TInt64 iReqPosClient; // position of data requested by client (unmodified) sl@0: sl@0: TLinAddr iLinAddressUser; // linear address of client buffer in user process sl@0: TLinAddr iLinAddressKernel; // linear address of client buffer in kernel process sl@0: TInt iFragLen; // length of data to be read into physical pages (possibly < a multiple of the page-size) sl@0: TInt iFragLenRemaining; // length of data to be read left in this fragment sl@0: sl@0: TMemoryType iMemoryType; sl@0: sl@0: /** array of (possibly non-contiguous) pages */ sl@0: TPhysAddr* iPageArray; sl@0: TInt iPageArrayCount; sl@0: sl@0: /** list of contiguous pages */ sl@0: TPageList* iPageList; sl@0: TInt iPageListCount; sl@0: sl@0: TInt iIndex; // Current memory fragment index sl@0: sl@0: /** Represents the current read/write position in terms of an offset sl@0: from the start of the caller's linear address */ sl@0: TInt iLenConsumed; // Offset from start of client buffer sl@0: sl@0: DChunk* iChunk; // Shared chunk object in use sl@0: TInt iChunkOffset; // Offset within shared chunk sl@0: TUint32 iMapAttr; // mmu mapping attributes for the Shared chunk or pinned physical memory. sl@0: TUint32 iPhysAddr; // Physical Address of chunk (if contiguous) sl@0: sl@0: TInt iLockCount; // Prevent 2+ threads accessing this object sl@0: sl@0: TBool iPhysPinningAvailable; // True if physical memory pinning Kernel interface is available sl@0: TUint iPageColour; // Mapping colour of the first page in iPageArray. sl@0: TPhysicalPinObject* iPhysicalPinObject; // Physical pinning object. sl@0: }; sl@0: sl@0: sl@0: sl@0: #endif // DMASUPPORT_H