blob: 5bc8b6a930053a9ae443d86f4f4f8a0a2b6da48e [file] [log] [blame]
Dhoat Harpalf76b2362018-03-22 20:37:38 +05301/* Copyright (c) 2012-2015, 2018 The Linux Foundation. All rights reserved.
Chris Lew3c8356762016-08-01 15:18:55 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#ifndef _IPC_LOGGING_H
14#define _IPC_LOGGING_H
15
16#include <linux/types.h>
17
18#define MAX_MSG_SIZE 255
19
20enum {
21 TSV_TYPE_MSG_START = 1,
22 TSV_TYPE_SKB = TSV_TYPE_MSG_START,
23 TSV_TYPE_STRING,
24 TSV_TYPE_MSG_END = TSV_TYPE_STRING,
25};
26
27struct tsv_header {
28 unsigned char type;
29 unsigned char size; /* size of data field */
30};
31
32struct encode_context {
33 struct tsv_header hdr;
34 char buff[MAX_MSG_SIZE];
35 int offset;
36};
37
38struct decode_context {
39 int output_format; /* 0 = debugfs */
40 char *buff; /* output buffer */
41 int size; /* size of output buffer */
42};
43
44#if defined(CONFIG_IPC_LOGGING)
45/*
46 * ipc_log_context_create: Create a debug log context
47 * Should not be called from atomic context
48 *
49 * @max_num_pages: Number of pages of logging space required (max. 10)
50 * @mod_name : Name of the directory entry under DEBUGFS
51 * @user_version : Version number of user-defined message formats
52 *
53 * returns context id on success, NULL on failure
54 */
55void *ipc_log_context_create(int max_num_pages, const char *modname,
56 uint16_t user_version);
57
58/*
59 * msg_encode_start: Start encoding a log message
60 *
61 * @ectxt: Temporary storage to hold the encoded message
62 * @type: Root event type defined by the module which is logging
63 */
64void msg_encode_start(struct encode_context *ectxt, uint32_t type);
65
66/*
67 * tsv_timestamp_write: Writes the current timestamp count
68 *
69 * @ectxt: Context initialized by calling msg_encode_start()
70 */
71int tsv_timestamp_write(struct encode_context *ectxt);
72
73/*
74 * tsv_qtimer_write: Writes the current QTimer timestamp count
75 *
76 * @ectxt: Context initialized by calling msg_encode_start()
77 */
78int tsv_qtimer_write(struct encode_context *ectxt);
79
80/*
81 * tsv_pointer_write: Writes a data pointer
82 *
83 * @ectxt: Context initialized by calling msg_encode_start()
84 * @pointer: Pointer value to write
85 */
86int tsv_pointer_write(struct encode_context *ectxt, void *pointer);
87
88/*
89 * tsv_int32_write: Writes a 32-bit integer value
90 *
91 * @ectxt: Context initialized by calling msg_encode_start()
92 * @n: Integer to write
93 */
94int tsv_int32_write(struct encode_context *ectxt, int32_t n);
95
96/*
97 * tsv_int32_write: Writes a 32-bit integer value
98 *
99 * @ectxt: Context initialized by calling msg_encode_start()
100 * @n: Integer to write
101 */
102int tsv_byte_array_write(struct encode_context *ectxt,
103 void *data, int data_size);
104
105/*
106 * msg_encode_end: Complete the message encode process
107 *
108 * @ectxt: Temporary storage which holds the encoded message
109 */
110void msg_encode_end(struct encode_context *ectxt);
111
112/*
113 * msg_encode_end: Complete the message encode process
114 *
115 * @ectxt: Temporary storage which holds the encoded message
116 */
117void ipc_log_write(void *ctxt, struct encode_context *ectxt);
118
119/*
120 * ipc_log_string: Helper function to log a string
121 *
122 * @ilctxt: Debug Log Context created using ipc_log_context_create()
123 * @fmt: Data specified using format specifiers
124 */
125int ipc_log_string(void *ilctxt, const char *fmt, ...) __printf(2, 3);
126
Dhoat Harpalf76b2362018-03-22 20:37:38 +0530127/*
128 * ipc_log_ctrl_all - disable/enable logging in all clients
129 *
130 * @ Data specified using format specifiers
131 */
132void ipc_log_ctrl_all(bool disable);
133
Chris Lew3c8356762016-08-01 15:18:55 -0700134/**
135 * ipc_log_extract - Reads and deserializes log
136 *
137 * @ilctxt: logging context
138 * @buff: buffer to receive the data
139 * @size: size of the buffer
140 * @returns: 0 if no data read; >0 number of bytes read; < 0 error
141 *
142 * If no data is available to be read, then the ilctxt::read_avail
143 * completion is reinitialized. This allows clients to block
144 * until new log data is save.
145 */
146int ipc_log_extract(void *ilctxt, char *buff, int size);
147
148/*
149 * Print a string to decode context.
150 * @dctxt Decode context
151 * @args printf args
152 */
153#define IPC_SPRINTF_DECODE(dctxt, args...) \
154do { \
155 int i; \
156 i = scnprintf(dctxt->buff, dctxt->size, args); \
157 dctxt->buff += i; \
158 dctxt->size -= i; \
159} while (0)
160
161/*
162 * tsv_timestamp_read: Reads a timestamp
163 *
164 * @ectxt: Context retrieved by reading from log space
165 * @dctxt: Temporary storage to hold the decoded message
166 * @format: Output format while dumping through DEBUGFS
167 */
168void tsv_timestamp_read(struct encode_context *ectxt,
169 struct decode_context *dctxt, const char *format);
170
171/*
172 * tsv_qtimer_read: Reads a QTimer timestamp
173 *
174 * @ectxt: Context retrieved by reading from log space
175 * @dctxt: Temporary storage to hold the decoded message
176 * @format: Output format while dumping through DEBUGFS
177 */
178void tsv_qtimer_read(struct encode_context *ectxt,
179 struct decode_context *dctxt, const char *format);
180
181/*
182 * tsv_pointer_read: Reads a data pointer
183 *
184 * @ectxt: Context retrieved by reading from log space
185 * @dctxt: Temporary storage to hold the decoded message
186 * @format: Output format while dumping through DEBUGFS
187 */
188void tsv_pointer_read(struct encode_context *ectxt,
189 struct decode_context *dctxt, const char *format);
190
191/*
192 * tsv_int32_read: Reads a 32-bit integer value
193 *
194 * @ectxt: Context retrieved by reading from log space
195 * @dctxt: Temporary storage to hold the decoded message
196 * @format: Output format while dumping through DEBUGFS
197 */
198int32_t tsv_int32_read(struct encode_context *ectxt,
199 struct decode_context *dctxt, const char *format);
200
201/*
202 * tsv_int32_read: Reads a 32-bit integer value
203 *
204 * @ectxt: Context retrieved by reading from log space
205 * @dctxt: Temporary storage to hold the decoded message
206 * @format: Output format while dumping through DEBUGFS
207 */
208void tsv_byte_array_read(struct encode_context *ectxt,
209 struct decode_context *dctxt, const char *format);
210
211/*
212 * add_deserialization_func: Register a deserialization function to
213 * to unpack the subevents of a main event
214 *
215 * @ctxt: Debug log context to which the deserialization function has
216 * to be registered
217 * @type: Main/Root event, defined by the module which is logging, to
218 * which this deserialization function has to be registered.
219 * @dfune: Deserialization function to be registered
220 *
221 * return 0 on success, -ve value on FAILURE
222 */
223int add_deserialization_func(void *ctxt, int type,
224 void (*dfunc)(struct encode_context *,
225 struct decode_context *));
226
227/*
228 * ipc_log_context_destroy: Destroy debug log context
229 *
230 * @ctxt: debug log context created by calling ipc_log_context_create API.
231 */
232int ipc_log_context_destroy(void *ctxt);
233
234#else
235
236static inline void *ipc_log_context_create(int max_num_pages,
237 const char *modname, uint16_t user_version)
238{ return NULL; }
239
240static inline void msg_encode_start(struct encode_context *ectxt,
241 uint32_t type) { }
242
243static inline int tsv_timestamp_write(struct encode_context *ectxt)
244{ return -EINVAL; }
245
246static inline int tsv_qtimer_write(struct encode_context *ectxt)
247{ return -EINVAL; }
248
249static inline int tsv_pointer_write(struct encode_context *ectxt, void *pointer)
250{ return -EINVAL; }
251
252static inline int tsv_int32_write(struct encode_context *ectxt, int32_t n)
253{ return -EINVAL; }
254
255static inline int tsv_byte_array_write(struct encode_context *ectxt,
256 void *data, int data_size)
257{ return -EINVAL; }
258
259static inline void msg_encode_end(struct encode_context *ectxt) { }
260
261static inline void ipc_log_write(void *ctxt, struct encode_context *ectxt) { }
262
263static inline int ipc_log_string(void *ilctxt, const char *fmt, ...)
264{ return -EINVAL; }
265
266static inline int ipc_log_extract(void *ilctxt, char *buff, int size)
267{ return -EINVAL; }
268
269#define IPC_SPRINTF_DECODE(dctxt, args...) do { } while (0)
270
271static inline void tsv_timestamp_read(struct encode_context *ectxt,
272 struct decode_context *dctxt, const char *format) { }
273
274static inline void tsv_qtimer_read(struct encode_context *ectxt,
275 struct decode_context *dctxt, const char *format) { }
276
277static inline void tsv_pointer_read(struct encode_context *ectxt,
278 struct decode_context *dctxt, const char *format) { }
279
280static inline int32_t tsv_int32_read(struct encode_context *ectxt,
281 struct decode_context *dctxt, const char *format)
282{ return 0; }
283
284static inline void tsv_byte_array_read(struct encode_context *ectxt,
285 struct decode_context *dctxt, const char *format) { }
286
287static inline int add_deserialization_func(void *ctxt, int type,
288 void (*dfunc)(struct encode_context *,
289 struct decode_context *))
290{ return 0; }
291
292static inline int ipc_log_context_destroy(void *ctxt)
293{ return 0; }
294
295#endif
296
297#endif