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>
31 #include "IOKitKernelInternal.h"
33 #define super IOMemoryDescriptor
35 OSDefineMetaClassAndStructors(IOSubMemoryDescriptor
, IOMemoryDescriptor
)
38 IOSubMemoryDescriptor::redirect( task_t safeTask
, bool doRedirect
)
41 super::redirect( safeTask
, doRedirect
);
43 return _parent
->redirect( safeTask
, doRedirect
);
46 IOSubMemoryDescriptor
*
47 IOSubMemoryDescriptor::withSubRange(IOMemoryDescriptor
* of
,
52 IOSubMemoryDescriptor
*self
= new IOSubMemoryDescriptor
;
54 if (self
&& !self
->initSubRange(of
, offset
, length
, (IODirection
) options
)) {
62 IOSubMemoryDescriptor::initSubRange( IOMemoryDescriptor
* parent
,
63 IOByteCount offset
, IOByteCount length
,
64 IODirection direction
)
66 if (parent
&& ((offset
+ length
) > parent
->getLength())) {
71 * We can check the _parent instance variable before having ever set it
72 * to an initial value because I/O Kit guarantees that all our instance
73 * variables are zeroed on an object's allocation.
82 * An existing memory descriptor is being retargeted to
83 * point to somewhere else. Clean up our present state.
91 _tag
= parent
->getTag();
99 _flags
|= kIOMemoryThreadSafe
;
102 _direction
= (IODirection
) (_flags
& kIOMemoryDirectionMask
);
103 #endif /* !__LP64__ */
109 IOSubMemoryDescriptor::free( void )
119 IOSubMemoryDescriptor::getPhysicalSegment(IOByteCount offset
, IOByteCount
* length
, IOOptionBits options
)
122 IOByteCount actualLength
;
124 assert(offset
<= _length
);
130 if (offset
>= _length
) {
134 address
= _parent
->getPhysicalSegment( offset
+ _start
, &actualLength
, options
);
136 if (address
&& length
) {
137 *length
= min( _length
- offset
, actualLength
);
144 IOSubMemoryDescriptor::setPurgeable( IOOptionBits newState
,
145 IOOptionBits
* oldState
)
149 err
= _parent
->setPurgeable( newState
, oldState
);
155 IOSubMemoryDescriptor::setOwnership( task_t newOwner
,
157 IOOptionBits newLedgerOptions
)
161 if (iokit_iomd_setownership_enabled
== FALSE
) {
162 return kIOReturnUnsupported
;
165 err
= _parent
->setOwnership( newOwner
, newLedgerTag
, newLedgerOptions
);
171 IOSubMemoryDescriptor::prepare(
172 IODirection forDirection
)
176 err
= _parent
->prepare( forDirection
);
182 IOSubMemoryDescriptor::complete(
183 IODirection forDirection
)
187 err
= _parent
->complete( forDirection
);
193 IOSubMemoryDescriptor::makeMapping(
194 IOMemoryDescriptor
* owner
,
196 IOVirtualAddress address
,
197 IOOptionBits options
,
201 IOMemoryMap
* mapping
= NULL
;
204 if (!(kIOMap64Bit
& options
)) {
205 panic("IOSubMemoryDescriptor::makeMapping !64bit");
207 #endif /* !__LP64__ */
209 mapping
= (IOMemoryMap
*) _parent
->makeMapping(
213 options
, _start
+ offset
, length
);
219 IOSubMemoryDescriptor::getPreparationID( void )
223 if (!super::getKernelReserved()) {
224 return kIOPreparationIDUnsupported
;
227 pID
= _parent
->getPreparationID();
228 if (reserved
->kernReserved
[0] != pID
) {
229 reserved
->kernReserved
[0] = pID
;
230 reserved
->preparationID
= kIOPreparationIDUnprepared
;
231 super::setPreparationID();
234 return super::getPreparationID();
238 IOSubMemoryDescriptor::getPageCounts(IOByteCount
* residentPageCount
,
239 IOByteCount
* dirtyPageCount
)
241 return _parent
->getPageCounts(residentPageCount
, dirtyPageCount
);