Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 1 | /* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 2 | * |
| 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 Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 23 | #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 Atkinson | de4270ab | 2017-06-27 16:43:53 -0400 | [diff] [blame] | 30 | #define SDE_EVTLOG_ERROR 0xebad |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 31 | |
Lloyd Atkinson | a54513f | 2016-10-03 22:31:43 -0400 | [diff] [blame] | 32 | #define SDE_DBG_DUMP_DATA_LIMITER (NULL) |
| 33 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 34 | enum sde_dbg_evtlog_flag { |
Clarence Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 35 | SDE_EVTLOG_CRITICAL = BIT(0), |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 36 | SDE_EVTLOG_IRQ = BIT(1), |
Clarence Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 37 | SDE_EVTLOG_VERBOSE = BIT(2), |
| 38 | SDE_EVTLOG_ALWAYS = -1 |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 39 | }; |
| 40 | |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 41 | enum 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 Patel | 6c66662 | 2017-03-21 23:02:59 -0700 | [diff] [blame] | 47 | #define SDE_EVTLOG_DEFAULT_ENABLE (SDE_EVTLOG_CRITICAL | SDE_EVTLOG_IRQ) |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 48 | #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 | |
| 69 | struct sde_dbg_power_ctrl { |
| 70 | void *handle; |
| 71 | void *client; |
| 72 | int (*enable_fn)(void *handle, void *client, bool enable); |
| 73 | }; |
| 74 | |
| 75 | struct sde_dbg_evtlog_log { |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 76 | 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 Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 84 | /** |
| 85 | * @filter_list: Linked list of currently active filter strings |
| 86 | */ |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 87 | struct 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 Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 95 | struct list_head filter_list; |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | extern struct sde_dbg_evtlog *sde_dbg_base_evtlog; |
| 99 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 100 | /** |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 101 | * SDE_EVT32 - Write a list of 32bit values to the event log, default area |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 102 | * ... - variable arguments |
| 103 | */ |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 104 | #define SDE_EVT32(...) sde_evtlog_log(sde_dbg_base_evtlog, __func__, \ |
Clarence Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 105 | __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 Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 114 | SDE_EVTLOG_DATA_LIMITER) |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 115 | |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 116 | /** |
| 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 Atkinson | a54513f | 2016-10-03 22:31:43 -0400 | [diff] [blame] | 133 | SDE_DBG_DUMP_DATA_LIMITER) |
| 134 | |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 135 | /** |
| 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 Atkinson | a54513f | 2016-10-03 22:31:43 -0400 | [diff] [blame] | 144 | SDE_DBG_DUMP_DATA_LIMITER) |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 145 | |
| 146 | #if defined(CONFIG_DEBUG_FS) |
| 147 | |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 148 | /** |
| 149 | * sde_evtlog_init - allocate a new event log object |
| 150 | * Returns: evtlog or -ERROR |
| 151 | */ |
| 152 | struct 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 | */ |
| 159 | void 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 | */ |
| 171 | void 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 | */ |
| 179 | void 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 | */ |
| 188 | bool 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 | */ |
| 197 | ssize_t sde_evtlog_dump_to_buffer(struct sde_dbg_evtlog *evtlog, |
| 198 | char *evtlog_buf, ssize_t evtlog_buf_size); |
| 199 | |
| 200 | /** |
Lloyd Atkinson | 274cc46 | 2017-02-21 11:52:06 -0500 | [diff] [blame] | 201 | * sde_dbg_init_dbg_buses - initialize debug bus dumping support for the chipset |
| 202 | * @hwversion: Chipset revision |
| 203 | */ |
| 204 | void sde_dbg_init_dbg_buses(u32 hwversion); |
| 205 | |
| 206 | /** |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 207 | * sde_dbg_init - initialize global sde debug facilities: evtlog, regdump |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 208 | * @dev: device handle |
| 209 | * @power_ctrl: power control callback structure for enabling clocks |
| 210 | * during register dumping |
| 211 | * Returns: 0 or -ERROR |
| 212 | */ |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 213 | int 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 | */ |
| 220 | int sde_dbg_debugfs_register(struct dentry *debugfs_root); |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * sde_dbg_destroy - destroy the global sde debug facilities |
| 224 | * Returns: none |
| 225 | */ |
| 226 | void 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 | */ |
| 239 | void 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 | */ |
| 250 | int 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 | */ |
| 264 | void 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 Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 268 | /** |
Lloyd Atkinson | ac4b6e0 | 2017-03-23 11:43:48 -0700 | [diff] [blame] | 269 | * 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 | */ |
| 273 | void sde_dbg_set_sde_top_offset(u32 blk_off); |
| 274 | |
| 275 | /** |
Clarence Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 276 | * 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 | */ |
| 280 | void 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 | */ |
| 290 | int sde_evtlog_get_filter(struct sde_dbg_evtlog *evtlog, int index, |
| 291 | char *buf, size_t bufsz); |
| 292 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 293 | #else |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 294 | static inline struct sde_dbg_evtlog *sde_evtlog_init(void) |
| 295 | { |
| 296 | return NULL; |
| 297 | } |
| 298 | |
| 299 | static inline void sde_evtlog_destroy(struct sde_dbg_evtlog *evtlog) |
| 300 | { |
| 301 | } |
| 302 | |
| 303 | static inline void sde_evtlog_log(struct sde_dbg_evtlog *evtlog, |
| 304 | const char *name, int line, int flag, ...) |
| 305 | { |
| 306 | } |
| 307 | |
| 308 | static inline void sde_evtlog_dump_all(struct sde_dbg_evtlog *evtlog) |
| 309 | { |
| 310 | } |
| 311 | |
| 312 | static inline bool sde_evtlog_is_enabled(struct sde_dbg_evtlog *evtlog, |
| 313 | u32 flag) |
| 314 | { |
| 315 | return false; |
| 316 | } |
| 317 | |
| 318 | static 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 Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 324 | static inline void sde_dbg_init_dbg_buses(u32 hwversion) |
Lloyd Atkinson | 274cc46 | 2017-02-21 11:52:06 -0500 | [diff] [blame] | 325 | { |
| 326 | } |
| 327 | |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 328 | static inline int sde_dbg_init(struct device *dev, |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 329 | struct sde_dbg_power_ctrl *power_ctrl) |
| 330 | { |
| 331 | return 0; |
| 332 | } |
| 333 | |
Clarence Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 334 | static inline int sde_dbg_debugfs_register(struct dentry *debugfs_root) |
Lloyd Atkinson | b020e0f | 2017-03-14 08:05:18 -0700 | [diff] [blame] | 335 | { |
| 336 | return 0; |
| 337 | } |
| 338 | |
Lloyd Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 339 | static inline void sde_dbg_destroy(void) |
| 340 | { |
| 341 | } |
| 342 | |
| 343 | static inline void sde_dbg_dump(bool queue_work, const char *name, ...) |
| 344 | { |
| 345 | } |
| 346 | |
| 347 | static inline int sde_dbg_reg_register_base(const char *name, |
| 348 | void __iomem *base, size_t max_offset) |
| 349 | { |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static 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 Atkinson | ac4b6e0 | 2017-03-23 11:43:48 -0700 | [diff] [blame] | 359 | void sde_dbg_set_sde_top_offset(u32 blk_off) |
| 360 | { |
| 361 | } |
| 362 | |
Clarence Ip | 6ac61cc | 2017-03-22 15:01:53 -0400 | [diff] [blame] | 363 | static inline void sde_evtlog_set_filter( |
| 364 | struct sde_dbg_evtlog *evtlog, char *filter) |
| 365 | { |
| 366 | } |
| 367 | |
| 368 | static 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 Atkinson | 113aefd | 2016-10-23 13:15:18 -0400 | [diff] [blame] | 374 | #endif /* defined(CONFIG_DEBUG_FS) */ |
| 375 | |
Lloyd Atkinson | 5d40d31 | 2016-09-06 08:34:13 -0400 | [diff] [blame] | 376 | |
| 377 | #endif /* SDE_DBG_H_ */ |