diag_dci.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /* Copyright (c) 2012-2015, 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 DIAG_DCI_H
  13. #define DIAG_DCI_H
  14. #define MAX_DCI_CLIENTS 10
  15. #define DCI_PKT_RSP_CODE 0x93
  16. #define DCI_DELAYED_RSP_CODE 0x94
  17. #define LOG_CMD_CODE 0x10
  18. #define EVENT_CMD_CODE 0x60
  19. #define DCI_PKT_RSP_TYPE 0
  20. #define DCI_LOG_TYPE -1
  21. #define DCI_EVENT_TYPE -2
  22. #define SET_LOG_MASK 1
  23. #define DISABLE_LOG_MASK 0
  24. #define MAX_EVENT_SIZE 512
  25. #define DCI_CLIENT_INDEX_INVALID -1
  26. #define DCI_PKT_REQ_MIN_LEN 5
  27. #define DCI_LOG_CON_MIN_LEN 14
  28. #define DCI_EVENT_CON_MIN_LEN 16
  29. #define DIAG_DATA_TYPE 1
  30. #define DIAG_CNTL_TYPE 2
  31. #define DCI_BUF_PRIMARY 1
  32. #define DCI_BUF_SECONDARY 2
  33. #define DCI_BUF_CMD 3
  34. #ifdef CONFIG_DEBUG_FS
  35. #define DIAG_DCI_DEBUG_CNT 100
  36. #define DIAG_DCI_DEBUG_LEN 100
  37. #endif
  38. /* 16 log code categories, each has:
  39. * 1 bytes equip id + 1 dirty byte + 512 byte max log mask
  40. */
  41. #define DCI_LOG_MASK_SIZE (16*514)
  42. #define DCI_EVENT_MASK_SIZE 512
  43. #define DCI_MASK_STREAM 2
  44. #define DCI_MAX_LOG_CODES 16
  45. #define DCI_MAX_ITEMS_PER_LOG_CODE 512
  46. #define MIN_DELAYED_RSP_LEN 12
  47. extern unsigned int dci_max_reg;
  48. extern unsigned int dci_max_clients;
  49. extern unsigned char dci_cumulative_log_mask[DCI_LOG_MASK_SIZE];
  50. extern unsigned char dci_cumulative_event_mask[DCI_EVENT_MASK_SIZE];
  51. extern struct mutex dci_health_mutex;
  52. struct dci_pkt_req_entry_t {
  53. int pid;
  54. int uid;
  55. int tag;
  56. struct list_head track;
  57. } __packed;
  58. struct diag_dci_reg_tbl_t {
  59. uint32_t client_id;
  60. uint16_t notification_list;
  61. int signal_type;
  62. };
  63. struct diag_dci_health_t {
  64. int dropped_logs;
  65. int dropped_events;
  66. int received_logs;
  67. int received_events;
  68. };
  69. struct diag_dci_buffer_t {
  70. unsigned char *data;
  71. unsigned int data_len;
  72. struct mutex data_mutex;
  73. uint8_t in_busy;
  74. uint8_t buf_type;
  75. int data_source;
  76. int capacity;
  77. uint8_t in_list;
  78. struct list_head buf_track;
  79. };
  80. struct diag_dci_buf_peripheral_t {
  81. struct diag_dci_buffer_t *buf_curr;
  82. struct diag_dci_buffer_t *buf_primary;
  83. struct diag_dci_buffer_t *buf_cmd;
  84. struct diag_dci_health_t health;
  85. struct mutex health_mutex;
  86. struct mutex buf_mutex;
  87. };
  88. struct diag_dci_client_tbl {
  89. int tgid;
  90. struct diag_dci_reg_tbl_t client_info;
  91. struct task_struct *client;
  92. unsigned char *dci_log_mask;
  93. unsigned char *dci_event_mask;
  94. uint8_t real_time;
  95. struct list_head track;
  96. struct diag_dci_buf_peripheral_t buffers[NUM_DCI_PROC];
  97. uint8_t in_service;
  98. struct list_head list_write_buf;
  99. struct mutex write_buf_mutex;
  100. };
  101. struct diag_dci_health_stats {
  102. struct diag_dci_health_t stats;
  103. int reset_status;
  104. };
  105. struct diag_dci_health_stats_proc {
  106. struct diag_dci_health_stats *health;
  107. int proc;
  108. };
  109. /* This is used for querying DCI Log
  110. or Event Mask */
  111. struct diag_log_event_stats {
  112. uint16_t code;
  113. int is_set;
  114. };
  115. struct diag_dci_pkt_rsp_header_t {
  116. int type;
  117. int length;
  118. uint8_t delete_flag;
  119. int uid;
  120. } __packed;
  121. struct diag_dci_pkt_header_t {
  122. uint8_t start;
  123. uint8_t version;
  124. uint16_t len;
  125. uint8_t pkt_code;
  126. int tag;
  127. } __packed;
  128. enum {
  129. DIAG_DCI_NO_ERROR = 1001, /* No error */
  130. DIAG_DCI_NO_REG, /* Could not register */
  131. DIAG_DCI_NO_MEM, /* Failed memory allocation */
  132. DIAG_DCI_NOT_SUPPORTED, /* This particular client is not supported */
  133. DIAG_DCI_HUGE_PACKET, /* Request/Response Packet too huge */
  134. DIAG_DCI_SEND_DATA_FAIL,/* writing to kernel or peripheral fails */
  135. DIAG_DCI_TABLE_ERR /* Error dealing with registration tables */
  136. };
  137. #ifdef CONFIG_DEBUG_FS
  138. /* To collect debug information during each smd read */
  139. struct diag_dci_data_info {
  140. unsigned long iteration;
  141. int data_size;
  142. char time_stamp[DIAG_TS_SIZE];
  143. uint8_t peripheral;
  144. uint8_t ch_type;
  145. };
  146. extern struct diag_dci_data_info *dci_data_smd;
  147. extern struct mutex dci_stat_mutex;
  148. #endif
  149. int diag_dci_init(void);
  150. void diag_dci_exit(void);
  151. int diag_dci_register_client(struct diag_dci_reg_tbl_t *reg_entry);
  152. int diag_dci_deinit_client(void);
  153. void diag_update_smd_dci_work_fn(struct work_struct *);
  154. void diag_dci_notify_client(int peripheral_mask, int data);
  155. void diag_dci_wakeup_clients(void);
  156. void diag_process_apps_dci_read_data(int data_type, void *buf, int recd_bytes);
  157. int diag_process_smd_dci_read_data(struct diag_smd_info *smd_info, void *buf,
  158. int recd_bytes);
  159. int diag_process_dci_transaction(unsigned char *buf, int len);
  160. void extract_dci_pkt_rsp(unsigned char *buf, int len, int data_source,
  161. struct diag_smd_info *smd_info);
  162. struct diag_dci_client_tbl *diag_dci_get_client_entry(void);
  163. /* DCI Log streaming functions */
  164. void create_dci_log_mask_tbl(unsigned char *tbl_buf);
  165. void update_dci_cumulative_log_mask(int offset, unsigned int byte_index,
  166. uint8_t byte_mask);
  167. void diag_dci_invalidate_cumulative_log_mask(void);
  168. int diag_send_dci_log_mask(void);
  169. void extract_dci_log(unsigned char *buf, int len, int data_source);
  170. int diag_dci_clear_log_mask(void);
  171. int diag_dci_query_log_mask(uint16_t log_code);
  172. /* DCI event streaming functions */
  173. void update_dci_cumulative_event_mask(int offset, uint8_t byte_mask);
  174. void diag_dci_invalidate_cumulative_event_mask(void);
  175. int diag_send_dci_event_mask(void);
  176. void extract_dci_events(unsigned char *buf, int len, int data_source);
  177. void create_dci_event_mask_tbl(unsigned char *tbl_buf);
  178. int diag_dci_clear_event_mask(void);
  179. int diag_dci_query_event_mask(uint16_t event_id);
  180. void diag_dci_smd_record_info(int read_bytes, uint8_t ch_type,
  181. uint8_t peripheral);
  182. uint8_t diag_dci_get_cumulative_real_time(void);
  183. int diag_dci_set_real_time(uint8_t real_time);
  184. int diag_dci_copy_health_stats(struct diag_dci_health_stats *stats, int proc);
  185. /* Functions related to DCI wakeup sources */
  186. void diag_dci_try_activate_wakeup_source(void);
  187. void diag_dci_try_deactivate_wakeup_source(void);
  188. int diag_dci_write_proc(int peripheral, int pkt_type, char *buf, int len);
  189. #endif