abc_common.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. /* abc_common.h
  2. *
  3. * Abnormal Behavior Catcher Common Driver
  4. *
  5. * Copyright (C) 2017 Samsung Electronics
  6. *
  7. * Hyeokseon Yu <[email protected]>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. */
  20. #ifndef SEC_ABC_H
  21. #define SEC_ABC_H
  22. #include <linux/kconfig.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #if IS_ENABLED(CONFIG_DRV_SAMSUNG)
  26. #include <linux/sec_class.h>
  27. #else
  28. extern struct class *sec_class;
  29. #endif
  30. #include <linux/device.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/of.h>
  33. #include <linux/of_device.h>
  34. #include <linux/of_gpio.h>
  35. #include <linux/err.h>
  36. #include <linux/kthread.h>
  37. #include <linux/delay.h>
  38. #include <linux/io.h>
  39. #include <linux/kfifo.h>
  40. #include <linux/slab.h>
  41. #include <linux/suspend.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/rtc.h>
  44. #include <linux/version.h>
  45. #if IS_ENABLED(CONFIG_SEC_KUNIT)
  46. #include <kunit/test.h>
  47. #include <kunit/mock.h>
  48. #else
  49. #define __visible_for_testing static
  50. #endif
  51. #if (KERNEL_VERSION(4, 11, 0) <= LINUX_VERSION_CODE)
  52. #include <linux/sched/clock.h>
  53. #else
  54. #include <linux/sched.h>
  55. #endif
  56. #if IS_ENABLED(CONFIG_SEC_ABC_MOTTO)
  57. #include <linux/sti/abc_motto.h>
  58. #endif
  59. #ifndef EXPORT_SYMBOL_KUNIT
  60. #define EXPORT_SYMBOL_KUNIT(sym) /* nothing */
  61. #endif
  62. #define ABC_CMD_MAX 8
  63. #define ABC_UEVENT_MAX 10
  64. #define ABC_BUFFER_MAX 128
  65. #define ABC_CMD_STR_MAX 16
  66. #define ABC_TYPE_STR_MAX 8
  67. #define ABC_EVENT_STR_MAX 60
  68. #define ABC_SPEC_CMD_STR_MAX 3
  69. #define ABC_WORK_MAX 5
  70. #define ABC_WAIT_ENABLE_TIMEOUT 10000
  71. #define ERROR_REPORT_MODE_BIT (1<<0)
  72. #define ALL_REPORT_MODE_BIT (1<<1)
  73. #define PRE_EVENT_ENABLE_BIT (1<<7)
  74. #define ABC_DISABLED 0
  75. #define ABC_PREOCCURRED_EVENT_MAX 30
  76. #define TIME_STAMP_STR_MAX 25
  77. #define ABC_CLEAR_EVENT_TIMEOUT 300000
  78. #define ABC_EVENT_BUFFER_MAX 30
  79. #define ABC_DEFAULT_COUNT 0
  80. #define ABC_TEST_STR_MAX 128
  81. #define ABC_SKIP_EVENT_COUNT_THRESHOLD 100
  82. enum abc_enable_cmd {
  83. ERROR_REPORT_MODE_ENABLE = 0,
  84. ERROR_REPORT_MODE_DISABLE,
  85. ALL_REPORT_MODE_ENABLE,
  86. ALL_REPORT_MODE_DISABLE,
  87. PRE_EVENT_ENABLE,
  88. PRE_EVENT_DISABLE,
  89. ABC_ENABLE_CMD_MAX,
  90. };
  91. enum abc_event_group {
  92. ABC_GROUP_NONE = -1,
  93. ABC_GROUP_CAMERA_MIPI_ERROR_ALL = 0,
  94. ABC_GROUP_MAX,
  95. };
  96. struct registered_abc_event_struct {
  97. char module_name[ABC_EVENT_STR_MAX];
  98. char error_name[ABC_EVENT_STR_MAX];
  99. char host[ABC_EVENT_STR_MAX];
  100. bool enabled;
  101. bool singular_spec;
  102. int error_count;
  103. enum abc_event_group group;
  104. };
  105. struct abc_event_group_struct {
  106. enum abc_event_group group;
  107. char module[ABC_EVENT_STR_MAX];
  108. char name[ABC_EVENT_STR_MAX];
  109. };
  110. struct abc_spec_cmd {
  111. char module[ABC_EVENT_STR_MAX];
  112. char name[ABC_EVENT_STR_MAX];
  113. char spec[ABC_EVENT_STR_MAX];
  114. };
  115. struct abc_enable_cmd_struct {
  116. enum abc_enable_cmd cmd;
  117. int enable_value;
  118. char abc_cmd_str[ABC_CMD_STR_MAX];
  119. };
  120. enum DATA_TYPE {
  121. TYPE_STRING,
  122. TYPE_INT,
  123. };
  124. struct abc_key_data {
  125. char event_type[ABC_TYPE_STR_MAX];
  126. char event_module[ABC_EVENT_STR_MAX];
  127. char event_name[ABC_EVENT_STR_MAX];
  128. char ext_log[ABC_EVENT_STR_MAX];
  129. unsigned int cur_time;
  130. int idx;
  131. };
  132. struct abc_pre_event {
  133. struct list_head node;
  134. int error_cnt;
  135. int all_cnt;
  136. int idx;
  137. struct abc_key_data key_data;
  138. };
  139. struct abc_fault_info {
  140. unsigned int cur_time;
  141. int cur_cnt;
  142. };
  143. struct abc_event_buffer {
  144. int size;
  145. int rear;
  146. int front;
  147. int warn_cnt;
  148. int buffer_max;
  149. struct abc_fault_info *abc_element;
  150. };
  151. struct abc_common_spec_data {
  152. char *module_name;
  153. char *error_name;
  154. int idx;
  155. //int spec_type; In case a new spec type is added
  156. };
  157. struct spec_data_type1 {
  158. int threshold_cnt;
  159. int threshold_time;
  160. int default_count;
  161. bool default_enabled;
  162. struct list_head node;
  163. struct abc_common_spec_data common_spec;
  164. struct abc_event_buffer buffer;
  165. };
  166. struct abc_platform_data {
  167. unsigned int nItem;
  168. #if IS_ENABLED(CONFIG_SEC_ABC_MOTTO)
  169. struct abc_motto_data *motto_data;
  170. #endif
  171. struct list_head abc_spec_list;
  172. };
  173. struct abc_event_work {
  174. char abc_str[ABC_BUFFER_MAX];
  175. struct work_struct work;
  176. };
  177. struct abc_info {
  178. struct device *dev;
  179. struct workqueue_struct *workqueue;
  180. struct abc_event_work event_work_data[ABC_WORK_MAX];
  181. struct completion enable_done;
  182. struct delayed_work clear_pre_events;
  183. #if IS_ENABLED(CONFIG_SEC_KUNIT)
  184. struct completion test_work_done;
  185. struct completion test_uevent_done;
  186. #endif
  187. struct abc_platform_data *pdata;
  188. struct mutex work_mutex;
  189. struct mutex spec_mutex;
  190. struct mutex pre_event_mutex;
  191. struct mutex enable_mutex;
  192. };
  193. void abc_common_test_get_log_str(char *log_str);
  194. int sec_abc_get_idx_of_registered_event(char *module_name, char *error_name);
  195. extern void sec_abc_change_spec(const char *str);
  196. extern int sec_abc_read_spec(char *str);
  197. extern void sec_abc_send_event(char *str);
  198. extern int sec_abc_get_enabled(void);
  199. extern int sec_abc_wait_enabled(void);
  200. int sec_abc_save_pre_events(struct abc_key_data *key_data, char *uevent_type);
  201. extern struct registered_abc_event_struct abc_event_list[];
  202. extern int REGISTERED_ABC_EVENT_TOTAL;
  203. #define ABC_PRINT(format, ...) pr_info("[sec_abc] %s : " format, __func__, ##__VA_ARGS__)
  204. #define ABC_DEBUG(format, ...) pr_debug("[sec_abc] %s : " format, __func__, ##__VA_ARGS__)
  205. #ifdef CONFIG_SEC_KUNIT
  206. #define ABC_PRINT_KUNIT(format, ...) do { \
  207. char temp[ABC_TEST_STR_MAX]; \
  208. ABC_PRINT(format, ##__VA_ARGS__); \
  209. snprintf(temp, ABC_TEST_STR_MAX, format, ##__VA_ARGS__); \
  210. abc_common_test_get_log_str(temp); \
  211. } while (0)
  212. #define ABC_DEBUG_KUNIT(format, ...) do { \
  213. char temp[ABC_TEST_STR_MAX]; \
  214. ABC_PRINT(format, ##__VA_ARGS__); \
  215. snprintf(temp, ABC_TEST_STR_MAX, format, ##__VA_ARGS__); \
  216. abc_common_test_get_log_str(temp); \
  217. } while (0)
  218. #else
  219. #define ABC_PRINT_KUNIT(format, ...) ABC_PRINT(format, ##__VA_ARGS__)
  220. #define ABC_DEBUG_KUNIT(format, ...) ABC_DEBUG(format, ##__VA_ARGS__)
  221. #endif
  222. #endif