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 kIOMemoryPhysicallyContiguous
= 0x00000010,
32 kIOMemoryPageable
= 0x00000020,
33 kIOMemorySharingTypeMask
= 0x000f0000,
34 kIOMemoryUnshared
= 0x00000000,
35 kIOMemoryKernelUserShared
= 0x00010000,
38 #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1
40 class IOBufferMemoryDescriptor
: public IOGeneralMemoryDescriptor
42 OSDeclareDefaultStructors(IOBufferMemoryDescriptor
);
45 /*! @struct ExpansionData
46 @discussion This structure will be used to expand the capablilties of this class in the future.
48 struct ExpansionData
{
53 Reserved for future use. (Internal use only) */
54 ExpansionData
* reserved
;
59 vm_offset_t _alignment
;
60 IOOptionBits _options
;
61 IOPhysicalAddress
* _physAddrs
;
62 unsigned _physSegCount
;
65 virtual bool initWithOptions(
68 vm_offset_t alignment
,
71 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
72 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
73 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
74 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
75 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
76 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
77 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
78 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
79 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
80 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
81 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
82 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
84 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
85 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
86 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
91 virtual bool initWithAddress( void * address
, /* not supported */
92 IOByteCount withLength
,
93 IODirection withDirection
);
95 virtual bool initWithAddress( vm_address_t address
, /* not supported */
96 IOByteCount withLength
,
97 IODirection withDirection
,
100 virtual bool initWithPhysicalAddress(
101 IOPhysicalAddress address
, /* not supported */
102 IOByteCount withLength
,
103 IODirection withDirection
);
105 virtual bool initWithPhysicalRanges(
106 IOPhysicalRange
* ranges
, /* not supported */
108 IODirection withDirection
,
109 bool asReference
= false );
111 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
113 IODirection withDirection
,
115 bool asReference
= false );
117 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
118 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
119 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
120 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
121 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
128 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
129 * hold capacity bytes. The descriptor's length is initially set to the
132 virtual bool initWithOptions( IOOptionBits options
,
134 vm_offset_t alignment
);
136 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
138 vm_offset_t alignment
= 1);
140 /*! @function inTaskWithOptions
141 @abstract Create a memory buffer with memory descriptor for that buffer. Added in Mac OS X 10.2.
142 @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.
143 @param inTask The task the buffer will be allocated in.
144 @param options Options for the allocation:
145 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.
146 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.
147 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
148 @param capacity The number of bytes to allocate.
149 @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.
150 @result An instance of class IOBufferMemoryDescriptor. To be released by the caller, which will free the memory desriptor and associated buffer. */
152 static IOBufferMemoryDescriptor
* inTaskWithOptions(
154 IOOptionBits options
,
156 vm_offset_t alignment
= 1);
161 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
162 * hold capacity bytes. The descriptor's length is initially set to the
165 static IOBufferMemoryDescriptor
* withCapacity(
167 IODirection withDirection
,
168 bool withContiguousMemory
= false);
172 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
173 * The descriptor's length and capacity are set to the input buffer's size.
175 virtual bool initWithBytes(const void * bytes
,
176 vm_size_t withLength
,
177 IODirection withDirection
,
178 bool withContiguousMemory
= false);
183 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
184 * The descriptor's length and capacity are set to the input buffer's size.
186 static IOBufferMemoryDescriptor
* withBytes(
188 vm_size_t withLength
,
189 IODirection withDirection
,
190 bool withContiguousMemory
= false);
195 * Change the buffer length of the memory descriptor. When a new buffer
196 * is created, the initial length of the buffer is set to be the same as
197 * the capacity. The length can be adjusted via setLength for a shorter
198 * transfer (there is no need to create more buffer descriptors when you
199 * can reuse an existing one, even for different transfer sizes). Note
200 * that the specified length must not exceed the capacity of the buffer.
202 virtual void setLength(vm_size_t length
);
207 * Change the direction of the transfer. This method allows one to redirect
208 * the descriptor's transfer direction. This eliminates the need to destroy
209 * and create new buffers when different transfer directions are needed.
211 virtual void setDirection(IODirection direction
);
216 * Get the buffer capacity
218 virtual vm_size_t
getCapacity() const;
223 * Return the virtual address of the beginning of the buffer
225 virtual void *getBytesNoCopy();
230 * Return the virtual address of an offset from the beginning of the buffer
232 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
237 * Add some data to the end of the buffer. This method automatically
238 * maintains the memory descriptor buffer length. Note that appendBytes
239 * will not copy past the end of the memory descriptor's current capacity.
241 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
244 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */