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
;
77 uint8_t reserved2
[16];
79 uint64_t encryptStart
;
80 uint64_t machineSignature
;
83 uint32_t previewPageListSize
;
87 int32_t graphicsInfoOffset
;
88 int32_t cryptVarsOffset
;
89 int32_t memoryMapOffset
;
90 uint32_t memoryMapSize
;
91 uint32_t systemTableOffset
;
93 uint32_t reserved
[77]; // make sizeof == 512
95 uint32_t fileExtentMapSize
;
96 IOPolledFileExtent fileExtentMap
[2];
98 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
101 struct hibernate_bitmap_t
105 uint32_t bitmapwords
;
108 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
110 struct hibernate_page_list_t
115 hibernate_bitmap_t bank_bitmap
[0];
117 typedef struct hibernate_page_list_t hibernate_page_list_t
;
121 struct hibernate_cryptwakevars_t
123 uint8_t aes_iv
[AES_BLOCK_SIZE
];
125 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
127 struct hibernate_cryptvars_t
129 uint8_t aes_iv
[AES_BLOCK_SIZE
];
132 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
134 #endif /* defined(_AES_H) */
139 kIOHibernateProgressCount
= 19,
140 kIOHibernateProgressWidth
= 7,
141 kIOHibernateProgressHeight
= 16,
142 kIOHibernateProgressSpacing
= 3,
143 kIOHibernateProgressOriginY
= 81,
145 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
147 kIOHibernateProgressLightGray
= 230,
148 kIOHibernateProgressMidGray
= 174,
149 kIOHibernateProgressDarkGray
= 92
154 kIOHibernatePostWriteSleep
= 0,
155 kIOHibernatePostWriteWake
= 1,
156 kIOHibernatePostWriteHalt
= 2,
157 kIOHibernatePostWriteRestart
= 3
161 struct hibernate_graphics_t
163 uint32_t physicalAddress
; // Base address of video memory
165 uint32_t rowBytes
; // Number of bytes per pixel row
166 uint32_t width
; // Width
167 uint32_t height
; // Height
168 uint32_t depth
; // Pixel Depth
170 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
172 typedef struct hibernate_graphics_t hibernate_graphics_t
;
174 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
175 static const uint8_t gIOHibernateProgressAlpha \
176 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
178 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
179 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
180 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
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 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
189 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
190 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
191 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
192 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
193 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
200 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
202 IOReturn
IOHibernateSystemSleep(void);
203 IOReturn
IOHibernateSystemHasSlept(void);
204 IOReturn
IOHibernateSystemWake(void);
205 IOReturn
IOHibernateSystemPostWake(void);
207 #endif /* __cplusplus */
210 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
212 struct kern_direct_file_io_ref_t
*
213 kern_open_file_for_direct_io(const char * name
,
214 kern_get_file_extents_callback_t callback
,
217 uint64_t * partitionbase_result
,
218 uint64_t * maxiocount_result
);
220 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
222 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
223 int get_kernel_symfile(struct proc
*p
, char const **symfile
);
224 #endif /* _SYS_CONF_H_ */
226 hibernate_page_list_t
*
227 hibernate_page_list_allocate(void);
230 hibernate_setup(IOHibernateImageHeader
* header
,
231 uint32_t free_page_ratio
,
232 uint32_t free_page_time
,
233 hibernate_page_list_t
** page_list_ret
,
234 hibernate_page_list_t
** page_list_wired_ret
,
235 boolean_t
* encryptedswap
);
237 hibernate_teardown(hibernate_page_list_t
* page_list
,
238 hibernate_page_list_t
* page_list_wired
);
241 hibernate_processor_setup(IOHibernateImageHeader
* header
);
244 hibernate_vm_lock(void);
246 hibernate_vm_unlock(void);
248 // mark pages not to be saved, based on VM system accounting
250 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
251 hibernate_page_list_t
* page_list_wired
,
252 uint32_t * pagesOut
);
254 // mark pages to be saved, or pages not to be saved but available
255 // for scratch usage during restore
257 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
258 hibernate_page_list_t
* page_list_wired
,
259 uint32_t * pagesOut
);
261 // mark pages not to be saved and not for scratch usage during restore
263 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
264 hibernate_page_list_t
* page_list_wired
,
265 uint32_t * pagesOut
);
268 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
271 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
272 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
275 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
278 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
281 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
284 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
287 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
290 hibernate_machine_init(void);
293 hibernate_write_image(void);
296 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
298 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
300 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
301 uint32_t system_table_offset
);
304 extern uint32_t gIOHibernateState
;
305 extern uint32_t gIOHibernateMode
;
306 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
307 extern uint8_t gIOHibernateRestoreStack
[];
308 extern uint8_t gIOHibernateRestoreStackEnd
[];
309 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
310 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
311 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
313 #define HIBLOG(fmt, args...) \
314 { kprintf(fmt, ## args); printf(fmt, ## args); }
316 #define HIBPRINT(fmt, args...) \
317 { kprintf(fmt, ## args); }
321 // gIOHibernateState, kIOHibernateStateKey
324 kIOHibernateStateInactive
= 0,
325 kIOHibernateStateHibernating
= 1, /* writing image */
326 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
329 // gIOHibernateMode, kIOHibernateModeKey
332 kIOHibernateModeOn
= 0x00000001,
333 kIOHibernateModeSleep
= 0x00000002,
334 kIOHibernateModeEncrypt
= 0x00000004,
335 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
336 kIOHibernateModeDiscardCleanActive
= 0x00000010,
337 kIOHibernateModeSwitch
= 0x00000020,
338 kIOHibernateModeRestart
= 0x00000040
341 // IOHibernateImageHeader.signature
344 kIOHibernateHeaderSignature
= 0x73696d65,
345 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
348 // kind for hibernate_set_page_state()
351 kIOHibernatePageStateFree
= 0,
352 kIOHibernatePageStateWiredSave
= 1,
353 kIOHibernatePageStateUnwiredSave
= 2
356 #define kIOHibernateModeKey "Hibernate Mode"
357 #define kIOHibernateFileKey "Hibernate File"
358 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
359 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
361 #define kIOHibernateStateKey "IOHibernateState"
362 #define kIOHibernateFeatureKey "Hibernation"
363 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
365 #define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
366 // values for kIOHibernatePreviewActiveKey
368 kIOHibernatePreviewActive
= 0x00000001,
369 kIOHibernatePreviewUpdates
= 0x00000002
372 #define kIOHibernateBootImageKey "boot-image"
373 #define kIOHibernateBootImageKeyKey "boot-image-key"
374 #define kIOHibernateBootSignatureKey "boot-signature"
376 #define kIOHibernateMemorySignatureKey "memory-signature"
377 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
378 #define kIOHibernateMachineSignatureKey "machine-signature"
380 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
382 #define kIOHibernateBootSwitchVarsKey "boot-switch-vars"