FreeBSD/sys/dev/drm2/ttm/ttm_page_alloc.c
/**
 * Allocate new pages with correct caching.
 *
 * This function is reentrant if caller updates count depending on number of
 * pages returned in pages array.
 */
Allocate new pages with correct caching.
This function is reentrant if caller updates count depending on number of
pages returned in pages array.
Allocate new pages with correct caching . This function is reentrant if caller updates count depending on number of pages returned in pages array .
static int ttm_alloc_new_pages(struct pglist *pages, int ttm_alloc_flags,
		int ttm_flags, enum ttm_caching_state cstate, unsigned count)
{
	vm_page_t *caching_array;
	vm_page_t p;
	int r = 0;
	unsigned i, cpages;
	unsigned max_cpages = min(count,
			(unsigned)(PAGE_SIZE/sizeof(vm_page_t)));
	caching_array = malloc(max_cpages * sizeof(vm_page_t), M_TEMP,
	    M_WAITOK | M_ZERO);
	for (i = 0, cpages = 0; i < count; ++i) {
		p = ttm_vm_page_alloc(ttm_alloc_flags, cstate);
		if (!p) {
			printf("[TTM] Unable to get page %u\n", i);
			if (cpages) {
				r = ttm_set_pages_caching(caching_array,
							  cstate, cpages);
				if (r)
					ttm_handle_caching_state_failure(pages,
						ttm_flags, cstate,
						caching_array, cpages);
			}
			r = -ENOMEM;
			goto out;
		}
#ifdef CONFIG_HIGHMEM 
		if (!PageHighMem(p))
#endif
		{
			caching_array[cpages++] = p;
			if (cpages == max_cpages) {
				r = ttm_set_pages_caching(caching_array,
						cstate, cpages);
				if (r) {
					ttm_handle_caching_state_failure(pages,
						ttm_flags, cstate,
						caching_array, cpages);
					goto out;
				}
				cpages = 0;
			}
		}
		TAILQ_INSERT_HEAD(pages, p, plinks.q);
	}
	if (cpages) {
		r = ttm_set_pages_caching(caching_array, cstate, cpages);
		if (r)
			ttm_handle_caching_state_failure(pages,
					ttm_flags, cstate,
					caching_array, cpages);
	}
out:
	free(caching_array, M_TEMP);
	return r;
}
static int ttm_alloc_new_pages ( struct pglist * pages , int ttm_alloc_flags , int ttm_flags , enum ttm_caching_state cstate , unsigned count ) { vm_page_t * caching_array ; vm_page_t p ; int r = 0 ; unsigned i , cpages ; unsigned max_cpages = min ( count , ( unsigned ) ( PAGE_SIZE / sizeof ( vm_page_t ) ) ) ; caching_array = malloc ( max_cpages * sizeof ( vm_page_t ) , M_TEMP , M_WAITOK | M_ZERO ) ; for ( i = 0 , cpages = 0 ; i < count ; ++ i ) { p = ttm_vm_page_alloc ( ttm_alloc_flags , cstate ) ; if ( ! p ) { printf ( " \n " , i ) ; if ( cpages ) { r = ttm_set_pages_caching ( caching_array , cstate , cpages ) ; if ( r ) ttm_handle_caching_state_failure ( pages , ttm_flags , cstate , caching_array , cpages ) ; } r = - ENOMEM ; goto out ; } #ifdef CONFIG_HIGHMEM if ( ! PageHighMem ( p ) ) #endif { caching_array [ cpages ++ ] = p ; if ( cpages == max_cpages ) { r = ttm_set_pages_caching ( caching_array , cstate , cpages ) ; if ( r ) { ttm_handle_caching_state_failure ( pages , ttm_flags , cstate , caching_array , cpages ) ; goto out ; } cpages = 0 ; } } TAILQ_INSERT_HEAD ( pages , p , plinks . q ) ; } if ( cpages ) { r = ttm_set_pages_caching ( caching_array , cstate , cpages ) ; if ( r ) ttm_handle_caching_state_failure ( pages , ttm_flags , cstate , caching_array , cpages ) ; } out : free ( caching_array , M_TEMP ) ; return r ; }
Allocate new pages with correct caching.
Allocate new pages with correct caching .
/* allocate array for page caching change */ /* store already allocated pages in the pool after
			 * setting the caching state */ /* KIB: nop */ /* gfp flags of highmem page should never be dma32 so we
		 * we should be fine in such case
		 */