log_backend_adsp.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2019 Intel Corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <logging/log_backend.h>
  7. #include <logging/log_core.h>
  8. #include <logging/log_msg.h>
  9. #include <logging/log_output.h>
  10. #include <logging/log_backend_std.h>
  11. void intel_adsp_trace_out(int8_t *str, size_t len);
  12. static int char_out(uint8_t *data, size_t length, void *ctx)
  13. {
  14. intel_adsp_trace_out(data, length);
  15. return length;
  16. }
  17. /* Trace output goes in 64 byte chunks with a 4-byte header, no point
  18. * in buffering more than 60 bytes at a time
  19. */
  20. static uint8_t log_buf[60];
  21. LOG_OUTPUT_DEFINE(log_output_adsp, char_out, log_buf, 1);
  22. static uint32_t format_flags(void)
  23. {
  24. uint32_t flags = LOG_OUTPUT_FLAG_LEVEL | LOG_OUTPUT_FLAG_TIMESTAMP;
  25. if (IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)) {
  26. flags |= LOG_OUTPUT_FLAG_FORMAT_TIMESTAMP;
  27. }
  28. return flags;
  29. }
  30. static inline void put(const struct log_backend *const backend,
  31. struct log_msg *msg)
  32. {
  33. log_backend_std_put(&log_output_adsp, format_flags(), msg);
  34. }
  35. static void panic(struct log_backend const *const backend)
  36. {
  37. log_backend_std_panic(&log_output_adsp);
  38. }
  39. static inline void dropped(const struct log_backend *const backend,
  40. uint32_t cnt)
  41. {
  42. log_output_dropped_process(&log_output_adsp, cnt);
  43. }
  44. static inline void put_sync_string(const struct log_backend *const backend,
  45. struct log_msg_ids src_level,
  46. uint32_t timestamp, const char *fmt,
  47. va_list ap)
  48. {
  49. log_output_string(&log_output_adsp, src_level,
  50. timestamp, fmt, ap, format_flags());
  51. }
  52. static inline void put_sync_hexdump(const struct log_backend *const backend,
  53. struct log_msg_ids src_level,
  54. uint32_t timestamp, const char *metadata,
  55. const uint8_t *data, uint32_t length)
  56. {
  57. log_output_hexdump(&log_output_adsp, src_level, timestamp,
  58. metadata, data, length, format_flags());
  59. }
  60. static void process(const struct log_backend *const backend,
  61. union log_msg2_generic *msg)
  62. {
  63. log_output_msg2_process(&log_output_adsp, &msg->log, format_flags());
  64. }
  65. const struct log_backend_api log_backend_adsp_api = {
  66. .process = IS_ENABLED(CONFIG_LOG2) ? process : NULL,
  67. .put_sync_string = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ?
  68. put_sync_string : NULL,
  69. .put_sync_hexdump = IS_ENABLED(CONFIG_LOG_MODE_IMMEDIATE) ?
  70. put_sync_hexdump : NULL,
  71. .put = IS_ENABLED(CONFIG_LOG_MODE_DEFERRED) ? put : NULL,
  72. .dropped = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : dropped,
  73. .panic = panic,
  74. };
  75. LOG_BACKEND_DEFINE(log_backend_adsp, log_backend_adsp_api, true);