Lines Matching refs:sa_manager

48 static void amdgpu_sa_bo_try_free(struct amdgpu_sa_manager *sa_manager);
51 struct amdgpu_sa_manager *sa_manager, in amdgpu_sa_bo_manager_init() argument
56 init_waitqueue_head(&sa_manager->wq); in amdgpu_sa_bo_manager_init()
57 sa_manager->bo = NULL; in amdgpu_sa_bo_manager_init()
58 sa_manager->size = size; in amdgpu_sa_bo_manager_init()
59 sa_manager->domain = domain; in amdgpu_sa_bo_manager_init()
60 sa_manager->align = align; in amdgpu_sa_bo_manager_init()
61 sa_manager->hole = &sa_manager->olist; in amdgpu_sa_bo_manager_init()
62 INIT_LIST_HEAD(&sa_manager->olist); in amdgpu_sa_bo_manager_init()
64 INIT_LIST_HEAD(&sa_manager->flist[i]); in amdgpu_sa_bo_manager_init()
66 r = amdgpu_bo_create_kernel(adev, size, align, domain, &sa_manager->bo, in amdgpu_sa_bo_manager_init()
67 &sa_manager->gpu_addr, &sa_manager->cpu_ptr); in amdgpu_sa_bo_manager_init()
73 memset(sa_manager->cpu_ptr, 0, sa_manager->size); in amdgpu_sa_bo_manager_init()
78 struct amdgpu_sa_manager *sa_manager) in amdgpu_sa_bo_manager_fini() argument
82 if (sa_manager->bo == NULL) { in amdgpu_sa_bo_manager_fini()
87 if (!list_empty(&sa_manager->olist)) { in amdgpu_sa_bo_manager_fini()
88 sa_manager->hole = &sa_manager->olist, in amdgpu_sa_bo_manager_fini()
89 amdgpu_sa_bo_try_free(sa_manager); in amdgpu_sa_bo_manager_fini()
90 if (!list_empty(&sa_manager->olist)) { in amdgpu_sa_bo_manager_fini()
94 list_for_each_entry_safe(sa_bo, tmp, &sa_manager->olist, olist) { in amdgpu_sa_bo_manager_fini()
98 amdgpu_bo_free_kernel(&sa_manager->bo, &sa_manager->gpu_addr, &sa_manager->cpu_ptr); in amdgpu_sa_bo_manager_fini()
99 sa_manager->size = 0; in amdgpu_sa_bo_manager_fini()
104 struct amdgpu_sa_manager *sa_manager = sa_bo->manager; in amdgpu_sa_bo_remove_locked() local
105 if (sa_manager->hole == &sa_bo->olist) { in amdgpu_sa_bo_remove_locked()
106 sa_manager->hole = sa_bo->olist.prev; in amdgpu_sa_bo_remove_locked()
114 static void amdgpu_sa_bo_try_free(struct amdgpu_sa_manager *sa_manager) in amdgpu_sa_bo_try_free() argument
118 if (sa_manager->hole->next == &sa_manager->olist) in amdgpu_sa_bo_try_free()
121 sa_bo = list_entry(sa_manager->hole->next, struct amdgpu_sa_bo, olist); in amdgpu_sa_bo_try_free()
122 list_for_each_entry_safe_from(sa_bo, tmp, &sa_manager->olist, olist) { in amdgpu_sa_bo_try_free()
131 static inline unsigned amdgpu_sa_bo_hole_soffset(struct amdgpu_sa_manager *sa_manager) in amdgpu_sa_bo_hole_soffset() argument
133 struct list_head *hole = sa_manager->hole; in amdgpu_sa_bo_hole_soffset()
135 if (hole != &sa_manager->olist) { in amdgpu_sa_bo_hole_soffset()
141 static inline unsigned amdgpu_sa_bo_hole_eoffset(struct amdgpu_sa_manager *sa_manager) in amdgpu_sa_bo_hole_eoffset() argument
143 struct list_head *hole = sa_manager->hole; in amdgpu_sa_bo_hole_eoffset()
145 if (hole->next != &sa_manager->olist) { in amdgpu_sa_bo_hole_eoffset()
148 return sa_manager->size; in amdgpu_sa_bo_hole_eoffset()
151 static bool amdgpu_sa_bo_try_alloc(struct amdgpu_sa_manager *sa_manager, in amdgpu_sa_bo_try_alloc() argument
157 soffset = amdgpu_sa_bo_hole_soffset(sa_manager); in amdgpu_sa_bo_try_alloc()
158 eoffset = amdgpu_sa_bo_hole_eoffset(sa_manager); in amdgpu_sa_bo_try_alloc()
164 sa_bo->manager = sa_manager; in amdgpu_sa_bo_try_alloc()
167 list_add(&sa_bo->olist, sa_manager->hole); in amdgpu_sa_bo_try_alloc()
169 sa_manager->hole = &sa_bo->olist; in amdgpu_sa_bo_try_alloc()
185 static bool amdgpu_sa_event(struct amdgpu_sa_manager *sa_manager, in amdgpu_sa_event() argument
192 if (!list_empty(&sa_manager->flist[i])) in amdgpu_sa_event()
195 soffset = amdgpu_sa_bo_hole_soffset(sa_manager); in amdgpu_sa_event()
196 eoffset = amdgpu_sa_bo_hole_eoffset(sa_manager); in amdgpu_sa_event()
206 static bool amdgpu_sa_bo_next_hole(struct amdgpu_sa_manager *sa_manager, in amdgpu_sa_bo_next_hole() argument
214 if (sa_manager->hole->next == &sa_manager->olist) { in amdgpu_sa_bo_next_hole()
216 sa_manager->hole = &sa_manager->olist; in amdgpu_sa_bo_next_hole()
220 soffset = amdgpu_sa_bo_hole_soffset(sa_manager); in amdgpu_sa_bo_next_hole()
222 best = sa_manager->size * 2; in amdgpu_sa_bo_next_hole()
231 if (list_empty(&sa_manager->flist[i])) in amdgpu_sa_bo_next_hole()
234 sa_bo = list_first_entry(&sa_manager->flist[i], in amdgpu_sa_bo_next_hole()
250 tmp += sa_manager->size; in amdgpu_sa_bo_next_hole()
265 sa_manager->hole = best_bo->olist.prev; in amdgpu_sa_bo_next_hole()
275 int amdgpu_sa_bo_new(struct amdgpu_sa_manager *sa_manager, in amdgpu_sa_bo_new() argument
285 if (WARN_ON_ONCE(align > sa_manager->align)) in amdgpu_sa_bo_new()
288 if (WARN_ON_ONCE(size > sa_manager->size)) in amdgpu_sa_bo_new()
294 (*sa_bo)->manager = sa_manager; in amdgpu_sa_bo_new()
299 spin_lock(&sa_manager->wq.lock); in amdgpu_sa_bo_new()
305 amdgpu_sa_bo_try_free(sa_manager); in amdgpu_sa_bo_new()
307 if (amdgpu_sa_bo_try_alloc(sa_manager, *sa_bo, in amdgpu_sa_bo_new()
309 spin_unlock(&sa_manager->wq.lock); in amdgpu_sa_bo_new()
314 } while (amdgpu_sa_bo_next_hole(sa_manager, fences, tries)); in amdgpu_sa_bo_new()
321 spin_unlock(&sa_manager->wq.lock); in amdgpu_sa_bo_new()
329 spin_lock(&sa_manager->wq.lock); in amdgpu_sa_bo_new()
333 sa_manager->wq, in amdgpu_sa_bo_new()
334 amdgpu_sa_event(sa_manager, size, align) in amdgpu_sa_bo_new()
340 spin_unlock(&sa_manager->wq.lock); in amdgpu_sa_bo_new()
349 struct amdgpu_sa_manager *sa_manager; in amdgpu_sa_bo_free() local
355 sa_manager = (*sa_bo)->manager; in amdgpu_sa_bo_free()
356 spin_lock(&sa_manager->wq.lock); in amdgpu_sa_bo_free()
362 list_add_tail(&(*sa_bo)->flist, &sa_manager->flist[idx]); in amdgpu_sa_bo_free()
366 wake_up_all_locked(&sa_manager->wq); in amdgpu_sa_bo_free()
367 spin_unlock(&sa_manager->wq.lock); in amdgpu_sa_bo_free()
373 void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager, in amdgpu_sa_bo_dump_debug_info() argument
378 spin_lock(&sa_manager->wq.lock); in amdgpu_sa_bo_dump_debug_info()
379 list_for_each_entry(i, &sa_manager->olist, olist) { in amdgpu_sa_bo_dump_debug_info()
380 uint64_t soffset = i->soffset + sa_manager->gpu_addr; in amdgpu_sa_bo_dump_debug_info()
381 uint64_t eoffset = i->eoffset + sa_manager->gpu_addr; in amdgpu_sa_bo_dump_debug_info()
382 if (&i->olist == sa_manager->hole) { in amdgpu_sa_bo_dump_debug_info()
396 spin_unlock(&sa_manager->wq.lock); in amdgpu_sa_bo_dump_debug_info()