/* * Copyright 2008 Jerome Glisse. * All Rights Reserved. * * 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 (including the next * paragraph) 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 * PRECISION INSIGHT AND/OR ITS SUPPLIERS 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: * Jerome Glisse <glisse@freedesktop.org>
*/
r = amdgpu_bo_create_list_entry_array(data, &info); if (r) return r;
r = amdgpu_bo_list_create(p->adev, p->filp, info, data->bo_number,
&p->bo_list); if (r) goto error_free;
kvfree(info); return 0;
error_free:
kvfree(info);
return r;
}
/* Copy the data from userspace and go over it the first time */ staticint amdgpu_cs_pass1(struct amdgpu_cs_parser *p, union drm_amdgpu_cs *cs)
{ struct amdgpu_fpriv *fpriv = p->filp->driver_priv; unsignedint num_ibs[AMDGPU_CS_GANG_SIZE] = { }; struct amdgpu_vm *vm = &fpriv->vm;
uint64_t *chunk_array_user;
uint64_t *chunk_array;
uint32_t uf_offset = 0;
size_t size; int ret; int i;
chunk_array = kvmalloc_array(cs->in.num_chunks, sizeof(uint64_t),
GFP_KERNEL); if (!chunk_array) return -ENOMEM;
/* get chunks */
chunk_array_user = u64_to_user_ptr(cs->in.chunks); if (copy_from_user(chunk_array, chunk_array_user, sizeof(uint64_t)*cs->in.num_chunks)) {
ret = -EFAULT; goto free_chunk;
}
p->nchunks = cs->in.num_chunks;
p->chunks = kvmalloc_array(p->nchunks, sizeof(struct amdgpu_cs_chunk),
GFP_KERNEL); if (!p->chunks) {
ret = -ENOMEM; goto free_chunk;
}
for (i = 0; i < p->nchunks; i++) { struct drm_amdgpu_cs_chunk __user *chunk_ptr = NULL; struct drm_amdgpu_cs_chunk user_chunk;
uint32_t __user *cdata;
p->chunks[i].kdata = kvmalloc_array(size, sizeof(uint32_t),
GFP_KERNEL); if (p->chunks[i].kdata == NULL) {
ret = -ENOMEM;
i--; goto free_partial_kdata;
}
size *= sizeof(uint32_t); if (copy_from_user(p->chunks[i].kdata, cdata, size)) {
ret = -EFAULT; goto free_partial_kdata;
}
/* Assume the worst on the following checks */
ret = -EINVAL; switch (p->chunks[i].chunk_id) { case AMDGPU_CHUNK_ID_IB: if (size < sizeof(struct drm_amdgpu_cs_chunk_ib)) goto free_partial_kdata;
ret = amdgpu_cs_p1_ib(p, p->chunks[i].kdata, num_ibs); if (ret) goto free_partial_kdata; break;
case AMDGPU_CHUNK_ID_FENCE: if (size < sizeof(struct drm_amdgpu_cs_chunk_fence)) goto free_partial_kdata;
ret = amdgpu_cs_p1_user_fence(p, p->chunks[i].kdata,
&uf_offset); if (ret) goto free_partial_kdata; break;
case AMDGPU_CHUNK_ID_BO_HANDLES: if (size < sizeof(struct drm_amdgpu_bo_list_in)) goto free_partial_kdata;
/* Only a single BO list is allowed to simplify handling. */ if (p->bo_list) goto free_partial_kdata;
ret = amdgpu_cs_p1_bo_handles(p, p->chunks[i].kdata); if (ret) goto free_partial_kdata; break;
case AMDGPU_CHUNK_ID_DEPENDENCIES: case AMDGPU_CHUNK_ID_SYNCOBJ_IN: case AMDGPU_CHUNK_ID_SYNCOBJ_OUT: case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES: case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT: case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL: case AMDGPU_CHUNK_ID_CP_GFX_SHADOW: break;
default: goto free_partial_kdata;
}
}
if (!p->gang_size || (amdgpu_sriov_vf(p->adev) && p->gang_size > 1)) {
ret = -EINVAL; goto free_all_kdata;
}
for (i = 0; i < p->gang_size; ++i) {
ret = amdgpu_job_alloc(p->adev, vm, p->entities[i], vm,
num_ibs[i], &p->jobs[i],
p->filp->client_id); if (ret) goto free_all_kdata; switch (p->adev->enforce_isolation[fpriv->xcp_id]) { case AMDGPU_ENFORCE_ISOLATION_DISABLE: default:
p->jobs[i]->enforce_isolation = false;
p->jobs[i]->run_cleaner_shader = false; break; case AMDGPU_ENFORCE_ISOLATION_ENABLE:
p->jobs[i]->enforce_isolation = true;
p->jobs[i]->run_cleaner_shader = true; break; case AMDGPU_ENFORCE_ISOLATION_ENABLE_LEGACY:
p->jobs[i]->enforce_isolation = true;
p->jobs[i]->run_cleaner_shader = false; break; case AMDGPU_ENFORCE_ISOLATION_NO_CLEANER_SHADER:
p->jobs[i]->enforce_isolation = true;
p->jobs[i]->run_cleaner_shader = false; break;
}
}
p->gang_leader = p->jobs[p->gang_leader_idx];
if (p->ctx->generation != p->gang_leader->generation) {
ret = -ECANCELED; goto free_all_kdata;
}
if (p->uf_bo)
p->gang_leader->uf_addr = uf_offset;
kvfree(chunk_array);
/* Use this opportunity to fill in task info for the vm */
amdgpu_vm_set_task_info(vm);
return 0;
free_all_kdata:
i = p->nchunks - 1;
free_partial_kdata: for (; i >= 0; i--)
kvfree(p->chunks[i].kdata);
kvfree(p->chunks);
p->chunks = NULL;
p->nchunks = 0;
free_chunk:
kvfree(chunk_array);
r = amdgpu_sync_fence(&p->sync, fence, GFP_KERNEL);
dma_fence_put(fence); if (r) return r;
} return 0;
}
staticint amdgpu_syncobj_lookup_and_add(struct amdgpu_cs_parser *p,
uint32_t handle, u64 point,
u64 flags)
{ struct dma_fence *fence; int r;
r = drm_syncobj_find_fence(p->filp, handle, point, flags, &fence); if (r) {
DRM_ERROR("syncobj %u failed to find fence @ %llu (%d)!\n",
handle, point, r); return r;
}
r = amdgpu_sync_fence(&p->sync, fence, GFP_KERNEL);
dma_fence_put(fence); return r;
}
staticint amdgpu_cs_p2_syncobj_in(struct amdgpu_cs_parser *p, struct amdgpu_cs_chunk *chunk)
{ struct drm_amdgpu_cs_chunk_sem *deps = chunk->kdata; unsignedint num_deps; int i, r;
num_deps = chunk->length_dw * 4 / sizeof(struct drm_amdgpu_cs_chunk_sem); for (i = 0; i < num_deps; ++i) {
r = amdgpu_syncobj_lookup_and_add(p, deps[i].handle, 0, 0); if (r) return r;
}
return 0;
}
staticint amdgpu_cs_p2_syncobj_timeline_wait(struct amdgpu_cs_parser *p, struct amdgpu_cs_chunk *chunk)
{ struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps = chunk->kdata; unsignedint num_deps; int i, r;
num_deps = chunk->length_dw * 4 / sizeof(struct drm_amdgpu_cs_chunk_syncobj); for (i = 0; i < num_deps; ++i) {
r = amdgpu_syncobj_lookup_and_add(p, syncobj_deps[i].handle,
syncobj_deps[i].point,
syncobj_deps[i].flags); if (r) return r;
}
if (shadow->flags & ~AMDGPU_CS_CHUNK_CP_GFX_SHADOW_FLAGS_INIT_SHADOW) return -EINVAL;
for (i = 0; i < p->gang_size; ++i) {
p->jobs[i]->shadow_va = shadow->shadow_va;
p->jobs[i]->csa_va = shadow->csa_va;
p->jobs[i]->gds_va = shadow->gds_va;
p->jobs[i]->init_shadow =
shadow->flags & AMDGPU_CS_CHUNK_CP_GFX_SHADOW_FLAGS_INIT_SHADOW;
}
return 0;
}
staticint amdgpu_cs_pass2(struct amdgpu_cs_parser *p)
{ unsignedint ce_preempt = 0, de_preempt = 0; int i, r;
for (i = 0; i < p->nchunks; ++i) { struct amdgpu_cs_chunk *chunk;
chunk = &p->chunks[i];
switch (chunk->chunk_id) { case AMDGPU_CHUNK_ID_IB:
r = amdgpu_cs_p2_ib(p, chunk, &ce_preempt, &de_preempt); if (r) return r; break; case AMDGPU_CHUNK_ID_DEPENDENCIES: case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES:
r = amdgpu_cs_p2_dependencies(p, chunk); if (r) return r; break; case AMDGPU_CHUNK_ID_SYNCOBJ_IN:
r = amdgpu_cs_p2_syncobj_in(p, chunk); if (r) return r; break; case AMDGPU_CHUNK_ID_SYNCOBJ_OUT:
r = amdgpu_cs_p2_syncobj_out(p, chunk); if (r) return r; break; case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT:
r = amdgpu_cs_p2_syncobj_timeline_wait(p, chunk); if (r) return r; break; case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL:
r = amdgpu_cs_p2_syncobj_timeline_signal(p, chunk); if (r) return r; break; case AMDGPU_CHUNK_ID_CP_GFX_SHADOW:
r = amdgpu_cs_p2_shadow(p, chunk); if (r) return r; break;
}
}
/* Since accum_us is incremented by a million per second, just * multiply it by the number of MB/s to get the number of bytes.
*/ return us << adev->mm_stats.log2_max_MBps;
}
/* Returns how many bytes TTM can move right now. If no bytes can be moved, * it returns 0. If it returns non-zero, it's OK to move at least one buffer, * which means it can go over the threshold once. If that happens, the driver * will be in debt and no other buffer migrations can be done until that debt * is repaid. * * This approach allows moving a buffer of any size (it's important to allow * that). * * The currency is simply time in microseconds and it increases as the clock * ticks. The accumulated microseconds (us) are converted to bytes and * returned.
*/ staticvoid amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,
u64 *max_bytes,
u64 *max_vis_bytes)
{
s64 time_us, increment_us;
u64 free_vram, total_vram, used_vram; /* Allow a maximum of 200 accumulated ms. This is basically per-IB * throttling. * * It means that in order to get full max MBps, at least 5 IBs per * second must be submitted and not more than 200ms apart from each * other.
*/ const s64 us_upper_bound = 200000;
/* This prevents the short period of low performance when the VRAM * usage is low and the driver is in debt or doesn't have enough * accumulated us to fill VRAM quickly. * * The situation can occur in these cases: * - a lot of VRAM is freed by userspace * - the presence of a big buffer causes a lot of evictions * (solution: split buffers into smaller ones) * * If 128 MB or 1/8th of VRAM is free, start filling it now by setting * accum_us to a positive number.
*/ if (free_vram >= 128 * 1024 * 1024 || free_vram >= total_vram / 8) {
s64 min_us;
/* Be more aggressive on dGPUs. Try to fill a portion of free * VRAM now.
*/ if (!(adev->flags & AMD_IS_APU))
min_us = bytes_to_us(adev, free_vram / 4); else
min_us = 0; /* Reset accum_us on APUs. */
/* This is set to 0 if the driver is in debt to disallow (optional) * buffer moves.
*/
*max_bytes = us_to_bytes(adev, adev->mm_stats.accum_us);
/* Do the same for visible VRAM if half of it is free */ if (!amdgpu_gmc_vram_full_visible(&adev->gmc)) {
u64 total_vis_vram = adev->gmc.visible_vram_size;
u64 used_vis_vram =
amdgpu_vram_mgr_vis_usage(&adev->mman.vram_mgr);
/* Report how many bytes have really been moved for the last command * submission. This can result in a debt that can stop buffer migrations * temporarily.
*/ void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64 num_bytes,
u64 num_vis_bytes)
{
spin_lock(&adev->mm_stats.lock);
adev->mm_stats.accum_us -= bytes_to_us(adev, num_bytes);
adev->mm_stats.accum_us_vis -= bytes_to_us(adev, num_vis_bytes);
spin_unlock(&adev->mm_stats.lock);
}
/* Don't move this buffer if we have depleted our allowance * to move it. Don't move anything if the threshold is zero.
*/ if (p->bytes_moved < p->bytes_moved_threshold &&
(!bo->tbo.base.dma_buf ||
list_empty(&bo->tbo.base.dma_buf->attachments))) { if (!amdgpu_gmc_vram_full_visible(&adev->gmc) &&
(bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)) { /* And don't move a CPU_ACCESS_REQUIRED BO to limited * visible VRAM if we've depleted our allowance to do * that.
*/ if (p->bytes_moved_vis < p->bytes_moved_vis_threshold)
domain = bo->preferred_domains; else
domain = bo->allowed_domains;
} else {
domain = bo->preferred_domains;
}
} else {
domain = bo->allowed_domains;
}
retry:
amdgpu_bo_placement_from_domain(bo, domain);
r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
/* p->bo_list could already be assigned if AMDGPU_CHUNK_ID_BO_HANDLES is present */ if (cs->in.bo_list_handle) { if (p->bo_list) return -EINVAL;
r = amdgpu_bo_list_get(fpriv, cs->in.bo_list_handle,
&p->bo_list); if (r) return r;
} elseif (!p->bo_list) { /* Create a empty bo_list when no handle is provided */
r = amdgpu_bo_list_create(p->adev, p->filp, NULL, 0,
&p->bo_list); if (r) return r;
}
mutex_lock(&p->bo_list->bo_list_mutex);
/* Get userptr backing pages. If pages are updated after registered * in amdgpu_gem_userptr_ioctl(), amdgpu_cs_list_validate() will do * amdgpu_ttm_backend_bind() to flush and invalidate new pages
*/
amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) { bool userpage_invalidated = false; struct amdgpu_bo *bo = e->bo; int i;
e->user_pages = kvcalloc(bo->tbo.ttm->num_pages, sizeof(struct page *),
GFP_KERNEL); if (!e->user_pages) {
DRM_ERROR("kvmalloc_array failure\n");
r = -ENOMEM; goto out_free_user_pages;
}
r = amdgpu_ttm_tt_get_user_pages(bo, e->user_pages, &e->range); if (r) {
kvfree(e->user_pages);
e->user_pages = NULL; goto out_free_user_pages;
}
for (i = 0; i < bo->tbo.ttm->num_pages; i++) { if (bo->tbo.ttm->pages[i] != e->user_pages[i]) {
userpage_invalidated = true; break;
}
}
e->user_invalidated = userpage_invalidated;
}
drm_exec_until_all_locked(&p->exec) {
r = amdgpu_vm_lock_pd(&fpriv->vm, &p->exec, 1 + p->gang_size);
drm_exec_retry_on_contention(&p->exec); if (unlikely(r)) goto out_free_user_pages;
amdgpu_bo_list_for_each_entry(e, p->bo_list) { /* One fence for TTM and one for each CS job */
r = drm_exec_prepare_obj(&p->exec, &e->bo->tbo.base,
1 + p->gang_size);
drm_exec_retry_on_contention(&p->exec); if (unlikely(r)) goto out_free_user_pages;
e->bo_va = amdgpu_vm_bo_find(vm, e->bo);
}
if (p->uf_bo) {
r = drm_exec_prepare_obj(&p->exec, &p->uf_bo->tbo.base,
1 + p->gang_size);
drm_exec_retry_on_contention(&p->exec); if (unlikely(r)) goto out_free_user_pages;
}
}
/* * We can't use gang submit on with reserved VMIDs when the VM changes * can't be invalidated by more than one engine at the same time.
*/ if (p->gang_size > 1 && !adev->vm_manager.concurrent_flush) { for (i = 0; i < p->gang_size; ++i) { struct drm_sched_entity *entity = p->entities[i]; struct drm_gpu_scheduler *sched = entity->rq->sched; struct amdgpu_ring *ring = to_amdgpu_ring(sched);
if (amdgpu_vmid_uses_reserved(vm, ring->vm_hub)) return -EINVAL;
}
}
if (!amdgpu_vm_ready(vm)) return -EINVAL;
r = amdgpu_vm_clear_freed(adev, vm, NULL); if (r) return r;
r = amdgpu_vm_bo_update(adev, fpriv->prt_va, false); if (r) return r;
r = amdgpu_sync_fence(&p->sync, fpriv->prt_va->last_pt_update,
GFP_KERNEL); if (r) return r;
if (fpriv->csa_va) {
bo_va = fpriv->csa_va;
BUG_ON(!bo_va);
r = amdgpu_vm_bo_update(adev, bo_va, false); if (r) return r;
r = amdgpu_sync_fence(&p->sync, bo_va->last_pt_update,
GFP_KERNEL); if (r) return r;
}
/* FIXME: In theory this loop shouldn't be needed any more when * amdgpu_vm_handle_moved handles all moved BOs that are reserved * with p->ticket. But removing it caused test regressions, so I'm * leaving it here for now.
*/
amdgpu_bo_list_for_each_entry(e, p->bo_list) {
bo_va = e->bo_va; if (bo_va == NULL) continue;
r = amdgpu_vm_bo_update(adev, bo_va, false); if (r) return r;
r = amdgpu_sync_fence(&p->sync, bo_va->last_pt_update,
GFP_KERNEL); if (r) return r;
}
r = amdgpu_vm_handle_moved(adev, vm, &p->exec.ticket); if (r) return r;
r = amdgpu_vm_update_pdes(adev, vm, false); if (r) return r;
r = amdgpu_sync_fence(&p->sync, vm->last_update, GFP_KERNEL); if (r) return r;
for (i = 0; i < p->gang_size; ++i) {
job = p->jobs[i];
/* * When we have an dependency it might be necessary to insert a * pipeline sync to make sure that all caches etc are flushed and the * next job actually sees the results from the previous one * before we start executing on the same scheduler ring.
*/ if (!s_fence || s_fence->sched != sched) {
dma_fence_put(fence); continue;
}
r = amdgpu_sync_fence(&p->gang_leader->explicit_sync, fence,
GFP_KERNEL);
dma_fence_put(fence); if (r) return r;
} return 0;
}
staticvoid amdgpu_cs_post_dependencies(struct amdgpu_cs_parser *p)
{ int i;
for (i = 0; i < p->num_post_deps; ++i) { if (p->post_deps[i].chain && p->post_deps[i].point) {
drm_syncobj_add_point(p->post_deps[i].syncobj,
p->post_deps[i].chain,
p->fence, p->post_deps[i].point);
p->post_deps[i].chain = NULL;
} else {
drm_syncobj_replace_fence(p->post_deps[i].syncobj,
p->fence);
}
}
}
for (i = 0; i < p->gang_size; ++i)
drm_sched_job_arm(&p->jobs[i]->base);
for (i = 0; i < p->gang_size; ++i) { struct dma_fence *fence;
if (p->jobs[i] == leader) continue;
fence = &p->jobs[i]->base.s_fence->scheduled;
dma_fence_get(fence);
r = drm_sched_job_add_dependency(&leader->base, fence); if (r) {
dma_fence_put(fence); return r;
}
}
if (p->gang_size > 1) { for (i = 0; i < p->gang_size; ++i)
amdgpu_job_set_gang_leader(p->jobs[i], leader);
}
/* No memory allocation is allowed while holding the notifier lock. * The lock is held until amdgpu_cs_submit is finished and fence is * added to BOs.
*/
mutex_lock(&p->adev->notifier_lock);
/* If userptr are invalidated after amdgpu_cs_parser_bos(), return * -EAGAIN, drmIoctl in libdrm will restart the amdgpu_cs_ioctl.
*/
r = 0;
amdgpu_bo_list_for_each_userptr_entry(e, p->bo_list) {
r |= !amdgpu_ttm_tt_get_user_pages_done(e->bo->tbo.ttm,
e->range);
e->range = NULL;
} if (r) {
r = -EAGAIN;
mutex_unlock(&p->adev->notifier_lock); return r;
}
for (i = 0; i < parser->num_post_deps; i++) {
drm_syncobj_put(parser->post_deps[i].syncobj);
kfree(parser->post_deps[i].chain);
}
kfree(parser->post_deps);
dma_fence_put(parser->fence);
if (parser->ctx)
amdgpu_ctx_put(parser->ctx); if (parser->bo_list)
amdgpu_bo_list_put(parser->bo_list);
for (i = 0; i < parser->nchunks; i++)
kvfree(parser->chunks[i].kdata);
kvfree(parser->chunks); for (i = 0; i < parser->gang_size; ++i) { if (parser->jobs[i])
amdgpu_job_free(parser->jobs[i]);
}
amdgpu_bo_unref(&parser->uf_bo);
}
int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{ struct amdgpu_device *adev = drm_to_adev(dev); struct amdgpu_cs_parser parser; int r;
if (amdgpu_ras_intr_triggered()) return -EHWPOISON;
if (!adev->accel_working) return -EBUSY;
r = amdgpu_cs_parser_init(&parser, adev, filp, data); if (r) {
DRM_ERROR_RATELIMITED("Failed to initialize parser %d!\n", r); return r;
}
r = amdgpu_cs_pass1(&parser, data); if (r) goto error_fini;
r = amdgpu_cs_pass2(&parser); if (r) goto error_fini;
r = amdgpu_cs_parser_bos(&parser, data); if (r) { if (r == -ENOMEM)
DRM_ERROR("Not enough memory for command submission!\n"); elseif (r != -ERESTARTSYS && r != -EAGAIN)
DRM_DEBUG("Failed to process the buffer list %d!\n", r); goto error_fini;
}
r = amdgpu_cs_patch_jobs(&parser); if (r) goto error_backoff;
r = amdgpu_cs_vm_handling(&parser); if (r) goto error_backoff;
r = amdgpu_cs_sync_rings(&parser); if (r) goto error_backoff;
trace_amdgpu_cs_ibs(&parser);
r = amdgpu_cs_submit(&parser, data); if (r) goto error_backoff;
fence = amdgpu_cs_get_fence(adev, filp, &info->in.fence); if (IS_ERR(fence)) return PTR_ERR(fence);
if (!fence)
fence = dma_fence_get_stub();
switch (info->in.what) { case AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ:
r = drm_syncobj_create(&syncobj, 0, fence);
dma_fence_put(fence); if (r) return r;
r = drm_syncobj_get_handle(filp, syncobj, &info->out.handle);
drm_syncobj_put(syncobj); return r;
case AMDGPU_FENCE_TO_HANDLE_GET_SYNCOBJ_FD:
r = drm_syncobj_create(&syncobj, 0, fence);
dma_fence_put(fence); if (r) return r;
r = drm_syncobj_get_fd(syncobj, (int *)&info->out.handle);
drm_syncobj_put(syncobj); return r;
case AMDGPU_FENCE_TO_HANDLE_GET_SYNC_FILE_FD:
fd = get_unused_fd_flags(O_CLOEXEC); if (fd < 0) {
dma_fence_put(fence); return fd;
}
if (first < fence_count && array[first])
r = array[first]->error; else
r = 0;
err_free_fence_array: for (i = 0; i < fence_count; i++)
dma_fence_put(array[i]);
kfree(array);
return r;
}
/** * amdgpu_cs_wait_fences_ioctl - wait for multiple command submissions to finish * * @dev: drm device * @data: data from userspace * @filp: file private
*/ int amdgpu_cs_wait_fences_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{ struct amdgpu_device *adev = drm_to_adev(dev); union drm_amdgpu_wait_fences *wait = data; struct drm_amdgpu_fence *fences; int r;
/* Get the fences from userspace */
fences = memdup_array_user(u64_to_user_ptr(wait->in.fences),
wait->in.fence_count, sizeof(struct drm_amdgpu_fence)); if (IS_ERR(fences)) return PTR_ERR(fences);
if (wait->in.wait_all)
r = amdgpu_cs_wait_all_fences(adev, filp, wait, fences); else
r = amdgpu_cs_wait_any_fence(adev, filp, wait, fences);
kfree(fences);
return r;
}
/** * amdgpu_cs_find_mapping - find bo_va for VM address * * @parser: command submission parser context * @addr: VM address * @bo: resulting BO of the mapping found * @map: Placeholder to return found BO mapping * * Search the buffer objects in the command submission context for a certain * virtual memory address. Returns allocation structure when found, NULL * otherwise.
*/ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser *parser,
uint64_t addr, struct amdgpu_bo **bo, struct amdgpu_bo_va_mapping **map)
{ struct amdgpu_fpriv *fpriv = parser->filp->driver_priv; struct ttm_operation_ctx ctx = { false, false }; struct amdgpu_vm *vm = &fpriv->vm; struct amdgpu_bo_va_mapping *mapping; int i, r;
/* Double check that the BO is reserved by this CS */ if (dma_resv_locking_ctx((*bo)->tbo.base.resv) != &parser->exec.ticket) return -EINVAL;
/* Make sure VRAM is allocated contigiously */
(*bo)->flags |= AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS; if ((*bo)->tbo.resource->mem_type == TTM_PL_VRAM &&
!((*bo)->tbo.resource->placement & TTM_PL_FLAG_CONTIGUOUS)) {
amdgpu_bo_placement_from_domain(*bo, (*bo)->allowed_domains); for (i = 0; i < (*bo)->placement.num_placement; i++)
(*bo)->placements[i].flags |= TTM_PL_FLAG_CONTIGUOUS;
r = ttm_bo_validate(&(*bo)->tbo, &(*bo)->placement, &ctx); if (r) return r;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.