2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 #ifndef _IOBUFFERMEMORYDESCRIPTOR_H
24 #define _IOBUFFERMEMORYDESCRIPTOR_H
26 #include <IOKit/IOMemoryDescriptor.h>
29 kIOMemoryPhysicallyContiguous
= 0x00000010,
30 kIOMemoryPageable
= 0x00000020,
31 kIOMemoryPurgeable
= 0x00000040,
32 kIOMemorySharingTypeMask
= 0x000f0000,
33 kIOMemoryUnshared
= 0x00000000,
34 kIOMemoryKernelUserShared
= 0x00010000
37 #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1
39 @class IOBufferMemoryDescriptor
40 @abstract Provides a simple memory descriptor that allocates its own buffer memory.
43 class IOBufferMemoryDescriptor
: public IOGeneralMemoryDescriptor
45 OSDeclareDefaultStructors(IOBufferMemoryDescriptor
);
48 /*! @struct ExpansionData
49 @discussion This structure will be used to expand the capablilties of this class in the future.
51 struct ExpansionData
{
56 Reserved for future use. (Internal use only) */
57 ExpansionData
* reserved
;
62 vm_offset_t _alignment
;
63 IOOptionBits _options
;
64 IOPhysicalAddress
* _physAddrs
;
65 unsigned _physSegCount
;
68 virtual bool initWithOptions(
71 vm_offset_t alignment
,
74 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
75 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
76 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
77 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
78 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
79 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
80 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
81 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
82 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
84 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
85 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
86 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
87 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
88 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
89 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
94 virtual bool initWithAddress( void * address
, /* not supported */
95 IOByteCount withLength
,
96 IODirection withDirection
);
98 virtual bool initWithAddress( vm_address_t address
, /* not supported */
99 IOByteCount withLength
,
100 IODirection withDirection
,
103 virtual bool initWithPhysicalAddress(
104 IOPhysicalAddress address
, /* not supported */
105 IOByteCount withLength
,
106 IODirection withDirection
);
108 virtual bool initWithPhysicalRanges(
109 IOPhysicalRange
* ranges
, /* not supported */
111 IODirection withDirection
,
112 bool asReference
= false );
114 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
116 IODirection withDirection
,
118 bool asReference
= false );
120 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
121 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
122 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
123 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
124 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
131 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
132 * hold capacity bytes. The descriptor's length is initially set to the
135 virtual bool initWithOptions( IOOptionBits options
,
137 vm_offset_t alignment
);
139 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
141 vm_offset_t alignment
= 1);
143 /*! @function inTaskWithOptions
144 @abstract Creates a memory buffer with memory descriptor for that buffer.
145 @discussion Added in Mac OS X 10.2, 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 that 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.
146 @param inTask The task the buffer will be allocated in.
147 @param options Options for the allocation:<br>
148 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.<br>
149 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br>
150 kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br>
151 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
152 @param capacity The number of bytes to allocate.
153 @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.
154 @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
156 static IOBufferMemoryDescriptor
* inTaskWithOptions(
158 IOOptionBits options
,
160 vm_offset_t alignment
= 1);
165 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
166 * hold capacity bytes. The descriptor's length is initially set to the
169 static IOBufferMemoryDescriptor
* withCapacity(
171 IODirection withDirection
,
172 bool withContiguousMemory
= false);
176 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
177 * The descriptor's length and capacity are set to the input buffer's size.
179 virtual bool initWithBytes(const void * bytes
,
180 vm_size_t withLength
,
181 IODirection withDirection
,
182 bool withContiguousMemory
= false);
187 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
188 * The descriptor's length and capacity are set to the input buffer's size.
190 static IOBufferMemoryDescriptor
* withBytes(
192 vm_size_t withLength
,
193 IODirection withDirection
,
194 bool withContiguousMemory
= false);
199 * Change the buffer length of the memory descriptor. When a new buffer
200 * is created, the initial length of the buffer is set to be the same as
201 * the capacity. The length can be adjusted via setLength for a shorter
202 * transfer (there is no need to create more buffer descriptors when you
203 * can reuse an existing one, even for different transfer sizes). Note
204 * that the specified length must not exceed the capacity of the buffer.
206 virtual void setLength(vm_size_t length
);
211 * Change the direction of the transfer. This method allows one to redirect
212 * the descriptor's transfer direction. This eliminates the need to destroy
213 * and create new buffers when different transfer directions are needed.
215 virtual void setDirection(IODirection direction
);
220 * Get the buffer capacity
222 virtual vm_size_t
getCapacity() const;
227 * Return the virtual address of the beginning of the buffer
229 virtual void *getBytesNoCopy();
234 * Return the virtual address of an offset from the beginning of the buffer
236 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
241 * Add some data to the end of the buffer. This method automatically
242 * maintains the memory descriptor buffer length. Note that appendBytes
243 * will not copy past the end of the memory descriptor's current capacity.
245 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
248 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */