2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 #ifndef _IOBUFFERMEMORYDESCRIPTOR_H
26 #define _IOBUFFERMEMORYDESCRIPTOR_H
28 #include <IOKit/IOMemoryDescriptor.h>
31 kIOMemoryDirectionMask
= 0x0000000f,
32 kIOMemoryPhysicallyContiguous
= 0x00000010,
33 kIOMemoryPageable
= 0x00000020,
34 kIOMemorySharingTypeMask
= 0x000f0000,
35 kIOMemoryUnshared
= 0x00000000,
36 kIOMemoryKernelUserShared
= 0x00010000,
39 #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1
41 class IOBufferMemoryDescriptor
: public IOGeneralMemoryDescriptor
43 OSDeclareDefaultStructors(IOBufferMemoryDescriptor
);
46 /*! @struct ExpansionData
47 @discussion This structure will be used to expand the capablilties of this class in the future.
49 struct ExpansionData
{
54 Reserved for future use. (Internal use only) */
55 ExpansionData
* reserved
;
60 vm_offset_t _alignment
;
61 IOOptionBits _options
;
62 IOPhysicalAddress
* _physAddrs
;
63 unsigned _physSegCount
;
66 virtual bool initWithOptions(
69 vm_offset_t alignment
,
72 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
73 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
74 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
75 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
76 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
77 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
78 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
79 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
80 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
81 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
82 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
84 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
85 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
86 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
87 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
92 virtual bool initWithAddress( void * address
, /* not supported */
93 IOByteCount withLength
,
94 IODirection withDirection
);
96 virtual bool initWithAddress( vm_address_t address
, /* not supported */
97 IOByteCount withLength
,
98 IODirection withDirection
,
101 virtual bool initWithPhysicalAddress(
102 IOPhysicalAddress address
, /* not supported */
103 IOByteCount withLength
,
104 IODirection withDirection
);
106 virtual bool initWithPhysicalRanges(
107 IOPhysicalRange
* ranges
, /* not supported */
109 IODirection withDirection
,
110 bool asReference
= false );
112 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
114 IODirection withDirection
,
116 bool asReference
= false );
118 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
119 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
120 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
121 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
122 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
129 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
130 * hold capacity bytes. The descriptor's length is initially set to the
133 virtual bool initWithOptions( IOOptionBits options
,
135 vm_offset_t alignment
);
137 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
139 vm_offset_t alignment
= 1);
141 /*! @function inTaskWithOptions
142 @abstract Create a memory buffer with memory descriptor for that buffer. Added in Mac OS X 10.2.
143 @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.
144 @param inTask The task the buffer will be allocated in.
145 @param options Options for the allocation:
146 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.
147 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.
148 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
149 @param capacity The number of bytes to allocate.
150 @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.
151 @result An instance of class IOBufferMemoryDescriptor. To be released by the caller, which will free the memory desriptor and associated buffer. */
153 static IOBufferMemoryDescriptor
* inTaskWithOptions(
155 IOOptionBits options
,
157 vm_offset_t alignment
= 1);
162 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
163 * hold capacity bytes. The descriptor's length is initially set to the
166 static IOBufferMemoryDescriptor
* withCapacity(
168 IODirection withDirection
,
169 bool withContiguousMemory
= false);
173 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
174 * The descriptor's length and capacity are set to the input buffer's size.
176 virtual bool initWithBytes(const void * bytes
,
177 vm_size_t withLength
,
178 IODirection withDirection
,
179 bool withContiguousMemory
= false);
184 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
185 * The descriptor's length and capacity are set to the input buffer's size.
187 static IOBufferMemoryDescriptor
* withBytes(
189 vm_size_t withLength
,
190 IODirection withDirection
,
191 bool withContiguousMemory
= false);
196 * Change the buffer length of the memory descriptor. When a new buffer
197 * is created, the initial length of the buffer is set to be the same as
198 * the capacity. The length can be adjusted via setLength for a shorter
199 * transfer (there is no need to create more buffer descriptors when you
200 * can reuse an existing one, even for different transfer sizes). Note
201 * that the specified length must not exceed the capacity of the buffer.
203 virtual void setLength(vm_size_t length
);
208 * Change the direction of the transfer. This method allows one to redirect
209 * the descriptor's transfer direction. This eliminates the need to destroy
210 * and create new buffers when different transfer directions are needed.
212 virtual void setDirection(IODirection direction
);
217 * Get the buffer capacity
219 virtual vm_size_t
getCapacity() const;
224 * Return the virtual address of the beginning of the buffer
226 virtual void *getBytesNoCopy();
231 * Return the virtual address of an offset from the beginning of the buffer
233 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
238 * Add some data to the end of the buffer. This method automatically
239 * maintains the memory descriptor buffer length. Note that appendBytes
240 * will not copy past the end of the memory descriptor's current capacity.
242 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
245 * getPhysicalSegment:
247 * Get the physical address of the buffer, relative to the current position.
248 * If the current position is at the end of the buffer, a zero is returned.
250 virtual IOPhysicalAddress
getPhysicalSegment(IOByteCount offset
,
251 IOByteCount
* length
);
254 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */