1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2013 Red Hat
4 * Author: Rob Clark <robdclark@gmail.com>
7 #include "msm_ringbuffer.h"
10 struct msm_ringbuffer
*msm_ringbuffer_new(struct msm_gpu
*gpu
, int id
,
11 void *memptrs
, uint64_t memptrs_iova
)
13 struct msm_ringbuffer
*ring
;
17 /* We assume everwhere that MSM_GPU_RINGBUFFER_SZ is a power of 2 */
18 BUILD_BUG_ON(!is_power_of_2(MSM_GPU_RINGBUFFER_SZ
));
20 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
29 ring
->start
= msm_gem_kernel_new(gpu
->dev
, MSM_GPU_RINGBUFFER_SZ
,
30 check_apriv(gpu
, MSM_BO_WC
| MSM_BO_GPU_READONLY
),
31 gpu
->aspace
, &ring
->bo
, &ring
->iova
);
33 if (IS_ERR(ring
->start
)) {
34 ret
= PTR_ERR(ring
->start
);
39 msm_gem_object_set_name(ring
->bo
, "ring%d", id
);
41 ring
->end
= ring
->start
+ (MSM_GPU_RINGBUFFER_SZ
>> 2);
42 ring
->next
= ring
->start
;
43 ring
->cur
= ring
->start
;
45 ring
->memptrs
= memptrs
;
46 ring
->memptrs_iova
= memptrs_iova
;
48 INIT_LIST_HEAD(&ring
->submits
);
49 spin_lock_init(&ring
->submit_lock
);
50 spin_lock_init(&ring
->preempt_lock
);
52 snprintf(name
, sizeof(name
), "gpu-ring-%d", ring
->id
);
54 ring
->fctx
= msm_fence_context_alloc(gpu
->dev
, name
);
59 msm_ringbuffer_destroy(ring
);
63 void msm_ringbuffer_destroy(struct msm_ringbuffer
*ring
)
65 if (IS_ERR_OR_NULL(ring
))
68 msm_fence_context_free(ring
->fctx
);
70 msm_gem_kernel_put(ring
->bo
, ring
->gpu
->aspace
, false);