xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_debug_csf_fault.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 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 #ifndef _KBASE_DEBUG_CSF_FAULT_H
23 #define _KBASE_DEBUG_CSF_FAULT_H
24 
25 #if IS_ENABLED(CONFIG_DEBUG_FS)
26 /**
27  * kbase_debug_csf_fault_debugfs_init - Initialize CSF fault debugfs
28  * @kbdev:	Device pointer
29  */
30 void kbase_debug_csf_fault_debugfs_init(struct kbase_device *kbdev);
31 
32 /**
33  * kbase_debug_csf_fault_init - Create the fault event wait queue per device
34  *                              and initialize the required resources.
35  * @kbdev:    Device pointer
36  *
37  * Return: Zero on success or a negative error code.
38  */
39 int kbase_debug_csf_fault_init(struct kbase_device *kbdev);
40 
41 /**
42  * kbase_debug_csf_fault_term - Clean up resources created by
43  *		                @kbase_debug_csf_fault_init.
44  * @kbdev:    Device pointer
45  */
46 void kbase_debug_csf_fault_term(struct kbase_device *kbdev);
47 
48 /**
49  * kbase_debug_csf_fault_wait_completion - Wait for the client to complete.
50  *
51  * @kbdev:    Device Pointer
52  *
53  * Wait for the user space client to finish reading the fault information.
54  * This function must be called in thread context.
55  */
56 void kbase_debug_csf_fault_wait_completion(struct kbase_device *kbdev);
57 
58 /**
59  * kbase_debug_csf_fault_notify - Notify client of a fault.
60  *
61  * @kbdev:    Device pointer
62  * @kctx:     Faulty context (can be NULL)
63  * @error:    Error code.
64  *
65  * Store fault information and wake up the user space client.
66  *
67  * Return: true if a dump on fault was initiated or was is in progress and
68  *         so caller can opt to wait for the dumping to complete.
69  */
70 bool kbase_debug_csf_fault_notify(struct kbase_device *kbdev,
71 		struct kbase_context *kctx, enum dumpfault_error_type error);
72 
73 /**
74  * kbase_debug_csf_fault_dump_enabled - Check if dump on fault is enabled.
75  *
76  * @kbdev:  Device pointer
77  *
78  * Return: true if debugfs file is opened so dump on fault is enabled.
79  */
kbase_debug_csf_fault_dump_enabled(struct kbase_device * kbdev)80 static inline bool kbase_debug_csf_fault_dump_enabled(struct kbase_device *kbdev)
81 {
82 	return atomic_read(&kbdev->csf.dof.enabled);
83 }
84 
85 /**
86  * kbase_debug_csf_fault_dump_complete - Check if dump on fault is completed.
87  *
88  * @kbdev:  Device pointer
89  *
90  * Return: true if dump on fault completes or file is closed.
91  */
kbase_debug_csf_fault_dump_complete(struct kbase_device * kbdev)92 static inline bool kbase_debug_csf_fault_dump_complete(struct kbase_device *kbdev)
93 {
94 	unsigned long flags;
95 	bool ret;
96 
97 	if (likely(!kbase_debug_csf_fault_dump_enabled(kbdev)))
98 		return true;
99 
100 	spin_lock_irqsave(&kbdev->csf.dof.lock, flags);
101 	ret = (kbdev->csf.dof.error_code == DF_NO_ERROR);
102 	spin_unlock_irqrestore(&kbdev->csf.dof.lock, flags);
103 
104 	return ret;
105 }
106 #else /* CONFIG_DEBUG_FS */
kbase_debug_csf_fault_init(struct kbase_device * kbdev)107 static inline int kbase_debug_csf_fault_init(struct kbase_device *kbdev)
108 {
109 	return 0;
110 }
111 
kbase_debug_csf_fault_term(struct kbase_device * kbdev)112 static inline void kbase_debug_csf_fault_term(struct kbase_device *kbdev)
113 {
114 }
115 
kbase_debug_csf_fault_wait_completion(struct kbase_device * kbdev)116 static inline void kbase_debug_csf_fault_wait_completion(struct kbase_device *kbdev)
117 {
118 }
119 
kbase_debug_csf_fault_notify(struct kbase_device * kbdev,struct kbase_context * kctx,enum dumpfault_error_type error)120 static inline bool kbase_debug_csf_fault_notify(struct kbase_device *kbdev,
121 		struct kbase_context *kctx, enum dumpfault_error_type error)
122 {
123 	return false;
124 }
125 
kbase_debug_csf_fault_dump_enabled(struct kbase_device * kbdev)126 static inline bool kbase_debug_csf_fault_dump_enabled(struct kbase_device *kbdev)
127 {
128 	return false;
129 }
130 
kbase_debug_csf_fault_dump_complete(struct kbase_device * kbdev)131 static inline bool kbase_debug_csf_fault_dump_complete(struct kbase_device *kbdev)
132 {
133 	return true;
134 }
135 #endif /* CONFIG_DEBUG_FS */
136 
137 #endif /*_KBASE_DEBUG_CSF_FAULT_H*/
138