]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/pms.h
xnu-792.6.61.tar.gz
[apple/xnu.git] / osfmk / ppc / pms.h
1 /*
2 * Copyright (c) 2004-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifdef KERNEL_PRIVATE
24
25 #ifndef _PPC_PMS_H_
26 #define _PPC_PMS_H_
27
28 #define pmsMaxStates 64
29 #define HalfwayToForever 0x7FFFFFFFFFFFFFFFULL
30 #define century 790560000000000ULL
31
32 typedef void (*pmsSetFunc_t)(uint32_t, uint32_t, uint32_t); /* Function used to set hardware power state */
33 typedef uint32_t (*pmsQueryFunc_t)(uint32_t, uint32_t); /* Function used to query hardware power state */
34
35 typedef struct pmsStat {
36 uint64_t stTime[2]; /* Total time until switch to next step */
37 uint32_t stCnt[2]; /* Number of times switched to next step */
38 } pmsStat;
39
40 typedef struct pmsDef {
41 uint64_t pmsLimit; /* Max time in this state in microseconds */
42 uint32_t pmsStepID; /* Unique ID for this step */
43 uint32_t pmsSetCmd; /* Command to select power state */
44 #define pmsCngXClk 0x80000000 /* Change external clock */
45 #define pmsXUnk 0x7F /* External clock unknown */
46 #define pmsXClk 0x7F000000 /* External clock frequency */
47 #define pmsCngCPU 0x00800000 /* Change CPU parameters */
48 #define pmsSync 0x00400000 /* Make changes synchronously, i.e., spin until delay finished */
49 #define pmsMustCmp 0x00200000 /* Delay must complete before next change */
50 #define pmsCPU 0x001F0000 /* CPU frequency */
51 #define pmsCPUUnk 0x1F /* CPU frequency unknown */
52 #define pmsCngVolt 0x00008000 /* Change voltage */
53 #define pmsVoltage 0x00007F00 /* Voltage */
54 #define pmsVoltUnk 0x7F /* Voltage unknown */
55 #define pmsPowerID 0x000000FF /* Identify power state to HW */
56
57 /* Special commands - various things */
58 #define pmsDelay 0xFFFFFFFD /* Delayed step, no processor or platform changes. Timer expiration causes transition to pmsTDelay */
59 #define pmsParkIt 0xFFFFFFFF /* Enters the parked state. No processor or platform changes. Timers cancelled */
60 #define pmsCInit ((pmsXUnk << 24) | (pmsCPUUnk << 16) | (pmsVoltUnk << 8)) /* Initial current set command value */
61 /* Note: pmsSetFuncInd is an index into a table of function pointers and pmsSetFunc is the address
62 * of a function. Initially, when you create a step table, this field is set as an index into
63 * a table of function addresses that gets passed as a parameter to pmsBuild. When pmsBuild
64 * internalizes the step and function tables, it converts the index to the function address.
65 */
66 union sf {
67 pmsSetFunc_t pmsSetFunc; /* Function used to set platform power state */
68 uint32_t pmsSetFuncInd; /* Index to function in function table */
69 } sf;
70
71 uint32_t pmsDown; /* Next state if going lower */
72 uint32_t pmsNext; /* Normal next state */
73 uint32_t pmsTDelay; /* State if command was pmsDelay and timer expired */
74 } pmsDef;
75
76 typedef struct pmsCtl {
77 pmsStat (*pmsStats)[pmsMaxStates]; /* Pointer to statistics information, 0 if not enabled */
78 pmsDef *pmsDefs[pmsMaxStates]; /* Indexed pointers to steps */
79 } pmsCtl;
80
81 /*
82 * Note that this block is in the middle of the per_proc and the size (32 bytes)
83 * can't be changed without moving it.
84 */
85
86 typedef struct pmsd {
87 uint32_t pmsState; /* Current power management state */
88 uint32_t pmsCSetCmd; /* Current select command */
89 uint64_t pmsPop; /* Time of next step */
90 uint64_t pmsStamp; /* Time of transition to current state */
91 uint64_t pmsTime; /* Total time in this state */
92 } pmsd;
93
94 /*
95 * Required power management step programs
96 */
97
98 enum {
99 pmsIdle = 0, /* Power state in idle loop */
100 pmsNorm = 1, /* Normal step - usually low power */
101 pmsNormHigh = 2, /* Highest power in normal step */
102 pmsBoost = 3, /* Boost/overdrive step */
103 pmsLow = 4, /* Lowest non-idle power state, no transitions */
104 pmsHigh = 5, /* Power step for full on, no transitions */
105 pmsPrepCng = 6, /* Prepare for step table change */
106 pmsPrepSleep = 7, /* Prepare for sleep */
107 pmsOverTemp = 8, /* Machine is too hot */
108 pmsEnterNorm = 9, /* Enter into the normal step program */
109 pmsFree = 10, /* First available empty step */
110 pmsStartUp = 0xFFFFFFFE, /* Start stepping */
111 pmsParked = 0xFFFFFFFF /* Power parked - used when changing stepping table */
112 };
113
114 /*
115 * Power Management Stepper Control requests
116 */
117
118 enum {
119 pmsCPark = 0, /* Parks the stepper */
120 pmsCStart = 1, /* Starts normal steppping */
121 pmsCFLow = 2, /* Forces low power */
122 pmsCFHigh = 3, /* Forces high power */
123 pmsCCnfg = 4, /* Loads new stepper program */
124 pmsCQuery = 5, /* Query current step and state */
125 pmsCExperimental = 6, /* Enter experimental mode */
126 pmsCFree = 7 /* Next control command to be assigned */
127 };
128
129 extern pmsCtl pmsCtls; /* Power Management Stepper control */
130 extern uint32_t pmsCtlp;
131 extern uint32_t pmsBroadcastWait; /* Number of outstanding broadcasts */
132 extern pmsDef pmsDefault[];
133 extern int pmsInstalled;
134 extern int pmsExperimental;
135
136 #define pmsSetFuncMax 32
137 extern pmsSetFunc_t pmsFuncTab[pmsSetFuncMax];
138 extern pmsQueryFunc_t pmsQueryFunc;
139 extern uint32_t pmsPlatformData;
140
141 extern int pmsCntrl(struct savearea *save);
142 extern void pmsInit(void);
143 extern void pmsStep(int timer);
144 extern void pmsDown(void);
145 extern void pmsSetStep(uint32_t nstep, int dir);
146 extern void pmsRemote(uint32_t nstep);
147 extern void pmsCPUSet(uint32_t sel);
148 extern uint32_t pmsCPUquery(void);
149 extern void pmsCPUConf(void);
150 extern void pmsCPUInit(void);
151
152 #ifdef __cplusplus
153 extern "C" {
154 #endif
155
156 extern kern_return_t pmsBuild(pmsDef *pd, uint32_t pdsize, pmsSetFunc_t *functab, uint32_t platformData, pmsQueryFunc_t queryFunc);
157 extern void pmsRun(uint32_t nstep);
158 extern void pmsRunLocal(uint32_t nstep);
159 extern void pmsPark(void);
160 extern void pmsStart(void);
161
162 #ifdef __cplusplus
163 }
164 #endif
165
166 #endif /* _PPC_PMS_H_ */
167 #endif /* KERNEL_PRIVATE */