1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kernel/eka/include/e32shbuf.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,351 @@
1.4 +// Copyright (c) 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/e32shbuf.h
1.18 +// Shareable Data Buffers
1.19 +
1.20 +/**
1.21 + @file
1.22 + @publishedPartner
1.23 + @prototype
1.24 +*/
1.25 +
1.26 +#ifndef E32SHBUF_H
1.27 +#define E32SHBUF_H
1.28 +
1.29 +#include <e32shbufcmn.h>
1.30 +#include <e32cmn.h>
1.31 +
1.32 +/**
1.33 + Specifies characteristics of the pool to be created.
1.34 +
1.35 + @see RShPool::Create()
1.36 +
1.37 + @publishedPartner
1.38 + @prototype
1.39 +*/
1.40 +
1.41 +class TShPoolCreateInfo
1.42 + {
1.43 +public:
1.44 + /**
1.45 + Enumeration type to create a pool with page-aligned buffers.
1.46 +
1.47 + The buffers in the pool will be at least the size of an MMU page,
1.48 + aligned to an MMU page, and may be mapped in and out of a process's
1.49 + address space independently.
1.50 + */
1.51 + enum TShPoolPageAlignedBuffers
1.52 + {
1.53 + EPageAlignedBuffer = EShPoolPageAlignedBuffer,
1.54 + };
1.55 +
1.56 + /**
1.57 + Enumeration type to create a pool with non-page-aligned buffers.
1.58 +
1.59 + The buffers in the pool do not have any size or alignment restrictions beyond
1.60 + the iAlignment specified in TShPoolInfo.
1.61 +
1.62 + The whole pool will always mapped into a process's address space.
1.63 + */
1.64 + enum TShPoolNonPageAlignedBuffers
1.65 + {
1.66 + ENonPageAlignedBuffer = EShPoolNonPageAlignedBuffer,
1.67 + };
1.68 +
1.69 + /**
1.70 + Specifies the buffer size and initial number of committed buffers for a pool
1.71 + with page-aligned buffers.
1.72 +
1.73 + @param aFlag Page-aligned buffers
1.74 + @param aBufSize Size in bytes of each buffer within the pool
1.75 + @param aInitialBufs Initial number of buffers allocated to the pool
1.76 + */
1.77 + IMPORT_C TShPoolCreateInfo(TShPoolPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs);
1.78 +
1.79 + /**
1.80 + Specifies the buffer size, initial number of committed buffers, and buffer
1.81 + alignment for a pool with non-page-aligned buffers.
1.82 +
1.83 + @param aFlag Non-page aligned buffers
1.84 + @param aBufSize Size in bytes of each buffer within the pool
1.85 + @param aInitialBufs Initial number of buffers allocated to the pool
1.86 + @param aAlignment Alignment of the start of each buffer in the pool (shift/log2 value)
1.87 + */
1.88 + IMPORT_C TShPoolCreateInfo(TShPoolNonPageAlignedBuffers aFlag, TUint aBufSize, TUint aInitialBufs, TUint aAlignment);
1.89 +
1.90 + /**
1.91 + Sets the sizing attributes for the pool, allowing it to grow and
1.92 + shrink automatically.
1.93 +
1.94 + If either aGrowTriggerRatio or aGrowByRatio is 0, no automatic growing or
1.95 + shrinking will be performed.
1.96 +
1.97 + @param aMaxBufs The maximum number of buffers that the pool
1.98 + can grow to. This value must not be less than
1.99 + aInitialBufs.
1.100 +
1.101 + @param aGrowTriggerRatio This specifies when to grow the pool. When the
1.102 + proportion of free buffers in the pool drops below
1.103 + this value, the pool will be grown. This value is
1.104 + expressed as a 32-bit fixed-point number, where
1.105 + the binary point is defined to be between bits
1.106 + 7 and 8 (where the least-significant bit is defined
1.107 + as bit 0). (This format is also known as a Q8, or
1.108 + fx24.8 number, or alternatively as the value * 256.)
1.109 + It must represent a value < 1 (i.e. must be < 256).
1.110 +
1.111 + @param aGrowByRatio The proportion to grow the pool by each time,
1.112 + expressed as a 32-bit fx24.8 fixed-point number, in
1.113 + the same way as aGrowTriggerRatio.
1.114 +
1.115 + @param aShrinkHysteresisRatio The hysteresis value to ensure that a pool is not
1.116 + automatically shrunk immediately after it is grown.
1.117 + Automatic shrinking will only happen when there are
1.118 + (aGrowTriggerRatio + aGrowByRatio) * aShrinkHysteresisRatio *
1.119 + (total buffers in the pool) free buffers left in the pool.
1.120 + This is a 32-bit fx24.8 fixed-point number in the
1.121 + same way as aGrowTriggerRatio and aGrowByRatio.
1.122 + It must represent a value > 1 (i.e. must be > 256).
1.123 + */
1.124 + IMPORT_C TInt SetSizingAttributes(TUint aMaxBufs, TUint aGrowTriggerRatio,
1.125 + TUint aGrowByRatio, TUint aShrinkHysteresisRatio);
1.126 +
1.127 + /**
1.128 + Ensures that each buffer is mapped into at most one process address space
1.129 + at a time.
1.130 +
1.131 + If this is set for a non-page-aligned pool, the pool creation will fail.
1.132 + */
1.133 + IMPORT_C TInt SetExclusive();
1.134 +
1.135 + /**
1.136 + Specifies that unmapped guard pages are inserted between each buffer in a process's
1.137 + address space.
1.138 +
1.139 + If this is set for a non-page-aligned pool, the pool creation will fail.
1.140 + */
1.141 + IMPORT_C TInt SetGuardPages();
1.142 +
1.143 +private:
1.144 + friend class RShPool;
1.145 + TShPoolCreateInfo(); // hide the default constructor
1.146 +
1.147 + TShPoolInfo iInfo;
1.148 +};
1.149 +
1.150 +
1.151 +/**
1.152 +A handle to a pool of buffers.
1.153 +
1.154 +Pools can be created by either user-side or kernel-side components.
1.155 +
1.156 +Upon receiving a pool handle the recipient must map either whole or part of the pool
1.157 +memory into its address space.
1.158 +
1.159 +When finished with the pool, the recipient must Close() it: this invalidates the handle.
1.160 +Any further attempt to use it will panic the thread.
1.161 +
1.162 +All pools are reference-counted and will only disappear after all users have closed them.
1.163 +
1.164 +These handles are process-relative.
1.165 +
1.166 +@publishedPartner
1.167 +@prototype
1.168 +*/
1.169 +class RShPool : public RHandleBase
1.170 + {
1.171 +public:
1.172 + IMPORT_C RShPool();
1.173 +
1.174 + /**
1.175 + Creates a pool of buffers with the required attributes and maps the memory to this process.
1.176 + The RShPool object is changed by this call (iHandle is set).
1.177 +
1.178 + @param aBufInfo A structure describing the parameters of the pool to be created.
1.179 + See TShPoolCreateInfo.
1.180 +
1.181 + @param aFlags Flags to modify the behaviour of the handle. This should be a bit-wise
1.182 + OR of values from TShPoolHandleFlags.
1.183 +
1.184 + @return the handle (>= 0) if successful, otherwise one of the system-wide error codes.
1.185 +
1.186 + @see TShPoolCreateInfo
1.187 + @see TShPoolClientFlags
1.188 + */
1.189 + IMPORT_C TInt Create(const TShPoolCreateInfo& aBufInfo, TUint aFlags);
1.190 +
1.191 + /**
1.192 + Retrieves information about the pool.
1.193 +
1.194 + @param aInfo returns pool info.
1.195 + */
1.196 + IMPORT_C void GetInfo(TShPoolInfo& aInfo) const;
1.197 +
1.198 + /**
1.199 + Specifies how many buffers of a page-aligned pool this process will require
1.200 + concurrent access to.
1.201 +
1.202 + This determines how much of the process's address space will be allocated for
1.203 + buffers of this pool.
1.204 +
1.205 + @param aCount Specifies the number of buffers to map into the process's virtual address space
1.206 + (-1 specifies that all buffers will be mapped).
1.207 +
1.208 + @param aAutoMap ETrue specifies that an allocated or received buffer
1.209 + will be automatically mapped into the process's address space.
1.210 +
1.211 + @pre the pool's buffers must be page-aligned
1.212 +
1.213 + @return KErrNone if successful, otherwise one of the system-wide error codes.
1.214 + */
1.215 + IMPORT_C TInt SetBufferWindow(TInt aCount, TBool aAutoMap);
1.216 +
1.217 + /**
1.218 + @return the number of free buffers in the pool
1.219 + */
1.220 + IMPORT_C TUint FreeCount() const;
1.221 +
1.222 + /**
1.223 + Requests a notification when the number of free buffers in the pool falls to the
1.224 + level specified.
1.225 +
1.226 + @param aFreeBuffers Specifies the number of free buffers that will trigger completion of the notification.
1.227 + @param aStatus Status request to be completed when the condition is met.
1.228 + */
1.229 + IMPORT_C void RequestLowSpaceNotification(TUint aFreeBuffers, TRequestStatus& aStatus);
1.230 +
1.231 + /**
1.232 + Requests a notification when the number of free buffers in the pool rises to the
1.233 + level specified.
1.234 +
1.235 + @param aFreeBuffers Specifies the number of free buffers that will trigger completion of the notification.
1.236 + @param aStatus Status request to be completed when the condition is met.
1.237 + */
1.238 + IMPORT_C void RequestFreeSpaceNotification(TUint aFreeBuffers, TRequestStatus& aStatus);
1.239 +
1.240 + /**
1.241 + Cancels a low space notification request.
1.242 +
1.243 + The status request completes with KErrCancel.
1.244 +
1.245 + @param aStatus The status request whose notification is to be cancelled.
1.246 + */
1.247 + IMPORT_C void CancelLowSpaceNotification(TRequestStatus& aStatus);
1.248 +
1.249 + /**
1.250 + Cancels a free space notification request.
1.251 +
1.252 + The status request completes with KErrCancel.
1.253 +
1.254 + @param aStatus The status request whose notification is to be cancelled.
1.255 + */
1.256 + IMPORT_C void CancelFreeSpaceNotification(TRequestStatus& aStatus);
1.257 + };
1.258 +
1.259 +
1.260 +/**
1.261 +A handle to a shared buffer within a pool.
1.262 +
1.263 +A user-side or kernel-side component allocates the buffer and then passes the
1.264 +handle to the recipient.
1.265 +
1.266 +Upon receiving a buffer handle. the recipient may map the buffer memory into its address space if not already done so.
1.267 +
1.268 +When finished with the buffer, the recipient must Close() the handle. This
1.269 +invalidates the handle; any further attempt to use it will panic the thread.
1.270 +
1.271 +Buffers are reference-counted and will only be freed and returned to the pool
1.272 +when all users have closed them.
1.273 +
1.274 +These handles are process-relative.
1.275 +
1.276 +@publishedPartner
1.277 +@prototype
1.278 +*/
1.279 +class RShBuf : public RHandleBase
1.280 + {
1.281 +public:
1.282 + inline RShBuf() : iBase(0), iSize(0) {};
1.283 +
1.284 + IMPORT_C void Close();
1.285 +
1.286 + /**
1.287 + Allocates a shared data buffer.
1.288 +
1.289 + By default this method will return immediately with KErrNoMemory if no buffer is
1.290 + available on the pool's free list, even if the pool could grow automatically.
1.291 +
1.292 + By default it will also map the allocated buffer into the calling process's address space.
1.293 +
1.294 + Setting EShPoolAllocCanWait in the flags indicates that the caller is prepared to
1.295 + wait while the pool is grown if a buffer is not immediately available on the free list.
1.296 +
1.297 + Setting EShPoolAllocNoMap in the flags indicates that the caller does not want the
1.298 + buffer to be automatically mapped into its address space. This can improve performance
1.299 + on buffers from page-aligned pools if the caller will not need to access the data in the
1.300 + buffer (e.g. if it will just be passing it on to another component). This only prevents
1.301 + mapping if the pool is set to not automatically map buffers into processes' address space.
1.302 +
1.303 + @param aPool Pool handle
1.304 + @param aFlags Bitwise OR of values from TShPoolAllocFlags to specify non-default behaviour.
1.305 +
1.306 + @return KErrNone if successful, otherwise one of the system-wide error codes.
1.307 +
1.308 + @see TShPoolAllocFlags
1.309 + */
1.310 + IMPORT_C TInt Alloc(RShPool& aPool, TUint aFlags = 0);
1.311 +
1.312 + /**
1.313 + Maps the buffer into the calling process's virtual address space if not already done.
1.314 +
1.315 + It is not necessary to call this method on buffers from non-page-aligned pools, although
1.316 + it will cause no harm to do so (and will result in KErrNone being returned).
1.317 +
1.318 + It is not necessary to call this method on buffers from page-aligned pools returned by
1.319 + Alloc() unless EShPoolAllocNoMap was specified.
1.320 +
1.321 + @param aReadOnly Indicates whether the buffer should be mapped as read-only. The default is
1.322 + that of pool in the clients address space.
1.323 +
1.324 + @return KErrNone if successful, otherwise one of the system-wide error codes.
1.325 + */
1.326 + IMPORT_C TInt Map(TBool aReadOnly = EFalse);
1.327 +
1.328 + /**
1.329 + Unmaps the buffer from the calling process's virtual address space.
1.330 +
1.331 + @return KErrNone if successful, otherwise one of the system-wide error codes.
1.332 + */
1.333 + IMPORT_C TInt UnMap();
1.334 +
1.335 + /**
1.336 + @return The size, in bytes, of this buffer (and every other buffer in the pool).
1.337 + */
1.338 + IMPORT_C TUint Size();
1.339 +
1.340 + /**
1.341 + @return A pointer to the start of the buffer.
1.342 + */
1.343 + IMPORT_C TUint8* Ptr();
1.344 +
1.345 +private:
1.346 + friend class RShPool;
1.347 + TLinAddr iBase;
1.348 + TUint iSize;
1.349 + TUint iSpare1;
1.350 + TUint iSpare2;
1.351 + };
1.352 +
1.353 +
1.354 +#endif // E32SHBUF_H