]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/IOKit/IOMemoryDescriptor.h
xnu-4570.71.2.tar.gz
[apple/xnu.git] / iokit / IOKit / IOMemoryDescriptor.h
index 242581bcb4a5c6d342d4696879213bfe2bf55116..35c3305816d0fa46e8fa86ec655b0007d3c81ff9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 #include <IOKit/IOTypes.h>
 #include <IOKit/IOLocks.h>
 #include <libkern/c++/OSContainers.h>
+#ifdef XNU_KERNEL_PRIVATE
+#include <IOKit/IOKitDebug.h>
+#endif
 
 #include <mach/memory_object_types.h>
 
 class IOMemoryMap;
 class IOMapper;
 class IOService;
+class IODMACommand;
 
 /*
  * Direction of transfer, with respect to the described memory.
@@ -68,6 +72,7 @@ enum IODirection
 #define IODIRECTIONCOMPLETEWITHDATAVALIDDEFINED        1
      kIODirectionCompleteWithDataValid = 0x00000080,
 };
+
 #ifdef __LP64__
 typedef IOOptionBits IODirection;
 #endif /* __LP64__ */
@@ -105,10 +110,13 @@ enum {
 #endif
     kIOMemoryPersistent                = 0x00010000,
 #ifdef XNU_KERNEL_PRIVATE
-    kIOMemoryReserved6156215   = 0x00020000,
+    kIOMemoryMapCopyOnWrite    = 0x00020000,
 #endif
+    kIOMemoryRemote            = 0x00040000,
     kIOMemoryThreadSafe                = 0x00100000,   // Shared with Buffer MD
     kIOMemoryClearEncrypt      = 0x00200000,   // Shared with Buffer MD
+    kIOMemoryUseReserve        = 0x00800000,   // Shared with Buffer MD
+#define IOMEMORYUSERESERVEDEFINED      1
 
 #ifdef XNU_KERNEL_PRIVATE
     kIOMemoryBufferPurgeable   = 0x00400000,
@@ -140,6 +148,7 @@ enum
     kIOMemoryPurgeableVolatileBehaviorLifo     = VM_PURGABLE_BEHAVIOR_LIFO,
     kIOMemoryPurgeableVolatileOrderingObsolete = VM_PURGABLE_ORDERING_OBSOLETE,
     kIOMemoryPurgeableVolatileOrderingNormal   = VM_PURGABLE_ORDERING_NORMAL,
+    kIOMemoryPurgeableFaultOnAccess            = VM_PURGABLE_DEBUG_FAULT,
 };
 enum 
 {
@@ -162,15 +171,79 @@ struct IODMAMapSpecification
        uint32_t    resvB[4];
 };
 
+struct IODMAMapPageList
+{
+    uint32_t                pageOffset;
+    uint32_t                pageListCount;
+    const upl_page_info_t * pageList;
+};
+
+// mapOptions for iovmMapMemory
 enum
 {
+    kIODMAMapReadAccess           = 0x00000001,
     kIODMAMapWriteAccess          = 0x00000002,
     kIODMAMapPhysicallyContiguous = 0x00000010,
     kIODMAMapDeviceMemory         = 0x00000020,
     kIODMAMapPagingPath           = 0x00000040,
     kIODMAMapIdentityMap          = 0x00000080,
+
+    kIODMAMapPageListFullyOccupied = 0x00000100,
+    kIODMAMapFixedAddress          = 0x00000200,
+};
+
+#ifdef KERNEL_PRIVATE
+
+// Used for dmaCommandOperation communications for IODMACommand and mappers
+
+enum  {
+    kIOMDWalkSegments             = 0x01000000,
+    kIOMDFirstSegment            = 1 | kIOMDWalkSegments,
+    kIOMDGetCharacteristics       = 0x02000000,
+    kIOMDGetCharacteristicsMapped = 1 | kIOMDGetCharacteristics,
+    kIOMDDMAActive                = 0x03000000,
+    kIOMDSetDMAActive             = 1 | kIOMDDMAActive,
+    kIOMDSetDMAInactive           = kIOMDDMAActive,
+    kIOMDAddDMAMapSpec            = 0x04000000,
+    kIOMDDMAMap                   = 0x05000000,
+    kIOMDDMAUnmap                 = 0x06000000,
+    kIOMDDMACommandOperationMask  = 0xFF000000,
+};
+struct IOMDDMACharacteristics {
+    UInt64 fLength;
+    UInt32 fSGCount;
+    UInt32 fPages;
+    UInt32 fPageAlign;
+    ppnum_t fHighestPage;
+    IODirection fDirection;
+    UInt8 fIsPrepared;
+};
+
+struct IOMDDMAMapArgs {
+    IOMapper            * fMapper;
+    IODMACommand        * fCommand;
+    IODMAMapSpecification fMapSpec;
+    uint64_t              fOffset;
+    uint64_t              fLength;
+    uint64_t              fAlloc;
+    uint64_t              fAllocLength;
+    uint8_t               fMapContig;
+};
+
+struct IOMDDMAWalkSegmentArgs {
+    UInt64 fOffset;                    // Input/Output offset
+    UInt64 fIOVMAddr, fLength;         // Output variables
+    UInt8 fMapped;                     // Input Variable, Require mapped IOVMA
+    UInt64 fMappedBase;                        // Input base of mapping
+};
+typedef UInt8 IOMDDMAWalkSegmentState[128];
+// fMapped:
+enum
+{
+       kIOMDDMAWalkMappedLocal = 2
 };
 
