Index: sys/dev/drm2/ttm/ttm_page_alloc.c =================================================================== --- sys/dev/drm2/ttm/ttm_page_alloc.c +++ sys/dev/drm2/ttm/ttm_page_alloc.c @@ -155,6 +155,66 @@ panic("caching state %d\n", cstate); } +static vm_page_t +ttm_vm_page_alloc_dma32(int req, vm_memattr_t memattr) +{ + vm_page_t p; + int tries; + + for (tries = 0; ; tries++) { + p = vm_page_alloc_contig(NULL, 0, req, 1, 0, 0xffffffff, + PAGE_SIZE, 0, memattr); + if (p != NULL || tries > 2) + return (p); + + /* + * Before growing the cache see if this is just a normal + * memory shortage. + */ + VM_WAIT; + vm_pageout_grow_cache(tries, 0, 0xffffffff); + } +} + +static vm_page_t +ttm_vm_page_alloc_any(int req, vm_memattr_t memattr) +{ + vm_page_t p; + + while (1) { + p = vm_page_alloc(NULL, 0, req); + if (p != NULL) + break; + VM_WAIT; + } + pmap_page_set_memattr(p, memattr); + return (p); +} + +static vm_page_t +ttm_vm_page_alloc(int flags, enum ttm_caching_state cstate) +{ + vm_page_t p; + vm_memattr_t memattr; + int req; + + memattr = ttm_caching_state_to_vm(cstate); + req = VM_ALLOC_NORMAL | VM_ALLOC_WIRED | VM_ALLOC_NOOBJ; + if ((flags & TTM_PAGE_FLAG_ZERO_ALLOC) != 0) + req |= VM_ALLOC_ZERO; + + if ((flags & TTM_PAGE_FLAG_DMA32) != 0) + p = ttm_vm_page_alloc_dma32(req, memattr); + else + p = ttm_vm_page_alloc_any(req, memattr); + + if (p != NULL) { + p->oflags &= ~VPO_UNMANAGED; + p->flags |= PG_FICTITIOUS; + } + return (p); +} + static void ttm_pool_kobj_release(struct ttm_pool_manager *m) { @@ -461,14 +521,6 @@ } } -static vm_paddr_t -ttm_alloc_high_bound(int ttm_alloc_flags) -{ - - return ((ttm_alloc_flags & TTM_PAGE_FLAG_DMA32) ? 0xffffffff : - VM_MAX_ADDRESS); -} - /** * Allocate new pages with correct caching. * @@ -481,32 +533,17 @@ vm_page_t *caching_array; vm_page_t p; int r = 0; - unsigned i, cpages, aflags; + unsigned i, cpages; unsigned max_cpages = min(count, (unsigned)(PAGE_SIZE/sizeof(vm_page_t))); - int tries; - aflags = VM_ALLOC_NORMAL | VM_ALLOC_WIRED | VM_ALLOC_NOOBJ | - ((ttm_alloc_flags & TTM_PAGE_FLAG_ZERO_ALLOC) != 0 ? - VM_ALLOC_ZERO : 0); - /* allocate array for page caching change */ caching_array = malloc(max_cpages * sizeof(vm_page_t), M_TEMP, M_WAITOK | M_ZERO); for (i = 0, cpages = 0; i < count; ++i) { - tries = 0; -retry: - p = vm_page_alloc_contig(NULL, 0, aflags, 1, 0, - ttm_alloc_high_bound(ttm_alloc_flags), - PAGE_SIZE, 0, ttm_caching_state_to_vm(cstate)); + p = ttm_vm_page_alloc(ttm_alloc_flags, cstate); if (!p) { - if (tries < 3) { - vm_pageout_grow_cache(tries, 0, - ttm_alloc_high_bound(ttm_alloc_flags)); - tries++; - goto retry; - } printf("[TTM] Unable to get page %u\n", i); /* store already allocated pages in the pool after @@ -522,8 +559,6 @@ r = -ENOMEM; goto out; } - p->oflags &= ~VPO_UNMANAGED; - p->flags |= PG_FICTITIOUS; #ifdef CONFIG_HIGHMEM /* KIB: nop */ /* gfp flags of highmem page should never be dma32 so we @@ -705,34 +740,18 @@ struct ttm_page_pool *pool = ttm_get_pool(flags, cstate); struct pglist plist; vm_page_t p = NULL; - int gfp_flags, aflags; + int gfp_flags; unsigned count; int r; - int tries; - - aflags = VM_ALLOC_NORMAL | VM_ALLOC_NOOBJ | VM_ALLOC_WIRED | - ((flags & TTM_PAGE_FLAG_ZERO_ALLOC) != 0 ? VM_ALLOC_ZERO : 0); /* No pool for cached pages */ if (pool == NULL) { for (r = 0; r < npages; ++r) { - tries = 0; -retry: - p = vm_page_alloc_contig(NULL, 0, aflags, 1, 0, - ttm_alloc_high_bound(flags), PAGE_SIZE, - 0, ttm_caching_state_to_vm(cstate)); + p = ttm_vm_page_alloc(flags, cstate); if (!p) { - if (tries < 3) { - vm_pageout_grow_cache(tries, 0, - ttm_alloc_high_bound(flags)); - tries++; - goto retry; - } printf("[TTM] Unable to allocate page\n"); return -ENOMEM; } - p->oflags &= ~VPO_UNMANAGED; - p->flags |= PG_FICTITIOUS; pages[r] = p; } return 0;