Chameleon

Chameleon Svn Source Tree

Root/tags/2.3/i386/boot2/IOHibernatePrivate.h

Source at commit 2862 created 7 years 24 days ago.
By ifabio, Tag 2.3 release, bump svn to 2.4
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{
39uint64_tstart;
40uint64_tlength;
41};
42typedef struct IOPolledFileExtent IOPolledFileExtent;
43
44struct IOHibernateImageHeader
45{
46uint64_timageSize;
47uint64_timage1Size;
48
49uint32_trestore1CodePhysPage;
50uint32_treserved1;
51uint64_trestore1CodeVirt;
52uint32_trestore1PageCount;
53uint32_trestore1CodeOffset;
54uint32_trestore1StackOffset;
55
56 uint32_tpageCount;
57 uint32_tbitmapSize;
58
59 uint32_trestore1Sum;
60 uint32_timage1Sum;
61 uint32_timage2Sum;
62
63 uint32_tactualRestore1Sum;
64 uint32_tactualImage1Sum;
65 uint32_tactualImage2Sum;
66
67 uint32_tactualUncompressedPages;
68 uint32_tconflictCount;
69 uint32_tnextFree;
70
71 uint32_tsignature;
72 uint32_tprocessorFlags;
73
74uint32_truntimePages;
75uint32_truntimePageCount;
76
77uint8_treserved2[16];
78
79uint64_tencryptStart;
80uint64_tmachineSignature;
81
82uint32_tpreviewSize;
83uint32_tpreviewPageListSize;
84
85uint32_tdiag[4];
86
87int32_tgraphicsInfoOffset;
88int32_tcryptVarsOffset;
89int32_tmemoryMapOffset;
90uint32_tmemoryMapSize;
91uint32_tsystemTableOffset;
92
93uint32_treserved[77];// make sizeof == 512
94
95uint32_tfileExtentMapSize;
96IOPolledFileExtentfileExtentMap[2];
97};
98typedef struct IOHibernateImageHeader IOHibernateImageHeader;
99
100
101struct hibernate_bitmap_t
102{
103uint32_tfirst_page;
104uint32_tlast_page;
105uint32_tbitmapwords;
106uint32_tbitmap[0];
107};
108typedef struct hibernate_bitmap_t hibernate_bitmap_t;
109
110struct hibernate_page_list_t
111{
112uint32_t list_size;
113uint32_t page_count;
114uint32_t bank_count;
115hibernate_bitmap_t bank_bitmap[0];
116};
117typedef struct hibernate_page_list_t hibernate_page_list_t;
118
119#if defined(_AES_H)
120
121struct hibernate_cryptwakevars_t
122{
123uint8_t aes_iv[AES_BLOCK_SIZE];
124};
125typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
126
127struct hibernate_cryptvars_t
128{
129uint8_t aes_iv[AES_BLOCK_SIZE];
130aes_ctx ctx;
131};
132typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
133
134#endif /* defined(_AES_H) */
135
136
137enum
138{
139kIOHibernateProgressCount = 19,
140kIOHibernateProgressWidth = 7,
141kIOHibernateProgressHeight = 16,
142kIOHibernateProgressSpacing = 3,
143kIOHibernateProgressOriginY = 81,
144
145kIOHibernateProgressSaveUnderSize = 2*5+14*2,
146
147kIOHibernateProgressLightGray = 230,
148kIOHibernateProgressMidGray = 174,
149kIOHibernateProgressDarkGray = 92
150};
151
152enum {
153kIOHibernatePostWriteSleep = 0,
154kIOHibernatePostWriteWake = 1,
155kIOHibernatePostWriteHalt = 2,
156kIOHibernatePostWriteRestart = 3
157};
158
159
160struct hibernate_graphics_t
161{
162uint32_t physicalAddress;// Base address of video memory
163uint32_t mode;//
164uint32_t rowBytes; // Number of bytes per pixel row
165uint32_t width; // Width
166uint32_t height; // Height
167uint32_t depth; // Pixel Depth
168
169uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
170};
171typedef struct hibernate_graphics_t hibernate_graphics_t;
172
173#define DECLARE_IOHIBERNATEPROGRESSALPHA\
174static 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
199void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
200
201IOReturn IOHibernateSystemSleep(void);
202IOReturn IOHibernateSystemHasSlept(void);
203IOReturn IOHibernateSystemWake(void);
204IOReturn IOHibernateSystemPostWake(void);
205
206#endif /* __cplusplus */
207
208#ifdef _SYS_CONF_H_
209typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
210
211struct kern_direct_file_io_ref_t *
212kern_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);
218void
219kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);
220int
221kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
222int get_kernel_symfile(struct proc *p, char const **symfile);
223#endif /* _SYS_CONF_H_ */
224
225hibernate_page_list_t *
226hibernate_page_list_allocate(void);
227
228kern_return_t
229hibernate_setup(IOHibernateImageHeader * header,
230 uint32_t free_page_ratio,
231 uint32_t free_page_time,
232hibernate_page_list_t ** page_list_ret,
233hibernate_page_list_t ** page_list_wired_ret,
234 boolean_t * encryptedswap);
235kern_return_t
236hibernate_teardown(hibernate_page_list_t * page_list,
237 hibernate_page_list_t * page_list_wired);
238
239kern_return_t
240hibernate_processor_setup(IOHibernateImageHeader * header);
241
242void
243hibernate_vm_lock(void);
244void
245hibernate_vm_unlock(void);
246
247// mark pages not to be saved, based on VM system accounting
248void
249hibernate_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
255void
256hibernate_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
261void
262hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
263 hibernate_page_list_t * page_list_wired,
264 uint32_t * pagesOut);
265
266void
267hibernate_page_list_discard(hibernate_page_list_t * page_list);
268
269void
270hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
271vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
272
273void
274hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
275
276boolean_t
277hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
278
279hibernate_bitmap_t *
280hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
281
282uint32_t
283hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
284
285void
286hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
287
288void
289hibernate_machine_init(void);
290
291uint32_t
292hibernate_write_image(void);
293
294long
295hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
296long
297hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
298void
299hibernate_newruntime_map(void * map, vm_size_t map_size,
300 uint32_t system_table_offset);
301
302
303extern uint32_t gIOHibernateState;
304extern uint32_t gIOHibernateMode;
305extern uint32_t gIOHibernateFreeTime;// max time to spend freeing pages (ms)
306extern uint8_t gIOHibernateRestoreStack[];
307extern uint8_t gIOHibernateRestoreStackEnd[];
308extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
309extern hibernate_graphics_t * gIOHibernateGraphicsInfo;
310extern 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
321enum
322{
323kIOHibernateStateInactive = 0,
324kIOHibernateStateHibernating = 1,/* writing image */
325kIOHibernateStateWakingFromHibernate = 2/* booted and restored image */
326};
327
328// gIOHibernateMode, kIOHibernateModeKey
329enum
330{
331kIOHibernateModeOn= 0x00000001,
332kIOHibernateModeSleep= 0x00000002,
333kIOHibernateModeEncrypt= 0x00000004,
334kIOHibernateModeDiscardCleanInactive= 0x00000008,
335kIOHibernateModeDiscardCleanActive= 0x00000010,
336kIOHibernateModeSwitch= 0x00000020,
337kIOHibernateModeRestart= 0x00000040
338};
339
340// IOHibernateImageHeader.signature
341enum
342{
343kIOHibernateHeaderSignature = 0x73696d65,
344kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
345};
346
347// kind for hibernate_set_page_state()
348enum
349{
350kIOHibernatePageStateFree = 0,
351kIOHibernatePageStateWiredSave = 1,
352kIOHibernatePageStateUnwiredSave = 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
366enum {
367kIOHibernatePreviewActive = 0x00000001,
368kIOHibernatePreviewUpdates = 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

Archive Download this file

Revision: 2862