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 uint8_t reserved2
[24];
78 uint64_t encryptStart
;
79 uint64_t machineSignature
;
82 uint32_t previewPageListSize
;
86 uint32_t reserved
[82]; // make sizeof == 512
88 uint32_t fileExtentMapSize
;
89 IOPolledFileExtent fileExtentMap
[2];
91 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
94 struct hibernate_bitmap_t
101 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
103 struct hibernate_page_list_t
108 hibernate_bitmap_t bank_bitmap
[0];
110 typedef struct hibernate_page_list_t hibernate_page_list_t
;
112 struct hibernate_cryptwakevars_t
115 uint8_t aes_iv
[AES_BLOCK_SIZE
];
117 #warning undef _AES_H
120 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
122 struct hibernate_cryptvars_t
125 uint8_t aes_iv
[AES_BLOCK_SIZE
];
128 #warning undef _AES_H
131 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
136 kIOHibernateProgressCount
= 19,
137 kIOHibernateProgressWidth
= 7,
138 kIOHibernateProgressHeight
= 16,
139 kIOHibernateProgressSpacing
= 3,
140 kIOHibernateProgressOriginY
= 81,
142 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
144 kIOHibernateProgressLightGray
= 230,
145 kIOHibernateProgressMidGray
= 174,
146 kIOHibernateProgressDarkGray
= 92
149 struct hibernate_graphics_t
151 unsigned long physicalAddress
; // Base address of video memory
152 unsigned long mode
; //
153 unsigned long rowBytes
; // Number of bytes per pixel row
154 unsigned long width
; // Width
155 unsigned long height
; // Height
156 unsigned long depth
; // Pixel Depth
158 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
160 typedef struct hibernate_graphics_t hibernate_graphics_t
;
162 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
163 static const uint8_t gIOHibernateProgressAlpha \
164 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
166 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
167 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
168 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
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 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
178 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
179 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
180 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
181 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
188 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
190 IOReturn
IOHibernateSystemSleep(void);
191 IOReturn
IOHibernateSystemHasSlept(void);
192 IOReturn
IOHibernateSystemWake(void);
193 IOReturn
IOHibernateSystemPostWake(void);
195 #endif /* __cplusplus */
198 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
200 struct kern_direct_file_io_ref_t
*
201 kern_open_file_for_direct_io(const char * name
,
202 kern_get_file_extents_callback_t callback
,
205 uint64_t * partitionbase_result
,
206 uint64_t * maxiocount_result
);
208 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
210 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
211 int get_kernel_symfile(struct proc
*p
, char **symfile
);
212 #endif /* _SYS_CONF_H_ */
214 hibernate_page_list_t
*
215 hibernate_page_list_allocate(void);
218 hibernate_setup(IOHibernateImageHeader
* header
,
219 uint32_t free_page_ratio
,
220 uint32_t free_page_time
,
221 hibernate_page_list_t
** page_list_ret
,
222 hibernate_page_list_t
** page_list_wired_ret
,
223 boolean_t
* encryptedswap
);
225 hibernate_teardown(hibernate_page_list_t
* page_list
,
226 hibernate_page_list_t
* page_list_wired
);
229 hibernate_processor_setup(IOHibernateImageHeader
* header
);
232 hibernate_vm_lock(void);
234 hibernate_vm_unlock(void);
237 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
238 hibernate_page_list_t
* page_list_wired
,
239 uint32_t * pagesOut
);
242 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
243 hibernate_page_list_t
* page_list_wired
,
244 uint32_t * pagesOut
);
246 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
249 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
250 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
253 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
255 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
258 hibernate_page_list_count(hibernate_page_list_t
*list
, uint32_t set
, uint32_t page
);
261 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
264 hibernate_machine_init(void);
266 hibernate_write_image(void);
269 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
271 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
273 extern uint32_t gIOHibernateState
;
274 extern uint32_t gIOHibernateMode
;
275 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
276 extern uint8_t gIOHibernateRestoreStack
[];
277 extern uint8_t gIOHibernateRestoreStackEnd
[];
278 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
279 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
280 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
282 #define HIBLOG(fmt, args...) \
283 { kprintf(fmt, ## args); printf(fmt, ## args); }
285 #define HIBPRINT(fmt, args...) \
286 { kprintf(fmt, ## args); }
290 // gIOHibernateState, kIOHibernateStateKey
293 kIOHibernateStateInactive
= 0,
294 kIOHibernateStateHibernating
= 1, /* writing image */
295 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
298 // gIOHibernateMode, kIOHibernateModeKey
301 kIOHibernateModeOn
= 0x00000001,
302 kIOHibernateModeSleep
= 0x00000002,
303 kIOHibernateModeEncrypt
= 0x00000004,
305 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
306 kIOHibernateModeDiscardCleanActive
= 0x00000010
309 // IOHibernateImageHeader.signature
312 kIOHibernateHeaderSignature
= 0x73696d65,
313 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
316 // kind for hibernate_set_page_state()
319 kIOHibernatePageStateFree
= 0,
320 kIOHibernatePageStateWiredSave
= 1,
321 kIOHibernatePageStateUnwiredSave
= 2
324 #define kIOHibernateModeKey "Hibernate Mode"
325 #define kIOHibernateFileKey "Hibernate File"
326 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
327 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
329 #define kIOHibernateStateKey "IOHibernateState"
330 #define kIOHibernateFeatureKey "Hibernation"
331 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
333 #define kIOHibernateBootImageKey "boot-image"
334 #define kIOHibernateBootImageKeyKey "boot-image-key"
335 #define kIOHibernateBootSignatureKey "boot-signature"
337 #define kIOHibernateMemorySignatureKey "memory-signature"
338 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
339 #define kIOHibernateMachineSignatureKey "machine-signature"