summaryrefslogtreecommitdiff
path: root/mali_kbase/csf/mali_kbase_debug_csf_fault.h
blob: 6e9b1a9d51de10c060fe2af5848fb23d36950914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
 *
 * (C) COPYRIGHT 2022 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 */

#ifndef _KBASE_DEBUG_CSF_FAULT_H
#define _KBASE_DEBUG_CSF_FAULT_H

#if IS_ENABLED(CONFIG_DEBUG_FS)
/**
 * kbase_debug_csf_fault_debugfs_init - Initialize CSF fault debugfs
 * @kbdev:	Device pointer
 */
void kbase_debug_csf_fault_debugfs_init(struct kbase_device *kbdev);

/**
 * kbase_debug_csf_fault_init - Create the fault event wait queue per device
 *                              and initialize the required resources.
 * @kbdev:    Device pointer
 *
 * Return: Zero on success or a negative error code.
 */
int kbase_debug_csf_fault_init(struct kbase_device *kbdev);

/**
 * kbase_debug_csf_fault_term - Clean up resources created by
 *		                @kbase_debug_csf_fault_init.
 * @kbdev:    Device pointer
 */
void kbase_debug_csf_fault_term(struct kbase_device *kbdev);

/**
 * kbase_debug_csf_fault_wait_completion - Wait for the client to complete.
 *
 * @kbdev:    Device Pointer
 *
 * Wait for the user space client to finish reading the fault information.
 * This function must be called in thread context.
 */
void kbase_debug_csf_fault_wait_completion(struct kbase_device *kbdev);

/**
 * kbase_debug_csf_fault_notify - Notify client of a fault.
 *
 * @kbdev:    Device pointer
 * @kctx:     Faulty context (can be NULL)
 * @error:    Error code.
 *
 * Store fault information and wake up the user space client.
 *
 * Return: true if a dump on fault was initiated or was is in progress and
 *         so caller can opt to wait for the dumping to complete.
 */
bool kbase_debug_csf_fault_notify(struct kbase_device *kbdev,
		struct kbase_context *kctx, enum dumpfault_error_type error);

/**
 * kbase_debug_csf_fault_dump_enabled - Check if dump on fault is enabled.
 *
 * @kbdev:  Device pointer
 *
 * Return: true if debugfs file is opened so dump on fault is enabled.
 */
static inline bool kbase_debug_csf_fault_dump_enabled(struct kbase_device *kbdev)
{
	return atomic_read(&kbdev->csf.dof.enabled);
}

/**
 * kbase_debug_csf_fault_dump_complete - Check if dump on fault is completed.
 *
 * @kbdev:  Device pointer
 *
 * Return: true if dump on fault completes or file is closed.
 */
static inline bool kbase_debug_csf_fault_dump_complete(struct kbase_device *kbdev)
{
	unsigned long flags;
	bool ret;

	if (likely(!kbase_debug_csf_fault_dump_enabled(kbdev)))
		return true;

	spin_lock_irqsave(&kbdev->csf.dof.lock, flags);
	ret = (kbdev->csf.dof.error_code == DF_NO_ERROR);
	spin_unlock_irqrestore(&kbdev->csf.dof.lock, flags);

	return ret;
}
#else /* CONFIG_DEBUG_FS */
static inline int kbase_debug_csf_fault_init(struct kbase_device *kbdev)
{
	return 0;
}

static inline void kbase_debug_csf_fault_term(struct kbase_device *kbdev)
{
}

static inline void kbase_debug_csf_fault_wait_completion(struct kbase_device *kbdev)
{
}

static inline bool kbase_debug_csf_fault_notify(struct kbase_device *kbdev,
		struct kbase_context *kctx, enum dumpfault_error_type error)
{
	return false;
}

static inline bool kbase_debug_csf_fault_dump_enabled(struct kbase_device *kbdev)
{
	return false;
}

static inline bool kbase_debug_csf_fault_dump_complete(struct kbase_device *kbdev)
{
	return true;
}
#endif /* CONFIG_DEBUG_FS */

#endif /*_KBASE_DEBUG_CSF_FAULT_H*/