os/kernelhwsrv/kernel/eka/include/drivers/resource_extend.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/resource_extend.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,198 @@
     1.4 +// Copyright (c) 2007-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\drivers\resource_extend.h
    1.18 +// 
    1.19 +// WARNING: This file contains some APIs which are internal and are subject
    1.20 +//          to change without notice. Such APIs should therefore not be used
    1.21 +//          outside the Kernel and Hardware Services package.
    1.22 +//
    1.23 +
    1.24 +#ifndef __RESOURCE_EXTEND_H__
    1.25 +#define __RESOURCE_EXTEND_H__
    1.26 +
    1.27 +#include <drivers/resource.h>
    1.28 +
    1.29 +#define ADD_DEPENDENCY_NODE(aNode, aDependencyList)																	\
    1.30 +	{																												\
    1.31 +	SNode* pDL = aDependencyList;																					\
    1.32 +	SNode* prev = NULL;																								\
    1.33 +	if(pDL == NULL)																									\
    1.34 +		{																											\
    1.35 +		aDependencyList = aNode;																					\
    1.36 +		aNode->iNext = NULL;																						\
    1.37 +		}																											\
    1.38 +	else																											\
    1.39 +		{																											\
    1.40 +		while(pDL != NULL)																							\
    1.41 +			{																										\
    1.42 +			if(aNode->iPriority == pDL->iPriority)																	\
    1.43 +				return KErrAlreadyExists;																			\
    1.44 +			if(aNode->iPriority < pDL->iPriority)																	\
    1.45 +				{																									\
    1.46 +				if(prev == NULL) /*Add it to the head	*/															\
    1.47 +					{																								\
    1.48 +					aDependencyList = aNode;																		\
    1.49 +					aNode->iNext = pDL;																				\
    1.50 +					break;																							\
    1.51 +					}																								\
    1.52 +				prev->iNext = aNode;																				\
    1.53 +				aNode->iNext = pDL;																					\
    1.54 +				break;																								\
    1.55 +				}																									\
    1.56 +			if(pDL->iNext == NULL) /* Add it to the end	*/															\
    1.57 +				{																									\
    1.58 +				pDL->iNext = aNode;																					\
    1.59 +				aNode->iNext = NULL;																				\
    1.60 +				break;																								\
    1.61 +				}																									\
    1.62 +			prev = pDL;																								\
    1.63 +			pDL = pDL->iNext;																						\
    1.64 +			}																										\
    1.65 +		}																											\
    1.66 +	}
    1.67 +
    1.68 +//Check whether the priority already exists
    1.69 +#define CHECK_IF_PRIORITY_ALREADY_EXISTS(aDependencyList, aPriority)			\
    1.70 +	{																			\
    1.71 +	for(SNode* node = aDependencyList; node != NULL; node = node->iNext)		\
    1.72 +		{																		\
    1.73 +		if(node->iPriority == aPriority)										\
    1.74 +			return KErrAlreadyExists;											\
    1.75 +		}																		\
    1.76 +	}
    1.77 +
    1.78 +
    1.79 +static const TUint KIdMaskStaticWithDependencies	= 0x00010000;
    1.80 +static const TUint KIdMaskDynamic					= 0x00020000;
    1.81 +static const TUint KIdMaskDynamicWithDependencies	= 0x00030000;
    1.82 +static const TUint KIdMaskResourceWithDependencies = 0x00010000;
    1.83 +static const TInt KDynamicResourceDeRegistering = -2; 
    1.84 +
    1.85 +struct SNode;
    1.86 +struct SPowerResourceClientLevel;
    1.87 +
    1.88 +//Various stages of resource dependency state change operation.
    1.89 +enum TPropagation
    1.90 +	{
    1.91 +	EChangeStart,
    1.92 +	ECheckChangeAllowed,
    1.93 +	ERequestStateChange,
    1.94 +	EIssueNotifications
    1.95 +	};
    1.96 +
    1.97 +//Return value of translate dependency state function. This is implemented by PSL for each resource.
    1.98 +enum TChangePropagationStatus {EChange, ENoChange, EChangeNotAccepted};
    1.99 +
   1.100 +/**
   1.101 +@publishedPartner
   1.102 +@prototype 9.5
   1.103 +class to represent dynamic resources
   1.104 +*/
   1.105 +class DDynamicPowerResource : public DStaticPowerResource
   1.106 +	{
   1.107 +public:
   1.108 +	IMPORT_C DDynamicPowerResource(const TDesC8& aName, TInt aDefaultLevel);
   1.109 +	IMPORT_C ~DDynamicPowerResource();
   1.110 +public:
   1.111 +	TBool InUse(); //Used by RC on deregistration to see if another client is having requirement on this resource
   1.112 +	inline void Lock() {++iCount;} //Resource is locked whenever operation is scheduled in RC thread. 
   1.113 +	inline void UnLock() {--iCount;}
   1.114 +	inline TUint LockCount() { return iCount;}
   1.115 +protected:
   1.116 +	TUint iCount;
   1.117 +	TUint iOwnerId; //Stores the ID of the client that registers the resource
   1.118 +	friend class DPowerResourceController;
   1.119 +	};
   1.120 +
   1.121 +/**
   1.122 +@publishedPartner
   1.123 +@prototype 9.5
   1.124 +*/
   1.125 +typedef TBool (*TDependencyCustomFunction) (TInt& /*aClientId*/,
   1.126 +                                            const TDesC8& /*aClientName*/,
   1.127 +                                            TUint /*aResourceId*/,
   1.128 +                                            TCustomOperation /*aCustomOperation*/,
   1.129 +                                            TInt& /*aLevel*/,
   1.130 +                                            TAny* /*aLevelList*/,
   1.131 +                                            TAny* /*aResourceLevelList */,
   1.132 +                                            TAny* /*aReserved*/); // For future use
   1.133 +
   1.134 +/**
   1.135 +@publishedPartner
   1.136 +@prototype 9.5
   1.137 +class to represent static resource with dependency
   1.138 +*/
   1.139 +class DStaticPowerResourceD : public DStaticPowerResource
   1.140 +	{
   1.141 +public:
   1.142 +	DStaticPowerResourceD(const TDesC8& aName, TInt aDefaultLevel);
   1.143 +	TInt AddNode(SNode* aNode);
   1.144 +	virtual TInt HandleChangePropagation(TPowerRequest aRequest, TPropagation aProp, TUint aOriginatorId, const TDesC8& aOriginatorName);
   1.145 +	virtual TChangePropagationStatus TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState) = 0;
   1.146 +public:
   1.147 +	SPowerResourceClientLevel* iResourceClientList; //To capture the dependent resource requirement on this resource
   1.148 +	TDependencyCustomFunction iDepCustomFunction;
   1.149 +private:
   1.150 +	SNode* iDependencyList; //Dependency resource list
   1.151 +	friend class DPowerResourceController;
   1.152 +	};
   1.153 +
   1.154 +/**
   1.155 +@publishedPartner
   1.156 +@prototype 9.5
   1.157 +class to represent dynamic resource with dependency
   1.158 +*/
   1.159 +class DDynamicPowerResourceD : public DDynamicPowerResource
   1.160 +	{
   1.161 +public:
   1.162 +	IMPORT_C DDynamicPowerResourceD(const TDesC8& aName, TInt aDefaultLevel);
   1.163 +	IMPORT_C ~DDynamicPowerResourceD();
   1.164 +	IMPORT_C virtual TInt HandleChangePropagation(TPowerRequest aRequest, TPropagation aProp, TUint aOriginatorId, const TDesC8& aOriginatorName);
   1.165 +	virtual TChangePropagationStatus TranslateDependentState(TInt aDepId, TInt aDepState, TInt& aResState) = 0;
   1.166 +public:
   1.167 +	SPowerResourceClientLevel* iResourceClientList; //To capture the dependent resource requirement on this resource
   1.168 +	TDependencyCustomFunction iDepCustomFunction;
   1.169 +private:
   1.170 +	SNode* iDependencyList; //Dependency resource list
   1.171 +	friend class DPowerResourceController;
   1.172 +	};
   1.173 +
   1.174 +/**
   1.175 +@publishedPartner
   1.176 +@prototype 9.5
   1.177 +structure to represent resource dependency information. This is used when registering resource dependency
   1.178 +*/
   1.179 +struct SResourceDependencyInfo
   1.180 +	{
   1.181 +	TUint iResourceId;
   1.182 +	TUint8 iDependencyPriority;
   1.183 +	};
   1.184 +
   1.185 +/**
   1.186 +@publishedPartner
   1.187 +@prototype 9.5
   1.188 +structure to encapsulate dependent resource information. 
   1.189 +*/
   1.190 +struct SNode
   1.191 +	{
   1.192 +	DStaticPowerResourceD* iResource;
   1.193 +	TInt iPropagatedLevel;
   1.194 +	TUint8 iRequiresChange;
   1.195 +	TUint8 iVisited;
   1.196 +	TUint8 iPriority;
   1.197 +	TUint8 iSpare;
   1.198 +	SNode* iNext;
   1.199 +	};
   1.200 +
   1.201 +#endif