Merge tag 'amd-drm-next-6.5-2023-06-09' of https://gitlab.freedesktop.org/agd5f/linux...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / ttm / ttm_pool.c
index 4db3982057be8d18fc20a423c91d4ab708bd7514..cddb9151d20f4465bfc269e62c3072ad51a990c0 100644 (file)
@@ -93,7 +93,7 @@ static struct page *ttm_pool_alloc_page(struct ttm_pool *pool, gfp_t gfp_flags,
                        __GFP_KSWAPD_RECLAIM;
 
        if (!pool->use_dma_alloc) {
-               p = alloc_pages(gfp_flags, order);
+               p = alloc_pages_node(pool->nid, gfp_flags, order);
                if (p)
                        p->private = order;
                return p;
@@ -287,7 +287,7 @@ static struct ttm_pool_type *ttm_pool_select_type(struct ttm_pool *pool,
                                                  enum ttm_caching caching,
                                                  unsigned int order)
 {
-       if (pool->use_dma_alloc)
+       if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE)
                return &pool->caching[caching].orders[order];
 
 #ifdef CONFIG_X86
@@ -545,29 +545,32 @@ EXPORT_SYMBOL(ttm_pool_free);
  *
  * @pool: the pool to initialize
  * @dev: device for DMA allocations and mappings
+ * @nid: NUMA node to use for allocations
  * @use_dma_alloc: true if coherent DMA alloc should be used
  * @use_dma32: true if GFP_DMA32 should be used
  *
  * Initialize the pool and its pool types.
  */
 void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
-                  bool use_dma_alloc, bool use_dma32)
+                  int nid, bool use_dma_alloc, bool use_dma32)
 {
        unsigned int i, j;
 
        WARN_ON(!dev && use_dma_alloc);
 
        pool->dev = dev;
+       pool->nid = nid;
        pool->use_dma_alloc = use_dma_alloc;
        pool->use_dma32 = use_dma32;
 
-       if (use_dma_alloc) {
+       if (use_dma_alloc || nid != NUMA_NO_NODE) {
                for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i)
                        for (j = 0; j <= MAX_ORDER; ++j)
                                ttm_pool_type_init(&pool->caching[i].orders[j],
                                                   pool, i, j);
        }
 }
+EXPORT_SYMBOL(ttm_pool_init);
 
 /**
  * ttm_pool_fini - Cleanup a pool
@@ -581,7 +584,7 @@ void ttm_pool_fini(struct ttm_pool *pool)
 {
        unsigned int i, j;
 
-       if (pool->use_dma_alloc) {
+       if (pool->use_dma_alloc || pool->nid != NUMA_NO_NODE) {
                for (i = 0; i < TTM_NUM_CACHING_TYPES; ++i)
                        for (j = 0; j <= MAX_ORDER; ++j)
                                ttm_pool_type_fini(&pool->caching[i].orders[j]);
@@ -592,6 +595,7 @@ void ttm_pool_fini(struct ttm_pool *pool)
         */
        synchronize_shrinkers();
 }
+EXPORT_SYMBOL(ttm_pool_fini);
 
 /* As long as pages are available make sure to release at least one */
 static unsigned long ttm_pool_shrinker_scan(struct shrinker *shrink,