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

Archive Download this file

Revision: HEAD