1/*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24#ifndef _privatelib_h_
25#define _privatelib_h_
26
27//#define DEBUG_MACH_PORT_ALLOCATIONS 1
28
29
30#include <TargetConditionals.h>
31#include <CoreFoundation/CoreFoundation.h>
32
33#include <SystemConfiguration/SystemConfiguration.h>
34#include <SystemConfiguration/SCValidation.h>
35#include <SystemConfiguration/SCPreferencesPrivate.h>
36#include <SystemConfiguration/SCDynamicStorePrivate.h>
37#include <SystemConfiguration/SCPreferences.h>
38#include <SystemConfiguration/SCDynamicStoreCopySpecificPrivate.h>
39#include <SystemConfiguration/SCDPlugin.h>
40#if TARGET_OS_EMBEDDED
41#define __MACH_PORT_DEBUG(cond, str, port) do {} while(0)
42#endif
43#include <SystemConfiguration/SCPrivate.h>
44
45#include <IOKit/pwr_mgt/IOPM.h>
46#include <IOKit/pwr_mgt/IOPMPrivate.h>
47#include <IOKit/pwr_mgt/IOPMLib.h>
48#include <IOKit/pwr_mgt/IOPMLibPrivate.h>
49#include <IOKit/pwr_mgt/IOPMUPSPrivate.h>
50#include <IOKit/ps/IOPSKeys.h>
51#include <IOKit/ps/IOPowerSources.h>
52#include <IOKit/ps/IOPowerSourcesPrivate.h>
53#include <IOKit/IOKitKeysPrivate.h>
54#include <IOKit/IOCFUnserialize.h>
55#include <IOKit/IOMessage.h>
56#include <IOKit/IOKitLib.h>
57#include <IOKit/IOReturn.h>
58
59#include <dispatch/dispatch.h>
60#include "PMAssertions.h"
61
62#if !TARGET_OS_EMBEDDED
63  #define HAVE_CF_USER_NOTIFICATION     1
64  #define HAVE_SMART_BATTERY            1
65#endif
66
67
68#define kProcNameBufLen                     (2*MAXCOMLEN)
69
70/* System Capability Macros */
71
72#define CAPABILITY_BIT_CHANGED(x, y, b)     ((x ^ y) & b)
73#define CHANGED_CAP_BITS(x, y)              ((x) ^ (y))
74#define BIT_IS_SET(x,b)                     ((x & b)==b)
75#define BIT_IS_NOT_SET(x,b)                 ((x & (b))==0)
76
77/*****************************************************************************/
78
79enum {
80    kLogWakeEvents =                        (1<<0),
81    kLogAssertions =                        (1<<1)
82};
83
84
85__private_extern__ bool PMDebugEnabled(uint32_t which);
86
87
88// Run states (R-state) defined within the ON power state.
89enum {
90    kRStateNormal = 0,
91    kRStateDark,
92    kRStateMaintenance,
93    kRStateCount
94};
95
96// Definitions of PFStatus keys for AppleSmartBattery failures
97enum {
98    kSmartBattPFExternalInput =             (1<<0),
99    kSmartBattPFSafetyOverVoltage =         (1<<1),
100    kSmartBattPFChargeSafeOverTemp =        (1<<2),
101    kSmartBattPFDischargeSafeOverTemp =     (1<<3),
102    kSmartBattPFCellImbalance =             (1<<4),
103    kSmartBattPFChargeFETFailure =          (1<<5),
104    kSmartBattPFDischargeFETFailure =       (1<<6),
105    kSmartBattPFDataFlushFault =            (1<<7),
106    kSmartBattPFPermanentAFECommFailure =   (1<<8),
107    kSmartBattPFPeriodicAFECommFailure =    (1<<9),
108    kSmartBattPFChargeSafetyOverCurrent =   (1<<10),
109    kSmartBattPFDischargeSafetyOverCurrent = (1<<11),
110    kSmartBattPFOpenThermistor =            (1<<12),
111    // reserved 1<<13,
112    // reserved 1<<14,
113    kSmartBattPFFuseBlown =                 (1<<15)
114};
115
116typedef enum {
117   kBatteryPowered = 0,
118   kACPowered
119} PowerSources;
120
121typedef enum {
122    kIsFullWake = 0,
123    kIsDarkWake = 1,
124    kIsDarkToFullWake = 2,
125    kIsS0Sleep = 3,
126    kIsUserWake = 4 // All FullWakes that are not notification wakes
127} WakeTypeEnum;
128
129struct IOPMBattery {
130    io_registry_entry_t     me;
131    io_object_t             msg_port;
132    CFMutableDictionaryRef  properties;
133    uint32_t                     externalConnected:1;
134    uint32_t                     externalChargeCapable:1;
135    uint32_t                     isCharging:1;
136    uint32_t                     isPresent:1;
137    uint32_t                     markedDeclining:1;
138    uint32_t                     isTimeRemainingUnknown:1;
139    uint32_t                     isCritical:1;
140    uint32_t                     isRestricted:1;
141    uint32_t                pfStatus;
142    int                     currentCap;
143    int                     maxCap;
144    int                     designCap;
145    int                     voltage;
146    int                     avgAmperage;
147    int                     instantAmperage;
148    int                     maxerr;
149    int                     cycleCount;
150    int                     location;
151    int                     hwAverageTR;
152    int                     hwInstantTR;
153    int                     swCalculatedTR;
154    int                     swCalculatedPR;
155    int                     invalidWakeSecs;
156    CFStringRef             batterySerialNumber;
157    CFStringRef             health;
158    CFStringRef             failureDetected;
159    CFStringRef             name;
160    CFStringRef             dynamicStoreKey;
161    CFStringRef             chargeStatus;
162    time_t                  lowCapRatioSinceTime;
163    boolean_t               hasLowCapRatio;
164};
165typedef struct IOPMBattery IOPMBattery;
166
167
168
169/* IOPMAggressivenessFactors
170 *
171 * The form of data that the kernel understands.
172 */
173typedef struct {
174    unsigned int        fMinutesToDim;
175    unsigned int        fMinutesToSpin;
176    unsigned int        fMinutesToSleep;
177
178    unsigned int        fWakeOnLAN;
179    unsigned int        fWakeOnRing;
180    unsigned int        fAutomaticRestart;
181    unsigned int        fSleepOnPowerButton;
182    unsigned int        fWakeOnClamshell;
183    unsigned int        fWakeOnACChange;
184    unsigned int        fDisplaySleepUsesDimming;
185    unsigned int        fMobileMotionModule;
186    unsigned int        fGPU;
187    unsigned int        fDeepSleepEnable;
188    unsigned int        fDeepSleepDelay;
189    unsigned int        fAutoPowerOffEnable;
190    unsigned int        fAutoPowerOffDelay;
191} IOPMAggressivenessFactors;
192
193enum {
194    kIOHibernateMinFreeSpace                            = 750*1024ULL*1024ULL  /* 750Mb */
195};
196
197__private_extern__ IOReturn ActivatePMSettings(
198    CFDictionaryRef                 useSettings,
199    bool                            removeUnsupportedSettings);
200
201
202
203#define kPowerManagementBundlePathCString       "/System/Library/CoreServices/powerd.bundle"
204#define kPowerdBundleIdentifier                 CFSTR("com.apple.powerd")
205#define kPowerManagementBundlePathString        CFSTR(kPowerManagementBundlePathCString)
206
207/*
208 * Power Management's ASL keys
209 */
210#define kPMASLDomainKey         	        "com.apple.iokit.domain"
211#define kPMASLSignatureKey         	        "signature"
212#define kPMASLUUIDKey            	        "uuid"
213#define kPMASLUUID2Key            	        "uuid2"
214#define kPMASLDelayKey                      "delay"
215#define kPMASLValueKey            	        "value"
216#define kPMASLTCPKeepAlive                  "tcpkeepaliveplatform"
217#define kPMASLTCPKeepAliveExpired           "tcpkeepaliveexpired"
218
219#define kPMASLValueSupported                "supported"
220#define kPMASLValueExpired                  "expired"
221#define kPMASLValueActive                   "active"
222
223#define kPMASLClaimedEventKey               "claimedEvents"
224
225/*
226 * Power Management Domains
227 */
228#define kPMASLDomainPMStart                 "Start"
229#define kPMASLDomainPMSleep                 "Sleep"
230#define kPMASLDomainPMMaintenance           "MaintenanceWake"
231#define kPMASLDomainPMWake                  "Wake"
232#define kPMASLDomainPMDarkWake              "DarkWake"
233#define kPMASLDomainPMAssertions            "Assertions"
234#define kPMASLDomainPMWakeRequests          "WakeRequests"
235#define kPMASLDomainHibernateStatistics     "HibernateStats"
236#define kPMASLDomainFilteredFailure         "FilteredFailure"
237#define kPMASLDomainAppNotify               "Notification"
238#define kPMASLDomainSWFailure               "Failure"
239
240#define kPMASLDomainDWTEmergency            "ThermalEvent"
241#define kPMASLDomainSleepRevert             "SleepAborted"
242
243#define kPMASLDomainBattery                 "BatteryHealth"
244
245#define kPMASLDomainSummaryPrefix           "Summary."
246    #define kPMASLDomainSummaryActive       "Summary.Active"
247    #define kPMASLDomainSummary             "Summary.Historical"
248
249#define kPMASLDomainAppResponse             "ApplicationResponse"
250    #define kPMASLDomainAppResponseReceived     "Response.Received"
251    #define kPMASLDomainAppResponseCancel       "Response.Cancelled"
252    #define kPMASLDomainAppResponseSlow         "Response.SlowResponse"
253    #define kPMASLDomainAppResponseTimedOut     "Response.Timedout"
254
255#define kPMASLDomainKernelClientStats       "KernelClientStats"
256#define kPMASLDomainPMClientStats           "PMClientStats"
257
258    /*
259     * Below three definitions are prefixes. Actual ASL keys will be
260     * AppName0, DelayTypeApp0, DelayFromApp0
261     * AppName1, DelayTypeApp1, DelayFromApp1  etc...
262     */
263#define kPMASLResponseAppNamePrefix         "AppName"
264#define kPMASLResponseRespTypePrefix        "DelayTypeApp"
265#define kPMASLResponseDelayPrefix           "DelayFromApp"
266#define kPMASLResponsePSCapsPrefix          "PowerStateCaps"
267#define kPMASLResponseMessagePrefix         "Message"
268
269#define kPMASLResponseSystemTransition      "SystemTransition"
270
271
272#define kPMASLDomainClientWakeRequests      "ClientWakeRequests"
273
274#define KPMASLWakeReqAppNamePrefix          "WakeAppName"
275#define kPMASLWakeReqTimeDeltaPrefix        "WakeTimeDelta"
276#define kPMASLWakeReqTypePrefix             "WakeType"
277#define kPMASLWakeReqClientInfoPrefix       "WakeClientInfo"
278#define kPMASLWakeReqChosenIdx              "WakeRequestChosen"
279
280
281/*
282 * Signatures
283 */
284#define kPMASLSigSuccess                    "success"
285#define kPMASLSigEarlyFailure               "Early Failure"
286#define kPMASLSigAppsFailure                "Apps Failure"
287#define kPMASLSigPriorityFailure            "Priority Failure"
288#define kPMASLSigInterestFailure            "Interest Failure"
289#define kPMASLSigCapabilityFailure          "Capability Failure"
290#define kPMASLSigNotificationFailure        "Notification Failure"
291#define kPMASLSigDriversFailure             "Drivers Failure"
292#define kPMASLSigHibernateFailure           "Hibernate Failure"
293#define kPMASLSigPlatformActionFailure      "Platform Action Failure"
294#define kPMASLSigPlatformDriverFailure      "Platform Driver Failure"
295#define kPMASLSigCpusFailure                "Cpus Failure"
296#define kPMASLSigPlatformFailure            "Platform Failure"
297#define kPMASLSigLoginwindowAuthFailure     "Loginwindow Authorization Failure"
298#define kPMASLSigResponseTimedOut           "Timed Out"
299#define kPMASLSigResponseCancel             "Cancelled"
300#define kPMASLSigResponseSlow               "Slow Response"
301
302/*
303 * SleepService Domains
304 */
305#define kPMASLDomainSleepServiceStarted     "com.apple.sleepservices.sessionStarted"
306#define kPMASLDomainSleepServiceTerminated  "com.apple.sleepservices.sessionTerminated"
307#define kPMASLDomainSleepServiceCapApp      "com.apple.sleepservices.clientCapTimeout"
308#define kPMASLPrefixSleepServices           "com.apple.sleepservices."
309#define kPMASLPrefixPM                      "com.apple.powermanagement."
310
311/*
312 * SleepService Signatures
313 */
314#define kPMASLSigSleepServiceExitClean      "com.apple.sleepserviced.ExitCleanAssertions"
315#define kPMASLSigSleepServiceTimedOut       "com.apple.sleepserviced.ExitTimeOutAssertions"
316#define kPMASLSigSleepServiceElevatedFull   "com.apple.sleepserviced.ElevatedToFullWake"
317#define kPMASLSigSleepServiceElevatedDark   "com.apple.sleepserviced.ElevatedToDarkWake"
318
319#define kPMFacility                             "com.apple.iokit.power"
320#define kPMASLActionKey                         "Action"
321#define kPMASLPIDKey                            "Process"
322#define kPMASLAssertionNameKey                  "AssertName"
323#define kPMASLAssertionActionCreate             "Created"
324#define kPMASLAssertionActionRetain             "Retain"
325#define kPMASLAssertionActionRelease            "Released"
326#define kPMASLAssertionActionClientDeath        "ClientDied"
327#define kPMASLAssertionActionTimeOut            "TimedOut"
328#define kPMASLAssertionActionSummary            "Summary"
329#define kPMASLAssertionActionTurnOff            "TurnedOff"
330#define kPMASLAssertionActionTurnOn             "TurnedOn"
331#define kPMASlAssertionActionCapTimeOut         "CapExpired"
332/***************************************************************
333 * FDR
334 * Flight Data Recorder SPI calls
335 *
336 ***************************************************************/
337
338enum {
339    kFDRInit                    = (1 << 0),
340    kFDRACChanged               = (1 << 1),
341    kFDRSleepEvent              = (1 << 2),
342    kFDRUserWakeEvent           = (1 << 3),
343    kFDRDarkWakeEvent           = (1 << 4),
344    kFDRBattEventPeriodic       = (1 << 5),
345    kFDRBattEventAsync          = (1 << 6)
346};
347
348/* recordFDREvent
349 * powerd uses this method to publish battery and system power state info
350 * to FDR.
351 */
352void recordFDREvent(int eventType, bool checkStandbyStatus, IOPMBattery **batteries);
353
354/***************************************************************
355 * MT2
356 * MessageTracer SPI calls
357 *
358 ***************************************************************/
359
360/* This is a bitfield. It describes system state at the time of a wakeup. */
361enum {
362    kWakeStateDark              = (1 << 0),     /* 0 == FullWake. 1 == DarkWake */
363    kWakeStateBattery           = (1 << 1),     /* 0 == AC. 1 == Battery */
364    kWakeStateLidClosed         = (1 << 2)      /* 0 == LidOpen. 1 == LidCLosed */
365};
366#define kWakeStateFull          0
367#define kWakeStateAC            0
368#define kWakeStateLidOpen       0
369#define kWakeStateCount         (8)
370
371/* This is a bitfield. It describes the themal state at the time of a "thermal event". */
372enum {
373    kThermalStateFansOn         = (1 << 0),     /* 0 == Fans off. 1 == Fans On */
374    kThermalStateSleepRequest   = (1 << 1)      /* 0 == No Sleep Request. 1 == Received sleep request. */
375};
376#define kThermalStateFansOff    0
377#define kThermalStateNoRequest  0
378#define kThermalStateCount      (4)
379
380
381/* initializeMT2Aggregator
382 * Call once at powerd launch.
383 * After calling this, powerd should let internal MT2Aggregator code decide
384 * when to publish reports, at what intervals to publish reports.
385 */
386void initializeMT2Aggregator(void);
387
388/* mt2DarkWakeEnded
389 * powerd must call mt2DarkWakeEnded to stop recording assertions when we exit DarkWake
390 */
391void mt2DarkWakeEnded(void);
392
393/* mt2EvaluateSystemSupport
394 * powerd should call this to report changes to Energy Saver settings.
395 * Populates MT2Aggregator fields SMCSupport, PlatformSupport, checkedForAC, checkedForBatt
396 */
397void mt2EvaluateSystemSupport(void);
398
399/* mt2RecordWakeEvent
400 * powerd should call this once upon wakeup from S3/S4 to S0.
401 * mt2RecordWakeEvent will populate the battery & lid bits; caller must only supply wake type.
402 * Arguments: kWakeStateFull, or kWakeStateDark
403 * Records a wake events as DarkWake/FullWake, and records AC/Batt, LidOpen/LidClosed.
404 */
405void mt2RecordWakeEvent(uint32_t description);
406
407/* mt2RecordThermalEvent
408 * powerd should call at most once per DarkWake. These should be rare conditions, and will not occur in all situations.
409 * Records a thermal event: Fanson/fansoff, sleeprequest/none.
410 */
411void mt2RecordThermalEvent(uint32_t description);
412
413/* mt2RecordAsserctionEvent
414 * powerd should call to indicate that a process "whichApp" has "action'd" assertion "AssertionType".
415 * @arg assertionType is one of PMAssertion.h: kPushServiceTaskIndex, kBackgroundTaskIndex
416 * @arg action is one of PMAssertions.h: kOpRaise, kOpGlobalTimeout
417 * @arg theAssertion is a valid assertion datastructure (we map this back to process name, then process index)
418 * OK to call many times during a DarkWake, upon unique (assertionType, action, whichApp) tuples.
419 */
420void mt2RecordAssertionEvent(assertionOps action, assertion_t *theAssertion);
421
422/*
423 * mt2RecordAppTimeouts
424 * powerd should call to report power notification acknowledgement timeouts.
425 * @arg sleepReason indicates the type of sleep, system is entering into when ack timeout occurred.
426 * @arg procName indicates the name of process which didn't respond to notification.
427 */
428void mt2RecordAppTimeouts(CFStringRef sleepReason, CFStringRef procName);
429
430/*
431 * mt2RecordWakeReason
432 * powerd should call to report wake reason claimed by the driver
433 * @arg wakeType     Wake Type
434 * @arg claimedWake  Wake reason string as provided by the driver
435 */
436void mt2RecordWakeReason(CFStringRef wakeType, CFStringRef claimedWake);
437
438/* mt2PublishReports
439 * Debug routines. Should only be used for debugging to influence the mt2 publishing cycle.
440 * Don't call these as part of a normal sleep/wake/darkwake cycle - these are special case calls.
441 */
442void mt2PublishReports(void);
443
444/* mt2PublishSleepFailure
445 * powerd should call to report a sleep failure.
446 * @arg failType is the category of the failure
447 * @arg pci_string is a list of pci devices
448 */
449void mt2PublishSleepFailure(const char *failType, const char *pci_string);
450
451/* mt2PublishWakeFailure
452 * powerd should call to report a wake failure.
453 * @arg failType is the category of the failure
454 * @arg pci_string is a list of pci devices
455 */
456void mt2PublishWakeFailure(const char *failType, const char *pci_string);
457
458// kIOPMAssertionProcessNameKey - key to IOPMAssertion dictionary
459#ifndef kIOPMAssertionProcessNameKey
460#define kIOPMAssertionProcessNameKey            CFSTR("Process Name")
461#endif
462
463// Key 'kIOPMAssertionTypeKey' may show old aliases.
464// 'kIOPMAssertionTrueTypeKey' current Official name of the type for logging
465#ifndef kIOPMAssertionTrueTypeKey
466#define kIOPMAssertionTrueTypeKey               CFSTR("AssertionTrueType")
467#endif
468
469#ifndef kIOPMRootDomainWakeReasonKey
470// As defined in Kernel.framework/IOKit/pwr_mgt/RootDomain.h
471#define kIOPMRootDomainWakeReasonKey            "Wake Reason"
472#endif
473
474#ifndef kIOPMRootDomainWakeTypeKey
475// As defined in Kernel.framework/IOKit/pwr_mgt/RootDomain.h
476#define kIOPMRootDomainWakeTypeKey              "Wake Type"
477#endif
478
479
480
481#define kAssertionHumanReadableReasonTTY        CFSTR("A remote user is connected. That prevents system sleep.")
482
483__private_extern__ void                 logASLMessagePMStart(void);
484__private_extern__ void                 logASLMessageSleep(const char *sig, const char *uuidStr,
485                                                           const char *failureStr, int sleep_type);
486
487__private_extern__ void                 logASLMessageWake(const char *sig, const char *uuidStr,
488                                                        const char *failureStr,
489                                                        IOPMCapabilityBits in_capabilities, WakeTypeEnum dark_wake);
490
491__private_extern__ void                 logASLAppWakeReason(const char * ident, const char * reason);
492
493
494__private_extern__ void                 logASLMessageHibernateStatistics(void);
495
496__private_extern__ void                 logASLMessagePMConnectionResponse(CFStringRef logSourceString, CFStringRef appNameString,
497                                                         CFStringRef responseTypeString, CFNumberRef responseTime,
498                                                         int notificationBits);
499
500__private_extern__ void                 logASLPMConnectionNotify(CFStringRef appNameString, int notificationBits);
501__private_extern__ void                 logASLDisplayStateChange();
502__private_extern__ void                 logASLMessageAppStats(CFArrayRef appStats, char *domain);
503
504__private_extern__ void                 logASLMessagePMConnectionScheduledWakeEvents(CFStringRef requestedMaintenancesString);
505
506__private_extern__ void                 logASLMessageExecutedWakeupEvent(CFStringRef requestedMaintenancesString);
507
508#if !TARGET_OS_EMBEDDED
509__private_extern__ void                 logASLMessageIgnoredDWTEmergency(void);
510#endif
511
512__private_extern__ void                 logASLMessageSleepCanceledAtLastCall(void);
513
514__private_extern__ void                 logASLBatteryHealthChanged(const char *health,
515                                                                   const char *oldhealth,
516                                                                   const char *reason);
517__private_extern__ void                 logASLLowBatteryWarning(IOPSLowBatteryWarningLevel level,
518                                                   int time, int ccap);
519
520#define kAppResponseLogSourceKernel             CFSTR("Kernel")
521#define kAppResponseLogSourcePMConnection       CFSTR("PMConnection")
522#define kAppResponseLogSourceSleepServiceCap    CFSTR("SleepService")
523
524/*
525 * If a PMConnection client doesn't respond to a sleep/wake notification in longer
526 * than kAppResponseLogThresholdMS, log it to pmset -g log.
527 */
528#define kAppResponseLogThresholdMS              250
529
530// Dictionary lives as a setting in com.apple.PowerManagement.plist
531// The keys to this dictionary are for Date & for UUID
532#define kPMSettingsCachedUUIDKey                "LastSleepUUID"
533#define kPMSettingsDictionaryDateKey            "Date"
534#define kPMSettingsDictionaryUUIDKey            "UUID"
535
536__private_extern__ aslmsg               new_msg_pmset_log(void);
537
538/* PM Kernel shares times with user space in a packed 64-bit integer.
539 * Seconds since 1970 in the lower 32, microseconds in the upper 32.
540 */
541__private_extern__ CFAbsoluteTime       _CFAbsoluteTimeFromPMEventTimeStamp(uint64_t kernelPackedTime);
542
543__private_extern__ IOPMBattery          **_batteries(void);
544__private_extern__ IOPMBattery          *_newBatteryFound(io_registry_entry_t);
545__private_extern__ void                 _batteryChanged(IOPMBattery *);
546__private_extern__ bool                 _batteryHas(IOPMBattery *, CFStringRef);
547__private_extern__ int                  _batteryCount(void);
548__private_extern__ void                 _removeBattery(io_registry_entry_t);
549__private_extern__ IOReturn             _getACAdapterInfo(uint64_t *acBits);
550__private_extern__ PowerSources         _getPowerSource(void);
551__private_extern__ IOReturn _getLowCapRatioTime(CFStringRef batterySerialNumber,
552                                                boolean_t *hasLowCapRatio,
553                                                time_t *since);
554__private_extern__ IOReturn _setLowCapRatioTime(CFStringRef batterySerialNumber,
555                                                boolean_t hasLowCapRatio,
556                                                time_t since);
557
558#if !TARGET_OS_EMBEDDED
559__private_extern__ CFUserNotificationRef _copyUPSWarning(void);
560__private_extern__ IOReturn              _smcWakeTimerPrimer(void);
561__private_extern__ IOReturn              _smcWakeTimerGetResults(uint16_t *mSec);
562#endif
563__private_extern__ bool                  smcSilentRunningSupport(void);
564
565__private_extern__ void                 _askNicelyThenShutdownSystem(void);
566__private_extern__ void                 _askNicelyThenRestartSystem(void);
567__private_extern__ void                 _askNicelyThenSleepSystem(void);
568
569
570__private_extern__ SCDynamicStoreRef    _getSharedPMDynamicStore(void);
571
572
573// getUUIDString copies the UUID string into the provided buffer
574// returns true on success; or false if the copy failed, or the UUID does not exist
575__private_extern__ bool                 _getUUIDString(char *buf, int buflen);
576__private_extern__ CFStringRef          _updateSleepReason(void);
577__private_extern__ CFStringRef          _getSleepReason();
578__private_extern__ void                 _resetWakeReason( );
579__private_extern__ void                 _updateWakeReason(CFStringRef *wakeReason, CFStringRef *wakeType);
580__private_extern__ void                 getPlatformWakeReason(CFStringRef *wakeReason, CFStringRef *wakeType);
581
582__private_extern__ io_registry_entry_t  getRootDomain(void);
583__private_extern__ IOReturn             _setRootDomainProperty(CFStringRef key, CFTypeRef val);
584__private_extern__ CFTypeRef            _copyRootDomainProperty(CFStringRef key);
585
586__private_extern__ bool                 platformPluginLoaded(void);
587
588__private_extern__ int                  callerIsRoot(int uid);
589__private_extern__ int                  callerIsAdmin(int uid, int gid);
590__private_extern__ int                  callerIsConsole(int uid, int gid);
591__private_extern__ void                 _PortInvalidatedCallout(CFMachPortRef port, void *info);
592
593__private_extern__ const char           *stringForLWCode(uint8_t code);
594__private_extern__ const char           *stringForPMCode(uint8_t code);
595
596__private_extern__ CFTimeInterval       _getHIDIdleTime(void);
597
598__private_extern__ CFRunLoopRef         _getPMRunLoop(void);
599__private_extern__ dispatch_queue_t     _getPMDispatchQueue(void);
600
601__private_extern__ bool getAggressivenessValue(CFDictionaryRef     dict,
602                                               CFStringRef         key,
603                                               CFNumberType        type,
604                                               uint32_t           *ret);
605
606__private_extern__ bool auditTokenHasEntitlement(
607                                                 audit_token_t token,
608                                                 CFStringRef entitlement);
609
610__private_extern__ CFCalendarRef        _gregorian(void);
611
612__private_extern__ void                 _oneOffHacksSetup(void);
613
614__private_extern__ IOReturn getNvramArgInt(char *key, int *value);
615
616__private_extern__ uint64_t             getMonotonicTime( );
617#endif
618
619