os/kernelhwsrv/kernel/eka/drivers/locmedia/dmasupport.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/drivers/locmedia/dmasupport.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,156 @@
     1.4 +// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of the License "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// e32\include\drivers\dmasupport.h
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#ifndef DMASUPPORT_H
    1.22 +#define DMASUPPORT_H
    1.23 +
    1.24 +#include "plat_priv.h"
    1.25 +#include <d32locd.h>
    1.26 +
    1.27 +
    1.28 +class TLocDrvRequest;
    1.29 +
    1.30 +/**
    1.31 +@internalTechnology
    1.32 +@prototype
    1.33 +
    1.34 +Class used for read / write requests to the local media subsystem to gain access
    1.35 +to physical memory address to make use of DMA without the need of an intermediate buffer.
    1.36 +*/
    1.37 +class DDmaHelper : public DBase
    1.38 +	{
    1.39 +public:
    1.40 +
    1.41 +	enum TMemoryType
    1.42 +		{
    1.43 +		EUnknown,
    1.44 +		EFileServerChunk,
    1.45 +		ESharedChunk,
    1.46 +		};
    1.47 +
    1.48 +	/**
    1.49 +	Class used to describe a number of contiguous physical pages
    1.50 +	*/
    1.51 +	class TPageList
    1.52 +		{
    1.53 +	public:
    1.54 +		TPhysAddr iAddress;	// address of page
    1.55 +		TInt 	  iLength;
    1.56 +		};
    1.57 +
    1.58 +public:
    1.59 +	DDmaHelper();
    1.60 +	~DDmaHelper();
    1.61 +	
    1.62 +	TInt Construct(TInt aLength, TInt aMediaBlockSize, TInt aDmaAlignment);
    1.63 +	
    1.64 +	TInt SendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress);
    1.65 +	TInt GetPhysicalAddress(TPhysAddr& aAddr, TInt& aLen);
    1.66 +
    1.67 +#ifdef __DEMAND_PAGING__
    1.68 +	static TInt GetPhysicalAddress(TLocDrvRequest& aReq, TPhysAddr& aAddr, TInt& aLen);
    1.69 +#endif
    1.70 +	inline TInt PageSize()	const { return iPageSize; }
    1.71 +	
    1.72 +private:
    1.73 +
    1.74 +	static inline TInt PageSizeLog2();
    1.75 +	static inline TBool IsPageAligned(TLinAddr aAddr);
    1.76 +	static inline TLinAddr PageAlign(TLinAddr aAddr);
    1.77 +	static inline TLinAddr PageOffset(TLinAddr aAddr);
    1.78 +
    1.79 +	inline TInt MaxFragLength()	const;
    1.80 +	inline void SetFragLength(TInt aLength);
    1.81 +	inline TInt FragLength()	const;
    1.82 +	inline TInt LengthRemaining() const;
    1.83 +	inline TUint32 LengthConsumed() const;
    1.84 +
    1.85 +	inline TBool IsDmaAligned(TLinAddr aAddr);
    1.86 +	inline TBool IsBlockAligned(TInt64 aPos);
    1.87 +	inline TInt64 BlockAlign(TInt64 aPos);
    1.88 +	inline TInt BlockOffset(TInt64 aPos);
    1.89 +
    1.90 +	inline TLinAddr LinAddress() const;
    1.91 +
    1.92 +	void ResetPageLists();
    1.93 +
    1.94 +	TInt UpdateRemoteDescriptorLength(TInt aLength);
    1.95 +
    1.96 +	TInt RequestStart();
    1.97 +	void RequestEnd();
    1.98 +	void BuildPageList();
    1.99 +	void ReleasePages(TLinAddr aAddr);
   1.100 +
   1.101 +private:
   1.102 +	TInt iMediaBlockSize;		// Minimum transfer size (bytes) for the media.
   1.103 +	TInt64 iMediaBlockSizeMask;	// iMediaBlockSize - 1
   1.104 +	TInt iDmaAlignment;			// DMA Alignment req for media's DMA controller i.e. word alignment
   1.105 +
   1.106 +	static TInt iPageSize;		// Memory page size in bytes (e.g. 4096 Bytes)
   1.107 +	static TInt iPageSizeLog2;	// Log2 of page size (e.g. 4096 -> 12)
   1.108 +	static TInt iPageSizeMsk;	// Mask of page size (e.g. 4096-1 -> 4095)
   1.109 +	TInt iMaxPages;				// Maximum number of pages that can be stored by this object
   1.110 +
   1.111 +	DThread* iRemoteThread;		// 
   1.112 +	DThread* iCurrentThread;	//  
   1.113 +	DThread* iOwningThread;		// Thread owning remote descriptor, either iRemoteThread or iCurrentThread
   1.114 +
   1.115 +	TLocDrvRequest* iReq;		// Current TLocDrvRequest
   1.116 +	
   1.117 +	// The following attributes are copied from the current TLocDrvRequest
   1.118 +	TInt iReqId;
   1.119 +	TInt iReqRemoteDesOffset;
   1.120 +	TInt iReqFlags;				// 
   1.121 +	TInt iReqLenClient;			// length of data requested by client (unmodified)
   1.122 +	TInt64 iReqPosClient;		// position of data requested by client (unmodified)
   1.123 +
   1.124 +	TLinAddr iLinAddressUser;	// linear address of client buffer in user process
   1.125 +	TLinAddr iLinAddressKernel;	// linear address of client buffer in kernel process
   1.126 +	TInt iFragLen;				// length of data to be read into physical pages (possibly < a multiple of the page-size)
   1.127 +	TInt iFragLenRemaining;		// length of data to be read left in this fragment
   1.128 +
   1.129 +	TMemoryType iMemoryType;
   1.130 +	
   1.131 +	/** array of (possibly non-contiguous) pages */
   1.132 +	TPhysAddr* iPageArray;
   1.133 +	TInt iPageArrayCount;
   1.134 +	
   1.135 +	/** list of contiguous pages */
   1.136 +	TPageList* iPageList;
   1.137 +	TInt iPageListCount;
   1.138 +
   1.139 +	TInt iIndex;					// Current memory fragment index
   1.140 +	
   1.141 +	/** Represents the current read/write position in terms of an offset 
   1.142 +	from the start of the caller's linear address */ 
   1.143 +	TInt iLenConsumed;				// Offset from start of client buffer
   1.144 +
   1.145 +	DChunk* iChunk;					// Shared chunk object in use
   1.146 +	TInt    iChunkOffset;			// Offset within shared chunk
   1.147 +	TUint32 iMapAttr;				// mmu mapping attributes for the Shared chunk or pinned physical memory.
   1.148 +	TUint32 iPhysAddr;				// Physical Address of chunk (if contiguous)
   1.149 +
   1.150 +	TInt iLockCount;				// Prevent 2+ threads accessing this object
   1.151 +	
   1.152 +	TBool iPhysPinningAvailable;    // True if physical memory pinning Kernel interface is available
   1.153 +	TUint  iPageColour;				// Mapping colour of the first page in iPageArray.
   1.154 +	TPhysicalPinObject* iPhysicalPinObject;	// Physical pinning object.
   1.155 +	};
   1.156 +
   1.157 +
   1.158 +
   1.159 +#endif	// DMASUPPORT_H