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