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
)
37 IOReturn
IOSubMemoryDescriptor::redirect( task_t safeTask
, bool doRedirect
)
40 super::redirect( safeTask
, doRedirect
);
42 return( _parent
->redirect( safeTask
, doRedirect
));
45 IOSubMemoryDescriptor
*
46 IOSubMemoryDescriptor::withSubRange(IOMemoryDescriptor
* of
,
51 IOSubMemoryDescriptor
*self
= new IOSubMemoryDescriptor
;
53 if (self
&& !self
->initSubRange(of
, offset
, length
, (IODirection
) options
)) {
60 bool IOSubMemoryDescriptor::initSubRange( IOMemoryDescriptor
* parent
,
61 IOByteCount offset
, IOByteCount length
,
62 IODirection direction
)
64 if( parent
&& ((offset
+ length
) > parent
->getLength()))
68 * We can check the _parent instance variable before having ever set it
69 * to an initial value because I/O Kit guarantees that all our instance
70 * variables are zeroed on an object's allocation.
78 * An existing memory descriptor is being retargeted to
79 * point to somewhere else. Clean up our present state.
87 _tag
= parent
->getTag();
96 _flags
|= kIOMemoryThreadSafe
;
99 _direction
= (IODirection
) (_flags
& kIOMemoryDirectionMask
);
100 #endif /* !__LP64__ */
105 void IOSubMemoryDescriptor::free( void )
114 IOSubMemoryDescriptor::getPhysicalSegment(IOByteCount offset
, IOByteCount
* length
, IOOptionBits options
)
117 IOByteCount actualLength
;
119 assert(offset
<= _length
);
124 if( offset
>= _length
)
127 address
= _parent
->getPhysicalSegment( offset
+ _start
, &actualLength
, options
);
129 if( address
&& length
)
130 *length
= min( _length
- offset
, actualLength
);
135 IOReturn
IOSubMemoryDescriptor::setPurgeable( IOOptionBits newState
,
136 IOOptionBits
* oldState
)
140 err
= _parent
->setPurgeable( newState
, oldState
);
145 IOReturn
IOSubMemoryDescriptor::prepare(
146 IODirection forDirection
)
150 err
= _parent
->prepare( forDirection
);
155 IOReturn
IOSubMemoryDescriptor::complete(
156 IODirection forDirection
)
160 err
= _parent
->complete( forDirection
);
165 IOMemoryMap
* IOSubMemoryDescriptor::makeMapping(
166 IOMemoryDescriptor
* owner
,
168 IOVirtualAddress address
,
169 IOOptionBits options
,
173 IOMemoryMap
* mapping
= 0;
176 if (!(kIOMap64Bit
& options
))
178 panic("IOSubMemoryDescriptor::makeMapping !64bit");
180 #endif /* !__LP64__ */
182 mapping
= (IOMemoryMap
*) _parent
->makeMapping(
186 options
, _start
+ offset
, length
);
192 IOSubMemoryDescriptor::getPreparationID( void )
196 if (!super::getKernelReserved())
197 return (kIOPreparationIDUnsupported
);
199 pID
= _parent
->getPreparationID();
200 if (reserved
->kernReserved
[0] != pID
)
202 reserved
->kernReserved
[0] = pID
;
203 reserved
->preparationID
= kIOPreparationIDUnprepared
;
204 super::setPreparationID();
207 return (super::getPreparationID());
211 IOSubMemoryDescriptor::getPageCounts(IOByteCount
* residentPageCount
,
212 IOByteCount
* dirtyPageCount
)
214 return (_parent
->getPageCounts(residentPageCount
, dirtyPageCount
));