Chameleon

Chameleon Svn Source Tree

Root/branches/cparm/i386/modules/HibernateEnabler/IOHibernatePrivate.h

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
30extern "C" {
31#endif
32
33#ifdef KERNEL
34#include <crypto/aes.h>
35#endif
36
37struct IOPolledFileExtent
38{
39 uint64_tstart;
40 uint64_tlength;
41};
42typedef struct IOPolledFileExtent IOPolledFileExtent;
43
44struct IOHibernateImageHeader
45{
46 uint64_timageSize;
47 uint64_timage1Size;
48
49 uint32_trestore1CodePage;
50 uint32_trestore1PageCount;
51 uint32_trestore1CodeOffset;
52 uint32_trestore1StackOffset;
53
54 uint32_tpageCount;
55 uint32_tbitmapSize;
56
57 uint32_trestore1Sum;
58 uint32_timage1Sum;
59 uint32_timage2Sum;
60
61 uint32_tactualRestore1Sum;
62 uint32_tactualImage1Sum;
63 uint32_tactualImage2Sum;
64
65 uint32_tactualUncompressedPages;
66 uint32_tconflictCount;
67 uint32_tnextFree;
68
69 uint32_tsignature;
70 uint32_tprocessorFlags;
71
72 uint32_t runtimePages;
73 uint32_t runtimePageCount;
74
75 uint8_treserved2[16];
76
77 uint64_tencryptStart;
78 uint64_tmachineSignature;
79
80 uint32_t previewSize;
81 uint32_t previewPageListSize;
82
83 uint32_tdiag[4];
84
85 int32_tgraphicsInfoOffset;
86 int32_tcryptVarsOffset;
87 int32_tmemoryMapOffset;
88 uint32_t memoryMapSize;
89 uint32_t systemTableOffset;
90
91 uint32_treserved[77];// make sizeof == 512
92
93 uint32_tfileExtentMapSize;
94 IOPolledFileExtentfileExtentMap[2];
95};
96typedef struct IOHibernateImageHeader IOHibernateImageHeader;
97
98struct IOHibernateImageHeader107
99{
100 uint64_timageSize;
101 uint64_timage1Size;
102
103 uint32_trestore1CodePhysPage;
104 uint32_t reserved1;
105 uint64_trestore1CodeVirt;
106 uint32_trestore1PageCount;
107 uint32_trestore1CodeOffset;
108 uint32_trestore1StackOffset;
109
110 uint32_tpageCount;
111 uint32_tbitmapSize;
112
113 uint32_trestore1Sum;
114 uint32_timage1Sum;
115 uint32_timage2Sum;
116
117 uint32_tactualRestore1Sum;
118 uint32_tactualImage1Sum;
119 uint32_tactualImage2Sum;
120
121 uint32_tactualUncompressedPages;
122 uint32_tconflictCount;
123 uint32_tnextFree;
124
125 uint32_tsignature;
126 uint32_tprocessorFlags;
127
128 uint32_t runtimePages;
129 uint32_t runtimePageCount;
130 uint64_t runtimeVirtualPages __attribute__ ((packed));
131
132 uint32_t performanceDataStart;
133 uint32_t performanceDataSize;
134
135 uint64_tencryptStart __attribute__ ((packed));
136 uint64_tmachineSignature __attribute__ ((packed));
137
138 uint32_t previewSize;
139 uint32_t previewPageListSize;
140
141 uint32_tdiag[4];
142
143 uint32_t handoffPages;
144 uint32_t handoffPageCount;
145
146 uint32_t systemTableOffset;
147
148 uint32_tdebugFlags;
149 uint32_toptions;
150
151 uint32_treserved[70];// make sizeof == 512
152
153 uint64_tencryptEnd __attribute__ ((packed));
154 uint64_tdeviceBase __attribute__ ((packed));
155
156 uint32_tfileExtentMapSize;
157 IOPolledFileExtentfileExtentMap[2];
158};
159
160
161typedef struct IOHibernateImageHeader107 IOHibernateImageHeader107;
162
163struct hibernate_bitmap_t
164{
165 uint32_tfirst_page;
166 uint32_tlast_page;
167 uint32_tbitmapwords;
168 uint32_tbitmap[0];
169};
170typedef struct hibernate_bitmap_t hibernate_bitmap_t;
171
172struct hibernate_page_list_t
173{
174 uint32_t list_size;
175 uint32_t page_count;
176 uint32_t bank_count;
177 hibernate_bitmap_t bank_bitmap[0];
178};
179typedef struct hibernate_page_list_t hibernate_page_list_t;
180
181#if defined(_AES_H)
182
183struct hibernate_cryptwakevars_t
184{
185 uint8_t aes_iv[AES_BLOCK_SIZE];
186};
187typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
188
189struct hibernate_cryptvars_t
190{
191 uint8_t aes_iv[AES_BLOCK_SIZE];
192 aes_ctx ctx;
193};
194typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
195
196#endif /* defined(_AES_H) */
197
198
199enum
200{
201 kIOHibernateProgressCount = 19,
202 kIOHibernateProgressWidth = 7,
203 kIOHibernateProgressHeight = 16,
204 kIOHibernateProgressSpacing = 3,
205 kIOHibernateProgressOriginY = 81,
206
207 kIOHibernateProgressSaveUnderSize = 2*5+14*2,
208
209 kIOHibernateProgressLightGray = 230,
210 kIOHibernateProgressMidGray = 174,
211 kIOHibernateProgressDarkGray = 92
212};
213
214enum
215{
216 kIOHibernatePostWriteSleep = 0,
217 kIOHibernatePostWriteWake = 1,
218 kIOHibernatePostWriteHalt = 2,
219 kIOHibernatePostWriteRestart = 3
220};
221
222
223struct hibernate_graphics_t
224{
225 uint32_t physicalAddress;// Base address of video memory
226 uint32_t mode;//
227 uint32_t rowBytes; // Number of bytes per pixel row
228 uint32_t width; // Width
229 uint32_t height; // Height
230 uint32_t depth; // Pixel Depth
231
232 uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
233};
234typedef struct hibernate_graphics_t hibernate_graphics_t;
235
236#define DECLARE_IOHIBERNATEPROGRESSALPHA\
237static const uint8_t gIOHibernateProgressAlpha\
238[kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
239{\
240 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 },\
241 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 },\
242 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae },\
243 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
244 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
245 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
246 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
247 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
248 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
249 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
250 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
251 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
252 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
253 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae },\
254 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 },\
255 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 }\
256};
257
258#ifdef KERNEL
259
260#ifdef __cplusplus
261
262void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
263
264IOReturn IOHibernateSystemSleep(void);
265IOReturn IOHibernateSystemHasSlept(void);
266IOReturn IOHibernateSystemWake(void);
267IOReturn IOHibernateSystemPostWake(void);
268
269#endif /* __cplusplus */
270
271#ifdef _SYS_CONF_H_
272typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
273
274struct kern_direct_file_io_ref_t *
275kern_open_file_for_direct_io(const char * name,
276 kern_get_file_extents_callback_t callback,
277 void * callback_ref,
278 dev_t * device,
279 uint64_t * partitionbase_result,
280 uint64_t * maxiocount_result);
281void
282kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);
283int
284kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
285int get_kernel_symfile(struct proc *p, char const **symfile);
286#endif /* _SYS_CONF_H_ */
287
288hibernate_page_list_t *
289hibernate_page_list_allocate(void);
290
291kern_return_t
292hibernate_setup(IOHibernateImageHeader * header,
293 uint32_t free_page_ratio,
294 uint32_t free_page_time,
295hibernate_page_list_t ** page_list_ret,
296hibernate_page_list_t ** page_list_wired_ret,
297 boolean_t * encryptedswap);
298kern_return_t
299hibernate_teardown(hibernate_page_list_t * page_list,
300 hibernate_page_list_t * page_list_wired);
301
302kern_return_t
303hibernate_processor_setup(IOHibernateImageHeader * header);
304
305void
306hibernate_vm_lock(void);
307void
308hibernate_vm_unlock(void);
309
310// mark pages not to be saved, based on VM system accounting
311void
312hibernate_page_list_setall(hibernate_page_list_t * page_list,
313 hibernate_page_list_t * page_list_wired,
314 uint32_t * pagesOut);
315
316// mark pages to be saved, or pages not to be saved but available
317// for scratch usage during restore
318void
319hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
320 hibernate_page_list_t * page_list_wired,
321 uint32_t * pagesOut);
322
323// mark pages not to be saved and not for scratch usage during restore
324void
325hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
326 hibernate_page_list_t * page_list_wired,
327 uint32_t * pagesOut);
328
329void
330hibernate_page_list_discard(hibernate_page_list_t * page_list);
331
332void
333hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
334vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
335
336void
337hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
338
339boolean_t
340hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
341
342hibernate_bitmap_t *
343hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
344
345uint32_t
346hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
347
348void
349hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
350
351void
352hibernate_machine_init(void);
353
354uint32_t
355hibernate_write_image(void);
356
357long
358hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
359long
360hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
361void
362hibernate_newruntime_map(void * map, vm_size_t map_size,
363 uint32_t system_table_offset);
364
365
366extern uint32_t gIOHibernateState;
367extern uint32_t gIOHibernateMode;
368extern uint32_t gIOHibernateFreeTime;// max time to spend freeing pages (ms)
369extern uint8_t gIOHibernateRestoreStack[];
370extern uint8_t gIOHibernateRestoreStackEnd[];
371extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
372extern hibernate_graphics_t * gIOHibernateGraphicsInfo;
373extern hibernate_cryptwakevars_t * gIOHibernateCryptWakeVars;
374
375#define HIBLOG(fmt, args...)\
376 { kprintf(fmt, ## args); printf(fmt, ## args); }
377
378#define HIBPRINT(fmt, args...)\
379 { kprintf(fmt, ## args); }
380
381#endif /* KERNEL */
382
383// gIOHibernateState, kIOHibernateStateKey
384enum
385{
386 kIOHibernateStateInactive = 0,
387 kIOHibernateStateHibernating = 1,/* writing image */
388 kIOHibernateStateWakingFromHibernate = 2/* booted and restored image */
389};
390
391// gIOHibernateMode, kIOHibernateModeKey
392enum
393{
394 kIOHibernateModeOn = 0x00000001,
395 kIOHibernateModeSleep = 0x00000002,
396 kIOHibernateModeEncrypt = 0x00000004,
397 kIOHibernateModeDiscardCleanInactive = 0x00000008,
398 kIOHibernateModeDiscardCleanActive = 0x00000010,
399 kIOHibernateModeSwitch= 0x00000020,
400 kIOHibernateModeRestart= 0x00000040
401};
402
403// IOHibernateImageHeader.signature
404enum
405{
406 kIOHibernateHeaderSignature = 0x73696d65,
407 kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
408};
409
410// kind for hibernate_set_page_state()
411enum
412{
413 kIOHibernatePageStateFree = 0,
414 kIOHibernatePageStateWiredSave = 1,
415 kIOHibernatePageStateUnwiredSave = 2
416};
417
418#define kIOHibernateModeKey"Hibernate Mode"
419#define kIOHibernateFileKey"Hibernate File"
420#define kIOHibernateFreeRatioKey"Hibernate Free Ratio"
421#define kIOHibernateFreeTimeKey"Hibernate Free Time"
422
423#define kIOHibernateStateKey"IOHibernateState"
424#define kIOHibernateFeatureKey"Hibernation"
425#define kIOHibernatePreviewBufferKey"IOPreviewBuffer"
426
427#define kIOHibernatePreviewActiveKey"IOHibernatePreviewActive"
428// values for kIOHibernatePreviewActiveKey
429enum {
430 kIOHibernatePreviewActive = 0x00000001,
431 kIOHibernatePreviewUpdates = 0x00000002
432};
433
434#define kIOHibernateBootImageKey"boot-image"
435#define kIOHibernateBootImageKeyKey"boot-image-key"
436#define kIOHibernateBootSignatureKey"boot-signature"
437
438#define kIOHibernateMemorySignatureKey "memory-signature"
439#define kIOHibernateMemorySignatureEnvKey "mem-sig"
440#define kIOHibernateMachineSignatureKey "machine-signature"
441
442#define kIOHibernateRTCVariablesKey"IOHibernateRTCVariables"
443
444#define kIOHibernateBootSwitchVarsKey"boot-switch-vars"
445
446
447#ifdef __cplusplus
448}
449#endif
450

Archive Download this file

Revision: 1525