log_helpers.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "core_types.h"
  26. #include "logger.h"
  27. #include "include/logger_interface.h"
  28. #include "dm_helpers.h"
  29. #define NUM_ELEMENTS(a) (sizeof(a) / sizeof((a)[0]))
  30. struct dc_signal_type_info {
  31. enum signal_type type;
  32. char name[MAX_NAME_LEN];
  33. };
  34. static const struct dc_signal_type_info signal_type_info_tbl[] = {
  35. {SIGNAL_TYPE_NONE, "NC"},
  36. {SIGNAL_TYPE_DVI_SINGLE_LINK, "DVI"},
  37. {SIGNAL_TYPE_DVI_DUAL_LINK, "DDVI"},
  38. {SIGNAL_TYPE_HDMI_TYPE_A, "HDMIA"},
  39. {SIGNAL_TYPE_LVDS, "LVDS"},
  40. {SIGNAL_TYPE_RGB, "VGA"},
  41. {SIGNAL_TYPE_DISPLAY_PORT, "DP"},
  42. {SIGNAL_TYPE_DISPLAY_PORT_MST, "MST"},
  43. {SIGNAL_TYPE_EDP, "eDP"},
  44. {SIGNAL_TYPE_VIRTUAL, "Virtual"}
  45. };
  46. void dc_conn_log(struct dc_context *ctx,
  47. const struct dc_link *link,
  48. uint8_t *hex_data,
  49. int hex_data_count,
  50. enum dc_log_type event,
  51. const char *msg,
  52. ...)
  53. {
  54. int i;
  55. va_list args;
  56. struct log_entry entry = { 0 };
  57. enum signal_type signal;
  58. if (link->local_sink)
  59. signal = link->local_sink->sink_signal;
  60. else
  61. signal = link->connector_signal;
  62. if (link->type == dc_connection_mst_branch)
  63. signal = SIGNAL_TYPE_DISPLAY_PORT_MST;
  64. dm_logger_open(ctx->logger, &entry, event);
  65. for (i = 0; i < NUM_ELEMENTS(signal_type_info_tbl); i++)
  66. if (signal == signal_type_info_tbl[i].type)
  67. break;
  68. if (i == NUM_ELEMENTS(signal_type_info_tbl))
  69. goto fail;
  70. dm_logger_append(&entry, "[%s][ConnIdx:%d] ",
  71. signal_type_info_tbl[i].name,
  72. link->link_index);
  73. va_start(args, msg);
  74. dm_logger_append_va(&entry, msg, args);
  75. if (entry.buf_offset > 0 &&
  76. entry.buf[entry.buf_offset - 1] == '\n')
  77. entry.buf_offset--;
  78. if (hex_data)
  79. for (i = 0; i < hex_data_count; i++)
  80. dm_logger_append(&entry, "%2.2X ", hex_data[i]);
  81. dm_logger_append(&entry, "^\n");
  82. dm_helpers_dc_conn_log(ctx, &entry, event);
  83. fail:
  84. dm_logger_close(&entry);
  85. va_end(args);
  86. }