Linux Audio

Check our new training course

Loading...
v4.17
 1/*
 2 * Copyright (C) 2013 Red Hat
 3 * Author: Rob Clark <robdclark@gmail.com>
 4 *
 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.
 8 *
 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.
13 *
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/>.
16 */
17
18#include "msm_ringbuffer.h"
19#include "msm_gpu.h"
20
21struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int id,
22		void *memptrs, uint64_t memptrs_iova)
23{
24	struct msm_ringbuffer *ring;
25	char name[32];
26	int ret;
27
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));
30
31	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
32	if (!ring) {
33		ret = -ENOMEM;
34		goto fail;
35	}
36
37	ring->gpu = gpu;
38	ring->id = id;
39	/* Pass NULL for the iova pointer - we will map it later */
40	ring->start = msm_gem_kernel_new(gpu->dev, MSM_GPU_RINGBUFFER_SZ,
41		MSM_BO_WC, gpu->aspace, &ring->bo, NULL);
 
 
42
 
43	if (IS_ERR(ring->start)) {
44		ret = PTR_ERR(ring->start);
45		ring->start = 0;
46		goto fail;
47	}
48	ring->end   = ring->start + (MSM_GPU_RINGBUFFER_SZ >> 2);
49	ring->next  = ring->start;
50	ring->cur   = ring->start;
51
52	ring->memptrs = memptrs;
53	ring->memptrs_iova = memptrs_iova;
54
55	INIT_LIST_HEAD(&ring->submits);
56	spin_lock_init(&ring->lock);
57
58	snprintf(name, sizeof(name), "gpu-ring-%d", ring->id);
59
60	ring->fctx = msm_fence_context_alloc(gpu->dev, name);
61
62	return ring;
63
64fail:
65	msm_ringbuffer_destroy(ring);
 
66	return ERR_PTR(ret);
67}
68
69void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
70{
71	if (IS_ERR_OR_NULL(ring))
72		return;
73
74	msm_fence_context_free(ring->fctx);
75
76	if (ring->bo) {
77		msm_gem_put_iova(ring->bo, ring->gpu->aspace);
78		msm_gem_put_vaddr(ring->bo);
79		drm_gem_object_put_unlocked(ring->bo);
80	}
81	kfree(ring);
82}
v4.10.11
 1/*
 2 * Copyright (C) 2013 Red Hat
 3 * Author: Rob Clark <robdclark@gmail.com>
 4 *
 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.
 8 *
 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.
13 *
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/>.
16 */
17
18#include "msm_ringbuffer.h"
19#include "msm_gpu.h"
20
21struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int size)
 
22{
23	struct msm_ringbuffer *ring;
 
24	int ret;
25
26	if (WARN_ON(!is_power_of_2(size)))
27		return ERR_PTR(-EINVAL);
28
29	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
30	if (!ring) {
31		ret = -ENOMEM;
32		goto fail;
33	}
34
35	ring->gpu = gpu;
36	ring->bo = msm_gem_new(gpu->dev, size, MSM_BO_WC);
37	if (IS_ERR(ring->bo)) {
38		ret = PTR_ERR(ring->bo);
39		ring->bo = NULL;
40		goto fail;
41	}
42
43	ring->start = msm_gem_get_vaddr_locked(ring->bo);
44	if (IS_ERR(ring->start)) {
45		ret = PTR_ERR(ring->start);
 
46		goto fail;
47	}
48	ring->end   = ring->start + (size / 4);
 
49	ring->cur   = ring->start;
50
51	ring->size = size;
 
 
 
 
 
 
 
 
52
53	return ring;
54
55fail:
56	if (ring)
57		msm_ringbuffer_destroy(ring);
58	return ERR_PTR(ret);
59}
60
61void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
62{
 
 
 
 
 
63	if (ring->bo) {
 
64		msm_gem_put_vaddr(ring->bo);
65		drm_gem_object_unreference_unlocked(ring->bo);
66	}
67	kfree(ring);
68}