PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/arm/mach-msm/include/mach/msm_ipc_logging.h

https://gitlab.com/bsd1993/android_kernel_zte_x9180
C Header | 267 lines | 95 code | 44 blank | 128 comment | 2 complexity | b2abe4ce63e9e87a1de39f91a4bdabfe MD5 | raw file
  1. /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  2. *
  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. #ifndef _MSM_IPC_LOGGING_H
  13. #define _MSM_IPC_LOGGING_H
  14. #include <linux/types.h>
  15. #define MAX_MSG_SIZE 255
  16. enum {
  17. TSV_TYPE_MSG_START = 1,
  18. TSV_TYPE_SKB = TSV_TYPE_MSG_START,
  19. TSV_TYPE_STRING,
  20. TSV_TYPE_MSG_END = TSV_TYPE_STRING,
  21. };
  22. struct tsv_header {
  23. unsigned char type;
  24. unsigned char size; /* size of data field */
  25. };
  26. struct encode_context {
  27. struct tsv_header hdr;
  28. char buff[MAX_MSG_SIZE];
  29. int offset;
  30. };
  31. struct decode_context {
  32. int output_format; /* 0 = debugfs */
  33. char *buff; /* output buffer */
  34. int size; /* size of output buffer */
  35. };
  36. #if defined(CONFIG_MSM_IPC_LOGGING)
  37. /*
  38. * ipc_log_context_create: Create a debug log context
  39. * Should not be called from atomic context
  40. *
  41. * @max_num_pages: Number of pages of logging space required (max. 10)
  42. * @mod_name : Name of the directory entry under DEBUGFS
  43. * @user_version : Version number of user-defined message formats
  44. *
  45. * returns context id on success, NULL on failure
  46. */
  47. void *ipc_log_context_create(int max_num_pages, const char *modname,
  48. uint16_t user_version);
  49. /*
  50. * msg_encode_start: Start encoding a log message
  51. *
  52. * @ectxt: Temporary storage to hold the encoded message
  53. * @type: Root event type defined by the module which is logging
  54. */
  55. void msg_encode_start(struct encode_context *ectxt, uint32_t type);
  56. /*
  57. * tsv_timestamp_write: Writes the current timestamp count
  58. *
  59. * @ectxt: Context initialized by calling msg_encode_start()
  60. */
  61. int tsv_timestamp_write(struct encode_context *ectxt);
  62. /*
  63. * tsv_pointer_write: Writes a data pointer
  64. *
  65. * @ectxt: Context initialized by calling msg_encode_start()
  66. * @pointer: Pointer value to write
  67. */
  68. int tsv_pointer_write(struct encode_context *ectxt, void *pointer);
  69. /*
  70. * tsv_int32_write: Writes a 32-bit integer value
  71. *
  72. * @ectxt: Context initialized by calling msg_encode_start()
  73. * @n: Integer to write
  74. */
  75. int tsv_int32_write(struct encode_context *ectxt, int32_t n);
  76. /*
  77. * tsv_int32_write: Writes a 32-bit integer value
  78. *
  79. * @ectxt: Context initialized by calling msg_encode_start()
  80. * @n: Integer to write
  81. */
  82. int tsv_byte_array_write(struct encode_context *ectxt,
  83. void *data, int data_size);
  84. /*
  85. * msg_encode_end: Complete the message encode process
  86. *
  87. * @ectxt: Temporary storage which holds the encoded message
  88. */
  89. void msg_encode_end(struct encode_context *ectxt);
  90. /*
  91. * msg_encode_end: Complete the message encode process
  92. *
  93. * @ectxt: Temporary storage which holds the encoded message
  94. */
  95. void ipc_log_write(void *ctxt, struct encode_context *ectxt);
  96. /*
  97. * ipc_log_string: Helper function to log a string
  98. *
  99. * @ilctxt: Debug Log Context created using ipc_log_context_create()
  100. * @fmt: Data specified using format specifiers
  101. */
  102. int ipc_log_string(void *ilctxt, const char *fmt, ...) __printf(2, 3);
  103. /**
  104. * ipc_log_extract - Reads and deserializes log
  105. *
  106. * @ilctxt: logging context
  107. * @buff: buffer to receive the data
  108. * @size: size of the buffer
  109. * @returns: 0 if no data read; >0 number of bytes read; < 0 error
  110. *
  111. * If no data is available to be read, then the ilctxt::read_avail
  112. * completion is reinitialized. This allows clients to block
  113. * until new log data is save.
  114. */
  115. int ipc_log_extract(void *ilctxt, char *buff, int size);
  116. /*
  117. * Print a string to decode context.
  118. * @dctxt Decode context
  119. * @args printf args
  120. */
  121. #define IPC_SPRINTF_DECODE(dctxt, args...) \
  122. do { \
  123. int i; \
  124. i = scnprintf(dctxt->buff, dctxt->size, args); \
  125. dctxt->buff += i; \
  126. dctxt->size -= i; \
  127. } while (0)
  128. /*
  129. * tsv_timestamp_read: Reads a timestamp
  130. *
  131. * @ectxt: Context retrieved by reading from log space
  132. * @dctxt: Temporary storage to hold the decoded message
  133. * @format: Output format while dumping through DEBUGFS
  134. */
  135. void tsv_timestamp_read(struct encode_context *ectxt,
  136. struct decode_context *dctxt, const char *format);
  137. /*
  138. * tsv_pointer_read: Reads a data pointer
  139. *
  140. * @ectxt: Context retrieved by reading from log space
  141. * @dctxt: Temporary storage to hold the decoded message
  142. * @format: Output format while dumping through DEBUGFS
  143. */
  144. void tsv_pointer_read(struct encode_context *ectxt,
  145. struct decode_context *dctxt, const char *format);
  146. /*
  147. * tsv_int32_read: Reads a 32-bit integer value
  148. *
  149. * @ectxt: Context retrieved by reading from log space
  150. * @dctxt: Temporary storage to hold the decoded message
  151. * @format: Output format while dumping through DEBUGFS
  152. */
  153. int32_t tsv_int32_read(struct encode_context *ectxt,
  154. struct decode_context *dctxt, const char *format);
  155. /*
  156. * tsv_int32_read: Reads a 32-bit integer value
  157. *
  158. * @ectxt: Context retrieved by reading from log space
  159. * @dctxt: Temporary storage to hold the decoded message
  160. * @format: Output format while dumping through DEBUGFS
  161. */
  162. void tsv_byte_array_read(struct encode_context *ectxt,
  163. struct decode_context *dctxt, const char *format);
  164. /*
  165. * add_deserialization_func: Register a deserialization function to
  166. * to unpack the subevents of a main event
  167. *
  168. * @ctxt: Debug log context to which the deserialization function has
  169. * to be registered
  170. * @type: Main/Root event, defined by the module which is logging, to
  171. * which this deserialization function has to be registered.
  172. * @dfune: Deserialization function to be registered
  173. *
  174. * return 0 on success, -ve value on FAILURE
  175. */
  176. int add_deserialization_func(void *ctxt, int type,
  177. void (*dfunc)(struct encode_context *,
  178. struct decode_context *));
  179. /*
  180. * ipc_log_context_destroy: Destroy debug log context
  181. *
  182. * @ctxt: debug log context created by calling ipc_log_context_create API.
  183. */
  184. int ipc_log_context_destroy(void *ctxt);
  185. #else
  186. static inline void *ipc_log_context_create(int max_num_pages,
  187. const char *modname, uint16_t user_version)
  188. { return NULL; }
  189. static inline void msg_encode_start(struct encode_context *ectxt,
  190. uint32_t type) { }
  191. static inline int tsv_timestamp_write(struct encode_context *ectxt)
  192. { return -EINVAL; }
  193. static inline int tsv_pointer_write(struct encode_context *ectxt, void *pointer)
  194. { return -EINVAL; }
  195. static inline int tsv_int32_write(struct encode_context *ectxt, int32_t n)
  196. { return -EINVAL; }
  197. static inline int tsv_byte_array_write(struct encode_context *ectxt,
  198. void *data, int data_size)
  199. { return -EINVAL; }
  200. static inline void msg_encode_end(struct encode_context *ectxt) { }
  201. static inline void ipc_log_write(void *ctxt, struct encode_context *ectxt) { }
  202. static inline int ipc_log_string(void *ilctxt, const char *fmt, ...)
  203. { return -EINVAL; }
  204. static inline int ipc_log_extract(void *ilctxt, char *buff, int size)
  205. { return -EINVAL; }
  206. #define IPC_SPRINTF_DECODE(dctxt, args...) do { } while (0)
  207. static inline void tsv_timestamp_read(struct encode_context *ectxt,
  208. struct decode_context *dctxt, const char *format) { }
  209. static inline void tsv_pointer_read(struct encode_context *ectxt,
  210. struct decode_context *dctxt, const char *format) { }
  211. static inline int32_t tsv_int32_read(struct encode_context *ectxt,
  212. struct decode_context *dctxt, const char *format)
  213. { return 0; }
  214. static inline void tsv_byte_array_read(struct encode_context *ectxt,
  215. struct decode_context *dctxt, const char *format) { }
  216. static inline int add_deserialization_func(void *ctxt, int type,
  217. void (*dfunc)(struct encode_context *,
  218. struct decode_context *))
  219. { return 0; }
  220. static inline int ipc_log_context_destroy(void *ctxt)
  221. { return 0; }
  222. #endif
  223. #endif