+#endif /* KERNEL_PRIVATE */
 
 enum 
 {
@@ -191,6 +264,7 @@ struct IOMemoryReference;
 class IOMemoryDescriptor : public OSObject
 {
     friend class IOMemoryMap;
+    friend class IOMultiMemoryDescriptor;
 
     OSDeclareDefaultStructors(IOMemoryDescriptor);
 
@@ -208,17 +282,22 @@ protected:
 #ifdef XNU_KERNEL_PRIVATE
 public:
     struct IOMemoryReference * _memRef;
+    vm_tag_t _kernelTag;
+    vm_tag_t _userTag;
+    int16_t _dmaReferences;
+    uint16_t _internalFlags;
+    kern_allocation_name_t _mapName;
 protected:
-#else
-    void * __iomd_reserved5;
-#endif
+#else /* XNU_KERNEL_PRIVATE */
+    void *             __iomd_reserved5;
+    uint16_t           __iomd_reserved1[4];
+    uintptr_t          __iomd_reserved2;
+#endif /* XNU_KERNEL_PRIVATE */
 
-#ifdef __LP64__
-    uint64_t           __iomd_reserved1;
-    uint64_t           __iomd_reserved2;
-    uint64_t           __iomd_reserved3;
-    uint64_t           __iomd_reserved4;
-#else /* !__LP64__ */
+    uintptr_t          __iomd_reserved3;
+    uintptr_t          __iomd_reserved4;
+
+#ifndef __LP64__
     IODirection         _direction;        /* use _flags instead */
 #endif /* !__LP64__ */
     IOByteCount         _length;           /* length of all ranges */
@@ -315,11 +394,25 @@ typedef IOOptionBits DMACommandOps;
     IOMemoryDescriptorReserved * getKernelReserved( void );
     IOReturn dmaMap(
        IOMapper                    * mapper,
+       IODMACommand                * command,
        const IODMAMapSpecification * mapSpec,
        uint64_t                      offset,
        uint64_t                      length,
-       uint64_t                    * address,
-       ppnum_t                     * mapPages);
+       uint64_t                    * mapAddress,
+       uint64_t                    * mapLength);
+    IOReturn dmaUnmap(
+       IOMapper                    * mapper,
+       IODMACommand                * command,
+       uint64_t                      offset,
+       uint64_t                      mapAddress,
+       uint64_t                      mapLength);
+    void dmaMapRecord(
+       IOMapper                    * mapper,
+       IODMACommand                * command,
+       uint64_t                      mapLength);
+
+    void     setVMTags(vm_tag_t kernelTag, vm_tag_t userTag);
+    vm_tag_t getVMTag(vm_map_t map);
 #endif
        
 private:
@@ -351,7 +444,7 @@ private:
     OSMetaClassDeclareReservedUnused(IOMemoryDescriptor, 15);
 
 protected:
-    virtual void free();
+    virtual void free() APPLE_KEXT_OVERRIDE;
 public:
     static void initialize( void );
 
@@ -400,7 +493,7 @@ public:
     @abstract Create an IOMemoryDescriptor to describe one virtual range of the specified map.
     @discussion This method creates and initializes an IOMemoryDescriptor for memory consisting of a single virtual memory range mapped into the specified map.  This memory descriptor needs to be prepared before it can be used to extract data from the memory described.
     @param address The virtual address of the first byte in the memory.
-    @param withLength The length of memory.
+    @param length The length of memory.
     @param options
         kIOMemoryDirectionMask (options:direction)     This nibble indicates the I/O direction to be associated with the descriptor, which may affect the operation of the prepare and complete methods on some architectures. 
     @param task The task the virtual ranges are mapped into. Note that unlike IOMemoryDescriptor::withAddress(), kernel_task memory must be explicitly prepared when passed to this api. The task argument may be NULL to specify memory by physical address.
@@ -535,6 +628,13 @@ public:
 
     virtual IOOptionBits getTag( void );
 
+/*! @function getFlags
+    @abstract Accessor to the retrieve the options the memory descriptor was created with.
+    @discussion Accessor to the retrieve the options the memory descriptor was created with, and flags with its state. These bits are defined by the kIOMemory* enum.
+    @result The flags bitfield. */
+
+    uint64_t getFlags(void);
+
 /*! @function readBytes
     @abstract Copy data from the memory descriptor's buffer to the specified buffer.
     @discussion This method copies data from the memory descriptor's memory at the given offset, to the caller's buffer.  The memory descriptor MUST have the kIODirectionOut direcction bit set  and be prepared.  kIODirectionOut means that this memory descriptor will be output to an external device, so readBytes is used to get memory into a local buffer for a PIO transfer to the device.
@@ -720,11 +820,14 @@ public:
     ipc_port_t          fRedirEntry;
     IOMemoryDescriptor * fOwner;
     uint8_t             fUserClientUnmap;
+#if IOTRACKING
+    IOTrackingUser       fTracking;
+#endif
 #endif /* XNU_KERNEL_PRIVATE */
 
 protected:
-    virtual void taggedRelease(const void *tag = 0) const;
-    virtual void free();
+    virtual void taggedRelease(const void *tag = 0) const APPLE_KEXT_OVERRIDE;
+    virtual void free() APPLE_KEXT_OVERRIDE;
 
 public:
 /*! @function getVirtualAddress
@@ -818,22 +921,22 @@ public:
     @abstract Accessor to the virtual address of the first byte in the mapping.
     @discussion This method returns the virtual address of the first byte in the mapping.
     @result A virtual address. */
+    inline mach_vm_address_t   getAddress() __attribute__((always_inline));
 /*! @function getSize
     @abstract Accessor to the length of the mapping.
     @discussion This method returns the length of the mapping.
     @result A byte count. */
-    inline mach_vm_address_t   getAddress() __attribute__((always_inline));
     inline mach_vm_size_t      getSize() __attribute__((always_inline));
 #else /* !__LP64__ */
 /*! @function getAddress
     @abstract Accessor to the virtual address of the first byte in the mapping.
     @discussion This method returns the virtual address of the first byte in the mapping.
     @result A virtual address. */
+    virtual mach_vm_address_t  getAddress();
 /*! @function getSize
     @abstract Accessor to the length of the mapping.
     @discussion This method returns the length of the mapping.
     @result A byte count. */
-    virtual mach_vm_address_t  getAddress();
     virtual mach_vm_size_t     getSize();
 #endif /* !__LP64__ */
 
@@ -922,22 +1025,23 @@ protected:
     bool               _initialized;      /* has superclass been initialized? */
 
 public:
-    virtual void free();
+    virtual void free() APPLE_KEXT_OVERRIDE;
 
-    virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const;
+    virtual IOReturn dmaCommandOperation(DMACommandOps op, void *vData, UInt dataSize) const APPLE_KEXT_OVERRIDE;
 
-    virtual uint64_t getPreparationID( void );
+    virtual uint64_t getPreparationID( void ) APPLE_KEXT_OVERRIDE;
 
 #ifdef XNU_KERNEL_PRIVATE
     // Internal APIs may be made virtual at some time in the future.
     IOReturn wireVirtual(IODirection forDirection);
     IOReturn dmaMap(
        IOMapper                    * mapper,
+       IODMACommand                * command,
        const IODMAMapSpecification * mapSpec,
        uint64_t                      offset,
        uint64_t                      length,
-       uint64_t                    * address,
-       ppnum_t                     * mapPages);
+       uint64_t                    * mapAddress,
+       uint64_t                    * mapLength);
     bool initMemoryEntries(size_t size, IOMapper * mapper);
 
     IOMemoryReference * memoryReferenceAlloc(uint32_t capacity, 
@@ -994,76 +1098,76 @@ public:
                                  UInt32                offset,
                                  task_t                task,
                                  IOOptionBits  options,
-                                 IOMapper *    mapper = kIOMapperSystem);
+                                 IOMapper *    mapper = kIOMapperSystem) APPLE_KEXT_OVERRIDE;
 
 #ifndef __LP64__
     // Secondary initialisers
     virtual bool initWithAddress(void *                address,
                                  IOByteCount   withLength,
-                                 IODirection   withDirection) APPLE_KEXT_DEPRECATED;
+                                 IODirection   withDirection) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 
     virtual bool initWithAddress(IOVirtualAddress address,
                                  IOByteCount    withLength,
                                  IODirection   withDirection,
-                                 task_t                withTask) APPLE_KEXT_DEPRECATED;
+                                 task_t                withTask) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 
     virtual bool initWithPhysicalAddress(
                                 IOPhysicalAddress      address,
                                 IOByteCount            withLength,
-                                IODirection            withDirection ) APPLE_KEXT_DEPRECATED;
+                                IODirection            withDirection ) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 
     virtual bool initWithRanges(        IOVirtualRange * ranges,
                                         UInt32           withCount,
                                         IODirection      withDirection,
                                         task_t           withTask,
-                                        bool             asReference = false) APPLE_KEXT_DEPRECATED;
+                                        bool             asReference = false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 
     virtual bool initWithPhysicalRanges(IOPhysicalRange * ranges,
                                         UInt32           withCount,
                                         IODirection      withDirection,
-                                        bool             asReference = false) APPLE_KEXT_DEPRECATED;
+                                        bool             asReference = false) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 
     virtual addr64_t getPhysicalSegment64( IOByteCount offset,
-                                            IOByteCount * length ) APPLE_KEXT_DEPRECATED;
+                                            IOByteCount * length ) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 
     virtual IOPhysicalAddress getPhysicalSegment(IOByteCount offset,
-                                                IOByteCount * length);
+                                                IOByteCount * length) APPLE_KEXT_OVERRIDE;
 
     virtual IOPhysicalAddress getSourceSegment(IOByteCount offset,
-                                               IOByteCount * length) APPLE_KEXT_DEPRECATED;
+                                               IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 
     virtual void * getVirtualSegment(IOByteCount offset,
-                                       IOByteCount * length) APPLE_KEXT_DEPRECATED;
+                                       IOByteCount * length) APPLE_KEXT_OVERRIDE APPLE_KEXT_DEPRECATED;
 #endif /* !__LP64__ */
 
     virtual IOReturn setPurgeable( IOOptionBits newState,
-                                    IOOptionBits * oldState );
+                                    IOOptionBits * oldState ) APPLE_KEXT_OVERRIDE;
     
     virtual addr64_t getPhysicalSegment( IOByteCount   offset,
                                          IOByteCount * length,
 #ifdef __LP64__
-                                         IOOptionBits  options = 0 );
+                                         IOOptionBits  options = 0 ) APPLE_KEXT_OVERRIDE;
 #else /* !__LP64__ */
