blob: e14d60ed800aed00a765688d022fccc5e4eded19 [file] [log] [blame]
Lloyd Atkinson113aefd2016-10-23 13:15:18 -04001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
Lloyd Atkinson5d40d312016-09-06 08:34:13 -04002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef SDE_DBG_H_
14#define SDE_DBG_H_
15
16#include <stdarg.h>
17#include <linux/debugfs.h>
18#include <linux/list.h>
19
20#define SDE_EVTLOG_DATA_LIMITER (-1)
21#define SDE_EVTLOG_FUNC_ENTRY 0x1111
22#define SDE_EVTLOG_FUNC_EXIT 0x2222
Dhaval Patel6c666622017-03-21 23:02:59 -070023#define SDE_EVTLOG_FUNC_CASE1 0x3333
24#define SDE_EVTLOG_FUNC_CASE2 0x4444
25#define SDE_EVTLOG_FUNC_CASE3 0x5555
26#define SDE_EVTLOG_FUNC_CASE4 0x6666
27#define SDE_EVTLOG_FUNC_CASE5 0x7777
28#define SDE_EVTLOG_PANIC 0xdead
29#define SDE_EVTLOG_FATAL 0xbad
Lloyd Atkinsonde4270ab2017-06-27 16:43:53 -040030#define SDE_EVTLOG_ERROR 0xebad
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040031
Lloyd Atkinsona54513f2016-10-03 22:31:43 -040032#define SDE_DBG_DUMP_DATA_LIMITER (NULL)
33
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040034enum sde_dbg_evtlog_flag {
Clarence Ip6ac61cc2017-03-22 15:01:53 -040035 SDE_EVTLOG_CRITICAL = BIT(0),
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040036 SDE_EVTLOG_IRQ = BIT(1),
Clarence Ip6ac61cc2017-03-22 15:01:53 -040037 SDE_EVTLOG_VERBOSE = BIT(2),
38 SDE_EVTLOG_ALWAYS = -1
Lloyd Atkinson5d40d312016-09-06 08:34:13 -040039};
40
Lloyd Atkinson113aefd2016-10-23 13:15:18 -040041enum sde_dbg_dump_flag {
42 SDE_DBG_DUMP_IN_LOG = BIT(0),
43 SDE_DBG_DUMP_IN_MEM = BIT(1),
44};
45
46#ifdef CONFIG_DRM_SDE_EVTLOG_DEBUG
Dhaval Patel6c666622017-03-21 23:02:59 -070047#define SDE_EVTLOG_DEFAULT_ENABLE (SDE_EVTLOG_CRITICAL | SDE_EVTLOG_IRQ)
Lloyd Atkinson113aefd2016-10-23 13:15:18 -040048#else
49#define SDE_EVTLOG_DEFAULT_ENABLE 0
50#endif
51
52/*
53 * evtlog will print this number of entries when it is called through
54 * sysfs node or panic. This prevents kernel log from evtlog message
55 * flood.
56 */
57#define SDE_EVTLOG_PRINT_ENTRY 256
58
59/*
60 * evtlog keeps this number of entries in memory for debug purpose. This
61 * number must be greater than print entry to prevent out of bound evtlog
62 * entry array access.
63 */
64#define SDE_EVTLOG_ENTRY (SDE_EVTLOG_PRINT_ENTRY * 4)
65#define SDE_EVTLOG_MAX_DATA 15
66#define SDE_EVTLOG_BUF_MAX 512
67#define SDE_EVTLOG_BUF_ALIGN 32
68
69struct sde_dbg_power_ctrl {
70 void *handle;
71 void *client;
72 int (*enable_fn)(void *handle, void *client, bool enable);
73};
74
75struct sde_dbg_evtlog_log {
Lloyd Atkinson113aefd2016-10-23 13:15:18 -040076 s64 time;
77 const char *name;
78 int line;
79 u32 data[SDE_EVTLOG_MAX_DATA];
80 u32 data_cnt;
81 int pid;
82};
83
Clarence Ip6ac61cc2017-03-22 15:01:53 -040084/**
85 * @filter_list: Linked list of currently active filter strings
86 */
Lloyd Atkinson113aefd2016-10-23 13:15:18 -040087struct sde_dbg_evtlog {
88 struct sde_dbg_evtlog_log logs[SDE_EVTLOG_ENTRY];
89 u32 first;
90 u32 last;
91 u32 curr;
92 u32 next;
93 u32 enable;
94 spinlock_t spin_lock;
Clarence Ip6ac61cc2017-03-22 15:01:53 -040095 struct list_head filter_list;
Lloyd Atkinson113aefd2016-10-23 13:15:18 -040096};
97
98extern struct sde_dbg_evtlog *sde_dbg_base_evtlog;
99
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400100/**
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400101 * SDE_EVT32 - Write a list of 32bit values to the event log, default area
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400102 * ... - variable arguments
103 */
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400104#define SDE_EVT32(...) sde_evtlog_log(sde_dbg_base_evtlog, __func__, \
Clarence Ip6ac61cc2017-03-22 15:01:53 -0400105 __LINE__, SDE_EVTLOG_ALWAYS, ##__VA_ARGS__, \
106 SDE_EVTLOG_DATA_LIMITER)
107
108/**
109 * SDE_EVT32_VERBOSE - Write a list of 32bit values for verbose event logging
110 * ... - variable arguments
111 */
112#define SDE_EVT32_VERBOSE(...) sde_evtlog_log(sde_dbg_base_evtlog, __func__, \
113 __LINE__, SDE_EVTLOG_VERBOSE, ##__VA_ARGS__, \
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400114 SDE_EVTLOG_DATA_LIMITER)
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400115
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400116/**
117 * SDE_EVT32_IRQ - Write a list of 32bit values to the event log, IRQ area
118 * ... - variable arguments
119 */
120#define SDE_EVT32_IRQ(...) sde_evtlog_log(sde_dbg_base_evtlog, __func__, \
121 __LINE__, SDE_EVTLOG_IRQ, ##__VA_ARGS__, \
122 SDE_EVTLOG_DATA_LIMITER)
123
124/**
125 * SDE_DBG_DUMP - trigger dumping of all sde_dbg facilities
126 * @va_args: list of named register dump ranges and regions to dump, as
127 * registered previously through sde_dbg_reg_register_base and
128 * sde_dbg_reg_register_dump_range.
129 * Including the special name "panic" will trigger a panic after
130 * the dumping work has completed.
131 */
132#define SDE_DBG_DUMP(...) sde_dbg_dump(false, __func__, ##__VA_ARGS__, \
Lloyd Atkinsona54513f2016-10-03 22:31:43 -0400133 SDE_DBG_DUMP_DATA_LIMITER)
134
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400135/**
136 * SDE_DBG_DUMP_WQ - trigger dumping of all sde_dbg facilities, queuing the work
137 * @va_args: list of named register dump ranges and regions to dump, as
138 * registered previously through sde_dbg_reg_register_base and
139 * sde_dbg_reg_register_dump_range.
140 * Including the special name "panic" will trigger a panic after
141 * the dumping work has completed.
142 */
143#define SDE_DBG_DUMP_WQ(...) sde_dbg_dump(true, __func__, ##__VA_ARGS__, \
Lloyd Atkinsona54513f2016-10-03 22:31:43 -0400144 SDE_DBG_DUMP_DATA_LIMITER)
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400145
146#if defined(CONFIG_DEBUG_FS)
147
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400148/**
149 * sde_evtlog_init - allocate a new event log object
150 * Returns: evtlog or -ERROR
151 */
152struct sde_dbg_evtlog *sde_evtlog_init(void);
153
154/**
155 * sde_evtlog_destroy - destroy previously allocated event log
156 * @evtlog: pointer to evtlog
157 * Returns: none
158 */
159void sde_evtlog_destroy(struct sde_dbg_evtlog *evtlog);
160
161/**
162 * sde_evtlog_log - log an entry into the event log.
163 * log collection may be enabled/disabled entirely via debugfs
164 * log area collection may be filtered by user provided flags via debugfs.
165 * @evtlog: pointer to evtlog
166 * @name: function name of call site
167 * @line: line number of call site
168 * @flag: log area filter flag checked against user's debugfs request
169 * Returns: none
170 */
171void sde_evtlog_log(struct sde_dbg_evtlog *evtlog, const char *name, int line,
172 int flag, ...);
173
174/**
175 * sde_evtlog_dump_all - print all entries in event log to kernel log
176 * @evtlog: pointer to evtlog
177 * Returns: none
178 */
179void sde_evtlog_dump_all(struct sde_dbg_evtlog *evtlog);
180
181/**
182 * sde_evtlog_is_enabled - check whether log collection is enabled for given
183 * event log and log area flag
184 * @evtlog: pointer to evtlog
185 * @flag: log area filter flag
186 * Returns: none
187 */
188bool sde_evtlog_is_enabled(struct sde_dbg_evtlog *evtlog, u32 flag);
189
190/**
191 * sde_evtlog_dump_to_buffer - print content of event log to the given buffer
192 * @evtlog: pointer to evtlog
193 * @evtlog_buf: target buffer to print into
194 * @evtlog_buf_size: size of target buffer
195 * Returns: number of bytes written to buffer
196 */
197ssize_t sde_evtlog_dump_to_buffer(struct sde_dbg_evtlog *evtlog,
198 char *evtlog_buf, ssize_t evtlog_buf_size);
199
200/**
Lloyd Atkinson274cc462017-02-21 11:52:06 -0500201 * sde_dbg_init_dbg_buses - initialize debug bus dumping support for the chipset
202 * @hwversion: Chipset revision
203 */
204void sde_dbg_init_dbg_buses(u32 hwversion);
205
206/**
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400207 * sde_dbg_init - initialize global sde debug facilities: evtlog, regdump
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400208 * @dev: device handle
209 * @power_ctrl: power control callback structure for enabling clocks
210 * during register dumping
211 * Returns: 0 or -ERROR
212 */
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700213int sde_dbg_init(struct device *dev, struct sde_dbg_power_ctrl *power_ctrl);
214
215/**
216 * sde_dbg_debugfs_register - register entries at the given debugfs dir
217 * @debugfs_root: debugfs root in which to create sde debug entries
218 * Returns: 0 or -ERROR
219 */
220int sde_dbg_debugfs_register(struct dentry *debugfs_root);
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400221
222/**
223 * sde_dbg_destroy - destroy the global sde debug facilities
224 * Returns: none
225 */
226void sde_dbg_destroy(void);
227
228/**
229 * sde_dbg_dump - trigger dumping of all sde_dbg facilities
230 * @queue_work: whether to queue the dumping work to the work_struct
231 * @name: string indicating origin of dump
232 * @va_args: list of named register dump ranges and regions to dump, as
233 * registered previously through sde_dbg_reg_register_base and
234 * sde_dbg_reg_register_dump_range.
235 * Including the special name "panic" will trigger a panic after
236 * the dumping work has completed.
237 * Returns: none
238 */
239void sde_dbg_dump(bool queue_work, const char *name, ...);
240
241/**
242 * sde_dbg_reg_register_base - register a hw register address section for later
243 * dumping. call this before calling sde_dbg_reg_register_dump_range
244 * to be able to specify sub-ranges within the base hw range.
245 * @name: name of base region
246 * @base: base pointer of region
247 * @max_offset: length of region
248 * Returns: 0 or -ERROR
249 */
250int sde_dbg_reg_register_base(const char *name, void __iomem *base,
251 size_t max_offset);
252
253/**
254 * sde_dbg_reg_register_dump_range - register a hw register sub-region for
255 * later register dumping associated with base specified by
256 * sde_dbg_reg_register_base
257 * @base_name: name of base region
258 * @range_name: name of sub-range within base region
259 * @offset_start: sub-range's start offset from base's base pointer
260 * @offset_end: sub-range's end offset from base's base pointer
261 * @xin_id: xin id
262 * Returns: none
263 */
264void sde_dbg_reg_register_dump_range(const char *base_name,
265 const char *range_name, u32 offset_start, u32 offset_end,
266 uint32_t xin_id);
267
Clarence Ip6ac61cc2017-03-22 15:01:53 -0400268/**
Lloyd Atkinsonac4b6e02017-03-23 11:43:48 -0700269 * sde_dbg_set_sde_top_offset - set the target specific offset from mdss base
270 * address of the top registers. Used for accessing debug bus controls.
271 * @blk_off: offset from mdss base of the top block
272 */
273void sde_dbg_set_sde_top_offset(u32 blk_off);
274
275/**
Clarence Ip6ac61cc2017-03-22 15:01:53 -0400276 * sde_evtlog_set_filter - update evtlog filtering
277 * @evtlog: pointer to evtlog
278 * @filter: pointer to optional function name filter, set to NULL to disable
279 */
280void sde_evtlog_set_filter(struct sde_dbg_evtlog *evtlog, char *filter);
281
282/**
283 * sde_evtlog_get_filter - query configured evtlog filters
284 * @evtlog: pointer to evtlog
285 * @index: filter index to retrieve
286 * @buf: pointer to output filter buffer
287 * @bufsz: size of output filter buffer
288 * Returns: zero if a filter string was returned
289 */
290int sde_evtlog_get_filter(struct sde_dbg_evtlog *evtlog, int index,
291 char *buf, size_t bufsz);
292
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400293#else
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400294static inline struct sde_dbg_evtlog *sde_evtlog_init(void)
295{
296 return NULL;
297}
298
299static inline void sde_evtlog_destroy(struct sde_dbg_evtlog *evtlog)
300{
301}
302
303static inline void sde_evtlog_log(struct sde_dbg_evtlog *evtlog,
304 const char *name, int line, int flag, ...)
305{
306}
307
308static inline void sde_evtlog_dump_all(struct sde_dbg_evtlog *evtlog)
309{
310}
311
312static inline bool sde_evtlog_is_enabled(struct sde_dbg_evtlog *evtlog,
313 u32 flag)
314{
315 return false;
316}
317
318static inline ssize_t sde_evtlog_dump_to_buffer(struct sde_dbg_evtlog *evtlog,
319 char *evtlog_buf, ssize_t evtlog_buf_size)
320{
321 return 0;
322}
323
Clarence Ip6ac61cc2017-03-22 15:01:53 -0400324static inline void sde_dbg_init_dbg_buses(u32 hwversion)
Lloyd Atkinson274cc462017-02-21 11:52:06 -0500325{
326}
327
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700328static inline int sde_dbg_init(struct device *dev,
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400329 struct sde_dbg_power_ctrl *power_ctrl)
330{
331 return 0;
332}
333
Clarence Ip6ac61cc2017-03-22 15:01:53 -0400334static inline int sde_dbg_debugfs_register(struct dentry *debugfs_root)
Lloyd Atkinsonb020e0f2017-03-14 08:05:18 -0700335{
336 return 0;
337}
338
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400339static inline void sde_dbg_destroy(void)
340{
341}
342
343static inline void sde_dbg_dump(bool queue_work, const char *name, ...)
344{
345}
346
347static inline int sde_dbg_reg_register_base(const char *name,
348 void __iomem *base, size_t max_offset)
349{
350 return 0;
351}
352
353static inline void sde_dbg_reg_register_dump_range(const char *base_name,
354 const char *range_name, u32 offset_start, u32 offset_end,
355 uint32_t xin_id)
356{
357}
358
Lloyd Atkinsonac4b6e02017-03-23 11:43:48 -0700359void sde_dbg_set_sde_top_offset(u32 blk_off)
360{
361}
362
Clarence Ip6ac61cc2017-03-22 15:01:53 -0400363static inline void sde_evtlog_set_filter(
364 struct sde_dbg_evtlog *evtlog, char *filter)
365{
366}
367
368static inline int sde_evtlog_get_filter(struct sde_dbg_evtlog *evtlog,
369 int index, char *buf, size_t bufsz)
370{
371 return -EINVAL;
372}
373
Lloyd Atkinson113aefd2016-10-23 13:15:18 -0400374#endif /* defined(CONFIG_DEBUG_FS) */
375
Lloyd Atkinson5d40d312016-09-06 08:34:13 -0400376
377#endif /* SDE_DBG_H_ */