genirq/debugfs: No need to check return value of debugfs_create functions
[linux/fpc-iii.git] / kernel / trace / trace_dynevent.h
blob8c334064e4d684d3cd3012bf316811f5f5b71945
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Common header file for generic dynamic events.
4 */
6 #ifndef _TRACE_DYNEVENT_H
7 #define _TRACE_DYNEVENT_H
9 #include <linux/kernel.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12 #include <linux/seq_file.h>
14 #include "trace.h"
16 struct dyn_event;
18 /**
19 * struct dyn_event_operations - Methods for each type of dynamic events
21 * These methods must be set for each type, since there is no default method.
22 * Before using this for dyn_event_init(), it must be registered by
23 * dyn_event_register().
25 * @create: Parse and create event method. This is invoked when user passes
26 * a event definition to dynamic_events interface. This must not destruct
27 * the arguments and return -ECANCELED if given arguments doesn't match its
28 * command prefix.
29 * @show: Showing method. This is invoked when user reads the event definitions
30 * via dynamic_events interface.
31 * @is_busy: Check whether given event is busy so that it can not be deleted.
32 * Return true if it is busy, otherwides false.
33 * @free: Delete the given event. Return 0 if success, otherwides error.
34 * @match: Check whether given event and system name match this event.
35 * Return true if it matches, otherwides false.
37 * Except for @create, these methods are called under holding event_mutex.
39 struct dyn_event_operations {
40 struct list_head list;
41 int (*create)(int argc, const char *argv[]);
42 int (*show)(struct seq_file *m, struct dyn_event *ev);
43 bool (*is_busy)(struct dyn_event *ev);
44 int (*free)(struct dyn_event *ev);
45 bool (*match)(const char *system, const char *event,
46 struct dyn_event *ev);
49 /* Register new dyn_event type -- must be called at first */
50 int dyn_event_register(struct dyn_event_operations *ops);
52 /**
53 * struct dyn_event - Dynamic event list header
55 * The dyn_event structure encapsulates a list and a pointer to the operators
56 * for making a global list of dynamic events.
57 * User must includes this in each event structure, so that those events can
58 * be added/removed via dynamic_events interface.
60 struct dyn_event {
61 struct list_head list;
62 struct dyn_event_operations *ops;
65 extern struct list_head dyn_event_list;
67 static inline
68 int dyn_event_init(struct dyn_event *ev, struct dyn_event_operations *ops)
70 if (!ev || !ops)
71 return -EINVAL;
73 INIT_LIST_HEAD(&ev->list);
74 ev->ops = ops;
75 return 0;
78 static inline int dyn_event_add(struct dyn_event *ev)
80 lockdep_assert_held(&event_mutex);
82 if (!ev || !ev->ops)
83 return -EINVAL;
85 list_add_tail(&ev->list, &dyn_event_list);
86 return 0;
89 static inline void dyn_event_remove(struct dyn_event *ev)
91 lockdep_assert_held(&event_mutex);
92 list_del_init(&ev->list);
95 void *dyn_event_seq_start(struct seq_file *m, loff_t *pos);
96 void *dyn_event_seq_next(struct seq_file *m, void *v, loff_t *pos);
97 void dyn_event_seq_stop(struct seq_file *m, void *v);
98 int dyn_events_release_all(struct dyn_event_operations *type);
99 int dyn_event_release(int argc, char **argv, struct dyn_event_operations *type);
102 * for_each_dyn_event - iterate over the dyn_event list
103 * @pos: the struct dyn_event * to use as a loop cursor
105 * This is just a basement of for_each macro. Wrap this for
106 * each actual event structure with ops filtering.
108 #define for_each_dyn_event(pos) \
109 list_for_each_entry(pos, &dyn_event_list, list)
112 * for_each_dyn_event - iterate over the dyn_event list safely
113 * @pos: the struct dyn_event * to use as a loop cursor
114 * @n: the struct dyn_event * to use as temporary storage
116 #define for_each_dyn_event_safe(pos, n) \
117 list_for_each_entry_safe(pos, n, &dyn_event_list, list)
119 #endif