]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/pmCPU.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / osfmk / i386 / pmCPU.h
CommitLineData
5d5c5d0d
A
1/*
2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30#ifdef KERNEL_PRIVATE
31#ifndef _I386_PMCPU_H_
32#define _I386_PMCPU_H_
33
34#include <kern/pms.h>
35
36#ifndef ASSEMBLER
37
38typedef enum { C1, C2, C3, C4, Hlt, C3Res, All, Cnum } pm_Cstate_t;
39typedef struct pmStats {
40 uint64_t pmNapCnt[Cnum]; /* Total nap calls for states */
41 uint64_t pmNapTime[Cnum]; /* Total nap time for states */
42 uint64_t pmNapC2HPET; /* Total nap time for C2 using HPET for stats */
43 uint64_t pmNapC4HPET; /* Total nap time for C4 using HPET for stats */
44 uint64_t pmNapHPETPops; /* Number of times we detect HPET popping */
45 uint64_t pmHPETRupt; /* Number of HPET interruptions */
46 uint32_t pmCurC3Res; /* Current value of the C3 residency timer */
47 uint32_t pmLastApic; /* Last value of apic timer */
48 uint32_t pmNewApic; /* New value of apic timer */
49 uint64_t pmHpetTim; /* Time to next interrupt in HPET ticks */
50 uint64_t pmHpetCmp; /* HPET comparator */
51 uint64_t pmHpetCfg; /* HPET configuration */
52 uint64_t pmLSNs; /* (TEST) Last set nanotime */
53 uint64_t pmLLHpet; /* (TEST) Last loaded HPET */
54} pmStats_t;
55
56#define MAX_PSTATES 32 /* architectural limit */
57
58typedef enum { Cn1, Cn2, Cn3, Cn4, Cnmax } Cstate_number_t;
59typedef struct {
60 Cstate_number_t number;
61 uint32_t hint;
62} Cstate_hint_t;
63
64
65struct pmData {
66 uint8_t pad[93];
67};
68typedef struct pmData pmData_t;
69
70#define pmNapHalt 0x00000010
71#define pmNapC1 0x00000008
72#define pmNapC2 0x00000004
73#define pmNapC3 0x00000002
74#define pmNapC4 0x00000001
75#define pmNapMask 0x000000FF
76
77#define cfgAdr 0xCF8
78#define cfgDat 0xCFC
79#define lpcCfg (0x80000000 | (0 << 16) | (31 << 11) | (0 << 8))
80
81/*
82 * Dispatch table for functions that get installed when the power
83 * management KEXT loads.
84 */
85typedef struct
86{
87 /*
88 * The following are the stepper table interfaces.
89 */
90 void (*pmsCPUMachineInit)(void);
91 void (*pmsCPUInit)(void);
92 void (*pmsCPUSet)(uint32_t sel);
93 void (*pmsCPUConf)(void);
94 void (*pmsCPURun)(uint32_t nstep);
95 uint32_t (*pmsCPUQuery)(void);
96 uint32_t (*pmsCPUPackageQuery)(void);
97 void (*pmsCPUYellowFlag)(void);
98 void (*pmsCPUGreenFlag)(void);
99 kern_return_t (*pmsCPULoadVIDTable)(uint16_t *tablep, int nstates);
100 kern_return_t (*pmsCPUSetPStateLimit)(uint32_t limit);
101
102 /*
103 * The following are the 'C' State interfaces.
104 */
105 void (*cstateInit)(void);
106 void (*cstateMachineIdle)(uint32_t napCtl);
107 kern_return_t (*cstateTableSet)(Cstate_hint_t *tablep, unsigned int nstates);
108 uint32_t (*cstateNapPolicy)(uint32_t forcenap, uint32_t napCtl);
109} pmDispatch_t;
110
111typedef struct {
112 uint32_t PState;
113 uint32_t PLimit;
114 uint16_t VIDTable[MAX_PSTATES];
115 uint32_t VIDTableCount;
116 Cstate_hint_t CStates[Cnmax];
117 uint32_t CStatesCount;
118} pmInitState_t;
119
120typedef struct {
121 void (*Park)(void);
122 void (*Run)(uint32_t nstep);
123 void (*RunLocal)(uint32_t nstep);
124 void (*SetStep)(uint32_t nstep, int dir);
125 void (*NapPolicy)(void);
126 kern_return_t (*Build)(pmsDef *pd, uint32_t pdsize, pmsSetFunc_t *functab, uint32_t platformData, pmsQueryFunc_t queryFunc);
127 pmStats_t *(*Stats)(void);
128 pmsd *(*StepperData)(void);
129 uint64_t *(*HPETAddr)(void);
130 pmInitState_t *InitState;
131 void (*resetPop)(void);
132} pmCallBacks_t;
133
134extern pmDispatch_t *pmDispatch;
135
136extern uint32_t maxBusDelay;
137extern uint32_t C4C2SnoopDelay;
138extern uint32_t forcenap;
139
140void power_management_init(void);
141void machine_nap_policy(void);
142kern_return_t Cstate_table_set(Cstate_hint_t *tablep, unsigned int nstates);
143void machine_idle_cstate(void);
144void pmRegister(pmDispatch_t *cpuFuncs, pmCallBacks_t *callbacks);
145void pmUnRegister(pmDispatch_t *cpuFuncs);
146
147#endif /* ASSEMBLER */
148#endif /* _I386_PMCPU_H_ */
149#endif /* KERNEL_PRIVATE */