@@ -223,7 +223,7 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)
223
223
bo -> bdev -> funcs -> delete_mem_notify (bo );
224
224
225
225
ttm_bo_tt_destroy (bo );
226
- ttm_resource_free (bo , bo -> resource );
226
+ ttm_resource_free (bo , & bo -> resource );
227
227
}
228
228
229
229
static int ttm_bo_individualize_resv (struct ttm_buffer_object * bo )
@@ -489,7 +489,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
489
489
struct ttm_operation_ctx * ctx )
490
490
{
491
491
struct ttm_device * bdev = bo -> bdev ;
492
- struct ttm_resource evict_mem ;
492
+ struct ttm_resource * evict_mem ;
493
493
struct ttm_placement placement ;
494
494
struct ttm_place hop ;
495
495
int ret = 0 ;
@@ -519,7 +519,7 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
519
519
goto out ;
520
520
}
521
521
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 );
523
523
if (unlikely (ret )) {
524
524
WARN (ret == - EMULTIHOP , "Unexpected multihop in eviction - likely driver bug\n" );
525
525
if (ret != - ERESTARTSYS )
@@ -728,14 +728,15 @@ static int ttm_bo_add_move_fence(struct ttm_buffer_object *bo,
728
728
*/
729
729
static int ttm_bo_mem_force_space (struct ttm_buffer_object * bo ,
730
730
const struct ttm_place * place ,
731
- struct ttm_resource * mem ,
731
+ struct ttm_resource * * mem ,
732
732
struct ttm_operation_ctx * ctx )
733
733
{
734
734
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 ;
736
736
struct ww_acquire_ctx * ticket ;
737
737
int ret ;
738
738
739
+ man = ttm_manager_type (bdev , (* mem )-> mem_type );
739
740
ticket = dma_resv_locking_ctx (bo -> base .resv );
740
741
do {
741
742
ret = ttm_resource_alloc (bo , place , mem );
@@ -749,37 +750,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
749
750
return ret ;
750
751
} while (1 );
751
752
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 );
783
754
}
784
755
785
756
/*
@@ -792,7 +763,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
792
763
*/
793
764
int ttm_bo_mem_space (struct ttm_buffer_object * bo ,
794
765
struct ttm_placement * placement ,
795
- struct ttm_resource * mem ,
766
+ struct ttm_resource * * mem ,
796
767
struct ttm_operation_ctx * ctx )
797
768
{
798
769
struct ttm_device * bdev = bo -> bdev ;
@@ -807,8 +778,8 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
807
778
const struct ttm_place * place = & placement -> placement [i ];
808
779
struct ttm_resource_manager * man ;
809
780
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 ) )
812
783
continue ;
813
784
814
785
type_found = true;
@@ -818,8 +789,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
818
789
if (unlikely (ret ))
819
790
goto error ;
820
791
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 );
823
793
if (unlikely (ret )) {
824
794
ttm_resource_free (bo , mem );
825
795
if (ret == - EBUSY )
@@ -832,9 +802,10 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
832
802
833
803
for (i = 0 ; i < placement -> num_busy_placement ; ++ i ) {
834
804
const struct ttm_place * place = & placement -> busy_placement [i ];
805
+ struct ttm_resource_manager * man ;
835
806
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 ) )
838
809
continue ;
839
810
840
811
type_found = true;
@@ -861,12 +832,12 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
861
832
EXPORT_SYMBOL (ttm_bo_mem_space );
862
833
863
834
static int ttm_bo_bounce_temp_buffer (struct ttm_buffer_object * bo ,
864
- struct ttm_resource * mem ,
835
+ struct ttm_resource * * mem ,
865
836
struct ttm_operation_ctx * ctx ,
866
837
struct ttm_place * hop )
867
838
{
868
839
struct ttm_placement hop_placement ;
869
- struct ttm_resource hop_mem ;
840
+ struct ttm_resource * hop_mem ;
870
841
int ret ;
871
842
872
843
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,
877
848
if (ret )
878
849
return ret ;
879
850
/* 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 );
881
852
if (ret ) {
882
853
ttm_resource_free (bo , & hop_mem );
883
854
return ret ;
@@ -889,14 +860,12 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
889
860
struct ttm_placement * placement ,
890
861
struct ttm_operation_ctx * ctx )
891
862
{
863
+ struct ttm_resource * mem ;
892
864
struct ttm_place hop ;
893
- struct ttm_resource mem ;
894
865
int ret ;
895
866
896
867
dma_resv_assert_held (bo -> base .resv );
897
868
898
- memset (& hop , 0 , sizeof (hop ));
899
-
900
869
/*
901
870
* Determine where to move the buffer.
902
871
*
@@ -910,7 +879,7 @@ static int ttm_bo_move_buffer(struct ttm_buffer_object *bo,
910
879
if (ret )
911
880
return ret ;
912
881
bounce :
913
- ret = ttm_bo_handle_move_mem (bo , & mem , false, ctx , & hop );
882
+ ret = ttm_bo_handle_move_mem (bo , mem , false, ctx , & hop );
914
883
if (ret == - EMULTIHOP ) {
915
884
ret = ttm_bo_bounce_temp_buffer (bo , & mem , ctx , & hop );
916
885
if (ret )
@@ -1019,7 +988,7 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
1019
988
{
1020
989
static const struct ttm_place sys_mem = { .mem_type = TTM_PL_SYSTEM };
1021
990
bool locked ;
1022
- int ret = 0 ;
991
+ int ret ;
1023
992
1024
993
bo -> destroy = destroy ? destroy : ttm_bo_default_destroy ;
1025
994
@@ -1029,8 +998,6 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
1029
998
bo -> bdev = bdev ;
1030
999
bo -> type = type ;
1031
1000
bo -> page_alignment = page_alignment ;
1032
- bo -> resource = & bo -> _mem ;
1033
- ttm_resource_alloc (bo , & sys_mem , bo -> resource );
1034
1001
bo -> moving = NULL ;
1035
1002
bo -> pin_count = 0 ;
1036
1003
bo -> sg = sg ;
@@ -1042,6 +1009,12 @@ int ttm_bo_init_reserved(struct ttm_device *bdev,
1042
1009
}
1043
1010
atomic_inc (& ttm_glob .bo_count );
1044
1011
1012
+ ret = ttm_resource_alloc (bo , & sys_mem , & bo -> resource );
1013
+ if (unlikely (ret )) {
1014
+ ttm_bo_put (bo );
1015
+ return ret ;
1016
+ }
1017
+
1045
1018
/*
1046
1019
* For ttm_bo_type_device buffers, allocate
1047
1020
* address space from the device.
@@ -1170,7 +1143,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
1170
1143
*/
1171
1144
if (bo -> resource -> mem_type != TTM_PL_SYSTEM ) {
1172
1145
struct ttm_operation_ctx ctx = { false, false };
1173
- struct ttm_resource evict_mem ;
1146
+ struct ttm_resource * evict_mem ;
1174
1147
struct ttm_place place , hop ;
1175
1148
1176
1149
memset (& place , 0 , sizeof (place ));
@@ -1182,7 +1155,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
1182
1155
if (unlikely (ret ))
1183
1156
goto out ;
1184
1157
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 );
1186
1159
if (unlikely (ret != 0 )) {
1187
1160
WARN (ret == - EMULTIHOP , "Unexpected multihop in swaput - likely driver bug.\n" );
1188
1161
goto out ;
0 commit comments