kernel/eka/include/drivers/resourcecontrol.h
changeset 259 57b9594f5772
parent 31 56f325a607ea
child 257 3e88ff8f41d5
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // e32\include\drivers\resourcecontrol.h
    14 // e32\include\drivers\resourcecontrol.h
    15 // 
    15 //
    16 // WARNING: This file contains some APIs which are internal and are subject
    16 // WARNING: This file contains some APIs which are internal and are subject
    17 //          to change without notice. Such APIs should therefore not be used
    17 //          to change without notice. Such APIs should therefore not be used
    18 //          outside the Kernel and Hardware Services package.
    18 //          outside the Kernel and Hardware Services package.
    19 //
    19 //
    20 
    20 
   131 
   131 
   132 
   132 
   133 /* Macro to add dynamic resource to appropriate containers. Used only in extended version */
   133 /* Macro to add dynamic resource to appropriate containers. Used only in extended version */
   134 #define ADD_TO_RESOURCE_CONTAINER(list, res, resId, resIdCount)				\
   134 #define ADD_TO_RESOURCE_CONTAINER(list, res, resId, resIdCount)				\
   135 	{																		\
   135 	{																		\
   136 	TUint16 growBy = (list).GrowBy();										\
   136 	TInt growBy = (list).GrowBy();										\
   137 	if(!growBy)																\
   137 	if(!growBy)																\
   138 		(list).Initialise((TUint16)PRM_DYNAMIC_RESOURCE_INITIAL_SIZE);		\
   138 		(list).Initialise(PRM_DYNAMIC_RESOURCE_INITIAL_SIZE);		\
   139 	if((list).Add(res, resId) == KErrNoMemory)								\
   139     TInt r = (list).Add(res, resId);                                        \
       
   140 	if(r == KErrNoMemory)								                    \
   140 		{																	\
   141 		{																	\
   141 		TInt r = (list).ReSize(growBy);										\
   142 		r = (list).ReSize(growBy);										    \
   142 		if(r != KErrNone)													\
   143         if(r == KErrNone)                                                   \
   143 			return r;														\
   144             {                                                               \
   144 		(list).Add(res, resId);												\
   145             r = (list).Add(res, resId);										\
       
   146             }                                                               \
   145 		}																	\
   147 		}																	\
       
   148     if(r != KErrNone)                                                       \
       
   149         {                                                                   \
       
   150         return r;                                                           \
       
   151         }                                                                   \
   146 	res->iResourceId |= resId;												\
   152 	res->iResourceId |= resId;												\
   147 	resId = res->iResourceId;												\
   153 	resId = res->iResourceId;												\
   148 	resIdCount++;															\
   154 	resIdCount++;															\
   149 	}
   155 	}
   150 	
   156 	
   152 #define GET_RESOURCE_FROM_LIST(resId, res)														\
   158 #define GET_RESOURCE_FROM_LIST(resId, res)														\
   153 	{																							\
   159 	{																							\
   154 	switch((resId >> RESOURCE_BIT_IN_ID_CHECK) & 0x3)											\
   160 	switch((resId >> RESOURCE_BIT_IN_ID_CHECK) & 0x3)											\
   155 		{																						\
   161 		{																						\
   156 		case PRM_STATIC_RESOURCE:																\
   162 		case PRM_STATIC_RESOURCE:																\
   157 			if(resId > iStaticResourceArrayEntries)												\
   163 			if((TInt)resId > iStaticResourceArray.Count())										\
   158 				UNLOCK_RETURN(KErrNotFound);													\
   164 				UNLOCK_RETURN(KErrNotFound);													\
   159 			res = iStaticResourceArray[resId - 1];												\
   165 			res = iStaticResourceArray[resId - 1];												\
   160 			if(!res)																			\
   166 			if(!res)																			\
   161 				UNLOCK_RETURN(KErrNotFound);													\
   167 				UNLOCK_RETURN(KErrNotFound);													\
   162 			break;																				\
   168 			break;																				\
   163 		case PRM_STATIC_DEPENDENCY_RESOURCE:													\
   169 		case PRM_STATIC_DEPENDENCY_RESOURCE:													\
   164 			if((TUint16)(resId & ID_INDEX_BIT_MASK) > iStaticResDependencyCount)				\
   170 			if((TInt)(resId & ID_INDEX_BIT_MASK) > iStaticResDependencyArray.Count())	\
   165 				UNLOCK_RETURN(KErrNotFound);													\
   171 				UNLOCK_RETURN(KErrNotFound);													\
   166 			res = iStaticResDependencyArray[(TUint16)(resId & ID_INDEX_BIT_MASK)  - 1];			\
   172 			res = iStaticResDependencyArray[(resId & ID_INDEX_BIT_MASK)  - 1];			\
   167 			break;																				\
   173 			break;																				\
   168 		case PRM_DYNAMIC_RESOURCE:																\
   174 		case PRM_DYNAMIC_RESOURCE:																\
   169 			res = iDynamicResourceList[(TUint16)(resId & ID_INDEX_BIT_MASK)];					\
   175 			res = iDynamicResourceList[(resId & ID_INDEX_BIT_MASK)];					\
   170 			if(!res)																			\
   176 			if(!res)																			\
   171 				UNLOCK_RETURN(KErrNotFound);													\
   177 				UNLOCK_RETURN(KErrNotFound);													\
   172 			break;																				\
   178 			break;																				\
   173 		case PRM_DYNAMIC_DEPENDENCY_RESOURCE:													\
   179 		case PRM_DYNAMIC_DEPENDENCY_RESOURCE:													\
   174 			res = iDynamicResDependencyList[(TUint16)(resId & ID_INDEX_BIT_MASK)];				\
   180 			res = iDynamicResDependencyList[(resId & ID_INDEX_BIT_MASK)];				\
   175 			if(!res)																			\
   181 			if(!res)																			\
   176 				UNLOCK_RETURN(KErrNotFound);													\
   182 				UNLOCK_RETURN(KErrNotFound);													\
   177 			break;																				\
   183 			break;																				\
   178 		default:																				\
   184 		default:																				\
   179 			UNLOCK_RETURN(KErrArgument);														\
   185 			UNLOCK_RETURN(KErrArgument);														\
   183 /**Macro to get the client from appropriate client list based on bit 14 of client ID.
   189 /**Macro to get the client from appropriate client list based on bit 14 of client ID.
   184    If the client is registered as thread relative, then check is made to make sure
   190    If the client is registered as thread relative, then check is made to make sure
   185    it is called from the same thread. */
   191    it is called from the same thread. */
   186 #define VALIDATE_CLIENT(t)																						\
   192 #define VALIDATE_CLIENT(t)																						\
   187 	if(aClientId & USER_SIDE_CLIENT_BIT_MASK)																	\
   193 	if(aClientId & USER_SIDE_CLIENT_BIT_MASK)																	\
   188 		pC = iUserSideClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)];										\
   194 		pC = iUserSideClientList[(aClientId & ID_INDEX_BIT_MASK)];										\
   189 	else																										\
   195 	else																										\
   190 		pC = iClientList[(TUint16)(aClientId & ID_INDEX_BIT_MASK)];												\
   196 		pC = iClientList[(aClientId & ID_INDEX_BIT_MASK)];												\
   191 	if(!pC)																										\
   197 	if(!pC)																										\
   192 		{																										\
   198 		{																										\
   193 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found"));											\
   199 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("Client ID not Found"));											\
   194 		UNLOCK_RETURN(KErrAccessDenied);																		\
   200 		UNLOCK_RETURN(KErrAccessDenied);																		\
   195 		}																										\
   201 		}																										\
   208 		}
   214 		}
   209 
   215 
   210 /** Macro to get the target client from appropriate client list based on bit 14 of client ID. */
   216 /** Macro to get the target client from appropriate client list based on bit 14 of client ID. */
   211 #define GET_TARGET_CLIENT()																				\
   217 #define GET_TARGET_CLIENT()																				\
   212 	if(aTargetClientId & USER_SIDE_CLIENT_BIT_MASK) 													\
   218 	if(aTargetClientId & USER_SIDE_CLIENT_BIT_MASK) 													\
   213 		pC = iUserSideClientList[(TUint16)(aTargetClientId & ID_INDEX_BIT_MASK)];	    				\
   219 		pC = iUserSideClientList[(aTargetClientId & ID_INDEX_BIT_MASK)];	    				\
   214 	else																								\
   220 	else																								\
   215 		pC = iClientList[(TUint16)(aTargetClientId & ID_INDEX_BIT_MASK)];								\
   221 		pC = iClientList[(aTargetClientId & ID_INDEX_BIT_MASK)];								\
   216 	if(!pC)																								\
   222 	if(!pC)																								\
   217 		{																								\
   223 		{																								\
   218 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("Target Client ID not found"));							\
   224 		__KTRACE_OPT(KRESMANAGER, Kern::Printf("Target Client ID not found"));							\
   219 		UNLOCK_RETURN(KErrNotFound);																	\
   225 		UNLOCK_RETURN(KErrNotFound);																	\
   220 		}																								\
   226 		}																								\
   316 */
   322 */
   317 template <class T>
   323 template <class T>
   318 class DResourceCon : public DBase
   324 class DResourceCon : public DBase
   319 	{
   325 	{
   320 public:
   326 public:
   321     inline TInt Initialise(TUint16 aInitialSize);
   327     inline TInt Initialise(TInt aInitialSize);
   322     inline void Delete();
   328     inline void Delete();
   323     inline T*  operator[](TUint16 aIndex);
   329     inline T*  operator[](TInt aIndex);
   324     inline TInt Remove(T* aObj, TUint16 aIndex);
   330     inline TInt Remove(T* aObj, TInt aIndex);
   325     inline TInt Add(T* aObj, TUint &aId);
   331     inline TInt Add(T* aObj, TUint &aId);
   326     inline TInt Find(T*& anEntry, TDesC& aName);
   332     inline TInt Find(T*& anEntry, TDesC& aName);
   327     inline TInt ReSize(TUint16 aGrowBy);
   333     inline TInt ReSize(TInt aGrowBy);
   328     inline TUint16 Count() {return iCount;}
   334     inline TInt Count() {return iCount;}
   329     inline TUint16 Allocd() {return iAllocated;}
   335     inline TInt Allocd() {return iAllocated;}
   330 	inline TUint16 GrowBy() {return iGrowBy;}
   336 	inline TInt GrowBy() {return iGrowBy;}
   331 private:
   337 private:
   332     TUint16 iGrowBy; //Size to grow the size of the array.
   338     TUint16 iGrowBy; //Size to grow the size of the array.
   333     TUint16 iAllocated;  //Size of the array
   339     TUint16 iAllocated;  //Size of the array
   334     TUint16 iCount; //Valid entries in the array
   340     TUint16 iCount; //Valid entries in the array
   335     TUint16 iInstanceCount; //FreeCounter incremented whenever an entry is added.
   341     TUint16 iInstanceCount; //FreeCounter incremented whenever an entry is added.
   452     virtual TInt DeregisterProxyClient(TUint aClientId);
   458     virtual TInt DeregisterProxyClient(TUint aClientId);
   453     //register list of resources whose state matter to Idle
   459     //register list of resources whose state matter to Idle
   454     virtual TInt RegisterResourcesForIdle(TInt aPowerControllerId, TUint aNumResources, TPtr* aBuf);
   460     virtual TInt RegisterResourcesForIdle(TInt aPowerControllerId, TUint aNumResources, TPtr* aBuf);
   455     static void Panic(TUint8 aPanic);
   461     static void Panic(TUint8 aPanic);
   456     virtual TInt GetInterface(TUint aClientId, TUint aInterfaceId, TAny* aParam1, TAny* aParam2, TAny* aParam3);
   462     virtual TInt GetInterface(TUint aClientId, TUint aInterfaceId, TAny* aParam1, TAny* aParam2, TAny* aParam3);
   457 	virtual ~DPowerResourceController();
       
   458 	/**@internalComponent*/
   463 	/**@internalComponent*/
   459 	void CompleteNotifications(TInt aClientId, DStaticPowerResource* aResource, TInt aState, TInt aReturnCode, TInt aLevelOwnerId, TBool aLock = ETrue);
   464 	void CompleteNotifications(TInt aClientId, DStaticPowerResource* aResource, TInt aState, TInt aReturnCode, TInt aLevelOwnerId, TBool aLock = ETrue);
   460 #ifdef PRM_ENABLE_EXTENDED_VERSION
   465 #ifdef PRM_ENABLE_EXTENDED_VERSION
   461 	/**@internalComponent*/
   466 	/**@internalComponent*/
   462 	TInt ReserveClientLevelPoolCount(TUint16 aCount);
   467 	TInt ReserveClientLevelPoolCount(TUint16 aCount);
   479 						  Kern::MutexWait(*iResourceMutex); }
   484 						  Kern::MutexWait(*iResourceMutex); }
   480 	inline void UnLock()	{ Kern::MutexSignal(*iResourceMutex);
   485 	inline void UnLock()	{ Kern::MutexSignal(*iResourceMutex);
   481 							  NKern::ThreadLeaveCS();}
   486 							  NKern::ThreadLeaveCS();}
   482 #ifdef PRM_ENABLE_EXTENDED_VERSION
   487 #ifdef PRM_ENABLE_EXTENDED_VERSION
   483 	//Default implementation, PSL re-implements these if features supported
   488 	//Default implementation, PSL re-implements these if features supported
   484 	virtual TInt DoRegisterStaticResourcesDependency(DStaticPowerResourceD**& aStaticResourceDArray, TUint16& aStaticResourceDCount);
   489 	virtual TInt DoRegisterStaticResourcesDependency(RPointerArray <DStaticPowerResourceD> & aStaticResourceDArray);
   485 #endif
   490 #endif
   486 private:
   491 private:
   487     // pure virtual implemented by PSL - to be called by PIL
   492     // pure virtual implemented by PSL - to be called by PIL
   488     virtual TInt DoInitController()=0;
   493     virtual TInt DoInitController()=0;
   489     virtual TInt DoRegisterStaticResources(DStaticPowerResource**& aStaticResourceArray, TUint16& aStaticResourceCount)=0;
   494     virtual TInt DoRegisterStaticResources(RPointerArray <DStaticPowerResource> & aStaticResourceArray)=0;
   490     /**@internalComponent*/
   495     /**@internalComponent*/
   491     TInt CheckLevelAndAddClient(SPowerResourceClient* pC, TPowerRequest* Request);
   496     TInt CheckLevelAndAddClient(SPowerResourceClient* pC, TPowerRequest* Request);
   492     static void MsgQFunc(TAny* aPtr);
   497     static void MsgQFunc(TAny* aPtr);
   493     #ifdef PRM_ENABLE_EXTENDED_VERSION
   498     #ifdef PRM_ENABLE_EXTENDED_VERSION
   494     static void MsgQDependencyFunc(TAny* aPtr);
   499     static void MsgQDependencyFunc(TAny* aPtr);
   521 	TInt HandleDependencyResourceStateChange(SPowerResourceClient* pC, TPowerRequest& aRequest);
   526 	TInt HandleDependencyResourceStateChange(SPowerResourceClient* pC, TPowerRequest& aRequest);
   522 	TInt GetNumDependentsForResource(TUint aResourceId, TUint* aNumResources);
   527 	TInt GetNumDependentsForResource(TUint aResourceId, TUint* aNumResources);
   523 	TInt GetDependentsIdForResource(TUint aResourceId, TAny* aInfo, TUint* aNumDepResources);
   528 	TInt GetDependentsIdForResource(TUint aResourceId, TAny* aInfo, TUint* aNumDepResources);
   524 	TInt HandleResourceRegistration(TPowerRequest& aReq);
   529 	TInt HandleResourceRegistration(TPowerRequest& aReq);
   525 #endif
   530 #endif
   526 public:
   531 protected:
   527 	DMutex* iResourceMutex;
   532 	DMutex* iResourceMutex;
   528 protected:
   533 	TDfcQue* iDfcQ;
   529     TDfcQue* iDfcQ;
       
   530     TMessageQue *iMsgQ;
   534     TMessageQue *iMsgQ;
   531 #ifdef PRM_ENABLE_EXTENDED_VERSION
   535 #ifdef PRM_ENABLE_EXTENDED_VERSION
   532 	TDfcQue* iDfcQDependency;
   536 	TDfcQue* iDfcQDependency;
   533 	TMessageQue* iMsgQDependency;
   537 	TMessageQue* iMsgQDependency;
   534 	TBool iDfcQDependencyLock;
   538 	TBool iDfcQDependencyLock;
   535 #endif
   539 #endif
   536 private:
   540 	RPointerArray <DStaticPowerResource> iStaticResourceArray;
   537     DStaticPowerResource** iStaticResourceArray;
       
   538     DResourceCon<SPowerResourceClient> iClientList;
   541     DResourceCon<SPowerResourceClient> iClientList;
   539     DResourceCon<SPowerResourceClient> iUserSideClientList;
   542     DResourceCon<SPowerResourceClient> iUserSideClientList;
   540 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
   543 #ifdef RESOURCE_MANAGER_SIMULATED_PSL
   541 	RPointerArray<SPowerResourceClient> iCleanList;
   544 	RPointerArray<SPowerResourceClient> iCleanList;
   542 #endif
   545 #endif
   550     TUint16 iUserSideClientCount;
   553     TUint16 iUserSideClientCount;
   551     TUint16 iClientLevelPoolCount;
   554     TUint16 iClientLevelPoolCount;
   552     TUint16 iClientLevelPoolGrowBy;
   555     TUint16 iClientLevelPoolGrowBy;
   553     TUint16 iRequestPoolCount;
   556     TUint16 iRequestPoolCount;
   554     TUint16 iRequestPoolGrowBy;
   557     TUint16 iRequestPoolGrowBy;
   555     TUint16 iStaticResourceArrayEntries; //Number of entries in the array including holes if any.
       
   556 	TUint16 iStaticResourceCount;  //Actual number of static resources registered (valid entries).
   558 	TUint16 iStaticResourceCount;  //Actual number of static resources registered (valid entries).
   557 	TUint	iReserved2; //Reserved for future use
   559 	TUint	iReserved2; //Reserved for future use
   558 #ifdef PRM_ENABLE_EXTENDED_VERSION
   560 #ifdef PRM_ENABLE_EXTENDED_VERSION
   559 	DResourceCon<DDynamicPowerResource> iDynamicResourceList;
   561 	DResourceCon<DDynamicPowerResource>   iDynamicResourceList;
   560 	DResourceCon<DDynamicPowerResourceD> iDynamicResDependencyList;
   562 	DResourceCon<DDynamicPowerResourceD>  iDynamicResDependencyList;
   561 	DStaticPowerResourceD** iStaticResDependencyArray;
   563 	RPointerArray <DStaticPowerResourceD> iStaticResDependencyArray;
   562 	SPowerResourceClientLevel* iResourceLevelPool;
   564 	SPowerResourceClientLevel* iResourceLevelPool;
   563 	TUint16 iResourceLevelPoolCount;
   565 	TUint16 iResourceLevelPoolCount;
   564 	TUint16 iStaticResDependencyCount;
       
   565 	TUint16 iDynamicResourceCount;
   566 	TUint16 iDynamicResourceCount;
   566 	TUint8 iDynamicResDependencyCount;
   567 	TUint8  iDynamicResDependencyCount;
   567 	TUint8 iSpare2;
   568 	TUint8  iSpare1;
       
   569 	TUint16 iSpare2;
   568 	TUint  iReserved3; //Reserved for future use.
   570 	TUint  iReserved3; //Reserved for future use.
   569 #endif
   571 #endif
   570 	};
   572 	};
   571 
   573 
   572 /**
   574 /**