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