]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/IOKit/IOHibernatePrivate.h
xnu-2050.7.9.tar.gz
[apple/xnu.git] / iokit / IOKit / IOHibernatePrivate.h
index 01e3b860cbe3d54028ff5513897e09d540639224..6e758273de6d4fda07833584ccef2cc5c0c7a046 100644 (file)
@@ -1,23 +1,29 @@
 /*
  * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 
 #include <stdint.h>
@@ -27,9 +33,13 @@ extern "C" {
 #endif
 
 #ifdef KERNEL
-#include <crypto/aes.h>
+#include <libkern/crypto/aes.h>
+#include <uuid/uuid.h>
 #endif
 
+#ifndef __IOKIT_IOHIBERNATEPRIVATE_H
+#define __IOKIT_IOHIBERNATEPRIVATE_H
+
 struct IOPolledFileExtent
 {
     uint64_t   start;
@@ -42,7 +52,9 @@ struct IOHibernateImageHeader
     uint64_t   imageSize;
     uint64_t   image1Size;
     
-    uint32_t   restore1CodePage;
+    uint32_t   restore1CodePhysPage;
+    uint32_t    reserved1;
+    uint64_t   restore1CodeVirt;
     uint32_t   restore1PageCount;
     uint32_t   restore1CodeOffset;
     uint32_t   restore1StackOffset;
@@ -65,23 +77,53 @@ struct IOHibernateImageHeader
     uint32_t   signature;
     uint32_t   processorFlags;
 
-    uint8_t    reserved2[24];
+    uint32_t    runtimePages;
+    uint32_t    runtimePageCount;
+    uint64_t    runtimeVirtualPages __attribute__ ((packed));
+
+    uint32_t    performanceDataStart;
+    uint32_t    performanceDataSize;
     
-    uint64_t   encryptStart;
-    uint64_t   machineSignature;
+    uint64_t   encryptStart __attribute__ ((packed));
+    uint64_t   machineSignature __attribute__ ((packed));
 
     uint32_t    previewSize;
     uint32_t    previewPageListSize;
 
     uint32_t   diag[4];
 
-    uint32_t   reserved[82];           // make sizeof == 512
+    uint32_t    handoffPages;
+    uint32_t    handoffPageCount;
+
+    uint32_t    systemTableOffset;
+
+    uint32_t   debugFlags;
+    uint32_t   options;
+    uint32_t   sleepTime;
+
+    uint32_t   reserved[69];           // make sizeof == 512
+
+    uint64_t   encryptEnd __attribute__ ((packed));
+    uint64_t   deviceBase __attribute__ ((packed));
 
     uint32_t           fileExtentMapSize;
     IOPolledFileExtent fileExtentMap[2];
 };
 typedef struct IOHibernateImageHeader IOHibernateImageHeader;
 
+enum
+{
+    kIOHibernateDebugRestoreLogs = 0x00000001
+};
+
+// options & IOHibernateOptions property
+enum
+{
+    kIOHibernateOptionSSD           = 0x00000001,
+    kIOHibernateOptionColor         = 0x00000002,
+    kIOHibernateOptionProgress      = 0x00000004,
+    kIOHibernateOptionDarkWake      = 0x00000008,
+};
 
 struct hibernate_bitmap_t
 {
@@ -101,27 +143,42 @@ struct hibernate_page_list_t
 };
 typedef struct hibernate_page_list_t hibernate_page_list_t;
 
+#if defined(_AES_H)
+
 struct hibernate_cryptwakevars_t
 {
-#ifdef _AES_H
     uint8_t aes_iv[AES_BLOCK_SIZE];
-#else
-#warning undef _AES_H
-#endif
 };
 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
 
 struct hibernate_cryptvars_t
 {
-#ifdef _AES_H
     uint8_t aes_iv[AES_BLOCK_SIZE];
     aes_ctx ctx;
-#else
-#warning undef _AES_H
-#endif
 };
 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
 
+#endif /* defined(_AES_H) */
+
+enum 
+{
+    kIOHibernateHandoffType                 = 0x686f0000,
+    kIOHibernateHandoffTypeEnd              = kIOHibernateHandoffType + 0,
+    kIOHibernateHandoffTypeGraphicsInfo     = kIOHibernateHandoffType + 1,
+    kIOHibernateHandoffTypeCryptVars        = kIOHibernateHandoffType + 2,
+    kIOHibernateHandoffTypeMemoryMap        = kIOHibernateHandoffType + 3,
+    kIOHibernateHandoffTypeDeviceTree       = kIOHibernateHandoffType + 4,
+    kIOHibernateHandoffTypeDeviceProperties = kIOHibernateHandoffType + 5,
+    kIOHibernateHandoffTypeKeyStore         = kIOHibernateHandoffType + 6,
+};
+
+struct IOHibernateHandoff
+{
+    uint32_t type;
+    uint32_t bytecount;
+    uint8_t  data[];
+};
+typedef struct IOHibernateHandoff IOHibernateHandoff;
 
 enum 
 {
@@ -138,16 +195,25 @@ enum
     kIOHibernateProgressDarkGray      = 92
 };
 
+enum
+{
+    kIOHibernatePostWriteSleep   = 0,
+    kIOHibernatePostWriteWake    = 1,
+    kIOHibernatePostWriteHalt    = 2,
+    kIOHibernatePostWriteRestart = 3
+};
+
+
 struct hibernate_graphics_t
 {
-    unsigned long physicalAddress;     // Base address of video memory
-    unsigned long mode;                // 
-    unsigned long rowBytes;            // Number of bytes per pixel row
-    unsigned long width;               // Width
-    unsigned long height;              // Height
-    unsigned long depth;               // Pixel Depth
-
-    uint8_t      progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
+    uint32_t physicalAddress;  // Base address of video memory
+    int32_t  gfxStatus;         // EFI config restore status
+    uint32_t rowBytes;                 // Number of bytes per pixel row
+    uint32_t width;                    // Width
+    uint32_t height;                   // Height
+    uint32_t depth;                    // Pixel Depth
+
+    uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
 };
 typedef struct hibernate_graphics_t hibernate_graphics_t;
 
@@ -173,6 +239,18 @@ static const uint8_t gIOHibernateProgressAlpha                     \
     { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 }                     \
 };
 
+struct hibernate_preview_t
+{
+    uint32_t  imageCount;      // Number of images
+    uint32_t  width;           // Width
+    uint32_t  height;          // Height
+    uint32_t  depth;           // Pixel Depth
+    uint32_t  lockTime;     // Lock time
+    uint32_t  reservedG[8]; // reserved
+    uint32_t  reservedK[8]; // reserved
+};
+typedef struct hibernate_preview_t hibernate_preview_t;
+
 #ifdef KERNEL
 
 #ifdef __cplusplus
@@ -180,9 +258,12 @@ static const uint8_t gIOHibernateProgressAlpha                     \
 void     IOHibernateSystemInit(IOPMrootDomain * rootDomain);
 
 IOReturn IOHibernateSystemSleep(void);
+IOReturn IOHibernateIOKitSleep(void);
 IOReturn IOHibernateSystemHasSlept(void);
 IOReturn IOHibernateSystemWake(void);
 IOReturn IOHibernateSystemPostWake(void);
+bool     IOHibernateWasScreenLocked(void);
+void     IOHibernateSetScreenLocked(uint32_t lockState);
 
 #endif /* __cplusplus */
 
@@ -193,14 +274,18 @@ struct kern_direct_file_io_ref_t *
 kern_open_file_for_direct_io(const char * name, 
                             kern_get_file_extents_callback_t callback, 
                             void * callback_ref,
-                            dev_t * device,
+                            dev_t * partition_device_result,
+                            dev_t * image_device_result,
                              uint64_t * partitionbase_result,
-                             uint64_t * maxiocount_result);
+                             uint64_t * maxiocount_result,
+                             uint32_t * oflags,
+                             off_t offset,
+                             caddr_t addr,
+                             vm_size_t len);
 void
-kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);
-int
-kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
-int get_kernel_symfile(struct proc *p, char **symfile);
+kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref,
+                             off_t write_offset, caddr_t addr, vm_size_t write_length,
+                             off_t discard_offset, off_t discard_end);
 #endif /* _SYS_CONF_H_ */
 
 hibernate_page_list_t *
@@ -208,10 +293,12 @@ hibernate_page_list_allocate(void);
 
 kern_return_t 
 hibernate_setup(IOHibernateImageHeader * header,
-                        uint32_t free_page_ratio,
-                        uint32_t free_page_time,
+                        uint32_t  free_page_ratio,
+                        uint32_t  free_page_time,
+                        boolean_t vmflush,
                        hibernate_page_list_t ** page_list_ret,
                        hibernate_page_list_t ** page_list_wired_ret,
+                       hibernate_page_list_t ** page_list_pal_ret,
                         boolean_t * encryptedswap);
 kern_return_t 
 hibernate_teardown(hibernate_page_list_t * page_list,
@@ -220,56 +307,83 @@ hibernate_teardown(hibernate_page_list_t * page_list,
 kern_return_t 
 hibernate_processor_setup(IOHibernateImageHeader * header);
 
+void
+hibernate_gobble_pages(uint32_t gobble_count, uint32_t free_page_time);
+void
+hibernate_free_gobble_pages(void);
+
 void
 hibernate_vm_lock(void);
 void
 hibernate_vm_unlock(void);
 
+// mark pages not to be saved, based on VM system accounting
 void
 hibernate_page_list_setall(hibernate_page_list_t * page_list,
                           hibernate_page_list_t * page_list_wired,
+                          hibernate_page_list_t * page_list_pal,
                           uint32_t * pagesOut);
 
+// mark pages to be saved, or pages not to be saved but available 
+// for scratch usage during restore
 void
 hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
                                     hibernate_page_list_t * page_list_wired,
                                     uint32_t * pagesOut);
+
+// mark pages not to be saved and not for scratch usage during restore
+void
+hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
+                                 hibernate_page_list_t * page_list_wired,
+                                 uint32_t * pagesOut);
+
 void
 hibernate_page_list_discard(hibernate_page_list_t * page_list);
 
