@@ -91,8 +91,8 @@ static void ttm_lru_bulk_move_pos_tail(struct ttm_lru_bulk_move_pos *pos,
9191}
9292
9393/* Add the resource to a bulk_move cursor */
94- void ttm_lru_bulk_move_add (struct ttm_lru_bulk_move * bulk ,
95- struct ttm_resource * res )
94+ static void ttm_lru_bulk_move_add (struct ttm_lru_bulk_move * bulk ,
95+ struct ttm_resource * res )
9696{
9797 struct ttm_lru_bulk_move_pos * pos = ttm_lru_bulk_move_pos (bulk , res );
9898
@@ -105,8 +105,8 @@ void ttm_lru_bulk_move_add(struct ttm_lru_bulk_move *bulk,
105105}
106106
107107/* Remove the resource from a bulk_move range */
108- void ttm_lru_bulk_move_del (struct ttm_lru_bulk_move * bulk ,
109- struct ttm_resource * res )
108+ static void ttm_lru_bulk_move_del (struct ttm_lru_bulk_move * bulk ,
109+ struct ttm_resource * res )
110110{
111111 struct ttm_lru_bulk_move_pos * pos = ttm_lru_bulk_move_pos (bulk , res );
112112
@@ -122,6 +122,22 @@ void ttm_lru_bulk_move_del(struct ttm_lru_bulk_move *bulk,
122122 }
123123}
124124
125+ /* Add the resource to a bulk move if the BO is configured for it */
126+ void ttm_resource_add_bulk_move (struct ttm_resource * res ,
127+ struct ttm_buffer_object * bo )
128+ {
129+ if (bo -> bulk_move && !bo -> pin_count )
130+ ttm_lru_bulk_move_add (bo -> bulk_move , res );
131+ }
132+
133+ /* Remove the resource from a bulk move if the BO is configured for it */
134+ void ttm_resource_del_bulk_move (struct ttm_resource * res ,
135+ struct ttm_buffer_object * bo )
136+ {
137+ if (bo -> bulk_move && !bo -> pin_count )
138+ ttm_lru_bulk_move_del (bo -> bulk_move , res );
139+ }
140+
125141/* Move a resource to the LRU or bulk tail */
126142void ttm_resource_move_to_lru_tail (struct ttm_resource * res )
127143{
@@ -169,15 +185,14 @@ void ttm_resource_init(struct ttm_buffer_object *bo,
169185 res -> bus .is_iomem = false;
170186 res -> bus .caching = ttm_cached ;
171187 res -> bo = bo ;
172- INIT_LIST_HEAD (& res -> lru );
173188
174189 man = ttm_manager_type (bo -> bdev , place -> mem_type );
175190 spin_lock (& bo -> bdev -> lru_lock );
176- man -> usage += res -> num_pages << PAGE_SHIFT ;
177- if (bo -> bulk_move )
178- ttm_lru_bulk_move_add (bo -> bulk_move , res );
191+ if (bo -> pin_count )
192+ list_add_tail (& res -> lru , & bo -> bdev -> pinned );
179193 else
180- ttm_resource_move_to_lru_tail (res );
194+ list_add_tail (& res -> lru , & man -> lru [bo -> priority ]);
195+ man -> usage += res -> num_pages << PAGE_SHIFT ;
181196 spin_unlock (& bo -> bdev -> lru_lock );
182197}
183198EXPORT_SYMBOL (ttm_resource_init );
@@ -210,8 +225,16 @@ int ttm_resource_alloc(struct ttm_buffer_object *bo,
210225{
211226 struct ttm_resource_manager * man =
212227 ttm_manager_type (bo -> bdev , place -> mem_type );
228+ int ret ;
229+
230+ ret = man -> func -> alloc (man , bo , place , res_ptr );
231+ if (ret )
232+ return ret ;
213233
214- return man -> func -> alloc (man , bo , place , res_ptr );
234+ spin_lock (& bo -> bdev -> lru_lock );
235+ ttm_resource_add_bulk_move (* res_ptr , bo );
236+ spin_unlock (& bo -> bdev -> lru_lock );
237+ return 0 ;
215238}
216239
217240void ttm_resource_free (struct ttm_buffer_object * bo , struct ttm_resource * * res )
@@ -221,12 +244,9 @@ void ttm_resource_free(struct ttm_buffer_object *bo, struct ttm_resource **res)
221244 if (!* res )
222245 return ;
223246
224- if (bo -> bulk_move ) {
225- spin_lock (& bo -> bdev -> lru_lock );
226- ttm_lru_bulk_move_del (bo -> bulk_move , * res );
227- spin_unlock (& bo -> bdev -> lru_lock );
228- }
229-
247+ spin_lock (& bo -> bdev -> lru_lock );
248+ ttm_resource_del_bulk_move (* res , bo );
249+ spin_unlock (& bo -> bdev -> lru_lock );
230250 man = ttm_manager_type (bo -> bdev , (* res )-> mem_type );
231251 man -> func -> free (man , * res );
232252 * res = NULL ;
0 commit comments