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