static iopa_t gIOPageablePageAllocator;
+uint32_t gIOPageAllocChunkBytes;
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
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);
#endif
}
+
mach_vm_address_t
IOKernelAllocateWithPhysicalRestrict(mach_vm_size_t size, mach_vm_address_t maxPhys,
mach_vm_size_t alignment, bool contiguous)
{
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) {
#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;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-#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)
{
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);
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);
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;
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)