2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
38 #include <crypto/aes.h>
41 struct IOPolledFileExtent
46 typedef struct IOPolledFileExtent IOPolledFileExtent
;
48 struct IOHibernateImageHeader
53 uint32_t restore1CodePage
;
54 uint32_t restore1PageCount
;
55 uint32_t restore1CodeOffset
;
56 uint32_t restore1StackOffset
;
65 uint32_t actualRestore1Sum
;
66 uint32_t actualImage1Sum
;
67 uint32_t actualImage2Sum
;
69 uint32_t actualUncompressedPages
;
70 uint32_t conflictCount
;
74 uint32_t processorFlags
;
76 uint32_t runtimePages
;
77 uint32_t runtimePageCount
;
79 uint8_t reserved2
[16];
81 uint64_t encryptStart
;
82 uint64_t machineSignature
;
85 uint32_t previewPageListSize
;
89 int32_t graphicsInfoOffset
;
90 int32_t cryptVarsOffset
;
91 int32_t memoryMapOffset
;
92 uint32_t memoryMapSize
;
93 uint32_t systemTableOffset
;
95 uint32_t reserved
[77]; // make sizeof == 512
97 uint32_t fileExtentMapSize
;
98 IOPolledFileExtent fileExtentMap
[2];
100 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
103 struct hibernate_bitmap_t
107 uint32_t bitmapwords
;
110 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
112 struct hibernate_page_list_t
117 hibernate_bitmap_t bank_bitmap
[0];
119 typedef struct hibernate_page_list_t hibernate_page_list_t
;
121 struct hibernate_cryptwakevars_t
124 uint8_t aes_iv
[AES_BLOCK_SIZE
];
126 #warning undef _AES_H
129 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
131 struct hibernate_cryptvars_t
134 uint8_t aes_iv
[AES_BLOCK_SIZE
];
137 #warning undef _AES_H
140 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
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
158 struct hibernate_graphics_t
160 unsigned long physicalAddress
; // Base address of video memory
161 unsigned long mode
; //
162 unsigned long rowBytes
; // Number of bytes per pixel row
163 unsigned long width
; // Width
164 unsigned long height
; // Height
165 unsigned long depth
; // Pixel Depth
167 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
169 typedef struct hibernate_graphics_t hibernate_graphics_t
;
171 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
172 static const uint8_t gIOHibernateProgressAlpha \
173 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
175 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
176 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
177 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
178 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
179 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
180 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
181 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
182 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
183 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
184 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
185 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
186 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
187 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
188 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
189 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
190 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
197 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
199 IOReturn
IOHibernateSystemSleep(void);
200 IOReturn
IOHibernateSystemHasSlept(void);
201 IOReturn
IOHibernateSystemWake(void);
202 IOReturn
IOHibernateSystemPostWake(void);
204 #endif /* __cplusplus */
207 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
209 struct kern_direct_file_io_ref_t
*
210 kern_open_file_for_direct_io(const char * name
,
211 kern_get_file_extents_callback_t callback
,
214 uint64_t * partitionbase_result
,
215 uint64_t * maxiocount_result
);
217 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
219 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
220 int get_kernel_symfile(struct proc
*p
, char **symfile
);
221 #endif /* _SYS_CONF_H_ */
223 hibernate_page_list_t
*
224 hibernate_page_list_allocate(void);
227 hibernate_setup(IOHibernateImageHeader
* header
,
228 uint32_t free_page_ratio
,
229 uint32_t free_page_time
,
230 hibernate_page_list_t
** page_list_ret
,
231 hibernate_page_list_t
** page_list_wired_ret
,
232 boolean_t
* encryptedswap
);
234 hibernate_teardown(hibernate_page_list_t
* page_list
,
235 hibernate_page_list_t
* page_list_wired
);
238 hibernate_processor_setup(IOHibernateImageHeader
* header
);
241 hibernate_vm_lock(void);
243 hibernate_vm_unlock(void);
245 // mark pages not to be saved, based on VM system accounting
247 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
248 hibernate_page_list_t
* page_list_wired
,
249 uint32_t * pagesOut
);
251 // mark pages to be saved, or pages not to be saved but available
252 // for scratch usage during restore
254 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
255 hibernate_page_list_t
* page_list_wired
,
256 uint32_t * pagesOut
);
258 // mark pages not to be saved and not for scratch usage during restore
260 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
261 hibernate_page_list_t
* page_list_wired
,
262 uint32_t * pagesOut
);
265 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
268 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
269 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
272 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
275 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
278 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
281 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
284 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
287 hibernate_machine_init(void);
289 hibernate_write_image(void);
292 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
294 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
296 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
297 uint32_t system_table_offset
);
300 extern uint32_t gIOHibernateState
;
301 extern uint32_t gIOHibernateMode
;
302 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
303 extern uint8_t gIOHibernateRestoreStack
[];
304 extern uint8_t gIOHibernateRestoreStackEnd
[];
305 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
306 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
307 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
309 #define HIBLOG(fmt, args...) \
310 { kprintf(fmt, ## args); printf(fmt, ## args); }
312 #define HIBPRINT(fmt, args...) \
313 { kprintf(fmt, ## args); }
317 // gIOHibernateState, kIOHibernateStateKey
320 kIOHibernateStateInactive
= 0,
321 kIOHibernateStateHibernating
= 1, /* writing image */
322 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
325 // gIOHibernateMode, kIOHibernateModeKey
328 kIOHibernateModeOn
= 0x00000001,
329 kIOHibernateModeSleep
= 0x00000002,
330 kIOHibernateModeEncrypt
= 0x00000004,
332 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
333 kIOHibernateModeDiscardCleanActive
= 0x00000010
336 // IOHibernateImageHeader.signature
339 kIOHibernateHeaderSignature
= 0x73696d65,
340 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
343 // kind for hibernate_set_page_state()
346 kIOHibernatePageStateFree
= 0,
347 kIOHibernatePageStateWiredSave
= 1,
348 kIOHibernatePageStateUnwiredSave
= 2
351 #define kIOHibernateModeKey "Hibernate Mode"
352 #define kIOHibernateFileKey "Hibernate File"
353 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
354 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
356 #define kIOHibernateStateKey "IOHibernateState"
357 #define kIOHibernateFeatureKey "Hibernation"
358 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
360 #define kIOHibernateBootImageKey "boot-image"
361 #define kIOHibernateBootImageKeyKey "boot-image-key"
362 #define kIOHibernateBootSignatureKey "boot-signature"
364 #define kIOHibernateMemorySignatureKey "memory-signature"
365 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
366 #define kIOHibernateMachineSignatureKey "machine-signature"
368 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"