-                                         IOOptionBits  options );
+                                         IOOptionBits  options ) APPLE_KEXT_OVERRIDE;
 #endif /* !__LP64__ */
 
-    virtual IOReturn prepare(IODirection forDirection = kIODirectionNone);
+    virtual IOReturn prepare(IODirection forDirection = kIODirectionNone) APPLE_KEXT_OVERRIDE;
 
-    virtual IOReturn complete(IODirection forDirection = kIODirectionNone);
+    virtual IOReturn complete(IODirection forDirection = kIODirectionNone) APPLE_KEXT_OVERRIDE;
 
     virtual IOReturn doMap(
        vm_map_t                addressMap,
        IOVirtualAddress *      atAddress,
        IOOptionBits            options,
        IOByteCount             sourceOffset = 0,
-       IOByteCount             length = 0 );
+       IOByteCount             length = 0 ) APPLE_KEXT_OVERRIDE;
 
     virtual IOReturn doUnmap(
        vm_map_t                addressMap,
        IOVirtualAddress        logical,
-       IOByteCount             length );
+       IOByteCount             length ) APPLE_KEXT_OVERRIDE;
 
-    virtual bool serialize(OSSerialize *s) const;
+    virtual bool serialize(OSSerialize *s) const APPLE_KEXT_OVERRIDE;
 
     // Factory method for cloning a persistent IOMD, see IOMemoryDescriptor
     static IOMemoryDescriptor *