]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
e5568f75 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | #ifndef _IOBUFFERMEMORYDESCRIPTOR_H | |
23 | #define _IOBUFFERMEMORYDESCRIPTOR_H | |
24 | ||
25 | #include <IOKit/IOMemoryDescriptor.h> | |
26 | ||
27 | enum { | |
1c79356b A |
28 | kIOMemoryPhysicallyContiguous = 0x00000010, |
29 | kIOMemoryPageable = 0x00000020, | |
30 | kIOMemorySharingTypeMask = 0x000f0000, | |
31 | kIOMemoryUnshared = 0x00000000, | |
55e303ae | 32 | kIOMemoryKernelUserShared = 0x00010000 |
1c79356b A |
33 | }; |
34 | ||
9bccf70c | 35 | #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1 |
1c79356b A |
36 | |
37 | class IOBufferMemoryDescriptor : public IOGeneralMemoryDescriptor | |
38 | { | |
39 | OSDeclareDefaultStructors(IOBufferMemoryDescriptor); | |
40 | ||
41 | protected: | |
42 | /*! @struct ExpansionData | |
43 | @discussion This structure will be used to expand the capablilties of this class in the future. | |
44 | */ | |
9bccf70c A |
45 | struct ExpansionData { |
46 | vm_map_t map; | |
47 | }; | |
1c79356b A |
48 | |
49 | /*! @var reserved | |
50 | Reserved for future use. (Internal use only) */ | |
51 | ExpansionData * reserved; | |
52 | ||
53 | protected: | |
54 | void * _buffer; | |
55 | vm_size_t _capacity; | |
56 | vm_offset_t _alignment; | |
57 | IOOptionBits _options; | |
58 | IOPhysicalAddress * _physAddrs; | |
59 | unsigned _physSegCount; | |
60 | ||
61 | private: | |
9bccf70c A |
62 | virtual bool initWithOptions( |
63 | IOOptionBits options, | |
64 | vm_size_t capacity, | |
65 | vm_offset_t alignment, | |
66 | task_t inTask); | |
67 | ||
68 | OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor, 0); | |
1c79356b A |
69 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 1); |
70 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 2); | |
71 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 3); | |
72 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 4); | |
73 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 5); | |
74 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 6); | |
75 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 7); | |
76 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 8); | |
77 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 9); | |
78 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 10); | |
79 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 11); | |
80 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 12); | |
81 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 13); | |
82 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 14); | |
83 | OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor, 15); | |
84 | ||
85 | protected: | |
86 | virtual void free(); | |
87 | ||
88 | virtual bool initWithAddress( void * address, /* not supported */ | |
89 | IOByteCount withLength, | |
90 | IODirection withDirection ); | |
91 | ||
92 | virtual bool initWithAddress( vm_address_t address, /* not supported */ | |
93 | IOByteCount withLength, | |
94 | IODirection withDirection, | |
95 | task_t withTask ); | |
96 | ||
97 | virtual bool initWithPhysicalAddress( | |
98 | IOPhysicalAddress address, /* not supported */ | |
99 | IOByteCount withLength, | |
100 | IODirection withDirection ); | |
101 | ||
102 | virtual bool initWithPhysicalRanges( | |
103 | IOPhysicalRange * ranges, /* not supported */ | |
104 | UInt32 withCount, | |
105 | IODirection withDirection, | |
106 | bool asReference = false ); | |
107 | ||
108 | virtual bool initWithRanges( IOVirtualRange * ranges, /* not supported */ | |
109 | UInt32 withCount, | |
110 | IODirection withDirection, | |
111 | task_t withTask, | |
112 | bool asReference = false ); | |
113 | ||
114 | IOGeneralMemoryDescriptor::withAddress; /* not supported */ | |
115 | IOGeneralMemoryDescriptor::withPhysicalAddress; /* not supported */ | |
116 | IOGeneralMemoryDescriptor::withPhysicalRanges; /* not supported */ | |
117 | IOGeneralMemoryDescriptor::withRanges; /* not supported */ | |
118 | IOGeneralMemoryDescriptor::withSubRange; /* not supported */ | |
119 | ||
120 | public: | |
121 | ||
122 | /* | |
123 | * withOptions: | |
124 | * | |
125 | * Returns a new IOBufferMemoryDescriptor with a buffer large enough to | |
126 | * hold capacity bytes. The descriptor's length is initially set to the | |
127 | * capacity. | |
128 | */ | |
129 | virtual bool initWithOptions( IOOptionBits options, | |
130 | vm_size_t capacity, | |
131 | vm_offset_t alignment); | |
132 | ||
133 | static IOBufferMemoryDescriptor * withOptions( IOOptionBits options, | |
134 | vm_size_t capacity, | |
135 | vm_offset_t alignment = 1); | |
136 | ||
9bccf70c A |
137 | /*! @function inTaskWithOptions |
138 | @abstract Create a memory buffer with memory descriptor for that buffer. Added in Mac OS X 10.2. | |
139 | @discussion This method allocates a memory buffer with a given size and alignment in the task's address space specified, and returns a memory descriptor instance representing the memory. It is recommended memory allocated for I/O or sharing via mapping be created via IOBufferMemoryDescriptor. Options passed with the request specify the kind of memory to be allocated - pageablity and sharing are specified with option bits. This function may block and so should not be called from interrupt level or while a simple lock is held. | |
140 | @param inTask The task the buffer will be allocated in. | |
141 | @param options Options for the allocation: | |
142 | kIOMemoryPhysicallyContiguous - pass to request memory be physically contiguous. This option is heavily discouraged. The request may fail if memory is fragmented, may cause large amounts of paging activity, and may take a very long time to execute. | |
143 | kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired. | |
144 | kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications. | |
145 | @param capacity The number of bytes to allocate. | |
146 | @param alignment The minimum required alignment of the buffer in bytes - 1 is the default for no required alignment. For example, pass 256 to get memory allocated at an address with bits 0-7 zero. | |
147 | @result An instance of class IOBufferMemoryDescriptor. To be released by the caller, which will free the memory desriptor and associated buffer. */ | |
148 | ||
149 | static IOBufferMemoryDescriptor * inTaskWithOptions( | |
150 | task_t inTask, | |
151 | IOOptionBits options, | |
152 | vm_size_t capacity, | |
153 | vm_offset_t alignment = 1); | |
154 | ||
1c79356b A |
155 | /* |
156 | * withCapacity: | |
157 | * | |
158 | * Returns a new IOBufferMemoryDescriptor with a buffer large enough to | |
159 | * hold capacity bytes. The descriptor's length is initially set to the | |
160 | * capacity. | |
161 | */ | |
162 | static IOBufferMemoryDescriptor * withCapacity( | |
163 | vm_size_t capacity, | |
164 | IODirection withDirection, | |
165 | bool withContiguousMemory = false); | |
166 | /* | |
167 | * initWithBytes: | |
168 | * | |
169 | * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied). | |
170 | * The descriptor's length and capacity are set to the input buffer's size. | |
171 | */ | |
172 | virtual bool initWithBytes(const void * bytes, | |
173 | vm_size_t withLength, | |
174 | IODirection withDirection, | |
175 | bool withContiguousMemory = false); | |
176 | ||
177 | /* | |
178 | * withBytes: | |
179 | * | |
180 | * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied). | |
181 | * The descriptor's length and capacity are set to the input buffer's size. | |
182 | */ | |
183 | static IOBufferMemoryDescriptor * withBytes( | |
184 | const void * bytes, | |
185 | vm_size_t withLength, | |
186 | IODirection withDirection, | |
187 | bool withContiguousMemory = false); | |
188 | ||
189 | /* | |
190 | * setLength: | |
191 | * | |
192 | * Change the buffer length of the memory descriptor. When a new buffer | |
193 | * is created, the initial length of the buffer is set to be the same as | |
194 | * the capacity. The length can be adjusted via setLength for a shorter | |
195 | * transfer (there is no need to create more buffer descriptors when you | |
196 | * can reuse an existing one, even for different transfer sizes). Note | |
197 | * that the specified length must not exceed the capacity of the buffer. | |
198 | */ | |
199 | virtual void setLength(vm_size_t length); | |
200 | ||
201 | /* | |
202 | * setDirection: | |
203 | * | |
204 | * Change the direction of the transfer. This method allows one to redirect | |
205 | * the descriptor's transfer direction. This eliminates the need to destroy | |
206 | * and create new buffers when different transfer directions are needed. | |
207 | */ | |
208 | virtual void setDirection(IODirection direction); | |
209 | ||
210 | /* | |
211 | * getCapacity: | |
212 | * | |
213 | * Get the buffer capacity | |
214 | */ | |
215 | virtual vm_size_t getCapacity() const; | |
216 | ||
217 | /* | |
218 | * getBytesNoCopy: | |
219 | * | |
220 | * Return the virtual address of the beginning of the buffer | |
221 | */ | |
222 | virtual void *getBytesNoCopy(); | |
223 | ||
224 | /* | |
225 | * getBytesNoCopy: | |
226 | * | |
227 | * Return the virtual address of an offset from the beginning of the buffer | |
228 | */ | |
229 | virtual void *getBytesNoCopy(vm_size_t start, vm_size_t withLength); | |
230 | ||
231 | /* | |
232 | * appendBytes: | |
233 | * | |
234 | * Add some data to the end of the buffer. This method automatically | |
235 | * maintains the memory descriptor buffer length. Note that appendBytes | |
236 | * will not copy past the end of the memory descriptor's current capacity. | |
237 | */ | |
238 | virtual bool appendBytes(const void *bytes, vm_size_t withLength); | |
1c79356b A |
239 | }; |
240 | ||
241 | #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */ |