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