os/kernelhwsrv/kernel/eka/drivers/locmedia/dmasupport.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-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\include\drivers\dmasupport.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef DMASUPPORT_H
sl@0
    19
#define DMASUPPORT_H
sl@0
    20
sl@0
    21
#include "plat_priv.h"
sl@0
    22
#include <d32locd.h>
sl@0
    23
sl@0
    24
sl@0
    25
class TLocDrvRequest;
sl@0
    26
sl@0
    27
/**
sl@0
    28
@internalTechnology
sl@0
    29
@prototype
sl@0
    30
sl@0
    31
Class used for read / write requests to the local media subsystem to gain access
sl@0
    32
to physical memory address to make use of DMA without the need of an intermediate buffer.
sl@0
    33
*/
sl@0
    34
class DDmaHelper : public DBase
sl@0
    35
	{
sl@0
    36
public:
sl@0
    37
sl@0
    38
	enum TMemoryType
sl@0
    39
		{
sl@0
    40
		EUnknown,
sl@0
    41
		EFileServerChunk,
sl@0
    42
		ESharedChunk,
sl@0
    43
		};
sl@0
    44
sl@0
    45
	/**
sl@0
    46
	Class used to describe a number of contiguous physical pages
sl@0
    47
	*/
sl@0
    48
	class TPageList
sl@0
    49
		{
sl@0
    50
	public:
sl@0
    51
		TPhysAddr iAddress;	// address of page
sl@0
    52
		TInt 	  iLength;
sl@0
    53
		};
sl@0
    54
sl@0
    55
public:
sl@0
    56
	DDmaHelper();
sl@0
    57
	~DDmaHelper();
sl@0
    58
	
sl@0
    59
	TInt Construct(TInt aLength, TInt aMediaBlockSize, TInt aDmaAlignment);
sl@0
    60
	
sl@0
    61
	TInt SendReceive(TLocDrvRequest& aReq, TLinAddr aLinAddress);
sl@0
    62
	TInt GetPhysicalAddress(TPhysAddr& aAddr, TInt& aLen);
sl@0
    63
sl@0
    64
#ifdef __DEMAND_PAGING__
sl@0
    65
	static TInt GetPhysicalAddress(TLocDrvRequest& aReq, TPhysAddr& aAddr, TInt& aLen);
sl@0
    66
#endif
sl@0
    67
	inline TInt PageSize()	const { return iPageSize; }
sl@0
    68
	
sl@0
    69
private:
sl@0
    70
sl@0
    71
	static inline TInt PageSizeLog2();
sl@0
    72
	static inline TBool IsPageAligned(TLinAddr aAddr);
sl@0
    73
	static inline TLinAddr PageAlign(TLinAddr aAddr);
sl@0
    74
	static inline TLinAddr PageOffset(TLinAddr aAddr);
sl@0
    75
sl@0
    76
	inline TInt MaxFragLength()	const;
sl@0
    77
	inline void SetFragLength(TInt aLength);
sl@0
    78
	inline TInt FragLength()	const;
sl@0
    79
	inline TInt LengthRemaining() const;
sl@0
    80
	inline TUint32 LengthConsumed() const;
sl@0
    81
sl@0
    82
	inline TBool IsDmaAligned(TLinAddr aAddr);
sl@0
    83
	inline TBool IsBlockAligned(TInt64 aPos);
sl@0
    84
	inline TInt64 BlockAlign(TInt64 aPos);
sl@0
    85
	inline TInt BlockOffset(TInt64 aPos);
sl@0
    86
sl@0
    87
	inline TLinAddr LinAddress() const;
sl@0
    88
sl@0
    89
	void ResetPageLists();
sl@0
    90
sl@0
    91
	TInt UpdateRemoteDescriptorLength(TInt aLength);
sl@0
    92
sl@0
    93
	TInt RequestStart();
sl@0
    94
	void RequestEnd();
sl@0
    95
	void BuildPageList();
sl@0
    96
	void ReleasePages(TLinAddr aAddr);
sl@0
    97
sl@0
    98
private:
sl@0
    99
	TInt iMediaBlockSize;		// Minimum transfer size (bytes) for the media.
sl@0
   100
	TInt64 iMediaBlockSizeMask;	// iMediaBlockSize - 1
sl@0
   101
	TInt iDmaAlignment;			// DMA Alignment req for media's DMA controller i.e. word alignment
sl@0
   102
sl@0
   103
	static TInt iPageSize;		// Memory page size in bytes (e.g. 4096 Bytes)
sl@0
   104
	static TInt iPageSizeLog2;	// Log2 of page size (e.g. 4096 -> 12)
sl@0
   105
	static TInt iPageSizeMsk;	// Mask of page size (e.g. 4096-1 -> 4095)
sl@0
   106
	TInt iMaxPages;				// Maximum number of pages that can be stored by this object
sl@0
   107
sl@0
   108
	DThread* iRemoteThread;		// 
sl@0
   109
	DThread* iCurrentThread;	//  
sl@0
   110
	DThread* iOwningThread;		// Thread owning remote descriptor, either iRemoteThread or iCurrentThread
sl@0
   111
sl@0
   112
	TLocDrvRequest* iReq;		// Current TLocDrvRequest
sl@0
   113
	
sl@0
   114
	// The following attributes are copied from the current TLocDrvRequest
sl@0
   115
	TInt iReqId;
sl@0
   116
	TInt iReqRemoteDesOffset;
sl@0
   117
	TInt iReqFlags;				// 
sl@0
   118
	TInt iReqLenClient;			// length of data requested by client (unmodified)
sl@0
   119
	TInt64 iReqPosClient;		// position of data requested by client (unmodified)
sl@0
   120
sl@0
   121
	TLinAddr iLinAddressUser;	// linear address of client buffer in user process
sl@0
   122
	TLinAddr iLinAddressKernel;	// linear address of client buffer in kernel process
sl@0
   123
	TInt iFragLen;				// length of data to be read into physical pages (possibly < a multiple of the page-size)
sl@0
   124
	TInt iFragLenRemaining;		// length of data to be read left in this fragment
sl@0
   125
sl@0
   126
	TMemoryType iMemoryType;
sl@0
   127
	
sl@0
   128
	/** array of (possibly non-contiguous) pages */
sl@0
   129
	TPhysAddr* iPageArray;
sl@0
   130
	TInt iPageArrayCount;
sl@0
   131
	
sl@0
   132
	/** list of contiguous pages */
sl@0
   133
	TPageList* iPageList;
sl@0
   134
	TInt iPageListCount;
sl@0
   135
sl@0
   136
	TInt iIndex;					// Current memory fragment index
sl@0
   137
	
sl@0
   138
	/** Represents the current read/write position in terms of an offset 
sl@0
   139
	from the start of the caller's linear address */ 
sl@0
   140
	TInt iLenConsumed;				// Offset from start of client buffer
sl@0
   141
sl@0
   142
	DChunk* iChunk;					// Shared chunk object in use
sl@0
   143
	TInt    iChunkOffset;			// Offset within shared chunk
sl@0
   144
	TUint32 iMapAttr;				// mmu mapping attributes for the Shared chunk or pinned physical memory.
sl@0
   145
	TUint32 iPhysAddr;				// Physical Address of chunk (if contiguous)
sl@0
   146
sl@0
   147
	TInt iLockCount;				// Prevent 2+ threads accessing this object
sl@0
   148
	
sl@0
   149
	TBool iPhysPinningAvailable;    // True if physical memory pinning Kernel interface is available
sl@0
   150
	TUint  iPageColour;				// Mapping colour of the first page in iPageArray.
sl@0
   151
	TPhysicalPinObject* iPhysicalPinObject;	// Physical pinning object.
sl@0
   152
	};
sl@0
   153
sl@0
   154
sl@0
   155
sl@0
   156
#endif	// DMASUPPORT_H