]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOPolledInterface.h
498814c826752431179f1a560d19e2fb4c752044
[apple/xnu.git] / iokit / IOKit / IOPolledInterface.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 #ifndef _IOPOLLEDINTERFACE_H_
30 #define _IOPOLLEDINTERFACE_H_
31
32 enum{
33 kIOPolledPreflightState = 1,
34 kIOPolledBeforeSleepState = 2,
35 kIOPolledAfterSleepState = 3,
36 kIOPolledPostflightState = 4,
37
38 kIOPolledPreflightCoreDumpState = 5,
39 kIOPolledPostflightCoreDumpState = 6,
40
41 kIOPolledBeforeSleepStateAborted = 7,
42 };
43
44 #if defined(__cplusplus)
45
46 #include <libkern/c++/OSObject.h>
47 #include <IOKit/IOMemoryDescriptor.h>
48
49 #define kIOPolledInterfaceSupportKey "IOPolledInterface"
50 #define kIOPolledInterfaceActiveKey "IOPolledInterfaceActive"
51 #define kIOPolledInterfaceStackKey "IOPolledInterfaceStack"
52
53 enum{
54 kIOPolledWrite = 1,
55 kIOPolledRead = 2,
56 kIOPolledFlush = 3
57 };
58
59 typedef void (*IOPolledCompletionAction)( void * target,
60 void * parameter,
61 IOReturn status,
62 uint64_t actualByteCount);
63 struct IOPolledCompletion {
64 void * target;
65 IOPolledCompletionAction action;
66 void * parameter;
67 };
68
69 class IOPolledInterface : public OSObject
70 {
71 OSDeclareAbstractStructors(IOPolledInterface);
72
73 protected:
74 struct ExpansionData { };
75 ExpansionData * reserved;
76
77 public:
78 virtual IOReturn probe(IOService * target) = 0;
79
80 virtual IOReturn open( IOOptionBits state, IOMemoryDescriptor * buffer) = 0;
81 virtual IOReturn close(IOOptionBits state) = 0;
82
83 virtual IOReturn startIO(uint32_t operation,
84 uint32_t bufferOffset,
85 uint64_t deviceOffset,
86 uint64_t length,
87 IOPolledCompletion completion) = 0;
88
89 virtual IOReturn checkForWork(void) = 0;
90
91 virtual IOReturn setEncryptionKey(const uint8_t * key, size_t keySize);
92
93 OSMetaClassDeclareReservedUsed(IOPolledInterface, 0);
94 OSMetaClassDeclareReservedUnused(IOPolledInterface, 1);
95 OSMetaClassDeclareReservedUnused(IOPolledInterface, 2);
96 OSMetaClassDeclareReservedUnused(IOPolledInterface, 3);
97 OSMetaClassDeclareReservedUnused(IOPolledInterface, 4);
98 OSMetaClassDeclareReservedUnused(IOPolledInterface, 5);
99 OSMetaClassDeclareReservedUnused(IOPolledInterface, 6);
100 OSMetaClassDeclareReservedUnused(IOPolledInterface, 7);
101 OSMetaClassDeclareReservedUnused(IOPolledInterface, 8);
102 OSMetaClassDeclareReservedUnused(IOPolledInterface, 9);
103 OSMetaClassDeclareReservedUnused(IOPolledInterface, 10);
104 OSMetaClassDeclareReservedUnused(IOPolledInterface, 11);
105 OSMetaClassDeclareReservedUnused(IOPolledInterface, 12);
106 OSMetaClassDeclareReservedUnused(IOPolledInterface, 13);
107 OSMetaClassDeclareReservedUnused(IOPolledInterface, 14);
108 OSMetaClassDeclareReservedUnused(IOPolledInterface, 15);
109 };
110
111 #endif /* defined(__cplusplus) */
112
113 #ifdef XNU_KERNEL_PRIVATE
114
115 #include <libkern/crypto/aes.h>
116 #include <IOKit/IOTypes.h>
117 #include <IOKit/IOHibernatePrivate.h>
118
119 // kern_open_file_for_direct_io() flags
120 enum{
121 kIOPolledFileCreate = 0x00000001,
122 kIOPolledFileHibernate = 0x00000002,
123 };
124
125 // kern_open_file_for_direct_io() oflags
126 enum{
127 kIOPolledFileSSD = 0x00000001
128 };
129
130 #if !defined(__cplusplus)
131 typedef struct IORegistryEntry IORegistryEntry;
132 typedef struct OSData OSData;
133 typedef struct OSArray OSArray;
134 typedef struct IOMemoryDescriptor IOMemoryDescriptor;
135 typedef struct IOPolledFilePollers IOPolledFilePollers;
136 #else
137 class IOPolledFilePollers;
138 #endif
139
140 struct IOPolledFileIOVars {
141 IOPolledFilePollers * pollers;
142 struct kern_direct_file_io_ref_t * fileRef;
143 OSData * fileExtents;
144 uint64_t block0;
145 IOByteCount blockSize;
146 uint64_t maxiobytes;
147 IOByteCount bufferLimit;
148 uint8_t * buffer;
149 IOByteCount bufferSize;
150 IOByteCount bufferOffset;
151 IOByteCount bufferHalf;
152 IOByteCount extentRemaining;
153 IOByteCount lastRead;
154 IOByteCount readEnd;
155 uint32_t flags;
156 uint64_t fileSize;
157 uint64_t position;
158 uint64_t extentPosition;
159 uint64_t encryptStart;
160 uint64_t encryptEnd;
161 uint64_t cryptBytes;
162 AbsoluteTime cryptTime;
163 IOPolledFileExtent * extentMap;
164 IOPolledFileExtent * currentExtent;
165 bool allocated;
166 };
167
168 typedef struct IOPolledFileIOVars IOPolledFileIOVars;
169
170 struct IOPolledFileCryptVars {
171 uint8_t aes_iv[AES_BLOCK_SIZE];
172 aes_ctx ctx;
173 };
174 typedef struct IOPolledFileCryptVars IOPolledFileCryptVars;
175
176 #if defined(__cplusplus)
177
178 IOReturn IOPolledFileOpen(const char * filename,
179 uint32_t flags,
180 uint64_t setFileSize, uint64_t fsFreeSize,
181 void * write_file_addr, size_t write_file_len,
182 IOPolledFileIOVars ** fileVars,
183 OSData ** imagePath,
184 uint8_t * volumeCryptKey, size_t * keySize);
185
186 IOReturn IOPolledFileClose(IOPolledFileIOVars ** pVars,
187 off_t write_offset, void * addr, size_t write_length,
188 off_t discard_offset, off_t discard_end);
189
190 IOReturn IOPolledFilePollersSetup(IOPolledFileIOVars * vars, uint32_t openState);
191
192 LIBKERN_RETURNS_NOT_RETAINED IOMemoryDescriptor * IOPolledFileGetIOBuffer(IOPolledFileIOVars * vars);
193
194 #endif /* defined(__cplusplus) */
195
196 #if defined(__cplusplus)
197 #define __C "C"
198 #else
199 #define __C
200 #endif
201
202 extern __C IOReturn IOPolledFileSeek(IOPolledFileIOVars * vars, uint64_t position);
203
204 extern __C IOReturn IOPolledFileWrite(IOPolledFileIOVars * vars,
205 const uint8_t * bytes, IOByteCount size,
206 IOPolledFileCryptVars * cryptvars);
207 extern __C IOReturn IOPolledFileRead(IOPolledFileIOVars * vars,
208 uint8_t * bytes, IOByteCount size,
209 IOPolledFileCryptVars * cryptvars);
210
211 extern __C IOReturn IOPolledFileFlush(IOPolledFileIOVars * vars);
212
213 extern __C IOReturn IOPolledFilePollersOpen(IOPolledFileIOVars * vars, uint32_t state, bool abortable);
214
215 extern __C IOReturn IOPolledFilePollersClose(IOPolledFileIOVars * vars, uint32_t state);
216
217 extern __C IOReturn IOPolledFilePollersSetEncryptionKey(IOPolledFileIOVars * vars,
218 const uint8_t * key, size_t keySize);
219
220 extern __C IOPolledFileIOVars * gCoreFileVars;
221
222 #ifdef _SYS_CONF_H_
223
224 __BEGIN_DECLS
225
226 typedef void (*kern_get_file_extents_callback_t)(void * ref, uint64_t start, uint64_t size);
227
228 struct kern_direct_file_io_ref_t *
229 kern_open_file_for_direct_io(const char * name,
230 uint32_t flags,
231 kern_get_file_extents_callback_t callback,
232 void * callback_ref,
233 off_t set_file_size,
234 off_t fs_free_size,
235 off_t write_file_offset,
236 void * write_file_addr,
237 size_t write_file_len,
238 dev_t * partition_device_result,
239 dev_t * image_device_result,
240 uint64_t * partitionbase_result,
241 uint64_t * maxiocount_result,
242 uint32_t * oflags);
243 void
244 kern_close_file_for_direct_io(struct kern_direct_file_io_ref_t * ref,
245 off_t write_offset, void * addr, size_t write_length,
246 off_t discard_offset, off_t discard_end);
247 int
248 kern_write_file(struct kern_direct_file_io_ref_t * ref, off_t offset, void * addr, size_t len, int ioflag);
249 int
250 kern_read_file(struct kern_direct_file_io_ref_t * ref, off_t offset, void * addr, size_t len, int ioflag);
251
252 struct mount *
253 kern_file_mount(struct kern_direct_file_io_ref_t * ref);
254
255 enum{
256 kIOPolledFileMountChangeMount = 0x00000101,
257 kIOPolledFileMountChangeUnmount = 0x00000102,
258 kIOPolledFileMountChangeWillResize = 0x00000201,
259 kIOPolledFileMountChangeDidResize = 0x00000202,
260 };
261 extern void IOPolledFileMountChange(struct mount * mp, uint32_t op);
262
263 __END_DECLS
264
265 #endif /* _SYS_CONF_H_ */
266
267 #endif /* XNU_KERNEL_PRIVATE */
268
269 #endif /* _IOPOLLEDINTERFACE_H_ */