2019-06-03 12:44:50 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2013-07-19 23:59:32 +07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Red Hat
|
|
|
|
* Author: Rob Clark <robdclark@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "msm_ringbuffer.h"
|
|
|
|
#include "msm_gpu.h"
|
|
|
|
|
2017-10-21 00:06:57 +07:00
|
|
|
struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,
|
|
|
|
void *memptrs, uint64_t memptrs_iova)
|
2013-07-19 23:59:32 +07:00
|
|
|
{
|
|
|
|
struct msm_ringbuffer *ring;
|
2017-10-21 00:06:57 +07:00
|
|
|
char name[32];
|
2013-07-19 23:59:32 +07:00
|
|
|
int ret;
|
|
|
|
|
2017-10-21 00:06:57 +07: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-19 23:59:32 +07:00
|
|
|
|
|
|
|
ring = kzalloc(sizeof(*ring), GFP_KERNEL);
|
|
|
|
if (!ring) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ring->gpu = gpu;
|
2017-10-21 00:06:57 +07:00
|
|
|
ring->id = id;
|
2018-11-08 05:35:54 +07:00
|
|
|
|
2017-10-21 00:06:57 +07:00
|
|
|
ring->start = msm_gem_kernel_new(gpu->dev, MSM_GPU_RINGBUFFER_SZ,
|
2018-11-08 05:35:54 +07:00
|
|
|
MSM_BO_WC, gpu->aspace, &ring->bo, &ring->iova);
|
2017-07-27 23:42:40 +07:00
|
|
|
|
2016-05-25 05:29:38 +07:00
|
|
|
if (IS_ERR(ring->start)) {
|
|
|
|
ret = PTR_ERR(ring->start);
|
2017-07-27 23:42:40 +07:00
|
|
|
ring->start = 0;
|
2016-05-25 05:29:38 +07:00
|
|
|
goto fail;
|
|
|
|
}
|
2018-11-08 05:35:52 +07:00
|
|
|
|
|
|
|
msm_gem_object_set_name(ring->bo, "ring%d", id);
|
|
|
|
|
2017-10-21 00:06:57 +07:00
|
|
|
ring->end = ring->start + (MSM_GPU_RINGBUFFER_SZ >> 2);
|
2017-10-21 00:06:59 +07:00
|
|
|
ring->next = ring->start;
|
2013-07-19 23:59:32 +07:00
|
|
|
ring->cur = ring->start;
|
|
|
|
|
2017-10-21 00:06:57 +07:00
|
|
|
ring->memptrs = memptrs;
|
|
|
|
ring->memptrs_iova = memptrs_iova;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&ring->submits);
|
2017-10-21 00:07:01 +07:00
|
|
|
spin_lock_init(&ring->lock);
|
2017-10-21 00:06:57 +07:00
|
|
|
|
|
|
|
snprintf(name, sizeof(name), "gpu-ring-%d", ring->id);
|
|
|
|
|
|
|
|
ring->fctx = msm_fence_context_alloc(gpu->dev, name);
|
2013-07-19 23:59:32 +07:00
|
|
|
|
|
|
|
return ring;
|
|
|
|
|
|
|
|
fail:
|
2017-10-21 00:06:57 +07:00
|
|
|
msm_ringbuffer_destroy(ring);
|
2013-07-19 23:59:32 +07:00
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
|
|
|
|
{
|
2017-10-21 00:06:57 +07:00
|
|
|
if (IS_ERR_OR_NULL(ring))
|
|
|
|
return;
|
|
|
|
|
|
|
|
msm_fence_context_free(ring->fctx);
|
|
|
|
|
2018-11-08 05:35:46 +07:00
|
|
|
msm_gem_kernel_put(ring->bo, ring->gpu->aspace, false);
|
|
|
|
|
2013-07-19 23:59:32 +07:00
|
|
|
kfree(ring);
|
|
|
|
}
|