2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef _IOBUFFERMEMORYDESCRIPTOR_H
23 #define _IOBUFFERMEMORYDESCRIPTOR_H
25 #include <IOKit/IOMemoryDescriptor.h>
28 kIOMemoryPhysicallyContiguous
= 0x00000010,
29 kIOMemoryPageable
= 0x00000020,
30 kIOMemoryPurgeable
= 0x00000040,
31 kIOMemorySharingTypeMask
= 0x000f0000,
32 kIOMemoryUnshared
= 0x00000000,
33 kIOMemoryKernelUserShared
= 0x00010000
36 #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1
38 @class IOBufferMemoryDescriptor
39 @abstract Provides a simple memory descriptor that allocates its own buffer memory.
42 class IOBufferMemoryDescriptor
: public IOGeneralMemoryDescriptor
44 OSDeclareDefaultStructors(IOBufferMemoryDescriptor
);
47 /*! @struct ExpansionData
48 @discussion This structure will be used to expand the capablilties of this class in the future.
50 struct ExpansionData
{
55 Reserved for future use. (Internal use only) */
56 ExpansionData
* reserved
;
61 vm_offset_t _alignment
;
62 IOOptionBits _options
;
63 IOPhysicalAddress
* _physAddrs
;
64 unsigned _physSegCount
;
67 virtual bool initWithOptions(
70 vm_offset_t alignment
,
72 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
74 #if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
75 virtual bool initWithPhysicalMask(
78 mach_vm_size_t capacity
,
79 mach_vm_address_t alignment
,
80 mach_vm_address_t physicalMask
);
81 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 1);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
85 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
86 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
87 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
88 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
89 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
90 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
91 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
92 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
93 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
94 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
95 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
96 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
97 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
98 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
103 virtual bool initWithAddress( void * address
, /* not supported */
104 IOByteCount withLength
,
105 IODirection withDirection
);
107 virtual bool initWithAddress( vm_address_t address
, /* not supported */
108 IOByteCount withLength
,
109 IODirection withDirection
,
112 virtual bool initWithPhysicalAddress(
113 IOPhysicalAddress address
, /* not supported */
114 IOByteCount withLength
,
115 IODirection withDirection
);
117 virtual bool initWithPhysicalRanges(
118 IOPhysicalRange
* ranges
, /* not supported */
120 IODirection withDirection
,
121 bool asReference
= false );
123 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
125 IODirection withDirection
,
127 bool asReference
= false );
129 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
130 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
131 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
132 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
133 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
140 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
141 * hold capacity bytes. The descriptor's length is initially set to the
144 virtual bool initWithOptions( IOOptionBits options
,
146 vm_offset_t alignment
);
148 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
150 vm_offset_t alignment
= 1);
152 /*! @function inTaskWithOptions
153 @abstract Creates a memory buffer with memory descriptor for that buffer.
154 @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.
155 @param inTask The task the buffer will be allocated in.
156 @param options Options for the allocation:<br>
157 kIODirectionOut, kIODirectionIn - set the direction of the I/O transfer.<br>
158 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>
159 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br>
160 kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br>
161 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
162 @param capacity The number of bytes to allocate.
163 @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.
164 @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
166 static IOBufferMemoryDescriptor
* inTaskWithOptions(
168 IOOptionBits options
,
170 vm_offset_t alignment
= 1);
172 #if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
173 /*! @function inTaskWithPhysicalMask
174 @abstract Creates a memory buffer with memory descriptor for that buffer.
175 @discussion Added in Mac OS X 10.5, 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.
176 @param inTask The task the buffer will be mapped in. Pass NULL to create memory unmapped in any task (eg. for use as a DMA buffer).
177 @param options Options for the allocation:<br>
178 kIODirectionOut, kIODirectionIn - set the direction of the I/O transfer.<br>
179 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>
180 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
181 @param capacity The number of bytes to allocate.
182 @param mask The buffer will be allocated with pages such that physical addresses will only have bits set present in physicalMask. For example, pass 0x00000000FFFFFFFFULL for a buffer to be accessed by hardware that has 32 address bits.
183 @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
185 static IOBufferMemoryDescriptor
* inTaskWithPhysicalMask(
187 IOOptionBits options
,
188 mach_vm_size_t capacity
,
189 mach_vm_address_t physicalMask
);
195 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
196 * hold capacity bytes. The descriptor's length is initially set to the
199 static IOBufferMemoryDescriptor
* withCapacity(
201 IODirection withDirection
,
202 bool withContiguousMemory
= false);
206 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
207 * The descriptor's length and capacity are set to the input buffer's size.
209 virtual bool initWithBytes(const void * bytes
,
210 vm_size_t withLength
,
211 IODirection withDirection
,
212 bool withContiguousMemory
= false);
217 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
218 * The descriptor's length and capacity are set to the input buffer's size.
220 static IOBufferMemoryDescriptor
* withBytes(
222 vm_size_t withLength
,
223 IODirection withDirection
,
224 bool withContiguousMemory
= false);
229 * Change the buffer length of the memory descriptor. When a new buffer
230 * is created, the initial length of the buffer is set to be the same as
231 * the capacity. The length can be adjusted via setLength for a shorter
232 * transfer (there is no need to create more buffer descriptors when you
233 * can reuse an existing one, even for different transfer sizes). Note
234 * that the specified length must not exceed the capacity of the buffer.
236 virtual void setLength(vm_size_t length
);
241 * Change the direction of the transfer. This method allows one to redirect
242 * the descriptor's transfer direction. This eliminates the need to destroy
243 * and create new buffers when different transfer directions are needed.
245 virtual void setDirection(IODirection direction
);
250 * Get the buffer capacity
252 virtual vm_size_t
getCapacity() const;
257 * Return the virtual address of the beginning of the buffer
259 virtual void *getBytesNoCopy();
264 * Return the virtual address of an offset from the beginning of the buffer
266 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
271 * Add some data to the end of the buffer. This method automatically
272 * maintains the memory descriptor buffer length. Note that appendBytes
273 * will not copy past the end of the memory descriptor's current capacity.
275 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
277 #if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
278 /* DEPRECATED */ virtual void * getVirtualSegment(IOByteCount offset
,
279 /* DEPRECATED */ IOByteCount
* length
);
283 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */