2015-04-21 04:55:21 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Advanced Micro Devices, Inc.
|
|
|
|
* Copyright 2008 Red Hat Inc.
|
|
|
|
* Copyright 2009 Jerome Glisse.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Dave Airlie
|
|
|
|
* Alex Deucher
|
|
|
|
* Jerome Glisse
|
|
|
|
*/
|
|
|
|
#include <linux/ktime.h>
|
2016-03-17 12:30:49 +08:00
|
|
|
#include <linux/pagemap.h>
|
2015-04-21 04:55:21 +08:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/amdgpu_drm.h>
|
|
|
|
#include "amdgpu.h"
|
|
|
|
|
|
|
|
void amdgpu_gem_object_free(struct drm_gem_object *gobj)
|
|
|
|
{
|
|
|
|
struct amdgpu_bo *robj = gem_to_amdgpu_bo(gobj);
|
|
|
|
|
|
|
|
if (robj) {
|
2015-06-04 03:31:20 +08:00
|
|
|
amdgpu_mn_unregister(robj);
|
2015-04-21 04:55:21 +08:00
|
|
|
amdgpu_bo_unref(&robj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_gem_object_create(struct amdgpu_device *adev, unsigned long size,
|
2017-08-25 15:14:43 +08:00
|
|
|
int alignment, u32 initial_domain,
|
2018-03-15 03:48:17 +08:00
|
|
|
u64 flags, enum ttm_bo_type type,
|
2017-08-25 15:14:43 +08:00
|
|
|
struct reservation_object *resv,
|
|
|
|
struct drm_gem_object **obj)
|
2015-04-21 04:55:21 +08:00
|
|
|
{
|
2017-08-25 15:14:43 +08:00
|
|
|
struct amdgpu_bo *bo;
|
2018-04-16 18:27:50 +08:00
|
|
|
struct amdgpu_bo_param bp;
|
2015-04-21 04:55:21 +08:00
|
|
|
int r;
|
|
|
|
|
2018-04-16 18:27:50 +08:00
|
|
|
memset(&bp, 0, sizeof(bp));
|
2015-04-21 04:55:21 +08:00
|
|
|
*obj = NULL;
|
|
|
|
/* At least align on page size */
|
|
|
|
if (alignment < PAGE_SIZE) {
|
|
|
|
alignment = PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
2018-04-16 18:27:50 +08:00
|
|
|
bp.size = size;
|
|
|
|
bp.byte_align = alignment;
|
|
|
|
bp.type = type;
|
|
|
|
bp.resv = resv;
|
2018-04-17 11:52:53 +08:00
|
|
|
bp.preferred_domain = initial_domain;
|
2018-04-10 19:42:38 +08:00
|
|
|
retry:
|
2018-04-16 18:27:50 +08:00
|
|
|
bp.flags = flags;
|
|
|
|
bp.domain = initial_domain;
|
|
|
|
r = amdgpu_bo_create(adev, &bp, &bo);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r) {
|
2018-04-10 19:42:38 +08:00
|
|
|
if (r != -ERESTARTSYS) {
|
|
|
|
if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
|
|
|
|
flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (initial_domain == AMDGPU_GEM_DOMAIN_VRAM) {
|
|
|
|
initial_domain |= AMDGPU_GEM_DOMAIN_GTT;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
DRM_DEBUG("Failed to allocate GEM object (%ld, %d, %u, %d)\n",
|
|
|
|
size, initial_domain, alignment, r);
|
|
|
|
}
|
2015-04-21 04:55:21 +08:00
|
|
|
return r;
|
|
|
|
}
|
2017-08-25 15:14:43 +08:00
|
|
|
*obj = &bo->gem_base;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-02-15 23:59:57 +08:00
|
|
|
void amdgpu_gem_force_release(struct amdgpu_device *adev)
|
2015-04-21 04:55:21 +08:00
|
|
|
{
|
2016-02-15 23:59:57 +08:00
|
|
|
struct drm_device *ddev = adev->ddev;
|
|
|
|
struct drm_file *file;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
2016-04-27 01:29:41 +08:00
|
|
|
mutex_lock(&ddev->filelist_mutex);
|
2016-02-15 23:59:57 +08:00
|
|
|
|
|
|
|
list_for_each_entry(file, &ddev->filelist, lhead) {
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
int handle;
|
|
|
|
|
|
|
|
WARN_ONCE(1, "Still active user space clients!\n");
|
|
|
|
spin_lock(&file->table_lock);
|
|
|
|
idr_for_each_entry(&file->object_idr, gobj, handle) {
|
|
|
|
WARN_ONCE(1, "And also active allocations!\n");
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2016-02-15 23:59:57 +08:00
|
|
|
}
|
|
|
|
idr_destroy(&file->object_idr);
|
|
|
|
spin_unlock(&file->table_lock);
|
|
|
|
}
|
|
|
|
|
2016-04-27 01:29:41 +08:00
|
|
|
mutex_unlock(&ddev->filelist_mutex);
|
2015-04-21 04:55:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call from drm_gem_handle_create which appear in both new and open ioctl
|
|
|
|
* case.
|
|
|
|
*/
|
2016-09-15 20:58:48 +08:00
|
|
|
int amdgpu_gem_object_open(struct drm_gem_object *obj,
|
|
|
|
struct drm_file *file_priv)
|
2015-04-21 04:55:21 +08:00
|
|
|
{
|
2016-09-15 21:06:50 +08:00
|
|
|
struct amdgpu_bo *abo = gem_to_amdgpu_bo(obj);
|
2016-09-15 20:58:48 +08:00
|
|
|
struct amdgpu_device *adev = amdgpu_ttm_adev(abo->tbo.bdev);
|
2015-04-21 04:55:21 +08:00
|
|
|
struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
|
|
|
|
struct amdgpu_vm *vm = &fpriv->vm;
|
|
|
|
struct amdgpu_bo_va *bo_va;
|
2017-08-29 22:07:31 +08:00
|
|
|
struct mm_struct *mm;
|
2015-04-21 04:55:21 +08:00
|
|
|
int r;
|
2017-08-29 22:07:31 +08:00
|
|
|
|
|
|
|
mm = amdgpu_ttm_tt_get_usermm(abo->tbo.ttm);
|
|
|
|
if (mm && mm != current->mm)
|
|
|
|
return -EPERM;
|
|
|
|
|
2017-08-25 15:14:43 +08:00
|
|
|
if (abo->flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID &&
|
|
|
|
abo->tbo.resv != vm->root.base.bo->tbo.resv)
|
|
|
|
return -EPERM;
|
|
|
|
|
2016-09-15 21:06:50 +08:00
|
|
|
r = amdgpu_bo_reserve(abo, false);
|
2015-11-13 15:22:04 +08:00
|
|
|
if (r)
|
2015-04-21 04:55:21 +08:00
|
|
|
return r;
|
|
|
|
|
2016-09-15 21:06:50 +08:00
|
|
|
bo_va = amdgpu_vm_bo_find(vm, abo);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (!bo_va) {
|
2016-09-15 21:06:50 +08:00
|
|
|
bo_va = amdgpu_vm_bo_add(adev, vm, abo);
|
2015-04-21 04:55:21 +08:00
|
|
|
} else {
|
|
|
|
++bo_va->ref_count;
|
|
|
|
}
|
2016-09-15 21:06:50 +08:00
|
|
|
amdgpu_bo_unreserve(abo);
|
2015-04-21 04:55:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void amdgpu_gem_object_close(struct drm_gem_object *obj,
|
|
|
|
struct drm_file *file_priv)
|
|
|
|
{
|
2016-03-09 00:47:46 +08:00
|
|
|
struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
|
2016-09-15 20:58:48 +08:00
|
|
|
struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
|
2015-04-21 04:55:21 +08:00
|
|
|
struct amdgpu_fpriv *fpriv = file_priv->driver_priv;
|
|
|
|
struct amdgpu_vm *vm = &fpriv->vm;
|
2016-03-09 00:47:46 +08:00
|
|
|
|
|
|
|
struct amdgpu_bo_list_entry vm_pd;
|
2017-08-25 15:14:43 +08:00
|
|
|
struct list_head list, duplicates;
|
2016-03-09 00:47:46 +08:00
|
|
|
struct ttm_validate_buffer tv;
|
|
|
|
struct ww_acquire_ctx ticket;
|
2015-04-21 04:55:21 +08:00
|
|
|
struct amdgpu_bo_va *bo_va;
|
|
|
|
int r;
|
2016-03-09 00:47:46 +08:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&list);
|
2017-08-25 15:14:43 +08:00
|
|
|
INIT_LIST_HEAD(&duplicates);
|
2016-03-09 00:47:46 +08:00
|
|
|
|
|
|
|
tv.bo = &bo->tbo;
|
|
|
|
tv.shared = true;
|
|
|
|
list_add(&tv.head, &list);
|
|
|
|
|
|
|
|
amdgpu_vm_get_pd_bo(vm, &list, &vm_pd);
|
|
|
|
|
2017-08-25 15:14:43 +08:00
|
|
|
r = ttm_eu_reserve_buffers(&ticket, &list, false, &duplicates);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r) {
|
|
|
|
dev_err(adev->dev, "leaking bo va because "
|
|
|
|
"we fail to reserve bo (%d)\n", r);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-09 00:47:46 +08:00
|
|
|
bo_va = amdgpu_vm_bo_find(vm, bo);
|
2017-04-21 16:05:56 +08:00
|
|
|
if (bo_va && --bo_va->ref_count == 0) {
|
|
|
|
amdgpu_vm_bo_rmv(adev, bo_va);
|
|
|
|
|
2017-08-03 20:02:13 +08:00
|
|
|
if (amdgpu_vm_ready(vm)) {
|
2017-04-21 16:05:56 +08:00
|
|
|
struct dma_fence *fence = NULL;
|
2017-03-24 02:34:11 +08:00
|
|
|
|
|
|
|
r = amdgpu_vm_clear_freed(adev, vm, &fence);
|
|
|
|
if (unlikely(r)) {
|
|
|
|
dev_err(adev->dev, "failed to clear page "
|
|
|
|
"tables on GEM object close (%d)\n", r);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fence) {
|
|
|
|
amdgpu_bo_fence(bo, fence, true);
|
|
|
|
dma_fence_put(fence);
|
|
|
|
}
|
2015-04-21 04:55:21 +08:00
|
|
|
}
|
|
|
|
}
|
2016-03-09 00:47:46 +08:00
|
|
|
ttm_eu_backoff_reservation(&ticket, &list);
|
2015-04-21 04:55:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GEM ioctls.
|
|
|
|
*/
|
|
|
|
int amdgpu_gem_create_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = dev->dev_private;
|
2017-08-25 15:14:43 +08:00
|
|
|
struct amdgpu_fpriv *fpriv = filp->driver_priv;
|
|
|
|
struct amdgpu_vm *vm = &fpriv->vm;
|
2015-04-21 04:55:21 +08:00
|
|
|
union drm_amdgpu_gem_create *args = data;
|
2017-08-24 02:11:25 +08:00
|
|
|
uint64_t flags = args->in.domain_flags;
|
2015-04-21 04:55:21 +08:00
|
|
|
uint64_t size = args->in.bo_size;
|
2017-08-25 15:14:43 +08:00
|
|
|
struct reservation_object *resv = NULL;
|
2015-04-21 04:55:21 +08:00
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
uint32_t handle;
|
|
|
|
int r;
|
|
|
|
|
2017-03-09 06:40:17 +08:00
|
|
|
/* reject invalid gem flags */
|
2017-08-24 02:11:25 +08:00
|
|
|
if (flags & ~(AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
|
|
|
|
AMDGPU_GEM_CREATE_NO_CPU_ACCESS |
|
|
|
|
AMDGPU_GEM_CREATE_CPU_GTT_USWC |
|
2017-08-25 15:14:43 +08:00
|
|
|
AMDGPU_GEM_CREATE_VRAM_CLEARED |
|
2017-09-16 08:44:06 +08:00
|
|
|
AMDGPU_GEM_CREATE_VM_ALWAYS_VALID |
|
|
|
|
AMDGPU_GEM_CREATE_EXPLICIT_SYNC))
|
|
|
|
|
2017-05-08 21:14:54 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2017-03-09 06:40:17 +08:00
|
|
|
/* reject invalid gem domains */
|
2018-04-17 18:34:40 +08:00
|
|
|
if (args->in.domains & ~AMDGPU_GEM_DOMAIN_MASK)
|
2017-05-08 21:14:54 +08:00
|
|
|
return -EINVAL;
|
2017-03-09 06:40:17 +08:00
|
|
|
|
2015-04-21 04:55:21 +08:00
|
|
|
/* create a gem object to contain this object in */
|
|
|
|
if (args->in.domains & (AMDGPU_GEM_DOMAIN_GDS |
|
|
|
|
AMDGPU_GEM_DOMAIN_GWS | AMDGPU_GEM_DOMAIN_OA)) {
|
2017-08-24 02:11:25 +08:00
|
|
|
flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
|
2015-04-21 04:55:21 +08:00
|
|
|
if (args->in.domains == AMDGPU_GEM_DOMAIN_GDS)
|
|
|
|
size = size << AMDGPU_GDS_SHIFT;
|
|
|
|
else if (args->in.domains == AMDGPU_GEM_DOMAIN_GWS)
|
|
|
|
size = size << AMDGPU_GWS_SHIFT;
|
|
|
|
else if (args->in.domains == AMDGPU_GEM_DOMAIN_OA)
|
|
|
|
size = size << AMDGPU_OA_SHIFT;
|
2017-05-08 21:14:54 +08:00
|
|
|
else
|
|
|
|
return -EINVAL;
|
2015-04-21 04:55:21 +08:00
|
|
|
}
|
|
|
|
size = roundup(size, PAGE_SIZE);
|
|
|
|
|
2017-08-25 15:14:43 +08:00
|
|
|
if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) {
|
|
|
|
r = amdgpu_bo_reserve(vm->root.base.bo, false);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
resv = vm->root.base.bo->tbo.resv;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:55:21 +08:00
|
|
|
r = amdgpu_gem_object_create(adev, size, args->in.alignment,
|
|
|
|
(u32)(0xffffffff & args->in.domains),
|
2017-08-25 15:14:43 +08:00
|
|
|
flags, false, resv, &gobj);
|
|
|
|
if (flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID) {
|
|
|
|
if (!r) {
|
|
|
|
struct amdgpu_bo *abo = gem_to_amdgpu_bo(gobj);
|
|
|
|
|
|
|
|
abo->parent = amdgpu_bo_ref(vm->root.base.bo);
|
|
|
|
}
|
|
|
|
amdgpu_bo_unreserve(vm->root.base.bo);
|
|
|
|
}
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r)
|
2017-05-08 21:14:54 +08:00
|
|
|
return r;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
r = drm_gem_handle_create(filp, gobj, &handle);
|
|
|
|
/* drop reference from allocate - handle holds it now */
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r)
|
2017-05-08 21:14:54 +08:00
|
|
|
return r;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
memset(args, 0, sizeof(*args));
|
|
|
|
args->out.handle = handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
2017-04-12 20:24:39 +08:00
|
|
|
struct ttm_operation_ctx ctx = { true, false };
|
2015-04-21 04:55:21 +08:00
|
|
|
struct amdgpu_device *adev = dev->dev_private;
|
|
|
|
struct drm_amdgpu_gem_userptr *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct amdgpu_bo *bo;
|
|
|
|
uint32_t handle;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (offset_in_page(args->addr | args->size))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* reject unknown flag values */
|
|
|
|
if (args->flags & ~(AMDGPU_GEM_USERPTR_READONLY |
|
|
|
|
AMDGPU_GEM_USERPTR_ANONONLY | AMDGPU_GEM_USERPTR_VALIDATE |
|
|
|
|
AMDGPU_GEM_USERPTR_REGISTER))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2016-03-11 22:29:27 +08:00
|
|
|
if (!(args->flags & AMDGPU_GEM_USERPTR_READONLY) &&
|
|
|
|
!(args->flags & AMDGPU_GEM_USERPTR_REGISTER)) {
|
2015-04-21 04:55:21 +08:00
|
|
|
|
2016-03-11 22:29:27 +08:00
|
|
|
/* if we want to write to it we must install a MMU notifier */
|
2015-04-21 04:55:21 +08:00
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a gem object to contain this object in */
|
2017-08-25 15:14:43 +08:00
|
|
|
r = amdgpu_gem_object_create(adev, args->size, 0, AMDGPU_GEM_DOMAIN_CPU,
|
|
|
|
0, 0, NULL, &gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r)
|
2017-05-08 21:14:54 +08:00
|
|
|
return r;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
bo = gem_to_amdgpu_bo(gobj);
|
2017-08-08 19:58:01 +08:00
|
|
|
bo->preferred_domains = AMDGPU_GEM_DOMAIN_GTT;
|
2015-12-19 05:13:12 +08:00
|
|
|
bo->allowed_domains = AMDGPU_GEM_DOMAIN_GTT;
|
2015-04-21 04:55:21 +08:00
|
|
|
r = amdgpu_ttm_tt_set_userptr(bo->tbo.ttm, args->addr, args->flags);
|
|
|
|
if (r)
|
|
|
|
goto release_object;
|
|
|
|
|
|
|
|
if (args->flags & AMDGPU_GEM_USERPTR_REGISTER) {
|
|
|
|
r = amdgpu_mn_register(bo, args->addr);
|
|
|
|
if (r)
|
|
|
|
goto release_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {
|
2016-02-23 19:36:59 +08:00
|
|
|
r = amdgpu_ttm_tt_get_user_pages(bo->tbo.ttm,
|
|
|
|
bo->tbo.ttm->pages);
|
|
|
|
if (r)
|
2017-10-20 17:21:40 +08:00
|
|
|
goto release_object;
|
2016-02-23 19:36:59 +08:00
|
|
|
|
2015-04-21 04:55:21 +08:00
|
|
|
r = amdgpu_bo_reserve(bo, true);
|
2016-02-23 19:36:59 +08:00
|
|
|
if (r)
|
|
|
|
goto free_pages;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
amdgpu_ttm_placement_from_domain(bo, AMDGPU_GEM_DOMAIN_GTT);
|
2017-04-12 20:24:39 +08:00
|
|
|
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
|
2015-04-21 04:55:21 +08:00
|
|
|
amdgpu_bo_unreserve(bo);
|
|
|
|
if (r)
|
2016-02-23 19:36:59 +08:00
|
|
|
goto free_pages;
|
2015-04-21 04:55:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
r = drm_gem_handle_create(filp, gobj, &handle);
|
|
|
|
/* drop reference from allocate - handle holds it now */
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r)
|
2017-05-08 21:14:54 +08:00
|
|
|
return r;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
args->handle = handle;
|
|
|
|
return 0;
|
|
|
|
|
2016-02-23 19:36:59 +08:00
|
|
|
free_pages:
|
2017-11-16 09:37:55 +08:00
|
|
|
release_pages(bo->tbo.ttm->pages, bo->tbo.ttm->num_pages);
|
2016-02-23 19:36:59 +08:00
|
|
|
|
2015-04-21 04:55:21 +08:00
|
|
|
release_object:
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_mode_dumb_mmap(struct drm_file *filp,
|
|
|
|
struct drm_device *dev,
|
|
|
|
uint32_t handle, uint64_t *offset_p)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct amdgpu_bo *robj;
|
|
|
|
|
2016-05-09 18:04:54 +08:00
|
|
|
gobj = drm_gem_object_lookup(filp, handle);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (gobj == NULL) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
robj = gem_to_amdgpu_bo(gobj);
|
2016-02-08 18:08:35 +08:00
|
|
|
if (amdgpu_ttm_tt_get_usermm(robj->tbo.ttm) ||
|
2015-05-13 20:30:53 +08:00
|
|
|
(robj->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS)) {
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
return -EPERM;
|
|
|
|
}
|
|
|
|
*offset_p = amdgpu_bo_mmap_offset(robj);
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_gem_mmap_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
union drm_amdgpu_gem_mmap *args = data;
|
|
|
|
uint32_t handle = args->in.handle;
|
|
|
|
memset(args, 0, sizeof(*args));
|
|
|
|
return amdgpu_mode_dumb_mmap(filp, dev, handle, &args->out.addr_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gem_timeout - calculate jiffies timeout from absolute value
|
|
|
|
*
|
|
|
|
* @timeout_ns: timeout in ns
|
|
|
|
*
|
|
|
|
* Calculate the timeout in jiffies from an absolute timeout in ns.
|
|
|
|
*/
|
|
|
|
unsigned long amdgpu_gem_timeout(uint64_t timeout_ns)
|
|
|
|
{
|
|
|
|
unsigned long timeout_jiffies;
|
|
|
|
ktime_t timeout;
|
|
|
|
|
|
|
|
/* clamp timeout if it's to large */
|
|
|
|
if (((int64_t)timeout_ns) < 0)
|
|
|
|
return MAX_SCHEDULE_TIMEOUT;
|
|
|
|
|
2015-07-08 22:58:48 +08:00
|
|
|
timeout = ktime_sub(ns_to_ktime(timeout_ns), ktime_get());
|
2015-04-21 04:55:21 +08:00
|
|
|
if (ktime_to_ns(timeout) < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
timeout_jiffies = nsecs_to_jiffies(ktime_to_ns(timeout));
|
|
|
|
/* clamp timeout to avoid unsigned-> signed overflow */
|
|
|
|
if (timeout_jiffies > MAX_SCHEDULE_TIMEOUT )
|
|
|
|
return MAX_SCHEDULE_TIMEOUT - 1;
|
|
|
|
|
|
|
|
return timeout_jiffies;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_gem_wait_idle_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
union drm_amdgpu_gem_wait_idle *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct amdgpu_bo *robj;
|
|
|
|
uint32_t handle = args->in.handle;
|
|
|
|
unsigned long timeout = amdgpu_gem_timeout(args->in.timeout);
|
|
|
|
int r = 0;
|
|
|
|
long ret;
|
|
|
|
|
2016-05-09 18:04:54 +08:00
|
|
|
gobj = drm_gem_object_lookup(filp, handle);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (gobj == NULL) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
robj = gem_to_amdgpu_bo(gobj);
|
2016-08-29 15:08:24 +08:00
|
|
|
ret = reservation_object_wait_timeout_rcu(robj->tbo.resv, true, true,
|
|
|
|
timeout);
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
/* ret == 0 means not signaled,
|
|
|
|
* ret > 0 means signaled
|
|
|
|
* ret < 0 means interrupted before timeout
|
|
|
|
*/
|
|
|
|
if (ret >= 0) {
|
|
|
|
memset(args, 0, sizeof(*args));
|
|
|
|
args->out.status = (ret == 0);
|
|
|
|
} else
|
|
|
|
r = ret;
|
|
|
|
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_gem_metadata_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
|
|
|
struct drm_amdgpu_gem_metadata *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct amdgpu_bo *robj;
|
|
|
|
int r = -1;
|
|
|
|
|
|
|
|
DRM_DEBUG("%d \n", args->handle);
|
2016-05-09 18:04:54 +08:00
|
|
|
gobj = drm_gem_object_lookup(filp, args->handle);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (gobj == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
robj = gem_to_amdgpu_bo(gobj);
|
|
|
|
|
|
|
|
r = amdgpu_bo_reserve(robj, false);
|
|
|
|
if (unlikely(r != 0))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (args->op == AMDGPU_GEM_METADATA_OP_GET_METADATA) {
|
|
|
|
amdgpu_bo_get_tiling_flags(robj, &args->data.tiling_info);
|
|
|
|
r = amdgpu_bo_get_metadata(robj, args->data.data,
|
|
|
|
sizeof(args->data.data),
|
|
|
|
&args->data.data_size_bytes,
|
|
|
|
&args->data.flags);
|
|
|
|
} else if (args->op == AMDGPU_GEM_METADATA_OP_SET_METADATA) {
|
2015-09-23 19:00:35 +08:00
|
|
|
if (args->data.data_size_bytes > sizeof(args->data.data)) {
|
|
|
|
r = -EINVAL;
|
|
|
|
goto unreserve;
|
|
|
|
}
|
2015-04-21 04:55:21 +08:00
|
|
|
r = amdgpu_bo_set_tiling_flags(robj, args->data.tiling_info);
|
|
|
|
if (!r)
|
|
|
|
r = amdgpu_bo_set_metadata(robj, args->data.data,
|
|
|
|
args->data.data_size_bytes,
|
|
|
|
args->data.flags);
|
|
|
|
}
|
|
|
|
|
2015-09-23 19:00:35 +08:00
|
|
|
unreserve:
|
2015-04-21 04:55:21 +08:00
|
|
|
amdgpu_bo_unreserve(robj);
|
|
|
|
out:
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gem_va_update_vm -update the bo_va in its VM
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
2017-03-13 17:13:38 +08:00
|
|
|
* @vm: vm to update
|
2015-04-21 04:55:21 +08:00
|
|
|
* @bo_va: bo_va to update
|
2017-01-27 22:58:43 +08:00
|
|
|
* @list: validation list
|
2017-03-13 17:13:38 +08:00
|
|
|
* @operation: map, unmap or clear
|
2015-04-21 04:55:21 +08:00
|
|
|
*
|
2017-01-27 22:58:43 +08:00
|
|
|
* Update the bo_va directly after setting its address. Errors are not
|
2015-04-21 04:55:21 +08:00
|
|
|
* vital here, so they are not reported back to userspace.
|
|
|
|
*/
|
|
|
|
static void amdgpu_gem_va_update_vm(struct amdgpu_device *adev,
|
2017-03-13 17:13:38 +08:00
|
|
|
struct amdgpu_vm *vm,
|
2016-09-28 18:03:04 +08:00
|
|
|
struct amdgpu_bo_va *bo_va,
|
2017-01-27 22:58:43 +08:00
|
|
|
struct list_head *list,
|
2016-09-28 18:03:04 +08:00
|
|
|
uint32_t operation)
|
2015-04-21 04:55:21 +08:00
|
|
|
{
|
2017-08-03 20:02:13 +08:00
|
|
|
int r;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
2017-08-03 20:02:13 +08:00
|
|
|
if (!amdgpu_vm_ready(vm))
|
|
|
|
return;
|
2015-12-07 15:02:52 +08:00
|
|
|
|
2017-03-24 02:36:31 +08:00
|
|
|
r = amdgpu_vm_clear_freed(adev, vm, NULL);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r)
|
2017-01-27 22:58:43 +08:00
|
|
|
goto error;
|
2015-07-22 13:29:28 +08:00
|
|
|
|
2017-03-13 17:13:39 +08:00
|
|
|
if (operation == AMDGPU_VA_OP_MAP ||
|
2018-02-15 13:20:00 +08:00
|
|
|
operation == AMDGPU_VA_OP_REPLACE) {
|
2016-09-22 11:34:47 +08:00
|
|
|
r = amdgpu_vm_bo_update(adev, bo_va, false);
|
2018-02-15 13:20:00 +08:00
|
|
|
if (r)
|
|
|
|
goto error;
|
|
|
|
}
|
2015-04-21 04:55:21 +08:00
|
|
|
|
2017-09-02 02:37:57 +08:00
|
|
|
r = amdgpu_vm_update_directories(adev, vm);
|
|
|
|
|
2017-01-27 22:58:43 +08:00
|
|
|
error:
|
2015-06-16 20:50:02 +08:00
|
|
|
if (r && r != -ERESTARTSYS)
|
2015-04-21 04:55:21 +08:00
|
|
|
DRM_ERROR("Couldn't update BO_VA (%d)\n", r);
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_gem_va_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
2017-01-16 13:59:01 +08:00
|
|
|
const uint32_t valid_flags = AMDGPU_VM_DELAY_UPDATE |
|
|
|
|
AMDGPU_VM_PAGE_READABLE | AMDGPU_VM_PAGE_WRITEABLE |
|
2017-02-15 01:04:52 +08:00
|
|
|
AMDGPU_VM_PAGE_EXECUTABLE | AMDGPU_VM_MTYPE_MASK;
|
2017-01-16 13:59:01 +08:00
|
|
|
const uint32_t prt_flags = AMDGPU_VM_DELAY_UPDATE |
|
|
|
|
AMDGPU_VM_PAGE_PRT;
|
|
|
|
|
2015-06-08 21:03:00 +08:00
|
|
|
struct drm_amdgpu_gem_va *args = data;
|
2015-04-21 04:55:21 +08:00
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct amdgpu_device *adev = dev->dev_private;
|
|
|
|
struct amdgpu_fpriv *fpriv = filp->driver_priv;
|
2016-09-15 21:06:50 +08:00
|
|
|
struct amdgpu_bo *abo;
|
2015-04-21 04:55:21 +08:00
|
|
|
struct amdgpu_bo_va *bo_va;
|
2016-09-28 22:33:01 +08:00
|
|
|
struct amdgpu_bo_list_entry vm_pd;
|
|
|
|
struct ttm_validate_buffer tv;
|
2015-11-13 14:18:38 +08:00
|
|
|
struct ww_acquire_ctx ticket;
|
2017-08-25 15:14:43 +08:00
|
|
|
struct list_head list, duplicates;
|
2017-02-15 01:22:57 +08:00
|
|
|
uint64_t va_flags;
|
2015-04-21 04:55:21 +08:00
|
|
|
int r = 0;
|
|
|
|
|
2015-06-08 21:03:00 +08:00
|
|
|
if (args->va_address < AMDGPU_VA_RESERVED_SIZE) {
|
2017-11-13 20:58:17 +08:00
|
|
|
dev_dbg(&dev->pdev->dev,
|
2017-11-06 22:25:37 +08:00
|
|
|
"va_address 0x%LX is in reserved area 0x%LX\n",
|
|
|
|
args->va_address, AMDGPU_VA_RESERVED_SIZE);
|
2015-04-21 04:55:21 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-11-06 22:37:01 +08:00
|
|
|
if (args->va_address >= AMDGPU_VA_HOLE_START &&
|
|
|
|
args->va_address < AMDGPU_VA_HOLE_END) {
|
|
|
|
dev_dbg(&dev->pdev->dev,
|
|
|
|
"va_address 0x%LX is in VA hole 0x%LX-0x%LX\n",
|
|
|
|
args->va_address, AMDGPU_VA_HOLE_START,
|
|
|
|
AMDGPU_VA_HOLE_END);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
args->va_address &= AMDGPU_VA_HOLE_MASK;
|
|
|
|
|
2017-01-16 13:59:01 +08:00
|
|
|
if ((args->flags & ~valid_flags) && (args->flags & ~prt_flags)) {
|
2017-11-13 20:58:17 +08:00
|
|
|
dev_dbg(&dev->pdev->dev, "invalid flags combination 0x%08X\n",
|
2017-01-16 13:59:01 +08:00
|
|
|
args->flags);
|
2015-04-21 04:55:21 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-06-08 21:03:00 +08:00
|
|
|
switch (args->operation) {
|
2015-04-21 04:55:21 +08:00
|
|
|
case AMDGPU_VA_OP_MAP:
|
|
|
|
case AMDGPU_VA_OP_UNMAP:
|
2017-03-13 17:13:38 +08:00
|
|
|
case AMDGPU_VA_OP_CLEAR:
|
2017-03-13 17:13:39 +08:00
|
|
|
case AMDGPU_VA_OP_REPLACE:
|
2015-04-21 04:55:21 +08:00
|
|
|
break;
|
|
|
|
default:
|
2017-11-13 20:58:17 +08:00
|
|
|
dev_dbg(&dev->pdev->dev, "unsupported operation %d\n",
|
2015-06-08 21:03:00 +08:00
|
|
|
args->operation);
|
2015-04-21 04:55:21 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-11-13 14:18:38 +08:00
|
|
|
INIT_LIST_HEAD(&list);
|
2017-08-25 15:14:43 +08:00
|
|
|
INIT_LIST_HEAD(&duplicates);
|
2017-03-13 17:13:38 +08:00
|
|
|
if ((args->operation != AMDGPU_VA_OP_CLEAR) &&
|
|
|
|
!(args->flags & AMDGPU_VM_PAGE_PRT)) {
|
2017-01-16 13:59:01 +08:00
|
|
|
gobj = drm_gem_object_lookup(filp, args->handle);
|
|
|
|
if (gobj == NULL)
|
|
|
|
return -ENOENT;
|
|
|
|
abo = gem_to_amdgpu_bo(gobj);
|
|
|
|
tv.bo = &abo->tbo;
|
|
|
|
tv.shared = false;
|
|
|
|
list_add(&tv.head, &list);
|
|
|
|
} else {
|
|
|
|
gobj = NULL;
|
|
|
|
abo = NULL;
|
|
|
|
}
|
2015-11-13 14:18:38 +08:00
|
|
|
|
2016-09-28 22:33:01 +08:00
|
|
|
amdgpu_vm_get_pd_bo(&fpriv->vm, &list, &vm_pd);
|
2016-03-09 00:47:46 +08:00
|
|
|
|
2017-08-25 15:14:43 +08:00
|
|
|
r = ttm_eu_reserve_buffers(&ticket, &list, true, &duplicates);
|
2017-01-16 13:59:01 +08:00
|
|
|
if (r)
|
|
|
|
goto error_unref;
|
2015-06-08 21:03:00 +08:00
|
|
|
|
2017-01-16 13:59:01 +08:00
|
|
|
if (abo) {
|
|
|
|
bo_va = amdgpu_vm_bo_find(&fpriv->vm, abo);
|
|
|
|
if (!bo_va) {
|
|
|
|
r = -ENOENT;
|
|
|
|
goto error_backoff;
|
|
|
|
}
|
2017-03-13 17:13:38 +08:00
|
|
|
} else if (args->operation != AMDGPU_VA_OP_CLEAR) {
|
2017-01-16 13:59:01 +08:00
|
|
|
bo_va = fpriv->prt_va;
|
2017-03-13 17:13:38 +08:00
|
|
|
} else {
|
|
|
|
bo_va = NULL;
|
2015-04-21 04:55:21 +08:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:03:00 +08:00
|
|
|
switch (args->operation) {
|
2015-04-21 04:55:21 +08:00
|
|
|
case AMDGPU_VA_OP_MAP:
|
2017-08-01 16:51:43 +08:00
|
|
|
r = amdgpu_vm_alloc_pts(adev, bo_va->base.vm, args->va_address,
|
2017-03-13 17:13:37 +08:00
|
|
|
args->map_size);
|
|
|
|
if (r)
|
|
|
|
goto error_backoff;
|
2017-02-15 01:22:57 +08:00
|
|
|
|
2018-01-12 22:26:08 +08:00
|
|
|
va_flags = amdgpu_gmc_get_pte_flags(adev, args->flags);
|
2015-06-08 21:03:00 +08:00
|
|
|
r = amdgpu_vm_bo_map(adev, bo_va, args->va_address,
|
|
|
|
args->offset_in_bo, args->map_size,
|
2015-05-18 22:05:57 +08:00
|
|
|
va_flags);
|
2015-04-21 04:55:21 +08:00
|
|
|
break;
|
|
|
|
case AMDGPU_VA_OP_UNMAP:
|
2015-06-08 21:03:00 +08:00
|
|
|
r = amdgpu_vm_bo_unmap(adev, bo_va, args->va_address);
|
2015-04-21 04:55:21 +08:00
|
|
|
break;
|
2017-03-13 17:13:38 +08:00
|
|
|
|
|
|
|
case AMDGPU_VA_OP_CLEAR:
|
|
|
|
r = amdgpu_vm_bo_clear_mappings(adev, &fpriv->vm,
|
|
|
|
args->va_address,
|
|
|
|
args->map_size);
|
|
|
|
break;
|
2017-03-13 17:13:39 +08:00
|
|
|
case AMDGPU_VA_OP_REPLACE:
|
2017-08-01 16:51:43 +08:00
|
|
|
r = amdgpu_vm_alloc_pts(adev, bo_va->base.vm, args->va_address,
|
2017-03-13 17:13:39 +08:00
|
|
|
args->map_size);
|
|
|
|
if (r)
|
|
|
|
goto error_backoff;
|
|
|
|
|
2018-01-12 22:26:08 +08:00
|
|
|
va_flags = amdgpu_gmc_get_pte_flags(adev, args->flags);
|
2017-03-13 17:13:39 +08:00
|
|
|
r = amdgpu_vm_bo_replace_map(adev, bo_va, args->va_address,
|
|
|
|
args->offset_in_bo, args->map_size,
|
|
|
|
va_flags);
|
|
|
|
break;
|
2015-04-21 04:55:21 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-01-16 13:59:01 +08:00
|
|
|
if (!r && !(args->flags & AMDGPU_VM_DELAY_UPDATE) && !amdgpu_vm_debug)
|
2017-03-13 17:13:38 +08:00
|
|
|
amdgpu_gem_va_update_vm(adev, &fpriv->vm, bo_va, &list,
|
|
|
|
args->operation);
|
2017-01-16 13:59:01 +08:00
|
|
|
|
|
|
|
error_backoff:
|
2017-01-27 22:58:43 +08:00
|
|
|
ttm_eu_backoff_reservation(&ticket, &list);
|
2015-11-13 15:22:04 +08:00
|
|
|
|
2017-01-16 13:59:01 +08:00
|
|
|
error_unref:
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_gem_op_ioctl(struct drm_device *dev, void *data,
|
|
|
|
struct drm_file *filp)
|
|
|
|
{
|
2017-08-25 15:14:43 +08:00
|
|
|
struct amdgpu_device *adev = dev->dev_private;
|
2015-04-21 04:55:21 +08:00
|
|
|
struct drm_amdgpu_gem_op *args = data;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
struct amdgpu_bo *robj;
|
|
|
|
int r;
|
|
|
|
|
2016-05-09 18:04:54 +08:00
|
|
|
gobj = drm_gem_object_lookup(filp, args->handle);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (gobj == NULL) {
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
robj = gem_to_amdgpu_bo(gobj);
|
|
|
|
|
|
|
|
r = amdgpu_bo_reserve(robj, false);
|
|
|
|
if (unlikely(r))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (args->op) {
|
|
|
|
case AMDGPU_GEM_OP_GET_GEM_CREATE_INFO: {
|
|
|
|
struct drm_amdgpu_gem_create_in info;
|
2017-07-26 23:02:52 +08:00
|
|
|
void __user *out = u64_to_user_ptr(args->value);
|
2015-04-21 04:55:21 +08:00
|
|
|
|
|
|
|
info.bo_size = robj->gem_base.size;
|
|
|
|
info.alignment = robj->tbo.mem.page_alignment << PAGE_SHIFT;
|
2017-08-08 19:58:01 +08:00
|
|
|
info.domains = robj->preferred_domains;
|
2015-04-21 04:55:21 +08:00
|
|
|
info.domain_flags = robj->flags;
|
2015-08-28 23:27:54 +08:00
|
|
|
amdgpu_bo_unreserve(robj);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (copy_to_user(out, &info, sizeof(info)))
|
|
|
|
r = -EFAULT;
|
|
|
|
break;
|
|
|
|
}
|
2015-05-27 20:30:38 +08:00
|
|
|
case AMDGPU_GEM_OP_SET_PLACEMENT:
|
2017-04-03 11:31:22 +08:00
|
|
|
if (robj->prime_shared_count && (args->value & AMDGPU_GEM_DOMAIN_VRAM)) {
|
|
|
|
r = -EINVAL;
|
|
|
|
amdgpu_bo_unreserve(robj);
|
|
|
|
break;
|
|
|
|
}
|
2016-02-08 18:08:35 +08:00
|
|
|
if (amdgpu_ttm_tt_get_usermm(robj->tbo.ttm)) {
|
2015-04-21 04:55:21 +08:00
|
|
|
r = -EPERM;
|
2015-08-28 23:27:54 +08:00
|
|
|
amdgpu_bo_unreserve(robj);
|
2015-04-21 04:55:21 +08:00
|
|
|
break;
|
|
|
|
}
|
2017-08-08 19:58:01 +08:00
|
|
|
robj->preferred_domains = args->value & (AMDGPU_GEM_DOMAIN_VRAM |
|
2015-12-19 05:13:12 +08:00
|
|
|
AMDGPU_GEM_DOMAIN_GTT |
|
|
|
|
AMDGPU_GEM_DOMAIN_CPU);
|
2017-08-08 19:58:01 +08:00
|
|
|
robj->allowed_domains = robj->preferred_domains;
|
2015-12-19 05:13:12 +08:00
|
|
|
if (robj->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
|
|
|
|
robj->allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
|
|
|
|
|
2017-08-25 15:14:43 +08:00
|
|
|
if (robj->flags & AMDGPU_GEM_CREATE_VM_ALWAYS_VALID)
|
|
|
|
amdgpu_vm_bo_invalidate(adev, robj, true);
|
|
|
|
|
2015-08-28 23:27:54 +08:00
|
|
|
amdgpu_bo_unreserve(robj);
|
2015-04-21 04:55:21 +08:00
|
|
|
break;
|
|
|
|
default:
|
2015-08-28 23:27:54 +08:00
|
|
|
amdgpu_bo_unreserve(robj);
|
2015-04-21 04:55:21 +08:00
|
|
|
r = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amdgpu_mode_dumb_create(struct drm_file *file_priv,
|
|
|
|
struct drm_device *dev,
|
|
|
|
struct drm_mode_create_dumb *args)
|
|
|
|
{
|
|
|
|
struct amdgpu_device *adev = dev->dev_private;
|
|
|
|
struct drm_gem_object *gobj;
|
|
|
|
uint32_t handle;
|
|
|
|
int r;
|
|
|
|
|
2016-10-18 06:41:17 +08:00
|
|
|
args->pitch = amdgpu_align_pitch(adev, args->width,
|
|
|
|
DIV_ROUND_UP(args->bpp, 8), 0);
|
2015-09-23 19:00:59 +08:00
|
|
|
args->size = (u64)args->pitch * args->height;
|
2015-04-21 04:55:21 +08:00
|
|
|
args->size = ALIGN(args->size, PAGE_SIZE);
|
|
|
|
|
|
|
|
r = amdgpu_gem_object_create(adev, args->size, 0,
|
|
|
|
AMDGPU_GEM_DOMAIN_VRAM,
|
2015-08-27 12:14:16 +08:00
|
|
|
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
|
2017-08-25 15:14:43 +08:00
|
|
|
false, NULL, &gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = drm_gem_handle_create(file_priv, gobj, &handle);
|
|
|
|
/* drop reference from allocate - handle holds it now */
|
2017-08-03 19:58:16 +08:00
|
|
|
drm_gem_object_put_unlocked(gobj);
|
2015-04-21 04:55:21 +08:00
|
|
|
if (r) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
args->handle = handle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
2016-02-15 22:23:00 +08:00
|
|
|
static int amdgpu_debugfs_gem_bo_info(int id, void *ptr, void *data)
|
|
|
|
{
|
|
|
|
struct drm_gem_object *gobj = ptr;
|
|
|
|
struct amdgpu_bo *bo = gem_to_amdgpu_bo(gobj);
|
|
|
|
struct seq_file *m = data;
|
|
|
|
|
2018-03-25 16:10:25 +08:00
|
|
|
struct dma_buf_attachment *attachment;
|
|
|
|
struct dma_buf *dma_buf;
|
2016-02-15 22:23:00 +08:00
|
|
|
unsigned domain;
|
|
|
|
const char *placement;
|
|
|
|
unsigned pin_count;
|
2017-06-26 21:19:30 +08:00
|
|
|
uint64_t offset;
|
2016-02-15 22:23:00 +08:00
|
|
|
|
|
|
|
domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
|
|
|
|
switch (domain) {
|
|
|
|
case AMDGPU_GEM_DOMAIN_VRAM:
|
|
|
|
placement = "VRAM";
|
|
|
|
break;
|
|
|
|
case AMDGPU_GEM_DOMAIN_GTT:
|
|
|
|
placement = " GTT";
|
|
|
|
break;
|
|
|
|
case AMDGPU_GEM_DOMAIN_CPU:
|
|
|
|
default:
|
|
|
|
placement = " CPU";
|
|
|
|
break;
|
|
|
|
}
|
2017-06-26 21:19:30 +08:00
|
|
|
seq_printf(m, "\t0x%08x: %12ld byte %s",
|
|
|
|
id, amdgpu_bo_size(bo), placement);
|
|
|
|
|
locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.
For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.
However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:
----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()
// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
virtual patch
@ depends on patch @
expression E1, E2;
@@
- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)
@ depends on patch @
expression E;
@@
- ACCESS_ONCE(E)
+ READ_ONCE(E)
----
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-24 05:07:29 +08:00
|
|
|
offset = READ_ONCE(bo->tbo.mem.start);
|
2017-06-26 21:19:30 +08:00
|
|
|
if (offset != AMDGPU_BO_INVALID_OFFSET)
|
|
|
|
seq_printf(m, " @ 0x%010Lx", offset);
|
2016-02-15 22:23:00 +08:00
|
|
|
|
locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.
For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.
However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:
----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()
// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch
virtual patch
@ depends on patch @
expression E1, E2;
@@
- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)
@ depends on patch @
expression E;
@@
- ACCESS_ONCE(E)
+ READ_ONCE(E)
----
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-10-24 05:07:29 +08:00
|
|
|
pin_count = READ_ONCE(bo->pin_count);
|
2016-02-15 22:23:00 +08:00
|
|
|
if (pin_count)
|
|
|
|
seq_printf(m, " pin count %d", pin_count);
|
2018-03-25 16:10:25 +08:00
|
|
|
|
|
|
|
dma_buf = READ_ONCE(bo->gem_base.dma_buf);
|
|
|
|
attachment = READ_ONCE(bo->gem_base.import_attach);
|
|
|
|
|
|
|
|
if (attachment)
|
|
|
|
seq_printf(m, " imported from %p", dma_buf);
|
|
|
|
else if (dma_buf)
|
|
|
|
seq_printf(m, " exported as %p", dma_buf);
|
|
|
|
|
2016-02-15 22:23:00 +08:00
|
|
|
seq_printf(m, "\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 04:55:21 +08:00
|
|
|
static int amdgpu_debugfs_gem_info(struct seq_file *m, void *data)
|
|
|
|
{
|
|
|
|
struct drm_info_node *node = (struct drm_info_node *)m->private;
|
|
|
|
struct drm_device *dev = node->minor->dev;
|
2016-02-15 22:23:00 +08:00
|
|
|
struct drm_file *file;
|
|
|
|
int r;
|
2015-04-21 04:55:21 +08:00
|
|
|
|
2016-04-27 01:29:41 +08:00
|
|
|
r = mutex_lock_interruptible(&dev->filelist_mutex);
|
2016-02-15 22:23:00 +08:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
list_for_each_entry(file, &dev->filelist, lhead) {
|
|
|
|
struct task_struct *task;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Although we have a valid reference on file->pid, that does
|
|
|
|
* not guarantee that the task_struct who called get_pid() is
|
|
|
|
* still alive (e.g. get_pid(current) => fork() => exit()).
|
|
|
|
* Therefore, we need to protect this ->comm access using RCU.
|
|
|
|
*/
|
|
|
|
rcu_read_lock();
|
|
|
|
task = pid_task(file->pid, PIDTYPE_PID);
|
|
|
|
seq_printf(m, "pid %8d command %s:\n", pid_nr(file->pid),
|
|
|
|
task ? task->comm : "<unknown>");
|
|
|
|
rcu_read_unlock();
|
|
|
|
|
|
|
|
spin_lock(&file->table_lock);
|
|
|
|
idr_for_each(&file->object_idr, amdgpu_debugfs_gem_bo_info, m);
|
|
|
|
spin_unlock(&file->table_lock);
|
2015-04-21 04:55:21 +08:00
|
|
|
}
|
2016-02-15 22:23:00 +08:00
|
|
|
|
2016-04-27 01:29:41 +08:00
|
|
|
mutex_unlock(&dev->filelist_mutex);
|
2015-04-21 04:55:21 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-03 00:46:15 +08:00
|
|
|
static const struct drm_info_list amdgpu_debugfs_gem_list[] = {
|
2015-04-21 04:55:21 +08:00
|
|
|
{"amdgpu_gem_info", &amdgpu_debugfs_gem_info, 0, NULL},
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2017-12-15 04:23:14 +08:00
|
|
|
int amdgpu_debugfs_gem_init(struct amdgpu_device *adev)
|
2015-04-21 04:55:21 +08:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_DEBUG_FS)
|
|
|
|
return amdgpu_debugfs_add_files(adev, amdgpu_debugfs_gem_list, 1);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|