2 * Copyright 2008 Advanced Micro Devices, Inc.
3 * Copyright 2008 Red Hat Inc.
4 * Copyright 2009 Jerome Glisse.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie
29 #include <linux/pci.h>
31 #include <drm/drm_device.h>
32 #include <drm/drm_file.h>
33 #include <drm/drm_gem_ttm_helper.h>
34 #include <drm/radeon_drm.h>
37 #include "radeon_prime.h"
39 struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
41 struct sg_table *radeon_gem_prime_get_sg_table(struct drm_gem_object *obj);
42 int radeon_gem_prime_pin(struct drm_gem_object *obj);
43 void radeon_gem_prime_unpin(struct drm_gem_object *obj);
45 const struct drm_gem_object_funcs radeon_gem_object_funcs;
47 static vm_fault_t radeon_gem_fault(struct vm_fault *vmf)
49 struct ttm_buffer_object *bo = vmf->vma->vm_private_data;
50 struct radeon_device *rdev = radeon_get_rdev(bo->bdev);
53 down_read(&rdev->pm.mclk_lock);
55 ret = ttm_bo_vm_reserve(bo, vmf);
59 ret = radeon_bo_fault_reserve_notify(bo);
63 ret = ttm_bo_vm_fault_reserved(vmf, vmf->vma->vm_page_prot,
64 TTM_BO_VM_NUM_PREFAULT, 1);
65 if (ret == VM_FAULT_RETRY && !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT))
69 dma_resv_unlock(bo->base.resv);
72 up_read(&rdev->pm.mclk_lock);
76 static const struct vm_operations_struct radeon_gem_vm_ops = {
77 .fault = radeon_gem_fault,
78 .open = ttm_bo_vm_open,
79 .close = ttm_bo_vm_close,
80 .access = ttm_bo_vm_access
83 static void radeon_gem_object_free(struct drm_gem_object *gobj)
85 struct radeon_bo *robj = gem_to_radeon_bo(gobj);
88 radeon_mn_unregister(robj);
89 radeon_bo_unref(&robj);
93 int radeon_gem_object_create(struct radeon_device *rdev, unsigned long size,
94 int alignment, int initial_domain,
95 u32 flags, bool kernel,
96 struct drm_gem_object **obj)
98 struct radeon_bo *robj;
99 unsigned long max_size;
103 /* At least align on page size */
104 if (alignment < PAGE_SIZE) {
105 alignment = PAGE_SIZE;
108 /* Maximum bo size is the unpinned gtt size since we use the gtt to
109 * handle vram to system pool migrations.
111 max_size = rdev->mc.gtt_size - rdev->gart_pin_size;
112 if (size > max_size) {
113 DRM_DEBUG("Allocation size %ldMb bigger than %ldMb limit\n",
114 size >> 20, max_size >> 20);
119 r = radeon_bo_create(rdev, size, alignment, kernel, initial_domain,
120 flags, NULL, NULL, &robj);
122 if (r != -ERESTARTSYS) {
123 if (initial_domain == RADEON_GEM_DOMAIN_VRAM) {
124 initial_domain |= RADEON_GEM_DOMAIN_GTT;
127 DRM_ERROR("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
128 size, initial_domain, alignment, r);
132 *obj = &robj->tbo.base;
133 (*obj)->funcs = &radeon_gem_object_funcs;
134 robj->pid = task_pid_nr(current);
136 mutex_lock(&rdev->gem.mutex);
137 list_add_tail(&robj->list, &rdev->gem.objects);
138 mutex_unlock(&rdev->gem.mutex);
143 static int radeon_gem_set_domain(struct drm_gem_object *gobj,
144 uint32_t rdomain, uint32_t wdomain)
146 struct radeon_bo *robj;
150 /* FIXME: reeimplement */
151 robj = gem_to_radeon_bo(gobj);
152 /* work out where to validate the buffer to */
159 pr_warn("Set domain without domain !\n");
162 if (domain == RADEON_GEM_DOMAIN_CPU) {
163 /* Asking for cpu access wait for object idle */
164 r = dma_resv_wait_timeout(robj->tbo.base.resv, true, true, 30 * HZ);
168 if (r < 0 && r != -EINTR) {
169 pr_err("Failed to wait for object: %li\n", r);
173 if (domain == RADEON_GEM_DOMAIN_VRAM && robj->prime_shared_count) {
174 /* A BO that is associated with a dma-buf cannot be sensibly migrated to VRAM */
180 int radeon_gem_init(struct radeon_device *rdev)
182 INIT_LIST_HEAD(&rdev->gem.objects);
186 void radeon_gem_fini(struct radeon_device *rdev)
188 radeon_bo_force_delete(rdev);
192 * Call from drm_gem_handle_create which appear in both new and open ioctl
195 static int radeon_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv)
197 struct radeon_bo *rbo = gem_to_radeon_bo(obj);
198 struct radeon_device *rdev = rbo->rdev;
199 struct radeon_fpriv *fpriv = file_priv->driver_priv;
200 struct radeon_vm *vm = &fpriv->vm;
201 struct radeon_bo_va *bo_va;
204 if ((rdev->family < CHIP_CAYMAN) ||
205 (!rdev->accel_working)) {
209 r = radeon_bo_reserve(rbo, false);
214 bo_va = radeon_vm_bo_find(vm, rbo);
216 bo_va = radeon_vm_bo_add(rdev, vm, rbo);
220 radeon_bo_unreserve(rbo);
225 static void radeon_gem_object_close(struct drm_gem_object *obj,
226 struct drm_file *file_priv)
228 struct radeon_bo *rbo = gem_to_radeon_bo(obj);
229 struct radeon_device *rdev = rbo->rdev;
230 struct radeon_fpriv *fpriv = file_priv->driver_priv;
231 struct radeon_vm *vm = &fpriv->vm;
232 struct radeon_bo_va *bo_va;
235 if ((rdev->family < CHIP_CAYMAN) ||
236 (!rdev->accel_working)) {
240 r = radeon_bo_reserve(rbo, true);
242 dev_err(rdev->dev, "leaking bo va because "
243 "we fail to reserve bo (%d)\n", r);
246 bo_va = radeon_vm_bo_find(vm, rbo);
248 if (--bo_va->ref_count == 0) {
249 radeon_vm_bo_rmv(rdev, bo_va);
252 radeon_bo_unreserve(rbo);
255 static int radeon_gem_handle_lockup(struct radeon_device *rdev, int r)
258 r = radeon_gpu_reset(rdev);
265 static int radeon_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma)
267 struct radeon_bo *bo = gem_to_radeon_bo(obj);
268 struct radeon_device *rdev = radeon_get_rdev(bo->tbo.bdev);
270 if (radeon_ttm_tt_has_userptr(rdev, bo->tbo.ttm))
273 return drm_gem_ttm_mmap(obj, vma);
276 const struct drm_gem_object_funcs radeon_gem_object_funcs = {
277 .free = radeon_gem_object_free,
278 .open = radeon_gem_object_open,
279 .close = radeon_gem_object_close,
280 .export = radeon_gem_prime_export,
281 .pin = radeon_gem_prime_pin,
282 .unpin = radeon_gem_prime_unpin,
283 .get_sg_table = radeon_gem_prime_get_sg_table,
284 .vmap = drm_gem_ttm_vmap,
285 .vunmap = drm_gem_ttm_vunmap,
286 .mmap = radeon_gem_object_mmap,
287 .vm_ops = &radeon_gem_vm_ops,
293 int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
294 struct drm_file *filp)
296 struct radeon_device *rdev = dev->dev_private;
297 struct drm_radeon_gem_info *args = data;
298 struct ttm_resource_manager *man;
300 man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
302 args->vram_size = (u64)man->size << PAGE_SHIFT;
303 args->vram_visible = rdev->mc.visible_vram_size;
304 args->vram_visible -= rdev->vram_pin_size;
305 args->gart_size = rdev->mc.gtt_size;
306 args->gart_size -= rdev->gart_pin_size;
311 int radeon_gem_pread_ioctl(struct drm_device *dev, void *data,
312 struct drm_file *filp)
314 /* TODO: implement */
315 DRM_ERROR("unimplemented %s\n", __func__);
319 int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data,
320 struct drm_file *filp)
322 /* TODO: implement */
323 DRM_ERROR("unimplemented %s\n", __func__);
327 int radeon_gem_create_ioctl(struct drm_device *dev, void *data,
328 struct drm_file *filp)
330 struct radeon_device *rdev = dev->dev_private;
331 struct drm_radeon_gem_create *args = data;
332 struct drm_gem_object *gobj;
336 down_read(&rdev->exclusive_lock);
337 /* create a gem object to contain this object in */
338 args->size = roundup(args->size, PAGE_SIZE);
339 r = radeon_gem_object_create(rdev, args->size, args->alignment,
340 args->initial_domain, args->flags,
343 up_read(&rdev->exclusive_lock);
344 r = radeon_gem_handle_lockup(rdev, r);
347 r = drm_gem_handle_create(filp, gobj, &handle);
348 /* drop reference from allocate - handle holds it now */
349 drm_gem_object_put(gobj);
351 up_read(&rdev->exclusive_lock);
352 r = radeon_gem_handle_lockup(rdev, r);
355 args->handle = handle;
356 up_read(&rdev->exclusive_lock);
360 int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data,
361 struct drm_file *filp)
363 struct ttm_operation_ctx ctx = { true, false };
364 struct radeon_device *rdev = dev->dev_private;
365 struct drm_radeon_gem_userptr *args = data;
366 struct drm_gem_object *gobj;
367 struct radeon_bo *bo;
371 args->addr = untagged_addr(args->addr);
373 if (offset_in_page(args->addr | args->size))
376 /* reject unknown flag values */
377 if (args->flags & ~(RADEON_GEM_USERPTR_READONLY |
378 RADEON_GEM_USERPTR_ANONONLY | RADEON_GEM_USERPTR_VALIDATE |
379 RADEON_GEM_USERPTR_REGISTER))
382 if (args->flags & RADEON_GEM_USERPTR_READONLY) {
383 /* readonly pages not tested on older hardware */
384 if (rdev->family < CHIP_R600)
387 } else if (!(args->flags & RADEON_GEM_USERPTR_ANONONLY) ||
388 !(args->flags & RADEON_GEM_USERPTR_REGISTER)) {
390 /* if we want to write to it we must require anonymous
391 memory and install a MMU notifier */
395 down_read(&rdev->exclusive_lock);
397 /* create a gem object to contain this object in */
398 r = radeon_gem_object_create(rdev, args->size, 0,
399 RADEON_GEM_DOMAIN_CPU, 0,
404 bo = gem_to_radeon_bo(gobj);
405 r = radeon_ttm_tt_set_userptr(rdev, bo->tbo.ttm, args->addr, args->flags);
409 if (args->flags & RADEON_GEM_USERPTR_REGISTER) {
410 r = radeon_mn_register(bo, args->addr);
415 if (args->flags & RADEON_GEM_USERPTR_VALIDATE) {
416 mmap_read_lock(current->mm);
417 r = radeon_bo_reserve(bo, true);
419 mmap_read_unlock(current->mm);
423 radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_GTT);
424 r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
425 radeon_bo_unreserve(bo);
426 mmap_read_unlock(current->mm);
431 r = drm_gem_handle_create(filp, gobj, &handle);
432 /* drop reference from allocate - handle holds it now */
433 drm_gem_object_put(gobj);
437 args->handle = handle;
438 up_read(&rdev->exclusive_lock);
442 drm_gem_object_put(gobj);
445 up_read(&rdev->exclusive_lock);
446 r = radeon_gem_handle_lockup(rdev, r);
451 int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data,
452 struct drm_file *filp)
454 /* transition the BO to a domain -
455 * just validate the BO into a certain domain */
456 struct radeon_device *rdev = dev->dev_private;
457 struct drm_radeon_gem_set_domain *args = data;
458 struct drm_gem_object *gobj;
459 struct radeon_bo *robj;
462 /* for now if someone requests domain CPU -
463 * just make sure the buffer is finished with */
464 down_read(&rdev->exclusive_lock);
466 /* just do a BO wait for now */
467 gobj = drm_gem_object_lookup(filp, args->handle);
469 up_read(&rdev->exclusive_lock);
472 robj = gem_to_radeon_bo(gobj);
474 r = radeon_gem_set_domain(gobj, args->read_domains, args->write_domain);
476 drm_gem_object_put(gobj);
477 up_read(&rdev->exclusive_lock);
478 r = radeon_gem_handle_lockup(robj->rdev, r);
482 int radeon_mode_dumb_mmap(struct drm_file *filp,
483 struct drm_device *dev,
484 uint32_t handle, uint64_t *offset_p)
486 struct drm_gem_object *gobj;
487 struct radeon_bo *robj;
489 gobj = drm_gem_object_lookup(filp, handle);
493 robj = gem_to_radeon_bo(gobj);
494 if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm)) {
495 drm_gem_object_put(gobj);
498 *offset_p = radeon_bo_mmap_offset(robj);
499 drm_gem_object_put(gobj);
503 int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data,
504 struct drm_file *filp)
506 struct drm_radeon_gem_mmap *args = data;
508 return radeon_mode_dumb_mmap(filp, dev, args->handle, &args->addr_ptr);
511 int radeon_gem_busy_ioctl(struct drm_device *dev, void *data,
512 struct drm_file *filp)
514 struct drm_radeon_gem_busy *args = data;
515 struct drm_gem_object *gobj;
516 struct radeon_bo *robj;
518 uint32_t cur_placement = 0;
520 gobj = drm_gem_object_lookup(filp, args->handle);
524 robj = gem_to_radeon_bo(gobj);
526 r = dma_resv_test_signaled(robj->tbo.base.resv, true);
532 cur_placement = READ_ONCE(robj->tbo.resource->mem_type);
533 args->domain = radeon_mem_type_to_domain(cur_placement);
534 drm_gem_object_put(gobj);
538 int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
539 struct drm_file *filp)
541 struct radeon_device *rdev = dev->dev_private;
542 struct drm_radeon_gem_wait_idle *args = data;
543 struct drm_gem_object *gobj;
544 struct radeon_bo *robj;
546 uint32_t cur_placement = 0;
549 gobj = drm_gem_object_lookup(filp, args->handle);
553 robj = gem_to_radeon_bo(gobj);
555 ret = dma_resv_wait_timeout(robj->tbo.base.resv, true, true, 30 * HZ);
561 /* Flush HDP cache via MMIO if necessary */
562 cur_placement = READ_ONCE(robj->tbo.resource->mem_type);
563 if (rdev->asic->mmio_hdp_flush &&
564 radeon_mem_type_to_domain(cur_placement) == RADEON_GEM_DOMAIN_VRAM)
565 robj->rdev->asic->mmio_hdp_flush(rdev);
566 drm_gem_object_put(gobj);
567 r = radeon_gem_handle_lockup(rdev, r);
571 int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data,
572 struct drm_file *filp)
574 struct drm_radeon_gem_set_tiling *args = data;
575 struct drm_gem_object *gobj;
576 struct radeon_bo *robj;
579 DRM_DEBUG("%d \n", args->handle);
580 gobj = drm_gem_object_lookup(filp, args->handle);
583 robj = gem_to_radeon_bo(gobj);
584 r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch);
585 drm_gem_object_put(gobj);
589 int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data,
590 struct drm_file *filp)
592 struct drm_radeon_gem_get_tiling *args = data;
593 struct drm_gem_object *gobj;
594 struct radeon_bo *rbo;
598 gobj = drm_gem_object_lookup(filp, args->handle);
601 rbo = gem_to_radeon_bo(gobj);
602 r = radeon_bo_reserve(rbo, false);
603 if (unlikely(r != 0))
605 radeon_bo_get_tiling_flags(rbo, &args->tiling_flags, &args->pitch);
606 radeon_bo_unreserve(rbo);
608 drm_gem_object_put(gobj);
613 * radeon_gem_va_update_vm -update the bo_va in its VM
615 * @rdev: radeon_device pointer
616 * @bo_va: bo_va to update
618 * Update the bo_va directly after setting it's address. Errors are not
619 * vital here, so they are not reported back to userspace.
621 static void radeon_gem_va_update_vm(struct radeon_device *rdev,
622 struct radeon_bo_va *bo_va)
624 struct ttm_validate_buffer tv, *entry;
625 struct radeon_bo_list *vm_bos;
626 struct ww_acquire_ctx ticket;
627 struct list_head list;
631 INIT_LIST_HEAD(&list);
633 tv.bo = &bo_va->bo->tbo;
635 list_add(&tv.head, &list);
637 vm_bos = radeon_vm_get_bos(rdev, bo_va->vm, &list);
641 r = ttm_eu_reserve_buffers(&ticket, &list, true, NULL);
645 list_for_each_entry(entry, &list, head) {
646 domain = radeon_mem_type_to_domain(entry->bo->resource->mem_type);
647 /* if anything is swapped out don't swap it in here,
648 just abort and wait for the next CS */
649 if (domain == RADEON_GEM_DOMAIN_CPU)
650 goto error_unreserve;
653 mutex_lock(&bo_va->vm->mutex);
654 r = radeon_vm_clear_freed(rdev, bo_va->vm);
659 r = radeon_vm_bo_update(rdev, bo_va, bo_va->bo->tbo.resource);
662 mutex_unlock(&bo_va->vm->mutex);
665 ttm_eu_backoff_reservation(&ticket, &list);
670 if (r && r != -ERESTARTSYS)
671 DRM_ERROR("Couldn't update BO_VA (%d)\n", r);
674 int radeon_gem_va_ioctl(struct drm_device *dev, void *data,
675 struct drm_file *filp)
677 struct drm_radeon_gem_va *args = data;
678 struct drm_gem_object *gobj;
679 struct radeon_device *rdev = dev->dev_private;
680 struct radeon_fpriv *fpriv = filp->driver_priv;
681 struct radeon_bo *rbo;
682 struct radeon_bo_va *bo_va;
686 if (!rdev->vm_manager.enabled) {
687 args->operation = RADEON_VA_RESULT_ERROR;
692 * We don't support vm_id yet, to be sure we don't have have broken
693 * userspace, reject anyone trying to use non 0 value thus moving
694 * forward we can use those fields without breaking existant userspace
697 args->operation = RADEON_VA_RESULT_ERROR;
701 if (args->offset < RADEON_VA_RESERVED_SIZE) {
703 "offset 0x%lX is in reserved area 0x%X\n",
704 (unsigned long)args->offset,
705 RADEON_VA_RESERVED_SIZE);
706 args->operation = RADEON_VA_RESULT_ERROR;
710 /* don't remove, we need to enforce userspace to set the snooped flag
711 * otherwise we will endup with broken userspace and we won't be able
712 * to enable this feature without adding new interface
714 invalid_flags = RADEON_VM_PAGE_VALID | RADEON_VM_PAGE_SYSTEM;
715 if ((args->flags & invalid_flags)) {
716 dev_err(dev->dev, "invalid flags 0x%08X vs 0x%08X\n",
717 args->flags, invalid_flags);
718 args->operation = RADEON_VA_RESULT_ERROR;
722 switch (args->operation) {
724 case RADEON_VA_UNMAP:
727 dev_err(dev->dev, "unsupported operation %d\n",
729 args->operation = RADEON_VA_RESULT_ERROR;
733 gobj = drm_gem_object_lookup(filp, args->handle);
735 args->operation = RADEON_VA_RESULT_ERROR;
738 rbo = gem_to_radeon_bo(gobj);
739 r = radeon_bo_reserve(rbo, false);
741 args->operation = RADEON_VA_RESULT_ERROR;
742 drm_gem_object_put(gobj);
745 bo_va = radeon_vm_bo_find(&fpriv->vm, rbo);
747 args->operation = RADEON_VA_RESULT_ERROR;
748 radeon_bo_unreserve(rbo);
749 drm_gem_object_put(gobj);
753 switch (args->operation) {
755 if (bo_va->it.start) {
756 args->operation = RADEON_VA_RESULT_VA_EXIST;
757 args->offset = bo_va->it.start * RADEON_GPU_PAGE_SIZE;
758 radeon_bo_unreserve(rbo);
761 r = radeon_vm_bo_set_addr(rdev, bo_va, args->offset, args->flags);
763 case RADEON_VA_UNMAP:
764 r = radeon_vm_bo_set_addr(rdev, bo_va, 0, 0);
770 radeon_gem_va_update_vm(rdev, bo_va);
771 args->operation = RADEON_VA_RESULT_OK;
773 args->operation = RADEON_VA_RESULT_ERROR;
776 drm_gem_object_put(gobj);
780 int radeon_gem_op_ioctl(struct drm_device *dev, void *data,
781 struct drm_file *filp)
783 struct drm_radeon_gem_op *args = data;
784 struct drm_gem_object *gobj;
785 struct radeon_bo *robj;
788 gobj = drm_gem_object_lookup(filp, args->handle);
792 robj = gem_to_radeon_bo(gobj);
795 if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm))
798 r = radeon_bo_reserve(robj, false);
803 case RADEON_GEM_OP_GET_INITIAL_DOMAIN:
804 args->value = robj->initial_domain;
806 case RADEON_GEM_OP_SET_INITIAL_DOMAIN:
807 robj->initial_domain = args->value & (RADEON_GEM_DOMAIN_VRAM |
808 RADEON_GEM_DOMAIN_GTT |
809 RADEON_GEM_DOMAIN_CPU);
815 radeon_bo_unreserve(robj);
817 drm_gem_object_put(gobj);
821 int radeon_mode_dumb_create(struct drm_file *file_priv,
822 struct drm_device *dev,
823 struct drm_mode_create_dumb *args)
825 struct radeon_device *rdev = dev->dev_private;
826 struct drm_gem_object *gobj;
830 args->pitch = radeon_align_pitch(rdev, args->width,
831 DIV_ROUND_UP(args->bpp, 8), 0);
832 args->size = args->pitch * args->height;
833 args->size = ALIGN(args->size, PAGE_SIZE);
835 r = radeon_gem_object_create(rdev, args->size, 0,
836 RADEON_GEM_DOMAIN_VRAM, 0,
841 r = drm_gem_handle_create(file_priv, gobj, &handle);
842 /* drop reference from allocate - handle holds it now */
843 drm_gem_object_put(gobj);
847 args->handle = handle;
851 #if defined(CONFIG_DEBUG_FS)
852 static int radeon_debugfs_gem_info_show(struct seq_file *m, void *unused)
854 struct radeon_device *rdev = (struct radeon_device *)m->private;
855 struct radeon_bo *rbo;
858 mutex_lock(&rdev->gem.mutex);
859 list_for_each_entry(rbo, &rdev->gem.objects, list) {
861 const char *placement;
863 domain = radeon_mem_type_to_domain(rbo->tbo.resource->mem_type);
865 case RADEON_GEM_DOMAIN_VRAM:
868 case RADEON_GEM_DOMAIN_GTT:
871 case RADEON_GEM_DOMAIN_CPU:
876 seq_printf(m, "bo[0x%08x] %8ldkB %8ldMB %s pid %8ld\n",
877 i, radeon_bo_size(rbo) >> 10, radeon_bo_size(rbo) >> 20,
878 placement, (unsigned long)rbo->pid);
881 mutex_unlock(&rdev->gem.mutex);
885 DEFINE_SHOW_ATTRIBUTE(radeon_debugfs_gem_info);
888 void radeon_gem_debugfs_init(struct radeon_device *rdev)
890 #if defined(CONFIG_DEBUG_FS)
891 struct dentry *root = rdev->ddev->primary->debugfs_root;
893 debugfs_create_file("radeon_gem_info", 0444, root, rdev,
894 &radeon_debugfs_gem_info_fops);