]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCopyMapper.h
e2a5f5df78e67919cc60782c4e8f6ecf1514ca9f
[apple/xnu.git] / iokit / Kernel / IOCopyMapper.h
1 /*
2 * Copyright (c) 2006 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 // 45678901234567890123456789012345678901234567890123456789012345678901234567890
23
24 #include <libkern/OSAtomic.h>
25
26 #include <IOKit/IOLocks.h>
27 #include <IOKit/IOPlatformExpert.h>
28 #include <IOKit/IODeviceTreeSupport.h>
29 #include <IOKit/IOMapper.h>
30
31 // General constants about all VART/DART style Address Re-Mapping Tables
32 #define kMapperPage (4 * 1024)
33 #define kTransPerPage (kMapperPage / sizeof(ppnum_t))
34
35 #define kMinZoneSize 4 // Minimum Zone size in pages
36 #define kMaxNumZones (31 - 14) // 31 bit mapped in 16K super pages
37
38 class IOCopyMapper : public IOMapper
39 {
40 OSDeclareDefaultStructors(IOCopyMapper);
41
42 // alias the fTable variable into our mappings table
43 #define fMappings ((ActiveDARTEntry *) super::fTable)
44
45 private:
46
47 UInt32 fFreeLists[kMaxNumZones];
48
49 IOLock *fTableLock;
50
51 void *fDummyPage;
52
53 UInt32 fNumZones;
54 UInt32 fMapperRegionSize;
55 UInt32 fMapperRegionUsed;
56 UInt32 fMapperRegionMaxUsed;
57 UInt32 fFreeSleepers;
58 ppnum_t fDummyPageNumber;
59 ppnum_t fBufferPage;
60
61 // Internal functions
62
63 void breakUp(unsigned start, unsigned end, unsigned freeInd);
64 void invalidateDART(ppnum_t pnum, IOItemCount size);
65 void tlbInvalidate(ppnum_t pnum, IOItemCount size);
66
67 virtual void free();
68
69 virtual bool initHardware(IOService * provider);
70 public:
71 virtual ppnum_t iovmAlloc(IOItemCount pages);
72 virtual void iovmFree(ppnum_t addr, IOItemCount pages);
73
74 virtual void iovmInsert(ppnum_t addr, IOItemCount offset, ppnum_t page);
75 virtual void iovmInsert(ppnum_t addr, IOItemCount offset,
76 ppnum_t *pageList, IOItemCount pageCount);
77 virtual void iovmInsert(ppnum_t addr, IOItemCount offset,
78 upl_page_info_t *pageList, IOItemCount pageCount);
79
80 virtual addr64_t mapAddr(IOPhysicalAddress addr);
81 };
82
83 extern IOCopyMapper * gIOCopyMapper;