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