1 /*
2 *
3 * (C) COPYRIGHT 2014 ARM Limited. All rights reserved.
4 *
5 * This program is free software and is provided to you under the terms of the
6 * GNU General Public License version 2 as published by the Free Software
7 * Foundation, and any use by you of this program is subject to the terms
8 * of such GNU licence.
9 *
10 * A copy of the licence is included with the program, and can also be obtained
11 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12 * Boston, MA 02110-1301, USA.
13 *
14 */
15
16
17
18 /*
19 * Base kernel disjoint events helper functions
20 */
21
22 #include <mali_kbase.h>
23
kbase_disjoint_init(struct kbase_device * kbdev)24 void kbase_disjoint_init(struct kbase_device *kbdev)
25 {
26 KBASE_DEBUG_ASSERT(kbdev != NULL);
27
28 atomic_set(&kbdev->disjoint_event.count, 0);
29 atomic_set(&kbdev->disjoint_event.state, 0);
30 }
31
32 /* increment the disjoint event count */
kbase_disjoint_event(struct kbase_device * kbdev)33 void kbase_disjoint_event(struct kbase_device *kbdev)
34 {
35 KBASE_DEBUG_ASSERT(kbdev != NULL);
36
37 atomic_inc(&kbdev->disjoint_event.count);
38 }
39
40 /* increment the state and the event counter */
kbase_disjoint_state_up(struct kbase_device * kbdev)41 void kbase_disjoint_state_up(struct kbase_device *kbdev)
42 {
43 KBASE_DEBUG_ASSERT(kbdev != NULL);
44
45 atomic_inc(&kbdev->disjoint_event.state);
46
47 kbase_disjoint_event(kbdev);
48 }
49
50 /* decrement the state */
kbase_disjoint_state_down(struct kbase_device * kbdev)51 void kbase_disjoint_state_down(struct kbase_device *kbdev)
52 {
53 KBASE_DEBUG_ASSERT(kbdev != NULL);
54 KBASE_DEBUG_ASSERT(atomic_read(&kbdev->disjoint_event.state) > 0);
55
56 kbase_disjoint_event(kbdev);
57
58 atomic_dec(&kbdev->disjoint_event.state);
59 }
60
61 /* increments the count only if the state is > 0 */
kbase_disjoint_event_potential(struct kbase_device * kbdev)62 void kbase_disjoint_event_potential(struct kbase_device *kbdev)
63 {
64 KBASE_DEBUG_ASSERT(kbdev != NULL);
65
66 if (atomic_read(&kbdev->disjoint_event.state))
67 kbase_disjoint_event(kbdev);
68 }
69
kbase_disjoint_event_get(struct kbase_device * kbdev)70 u32 kbase_disjoint_event_get(struct kbase_device *kbdev)
71 {
72 KBASE_DEBUG_ASSERT(kbdev != NULL);
73
74 return atomic_read(&kbdev->disjoint_event.count);
75 }
76 KBASE_EXPORT_TEST_API(kbase_disjoint_event_get);
77