]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOLib.cpp
xnu-2782.20.48.tar.gz
[apple/xnu.git] / iokit / Kernel / IOLib.cpp
index 45504157aa469ccacd400731e9c7a611a54d7b3f..3714d1d4fb9018868dd6f59bd91733572a6ed4c8 100644 (file)
@@ -119,9 +119,15 @@ iopa_t gIOBMDPageAllocator;
 static queue_head_t gIOMallocContiguousEntries;
 static lck_mtx_t *  gIOMallocContiguousEntriesLock;
 
 static queue_head_t gIOMallocContiguousEntries;
 static lck_mtx_t *  gIOMallocContiguousEntriesLock;
 
-enum { kIOMaxPageableMaps = 16 };
-enum { kIOPageableMapSize = 96 * 1024 * 1024 };
+#if __x86_64__
+enum { kIOMaxPageableMaps    = 8 };
+enum { kIOPageableMapSize    = 512 * 1024 * 1024 };
+enum { kIOPageableMaxMapSize = 512 * 1024 * 1024 };
+#else
+enum { kIOMaxPageableMaps    = 16 };
+enum { kIOPageableMapSize    = 96 * 1024 * 1024 };
 enum { kIOPageableMaxMapSize = 96 * 1024 * 1024 };
 enum { kIOPageableMaxMapSize = 96 * 1024 * 1024 };