+int
+hibernate_should_abort(void);
+
 void
 hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
                                vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
 
 void 
 hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
+
 boolean_t 
 hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
 
+hibernate_bitmap_t *
+hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
+
 uint32_t
-hibernate_page_list_count(hibernate_page_list_t *list, uint32_t set, uint32_t page);
+hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
 
-void 
+uintptr_t 
 hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
 
 void
 hibernate_machine_init(void);
-boolean_t
+
+uint32_t
 hibernate_write_image(void);
 
 long
-hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
+hibernate_machine_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
 long
-hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
+hibernate_kernel_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
+void
+hibernate_newruntime_map(void * map, vm_size_t map_size, 
+                           uint32_t system_table_offset);
+
 
 extern uint32_t    gIOHibernateState;
 extern uint32_t    gIOHibernateMode;
+extern uint32_t    gIOHibernateDebugFlags;
 extern uint32_t    gIOHibernateFreeTime;       // max time to spend freeing pages (ms)
 extern uint8_t     gIOHibernateRestoreStack[];
 extern uint8_t     gIOHibernateRestoreStackEnd[];
 extern IOHibernateImageHeader *    gIOHibernateCurrentHeader;
-extern hibernate_graphics_t *      gIOHibernateGraphicsInfo;
-extern hibernate_cryptwakevars_t * gIOHibernateCryptWakeVars;
 
 #define HIBLOG(fmt, args...)   \
     { kprintf(fmt, ## args); printf(fmt, ## args); }
@@ -293,9 +407,11 @@ enum
     kIOHibernateModeOn      = 0x00000001,
     kIOHibernateModeSleep   = 0x00000002,
     kIOHibernateModeEncrypt = 0x00000004,
-
     kIOHibernateModeDiscardCleanInactive = 0x00000008,
-    kIOHibernateModeDiscardCleanActive   = 0x00000010
+    kIOHibernateModeDiscardCleanActive   = 0x00000010,
+    kIOHibernateModeSwitch     = 0x00000020,
+    kIOHibernateModeRestart    = 0x00000040,
+    kIOHibernateModeSSDInvert  = 0x00000080,
 };
 
 // IOHibernateImageHeader.signature
@@ -322,6 +438,21 @@ enum
 #define kIOHibernateFeatureKey         "Hibernation"
 #define kIOHibernatePreviewBufferKey   "IOPreviewBuffer"
 
+#ifndef kIOHibernatePreviewActiveKey
+#define kIOHibernatePreviewActiveKey   "IOHibernatePreviewActive"
+// values for kIOHibernatePreviewActiveKey
+enum {
+    kIOHibernatePreviewActive  = 0x00000001,
+    kIOHibernatePreviewUpdates = 0x00000002
+};
+#endif
+
+#define kIOHibernateOptionsKey      "IOHibernateOptions"
+#define kIOHibernateGfxStatusKey    "IOHibernateGfxStatus"
+enum {
+    kIOHibernateGfxStatusUnknown = ((int32_t) 0xFFFFFFFF)
+};
+
 #define kIOHibernateBootImageKey       "boot-image"
 #define kIOHibernateBootImageKeyKey    "boot-image-key"
 #define kIOHibernateBootSignatureKey   "boot-signature"
@@ -330,6 +461,32 @@ enum
 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
 #define kIOHibernateMachineSignatureKey          "machine-signature"
 
+#define kIOHibernateRTCVariablesKey    "IOHibernateRTCVariables"
+#define kIOHibernateSMCVariablesKey    "IOHibernateSMCVariables"
+
+#define kIOHibernateBootSwitchVarsKey                  "boot-switch-vars"
+
+#define kIOHibernateUseKernelInterpreter    0x80000000
+
+enum
+{
+       kIOPreviewImageIndexDesktop = 0, 
+       kIOPreviewImageIndexLockScreen = 1, 
+       kIOPreviewImageCount = 2
+};
+
+enum
+{
+       kIOScreenLockNoLock          = 1,
+       kIOScreenLockUnlocked        = 2,
+       kIOScreenLockLocked          = 3,
+       kIOScreenLockFileVaultDialog = 4,
+};     
+
+#define kIOScreenLockStateKey      "IOScreenLockState"
+
+#endif /* ! __IOKIT_IOHIBERNATEPRIVATE_H */
+
 #ifdef __cplusplus
 }
 #endif