2013-07-20 00:59:32 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Red Hat
|
|
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "msm_ringbuffer.h"
|
|
|
|
#include "msm_gpu.h"
|
|
|
|
|
2017-10-21 01:06:57 +08:00
|
|
|
struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,
|
|
|
|
void *memptrs, uint64_t memptrs_iova)
|
2013-07-20 00:59:32 +08:00
|
|
|
{
|
|
|
|
struct msm_ringbuffer *ring;
|
2017-10-21 01:06:57 +08:00
|
|
|
char name[32];
|
2013-07-20 00:59:32 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-10-21 01:06:57 +08:00
|
|
|
/* We assume everwhere that MSM_GPU_RINGBUFFER_SZ is a power of 2 */
|
|
|
|
BUILD_BUG_ON(!is_power_of_2(MSM_GPU_RINGBUFFER_SZ));
|
2013-07-20 00:59:32 +08:00
|
|
|
|
|
|
|
ring = kzalloc(sizeof(*ring), GFP_KERNEL);
|
|
|
|
if (!ring) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ring->gpu = gpu;
|
2017-10-21 01:06:57 +08:00
|
|
|
ring->id = id;
|
2017-07-28 00:42:40 +08:00
|
|
|
/* Pass NULL for the iova pointer - we will map it later */
|
2017-10-21 01:06:57 +08:00
|
|
|
ring->start = msm_gem_kernel_new(gpu->dev, MSM_GPU_RINGBUFFER_SZ,
|
|
|
|
MSM_BO_WC, gpu->aspace, &ring->bo, NULL);
|
2017-07-28 00:42:40 +08:00
|
|
|
|
2016-05-25 06:29:38 +08:00
|
|
|
if (IS_ERR(ring->start)) {
|
|
|
|
ret = PTR_ERR(ring->start);
|
2017-07-28 00:42:40 +08:00
|
|
|
ring->start = 0;
|
2016-05-25 06:29:38 +08:00
|
|
|
goto fail;
|
|
|
|
}
|
2017-10-21 01:06:57 +08:00
|
|
|
ring->end = ring->start + (MSM_GPU_RINGBUFFER_SZ >> 2);
|
2017-10-21 01:06:59 +08:00
|
|
|
ring->next = ring->start;
|
2013-07-20 00:59:32 +08:00
|
|
|
ring->cur = ring->start;
|
|
|
|
|
2017-10-21 01:06:57 +08:00
|
|
|
ring->memptrs = memptrs;
|
|
|
|
ring->memptrs_iova = memptrs_iova;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ring->submits);
|
2017-10-21 01:07:01 +08:00
|
|
|
spin_lock_init(&ring->lock);
|
2017-10-21 01:06:57 +08:00
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "gpu-ring-%d", ring->id);
|
|
|
|
|
|
|
|
ring->fctx = msm_fence_context_alloc(gpu->dev, name);
|
2013-07-20 00:59:32 +08:00
|
|
|
|
|
|
|
return ring;
|
|
|
|
|
|
|
|
fail:
|
2017-10-21 01:06:57 +08:00
|
|
|
msm_ringbuffer_destroy(ring);
|
2013-07-20 00:59:32 +08:00
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
|
|
|
|
{
|
2017-10-21 01:06:57 +08:00
|
|
|
if (IS_ERR_OR_NULL(ring))
|
|
|
|
return;
|
|
|
|
|
|
|
|
msm_fence_context_free(ring->fctx);
|
|
|
|
|
2016-05-27 04:24:35 +08:00
|
|
|
if (ring->bo) {
|
2017-10-21 01:06:57 +08:00
|
|
|
msm_gem_put_iova(ring->bo, ring->gpu->aspace);
|
2016-05-27 04:24:35 +08:00
|
|
|
msm_gem_put_vaddr(ring->bo);
|
2018-01-26 11:55:54 +08:00
|
|
|
drm_gem_object_put_unlocked(ring->bo);
|
2016-05-27 04:24:35 +08:00
|
|
|
}
|
2013-07-20 00:59:32 +08:00
|
|
|
kfree(ring);
|
|
|
|
}
|