2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _IOBUFFERMEMORYDESCRIPTOR_H
29 #define _IOBUFFERMEMORYDESCRIPTOR_H
31 #include <IOKit/IOMemoryDescriptor.h>
34 kIOMemoryPhysicallyContiguous
= 0x00000010,
35 kIOMemoryPageable
= 0x00000020,
36 kIOMemoryPurgeable
= 0x00000040,
37 kIOMemorySharingTypeMask
= 0x000f0000,
38 kIOMemoryUnshared
= 0x00000000,
39 kIOMemoryKernelUserShared
= 0x00010000
42 #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1
44 @class IOBufferMemoryDescriptor
45 @abstract Provides a simple memory descriptor that allocates its own buffer memory.
48 class IOBufferMemoryDescriptor
: public IOGeneralMemoryDescriptor
50 OSDeclareDefaultStructors(IOBufferMemoryDescriptor
);
53 /*! @struct ExpansionData
54 @discussion This structure will be used to expand the capablilties of this class in the future.
56 struct ExpansionData
{
61 Reserved for future use. (Internal use only) */
62 ExpansionData
* reserved
;
67 vm_offset_t _alignment
;
68 IOOptionBits _options
;
69 IOPhysicalAddress
* _physAddrs
;
70 unsigned _physSegCount
;
73 virtual bool initWithOptions(
76 vm_offset_t alignment
,
79 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
80 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
81 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
82 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
84 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
85 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
86 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
87 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
88 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
89 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
90 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
91 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
92 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
93 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
94 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
99 virtual bool initWithAddress( void * address
, /* not supported */
100 IOByteCount withLength
,
101 IODirection withDirection
);
103 virtual bool initWithAddress( vm_address_t address
, /* not supported */
104 IOByteCount withLength
,
105 IODirection withDirection
,
108 virtual bool initWithPhysicalAddress(
109 IOPhysicalAddress address
, /* not supported */
110 IOByteCount withLength
,
111 IODirection withDirection
);
113 virtual bool initWithPhysicalRanges(
114 IOPhysicalRange
* ranges
, /* not supported */
116 IODirection withDirection
,
117 bool asReference
= false );
119 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
121 IODirection withDirection
,
123 bool asReference
= false );
125 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
126 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
127 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
128 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
129 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
136 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
137 * hold capacity bytes. The descriptor's length is initially set to the
140 virtual bool initWithOptions( IOOptionBits options
,
142 vm_offset_t alignment
);
144 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
146 vm_offset_t alignment
= 1);
148 /*! @function inTaskWithOptions
149 @abstract Creates a memory buffer with memory descriptor for that buffer.
150 @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.
151 @param inTask The task the buffer will be allocated in.
152 @param options Options for the allocation:<br>
153 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>
154 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br>
155 kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br>
156 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
157 @param capacity The number of bytes to allocate.
158 @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.
159 @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
161 static IOBufferMemoryDescriptor
* inTaskWithOptions(
163 IOOptionBits options
,
165 vm_offset_t alignment
= 1);
170 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
171 * hold capacity bytes. The descriptor's length is initially set to the
174 static IOBufferMemoryDescriptor
* withCapacity(
176 IODirection withDirection
,
177 bool withContiguousMemory
= false);
181 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
182 * The descriptor's length and capacity are set to the input buffer's size.
184 virtual bool initWithBytes(const void * bytes
,
185 vm_size_t withLength
,
186 IODirection withDirection
,
187 bool withContiguousMemory
= false);
192 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
193 * The descriptor's length and capacity are set to the input buffer's size.
195 static IOBufferMemoryDescriptor
* withBytes(
197 vm_size_t withLength
,
198 IODirection withDirection
,
199 bool withContiguousMemory
= false);
204 * Change the buffer length of the memory descriptor. When a new buffer
205 * is created, the initial length of the buffer is set to be the same as
206 * the capacity. The length can be adjusted via setLength for a shorter
207 * transfer (there is no need to create more buffer descriptors when you
208 * can reuse an existing one, even for different transfer sizes). Note
209 * that the specified length must not exceed the capacity of the buffer.
211 virtual void setLength(vm_size_t length
);
216 * Change the direction of the transfer. This method allows one to redirect
217 * the descriptor's transfer direction. This eliminates the need to destroy
218 * and create new buffers when different transfer directions are needed.
220 virtual void setDirection(IODirection direction
);
225 * Get the buffer capacity
227 virtual vm_size_t
getCapacity() const;
232 * Return the virtual address of the beginning of the buffer
234 virtual void *getBytesNoCopy();
239 * Return the virtual address of an offset from the beginning of the buffer
241 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
246 * Add some data to the end of the buffer. This method automatically
247 * maintains the memory descriptor buffer length. Note that appendBytes
248 * will not copy past the end of the memory descriptor's current capacity.
250 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
253 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */