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