Annotation of XNU/iokit/IOKit/IOMemoryDescriptor.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
                      3:  *
                      4:  * @APPLE_LICENSE_HEADER_START@
                      5:  * 
                      6:  * The contents of this file constitute Original Code as defined in and
                      7:  * are subject to the Apple Public Source License Version 1.1 (the
                      8:  * "License").  You may not use this file except in compliance with the
                      9:  * License.  Please obtain a copy of the License at
                     10:  * http://www.apple.com/publicsource and read it before using this file.
                     11:  * 
                     12:  * This Original Code and all software distributed under the License are
                     13:  * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
                     14:  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
                     15:  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
                     16:  * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
                     17:  * License for the specific language governing rights and limitations
                     18:  * under the License.
                     19:  * 
                     20:  * @APPLE_LICENSE_HEADER_END@
                     21:  */
                     22: #ifndef _IOMEMORYDESCRIPTOR_H
                     23: #define _IOMEMORYDESCRIPTOR_H
                     24: 
                     25: #include <IOKit/IOTypes.h>
                     26: #include <libkern/c++/OSContainers.h>
                     27: 
                     28: struct IOVirtualRange
                     29: {
                     30:     IOVirtualAddress   address;
                     31:     IOByteCount                length;
                     32: };
                     33: 
                     34: struct IOPhysicalRange
                     35: {
                     36:     IOPhysicalAddress  address;
                     37:     IOByteCount                length;
                     38: };
                     39: 
                     40: class IOMemoryMap;
                     41: 
                     42: /*
                     43:  * Direction of transfer, with respect to the described memory.
                     44:  */
                     45: enum IODirection
                     46: {
                     47:     kIODirectionNone  = 0,
                     48:     kIODirectionIn    = 1,
                     49:     kIODirectionOut   = 2,
                     50:     kIODirectionOutIn = 3
                     51: };
                     52: 
                     53: /*! @class IOMemoryDescriptor : public OSObject
                     54:     @abstract An abstract base class defining common methods for describing physical or virtual memory.
                     55:     @discussion The IOMemoryDescriptor object represents a buffer or range of memory, specified as one or more physical or virtual address ranges. It contains methods to return the memory's physically contiguous segments (fragments), for use with the IOMemoryCursor, and methods to map the memory into any address space with caching and placed mapping options. */
                     56: 
                     57: class IOMemoryDescriptor : public OSObject
                     58: {
                     59:     friend class _IOMemoryMap;
                     60:     friend class IOSubMemoryDescriptor;
                     61: 
                     62:     OSDeclareDefaultStructors(IOMemoryDescriptor);
                     63: 
                     64: protected:
                     65:     OSSet *            _mappings;
                     66: 
                     67:     IODirection         _direction;        /* direction of transfer */
                     68:     IOByteCount         _length;           /* length of all ranges */
                     69: 
                     70:     IOOptionBits       _tag;
                     71: 
                     72:     virtual void free();
                     73:     virtual bool serialize( OSSerialize * s ) const;
                     74: public:
                     75:     static void initialize( void );
                     76: 
                     77: public:
                     78: /*! @function withAddress
                     79:     @abstract Create an IOMemoryDescriptor to describe one virtual range of the kernel task.
                     80:     @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map.
                     81:     @param address The virtual address of the first byte in the memory.
                     82:     @param withLength The length of memory.
                     83:     @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.
                     84:     @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
                     85: 
                     86:     static IOMemoryDescriptor * withAddress(void *       address,
                     87:                                             IOByteCount  withLength,
                     88:                                             IODirection  withDirection);
                     89: 
                     90: /*! @function withAddress
                     91:     @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
                     92:     @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.
                     93:     @param address The virtual address of the first byte in the memory.
                     94:     @param withLength The length of memory.
                     95:     @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.
                     96:     @param withTask The task the virtual ranges are mapped into.
                     97:     @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
                     98: 
                     99:     static IOMemoryDescriptor * withAddress(vm_address_t address,
                    100:                                             IOByteCount  withLength,
                    101:                                             IODirection  withDirection,
                    102:                                             task_t       withTask);
                    103: 
                    104: /*! @function withPhysicalAddress
                    105:     @abstract Create an IOMemoryDescriptor to describe one physical range.
                    106:     @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single physical memory range.
                    107:     @param address The physical address of the first byte in the memory.
                    108:     @param withLength The length of memory.
                    109:     @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.
                    110:     @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
                    111: 
                    112:     static IOMemoryDescriptor * withPhysicalAddress(
                    113:                                IOPhysicalAddress       address,
                    114:                                IOByteCount             withLength,
                    115:                                IODirection             withDirection );
                    116: 
                    117: /*! @function withRanges
                    118:     @abstract Create an IOMemoryDescriptor to describe one or more virtual ranges.
                    119:     @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of virtual memory ranges each mapped into a specified source task.
                    120:     @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
                    121:     @param withCount The member count of the ranges array.
                    122:     @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.
                    123:     @param withTask The task each of the virtual ranges are mapped into.
                    124:     @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
                    125:     @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
                    126: 
                    127:      static IOMemoryDescriptor * withRanges(IOVirtualRange *   ranges,
                    128:                                             UInt32             withCount,
                    129:                                             IODirection                withDirection,
                    130:                                             task_t            withTask,
                    131:                                             bool               asReference = false);
                    132: 
                    133: /*! @function withPhysicalRanges
                    134:     @abstract Create an IOMemoryDescriptor to describe one or more physical ranges.
                    135:     @discussion  This method creates and initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges.
                    136:     @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
                    137:     @param withCount The member count of the ranges array.
                    138:     @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.
                    139:     @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
                    140:     @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
                    141: 
                    142:     static IOMemoryDescriptor * withPhysicalRanges(
                    143:                                             IOPhysicalRange *  ranges,
                    144:                                             UInt32             withCount,
                    145:                                             IODirection                withDirection,
                    146:                                             bool               asReference = false);
                    147: 
                    148: /*! @function withSubRange
                    149:     @abstract Create an IOMemoryDescriptor to describe a subrange of an existing descriptor.
                    150:     @discussion  This method creates and initializes an IOMemoryDescriptor for memory consisting of a subrange of the specified memory descriptor. The parent memory descriptor is retained by the new descriptor.
                    151:     @param of The parent IOMemoryDescriptor of which a subrange is to be used for the new descriptor, which will be retained by the subrange IOMemoryDescriptor.
                    152:     @param offset A byte offset into the parent memory descriptor's memory.
                    153:     @param length The length of the subrange.
                    154:     @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. This is used over the direction of the parent descriptor.
                    155:     @result The created IOMemoryDescriptor on success, to be released by the caller, or zero on failure. */
                    156: 
                    157:     static IOMemoryDescriptor *        withSubRange(IOMemoryDescriptor *       of,
                    158:                                             IOByteCount                offset,
                    159:                                             IOByteCount                length,
                    160:                                              IODirection               withDirection);
                    161: 
                    162: /*! @function initWithAddress
                    163:     @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the kernel task.
                    164:     @discussion This method initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the kernel map. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
                    165:     @param address The virtual address of the first byte in the memory.
                    166:     @param withLength The length of memory.
                    167:     @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.
                    168:     @result true on success, false on failure. */
                    169: 
                    170:     virtual bool initWithAddress(void *       address,
                    171:                                  IOByteCount  withLength,
                    172:                                  IODirection  withDirection) = 0;
                    173: 
                    174: /*! @function initWithAddress
                    175:     @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one virtual range of the specified map.
                    176:     @discussion This method initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
                    177:     @param address The virtual address of the first byte in the memory.
                    178:     @param withLength The length of memory.
                    179:     @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.
                    180:     @param withTask The task the virtual ranges are mapped into.
                    181:     @result true on success, false on failure. */
                    182: 
                    183:     virtual bool initWithAddress(vm_address_t address,
                    184:                                  IOByteCount  withLength,
                    185:                                  IODirection  withDirection,
                    186:                                  task_t       withTask) = 0;
                    187: 
                    188: /*! @function initWithPhysicalAddress
                    189:     @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one physical range.
                    190:     @discussion This method initializes an IOMemoryDescriptor for memory consisting of a single physical memory range. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
                    191:     @param address The physical address of the first byte in the memory.
                    192:     @param withLength The length of memory.
                    193:     @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.
                    194:     @result true on success, false on failure. */
                    195: 
                    196:     virtual bool initWithPhysicalAddress(
                    197:                                 IOPhysicalAddress      address,
                    198:                                 IOByteCount            withLength,
                    199:                                 IODirection            withDirection ) = 0;
                    200: 
                    201: /*! @function initWithRanges
                    202:     @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more virtual ranges.
                    203:     @discussion This method initializes an IOMemoryDescriptor for memory consisting of an array of virtual memory ranges each mapped into a specified source task. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
                    204:     @param ranges An array of IOVirtualRange structures which specify the virtual ranges in the specified map which make up the memory to be described.
                    205:     @param withCount The member count of the ranges array.
                    206:     @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.
                    207:     @param withTask The task each of the virtual ranges are mapped into.
                    208:     @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
                    209:     @result true on success, false on failure. */
                    210: 
                    211:     virtual bool initWithRanges(        IOVirtualRange * ranges,
                    212:                                         UInt32           withCount,
                    213:                                         IODirection      withDirection,
                    214:                                         task_t           withTask,
                    215:                                         bool             asReference = false) = 0;
                    216: 
                    217: /*! @function initWithPhysicalRanges
                    218:     @abstract Initialize or reinitialize an IOMemoryDescriptor to describe one or more physical ranges.
                    219:     @discussion  This method initializes an IOMemoryDescriptor for memory consisting of an array of physical memory ranges. An IOMemoryDescriptor can be re-used by calling initWithAddress or initWithRanges again on an existing instance -- note this behavior is not commonly supported in other IOKit classes, although it is supported here.
                    220:     @param ranges An array of IOPhysicalRange structures which specify the physical ranges which make up the memory to be described.
                    221:     @param withCount The member count of the ranges array.
                    222:     @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.
                    223:     @param asReference If false, the IOMemoryDescriptor object will make a copy of the ranges array, otherwise, the array will be used in situ, avoiding an extra allocation.
                    224:     @result true on success, false on failure. */
                    225: 
                    226:     virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
                    227:                                         UInt32           withCount,
                    228:                                         IODirection      withDirection,
                    229:                                         bool             asReference = false) = 0;
                    230: 
                    231: /*! @function getDirection
                    232:     @abstract Accessor to get the direction the memory descriptor was created with.
                    233:     @discussion This method returns the direction the memory descriptor was created with.
                    234:     @result The direction. */
                    235: 
                    236:     virtual IODirection getDirection() const;
                    237: 
                    238: /*! @function getLength
                    239:     @abstract Accessor to get the length of the memory descriptor (over all its ranges).
                    240:     @discussion This method returns the total length of the memory described by the descriptor, ie. the sum of its ranges' lengths.
                    241:     @result The byte count. */
                    242: 
                    243:     virtual IOByteCount getLength() const;
                    244: 
                    245: /*! @function setTag
                    246:     @abstract Set the tag for the memory descriptor.
                    247:     @discussion This method sets the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
                    248:     @param tag The tag. */
                    249: 
                    250:     virtual void setTag( IOOptionBits tag );
                    251: 
                    252: /*! @function getTag
                    253:     @abstract Accessor to the retrieve the tag for the memory descriptor.
                    254:     @discussion This method returns the tag for the memory descriptor. Tag bits are not interpreted by IOMemoryDescriptor.
                    255:     @result The tag. */
                    256: 
                    257:     virtual IOOptionBits getTag( void );
                    258: 
                    259: /*! @function readBytes
                    260:     @abstract Copy data from the memory descriptor's buffer to the specified buffer.
                    261:     @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.
                    262:     @param offset A byte offset into the memory descriptor's memory.
                    263:     @param bytes The caller supplied buffer to copy the data to.
                    264:     @param withLength The length of the data to copy.
                    265:     @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
                    266: 
                    267:     virtual IOByteCount readBytes(IOByteCount offset,
                    268:                                void * bytes, IOByteCount withLength) = 0;
                    269: 
                    270: /*! @function writeBytes
                    271:     @abstract Copy data to the memory descriptor's buffer from the specified buffer.
                    272:     @discussion This method copies data to the memory descriptor's memory at the given offset, from the caller's buffer.
                    273:     @param offset A byte offset into the memory descriptor's memory.
                    274:     @param bytes The caller supplied buffer to copy the data from.
                    275:     @param withLength The length of the data to copy.
                    276:     @result The number of bytes copied, zero will be returned if the specified offset is beyond the length of the descriptor. */
                    277: 
                    278:     virtual IOByteCount writeBytes(IOByteCount offset,
                    279:                                const void * bytes, IOByteCount withLength) = 0;
                    280: 
                    281: /*! @function getPhysicalSegment
                    282:     @abstract Break a memory descriptor into its physically contiguous segments.
                    283:     @discussion This method returns the physical address of the byte at the given offset into the memory, and optionally the length of the physically contiguous segment from that offset.
                    284:     @param offset A byte offset into the memory whose physical address to return.
                    285:     @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
                    286:     @result A physical address, or zero if the offset is beyond the length of the memory. */
                    287: 
                    288:     virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
                    289:                                                 IOByteCount * length) = 0;
                    290: 
                    291: /*! @function getPhysicalAddress
                    292:     @abstract Return the physical address of the first byte in the memory.
                    293:     @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.
                    294:     @result A physical address. */
                    295: 
                    296:     inline IOPhysicalAddress   getPhysicalAddress()
                    297:                                { return( getPhysicalSegment( 0, 0 )); }
                    298: 
                    299:     /*
                    300:      * getVirtualSegment:
                    301:      *
                    302:      * Get the virtual address of the buffer, relative to the given offset.
                    303:      * If the memory wasn't mapped into the caller's address space, it will be
                    304:      * mapped in now.   If the current position is at the end of the buffer, a
                    305:      * null is returned.
                    306:      */
                    307:     virtual void * getVirtualSegment(IOByteCount offset,
                    308:                                        IOByteCount * length) = 0;
                    309: 
                    310: /*! @function prepare
                    311:     @abstract Prepare the memory for an I/O transfer.
                    312:     @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.
                    313:     @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
                    314:     @result An IOReturn code. */
                    315: 
                    316:     virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) = 0;
                    317: 
                    318: /*! @function complete
                    319:     @abstract Complete processing of the memory after an I/O transfer finishes.
                    320:     @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.
                    321:     @param forDirection The direction of the I/O just completed, or kIODirectionNone for the direction specified by the memory descriptor.
                    322:     @result An IOReturn code. */
                    323: 
                    324:     virtual IOReturn complete(IODirection forDirection = kIODirectionNone) = 0;
                    325: 
                    326:     /*
                    327:      * Mapping functions.
                    328:      */
                    329: 
                    330: /*! @function map
                    331:     @abstract Maps a IOMemoryDescriptor into a task.
                    332:     @discussion This is the general purpose method to map all or part of the memory described by a memory descriptor into a task at any available address, or at a fixed address if possible. Caching & read-only options may be set for the mapping. The mapping is represented as a returned reference to a IOMemoryMap object, which may be shared if the mapping is compatible with an existing mapping of the IOMemoryDescriptor. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping. 
                    333:     @param intoTask Sets the target task for the mapping. Pass kernel_task for the kernel address space.
                    334:     @param atAddress If a placed mapping is requested, atAddress specifies its address, and the kIOMapAnywhere should not be set. Otherwise, atAddress is ignored.
                    335:     @param options Mapping options are defined in IOTypes.h,<br>
                    336:        kIOMapAnywhere should be passed if the mapping can be created anywhere. If not set, the atAddress parameter sets the location of the mapping, if it is available in the target map.<br>
                    337:        kIOMapDefaultCache to inhibit the cache in I/O areas, kIOMapCopybackCache in general purpose RAM.<br>
                    338:        kIOMapInhibitCache, kIOMapWriteThruCache, kIOMapCopybackCache to set the appropriate caching.<br>
                    339:        kIOMapReadOnly to allow only read only accesses to the memory - writes will cause and access fault.<br>
                    340:        kIOMapReference will only succeed if the mapping already exists, and the IOMemoryMap object is just an extra reference, ie. no new mapping will be created.<br>
                    341:     @param offset Is a beginning offset into the IOMemoryDescriptor's memory where the mapping starts. Zero is the default to map all the memory.
                    342:     @param length Is the length of the mapping requested for a subset of the IOMemoryDescriptor. Zero is the default to map all the memory.
                    343:     @result A reference to an IOMemoryMap object representing the mapping, which can supply the virtual address of the mapping and other information. The mapping may be shared with multiple callers - multiple maps are avoided if a compatible one exists. The IOMemoryMap object returned should be released only when the caller has finished accessing the mapping, as freeing the object destroys the mapping. The IOMemoryMap instance also retains the IOMemoryDescriptor it maps while it exists. */
                    344: 
                    345:     virtual IOMemoryMap *      map(
                    346:        task_t          intoTask,
                    347:        IOVirtualAddress        atAddress,
                    348:        IOOptionBits            options,
                    349:        IOByteCount             offset = 0,
                    350:        IOByteCount             length = 0 );
                    351: 
                    352: /*! @function map
                    353:     @abstract Maps a IOMemoryDescriptor into the kernel map.
                    354:     @discussion This is a shortcut method to map all the memory described by a memory descriptor into the kernel map at any available address. See the full version of the map method for further details.
                    355:     @param options Mapping options as in the full version of the map method, with kIOMapAnywhere assumed.
                    356:     @result See the full version of the map method. */
                    357: 
                    358:     virtual IOMemoryMap *      map(
                    359:        IOOptionBits            options = 0 );
                    360: 
                    361: /*! @function setMapping
                    362:     @abstract Establishes an already existing mapping.
                    363:     @discussion This method tells the IOMemoryDescriptor about a mapping that exists, but was created elsewhere. It allows later callers of the map method to share this externally created mapping. The IOMemoryMap object returned is created to represent it. This method is not commonly needed.
                    364:     @param task Address space in which the mapping exists.
                    365:     @param mapAddress Virtual address of the mapping.
                    366:     @param options Caching and read-only attributes of the mapping.
                    367:     @result A IOMemoryMap object created to represent the mapping. */
                    368: 
                    369:     virtual IOMemoryMap *      setMapping(
                    370:        task_t          task,
                    371:        IOVirtualAddress        mapAddress,
                    372:        IOOptionBits            options = 0 );
                    373: 
                    374: protected:
                    375:     virtual IOMemoryMap *      makeMapping(
                    376:        IOMemoryDescriptor *    owner,
                    377:        task_t          intoTask,
                    378:        IOVirtualAddress        atAddress,
                    379:        IOOptionBits            options,
                    380:        IOByteCount             offset,
                    381:        IOByteCount             length );
                    382: 
                    383:     virtual void               addMapping(
                    384:        IOMemoryMap *           mapping );
                    385: 
                    386:     virtual void               removeMapping(
                    387:        IOMemoryMap *           mapping );
                    388: 
                    389:     virtual IOReturn doMap(
                    390:        task_t          addressTask,
                    391:        IOVirtualAddress *      atAddress,
                    392:        IOOptionBits            options,
                    393:        IOByteCount             sourceOffset = 0,
                    394:        IOByteCount             length = 0 );
                    395: 
                    396:     virtual IOReturn doUnmap(
                    397:        task_t          addressTask,
                    398:        IOVirtualAddress        logical,
                    399:        IOByteCount             length );
                    400: };
                    401: 
                    402: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                    403: 
                    404: /*! @class IOMemoryMap : public OSObject
                    405:     @abstract An abstract base class defining common methods for describing a memory mapping.
                    406:     @discussion The IOMemoryMap object represents a mapped range of memory, described by a IOMemoryDescriptor. The mapping may be in the kernel or a non-kernel task and has processor cache mode attributes. IOMemoryMap instances are created by IOMemoryDescriptor when it creates mappings in its map method, and returned to the caller. */
                    407: 
                    408: class IOMemoryMap : public OSObject
                    409: {
                    410:     OSDeclareAbstractStructors(IOMemoryMap)
                    411: 
                    412: public:
                    413: /*! @function getVirtualAddress
                    414:     @abstract Accessor to the virtual address of the first byte in the mapping.
                    415:     @discussion This method returns the virtual address of the first byte in the mapping.
                    416:     @result A virtual address. */
                    417: 
                    418:     virtual IOVirtualAddress   getVirtualAddress() = 0;
                    419: 
                    420: /*! @function getPhysicalSegment
                    421:     @abstract Break a mapping into its physically contiguous segments.
                    422:     @discussion This method returns the physical address of the byte at the given offset into the mapping, and optionally the length of the physically contiguous segment from that offset. It functions similarly to IOMemoryDescriptor::getPhysicalSegment.
                    423:     @param offset A byte offset into the mapping whose physical address to return.
                    424:     @param length If non-zero, getPhysicalSegment will store here the length of the physically contiguous segement at the given offset.
                    425:     @result A physical address, or zero if the offset is beyond the length of the mapping. */
                    426: 
                    427:     virtual IOPhysicalAddress  getPhysicalSegment(IOByteCount offset,
                    428:                                                   IOByteCount * length) = 0;
                    429: 
                    430: /*! @function getPhysicalAddress
                    431:     @abstract Return the physical address of the first byte in the mapping.
                    432:     @discussion This method returns the physical address of the  first byte in the mapping. It is most useful on mappings known to be physically contiguous.
                    433:     @result A physical address. */
                    434: 
                    435:     inline IOPhysicalAddress   getPhysicalAddress()
                    436:                                { return( getPhysicalSegment( 0, 0 )); }
                    437: 
                    438: /*! @function getLength
                    439:     @abstract Accessor to the length of the mapping.
                    440:     @discussion This method returns the length of the mapping.
                    441:     @result A byte count. */
                    442: 
                    443:     virtual IOByteCount        getLength() = 0;
                    444: 
                    445: /*! @function getAddressTask
                    446:     @abstract Accessor to the task of the mapping.
                    447:     @discussion This method returns the mach task the mapping exists in.
                    448:     @result A mach task_t. */
                    449: 
                    450:     virtual task_t             getAddressTask() = 0;
                    451: 
                    452: /*! @function getMemoryDescriptor
                    453:     @abstract Accessor to the IOMemoryDescriptor the mapping was created from.
                    454:     @discussion This method returns the IOMemoryDescriptor the mapping was created from.
                    455:     @result An IOMemoryDescriptor reference, which is valid while the IOMemoryMap object is retained. It should not be released by the caller. */
                    456: 
                    457:     virtual IOMemoryDescriptor * getMemoryDescriptor() = 0;
                    458: 
                    459: /*! @function getMapOptions
                    460:     @abstract Accessor to the options the mapping was created with.
                    461:     @discussion This method returns the options to IOMemoryDescriptor::map the mapping was created with.
                    462:     @result Options for the mapping, including cache settings. */
                    463: 
                    464:     virtual IOOptionBits       getMapOptions() = 0;
                    465: 
                    466: /*! @function unmap
                    467:     @abstract Force the IOMemoryMap to unmap, without destroying the object.
                    468:     @discussion IOMemoryMap instances will unmap themselves upon free, ie. when the last client with a reference calls release. This method forces the IOMemoryMap to destroy the mapping it represents, regardless of the number of clients. It is not generally used.
                    469:     @result An IOReturn code. */
                    470: 
                    471:     virtual IOReturn           unmap() = 0;
                    472: 
                    473: };
                    474: 
                    475: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                    476: 
                    477: class IOGeneralMemoryDescriptor : public IOMemoryDescriptor
                    478: {
                    479:     OSDeclareDefaultStructors(IOGeneralMemoryDescriptor);
                    480: 
                    481: protected:
                    482:     union {
                    483:     IOVirtualRange *   v;
                    484:     IOPhysicalRange *  p;
                    485:     }                  _ranges;            /* list of address ranges */
                    486:     unsigned           _rangesCount;       /* number of address ranges in list */
                    487:     bool               _rangesIsAllocated; /* is list allocated by us? */
                    488: 
                    489:     task_t             _task;               /* task where all ranges are mapped to */
                    490: 
                    491:     union {
                    492:     IOVirtualRange     v;
                    493:     IOPhysicalRange    p;
                    494:     }                  _singleRange;      /* storage space for a single range */
                    495: 
                    496:     unsigned           _wireCount;        /* number of outstanding wires */
                    497: 
                    498:     vm_address_t       _cachedVirtualAddress;  /* a cached virtual-to-physical */
                    499:     IOPhysicalAddress  _cachedPhysicalAddress; /*    mapping, for optimization */
                    500: 
                    501:     IOByteCount                _position;         /* absolute position over all ranges */
                    502:     unsigned           _positionAtIndex;  /* range #n in which position is now */
                    503:     IOByteCount                _positionAtOffset; /* relative position within range #n */
                    504: 
                    505:     bool               _initialized;      /* has superclass been initialized? */
                    506: 
                    507:     vm_offset_t _kernPtr;
                    508:     vm_offset_t _kernPtrAligned;
                    509:     unsigned    _kernPtrAtIndex;
                    510:     IOByteCount  _kernSize;
                    511:     virtual void mapIntoKernel(unsigned rangeIndex);
                    512:     virtual void unmapFromKernel();
                    513: 
                    514:     virtual void free();
                    515: 
                    516: public:
                    517:     /*
                    518:      * IOMemoryDescriptor required methods
                    519:      */
                    520: 
                    521:     virtual bool initWithAddress(void *       address,
                    522:                                  IOByteCount    withLength,
                    523:                                  IODirection  withDirection);
                    524: 
                    525:     virtual bool initWithAddress(vm_address_t address,
                    526:                                  IOByteCount    withLength,
                    527:                                  IODirection  withDirection,
                    528:                                  task_t       withTask);
                    529: 
                    530:     virtual bool initWithPhysicalAddress(
                    531:                                 IOPhysicalAddress      address,
                    532:                                 IOByteCount            withLength,
                    533:                                 IODirection            withDirection );
                    534: 
                    535:     virtual bool initWithRanges(        IOVirtualRange * ranges,
                    536:                                         UInt32           withCount,
                    537:                                         IODirection      withDirection,
                    538:                                         task_t           withTask,
                    539:                                         bool             asReference = false);
                    540: 
                    541:     virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
                    542:                                         UInt32           withCount,
                    543:                                         IODirection      withDirection,
                    544:                                         bool             asReference = false);
                    545: 
                    546:     virtual IOByteCount readBytes(IOByteCount offset,
                    547:                                void * bytes, IOByteCount withLength);
                    548: 
                    549:     virtual IOByteCount writeBytes(IOByteCount offset,
                    550:                                const void * bytes, IOByteCount withLength);
                    551: 
                    552:     virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
                    553:                                                 IOByteCount * length);
                    554: 
                    555:     virtual void * getVirtualSegment(IOByteCount offset,
                    556:                                        IOByteCount * length);
                    557: 
                    558:     virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
                    559: 
                    560:     virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
                    561: 
                    562:     virtual IOReturn doMap(
                    563:        task_t          addressTask,
                    564:        IOVirtualAddress *      atAddress,
                    565:        IOOptionBits            options,
                    566:        IOByteCount             sourceOffset = 0,
                    567:        IOByteCount             length = 0 );
                    568: 
                    569:     virtual IOReturn doUnmap(
                    570:        task_t          addressTask,
                    571:        IOVirtualAddress        logical,
                    572:        IOByteCount             length );
                    573: 
                    574: protected:
                    575:     virtual void setPosition(IOByteCount position);
                    576: };
                    577: 
                    578: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                    579: 
                    580: class IOSubMemoryDescriptor : public IOMemoryDescriptor
                    581: {
                    582:     friend IOMemoryDescriptor;
                    583: 
                    584:     OSDeclareDefaultStructors(IOSubMemoryDescriptor);
                    585: 
                    586: protected:
                    587:     IOMemoryDescriptor * _parent;
                    588:     IOByteCount         _start;
                    589: 
                    590:     virtual void free();
                    591: 
                    592:     virtual bool initSubRange( IOMemoryDescriptor * parent,
                    593:                                IOByteCount offset, IOByteCount length,
                    594:                                IODirection withDirection );
                    595: 
                    596:     virtual bool initWithAddress(void *       address,
                    597:                                  IOByteCount    withLength,
                    598:                                  IODirection  withDirection);
                    599: 
                    600:     virtual bool initWithAddress(vm_address_t address,
                    601:                                  IOByteCount    withLength,
                    602:                                  IODirection  withDirection,
                    603:                                  task_t       withTask);
                    604: 
                    605:     virtual bool initWithPhysicalAddress(
                    606:                                 IOPhysicalAddress      address,
                    607:                                 IOByteCount            withLength,
                    608:                                 IODirection            withDirection );
                    609: 
                    610:     virtual bool initWithRanges(        IOVirtualRange * ranges,
                    611:                                         UInt32           withCount,
                    612:                                         IODirection      withDirection,
                    613:                                         task_t           withTask,
                    614:                                         bool             asReference = false);
                    615: 
                    616:     virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
                    617:                                         UInt32           withCount,
                    618:                                         IODirection      withDirection,
                    619:                                         bool             asReference = false);
                    620: 
                    621: public:
                    622:     /*
                    623:      * IOMemoryDescriptor required methods
                    624:      */
                    625: 
                    626:     virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
                    627:                                                 IOByteCount * length);
                    628: 
                    629:     virtual IOByteCount readBytes(IOByteCount offset,
                    630:                                void * bytes, IOByteCount withLength);
                    631: 
                    632:     virtual IOByteCount writeBytes(IOByteCount offset,
                    633:                                const void * bytes, IOByteCount withLength);
                    634: 
                    635:     virtual void * getVirtualSegment(IOByteCount offset,
                    636:                                        IOByteCount * length);
                    637: 
                    638:     virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
                    639: 
                    640:     virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
                    641: 
                    642: protected:
                    643:     virtual IOMemoryMap *      makeMapping(
                    644:        IOMemoryDescriptor *    owner,
                    645:        task_t          intoTask,
                    646:        IOVirtualAddress        atAddress,
                    647:        IOOptionBits            options,
                    648:        IOByteCount             offset,
                    649:        IOByteCount             length );
                    650: };
                    651: 
                    652: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                    653: 
                    654: #endif /* !_IOMEMORYDESCRIPTOR_H */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.