4747
4848#include "ttm_module.h"
4949
50- #define TTM_MAX_ORDER (PMD_SHIFT - PAGE_SHIFT)
51- #define __TTM_DIM_ORDER (TTM_MAX_ORDER + 1)
52- /* Some architectures have a weird PMD_SHIFT */
53- #define TTM_DIM_ORDER (__TTM_DIM_ORDER <= MAX_ORDER ? __TTM_DIM_ORDER : MAX_ORDER)
54-
5550/**
5651 * struct ttm_pool_dma - Helper object for coherent DMA mappings
5752 *
@@ -70,11 +65,11 @@ module_param(page_pool_size, ulong, 0644);
7065
7166static atomic_long_t allocated_pages ;
7267
73- static struct ttm_pool_type global_write_combined [TTM_DIM_ORDER ];
74- static struct ttm_pool_type global_uncached [TTM_DIM_ORDER ];
68+ static struct ttm_pool_type global_write_combined [MAX_ORDER ];
69+ static struct ttm_pool_type global_uncached [MAX_ORDER ];
7570
76- static struct ttm_pool_type global_dma32_write_combined [TTM_DIM_ORDER ];
77- static struct ttm_pool_type global_dma32_uncached [TTM_DIM_ORDER ];
71+ static struct ttm_pool_type global_dma32_write_combined [MAX_ORDER ];
72+ static struct ttm_pool_type global_dma32_uncached [MAX_ORDER ];
7873
7974static spinlock_t shrinker_lock ;
8075static struct list_head shrinker_list ;
@@ -449,7 +444,7 @@ int ttm_pool_alloc(struct ttm_pool *pool, struct ttm_tt *tt,
449444 else
450445 gfp_flags |= GFP_HIGHUSER ;
451446
452- for (order = min_t (unsigned int , TTM_MAX_ORDER , __fls (num_pages ));
447+ for (order = min_t (unsigned int , MAX_ORDER - 1 , __fls (num_pages ));
453448 num_pages ;
454449 order = min_t (unsigned int , order , __fls (num_pages ))) {
455450 struct ttm_pool_type * pt ;
@@ -568,7 +563,7 @@ void ttm_pool_init(struct ttm_pool *pool, struct device *dev,
568563
569564 if (use_dma_alloc ) {
570565 for (i = 0 ; i < TTM_NUM_CACHING_TYPES ; ++ i )
571- for (j = 0 ; j < TTM_DIM_ORDER ; ++ j )
566+ for (j = 0 ; j < MAX_ORDER ; ++ j )
572567 ttm_pool_type_init (& pool -> caching [i ].orders [j ],
573568 pool , i , j );
574569 }
@@ -588,7 +583,7 @@ void ttm_pool_fini(struct ttm_pool *pool)
588583
589584 if (pool -> use_dma_alloc ) {
590585 for (i = 0 ; i < TTM_NUM_CACHING_TYPES ; ++ i )
591- for (j = 0 ; j < TTM_DIM_ORDER ; ++ j )
586+ for (j = 0 ; j < MAX_ORDER ; ++ j )
592587 ttm_pool_type_fini (& pool -> caching [i ].orders [j ]);
593588 }
594589
@@ -642,7 +637,7 @@ static void ttm_pool_debugfs_header(struct seq_file *m)
642637 unsigned int i ;
643638
644639 seq_puts (m , "\t " );
645- for (i = 0 ; i < TTM_DIM_ORDER ; ++ i )
640+ for (i = 0 ; i < MAX_ORDER ; ++ i )
646641 seq_printf (m , " ---%2u---" , i );
647642 seq_puts (m , "\n" );
648643}
@@ -653,7 +648,7 @@ static void ttm_pool_debugfs_orders(struct ttm_pool_type *pt,
653648{
654649 unsigned int i ;
655650
656- for (i = 0 ; i < TTM_DIM_ORDER ; ++ i )
651+ for (i = 0 ; i < MAX_ORDER ; ++ i )
657652 seq_printf (m , " %8u" , ttm_pool_type_count (& pt [i ]));
658653 seq_puts (m , "\n" );
659654}
@@ -756,16 +751,13 @@ int ttm_pool_mgr_init(unsigned long num_pages)
756751{
757752 unsigned int i ;
758753
759- BUILD_BUG_ON (TTM_DIM_ORDER > MAX_ORDER );
760- BUILD_BUG_ON (TTM_DIM_ORDER < 1 );
761-
762754 if (!page_pool_size )
763755 page_pool_size = num_pages ;
764756
765757 spin_lock_init (& shrinker_lock );
766758 INIT_LIST_HEAD (& shrinker_list );
767759
768- for (i = 0 ; i < TTM_DIM_ORDER ; ++ i ) {
760+ for (i = 0 ; i < MAX_ORDER ; ++ i ) {
769761 ttm_pool_type_init (& global_write_combined [i ], NULL ,
770762 ttm_write_combined , i );
771763 ttm_pool_type_init (& global_uncached [i ], NULL , ttm_uncached , i );
@@ -798,7 +790,7 @@ void ttm_pool_mgr_fini(void)
798790{
799791 unsigned int i ;
800792
801- for (i = 0 ; i < TTM_DIM_ORDER ; ++ i ) {
793+ for (i = 0 ; i < MAX_ORDER ; ++ i ) {
802794 ttm_pool_type_fini (& global_write_combined [i ]);
803795 ttm_pool_type_fini (& global_uncached [i ]);
804796
0 commit comments