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