xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/csf/mali_kbase_csf_tl_reader.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2019-2023 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_CSFFW_TL_READER_H_
23 #define _KBASE_CSFFW_TL_READER_H_
24 
25 #include <linux/spinlock.h>
26 #include <linux/timer.h>
27 #include <asm/page.h>
28 
29 /* The number of pages used for CSFFW trace buffer. Can be tweaked. */
30 #define KBASE_CSF_TL_BUFFER_NR_PAGES 128
31 /* CSFFW Timeline read polling minimum period in milliseconds. */
32 #define KBASE_CSF_TL_READ_INTERVAL_MIN 20
33 /* CSFFW Timeline read polling default period in milliseconds. */
34 #define KBASE_CSF_TL_READ_INTERVAL_DEFAULT 200
35 /* CSFFW Timeline read polling maximum period in milliseconds. */
36 #define KBASE_CSF_TL_READ_INTERVAL_MAX (60*1000)
37 
38 struct firmware_trace_buffer;
39 struct kbase_tlstream;
40 struct kbase_device;
41 
42 /**
43  * struct kbase_csf_tl_reader - CSFFW timeline reader state.
44  *
45  * @read_timer:        Timer used for periodical tracebufer reading.
46  * @timer_interval:    Timer polling period in milliseconds.
47  * @stream:            Timeline stream where to the tracebuffer content
48  *                     is copied.
49  * @kbdev:             KBase device.
50  * @trace_buffer:      CSF Firmware timeline tracebuffer.
51  * @tl_header:         CSFFW Timeline header
52  * @tl_header.data:    CSFFW Timeline header content.
53  * @tl_header.size:    CSFFW Timeline header size.
54  * @tl_header.btc:     CSFFW Timeline header remaining bytes to copy to
55  *                     the user space.
56  * @ts_converter:      Timestamp converter state.
57  * @got_first_event:   True, if a CSFFW timelime session has been enabled
58  *                     and the first event was received.
59  * @is_active:         True, if a CSFFW timelime session has been enabled.
60  * @expected_event_id: The last 16 bit event ID received from CSFFW. It
61  *                     is only valid when got_first_event is true.
62  * @read_buffer:       Temporary buffer used for CSFFW timeline data
63  *                     reading from the tracebufer.
64  * @read_lock:         CSFFW timeline reader lock.
65  */
66 struct kbase_csf_tl_reader {
67 	struct timer_list read_timer;
68 	u32 timer_interval;
69 	struct kbase_tlstream *stream;
70 
71 	struct kbase_device *kbdev;
72 	struct firmware_trace_buffer *trace_buffer;
73 	struct {
74 		const char *data;
75 		size_t size;
76 		size_t btc;
77 	} tl_header;
78 
79 	bool got_first_event;
80 	bool is_active;
81 	u16 expected_event_id;
82 
83 	u8 read_buffer[PAGE_SIZE * KBASE_CSF_TL_BUFFER_NR_PAGES];
84 	spinlock_t read_lock;
85 };
86 
87 /**
88  * kbase_csf_tl_reader_init() - Initialize CSFFW Timelime Stream Reader.
89  *
90  * @self:	CSFFW TL Reader instance.
91  * @stream:	Destination timeline stream.
92  */
93 void kbase_csf_tl_reader_init(struct kbase_csf_tl_reader *self,
94 	struct kbase_tlstream *stream);
95 
96 /**
97  * kbase_csf_tl_reader_term() - Terminate CSFFW Timelime Stream Reader.
98  *
99  * @self:	CSFFW TL Reader instance.
100  */
101 void kbase_csf_tl_reader_term(struct kbase_csf_tl_reader *self);
102 
103 /**
104  *  kbase_csf_tl_reader_flush_buffer() - Flush trace from buffer into CSFFW timeline stream.
105  *
106  * @self:    CSFFW TL Reader instance.
107  *
108  * Return: Zero on success, negative error code (EBUSY) otherwise
109  */
110 int kbase_csf_tl_reader_flush_buffer(struct kbase_csf_tl_reader *self);
111 
112 /**
113  * kbase_csf_tl_reader_start() - Start asynchronous copying of CSFFW timeline stream.
114  *
115  * @self:	CSFFW TL Reader instance.
116  * @kbdev:	Kbase device.
117  *
118  * Return: zero on success, a negative error code otherwise.
119  */
120 int kbase_csf_tl_reader_start(struct kbase_csf_tl_reader *self,
121 	struct kbase_device *kbdev);
122 
123 /**
124  * kbase_csf_tl_reader_stop() - Stop asynchronous copying of CSFFW timeline stream.
125  *
126  * @self:	CSFFW TL Reader instance.
127  */
128 void kbase_csf_tl_reader_stop(struct kbase_csf_tl_reader *self);
129 
130 #if IS_ENABLED(CONFIG_DEBUG_FS)
131 /**
132  * kbase_csf_tl_reader_debugfs_init() - Initialize debugfs for CSFFW Timelime Stream Reader.
133  *
134  * @kbdev:	Kbase device.
135  */
136 void kbase_csf_tl_reader_debugfs_init(struct kbase_device *kbdev);
137 #endif
138 
139 /**
140  * kbase_csf_tl_reader_reset() - Reset CSFFW timeline reader, it should be called before reset CSFFW.
141  *
142  * @self:	CSFFW TL Reader instance.
143  */
144 void kbase_csf_tl_reader_reset(struct kbase_csf_tl_reader *self);
145 
146 #endif /* _KBASE_CSFFW_TL_READER_H_ */
147