logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

counter.h (4889B)


  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * Userspace ABI for Counter character devices
  4. * Copyright (C) 2020 William Breathitt Gray
  5. */
  6. #ifndef _COUNTER_H_
  7. #define _COUNTER_H_
  8. #include <linux/ioctl.h>
  9. #include <linux/types.h>
  10. /* Component type definitions */
  11. enum counter_component_type {
  12. COUNTER_COMPONENT_NONE,
  13. COUNTER_COMPONENT_SIGNAL,
  14. COUNTER_COMPONENT_COUNT,
  15. COUNTER_COMPONENT_FUNCTION,
  16. COUNTER_COMPONENT_SYNAPSE_ACTION,
  17. COUNTER_COMPONENT_EXTENSION,
  18. };
  19. /* Component scope definitions */
  20. enum counter_scope {
  21. COUNTER_SCOPE_DEVICE,
  22. COUNTER_SCOPE_SIGNAL,
  23. COUNTER_SCOPE_COUNT,
  24. };
  25. /**
  26. * struct counter_component - Counter component identification
  27. * @type: component type (one of enum counter_component_type)
  28. * @scope: component scope (one of enum counter_scope)
  29. * @parent: parent ID (matching the ID suffix of the respective parent sysfs
  30. * path as described by the ABI documentation file
  31. * Documentation/ABI/testing/sysfs-bus-counter)
  32. * @id: component ID (matching the ID provided by the respective *_component_id
  33. * sysfs attribute of the desired component)
  34. *
  35. * For example, if the Count 2 ceiling extension of Counter device 4 is desired,
  36. * set type equal to COUNTER_COMPONENT_EXTENSION, scope equal to
  37. * COUNTER_SCOPE_COUNT, parent equal to 2, and id equal to the value provided by
  38. * the respective /sys/bus/counter/devices/counter4/count2/ceiling_component_id
  39. * sysfs attribute.
  40. */
  41. struct counter_component {
  42. __u8 type;
  43. __u8 scope;
  44. __u8 parent;
  45. __u8 id;
  46. };
  47. /* Event type definitions */
  48. enum counter_event_type {
  49. /* Count value increased past ceiling */
  50. COUNTER_EVENT_OVERFLOW,
  51. /* Count value decreased past floor */
  52. COUNTER_EVENT_UNDERFLOW,
  53. /* Count value increased past ceiling, or decreased past floor */
  54. COUNTER_EVENT_OVERFLOW_UNDERFLOW,
  55. /* Count value reached threshold */
  56. COUNTER_EVENT_THRESHOLD,
  57. /* Index signal detected */
  58. COUNTER_EVENT_INDEX,
  59. /* State of counter is changed */
  60. COUNTER_EVENT_CHANGE_OF_STATE,
  61. /* Count value captured */
  62. COUNTER_EVENT_CAPTURE,
  63. };
  64. /**
  65. * struct counter_watch - Counter component watch configuration
  66. * @component: component to watch when event triggers
  67. * @event: event that triggers (one of enum counter_event_type)
  68. * @channel: event channel (typically 0 unless the device supports concurrent
  69. * events of the same type)
  70. */
  71. struct counter_watch {
  72. struct counter_component component;
  73. __u8 event;
  74. __u8 channel;
  75. };
  76. /*
  77. * Queues a Counter watch for the specified event.
  78. *
  79. * The queued watches will not be applied until COUNTER_ENABLE_EVENTS_IOCTL is
  80. * called.
  81. */
  82. #define COUNTER_ADD_WATCH_IOCTL _IOW(0x3E, 0x00, struct counter_watch)
  83. /*
  84. * Enables monitoring the events specified by the Counter watches that were
  85. * queued by COUNTER_ADD_WATCH_IOCTL.
  86. *
  87. * If events are already enabled, the new set of watches replaces the old one.
  88. * Calling this ioctl also has the effect of clearing the queue of watches added
  89. * by COUNTER_ADD_WATCH_IOCTL.
  90. */
  91. #define COUNTER_ENABLE_EVENTS_IOCTL _IO(0x3E, 0x01)
  92. /*
  93. * Stops monitoring the previously enabled events.
  94. */
  95. #define COUNTER_DISABLE_EVENTS_IOCTL _IO(0x3E, 0x02)
  96. /**
  97. * struct counter_event - Counter event data
  98. * @timestamp: best estimate of time of event occurrence, in nanoseconds
  99. * @value: component value
  100. * @watch: component watch configuration
  101. * @status: return status (system error number)
  102. */
  103. struct counter_event {
  104. __aligned_u64 timestamp;
  105. __aligned_u64 value;
  106. struct counter_watch watch;
  107. __u8 status;
  108. };
  109. /* Count direction values */
  110. enum counter_count_direction {
  111. COUNTER_COUNT_DIRECTION_FORWARD,
  112. COUNTER_COUNT_DIRECTION_BACKWARD,
  113. };
  114. /* Count mode values */
  115. enum counter_count_mode {
  116. COUNTER_COUNT_MODE_NORMAL,
  117. COUNTER_COUNT_MODE_RANGE_LIMIT,
  118. COUNTER_COUNT_MODE_NON_RECYCLE,
  119. COUNTER_COUNT_MODE_MODULO_N,
  120. COUNTER_COUNT_MODE_INTERRUPT_ON_TERMINAL_COUNT,
  121. COUNTER_COUNT_MODE_HARDWARE_RETRIGGERABLE_ONESHOT,
  122. COUNTER_COUNT_MODE_RATE_GENERATOR,
  123. COUNTER_COUNT_MODE_SQUARE_WAVE_MODE,
  124. COUNTER_COUNT_MODE_SOFTWARE_TRIGGERED_STROBE,
  125. COUNTER_COUNT_MODE_HARDWARE_TRIGGERED_STROBE,
  126. };
  127. /* Count function values */
  128. enum counter_function {
  129. COUNTER_FUNCTION_INCREASE,
  130. COUNTER_FUNCTION_DECREASE,
  131. COUNTER_FUNCTION_PULSE_DIRECTION,
  132. COUNTER_FUNCTION_QUADRATURE_X1_A,
  133. COUNTER_FUNCTION_QUADRATURE_X1_B,
  134. COUNTER_FUNCTION_QUADRATURE_X2_A,
  135. COUNTER_FUNCTION_QUADRATURE_X2_B,
  136. COUNTER_FUNCTION_QUADRATURE_X4,
  137. };
  138. /* Signal values */
  139. enum counter_signal_level {
  140. COUNTER_SIGNAL_LEVEL_LOW,
  141. COUNTER_SIGNAL_LEVEL_HIGH,
  142. };
  143. /* Action mode values */
  144. enum counter_synapse_action {
  145. COUNTER_SYNAPSE_ACTION_NONE,
  146. COUNTER_SYNAPSE_ACTION_RISING_EDGE,
  147. COUNTER_SYNAPSE_ACTION_FALLING_EDGE,
  148. COUNTER_SYNAPSE_ACTION_BOTH_EDGES,
  149. };
  150. /* Signal polarity values */
  151. enum counter_signal_polarity {
  152. COUNTER_SIGNAL_POLARITY_POSITIVE,
  153. COUNTER_SIGNAL_POLARITY_NEGATIVE,
  154. };
  155. #endif /* _COUNTER_H_ */