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
51 typedef struct IOPolledFileExtent IOPolledFileExtent
;
53 struct IOHibernateImageHeader
58 uint32_t restore1CodePhysPage
;
60 uint64_t restore1CodeVirt
;
61 uint32_t restore1PageCount
;
62 uint32_t restore1CodeOffset
;
63 uint32_t restore1StackOffset
;
72 uint32_t actualRestore1Sum
;
73 uint32_t actualImage1Sum
;
74 uint32_t actualImage2Sum
;
76 uint32_t actualUncompressedPages
;
77 uint32_t conflictCount
;
81 uint32_t processorFlags
;
83 uint32_t runtimePages
;
84 uint32_t runtimePageCount
;
85 uint64_t runtimeVirtualPages
__attribute__ ((packed
));
87 uint32_t performanceDataStart
;
88 uint32_t performanceDataSize
;
90 uint64_t encryptStart
__attribute__ ((packed
));
91 uint64_t machineSignature
__attribute__ ((packed
));
94 uint32_t previewPageListSize
;
98 uint32_t handoffPages
;
99 uint32_t handoffPageCount
;
101 uint32_t systemTableOffset
;
106 uint32_t compression
;
108 uint32_t reserved
[58]; // 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
;
131 kIOHibernateDebugRestoreLogs
= 0x00000001
134 // options & IOHibernateOptions property
137 kIOHibernateOptionSSD
= 0x00000001,
138 kIOHibernateOptionColor
= 0x00000002,
139 kIOHibernateOptionProgress
= 0x00000004,
140 kIOHibernateOptionDarkWake
= 0x00000008,
143 struct hibernate_bitmap_t
147 uint32_t bitmapwords
;
150 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
152 struct hibernate_page_list_t
157 hibernate_bitmap_t bank_bitmap
[0];
159 typedef struct hibernate_page_list_t hibernate_page_list_t
;
163 struct hibernate_cryptwakevars_t
165 uint8_t aes_iv
[AES_BLOCK_SIZE
];
167 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
169 struct hibernate_cryptvars_t
171 uint8_t aes_iv
[AES_BLOCK_SIZE
];
174 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
176 #endif /* defined(_AES_H) */
180 kIOHibernateHandoffType
= 0x686f0000,
181 kIOHibernateHandoffTypeEnd
= kIOHibernateHandoffType
+ 0,
182 kIOHibernateHandoffTypeGraphicsInfo
= kIOHibernateHandoffType
+ 1,
183 kIOHibernateHandoffTypeCryptVars
= kIOHibernateHandoffType
+ 2,
184 kIOHibernateHandoffTypeMemoryMap
= kIOHibernateHandoffType
+ 3,
185 kIOHibernateHandoffTypeDeviceTree
= kIOHibernateHandoffType
+ 4,
186 kIOHibernateHandoffTypeDeviceProperties
= kIOHibernateHandoffType
+ 5,
187 kIOHibernateHandoffTypeKeyStore
= kIOHibernateHandoffType
+ 6,
190 struct IOHibernateHandoff
196 typedef struct IOHibernateHandoff IOHibernateHandoff
;
200 kIOHibernateProgressCount
= 19,
201 kIOHibernateProgressWidth
= 7,
202 kIOHibernateProgressHeight
= 16,
203 kIOHibernateProgressSpacing
= 3,
204 kIOHibernateProgressOriginY
= 81,
206 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
208 kIOHibernateProgressLightGray
= 230,
209 kIOHibernateProgressMidGray
= 174,
210 kIOHibernateProgressDarkGray
= 92
215 kIOHibernatePostWriteSleep
= 0,
216 kIOHibernatePostWriteWake
= 1,
217 kIOHibernatePostWriteHalt
= 2,
218 kIOHibernatePostWriteRestart
= 3
222 struct hibernate_graphics_t
224 uint64_t physicalAddress
; // Base address of video memory
225 int32_t gfxStatus
; // EFI config restore status
226 uint32_t rowBytes
; // Number of bytes per pixel row
227 uint32_t width
; // Width
228 uint32_t height
; // Height
229 uint32_t depth
; // Pixel Depth
231 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
233 typedef struct hibernate_graphics_t hibernate_graphics_t
;
235 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
236 static const uint8_t gIOHibernateProgressAlpha \
237 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
239 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
240 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
241 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
242 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
243 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
244 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
245 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
246 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
247 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
248 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
249 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
250 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
251 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
252 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
253 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
254 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
257 struct hibernate_preview_t
259 uint32_t imageCount
; // Number of images
260 uint32_t width
; // Width
261 uint32_t height
; // Height
262 uint32_t depth
; // Pixel Depth
263 uint32_t lockTime
; // Lock time
264 uint32_t reservedG
[8]; // reserved
265 uint32_t reservedK
[8]; // reserved
267 typedef struct hibernate_preview_t hibernate_preview_t
;
269 struct hibernate_statistics_t
273 uint32_t image1Pages
;
275 uint32_t booterStart
;
277 uint32_t booterDuration
;
278 uint32_t booterConnectDisplayDuration
;
279 uint32_t booterSplashDuration
;
280 uint32_t booterDuration0
;
281 uint32_t booterDuration1
;
282 uint32_t booterDuration2
;
283 uint32_t trampolineDuration
;
284 uint32_t kernelImageReadDuration
;
286 uint32_t graphicsReadyTime
;
287 uint32_t wakeNotificationTime
;
288 uint32_t lockScreenReadyTime
;
289 uint32_t hidReadyTime
;
291 uint32_t wakeCapability
;
294 typedef struct hibernate_statistics_t hibernate_statistics_t
;
296 #define kIOSysctlHibernateStatistics "kern.hibernatestatistics"
297 #define kIOSysctlHibernateGraphicsReady "kern.hibernategraphicsready"
298 #define kIOSysctlHibernateWakeNotify "kern.hibernatewakenotification"
299 #define kIOSysctlHibernateScreenReady "kern.hibernatelockscreenready"
300 #define kIOSysctlHibernateHIDReady "kern.hibernatehidready"
306 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
308 IOReturn
IOHibernateSystemSleep(void);
309 void IOOpenDebugDataFile(const char *fname
, uint64_t size
);
310 void IOCloseDebugDataFile();
311 IOReturn
IOHibernateIOKitSleep(void);
312 IOReturn
IOHibernateSystemHasSlept(void);
313 IOReturn
IOHibernateSystemWake(void);
314 IOReturn
IOHibernateSystemPostWake(bool now
);
315 uint32_t IOHibernateWasScreenLocked(void);
316 void IOHibernateSetScreenLocked(uint32_t lockState
);
317 void IOHibernateSetWakeCapabilities(uint32_t capability
);
318 void IOHibernateSystemRestart(void);
320 #endif /* __cplusplus */
323 vm_compressor_do_warmup(void);
326 hibernate_page_list_t
*
327 hibernate_page_list_allocate(boolean_t log
);
330 hibernate_alloc_page_lists(
331 hibernate_page_list_t
** page_list_ret
,
332 hibernate_page_list_t
** page_list_wired_ret
,
333 hibernate_page_list_t
** page_list_pal_ret
);
336 hibernate_setup(IOHibernateImageHeader
* header
,
338 hibernate_page_list_t
* page_list
,
339 hibernate_page_list_t
* page_list_wired
,
340 hibernate_page_list_t
* page_list_pal
);
343 hibernate_teardown(hibernate_page_list_t
* page_list
,
344 hibernate_page_list_t
* page_list_wired
,
345 hibernate_page_list_t
* page_list_pal
);
348 hibernate_pin_swap(boolean_t begin
);
351 hibernate_processor_setup(IOHibernateImageHeader
* header
);
354 hibernate_gobble_pages(uint32_t gobble_count
, uint32_t free_page_time
);
356 hibernate_free_gobble_pages(void);
359 hibernate_vm_lock_queues(void);
361 hibernate_vm_unlock_queues(void);
364 hibernate_vm_lock(void);
366 hibernate_vm_unlock(void);
368 hibernate_vm_lock_end(void);
370 hibernate_vm_locks_are_safe(void);
372 // mark pages not to be saved, based on VM system accounting
374 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
375 hibernate_page_list_t
* page_list_wired
,
376 hibernate_page_list_t
* page_list_pal
,
378 boolean_t discard_all
,
379 uint32_t * pagesOut
);
381 // mark pages to be saved, or pages not to be saved but available
382 // for scratch usage during restore
384 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
385 hibernate_page_list_t
* page_list_wired
,
387 uint32_t * pagesOut
);
389 // mark pages not to be saved and not for scratch usage during restore
391 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
392 hibernate_page_list_t
* page_list_wired
,
393 uint32_t * pagesOut
);
396 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
399 hibernate_should_abort(void);
402 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
403 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
406 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
409 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
412 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
415 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
418 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
421 hibernate_machine_init(void);
424 hibernate_write_image(void);
427 hibernate_machine_entrypoint(uint32_t p1
, uint32_t p2
, uint32_t p3
, uint32_t p4
);
429 hibernate_kernel_entrypoint(uint32_t p1
, uint32_t p2
, uint32_t p3
, uint32_t p4
);
431 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
432 uint32_t system_table_offset
);
435 extern uint32_t gIOHibernateState
;
436 extern uint32_t gIOHibernateMode
;
437 extern uint32_t gIOHibernateDebugFlags
;
438 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
439 extern boolean_t gIOHibernateStandbyDisabled
;
440 extern uint8_t gIOHibernateRestoreStack
[];
441 extern uint8_t gIOHibernateRestoreStackEnd
[];
442 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
444 #define HIBLOGFROMPANIC(fmt, args...) \
445 { if (kernel_debugger_entry_count) { kdb_printf(fmt, ## args); } }
447 #define HIBLOG(fmt, args...) \
448 { if (kernel_debugger_entry_count) { kdb_printf(fmt, ## args); } else { kprintf(fmt, ## args); printf(fmt, ## args); } }
450 #define HIBPRINT(fmt, args...) \
451 { if (kernel_debugger_entry_count) { kdb_printf(fmt, ## args); } else { kprintf(fmt, ## args); } }
456 // gIOHibernateState, kIOHibernateStateKey
459 kIOHibernateStateInactive
= 0,
460 kIOHibernateStateHibernating
= 1, /* writing image */
461 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
464 // gIOHibernateMode, kIOHibernateModeKey
467 kIOHibernateModeOn
= 0x00000001,
468 kIOHibernateModeSleep
= 0x00000002,
469 kIOHibernateModeEncrypt
= 0x00000004,
470 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
471 kIOHibernateModeDiscardCleanActive
= 0x00000010,
472 kIOHibernateModeSwitch
= 0x00000020,
473 kIOHibernateModeRestart
= 0x00000040,
474 kIOHibernateModeSSDInvert
= 0x00000080,
475 kIOHibernateModeFileResize
= 0x00000100,
478 // IOHibernateImageHeader.signature
481 kIOHibernateHeaderSignature
= 0x73696d65,
482 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a,
483 kIOHibernateHeaderOpenSignature
= 0xf1e0be9d,
484 kIOHibernateHeaderDebugDataSignature
= 0xfcddfcdd
487 // kind for hibernate_set_page_state()
490 kIOHibernatePageStateFree
= 0,
491 kIOHibernatePageStateWiredSave
= 1,
492 kIOHibernatePageStateUnwiredSave
= 2
495 #define kIOHibernateModeKey "Hibernate Mode"
496 #define kIOHibernateFileKey "Hibernate File"
497 #define kIOHibernateFileMinSizeKey "Hibernate File Min"
498 #define kIOHibernateFileMaxSizeKey "Hibernate File Max"
499 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
500 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
502 #define kIOHibernateStateKey "IOHibernateState"
503 #define kIOHibernateFeatureKey "Hibernation"
504 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
506 #ifndef kIOHibernatePreviewActiveKey
507 #define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
508 // values for kIOHibernatePreviewActiveKey
510 kIOHibernatePreviewActive
= 0x00000001,
511 kIOHibernatePreviewUpdates
= 0x00000002
515 #define kIOHibernateOptionsKey "IOHibernateOptions"
516 #define kIOHibernateGfxStatusKey "IOHibernateGfxStatus"
518 kIOHibernateGfxStatusUnknown
= ((int32_t) 0xFFFFFFFF)
521 #define kIOHibernateBootImageKey "boot-image"
522 #define kIOHibernateBootImageKeyKey "boot-image-key"
523 #define kIOHibernateBootSignatureKey "boot-signature"
525 #define kIOHibernateMemorySignatureKey "memory-signature"
526 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
527 #define kIOHibernateMachineSignatureKey "machine-signature"
529 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
530 #define kIOHibernateSMCVariablesKey "IOHibernateSMCVariables"
532 #define kIOHibernateBootSwitchVarsKey "boot-switch-vars"
534 #define kIOHibernateBootNoteKey "boot-note"
537 #define kIOHibernateUseKernelInterpreter 0x80000000
541 kIOPreviewImageIndexDesktop
= 0,
542 kIOPreviewImageIndexLockScreen
= 1,
543 kIOPreviewImageCount
= 2
548 kIOScreenLockNoLock
= 1,
549 kIOScreenLockUnlocked
= 2,
550 kIOScreenLockLocked
= 3,
551 kIOScreenLockFileVaultDialog
= 4,
554 #define kIOScreenLockStateKey "IOScreenLockState"
555 #define kIOBooterScreenLockStateKey "IOBooterScreenLockState"
557 #endif /* ! __IOKIT_IOHIBERNATEPRIVATE_H */