Merge remote-tracking branches 'asoc/fix/msm8916', 'asoc/fix/nau8825', 'asoc/fix...
[sfrench/cifs-2.6.git] / drivers / gpu / drm / amd / display / dc / basics / log_helpers.c
1 /*
2  * Copyright 2012-16 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 #include "core_types.h"
27 #include "logger.h"
28 #include "include/logger_interface.h"
29 #include "dm_helpers.h"
30
31 #define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
32
33 struct dc_signal_type_info {
34         enum signal_type type;
35         char name[MAX_NAME_LEN];
36 };
37
38 static const struct dc_signal_type_info signal_type_info_tbl[] = {
39                 {SIGNAL_TYPE_NONE,             "NC"},
40                 {SIGNAL_TYPE_DVI_SINGLE_LINK,  "DVI"},
41                 {SIGNAL_TYPE_DVI_DUAL_LINK,    "DDVI"},
42                 {SIGNAL_TYPE_HDMI_TYPE_A,      "HDMIA"},
43                 {SIGNAL_TYPE_LVDS,             "LVDS"},
44                 {SIGNAL_TYPE_RGB,              "VGA"},
45                 {SIGNAL_TYPE_DISPLAY_PORT,     "DP"},
46                 {SIGNAL_TYPE_DISPLAY_PORT_MST, "MST"},
47                 {SIGNAL_TYPE_EDP,              "eDP"},
48                 {SIGNAL_TYPE_VIRTUAL,          "Virtual"}
49 };
50
51 void dc_conn_log(struct dc_context *ctx,
52                 const struct dc_link *link,
53                 uint8_t *hex_data,
54                 int hex_data_count,
55                 enum dc_log_type event,
56                 const char *msg,
57                 ...)
58 {
59         int i;
60         va_list args;
61         struct log_entry entry = { 0 };
62         enum signal_type signal;
63
64         if (link->local_sink)
65                 signal = link->local_sink->sink_signal;
66         else
67                 signal = link->connector_signal;
68
69         if (link->type == dc_connection_mst_branch)
70                 signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
71
72         dm_logger_open(ctx->logger, &entry, event);
73
74         for (i = 0; i < NUM_ELEMENTS(signal_type_info_tbl); i++)
75                 if (signal == signal_type_info_tbl[i].type)
76                         break;
77
78         if (i == NUM_ELEMENTS(signal_type_info_tbl))
79                 goto fail;
80
81         dm_logger_append(&entry, "[%s][ConnIdx:%d] ",
82                         signal_type_info_tbl[i].name,
83                         link->link_index);
84
85         va_start(args, msg);
86         entry.buf_offset += dm_log_to_buffer(
87                 &entry.buf[entry.buf_offset],
88                 LOG_MAX_LINE_SIZE - entry.buf_offset,
89                 msg, args);
90
91         if (entry.buf[strlen(entry.buf) - 1] == '\n') {
92                 entry.buf[strlen(entry.buf) - 1] = '\0';
93                 entry.buf_offset--;
94         }
95
96         if (hex_data)
97                 for (i = 0; i < hex_data_count; i++)
98                         dm_logger_append(&entry, "%2.2X ", hex_data[i]);
99
100         dm_logger_append(&entry, "^\n");
101         dm_helpers_dc_conn_log(ctx, &entry, event);
102
103 fail:
104         dm_logger_close(&entry);
105
106         va_end(args);
107 }