2 * Copyright (c) 2004 Apple Computer, 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@
36 #include <libkern/crypto/aes.h>
37 #include <uuid/uuid.h>
38 #include <kern/debug.h>
40 extern int kdb_printf(const char *format
, ...) __printflike(1, 2);
43 #ifndef __IOKIT_IOHIBERNATEPRIVATE_H
44 #define __IOKIT_IOHIBERNATEPRIVATE_H
46 struct IOPolledFileExtent
{
50 typedef struct IOPolledFileExtent IOPolledFileExtent
;
52 struct IOHibernateImageHeader
{
56 uint32_t restore1CodePhysPage
;
58 uint64_t restore1CodeVirt
;
59 uint32_t restore1PageCount
;
60 uint32_t restore1CodeOffset
;
61 uint32_t restore1StackOffset
;
70 uint32_t actualRestore1Sum
;
71 uint32_t actualImage1Sum
;
72 uint32_t actualImage2Sum
;
74 uint32_t actualUncompressedPages
;
75 uint32_t conflictCount
;
79 uint32_t processorFlags
;
81 uint32_t runtimePages
;
82 uint32_t runtimePageCount
;
83 uint64_t runtimeVirtualPages
__attribute__ ((packed
));
85 uint32_t performanceDataStart
;
86 uint32_t performanceDataSize
;
88 uint64_t encryptStart
__attribute__ ((packed
));
89 uint64_t machineSignature
__attribute__ ((packed
));
92 uint32_t previewPageListSize
;
96 uint32_t handoffPages
;
97 uint32_t handoffPageCount
;
99 uint32_t systemTableOffset
;
104 uint32_t compression
;
106 uint8_t bridgeBootSessionUUID
[16];
108 uint32_t reserved
[54]; // make sizeof == 512
109 uint32_t booterTime0
;
110 uint32_t booterTime1
;
111 uint32_t booterTime2
;
113 uint32_t booterStart
;
115 uint32_t connectDisplayTime
;
118 uint32_t trampolineTime
;
120 uint64_t encryptEnd
__attribute__ ((packed
));
121 uint64_t deviceBase
__attribute__ ((packed
));
122 uint32_t deviceBlockSize
;
124 uint32_t fileExtentMapSize
;
125 IOPolledFileExtent fileExtentMap
[2];
127 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
130 kIOHibernateDebugRestoreLogs
= 0x00000001
133 // options & IOHibernateOptions property
135 kIOHibernateOptionSSD
= 0x00000001,
136 kIOHibernateOptionColor
= 0x00000002,
137 kIOHibernateOptionProgress
= 0x00000004,
138 kIOHibernateOptionDarkWake
= 0x00000008,
139 kIOHibernateOptionHWEncrypt
= 0x00000010,
142 struct hibernate_bitmap_t
{
145 uint32_t bitmapwords
;
148 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
150 struct hibernate_page_list_t
{
154 hibernate_bitmap_t bank_bitmap
[0];
156 typedef struct hibernate_page_list_t hibernate_page_list_t
;
160 struct hibernate_cryptwakevars_t
{
161 uint8_t aes_iv
[AES_BLOCK_SIZE
];
163 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
165 struct hibernate_cryptvars_t
{
166 uint8_t aes_iv
[AES_BLOCK_SIZE
];
169 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
171 #endif /* defined(_AES_H) */
174 kIOHibernateHandoffType
= 0x686f0000,
175 kIOHibernateHandoffTypeEnd
= kIOHibernateHandoffType
+ 0,
176 kIOHibernateHandoffTypeGraphicsInfo
= kIOHibernateHandoffType
+ 1,
177 kIOHibernateHandoffTypeCryptVars
= kIOHibernateHandoffType
+ 2,
178 kIOHibernateHandoffTypeMemoryMap
= kIOHibernateHandoffType
+ 3,
179 kIOHibernateHandoffTypeDeviceTree
= kIOHibernateHandoffType
+ 4,
180 kIOHibernateHandoffTypeDeviceProperties
= kIOHibernateHandoffType
+ 5,
181 kIOHibernateHandoffTypeKeyStore
= kIOHibernateHandoffType
+ 6,
182 kIOHibernateHandoffTypeVolumeCryptKey
= kIOHibernateHandoffType
+ 7,
185 struct IOHibernateHandoff
{
190 typedef struct IOHibernateHandoff IOHibernateHandoff
;
193 kIOHibernateProgressCount
= 19,
194 kIOHibernateProgressWidth
= 7,
195 kIOHibernateProgressHeight
= 16,
196 kIOHibernateProgressSpacing
= 3,
197 kIOHibernateProgressOriginY
= 81,
199 kIOHibernateProgressSaveUnderSize
= 2 * 5 + 14 * 2,
201 kIOHibernateProgressLightGray
= 230,
202 kIOHibernateProgressMidGray
= 174,
203 kIOHibernateProgressDarkGray
= 92
207 kIOHibernatePostWriteSleep
= 0,
208 kIOHibernatePostWriteWake
= 1,
209 kIOHibernatePostWriteHalt
= 2,
210 kIOHibernatePostWriteRestart
= 3
214 struct hibernate_graphics_t
{
215 uint64_t physicalAddress
; // Base address of video memory
216 int32_t gfxStatus
; // EFI config restore status
217 uint32_t rowBytes
; // Number of bytes per pixel row
218 uint32_t width
; // Width
219 uint32_t height
; // Height
220 uint32_t depth
; // Pixel Depth
222 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
224 typedef struct hibernate_graphics_t hibernate_graphics_t
;
226 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
227 static const uint8_t gIOHibernateProgressAlpha \
228 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
230 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
231 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
232 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
233 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
234 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
235 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
236 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
237 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
238 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
239 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
240 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
241 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
242 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
243 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
244 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
245 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
248 struct hibernate_preview_t
{
249 uint32_t imageCount
; // Number of images
250 uint32_t width
; // Width
251 uint32_t height
; // Height
252 uint32_t depth
; // Pixel Depth
253 uint32_t lockTime
; // Lock time
254 uint32_t reservedG
[8];// reserved
255 uint32_t reservedK
[8];// reserved
257 typedef struct hibernate_preview_t hibernate_preview_t
;
259 struct hibernate_statistics_t
{
262 uint32_t image1Pages
;
264 uint32_t booterStart
;
266 uint32_t booterDuration
;
267 uint32_t booterConnectDisplayDuration
;
268 uint32_t booterSplashDuration
;
269 uint32_t booterDuration0
;
270 uint32_t booterDuration1
;
271 uint32_t booterDuration2
;
272 uint32_t trampolineDuration
;
273 uint32_t kernelImageReadDuration
;
275 uint32_t graphicsReadyTime
;
276 uint32_t wakeNotificationTime
;
277 uint32_t lockScreenReadyTime
;
278 uint32_t hidReadyTime
;
280 uint32_t wakeCapability
;
283 typedef struct hibernate_statistics_t hibernate_statistics_t
;
285 #define kIOSysctlHibernateStatistics "kern.hibernatestatistics"
286 #define kIOSysctlHibernateGraphicsReady "kern.hibernategraphicsready"
287 #define kIOSysctlHibernateWakeNotify "kern.hibernatewakenotification"
288 #define kIOSysctlHibernateScreenReady "kern.hibernatelockscreenready"
289 #define kIOSysctlHibernateHIDReady "kern.hibernatehidready"
295 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
297 IOReturn
IOHibernateSystemSleep(void);
298 IOReturn
IOHibernateIOKitSleep(void);
299 IOReturn
IOHibernateSystemHasSlept(void);
300 IOReturn
IOHibernateSystemWake(void);
301 IOReturn
IOHibernateSystemPostWake(bool now
);
302 uint32_t IOHibernateWasScreenLocked(void);
303 void IOHibernateSetScreenLocked(uint32_t lockState
);
304 void IOHibernateSetWakeCapabilities(uint32_t capability
);
305 void IOHibernateSystemRestart(void);
307 #endif /* __cplusplus */
310 vm_compressor_do_warmup(void);
313 hibernate_page_list_t
*
314 hibernate_page_list_allocate(boolean_t log
);
317 hibernate_alloc_page_lists(
318 hibernate_page_list_t
** page_list_ret
,
319 hibernate_page_list_t
** page_list_wired_ret
,
320 hibernate_page_list_t
** page_list_pal_ret
);
323 hibernate_setup(IOHibernateImageHeader
* header
,
325 hibernate_page_list_t
* page_list
,
326 hibernate_page_list_t
* page_list_wired
,
327 hibernate_page_list_t
* page_list_pal
);
330 hibernate_teardown(hibernate_page_list_t
* page_list
,
331 hibernate_page_list_t
* page_list_wired
,
332 hibernate_page_list_t
* page_list_pal
);
335 hibernate_pin_swap(boolean_t begin
);
338 hibernate_processor_setup(IOHibernateImageHeader
* header
);
341 hibernate_gobble_pages(uint32_t gobble_count
, uint32_t free_page_time
);
343 hibernate_free_gobble_pages(void);
346 hibernate_vm_lock_queues(void);
348 hibernate_vm_unlock_queues(void);
351 hibernate_vm_lock(void);
353 hibernate_vm_unlock(void);
355 hibernate_vm_lock_end(void);
357 hibernate_vm_locks_are_safe(void);
359 // mark pages not to be saved, based on VM system accounting
361 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
362 hibernate_page_list_t
* page_list_wired
,
363 hibernate_page_list_t
* page_list_pal
,
365 boolean_t discard_all
,
366 uint32_t * pagesOut
);
368 // mark pages to be saved, or pages not to be saved but available
369 // for scratch usage during restore
371 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
372 hibernate_page_list_t
* page_list_wired
,
374 uint32_t * pagesOut
);
376 // mark pages not to be saved and not for scratch usage during restore
378 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
379 hibernate_page_list_t
* page_list_wired
,
380 uint32_t * pagesOut
);
383 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
386 hibernate_should_abort(void);
389 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
390 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
393 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
396 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
399 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
402 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
405 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
408 hibernate_machine_init(void);
411 hibernate_write_image(void);
414 hibernate_machine_entrypoint(uint32_t p1
, uint32_t p2
, uint32_t p3
, uint32_t p4
);
416 hibernate_kernel_entrypoint(uint32_t p1
, uint32_t p2
, uint32_t p3
, uint32_t p4
);
418 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
419 uint32_t system_table_offset
);
422 extern uint32_t gIOHibernateState
;
423 extern uint32_t gIOHibernateMode
;
424 extern uint32_t gIOHibernateDebugFlags
;
425 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
426 extern boolean_t gIOHibernateStandbyDisabled
;
427 extern uint8_t gIOHibernateRestoreStack
[];
428 extern uint8_t gIOHibernateRestoreStackEnd
[];
429 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
431 #define HIBLOGFROMPANIC(fmt, args...) \
432 { if (kernel_debugger_entry_count) { kdb_printf(fmt, ## args); } }
434 #define HIBLOG(fmt, args...) \
435 { if (kernel_debugger_entry_count) { kdb_printf(fmt, ## args); } else { kprintf(fmt, ## args); printf(fmt, ## args); } }
437 #define HIBPRINT(fmt, args...) \
438 { if (kernel_debugger_entry_count) { kdb_printf(fmt, ## args); } else { kprintf(fmt, ## args); } }
443 // gIOHibernateState, kIOHibernateStateKey
445 kIOHibernateStateInactive
= 0,
446 kIOHibernateStateHibernating
= 1,/* writing image */
447 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
450 // gIOHibernateMode, kIOHibernateModeKey
452 kIOHibernateModeOn
= 0x00000001,
453 kIOHibernateModeSleep
= 0x00000002,
454 kIOHibernateModeEncrypt
= 0x00000004,
455 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
456 kIOHibernateModeDiscardCleanActive
= 0x00000010,
457 kIOHibernateModeSwitch
= 0x00000020,
458 kIOHibernateModeRestart
= 0x00000040,
459 kIOHibernateModeSSDInvert
= 0x00000080,
460 kIOHibernateModeFileResize
= 0x00000100,
463 // IOHibernateImageHeader.signature
465 kIOHibernateHeaderSignature
= 0x73696d65,
466 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a,
467 kIOHibernateHeaderOpenSignature
= 0xf1e0be9d,
468 kIOHibernateHeaderDebugDataSignature
= 0xfcddfcdd
471 // kind for hibernate_set_page_state()
473 kIOHibernatePageStateFree
= 0,
474 kIOHibernatePageStateWiredSave
= 1,
475 kIOHibernatePageStateUnwiredSave
= 2
478 #define kIOHibernateModeKey "Hibernate Mode"
479 #define kIOHibernateFileKey "Hibernate File"
480 #define kIOHibernateFileMinSizeKey "Hibernate File Min"
481 #define kIOHibernateFileMaxSizeKey "Hibernate File Max"
482 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
483 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
485 #define kIOHibernateStateKey "IOHibernateState"
486 #define kIOHibernateFeatureKey "Hibernation"
487 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
489 #ifndef kIOHibernatePreviewActiveKey
490 #define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
491 // values for kIOHibernatePreviewActiveKey
493 kIOHibernatePreviewActive
= 0x00000001,
494 kIOHibernatePreviewUpdates
= 0x00000002
498 #define kIOHibernateOptionsKey "IOHibernateOptions"
499 #define kIOHibernateGfxStatusKey "IOHibernateGfxStatus"
501 kIOHibernateGfxStatusUnknown
= ((int32_t) 0xFFFFFFFF)
504 #define kIOHibernateBootImageKey "boot-image"
505 #define kIOHibernateBootImageKeyKey "boot-image-key"
506 #define kIOHibernateBootSignatureKey "boot-signature"
508 #define kIOHibernateMemorySignatureKey "memory-signature"
509 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
510 #define kIOHibernateMachineSignatureKey "machine-signature"
512 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
513 #define kIOHibernateSMCVariablesKey "IOHibernateSMCVariables"
515 #define kIOHibernateBootSwitchVarsKey "boot-switch-vars"
517 #define kIOHibernateBootNoteKey "boot-note"
520 #define kIOHibernateUseKernelInterpreter 0x80000000
523 kIOPreviewImageIndexDesktop
= 0,
524 kIOPreviewImageIndexLockScreen
= 1,
525 kIOPreviewImageCount
= 2
529 kIOScreenLockNoLock
= 1,
530 kIOScreenLockUnlocked
= 2,
531 kIOScreenLockLocked
= 3,
532 kIOScreenLockFileVaultDialog
= 4,
535 #define kIOScreenLockStateKey "IOScreenLockState"
536 #define kIOBooterScreenLockStateKey "IOBooterScreenLockState"
538 #endif /* ! __IOKIT_IOHIBERNATEPRIVATE_H */