]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOHibernatePrivate.h
xnu-792.24.17.tar.gz
[apple/xnu.git] / iokit / IOKit / IOHibernatePrivate.h
CommitLineData
3a60a9f5
A
1/*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
3a60a9f5 5 *
6601e61a
A
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.
8f6c56a5 11 *
6601e61a
A
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
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
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.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
3a60a9f5
A
21 */
22
23#include <stdint.h>
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
29#ifdef KERNEL
30#include <crypto/aes.h>
31#endif
32
33struct IOPolledFileExtent
34{
35 uint64_t start;
36 uint64_t length;
37};
38typedef struct IOPolledFileExtent IOPolledFileExtent;
39
40struct 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
6601e61a 68 uint8_t reserved2[24];
3a60a9f5
A
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
6601e61a 78 uint32_t reserved[82]; // make sizeof == 512
3a60a9f5
A
79
80 uint32_t fileExtentMapSize;
81 IOPolledFileExtent fileExtentMap[2];
82};
83typedef struct IOHibernateImageHeader IOHibernateImageHeader;
84
85
86struct hibernate_bitmap_t
87{
88 uint32_t first_page;
89 uint32_t last_page;
90 uint32_t bitmapwords;
91 uint32_t bitmap[0];
92};
93typedef struct hibernate_bitmap_t hibernate_bitmap_t;
94
95struct 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};
102typedef struct hibernate_page_list_t hibernate_page_list_t;
103
104struct 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};
112typedef struct hibernate_cryptwakevars_t hibernate_cryptwakevars_t;
113
114struct 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};
123typedef struct hibernate_cryptvars_t hibernate_cryptvars_t;
124
125
126enum
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
141struct hibernate_graphics_t
142{
6601e61a
A
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];
3a60a9f5
A
151};
152typedef struct hibernate_graphics_t hibernate_graphics_t;
153
154#define DECLARE_IOHIBERNATEPROGRESSALPHA \
155static 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
180void IOHibernateSystemInit(IOPMrootDomain * rootDomain);
181
182IOReturn IOHibernateSystemSleep(void);
183IOReturn IOHibernateSystemHasSlept(void);
184IOReturn IOHibernateSystemWake(void);
185IOReturn IOHibernateSystemPostWake(void);
186
187#endif /* __cplusplus */
188
189#ifdef _SYS_CONF_H_
190typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
191
192struct kern_direct_file_io_ref_t *
193kern_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);
199void
200kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref);
201int
202kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, caddr_t addr, vm_size_t len);
203int get_kernel_symfile(struct proc *p, char **symfile);
204#endif /* _SYS_CONF_H_ */
205
206hibernate_page_list_t *
207hibernate_page_list_allocate(void);
208
209kern_return_t
210hibernate_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);
216kern_return_t
217hibernate_teardown(hibernate_page_list_t * page_list,
218 hibernate_page_list_t * page_list_wired);
219
220kern_return_t
221hibernate_processor_setup(IOHibernateImageHeader * header);
222
223void
224hibernate_vm_lock(void);
225void
226hibernate_vm_unlock(void);
227
228void
229hibernate_page_list_setall(hibernate_page_list_t * page_list,
230 hibernate_page_list_t * page_list_wired,
231 uint32_t * pagesOut);
232
233void
234hibernate_page_list_setall_machine(hibernate_page_list_t * page_list,
235 hibernate_page_list_t * page_list_wired,
236 uint32_t * pagesOut);
237void
238hibernate_page_list_discard(hibernate_page_list_t * page_list);
239
240void
241hibernate_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
244void
245hibernate_page_bitset(hibernate_page_list_t * list, boolean_t set, uint32_t page);
246boolean_t
247hibernate_page_bittst(hibernate_page_list_t * list, uint32_t page);
248
249uint32_t
6601e61a 250hibernate_page_list_count(hibernate_page_list_t *list, uint32_t set, uint32_t page);
3a60a9f5
A
251
252void
253hibernate_restore_phys_page(uint64_t src, uint64_t dst, uint32_t len, uint32_t procFlags);
254
255void
256hibernate_machine_init(void);
257boolean_t
258hibernate_write_image(void);
259
260long
261hibernate_machine_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
262long
263hibernate_kernel_entrypoint(IOHibernateImageHeader * header, void * p2, void * p3, void * p4);
264
265extern uint32_t gIOHibernateState;
266extern uint32_t gIOHibernateMode;
267extern uint32_t gIOHibernateFreeTime; // max time to spend freeing pages (ms)
268extern uint8_t gIOHibernateRestoreStack[];
269extern uint8_t gIOHibernateRestoreStackEnd[];
270extern IOHibernateImageHeader * gIOHibernateCurrentHeader;
271extern hibernate_graphics_t * gIOHibernateGraphicsInfo;
272extern 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
283enum
284{
285 kIOHibernateStateInactive = 0,
286 kIOHibernateStateHibernating = 1, /* writing image */
287 kIOHibernateStateWakingFromHibernate = 2 /* booted and restored image */
288};
289
290// gIOHibernateMode, kIOHibernateModeKey
291enum
292{
293 kIOHibernateModeOn = 0x00000001,
294 kIOHibernateModeSleep = 0x00000002,
295 kIOHibernateModeEncrypt = 0x00000004,
296
297 kIOHibernateModeDiscardCleanInactive = 0x00000008,
298 kIOHibernateModeDiscardCleanActive = 0x00000010
299};
300
301// IOHibernateImageHeader.signature
302enum
303{
304 kIOHibernateHeaderSignature = 0x73696d65,
305 kIOHibernateHeaderInvalidSignature = 0x7a7a7a7a
306};
307
308// kind for hibernate_set_page_state()
309enum
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