1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * (C) COPYRIGHT 2011-2022 ARM Limited. All rights reserved.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * This program is free software and is provided to you under the terms of the
7*4882a593Smuzhiyun * GNU General Public License version 2 as published by the Free Software
8*4882a593Smuzhiyun * Foundation, and any use by you of this program is subject to the terms
9*4882a593Smuzhiyun * of such GNU license.
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful,
12*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14*4882a593Smuzhiyun * GNU General Public License for more details.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * You should have received a copy of the GNU General Public License
17*4882a593Smuzhiyun * along with this program; if not, you can access it online at
18*4882a593Smuzhiyun * http://www.gnu.org/licenses/gpl-2.0.html.
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun */
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #include <linux/atomic.h>
23*4882a593Smuzhiyun #include <linux/list.h>
24*4882a593Smuzhiyun #include <linux/spinlock.h>
25*4882a593Smuzhiyun #include <mali_kbase_fence.h>
26*4882a593Smuzhiyun #include <mali_kbase.h>
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun /* Spin lock protecting all Mali fences as fence->lock. */
29*4882a593Smuzhiyun static DEFINE_SPINLOCK(kbase_fence_lock);
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
32*4882a593Smuzhiyun struct fence *
kbase_fence_out_new(struct kbase_jd_atom * katom)33*4882a593Smuzhiyun kbase_fence_out_new(struct kbase_jd_atom *katom)
34*4882a593Smuzhiyun #else
35*4882a593Smuzhiyun struct dma_fence *
36*4882a593Smuzhiyun kbase_fence_out_new(struct kbase_jd_atom *katom)
37*4882a593Smuzhiyun #endif
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun #if (KERNEL_VERSION(4, 10, 0) > LINUX_VERSION_CODE)
40*4882a593Smuzhiyun struct fence *fence;
41*4882a593Smuzhiyun #else
42*4882a593Smuzhiyun struct dma_fence *fence;
43*4882a593Smuzhiyun #endif
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun WARN_ON(katom->dma_fence.fence);
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun fence = kzalloc(sizeof(*fence), GFP_KERNEL);
48*4882a593Smuzhiyun if (!fence)
49*4882a593Smuzhiyun return NULL;
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun dma_fence_init(fence,
52*4882a593Smuzhiyun &kbase_fence_ops,
53*4882a593Smuzhiyun &kbase_fence_lock,
54*4882a593Smuzhiyun katom->dma_fence.context,
55*4882a593Smuzhiyun atomic_inc_return(&katom->dma_fence.seqno));
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun katom->dma_fence.fence = fence;
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun return fence;
60*4882a593Smuzhiyun }
61*4882a593Smuzhiyun
62