@@ -223,7 +223,7 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)
223223 bo -> bdev -> funcs -> delete_mem_notify (bo );
224224
225225 ttm_bo_tt_destroy (bo );
226- ttm_resource_free (bo , bo -> resource );
226+ ttm_resource_free (bo , & bo -> resource );
227227}
228228
229229static int ttm_bo_individualize_resv (struct ttm_buffer_object * bo )
@@ -489,7 +489,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
489489 struct ttm_operation_ctx * ctx )
490490{
491491 struct ttm_device * bdev = bo -> bdev ;
492- struct ttm_resource evict_mem ;
492+ struct ttm_resource * evict_mem ;
493493 struct ttm_placement placement ;
494494 struct ttm_place hop ;
495495 int ret = 0 ;
@@ -519,7 +519,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
519519 goto out ;
520520 }
521521
522- ret = ttm_bo_handle_move_mem (bo , & evict_mem , true, ctx , & hop );
522+ ret = ttm_bo_handle_move_mem (bo , evict_mem , true, ctx , & hop );
523523 if (unlikely (ret )) {
524524 WARN (ret == - EMULTIHOP , "Unexpected multihop in eviction - likely driver bug\n" );
525525 if (ret != - ERESTARTSYS )
@@ -728,14 +728,15 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo,
728728 */
729729static int ttm_bo_mem_force_space (struct ttm_buffer_object * bo ,
730730 const struct ttm_place * place ,
731- struct ttm_resource * mem ,
731+ struct ttm_resource * * mem ,
732732 struct ttm_operation_ctx * ctx )
733733{
734734 struct ttm_device * bdev = bo -> bdev ;
735- struct ttm_resource_manager * man = ttm_manager_type ( bdev , mem -> mem_type ) ;
735+ struct ttm_resource_manager * man ;
736736 struct ww_acquire_ctx * ticket ;
737737 int ret ;
738738
739+ man = ttm_manager_type (bdev , (* mem )-> mem_type );
739740 ticket = dma_resv_locking_ctx (bo -> base .resv );
740741 do {
741742 ret = ttm_resource_alloc (bo , place , mem );
@@ -749,37 +750,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
749750 return ret ;
750751 } while (1 );
751752
752- return ttm_bo_add_move_fence (bo , man , mem , ctx -> no_wait_gpu );
753- }
754-
755- /**
756- * ttm_bo_mem_placement - check if placement is compatible
757- * @bo: BO to find memory for
758- * @place: where to search
759- * @mem: the memory object to fill in
760- *
761- * Check if placement is compatible and fill in mem structure.
762- * Returns -EBUSY if placement won't work or negative error code.
763- * 0 when placement can be used.
764- */
765- static int ttm_bo_mem_placement (struct ttm_buffer_object * bo ,
766- const struct ttm_place * place ,
767- struct ttm_resource * mem )
768- {
769- struct ttm_device * bdev = bo -> bdev ;
770- struct ttm_resource_manager * man ;
771-
772- man = ttm_manager_type (bdev , place -> mem_type );
773- if (!man || !ttm_resource_manager_used (man ))
774- return - EBUSY ;
775-
776- mem -> mem_type = place -> mem_type ;
777- mem -> placement = place -> flags ;
778-
779- spin_lock (& bo -> bdev -> lru_lock );
780- ttm_bo_move_to_lru_tail (bo , mem , NULL );
781- spin_unlock (& bo -> bdev -> lru_lock );
782- return 0 ;
753+ return ttm_bo_add_move_fence (bo , man , * mem , ctx -> no_wait_gpu );
783754}
784755
785756/*
@@ -792,7 +763,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
792763 */
793764int ttm_bo_mem_space (struct ttm_buffer_object * bo ,
794765 struct ttm_placement * placement ,
795- struct ttm_resource * mem ,
766+ struct ttm_resource * * mem ,
796767 struct ttm_operation_ctx * ctx )
797768{
798769 struct ttm_device * bdev = bo -> bdev ;
@@ -807,8 +778,8 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
807778 const struct ttm_place * place = & placement -> placement [i ];
808779 struct ttm_resource_manager * man ;
809780
810- ret = ttm_bo_mem_placement ( bo , place , mem );
811- if (ret )
781+ man = ttm_manager_type ( bdev , place -> mem_type );
782+ if (! man || ! ttm_resource_manager_used ( man ) )
812783 continue ;
813784
814785 type_found = true;
@@ -818,8 +789,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
818789 if (unlikely (ret ))
819790 goto error ;
820791
821- man = ttm_manager_type (bdev , mem -> mem_type );
822- ret = ttm_bo_add_move_fence (bo , man , mem , ctx -> no_wait_gpu );
792+ ret = ttm_bo_add_move_fence (bo , man , * mem , ctx -> no_wait_gpu );
823793 if (unlikely (ret )) {
824794 ttm_resource_free (bo , mem );
825795 if (ret == - EBUSY )
@@ -832,9 +802,10 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
832802
833803 for (i = 0 ; i < placement -> num_busy_placement ; ++ i ) {
834804 const struct ttm_place * place = & placement -> busy_placement [i ];
805+ struct ttm_resource_manager * man ;
835806
836- ret = ttm_bo_mem_placement ( bo , place , mem );
837- if (ret )
807+ man = ttm_manager_type ( bdev , place -> mem_type );
808+ if (! man || ! ttm_resource_manager_used ( man ) )
838809 continue ;
839810
840811 type_found = true;
@@ -861,12 +832,12 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
861832EXPORT_SYMBOL (ttm_bo_mem_space );
862833
863834static int ttm_bo_bounce_temp_buffer (struct ttm_buffer_object * bo ,
864- struct ttm_resource * mem ,
835+ struct ttm_resource * * mem ,
865836 struct ttm_operation_ctx * ctx ,
866837 struct ttm_place * hop )
867838{
868839 struct ttm_placement hop_placement ;
869- struct ttm_resource hop_mem ;
840+ struct ttm_resource * hop_mem ;
870841 int ret ;
871842
872843 hop_placement .num_placement = hop_placement .num_busy_placement = 1 ;
@@ -877,7 +848,7 @@ static int ttm_bo_bounce_temp_buffer(struct ttm_buffer_object *bo,
877848 if (ret )
878849 return ret ;
879850 /* move to the bounce domain */
880- ret = ttm_bo_handle_move_mem (bo , & hop_mem , false, ctx , NULL );
851+ ret = ttm_bo_handle_move_mem (bo , hop_mem , false, ctx , NULL );
881852 if (ret ) {
882853 ttm_resource_free (bo , & hop_mem );
883854 return ret ;
@@ -889,14 +860,12 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
889860 struct ttm_placement * placement ,
890861 struct ttm_operation_ctx * ctx )
891862{
863+ struct ttm_resource * mem ;
892864 struct ttm_place hop ;
893- struct ttm_resource mem ;
894865 int ret ;
895866
896867 dma_resv_assert_held (bo -> base .resv );
897868
898- memset (& hop , 0 , sizeof (hop ));
899-
900869 /*
901870 * Determine where to move the buffer.
902871 *
@@ -910,7 +879,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
910879 if (ret )
911880 return ret ;
912881bounce :
913- ret = ttm_bo_handle_move_mem (bo , & mem , false, ctx , & hop );
882+ ret = ttm_bo_handle_move_mem (bo , mem , false, ctx , & hop );
914883 if (ret == - EMULTIHOP ) {
915884 ret = ttm_bo_bounce_temp_buffer (bo , & mem , ctx , & hop );
916885 if (ret )
@@ -1019,7 +988,7 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
1019988{
1020989 static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
1021990 bool locked ;
1022- int ret = 0 ;
991+ int ret ;
1023992
1024993 bo -> destroy = destroy ? destroy : ttm_bo_default_destroy ;
1025994
@@ -1029,8 +998,6 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
1029998 bo -> bdev = bdev ;
1030999 bo -> type = type ;
10311000 bo -> page_alignment = page_alignment ;
1032- bo -> resource = & bo -> _mem ;
1033- ttm_resource_alloc (bo , & sys_mem , bo -> resource );
10341001 bo -> moving = NULL ;
10351002 bo -> pin_count = 0 ;
10361003 bo -> sg = sg ;
@@ -1042,6 +1009,12 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
10421009 }
10431010 atomic_inc (& ttm_glob .bo_count );
10441011
1012+ ret = ttm_resource_alloc (bo , & sys_mem , & bo -> resource );
1013+ if (unlikely (ret )) {
1014+ ttm_bo_put (bo );
1015+ return ret ;
1016+ }
1017+
10451018 /*
10461019 * For ttm_bo_type_device buffers, allocate
10471020 * address space from the device.
@@ -1170,7 +1143,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
11701143 */
11711144 if (bo -> resource -> mem_type != TTM_PL_SYSTEM ) {
11721145 struct ttm_operation_ctx ctx = { false, false };
1173- struct ttm_resource evict_mem ;
1146+ struct ttm_resource * evict_mem ;
11741147 struct ttm_place place , hop ;
11751148
11761149 memset (& place , 0 , sizeof (place ));
@@ -1182,7 +1155,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
11821155 if (unlikely (ret ))
11831156 goto out ;
11841157
1185- ret = ttm_bo_handle_move_mem (bo , & evict_mem , true, & ctx , & hop );
1158+ ret = ttm_bo_handle_move_mem (bo , evict_mem , true, & ctx , & hop );
11861159 if (unlikely (ret != 0 )) {
11871160 WARN (ret == - EMULTIHOP , "Unexpected multihop in swaput - likely driver bug.\n" );
11881161 goto out ;
0 commit comments