FreeBSD/sys/dev/drm2/ttm/ttm_page_alloc.c
/*
 * On success pages list will hold count number of correctly
 * cached pages.
 */
On success pages list will hold count number of correctly
cached pages.
On success pages list will hold count number of correctly cached pages .
static int ttm_get_pages(vm_page_t *pages, unsigned npages, int flags,
			 enum ttm_caching_state cstate)
{
	struct ttm_page_pool *pool = ttm_get_pool(flags, cstate);
	struct pglist plist;
	vm_page_t p = NULL;
	int gfp_flags;
	unsigned count;
	int r;
	if (pool == NULL) {
		for (r = 0; r < npages; ++r) {
			p = ttm_vm_page_alloc(flags, cstate);
			if (!p) {
				printf("[TTM] Unable to allocate page\n");
				return -ENOMEM;
			}
			pages[r] = p;
		}
		return 0;
	}
	gfp_flags = flags | pool->ttm_page_alloc_flags;
	TAILQ_INIT(&plist);
	npages = ttm_page_pool_get_pages(pool, &plist, flags, cstate, npages);
	count = 0;
	TAILQ_FOREACH(p, &plist, plinks.q) {
		pages[count++] = p;
	}
	if (flags & TTM_PAGE_FLAG_ZERO_ALLOC) {
		TAILQ_FOREACH(p, &plist, plinks.q) {
			pmap_zero_page(p);
		}
	}
	if (npages > 0) {
		TAILQ_INIT(&plist);
		r = ttm_alloc_new_pages(&plist, gfp_flags, flags, cstate,
		    npages);
		TAILQ_FOREACH(p, &plist, plinks.q) {
			pages[count++] = p;
		}
		if (r) {
			printf("[TTM] Failed to allocate extra pages for large request\n");
			ttm_put_pages(pages, count, flags, cstate);
			return r;
		}
	}
	return 0;
}
static int ttm_get_pages ( vm_page_t * pages , unsigned npages , int flags , enum ttm_caching_state cstate ) { struct ttm_page_pool * pool = ttm_get_pool ( flags , cstate ) ; struct pglist plist ; vm_page_t p = NULL ; int gfp_flags ; unsigned count ; int r ; if ( pool == NULL ) { for ( r = 0 ; r < npages ; ++ r ) { p = ttm_vm_page_alloc ( flags , cstate ) ; if ( ! p ) { printf ( " \n " ) ; return - ENOMEM ; } pages [ r ] = p ; } return 0 ; } gfp_flags = flags | pool -> ttm_page_alloc_flags ; TAILQ_INIT ( & plist ) ; npages = ttm_page_pool_get_pages ( pool , & plist , flags , cstate , npages ) ; count = 0 ; TAILQ_FOREACH ( p , & plist , plinks . q ) { pages [ count ++ ] = p ; } if ( flags & TTM_PAGE_FLAG_ZERO_ALLOC ) { TAILQ_FOREACH ( p , & plist , plinks . q ) { pmap_zero_page ( p ) ; } } if ( npages > 0 ) { TAILQ_INIT ( & plist ) ; r = ttm_alloc_new_pages ( & plist , gfp_flags , flags , cstate , npages ) ; TAILQ_FOREACH ( p , & plist , plinks . q ) { pages [ count ++ ] = p ; } if ( r ) { printf ( " \n " ) ; ttm_put_pages ( pages , count , flags , cstate ) ; return r ; } } return 0 ; }
On success pages list will hold count number of correctly
 cached pages.
On success pages list will hold count number of correctly cached pages .
/* No pool for cached pages */ /* combine zero flag to pool flags */ /* First we take pages from the pool */ /* clear the pages coming from the pool if requested */ /* If pool didn't have enough pages allocate new one. */ /* ttm_alloc_new_pages doesn't reference pool so we can run
		 * multiple requests in parallel.
		 **/ /* If there is any pages in the list put them back to
			 * the pool. */