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>
40 #ifndef __IOKIT_IOHIBERNATEPRIVATE_H
41 #define __IOKIT_IOHIBERNATEPRIVATE_H
43 struct IOPolledFileExtent
48 typedef struct IOPolledFileExtent IOPolledFileExtent
;
50 struct IOHibernateImageHeader
55 uint32_t restore1CodePhysPage
;
57 uint64_t restore1CodeVirt
;
58 uint32_t restore1PageCount
;
59 uint32_t restore1CodeOffset
;
60 uint32_t restore1StackOffset
;
69 uint32_t actualRestore1Sum
;
70 uint32_t actualImage1Sum
;
71 uint32_t actualImage2Sum
;
73 uint32_t actualUncompressedPages
;
74 uint32_t conflictCount
;
78 uint32_t processorFlags
;
80 uint32_t runtimePages
;
81 uint32_t runtimePageCount
;
82 uint64_t runtimeVirtualPages
__attribute__ ((packed
));
84 uint32_t performanceDataStart
;
85 uint32_t performanceDataSize
;
87 uint64_t encryptStart
__attribute__ ((packed
));
88 uint64_t machineSignature
__attribute__ ((packed
));
91 uint32_t previewPageListSize
;
95 uint32_t handoffPages
;
96 uint32_t handoffPageCount
;
98 uint32_t systemTableOffset
;
103 uint32_t compression
;
105 uint32_t reserved
[58]; // make sizeof == 512
106 uint32_t booterTime0
;
107 uint32_t booterTime1
;
108 uint32_t booterTime2
;
110 uint32_t booterStart
;
112 uint32_t connectDisplayTime
;
115 uint32_t trampolineTime
;
117 uint64_t encryptEnd
__attribute__ ((packed
));
118 uint64_t deviceBase
__attribute__ ((packed
));
119 uint32_t deviceBlockSize
;
121 uint32_t fileExtentMapSize
;
122 IOPolledFileExtent fileExtentMap
[2];
124 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
128 kIOHibernateDebugRestoreLogs
= 0x00000001
131 // options & IOHibernateOptions property
134 kIOHibernateOptionSSD
= 0x00000001,
135 kIOHibernateOptionColor
= 0x00000002,
136 kIOHibernateOptionProgress
= 0x00000004,
137 kIOHibernateOptionDarkWake
= 0x00000008,
140 struct hibernate_bitmap_t
144 uint32_t bitmapwords
;
147 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
149 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
162 uint8_t aes_iv
[AES_BLOCK_SIZE
];
164 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
166 struct hibernate_cryptvars_t
168 uint8_t aes_iv
[AES_BLOCK_SIZE
];
171 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
173 #endif /* defined(_AES_H) */
177 kIOHibernateHandoffType
= 0x686f0000,
178 kIOHibernateHandoffTypeEnd
= kIOHibernateHandoffType
+ 0,
179 kIOHibernateHandoffTypeGraphicsInfo
= kIOHibernateHandoffType
+ 1,
180 kIOHibernateHandoffTypeCryptVars
= kIOHibernateHandoffType
+ 2,
181 kIOHibernateHandoffTypeMemoryMap
= kIOHibernateHandoffType
+ 3,
182 kIOHibernateHandoffTypeDeviceTree
= kIOHibernateHandoffType
+ 4,
183 kIOHibernateHandoffTypeDeviceProperties
= kIOHibernateHandoffType
+ 5,
184 kIOHibernateHandoffTypeKeyStore
= kIOHibernateHandoffType
+ 6,
187 struct IOHibernateHandoff
193 typedef struct IOHibernateHandoff IOHibernateHandoff
;
197 kIOHibernateProgressCount
= 19,
198 kIOHibernateProgressWidth
= 7,
199 kIOHibernateProgressHeight
= 16,
200 kIOHibernateProgressSpacing
= 3,
201 kIOHibernateProgressOriginY
= 81,
203 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
205 kIOHibernateProgressLightGray
= 230,
206 kIOHibernateProgressMidGray
= 174,
207 kIOHibernateProgressDarkGray
= 92
212 kIOHibernatePostWriteSleep
= 0,
213 kIOHibernatePostWriteWake
= 1,
214 kIOHibernatePostWriteHalt
= 2,
215 kIOHibernatePostWriteRestart
= 3
219 struct hibernate_graphics_t
221 uint32_t physicalAddress
; // Base address of video memory
222 int32_t gfxStatus
; // EFI config restore status
223 uint32_t rowBytes
; // Number of bytes per pixel row
224 uint32_t width
; // Width
225 uint32_t height
; // Height
226 uint32_t depth
; // Pixel Depth
228 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
230 typedef struct hibernate_graphics_t hibernate_graphics_t
;
232 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
233 static const uint8_t gIOHibernateProgressAlpha \
234 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
236 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
237 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
238 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
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 { 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 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
250 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
251 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
254 struct hibernate_preview_t
256 uint32_t imageCount
; // Number of images
257 uint32_t width
; // Width
258 uint32_t height
; // Height
259 uint32_t depth
; // Pixel Depth
260 uint32_t lockTime
; // Lock time
261 uint32_t reservedG
[8]; // reserved
262 uint32_t reservedK
[8]; // reserved
264 typedef struct hibernate_preview_t hibernate_preview_t
;
266 struct hibernate_statistics_t
270 uint32_t image1Pages
;
272 uint32_t booterStart
;
274 uint32_t booterDuration
;
275 uint32_t booterConnectDisplayDuration
;
276 uint32_t booterSplashDuration
;
277 uint32_t booterDuration0
;
278 uint32_t booterDuration1
;
279 uint32_t booterDuration2
;
280 uint32_t trampolineDuration
;
281 uint32_t kernelImageReadDuration
;
283 uint32_t graphicsReadyTime
;
284 uint32_t wakeNotificationTime
;
285 uint32_t lockScreenReadyTime
;
286 uint32_t hidReadyTime
;
288 uint32_t wakeCapability
;
291 typedef struct hibernate_statistics_t hibernate_statistics_t
;
293 #define kIOSysctlHibernateStatistics "kern.hibernatestatistics"
294 #define kIOSysctlHibernateGraphicsReady "kern.hibernategraphicsready"
295 #define kIOSysctlHibernateWakeNotify "kern.hibernatewakenotification"
296 #define kIOSysctlHibernateScreenReady "kern.hibernatelockscreenready"
297 #define kIOSysctlHibernateHIDReady "kern.hibernatehidready"
303 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
305 IOReturn
IOHibernateSystemSleep(void);
306 IOReturn
IOHibernateOpenForDebugData(void);
307 IOReturn
IOHibernateIOKitSleep(void);
308 IOReturn
IOHibernateSystemHasSlept(void);
309 IOReturn
IOHibernateSystemWake(void);
310 IOReturn
IOHibernateSystemPostWake(void);
311 bool IOHibernateWasScreenLocked(void);
312 void IOHibernateSetScreenLocked(uint32_t lockState
);
313 void IOHibernateSetWakeCapabilities(uint32_t capability
);
314 void IOHibernateSystemRestart(void);
316 #endif /* __cplusplus */
319 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
321 struct kern_direct_file_io_ref_t
*
322 kern_open_file_for_direct_io(const char * name
, boolean_t create_file
,
323 kern_get_file_extents_callback_t callback
,
328 off_t write_file_offset
,
329 caddr_t write_file_addr
,
330 vm_size_t write_file_len
,
332 dev_t
* partition_device_result
,
333 dev_t
* image_device_result
,
334 uint64_t * partitionbase_result
,
335 uint64_t * maxiocount_result
,
338 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
, int ioflag
);
340 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
,
341 off_t write_offset
, caddr_t addr
, vm_size_t write_length
,
342 off_t discard_offset
, off_t discard_end
);
343 #endif /* _SYS_CONF_H_ */
347 vm_compressor_do_warmup(void);
350 hibernate_page_list_t
*
351 hibernate_page_list_allocate(boolean_t log
);
354 hibernate_alloc_page_lists(
355 hibernate_page_list_t
** page_list_ret
,
356 hibernate_page_list_t
** page_list_wired_ret
,
357 hibernate_page_list_t
** page_list_pal_ret
);
360 hibernate_setup(IOHibernateImageHeader
* header
,
361 uint32_t free_page_ratio
,
362 uint32_t free_page_time
,
364 hibernate_page_list_t
* page_list
,
365 hibernate_page_list_t
* page_list_wired
,
366 hibernate_page_list_t
* page_list_pal
);
369 hibernate_teardown(hibernate_page_list_t
* page_list
,
370 hibernate_page_list_t
* page_list_wired
,
371 hibernate_page_list_t
* page_list_pal
);
374 hibernate_processor_setup(IOHibernateImageHeader
* header
);
377 hibernate_gobble_pages(uint32_t gobble_count
, uint32_t free_page_time
);
379 hibernate_free_gobble_pages(void);
382 hibernate_vm_lock_queues(void);
384 hibernate_vm_unlock_queues(void);
387 hibernate_vm_lock(void);
389 hibernate_vm_unlock(void);
391 // mark pages not to be saved, based on VM system accounting
393 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
394 hibernate_page_list_t
* page_list_wired
,
395 hibernate_page_list_t
* page_list_pal
,
397 boolean_t discard_all
,
398 uint32_t * pagesOut
);
400 // mark pages to be saved, or pages not to be saved but available
401 // for scratch usage during restore
403 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
404 hibernate_page_list_t
* page_list_wired
,
406 uint32_t * pagesOut
);
408 // mark pages not to be saved and not for scratch usage during restore
410 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
411 hibernate_page_list_t
* page_list_wired
,
412 uint32_t * pagesOut
);
415 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
418 hibernate_should_abort(void);
421 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
422 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
425 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
428 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
431 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
434 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
437 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
440 hibernate_machine_init(void);
443 hibernate_write_image(void);
446 hibernate_machine_entrypoint(uint32_t p1
, uint32_t p2
, uint32_t p3
, uint32_t p4
);
448 hibernate_kernel_entrypoint(uint32_t p1
, uint32_t p2
, uint32_t p3
, uint32_t p4
);
450 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
451 uint32_t system_table_offset
);
454 extern uint32_t gIOHibernateState
;
455 extern uint32_t gIOHibernateMode
;
456 extern uint32_t gIOHibernateDebugFlags
;
457 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
458 extern uint8_t gIOHibernateRestoreStack
[];
459 extern uint8_t gIOHibernateRestoreStackEnd
[];
460 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
462 #define HIBLOG(fmt, args...) \
463 { kprintf(fmt, ## args); printf(fmt, ## args); }
465 #define HIBPRINT(fmt, args...) \
466 { kprintf(fmt, ## args); }
470 // gIOHibernateState, kIOHibernateStateKey
473 kIOHibernateStateInactive
= 0,
474 kIOHibernateStateHibernating
= 1, /* writing image */
475 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
478 // gIOHibernateMode, kIOHibernateModeKey
481 kIOHibernateModeOn
= 0x00000001,
482 kIOHibernateModeSleep
= 0x00000002,
483 kIOHibernateModeEncrypt
= 0x00000004,
484 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
485 kIOHibernateModeDiscardCleanActive
= 0x00000010,
486 kIOHibernateModeSwitch
= 0x00000020,
487 kIOHibernateModeRestart
= 0x00000040,
488 kIOHibernateModeSSDInvert
= 0x00000080,
489 kIOHibernateModeFileResize
= 0x00000100,
492 // IOHibernateImageHeader.signature
495 kIOHibernateHeaderSignature
= 0x73696d65,
496 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a,
497 kIOHibernateHeaderOpenSignature
= 0xf1e0be9d,
498 kIOHibernateHeaderDebugDataSignature
= 0xfcddfcdd
501 // kind for hibernate_set_page_state()
504 kIOHibernatePageStateFree
= 0,
505 kIOHibernatePageStateWiredSave
= 1,
506 kIOHibernatePageStateUnwiredSave
= 2
509 #define kIOHibernateModeKey "Hibernate Mode"
510 #define kIOHibernateFileKey "Hibernate File"
511 #define kIOHibernateFileMinSizeKey "Hibernate File Min"
512 #define kIOHibernateFileMaxSizeKey "Hibernate File Max"
513 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
514 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
516 #define kIOHibernateStateKey "IOHibernateState"
517 #define kIOHibernateFeatureKey "Hibernation"
518 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
520 #ifndef kIOHibernatePreviewActiveKey
521 #define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
522 // values for kIOHibernatePreviewActiveKey
524 kIOHibernatePreviewActive
= 0x00000001,
525 kIOHibernatePreviewUpdates
= 0x00000002
529 #define kIOHibernateOptionsKey "IOHibernateOptions"
530 #define kIOHibernateGfxStatusKey "IOHibernateGfxStatus"
532 kIOHibernateGfxStatusUnknown
= ((int32_t) 0xFFFFFFFF)
535 #define kIOHibernateBootImageKey "boot-image"
536 #define kIOHibernateBootImageKeyKey "boot-image-key"
537 #define kIOHibernateBootSignatureKey "boot-signature"
539 #define kIOHibernateMemorySignatureKey "memory-signature"
540 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
541 #define kIOHibernateMachineSignatureKey "machine-signature"
543 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
544 #define kIOHibernateSMCVariablesKey "IOHibernateSMCVariables"
546 #define kIOHibernateBootSwitchVarsKey "boot-switch-vars"
548 #define kIOHibernateBootNoteKey "boot-note"
551 #define kIOHibernateUseKernelInterpreter 0x80000000
555 kIOPreviewImageIndexDesktop
= 0,
556 kIOPreviewImageIndexLockScreen
= 1,
557 kIOPreviewImageCount
= 2
562 kIOScreenLockNoLock
= 1,
563 kIOScreenLockUnlocked
= 2,
564 kIOScreenLockLocked
= 3,
565 kIOScreenLockFileVaultDialog
= 4,
568 #define kIOScreenLockStateKey "IOScreenLockState"
570 #endif /* ! __IOKIT_IOHIBERNATEPRIVATE_H */