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
,
73 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
74 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
75 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
76 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
77 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
78 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
79 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
80 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
81 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
82 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
84 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
85 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
86 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
87 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
88 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
93 virtual bool initWithAddress( void * address
, /* not supported */
94 IOByteCount withLength
,
95 IODirection withDirection
);
97 virtual bool initWithAddress( vm_address_t address
, /* not supported */
98 IOByteCount withLength
,
99 IODirection withDirection
,
102 virtual bool initWithPhysicalAddress(
103 IOPhysicalAddress address
, /* not supported */
104 IOByteCount withLength
,
105 IODirection withDirection
);
107 virtual bool initWithPhysicalRanges(
108 IOPhysicalRange
* ranges
, /* not supported */
110 IODirection withDirection
,
111 bool asReference
= false );
113 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
115 IODirection withDirection
,
117 bool asReference
= false );
119 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
120 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
121 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
122 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
123 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
130 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
131 * hold capacity bytes. The descriptor's length is initially set to the
134 virtual bool initWithOptions( IOOptionBits options
,
136 vm_offset_t alignment
);
138 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
140 vm_offset_t alignment
= 1);
142 /*! @function inTaskWithOptions
143 @abstract Creates a memory buffer with memory descriptor for that buffer.
144 @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.
145 @param inTask The task the buffer will be allocated in.
146 @param options Options for the allocation:<br>
147 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>
148 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.<br>
149 kIOMemoryPurgeable - pass to request memory that may later have its purgeable state set with IOMemoryDescriptor::setPurgeable. Only supported for kIOMemoryPageable allocations.<br>
150 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
151 @param capacity The number of bytes to allocate.
152 @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.
153 @result Returns an instance of class IOBufferMemoryDescriptor to be released by the caller, which will free the memory desriptor and associated buffer. */
155 static IOBufferMemoryDescriptor
* inTaskWithOptions(
157 IOOptionBits options
,
159 vm_offset_t alignment
= 1);
164 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
165 * hold capacity bytes. The descriptor's length is initially set to the
168 static IOBufferMemoryDescriptor
* withCapacity(
170 IODirection withDirection
,
171 bool withContiguousMemory
= false);
175 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
176 * The descriptor's length and capacity are set to the input buffer's size.
178 virtual bool initWithBytes(const void * bytes
,
179 vm_size_t withLength
,
180 IODirection withDirection
,
181 bool withContiguousMemory
= false);
186 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
187 * The descriptor's length and capacity are set to the input buffer's size.
189 static IOBufferMemoryDescriptor
* withBytes(
191 vm_size_t withLength
,
192 IODirection withDirection
,
193 bool withContiguousMemory
= false);
198 * Change the buffer length of the memory descriptor. When a new buffer
199 * is created, the initial length of the buffer is set to be the same as
200 * the capacity. The length can be adjusted via setLength for a shorter
201 * transfer (there is no need to create more buffer descriptors when you
202 * can reuse an existing one, even for different transfer sizes). Note
203 * that the specified length must not exceed the capacity of the buffer.
205 virtual void setLength(vm_size_t length
);
210 * Change the direction of the transfer. This method allows one to redirect
211 * the descriptor's transfer direction. This eliminates the need to destroy
212 * and create new buffers when different transfer directions are needed.
214 virtual void setDirection(IODirection direction
);
219 * Get the buffer capacity
221 virtual vm_size_t
getCapacity() const;
226 * Return the virtual address of the beginning of the buffer
228 virtual void *getBytesNoCopy();
233 * Return the virtual address of an offset from the beginning of the buffer
235 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
240 * Add some data to the end of the buffer. This method automatically
241 * maintains the memory descriptor buffer length. Note that appendBytes
242 * will not copy past the end of the memory descriptor's current capacity.
244 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
247 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */