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 uint32_t runtimePages
;
69 uint32_t runtimePageCount
;
71 uint8_t reserved2
[16];
73 uint64_t encryptStart
;
74 uint64_t machineSignature
;
77 uint32_t previewPageListSize
;
81 int32_t graphicsInfoOffset
;
82 int32_t cryptVarsOffset
;
83 int32_t memoryMapOffset
;
84 uint32_t memoryMapSize
;
85 uint32_t systemTableOffset
;
87 uint32_t reserved
[77]; // make sizeof == 512
89 uint32_t fileExtentMapSize
;
90 IOPolledFileExtent fileExtentMap
[2];
92 typedef struct IOHibernateImageHeader IOHibernateImageHeader
;
95 struct hibernate_bitmap_t
102 typedef struct hibernate_bitmap_t hibernate_bitmap_t
;
104 struct hibernate_page_list_t
109 hibernate_bitmap_t bank_bitmap
[0];
111 typedef struct hibernate_page_list_t hibernate_page_list_t
;
113 struct hibernate_cryptwakevars_t
116 uint8_t aes_iv
[AES_BLOCK_SIZE
];
118 #warning undef _AES_H
121 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t
;
123 struct hibernate_cryptvars_t
126 uint8_t aes_iv
[AES_BLOCK_SIZE
];
129 #warning undef _AES_H
132 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t
;
137 kIOHibernateProgressCount
= 19,
138 kIOHibernateProgressWidth
= 7,
139 kIOHibernateProgressHeight
= 16,
140 kIOHibernateProgressSpacing
= 3,
141 kIOHibernateProgressOriginY
= 81,
143 kIOHibernateProgressSaveUnderSize
= 2*5+14*2,
145 kIOHibernateProgressLightGray
= 230,
146 kIOHibernateProgressMidGray
= 174,
147 kIOHibernateProgressDarkGray
= 92
150 struct hibernate_graphics_t
152 unsigned long physicalAddress
; // Base address of video memory
153 unsigned long mode
; //
154 unsigned long rowBytes
; // Number of bytes per pixel row
155 unsigned long width
; // Width
156 unsigned long height
; // Height
157 unsigned long depth
; // Pixel Depth
159 uint8_t progressSaveUnder
[kIOHibernateProgressCount
][kIOHibernateProgressSaveUnderSize
];
161 typedef struct hibernate_graphics_t hibernate_graphics_t
;
163 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
164 static const uint8_t gIOHibernateProgressAlpha \
165 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
167 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
168 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
169 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
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 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
180 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
181 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
182 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
189 void IOHibernateSystemInit(IOPMrootDomain
* rootDomain
);
191 IOReturn
IOHibernateSystemSleep(void);
192 IOReturn
IOHibernateSystemHasSlept(void);
193 IOReturn
IOHibernateSystemWake(void);
194 IOReturn
IOHibernateSystemPostWake(void);
196 #endif /* __cplusplus */
199 typedef void (*kern_get_file_extents_callback_t
)(void * ref
, uint64_t start
, uint64_t size
);
201 struct kern_direct_file_io_ref_t
*
202 kern_open_file_for_direct_io(const char * name
,
203 kern_get_file_extents_callback_t callback
,
206 uint64_t * partitionbase_result
,
207 uint64_t * maxiocount_result
);
209 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t
* ref
);
211 kern_write_file(struct kern_direct_file_io_ref_t
* ref
, off_t offset
, caddr_t addr
, vm_size_t len
);
212 int get_kernel_symfile(struct proc
*p
, char **symfile
);
213 #endif /* _SYS_CONF_H_ */
215 hibernate_page_list_t
*
216 hibernate_page_list_allocate(void);
219 hibernate_setup(IOHibernateImageHeader
* header
,
220 uint32_t free_page_ratio
,
221 uint32_t free_page_time
,
222 hibernate_page_list_t
** page_list_ret
,
223 hibernate_page_list_t
** page_list_wired_ret
,
224 boolean_t
* encryptedswap
);
226 hibernate_teardown(hibernate_page_list_t
* page_list
,
227 hibernate_page_list_t
* page_list_wired
);
230 hibernate_processor_setup(IOHibernateImageHeader
* header
);
233 hibernate_vm_lock(void);
235 hibernate_vm_unlock(void);
237 // mark pages not to be saved, based on VM system accounting
239 hibernate_page_list_setall(hibernate_page_list_t
* page_list
,
240 hibernate_page_list_t
* page_list_wired
,
241 uint32_t * pagesOut
);
243 // mark pages to be saved, or pages not to be saved but available
244 // for scratch usage during restore
246 hibernate_page_list_setall_machine(hibernate_page_list_t
* page_list
,
247 hibernate_page_list_t
* page_list_wired
,
248 uint32_t * pagesOut
);
250 // mark pages not to be saved and not for scratch usage during restore
252 hibernate_page_list_set_volatile( hibernate_page_list_t
* page_list
,
253 hibernate_page_list_t
* page_list_wired
,
254 uint32_t * pagesOut
);
257 hibernate_page_list_discard(hibernate_page_list_t
* page_list
);
260 hibernate_set_page_state(hibernate_page_list_t
* page_list
, hibernate_page_list_t
* page_list_wired
,
261 vm_offset_t ppnum
, vm_offset_t count
, uint32_t kind
);
264 hibernate_page_bitset(hibernate_page_list_t
* list
, boolean_t set
, uint32_t page
);
267 hibernate_page_bittst(hibernate_page_list_t
* list
, uint32_t page
);
270 hibernate_page_bitmap_pin(hibernate_page_list_t
* list
, uint32_t * page
);
273 hibernate_page_bitmap_count(hibernate_bitmap_t
* bitmap
, uint32_t set
, uint32_t page
);
276 hibernate_restore_phys_page(uint64_t src
, uint64_t dst
, uint32_t len
, uint32_t procFlags
);
279 hibernate_machine_init(void);
281 hibernate_write_image(void);
284 hibernate_machine_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
286 hibernate_kernel_entrypoint(IOHibernateImageHeader
* header
, void * p2
, void * p3
, void * p4
);
288 hibernate_newruntime_map(void * map
, vm_size_t map_size
,
289 uint32_t system_table_offset
);
292 extern uint32_t gIOHibernateState
;
293 extern uint32_t gIOHibernateMode
;
294 extern uint32_t gIOHibernateFreeTime
; // max time to spend freeing pages (ms)
295 extern uint8_t gIOHibernateRestoreStack
[];
296 extern uint8_t gIOHibernateRestoreStackEnd
[];
297 extern IOHibernateImageHeader
* gIOHibernateCurrentHeader
;
298 extern hibernate_graphics_t
* gIOHibernateGraphicsInfo
;
299 extern hibernate_cryptwakevars_t
* gIOHibernateCryptWakeVars
;
301 #define HIBLOG(fmt, args...) \
302 { kprintf(fmt, ## args); printf(fmt, ## args); }
304 #define HIBPRINT(fmt, args...) \
305 { kprintf(fmt, ## args); }
309 // gIOHibernateState, kIOHibernateStateKey
312 kIOHibernateStateInactive
= 0,
313 kIOHibernateStateHibernating
= 1, /* writing image */
314 kIOHibernateStateWakingFromHibernate
= 2 /* booted and restored image */
317 // gIOHibernateMode, kIOHibernateModeKey
320 kIOHibernateModeOn
= 0x00000001,
321 kIOHibernateModeSleep
= 0x00000002,
322 kIOHibernateModeEncrypt
= 0x00000004,
324 kIOHibernateModeDiscardCleanInactive
= 0x00000008,
325 kIOHibernateModeDiscardCleanActive
= 0x00000010
328 // IOHibernateImageHeader.signature
331 kIOHibernateHeaderSignature
= 0x73696d65,
332 kIOHibernateHeaderInvalidSignature
= 0x7a7a7a7a
335 // kind for hibernate_set_page_state()
338 kIOHibernatePageStateFree
= 0,
339 kIOHibernatePageStateWiredSave
= 1,
340 kIOHibernatePageStateUnwiredSave
= 2
343 #define kIOHibernateModeKey "Hibernate Mode"
344 #define kIOHibernateFileKey "Hibernate File"
345 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
346 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
348 #define kIOHibernateStateKey "IOHibernateState"
349 #define kIOHibernateFeatureKey "Hibernation"
350 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
352 #define kIOHibernateBootImageKey "boot-image"
353 #define kIOHibernateBootImageKeyKey "boot-image-key"
354 #define kIOHibernateBootSignatureKey "boot-signature"
356 #define kIOHibernateMemorySignatureKey "memory-signature"
357 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
358 #define kIOHibernateMachineSignatureKey "machine-signature"
360 #define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"