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 kIOMemorySharingTypeMask
= 0x000f0000,
31 kIOMemoryUnshared
= 0x00000000,
32 kIOMemoryKernelUserShared
= 0x00010000
35 #define _IOBUFFERMEMORYDESCRIPTOR_INTASKWITHOPTIONS_ 1
37 class IOBufferMemoryDescriptor
: public IOGeneralMemoryDescriptor
39 OSDeclareDefaultStructors(IOBufferMemoryDescriptor
);
42 /*! @struct ExpansionData
43 @discussion This structure will be used to expand the capablilties of this class in the future.
45 struct ExpansionData
{
50 Reserved for future use. (Internal use only) */
51 ExpansionData
* reserved
;
56 vm_offset_t _alignment
;
57 IOOptionBits _options
;
58 IOPhysicalAddress
* _physAddrs
;
59 unsigned _physSegCount
;
62 virtual bool initWithOptions(
65 vm_offset_t alignment
,
68 OSMetaClassDeclareReservedUsed(IOBufferMemoryDescriptor
, 0);
69 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 1);
70 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 2);
71 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 3);
72 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 4);
73 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 5);
74 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 6);
75 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 7);
76 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 8);
77 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 9);
78 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 10);
79 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 11);
80 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 12);
81 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 13);
82 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 14);
83 OSMetaClassDeclareReservedUnused(IOBufferMemoryDescriptor
, 15);
88 virtual bool initWithAddress( void * address
, /* not supported */
89 IOByteCount withLength
,
90 IODirection withDirection
);
92 virtual bool initWithAddress( vm_address_t address
, /* not supported */
93 IOByteCount withLength
,
94 IODirection withDirection
,
97 virtual bool initWithPhysicalAddress(
98 IOPhysicalAddress address
, /* not supported */
99 IOByteCount withLength
,
100 IODirection withDirection
);
102 virtual bool initWithPhysicalRanges(
103 IOPhysicalRange
* ranges
, /* not supported */
105 IODirection withDirection
,
106 bool asReference
= false );
108 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
110 IODirection withDirection
,
112 bool asReference
= false );
114 IOGeneralMemoryDescriptor::withAddress
; /* not supported */
115 IOGeneralMemoryDescriptor::withPhysicalAddress
; /* not supported */
116 IOGeneralMemoryDescriptor::withPhysicalRanges
; /* not supported */
117 IOGeneralMemoryDescriptor::withRanges
; /* not supported */
118 IOGeneralMemoryDescriptor::withSubRange
; /* not supported */
125 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
126 * hold capacity bytes. The descriptor's length is initially set to the
129 virtual bool initWithOptions( IOOptionBits options
,
131 vm_offset_t alignment
);
133 static IOBufferMemoryDescriptor
* withOptions( IOOptionBits options
,
135 vm_offset_t alignment
= 1);
137 /*! @function inTaskWithOptions
138 @abstract Create a memory buffer with memory descriptor for that buffer. Added in Mac OS X 10.2.
139 @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.
140 @param inTask The task the buffer will be allocated in.
141 @param options Options for the allocation:
142 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.
143 kIOMemoryPageable - pass to request memory be non-wired - the default for kernel allocated memory is wired.
144 kIOMemoryKernelUserShared - pass to request memory that will be mapped into both the kernel and client applications.
145 @param capacity The number of bytes to allocate.
146 @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.
147 @result An instance of class IOBufferMemoryDescriptor. To be released by the caller, which will free the memory desriptor and associated buffer. */
149 static IOBufferMemoryDescriptor
* inTaskWithOptions(
151 IOOptionBits options
,
153 vm_offset_t alignment
= 1);
158 * Returns a new IOBufferMemoryDescriptor with a buffer large enough to
159 * hold capacity bytes. The descriptor's length is initially set to the
162 static IOBufferMemoryDescriptor
* withCapacity(
164 IODirection withDirection
,
165 bool withContiguousMemory
= false);
169 * Initialize a new IOBufferMemoryDescriptor preloaded with bytes (copied).
170 * The descriptor's length and capacity are set to the input buffer's size.
172 virtual bool initWithBytes(const void * bytes
,
173 vm_size_t withLength
,
174 IODirection withDirection
,
175 bool withContiguousMemory
= false);
180 * Returns a new IOBufferMemoryDescriptor preloaded with bytes (copied).
181 * The descriptor's length and capacity are set to the input buffer's size.
183 static IOBufferMemoryDescriptor
* withBytes(
185 vm_size_t withLength
,
186 IODirection withDirection
,
187 bool withContiguousMemory
= false);
192 * Change the buffer length of the memory descriptor. When a new buffer
193 * is created, the initial length of the buffer is set to be the same as
194 * the capacity. The length can be adjusted via setLength for a shorter
195 * transfer (there is no need to create more buffer descriptors when you
196 * can reuse an existing one, even for different transfer sizes). Note
197 * that the specified length must not exceed the capacity of the buffer.
199 virtual void setLength(vm_size_t length
);
204 * Change the direction of the transfer. This method allows one to redirect
205 * the descriptor's transfer direction. This eliminates the need to destroy
206 * and create new buffers when different transfer directions are needed.
208 virtual void setDirection(IODirection direction
);
213 * Get the buffer capacity
215 virtual vm_size_t
getCapacity() const;
220 * Return the virtual address of the beginning of the buffer
222 virtual void *getBytesNoCopy();
227 * Return the virtual address of an offset from the beginning of the buffer
229 virtual void *getBytesNoCopy(vm_size_t start
, vm_size_t withLength
);
234 * Add some data to the end of the buffer. This method automatically
235 * maintains the memory descriptor buffer length. Note that appendBytes
236 * will not copy past the end of the memory descriptor's current capacity.
238 virtual bool appendBytes(const void *bytes
, vm_size_t withLength
);
241 #endif /* !_IOBUFFERMEMORYDESCRIPTOR_H */