0
|
1 |
// Copyright (c) 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".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32/include/kernel/sshbuf.h
|
|
15 |
// Shareable Data Buffers
|
|
16 |
|
|
17 |
|
|
18 |
/**
|
|
19 |
@file
|
|
20 |
@internalComponent
|
|
21 |
@prototype
|
|
22 |
*/
|
|
23 |
|
|
24 |
#ifndef SSHBUF_H
|
|
25 |
#define SSHBUF_H
|
|
26 |
|
|
27 |
|
|
28 |
// Forward declarations
|
|
29 |
class DShBuf;
|
|
30 |
class SMap;
|
|
31 |
|
|
32 |
#include <kernel/kern_priv.h>
|
|
33 |
|
|
34 |
|
|
35 |
class DShPoolClient : public DBase
|
|
36 |
{
|
|
37 |
public:
|
|
38 |
DShPoolClient() : iAccessCount(1), iFlags(0)
|
|
39 |
{};
|
|
40 |
TInt iAccessCount;
|
|
41 |
TUint iFlags;
|
|
42 |
};
|
|
43 |
|
|
44 |
|
|
45 |
class DShPool : public DObject
|
|
46 |
{
|
|
47 |
public:
|
|
48 |
DShPool();
|
|
49 |
virtual ~DShPool();
|
|
50 |
|
|
51 |
TInt Create(DObject* aOwner, TShPoolCreateInfo& aInfo);
|
|
52 |
virtual TInt Close(TAny*);
|
|
53 |
|
|
54 |
virtual TInt Alloc(DShBuf*&) = 0;
|
|
55 |
void GetInfo(TShPoolInfo& aInfo);
|
|
56 |
inline TUint BufSize() const {return iBufSize;};
|
|
57 |
TUint FreeCount();
|
|
58 |
TInt AddNotification(TShPoolNotifyType aType, TUint aThreshold, TRequestStatus& aStatus);
|
|
59 |
TInt RemoveNotification(TShPoolNotifyType aType, TRequestStatus& aStatus);
|
|
60 |
|
|
61 |
TInt RequestUserHandle(DThread *aThread, TOwnerType aType);
|
|
62 |
TInt ModifyClientFlags(DProcess* aProcess, TUint aSetMask, TUint aClearMask);
|
|
63 |
|
|
64 |
virtual TInt SetBufferWindow(DProcess* aProcess, TInt aWindowSize);
|
|
65 |
|
|
66 |
protected:
|
|
67 |
virtual TInt DoCreate(TShPoolCreateInfo& aInfo);
|
|
68 |
virtual TInt CreateInitialBuffers();
|
|
69 |
virtual TInt DeleteInitialBuffers();
|
|
70 |
virtual TInt GrowPool()=0;
|
|
71 |
virtual TInt ShrinkPool()=0;
|
|
72 |
TInt OpenClient(DProcess* aProcess, TUint& aFlags);
|
|
73 |
void CloseClient(DProcess* aProcess);
|
|
74 |
virtual void DestroyClientResources(DProcess* aProcess)=0;
|
|
75 |
virtual void Free(DShBuf* aBuf) = 0;
|
|
76 |
TInt UpdateReservedHandles(TInt aNoOfBuffers);
|
|
77 |
virtual TInt UpdateFreeList() = 0;
|
|
78 |
static void ManagementDfc(TAny* aPool); // this DFC does the automatic allocations in the context of the driver thread, and completes any pending notification requests
|
|
79 |
|
|
80 |
void CalculateGrowShrinkTriggers();
|
|
81 |
static TUint mult_fx248(TUint n, TUint f); // multiplies a TUint by an fx24.8 fixed-point ratio
|
|
82 |
TBool HaveWorkToDo();
|
|
83 |
void KickManagementDfc();
|
|
84 |
|
|
85 |
void CompleteAllNotifications();
|
|
86 |
void CheckAndCompleteNotifications(TBool aAll);
|
|
87 |
void CheckLowSpaceNotificationQueue(TBool aAll);
|
|
88 |
void CheckFreeSpaceNotificationQueue(TBool aAll);
|
|
89 |
|
|
90 |
inline void LockPool()
|
|
91 |
{
|
|
92 |
NKern::FMWait(&iLock);
|
|
93 |
}
|
|
94 |
inline void UnlockPool()
|
|
95 |
{
|
|
96 |
NKern::FMSignal(&iLock);
|
|
97 |
}
|
|
98 |
|
|
99 |
protected:
|
|
100 |
SMap* iClientMap;
|
|
101 |
|
|
102 |
static TDfcQue iSharedDfcQue; // shared DFCQ thread for servicing asynch notification requests
|
|
103 |
|
|
104 |
SDblQue iNotifLowReqQueue; // queue of TShPoolNotificationRequests for low space (only accessed from our DFC thread, so access doesn't need to be protected by a mutex)
|
|
105 |
SDblQue iNotifFreeReqQueue; // queue of TShPoolNotificationRequests for free space (only accessed from our DFC thread, so access doesn't need to be protected by a mutex)
|
|
106 |
TDfc iNotifDfc; // DFC to auto alloc and/or complete notification requests (will run in DFC thread)
|
|
107 |
TUint iLowSpaceThreshold; // Value of largest threshold on list + 1
|
|
108 |
TUint iFreeSpaceThreshold; // Value of smallest threshold on list
|
|
109 |
NFastMutex iLock; // to protect allocations/deallocations of buffers on pool
|
|
110 |
DMutex *iProcessLock; // to protect access to the following
|
|
111 |
|
|
112 |
SDblQue iFreeList;
|
|
113 |
SDblQue iAltFreeList;
|
|
114 |
TUint iFreeBuffers; // number of free buffers
|
|
115 |
TUint iTotalBuffers; // number of buffers in the pool
|
|
116 |
#ifdef _DEBUG
|
|
117 |
TUint iAllocatedBuffers; // number of allocated buffers
|
|
118 |
SDblQue iAllocated;
|
|
119 |
#endif
|
|
120 |
TUint iInitialBuffers; // initial number of buffers
|
|
121 |
TUint iMaxBuffers; // total number of buffers there can ever be (if pool grown to max)
|
|
122 |
TUint iAlignment;
|
|
123 |
TUint iBufSize; // size of buffers in this pool
|
|
124 |
TUint iBufGap; // bytes from one buffer to the next in this pool. >= iBufSize. For alignment.
|
|
125 |
TUint iCommittedPages; // current committed size of pool (chunk)
|
|
126 |
TUint iMaxPages; // max size of pool (chunk)
|
|
127 |
// for growing and shrinking:
|
|
128 |
TUint iGrowTriggerRatio; // when to grow the pool (proportion free of total buffers, fixed-point fx24.8)
|
|
129 |
TUint iGrowByRatio; // how much bigger to make pool (proportion of total buffers, fx24.8)
|
|
130 |
TUint iShrinkHysteresisRatio; // to avoid shrinking immed after growing, also fx24.8
|
|
131 |
TUint iShrinkByRatio; // calculated from iGrowByRatio
|
|
132 |
TUint iGrowTrigger; // actual number of buffers to trigger grow, calculated from iGrowTriggerRatio
|
|
133 |
TUint iShrinkTrigger; // actual number of buffers to trigger shrink, (calc'd from iGrowShrinkRatio)
|
|
134 |
|
|
135 |
TPhysAddr* iPhysAddr;
|
|
136 |
TUint iPoolFlags; // bitwise OR of values from TShPoolCreateFlags
|
|
137 |
friend class ExecHandler;
|
|
138 |
friend class DShBuf;
|
|
139 |
friend class TShPoolNotificationCleanup;
|
|
140 |
friend class DMemModelAlignedShBuf;
|
|
141 |
friend class DMemModelNonAlignedShBuf;
|
|
142 |
friend class DWin32ShBuf;
|
|
143 |
friend class Kern;
|
|
144 |
friend class K;
|
|
145 |
};
|
|
146 |
|
|
147 |
|
|
148 |
/**
|
|
149 |
A kernel-side representation of a shared buffer.
|
|
150 |
|
|
151 |
Buffers are created and held by the pool (DShPool). Device drivers get pointers to buffer
|
|
152 |
objects when allocating or when translating from received RShBuf handles.
|
|
153 |
|
|
154 |
DShBufs objects are created (on the kernel heap) as a result of calling Alloc() or FromRShBuf().
|
|
155 |
|
|
156 |
User-side, buffers are represented by objects of the RShBuf class, which holds a handle to
|
|
157 |
the DShBuf object. Create()ing an RShBuf a mapping is added to the respective DShPool and a
|
|
158 |
DShBuf is also created.
|
|
159 |
|
|
160 |
@see RShBuf
|
|
161 |
*/
|
|
162 |
class DShBuf : public DObject
|
|
163 |
{
|
|
164 |
friend class DShPool;
|
|
165 |
friend class DMemModelShPool;
|
|
166 |
friend class DMemModelAlignedShPool;
|
|
167 |
friend class DMemModelNonAlignedShPool;
|
|
168 |
friend class DWin32ShPool;
|
|
169 |
friend class DWin32AlignedShPool;
|
|
170 |
friend class DWin32NonAlignedShPool;
|
|
171 |
|
|
172 |
public:
|
|
173 |
|
|
174 |
TInt RequestUserHandle(DThread *aThread, TOwnerType aType, TUint aAttr);
|
|
175 |
|
|
176 |
TInt Close(TAny*);
|
|
177 |
|
|
178 |
virtual TInt Construct();
|
|
179 |
|
|
180 |
/**
|
|
181 |
@return The size, in bytes, of this buffer (and every other buffer in the pool).
|
|
182 |
*/
|
|
183 |
inline TUint Size() const
|
|
184 |
{
|
|
185 |
return iPool->BufSize();
|
|
186 |
};
|
|
187 |
|
|
188 |
protected:
|
|
189 |
DShBuf(DShPool* aPool, TLinAddr aRelAddr);
|
|
190 |
DShBuf(DShPool* aPool);
|
|
191 |
virtual ~DShBuf();
|
|
192 |
|
|
193 |
virtual TUint8* Base(DProcess* aProcess) = 0;
|
|
194 |
virtual TUint8* Base() = 0;
|
|
195 |
virtual TInt Map(TUint, DProcess*, TLinAddr&) = 0;
|
|
196 |
virtual TInt UnMap(DProcess*) = 0;
|
|
197 |
virtual TInt Pin(TPhysicalPinObject* aPinObject, TBool aReadOnly, TPhysAddr& aAddress, TPhysAddr* aPages, TUint32& aMapAttr, TUint& aColour);
|
|
198 |
|
|
199 |
friend class ExecHandler;
|
|
200 |
friend class Kern;
|
|
201 |
|
|
202 |
DShPool* iPool; ///< Kern code sees pool
|
|
203 |
TLinAddr iRelAddress; ///< Address of this buffer w.r.t. pool's iBaseAddress
|
|
204 |
SDblQueLink iObjLink;
|
|
205 |
};
|
|
206 |
|
|
207 |
#endif // SSHBUF_H
|