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
));
78 uint32_t performanceDataStart
;
79 uint32_t performanceDataSize
;
81 uint64_t encryptStart
__attribute__ ((packed
));
82 uint64_t machineSignature
__attribute__ ((packed
));
85 uint32_t previewPageListSize
;
89 int32_t graphicsInfoOffset
;
90 int32_t cryptVarsOffset
;
91 int32_t memoryMapOffset
;
92 uint32_t memoryMapSize
;
93 uint32_t systemTableOffset
;
97 uint32_t reserved
[76]; // make sizeof == 512
99 uint32_t fileExtentMapSize
;
100 IOPolledFileExtent fileExtentMap
[2];
102 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
106 kIOHibernateDebugRestoreLogs
= 0x00000001
109 struct hibernate_bitmap_t
113 uint32_t bitmapwords
;
116 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
118 struct hibernate_page_list_t
123 hibernate_bitmap_t bank_bitmap
[0];
125 typedef struct hibernate_page_list_t hibernate_page_list_t
;
129 struct hibernate_cryptwakevars_t
131 uint8_t aes_iv
[AES_BLOCK_SIZE
];
133 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
135 struct hibernate_cryptvars_t
137 uint8_t aes_iv
[AES_BLOCK_SIZE
];
140 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
142 #endif /* defined(_AES_H) */
147 kIOHibernateProgressCount
= 19,
148 kIOHibernateProgressWidth
= 7,
149 kIOHibernateProgressHeight
= 16,
150 kIOHibernateProgressSpacing
= 3,
151 kIOHibernateProgressOriginY
= 81,
153 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
155 kIOHibernateProgressLightGray
= 230,
156 kIOHibernateProgressMidGray
= 174,
157 kIOHibernateProgressDarkGray
= 92
162 kIOHibernatePostWriteSleep
= 0,
163 kIOHibernatePostWriteWake
= 1,
164 kIOHibernatePostWriteHalt
= 2,
165 kIOHibernatePostWriteRestart
= 3
169 struct hibernate_graphics_t
171 uint32_t physicalAddress
; // Base address of video memory
173 uint32_t rowBytes
; // Number of bytes per pixel row
174 uint32_t width
; // Width
175 uint32_t height
; // Height
176 uint32_t depth
; // Pixel Depth
178 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
180 typedef struct hibernate_graphics_t hibernate_graphics_t
;
182 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
183 static const uint8_t gIOHibernateProgressAlpha \
184 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
186 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
187 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
188 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
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 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
198 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
199 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
200 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
201 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
208 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
210 IOReturn
IOHibernateSystemSleep(void);
211 IOReturn
IOHibernateSystemHasSlept(void);
212 IOReturn
IOHibernateSystemWake(void);
213 IOReturn
IOHibernateSystemPostWake(void);
215 #endif /* __cplusplus */
218 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
220 struct kern_direct_file_io_ref_t
*
221 kern_open_file_for_direct_io(const char * name
,
222 kern_get_file_extents_callback_t callback
,
225 uint64_t * partitionbase_result
,
226 uint64_t * maxiocount_result
);
228 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
230 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
231 int get_kernel_symfile(struct proc
*p
, char const **symfile
);
232 #endif /* _SYS_CONF_H_ */
234 hibernate_page_list_t
*
235 hibernate_page_list_allocate(void);
238 hibernate_setup(IOHibernateImageHeader
* header
,
239 uint32_t free_page_ratio
,
240 uint32_t free_page_time
,
241 hibernate_page_list_t
** page_list_ret
,
242 hibernate_page_list_t
** page_list_wired_ret
,
243 boolean_t
* encryptedswap
);
245 hibernate_teardown(hibernate_page_list_t
* page_list
,
246 hibernate_page_list_t
* page_list_wired
);
249 hibernate_processor_setup(IOHibernateImageHeader
* header
);
252 hibernate_gobble_pages(uint32_t gobble_count
, uint32_t free_page_time
);
254 hibernate_free_gobble_pages(void);
257 hibernate_vm_lock(void);
259 hibernate_vm_unlock(void);
261 // mark pages not to be saved, based on VM system accounting
263 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
264 hibernate_page_list_t
* page_list_wired
,
265 uint32_t * pagesOut
);
267 // mark pages to be saved, or pages not to be saved but available
268 // for scratch usage during restore
270 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
271 hibernate_page_list_t
* page_list_wired
,
272 uint32_t * pagesOut
);
274 // mark pages not to be saved and not for scratch usage during restore
276 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
277 hibernate_page_list_t
* page_list_wired
,
278 uint32_t * pagesOut
);
281 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
284 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
285 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
288 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
291 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
294 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
297 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
300 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
303 hibernate_machine_init(void);
306 hibernate_write_image(void);
309 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
311 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
313 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
314 uint32_t system_table_offset
);
317 extern uint32_t gIOHibernateState
;
318 extern uint32_t gIOHibernateMode
;
319 extern uint32_t gIOHibernateDebugFlags
;
320 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
321 extern uint8_t gIOHibernateRestoreStack
[];
322 extern uint8_t gIOHibernateRestoreStackEnd
[];
323 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
324 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
325 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
327 #define HIBLOG(fmt, args...) \
328 { kprintf(fmt, ## args); printf(fmt, ## args); }
330 #define HIBPRINT(fmt, args...) \
331 { kprintf(fmt, ## args); }
335 // gIOHibernateState, kIOHibernateStateKey
338 kIOHibernateStateInactive
= 0,
339 kIOHibernateStateHibernating
= 1, /* writing image */
340 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
343 // gIOHibernateMode, kIOHibernateModeKey
346 kIOHibernateModeOn
= 0x00000001,
347 kIOHibernateModeSleep
= 0x00000002,
348 kIOHibernateModeEncrypt
= 0x00000004,
349 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
350 kIOHibernateModeDiscardCleanActive
= 0x00000010,
351 kIOHibernateModeSwitch
= 0x00000020,
352 kIOHibernateModeRestart
= 0x00000040
355 // IOHibernateImageHeader.signature
358 kIOHibernateHeaderSignature
= 0x73696d65,
359 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
362 // kind for hibernate_set_page_state()
365 kIOHibernatePageStateFree
= 0,
366 kIOHibernatePageStateWiredSave
= 1,
367 kIOHibernatePageStateUnwiredSave
= 2
370 #define kIOHibernateModeKey "Hibernate Mode"
371 #define kIOHibernateFileKey "Hibernate File"
372 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
373 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
375 #define kIOHibernateStateKey "IOHibernateState"
376 #define kIOHibernateFeatureKey "Hibernation"
377 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
379 #define kIOHibernatePreviewActiveKey "IOHibernatePreviewActive"
380 // values for kIOHibernatePreviewActiveKey
382 kIOHibernatePreviewActive
= 0x00000001,
383 kIOHibernatePreviewUpdates
= 0x00000002
386 #define kIOHibernateBootImageKey "boot-image"
387 #define kIOHibernateBootImageKeyKey "boot-image-key"
388 #define kIOHibernateBootSignatureKey "boot-signature"
390 #define kIOHibernateMemorySignatureKey "memory-signature"
391 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
392 #define kIOHibernateMachineSignatureKey "machine-signature"
394 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
396 #define kIOHibernateBootSwitchVarsKey "boot-switch-vars"