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@
26 #ifndef _IOMULTIMEMORYDESCRIPTOR_H
27 #define _IOMULTIMEMORYDESCRIPTOR_H
29 #include <IOKit/IOMemoryDescriptor.h>
31 /*! @class IOMultiMemoryDescriptor : public IOMemoryDescriptor
32 @abstract The IOMultiMemoryDescriptor object describes a memory area made up of several other IOMemoryDescriptors.
33 @discussion The IOMultiMemoryDescriptor object represents multiple ranges of memory, specified as an ordered list of IOMemoryDescriptors. The descriptors are chained end-to-end to make up a single contiguous buffer. */
35 class IOMultiMemoryDescriptor
: public IOMemoryDescriptor
37 OSDeclareDefaultStructors(IOMultiMemoryDescriptor
);
41 IOMemoryDescriptor
** _descriptors
;
42 UInt32 _descriptorsCount
;
43 bool _descriptorsIsAllocated
;
48 * These methods are not supported under this subclass.
51 virtual bool initWithAddress( void * address
, /* not supported */
52 IOByteCount withLength
,
53 IODirection withDirection
);
55 virtual bool initWithAddress( vm_address_t address
, /* not supported */
56 IOByteCount withLength
,
57 IODirection withDirection
,
60 virtual bool initWithPhysicalAddress(
61 IOPhysicalAddress address
, /* not supported */
62 IOByteCount withLength
,
63 IODirection withDirection
);
65 virtual bool initWithPhysicalRanges(
66 IOPhysicalRange
* ranges
, /* not supported */
68 IODirection withDirection
,
69 bool asReference
= false );
71 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
73 IODirection withDirection
,
75 bool asReference
= false );
77 virtual void * getVirtualSegment( IOByteCount offset
, /* not supported */
78 IOByteCount
* length
);
80 IOMemoryDescriptor::withAddress
; /* not supported */
81 IOMemoryDescriptor::withPhysicalAddress
; /* not supported */
82 IOMemoryDescriptor::withPhysicalRanges
; /* not supported */
83 IOMemoryDescriptor::withRanges
; /* not supported */
84 IOMemoryDescriptor::withSubRange
; /* not supported */
88 /*! @function withDescriptors
89 @abstract Create an IOMultiMemoryDescriptor to describe a memory area made up of several other IOMemoryDescriptors.
90 @discussion This method creates and initializes an IOMultiMemoryDescriptor for memory consisting of a number of other IOMemoryDescriptors, chained end-to-end (in the order they appear in the array) to represent a single contiguous memory buffer. Passing the descriptor array as a reference will avoid an extra allocation.
91 @param descriptors An array of IOMemoryDescriptors which make up the memory to be described.
92 @param withCount The object count for the descriptors array.
93 @param withDirection An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
94 @param asReference If false, the IOMultiMemoryDescriptor object will make a copy of the descriptors array, otherwise, the array will be used in situ, avoiding an extra allocation.
95 @result The created IOMultiMemoryDescriptor on success, to be released by the caller, or zero on failure. */
97 static IOMultiMemoryDescriptor
* withDescriptors(
98 IOMemoryDescriptor
** descriptors
,
100 IODirection withDirection
,
101 bool asReference
= false );
103 /*! @function withDescriptors
104 @abstract Initialize an IOMultiMemoryDescriptor to describe a memory area made up of several other IOMemoryDescriptors.
105 @discussion This method initializes an IOMultiMemoryDescriptor for memory consisting of a number of other IOMemoryDescriptors, chained end-to-end (in the order they appear in the array) to represent a single contiguous memory buffer. Passing the descriptor array as a reference will avoid an extra allocation.
106 @param descriptors An array of IOMemoryDescriptors which make up the memory to be described.
107 @param withCount The object count for the descriptors array.
108 @param withDirection An I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures.
109 @param asReference If false, the IOMultiMemoryDescriptor object will make a copy of the descriptors array, otherwise, the array will be used in situ, avoiding an extra allocation.
110 @result The created IOMultiMemoryDescriptor on success, to be released by the caller, or zero on failure. */
112 virtual bool initWithDescriptors(
113 IOMemoryDescriptor
** descriptors
,
115 IODirection withDirection
,
116 bool asReference
= false );
118 /*! @function getPhysicalAddress
119 @abstract Return the physical address of the first byte in the memory.
120 @discussion This method returns the physical address of the first byte in the memory. It is most useful on memory known to be physically contiguous.
121 @result A physical address. */
123 virtual IOPhysicalAddress
getPhysicalSegment( IOByteCount offset
,
124 IOByteCount
* length
);
126 /*! @function prepare
127 @abstract Prepare the memory for an I/O transfer.
128 @discussion This involves paging in the memory, if necessary, and wiring it down for the duration of the transfer. The complete() method completes the processing of the memory after the I/O transfer finishes. This method needn't called for non-pageable memory.
129 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
130 @result An IOReturn code. */
132 virtual IOReturn
prepare(IODirection forDirection
= kIODirectionNone
);
134 /*! @function complete
135 @abstract Complete processing of the memory after an I/O transfer finishes.
136 @discussion This method should not be called unless a prepare was previously issued; the prepare() and complete() must occur in pairs, before and after an I/O transfer involving pageable memory.
137 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
138 @result An IOReturn code. */
140 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
142 /*! @function readBytes
143 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
144 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
145 @param offset A byte offset into the memory descriptor's memory.
146 @param bytes The caller supplied buffer to copy the data to.
147 @param withLength The length of the data to copy.
148 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
150 virtual IOByteCount
readBytes( IOByteCount offset
,
152 IOByteCount withLength
);
154 /*! @function writeBytes
155 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
156 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
157 @param offset A byte offset into the memory descriptor's memory.
158 @param bytes The caller supplied buffer to copy the data from.
159 @param withLength The length of the data to copy.
160 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
162 virtual IOByteCount
writeBytes( IOByteCount offset
,
164 IOByteCount withLength
);
166 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
167 IOByteCount
* length
);
170 #endif /* !_IOMULTIMEMORYDESCRIPTOR_H */