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 uint8_t reserved2
[24];
76 uint64_t encryptStart
;
77 uint64_t machineSignature
;
80 uint32_t previewPageListSize
;
84 uint32_t reserved
[82]; // make sizeof == 512
86 uint32_t fileExtentMapSize
;
87 IOPolledFileExtent fileExtentMap
[2];
89 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
92 struct hibernate_bitmap_t
99 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
101 struct hibernate_page_list_t
106 hibernate_bitmap_t bank_bitmap
[0];
108 typedef struct hibernate_page_list_t hibernate_page_list_t
;
110 struct hibernate_cryptwakevars_t
113 uint8_t aes_iv
[AES_BLOCK_SIZE
];
115 #warning undef _AES_H
118 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
120 struct hibernate_cryptvars_t
123 uint8_t aes_iv
[AES_BLOCK_SIZE
];
126 #warning undef _AES_H
129 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
134 kIOHibernateProgressCount
= 19,
135 kIOHibernateProgressWidth
= 7,
136 kIOHibernateProgressHeight
= 16,
137 kIOHibernateProgressSpacing
= 3,
138 kIOHibernateProgressOriginY
= 81,
140 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
142 kIOHibernateProgressLightGray
= 230,
143 kIOHibernateProgressMidGray
= 174,
144 kIOHibernateProgressDarkGray
= 92
147 struct hibernate_graphics_t
149 unsigned long physicalAddress
; // Base address of video memory
150 unsigned long mode
; //
151 unsigned long rowBytes
; // Number of bytes per pixel row
152 unsigned long width
; // Width
153 unsigned long height
; // Height
154 unsigned long depth
; // Pixel Depth
156 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
158 typedef struct hibernate_graphics_t hibernate_graphics_t
;
160 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
161 static const uint8_t gIOHibernateProgressAlpha \
162 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
164 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
165 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
166 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
167 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
168 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
169 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
170 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
171 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
172 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
173 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
174 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
175 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
176 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
177 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
178 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
179 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
186 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
188 IOReturn
IOHibernateSystemSleep(void);
189 IOReturn
IOHibernateSystemHasSlept(void);
190 IOReturn
IOHibernateSystemWake(void);
191 IOReturn
IOHibernateSystemPostWake(void);
193 #endif /* __cplusplus */
196 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
198 struct kern_direct_file_io_ref_t
*
199 kern_open_file_for_direct_io(const char * name
,
200 kern_get_file_extents_callback_t callback
,
203 uint64_t * partitionbase_result
,
204 uint64_t * maxiocount_result
);
206 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
208 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
209 int get_kernel_symfile(struct proc
*p
, char **symfile
);
210 #endif /* _SYS_CONF_H_ */
212 hibernate_page_list_t
*
213 hibernate_page_list_allocate(void);
216 hibernate_setup(IOHibernateImageHeader
* header
,
217 uint32_t free_page_ratio
,
218 uint32_t free_page_time
,
219 hibernate_page_list_t
** page_list_ret
,
220 hibernate_page_list_t
** page_list_wired_ret
,
221 boolean_t
* encryptedswap
);
223 hibernate_teardown(hibernate_page_list_t
* page_list
,
224 hibernate_page_list_t
* page_list_wired
);
227 hibernate_processor_setup(IOHibernateImageHeader
* header
);
230 hibernate_vm_lock(void);
232 hibernate_vm_unlock(void);
235 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
236 hibernate_page_list_t
* page_list_wired
,
237 uint32_t * pagesOut
);
240 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
241 hibernate_page_list_t
* page_list_wired
,
242 uint32_t * pagesOut
);
244 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
247 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
248 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
251 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
253 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
256 hibernate_page_list_count(hibernate_page_list_t
*list
, uint32_t set
, uint32_t page
);
259 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
262 hibernate_machine_init(void);
264 hibernate_write_image(void);
267 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
269 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
271 extern uint32_t gIOHibernateState
;
272 extern uint32_t gIOHibernateMode
;
273 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
274 extern uint8_t gIOHibernateRestoreStack
[];
275 extern uint8_t gIOHibernateRestoreStackEnd
[];
276 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
277 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
278 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
280 #define HIBLOG(fmt, args...) \
281 { kprintf(fmt, ## args); printf(fmt, ## args); }
283 #define HIBPRINT(fmt, args...) \
284 { kprintf(fmt, ## args); }
288 // gIOHibernateState, kIOHibernateStateKey
291 kIOHibernateStateInactive
= 0,
292 kIOHibernateStateHibernating
= 1, /* writing image */
293 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
296 // gIOHibernateMode, kIOHibernateModeKey
299 kIOHibernateModeOn
= 0x00000001,
300 kIOHibernateModeSleep
= 0x00000002,
301 kIOHibernateModeEncrypt
= 0x00000004,
303 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
304 kIOHibernateModeDiscardCleanActive
= 0x00000010
307 // IOHibernateImageHeader.signature
310 kIOHibernateHeaderSignature
= 0x73696d65,
311 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
314 // kind for hibernate_set_page_state()
317 kIOHibernatePageStateFree
= 0,
318 kIOHibernatePageStateWiredSave
= 1,
319 kIOHibernatePageStateUnwiredSave
= 2
322 #define kIOHibernateModeKey "Hibernate Mode"
323 #define kIOHibernateFileKey "Hibernate File"
324 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
325 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
327 #define kIOHibernateStateKey "IOHibernateState"
328 #define kIOHibernateFeatureKey "Hibernation"
329 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
331 #define kIOHibernateBootImageKey "boot-image"
332 #define kIOHibernateBootImageKeyKey "boot-image-key"
333 #define kIOHibernateBootSignatureKey "boot-signature"
335 #define kIOHibernateMemorySignatureKey "memory-signature"
336 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
337 #define kIOHibernateMachineSignatureKey "machine-signature"