blob: 64e77b513697488272a785b382161c8af42420a7 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Pekka Paalanenf984b512008-05-12 21:20:57 +02002/*
3 * Memory mapped I/O tracing
4 *
5 * Copyright (C) 2008 Pekka Paalanen <pq@iki.fi>
6 */
7
Pekka Paalanenf984b512008-05-12 21:20:57 +02008#include <linux/kernel.h>
9#include <linux/mmiotrace.h>
Pekka Paalanen13829532008-05-12 21:20:58 +020010#include <linux/pci.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Li Zefana5dec552009-03-27 14:55:44 +080012#include <linux/time.h>
13
Arun Sharma600634972011-07-26 16:09:06 -070014#include <linux/atomic.h>
Pekka Paalanenf984b512008-05-12 21:20:57 +020015
16#include "trace.h"
Steven Rostedtf0868d12008-12-23 23:24:12 -050017#include "trace_output.h"
Pekka Paalanenf984b512008-05-12 21:20:57 +020018
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +020019struct header_iter {
20 struct pci_dev *dev;
21};
22
Pekka Paalanenf984b512008-05-12 21:20:57 +020023static struct trace_array *mmio_trace_array;
Pekka Paalanen20392382008-05-12 21:21:02 +020024static bool overrun_detected;
Pekka Paalanen7ee17682008-11-23 21:24:30 +020025static unsigned long prev_overruns;
Pekka Paalanen173ed242009-01-06 13:57:11 +020026static atomic_t dropped_count;
Pekka Paalanenf984b512008-05-12 21:20:57 +020027
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020028static void mmio_reset_data(struct trace_array *tr)
29{
Pekka Paalanen20392382008-05-12 21:21:02 +020030 overrun_detected = false;
Pekka Paalanen7ee17682008-11-23 21:24:30 +020031 prev_overruns = 0;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020032
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -050033 tracing_reset_online_cpus(&tr->array_buffer);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020034}
Pekka Paalanenf984b512008-05-12 21:20:57 +020035
Frederic Weisbecker1c800252008-11-16 05:57:26 +010036static int mmio_trace_init(struct trace_array *tr)
Pekka Paalanenf984b512008-05-12 21:20:57 +020037{
38 pr_debug("in %s\n", __func__);
39 mmio_trace_array = tr;
Steven Rostedtc76f0692008-11-07 22:36:02 -050040
41 mmio_reset_data(tr);
42 enable_mmiotrace();
Frederic Weisbecker1c800252008-11-16 05:57:26 +010043 return 0;
Pekka Paalanenf984b512008-05-12 21:20:57 +020044}
45
46static void mmio_trace_reset(struct trace_array *tr)
47{
48 pr_debug("in %s\n", __func__);
Steven Rostedtc76f0692008-11-07 22:36:02 -050049
50 disable_mmiotrace();
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020051 mmio_reset_data(tr);
52 mmio_trace_array = NULL;
Pekka Paalanenf984b512008-05-12 21:20:57 +020053}
54
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -050055static void mmio_trace_start(struct trace_array *tr)
Pekka Paalanenf984b512008-05-12 21:20:57 +020056{
57 pr_debug("in %s\n", __func__);
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -050058 mmio_reset_data(tr);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020059}
60
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -050061static void mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev)
Pekka Paalanen13829532008-05-12 21:20:58 +020062{
Pekka Paalanen13829532008-05-12 21:20:58 +020063 int i;
64 resource_size_t start, end;
65 const struct pci_driver *drv = pci_dev_driver(dev);
66
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -050067 trace_seq_printf(s, "PCIDEV %02x%02x %04x%04x %x",
68 dev->bus->number, dev->devfn,
69 dev->vendor, dev->device, dev->irq);
Pekka Paalanen13829532008-05-12 21:20:58 +020070 for (i = 0; i < 7; i++) {
Bjorn Helgaas9a519332016-05-11 14:06:57 -050071 start = dev->resource[i].start;
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -050072 trace_seq_printf(s, " %llx",
Pekka Paalanen13829532008-05-12 21:20:58 +020073 (unsigned long long)(start |
74 (dev->resource[i].flags & PCI_REGION_FLAG_MASK)));
75 }
76 for (i = 0; i < 7; i++) {
Bjorn Helgaas9a519332016-05-11 14:06:57 -050077 start = dev->resource[i].start;
78 end = dev->resource[i].end;
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -050079 trace_seq_printf(s, " %llx",
Pekka Paalanen13829532008-05-12 21:20:58 +020080 dev->resource[i].start < dev->resource[i].end ?
81 (unsigned long long)(end - start) + 1 : 0);
82 }
83 if (drv)
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -050084 trace_seq_printf(s, " %s\n", drv->name);
Pekka Paalanen13829532008-05-12 21:20:58 +020085 else
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -050086 trace_seq_puts(s, " \n");
Pekka Paalanen13829532008-05-12 21:20:58 +020087}
88
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +020089static void destroy_header_iter(struct header_iter *hiter)
Pekka Paalanenbd8ac682008-05-12 21:20:57 +020090{
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +020091 if (!hiter)
92 return;
93 pci_dev_put(hiter->dev);
94 kfree(hiter);
95}
96
97static void mmio_pipe_open(struct trace_iterator *iter)
98{
99 struct header_iter *hiter;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200100 struct trace_seq *s = &iter->seq;
Pekka Paalanen13829532008-05-12 21:20:58 +0200101
zhangwei(Jovi)146c3442013-07-15 16:32:44 +0800102 trace_seq_puts(s, "VERSION 20070824\n");
Pekka Paalanen13829532008-05-12 21:20:58 +0200103
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +0200104 hiter = kzalloc(sizeof(*hiter), GFP_KERNEL);
105 if (!hiter)
106 return;
107
108 hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
109 iter->private = hiter;
110}
111
112/* XXX: This is not called when the pipe is closed! */
113static void mmio_close(struct trace_iterator *iter)
114{
115 struct header_iter *hiter = iter->private;
116 destroy_header_iter(hiter);
117 iter->private = NULL;
118}
119
Pekka Paalanen20392382008-05-12 21:21:02 +0200120static unsigned long count_overruns(struct trace_iterator *iter)
121{
Pekka Paalanen173ed242009-01-06 13:57:11 +0200122 unsigned long cnt = atomic_xchg(&dropped_count, 0);
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500123 unsigned long over = ring_buffer_overruns(iter->array_buffer->buffer);
Pekka Paalanen7ee17682008-11-23 21:24:30 +0200124
125 if (over > prev_overruns)
Pekka Paalanen173ed242009-01-06 13:57:11 +0200126 cnt += over - prev_overruns;
Pekka Paalanen7ee17682008-11-23 21:24:30 +0200127 prev_overruns = over;
Pekka Paalanen20392382008-05-12 21:21:02 +0200128 return cnt;
129}
130
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +0200131static ssize_t mmio_read(struct trace_iterator *iter, struct file *filp,
132 char __user *ubuf, size_t cnt, loff_t *ppos)
133{
134 ssize_t ret;
135 struct header_iter *hiter = iter->private;
136 struct trace_seq *s = &iter->seq;
Pekka Paalanen20392382008-05-12 21:21:02 +0200137 unsigned long n;
138
139 n = count_overruns(iter);
140 if (n) {
141 /* XXX: This is later than where events were lost. */
142 trace_seq_printf(s, "MARK 0.000000 Lost %lu events.\n", n);
143 if (!overrun_detected)
Joe Perchesa395d6a2016-03-22 14:28:09 -0700144 pr_warn("mmiotrace has lost events\n");
Pekka Paalanen20392382008-05-12 21:21:02 +0200145 overrun_detected = true;
146 goto print_out;
147 }
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +0200148
149 if (!hiter)
150 return 0;
151
152 mmio_print_pcidev(s, hiter->dev);
153 hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev);
154
155 if (!hiter->dev) {
156 destroy_header_iter(hiter);
157 iter->private = NULL;
158 }
159
Pekka Paalanen20392382008-05-12 21:21:02 +0200160print_out:
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +0200161 ret = trace_seq_to_user(s, ubuf, cnt);
162 return (ret == -EBUSY) ? 0 : ret;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200163}
164
Frederic Weisbecker07f4e4f2008-09-29 20:27:42 +0200165static enum print_line_t mmio_print_rw(struct trace_iterator *iter)
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200166{
167 struct trace_entry *entry = iter->ent;
Steven Rostedt7104f302008-10-01 10:52:51 -0400168 struct trace_mmiotrace_rw *field;
169 struct mmiotrace_rw *rw;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200170 struct trace_seq *s = &iter->seq;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400171 unsigned long long t = ns2usecs(iter->ts);
Li Zefana5dec552009-03-27 14:55:44 +0800172 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200173 unsigned secs = (unsigned long)t;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200174
Steven Rostedt7104f302008-10-01 10:52:51 -0400175 trace_assign_type(field, entry);
176 rw = &field->rw;
177
Steven Rostedt777e2082008-09-29 23:02:42 -0400178 switch (rw->opcode) {
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200179 case MMIO_READ:
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500180 trace_seq_printf(s,
Steven Rostedt5e4abc92009-01-15 21:00:50 -0500181 "R %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
Pekka Paalanendee310d2008-05-12 21:21:03 +0200182 rw->width, secs, usec_rem, rw->map_id,
183 (unsigned long long)rw->phys,
Pekka Paalanen736ca612008-05-12 21:20:59 +0200184 rw->value, rw->pc, 0);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200185 break;
186 case MMIO_WRITE:
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500187 trace_seq_printf(s,
Steven Rostedt5e4abc92009-01-15 21:00:50 -0500188 "W %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
Pekka Paalanendee310d2008-05-12 21:21:03 +0200189 rw->width, secs, usec_rem, rw->map_id,
190 (unsigned long long)rw->phys,
Pekka Paalanen736ca612008-05-12 21:20:59 +0200191 rw->value, rw->pc, 0);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200192 break;
193 case MMIO_UNKNOWN_OP:
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500194 trace_seq_printf(s,
Steven Rostedt5e4abc92009-01-15 21:00:50 -0500195 "UNKNOWN %u.%06lu %d 0x%llx %02lx,%02lx,"
196 "%02lx 0x%lx %d\n",
Pekka Paalanendee310d2008-05-12 21:21:03 +0200197 secs, usec_rem, rw->map_id,
198 (unsigned long long)rw->phys,
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200199 (rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
Pekka Paalanen736ca612008-05-12 21:20:59 +0200200 (rw->value >> 0) & 0xff, rw->pc, 0);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200201 break;
202 default:
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500203 trace_seq_puts(s, "rw what?\n");
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200204 break;
205 }
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500206
207 return trace_handle_return(s);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200208}
209
Frederic Weisbecker07f4e4f2008-09-29 20:27:42 +0200210static enum print_line_t mmio_print_map(struct trace_iterator *iter)
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200211{
212 struct trace_entry *entry = iter->ent;
Steven Rostedt7104f302008-10-01 10:52:51 -0400213 struct trace_mmiotrace_map *field;
214 struct mmiotrace_map *m;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200215 struct trace_seq *s = &iter->seq;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400216 unsigned long long t = ns2usecs(iter->ts);
Li Zefana5dec552009-03-27 14:55:44 +0800217 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200218 unsigned secs = (unsigned long)t;
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200219
Steven Rostedt7104f302008-10-01 10:52:51 -0400220 trace_assign_type(field, entry);
221 m = &field->map;
222
Steven Rostedt777e2082008-09-29 23:02:42 -0400223 switch (m->opcode) {
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200224 case MMIO_PROBE:
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500225 trace_seq_printf(s,
Steven Rostedt5e4abc92009-01-15 21:00:50 -0500226 "MAP %u.%06lu %d 0x%llx 0x%lx 0x%lx 0x%lx %d\n",
Pekka Paalanendee310d2008-05-12 21:21:03 +0200227 secs, usec_rem, m->map_id,
228 (unsigned long long)m->phys, m->virt, m->len,
Pekka Paalanene0fd5c22008-05-12 21:21:02 +0200229 0UL, 0);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200230 break;
231 case MMIO_UNPROBE:
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500232 trace_seq_printf(s,
Steven Rostedt5e4abc92009-01-15 21:00:50 -0500233 "UNMAP %u.%06lu %d 0x%lx %d\n",
Pekka Paalanene0fd5c22008-05-12 21:21:02 +0200234 secs, usec_rem, m->map_id, 0UL, 0);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200235 break;
236 default:
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500237 trace_seq_puts(s, "map what?\n");
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200238 break;
239 }
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500240
241 return trace_handle_return(s);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200242}
243
Frederic Weisbecker07f4e4f2008-09-29 20:27:42 +0200244static enum print_line_t mmio_print_mark(struct trace_iterator *iter)
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300245{
246 struct trace_entry *entry = iter->ent;
Steven Rostedt777e2082008-09-29 23:02:42 -0400247 struct print_entry *print = (struct print_entry *)entry;
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100248 const char *msg = print->buf;
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300249 struct trace_seq *s = &iter->seq;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400250 unsigned long long t = ns2usecs(iter->ts);
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100251 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300252 unsigned secs = (unsigned long)t;
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300253
254 /* The trailing newline must be in the message. */
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500255 trace_seq_printf(s, "MARK %u.%06lu %s", secs, usec_rem, msg);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300256
Steven Rostedt (Red Hat)a72e10a2014-11-12 16:26:06 -0500257 return trace_handle_return(s);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300258}
259
Frederic Weisbecker07f4e4f2008-09-29 20:27:42 +0200260static enum print_line_t mmio_print_line(struct trace_iterator *iter)
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200261{
262 switch (iter->ent->type) {
263 case TRACE_MMIO_RW:
264 return mmio_print_rw(iter);
265 case TRACE_MMIO_MAP:
266 return mmio_print_map(iter);
Pekka Paalanenfc5e27a2008-09-16 22:02:27 +0300267 case TRACE_PRINT:
268 return mmio_print_mark(iter);
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200269 default:
Frederic Weisbecker07f4e4f2008-09-29 20:27:42 +0200270 return TRACE_TYPE_HANDLED; /* ignore unknown entries */
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200271 }
Pekka Paalanenf984b512008-05-12 21:20:57 +0200272}
273
274static struct tracer mmio_tracer __read_mostly =
275{
276 .name = "mmiotrace",
277 .init = mmio_trace_init,
278 .reset = mmio_trace_reset,
Steven Rostedtbbf5b1a2008-11-07 22:36:02 -0500279 .start = mmio_trace_start,
Pekka Paalanend0a7e8ca2008-05-12 21:21:02 +0200280 .pipe_open = mmio_pipe_open,
281 .close = mmio_close,
282 .read = mmio_read,
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200283 .print_line = mmio_print_line,
Ziqian SUN (Zamir)c7b3ae02017-09-11 14:26:35 +0800284 .noboot = true,
Pekka Paalanenf984b512008-05-12 21:20:57 +0200285};
286
287__init static int init_mmio_trace(void)
288{
Pekka Paalanenf984b512008-05-12 21:20:57 +0200289 return register_tracer(&mmio_tracer);
290}
291device_initcall(init_mmio_trace);
292
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300293static void __trace_mmiotrace_rw(struct trace_array *tr,
294 struct trace_array_cpu *data,
295 struct mmiotrace_rw *rw)
296{
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400297 struct trace_event_call *call = &event_mmiotrace_rw;
Steven Rostedt (VMware)13292492019-12-13 13:58:57 -0500298 struct trace_buffer *buffer = tr->array_buffer.buffer;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400299 struct ring_buffer_event *event;
Steven Rostedt777e2082008-09-29 23:02:42 -0400300 struct trace_mmiotrace_rw *entry;
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100301 unsigned int trace_ctx;
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300302
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100303 trace_ctx = tracing_gen_ctx_flags(0);
Steven Rostedte77405a2009-09-02 14:17:06 -0400304 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100305 sizeof(*entry), trace_ctx);
Pekka Paalanen173ed242009-01-06 13:57:11 +0200306 if (!event) {
307 atomic_inc(&dropped_count);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400308 return;
Pekka Paalanen173ed242009-01-06 13:57:11 +0200309 }
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400310 entry = ring_buffer_event_data(event);
Steven Rostedt777e2082008-09-29 23:02:42 -0400311 entry->rw = *rw;
Steven Rostedt60ba7702009-09-12 23:34:04 -0400312
Tom Zanussif306cc82013-10-24 08:34:17 -0500313 if (!call_filter_check_discard(call, entry, buffer, event))
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100314 trace_buffer_unlock_commit(tr, buffer, event, trace_ctx);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300315}
316
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200317void mmio_trace_rw(struct mmiotrace_rw *rw)
Pekka Paalanenf984b512008-05-12 21:20:57 +0200318{
319 struct trace_array *tr = mmio_trace_array;
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500320 struct trace_array_cpu *data = per_cpu_ptr(tr->array_buffer.data, smp_processor_id());
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200321 __trace_mmiotrace_rw(tr, data, rw);
322}
Pekka Paalanenf984b512008-05-12 21:20:57 +0200323
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300324static void __trace_mmiotrace_map(struct trace_array *tr,
325 struct trace_array_cpu *data,
326 struct mmiotrace_map *map)
327{
Steven Rostedt (Red Hat)2425bcb2015-05-05 11:45:27 -0400328 struct trace_event_call *call = &event_mmiotrace_map;
Steven Rostedt (VMware)13292492019-12-13 13:58:57 -0500329 struct trace_buffer *buffer = tr->array_buffer.buffer;
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400330 struct ring_buffer_event *event;
Steven Rostedt777e2082008-09-29 23:02:42 -0400331 struct trace_mmiotrace_map *entry;
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100332 unsigned int trace_ctx;
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300333
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100334 trace_ctx = tracing_gen_ctx_flags(0);
Steven Rostedte77405a2009-09-02 14:17:06 -0400335 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100336 sizeof(*entry), trace_ctx);
Pekka Paalanen173ed242009-01-06 13:57:11 +0200337 if (!event) {
338 atomic_inc(&dropped_count);
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400339 return;
Pekka Paalanen173ed242009-01-06 13:57:11 +0200340 }
Steven Rostedt3928a8a2008-09-29 23:02:41 -0400341 entry = ring_buffer_event_data(event);
Steven Rostedt777e2082008-09-29 23:02:42 -0400342 entry->map = *map;
Steven Rostedt60ba7702009-09-12 23:34:04 -0400343
Tom Zanussif306cc82013-10-24 08:34:17 -0500344 if (!call_filter_check_discard(call, entry, buffer, event))
Sebastian Andrzej Siewior36590c502021-01-25 20:45:08 +0100345 trace_buffer_unlock_commit(tr, buffer, event, trace_ctx);
Pekka Paalanen45dcd8b2008-09-16 21:56:41 +0300346}
347
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200348void mmio_trace_mapping(struct mmiotrace_map *map)
349{
350 struct trace_array *tr = mmio_trace_array;
351 struct trace_array_cpu *data;
352
353 preempt_disable();
Steven Rostedt (VMware)1c5eb442020-01-09 18:53:48 -0500354 data = per_cpu_ptr(tr->array_buffer.data, smp_processor_id());
Pekka Paalanenbd8ac682008-05-12 21:20:57 +0200355 __trace_mmiotrace_map(tr, data, map);
356 preempt_enable();
Pekka Paalanenf984b512008-05-12 21:20:57 +0200357}
Pekka Paalanen9e57fb32008-09-16 22:00:34 +0300358
359int mmio_trace_printk(const char *fmt, va_list args)
360{
Steven Rostedt40ce74f2009-03-19 14:03:53 -0400361 return trace_vprintk(0, fmt, args);
Pekka Paalanen9e57fb32008-09-16 22:00:34 +0300362}