2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #ifndef _IOBUFFERMEMORYDESCRIPTOR_H
31 #define _IOBUFFERMEMORYDESCRIPTOR_H
33 #include <IOKit/IOMemoryDescriptor.h>
36 kIOMemoryPhysicallyContiguous
= 0x00000010,
37 kIOMemoryPageable
= 0x00000020,
38 kIOMemoryPurgeable
= 0x00000040,
39 kIOMemorySharingTypeMask
= 0x000f0000,
40 kIOMemoryUnshared
= 0x00000000,
41 kIOMemoryKernelUserShared
= 0x00010000
44 #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1
46 @class IOBufferMemoryDescriptor
47 @abstract Provides a simple memory descriptor that allocates its own buffer memory.
50 class IOBufferMemoryDescriptor
: public IOGeneralMemoryDescriptor
52 OSDeclareDefaultStructors(IOBufferMemoryDescriptor
);
55 /*! @struct ExpansionData
56 @discussion This structure will be used to expand the capablilties of this class in the future.
58 struct ExpansionData
{
63 Reserved for future use. (Internal use only) */
64 ExpansionData
* reserved
;
69 vm_offset_t _alignment
;
70 IOOptionBits _options
;
71 IOPhysicalAddress
* _physAddrs
;
72 unsigned _physSegCount
;
75 virtual bool initWithOptions(
78 vm_offset_t alignment
,
81 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
82 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
84 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
85 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
86 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
87 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
88 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
89 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
90 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
91 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
92 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
93 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
94 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
95 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
96 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
101 virtual bool initWithAddress( void * address
, /* not supported */
102 IOByteCount withLength
,
103 IODirection withDirection
);
105 virtual bool initWithAddress( vm_address_t address
, /* not supported */
106 IOByteCount withLength
,
107 IODirection withDirection
,
110 virtual bool initWithPhysicalAddress(
111 IOPhysicalAddress address
, /* not supported */
112 IOByteCount withLength
,
113 IODirection withDirection
);
115 virtual bool initWithPhysicalRanges(
116 IOPhysicalRange
* ranges
, /* not supported */
118 IODirection withDirection
,
119 bool asReference
= false );
121 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
123 IODirection withDirection
,
125 bool asReference
= false );
127 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
128 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
129 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
130 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
131 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
138 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
139 * hold capacity bytes. The descriptor's length is initially set to the
142 virtual bool initWithOptions( IOOptionBits options
,
144 vm_offset_t alignment
);
146 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
148 vm_offset_t alignment
= 1);
150 /*! @function inTaskWithOptions
151 @abstract Creates a memory buffer with memory descriptor for that buffer.
152 @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.
153 @param inTask The task the buffer will be allocated in.
154 @param options Options for the allocation:<br>
155 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>
156 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br>
157 kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br>
158 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
159 @param capacity The number of bytes to allocate.
160 @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.
161 @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
163 static IOBufferMemoryDescriptor
* inTaskWithOptions(
165 IOOptionBits options
,
167 vm_offset_t alignment
= 1);
172 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
173 * hold capacity bytes. The descriptor's length is initially set to the
176 static IOBufferMemoryDescriptor
* withCapacity(
178 IODirection withDirection
,
179 bool withContiguousMemory
= false);
183 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
184 * The descriptor's length and capacity are set to the input buffer's size.
186 virtual bool initWithBytes(const void * bytes
,
187 vm_size_t withLength
,
188 IODirection withDirection
,
189 bool withContiguousMemory
= false);
194 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
195 * The descriptor's length and capacity are set to the input buffer's size.
197 static IOBufferMemoryDescriptor
* withBytes(
199 vm_size_t withLength
,
200 IODirection withDirection
,
201 bool withContiguousMemory
= false);
206 * Change the buffer length of the memory descriptor. When a new buffer
207 * is created, the initial length of the buffer is set to be the same as
208 * the capacity. The length can be adjusted via setLength for a shorter
209 * transfer (there is no need to create more buffer descriptors when you
210 * can reuse an existing one, even for different transfer sizes). Note
211 * that the specified length must not exceed the capacity of the buffer.
213 virtual void setLength(vm_size_t length
);
218 * Change the direction of the transfer. This method allows one to redirect
219 * the descriptor's transfer direction. This eliminates the need to destroy
220 * and create new buffers when different transfer directions are needed.
222 virtual void setDirection(IODirection direction
);
227 * Get the buffer capacity
229 virtual vm_size_t
getCapacity() const;
234 * Return the virtual address of the beginning of the buffer
236 virtual void *getBytesNoCopy();
241 * Return the virtual address of an offset from the beginning of the buffer
243 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
248 * Add some data to the end of the buffer. This method automatically
249 * maintains the memory descriptor buffer length. Note that appendBytes
250 * will not copy past the end of the memory descriptor's current capacity.
252 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
255 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */