1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 * Userspace ABI for Counter character devices
4 * Copyright (C) 2020 William Breathitt Gray
6 #ifndef _UAPI_COUNTER_H_
7 #define _UAPI_COUNTER_H_
9 #include <linux/ioctl.h>
10 #include <linux/types.h>
12 /* Component type definitions */
13 enum counter_component_type {
14 COUNTER_COMPONENT_NONE,
15 COUNTER_COMPONENT_SIGNAL,
16 COUNTER_COMPONENT_COUNT,
17 COUNTER_COMPONENT_FUNCTION,
18 COUNTER_COMPONENT_SYNAPSE_ACTION,
19 COUNTER_COMPONENT_EXTENSION,
22 /* Component scope definitions */
30 * struct counter_component - Counter component identification
31 * @type: component type (one of enum counter_component_type)
32 * @scope: component scope (one of enum counter_scope)
33 * @parent: parent ID (matching the ID suffix of the respective parent sysfs
34 * path as described by the ABI documentation file
35 * Documentation/ABI/testing/sysfs-bus-counter)
36 * @id: component ID (matching the ID provided by the respective *_component_id
37 * sysfs attribute of the desired component)
39 * For example, if the Count 2 ceiling extension of Counter device 4 is desired,
40 * set type equal to COUNTER_COMPONENT_EXTENSION, scope equal to
41 * COUNTER_COUNT_SCOPE, parent equal to 2, and id equal to the value provided by
42 * the respective /sys/bus/counter/devices/counter4/count2/ceiling_component_id
45 struct counter_component {
52 /* Event type definitions */
53 enum counter_event_type {
54 /* Count value increased past ceiling */
55 COUNTER_EVENT_OVERFLOW,
56 /* Count value decreased past floor */
57 COUNTER_EVENT_UNDERFLOW,
58 /* Count value increased past ceiling, or decreased past floor */
59 COUNTER_EVENT_OVERFLOW_UNDERFLOW,
60 /* Count value reached threshold */
61 COUNTER_EVENT_THRESHOLD,
62 /* Index signal detected */
64 /* State of counter is changed */
65 COUNTER_EVENT_CHANGE_OF_STATE,
69 * struct counter_watch - Counter component watch configuration
70 * @component: component to watch when event triggers
71 * @event: event that triggers (one of enum counter_event_type)
72 * @channel: event channel (typically 0 unless the device supports concurrent
73 * events of the same type)
75 struct counter_watch {
76 struct counter_component component;
82 * Queues a Counter watch for the specified event.
84 * The queued watches will not be applied until COUNTER_ENABLE_EVENTS_IOCTL is
87 #define COUNTER_ADD_WATCH_IOCTL _IOW(0x3E, 0x00, struct counter_watch)
89 * Enables monitoring the events specified by the Counter watches that were
90 * queued by COUNTER_ADD_WATCH_IOCTL.
92 * If events are already enabled, the new set of watches replaces the old one.
93 * Calling this ioctl also has the effect of clearing the queue of watches added
94 * by COUNTER_ADD_WATCH_IOCTL.
96 #define COUNTER_ENABLE_EVENTS_IOCTL _IO(0x3E, 0x01)
98 * Stops monitoring the previously enabled events.
100 #define COUNTER_DISABLE_EVENTS_IOCTL _IO(0x3E, 0x02)
103 * struct counter_event - Counter event data
104 * @timestamp: best estimate of time of event occurrence, in nanoseconds
105 * @value: component value
106 * @watch: component watch configuration
107 * @status: return status (system error number)
109 struct counter_event {
110 __aligned_u64 timestamp;
112 struct counter_watch watch;
116 /* Count direction values */
117 enum counter_count_direction {
118 COUNTER_COUNT_DIRECTION_FORWARD,
119 COUNTER_COUNT_DIRECTION_BACKWARD,
122 /* Count mode values */
123 enum counter_count_mode {
124 COUNTER_COUNT_MODE_NORMAL,
125 COUNTER_COUNT_MODE_RANGE_LIMIT,
126 COUNTER_COUNT_MODE_NON_RECYCLE,
127 COUNTER_COUNT_MODE_MODULO_N,
130 /* Count function values */
131 enum counter_function {
132 COUNTER_FUNCTION_INCREASE,
133 COUNTER_FUNCTION_DECREASE,
134 COUNTER_FUNCTION_PULSE_DIRECTION,
135 COUNTER_FUNCTION_QUADRATURE_X1_A,
136 COUNTER_FUNCTION_QUADRATURE_X1_B,
137 COUNTER_FUNCTION_QUADRATURE_X2_A,
138 COUNTER_FUNCTION_QUADRATURE_X2_B,
139 COUNTER_FUNCTION_QUADRATURE_X4,
143 enum counter_signal_level {
144 COUNTER_SIGNAL_LEVEL_LOW,
145 COUNTER_SIGNAL_LEVEL_HIGH,
148 /* Action mode values */
149 enum counter_synapse_action {
150 COUNTER_SYNAPSE_ACTION_NONE,
151 COUNTER_SYNAPSE_ACTION_RISING_EDGE,
152 COUNTER_SYNAPSE_ACTION_FALLING_EDGE,
153 COUNTER_SYNAPSE_ACTION_BOTH_EDGES,
156 #endif /* _UAPI_COUNTER_H_ */