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
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"
21 struct msm_ringbuffer
*msm_ringbuffer_new(struct msm_gpu
*gpu
, int size
)
23 struct msm_ringbuffer
*ring
;
26 if (WARN_ON(!is_power_of_2(size
)))
27 return ERR_PTR(-EINVAL
);
29 ring
= kzalloc(sizeof(*ring
), GFP_KERNEL
);
36 ring
->bo
= msm_gem_new(gpu
->dev
, size
, MSM_BO_WC
);
37 if (IS_ERR(ring
->bo
)) {
38 ret
= PTR_ERR(ring
->bo
);
43 ring
->start
= msm_gem_get_vaddr_locked(ring
->bo
);
44 if (IS_ERR(ring
->start
)) {
45 ret
= PTR_ERR(ring
->start
);
48 ring
->end
= ring
->start
+ (size
/ 4);
49 ring
->cur
= ring
->start
;
57 msm_ringbuffer_destroy(ring
);
61 void msm_ringbuffer_destroy(struct msm_ringbuffer
*ring
)
64 msm_gem_put_vaddr(ring
->bo
);
65 drm_gem_object_unreference_unlocked(ring
->bo
);