Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/boot2/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
98
99struct hibernate_bitmap_t
100{
101 uint32_tfirst_page;
102 uint32_tlast_page;
103 uint32_tbitmapwords;
104 uint32_tbitmap[0];
105};
106typedef struct hibernate_bitmap_t hibernate_bitmap_t;
107
108struct hibernate_page_list_t
109{
110 uint32_t list_size;
111 uint32_t page_count;
112 uint32_t bank_count;
113 hibernate_bitmap_t bank_bitmap[0];
114};
115typedef struct hibernate_page_list_t hibernate_page_list_t;
116
117#if defined(_AES_H)
118
119struct hibernate_cryptwakevars_t
120{
121 uint8_t aes_iv[AES_BLOCK_SIZE];
122};
123typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
124
125struct hibernate_cryptvars_t
126{
127 uint8_t aes_iv[AES_BLOCK_SIZE];
128 aes_ctx ctx;
129};
130typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
131
132#endif /* defined(_AES_H) */
133
134
135enum
136{
137 kIOHibernateProgressCount = 19,
138 kIOHibernateProgressWidth = 7,
139 kIOHibernateProgressHeight = 16,
140 kIOHibernateProgressSpacing = 3,
141 kIOHibernateProgressOriginY = 81,
142
143 kIOHibernateProgressSaveUnderSize = 2*5+14*2,
144
145 kIOHibernateProgressLightGray = 230,
146 kIOHibernateProgressMidGray = 174,
147 kIOHibernateProgressDarkGray = 92
148};
149
150enum
151{
152 kIOHibernatePostWriteSleep = 0,
153 kIOHibernatePostWriteWake = 1,
154 kIOHibernatePostWriteHalt = 2,
155 kIOHibernatePostWriteRestart = 3
156};
157
158
159struct hibernate_graphics_t
160{
161 uint32_t physicalAddress;// Base address of video memory
162 uint32_t mode;//
163 uint32_t rowBytes; // Number of bytes per pixel row
164 uint32_t width; // Width
165 uint32_t height; // Height
166 uint32_t depth; // Pixel Depth
167
168 uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
169};
170typedef struct hibernate_graphics_t hibernate_graphics_t;
171
172#define DECLARE_IOHIBERNATEPROGRESSALPHA\
173static const uint8_t gIOHibernateProgressAlpha\
174[kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
175{\
176 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 },\
177 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 },\
178 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae },\
179 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
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 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae },\
190 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 },\
191 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 }\
192};
193
194#ifdef KERNEL
195
196#ifdef __cplusplus
197
198void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
199
200IOReturn IOHibernateSystemSleep(void);
201IOReturn IOHibernateSystemHasSlept(void);
202IOReturn IOHibernateSystemWake(void);
203IOReturn IOHibernateSystemPostWake(void);
204
205#endif /* __cplusplus */
206
207#ifdef _SYS_CONF_H_
208typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
209
210struct kern_direct_file_io_ref_t *
211kern_open_file_for_direct_io(const char * name,
212 kern_get_file_extents_callback_t callback,
213 void * callback_ref,
214 dev_t * device,
215 uint64_t * partitionbase_result,
216 uint64_t * maxiocount_result);
217void
218kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);
219int
220kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
221int get_kernel_symfile(struct proc *p, char const **symfile);
222#endif /* _SYS_CONF_H_ */
223
224hibernate_page_list_t *
225hibernate_page_list_allocate(void);
226
227kern_return_t
228hibernate_setup(IOHibernateImageHeader * header,
229 uint32_t free_page_ratio,
230 uint32_t free_page_time,
231hibernate_page_list_t ** page_list_ret,
232hibernate_page_list_t ** page_list_wired_ret,
233 boolean_t * encryptedswap);
234kern_return_t
235hibernate_teardown(hibernate_page_list_t * page_list,
236 hibernate_page_list_t * page_list_wired);
237
238kern_return_t
239hibernate_processor_setup(IOHibernateImageHeader * header);
240
241void
242hibernate_vm_lock(void);
243void
244hibernate_vm_unlock(void);
245
246// mark pages not to be saved, based on VM system accounting
247void
248hibernate_page_list_setall(hibernate_page_list_t * page_list,
249 hibernate_page_list_t * page_list_wired,
250 uint32_t * pagesOut);
251
252// mark pages to be saved, or pages not to be saved but available
253// for scratch usage during restore
254void
255hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
256 hibernate_page_list_t * page_list_wired,
257 uint32_t * pagesOut);
258
259// mark pages not to be saved and not for scratch usage during restore
260void
261hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
262 hibernate_page_list_t * page_list_wired,
263 uint32_t * pagesOut);
264
265void
266hibernate_page_list_discard(hibernate_page_list_t * page_list);
267
268void
269hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
270vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
271
272void
273hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
274
275boolean_t
276hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
277
278hibernate_bitmap_t *
279hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
280
281uint32_t
282hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
283
284void
285hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
286
287void
288hibernate_machine_init(void);
289
290uint32_t
291hibernate_write_image(void);
292
293long
294hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
295long
296hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
297void
298hibernate_newruntime_map(void * map, vm_size_t map_size,
299 uint32_t system_table_offset);
300
301
302extern uint32_t gIOHibernateState;
303extern uint32_t gIOHibernateMode;
304extern uint32_t gIOHibernateFreeTime;// max time to spend freeing pages (ms)
305extern uint8_t gIOHibernateRestoreStack[];
306extern uint8_t gIOHibernateRestoreStackEnd[];
307extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
308extern hibernate_graphics_t * gIOHibernateGraphicsInfo;
309extern hibernate_cryptwakevars_t * gIOHibernateCryptWakeVars;
310
311#define HIBLOG(fmt, args...)\
312 { kprintf(fmt, ## args); printf(fmt, ## args); }
313
314#define HIBPRINT(fmt, args...)\
315 { kprintf(fmt, ## args); }
316
317#endif /* KERNEL */
318
319// gIOHibernateState, kIOHibernateStateKey
320enum
321{
322 kIOHibernateStateInactive = 0,
323 kIOHibernateStateHibernating = 1,/* writing image */
324 kIOHibernateStateWakingFromHibernate = 2/* booted and restored image */
325};
326
327// gIOHibernateMode, kIOHibernateModeKey
328enum
329{
330 kIOHibernateModeOn = 0x00000001,
331 kIOHibernateModeSleep = 0x00000002,
332 kIOHibernateModeEncrypt = 0x00000004,
333 kIOHibernateModeDiscardCleanInactive = 0x00000008,
334 kIOHibernateModeDiscardCleanActive = 0x00000010,
335 kIOHibernateModeSwitch= 0x00000020,
336 kIOHibernateModeRestart= 0x00000040
337};
338
339// IOHibernateImageHeader.signature
340enum
341{
342 kIOHibernateHeaderSignature = 0x73696d65,
343 kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
344};
345
346// kind for hibernate_set_page_state()
347enum
348{
349 kIOHibernatePageStateFree = 0,
350 kIOHibernatePageStateWiredSave = 1,
351 kIOHibernatePageStateUnwiredSave = 2
352};
353
354#define kIOHibernateModeKey"Hibernate Mode"
355#define kIOHibernateFileKey"Hibernate File"
356#define kIOHibernateFreeRatioKey"Hibernate Free Ratio"
357#define kIOHibernateFreeTimeKey"Hibernate Free Time"
358
359#define kIOHibernateStateKey"IOHibernateState"
360#define kIOHibernateFeatureKey"Hibernation"
361#define kIOHibernatePreviewBufferKey"IOPreviewBuffer"
362
363#define kIOHibernatePreviewActiveKey"IOHibernatePreviewActive"
364// values for kIOHibernatePreviewActiveKey
365enum {
366 kIOHibernatePreviewActive = 0x00000001,
367 kIOHibernatePreviewUpdates = 0x00000002
368};
369
370#define kIOHibernateBootImageKey"boot-image"
371#define kIOHibernateBootImageKeyKey"boot-image-key"
372#define kIOHibernateBootSignatureKey"boot-signature"
373
374#define kIOHibernateMemorySignatureKey "memory-signature"
375#define kIOHibernateMemorySignatureEnvKey "mem-sig"
376#define kIOHibernateMachineSignatureKey "machine-signature"
377
378#define kIOHibernateRTCVariablesKey"IOHibernateRTCVariables"
379
380#define kIOHibernateBootSwitchVarsKey"boot-switch-vars"
381
382
383#ifdef __cplusplus
384}
385#endif
386

Archive Download this file

Revision: 840