1/*	$NetBSD: logger_interface.h,v 1.2 2021/12/18 23:45:07 riastradh Exp $	*/
2
3/*
4 * Copyright 2012-15 Advanced Micro Devices, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: AMD
25 *
26 */
27
28#ifndef __DAL_LOGGER_INTERFACE_H__
29#define __DAL_LOGGER_INTERFACE_H__
30
31#include "logger_types.h"
32
33struct dc_context;
34struct dc_link;
35struct dc_surface_update;
36struct resource_context;
37struct dc_state;
38
39/*
40 *
41 * DAL logger functionality
42 *
43 */
44
45void dc_conn_log_hex_linux(const uint8_t *hex_data, int hex_data_count);
46
47void pre_surface_trace(
48		struct dc *dc,
49		const struct dc_plane_state *const *plane_states,
50		int surface_count);
51
52void update_surface_trace(
53		struct dc *dc,
54		const struct dc_surface_update *updates,
55		int surface_count);
56
57void post_surface_trace(struct dc *dc);
58
59void context_timing_trace(
60		struct dc *dc,
61		struct resource_context *res_ctx);
62
63void context_clock_trace(
64		struct dc *dc,
65		struct dc_state *context);
66
67/* Any function which is empty or have incomplete implementation should be
68 * marked by this macro.
69 * Note that the message will be printed exactly once for every function
70 * it is used in order to avoid repeating of the same message. */
71
72#define DAL_LOGGER_NOT_IMPL(fmt, ...) \
73	do { \
74		static bool print_not_impl = true; \
75		if (print_not_impl == true) { \
76			print_not_impl = false; \
77			DRM_WARN("DAL_NOT_IMPL: " fmt, ##__VA_ARGS__); \
78		} \
79	} while (0)
80
81/******************************************************************************
82 * Convenience macros to save on typing.
83 *****************************************************************************/
84
85#define DC_ERROR(...) \
86		do { \
87			(void)(dc_ctx); \
88			DC_LOG_ERROR(__VA_ARGS__); \
89		} while (0)
90
91#define DC_SYNC_INFO(...) \
92		do { \
93			(void)(dc_ctx); \
94			DC_LOG_SYNC(__VA_ARGS__); \
95		} while (0)
96
97/* Connectivity log format:
98 * [time stamp]   [drm] [Major_minor] [connector name] message.....
99 * eg:
100 * [   26.590965] [drm] [Conn_LKTN]	  [DP-1] HBRx4 pass VS=0, PE=0^
101 * [   26.881060] [drm] [Conn_Mode]	  [DP-1] {2560x1080, 2784x1111@185580Khz}^
102 */
103
104#define CONN_DATA_DETECT(link, hex_data, hex_len, ...) \
105		do { \
106			(void)(link); \
107			dc_conn_log_hex_linux(hex_data, hex_len); \
108			DC_LOG_EVENT_DETECTION(__VA_ARGS__); \
109		} while (0)
110
111#define CONN_DATA_LINK_LOSS(link, hex_data, hex_len, ...) \
112		do { \
113			(void)(link); \
114			dc_conn_log_hex_linux(hex_data, hex_len); \
115			DC_LOG_EVENT_LINK_LOSS(__VA_ARGS__); \
116		} while (0)
117
118#define CONN_MSG_LT(link, ...) \
119		do { \
120			(void)(link); \
121			DC_LOG_EVENT_LINK_TRAINING(__VA_ARGS__); \
122		} while (0)
123
124#define CONN_MSG_MODE(link, ...) \
125		do { \
126			(void)(link); \
127			DC_LOG_EVENT_MODE_SET(__VA_ARGS__); \
128		} while (0)
129
130/*
131 * Display Test Next logging
132 */
133#define DTN_INFO_BEGIN() \
134	dm_dtn_log_begin(dc_ctx, log_ctx)
135
136#define DTN_INFO(msg, ...) \
137	dm_dtn_log_append_v(dc_ctx, log_ctx, msg, ##__VA_ARGS__)
138
139#define DTN_INFO_END() \
140	dm_dtn_log_end(dc_ctx, log_ctx)
141
142#define PERFORMANCE_TRACE_START() \
143	unsigned long long perf_trc_start_stmp = dm_get_timestamp(dc->ctx)
144
145#define PERFORMANCE_TRACE_END() \
146	do { \
147		unsigned long long perf_trc_end_stmp = dm_get_timestamp(dc->ctx); \
148		if (dc->debug.performance_trace) { \
149			DC_LOG_PERF_TRACE("%s duration: %lld ticks\n", __func__, \
150				perf_trc_end_stmp - perf_trc_start_stmp); \
151		} \
152	} while (0)
153
154#define DISPLAY_STATS_BEGIN(entry) (void)(entry)
155
156#define DISPLAY_STATS(msg, ...) DC_LOG_PERF_TRACE(msg, __VA_ARGS__)
157
158#define DISPLAY_STATS_END(entry) (void)(entry)
159
160#define LOG_GAMMA_WRITE(msg, ...)
161
162#endif /* __DAL_LOGGER_INTERFACE_H__ */
163