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