Linux Audio

Check our new training course

Open-source upstreaming

Need help get the support for your hardware in upstream Linux?
Loading...
v4.6
 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	size = ALIGN(size, 4);   /* size should be dword aligned */
 
27
28	ring = kzalloc(sizeof(*ring), GFP_KERNEL);
29	if (!ring) {
30		ret = -ENOMEM;
31		goto fail;
32	}
33
34	ring->gpu = gpu;
35	ring->bo = msm_gem_new(gpu->dev, size, MSM_BO_WC);
36	if (IS_ERR(ring->bo)) {
37		ret = PTR_ERR(ring->bo);
38		ring->bo = NULL;
39		goto fail;
40	}
41
42	ring->start = msm_gem_vaddr_locked(ring->bo);
 
 
 
 
43	ring->end   = ring->start + (size / 4);
44	ring->cur   = ring->start;
45
46	ring->size = size;
47
48	return ring;
49
50fail:
51	if (ring)
52		msm_ringbuffer_destroy(ring);
53	return ERR_PTR(ret);
54}
55
56void msm_ringbuffer_destroy(struct msm_ringbuffer *ring)
57{
58	if (ring->bo)
 
59		drm_gem_object_unreference_unlocked(ring->bo);
 
60	kfree(ring);
61}
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}