os/kernelhwsrv/kernel/eka/include/drivers/resmanus.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/kernel/eka/include/drivers/resmanus.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,334 @@
     1.4 +/*
     1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +// Resmanus.h
    1.21 +//
    1.22 +//
    1.23 +
    1.24 +// Base classes for implementating power resource support (Kernel-side only)
    1.25 +
    1.26 +/**
    1.27 +@file
    1.28 +@internalComponent
    1.29 +*/
    1.30 +#ifndef __RESMANUS_H__
    1.31 +#define __RESMANUS_H__
    1.32 +
    1.33 +#include <platform.h>
    1.34 +#include <d32resmanus.h>
    1.35 +
    1.36 +#define USERSIDE_LDD
    1.37 +#include <drivers/resourcecontrol.h>	// For class DResourceController
    1.38 +
    1.39 +#include <e32ver.h>
    1.40 +#include <e32des8.h>	// for HBufC8
    1.41 +
    1.42 +// Use the following macro for debug output of request-tracking information
    1.43 +// #define _DUMP_TRACKERS
    1.44 +
    1.45 +const TInt KResManUsMajorVersionNumber = 1;
    1.46 +const TInt KResManUsMinorVersionNumber = 0;
    1.47 +const TInt KResManUsBuildVersionNumber = KE32BuildVersionNumber;
    1.48 +
    1.49 +const TInt KMaxNumChannels = 4;	// Limit for the number of channels to be open
    1.50 +
    1.51 +const TInt KNumClientNamesResCtrl	= 10; // Default number for kernel plus user side clients
    1.52 +const TInt KNumClientNamesUserSide	= 10; // Sized as above (client may have PlatSec capabilities for access)
    1.53 +const TInt KNumResourceInfoResCtrl	= 25; // To contain object types used by Resource Controller
    1.54 +const TInt KNumResourceInfoUserSide	= 25; // To contain object types used by Client
    1.55 +const TInt KNumResourceDependencies = 5; // Default number of dependencies for a resource
    1.56 +
    1.57 +const TUint8 KAllResInfoStored = 0xff;
    1.58 +const TUint8 KAllClientInfoStored = 0xff;
    1.59 +
    1.60 +enum TAsyncOpType
    1.61 +	{
    1.62 +	EGetState,
    1.63 +	ESetState,
    1.64 +	ENotify
    1.65 +	};
    1.66 +
    1.67 +#define USER_SIDE_CLIENT_BIT_MASK 0x4000 //Bit 14
    1.68 +
    1.69 +
    1.70 +class DChannelResManUs;
    1.71 +
    1.72 +/*
    1.73 +	Classes used to track client usage
    1.74 +*/
    1.75 +
    1.76 +class TTrackingControl
    1.77 +	{
    1.78 +	public:
    1.79 +	DChannelResManUs* iOwningChannel;
    1.80 +	SDblQue* iFreeQue;
    1.81 +	SDblQue* iBusyQue;
    1.82 +	TAsyncOpType iType;
    1.83 +	TUint8 iReserved1; // reserved for future expansion
    1.84 +	TUint8 iReserved2; // reserved for future expansion
    1.85 +	TUint8 iReserved3; // reserved for future expansion
    1.86 +	};
    1.87 +
    1.88 +class TTrackingBuffer : public SDblQueLink
    1.89 +	{
    1.90 +	public:
    1.91 +	inline void SetTrackingControl(TTrackingControl* aControl){iTrackingControl=aControl;};
    1.92 +	inline TTrackingControl* GetTrackingControl(){return iTrackingControl;};
    1.93 +	inline TUint GetResourceId(){return iResourceId;};
    1.94 +	inline void SetResourceId(TUint aResourceId){iResourceId=aResourceId;};
    1.95 +	inline SDblQue* GetQue() {return iQue;};
    1.96 +	inline void SetQue(SDblQue* aQue) {iQue=aQue;};
    1.97 +
    1.98 +	private:
    1.99 +	TTrackingControl* iTrackingControl;
   1.100 +	SDblQue* iQue;
   1.101 +	TUint iResourceId;
   1.102 +	};
   1.103 +
   1.104 +class TTrackGetStateBuf : public TTrackingBuffer
   1.105 +	{
   1.106 +	public:
   1.107 +	TTrackGetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, 
   1.108 +					TDfcQue* aQue, TInt aPriority);
   1.109 +	~TTrackGetStateBuf();
   1.110 +
   1.111 +	public:
   1.112 +	TPowerResourceCb iCtrlBlock;
   1.113 +	TClientDataRequest2<TInt,TInt>* iRequest;
   1.114 +	};
   1.115 +
   1.116 +class TTrackSetStateBuf : public TTrackingBuffer
   1.117 +	{
   1.118 +	public:
   1.119 +	TTrackSetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, 
   1.120 +					TDfcQue* aQue, TInt aPriority);
   1.121 +	~TTrackSetStateBuf();
   1.122 + 	public:
   1.123 +	TPowerResourceCb iCtrlBlock;
   1.124 +	TClientRequest* iRequest;
   1.125 +	};
   1.126 +
   1.127 +class TTrackNotifyBuf : public TTrackingBuffer
   1.128 +	{
   1.129 +	public:
   1.130 +	TTrackNotifyBuf(TPowerResourceCbFn aFn, TAny* aPtr, 
   1.131 +					TDfcQue* aQue, TInt aPriority);
   1.132 +	~TTrackNotifyBuf();
   1.133 +	public:
   1.134 +	DPowerResourceNotification iNotifyBlock;
   1.135 +	TClientRequest* iRequest;
   1.136 +	};
   1.137 +
   1.138 +
   1.139 +/* 
   1.140 +	Power resource logical device
   1.141 +	The class representing the power resource logical device
   1.142 +*/
   1.143 +class DDeviceResManUs : public DLogicalDevice
   1.144 +    {
   1.145 +    public:
   1.146 +    /**
   1.147 +     * The constructor
   1.148 +     */
   1.149 +    DDeviceResManUs();
   1.150 +    /**
   1.151 +     * The destructor
   1.152 +     */
   1.153 +    ~DDeviceResManUs();
   1.154 +    /**
   1.155 +     * Second stage constructor - install the device
   1.156 +     */
   1.157 +    virtual TInt Install();
   1.158 +    /**
   1.159 +     * Get the Capabilites of the device
   1.160 +     * @param aDes descriptor that will contain the returned capibilites
   1.161 +     */
   1.162 +    virtual void GetCaps(TDes8 &aDes) const;
   1.163 +    /**
   1.164 +     * Create a logical channel to the device
   1.165 +     */
   1.166 +    virtual TInt Create(DLogicalChannelBase*& aChannel);
   1.167 +
   1.168 +	public:
   1.169 +#ifndef RESOURCE_MANAGER_SIMULATED_PSL
   1.170 +	TDfcQue* iSharedDfcQue; // To allow access from device entry point
   1.171 +#else
   1.172 +	TDynamicDfcQue* iSharedDfcQue; // To allow LDD unload/re-load in testing
   1.173 +#endif
   1.174 +    };
   1.175 +
   1.176 +
   1.177 +
   1.178 +	// The logical channel for power resource devices
   1.179 +class DChannelResManUs : public DLogicalChannel
   1.180 +    {
   1.181 +    public:
   1.182 +
   1.183 +	/*
   1.184 +     * The constructor 
   1.185 +     */
   1.186 +    DChannelResManUs();
   1.187 +	/*   
   1.188 +     * The destructor
   1.189 +     */
   1.190 +    ~DChannelResManUs();
   1.191 +
   1.192 +	// Helper methods
   1.193 +	TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
   1.194 +	void FreeTrackingBuffer(TTrackingBuffer*& aBuffer);
   1.195 +
   1.196 +	inline TInt ClientHandle() {return iClientHandle;};
   1.197 +
   1.198 +    /**
   1.199 +     * Create a logical power resource channel
   1.200 +     * @param aUnit The channel number to create
   1.201 +     * @param anInfo not used, can be NULL
   1.202 +     * @param aVer The minimun driver version allowed
   1.203 +     * @return KErrNone if channel created
   1.204 +     */
   1.205 +    virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
   1.206 +
   1.207 +    protected:
   1.208 +    /**
   1.209 +     * Handle a message from the channels user
   1.210 +     * @param aMsg The message to handle
   1.211 +     */
   1.212 +    virtual void HandleMsg(TMessageBase* aMsg);	// Note: this is a pure virtual in DLogicalChannel
   1.213 +
   1.214 +	virtual TInt SendMsg(TMessageBase* aMsg);
   1.215 +
   1.216 +	TInt SendControl(TMessageBase* aMsg);
   1.217 +
   1.218 +	TInt SendRequest(TMessageBase* aMsg);
   1.219 +    /**
   1.220 +     * Cancel an outstanding request
   1.221 +     * @param aMask A mask containing the requests to be canceled
   1.222 +     */
   1.223 +    void DoCancel(TInt aMask);	// Name for convenience!
   1.224 +    /**
   1.225 +     * Preform a control operation on the channel
   1.226 +     * Control operations are:
   1.227 +     * - Get the current configuration
   1.228 +     * - Configure the channel
   1.229 +     * - Set the MAC address for the channel
   1.230 +     * - Get the capibilities of the channel
   1.231 +     * @param aId The operation to preform
   1.232 +     * @param a1 The data to use with the operation
   1.233 +     * @param a2 can be NULL - not used
   1.234 +     * @return KErrNone if operation done
   1.235 +     */
   1.236 +   TInt DoControl(TInt aId, TAny* a1, TAny* a2); // Name for convenience!
   1.237 +    /**
   1.238 +     * Preform an asynchros operation on the channel
   1.239 +     * Operations are:
   1.240 +     * - Read data from the channel
   1.241 +     * - Write data to the channel
   1.242 +     * @param aId The operation to perform
   1.243 +     * @param aStatus The status object to use when complete
   1.244 +     * @param a1 The data to use
   1.245 +     * @param a2 The length of the data to use
   1.246 +     * @return KErrNone if operation started ok
   1.247 +     * @see Complete()
   1.248 +     */
   1.249 +    TInt DoRequest(TInt aId, TRequestStatus* aStatus, TAny* a1, TAny* a2); // Name for convenience!
   1.250 +
   1.251 +
   1.252 +	inline void SetClientHandle(TInt aHandle) {iClientHandle=aHandle;};
   1.253 +
   1.254 +	TInt InitTrackingControl(TTrackingControl*& aTracker, TUint8 aType, TUint8 aNumBuffers);
   1.255 +#ifdef RESOURCE_MANAGER_SIMULATED_PSL
   1.256 +	void GetNumCandidateAsyncResources(TUint& aNumResources);
   1.257 +	TInt GetCandidateAsyncResourceId(TUint aIndex, TUint& aResourceId);
   1.258 +	void GetNumCandidateSharedResources(TUint& aNumResources);
   1.259 +	TInt GetCandidateSharedResourceId(TUint aIndex, TUint& aResourceId);
   1.260 +#endif
   1.261 +
   1.262 +    private:
   1.263 +	static void RegistrationDfcFunc(TAny* aChannel);
   1.264 +	TInt RegisterWithResCtrlr();
   1.265 +	TInt GetValidName(const TDesC8* aInfo);
   1.266 +	void RemoveTrackingControl(TTrackingControl*& aTracker);
   1.267 +	TInt GetAndInitTrackingBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TRequestStatus* aStatus);
   1.268 +	TInt GetStateBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TInt *aState, TInt* aLevelOwnerPtr, TPowerResourceCb*& aCb, TRequestStatus* aStatus);
   1.269 +	TTrackingControl* MapRequestToTracker(TInt aRequestType);
   1.270 +	TInt CancelTrackerRequests(TTrackingControl* aTracker,TBool aSingleRsrc, TUint aResourceId, TRequestStatus* aStatus);
   1.271 +	TInt CancelRequestsOfType(TInt aRequestType, TRequestStatus* aStatus);
   1.272 +	TInt EnsureSizeIsSufficient(HBuf*& aBuffer, TInt aMinSize);
   1.273 +	TInt ExtractResourceInfo(const TPowerResourceInfoV01* aPwrResInfo, TResourceInfoBuf& aInfo);
   1.274 +#ifdef _DUMP_TRACKERS
   1.275 +	TInt DumpResource(const TPowerResourceInfoV01* aResource);
   1.276 +	TInt DumpTracker(TTrackingControl* aTracker);
   1.277 +#endif
   1.278 +#ifdef RESOURCE_MANAGER_SIMULATED_PSL
   1.279 +	void CheckForCandidateAsyncResource(TPowerResourceInfoV01* aResource);
   1.280 +	void CheckForCandidateSharedResource(TPowerResourceInfoV01* aResource);
   1.281 +#endif
   1.282 +	typedef void ClientCopyFunc(TDes8*, const TPowerClientInfoV01*);
   1.283 +
   1.284 +	// Registration and identification support
   1.285 +    public:
   1.286 +	DThread* iClient;
   1.287 +
   1.288 +	DPowerResourceController* iPddPtr;
   1.289 +
   1.290 +	private:
   1.291 +	NFastMutex iBufferFastMutex;
   1.292 +	NFastSemaphore *iFastSem;
   1.293 +	TInt iClientHandle;
   1.294 +	TUint iNameProvidedLength;
   1.295 +	HBuf8* iUserNameUsed;
   1.296 +
   1.297 +	// Support for usage tracking
   1.298 +	TTrackingControl *iGetStateTracker;
   1.299 +	TTrackingControl *iSetStateTracker;
   1.300 +	TTrackingControl *iListenableTracker;
   1.301 +
   1.302 +	// Buffers to support acquisition of resource and client information
   1.303 +	HBuf8* iClientNamesResCtrl;		// Stores client information
   1.304 +	TUint iClientInfoStoredResId;	// The ID of the resource for which the data is stored (none=0, all=KAllClientInfoStored)
   1.305 +	TUint iClientInfoStoredNum;		// The number of clients for which data is stored
   1.306 +
   1.307 +	HBuf8* iResourceInfoResCtrl;	// Stores resource information
   1.308 +	TUint iResInfoStoredClientId;	// The ID of the client for which the data is stored (none=0, all=KAllResInfoStored)
   1.309 +	TUint iResInfoStoredNum;		// The number of resources for which data is stored
   1.310 +
   1.311 +	HBuf8* iResourceDependencyIds;	// To contain the identifiers for resource dependencies
   1.312 +	TUint iNumResDepsStored;
   1.313 +
   1.314 +#ifdef RESOURCE_MANAGER_SIMULATED_PSL
   1.315 +	// Support for testing
   1.316 +	TBool iHaveLongLatencyResource;
   1.317 +
   1.318 +	// Array for candidate resources to use for testing
   1.319 +	// Store a maximum of MAX_NUM_CANDIDATE_RESOURCES
   1.320 +	#define MAX_NUM_CANDIDATE_RESOURCES 10
   1.321 +	TUint iNoCandidateAsyncRes;
   1.322 +	TUint iCandidateAsyncResIds[MAX_NUM_CANDIDATE_RESOURCES];
   1.323 +	TUint iNoCandidateSharedRes;
   1.324 +	TUint iCandidateSharedResIds[MAX_NUM_CANDIDATE_RESOURCES];
   1.325 +#endif
   1.326 +
   1.327 +	// 8-bit values, placed here to aid size management
   1.328 +	TUint8 iClientInfoValid;		// To indicate if a valid set of client data is stored
   1.329 +	TUint8 iResInfoValid;			// To indicate if a valid set of resource data is stored
   1.330 +	TUint8 iResDepsValid;			// Guard flag for the RArray
   1.331 +
   1.332 +	TUint8 iReserved1;				 // reserved for future expansion
   1.333 +
   1.334 +    };
   1.335 +
   1.336 +
   1.337 +#endif