1926deccbSFrançois Tigeot /* 2926deccbSFrançois Tigeot * Copyright 2008 Advanced Micro Devices, Inc. 3926deccbSFrançois Tigeot * Copyright 2008 Red Hat Inc. 4926deccbSFrançois Tigeot * Copyright 2009 Jerome Glisse. 5926deccbSFrançois Tigeot * 6926deccbSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a 7926deccbSFrançois Tigeot * copy of this software and associated documentation files (the "Software"), 8926deccbSFrançois Tigeot * to deal in the Software without restriction, including without limitation 9926deccbSFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10926deccbSFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the 11926deccbSFrançois Tigeot * Software is furnished to do so, subject to the following conditions: 12926deccbSFrançois Tigeot * 13926deccbSFrançois Tigeot * The above copyright notice and this permission notice shall be included in 14926deccbSFrançois Tigeot * all copies or substantial portions of the Software. 15926deccbSFrançois Tigeot * 16926deccbSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17926deccbSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18926deccbSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19926deccbSFrançois Tigeot * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 20926deccbSFrançois Tigeot * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21926deccbSFrançois Tigeot * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22926deccbSFrançois Tigeot * OTHER DEALINGS IN THE SOFTWARE. 23926deccbSFrançois Tigeot * 24926deccbSFrançois Tigeot * Authors: Dave Airlie 25926deccbSFrançois Tigeot * Alex Deucher 26926deccbSFrançois Tigeot * Jerome Glisse 27926deccbSFrançois Tigeot * 28926deccbSFrançois Tigeot * $FreeBSD: head/sys/dev/drm2/radeon/radeon_gem.c 254885 2013-08-25 19:37:15Z dumbbell $ 29926deccbSFrançois Tigeot */ 30926deccbSFrançois Tigeot 31926deccbSFrançois Tigeot #include <drm/drmP.h> 3283b4b9b9SFrançois Tigeot #include <drm/radeon_drm.h> 33926deccbSFrançois Tigeot #include "radeon.h" 34926deccbSFrançois Tigeot #include "radeon_gem.h" 35926deccbSFrançois Tigeot 36926deccbSFrançois Tigeot void radeon_gem_object_free(struct drm_gem_object *gobj) 37926deccbSFrançois Tigeot { 38926deccbSFrançois Tigeot struct radeon_bo *robj = gem_to_radeon_bo(gobj); 39926deccbSFrançois Tigeot 40926deccbSFrançois Tigeot if (robj) { 41926deccbSFrançois Tigeot #ifdef DUMBBELL_WIP 42926deccbSFrançois Tigeot if (robj->gem_base.import_attach) 43926deccbSFrançois Tigeot drm_prime_gem_destroy(&robj->gem_base, robj->tbo.sg); 44926deccbSFrançois Tigeot #endif /* DUMBBELL_WIP */ 45926deccbSFrançois Tigeot radeon_bo_unref(&robj); 46926deccbSFrançois Tigeot } 47926deccbSFrançois Tigeot } 48926deccbSFrançois Tigeot 49c6f73aabSFrançois Tigeot int radeon_gem_object_create(struct radeon_device *rdev, unsigned long size, 50926deccbSFrançois Tigeot int alignment, int initial_domain, 51c6f73aabSFrançois Tigeot u32 flags, bool kernel, 52926deccbSFrançois Tigeot struct drm_gem_object **obj) 53926deccbSFrançois Tigeot { 54926deccbSFrançois Tigeot struct radeon_bo *robj; 55926deccbSFrançois Tigeot unsigned long max_size; 56926deccbSFrançois Tigeot int r; 57926deccbSFrançois Tigeot 58926deccbSFrançois Tigeot *obj = NULL; 59926deccbSFrançois Tigeot /* At least align on page size */ 60926deccbSFrançois Tigeot if (alignment < PAGE_SIZE) { 61926deccbSFrançois Tigeot alignment = PAGE_SIZE; 62926deccbSFrançois Tigeot } 63926deccbSFrançois Tigeot 64c6f73aabSFrançois Tigeot /* Maximum bo size is the unpinned gtt size since we use the gtt to 65c6f73aabSFrançois Tigeot * handle vram to system pool migrations. 66c6f73aabSFrançois Tigeot */ 67c6f73aabSFrançois Tigeot max_size = rdev->mc.gtt_size - rdev->gart_pin_size; 68926deccbSFrançois Tigeot if (size > max_size) { 69c6f73aabSFrançois Tigeot DRM_DEBUG("Allocation size %ldMb bigger than %ldMb limit\n", 70c6f73aabSFrançois Tigeot size >> 20, max_size >> 20); 71926deccbSFrançois Tigeot return -ENOMEM; 72926deccbSFrançois Tigeot } 73926deccbSFrançois Tigeot 74926deccbSFrançois Tigeot retry: 75c6f73aabSFrançois Tigeot r = radeon_bo_create(rdev, size, alignment, kernel, initial_domain, 76c6f73aabSFrançois Tigeot flags, NULL, &robj); 77926deccbSFrançois Tigeot if (r) { 78797013cfSFrançois Tigeot if (r != -ERESTARTSYS) { 79926deccbSFrançois Tigeot if (initial_domain == RADEON_GEM_DOMAIN_VRAM) { 80926deccbSFrançois Tigeot initial_domain |= RADEON_GEM_DOMAIN_GTT; 81926deccbSFrançois Tigeot goto retry; 82926deccbSFrançois Tigeot } 83c6f73aabSFrançois Tigeot DRM_ERROR("Failed to allocate GEM object (%ld, %d, %u, %d)\n", 84926deccbSFrançois Tigeot size, initial_domain, alignment, r); 85926deccbSFrançois Tigeot } 86926deccbSFrançois Tigeot return r; 87926deccbSFrançois Tigeot } 88926deccbSFrançois Tigeot *obj = &robj->gem_base; 89f43cf1b1SMichael Neumann robj->pid = curproc ? curproc->p_pid : 0; 90926deccbSFrançois Tigeot 91fefad7a7SFrançois Tigeot mutex_lock(&rdev->gem.mutex); 92926deccbSFrançois Tigeot list_add_tail(&robj->list, &rdev->gem.objects); 93fefad7a7SFrançois Tigeot mutex_unlock(&rdev->gem.mutex); 94926deccbSFrançois Tigeot 95926deccbSFrançois Tigeot return 0; 96926deccbSFrançois Tigeot } 97926deccbSFrançois Tigeot 98926deccbSFrançois Tigeot static int radeon_gem_set_domain(struct drm_gem_object *gobj, 99926deccbSFrançois Tigeot uint32_t rdomain, uint32_t wdomain) 100926deccbSFrançois Tigeot { 101926deccbSFrançois Tigeot struct radeon_bo *robj; 102926deccbSFrançois Tigeot uint32_t domain; 103*1cfef1a5SFrançois Tigeot long r; 104926deccbSFrançois Tigeot 105926deccbSFrançois Tigeot /* FIXME: reeimplement */ 106926deccbSFrançois Tigeot robj = gem_to_radeon_bo(gobj); 107926deccbSFrançois Tigeot /* work out where to validate the buffer to */ 108926deccbSFrançois Tigeot domain = wdomain; 109926deccbSFrançois Tigeot if (!domain) { 110926deccbSFrançois Tigeot domain = rdomain; 111926deccbSFrançois Tigeot } 112926deccbSFrançois Tigeot if (!domain) { 113926deccbSFrançois Tigeot /* Do nothings */ 114c4ef309bSzrj printk(KERN_WARNING "Set domain without domain !\n"); 115926deccbSFrançois Tigeot return 0; 116926deccbSFrançois Tigeot } 117926deccbSFrançois Tigeot if (domain == RADEON_GEM_DOMAIN_CPU) { 118926deccbSFrançois Tigeot /* Asking for cpu access wait for object idle */ 119*1cfef1a5SFrançois Tigeot r = reservation_object_wait_timeout_rcu(robj->tbo.resv, true, true, 30 * HZ); 120*1cfef1a5SFrançois Tigeot if (!r) 121*1cfef1a5SFrançois Tigeot r = -EBUSY; 122*1cfef1a5SFrançois Tigeot 123*1cfef1a5SFrançois Tigeot if (r < 0 && r != -EINTR) { 124*1cfef1a5SFrançois Tigeot printk(KERN_ERR "Failed to wait for object: %li\n", r); 125926deccbSFrançois Tigeot return r; 126926deccbSFrançois Tigeot } 127926deccbSFrançois Tigeot } 128926deccbSFrançois Tigeot return 0; 129926deccbSFrançois Tigeot } 130926deccbSFrançois Tigeot 131926deccbSFrançois Tigeot int radeon_gem_init(struct radeon_device *rdev) 132926deccbSFrançois Tigeot { 133926deccbSFrançois Tigeot INIT_LIST_HEAD(&rdev->gem.objects); 134926deccbSFrançois Tigeot return 0; 135926deccbSFrançois Tigeot } 136926deccbSFrançois Tigeot 137926deccbSFrançois Tigeot void radeon_gem_fini(struct radeon_device *rdev) 138926deccbSFrançois Tigeot { 139926deccbSFrançois Tigeot radeon_bo_force_delete(rdev); 140926deccbSFrançois Tigeot } 141926deccbSFrançois Tigeot 142926deccbSFrançois Tigeot /* 143926deccbSFrançois Tigeot * Call from drm_gem_handle_create which appear in both new and open ioctl 144926deccbSFrançois Tigeot * case. 145926deccbSFrançois Tigeot */ 146926deccbSFrançois Tigeot int radeon_gem_object_open(struct drm_gem_object *obj, struct drm_file *file_priv) 147926deccbSFrançois Tigeot { 148926deccbSFrançois Tigeot struct radeon_bo *rbo = gem_to_radeon_bo(obj); 149926deccbSFrançois Tigeot struct radeon_device *rdev = rbo->rdev; 150926deccbSFrançois Tigeot struct radeon_fpriv *fpriv = file_priv->driver_priv; 151926deccbSFrançois Tigeot struct radeon_vm *vm = &fpriv->vm; 152926deccbSFrançois Tigeot struct radeon_bo_va *bo_va; 153926deccbSFrançois Tigeot int r; 154926deccbSFrançois Tigeot 155ee479021SImre Vadász if (rdev->family < CHIP_CAYMAN) { 156926deccbSFrançois Tigeot return 0; 157926deccbSFrançois Tigeot } 158926deccbSFrançois Tigeot 159926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 160926deccbSFrançois Tigeot if (r) { 161926deccbSFrançois Tigeot return r; 162926deccbSFrançois Tigeot } 163926deccbSFrançois Tigeot 164926deccbSFrançois Tigeot bo_va = radeon_vm_bo_find(vm, rbo); 165926deccbSFrançois Tigeot if (!bo_va) { 166926deccbSFrançois Tigeot bo_va = radeon_vm_bo_add(rdev, vm, rbo); 167926deccbSFrançois Tigeot } else { 168926deccbSFrançois Tigeot ++bo_va->ref_count; 169926deccbSFrançois Tigeot } 170926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 171926deccbSFrançois Tigeot 172926deccbSFrançois Tigeot return 0; 173926deccbSFrançois Tigeot } 174926deccbSFrançois Tigeot 175926deccbSFrançois Tigeot void radeon_gem_object_close(struct drm_gem_object *obj, 176926deccbSFrançois Tigeot struct drm_file *file_priv) 177926deccbSFrançois Tigeot { 178926deccbSFrançois Tigeot struct radeon_bo *rbo = gem_to_radeon_bo(obj); 179926deccbSFrançois Tigeot struct radeon_device *rdev = rbo->rdev; 180926deccbSFrançois Tigeot struct radeon_fpriv *fpriv = file_priv->driver_priv; 181926deccbSFrançois Tigeot struct radeon_vm *vm = &fpriv->vm; 182926deccbSFrançois Tigeot struct radeon_bo_va *bo_va; 183926deccbSFrançois Tigeot int r; 184926deccbSFrançois Tigeot 185ee479021SImre Vadász if (rdev->family < CHIP_CAYMAN) { 186926deccbSFrançois Tigeot return; 187926deccbSFrançois Tigeot } 188926deccbSFrançois Tigeot 189926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, true); 190926deccbSFrançois Tigeot if (r) { 191926deccbSFrançois Tigeot dev_err(rdev->dev, "leaking bo va because " 192926deccbSFrançois Tigeot "we fail to reserve bo (%d)\n", r); 193926deccbSFrançois Tigeot return; 194926deccbSFrançois Tigeot } 195926deccbSFrançois Tigeot bo_va = radeon_vm_bo_find(vm, rbo); 196926deccbSFrançois Tigeot if (bo_va) { 197926deccbSFrançois Tigeot if (--bo_va->ref_count == 0) { 198926deccbSFrançois Tigeot radeon_vm_bo_rmv(rdev, bo_va); 199926deccbSFrançois Tigeot } 200926deccbSFrançois Tigeot } 201926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 202926deccbSFrançois Tigeot } 203926deccbSFrançois Tigeot 204926deccbSFrançois Tigeot static int radeon_gem_handle_lockup(struct radeon_device *rdev, int r) 205926deccbSFrançois Tigeot { 206926deccbSFrançois Tigeot if (r == -EDEADLK) { 207926deccbSFrançois Tigeot r = radeon_gpu_reset(rdev); 208926deccbSFrançois Tigeot if (!r) 209926deccbSFrançois Tigeot r = -EAGAIN; 210926deccbSFrançois Tigeot } 211926deccbSFrançois Tigeot return r; 212926deccbSFrançois Tigeot } 213926deccbSFrançois Tigeot 214926deccbSFrançois Tigeot /* 215926deccbSFrançois Tigeot * GEM ioctls. 216926deccbSFrançois Tigeot */ 217926deccbSFrançois Tigeot int radeon_gem_info_ioctl(struct drm_device *dev, void *data, 218926deccbSFrançois Tigeot struct drm_file *filp) 219926deccbSFrançois Tigeot { 220926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 221926deccbSFrançois Tigeot struct drm_radeon_gem_info *args = data; 222926deccbSFrançois Tigeot struct ttm_mem_type_manager *man; 223926deccbSFrançois Tigeot 224926deccbSFrançois Tigeot man = &rdev->mman.bdev.man[TTM_PL_VRAM]; 225926deccbSFrançois Tigeot 226926deccbSFrançois Tigeot args->vram_size = rdev->mc.real_vram_size; 227926deccbSFrançois Tigeot args->vram_visible = (u64)man->size << PAGE_SHIFT; 228c6f73aabSFrançois Tigeot args->vram_visible -= rdev->vram_pin_size; 229c6f73aabSFrançois Tigeot args->gart_size = rdev->mc.gtt_size; 230c6f73aabSFrançois Tigeot args->gart_size -= rdev->gart_pin_size; 231c6f73aabSFrançois Tigeot 232926deccbSFrançois Tigeot return 0; 233926deccbSFrançois Tigeot } 234926deccbSFrançois Tigeot 235926deccbSFrançois Tigeot int radeon_gem_pread_ioctl(struct drm_device *dev, void *data, 236926deccbSFrançois Tigeot struct drm_file *filp) 237926deccbSFrançois Tigeot { 238926deccbSFrançois Tigeot /* TODO: implement */ 239926deccbSFrançois Tigeot DRM_ERROR("unimplemented %s\n", __func__); 240926deccbSFrançois Tigeot return -ENOSYS; 241926deccbSFrançois Tigeot } 242926deccbSFrançois Tigeot 243926deccbSFrançois Tigeot int radeon_gem_pwrite_ioctl(struct drm_device *dev, void *data, 244926deccbSFrançois Tigeot struct drm_file *filp) 245926deccbSFrançois Tigeot { 246926deccbSFrançois Tigeot /* TODO: implement */ 247926deccbSFrançois Tigeot DRM_ERROR("unimplemented %s\n", __func__); 248926deccbSFrançois Tigeot return -ENOSYS; 249926deccbSFrançois Tigeot } 250926deccbSFrançois Tigeot 251926deccbSFrançois Tigeot int radeon_gem_create_ioctl(struct drm_device *dev, void *data, 252926deccbSFrançois Tigeot struct drm_file *filp) 253926deccbSFrançois Tigeot { 254926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 255926deccbSFrançois Tigeot struct drm_radeon_gem_create *args = data; 256926deccbSFrançois Tigeot struct drm_gem_object *gobj; 257926deccbSFrançois Tigeot uint32_t handle; 258926deccbSFrançois Tigeot int r; 259926deccbSFrançois Tigeot 260926deccbSFrançois Tigeot lockmgr(&rdev->exclusive_lock, LK_SHARED); 261926deccbSFrançois Tigeot /* create a gem object to contain this object in */ 262926deccbSFrançois Tigeot args->size = roundup(args->size, PAGE_SIZE); 263926deccbSFrançois Tigeot r = radeon_gem_object_create(rdev, args->size, args->alignment, 264c6f73aabSFrançois Tigeot args->initial_domain, args->flags, 265926deccbSFrançois Tigeot false, &gobj); 266926deccbSFrançois Tigeot if (r) { 26763c3939fSImre Vadasz if (r == -ERESTARTSYS) 26863c3939fSImre Vadasz r = -EINTR; 269926deccbSFrançois Tigeot lockmgr(&rdev->exclusive_lock, LK_RELEASE); 270926deccbSFrançois Tigeot r = radeon_gem_handle_lockup(rdev, r); 271926deccbSFrançois Tigeot return r; 272926deccbSFrançois Tigeot } 273926deccbSFrançois Tigeot handle = 0; 274926deccbSFrançois Tigeot r = drm_gem_handle_create(filp, gobj, &handle); 275926deccbSFrançois Tigeot /* drop reference from allocate - handle holds it now */ 276926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 277926deccbSFrançois Tigeot if (r) { 278926deccbSFrançois Tigeot lockmgr(&rdev->exclusive_lock, LK_RELEASE); 279926deccbSFrançois Tigeot r = radeon_gem_handle_lockup(rdev, r); 280926deccbSFrançois Tigeot return r; 281926deccbSFrançois Tigeot } 282926deccbSFrançois Tigeot args->handle = handle; 283926deccbSFrançois Tigeot lockmgr(&rdev->exclusive_lock, LK_RELEASE); 284926deccbSFrançois Tigeot return 0; 285926deccbSFrançois Tigeot } 286926deccbSFrançois Tigeot 287*1cfef1a5SFrançois Tigeot #if 0 288*1cfef1a5SFrançois Tigeot int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data, 289*1cfef1a5SFrançois Tigeot struct drm_file *filp) 290*1cfef1a5SFrançois Tigeot { 291*1cfef1a5SFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 292*1cfef1a5SFrançois Tigeot struct drm_radeon_gem_userptr *args = data; 293*1cfef1a5SFrançois Tigeot struct drm_gem_object *gobj; 294*1cfef1a5SFrançois Tigeot struct radeon_bo *bo; 295*1cfef1a5SFrançois Tigeot uint32_t handle; 296*1cfef1a5SFrançois Tigeot int r; 297*1cfef1a5SFrançois Tigeot 298*1cfef1a5SFrançois Tigeot if (offset_in_page(args->addr | args->size)) 299*1cfef1a5SFrançois Tigeot return -EINVAL; 300*1cfef1a5SFrançois Tigeot 301*1cfef1a5SFrançois Tigeot /* reject unknown flag values */ 302*1cfef1a5SFrançois Tigeot if (args->flags & ~(RADEON_GEM_USERPTR_READONLY | 303*1cfef1a5SFrançois Tigeot RADEON_GEM_USERPTR_ANONONLY | RADEON_GEM_USERPTR_VALIDATE | 304*1cfef1a5SFrançois Tigeot RADEON_GEM_USERPTR_REGISTER)) 305*1cfef1a5SFrançois Tigeot return -EINVAL; 306*1cfef1a5SFrançois Tigeot 307*1cfef1a5SFrançois Tigeot if (args->flags & RADEON_GEM_USERPTR_READONLY) { 308*1cfef1a5SFrançois Tigeot /* readonly pages not tested on older hardware */ 309*1cfef1a5SFrançois Tigeot if (rdev->family < CHIP_R600) 310*1cfef1a5SFrançois Tigeot return -EINVAL; 311*1cfef1a5SFrançois Tigeot 312*1cfef1a5SFrançois Tigeot } else if (!(args->flags & RADEON_GEM_USERPTR_ANONONLY) || 313*1cfef1a5SFrançois Tigeot !(args->flags & RADEON_GEM_USERPTR_REGISTER)) { 314*1cfef1a5SFrançois Tigeot 315*1cfef1a5SFrançois Tigeot /* if we want to write to it we must require anonymous 316*1cfef1a5SFrançois Tigeot memory and install a MMU notifier */ 317*1cfef1a5SFrançois Tigeot return -EACCES; 318*1cfef1a5SFrançois Tigeot } 319*1cfef1a5SFrançois Tigeot 320*1cfef1a5SFrançois Tigeot down_read(&rdev->exclusive_lock); 321*1cfef1a5SFrançois Tigeot 322*1cfef1a5SFrançois Tigeot /* create a gem object to contain this object in */ 323*1cfef1a5SFrançois Tigeot r = radeon_gem_object_create(rdev, args->size, 0, 324*1cfef1a5SFrançois Tigeot RADEON_GEM_DOMAIN_CPU, 0, 325*1cfef1a5SFrançois Tigeot false, &gobj); 326*1cfef1a5SFrançois Tigeot if (r) 327*1cfef1a5SFrançois Tigeot goto handle_lockup; 328*1cfef1a5SFrançois Tigeot 329*1cfef1a5SFrançois Tigeot bo = gem_to_radeon_bo(gobj); 330*1cfef1a5SFrançois Tigeot r = radeon_ttm_tt_set_userptr(bo->tbo.ttm, args->addr, args->flags); 331*1cfef1a5SFrançois Tigeot if (r) 332*1cfef1a5SFrançois Tigeot goto release_object; 333*1cfef1a5SFrançois Tigeot 334*1cfef1a5SFrançois Tigeot if (args->flags & RADEON_GEM_USERPTR_REGISTER) { 335*1cfef1a5SFrançois Tigeot r = radeon_mn_register(bo, args->addr); 336*1cfef1a5SFrançois Tigeot if (r) 337*1cfef1a5SFrançois Tigeot goto release_object; 338*1cfef1a5SFrançois Tigeot } 339*1cfef1a5SFrançois Tigeot 340*1cfef1a5SFrançois Tigeot if (args->flags & RADEON_GEM_USERPTR_VALIDATE) { 341*1cfef1a5SFrançois Tigeot down_read(¤t->mm->mmap_sem); 342*1cfef1a5SFrançois Tigeot r = radeon_bo_reserve(bo, true); 343*1cfef1a5SFrançois Tigeot if (r) { 344*1cfef1a5SFrançois Tigeot up_read(¤t->mm->mmap_sem); 345*1cfef1a5SFrançois Tigeot goto release_object; 346*1cfef1a5SFrançois Tigeot } 347*1cfef1a5SFrançois Tigeot 348*1cfef1a5SFrançois Tigeot radeon_ttm_placement_from_domain(bo, RADEON_GEM_DOMAIN_GTT); 349*1cfef1a5SFrançois Tigeot r = ttm_bo_validate(&bo->tbo, &bo->placement, true, false); 350*1cfef1a5SFrançois Tigeot radeon_bo_unreserve(bo); 351*1cfef1a5SFrançois Tigeot up_read(¤t->mm->mmap_sem); 352*1cfef1a5SFrançois Tigeot if (r) 353*1cfef1a5SFrançois Tigeot goto release_object; 354*1cfef1a5SFrançois Tigeot } 355*1cfef1a5SFrançois Tigeot 356*1cfef1a5SFrançois Tigeot r = drm_gem_handle_create(filp, gobj, &handle); 357*1cfef1a5SFrançois Tigeot /* drop reference from allocate - handle holds it now */ 358*1cfef1a5SFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 359*1cfef1a5SFrançois Tigeot if (r) 360*1cfef1a5SFrançois Tigeot goto handle_lockup; 361*1cfef1a5SFrançois Tigeot 362*1cfef1a5SFrançois Tigeot args->handle = handle; 363*1cfef1a5SFrançois Tigeot up_read(&rdev->exclusive_lock); 364*1cfef1a5SFrançois Tigeot return 0; 365*1cfef1a5SFrançois Tigeot 366*1cfef1a5SFrançois Tigeot release_object: 367*1cfef1a5SFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 368*1cfef1a5SFrançois Tigeot 369*1cfef1a5SFrançois Tigeot handle_lockup: 370*1cfef1a5SFrançois Tigeot up_read(&rdev->exclusive_lock); 371*1cfef1a5SFrançois Tigeot r = radeon_gem_handle_lockup(rdev, r); 372*1cfef1a5SFrançois Tigeot 373*1cfef1a5SFrançois Tigeot return r; 374*1cfef1a5SFrançois Tigeot } 375*1cfef1a5SFrançois Tigeot #endif 376*1cfef1a5SFrançois Tigeot 377926deccbSFrançois Tigeot int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data, 378926deccbSFrançois Tigeot struct drm_file *filp) 379926deccbSFrançois Tigeot { 380926deccbSFrançois Tigeot /* transition the BO to a domain - 381926deccbSFrançois Tigeot * just validate the BO into a certain domain */ 382926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 383926deccbSFrançois Tigeot struct drm_radeon_gem_set_domain *args = data; 384926deccbSFrançois Tigeot struct drm_gem_object *gobj; 385926deccbSFrançois Tigeot struct radeon_bo *robj; 386926deccbSFrançois Tigeot int r; 387926deccbSFrançois Tigeot 388926deccbSFrançois Tigeot /* for now if someone requests domain CPU - 389926deccbSFrançois Tigeot * just make sure the buffer is finished with */ 390926deccbSFrançois Tigeot lockmgr(&rdev->exclusive_lock, LK_SHARED); 391926deccbSFrançois Tigeot 392926deccbSFrançois Tigeot /* just do a BO wait for now */ 3938621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, args->handle); 394926deccbSFrançois Tigeot if (gobj == NULL) { 395926deccbSFrançois Tigeot lockmgr(&rdev->exclusive_lock, LK_RELEASE); 396926deccbSFrançois Tigeot return -ENOENT; 397926deccbSFrançois Tigeot } 398926deccbSFrançois Tigeot robj = gem_to_radeon_bo(gobj); 399926deccbSFrançois Tigeot 400926deccbSFrançois Tigeot r = radeon_gem_set_domain(gobj, args->read_domains, args->write_domain); 401926deccbSFrançois Tigeot 402926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 403926deccbSFrançois Tigeot lockmgr(&rdev->exclusive_lock, LK_RELEASE); 404926deccbSFrançois Tigeot r = radeon_gem_handle_lockup(robj->rdev, r); 405926deccbSFrançois Tigeot return r; 406926deccbSFrançois Tigeot } 407926deccbSFrançois Tigeot 408926deccbSFrançois Tigeot int radeon_mode_dumb_mmap(struct drm_file *filp, 409926deccbSFrançois Tigeot struct drm_device *dev, 410926deccbSFrançois Tigeot uint32_t handle, uint64_t *offset_p) 411926deccbSFrançois Tigeot { 412926deccbSFrançois Tigeot struct drm_gem_object *gobj; 413926deccbSFrançois Tigeot struct radeon_bo *robj; 414926deccbSFrançois Tigeot 4158621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, handle); 416926deccbSFrançois Tigeot if (gobj == NULL) { 417926deccbSFrançois Tigeot return -ENOENT; 418926deccbSFrançois Tigeot } 419926deccbSFrançois Tigeot robj = gem_to_radeon_bo(gobj); 420926deccbSFrançois Tigeot *offset_p = radeon_bo_mmap_offset(robj); 421926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 422926deccbSFrançois Tigeot return 0; 423926deccbSFrançois Tigeot } 424926deccbSFrançois Tigeot 425926deccbSFrançois Tigeot int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data, 426926deccbSFrançois Tigeot struct drm_file *filp) 427926deccbSFrançois Tigeot { 428926deccbSFrançois Tigeot struct drm_radeon_gem_mmap *args = data; 429926deccbSFrançois Tigeot 430f77dbd6cSFrançois Tigeot return radeon_mode_dumb_mmap(filp, dev, args->handle, (uint64_t *)&args->addr_ptr); 431926deccbSFrançois Tigeot } 432926deccbSFrançois Tigeot 433926deccbSFrançois Tigeot int radeon_gem_busy_ioctl(struct drm_device *dev, void *data, 434926deccbSFrançois Tigeot struct drm_file *filp) 435926deccbSFrançois Tigeot { 436926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 437926deccbSFrançois Tigeot struct drm_radeon_gem_busy *args = data; 438926deccbSFrançois Tigeot struct drm_gem_object *gobj; 439926deccbSFrançois Tigeot struct radeon_bo *robj; 440926deccbSFrançois Tigeot int r; 441926deccbSFrançois Tigeot uint32_t cur_placement = 0; 442926deccbSFrançois Tigeot 4438621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, args->handle); 444926deccbSFrançois Tigeot if (gobj == NULL) { 445926deccbSFrançois Tigeot return -ENOENT; 446926deccbSFrançois Tigeot } 447926deccbSFrançois Tigeot robj = gem_to_radeon_bo(gobj); 448926deccbSFrançois Tigeot r = radeon_bo_wait(robj, &cur_placement, true); 449c6f73aabSFrançois Tigeot args->domain = radeon_mem_type_to_domain(cur_placement); 450926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 451926deccbSFrançois Tigeot r = radeon_gem_handle_lockup(rdev, r); 452926deccbSFrançois Tigeot return r; 453926deccbSFrançois Tigeot } 454926deccbSFrançois Tigeot 455926deccbSFrançois Tigeot int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, 456926deccbSFrançois Tigeot struct drm_file *filp) 457926deccbSFrançois Tigeot { 458926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 459926deccbSFrançois Tigeot struct drm_radeon_gem_wait_idle *args = data; 460926deccbSFrançois Tigeot struct drm_gem_object *gobj; 461926deccbSFrançois Tigeot struct radeon_bo *robj; 462*1cfef1a5SFrançois Tigeot int r = 0; 463c6f73aabSFrançois Tigeot uint32_t cur_placement = 0; 464*1cfef1a5SFrançois Tigeot long ret; 465926deccbSFrançois Tigeot 4668621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, args->handle); 467926deccbSFrançois Tigeot if (gobj == NULL) { 468926deccbSFrançois Tigeot return -ENOENT; 469926deccbSFrançois Tigeot } 470926deccbSFrançois Tigeot robj = gem_to_radeon_bo(gobj); 471*1cfef1a5SFrançois Tigeot 472*1cfef1a5SFrançois Tigeot ret = reservation_object_wait_timeout_rcu(robj->tbo.resv, true, true, 30 * HZ); 473*1cfef1a5SFrançois Tigeot if (ret == 0) 474*1cfef1a5SFrançois Tigeot r = -EBUSY; 475*1cfef1a5SFrançois Tigeot else if (ret < 0) 476*1cfef1a5SFrançois Tigeot r = ret; 477*1cfef1a5SFrançois Tigeot 478c6f73aabSFrançois Tigeot /* Flush HDP cache via MMIO if necessary */ 479c6f73aabSFrançois Tigeot if (rdev->asic->mmio_hdp_flush && 480c6f73aabSFrançois Tigeot radeon_mem_type_to_domain(cur_placement) == RADEON_GEM_DOMAIN_VRAM) 481c6f73aabSFrançois Tigeot robj->rdev->asic->mmio_hdp_flush(rdev); 482926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 48363c3939fSImre Vadasz if (r == -ERESTARTSYS) 48463c3939fSImre Vadasz r = -EINTR; 485926deccbSFrançois Tigeot r = radeon_gem_handle_lockup(rdev, r); 486926deccbSFrançois Tigeot return r; 487926deccbSFrançois Tigeot } 488926deccbSFrançois Tigeot 489926deccbSFrançois Tigeot int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data, 490926deccbSFrançois Tigeot struct drm_file *filp) 491926deccbSFrançois Tigeot { 492926deccbSFrançois Tigeot struct drm_radeon_gem_set_tiling *args = data; 493926deccbSFrançois Tigeot struct drm_gem_object *gobj; 494926deccbSFrançois Tigeot struct radeon_bo *robj; 495926deccbSFrançois Tigeot int r = 0; 496926deccbSFrançois Tigeot 497926deccbSFrançois Tigeot DRM_DEBUG("%d \n", args->handle); 4988621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, args->handle); 499926deccbSFrançois Tigeot if (gobj == NULL) 500926deccbSFrançois Tigeot return -ENOENT; 501926deccbSFrançois Tigeot robj = gem_to_radeon_bo(gobj); 502926deccbSFrançois Tigeot r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch); 503926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 504926deccbSFrançois Tigeot return r; 505926deccbSFrançois Tigeot } 506926deccbSFrançois Tigeot 507926deccbSFrançois Tigeot int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data, 508926deccbSFrançois Tigeot struct drm_file *filp) 509926deccbSFrançois Tigeot { 510926deccbSFrançois Tigeot struct drm_radeon_gem_get_tiling *args = data; 511926deccbSFrançois Tigeot struct drm_gem_object *gobj; 512926deccbSFrançois Tigeot struct radeon_bo *rbo; 513926deccbSFrançois Tigeot int r = 0; 514926deccbSFrançois Tigeot 515926deccbSFrançois Tigeot DRM_DEBUG("\n"); 5168621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, args->handle); 517926deccbSFrançois Tigeot if (gobj == NULL) 518926deccbSFrançois Tigeot return -ENOENT; 519926deccbSFrançois Tigeot rbo = gem_to_radeon_bo(gobj); 520926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 521926deccbSFrançois Tigeot if (unlikely(r != 0)) 522926deccbSFrançois Tigeot goto out; 523926deccbSFrançois Tigeot radeon_bo_get_tiling_flags(rbo, &args->tiling_flags, &args->pitch); 524926deccbSFrançois Tigeot radeon_bo_unreserve(rbo); 525926deccbSFrançois Tigeot out: 526926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 527926deccbSFrançois Tigeot return r; 528926deccbSFrançois Tigeot } 529926deccbSFrançois Tigeot 530926deccbSFrançois Tigeot int radeon_gem_va_ioctl(struct drm_device *dev, void *data, 531926deccbSFrançois Tigeot struct drm_file *filp) 532926deccbSFrançois Tigeot { 533926deccbSFrançois Tigeot struct drm_radeon_gem_va *args = data; 534926deccbSFrançois Tigeot struct drm_gem_object *gobj; 535926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 536926deccbSFrançois Tigeot struct radeon_fpriv *fpriv = filp->driver_priv; 537926deccbSFrançois Tigeot struct radeon_bo *rbo; 538926deccbSFrançois Tigeot struct radeon_bo_va *bo_va; 539926deccbSFrançois Tigeot u32 invalid_flags; 540926deccbSFrançois Tigeot int r = 0; 541926deccbSFrançois Tigeot 542926deccbSFrançois Tigeot if (!rdev->vm_manager.enabled) { 543926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 544926deccbSFrançois Tigeot return -ENOTTY; 545926deccbSFrançois Tigeot } 546926deccbSFrançois Tigeot 547926deccbSFrançois Tigeot /* !! DONT REMOVE !! 548926deccbSFrançois Tigeot * We don't support vm_id yet, to be sure we don't have have broken 549926deccbSFrançois Tigeot * userspace, reject anyone trying to use non 0 value thus moving 550926deccbSFrançois Tigeot * forward we can use those fields without breaking existant userspace 551926deccbSFrançois Tigeot */ 552926deccbSFrançois Tigeot if (args->vm_id) { 553926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 554926deccbSFrançois Tigeot return -EINVAL; 555926deccbSFrançois Tigeot } 556926deccbSFrançois Tigeot 557926deccbSFrançois Tigeot if (args->offset < RADEON_VA_RESERVED_SIZE) { 558fb572d17SFrançois Tigeot dev_err(&dev->pdev->dev, 559926deccbSFrançois Tigeot "offset 0x%lX is in reserved area 0x%X\n", 560926deccbSFrançois Tigeot (unsigned long)args->offset, 561926deccbSFrançois Tigeot RADEON_VA_RESERVED_SIZE); 562926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 563926deccbSFrançois Tigeot return -EINVAL; 564926deccbSFrançois Tigeot } 565926deccbSFrançois Tigeot 566926deccbSFrançois Tigeot /* don't remove, we need to enforce userspace to set the snooped flag 567926deccbSFrançois Tigeot * otherwise we will endup with broken userspace and we won't be able 568926deccbSFrançois Tigeot * to enable this feature without adding new interface 569926deccbSFrançois Tigeot */ 570926deccbSFrançois Tigeot invalid_flags = RADEON_VM_PAGE_VALID | RADEON_VM_PAGE_SYSTEM; 571926deccbSFrançois Tigeot if ((args->flags & invalid_flags)) { 572fb572d17SFrançois Tigeot dev_err(&dev->pdev->dev, "invalid flags 0x%08X vs 0x%08X\n", 573926deccbSFrançois Tigeot args->flags, invalid_flags); 574926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 575926deccbSFrançois Tigeot return -EINVAL; 576926deccbSFrançois Tigeot } 577926deccbSFrançois Tigeot 578926deccbSFrançois Tigeot switch (args->operation) { 579926deccbSFrançois Tigeot case RADEON_VA_MAP: 580926deccbSFrançois Tigeot case RADEON_VA_UNMAP: 581926deccbSFrançois Tigeot break; 582926deccbSFrançois Tigeot default: 583fb572d17SFrançois Tigeot dev_err(&dev->pdev->dev, "unsupported operation %d\n", 584926deccbSFrançois Tigeot args->operation); 585926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 586926deccbSFrançois Tigeot return -EINVAL; 587926deccbSFrançois Tigeot } 588926deccbSFrançois Tigeot 5898621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, args->handle); 590926deccbSFrançois Tigeot if (gobj == NULL) { 591926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 592926deccbSFrançois Tigeot return -ENOENT; 593926deccbSFrançois Tigeot } 594926deccbSFrançois Tigeot rbo = gem_to_radeon_bo(gobj); 595926deccbSFrançois Tigeot r = radeon_bo_reserve(rbo, false); 596926deccbSFrançois Tigeot if (r) { 597926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 598926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 599926deccbSFrançois Tigeot return r; 600926deccbSFrançois Tigeot } 601926deccbSFrançois Tigeot bo_va = radeon_vm_bo_find(&fpriv->vm, rbo); 602926deccbSFrançois Tigeot if (!bo_va) { 603926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 604926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 605926deccbSFrançois Tigeot return -ENOENT; 606926deccbSFrançois Tigeot } 607926deccbSFrançois Tigeot 608926deccbSFrançois Tigeot switch (args->operation) { 609926deccbSFrançois Tigeot case RADEON_VA_MAP: 610*1cfef1a5SFrançois Tigeot if (bo_va->it.start) { 611926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_VA_EXIST; 612*1cfef1a5SFrançois Tigeot args->offset = bo_va->it.start * RADEON_GPU_PAGE_SIZE; 613*1cfef1a5SFrançois Tigeot radeon_bo_unreserve(rbo); 614926deccbSFrançois Tigeot goto out; 615926deccbSFrançois Tigeot } 616926deccbSFrançois Tigeot r = radeon_vm_bo_set_addr(rdev, bo_va, args->offset, args->flags); 617926deccbSFrançois Tigeot break; 618926deccbSFrançois Tigeot case RADEON_VA_UNMAP: 619926deccbSFrançois Tigeot r = radeon_vm_bo_set_addr(rdev, bo_va, 0, 0); 620926deccbSFrançois Tigeot break; 621926deccbSFrançois Tigeot default: 622926deccbSFrançois Tigeot break; 623926deccbSFrançois Tigeot } 624926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_OK; 625926deccbSFrançois Tigeot if (r) { 626926deccbSFrançois Tigeot args->operation = RADEON_VA_RESULT_ERROR; 627926deccbSFrançois Tigeot } 628926deccbSFrançois Tigeot out: 629ee479021SImre Vadász radeon_bo_unreserve(rbo); 630926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 631926deccbSFrançois Tigeot return r; 632926deccbSFrançois Tigeot } 633926deccbSFrançois Tigeot 634c6f73aabSFrançois Tigeot int radeon_gem_op_ioctl(struct drm_device *dev, void *data, 635c6f73aabSFrançois Tigeot struct drm_file *filp) 636c6f73aabSFrançois Tigeot { 637c6f73aabSFrançois Tigeot struct drm_radeon_gem_op *args = data; 638c6f73aabSFrançois Tigeot struct drm_gem_object *gobj; 639c6f73aabSFrançois Tigeot struct radeon_bo *robj; 640c6f73aabSFrançois Tigeot int r; 641c6f73aabSFrançois Tigeot 6428621f407SFrançois Tigeot gobj = drm_gem_object_lookup(filp, args->handle); 643c6f73aabSFrançois Tigeot if (gobj == NULL) { 644c6f73aabSFrançois Tigeot return -ENOENT; 645c6f73aabSFrançois Tigeot } 646c6f73aabSFrançois Tigeot robj = gem_to_radeon_bo(gobj); 647c6f73aabSFrançois Tigeot r = radeon_bo_reserve(robj, false); 648c6f73aabSFrançois Tigeot if (unlikely(r)) 649c6f73aabSFrançois Tigeot goto out; 650c6f73aabSFrançois Tigeot 651c6f73aabSFrançois Tigeot switch (args->op) { 652c6f73aabSFrançois Tigeot case RADEON_GEM_OP_GET_INITIAL_DOMAIN: 653c6f73aabSFrançois Tigeot args->value = robj->initial_domain; 654c6f73aabSFrançois Tigeot break; 655c6f73aabSFrançois Tigeot case RADEON_GEM_OP_SET_INITIAL_DOMAIN: 656c6f73aabSFrançois Tigeot robj->initial_domain = args->value & (RADEON_GEM_DOMAIN_VRAM | 657c6f73aabSFrançois Tigeot RADEON_GEM_DOMAIN_GTT | 658c6f73aabSFrançois Tigeot RADEON_GEM_DOMAIN_CPU); 659c6f73aabSFrançois Tigeot break; 660c6f73aabSFrançois Tigeot default: 661c6f73aabSFrançois Tigeot r = -EINVAL; 662c6f73aabSFrançois Tigeot } 663c6f73aabSFrançois Tigeot 664c6f73aabSFrançois Tigeot radeon_bo_unreserve(robj); 665c6f73aabSFrançois Tigeot out: 666c6f73aabSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 667c6f73aabSFrançois Tigeot return r; 668c6f73aabSFrançois Tigeot } 669c6f73aabSFrançois Tigeot 670926deccbSFrançois Tigeot int radeon_mode_dumb_create(struct drm_file *file_priv, 671926deccbSFrançois Tigeot struct drm_device *dev, 672926deccbSFrançois Tigeot struct drm_mode_create_dumb *args) 673926deccbSFrançois Tigeot { 674926deccbSFrançois Tigeot struct radeon_device *rdev = dev->dev_private; 675926deccbSFrançois Tigeot struct drm_gem_object *gobj; 676926deccbSFrançois Tigeot uint32_t handle; 677926deccbSFrançois Tigeot int r; 678926deccbSFrançois Tigeot 679926deccbSFrançois Tigeot args->pitch = radeon_align_pitch(rdev, args->width, args->bpp, 0) * ((args->bpp + 1) / 8); 680926deccbSFrançois Tigeot args->size = args->pitch * args->height; 681c4ef309bSzrj args->size = ALIGN(args->size, PAGE_SIZE); 682926deccbSFrançois Tigeot 683926deccbSFrançois Tigeot r = radeon_gem_object_create(rdev, args->size, 0, 684c6f73aabSFrançois Tigeot RADEON_GEM_DOMAIN_VRAM, 0, 685c6f73aabSFrançois Tigeot false, &gobj); 686926deccbSFrançois Tigeot if (r) 687926deccbSFrançois Tigeot return -ENOMEM; 688926deccbSFrançois Tigeot 689926deccbSFrançois Tigeot r = drm_gem_handle_create(file_priv, gobj, &handle); 690926deccbSFrançois Tigeot /* drop reference from allocate - handle holds it now */ 691926deccbSFrançois Tigeot drm_gem_object_unreference_unlocked(gobj); 692926deccbSFrançois Tigeot if (r) { 693926deccbSFrançois Tigeot return r; 694926deccbSFrançois Tigeot } 695926deccbSFrançois Tigeot args->handle = handle; 696926deccbSFrançois Tigeot return 0; 697926deccbSFrançois Tigeot } 698926deccbSFrançois Tigeot 699f43cf1b1SMichael Neumann #if defined(CONFIG_DEBUG_FS) 700f43cf1b1SMichael Neumann static int radeon_debugfs_gem_info(struct seq_file *m, void *data) 701f43cf1b1SMichael Neumann { 702f43cf1b1SMichael Neumann struct drm_info_node *node = (struct drm_info_node *)m->private; 703f43cf1b1SMichael Neumann struct drm_device *dev = node->minor->dev; 704f43cf1b1SMichael Neumann struct radeon_device *rdev = dev->dev_private; 705f43cf1b1SMichael Neumann struct radeon_bo *rbo; 706f43cf1b1SMichael Neumann unsigned i = 0; 707f43cf1b1SMichael Neumann 708f43cf1b1SMichael Neumann mutex_lock(&rdev->gem.mutex); 709f43cf1b1SMichael Neumann list_for_each_entry(rbo, &rdev->gem.objects, list) { 710f43cf1b1SMichael Neumann unsigned domain; 711f43cf1b1SMichael Neumann const char *placement; 712f43cf1b1SMichael Neumann 713f43cf1b1SMichael Neumann domain = radeon_mem_type_to_domain(rbo->tbo.mem.mem_type); 714f43cf1b1SMichael Neumann switch (domain) { 715f43cf1b1SMichael Neumann case RADEON_GEM_DOMAIN_VRAM: 716f43cf1b1SMichael Neumann placement = "VRAM"; 717f43cf1b1SMichael Neumann break; 718f43cf1b1SMichael Neumann case RADEON_GEM_DOMAIN_GTT: 719f43cf1b1SMichael Neumann placement = " GTT"; 720f43cf1b1SMichael Neumann break; 721f43cf1b1SMichael Neumann case RADEON_GEM_DOMAIN_CPU: 722f43cf1b1SMichael Neumann default: 723f43cf1b1SMichael Neumann placement = " CPU"; 724f43cf1b1SMichael Neumann break; 725f43cf1b1SMichael Neumann } 726f43cf1b1SMichael Neumann seq_printf(m, "bo[0x%08x] %8ldkB %8ldMB %s pid %8ld\n", 727f43cf1b1SMichael Neumann i, radeon_bo_size(rbo) >> 10, radeon_bo_size(rbo) >> 20, 728f43cf1b1SMichael Neumann placement, (unsigned long)rbo->pid); 729f43cf1b1SMichael Neumann i++; 730f43cf1b1SMichael Neumann } 731f43cf1b1SMichael Neumann mutex_unlock(&rdev->gem.mutex); 732f43cf1b1SMichael Neumann return 0; 733f43cf1b1SMichael Neumann } 734f43cf1b1SMichael Neumann 735f43cf1b1SMichael Neumann static struct drm_info_list radeon_debugfs_gem_list[] = { 736f43cf1b1SMichael Neumann {"radeon_gem_info", &radeon_debugfs_gem_info, 0, NULL}, 737f43cf1b1SMichael Neumann }; 738f43cf1b1SMichael Neumann #endif 739f43cf1b1SMichael Neumann 740f43cf1b1SMichael Neumann int radeon_gem_debugfs_init(struct radeon_device *rdev) 741f43cf1b1SMichael Neumann { 742f43cf1b1SMichael Neumann #if defined(CONFIG_DEBUG_FS) 743f43cf1b1SMichael Neumann return radeon_debugfs_add_files(rdev, radeon_debugfs_gem_list, 1); 744f43cf1b1SMichael Neumann #endif 745f43cf1b1SMichael Neumann return 0; 746f43cf1b1SMichael Neumann } 747