2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _IOMULTIMEMORYDESCRIPTOR_H
30 #define _IOMULTIMEMORYDESCRIPTOR_H
32 #include <IOKit/IOMemoryDescriptor.h>
34 /*! @class IOMultiMemoryDescriptor : public IOMemoryDescriptor
35 @abstract The IOMultiMemoryDescriptor object describes a memory area made up of several other IOMemoryDescriptors.
36 @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. */
38 class IOMultiMemoryDescriptor
: public IOMemoryDescriptor
40 OSDeclareDefaultStructors(IOMultiMemoryDescriptor
);
44 IOMemoryDescriptor
** _descriptors
;
45 UInt32 _descriptorsCount
;
46 bool _descriptorsIsAllocated
;
51 * These methods are not supported under this subclass.
54 virtual bool initWithAddress( void * address
, /* not supported */
55 IOByteCount withLength
,
56 IODirection withDirection
);
58 virtual bool initWithAddress( vm_address_t address
, /* not supported */
59 IOByteCount withLength
,
60 IODirection withDirection
,
63 virtual bool initWithPhysicalAddress(
64 IOPhysicalAddress address
, /* not supported */
65 IOByteCount withLength
,
66 IODirection withDirection
);
68 virtual bool initWithPhysicalRanges(
69 IOPhysicalRange
* ranges
, /* not supported */
71 IODirection withDirection
,
72 bool asReference
= false );
74 virtual bool initWithRanges( IOVirtualRange
* ranges
, /* not supported */
76 IODirection withDirection
,
78 bool asReference
= false );
80 virtual void * getVirtualSegment( IOByteCount offset
, /* not supported */
81 IOByteCount
* length
);
83 IOMemoryDescriptor::withAddress
; /* not supported */
84 IOMemoryDescriptor::withPhysicalAddress
; /* not supported */
85 IOMemoryDescriptor::withPhysicalRanges
; /* not supported */
86 IOMemoryDescriptor::withRanges
; /* not supported */
87 IOMemoryDescriptor::withSubRange
; /* not supported */
91 /*! @function withDescriptors
92 @abstract Create an IOMultiMemoryDescriptor to describe a memory area made up of several other IOMemoryDescriptors.
93 @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.
94 @param descriptors An array of IOMemoryDescriptors which make up the memory to be described.
95 @param withCount The object count for the descriptors array.
96 @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.
97 @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.
98 @result The created IOMultiMemoryDescriptor on success, to be released by the caller, or zero on failure. */
100 static IOMultiMemoryDescriptor
* withDescriptors(
101 IOMemoryDescriptor
** descriptors
,
103 IODirection withDirection
,
104 bool asReference
= false );
106 /*! @function withDescriptors
107 @abstract Initialize an IOMultiMemoryDescriptor to describe a memory area made up of several other IOMemoryDescriptors.
108 @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.
109 @param descriptors An array of IOMemoryDescriptors which make up the memory to be described.
110 @param withCount The object count for the descriptors array.
111 @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.
112 @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.
113 @result The created IOMultiMemoryDescriptor on success, to be released by the caller, or zero on failure. */
115 virtual bool initWithDescriptors(
116 IOMemoryDescriptor
** descriptors
,
118 IODirection withDirection
,
119 bool asReference
= false );
121 /*! @function getPhysicalAddress
122 @abstract Return the physical address of the first byte in the memory.
123 @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.
124 @result A physical address. */
126 virtual IOPhysicalAddress
getPhysicalSegment( IOByteCount offset
,
127 IOByteCount
* length
);
129 #if !(defined(__ppc__) && defined(KPI_10_4_0_PPC_COMPAT))
130 virtual addr64_t
getPhysicalSegment64( IOByteCount offset
,
131 IOByteCount
* length
);
134 /*! @function prepare
135 @abstract Prepare the memory for an I/O transfer.
136 @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.
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
prepare(IODirection forDirection
= kIODirectionNone
);
142 /*! @function complete
143 @abstract Complete processing of the memory after an I/O transfer finishes.
144 @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.
145 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
146 @result An IOReturn code. */
148 virtual IOReturn
complete(IODirection forDirection
= kIODirectionNone
);
150 /*! @function readBytes
151 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
152 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
153 @param offset A byte offset into the memory descriptor's memory.
154 @param bytes The caller supplied buffer to copy the data to.
155 @param withLength The length of the data to copy.
156 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
158 virtual IOByteCount
readBytes( IOByteCount offset
,
160 IOByteCount withLength
);
162 /*! @function writeBytes
163 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
164 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
165 @param offset A byte offset into the memory descriptor's memory.
166 @param bytes The caller supplied buffer to copy the data from.
167 @param withLength The length of the data to copy.
168 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
170 virtual IOByteCount
writeBytes( IOByteCount offset
,
172 IOByteCount withLength
);
174 virtual IOPhysicalAddress
getSourceSegment(IOByteCount offset
,
175 IOByteCount
* length
);
178 #endif /* !_IOMULTIMEMORYDESCRIPTOR_H */