X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/22ba694c5857e62b5a553b1505dcf2e509177f28..04b8595b18b1b41ac7a206e4b3d51a635f8413d7:/iokit/Kernel/IOLib.cpp?ds=inline diff --git a/iokit/Kernel/IOLib.cpp b/iokit/Kernel/IOLib.cpp index 1c39602d7..3714d1d4f 100644 --- a/iokit/Kernel/IOLib.cpp +++ b/iokit/Kernel/IOLib.cpp @@ -144,6 +144,8 @@ static struct { static iopa_t gIOPageablePageAllocator; +uint32_t gIOPageAllocChunkBytes; + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void IOLibInit(void) @@ -175,6 +177,8 @@ void IOLibInit(void) 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); @@ -366,6 +370,7 @@ IOKernelFreePhysical(mach_vm_address_t address, mach_vm_size_t size) #endif } + mach_vm_address_t IOKernelAllocateWithPhysicalRestrict(mach_vm_size_t size, mach_vm_address_t maxPhys, mach_vm_size_t alignment, bool contiguous) @@ -693,7 +698,7 @@ void * IOMallocPageable(vm_size_t size, vm_size_t alignment) { 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) { @@ -713,7 +718,7 @@ void IOFreePageable(void * address, vm_size_t 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; @@ -723,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) { @@ -765,7 +762,7 @@ iopa_allocinpage(iopa_page_t * pa, uint32_t count, uint64_t align) 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); @@ -797,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; - 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); @@ -819,7 +816,7 @@ iopa_alloc(iopa_t * a, iopa_proc_t alloc, vm_size_t bytes, uint32_t balign) 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; @@ -846,13 +843,13 @@ iopa_free(iopa_t * a, uintptr_t addr, vm_size_t bytes) 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); - count = (bytes + kIOPageAllocChunkBytes - 1) / kIOPageAllocChunkBytes; - chunk /= kIOPageAllocChunkBytes; + count = (bytes + gIOPageAllocChunkBytes - 1) / gIOPageAllocChunkBytes; + chunk /= gIOPageAllocChunkBytes; IOLockLock(a->lock); if (!pa->avail)