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