xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/mali_kbase_disjoint_events.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note
2 /*
3  *
4  * (C) COPYRIGHT 2014, 2020-2021 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 /*
23  * Base kernel disjoint events helper functions
24  */
25 
26 #include <mali_kbase.h>
27 
kbase_disjoint_init(struct kbase_device * kbdev)28 void kbase_disjoint_init(struct kbase_device *kbdev)
29 {
30 	KBASE_DEBUG_ASSERT(kbdev != NULL);
31 
32 	atomic_set(&kbdev->disjoint_event.count, 0);
33 	atomic_set(&kbdev->disjoint_event.state, 0);
34 }
35 
36 /* increment the disjoint event count */
kbase_disjoint_event(struct kbase_device * kbdev)37 void kbase_disjoint_event(struct kbase_device *kbdev)
38 {
39 	KBASE_DEBUG_ASSERT(kbdev != NULL);
40 
41 	atomic_inc(&kbdev->disjoint_event.count);
42 }
43 
44 /* increment the state and the event counter */
kbase_disjoint_state_up(struct kbase_device * kbdev)45 void kbase_disjoint_state_up(struct kbase_device *kbdev)
46 {
47 	KBASE_DEBUG_ASSERT(kbdev != NULL);
48 
49 	atomic_inc(&kbdev->disjoint_event.state);
50 
51 	kbase_disjoint_event(kbdev);
52 }
53 
54 /* decrement the state */
kbase_disjoint_state_down(struct kbase_device * kbdev)55 void kbase_disjoint_state_down(struct kbase_device *kbdev)
56 {
57 	KBASE_DEBUG_ASSERT(kbdev != NULL);
58 	KBASE_DEBUG_ASSERT(atomic_read(&kbdev->disjoint_event.state) > 0);
59 
60 	kbase_disjoint_event(kbdev);
61 
62 	atomic_dec(&kbdev->disjoint_event.state);
63 }
64 
65 /* increments the count only if the state is > 0 */
kbase_disjoint_event_potential(struct kbase_device * kbdev)66 void kbase_disjoint_event_potential(struct kbase_device *kbdev)
67 {
68 	KBASE_DEBUG_ASSERT(kbdev != NULL);
69 
70 	if (atomic_read(&kbdev->disjoint_event.state))
71 		kbase_disjoint_event(kbdev);
72 }
73 
kbase_disjoint_event_get(struct kbase_device * kbdev)74 u32 kbase_disjoint_event_get(struct kbase_device *kbdev)
75 {
76 	KBASE_DEBUG_ASSERT(kbdev != NULL);
77 
78 	return atomic_read(&kbdev->disjoint_event.count);
79 }
80 KBASE_EXPORT_TEST_API(kbase_disjoint_event_get);
81