]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOHibernatePrivate.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / iokit / IOKit / IOHibernatePrivate.h
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
34 extern "C" {
35 #endif
36
37 #ifdef KERNEL
38 #include <crypto/aes.h>
39 #endif
40
41 struct IOPolledFileExtent
42 {
43 uint64_t start;
44 uint64_t length;
45 };
46 typedef struct IOPolledFileExtent IOPolledFileExtent;
47
48 struct 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 uint8_t reserved2[24];
77
78 uint64_t encryptStart;
79 uint64_t machineSignature;
80
81 uint32_t previewSize;
82 uint32_t previewPageListSize;
83
84 uint32_t diag[4];
85
86 uint32_t reserved[82]; // make sizeof == 512
87
88 uint32_t fileExtentMapSize;
89 IOPolledFileExtent fileExtentMap[2];
90 };
91 typedef struct IOHibernateImageHeader IOHibernateImageHeader;
92
93
94 struct hibernate_bitmap_t
95 {
96 uint32_t first_page;
97 uint32_t last_page;
98 uint32_t bitmapwords;
99 uint32_t bitmap[0];
100 };
101 typedef struct hibernate_bitmap_t hibernate_bitmap_t;
102
103 struct hibernate_page_list_t
104 {
105 uint32_t list_size;
106 uint32_t page_count;
107 uint32_t bank_count;
108 hibernate_bitmap_t bank_bitmap[0];
109 };
110 typedef struct hibernate_page_list_t hibernate_page_list_t;
111
112 struct hibernate_cryptwakevars_t
113 {
114 #ifdef _AES_H
115 uint8_t aes_iv[AES_BLOCK_SIZE];
116 #else
117 #warning undef _AES_H
118 #endif
119 };
120 typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
121
122 struct hibernate_cryptvars_t
123 {
124 #ifdef _AES_H
125 uint8_t aes_iv[AES_BLOCK_SIZE];
126 aes_ctx ctx;
127 #else
128 #warning undef _AES_H
129 #endif
130 };
131 typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
132
133
134 enum
135 {
136 kIOHibernateProgressCount = 19,
137 kIOHibernateProgressWidth = 7,
138 kIOHibernateProgressHeight = 16,
139 kIOHibernateProgressSpacing = 3,
140 kIOHibernateProgressOriginY = 81,
141
142 kIOHibernateProgressSaveUnderSize = 2*5+14*2,
143
144 kIOHibernateProgressLightGray = 230,
145 kIOHibernateProgressMidGray = 174,
146 kIOHibernateProgressDarkGray = 92
147 };
148
149 struct hibernate_graphics_t
150 {
151 unsigned long physicalAddress; // Base address of video memory
152 unsigned long mode; //
153 unsigned long rowBytes; // Number of bytes per pixel row
154 unsigned long width; // Width
155 unsigned long height; // Height
156 unsigned long depth; // Pixel Depth
157
158 uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize];
159 };
160 typedef struct hibernate_graphics_t hibernate_graphics_t;
161
162 #define DECLARE_IOHIBERNATEPROGRESSALPHA \
163 static const uint8_t gIOHibernateProgressAlpha \
164 [kIOHibernateProgressHeight][kIOHibernateProgressWidth] = \
165 { \
166 { 0x00,0x63,0xd8,0xf0,0xd8,0x63,0x00 }, \
167 { 0x51,0xff,0xff,0xff,0xff,0xff,0x51 }, \
168 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
169 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
170 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
171 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
172 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
173 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
174 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
175 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
176 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
177 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
178 { 0xc3,0xff,0xff,0xff,0xff,0xff,0xc3 }, \
179 { 0xae,0xff,0xff,0xff,0xff,0xff,0xae }, \
180 { 0x54,0xff,0xff,0xff,0xff,0xff,0x54 }, \
181 { 0x00,0x66,0xdb,0xf3,0xdb,0x66,0x00 } \
182 };
183
184 #ifdef KERNEL
185
186 #ifdef __cplusplus
187
188 void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
189
190 IOReturn IOHibernateSystemSleep(void);
191 IOReturn IOHibernateSystemHasSlept(void);
192 IOReturn IOHibernateSystemWake(void);
193 IOReturn IOHibernateSystemPostWake(void);
194
195 #endif /* __cplusplus */
196
197 #ifdef _SYS_CONF_H_
198 typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
199
200 struct kern_direct_file_io_ref_t *
201 kern_open_file_for_direct_io(const char * name,
202 kern_get_file_extents_callback_t callback,
203 void * callback_ref,
204 dev_t * device,
205 uint64_t * partitionbase_result,
206 uint64_t * maxiocount_result);
207 void
208 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);
209 int
210 kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
211 int get_kernel_symfile(struct proc *p, char **symfile);
212 #endif /* _SYS_CONF_H_ */
213
214 hibernate_page_list_t *
215 hibernate_page_list_allocate(void);
216
217 kern_return_t
218 hibernate_setup(IOHibernateImageHeader * header,
219 uint32_t free_page_ratio,
220 uint32_t free_page_time,
221 hibernate_page_list_t ** page_list_ret,
222 hibernate_page_list_t ** page_list_wired_ret,
223 boolean_t * encryptedswap);
224 kern_return_t
225 hibernate_teardown(hibernate_page_list_t * page_list,
226 hibernate_page_list_t * page_list_wired);
227
228 kern_return_t
229 hibernate_processor_setup(IOHibernateImageHeader * header);
230
231 void
232 hibernate_vm_lock(void);
233 void
234 hibernate_vm_unlock(void);
235
236 void
237 hibernate_page_list_setall(hibernate_page_list_t * page_list,
238 hibernate_page_list_t * page_list_wired,
239 uint32_t * pagesOut);
240
241 void
242 hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
243 hibernate_page_list_t * page_list_wired,
244 uint32_t * pagesOut);
245 void
246 hibernate_page_list_discard(hibernate_page_list_t * page_list);
247
248 void
249 hibernate_set_page_state(hibernate_page_list_t * page_list, hibernate_page_list_t * page_list_wired,
250 vm_offset_t ppnum, vm_offset_t count, uint32_t kind);
251
252 void
253 hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
254 boolean_t
255 hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
256
257 uint32_t
258 hibernate_page_list_count(hibernate_page_list_t *list, uint32_t set, uint32_t page);
259
260 void
261 hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
262
263 void
264 hibernate_machine_init(void);
265 boolean_t
266 hibernate_write_image(void);
267
268 long
269 hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
270 long
271 hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
272
273 extern uint32_t gIOHibernateState;
274 extern uint32_t gIOHibernateMode;
275 extern uint32_t gIOHibernateFreeTime; // max time to spend freeing pages (ms)
276 extern uint8_t gIOHibernateRestoreStack[];
277 extern uint8_t gIOHibernateRestoreStackEnd[];
278 extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
279 extern hibernate_graphics_t * gIOHibernateGraphicsInfo;
280 extern hibernate_cryptwakevars_t * gIOHibernateCryptWakeVars;
281
282 #define HIBLOG(fmt, args...) \
283 { kprintf(fmt, ## args); printf(fmt, ## args); }
284
285 #define HIBPRINT(fmt, args...) \
286 { kprintf(fmt, ## args); }
287
288 #endif /* KERNEL */
289
290 // gIOHibernateState, kIOHibernateStateKey
291 enum
292 {
293 kIOHibernateStateInactive = 0,
294 kIOHibernateStateHibernating = 1, /* writing image */
295 kIOHibernateStateWakingFromHibernate = 2 /* booted and restored image */
296 };
297
298 // gIOHibernateMode, kIOHibernateModeKey
299 enum
300 {
301 kIOHibernateModeOn = 0x00000001,
302 kIOHibernateModeSleep = 0x00000002,
303 kIOHibernateModeEncrypt = 0x00000004,
304
305 kIOHibernateModeDiscardCleanInactive = 0x00000008,
306 kIOHibernateModeDiscardCleanActive = 0x00000010
307 };
308
309 // IOHibernateImageHeader.signature
310 enum
311 {
312 kIOHibernateHeaderSignature = 0x73696d65,
313 kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
314 };
315
316 // kind for hibernate_set_page_state()
317 enum
318 {
319 kIOHibernatePageStateFree = 0,
320 kIOHibernatePageStateWiredSave = 1,
321 kIOHibernatePageStateUnwiredSave = 2
322 };
323
324 #define kIOHibernateModeKey "Hibernate Mode"
325 #define kIOHibernateFileKey "Hibernate File"
326 #define kIOHibernateFreeRatioKey "Hibernate Free Ratio"
327 #define kIOHibernateFreeTimeKey "Hibernate Free Time"
328
329 #define kIOHibernateStateKey "IOHibernateState"
330 #define kIOHibernateFeatureKey "Hibernation"
331 #define kIOHibernatePreviewBufferKey "IOPreviewBuffer"
332
333 #define kIOHibernateBootImageKey "boot-image"
334 #define kIOHibernateBootImageKeyKey "boot-image-key"
335 #define kIOHibernateBootSignatureKey "boot-signature"
336
337 #define kIOHibernateMemorySignatureKey "memory-signature"
338 #define kIOHibernateMemorySignatureEnvKey "mem-sig"
339 #define kIOHibernateMachineSignatureKey "machine-signature"
340
341 #ifdef __cplusplus
342 }
343 #endif