kernel/eka/include/drivers/resmanus.h
changeset 0 a41df078684a
child 244 a77889bee936
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 // Resmanus.h
       
    18 //
       
    19 //
       
    20 
       
    21 // Base classes for implementating power resource support (Kernel-side only)
       
    22 
       
    23 /**
       
    24 @file
       
    25 @internalComponent
       
    26 */
       
    27 #ifndef __RESMANUS_H__
       
    28 #define __RESMANUS_H__
       
    29 
       
    30 #include <platform.h>
       
    31 #include <d32resmanus.h>
       
    32 
       
    33 #define USERSIDE_LDD
       
    34 #include <drivers/resourcecontrol.h>	// For class DResourceController
       
    35 
       
    36 #include <e32ver.h>
       
    37 #include <e32des8.h>	// for HBufC8
       
    38 
       
    39 // Use the following macro for debug output of request-tracking information
       
    40 // #define _DUMP_TRACKERS
       
    41 
       
    42 const TInt KResManUsMajorVersionNumber = 1;
       
    43 const TInt KResManUsMinorVersionNumber = 0;
       
    44 const TInt KResManUsBuildVersionNumber = KE32BuildVersionNumber;
       
    45 
       
    46 const TInt KMaxNumChannels = 4;	// Limit for the number of channels to be open
       
    47 
       
    48 const TInt KNumClientNamesResCtrl	= 10; // Default number for kernel plus user side clients
       
    49 const TInt KNumClientNamesUserSide	= 10; // Sized as above (client may have PlatSec capabilities for access)
       
    50 const TInt KNumResourceInfoResCtrl	= 25; // To contain object types used by Resource Controller
       
    51 const TInt KNumResourceInfoUserSide	= 25; // To contain object types used by Client
       
    52 const TInt KNumResourceDependencies = 5; // Default number of dependencies for a resource
       
    53 
       
    54 const TUint8 KAllResInfoStored = 0xff;
       
    55 const TUint8 KAllClientInfoStored = 0xff;
       
    56 
       
    57 enum TAsyncOpType
       
    58 	{
       
    59 	EGetState,
       
    60 	ESetState,
       
    61 	ENotify
       
    62 	};
       
    63 
       
    64 #define USER_SIDE_CLIENT_BIT_MASK 0x4000 //Bit 14
       
    65 
       
    66 
       
    67 class DChannelResManUs;
       
    68 
       
    69 /*
       
    70 	Classes used to track client usage
       
    71 */
       
    72 
       
    73 class TTrackingControl
       
    74 	{
       
    75 	public:
       
    76 	DChannelResManUs* iOwningChannel;
       
    77 	SDblQue* iFreeQue;
       
    78 	SDblQue* iBusyQue;
       
    79 	TAsyncOpType iType;
       
    80 	TUint8 iReserved1; // reserved for future expansion
       
    81 	TUint8 iReserved2; // reserved for future expansion
       
    82 	TUint8 iReserved3; // reserved for future expansion
       
    83 	};
       
    84 
       
    85 class TTrackingBuffer : public SDblQueLink
       
    86 	{
       
    87 	public:
       
    88 	inline void SetTrackingControl(TTrackingControl* aControl){iTrackingControl=aControl;};
       
    89 	inline TTrackingControl* GetTrackingControl(){return iTrackingControl;};
       
    90 	inline TUint GetResourceId(){return iResourceId;};
       
    91 	inline void SetResourceId(TUint aResourceId){iResourceId=aResourceId;};
       
    92 	inline SDblQue* GetQue() {return iQue;};
       
    93 	inline void SetQue(SDblQue* aQue) {iQue=aQue;};
       
    94 
       
    95 	private:
       
    96 	TTrackingControl* iTrackingControl;
       
    97 	SDblQue* iQue;
       
    98 	TUint iResourceId;
       
    99 	};
       
   100 
       
   101 class TTrackGetStateBuf : public TTrackingBuffer
       
   102 	{
       
   103 	public:
       
   104 	TTrackGetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, 
       
   105 					TDfcQue* aQue, TInt aPriority);
       
   106 	~TTrackGetStateBuf();
       
   107 
       
   108 	public:
       
   109 	TPowerResourceCb iCtrlBlock;
       
   110 	TClientDataRequest2<TInt,TInt>* iRequest;
       
   111 	};
       
   112 
       
   113 class TTrackSetStateBuf : public TTrackingBuffer
       
   114 	{
       
   115 	public:
       
   116 	TTrackSetStateBuf(TPowerResourceCbFn aFn, TAny* aPtr, 
       
   117 					TDfcQue* aQue, TInt aPriority);
       
   118 	~TTrackSetStateBuf();
       
   119  	public:
       
   120 	TPowerResourceCb iCtrlBlock;
       
   121 	TClientRequest* iRequest;
       
   122 	};
       
   123 
       
   124 class TTrackNotifyBuf : public TTrackingBuffer
       
   125 	{
       
   126 	public:
       
   127 	TTrackNotifyBuf(TPowerResourceCbFn aFn, TAny* aPtr, 
       
   128 					TDfcQue* aQue, TInt aPriority);
       
   129 	~TTrackNotifyBuf();
       
   130 	public:
       
   131 	DPowerResourceNotification iNotifyBlock;
       
   132 	TClientRequest* iRequest;
       
   133 	};
       
   134 
       
   135 
       
   136 /* 
       
   137 	Power resource logical device
       
   138 	The class representing the power resource logical device
       
   139 */
       
   140 class DDeviceResManUs : public DLogicalDevice
       
   141     {
       
   142     public:
       
   143     /**
       
   144      * The constructor
       
   145      */
       
   146     DDeviceResManUs();
       
   147     /**
       
   148      * The destructor
       
   149      */
       
   150     ~DDeviceResManUs();
       
   151     /**
       
   152      * Second stage constructor - install the device
       
   153      */
       
   154     virtual TInt Install();
       
   155     /**
       
   156      * Get the Capabilites of the device
       
   157      * @param aDes descriptor that will contain the returned capibilites
       
   158      */
       
   159     virtual void GetCaps(TDes8 &aDes) const;
       
   160     /**
       
   161      * Create a logical channel to the device
       
   162      */
       
   163     virtual TInt Create(DLogicalChannelBase*& aChannel);
       
   164 
       
   165 	public:
       
   166 #ifndef RESOURCE_MANAGER_SIMULATED_PSL
       
   167 	TDfcQue* iSharedDfcQue; // To allow access from device entry point
       
   168 #else
       
   169 	TDynamicDfcQue* iSharedDfcQue; // To allow LDD unload/re-load in testing
       
   170 #endif
       
   171     };
       
   172 
       
   173 
       
   174 
       
   175 	// The logical channel for power resource devices
       
   176 class DChannelResManUs : public DLogicalChannel
       
   177     {
       
   178     public:
       
   179 
       
   180 	/*
       
   181      * The constructor 
       
   182      */
       
   183     DChannelResManUs();
       
   184 	/*   
       
   185      * The destructor
       
   186      */
       
   187     ~DChannelResManUs();
       
   188 
       
   189 	// Helper methods
       
   190 	TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
       
   191 	void FreeTrackingBuffer(TTrackingBuffer*& aBuffer);
       
   192 
       
   193 	inline TInt ClientHandle() {return iClientHandle;};
       
   194 
       
   195     /**
       
   196      * Create a logical power resource channel
       
   197      * @param aUnit The channel number to create
       
   198      * @param anInfo not used, can be NULL
       
   199      * @param aVer The minimun driver version allowed
       
   200      * @return KErrNone if channel created
       
   201      */
       
   202     virtual TInt DoCreate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer);
       
   203 
       
   204     protected:
       
   205     /**
       
   206      * Handle a message from the channels user
       
   207      * @param aMsg The message to handle
       
   208      */
       
   209     virtual void HandleMsg(TMessageBase* aMsg);	// Note: this is a pure virtual in DLogicalChannel
       
   210 
       
   211 	virtual TInt SendMsg(TMessageBase* aMsg);
       
   212 
       
   213 	TInt SendControl(TMessageBase* aMsg);
       
   214 
       
   215 	TInt SendRequest(TMessageBase* aMsg);
       
   216     /**
       
   217      * Cancel an outstanding request
       
   218      * @param aMask A mask containing the requests to be canceled
       
   219      */
       
   220     void DoCancel(TInt aMask);	// Name for convenience!
       
   221     /**
       
   222      * Preform a control operation on the channel
       
   223      * Control operations are:
       
   224      * - Get the current configuration
       
   225      * - Configure the channel
       
   226      * - Set the MAC address for the channel
       
   227      * - Get the capibilities of the channel
       
   228      * @param aId The operation to preform
       
   229      * @param a1 The data to use with the operation
       
   230      * @param a2 can be NULL - not used
       
   231      * @return KErrNone if operation done
       
   232      */
       
   233    TInt DoControl(TInt aId, TAny* a1, TAny* a2); // Name for convenience!
       
   234     /**
       
   235      * Preform an asynchros operation on the channel
       
   236      * Operations are:
       
   237      * - Read data from the channel
       
   238      * - Write data to the channel
       
   239      * @param aId The operation to perform
       
   240      * @param aStatus The status object to use when complete
       
   241      * @param a1 The data to use
       
   242      * @param a2 The length of the data to use
       
   243      * @return KErrNone if operation started ok
       
   244      * @see Complete()
       
   245      */
       
   246     TInt DoRequest(TInt aId, TRequestStatus* aStatus, TAny* a1, TAny* a2); // Name for convenience!
       
   247 
       
   248 
       
   249 	inline void SetClientHandle(TInt aHandle) {iClientHandle=aHandle;};
       
   250 
       
   251 	TInt InitTrackingControl(TTrackingControl*& aTracker, TUint8 aType, TUint8 aNumBuffers);
       
   252 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
       
   253 	void GetNumCandidateAsyncResources(TUint& aNumResources);
       
   254 	TInt GetCandidateAsyncResourceId(TUint aIndex, TUint& aResourceId);
       
   255 	void GetNumCandidateSharedResources(TUint& aNumResources);
       
   256 	TInt GetCandidateSharedResourceId(TUint aIndex, TUint& aResourceId);
       
   257 #endif
       
   258 
       
   259     private:
       
   260 	static void RegistrationDfcFunc(TAny* aChannel);
       
   261 	TInt RegisterWithResCtrlr();
       
   262 	TInt GetValidName(const TDesC8* aInfo);
       
   263 	void RemoveTrackingControl(TTrackingControl*& aTracker);
       
   264 	TInt GetAndInitTrackingBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TRequestStatus* aStatus);
       
   265 	TInt GetStateBuffer(TTrackingControl*& aTracker, TTrackingBuffer*& aBuffer, TUint aResourceId, TInt *aState, TInt* aLevelOwnerPtr, TPowerResourceCb*& aCb, TRequestStatus* aStatus);
       
   266 	TTrackingControl* MapRequestToTracker(TInt aRequestType);
       
   267 	TInt CancelTrackerRequests(TTrackingControl* aTracker,TBool aSingleRsrc, TUint aResourceId, TRequestStatus* aStatus);
       
   268 	TInt CancelRequestsOfType(TInt aRequestType, TRequestStatus* aStatus);
       
   269 	TInt EnsureSizeIsSufficient(HBuf*& aBuffer, TInt aMinSize);
       
   270 	TInt ExtractResourceInfo(const TPowerResourceInfoV01* aPwrResInfo, TResourceInfoBuf& aInfo);
       
   271 #ifdef _DUMP_TRACKERS
       
   272 	TInt DumpResource(const TPowerResourceInfoV01* aResource);
       
   273 	TInt DumpTracker(TTrackingControl* aTracker);
       
   274 #endif
       
   275 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
       
   276 	void CheckForCandidateAsyncResource(TPowerResourceInfoV01* aResource);
       
   277 	void CheckForCandidateSharedResource(TPowerResourceInfoV01* aResource);
       
   278 #endif
       
   279 	typedef void ClientCopyFunc(TDes8*, const TPowerClientInfoV01*);
       
   280 
       
   281 	// Registration and identification support
       
   282     public:
       
   283 	DThread* iClient;
       
   284 
       
   285 	DPowerResourceController* iPddPtr;
       
   286 
       
   287 	private:
       
   288 	NFastMutex iBufferFastMutex;
       
   289 	NFastSemaphore *iFastSem;
       
   290 	TInt iClientHandle;
       
   291 	TUint iNameProvidedLength;
       
   292 	HBuf8* iUserNameUsed;
       
   293 
       
   294 	// Support for usage tracking
       
   295 	TTrackingControl *iGetStateTracker;
       
   296 	TTrackingControl *iSetStateTracker;
       
   297 	TTrackingControl *iListenableTracker;
       
   298 
       
   299 	// Buffers to support acquisition of resource and client information
       
   300 	HBuf8* iClientNamesResCtrl;		// Stores client information
       
   301 	TUint iClientInfoStoredResId;	// The ID of the resource for which the data is stored (none=0, all=KAllClientInfoStored)
       
   302 	TUint iClientInfoStoredNum;		// The number of clients for which data is stored
       
   303 
       
   304 	HBuf8* iResourceInfoResCtrl;	// Stores resource information
       
   305 	TUint iResInfoStoredClientId;	// The ID of the client for which the data is stored (none=0, all=KAllResInfoStored)
       
   306 	TUint iResInfoStoredNum;		// The number of resources for which data is stored
       
   307 
       
   308 	HBuf8* iResourceDependencyIds;	// To contain the identifiers for resource dependencies
       
   309 	TUint iNumResDepsStored;
       
   310 
       
   311 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
       
   312 	// Support for testing
       
   313 	TBool iHaveLongLatencyResource;
       
   314 
       
   315 	// Array for candidate resources to use for testing
       
   316 	// Store a maximum of MAX_NUM_CANDIDATE_RESOURCES
       
   317 	#define MAX_NUM_CANDIDATE_RESOURCES 10
       
   318 	TUint iNoCandidateAsyncRes;
       
   319 	TUint iCandidateAsyncResIds[MAX_NUM_CANDIDATE_RESOURCES];
       
   320 	TUint iNoCandidateSharedRes;
       
   321 	TUint iCandidateSharedResIds[MAX_NUM_CANDIDATE_RESOURCES];
       
   322 #endif
       
   323 
       
   324 	// 8-bit values, placed here to aid size management
       
   325 	TUint8 iClientInfoValid;		// To indicate if a valid set of client data is stored
       
   326 	TUint8 iResInfoValid;			// To indicate if a valid set of resource data is stored
       
   327 	TUint8 iResDepsValid;			// Guard flag for the RArray
       
   328 
       
   329 	TUint8 iReserved1;				 // reserved for future expansion
       
   330 
       
   331     };
       
   332 
       
   333 
       
   334 #endif