Lines Matching full:vc4
10 * DOC: VC4 GEM BO management support
12 * The VC4 GPU architecture (both scanout and rendering) has direct
43 static void vc4_bo_stats_dump(struct vc4_dev *vc4) in vc4_bo_stats_dump() argument
47 for (i = 0; i < vc4->num_labels; i++) { in vc4_bo_stats_dump()
48 if (!vc4->bo_labels[i].num_allocated) in vc4_bo_stats_dump()
52 vc4->bo_labels[i].name, in vc4_bo_stats_dump()
53 vc4->bo_labels[i].size_allocated / 1024, in vc4_bo_stats_dump()
54 vc4->bo_labels[i].num_allocated); in vc4_bo_stats_dump()
57 mutex_lock(&vc4->purgeable.lock); in vc4_bo_stats_dump()
58 if (vc4->purgeable.num) in vc4_bo_stats_dump()
60 vc4->purgeable.size / 1024, vc4->purgeable.num); in vc4_bo_stats_dump()
62 if (vc4->purgeable.purged_num) in vc4_bo_stats_dump()
64 vc4->purgeable.purged_size / 1024, in vc4_bo_stats_dump()
65 vc4->purgeable.purged_num); in vc4_bo_stats_dump()
66 mutex_unlock(&vc4->purgeable.lock); in vc4_bo_stats_dump()
74 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_stats_debugfs() local
77 mutex_lock(&vc4->bo_lock); in vc4_bo_stats_debugfs()
78 for (i = 0; i < vc4->num_labels; i++) { in vc4_bo_stats_debugfs()
79 if (!vc4->bo_labels[i].num_allocated) in vc4_bo_stats_debugfs()
83 vc4->bo_labels[i].name, in vc4_bo_stats_debugfs()
84 vc4->bo_labels[i].size_allocated / 1024, in vc4_bo_stats_debugfs()
85 vc4->bo_labels[i].num_allocated); in vc4_bo_stats_debugfs()
87 mutex_unlock(&vc4->bo_lock); in vc4_bo_stats_debugfs()
89 mutex_lock(&vc4->purgeable.lock); in vc4_bo_stats_debugfs()
90 if (vc4->purgeable.num) in vc4_bo_stats_debugfs()
92 vc4->purgeable.size / 1024, vc4->purgeable.num); in vc4_bo_stats_debugfs()
94 if (vc4->purgeable.purged_num) in vc4_bo_stats_debugfs()
96 vc4->purgeable.purged_size / 1024, in vc4_bo_stats_debugfs()
97 vc4->purgeable.purged_num); in vc4_bo_stats_debugfs()
98 mutex_unlock(&vc4->purgeable.lock); in vc4_bo_stats_debugfs()
112 static int vc4_get_user_label(struct vc4_dev *vc4, const char *name) in vc4_get_user_label() argument
117 for (i = 0; i < vc4->num_labels; i++) { in vc4_get_user_label()
118 if (!vc4->bo_labels[i].name) { in vc4_get_user_label()
120 } else if (strcmp(vc4->bo_labels[i].name, name) == 0) { in vc4_get_user_label()
127 WARN_ON(vc4->bo_labels[free_slot].num_allocated != 0); in vc4_get_user_label()
128 vc4->bo_labels[free_slot].name = name; in vc4_get_user_label()
131 u32 new_label_count = vc4->num_labels + 1; in vc4_get_user_label()
133 krealloc(vc4->bo_labels, in vc4_get_user_label()
142 free_slot = vc4->num_labels; in vc4_get_user_label()
143 vc4->bo_labels = new_labels; in vc4_get_user_label()
144 vc4->num_labels = new_label_count; in vc4_get_user_label()
146 vc4->bo_labels[free_slot].name = name; in vc4_get_user_label()
147 vc4->bo_labels[free_slot].num_allocated = 0; in vc4_get_user_label()
148 vc4->bo_labels[free_slot].size_allocated = 0; in vc4_get_user_label()
157 struct vc4_dev *vc4 = to_vc4_dev(gem_obj->dev); in vc4_bo_set_label() local
159 lockdep_assert_held(&vc4->bo_lock); in vc4_bo_set_label()
162 vc4->bo_labels[label].num_allocated++; in vc4_bo_set_label()
163 vc4->bo_labels[label].size_allocated += gem_obj->size; in vc4_bo_set_label()
166 vc4->bo_labels[bo->label].num_allocated--; in vc4_bo_set_label()
167 vc4->bo_labels[bo->label].size_allocated -= gem_obj->size; in vc4_bo_set_label()
169 if (vc4->bo_labels[bo->label].num_allocated == 0 && in vc4_bo_set_label()
176 kfree(vc4->bo_labels[bo->label].name); in vc4_bo_set_label()
177 vc4->bo_labels[bo->label].name = NULL; in vc4_bo_set_label()
191 struct vc4_dev *vc4 = to_vc4_dev(obj->dev); in vc4_bo_destroy() local
193 lockdep_assert_held(&vc4->bo_lock); in vc4_bo_destroy()
211 struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev); in vc4_bo_remove_from_cache() local
213 lockdep_assert_held(&vc4->bo_lock); in vc4_bo_remove_from_cache()
221 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_get_cache_list_for_size() local
224 if (vc4->bo_cache.size_list_size <= page_index) { in vc4_get_cache_list_for_size()
225 uint32_t new_size = max(vc4->bo_cache.size_list_size * 2, in vc4_get_cache_list_for_size()
238 for (i = 0; i < vc4->bo_cache.size_list_size; i++) { in vc4_get_cache_list_for_size()
240 &vc4->bo_cache.size_list[i]; in vc4_get_cache_list_for_size()
248 for (i = vc4->bo_cache.size_list_size; i < new_size; i++) in vc4_get_cache_list_for_size()
251 kfree(vc4->bo_cache.size_list); in vc4_get_cache_list_for_size()
252 vc4->bo_cache.size_list = new_list; in vc4_get_cache_list_for_size()
253 vc4->bo_cache.size_list_size = new_size; in vc4_get_cache_list_for_size()
256 return &vc4->bo_cache.size_list[page_index]; in vc4_get_cache_list_for_size()
261 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_cache_purge() local
263 mutex_lock(&vc4->bo_lock); in vc4_bo_cache_purge()
264 while (!list_empty(&vc4->bo_cache.time_list)) { in vc4_bo_cache_purge()
265 struct vc4_bo *bo = list_last_entry(&vc4->bo_cache.time_list, in vc4_bo_cache_purge()
270 mutex_unlock(&vc4->bo_lock); in vc4_bo_cache_purge()
275 struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev); in vc4_bo_add_to_purgeable_pool() local
277 mutex_lock(&vc4->purgeable.lock); in vc4_bo_add_to_purgeable_pool()
278 list_add_tail(&bo->size_head, &vc4->purgeable.list); in vc4_bo_add_to_purgeable_pool()
279 vc4->purgeable.num++; in vc4_bo_add_to_purgeable_pool()
280 vc4->purgeable.size += bo->base.base.size; in vc4_bo_add_to_purgeable_pool()
281 mutex_unlock(&vc4->purgeable.lock); in vc4_bo_add_to_purgeable_pool()
286 struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev); in vc4_bo_remove_from_purgeable_pool_locked() local
301 vc4->purgeable.num--; in vc4_bo_remove_from_purgeable_pool_locked()
302 vc4->purgeable.size -= bo->base.base.size; in vc4_bo_remove_from_purgeable_pool_locked()
307 struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev); in vc4_bo_remove_from_purgeable_pool() local
309 mutex_lock(&vc4->purgeable.lock); in vc4_bo_remove_from_purgeable_pool()
311 mutex_unlock(&vc4->purgeable.lock); in vc4_bo_remove_from_purgeable_pool()
331 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_userspace_cache_purge() local
333 mutex_lock(&vc4->purgeable.lock); in vc4_bo_userspace_cache_purge()
334 while (!list_empty(&vc4->purgeable.list)) { in vc4_bo_userspace_cache_purge()
335 struct vc4_bo *bo = list_first_entry(&vc4->purgeable.list, in vc4_bo_userspace_cache_purge()
347 mutex_unlock(&vc4->purgeable.lock); in vc4_bo_userspace_cache_purge()
366 mutex_lock(&vc4->purgeable.lock); in vc4_bo_userspace_cache_purge()
369 vc4->purgeable.purged_size += purged_size; in vc4_bo_userspace_cache_purge()
370 vc4->purgeable.purged_num++; in vc4_bo_userspace_cache_purge()
373 mutex_unlock(&vc4->purgeable.lock); in vc4_bo_userspace_cache_purge()
380 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_get_from_cache() local
386 mutex_lock(&vc4->bo_lock); in vc4_bo_get_from_cache()
387 if (page_index >= vc4->bo_cache.size_list_size) in vc4_bo_get_from_cache()
390 if (list_empty(&vc4->bo_cache.size_list[page_index])) in vc4_bo_get_from_cache()
393 bo = list_first_entry(&vc4->bo_cache.size_list[page_index], in vc4_bo_get_from_cache()
401 mutex_unlock(&vc4->bo_lock); in vc4_bo_get_from_cache()
415 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_create_object() local
425 mutex_lock(&vc4->bo_lock); in vc4_create_object()
427 vc4->bo_labels[VC4_BO_TYPE_KERNEL].num_allocated++; in vc4_create_object()
428 vc4->bo_labels[VC4_BO_TYPE_KERNEL].size_allocated += size; in vc4_create_object()
429 mutex_unlock(&vc4->bo_lock); in vc4_create_object()
440 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_create() local
483 vc4_bo_stats_dump(vc4); in vc4_bo_create()
494 mutex_lock(&vc4->bo_lock); in vc4_bo_create()
496 mutex_unlock(&vc4->bo_lock); in vc4_bo_create()
529 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_cache_free_old() local
532 lockdep_assert_held(&vc4->bo_lock); in vc4_bo_cache_free_old()
534 while (!list_empty(&vc4->bo_cache.time_list)) { in vc4_bo_cache_free_old()
535 struct vc4_bo *bo = list_last_entry(&vc4->bo_cache.time_list, in vc4_bo_cache_free_old()
538 mod_timer(&vc4->bo_cache.time_timer, in vc4_bo_cache_free_old()
555 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_free_object() local
565 mutex_lock(&vc4->bo_lock); in vc4_free_object()
608 list_add(&bo->unref_head, &vc4->bo_cache.time_list); in vc4_free_object()
615 mutex_unlock(&vc4->bo_lock); in vc4_free_object()
620 struct vc4_dev *vc4 = in vc4_bo_cache_time_work() local
622 struct drm_device *dev = vc4->dev; in vc4_bo_cache_time_work()
624 mutex_lock(&vc4->bo_lock); in vc4_bo_cache_time_work()
626 mutex_unlock(&vc4->bo_lock); in vc4_bo_cache_time_work()
682 struct vc4_dev *vc4 = from_timer(vc4, t, bo_cache.time_timer); in vc4_bo_cache_time_timer() local
684 schedule_work(&vc4->bo_cache.time_work); in vc4_bo_cache_time_timer()
1022 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_cache_init() local
1029 vc4->bo_labels = kcalloc(VC4_BO_TYPE_COUNT, sizeof(*vc4->bo_labels), in vc4_bo_cache_init()
1031 if (!vc4->bo_labels) in vc4_bo_cache_init()
1033 vc4->num_labels = VC4_BO_TYPE_COUNT; in vc4_bo_cache_init()
1037 vc4->bo_labels[i].name = bo_type_names[i]; in vc4_bo_cache_init()
1039 mutex_init(&vc4->bo_lock); in vc4_bo_cache_init()
1041 INIT_LIST_HEAD(&vc4->bo_cache.time_list); in vc4_bo_cache_init()
1043 INIT_WORK(&vc4->bo_cache.time_work, vc4_bo_cache_time_work); in vc4_bo_cache_init()
1044 timer_setup(&vc4->bo_cache.time_timer, vc4_bo_cache_time_timer, 0); in vc4_bo_cache_init()
1051 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_bo_cache_destroy() local
1054 del_timer(&vc4->bo_cache.time_timer); in vc4_bo_cache_destroy()
1055 cancel_work_sync(&vc4->bo_cache.time_work); in vc4_bo_cache_destroy()
1059 for (i = 0; i < vc4->num_labels; i++) { in vc4_bo_cache_destroy()
1060 if (vc4->bo_labels[i].num_allocated) { in vc4_bo_cache_destroy()
1063 vc4->bo_labels[i].num_allocated, in vc4_bo_cache_destroy()
1064 vc4->bo_labels[i].name); in vc4_bo_cache_destroy()
1068 kfree(vc4->bo_labels[i].name); in vc4_bo_cache_destroy()
1070 kfree(vc4->bo_labels); in vc4_bo_cache_destroy()
1076 struct vc4_dev *vc4 = to_vc4_dev(dev); in vc4_label_bo_ioctl() local
1096 mutex_lock(&vc4->bo_lock); in vc4_label_bo_ioctl()
1097 label = vc4_get_user_label(vc4, name); in vc4_label_bo_ioctl()
1102 mutex_unlock(&vc4->bo_lock); in vc4_label_bo_ioctl()