]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOMultiMemoryDescriptor.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / iokit / IOKit / IOMultiMemoryDescriptor.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _IOMULTIMEMORYDESCRIPTOR_H
25 #define _IOMULTIMEMORYDESCRIPTOR_H
26
27 #include <IOKit/IOMemoryDescriptor.h>
28
29 /*! @class IOMultiMemoryDescriptor : public IOMemoryDescriptor
30 @abstract The IOMultiMemoryDescriptor object describes a memory area made up of several other IOMemoryDescriptors.
31 @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. */
32
33 class IOMultiMemoryDescriptor : public IOMemoryDescriptor
34 {
35 OSDeclareDefaultStructors(IOMultiMemoryDescriptor);
36
37 protected:
38
39 IOMemoryDescriptor ** _descriptors;
40 UInt32 _descriptorsCount;
41 bool _descriptorsIsAllocated;
42
43 virtual void free();
44
45 /*
46 * These methods are not supported under this subclass.
47 */
48
49 virtual bool initWithAddress( void * address, /* not supported */
50 IOByteCount withLength,
51 IODirection withDirection );
52
53 virtual bool initWithAddress( vm_address_t address, /* not supported */
54 IOByteCount withLength,
55 IODirection withDirection,
56 task_t withTask );
57
58 virtual bool initWithPhysicalAddress(
59 IOPhysicalAddress address, /* not supported */
60 IOByteCount withLength,
61 IODirection withDirection );
62
63 virtual bool initWithPhysicalRanges(
64 IOPhysicalRange * ranges, /* not supported */
65 UInt32 withCount,
66 IODirection withDirection,
67 bool asReference = false );
68
69 virtual bool initWithRanges( IOVirtualRange * ranges, /* not supported */
70 UInt32 withCount,
71 IODirection withDirection,
72 task_t withTask,
73 bool asReference = false );
74
75 virtual void * getVirtualSegment( IOByteCount offset, /* not supported */
76 IOByteCount * length );
77
78 IOMemoryDescriptor::withAddress; /* not supported */
79 IOMemoryDescriptor::withPhysicalAddress; /* not supported */
80 IOMemoryDescriptor::withPhysicalRanges; /* not supported */
81 IOMemoryDescriptor::withRanges; /* not supported */
82 IOMemoryDescriptor::withSubRange; /* not supported */
83
84 public:
85
86 /*! @function withDescriptors
87 @abstract Create an IOMultiMemoryDescriptor to describe a memory area made up of several other IOMemoryDescriptors.
88 @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.
89 @param descriptors An array of IOMemoryDescriptors which make up the memory to be described.
90 @param withCount The object count for the descriptors array.
91 @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.
92 @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.
93 @result The created IOMultiMemoryDescriptor on success, to be released by the caller, or zero on failure. */
94
95 static IOMultiMemoryDescriptor * withDescriptors(
96 IOMemoryDescriptor ** descriptors,
97 UInt32 withCount,
98 IODirection withDirection,
99 bool asReference = false );
100
101 /*! @function withDescriptors
102 @abstract Initialize an IOMultiMemoryDescriptor to describe a memory area made up of several other IOMemoryDescriptors.
103 @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.
104 @param descriptors An array of IOMemoryDescriptors which make up the memory to be described.
105 @param withCount The object count for the descriptors array.
106 @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.
107 @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.
108 @result The created IOMultiMemoryDescriptor on success, to be released by the caller, or zero on failure. */
109
110 virtual bool initWithDescriptors(
111 IOMemoryDescriptor ** descriptors,
112 UInt32 withCount,
113 IODirection withDirection,
114 bool asReference = false );
115
116 /*! @function getPhysicalAddress
117 @abstract Return the physical address of the first byte in the memory.
118 @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.
119 @result A physical address. */
120
121 virtual IOPhysicalAddress getPhysicalSegment( IOByteCount offset,
122 IOByteCount * length );
123
124 /*! @function prepare
125 @abstract Prepare the memory for an I/O transfer.
126 @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.
127 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
128 @result An IOReturn code. */
129
130 virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
131
132 /*! @function complete
133 @abstract Complete processing of the memory after an I/O transfer finishes.
134 @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.
135 @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
136 @result An IOReturn code. */
137
138 virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
139
140 /*! @function readBytes
141 @abstract Copy data from the memory descriptor's buffer to the specified buffer.
142 @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
143 @param offset A byte offset into the memory descriptor's memory.
144 @param bytes The caller supplied buffer to copy the data to.
145 @param withLength The length of the data to copy.
146 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
147
148 virtual IOByteCount readBytes( IOByteCount offset,
149 void * bytes,
150 IOByteCount withLength );
151
152 /*! @function writeBytes
153 @abstract Copy data to the memory descriptor's buffer from the specified buffer.
154 @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
155 @param offset A byte offset into the memory descriptor's memory.
156 @param bytes The caller supplied buffer to copy the data from.
157 @param withLength The length of the data to copy.
158 @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
159
160 virtual IOByteCount writeBytes( IOByteCount offset,
161 const void * bytes,
162 IOByteCount withLength );
163
164 virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
165 IOByteCount * length);
166 };
167
168 #endif /* !_IOMULTIMEMORYDESCRIPTOR_H */