The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/iokit/IOKit/IOHibernatePrivate.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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
   32 extern "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 
   43 struct IOPolledFileExtent
   44 {
   45     uint64_t    start;
   46     uint64_t    length;
   47 };
   48 typedef struct IOPolledFileExtent IOPolledFileExtent;
   49 
   50 struct IOHibernateImageHeader
   51 {
   52     uint64_t    imageSize;
   53     uint64_t    image1Size;
   54     
   55     uint32_t    restore1CodePhysPage;
   56     uint32_t    reserved1;
   57     uint64_t    restore1CodeVirt;
   58     uint32_t    restore1PageCount;
   59     uint32_t    restore1CodeOffset;
   60     uint32_t    restore1StackOffset;
   61     
   62     uint32_t    pageCount;
   63     uint32_t    bitmapSize;
   64 
   65     uint32_t    restore1Sum;
   66     uint32_t    image1Sum;
   67     uint32_t    image2Sum;
   68 
   69     uint32_t    actualRestore1Sum;
   70     uint32_t    actualImage1Sum;
   71     uint32_t    actualImage2Sum;
   72 
   73     uint32_t    actualUncompressedPages;
   74     uint32_t    conflictCount;
   75     uint32_t    nextFree;
   76 
   77     uint32_t    signature;
   78     uint32_t    processorFlags;
   79 
   80     uint32_t    runtimePages;
   81     uint32_t    runtimePageCount;
   82     uint64_t    runtimeVirtualPages __attribute__ ((packed));
   83 
   84     uint32_t    performanceDataStart;
   85     uint32_t    performanceDataSize;
   86     
   87     uint64_t    encryptStart __attribute__ ((packed));
   88     uint64_t    machineSignature __attribute__ ((packed));
   89 
   90     uint32_t    previewSize;
   91     uint32_t    previewPageListSize;
   92 
   93     uint32_t    diag[4];
   94 
   95     uint32_t    handoffPages;
   96     uint32_t    handoffPageCount;
   97 
   98     uint32_t    systemTableOffset;
   99 
  100     uint32_t    debugFlags;
  101     uint32_t    options;
  102     uint32_t    sleepTime;
  103 
  104     uint32_t    reserved[69];           // make sizeof == 512
  105 
  106     uint64_t    encryptEnd __attribute__ ((packed));
  107     uint64_t    deviceBase __attribute__ ((packed));
  108 
  109     uint32_t            fileExtentMapSize;
  110     IOPolledFileExtent  fileExtentMap[2];
  111 };
  112 typedef struct IOHibernateImageHeader IOHibernateImageHeader;
  113 
  114 enum
  115 {
  116     kIOHibernateDebugRestoreLogs = 0x00000001
  117 };
  118 
  119 // options & IOHibernateOptions property
  120 enum
  121 {
  122     kIOHibernateOptionSSD           = 0x00000001,
  123     kIOHibernateOptionColor         = 0x00000002,
  124     kIOHibernateOptionProgress      = 0x00000004,
  125     kIOHibernateOptionDarkWake      = 0x00000008,
  126 };
  127 
  128 struct hibernate_bitmap_t
  129 {
  130     uint32_t    first_page;
  131     uint32_t    last_page;
  132     uint32_t    bitmapwords;
  133     uint32_t    bitmap[0];
  134 };
  135 typedef struct hibernate_bitmap_t hibernate_bitmap_t;
  136 
  137 struct hibernate_page_list_t
  138 {
  139     uint32_t              list_size;
  140     uint32_t              page_count;
  141     uint32_t              bank_count;
  142     hibernate_bitmap_t    bank_bitmap[0];
  143 };
  144 typedef struct hibernate_page_list_t hibernate_page_list_t;
  145 
  146 #if defined(_AES_H)
  147 
  148 struct hibernate_cryptwakevars_t
  149 {
  150     uint8_t aes_iv[AES_BLOCK_SIZE];
  151 };
  152 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
  153 
  154 struct hibernate_cryptvars_t
  155 {
  156     uint8_t aes_iv[AES_BLOCK_SIZE];
  157     aes_ctx ctx;
  158 };
  159 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
  160 
  161 #endif /* defined(_AES_H) */
  162 
  163 enum 
  164 {
  165     kIOHibernateHandoffType                 = 0x686f0000,
  166     kIOHibernateHandoffTypeEnd              = kIOHibernateHandoffType + 0,
  167     kIOHibernateHandoffTypeGraphicsInfo     = kIOHibernateHandoffType + 1,
  168     kIOHibernateHandoffTypeCryptVars        = kIOHibernateHandoffType + 2,
  169     kIOHibernateHandoffTypeMemoryMap        = kIOHibernateHandoffType + 3,
  170     kIOHibernateHandoffTypeDeviceTree       = kIOHibernateHandoffType + 4,
  171     kIOHibernateHandoffTypeDeviceProperties = kIOHibernateHandoffType + 5,
  172     kIOHibernateHandoffTypeKeyStore         = kIOHibernateHandoffType + 6,
  173 };
  174 
  175 struct IOHibernateHandoff
  176 {
  177     uint32_t type;
  178     uint32_t bytecount;
  179     uint8_t  data[];
  180 };
  181 typedef struct IOHibernateHandoff IOHibernateHandoff;
  182 
  183 enum 
  184 {
  185     kIOHibernateProgressCount         = 19,
  186     kIOHibernateProgressWidth         = 7,
  187     kIOHibernateProgressHeight        = 16,
  188     kIOHibernateProgressSpacing       = 3,
  189     kIOHibernateProgressOriginY       = 81,
  190 
  191     kIOHibernateProgressSaveUnderSize = 2*5+14*2,
  192 
  193     kIOHibernateProgressLightGray     = 230,
  194     kIOHibernateProgressMidGray       = 174,
  195     kIOHibernateProgressDarkGray      = 92
  196 };
  197 
  198 enum
  199 {
  200     kIOHibernatePostWriteSleep   = 0,
  201     kIOHibernatePostWriteWake    = 1,
  202     kIOHibernatePostWriteHalt    = 2,
  203     kIOHibernatePostWriteRestart = 3
  204 };
  205 
  206 
  207 struct hibernate_graphics_t
  208 {
  209     uint32_t physicalAddress;   // Base address of video memory
  210     int32_t  gfxStatus;         // EFI config restore status
  211     uint32_t rowBytes;                  // Number of bytes per pixel row
  212     uint32_t width;                     // Width
  213     uint32_t height;                    // Height
  214     uint32_t depth;                     // Pixel Depth
  215 
  216     uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
  217 };
  218 typedef struct hibernate_graphics_t hibernate_graphics_t;
  219 
  220 #define DECLARE_IOHIBERNATEPROGRESSALPHA                                \
  221 static const uint8_t gIOHibernateProgressAlpha                  \
  222 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] =       \
  223 {                                                               \
  224     { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 },                     \
  225     { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 },                     \
  226     { 0xae,0xff,0xff,0xff,0xff,0xff,0xae },                     \
  227     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  228     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  229     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  230     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  231     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  232     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  233     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  234     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  235     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  236     { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 },                     \
  237     { 0xae,0xff,0xff,0xff,0xff,0xff,0xae },                     \
  238     { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 },                     \
  239     { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 }                      \
  240 };
  241 
  242 struct hibernate_preview_t
  243 {
  244     uint32_t  imageCount;       // Number of images
  245     uint32_t  width;            // Width
  246     uint32_t  height;           // Height
  247     uint32_t  depth;            // Pixel Depth
  248     uint32_t  lockTime;     // Lock time
  249     uint32_t  reservedG[8]; // reserved
  250     uint32_t  reservedK[8]; // reserved
  251 };
  252 typedef struct hibernate_preview_t hibernate_preview_t;
  253 
  254 #ifdef KERNEL
  255 
  256 #ifdef __cplusplus
  257 
  258 void     IOHibernateSystemInit(IOPMrootDomain * rootDomain);
  259 
  260 IOReturn IOHibernateSystemSleep(void);
  261 IOReturn IOHibernateIOKitSleep(void);
  262 IOReturn IOHibernateSystemHasSlept(void);
  263 IOReturn IOHibernateSystemWake(void);
  264 IOReturn IOHibernateSystemPostWake(void);
  265 bool     IOHibernateWasScreenLocked(void);
  266 void     IOHibernateSetScreenLocked(uint32_t lockState);
  267 void     IOHibernateSystemRestart(void);
  268 
  269 #endif /* __cplusplus */
  270 
  271 #ifdef _SYS_CONF_H_
  272 typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
  273 
  274 struct kern_direct_file_io_ref_t *
  275 kern_open_file_for_direct_io(const char * name, 
  276                              kern_get_file_extents_callback_t callback, 
  277                              void * callback_ref,
  278                              dev_t * partition_device_result,
  279                              dev_t * image_device_result,
  280                              uint64_t * partitionbase_result,
  281                              uint64_t * maxiocount_result,
  282                              uint32_t * oflags,
  283                              off_t offset,
  284                              caddr_t addr,
  285                              vm_size_t len);
  286 void
  287 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref,
  288                               off_t write_offset, caddr_t addr, vm_size_t write_length,
  289                               off_t discard_offset, off_t discard_end);
  290 #endif /* _SYS_CONF_H_ */
  291 
  292 hibernate_page_list_t *
  293 hibernate_page_list_allocate(void);
  294 
  295 kern_return_t 
  296 hibernate_setup(IOHibernateImageHeader * header,
  297                         uint32_t  free_page_ratio,
  298                         uint32_t  free_page_time,
  299                         boolean_t vmflush,
  300                         hibernate_page_list_t ** page_list_ret,
  301                         hibernate_page_list_t ** page_list_wired_ret,
  302                         hibernate_page_list_t ** page_list_pal_ret,
  303                         boolean_t * encryptedswap);
  304 kern_return_t 
  305 hibernate_teardown(hibernate_page_list_t * page_list,
  306                     hibernate_page_list_t * page_list_wired,
  307                     hibernate_page_list_t * page_list_pal);
  308 
  309 kern_return_t 
  310 hibernate_processor_setup(IOHibernateImageHeader * header);
  311 
  312 void
  313 hibernate_gobble_pages(uint32_t gobble_count, uint32_t free_page_time);
  314 void
  315 hibernate_free_gobble_pages(void);
  316 
  317 void
  318 hibernate_vm_lock(void);
  319 void
  320 hibernate_vm_unlock(void);
  321 
  322 // mark pages not to be saved, based on VM system accounting
  323 void
  324 hibernate_page_list_setall(hibernate_page_list_t * page_list,
  325                            hibernate_page_list_t * page_list_wired,
  326                            hibernate_page_list_t * page_list_pal,
  327                            uint32_t * pagesOut);
  328 
  329 // mark pages to be saved, or pages not to be saved but available 
  330 // for scratch usage during restore
  331 void
  332 hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
  333                                     hibernate_page_list_t * page_list_wired,
  334                                     uint32_t * pagesOut);
  335 
  336 // mark pages not to be saved and not for scratch usage during restore
  337 void
  338 hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
  339                                   hibernate_page_list_t * page_list_wired,
  340                                   uint32_t * pagesOut);
  341 
  342 void
  343 hibernate_page_list_discard(hibernate_page_list_t * page_list);
  344 
  345 int
  346 hibernate_should_abort(void);
  347 
  348 void
  349 hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
  350                                 vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
  351 
  352 void 
  353 hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
  354 
  355 boolean_t 
  356 hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
  357 
  358 hibernate_bitmap_t *
  359 hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
  360 
  361 uint32_t
  362 hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
  363 
  364 uintptr_t 
  365 hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
  366 
  367 void
  368 hibernate_machine_init(void);
  369 
  370 uint32_t
  371 hibernate_write_image(void);
  372 
  373 long
  374 hibernate_machine_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
  375 long
  376 hibernate_kernel_entrypoint(uint32_t p1, uint32_t p2, uint32_t p3, uint32_t p4);
  377 void
  378 hibernate_newruntime_map(void * map, vm_size_t map_size, 
  379                             uint32_t system_table_offset);
  380 
  381 
  382 extern uint32_t    gIOHibernateState;
  383 extern uint32_t    gIOHibernateMode;
  384 extern uint32_t    gIOHibernateDebugFlags;
  385 extern uint32_t    gIOHibernateFreeTime;        // max time to spend freeing pages (ms)
  386 extern uint8_t     gIOHibernateRestoreStack[];
  387 extern uint8_t     gIOHibernateRestoreStackEnd[];
  388 extern IOHibernateImageHeader *    gIOHibernateCurrentHeader;
  389 
  390 #define HIBLOG(fmt, args...)    \
  391     { kprintf(fmt, ## args); printf(fmt, ## args); }
  392 
  393 #define HIBPRINT(fmt, args...)  \
  394     { kprintf(fmt, ## args); }
  395 
  396 #endif /* KERNEL */
  397 
  398 // gIOHibernateState, kIOHibernateStateKey
  399 enum
  400 {
  401     kIOHibernateStateInactive            = 0,
  402     kIOHibernateStateHibernating         = 1,   /* writing image */
  403     kIOHibernateStateWakingFromHibernate = 2    /* booted and restored image */
  404 };
  405 
  406 // gIOHibernateMode, kIOHibernateModeKey
  407 enum
  408 {
  409     kIOHibernateModeOn      = 0x00000001,
  410     kIOHibernateModeSleep   = 0x00000002,
  411     kIOHibernateModeEncrypt = 0x00000004,
  412     kIOHibernateModeDiscardCleanInactive = 0x00000008,
  413     kIOHibernateModeDiscardCleanActive   = 0x00000010,
  414     kIOHibernateModeSwitch      = 0x00000020,
  415     kIOHibernateModeRestart     = 0x00000040,
  416     kIOHibernateModeSSDInvert   = 0x00000080,
  417 };
  418 
  419 // IOHibernateImageHeader.signature
  420 enum
  421 {
  422     kIOHibernateHeaderSignature        = 0x73696d65,
  423     kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
  424 };
  425 
  426 // kind for hibernate_set_page_state()
  427 enum
  428 {
  429     kIOHibernatePageStateFree        = 0,
  430     kIOHibernatePageStateWiredSave   = 1,
  431     kIOHibernatePageStateUnwiredSave = 2
  432 };
  433 
  434 #define kIOHibernateModeKey             "Hibernate Mode"
  435 #define kIOHibernateFileKey             "Hibernate File"
  436 #define kIOHibernateFreeRatioKey        "Hibernate Free Ratio"
  437 #define kIOHibernateFreeTimeKey         "Hibernate Free Time"
  438 
  439 #define kIOHibernateStateKey            "IOHibernateState"
  440 #define kIOHibernateFeatureKey          "Hibernation"
  441 #define kIOHibernatePreviewBufferKey    "IOPreviewBuffer"
  442 
  443 #ifndef kIOHibernatePreviewActiveKey
  444 #define kIOHibernatePreviewActiveKey    "IOHibernatePreviewActive"
  445 // values for kIOHibernatePreviewActiveKey
  446 enum {
  447     kIOHibernatePreviewActive  = 0x00000001,
  448     kIOHibernatePreviewUpdates = 0x00000002
  449 };
  450 #endif
  451 
  452 #define kIOHibernateOptionsKey      "IOHibernateOptions"
  453 #define kIOHibernateGfxStatusKey    "IOHibernateGfxStatus"
  454 enum {
  455     kIOHibernateGfxStatusUnknown = ((int32_t) 0xFFFFFFFF)
  456 };
  457 
  458 #define kIOHibernateBootImageKey        "boot-image"
  459 #define kIOHibernateBootImageKeyKey     "boot-image-key"
  460 #define kIOHibernateBootSignatureKey    "boot-signature"
  461 
  462 #define kIOHibernateMemorySignatureKey    "memory-signature"
  463 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
  464 #define kIOHibernateMachineSignatureKey   "machine-signature"
  465 
  466 #define kIOHibernateRTCVariablesKey     "IOHibernateRTCVariables"
  467 #define kIOHibernateSMCVariablesKey     "IOHibernateSMCVariables"
  468 
  469 #define kIOHibernateBootSwitchVarsKey   "boot-switch-vars"
  470 
  471 #define kIOHibernateBootNoteKey         "boot-note"
  472 
  473 
  474 #define kIOHibernateUseKernelInterpreter    0x80000000
  475 
  476 enum
  477 {
  478         kIOPreviewImageIndexDesktop = 0, 
  479         kIOPreviewImageIndexLockScreen = 1, 
  480         kIOPreviewImageCount = 2
  481 };
  482 
  483 enum
  484 {
  485         kIOScreenLockNoLock          = 1,
  486         kIOScreenLockUnlocked        = 2,
  487         kIOScreenLockLocked          = 3,
  488         kIOScreenLockFileVaultDialog = 4,
  489 };      
  490 
  491 #define kIOScreenLockStateKey      "IOScreenLockState"
  492 
  493 #endif /* ! __IOKIT_IOHIBERNATEPRIVATE_H */
  494 
  495 #ifdef __cplusplus
  496 }
  497 #endif

Cache object: 95df421a25c351cc5d288d49a6859df7


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.