]> git.saurik.com Git - apple/xnu.git/blame_incremental - iokit/IOKit/IOHibernatePrivate.h
xnu-792.13.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_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30
31#include <stdint.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37#ifdef KERNEL
38#include <crypto/aes.h>
39#endif
40
41struct IOPolledFileExtent
42{
43 uint64_t start;
44 uint64_t length;
45};
46typedef struct IOPolledFileExtent IOPolledFileExtent;
47
48struct IOHibernateImageHeader
49{
50 uint64_t imageSize;
51 uint64_t image1Size;
52
53 uint32_t restore1CodePage;
54 uint32_t restore1PageCount;
55 uint32_t restore1CodeOffset;
56 uint32_t restore1StackOffset;
57
58 uint32_t pageCount;
59 uint32_t bitmapSize;
60
61 uint32_t restore1Sum;
62 uint32_t image1Sum;
63 uint32_t image2Sum;
64
65 uint32_t actualRestore1Sum;
66 uint32_t actualImage1Sum;
67 uint32_t actualImage2Sum;
68
69 uint32_t actualUncompressedPages;
70 uint32_t conflictCount;
71 uint32_t nextFree;
72
73 uint32_t signature;
74 uint32_t processorFlags;
75
76 uint32_t runtimePages;
77 uint32_t runtimePageCount;
78
79 uint8_t reserved2[16];
80
81 uint64_t encryptStart;
82 uint64_t machineSignature;
83
84 uint32_t previewSize;
85 uint32_t previewPageListSize;
86
87 uint32_t diag[4];
88
89 int32_t graphicsInfoOffset;
90 int32_t cryptVarsOffset;
91 int32_t memoryMapOffset;
92 uint32_t memoryMapSize;
93 uint32_t systemTableOffset;
94
95 uint32_t reserved[77]; // make sizeof == 512
96
97 uint32_t fileExtentMapSize;
98 IOPolledFileExtent fileExtentMap[2];
99};
100typedef struct IOHibernateImageHeader IOHibernateImageHeader;
101
102
103struct hibernate_bitmap_t
104{
105 uint32_t first_page;
106 uint32_t last_page;
107 uint32_t bitmapwords;
108 uint32_t bitmap[0];
109};
110typedef struct hibernate_bitmap_t hibernate_bitmap_t;
111
112struct hibernate_page_list_t
113{
114 uint32_t list_size;
115 uint32_t page_count;
116 uint32_t bank_count;
117 hibernate_bitmap_t bank_bitmap[0];
118};
119typedef struct hibernate_page_list_t hibernate_page_list_t;
120
121struct hibernate_cryptwakevars_t
122{
123#ifdef _AES_H
124 uint8_t aes_iv[AES_BLOCK_SIZE];
125#else
126#warning undef _AES_H
127#endif
128};
129typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
130
131struct hibernate_cryptvars_t
132{
133#ifdef _AES_H
134 uint8_t aes_iv[AES_BLOCK_SIZE];
135 aes_ctx ctx;
136#else
137#warning undef _AES_H
138#endif
139};
140typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
141
142
143enum
144{
145 kIOHibernateProgressCount = 19,
146 kIOHibernateProgressWidth = 7,
147 kIOHibernateProgressHeight = 16,
148 kIOHibernateProgressSpacing = 3,
149 kIOHibernateProgressOriginY = 81,
150
151 kIOHibernateProgressSaveUnderSize = 2*5+14*2,
152
153 kIOHibernateProgressLightGray = 230,
154 kIOHibernateProgressMidGray = 174,
155 kIOHibernateProgressDarkGray = 92
156};
157
158struct hibernate_graphics_t
159{
160 unsigned long physicalAddress; // Base address of video memory
161 unsigned long mode; //
162 unsigned long rowBytes; // Number of bytes per pixel row
163 unsigned long width; // Width
164 unsigned long height; // Height
165 unsigned long depth; // Pixel Depth
166
167 uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
168};
169typedef struct hibernate_graphics_t hibernate_graphics_t;
170
171#define DECLARE_IOHIBERNATEPROGRESSALPHA \
172static const uint8_t gIOHibernateProgressAlpha \
173[kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
174{ \
175 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
176 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
177 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
178 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
179 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
180 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
181 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
182 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
183 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
184 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
185 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
186 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
187 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
188 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
189 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
190 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
191};
192
193#ifdef KERNEL
194
195#ifdef __cplusplus
196
197void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
198
199IOReturn IOHibernateSystemSleep(void);
200IOReturn IOHibernateSystemHasSlept(void);
201IOReturn IOHibernateSystemWake(void);
202IOReturn IOHibernateSystemPostWake(void);
203
204#endif /* __cplusplus */
205
206#ifdef _SYS_CONF_H_
207typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
208
209struct kern_direct_file_io_ref_t *
210kern_open_file_for_direct_io(const char * name,
211 kern_get_file_extents_callback_t callback,
212 void * callback_ref,
213 dev_t * device,
214 uint64_t * partitionbase_result,
215 uint64_t * maxiocount_result);
216void
217kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);
218int
219kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
220int get_kernel_symfile(struct proc *p, char **symfile);
221#endif /* _SYS_CONF_H_ */
222
223hibernate_page_list_t *
224hibernate_page_list_allocate(void);
225
226kern_return_t
227hibernate_setup(IOHibernateImageHeader * header,
228 uint32_t free_page_ratio,
229 uint32_t free_page_time,
230 hibernate_page_list_t ** page_list_ret,
231 hibernate_page_list_t ** page_list_wired_ret,
232 boolean_t * encryptedswap);
233kern_return_t
234hibernate_teardown(hibernate_page_list_t * page_list,
235 hibernate_page_list_t * page_list_wired);
236
237kern_return_t
238hibernate_processor_setup(IOHibernateImageHeader * header);
239
240void
241hibernate_vm_lock(void);
242void
243hibernate_vm_unlock(void);
244
245// mark pages not to be saved, based on VM system accounting
246void
247hibernate_page_list_setall(hibernate_page_list_t * page_list,
248 hibernate_page_list_t * page_list_wired,
249 uint32_t * pagesOut);
250
251// mark pages to be saved, or pages not to be saved but available
252// for scratch usage during restore
253void
254hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
255 hibernate_page_list_t * page_list_wired,
256 uint32_t * pagesOut);
257
258// mark pages not to be saved and not for scratch usage during restore
259void
260hibernate_page_list_set_volatile( hibernate_page_list_t * page_list,
261 hibernate_page_list_t * page_list_wired,
262 uint32_t * pagesOut);
263
264void
265hibernate_page_list_discard(hibernate_page_list_t * page_list);
266
267void
268hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
269 vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
270
271void
272hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
273
274boolean_t
275hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
276
277hibernate_bitmap_t *
278hibernate_page_bitmap_pin(hibernate_page_list_t * list, uint32_t * page);
279
280uint32_t
281hibernate_page_bitmap_count(hibernate_bitmap_t * bitmap, uint32_t set, uint32_t page);
282
283void
284hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
285
286void
287hibernate_machine_init(void);
288boolean_t
289hibernate_write_image(void);
290
291long
292hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
293long
294hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
295void
296hibernate_newruntime_map(void * map, vm_size_t map_size,
297 uint32_t system_table_offset);
298
299
300extern uint32_t gIOHibernateState;
301extern uint32_t gIOHibernateMode;
302extern uint32_t gIOHibernateFreeTime; // max time to spend freeing pages (ms)
303extern uint8_t gIOHibernateRestoreStack[];
304extern uint8_t gIOHibernateRestoreStackEnd[];
305extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
306extern hibernate_graphics_t * gIOHibernateGraphicsInfo;
307extern hibernate_cryptwakevars_t * gIOHibernateCryptWakeVars;
308
309#define HIBLOG(fmt, args...) \
310 { kprintf(fmt, ## args); printf(fmt, ## args); }
311
312#define HIBPRINT(fmt, args...) \
313 { kprintf(fmt, ## args); }
314
315#endif /* KERNEL */
316
317// gIOHibernateState, kIOHibernateStateKey
318enum
319{
320 kIOHibernateStateInactive = 0,
321 kIOHibernateStateHibernating = 1, /* writing image */
322 kIOHibernateStateWakingFromHibernate = 2 /* booted and restored image */
323};
324
325// gIOHibernateMode, kIOHibernateModeKey
326enum
327{
328 kIOHibernateModeOn = 0x00000001,
329 kIOHibernateModeSleep = 0x00000002,
330 kIOHibernateModeEncrypt = 0x00000004,
331
332 kIOHibernateModeDiscardCleanInactive = 0x00000008,
333 kIOHibernateModeDiscardCleanActive = 0x00000010
334};
335
336// IOHibernateImageHeader.signature
337enum
338{
339 kIOHibernateHeaderSignature = 0x73696d65,
340 kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
341};
342
343// kind for hibernate_set_page_state()
344enum
345{
346 kIOHibernatePageStateFree = 0,
347 kIOHibernatePageStateWiredSave = 1,
348 kIOHibernatePageStateUnwiredSave = 2
349};
350
351#define kIOHibernateModeKey "Hibernate Mode"
352#define kIOHibernateFileKey "Hibernate File"
353#define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
354#define kIOHibernateFreeTimeKey "Hibernate Free Time"
355
356#define kIOHibernateStateKey "IOHibernateState"
357#define kIOHibernateFeatureKey "Hibernation"
358#define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
359
360#define kIOHibernateBootImageKey "boot-image"
361#define kIOHibernateBootImageKeyKey "boot-image-key"
362#define kIOHibernateBootSignatureKey "boot-signature"
363
364#define kIOHibernateMemorySignatureKey "memory-signature"
365#define kIOHibernateMemorySignatureEnvKey "mem-sig"
366#define kIOHibernateMachineSignatureKey "machine-signature"
367
368#define kIOHibernateRTCVariablesKey "IOHibernateRTCVariables"
369
370#ifdef __cplusplus
371}
372#endif