dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / gpu / drm / msm / msm_ringbuffer.c
blob20a96fe69dcd89b4ed4e5cf3332df81deb709d33
1 /*
2 * Copyright (C) 2013 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
14 * You should have received a copy of the GNU General Public License along with
15 * this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "msm_ringbuffer.h"
19 #include "msm_gpu.h"
21 struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,
22 void *memptrs, uint64_t memptrs_iova)
24 struct msm_ringbuffer *ring;
25 char name[32];
26 int ret;
28 /* We assume everwhere that MSM_GPU_RINGBUFFER_SZ is a power of 2 */
29 BUILD_BUG_ON(!is_power_of_2(MSM_GPU_RINGBUFFER_SZ));
31 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
32 if (!ring) {
33 ret = -ENOMEM;
34 goto fail;
37 ring->gpu = gpu;
38 ring->id = id;
40 ring->start = msm_gem_kernel_new(gpu->dev, MSM_GPU_RINGBUFFER_SZ,
41 MSM_BO_WC, gpu->aspace, &ring->bo, &ring->iova);
43 if (IS_ERR(ring->start)) {
44 ret = PTR_ERR(ring->start);
45 ring->start = 0;
46 goto fail;
49 msm_gem_object_set_name(ring->bo, "ring%d", id);
51 ring->end = ring->start + (MSM_GPU_RINGBUFFER_SZ >> 2);
52 ring->next = ring->start;
53 ring->cur = ring->start;
55 ring->memptrs = memptrs;
56 ring->memptrs_iova = memptrs_iova;
58 INIT_LIST_HEAD(&ring->submits);
59 spin_lock_init(&ring->lock);
61 snprintf(name, sizeof(name), "gpu-ring-%d", ring->id);
63 ring->fctx = msm_fence_context_alloc(gpu->dev, name);
65 return ring;
67 fail:
68 msm_ringbuffer_destroy(ring);
69 return ERR_PTR(ret);
72 void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
74 if (IS_ERR_OR_NULL(ring))
75 return;
77 msm_fence_context_free(ring->fctx);
79 msm_gem_kernel_put(ring->bo, ring->gpu->aspace, false);
81 kfree(ring);