2 * Copyright (c) 1998-2007 Apple 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 #include <IOKit/IOSubMemoryDescriptor.h>
30 #include <IOKit/IOLib.h>
32 #include "IOKitKernelInternal.h"
34 #define super IOMemoryDescriptor
36 OSDefineMetaClassAndStructors(IOSubMemoryDescriptor
, IOMemoryDescriptor
)
39 IOSubMemoryDescriptor::redirect( task_t safeTask
, bool doRedirect
)
42 super::redirect( safeTask
, doRedirect
);
44 return _parent
->redirect( safeTask
, doRedirect
);
47 IOSubMemoryDescriptor
*
48 IOSubMemoryDescriptor::withSubRange(IOMemoryDescriptor
* of
,
53 IOSubMemoryDescriptor
*self
= new IOSubMemoryDescriptor
;
55 if (self
&& !self
->initSubRange(of
, offset
, length
, (IODirection
) options
)) {
63 IOSubMemoryDescriptor::initSubRange( IOMemoryDescriptor
* parent
,
64 IOByteCount offset
, IOByteCount length
,
65 IODirection direction
)
67 if (parent
&& ((offset
+ length
) > parent
->getLength())) {
72 * We can check the _parent instance variable before having ever set it
73 * to an initial value because I/O Kit guarantees that all our instance
74 * variables are zeroed on an object's allocation.
83 * An existing memory descriptor is being retargeted to
84 * point to somewhere else. Clean up our present state.
92 _tag
= parent
->getTag();
100 _flags
|= kIOMemoryThreadSafe
;
103 _direction
= (IODirection
) (_flags
& kIOMemoryDirectionMask
);
104 #endif /* !__LP64__ */
110 IOSubMemoryDescriptor::free( void )
120 IOSubMemoryDescriptor::getPhysicalSegment(IOByteCount offset
, IOByteCount
* length
, IOOptionBits options
)
123 IOByteCount actualLength
;
125 assert(offset
<= _length
);
131 if (offset
>= _length
) {
135 address
= _parent
->getPhysicalSegment( offset
+ _start
, &actualLength
, options
);
137 if (address
&& length
) {
138 *length
= min( _length
- offset
, actualLength
);
145 IOSubMemoryDescriptor::setPurgeable( IOOptionBits newState
,
146 IOOptionBits
* oldState
)
150 err
= _parent
->setPurgeable( newState
, oldState
);
156 IOSubMemoryDescriptor::setOwnership( task_t newOwner
,
158 IOOptionBits newLedgerOptions
)
162 if (iokit_iomd_setownership_enabled
== FALSE
) {
163 return kIOReturnUnsupported
;
166 err
= _parent
->setOwnership( newOwner
, newLedgerTag
, newLedgerOptions
);
172 IOSubMemoryDescriptor::prepare(
173 IODirection forDirection
)
177 err
= _parent
->prepare( forDirection
);
183 IOSubMemoryDescriptor::complete(
184 IODirection forDirection
)
188 err
= _parent
->complete( forDirection
);
194 IOSubMemoryDescriptor::makeMapping(
195 IOMemoryDescriptor
* owner
,
197 IOVirtualAddress address
,
198 IOOptionBits options
,
202 IOMemoryMap
* mapping
= NULL
;
205 if (!(kIOMap64Bit
& options
)) {
206 panic("IOSubMemoryDescriptor::makeMapping !64bit");
208 #endif /* !__LP64__ */
210 mapping
= (IOMemoryMap
*) _parent
->makeMapping(
214 options
, _start
+ offset
, length
);
220 IOSubMemoryDescriptor::getPreparationID( void )
224 if (!super::getKernelReserved()) {
225 return kIOPreparationIDUnsupported
;
228 pID
= _parent
->getPreparationID();
229 if (reserved
->kernReserved
[0] != pID
) {
230 reserved
->kernReserved
[0] = pID
;
231 reserved
->preparationID
= kIOPreparationIDUnprepared
;
232 super::setPreparationID();
235 return super::getPreparationID();
239 IOSubMemoryDescriptor::getPageCounts(IOByteCount
* residentPageCount
,
240 IOByteCount
* dirtyPageCount
)
242 return _parent
->getPageCounts(residentPageCount
, dirtyPageCount
);