2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
31 #include <crypto/aes.h>
34 struct IOPolledFileExtent
39 typedef struct IOPolledFileExtent IOPolledFileExtent
;
41 struct IOHibernateImageHeader
46 uint32_t restore1CodePage
;
47 uint32_t restore1PageCount
;
48 uint32_t restore1CodeOffset
;
49 uint32_t restore1StackOffset
;
58 uint32_t actualRestore1Sum
;
59 uint32_t actualImage1Sum
;
60 uint32_t actualImage2Sum
;
62 uint32_t actualUncompressedPages
;
63 uint32_t conflictCount
;
67 uint32_t processorFlags
;
69 uint8_t reserved2
[24];
71 uint64_t encryptStart
;
72 uint64_t machineSignature
;
75 uint32_t previewPageListSize
;
79 uint32_t reserved
[82]; // make sizeof == 512
81 uint32_t fileExtentMapSize
;
82 IOPolledFileExtent fileExtentMap
[2];
84 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
87 struct hibernate_bitmap_t
94 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
96 struct hibernate_page_list_t
101 hibernate_bitmap_t bank_bitmap
[0];
103 typedef struct hibernate_page_list_t hibernate_page_list_t
;
105 struct hibernate_cryptwakevars_t
108 uint8_t aes_iv
[AES_BLOCK_SIZE
];
110 #warning undef _AES_H
113 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
115 struct hibernate_cryptvars_t
118 uint8_t aes_iv
[AES_BLOCK_SIZE
];
121 #warning undef _AES_H
124 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
129 kIOHibernateProgressCount
= 19,
130 kIOHibernateProgressWidth
= 7,
131 kIOHibernateProgressHeight
= 16,
132 kIOHibernateProgressSpacing
= 3,
133 kIOHibernateProgressOriginY
= 81,
135 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
137 kIOHibernateProgressLightGray
= 230,
138 kIOHibernateProgressMidGray
= 174,
139 kIOHibernateProgressDarkGray
= 92
142 struct hibernate_graphics_t
144 unsigned long physicalAddress
; // Base address of video memory
145 unsigned long mode
; //
146 unsigned long rowBytes
; // Number of bytes per pixel row
147 unsigned long width
; // Width
148 unsigned long height
; // Height
149 unsigned long depth
; // Pixel Depth
151 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
153 typedef struct hibernate_graphics_t hibernate_graphics_t
;
155 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
156 static const uint8_t gIOHibernateProgressAlpha \
157 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
159 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
160 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
161 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
162 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
163 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
164 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
165 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
166 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
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 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
173 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
174 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
181 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
183 IOReturn
IOHibernateSystemSleep(void);
184 IOReturn
IOHibernateSystemHasSlept(void);
185 IOReturn
IOHibernateSystemWake(void);
186 IOReturn
IOHibernateSystemPostWake(void);
188 #endif /* __cplusplus */
191 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
193 struct kern_direct_file_io_ref_t
*
194 kern_open_file_for_direct_io(const char * name
,
195 kern_get_file_extents_callback_t callback
,
198 uint64_t * partitionbase_result
,
199 uint64_t * maxiocount_result
);
201 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
203 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
204 int get_kernel_symfile(struct proc
*p
, char **symfile
);
205 #endif /* _SYS_CONF_H_ */
207 hibernate_page_list_t
*
208 hibernate_page_list_allocate(void);
211 hibernate_setup(IOHibernateImageHeader
* header
,
212 uint32_t free_page_ratio
,
213 uint32_t free_page_time
,
214 hibernate_page_list_t
** page_list_ret
,
215 hibernate_page_list_t
** page_list_wired_ret
,
216 boolean_t
* encryptedswap
);
218 hibernate_teardown(hibernate_page_list_t
* page_list
,
219 hibernate_page_list_t
* page_list_wired
);
222 hibernate_processor_setup(IOHibernateImageHeader
* header
);
225 hibernate_vm_lock(void);
227 hibernate_vm_unlock(void);
230 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
231 hibernate_page_list_t
* page_list_wired
,
232 uint32_t * pagesOut
);
235 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
236 hibernate_page_list_t
* page_list_wired
,
237 uint32_t * pagesOut
);
239 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
242 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
243 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
246 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
248 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
251 hibernate_page_list_count(hibernate_page_list_t
*list
, uint32_t set
, uint32_t page
);
254 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
257 hibernate_machine_init(void);
259 hibernate_write_image(void);
262 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
264 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
266 extern uint32_t gIOHibernateState
;
267 extern uint32_t gIOHibernateMode
;
268 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
269 extern uint8_t gIOHibernateRestoreStack
[];
270 extern uint8_t gIOHibernateRestoreStackEnd
[];
271 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
272 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
273 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
275 #define HIBLOG(fmt, args...) \
276 { kprintf(fmt, ## args); printf(fmt, ## args); }
278 #define HIBPRINT(fmt, args...) \
279 { kprintf(fmt, ## args); }
283 // gIOHibernateState, kIOHibernateStateKey
286 kIOHibernateStateInactive
= 0,
287 kIOHibernateStateHibernating
= 1, /* writing image */
288 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
291 // gIOHibernateMode, kIOHibernateModeKey
294 kIOHibernateModeOn
= 0x00000001,
295 kIOHibernateModeSleep
= 0x00000002,
296 kIOHibernateModeEncrypt
= 0x00000004,
298 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
299 kIOHibernateModeDiscardCleanActive
= 0x00000010
302 // IOHibernateImageHeader.signature
305 kIOHibernateHeaderSignature
= 0x73696d65,
306 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
309 // kind for hibernate_set_page_state()
312 kIOHibernatePageStateFree
= 0,
313 kIOHibernatePageStateWiredSave
= 1,
314 kIOHibernatePageStateUnwiredSave
= 2
317 #define kIOHibernateModeKey "Hibernate Mode"
318 #define kIOHibernateFileKey "Hibernate File"
319 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
320 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
322 #define kIOHibernateStateKey "IOHibernateState"
323 #define kIOHibernateFeatureKey "Hibernation"
324 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
326 #define kIOHibernateBootImageKey "boot-image"
327 #define kIOHibernateBootImageKeyKey "boot-image-key"
328 #define kIOHibernateBootSignatureKey "boot-signature"
330 #define kIOHibernateMemorySignatureKey "memory-signature"
331 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
332 #define kIOHibernateMachineSignatureKey "machine-signature"