/* * Copyright 2013 Advanced Micro Devices, Inc. * 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, sub license, 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 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 NON-INFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDERS, AUTHORS 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. * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * Authors: Christian König <christian.koenig@amd.com>
*/
/** * amdgpu_vce_sw_init - allocate memory, load vce firmware * * @adev: amdgpu_device pointer * @size: size for the new BO * * First step to get VCE online, allocate memory and load the firmware
*/ int amdgpu_vce_sw_init(struct amdgpu_device *adev, unsignedlong size)
{ constchar *fw_name; conststruct common_firmware_header *hdr; unsignedint ucode_version, version_major, version_minor, binary_id; int i, r;
switch (adev->asic_type) { #ifdef CONFIG_DRM_AMDGPU_CIK case CHIP_BONAIRE:
fw_name = FIRMWARE_BONAIRE; break; case CHIP_KAVERI:
fw_name = FIRMWARE_KAVERI; break; case CHIP_KABINI:
fw_name = FIRMWARE_KABINI; break; case CHIP_HAWAII:
fw_name = FIRMWARE_HAWAII; break; case CHIP_MULLINS:
fw_name = FIRMWARE_MULLINS; break; #endif case CHIP_TONGA:
fw_name = FIRMWARE_TONGA; break; case CHIP_CARRIZO:
fw_name = FIRMWARE_CARRIZO; break; case CHIP_FIJI:
fw_name = FIRMWARE_FIJI; break; case CHIP_STONEY:
fw_name = FIRMWARE_STONEY; break; case CHIP_POLARIS10:
fw_name = FIRMWARE_POLARIS10; break; case CHIP_POLARIS11:
fw_name = FIRMWARE_POLARIS11; break; case CHIP_POLARIS12:
fw_name = FIRMWARE_POLARIS12; break; case CHIP_VEGAM:
fw_name = FIRMWARE_VEGAM; break; case CHIP_VEGA10:
fw_name = FIRMWARE_VEGA10; break; case CHIP_VEGA12:
fw_name = FIRMWARE_VEGA12; break; case CHIP_VEGA20:
fw_name = FIRMWARE_VEGA20; break;
/** * amdgpu_vce_idle_work_handler - power off VCE * * @work: pointer to work structure * * power of VCE when it's not used any more
*/ staticvoid amdgpu_vce_idle_work_handler(struct work_struct *work)
{ struct amdgpu_device *adev =
container_of(work, struct amdgpu_device, vce.idle_work.work); unsignedint i, count = 0;
for (i = 0; i < adev->vce.num_rings; i++)
count += amdgpu_fence_count_emitted(&adev->vce.ring[i]);
/** * amdgpu_vce_ring_begin_use - power up VCE * * @ring: amdgpu ring * * Make sure VCE is powerd up when we want to use it
*/ void amdgpu_vce_ring_begin_use(struct amdgpu_ring *ring)
{ struct amdgpu_device *adev = ring->adev; bool set_clocks;
/** * amdgpu_vce_ring_end_use - power VCE down * * @ring: amdgpu ring * * Schedule work to power VCE down again
*/ void amdgpu_vce_ring_end_use(struct amdgpu_ring *ring)
{ if (!amdgpu_sriov_vf(ring->adev))
schedule_delayed_work(&ring->adev->vce.idle_work, VCE_IDLE_TIMEOUT);
}
/** * amdgpu_vce_free_handles - free still open VCE handles * * @adev: amdgpu_device pointer * @filp: drm file pointer * * Close all VCE handles still open by this file pointer
*/ void amdgpu_vce_free_handles(struct amdgpu_device *adev, struct drm_file *filp)
{ struct amdgpu_ring *ring = &adev->vce.ring[0]; int i, r;
for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i) {
uint32_t handle = atomic_read(&adev->vce.handles[i]);
if (!handle || adev->vce.filp[i] != filp) continue;
r = amdgpu_vce_get_destroy_msg(ring, handle, false, NULL); if (r)
DRM_ERROR("Error destroying VCE handle (%d)!\n", r);
/** * amdgpu_vce_get_create_msg - generate a VCE create msg * * @ring: ring we should submit the msg to * @handle: VCE session handle to use * @fence: optional fence to return * * Open up a stream for HW test
*/ staticint amdgpu_vce_get_create_msg(struct amdgpu_ring *ring, uint32_t handle, struct dma_fence **fence)
{ constunsignedint ib_size_dw = 1024; struct amdgpu_job *job; struct amdgpu_ib *ib; struct amdgpu_ib ib_msg; struct dma_fence *f = NULL;
uint64_t addr; int i, r;
r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity,
AMDGPU_FENCE_OWNER_UNDEFINED,
ib_size_dw * 4, AMDGPU_IB_POOL_DIRECT,
&job); if (r) return r;
memset(&ib_msg, 0, sizeof(ib_msg)); /* only one gpu page is needed, alloc +1 page to make addr aligned. */
r = amdgpu_ib_get(ring->adev, NULL, AMDGPU_GPU_PAGE_SIZE * 2,
AMDGPU_IB_POOL_DIRECT,
&ib_msg); if (r) goto err;
ib = &job->ibs[0]; /* let addr point to page boundary */
addr = AMDGPU_GPU_PAGE_ALIGN(ib_msg.gpu_addr);
/* stitch together an VCE create msg */
ib->length_dw = 0;
ib->ptr[ib->length_dw++] = 0x0000000c; /* len */
ib->ptr[ib->length_dw++] = 0x00000001; /* session cmd */
ib->ptr[ib->length_dw++] = handle;
for (i = ib->length_dw; i < ib_size_dw; ++i)
ib->ptr[i] = 0x0;
r = amdgpu_job_submit_direct(job, ring, &f);
amdgpu_ib_free(&ib_msg, f); if (r) goto err;
if (fence)
*fence = dma_fence_get(f);
dma_fence_put(f); return 0;
err:
amdgpu_job_free(job); return r;
}
/** * amdgpu_vce_get_destroy_msg - generate a VCE destroy msg * * @ring: ring we should submit the msg to * @handle: VCE session handle to use * @direct: direct or delayed pool * @fence: optional fence to return * * Close up a stream for HW test or if userspace failed to do so
*/ staticint amdgpu_vce_get_destroy_msg(struct amdgpu_ring *ring, uint32_t handle, bool direct, struct dma_fence **fence)
{ constunsignedint ib_size_dw = 1024; struct amdgpu_job *job; struct amdgpu_ib *ib; struct dma_fence *f = NULL; int i, r;
r = amdgpu_job_alloc_with_ib(ring->adev, &ring->adev->vce.entity,
AMDGPU_FENCE_OWNER_UNDEFINED,
ib_size_dw * 4,
direct ? AMDGPU_IB_POOL_DIRECT :
AMDGPU_IB_POOL_DELAYED, &job); if (r) return r;
ib = &job->ibs[0];
/* stitch together an VCE destroy msg */
ib->length_dw = 0;
ib->ptr[ib->length_dw++] = 0x0000000c; /* len */
ib->ptr[ib->length_dw++] = 0x00000001; /* session cmd */
ib->ptr[ib->length_dw++] = handle;
ib->ptr[ib->length_dw++] = 0x00000020; /* len */
ib->ptr[ib->length_dw++] = 0x00000002; /* task info */
ib->ptr[ib->length_dw++] = 0xffffffff; /* next task info, set to 0xffffffff if no */
ib->ptr[ib->length_dw++] = 0x00000001; /* destroy session */
ib->ptr[ib->length_dw++] = 0x00000000;
ib->ptr[ib->length_dw++] = 0x00000000;
ib->ptr[ib->length_dw++] = 0xffffffff; /* feedback is not needed, set to 0xffffffff and firmware will not output feedback */
ib->ptr[ib->length_dw++] = 0x00000000;
/** * amdgpu_vce_validate_handle - validate stream handle * * @p: parser context * @handle: handle to validate * @allocated: allocated a new handle? * * Validates the handle and return the found session index or -EINVAL * we don't have another free session index.
*/ staticint amdgpu_vce_validate_handle(struct amdgpu_cs_parser *p,
uint32_t handle, uint32_t *allocated)
{ unsignedint i;
/* validate the handle */ for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i) { if (atomic_read(&p->adev->vce.handles[i]) == handle) { if (p->adev->vce.filp[i] != p->filp) {
DRM_ERROR("VCE handle collision detected!\n"); return -EINVAL;
} return i;
}
}
/* handle not found try to alloc a new one */ for (i = 0; i < AMDGPU_MAX_VCE_HANDLES; ++i) { if (!atomic_cmpxchg(&p->adev->vce.handles[i], 0, handle)) {
p->adev->vce.filp[i] = p->filp;
p->adev->vce.img_size[i] = 0;
*allocated |= 1 << i; return i;
}
}
DRM_ERROR("No more free VCE handles!\n"); return -EINVAL;
}
/** * amdgpu_vce_ring_parse_cs - parse and validate the command stream * * @p: parser context * @job: the job to parse * @ib: the IB to patch
*/ int amdgpu_vce_ring_parse_cs(struct amdgpu_cs_parser *p, struct amdgpu_job *job, struct amdgpu_ib *ib)
{ unsignedint fb_idx = 0, bs_idx = 0; int session_idx = -1;
uint32_t destroyed = 0;
uint32_t created = 0;
uint32_t allocated = 0;
uint32_t tmp, handle = 0;
uint32_t dummy = 0xffffffff;
uint32_t *size = &dummy; unsignedint idx; int i, r = 0;
job->vm = NULL;
for (idx = 0; idx < ib->length_dw;) {
uint32_t len = amdgpu_ib_get_value(ib, idx);
uint32_t cmd = amdgpu_ib_get_value(ib, idx + 1);
case 0x04000001: /* config extension */ case 0x04000002: /* pic control */ case 0x04000005: /* rate control */ case 0x04000007: /* motion estimation */ case 0x04000008: /* rdo */ case 0x04000009: /* vui */ case 0x05000002: /* auxiliary buffer */ case 0x05000009: /* clock table */ break;
case 0x0500000c: /* hw config */ switch (p->adev->asic_type) { #ifdef CONFIG_DRM_AMDGPU_CIK case CHIP_KAVERI: case CHIP_MULLINS: #endif case CHIP_CARRIZO: break; default:
r = -EINVAL; goto out;
} break;
case 0x03000001: /* encode */
r = amdgpu_vce_cs_reloc(p, ib, idx + 10, idx + 9,
*size, 0); if (r) goto out;
r = amdgpu_vce_cs_reloc(p, ib, idx + 12, idx + 11,
*size / 3, 0); if (r) goto out; break;
/** * amdgpu_vce_ring_test_ring - test if VCE ring is working * * @ring: the engine to test on *
*/ int amdgpu_vce_ring_test_ring(struct amdgpu_ring *ring)
{ struct amdgpu_device *adev = ring->adev;
uint32_t rptr; unsignedint i; int r, timeout = adev->usec_timeout;
/* skip ring test for sriov*/ if (amdgpu_sriov_vf(adev)) return 0;
for (i = 0; i < timeout; i++) { if (amdgpu_ring_get_rptr(ring) != rptr) break;
udelay(1);
}
if (i >= timeout)
r = -ETIMEDOUT;
return r;
}
/** * amdgpu_vce_ring_test_ib - test if VCE IBs are working * * @ring: the engine to test on * @timeout: timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT *
*/ int amdgpu_vce_ring_test_ib(struct amdgpu_ring *ring, long timeout)
{ struct dma_fence *fence = NULL; long r;
/* skip vce ring1/2 ib test for now, since it's not reliable */ if (ring != &ring->adev->vce.ring[0]) return 0;
r = amdgpu_vce_get_create_msg(ring, 1, NULL); if (r) goto error;
r = amdgpu_vce_get_destroy_msg(ring, 1, true, &fence); if (r) goto error;
r = dma_fence_wait_timeout(fence, false, timeout); if (r == 0)
r = -ETIMEDOUT; elseif (r > 0)
r = 0;
error:
dma_fence_put(fence); return r;
}
enum amdgpu_ring_priority_level amdgpu_vce_get_ring_prio(int ring)
{ switch (ring) { case 0: return AMDGPU_RING_PRIO_0; case 1: return AMDGPU_RING_PRIO_1; case 2: return AMDGPU_RING_PRIO_2; default: return AMDGPU_RING_PRIO_0;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.4 Sekunden
(vorverarbeitet)
¤
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.