@@ -312,7 +312,6 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
312
312
if (bdev -> driver -> move_notify )
313
313
bdev -> driver -> move_notify (bo , evict , mem );
314
314
bo -> mem = * mem ;
315
- mem -> mm_node = NULL ;
316
315
goto moved ;
317
316
}
318
317
}
@@ -616,7 +615,6 @@ static void ttm_bo_release(struct kref *kref)
616
615
ttm_bo_cleanup_memtype_use (bo );
617
616
dma_resv_unlock (bo -> base .resv );
618
617
619
- BUG_ON (bo -> mem .mm_node != NULL );
620
618
atomic_dec (& ttm_bo_glob .bo_count );
621
619
dma_fence_put (bo -> moving );
622
620
if (!ttm_bo_uses_embedded_gem_object (bo ))
@@ -843,12 +841,29 @@ static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
843
841
return ret ;
844
842
}
845
843
844
+ static int ttm_bo_mem_get (struct ttm_buffer_object * bo ,
845
+ const struct ttm_place * place ,
846
+ struct ttm_mem_reg * mem )
847
+ {
848
+ struct ttm_mem_type_manager * man = & bo -> bdev -> man [mem -> mem_type ];
849
+
850
+ mem -> mm_node = NULL ;
851
+ if (!man -> func || !man -> func -> get_node )
852
+ return 0 ;
853
+
854
+ return man -> func -> get_node (man , bo , place , mem );
855
+ }
856
+
846
857
void ttm_bo_mem_put (struct ttm_buffer_object * bo , struct ttm_mem_reg * mem )
847
858
{
848
859
struct ttm_mem_type_manager * man = & bo -> bdev -> man [mem -> mem_type ];
849
860
850
- if (mem -> mm_node )
851
- (* man -> func -> put_node )(man , mem );
861
+ if (!man -> func || !man -> func -> put_node )
862
+ return ;
863
+
864
+ man -> func -> put_node (man , mem );
865
+ mem -> mm_node = NULL ;
866
+ mem -> mem_type = TTM_PL_SYSTEM ;
852
867
}
853
868
EXPORT_SYMBOL (ttm_bo_mem_put );
854
869
@@ -902,7 +917,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
902
917
903
918
ticket = dma_resv_locking_ctx (bo -> base .resv );
904
919
do {
905
- ret = ( * man -> func -> get_node )( man , bo , place , mem );
920
+ ret = ttm_bo_mem_get ( bo , place , mem );
906
921
if (likely (!ret ))
907
922
break ;
908
923
if (unlikely (ret != - ENOSPC ))
@@ -1032,7 +1047,6 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
1032
1047
if (unlikely (ret ))
1033
1048
return ret ;
1034
1049
1035
- mem -> mm_node = NULL ;
1036
1050
for (i = 0 ; i < placement -> num_placement ; ++ i ) {
1037
1051
const struct ttm_place * place = & placement -> placement [i ];
1038
1052
struct ttm_mem_type_manager * man ;
@@ -1044,20 +1058,16 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
1044
1058
goto error ;
1045
1059
1046
1060
type_found = true;
1047
- mem -> mm_node = NULL ;
1048
- if (mem -> mem_type == TTM_PL_SYSTEM )
1049
- return 0 ;
1050
-
1051
- man = & bdev -> man [mem -> mem_type ];
1052
- ret = (* man -> func -> get_node )(man , bo , place , mem );
1061
+ ret = ttm_bo_mem_get (bo , place , mem );
1053
1062
if (ret == - ENOSPC )
1054
1063
continue ;
1055
1064
if (unlikely (ret ))
1056
1065
goto error ;
1057
1066
1067
+ man = & bdev -> man [mem -> mem_type ];
1058
1068
ret = ttm_bo_add_move_fence (bo , man , mem , ctx -> no_wait_gpu );
1059
1069
if (unlikely (ret )) {
1060
- ( * man -> func -> put_node )( man , mem );
1070
+ ttm_bo_mem_put ( bo , mem );
1061
1071
if (ret == - EBUSY )
1062
1072
continue ;
1063
1073
@@ -1076,12 +1086,8 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
1076
1086
goto error ;
1077
1087
1078
1088
type_found = true;
1079
- mem -> mm_node = NULL ;
1080
- if (mem -> mem_type == TTM_PL_SYSTEM )
1081
- return 0 ;
1082
-
1083
1089
ret = ttm_bo_mem_force_space (bo , place , mem , ctx );
1084
- if (ret == 0 && mem -> mm_node )
1090
+ if (likely (! ret ) )
1085
1091
return 0 ;
1086
1092
1087
1093
if (ret && ret != - EBUSY )
@@ -1129,7 +1135,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
1129
1135
goto out_unlock ;
1130
1136
ret = ttm_bo_handle_move_mem (bo , & mem , false, ctx );
1131
1137
out_unlock :
1132
- if (ret && mem . mm_node )
1138
+ if (ret )
1133
1139
ttm_bo_mem_put (bo , & mem );
1134
1140
return ret ;
1135
1141
}
@@ -1144,7 +1150,7 @@ static bool ttm_bo_places_compat(const struct ttm_place *places,
1144
1150
for (i = 0 ; i < num_placement ; i ++ ) {
1145
1151
const struct ttm_place * heap = & places [i ];
1146
1152
1147
- if (mem -> mm_node && (mem -> start < heap -> fpfn ||
1153
+ if ((mem -> start < heap -> fpfn ||
1148
1154
(heap -> lpfn != 0 && (mem -> start + mem -> num_pages ) > heap -> lpfn )))
1149
1155
continue ;
1150
1156
0 commit comments