Chameleon

Chameleon Svn Source Tree

Root/branches/ErmaC/Enoch/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
37#ifndef __IOKIT_IOHIBERNATEPRIVATE_H
38#define __IOKIT_IOHIBERNATEPRIVATE_H
39
40struct IOPolledFileExtent
41{
42uint64_tstart;
43uint64_tlength;
44};
45typedef struct IOPolledFileExtent IOPolledFileExtent;
46
47struct IOHibernateImageHeader
48{
49uint64_timageSize; // 0
50uint64_timage1Size; // 8
51
52uint32_trestore1CodePhysPage; // 10
53uint32_treserved1; // 14
54uint64_trestore1CodeVirt; // 18
55uint32_trestore1PageCount; // 20
56uint32_trestore1CodeOffset;
57uint32_trestore1StackOffset;
58
59 uint32_tpageCount;
60 uint32_tbitmapSize;
61
62 uint32_trestore1Sum;
63 uint32_timage1Sum;
64 uint32_timage2Sum;
65
66 uint32_tactualRestore1Sum;
67 uint32_tactualImage1Sum;
68 uint32_tactualImage2Sum;
69
70 uint32_tactualUncompressedPages;
71 uint32_tconflictCount;
72 uint32_tnextFree;
73
74 uint32_tsignature;
75 uint32_tprocessorFlags;
76
77 uint32_truntimePages;
78 uint32_truntimePageCount;
79uint64_truntimeVirtualPages __attribute__ ((packed));
80
81uint32_tperformanceDataStart;
82uint32_tperformanceDataSize;
83
84uint64_tencryptStart __attribute__ ((packed));
85uint64_tmachineSignature __attribute__ ((packed));
86
87uint32_tpreviewSize;
88uint32_tpreviewPageListSize;
89
90uint32_tdiag[4];
91
92uint32_thandoffPages;
93uint32_thandoffPageCount;
94
95uint32_tsystemTableOffset;
96
97uint32_tdebugFlags;
98uint32_toptions;
99uint32_tsleepTime;
100uint32_tcompression;
101
102uint32_treserved[58];// make sizeof == 512
103uint32_tbooterTime0;
104uint32_tbooterTime1;
105uint32_tbooterTime2;
106
107uint32_tbooterStart;
108uint32_tsmcStart;
109uint32_tconnectDisplayTime;
110uint32_tsplashTime;
111uint32_tbooterTime;
112uint32_ttrampolineTime;
113
114uint64_tencryptEnd __attribute__ ((packed));
115uint64_tdeviceBase __attribute__ ((packed));
116uint32_tdeviceBlockSize;
117
118uint32_tfileExtentMapSize;
119IOPolledFileExtentfileExtentMap[2];
120};
121typedef struct IOHibernateImageHeader IOHibernateImageHeader;
122
123struct IOHibernateImageHeaderSnow
124{
125uint64_timageSize;
126uint64_timage1Size;
127
128uint32_trestore1CodePhysPage;
129
130uint32_trestore1PageCount;
131uint32_trestore1CodeOffset;
132uint32_trestore1StackOffset;
133
134uint32_tpageCount;
135uint32_tbitmapSize;
136
137uint32_trestore1Sum;
138uint32_timage1Sum;
139uint32_timage2Sum;
140
141uint32_tactualRestore1Sum;
142uint32_tactualImage1Sum;
143uint32_tactualImage2Sum;
144
145uint32_tactualUncompressedPages;
146uint32_tconflictCount;
147uint32_tnextFree;
148
149uint32_tsignature;
150uint32_tprocessorFlags;
151
152uint32_truntimePages;
153uint32_truntimePageCount;
154
155uint8_treserved2[16];
156
157uint64_tencryptStart;
158uint64_tmachineSignature;
159
160uint32_tpreviewSize;
161uint32_tpreviewPageListSize;
162
163uint32_tdiag[4];
164
165int32_tgraphicsInfoOffset;
166int32_tcryptVarsOffset;
167int32_tmemoryMapOffset;
168uint32_tmemoryMapSize;
169uint32_tsystemTableOffset;
170
171uint32_treserved[77];// make sizeof == 512
172
173uint32_tfileExtentMapSize;
174IOPolledFileExtentfileExtentMap[2];
175};
176typedef struct IOHibernateImageHeaderSnow IOHibernateImageHeaderSnow;
177
178enum
179{
180kIOHibernateDebugRestoreLogs = 0x00000001
181};
182
183// options & IOHibernateOptions property
184enum
185{
186kIOHibernateOptionSSD = 0x00000001,
187kIOHibernateOptionColor = 0x00000002,
188kIOHibernateOptionProgress = 0x00000004,
189kIOHibernateOptionDarkWake = 0x00000008,
190};
191
192struct hibernate_bitmap_t
193{
194uint32_tfirst_page;
195uint32_tlast_page;
196uint32_tbitmapwords;
197uint32_tbitmap[0];
198};
199typedef struct hibernate_bitmap_t hibernate_bitmap_t;
200
201struct hibernate_page_list_t
202{
203uint32_t list_size;
204uint32_t page_count;
205uint32_t bank_count;
206hibernate_bitmap_t bank_bitmap[0];
207};
208typedef struct hibernate_page_list_t hibernate_page_list_t;
209
210#if defined(_AES_H)
211
212struct hibernate_cryptwakevars_t
213{
214uint8_t aes_iv[AES_BLOCK_SIZE];
215};
216typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
217
218struct hibernate_cryptvars_t
219{
220uint8_t aes_iv[AES_BLOCK_SIZE];
221aes_ctx ctx;
222};
223typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
224
225#endif /* defined(_AES_H) */
226
227enum
228{
229 kIOHibernateHandoffType = 0x686f0000,
230 kIOHibernateHandoffTypeEnd = kIOHibernateHandoffType + 0,
231 kIOHibernateHandoffTypeGraphicsInfo = kIOHibernateHandoffType + 1,
232 kIOHibernateHandoffTypeCryptVars = kIOHibernateHandoffType + 2,
233 kIOHibernateHandoffTypeMemoryMap = kIOHibernateHandoffType + 3,
234 kIOHibernateHandoffTypeDeviceTree = kIOHibernateHandoffType + 4,
235 kIOHibernateHandoffTypeDeviceProperties = kIOHibernateHandoffType + 5,
236 kIOHibernateHandoffTypeKeyStore = kIOHibernateHandoffType + 6,
237};
238
239struct IOHibernateHandoff
240{
241 uint32_t type;
242 uint32_t bytecount;
243 uint8_t data[];
244};
245typedef struct IOHibernateHandoff IOHibernateHandoff;
246
247enum
248{
249kIOHibernateProgressCount = 19,
250kIOHibernateProgressWidth = 7,
251kIOHibernateProgressHeight = 16,
252kIOHibernateProgressSpacing = 3,
253kIOHibernateProgressOriginY = 81,
254
255kIOHibernateProgressSaveUnderSize = 2*5+14*2,
256
257kIOHibernateProgressLightGray = 230,
258kIOHibernateProgressMidGray = 174,
259kIOHibernateProgressDarkGray = 92
260};
261
262enum
263{
264kIOHibernatePostWriteSleep = 0,
265kIOHibernatePostWriteWake = 1,
266kIOHibernatePostWriteHalt = 2,
267kIOHibernatePostWriteRestart = 3
268};
269
270
271struct hibernate_graphics_t
272{
273uint32_t physicalAddress;// Base address of video memory
274int32_t gfxStatus;// EFI config restore status
275uint32_t mode;//
276uint32_t rowBytes; // Number of bytes per pixel row
277uint32_t width; // Width
278uint32_t height; // Height
279uint32_t depth; // Pixel Depth
280
281uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
282};
283typedef struct hibernate_graphics_t hibernate_graphics_t;
284
285#define DECLARE_IOHIBERNATEPROGRESSALPHA\
286static const uint8_t gIOHibernateProgressAlpha\
287[kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
288{\
289{ 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 },\
290{ 0x51,0xff,0xff,0xff,0xff,0xff,0x51 },\
291{ 0xae,0xff,0xff,0xff,0xff,0xff,0xae },\
292{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
293{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
294{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
295{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
296{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
297{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
298{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
299{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
300{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
301{ 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },\
302{ 0xae,0xff,0xff,0xff,0xff,0xff,0xae },\
303{ 0x54,0xff,0xff,0xff,0xff,0xff,0x54 },\
304{ 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 }\
305};
306
307struct hibernate_preview_t
308{
309uint32_t imageCount;// Number of images
310uint32_t width; // Width
311uint32_t height; // Height
312uint32_t depth; // Pixel Depth
313uint32_t lockTime; // Lock time
314uint32_t reservedG[8]; // reserved
315uint32_t reservedK[8]; // reserved
316};
317typedef struct hibernate_preview_t hibernate_preview_t;
318
319struct hibernate_statistics_t
320{
321uint64_t image1Size;
322uint64_t imageSize;
323uint32_t image1Pages;
324uint32_t imagePages;
325uint32_t booterStart;
326uint32_t smcStart;
327uint32_t booterDuration;
328uint32_t booterConnectDisplayDuration;
329uint32_t booterSplashDuration;
330uint32_t booterDuration0;
331uint32_t booterDuration1;
332uint32_t booterDuration2;
333uint32_t trampolineDuration;
334uint32_t kernelImageReadDuration;
335
336uint32_t graphicsReadyTime;
337uint32_t wakeNotificationTime;
338uint32_t lockScreenReadyTime;
339uint32_t hidReadyTime;
340
341uint32_t wakeCapability;
342uint32_t resvA[15];
343};
344typedef struct hibernate_statistics_t hibernate_statistics_t;
345
346#define kIOSysctlHibernateStatistics"kern.hibernatestatistics"
347#define kIOSysctlHibernateGraphicsReady"kern.hibernategraphicsready"
348#define kIOSysctlHibernateWakeNotify"kern.hibernatewakenotification"
349#define kIOSysctlHibernateScreenReady"kern.hibernatelockscreenready"
350#define kIOSysctlHibernateHIDReady"kern.hibernatehidready"
351
352#ifdef KERNEL
353
354#ifdef __cplusplus
355
356void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
357
358IOReturn IOHibernateSystemSleep(void);
359IOReturn IOHibernateIOKitSleep(void);
360IOReturn IOHibernateSystemHasSlept(void);
361IOReturn IOHibernateSystemWake(void);
362IOReturn IOHibernateSystemPostWake(void);
363bool IOHibernateWasScreenLocked(void);
364void IOHibernateSetScreenLocked(uint32_t lockState);
365void IOHibernateSetWakeCapabilities(uint32_t capability);
366void IOHibernateSystemRestart(void);
367
368#endif /* __cplusplus */
369
370#ifdef _SYS_CONF_H_
371typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
372
373struct kern_direct_file_io_ref_t *
374kern_open_file_for_direct_io(const char * name,
375kern_get_file_extents_callback_t callback,
376void * callback_ref,
377
378off_t set_file_size,
379
380off_t write_file_offset,
381caddr_t write_file_addr,
382vm_size_t write_file_len,
383
384dev_t * partition_device_result,
385dev_t * image_device_result,
386uint64_t * partitionbase_result,
387uint64_t * maxiocount_result,
388uint32_t * oflags);
389void
390kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref,
391 off_t write_offset, caddr_t addr, vm_size_t write_length,
392 off_t discard_offset, off_t discard_end);
393#endif /* _SYS_CONF_H_ */
394
395hibernate_page_list_t *
396hibernate_page_list_allocate(boolean_t log);
397
398kern_return_t
399 hibernate_alloc_page_lists(
400 hibernate_page_list_t ** page_list_ret,
401 hibernate_page_list_t ** page_list_wired_ret,
402 hibernate_page_list_t ** page_list_pal_ret);
403
404kern_return_t
405hibernate_setup(IOHibernateImageHeader * header,
406uint32_t free_page_ratio,
407uint32_t free_page_time,
408boolean_t vmflush,
409hibernate_page_list_t * page_list,
410hibernate_page_list_t * page_list_wired,
411hibernate_page_list_t * page_list_pal);
412
413kern_return_t
414hibernate_teardown(hibernate_page_list_t * page_list,
415hibernate_page_list_t * page_list_wired,
416hibernate_page_list_t * page_list_pal);
417
418kern_return_t
419hibernate_processor_setup(IOHibernateImageHeader * header);
420
421void
422hibernate_gobble_pages(uint32_t gobble_count, uint32_t free_page_time);
423void
424hibernate_free_gobble_pages(void);
425
426void
427hibernate_vm_lock_queues(void);
428void
429hibernate_vm_unlock_queues(void);
430
431void
432hibernate_vm_lock(void);
433void
434hibernate_vm_unlock(void);
435
436// mark pages not to be saved, based on VM system accounting
437void
438hibernate_page_list_setall(hibernate_page_list_t * page_list,
439 hibernate_page_list_t * page_list_wired,
440 hibernate_page_list_t * page_list_pal,
441 boolean_t preflight,
442 boolean_t discard_all,
443 uint32_t * pagesOut);
444
445// mark pages to be saved, or pages not to be saved but available
446// for scratch usage during restore
447void
448hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
449 hibernate_page_list_t * page_list_wired,
450 boolean_t preflight,
451 uint32_t * pagesOut);
452
453// mark pages not to be saved and not for scratch usage during restore
454void
455hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
456 hibernate_page_list_t * page_list_wired,
457 uint32_t * pagesOut);
458
459void
460hibernate_page_list_discard(hibernate_page_list_t * page_list);
461
462int
463hibernate_should_abort(void);
464
465void
466hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
467vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
468
469void
470hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
471
472boolean_t
473hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
474
475hibernate_bitmap_t *
476hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
477
478uint32_t
479hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
480
481uintptr_t
482hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
483
484void
485hibernate_machine_init(void);
486
487uint32_t
488hibernate_write_image(void);
489
490long
491hibernate_machine_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
492long
493hibernate_kernel_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
494void
495hibernate_newruntime_map(void * map, vm_size_t map_size,
496 uint32_t system_table_offset);
497
498
499extern uint32_t gIOHibernateState;
500extern uint32_t gIOHibernateMode;
501extern uint32_t gIOHibernateDebugFlags;
502extern uint32_t gIOHibernateFreeTime;// max time to spend freeing pages (ms)
503extern uint8_t gIOHibernateRestoreStack[];
504extern uint8_t gIOHibernateRestoreStackEnd[];
505extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
506extern hibernate_graphics_t * gIOHibernateGraphicsInfo;
507extern hibernate_cryptwakevars_t * gIOHibernateCryptWakeVars;
508
509#define HIBLOG(fmt, args...)\
510{ kprintf(fmt, ## args); printf(fmt, ## args); }
511
512#define HIBPRINT(fmt, args...)\
513{ kprintf(fmt, ## args); }
514
515#endif /* KERNEL */
516
517// gIOHibernateState, kIOHibernateStateKey
518enum
519{
520kIOHibernateStateInactive = 0,
521kIOHibernateStateHibernating = 1,/* writing image */
522kIOHibernateStateWakingFromHibernate = 2/* booted and restored image */
523};
524
525// gIOHibernateMode, kIOHibernateModeKey
526enum
527{
528kIOHibernateModeOn= 0x00000001,
529kIOHibernateModeSleep= 0x00000002,
530kIOHibernateModeEncrypt= 0x00000004,
531kIOHibernateModeDiscardCleanInactive= 0x00000008,
532kIOHibernateModeDiscardCleanActive= 0x00000010,
533kIOHibernateModeSwitch= 0x00000020,
534kIOHibernateModeRestart= 0x00000040,
535kIOHibernateModeSSDInvert= 0x00000080,
536kIOHibernateModeFileResize= 0x00000100,
537};
538
539// IOHibernateImageHeader.signature
540enum
541{
542kIOHibernateHeaderSignature = 0x73696d65,
543kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
544};
545
546// kind for hibernate_set_page_state()
547enum
548{
549kIOHibernatePageStateFree = 0,
550kIOHibernatePageStateWiredSave = 1,
551kIOHibernatePageStateUnwiredSave = 2
552};
553
554#define kIOHibernateModeKey"Hibernate Mode"
555#define kIOHibernateFileKey"Hibernate File"
556#define kIOHibernateFileMinSizeKey"Hibernate File Min"
557#define kIOHibernateFileMaxSizeKey"Hibernate File Max"
558#define kIOHibernateFreeRatioKey"Hibernate Free Ratio"
559#define kIOHibernateFreeTimeKey"Hibernate Free Time"
560
561#define kIOHibernateStateKey"IOHibernateState"
562#define kIOHibernateFeatureKey"Hibernation"
563#define kIOHibernatePreviewBufferKey"IOPreviewBuffer"
564
565#ifndef kIOHibernatePreviewActiveKey
566#define kIOHibernatePreviewActiveKey"IOHibernatePreviewActive"
567// values for kIOHibernatePreviewActiveKey
568enum {
569kIOHibernatePreviewActive = 0x00000001,
570kIOHibernatePreviewUpdates = 0x00000002
571};
572#endif
573
574#define kIOHibernateOptionsKey "IOHibernateOptions"
575#define kIOHibernateGfxStatusKey "IOHibernateGfxStatus"
576enum {
577kIOHibernateGfxStatusUnknown = ((int32_t) 0xFFFFFFFF)
578};
579
580#define kIOHibernateBootImageKey"boot-image"
581#define kIOHibernateBootImageKeyKey"boot-image-key"
582#define kIOHibernateBootSignatureKey"boot-signature"
583
584#define kIOHibernateMemorySignatureKey "memory-signature"
585#define kIOHibernateMemorySignatureEnvKey "mem-sig"
586#define kIOHibernateMachineSignatureKey "machine-signature"
587
588#define kIOHibernateRTCVariablesKey"IOHibernateRTCVariables"
589#define kIOHibernateSMCVariablesKey"IOHibernateSMCVariables"
590
591#define kIOHibernateBootSwitchVarsKey"boot-switch-vars"
592
593#define kIOHibernateBootNoteKey"boot-note"
594
595#define kIOHibernateUseKernelInterpreter 0x80000000
596
597enum {
598kIOPreviewImageIndexDesktop = 0,
599kIOPreviewImageIndexLockScreen = 1,
600kIOPreviewImageCount = 2
601};
602
603enum {
604kIOScreenLockNoLock = 1,
605kIOScreenLockUnlocked = 2,
606kIOScreenLockLocked = 3,
607kIOScreenLockFileVaultDialog = 4,
608};
609
610#define kIOScreenLockStateKey "IOScreenLockState"
611
612#endif /* ! __IOKIT_IOHIBERNATEPRIVATE_H */
613
614#ifdef __cplusplus
615}
616#endif
617

Archive Download this file

Revision: 2364