2 * Copyright (c) 2006-2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _I386_PMCPU_H_
30 #define _I386_PMCPU_H_
32 #include <i386/cpu_topology.h>
33 #include <i386/rtclock.h>
38 * This value should be changed each time that pmDsipatch_t or pmCallBacks_t
41 #define PM_DISPATCH_VERSION 19
44 * Dispatch table for functions that get installed when the power
45 * management KEXT loads.
47 * pmDispatch_t is the set of functions that the kernel can use to call
48 * into the power management KEXT.
50 * pmCallBacks_t is the set of functions that the power management kext
51 * can call to get at specific kernel functions.
55 int (*pmCPUStateInit
)(void);
56 void (*cstateInit
)(void);
57 uint64_t (*MachineIdle
)(uint64_t maxIdleDuration
);
58 uint64_t (*GetDeadline
)(x86_lcpu_t
*lcpu
);
59 uint64_t (*SetDeadline
)(x86_lcpu_t
*lcpu
, uint64_t);
60 void (*Deadline
)(x86_lcpu_t
*lcpu
);
61 boolean_t (*exitIdle
)(x86_lcpu_t
*lcpu
);
62 void (*markCPURunning
)(x86_lcpu_t
*lcpu
);
63 int (*pmCPUControl
)(uint32_t cmd
, void *datap
);
64 void (*pmCPUHalt
)(void);
65 uint64_t (*getMaxSnoop
)(void);
66 void (*setMaxBusDelay
)(uint64_t time
);
67 uint64_t (*getMaxBusDelay
)(void);
68 void (*setMaxIntDelay
)(uint64_t time
);
69 uint64_t (*getMaxIntDelay
)(void);
70 void (*pmCPUSafeMode
)(x86_lcpu_t
*lcpu
, uint32_t flags
);
71 void (*pmTimerStateSave
)(void);
72 void (*pmTimerStateRestore
)(void);
73 kern_return_t (*exitHalt
)(x86_lcpu_t
*lcpu
);
74 kern_return_t (*exitHaltToOff
)(x86_lcpu_t
*lcpu
);
75 void (*markAllCPUsOff
)(void);
76 void (*pmSetRunCount
)(uint32_t count
);
77 boolean_t (*pmIsCPUUnAvailable
)(x86_lcpu_t
*lcpu
);
78 int (*pmChooseCPU
)(int startCPU
, int endCPU
, int preferredCPU
);
79 int (*pmIPIHandler
)(void *state
);
84 int (*setRTCPop
)(uint64_t time
);
85 void (*resyncDeadlines
)(int cpu
);
86 void (*initComplete
)(void);
87 x86_lcpu_t
*(*GetLCPU
)(int cpu
);
88 x86_core_t
*(*GetCore
)(int cpu
);
89 x86_die_t
*(*GetDie
)(int cpu
);
90 x86_pkg_t
*(*GetPackage
)(int cpu
);
91 x86_lcpu_t
*(*GetMyLCPU
)(void);
92 x86_core_t
*(*GetMyCore
)(void);
93 x86_die_t
*(*GetMyDie
)(void);
94 x86_pkg_t
*(*GetMyPackage
)(void);
95 x86_pkg_t
*(*GetPkgRoot
)(void);
96 void (*LockCPUTopology
)(int lock
);
97 boolean_t (*GetHibernate
)(int cpu
);
98 processor_t (*LCPUtoProcessor
)(int lcpu
);
99 processor_t (*ThreadBind
)(processor_t proc
);
100 uint32_t (*GetSavedRunCount
)(void);
101 void (*pmSendIPI
)(int cpu
);
102 rtc_nanotime_t
*(*GetNanotimeInfo
)(void);
103 x86_topology_parameters_t
*topoParms
;
106 extern pmDispatch_t
*pmDispatch
;
108 void power_management_init(void);
109 void pmKextRegister(uint32_t version
, pmDispatch_t
*cpuFuncs
,
110 pmCallBacks_t
*callbacks
);
111 void pmUnRegister(pmDispatch_t
*cpuFuncs
);
112 void pmCPUStateInit(void);
113 uint64_t pmCPUGetDeadline(struct cpu_data
*cpu
);
114 uint64_t pmCPUSetDeadline(struct cpu_data
*cpu
, uint64_t deadline
);
115 void pmCPUDeadline(struct cpu_data
*cpu
);
116 boolean_t
pmCPUExitIdle(struct cpu_data
*cpu
);
117 void pmCPUMarkRunning(struct cpu_data
*cpu
);
118 void pmMarkAllCPUsOff(void);
119 int pmCPUControl(uint32_t cmd
, void *datap
);
120 void pmCPUHalt(uint32_t reason
);
121 void pmTimerSave(void);
122 void pmTimerRestore(void);
123 kern_return_t
pmCPUExitHalt(int cpu
);
124 kern_return_t
pmCPUExitHaltToOff(int cpu
);
126 #define PM_HALT_NORMAL 0 /* normal halt path */
127 #define PM_HALT_DEBUG 1 /* debug code wants to halt */
128 #define PM_HALT_PANIC 2 /* panic code wants to halt */
129 #define PM_HALT_SLEEP 3 /* sleep code wants to halt */
131 void pmSafeMode(x86_lcpu_t
*lcpu
, uint32_t flags
);
133 #define PM_SAFE_FL_NORMAL 0x00000001 /* put CPU into "normal" power mode */
134 #define PM_SAFE_FL_SAFE 0x00000002 /* put CPU into a "safe" power mode */
135 #define PM_SAFE_FL_PAUSE 0x00000010 /* pause execution on the CPU */
136 #define PM_SAFE_FL_RESUME 0x00000020 /* resume execution on the CPU */
138 extern int pmsafe_debug
;
141 /******************************************************************************
143 * All of the following are deprecated interfaces and no longer used.
145 ******************************************************************************/
148 #endif /* ASSEMBLER */
150 #endif /* _I386_PMCPU_H_ */
151 #endif /* KERNEL_PRIVATE */