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 <crypto/aes.h>
37 #include <uuid/uuid.h>
40 struct IOPolledFileExtent
45 typedef struct IOPolledFileExtent IOPolledFileExtent
;
47 struct IOHibernateImageHeader
52 uint32_t restore1CodePhysPage
;
54 uint64_t restore1CodeVirt
;
55 uint32_t restore1PageCount
;
56 uint32_t restore1CodeOffset
;
57 uint32_t restore1StackOffset
;
66 uint32_t actualRestore1Sum
;
67 uint32_t actualImage1Sum
;
68 uint32_t actualImage2Sum
;
70 uint32_t actualUncompressedPages
;
71 uint32_t conflictCount
;
75 uint32_t processorFlags
;
77 uint32_t runtimePages
;
78 uint32_t runtimePageCount
;
79 uint64_t runtimeVirtualPages
__attribute__ ((packed
));
81 uint32_t performanceDataStart
;
82 uint32_t performanceDataSize
;
84 uint64_t encryptStart
__attribute__ ((packed
));
85 uint64_t machineSignature
__attribute__ ((packed
));
88 uint32_t previewPageListSize
;
92 uint32_t handoffPages
;
93 uint32_t handoffPageCount
;
95 uint32_t systemTableOffset
;
100 uint32_t reserved
[70]; // make sizeof == 512
102 uint64_t encryptEnd
__attribute__ ((packed
));
103 uint64_t deviceBase
__attribute__ ((packed
));
105 uint32_t fileExtentMapSize
;
106 IOPolledFileExtent fileExtentMap
[2];
108 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
112 kIOHibernateDebugRestoreLogs
= 0x00000001
115 // options & IOHibernateOptions property
118 kIOHibernateOptionSSD
= 0x00000001,
119 kIOHibernateOptionColor
= 0x00000002,
120 kIOHibernateOptionProgress
= 0x00000004,
121 kIOHibernateOptionDarkWake
= 0x00000008,
124 struct hibernate_bitmap_t
128 uint32_t bitmapwords
;
131 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
133 struct hibernate_page_list_t
138 hibernate_bitmap_t bank_bitmap
[0];
140 typedef struct hibernate_page_list_t hibernate_page_list_t
;
144 struct hibernate_cryptwakevars_t
146 uint8_t aes_iv
[AES_BLOCK_SIZE
];
148 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
150 struct hibernate_cryptvars_t
152 uint8_t aes_iv
[AES_BLOCK_SIZE
];
155 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
157 #endif /* defined(_AES_H) */
161 kIOHibernateHandoffType
= 0x686f0000,
162 kIOHibernateHandoffTypeEnd
= kIOHibernateHandoffType
+ 0,
163 kIOHibernateHandoffTypeGraphicsInfo
= kIOHibernateHandoffType
+ 1,
164 kIOHibernateHandoffTypeCryptVars
= kIOHibernateHandoffType
+ 2,
165 kIOHibernateHandoffTypeMemoryMap
= kIOHibernateHandoffType
+ 3,
166 kIOHibernateHandoffTypeDeviceTree
= kIOHibernateHandoffType
+ 4,
167 kIOHibernateHandoffTypeDeviceProperties
= kIOHibernateHandoffType
+ 5,
168 kIOHibernateHandoffTypeKeyStore
= kIOHibernateHandoffType
+ 6,
171 struct IOHibernateHandoff
177 typedef struct IOHibernateHandoff IOHibernateHandoff
;
181 kIOHibernateProgressCount
= 19,
182 kIOHibernateProgressWidth
= 7,
183 kIOHibernateProgressHeight
= 16,
184 kIOHibernateProgressSpacing
= 3,
185 kIOHibernateProgressOriginY
= 81,
187 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
189 kIOHibernateProgressLightGray
= 230,
190 kIOHibernateProgressMidGray
= 174,
191 kIOHibernateProgressDarkGray
= 92
196 kIOHibernatePostWriteSleep
= 0,
197 kIOHibernatePostWriteWake
= 1,
198 kIOHibernatePostWriteHalt
= 2,
199 kIOHibernatePostWriteRestart
= 3
203 struct hibernate_graphics_t
205 uint32_t physicalAddress
; // Base address of video memory
206 int32_t gfxStatus
; // EFI config restore status
207 uint32_t rowBytes
; // Number of bytes per pixel row
208 uint32_t width
; // Width
209 uint32_t height
; // Height
210 uint32_t depth
; // Pixel Depth
212 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
214 typedef struct hibernate_graphics_t hibernate_graphics_t
;
216 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
217 static const uint8_t gIOHibernateProgressAlpha \
218 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
220 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
221 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
222 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
223 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
224 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
225 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
226 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
227 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
228 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
229 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
230 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
231 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
232 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
233 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
234 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
235 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
242 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
244 IOReturn
IOHibernateSystemSleep(void);
245 IOReturn
IOHibernateSystemHasSlept(void);
246 IOReturn
IOHibernateSystemWake(void);
247 IOReturn
IOHibernateSystemPostWake(void);
249 #endif /* __cplusplus */
252 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
254 struct kern_direct_file_io_ref_t
*
255 kern_open_file_for_direct_io(const char * name
,
256 kern_get_file_extents_callback_t callback
,
258 dev_t
* partition_device_result
,
259 dev_t
* image_device_result
,
260 uint64_t * partitionbase_result
,
261 uint64_t * maxiocount_result
,
269 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
,
270 off_t offset
, caddr_t addr
, vm_size_t len
);
272 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
273 int get_kernel_symfile(struct proc
*p
, char const **symfile
);
274 #endif /* _SYS_CONF_H_ */
276 hibernate_page_list_t
*
277 hibernate_page_list_allocate(void);
280 hibernate_setup(IOHibernateImageHeader
* header
,
281 uint32_t free_page_ratio
,
282 uint32_t free_page_time
,
284 hibernate_page_list_t
** page_list_ret
,
285 hibernate_page_list_t
** page_list_wired_ret
,
286 hibernate_page_list_t
** page_list_pal_ret
,
287 boolean_t
* encryptedswap
);
289 hibernate_teardown(hibernate_page_list_t
* page_list
,
290 hibernate_page_list_t
* page_list_wired
);
293 hibernate_processor_setup(IOHibernateImageHeader
* header
);
296 hibernate_gobble_pages(uint32_t gobble_count
, uint32_t free_page_time
);
298 hibernate_free_gobble_pages(void);
301 hibernate_vm_lock(void);
303 hibernate_vm_unlock(void);
305 // mark pages not to be saved, based on VM system accounting
307 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
308 hibernate_page_list_t
* page_list_wired
,
309 hibernate_page_list_t
* page_list_pal
,
310 uint32_t * pagesOut
);
312 // mark pages to be saved, or pages not to be saved but available
313 // for scratch usage during restore
315 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
316 hibernate_page_list_t
* page_list_wired
,
317 uint32_t * pagesOut
);
319 // mark pages not to be saved and not for scratch usage during restore
321 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
322 hibernate_page_list_t
* page_list_wired
,
323 uint32_t * pagesOut
);
326 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
329 hibernate_should_abort(void);
332 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
333 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
336 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
339 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
342 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
345 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
348 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
351 hibernate_machine_init(void);
354 hibernate_write_image(void);
357 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
359 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
361 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
362 uint32_t system_table_offset
);
365 extern uint32_t gIOHibernateState
;
366 extern uint32_t gIOHibernateMode
;
367 extern uint32_t gIOHibernateDebugFlags
;
368 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
369 extern uint8_t gIOHibernateRestoreStack
[];
370 extern uint8_t gIOHibernateRestoreStackEnd
[];
371 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
373 #define HIBLOG(fmt, args...) \
374 { kprintf(fmt, ## args); printf(fmt, ## args); }
376 #define HIBPRINT(fmt, args...) \
377 { kprintf(fmt, ## args); }
381 // gIOHibernateState, kIOHibernateStateKey
384 kIOHibernateStateInactive
= 0,
385 kIOHibernateStateHibernating
= 1, /* writing image */
386 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
389 // gIOHibernateMode, kIOHibernateModeKey
392 kIOHibernateModeOn
= 0x00000001,
393 kIOHibernateModeSleep
= 0x00000002,
394 kIOHibernateModeEncrypt
= 0x00000004,
395 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
396 kIOHibernateModeDiscardCleanActive
= 0x00000010,
397 kIOHibernateModeSwitch
= 0x00000020,
398 kIOHibernateModeRestart
= 0x00000040,
399 kIOHibernateModeSSDInvert
= 0x00000080,
402 // IOHibernateImageHeader.signature
405 kIOHibernateHeaderSignature
= 0x73696d65,
406 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
409 // kind for hibernate_set_page_state()
412 kIOHibernatePageStateFree
= 0,
413 kIOHibernatePageStateWiredSave
= 1,
414 kIOHibernatePageStateUnwiredSave
= 2
417 #define kIOHibernateModeKey "Hibernate Mode"
418 #define kIOHibernateFileKey "Hibernate File"
419 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
420 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
422 #define kIOHibernateStateKey "IOHibernateState"
423 #define kIOHibernateFeatureKey "Hibernation"
424 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
426 #define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
427 // values for kIOHibernatePreviewActiveKey
429 kIOHibernatePreviewActive
= 0x00000001,
430 kIOHibernatePreviewUpdates
= 0x00000002
433 #define kIOHibernateOptionsKey "IOHibernateOptions"
434 #define kIOHibernateGfxStatusKey "IOHibernateGfxStatus"
436 kIOHibernateGfxStatusUnknown
= ((int32_t) 0xFFFFFFFF)
439 #define kIOHibernateBootImageKey "boot-image"
440 #define kIOHibernateBootImageKeyKey "boot-image-key"
441 #define kIOHibernateBootSignatureKey "boot-signature"
443 #define kIOHibernateMemorySignatureKey "memory-signature"
444 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
445 #define kIOHibernateMachineSignatureKey "machine-signature"
447 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
448 #define kIOHibernateSMCVariablesKey "IOHibernateSMCVariables"
450 #define kIOHibernateBootSwitchVarsKey "boot-switch-vars"
452 #define kIOHibernateUseKernelInterpreter 0x80000000