#include <libkern/OSAtomic.h>
#include <IOKit/IOLocks.h>
#include <IOKit/IOPlatformExpert.h>
#include <IOKit/IODeviceTreeSupport.h>
#include <IOKit/IOMapper.h>
#define kMapperPage (4 * 1024)
#define kTransPerPage (kMapperPage / sizeof(ppnum_t))
#define kMinZoneSize 4 // Minimum Zone size in pages
#define kMaxNumZones (31 - 14) // 31 bit mapped in 16K super pages
class IOCopyMapper : public IOMapper
{
OSDeclareDefaultStructors(IOCopyMapper);
#define fMappings ((ActiveDARTEntry *) super::fTable)
private:
UInt32 fFreeLists[kMaxNumZones];
IOLock *fTableLock;
void *fDummyPage;
UInt32 fNumZones;
UInt32 fMapperRegionSize;
UInt32 fMapperRegionUsed;
UInt32 fMapperRegionMaxUsed;
UInt32 fFreeSleepers;
ppnum_t fDummyPageNumber;
ppnum_t fBufferPage;
void breakUp(unsigned start, unsigned end, unsigned freeInd);
void invalidateDART(ppnum_t pnum, IOItemCount size);
void tlbInvalidate(ppnum_t pnum, IOItemCount size);
virtual void free();
virtual bool initHardware(IOService * provider);
public:
virtual ppnum_t iovmAlloc(IOItemCount pages);
virtual void iovmFree(ppnum_t addr, IOItemCount pages);
virtual void iovmInsert(ppnum_t addr, IOItemCount offset, ppnum_t page);
virtual void iovmInsert(ppnum_t addr, IOItemCount offset,
ppnum_t *pageList, IOItemCount pageCount);
virtual void iovmInsert(ppnum_t addr, IOItemCount offset,
upl_page_info_t *pageList, IOItemCount pageCount);
virtual addr64_t mapAddr(IOPhysicalAddress addr);
};
extern IOCopyMapper * gIOCopyMapper;