counter.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Counter interface
  4. * Copyright (C) 2018 William Breathitt Gray
  5. */
  6. #ifndef _COUNTER_H_
  7. #define _COUNTER_H_
  8. #include <linux/cdev.h>
  9. #include <linux/device.h>
  10. #include <linux/kernel.h>
  11. #include <linux/kfifo.h>
  12. #include <linux/mutex.h>
  13. #include <linux/spinlock_types.h>
  14. #include <linux/types.h>
  15. #include <linux/wait.h>
  16. #include <uapi/linux/counter.h>
  17. struct counter_device;
  18. struct counter_count;
  19. struct counter_synapse;
  20. struct counter_signal;
  21. enum counter_comp_type {
  22. COUNTER_COMP_U8,
  23. COUNTER_COMP_U64,
  24. COUNTER_COMP_BOOL,
  25. COUNTER_COMP_SIGNAL_LEVEL,
  26. COUNTER_COMP_FUNCTION,
  27. COUNTER_COMP_SYNAPSE_ACTION,
  28. COUNTER_COMP_ENUM,
  29. COUNTER_COMP_COUNT_DIRECTION,
  30. COUNTER_COMP_COUNT_MODE,
  31. COUNTER_COMP_SIGNAL_POLARITY,
  32. COUNTER_COMP_ARRAY,
  33. };
  34. /**
  35. * struct counter_comp - Counter component node
  36. * @type: Counter component data type
  37. * @name: device-specific component name
  38. * @priv: component-relevant data
  39. * @action_read: Synapse action mode read callback. The read value of the
  40. * respective Synapse action mode should be passed back via
  41. * the action parameter.
  42. * @device_u8_read: Device u8 component read callback. The read value of the
  43. * respective Device u8 component should be passed back via
  44. * the val parameter.
  45. * @count_u8_read: Count u8 component read callback. The read value of the
  46. * respective Count u8 component should be passed back via
  47. * the val parameter.
  48. * @signal_u8_read: Signal u8 component read callback. The read value of the
  49. * respective Signal u8 component should be passed back via
  50. * the val parameter.
  51. * @device_u32_read: Device u32 component read callback. The read value of
  52. * the respective Device u32 component should be passed
  53. * back via the val parameter.
  54. * @count_u32_read: Count u32 component read callback. The read value of the
  55. * respective Count u32 component should be passed back via
  56. * the val parameter.
  57. * @signal_u32_read: Signal u32 component read callback. The read value of
  58. * the respective Signal u32 component should be passed
  59. * back via the val parameter.
  60. * @device_u64_read: Device u64 component read callback. The read value of
  61. * the respective Device u64 component should be passed
  62. * back via the val parameter.
  63. * @count_u64_read: Count u64 component read callback. The read value of the
  64. * respective Count u64 component should be passed back via
  65. * the val parameter.
  66. * @signal_u64_read: Signal u64 component read callback. The read value of
  67. * the respective Signal u64 component should be passed
  68. * back via the val parameter.
  69. * @signal_array_u32_read: Signal u32 array component read callback. The
  70. * index of the respective Count u32 array
  71. * component element is passed via the idx
  72. * parameter. The read value of the respective
  73. * Count u32 array component element should be
  74. * passed back via the val parameter.
  75. * @device_array_u64_read: Device u64 array component read callback. The
  76. * index of the respective Device u64 array
  77. * component element is passed via the idx
  78. * parameter. The read value of the respective
  79. * Device u64 array component element should be
  80. * passed back via the val parameter.
  81. * @count_array_u64_read: Count u64 array component read callback. The
  82. * index of the respective Count u64 array
  83. * component element is passed via the idx
  84. * parameter. The read value of the respective
  85. * Count u64 array component element should be
  86. * passed back via the val parameter.
  87. * @signal_array_u64_read: Signal u64 array component read callback. The
  88. * index of the respective Count u64 array
  89. * component element is passed via the idx
  90. * parameter. The read value of the respective
  91. * Count u64 array component element should be
  92. * passed back via the val parameter.
  93. * @action_write: Synapse action mode write callback. The write value of
  94. * the respective Synapse action mode is passed via the
  95. * action parameter.
  96. * @device_u8_write: Device u8 component write callback. The write value of
  97. * the respective Device u8 component is passed via the val
  98. * parameter.
  99. * @count_u8_write: Count u8 component write callback. The write value of
  100. * the respective Count u8 component is passed via the val
  101. * parameter.
  102. * @signal_u8_write: Signal u8 component write callback. The write value of
  103. * the respective Signal u8 component is passed via the val
  104. * parameter.
  105. * @device_u32_write: Device u32 component write callback. The write value of
  106. * the respective Device u32 component is passed via the
  107. * val parameter.
  108. * @count_u32_write: Count u32 component write callback. The write value of
  109. * the respective Count u32 component is passed via the val
  110. * parameter.
  111. * @signal_u32_write: Signal u32 component write callback. The write value of
  112. * the respective Signal u32 component is passed via the
  113. * val parameter.
  114. * @device_u64_write: Device u64 component write callback. The write value of
  115. * the respective Device u64 component is passed via the
  116. * val parameter.
  117. * @count_u64_write: Count u64 component write callback. The write value of
  118. * the respective Count u64 component is passed via the val
  119. * parameter.
  120. * @signal_u64_write: Signal u64 component write callback. The write value of
  121. * the respective Signal u64 component is passed via the
  122. * val parameter.
  123. * @signal_array_u32_write: Signal u32 array component write callback. The
  124. * index of the respective Signal u32 array
  125. * component element is passed via the idx
  126. * parameter. The write value of the respective
  127. * Signal u32 array component element is passed via
  128. * the val parameter.
  129. * @device_array_u64_write: Device u64 array component write callback. The
  130. * index of the respective Device u64 array
  131. * component element is passed via the idx
  132. * parameter. The write value of the respective
  133. * Device u64 array component element is passed via
  134. * the val parameter.
  135. * @count_array_u64_write: Count u64 array component write callback. The
  136. * index of the respective Count u64 array
  137. * component element is passed via the idx
  138. * parameter. The write value of the respective
  139. * Count u64 array component element is passed via
  140. * the val parameter.
  141. * @signal_array_u64_write: Signal u64 array component write callback. The
  142. * index of the respective Signal u64 array
  143. * component element is passed via the idx
  144. * parameter. The write value of the respective
  145. * Signal u64 array component element is passed via
  146. * the val parameter.
  147. */
  148. struct counter_comp {
  149. enum counter_comp_type type;
  150. const char *name;
  151. void *priv;
  152. union {
  153. int (*action_read)(struct counter_device *counter,
  154. struct counter_count *count,
  155. struct counter_synapse *synapse,
  156. enum counter_synapse_action *action);
  157. int (*device_u8_read)(struct counter_device *counter, u8 *val);
  158. int (*count_u8_read)(struct counter_device *counter,
  159. struct counter_count *count, u8 *val);
  160. int (*signal_u8_read)(struct counter_device *counter,
  161. struct counter_signal *signal, u8 *val);
  162. int (*device_u32_read)(struct counter_device *counter,
  163. u32 *val);
  164. int (*count_u32_read)(struct counter_device *counter,
  165. struct counter_count *count, u32 *val);
  166. int (*signal_u32_read)(struct counter_device *counter,
  167. struct counter_signal *signal, u32 *val);
  168. int (*device_u64_read)(struct counter_device *counter,
  169. u64 *val);
  170. int (*count_u64_read)(struct counter_device *counter,
  171. struct counter_count *count, u64 *val);
  172. int (*signal_u64_read)(struct counter_device *counter,
  173. struct counter_signal *signal, u64 *val);
  174. int (*signal_array_u32_read)(struct counter_device *counter,
  175. struct counter_signal *signal,
  176. size_t idx, u32 *val);
  177. int (*device_array_u64_read)(struct counter_device *counter,
  178. size_t idx, u64 *val);
  179. int (*count_array_u64_read)(struct counter_device *counter,
  180. struct counter_count *count,
  181. size_t idx, u64 *val);
  182. int (*signal_array_u64_read)(struct counter_device *counter,
  183. struct counter_signal *signal,
  184. size_t idx, u64 *val);
  185. };
  186. union {
  187. int (*action_write)(struct counter_device *counter,
  188. struct counter_count *count,
  189. struct counter_synapse *synapse,
  190. enum counter_synapse_action action);
  191. int (*device_u8_write)(struct counter_device *counter, u8 val);
  192. int (*count_u8_write)(struct counter_device *counter,
  193. struct counter_count *count, u8 val);
  194. int (*signal_u8_write)(struct counter_device *counter,
  195. struct counter_signal *signal, u8 val);
  196. int (*device_u32_write)(struct counter_device *counter,
  197. u32 val);
  198. int (*count_u32_write)(struct counter_device *counter,
  199. struct counter_count *count, u32 val);
  200. int (*signal_u32_write)(struct counter_device *counter,
  201. struct counter_signal *signal, u32 val);
  202. int (*device_u64_write)(struct counter_device *counter,
  203. u64 val);
  204. int (*count_u64_write)(struct counter_device *counter,
  205. struct counter_count *count, u64 val);
  206. int (*signal_u64_write)(struct counter_device *counter,
  207. struct counter_signal *signal, u64 val);
  208. int (*signal_array_u32_write)(struct counter_device *counter,
  209. struct counter_signal *signal,
  210. size_t idx, u32 val);
  211. int (*device_array_u64_write)(struct counter_device *counter,
  212. size_t idx, u64 val);
  213. int (*count_array_u64_write)(struct counter_device *counter,
  214. struct counter_count *count,
  215. size_t idx, u64 val);
  216. int (*signal_array_u64_write)(struct counter_device *counter,
  217. struct counter_signal *signal,
  218. size_t idx, u64 val);
  219. };
  220. };
  221. /**
  222. * struct counter_signal - Counter Signal node
  223. * @id: unique ID used to identify the Signal
  224. * @name: device-specific Signal name
  225. * @ext: optional array of Signal extensions
  226. * @num_ext: number of Signal extensions specified in @ext
  227. */
  228. struct counter_signal {
  229. int id;
  230. const char *name;
  231. struct counter_comp *ext;
  232. size_t num_ext;
  233. };
  234. /**
  235. * struct counter_synapse - Counter Synapse node
  236. * @actions_list: array of available action modes
  237. * @num_actions: number of action modes specified in @actions_list
  238. * @signal: pointer to the associated Signal
  239. */
  240. struct counter_synapse {
  241. const enum counter_synapse_action *actions_list;
  242. size_t num_actions;
  243. struct counter_signal *signal;
  244. };
  245. /**
  246. * struct counter_count - Counter Count node
  247. * @id: unique ID used to identify the Count
  248. * @name: device-specific Count name
  249. * @functions_list: array of available function modes
  250. * @num_functions: number of function modes specified in @functions_list
  251. * @synapses: array of Synapses for initialization
  252. * @num_synapses: number of Synapses specified in @synapses
  253. * @ext: optional array of Count extensions
  254. * @num_ext: number of Count extensions specified in @ext
  255. */
  256. struct counter_count {
  257. int id;
  258. const char *name;
  259. const enum counter_function *functions_list;
  260. size_t num_functions;
  261. struct counter_synapse *synapses;
  262. size_t num_synapses;
  263. struct counter_comp *ext;
  264. size_t num_ext;
  265. };
  266. /**
  267. * struct counter_event_node - Counter Event node
  268. * @l: list of current watching Counter events
  269. * @event: event that triggers
  270. * @channel: event channel
  271. * @comp_list: list of components to watch when event triggers
  272. */
  273. struct counter_event_node {
  274. struct list_head l;
  275. u8 event;
  276. u8 channel;
  277. struct list_head comp_list;
  278. };
  279. /**
  280. * struct counter_ops - Callbacks from driver
  281. * @signal_read: optional read callback for Signals. The read level of
  282. * the respective Signal should be passed back via the
  283. * level parameter.
  284. * @count_read: read callback for Counts. The read value of the
  285. * respective Count should be passed back via the value
  286. * parameter.
  287. * @count_write: optional write callback for Counts. The write value for
  288. * the respective Count is passed in via the value
  289. * parameter.
  290. * @function_read: read callback the Count function modes. The read
  291. * function mode of the respective Count should be passed
  292. * back via the function parameter.
  293. * @function_write: optional write callback for Count function modes. The
  294. * function mode to write for the respective Count is
  295. * passed in via the function parameter.
  296. * @action_read: optional read callback the Synapse action modes. The
  297. * read action mode of the respective Synapse should be
  298. * passed back via the action parameter.
  299. * @action_write: optional write callback for Synapse action modes. The
  300. * action mode to write for the respective Synapse is
  301. * passed in via the action parameter.
  302. * @events_configure: optional write callback to configure events. The list of
  303. * struct counter_event_node may be accessed via the
  304. * events_list member of the counter parameter.
  305. * @watch_validate: optional callback to validate a watch. The Counter
  306. * component watch configuration is passed in via the watch
  307. * parameter. A return value of 0 indicates a valid Counter
  308. * component watch configuration.
  309. */
  310. struct counter_ops {
  311. int (*signal_read)(struct counter_device *counter,
  312. struct counter_signal *signal,
  313. enum counter_signal_level *level);
  314. int (*count_read)(struct counter_device *counter,
  315. struct counter_count *count, u64 *value);
  316. int (*count_write)(struct counter_device *counter,
  317. struct counter_count *count, u64 value);
  318. int (*function_read)(struct counter_device *counter,
  319. struct counter_count *count,
  320. enum counter_function *function);
  321. int (*function_write)(struct counter_device *counter,
  322. struct counter_count *count,
  323. enum counter_function function);
  324. int (*action_read)(struct counter_device *counter,
  325. struct counter_count *count,
  326. struct counter_synapse *synapse,
  327. enum counter_synapse_action *action);
  328. int (*action_write)(struct counter_device *counter,
  329. struct counter_count *count,
  330. struct counter_synapse *synapse,
  331. enum counter_synapse_action action);
  332. int (*events_configure)(struct counter_device *counter);
  333. int (*watch_validate)(struct counter_device *counter,
  334. const struct counter_watch *watch);
  335. };
  336. /**
  337. * struct counter_device - Counter data structure
  338. * @name: name of the device
  339. * @parent: optional parent device providing the counters
  340. * @ops: callbacks from driver
  341. * @signals: array of Signals
  342. * @num_signals: number of Signals specified in @signals
  343. * @counts: array of Counts
  344. * @num_counts: number of Counts specified in @counts
  345. * @ext: optional array of Counter device extensions
  346. * @num_ext: number of Counter device extensions specified in @ext
  347. * @priv: optional private data supplied by driver
  348. * @dev: internal device structure
  349. * @chrdev: internal character device structure
  350. * @events_list: list of current watching Counter events
  351. * @events_list_lock: lock to protect Counter events list operations
  352. * @next_events_list: list of next watching Counter events
  353. * @n_events_list_lock: lock to protect Counter next events list operations
  354. * @events: queue of detected Counter events
  355. * @events_wait: wait queue to allow blocking reads of Counter events
  356. * @events_in_lock: lock to protect Counter events queue in operations
  357. * @events_out_lock: lock to protect Counter events queue out operations
  358. * @ops_exist_lock: lock to prevent use during removal
  359. */
  360. struct counter_device {
  361. const char *name;
  362. struct device *parent;
  363. const struct counter_ops *ops;
  364. struct counter_signal *signals;
  365. size_t num_signals;
  366. struct counter_count *counts;
  367. size_t num_counts;
  368. struct counter_comp *ext;
  369. size_t num_ext;
  370. struct device dev;
  371. struct cdev chrdev;
  372. struct list_head events_list;
  373. spinlock_t events_list_lock;
  374. struct list_head next_events_list;
  375. struct mutex n_events_list_lock;
  376. DECLARE_KFIFO_PTR(events, struct counter_event);
  377. wait_queue_head_t events_wait;
  378. spinlock_t events_in_lock;
  379. struct mutex events_out_lock;
  380. struct mutex ops_exist_lock;
  381. };
  382. void *counter_priv(const struct counter_device *const counter);
  383. struct counter_device *counter_alloc(size_t sizeof_priv);
  384. void counter_put(struct counter_device *const counter);
  385. int counter_add(struct counter_device *const counter);
  386. void counter_unregister(struct counter_device *const counter);
  387. struct counter_device *devm_counter_alloc(struct device *dev,
  388. size_t sizeof_priv);
  389. int devm_counter_add(struct device *dev,
  390. struct counter_device *const counter);
  391. void counter_push_event(struct counter_device *const counter, const u8 event,
  392. const u8 channel);
  393. #define COUNTER_COMP_DEVICE_U8(_name, _read, _write) \
  394. { \
  395. .type = COUNTER_COMP_U8, \
  396. .name = (_name), \
  397. .device_u8_read = (_read), \
  398. .device_u8_write = (_write), \
  399. }
  400. #define COUNTER_COMP_COUNT_U8(_name, _read, _write) \
  401. { \
  402. .type = COUNTER_COMP_U8, \
  403. .name = (_name), \
  404. .count_u8_read = (_read), \
  405. .count_u8_write = (_write), \
  406. }
  407. #define COUNTER_COMP_SIGNAL_U8(_name, _read, _write) \
  408. { \
  409. .type = COUNTER_COMP_U8, \
  410. .name = (_name), \
  411. .signal_u8_read = (_read), \
  412. .signal_u8_write = (_write), \
  413. }
  414. #define COUNTER_COMP_DEVICE_U64(_name, _read, _write) \
  415. { \
  416. .type = COUNTER_COMP_U64, \
  417. .name = (_name), \
  418. .device_u64_read = (_read), \
  419. .device_u64_write = (_write), \
  420. }
  421. #define COUNTER_COMP_COUNT_U64(_name, _read, _write) \
  422. { \
  423. .type = COUNTER_COMP_U64, \
  424. .name = (_name), \
  425. .count_u64_read = (_read), \
  426. .count_u64_write = (_write), \
  427. }
  428. #define COUNTER_COMP_SIGNAL_U64(_name, _read, _write) \
  429. { \
  430. .type = COUNTER_COMP_U64, \
  431. .name = (_name), \
  432. .signal_u64_read = (_read), \
  433. .signal_u64_write = (_write), \
  434. }
  435. #define COUNTER_COMP_DEVICE_BOOL(_name, _read, _write) \
  436. { \
  437. .type = COUNTER_COMP_BOOL, \
  438. .name = (_name), \
  439. .device_u8_read = (_read), \
  440. .device_u8_write = (_write), \
  441. }
  442. #define COUNTER_COMP_COUNT_BOOL(_name, _read, _write) \
  443. { \
  444. .type = COUNTER_COMP_BOOL, \
  445. .name = (_name), \
  446. .count_u8_read = (_read), \
  447. .count_u8_write = (_write), \
  448. }
  449. #define COUNTER_COMP_SIGNAL_BOOL(_name, _read, _write) \
  450. { \
  451. .type = COUNTER_COMP_BOOL, \
  452. .name = (_name), \
  453. .signal_u8_read = (_read), \
  454. .signal_u8_write = (_write), \
  455. }
  456. struct counter_available {
  457. union {
  458. const u32 *enums;
  459. const char *const *strs;
  460. };
  461. size_t num_items;
  462. };
  463. #define DEFINE_COUNTER_AVAILABLE(_name, _enums) \
  464. struct counter_available _name = { \
  465. .enums = (_enums), \
  466. .num_items = ARRAY_SIZE(_enums), \
  467. }
  468. #define DEFINE_COUNTER_ENUM(_name, _strs) \
  469. struct counter_available _name = { \
  470. .strs = (_strs), \
  471. .num_items = ARRAY_SIZE(_strs), \
  472. }
  473. #define COUNTER_COMP_DEVICE_ENUM(_name, _get, _set, _available) \
  474. { \
  475. .type = COUNTER_COMP_ENUM, \
  476. .name = (_name), \
  477. .device_u32_read = (_get), \
  478. .device_u32_write = (_set), \
  479. .priv = &(_available), \
  480. }
  481. #define COUNTER_COMP_COUNT_ENUM(_name, _get, _set, _available) \
  482. { \
  483. .type = COUNTER_COMP_ENUM, \
  484. .name = (_name), \
  485. .count_u32_read = (_get), \
  486. .count_u32_write = (_set), \
  487. .priv = &(_available), \
  488. }
  489. #define COUNTER_COMP_SIGNAL_ENUM(_name, _get, _set, _available) \
  490. { \
  491. .type = COUNTER_COMP_ENUM, \
  492. .name = (_name), \
  493. .signal_u32_read = (_get), \
  494. .signal_u32_write = (_set), \
  495. .priv = &(_available), \
  496. }
  497. struct counter_array {
  498. enum counter_comp_type type;
  499. const struct counter_available *avail;
  500. union {
  501. size_t length;
  502. size_t idx;
  503. };
  504. };
  505. #define DEFINE_COUNTER_ARRAY_U64(_name, _length) \
  506. struct counter_array _name = { \
  507. .type = COUNTER_COMP_U64, \
  508. .length = (_length), \
  509. }
  510. #define DEFINE_COUNTER_ARRAY_CAPTURE(_name, _length) \
  511. DEFINE_COUNTER_ARRAY_U64(_name, _length)
  512. #define DEFINE_COUNTER_ARRAY_POLARITY(_name, _available, _length) \
  513. struct counter_array _name = { \
  514. .type = COUNTER_COMP_SIGNAL_POLARITY, \
  515. .avail = &(_available), \
  516. .length = (_length), \
  517. }
  518. #define COUNTER_COMP_DEVICE_ARRAY_U64(_name, _read, _write, _array) \
  519. { \
  520. .type = COUNTER_COMP_ARRAY, \
  521. .name = (_name), \
  522. .device_array_u64_read = (_read), \
  523. .device_array_u64_write = (_write), \
  524. .priv = &(_array), \
  525. }
  526. #define COUNTER_COMP_COUNT_ARRAY_U64(_name, _read, _write, _array) \
  527. { \
  528. .type = COUNTER_COMP_ARRAY, \
  529. .name = (_name), \
  530. .count_array_u64_read = (_read), \
  531. .count_array_u64_write = (_write), \
  532. .priv = &(_array), \
  533. }
  534. #define COUNTER_COMP_SIGNAL_ARRAY_U64(_name, _read, _write, _array) \
  535. { \
  536. .type = COUNTER_COMP_ARRAY, \
  537. .name = (_name), \
  538. .signal_array_u64_read = (_read), \
  539. .signal_array_u64_write = (_write), \
  540. .priv = &(_array), \
  541. }
  542. #define COUNTER_COMP_CAPTURE(_read, _write) \
  543. COUNTER_COMP_COUNT_U64("capture", _read, _write)
  544. #define COUNTER_COMP_CEILING(_read, _write) \
  545. COUNTER_COMP_COUNT_U64("ceiling", _read, _write)
  546. #define COUNTER_COMP_COUNT_MODE(_read, _write, _available) \
  547. { \
  548. .type = COUNTER_COMP_COUNT_MODE, \
  549. .name = "count_mode", \
  550. .count_u32_read = (_read), \
  551. .count_u32_write = (_write), \
  552. .priv = &(_available), \
  553. }
  554. #define COUNTER_COMP_DIRECTION(_read) \
  555. { \
  556. .type = COUNTER_COMP_COUNT_DIRECTION, \
  557. .name = "direction", \
  558. .count_u32_read = (_read), \
  559. }
  560. #define COUNTER_COMP_ENABLE(_read, _write) \
  561. COUNTER_COMP_COUNT_BOOL("enable", _read, _write)
  562. #define COUNTER_COMP_FLOOR(_read, _write) \
  563. COUNTER_COMP_COUNT_U64("floor", _read, _write)
  564. #define COUNTER_COMP_POLARITY(_read, _write, _available) \
  565. { \
  566. .type = COUNTER_COMP_SIGNAL_POLARITY, \
  567. .name = "polarity", \
  568. .signal_u32_read = (_read), \
  569. .signal_u32_write = (_write), \
  570. .priv = &(_available), \
  571. }
  572. #define COUNTER_COMP_PRESET(_read, _write) \
  573. COUNTER_COMP_COUNT_U64("preset", _read, _write)
  574. #define COUNTER_COMP_PRESET_ENABLE(_read, _write) \
  575. COUNTER_COMP_COUNT_BOOL("preset_enable", _read, _write)
  576. #define COUNTER_COMP_ARRAY_CAPTURE(_read, _write, _array) \
  577. COUNTER_COMP_COUNT_ARRAY_U64("capture", _read, _write, _array)
  578. #define COUNTER_COMP_ARRAY_POLARITY(_read, _write, _array) \
  579. { \
  580. .type = COUNTER_COMP_ARRAY, \
  581. .name = "polarity", \
  582. .signal_array_u32_read = (_read), \
  583. .signal_array_u32_write = (_write), \
  584. .priv = &(_array), \
  585. }
  586. #endif /* _COUNTER_H_ */