+#endif
 
 typedef struct {
     vm_map_t           map;
 
 typedef struct {
     vm_map_t           map;
@@ -138,6 +144,8 @@ static struct {
 
 static iopa_t gIOPageablePageAllocator;
 
 
 static iopa_t gIOPageablePageAllocator;
 
+uint32_t  gIOPageAllocChunkBytes;
+
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 void IOLibInit(void)
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 void IOLibInit(void)
@@ -169,6 +177,8 @@ void IOLibInit(void)
     gIOMallocContiguousEntriesLock     = lck_mtx_alloc_init(IOLockGroup, LCK_ATTR_NULL);
     queue_init( &gIOMallocContiguousEntries );
 
     gIOMallocContiguousEntriesLock     = lck_mtx_alloc_init(IOLockGroup, LCK_ATTR_NULL);
     queue_init( &gIOMallocContiguousEntries );
 
+    gIOPageAllocChunkBytes = PAGE_SIZE/64;
+    assert(sizeof(iopa_page_t) <= gIOPageAllocChunkBytes);
     iopa_init(&gIOBMDPageAllocator);
     iopa_init(&gIOPageablePageAllocator);
 
     iopa_init(&gIOBMDPageAllocator);
     iopa_init(&gIOPageablePageAllocator);
 
@@ -360,6 +370,7 @@ IOKernelFreePhysical(mach_vm_address_t address, mach_vm_size_t size)
 #endif
 }
 
 #endif
 }
 
+
 mach_vm_address_t
 IOKernelAllocateWithPhysicalRestrict(mach_vm_size_t size, mach_vm_address_t maxPhys, 
                                        mach_vm_size_t alignment, bool contiguous)
 mach_vm_address_t
 IOKernelAllocateWithPhysicalRestrict(mach_vm_size_t size, mach_vm_address_t maxPhys, 
                                        mach_vm_size_t alignment, bool contiguous)
@@ -687,7 +698,7 @@ void * IOMallocPageable(vm_size_t size, vm_size_t alignment)
 {
     void * addr;
 
 {
     void * addr;
 
-    if (size >= (page_size - 4*kIOPageAllocChunkBytes)) addr = IOMallocPageablePages(size, alignment);
+    if (size >= (page_size - 4*gIOPageAllocChunkBytes)) addr = IOMallocPageablePages(size, alignment);
     else                   addr = ((void * ) iopa_alloc(&gIOPageablePageAllocator, &IOMallocOnePageablePage, size, alignment));
 
     if (addr) {
     else                   addr = ((void * ) iopa_alloc(&gIOPageablePageAllocator, &IOMallocOnePageablePage, size, alignment));
 
     if (addr) {
@@ -707,7 +718,7 @@ void IOFreePageable(void * address, vm_size_t size)
 #endif
     IOStatisticsAlloc(kIOStatisticsFreePageable, size);
 
 #endif
     IOStatisticsAlloc(kIOStatisticsFreePageable, size);
 
-    if (size < (page_size - 4*kIOPageAllocChunkBytes))
+    if (size < (page_size - 4*gIOPageAllocChunkBytes))
     {
        address = (void *) iopa_free(&gIOPageablePageAllocator, (uintptr_t) address, size);
        size = page_size;
     {
        address = (void *) iopa_free(&gIOPageablePageAllocator, (uintptr_t) address, size);
        size = page_size;
@@ -717,14 +728,6 @@ void IOFreePageable(void * address, vm_size_t size)
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
-#if 0
-#undef assert
-#define assert(ex)  \
-       ((ex) ? (void)0 : Assert(__FILE__, __LINE__, # ex))
-#endif
-
-typedef char iopa_page_t_assert[(sizeof(iopa_page_t) <= kIOPageAllocChunkBytes) ? 1 : -1];
-
 extern "C" void 
 iopa_init(iopa_t * a)
 {
 extern "C" void 
 iopa_init(iopa_t * a)
 {
@@ -759,7 +762,7 @@ iopa_allocinpage(iopa_page_t * pa, uint32_t count, uint64_t align)
            remque(&pa->link);
            pa->link.next = 0;
        }
            remque(&pa->link);
            pa->link.next = 0;
        }
-       return (n * kIOPageAllocChunkBytes + trunc_page((uintptr_t) pa));
+       return (n * gIOPageAllocChunkBytes + trunc_page((uintptr_t) pa));
     }
 
     return (0);
     }
 
     return (0);
@@ -791,8 +794,8 @@ iopa_alloc(iopa_t * a, iopa_proc_t alloc, vm_size_t bytes, uint32_t balign)
     uint64_t      align;
 
     if (!bytes) bytes = 1;
     uint64_t      align;
 
     if (!bytes) bytes = 1;
-    count = (bytes + kIOPageAllocChunkBytes - 1) / kIOPageAllocChunkBytes;
-    align = align_masks[log2up((balign + kIOPageAllocChunkBytes - 1) / kIOPageAllocChunkBytes)];
+    count = (bytes + gIOPageAllocChunkBytes - 1) / gIOPageAllocChunkBytes;
+    align = align_masks[log2up((balign + gIOPageAllocChunkBytes - 1) / gIOPageAllocChunkBytes)];
 
     IOLockLock(a->lock);
     pa = (typeof(pa)) queue_first(&a->list);
 
     IOLockLock(a->lock);
     pa = (typeof(pa)) queue_first(&a->list);
@@ -813,7 +816,7 @@ iopa_alloc(iopa_t * a, iopa_proc_t alloc, vm_size_t bytes, uint32_t balign)
        addr = alloc(a);
        if (addr)
        {
        addr = alloc(a);
        if (addr)
        {
-           pa = (typeof(pa)) (addr + page_size - kIOPageAllocChunkBytes);
+           pa = (typeof(pa)) (addr + page_size - gIOPageAllocChunkBytes);
            pa->signature = kIOPageAllocSignature;
            pa->avail     = -2ULL;
 
            pa->signature = kIOPageAllocSignature;
            pa->avail     = -2ULL;
 
@@ -840,13 +843,13 @@ iopa_free(iopa_t * a, uintptr_t addr, vm_size_t bytes)
     if (!bytes) bytes = 1;
 
     chunk = (addr & page_mask);
     if (!bytes) bytes = 1;
 
     chunk = (addr & page_mask);
-    assert(0 == (chunk & (kIOPageAllocChunkBytes - 1)));
+    assert(0 == (chunk & (gIOPageAllocChunkBytes - 1)));
 
 
-    pa = (typeof(pa)) (addr | (page_size - kIOPageAllocChunkBytes));
+    pa = (typeof(pa)) (addr | (page_size - gIOPageAllocChunkBytes));
     assert(kIOPageAllocSignature == pa->signature);
 
     assert(kIOPageAllocSignature == pa->signature);
 
-    count = (bytes + kIOPageAllocChunkBytes - 1) / kIOPageAllocChunkBytes;
-    chunk /= kIOPageAllocChunkBytes;
+    count = (bytes + gIOPageAllocChunkBytes - 1) / gIOPageAllocChunkBytes;
+    chunk /= gIOPageAllocChunkBytes;
 
     IOLockLock(a->lock);
     if (!pa->avail)
 
     IOLockLock(a->lock);
     if (!pa->avail)