os/kernelhwsrv/kernel/eka/include/drivers/resource.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.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,271 @@
     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.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_H__
    1.25 +#define __RESOURCE_H__
    1.26 +#include <kernel/kernel.h>
    1.27 +#include <kernel/kern_priv.h>
    1.28 +#include <drivers/resourcecontrol_trace.h>
    1.29 +#include <drivers/resource_category.h>
    1.30 +
    1.31 +//Definition for resource flag setting. Used by PSL.
    1.32 +static const TUint KTypeMask= 0x3;
    1.33 +static const TUint KUsageOffset=0x1F;
    1.34 +static const TUint KLongLatencySetOffset=0x1E;
    1.35 +static const TUint KLongLatencyGetOffset=0x1D;
    1.36 +static const TUint KClassOffset=0x1C;
    1.37 +static const TUint KSenseOffset=0x1A;
    1.38 +static const TUint KShared=0x1<<KUsageOffset;
    1.39 +static const TUint KLongLatencySet=0x1<<KLongLatencySetOffset;
    1.40 +static const TUint KLongLatencyGet=0x1<<KLongLatencyGetOffset;
    1.41 +static const TUint KLogical=0x1<<KClassOffset;
    1.42 +static const TUint KSenseNegative=0x01<<KSenseOffset;
    1.43 +static const TUint KSenseCustom=0x2<<KSenseOffset;
    1.44 +
    1.45 +struct TPowerRequest;
    1.46 +struct SIdleResourceInfo;
    1.47 +
    1.48 +
    1.49 +/**
    1.50 + * List of operations that a Custom Function may be informed of. 
    1.51 + *
    1.52 + * @publishedPartner
    1.53 + * @prototype 9.5
    1.54 + */
    1.55 +enum TCustomOperation
    1.56 +    {
    1.57 +	/**
    1.58 +	Client has requested the given level.
    1.59 +	*/
    1.60 +	EClientRequestLevel,
    1.61 +
    1.62 +	/**
    1.63 +	Client has relinquished the given level.
    1.64 +    */
    1.65 +	EClientRelinquishLevel,
    1.66 +	
    1.67 +	/**
    1.68 +	Client is changing the level.
    1.69 +	*/
    1.70 +	EClientChangeLevel,
    1.71 +	
    1.72 +	/**
    1.73 +	A dynamic resource is being deregistered.
    1.74 +	*/
    1.75 +	EDynamicResourceDeregister
    1.76 +	};
    1.77 +
    1.78 +
    1.79 +/**
    1.80 + *  Function prototype for the Custom Function.
    1.81 + *  
    1.82 + *  @publishedPartner
    1.83 + *  @prototype 9.5
    1.84 + */
    1.85 +typedef TBool (*TCustomFunction) (TInt& /*aClientId*/,
    1.86 +								  const TDesC8& /*aClientName*/,
    1.87 +                                  TUint /*aResourceId*/,
    1.88 +                                  TCustomOperation /*aCustomOperation*/,
    1.89 +                                  TInt& /*aLevel*/,
    1.90 +                                  TAny* /*aLevelList*/,
    1.91 +                                  TAny* /*aReserved*/);  // For future use
    1.92 +
    1.93 +/**
    1.94 +@publishedPartner
    1.95 +@prototype 9.5
    1.96 +class to represent static resources
    1.97 +*/
    1.98 +class DStaticPowerResource : public DBase
    1.99 +	{
   1.100 +public:
   1.101 +    enum TType {EBinary = EResBinary, EMultilevel, EMultiProperty};
   1.102 +    enum TUsage {ESingleUse = EResSingleUse, EShared};
   1.103 +    enum TLatency {EInstantaneous = EResInstantaneous, ELongLatency};
   1.104 +    enum TClass {EPhysical = EResPhysical, ELogical};
   1.105 +    enum TSense {EPositive = EResPositive, ENegative, ECustom};
   1.106 +public:
   1.107 +    //exported to allow construction from other base port components.
   1.108 +    IMPORT_C DStaticPowerResource(const TDesC8& aName, TInt aDefaultLevel);
   1.109 +    IMPORT_C virtual TInt GetInfo(TDes8* aInfo)const;
   1.110 +    inline void SetCustomFunction(TCustomFunction aCustomFunction)
   1.111 +           {iCustomFunction=aCustomFunction;}
   1.112 +
   1.113 +    //private data inlined accessors
   1.114 +    TType Type() const {return TType(iFlags&KTypeMask);}
   1.115 +    TClass Class() const {return TClass((iFlags>>KClassOffset)&0x1);}
   1.116 +    TUsage Usage() const {return TUsage((iFlags>>KUsageOffset)&0x1);}
   1.117 +    TLatency LatencyGet() const
   1.118 +             {return TLatency((iFlags>>KLongLatencyGetOffset)&0x1);}
   1.119 +    TLatency LatencySet() const
   1.120 +             {return TLatency((iFlags>>KLongLatencySetOffset)&0x1);}
   1.121 +    TSense Sense() const {return TSense((iFlags>>KSenseOffset)&0x3);}
   1.122 +protected:
   1.123 +    //pure virtual function to be implement by PSL
   1.124 +    virtual TInt DoRequest(TPowerRequest& aRequest)=0;
   1.125 +public:
   1.126 +	HBuf8* iName;
   1.127 +protected:
   1.128 +    TInt iPostBootLevel;
   1.129 +	TInt iDefaultLevel;
   1.130 +protected:
   1.131 +    TInt iCachedLevel;
   1.132 +	TUint iResourceId;
   1.133 +    SDblQue iNotificationList;
   1.134 +    SDblQue iClientList;
   1.135 +    TCustomFunction iCustomFunction;
   1.136 +    TInt iLevelOwnerId;
   1.137 +    SIdleResourceInfo* iIdleListEntry;
   1.138 +protected:
   1.139 +    TUint iFlags;
   1.140 +#ifdef PRM_CONTROLLER
   1.141 +    friend class DPowerResourceController;
   1.142 +#endif
   1.143 +	};
   1.144 +
   1.145 +typedef void (*TPowerResourceCbFn)(TUint /*aClientId*/,
   1.146 +                                   TUint /*aResourceId*/,
   1.147 +                                   TInt /*aLevel*/,
   1.148 +								   TInt /*aLevelOwnerId*/,
   1.149 +                                   TInt /*aResult*/,
   1.150 +                                   TAny* /*aParam*/);
   1.151 +
   1.152 +/**
   1.153 +@publishedPartner
   1.154 +@prototype 9.5
   1.155 +An object of this type prepresents a customised Dfc
   1.156 +used to signal completion of the resource manager's asynchronous APIs
   1.157 +and completion of notifications
   1.158 +@see TPowerResourceManager
   1.159 + */
   1.160 +class TPowerResourceCb : public TDfc
   1.161 +	{
   1.162 +public:
   1.163 +	inline TPowerResourceCb(TPowerResourceCbFn aFn, TAny* aPtr, TInt aPriority) : TDfc(DfcFunc, this, aPriority), 
   1.164 +		                                                            iParam(aPtr), iCallback(aFn){ }
   1.165 +	inline TPowerResourceCb(TPowerResourceCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority):  
   1.166 +	                              TDfc(DfcFunc, this, aQue, aPriority), iParam(aPtr), iCallback(aFn) { }
   1.167 +private:
   1.168 +    inline static void DfcFunc(TAny* aPtr)
   1.169 +        {
   1.170 +        TPowerResourceCb* pCb = (TPowerResourceCb*) aPtr;
   1.171 +	    __KTRACE_OPT(KRESMANAGER, Kern::Printf(">TPowerResourceCb::DfcFunc ClientId = 0x%x, ResourceId = %d, Level = %d, \
   1.172 +			                    LevelOwnerId = %d, Result = %d", pCb->iClientId, pCb->iResourceId, pCb->iLevel, \
   1.173 +								pCb->iLevelOwnerId, pCb->iResult));
   1.174 +	    // Call the client specified callback function
   1.175 +        pCb->iCallback(pCb->iClientId, pCb->iResourceId, pCb->iLevel, pCb->iLevelOwnerId, pCb->iResult, pCb->iParam);
   1.176 +		pCb->iResult = KErrCompletion; //Mark the callback object to act properly during cancellation of this request.
   1.177 +        PRM_CALLBACK_COMPLETION_TRACE
   1.178 +        }
   1.179 +private:
   1.180 +    TAny* iParam; //Stores the aPtr argument passed in the constructor, to be passed as 5th argument to the callback function
   1.181 +    TInt iResult; //Used to store the result aswell as binary usage count for the callback
   1.182 +    TInt iLevel; // Level of the resource
   1.183 +	TInt iLevelOwnerId; // Stores owner of the resource for asynchronous get operation
   1.184 +    TUint iResourceId; //Stores the ID of the resource whose state is changed/read asynchronously
   1.185 +    TUint iClientId; //Stores the ID of the client that requested the asynchronous operation
   1.186 +    TPowerResourceCbFn iCallback; //Callback function object
   1.187 +#ifdef PRM_CONTROLLER
   1.188 +    friend class DPowerResourceController;
   1.189 +#endif
   1.190 +	};
   1.191 +
   1.192 +/**
   1.193 +@publishedPartner
   1.194 +@prototype 9.5
   1.195 +Notifications class. Conditional and unconditional notifications are encapsulated in this class. 
   1.196 +It uses TPowerResourceCb to perform the actual notification call.
   1.197 +@see TPowerResourceCb
   1.198 + */
   1.199 +class DPowerResourceNotification : public DBase
   1.200 +    {
   1.201 +public:
   1.202 +    enum TType {EUnconditional, EConditional};
   1.203 +	enum TResNotiPanic {ENotificationObjectStillInList = 25}; 
   1.204 +public:
   1.205 +	inline DPowerResourceNotification(TPowerResourceCbFn aFn, TAny* aPtr, TInt aPriority): 
   1.206 +	                                                 iCallback(aFn, aPtr, aPriority) {}
   1.207 +	inline DPowerResourceNotification(TPowerResourceCbFn aFn, TAny* aPtr, TDfcQue* aQue, TInt aPriority) : 
   1.208 +	                                                 iCallback(aFn, aPtr, aQue, aPriority) {}
   1.209 +	inline ~DPowerResourceNotification() 
   1.210 +		{
   1.211 +		if(iRegistered)
   1.212 +			Kern::Fault("Power Resource Controller", ENotificationObjectStillInList);
   1.213 +		}
   1.214 +public:
   1.215 +	TInt iPreviousLevel; //Previous level of the resource. This is used for checking the threshold condition
   1.216 +	TUint8 iRegistered;
   1.217 +private:
   1.218 +    TUint8 iType; // the type of notification required (conditional or unconditional).
   1.219 +    TUint16 iOwnerId; // the bottom 16 bits of the Id of the client which requested the notification
   1.220 +    TInt iThreshold; // the threshold which when crossed on a specified direction will cause a notification to be issued.
   1.221 +    TBool iDirection; // the direction of the resource change that together with the threshold to be crossed will result in the notification
   1.222 +    TPowerResourceCb iCallback; //Callback object associated with this notification
   1.223 +    SDblQueLink iNotificationLink; 
   1.224 +    DPowerResourceNotification* iNextInClient;
   1.225 +#ifdef PRM_CONTROLLER
   1.226 +    friend class DPowerResourceController;
   1.227 +#endif
   1.228 +	};
   1.229 +
   1.230 +/**
   1.231 +@publishedPartner
   1.232 +@prototype 9.5
   1.233 +class to represent resource properties
   1.234 +*/
   1.235 +class TPowerResourceInfoV01
   1.236 +	{
   1.237 +public:
   1.238 +    DStaticPowerResource::TClass iClass;
   1.239 +    DStaticPowerResource::TLatency iLatencyGet;
   1.240 +    DStaticPowerResource::TLatency iLatencySet;
   1.241 +    DStaticPowerResource::TType iType;
   1.242 +    DStaticPowerResource::TUsage iUsage;
   1.243 +    DStaticPowerResource::TSense iSense;
   1.244 +    TDesC8* iResourceName;
   1.245 +    TUint iResourceId;
   1.246 +    TInt iDefaultLevel;  
   1.247 +    TInt iMinLevel;      //PSL mandatory field
   1.248 +    TInt iMaxLevel;      //PSL mandatory field
   1.249 +	TInt iReserved1;	 //Reserved for future use.	
   1.250 +	TInt iReserved2;	 //Reserved for future use.
   1.251 +	TInt iReserved3;	 //Reserved for future use.
   1.252 +    TInt iPslReserved1;  //PSL specific field
   1.253 +    TInt iPslReserved2;  //PSL specific field
   1.254 +    TInt iPslReserved3;  //PSL specific field
   1.255 +	};
   1.256 +
   1.257 +/**
   1.258 +@publishedPartner
   1.259 +@prototype 9.5
   1.260 +*/
   1.261 +typedef TPckgBuf<TPowerResourceInfoV01> TPowerResourceInfoBuf01;
   1.262 +
   1.263 +/**
   1.264 +@publishedPartner
   1.265 +@prototype 9.5
   1.266 +structure to represent client properties
   1.267 +*/
   1.268 +struct TPowerClientInfoV01
   1.269 +	{
   1.270 +    TUint iClientId;
   1.271 +    TDesC8* iClientName;
   1.272 +	};
   1.273 +
   1.274 +#endif // __RESOURCE_H__