Root/
Source at commit 2740 created 8 years 11 months ago. By ifabio, sync with trunk. | |
---|---|
1 | /*␊ |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@␊ |
5 | *␊ |
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.␊ |
14 | *␊ |
15 | * Please obtain a copy of the License at␊ |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file.␊ |
17 | *␊ |
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.␊ |
25 | *␊ |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@␊ |
27 | */␊ |
28 | ␊ |
29 | #ifdef __cplusplus␊ |
30 | extern "C" {␊ |
31 | #endif␊ |
32 | ␊ |
33 | #ifdef KERNEL␊ |
34 | #include <crypto/aes.h>␊ |
35 | #endif␊ |
36 | ␊ |
37 | struct IOPolledFileExtent␊ |
38 | {␊ |
39 | ␉uint64_t␉start;␊ |
40 | ␉uint64_t␉length;␊ |
41 | };␊ |
42 | typedef struct IOPolledFileExtent IOPolledFileExtent;␊ |
43 | ␊ |
44 | struct IOHibernateImageHeader␊ |
45 | {␊ |
46 | ␉uint64_t␉imageSize;␊ |
47 | ␉uint64_t␉image1Size;␊ |
48 | ␊ |
49 | ␉uint32_t␉restore1CodePhysPage;␊ |
50 | ␉uint32_t␉reserved1;␊ |
51 | ␉uint64_t␉restore1CodeVirt;␊ |
52 | ␉uint32_t␉restore1PageCount;␊ |
53 | ␉uint32_t␉restore1CodeOffset;␊ |
54 | ␉uint32_t␉restore1StackOffset;␊ |
55 | ␊ |
56 | uint32_t␉pageCount;␊ |
57 | uint32_t␉bitmapSize;␊ |
58 | ␊ |
59 | uint32_t␉restore1Sum;␊ |
60 | uint32_t␉image1Sum;␊ |
61 | uint32_t␉image2Sum;␊ |
62 | ␊ |
63 | uint32_t␉actualRestore1Sum;␊ |
64 | uint32_t␉actualImage1Sum;␊ |
65 | uint32_t␉actualImage2Sum;␊ |
66 | ␊ |
67 | uint32_t␉actualUncompressedPages;␊ |
68 | uint32_t␉conflictCount;␊ |
69 | uint32_t␉nextFree;␊ |
70 | ␊ |
71 | uint32_t␉signature;␊ |
72 | uint32_t␉processorFlags;␊ |
73 | ␊ |
74 | ␉uint32_t␉runtimePages;␊ |
75 | ␉uint32_t␉runtimePageCount;␊ |
76 | ␊ |
77 | ␉uint8_t␉␉reserved2[16];␊ |
78 | ␊ |
79 | ␉uint64_t␉encryptStart;␊ |
80 | ␉uint64_t␉machineSignature;␊ |
81 | ␊ |
82 | ␉uint32_t␉previewSize;␊ |
83 | ␉uint32_t␉previewPageListSize;␊ |
84 | ␊ |
85 | ␉uint32_t␉diag[4];␊ |
86 | ␊ |
87 | ␉int32_t␉␉graphicsInfoOffset;␊ |
88 | ␉int32_t␉␉cryptVarsOffset;␊ |
89 | ␉int32_t␉␉memoryMapOffset;␊ |
90 | ␉uint32_t␉memoryMapSize;␊ |
91 | ␉uint32_t␉systemTableOffset;␊ |
92 | ␊ |
93 | ␉uint32_t␉reserved[77];␉␉// make sizeof == 512␊ |
94 | ␊ |
95 | ␉uint32_t␉␉fileExtentMapSize;␊ |
96 | ␉IOPolledFileExtent␉fileExtentMap[2];␊ |
97 | };␊ |
98 | typedef struct IOHibernateImageHeader IOHibernateImageHeader;␊ |
99 | ␊ |
100 | ␊ |
101 | struct hibernate_bitmap_t␊ |
102 | {␊ |
103 | ␉uint32_t␉first_page;␊ |
104 | ␉uint32_t␉last_page;␊ |
105 | ␉uint32_t␉bitmapwords;␊ |
106 | ␉uint32_t␉bitmap[0];␊ |
107 | };␊ |
108 | typedef struct hibernate_bitmap_t hibernate_bitmap_t;␊ |
109 | ␊ |
110 | struct hibernate_page_list_t␊ |
111 | {␊ |
112 | ␉uint32_t␉␉ list_size;␊ |
113 | ␉uint32_t␉␉ page_count;␊ |
114 | ␉uint32_t␉␉ bank_count;␊ |
115 | ␉hibernate_bitmap_t bank_bitmap[0];␊ |
116 | };␊ |
117 | typedef struct hibernate_page_list_t hibernate_page_list_t;␊ |
118 | ␊ |
119 | #if defined(_AES_H)␊ |
120 | ␊ |
121 | struct hibernate_cryptwakevars_t␊ |
122 | {␊ |
123 | ␉uint8_t aes_iv[AES_BLOCK_SIZE];␊ |
124 | };␊ |
125 | typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;␊ |
126 | ␊ |
127 | struct hibernate_cryptvars_t␊ |
128 | {␊ |
129 | ␉uint8_t aes_iv[AES_BLOCK_SIZE];␊ |
130 | ␉aes_ctx ctx;␊ |
131 | };␊ |
132 | typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;␊ |
133 | ␊ |
134 | #endif /* defined(_AES_H) */␊ |
135 | ␊ |
136 | ␊ |
137 | enum ␊ |
138 | {␊ |
139 | ␉kIOHibernateProgressCount = 19,␊ |
140 | ␉kIOHibernateProgressWidth = 7,␊ |
141 | ␉kIOHibernateProgressHeight = 16,␊ |
142 | ␉kIOHibernateProgressSpacing = 3,␊ |
143 | ␉kIOHibernateProgressOriginY = 81,␊ |
144 | ␊ |
145 | ␉kIOHibernateProgressSaveUnderSize = 2*5+14*2,␊ |
146 | ␊ |
147 | ␉kIOHibernateProgressLightGray = 230,␊ |
148 | ␉kIOHibernateProgressMidGray = 174,␊ |
149 | ␉kIOHibernateProgressDarkGray = 92␊ |
150 | };␊ |
151 | ␊ |
152 | enum {␊ |
153 | ␉kIOHibernatePostWriteSleep = 0,␊ |
154 | ␉kIOHibernatePostWriteWake = 1,␊ |
155 | ␉kIOHibernatePostWriteHalt = 2,␊ |
156 | ␉kIOHibernatePostWriteRestart = 3␊ |
157 | };␊ |
158 | ␊ |
159 | ␊ |
160 | struct hibernate_graphics_t␊ |
161 | {␊ |
162 | ␉uint32_t physicalAddress;␉␉// Base address of video memory␊ |
163 | ␉uint32_t mode;␉␉␉// ␊ |
164 | ␉uint32_t rowBytes; ␉␉// Number of bytes per pixel row␊ |
165 | ␉uint32_t width; ␉␉// Width␊ |
166 | ␉uint32_t height; ␉␉// Height␊ |
167 | ␉uint32_t depth; ␉␉// Pixel Depth␊ |
168 | ␊ |
169 | ␉uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];␊ |
170 | };␊ |
171 | typedef struct hibernate_graphics_t hibernate_graphics_t;␊ |
172 | ␊ |
173 | #define DECLARE_IOHIBERNATEPROGRESSALPHA␉␉␉␉\␊ |
174 | static const uint8_t gIOHibernateProgressAlpha␉␉␉\␊ |
175 | [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = ␉\␊ |
176 | {␉␉␉␉␉␉␉␉\␊ |
177 | ␉{ 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 },␉␉␉\␊ |
178 | ␉{ 0x51,0xff,0xff,0xff,0xff,0xff,0x51 },␉␉␉\␊ |
179 | ␉{ 0xae,0xff,0xff,0xff,0xff,0xff,0xae },␉␉␉\␊ |
180 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
181 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
182 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
183 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
184 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
185 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
186 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
187 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
188 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
189 | ␉{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },␉␉␉\␊ |
190 | ␉{ 0xae,0xff,0xff,0xff,0xff,0xff,0xae },␉␉␉\␊ |
191 | ␉{ 0x54,0xff,0xff,0xff,0xff,0xff,0x54 },␉␉␉\␊ |
192 | ␉{ 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 }␉␉␉\␊ |
193 | };␊ |
194 | ␊ |
195 | #ifdef KERNEL␊ |
196 | ␊ |
197 | #ifdef __cplusplus␊ |
198 | ␊ |
199 | void IOHibernateSystemInit(IOPMrootDomain * rootDomain);␊ |
200 | ␊ |
201 | IOReturn IOHibernateSystemSleep(void);␊ |
202 | IOReturn IOHibernateSystemHasSlept(void);␊ |
203 | IOReturn IOHibernateSystemWake(void);␊ |
204 | IOReturn IOHibernateSystemPostWake(void);␊ |
205 | ␊ |
206 | #endif /* __cplusplus */␊ |
207 | ␊ |
208 | #ifdef _SYS_CONF_H_␊ |
209 | typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);␊ |
210 | ␊ |
211 | struct kern_direct_file_io_ref_t *␊ |
212 | kern_open_file_for_direct_io(const char * name,␊ |
213 | ␉␉␉ kern_get_file_extents_callback_t callback,␊ |
214 | ␉␉␉ void * callback_ref,␊ |
215 | ␉␉␉ dev_t * device,␊ |
216 | uint64_t * partitionbase_result,␊ |
217 | uint64_t * maxiocount_result);␊ |
218 | void␊ |
219 | kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);␊ |
220 | int␊ |
221 | kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);␊ |
222 | int get_kernel_symfile(struct proc *p, char const **symfile);␊ |
223 | #endif /* _SYS_CONF_H_ */␊ |
224 | ␊ |
225 | hibernate_page_list_t *␊ |
226 | hibernate_page_list_allocate(void);␊ |
227 | ␊ |
228 | kern_return_t␊ |
229 | hibernate_setup(IOHibernateImageHeader * header,␊ |
230 | uint32_t free_page_ratio,␊ |
231 | uint32_t free_page_time,␊ |
232 | ␉␉␉hibernate_page_list_t ** page_list_ret,␊ |
233 | ␉␉␉hibernate_page_list_t ** page_list_wired_ret,␊ |
234 | boolean_t * encryptedswap);␊ |
235 | kern_return_t␊ |
236 | hibernate_teardown(hibernate_page_list_t * page_list,␊ |
237 | hibernate_page_list_t * page_list_wired);␊ |
238 | ␊ |
239 | kern_return_t␊ |
240 | hibernate_processor_setup(IOHibernateImageHeader * header);␊ |
241 | ␊ |
242 | void␊ |
243 | hibernate_vm_lock(void);␊ |
244 | void␊ |
245 | hibernate_vm_unlock(void);␊ |
246 | ␊ |
247 | // mark pages not to be saved, based on VM system accounting␊ |
248 | void␊ |
249 | hibernate_page_list_setall(hibernate_page_list_t * page_list,␊ |
250 | ␉␉␉ hibernate_page_list_t * page_list_wired,␊ |
251 | ␉␉␉ uint32_t * pagesOut);␊ |
252 | ␊ |
253 | // mark pages to be saved, or pages not to be saved but available␊ |
254 | // for scratch usage during restore␊ |
255 | void␊ |
256 | hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,␊ |
257 | hibernate_page_list_t * page_list_wired,␊ |
258 | uint32_t * pagesOut);␊ |
259 | ␊ |
260 | // mark pages not to be saved and not for scratch usage during restore␊ |
261 | void␊ |
262 | hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,␊ |
263 | ␉␉␉␉ hibernate_page_list_t * page_list_wired,␊ |
264 | ␉␉␉␉ uint32_t * pagesOut);␊ |
265 | ␊ |
266 | void␊ |
267 | hibernate_page_list_discard(hibernate_page_list_t * page_list);␊ |
268 | ␊ |
269 | void␊ |
270 | hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,␊ |
271 | ␉␉␉␉vm_offset_t ppnum, vm_offset_t count, uint32_t kind);␊ |
272 | ␊ |
273 | void␊ |
274 | hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);␊ |
275 | ␊ |
276 | boolean_t␊ |
277 | hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);␊ |
278 | ␊ |
279 | hibernate_bitmap_t *␊ |
280 | hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);␊ |
281 | ␊ |
282 | uint32_t␊ |
283 | hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);␊ |
284 | ␊ |
285 | void ␊ |
286 | hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);␊ |
287 | ␊ |
288 | void␊ |
289 | hibernate_machine_init(void);␊ |
290 | ␊ |
291 | uint32_t␊ |
292 | hibernate_write_image(void);␊ |
293 | ␊ |
294 | long␊ |
295 | hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);␊ |
296 | long␊ |
297 | hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);␊ |
298 | void␊ |
299 | hibernate_newruntime_map(void * map, vm_size_t map_size, ␊ |
300 | ␉␉␉ uint32_t system_table_offset);␊ |
301 | ␊ |
302 | ␊ |
303 | extern uint32_t gIOHibernateState;␊ |
304 | extern uint32_t gIOHibernateMode;␊ |
305 | extern uint32_t gIOHibernateFreeTime;␉// max time to spend freeing pages (ms)␊ |
306 | extern uint8_t gIOHibernateRestoreStack[];␊ |
307 | extern uint8_t gIOHibernateRestoreStackEnd[];␊ |
308 | extern IOHibernateImageHeader * gIOHibernateCurrentHeader;␊ |
309 | extern hibernate_graphics_t * gIOHibernateGraphicsInfo;␊ |
310 | extern hibernate_cryptwakevars_t * gIOHibernateCryptWakeVars;␊ |
311 | ␊ |
312 | #define HIBLOG(fmt, args...)␉\␊ |
313 | ␉{ kprintf(fmt, ## args); printf(fmt, ## args); }␊ |
314 | ␊ |
315 | #define HIBPRINT(fmt, args...)␉\␊ |
316 | ␉{ kprintf(fmt, ## args); }␊ |
317 | ␊ |
318 | #endif /* KERNEL */␊ |
319 | ␊ |
320 | // gIOHibernateState, kIOHibernateStateKey␊ |
321 | enum␊ |
322 | {␊ |
323 | ␉kIOHibernateStateInactive = 0,␊ |
324 | ␉kIOHibernateStateHibernating ␉ = 1,␉/* writing image */␊ |
325 | ␉kIOHibernateStateWakingFromHibernate = 2␉/* booted and restored image */␊ |
326 | };␊ |
327 | ␊ |
328 | // gIOHibernateMode, kIOHibernateModeKey␊ |
329 | enum␊ |
330 | {␊ |
331 | ␉kIOHibernateModeOn␉␉␉= 0x00000001,␊ |
332 | ␉kIOHibernateModeSleep␉␉␉= 0x00000002,␊ |
333 | ␉kIOHibernateModeEncrypt␉␉␉= 0x00000004,␊ |
334 | ␉kIOHibernateModeDiscardCleanInactive␉= 0x00000008,␊ |
335 | ␉kIOHibernateModeDiscardCleanActive␉= 0x00000010,␊ |
336 | ␉kIOHibernateModeSwitch␉␉␉= 0x00000020,␊ |
337 | ␉kIOHibernateModeRestart␉␉␉= 0x00000040␊ |
338 | };␊ |
339 | ␊ |
340 | // IOHibernateImageHeader.signature␊ |
341 | enum␊ |
342 | {␊ |
343 | ␉kIOHibernateHeaderSignature = 0x73696d65,␊ |
344 | ␉kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a␊ |
345 | };␊ |
346 | ␊ |
347 | // kind for hibernate_set_page_state()␊ |
348 | enum␊ |
349 | {␊ |
350 | ␉kIOHibernatePageStateFree = 0,␊ |
351 | ␉kIOHibernatePageStateWiredSave = 1,␊ |
352 | ␉kIOHibernatePageStateUnwiredSave = 2␊ |
353 | };␊ |
354 | ␊ |
355 | #define kIOHibernateModeKey␉␉"Hibernate Mode"␊ |
356 | #define kIOHibernateFileKey␉␉"Hibernate File"␊ |
357 | #define kIOHibernateFreeRatioKey␉"Hibernate Free Ratio"␊ |
358 | #define kIOHibernateFreeTimeKey␉␉"Hibernate Free Time"␊ |
359 | ␊ |
360 | #define kIOHibernateStateKey␉␉"IOHibernateState"␊ |
361 | #define kIOHibernateFeatureKey␉␉"Hibernation"␊ |
362 | #define kIOHibernatePreviewBufferKey␉"IOPreviewBuffer"␊ |
363 | ␊ |
364 | #define kIOHibernatePreviewActiveKey␉"IOHibernatePreviewActive"␊ |
365 | // values for kIOHibernatePreviewActiveKey␊ |
366 | enum {␊ |
367 | ␉kIOHibernatePreviewActive = 0x00000001,␊ |
368 | ␉kIOHibernatePreviewUpdates = 0x00000002␊ |
369 | };␊ |
370 | ␊ |
371 | #define kIOHibernateBootImageKey␉"boot-image"␊ |
372 | #define kIOHibernateBootImageKeyKey␉"boot-image-key"␊ |
373 | #define kIOHibernateBootSignatureKey␉"boot-signature"␊ |
374 | ␊ |
375 | #define kIOHibernateMemorySignatureKey␉ "memory-signature"␊ |
376 | #define kIOHibernateMemorySignatureEnvKey "mem-sig"␊ |
377 | #define kIOHibernateMachineSignatureKey␉ "machine-signature"␊ |
378 | ␊ |
379 | #define kIOHibernateRTCVariablesKey␉"IOHibernateRTCVariables"␊ |
380 | ␊ |
381 | #define kIOHibernateBootSwitchVarsKey␉␉␉"boot-switch-vars"␊ |
382 | ␊ |
383 | ␊ |
384 | #ifdef __cplusplus␊ |
385 | }␊ |
386 | #endif␊ |
387 |