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