2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
30 #include <crypto/aes.h>
33 struct IOPolledFileExtent
38 typedef struct IOPolledFileExtent IOPolledFileExtent
;
40 struct IOHibernateImageHeader
45 uint32_t restore1CodePage
;
46 uint32_t restore1PageCount
;
47 uint32_t restore1CodeOffset
;
48 uint32_t restore1StackOffset
;
57 uint32_t actualRestore1Sum
;
58 uint32_t actualImage1Sum
;
59 uint32_t actualImage2Sum
;
61 uint32_t actualUncompressedPages
;
62 uint32_t conflictCount
;
66 uint32_t processorFlags
;
68 uint8_t reserved2
[24];
70 uint64_t encryptStart
;
71 uint64_t machineSignature
;
74 uint32_t previewPageListSize
;
78 uint32_t reserved
[82]; // make sizeof == 512
80 uint32_t fileExtentMapSize
;
81 IOPolledFileExtent fileExtentMap
[2];
83 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
86 struct hibernate_bitmap_t
93 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
95 struct hibernate_page_list_t
100 hibernate_bitmap_t bank_bitmap
[0];
102 typedef struct hibernate_page_list_t hibernate_page_list_t
;
104 struct hibernate_cryptwakevars_t
107 uint8_t aes_iv
[AES_BLOCK_SIZE
];
109 #warning undef _AES_H
112 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
114 struct hibernate_cryptvars_t
117 uint8_t aes_iv
[AES_BLOCK_SIZE
];
120 #warning undef _AES_H
123 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
128 kIOHibernateProgressCount
= 19,
129 kIOHibernateProgressWidth
= 7,
130 kIOHibernateProgressHeight
= 16,
131 kIOHibernateProgressSpacing
= 3,
132 kIOHibernateProgressOriginY
= 81,
134 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
136 kIOHibernateProgressLightGray
= 230,
137 kIOHibernateProgressMidGray
= 174,
138 kIOHibernateProgressDarkGray
= 92
141 struct hibernate_graphics_t
143 unsigned long physicalAddress
; // Base address of video memory
144 unsigned long mode
; //
145 unsigned long rowBytes
; // Number of bytes per pixel row
146 unsigned long width
; // Width
147 unsigned long height
; // Height
148 unsigned long depth
; // Pixel Depth
150 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
152 typedef struct hibernate_graphics_t hibernate_graphics_t
;
154 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
155 static const uint8_t gIOHibernateProgressAlpha \
156 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
158 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
159 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
160 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
161 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
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 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
172 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
173 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
180 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
182 IOReturn
IOHibernateSystemSleep(void);
183 IOReturn
IOHibernateSystemHasSlept(void);
184 IOReturn
IOHibernateSystemWake(void);
185 IOReturn
IOHibernateSystemPostWake(void);
187 #endif /* __cplusplus */
190 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
192 struct kern_direct_file_io_ref_t
*
193 kern_open_file_for_direct_io(const char * name
,
194 kern_get_file_extents_callback_t callback
,
197 uint64_t * partitionbase_result
,
198 uint64_t * maxiocount_result
);
200 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
202 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
203 int get_kernel_symfile(struct proc
*p
, char **symfile
);
204 #endif /* _SYS_CONF_H_ */
206 hibernate_page_list_t
*
207 hibernate_page_list_allocate(void);
210 hibernate_setup(IOHibernateImageHeader
* header
,
211 uint32_t free_page_ratio
,
212 uint32_t free_page_time
,
213 hibernate_page_list_t
** page_list_ret
,
214 hibernate_page_list_t
** page_list_wired_ret
,
215 boolean_t
* encryptedswap
);
217 hibernate_teardown(hibernate_page_list_t
* page_list
,
218 hibernate_page_list_t
* page_list_wired
);
221 hibernate_processor_setup(IOHibernateImageHeader
* header
);
224 hibernate_vm_lock(void);
226 hibernate_vm_unlock(void);
229 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
230 hibernate_page_list_t
* page_list_wired
,
231 uint32_t * pagesOut
);
234 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
235 hibernate_page_list_t
* page_list_wired
,
236 uint32_t * pagesOut
);
238 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
241 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
242 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
245 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
247 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
250 hibernate_page_list_count(hibernate_page_list_t
*list
, uint32_t set
, uint32_t page
);
253 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
256 hibernate_machine_init(void);
258 hibernate_write_image(void);
261 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
263 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
265 extern uint32_t gIOHibernateState
;
266 extern uint32_t gIOHibernateMode
;
267 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
268 extern uint8_t gIOHibernateRestoreStack
[];
269 extern uint8_t gIOHibernateRestoreStackEnd
[];
270 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
271 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
272 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
274 #define HIBLOG(fmt, args...) \
275 { kprintf(fmt, ## args); printf(fmt, ## args); }
277 #define HIBPRINT(fmt, args...) \
278 { kprintf(fmt, ## args); }
282 // gIOHibernateState, kIOHibernateStateKey
285 kIOHibernateStateInactive
= 0,
286 kIOHibernateStateHibernating
= 1, /* writing image */
287 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
290 // gIOHibernateMode, kIOHibernateModeKey
293 kIOHibernateModeOn
= 0x00000001,
294 kIOHibernateModeSleep
= 0x00000002,
295 kIOHibernateModeEncrypt
= 0x00000004,
297 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
298 kIOHibernateModeDiscardCleanActive
= 0x00000010
301 // IOHibernateImageHeader.signature
304 kIOHibernateHeaderSignature
= 0x73696d65,
305 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
308 // kind for hibernate_set_page_state()
311 kIOHibernatePageStateFree
= 0,
312 kIOHibernatePageStateWiredSave
= 1,
313 kIOHibernatePageStateUnwiredSave
= 2
316 #define kIOHibernateModeKey "Hibernate Mode"
317 #define kIOHibernateFileKey "Hibernate File"
318 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
319 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
321 #define kIOHibernateStateKey "IOHibernateState"
322 #define kIOHibernateFeatureKey "Hibernation"
323 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
325 #define kIOHibernateBootImageKey "boot-image"
326 #define kIOHibernateBootImageKeyKey "boot-image-key"
327 #define kIOHibernateBootSignatureKey "boot-signature"
329 #define kIOHibernateMemorySignatureKey "memory-signature"
330 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
331 #define kIOHibernateMachineSignatureKey "machine-signature"