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