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>
39 struct IOPolledFileExtent
44 typedef struct IOPolledFileExtent IOPolledFileExtent
;
46 struct IOHibernateImageHeader
51 uint32_t restore1CodePage
;
52 uint32_t restore1PageCount
;
53 uint32_t restore1CodeOffset
;
54 uint32_t restore1StackOffset
;
63 uint32_t actualRestore1Sum
;
64 uint32_t actualImage1Sum
;
65 uint32_t actualImage2Sum
;
67 uint32_t actualUncompressedPages
;
68 uint32_t conflictCount
;
72 uint32_t processorFlags
;
74 uint32_t runtimePages
;
75 uint32_t runtimePageCount
;
76 uint64_t runtimeVirtualPages
__attribute__ ((packed
));
79 uint64_t encryptStart
__attribute__ ((packed
));
80 uint64_t machineSignature
__attribute__ ((packed
));
83 uint32_t previewPageListSize
;
87 int32_t graphicsInfoOffset
;
88 int32_t cryptVarsOffset
;
89 int32_t memoryMapOffset
;
90 uint32_t memoryMapSize
;
91 uint32_t systemTableOffset
;
95 uint32_t reserved
[76]; // make sizeof == 512
97 uint32_t fileExtentMapSize
;
98 IOPolledFileExtent fileExtentMap
[2];
100 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
104 kIOHibernateDebugRestoreLogs
= 0x00000001
107 struct hibernate_bitmap_t
111 uint32_t bitmapwords
;
114 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
116 struct hibernate_page_list_t
121 hibernate_bitmap_t bank_bitmap
[0];
123 typedef struct hibernate_page_list_t hibernate_page_list_t
;
127 struct hibernate_cryptwakevars_t
129 uint8_t aes_iv
[AES_BLOCK_SIZE
];
131 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
133 struct hibernate_cryptvars_t
135 uint8_t aes_iv
[AES_BLOCK_SIZE
];
138 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
140 #endif /* defined(_AES_H) */
145 kIOHibernateProgressCount
= 19,
146 kIOHibernateProgressWidth
= 7,
147 kIOHibernateProgressHeight
= 16,
148 kIOHibernateProgressSpacing
= 3,
149 kIOHibernateProgressOriginY
= 81,
151 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
153 kIOHibernateProgressLightGray
= 230,
154 kIOHibernateProgressMidGray
= 174,
155 kIOHibernateProgressDarkGray
= 92
160 kIOHibernatePostWriteSleep
= 0,
161 kIOHibernatePostWriteWake
= 1,
162 kIOHibernatePostWriteHalt
= 2,
163 kIOHibernatePostWriteRestart
= 3
167 struct hibernate_graphics_t
169 uint32_t physicalAddress
; // Base address of video memory
171 uint32_t rowBytes
; // Number of bytes per pixel row
172 uint32_t width
; // Width
173 uint32_t height
; // Height
174 uint32_t depth
; // Pixel Depth
176 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
178 typedef struct hibernate_graphics_t hibernate_graphics_t
;
180 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
181 static const uint8_t gIOHibernateProgressAlpha \
182 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
184 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
185 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
186 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
187 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
188 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
189 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
190 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
191 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
192 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
193 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
194 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
195 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
196 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
197 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
198 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
199 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
206 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
208 IOReturn
IOHibernateSystemSleep(void);
209 IOReturn
IOHibernateSystemHasSlept(void);
210 IOReturn
IOHibernateSystemWake(void);
211 IOReturn
IOHibernateSystemPostWake(void);
213 #endif /* __cplusplus */
216 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
218 struct kern_direct_file_io_ref_t
*
219 kern_open_file_for_direct_io(const char * name
,
220 kern_get_file_extents_callback_t callback
,
223 uint64_t * partitionbase_result
,
224 uint64_t * maxiocount_result
);
226 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
228 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
229 int get_kernel_symfile(struct proc
*p
, char const **symfile
);
230 #endif /* _SYS_CONF_H_ */
232 hibernate_page_list_t
*
233 hibernate_page_list_allocate(void);
236 hibernate_setup(IOHibernateImageHeader
* header
,
237 uint32_t free_page_ratio
,
238 uint32_t free_page_time
,
239 hibernate_page_list_t
** page_list_ret
,
240 hibernate_page_list_t
** page_list_wired_ret
,
241 boolean_t
* encryptedswap
);
243 hibernate_teardown(hibernate_page_list_t
* page_list
,
244 hibernate_page_list_t
* page_list_wired
);
247 hibernate_processor_setup(IOHibernateImageHeader
* header
);
250 hibernate_gobble_pages(uint32_t gobble_count
, uint32_t free_page_time
);
252 hibernate_free_gobble_pages(void);
255 hibernate_vm_lock(void);
257 hibernate_vm_unlock(void);
259 // mark pages not to be saved, based on VM system accounting
261 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
262 hibernate_page_list_t
* page_list_wired
,
263 uint32_t * pagesOut
);
265 // mark pages to be saved, or pages not to be saved but available
266 // for scratch usage during restore
268 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
269 hibernate_page_list_t
* page_list_wired
,
270 uint32_t * pagesOut
);
272 // mark pages not to be saved and not for scratch usage during restore
274 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
275 hibernate_page_list_t
* page_list_wired
,
276 uint32_t * pagesOut
);
279 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
282 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
283 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
286 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
289 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
292 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
295 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
298 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
301 hibernate_machine_init(void);
304 hibernate_write_image(void);
307 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
309 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
311 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
312 uint32_t system_table_offset
);
315 extern uint32_t gIOHibernateState
;
316 extern uint32_t gIOHibernateMode
;
317 extern uint32_t gIOHibernateDebugFlags
;
318 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
319 extern uint8_t gIOHibernateRestoreStack
[];
320 extern uint8_t gIOHibernateRestoreStackEnd
[];
321 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
322 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
323 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
325 #define HIBLOG(fmt, args...) \
326 { kprintf(fmt, ## args); printf(fmt, ## args); }
328 #define HIBPRINT(fmt, args...) \
329 { kprintf(fmt, ## args); }
333 // gIOHibernateState, kIOHibernateStateKey
336 kIOHibernateStateInactive
= 0,
337 kIOHibernateStateHibernating
= 1, /* writing image */
338 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
341 // gIOHibernateMode, kIOHibernateModeKey
344 kIOHibernateModeOn
= 0x00000001,
345 kIOHibernateModeSleep
= 0x00000002,
346 kIOHibernateModeEncrypt
= 0x00000004,
347 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
348 kIOHibernateModeDiscardCleanActive
= 0x00000010,
349 kIOHibernateModeSwitch
= 0x00000020,
350 kIOHibernateModeRestart
= 0x00000040
353 // IOHibernateImageHeader.signature
356 kIOHibernateHeaderSignature
= 0x73696d65,
357 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
360 // kind for hibernate_set_page_state()
363 kIOHibernatePageStateFree
= 0,
364 kIOHibernatePageStateWiredSave
= 1,
365 kIOHibernatePageStateUnwiredSave
= 2
368 #define kIOHibernateModeKey "Hibernate Mode"
369 #define kIOHibernateFileKey "Hibernate File"
370 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
371 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
373 #define kIOHibernateStateKey "IOHibernateState"
374 #define kIOHibernateFeatureKey "Hibernation"
375 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
377 #define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
378 // values for kIOHibernatePreviewActiveKey
380 kIOHibernatePreviewActive
= 0x00000001,
381 kIOHibernatePreviewUpdates
= 0x00000002
384 #define kIOHibernateBootImageKey "boot-image"
385 #define kIOHibernateBootImageKeyKey "boot-image-key"
386 #define kIOHibernateBootSignatureKey "boot-signature"
388 #define kIOHibernateMemorySignatureKey "memory-signature"
389 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
390 #define kIOHibernateMachineSignatureKey "machine-signature"
392 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
394 #define kIOHibernateBootSwitchVarsKey "boot-switch-vars"