diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
index 46e83c2..f0c7426 100644
--- a/include/linux/ftrace_event.h
+++ b/include/linux/ftrace_event.h
@@ -14,6 +14,7 @@ struct trace_buffer;
 struct tracer;
 struct dentry;
 struct bpf_prog;
+struct trace_buffer_stm;

 struct trace_print_flags {
        unsigned long           mask;
@@ -304,6 +305,9 @@ struct ftrace_event_call {
         */
        int                     flags; /* static flags of different events */

+       void (*output_stm)(struct trace_seq *tmp_seq, void *entry,
+                          struct trace_buffer_stm *tb);
+
 #ifdef CONFIG_PERF_EVENTS
        int                             perf_refcount;
        struct hlist_head __percpu      *perf_events;
@@ -423,6 +427,17 @@ enum event_trigger_type {
        ETT_EVENT_ENABLE        = (1 << 3),
 };

+#ifdef CONFIG_STM_TRACE_EVENT
+extern void trace_event_stm_log(struct ftrace_event_buffer *fbuffer);
+extern void trace_event_buf_vprintf(struct trace_buffer_stm *tb,
+                           const char *fmt, ...) __attribute__ ((weak));
+extern void stm_trace_event_write(const char *buf, unsigned len);
+#else
+static inline void trace_event_stm_log(struct ftrace_event_buffer *fbuffer) {}
+static inline void trace_event_buf_vprintf(struct trace_buffer_stm *tb,
+                           const char *fmt, ...) {}
+#endif
+
 extern int filter_match_preds(struct event_filter *filter, void *rec);

 extern int filter_check_discard(struct ftrace_event_file *file, void *rec,
diff --git a/include/trace/ftrace.h b/include/trace/ftrace.h
index 37d4b10..cc1b426 100644
--- a/include/trace/ftrace.h
+++ b/include/trace/ftrace.h
@@ -302,6 +302,50 @@ TRACE_MAKE_SYSTEM_STR();
        })

 #undef DECLARE_EVENT_CLASS
+#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print)  \
+static notrace void                                     \
+trace_event_stm_output_##call(struct trace_seq *tmp_seq,               \
+                        void *entry,                   \
+                        struct trace_buffer_stm *trace_buf)            \
+{                                                                      \
+       struct ftrace_raw_##call *field = entry;                        \
+       struct trace_seq *p = tmp_seq;                                  \
+                                                                       \
+       trace_seq_init(p);                                              \
+                                                                       \
+       trace_event_buf_vprintf(trace_buf, print);                      \
+                                                                       \
+       return;                                                         \
+}
+
+#undef DEFINE_EVENT_PRINT
+#define DEFINE_EVENT_PRINT(template, call, proto, args, print)         \
+static notrace void                                                    \
+trace_event_stm_output_##call(struct trace_seq *tmp_seq,               \
+                        void *entry,                                   \
+                        struct trace_buffer_stm *trace_buf)            \
+{                                                                      \
+       struct trace_seq *p = tmp_seq;                                  \
+       struct trace_entry *ent = entry;                                \
+       struct ftrace_raw_##template *field;                            \
+                                                                       \
+       if (ent->type != event_##call.event.type) {                     \
+               WARN_ON_ONCE(1);                                        \
+               return;                                                 \
+       }                                                               \
+                                                                       \
+       field = (typeof(field))entry;                                   \
+                                                                       \
+       trace_seq_init(p);                                              \
+                                                                       \
+       trace_event_buf_vprintf(trace_buf, print);                      \
+                                                                       \
+       return;                                                         \
+}
+
+#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
+
+#undef DECLARE_EVENT_CLASS
 #define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
 static notrace enum print_line_t                                       \
 ftrace_raw_output_##call(struct trace_iterator *iter, int flags,       \
@@ -683,6 +727,7 @@ ftrace_raw_event_##call(void *__data, proto)
                         \
        { assign; }                                                     \
                                                                        \
        ftrace_event_buffer_commit(&fbuffer);                           \
+       trace_event_stm_log(&fbuffer);          \
 }
 /*
