xref: /openbmc/linux/kernel/trace/trace_mmiotrace.c (revision 769b0441f438c4bb4872cb8560eb6fe51bcc09ee)
1f984b51eSPekka Paalanen /*
2f984b51eSPekka Paalanen  * Memory mapped I/O tracing
3f984b51eSPekka Paalanen  *
4f984b51eSPekka Paalanen  * Copyright (C) 2008 Pekka Paalanen <pq@iki.fi>
5f984b51eSPekka Paalanen  */
6f984b51eSPekka Paalanen 
7f984b51eSPekka Paalanen #define DEBUG 1
8f984b51eSPekka Paalanen 
9f984b51eSPekka Paalanen #include <linux/kernel.h>
10f984b51eSPekka Paalanen #include <linux/mmiotrace.h>
1113829537SPekka Paalanen #include <linux/pci.h>
12173ed24eSPekka Paalanen #include <asm/atomic.h>
13f984b51eSPekka Paalanen 
14f984b51eSPekka Paalanen #include "trace.h"
15f0868d1eSSteven Rostedt #include "trace_output.h"
16f984b51eSPekka Paalanen 
17d0a7e8caSPekka Paalanen struct header_iter {
18d0a7e8caSPekka Paalanen 	struct pci_dev *dev;
19d0a7e8caSPekka Paalanen };
20d0a7e8caSPekka Paalanen 
21f984b51eSPekka Paalanen static struct trace_array *mmio_trace_array;
222039238bSPekka Paalanen static bool overrun_detected;
237ee1768dSPekka Paalanen static unsigned long prev_overruns;
24173ed24eSPekka Paalanen static atomic_t dropped_count;
25f984b51eSPekka Paalanen 
26bd8ac686SPekka Paalanen static void mmio_reset_data(struct trace_array *tr)
27bd8ac686SPekka Paalanen {
282039238bSPekka Paalanen 	overrun_detected = false;
297ee1768dSPekka Paalanen 	prev_overruns = 0;
30bd8ac686SPekka Paalanen 
31213cc060SPekka J Enberg 	tracing_reset_online_cpus(tr);
32bd8ac686SPekka Paalanen }
33f984b51eSPekka Paalanen 
341c80025aSFrederic Weisbecker static int mmio_trace_init(struct trace_array *tr)
35f984b51eSPekka Paalanen {
36f984b51eSPekka Paalanen 	pr_debug("in %s\n", __func__);
37f984b51eSPekka Paalanen 	mmio_trace_array = tr;
38c76f0694SSteven Rostedt 
39bd8ac686SPekka Paalanen 	mmio_reset_data(tr);
40f984b51eSPekka Paalanen 	enable_mmiotrace();
411c80025aSFrederic Weisbecker 	return 0;
42f984b51eSPekka Paalanen }
43f984b51eSPekka Paalanen 
44f984b51eSPekka Paalanen static void mmio_trace_reset(struct trace_array *tr)
45f984b51eSPekka Paalanen {
46f984b51eSPekka Paalanen 	pr_debug("in %s\n", __func__);
47c76f0694SSteven Rostedt 
48f984b51eSPekka Paalanen 	disable_mmiotrace();
49bd8ac686SPekka Paalanen 	mmio_reset_data(tr);
50bd8ac686SPekka Paalanen 	mmio_trace_array = NULL;
51f984b51eSPekka Paalanen }
52f984b51eSPekka Paalanen 
53bbf5b1a0SSteven Rostedt static void mmio_trace_start(struct trace_array *tr)
54f984b51eSPekka Paalanen {
55f984b51eSPekka Paalanen 	pr_debug("in %s\n", __func__);
56bd8ac686SPekka Paalanen 	mmio_reset_data(tr);
57bd8ac686SPekka Paalanen }
58bd8ac686SPekka Paalanen 
5913829537SPekka Paalanen static int mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev)
6013829537SPekka Paalanen {
6113829537SPekka Paalanen 	int ret = 0;
6213829537SPekka Paalanen 	int i;
6313829537SPekka Paalanen 	resource_size_t start, end;
6413829537SPekka Paalanen 	const struct pci_driver *drv = pci_dev_driver(dev);
6513829537SPekka Paalanen 
6613829537SPekka Paalanen 	/* XXX: incomplete checks for trace_seq_printf() return value */
6713829537SPekka Paalanen 	ret += trace_seq_printf(s, "PCIDEV %02x%02x %04x%04x %x",
6813829537SPekka Paalanen 				dev->bus->number, dev->devfn,
6913829537SPekka Paalanen 				dev->vendor, dev->device, dev->irq);
7013829537SPekka Paalanen 	/*
7113829537SPekka Paalanen 	 * XXX: is pci_resource_to_user() appropriate, since we are
7213829537SPekka Paalanen 	 * supposed to interpret the __ioremap() phys_addr argument based on
7313829537SPekka Paalanen 	 * these printed values?
7413829537SPekka Paalanen 	 */
7513829537SPekka Paalanen 	for (i = 0; i < 7; i++) {
7613829537SPekka Paalanen 		pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
7713829537SPekka Paalanen 		ret += trace_seq_printf(s, " %llx",
7813829537SPekka Paalanen 			(unsigned long long)(start |
7913829537SPekka Paalanen 			(dev->resource[i].flags & PCI_REGION_FLAG_MASK)));
8013829537SPekka Paalanen 	}
8113829537SPekka Paalanen 	for (i = 0; i < 7; i++) {
8213829537SPekka Paalanen 		pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
8313829537SPekka Paalanen 		ret += trace_seq_printf(s, " %llx",
8413829537SPekka Paalanen 			dev->resource[i].start < dev->resource[i].end ?
8513829537SPekka Paalanen 			(unsigned long long)(end - start) + 1 : 0);
8613829537SPekka Paalanen 	}
8713829537SPekka Paalanen 	if (drv)
8813829537SPekka Paalanen 		ret += trace_seq_printf(s, " %s\n", drv->name);
8913829537SPekka Paalanen 	else
9013829537SPekka Paalanen 		ret += trace_seq_printf(s, " \n");
9113829537SPekka Paalanen 	return ret;
9213829537SPekka Paalanen }
9313829537SPekka Paalanen 
94d0a7e8caSPekka Paalanen static void destroy_header_iter(struct header_iter *hiter)
95bd8ac686SPekka Paalanen {
96d0a7e8caSPekka Paalanen 	if (!hiter)
97d0a7e8caSPekka Paalanen 		return;
98d0a7e8caSPekka Paalanen 	pci_dev_put(hiter->dev);
99d0a7e8caSPekka Paalanen 	kfree(hiter);
100d0a7e8caSPekka Paalanen }
101d0a7e8caSPekka Paalanen 
102d0a7e8caSPekka Paalanen static void mmio_pipe_open(struct trace_iterator *iter)
103d0a7e8caSPekka Paalanen {
104d0a7e8caSPekka Paalanen 	struct header_iter *hiter;
105bd8ac686SPekka Paalanen 	struct trace_seq *s = &iter->seq;
10613829537SPekka Paalanen 
10713829537SPekka Paalanen 	trace_seq_printf(s, "VERSION 20070824\n");
10813829537SPekka Paalanen 
109d0a7e8caSPekka Paalanen 	hiter = kzalloc(sizeof(*hiter), GFP_KERNEL);
110d0a7e8caSPekka Paalanen 	if (!hiter)
111d0a7e8caSPekka Paalanen 		return;
112d0a7e8caSPekka Paalanen 
113d0a7e8caSPekka Paalanen 	hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
114d0a7e8caSPekka Paalanen 	iter->private = hiter;
115d0a7e8caSPekka Paalanen }
116d0a7e8caSPekka Paalanen 
117d0a7e8caSPekka Paalanen /* XXX: This is not called when the pipe is closed! */
118d0a7e8caSPekka Paalanen static void mmio_close(struct trace_iterator *iter)
119d0a7e8caSPekka Paalanen {
120d0a7e8caSPekka Paalanen 	struct header_iter *hiter = iter->private;
121d0a7e8caSPekka Paalanen 	destroy_header_iter(hiter);
122d0a7e8caSPekka Paalanen 	iter->private = NULL;
123d0a7e8caSPekka Paalanen }
124d0a7e8caSPekka Paalanen 
1252039238bSPekka Paalanen static unsigned long count_overruns(struct trace_iterator *iter)
1262039238bSPekka Paalanen {
127173ed24eSPekka Paalanen 	unsigned long cnt = atomic_xchg(&dropped_count, 0);
1287ee1768dSPekka Paalanen 	unsigned long over = ring_buffer_overruns(iter->tr->buffer);
1297ee1768dSPekka Paalanen 
1307ee1768dSPekka Paalanen 	if (over > prev_overruns)
131173ed24eSPekka Paalanen 		cnt += over - prev_overruns;
1327ee1768dSPekka Paalanen 	prev_overruns = over;
1332039238bSPekka Paalanen 	return cnt;
1342039238bSPekka Paalanen }
1352039238bSPekka Paalanen 
136d0a7e8caSPekka Paalanen static ssize_t mmio_read(struct trace_iterator *iter, struct file *filp,
137d0a7e8caSPekka Paalanen 				char __user *ubuf, size_t cnt, loff_t *ppos)
138d0a7e8caSPekka Paalanen {
139d0a7e8caSPekka Paalanen 	ssize_t ret;
140d0a7e8caSPekka Paalanen 	struct header_iter *hiter = iter->private;
141d0a7e8caSPekka Paalanen 	struct trace_seq *s = &iter->seq;
1422039238bSPekka Paalanen 	unsigned long n;
1432039238bSPekka Paalanen 
1442039238bSPekka Paalanen 	n = count_overruns(iter);
1452039238bSPekka Paalanen 	if (n) {
1462039238bSPekka Paalanen 		/* XXX: This is later than where events were lost. */
1472039238bSPekka Paalanen 		trace_seq_printf(s, "MARK 0.000000 Lost %lu events.\n", n);
1482039238bSPekka Paalanen 		if (!overrun_detected)
1492039238bSPekka Paalanen 			pr_warning("mmiotrace has lost events.\n");
1502039238bSPekka Paalanen 		overrun_detected = true;
1512039238bSPekka Paalanen 		goto print_out;
1522039238bSPekka Paalanen 	}
153d0a7e8caSPekka Paalanen 
154d0a7e8caSPekka Paalanen 	if (!hiter)
155d0a7e8caSPekka Paalanen 		return 0;
156d0a7e8caSPekka Paalanen 
157d0a7e8caSPekka Paalanen 	mmio_print_pcidev(s, hiter->dev);
158d0a7e8caSPekka Paalanen 	hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev);
159d0a7e8caSPekka Paalanen 
160d0a7e8caSPekka Paalanen 	if (!hiter->dev) {
161d0a7e8caSPekka Paalanen 		destroy_header_iter(hiter);
162d0a7e8caSPekka Paalanen 		iter->private = NULL;
163d0a7e8caSPekka Paalanen 	}
164d0a7e8caSPekka Paalanen 
1652039238bSPekka Paalanen print_out:
166d0a7e8caSPekka Paalanen 	ret = trace_seq_to_user(s, ubuf, cnt);
167d0a7e8caSPekka Paalanen 	return (ret == -EBUSY) ? 0 : ret;
168bd8ac686SPekka Paalanen }
169bd8ac686SPekka Paalanen 
17007f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_rw(struct trace_iterator *iter)
171bd8ac686SPekka Paalanen {
172bd8ac686SPekka Paalanen 	struct trace_entry *entry = iter->ent;
1737104f300SSteven Rostedt 	struct trace_mmiotrace_rw *field;
1747104f300SSteven Rostedt 	struct mmiotrace_rw *rw;
175bd8ac686SPekka Paalanen 	struct trace_seq *s	= &iter->seq;
1763928a8a2SSteven Rostedt 	unsigned long long t	= ns2usecs(iter->ts);
177bd8ac686SPekka Paalanen 	unsigned long usec_rem	= do_div(t, 1000000ULL);
178bd8ac686SPekka Paalanen 	unsigned secs		= (unsigned long)t;
179bd8ac686SPekka Paalanen 	int ret = 1;
180bd8ac686SPekka Paalanen 
1817104f300SSteven Rostedt 	trace_assign_type(field, entry);
1827104f300SSteven Rostedt 	rw = &field->rw;
1837104f300SSteven Rostedt 
184777e208dSSteven Rostedt 	switch (rw->opcode) {
185bd8ac686SPekka Paalanen 	case MMIO_READ:
186bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
1875e4abc98SSteven Rostedt 			"R %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
188dee310d0SPekka Paalanen 			rw->width, secs, usec_rem, rw->map_id,
189dee310d0SPekka Paalanen 			(unsigned long long)rw->phys,
190736ca61fSPekka Paalanen 			rw->value, rw->pc, 0);
191bd8ac686SPekka Paalanen 		break;
192bd8ac686SPekka Paalanen 	case MMIO_WRITE:
193bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
1945e4abc98SSteven Rostedt 			"W %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
195dee310d0SPekka Paalanen 			rw->width, secs, usec_rem, rw->map_id,
196dee310d0SPekka Paalanen 			(unsigned long long)rw->phys,
197736ca61fSPekka Paalanen 			rw->value, rw->pc, 0);
198bd8ac686SPekka Paalanen 		break;
199bd8ac686SPekka Paalanen 	case MMIO_UNKNOWN_OP:
200bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
2015e4abc98SSteven Rostedt 			"UNKNOWN %u.%06lu %d 0x%llx %02lx,%02lx,"
2025e4abc98SSteven Rostedt 			"%02lx 0x%lx %d\n",
203dee310d0SPekka Paalanen 			secs, usec_rem, rw->map_id,
204dee310d0SPekka Paalanen 			(unsigned long long)rw->phys,
205bd8ac686SPekka Paalanen 			(rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
206736ca61fSPekka Paalanen 			(rw->value >> 0) & 0xff, rw->pc, 0);
207bd8ac686SPekka Paalanen 		break;
208bd8ac686SPekka Paalanen 	default:
209bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s, "rw what?\n");
210bd8ac686SPekka Paalanen 		break;
211bd8ac686SPekka Paalanen 	}
212bd8ac686SPekka Paalanen 	if (ret)
21307f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_HANDLED;
21407f4e4f7SFrederic Weisbecker 	return TRACE_TYPE_PARTIAL_LINE;
215bd8ac686SPekka Paalanen }
216bd8ac686SPekka Paalanen 
21707f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_map(struct trace_iterator *iter)
218bd8ac686SPekka Paalanen {
219bd8ac686SPekka Paalanen 	struct trace_entry *entry = iter->ent;
2207104f300SSteven Rostedt 	struct trace_mmiotrace_map *field;
2217104f300SSteven Rostedt 	struct mmiotrace_map *m;
222bd8ac686SPekka Paalanen 	struct trace_seq *s	= &iter->seq;
2233928a8a2SSteven Rostedt 	unsigned long long t	= ns2usecs(iter->ts);
224bd8ac686SPekka Paalanen 	unsigned long usec_rem	= do_div(t, 1000000ULL);
225bd8ac686SPekka Paalanen 	unsigned secs		= (unsigned long)t;
22607f4e4f7SFrederic Weisbecker 	int ret;
227bd8ac686SPekka Paalanen 
2287104f300SSteven Rostedt 	trace_assign_type(field, entry);
2297104f300SSteven Rostedt 	m = &field->map;
2307104f300SSteven Rostedt 
231777e208dSSteven Rostedt 	switch (m->opcode) {
232bd8ac686SPekka Paalanen 	case MMIO_PROBE:
233bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
2345e4abc98SSteven Rostedt 			"MAP %u.%06lu %d 0x%llx 0x%lx 0x%lx 0x%lx %d\n",
235dee310d0SPekka Paalanen 			secs, usec_rem, m->map_id,
236dee310d0SPekka Paalanen 			(unsigned long long)m->phys, m->virt, m->len,
237e0fd5c2fSPekka Paalanen 			0UL, 0);
238bd8ac686SPekka Paalanen 		break;
239bd8ac686SPekka Paalanen 	case MMIO_UNPROBE:
240bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
2415e4abc98SSteven Rostedt 			"UNMAP %u.%06lu %d 0x%lx %d\n",
242e0fd5c2fSPekka Paalanen 			secs, usec_rem, m->map_id, 0UL, 0);
243bd8ac686SPekka Paalanen 		break;
244bd8ac686SPekka Paalanen 	default:
245bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s, "map what?\n");
246bd8ac686SPekka Paalanen 		break;
247bd8ac686SPekka Paalanen 	}
248bd8ac686SPekka Paalanen 	if (ret)
24907f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_HANDLED;
25007f4e4f7SFrederic Weisbecker 	return TRACE_TYPE_PARTIAL_LINE;
251bd8ac686SPekka Paalanen }
252bd8ac686SPekka Paalanen 
25307f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_mark(struct trace_iterator *iter)
254fc5e27aeSPekka Paalanen {
255fc5e27aeSPekka Paalanen 	struct trace_entry *entry = iter->ent;
256777e208dSSteven Rostedt 	struct print_entry *print = (struct print_entry *)entry;
257fc5e27aeSPekka Paalanen 	struct trace_seq *s	= &iter->seq;
2583928a8a2SSteven Rostedt 	unsigned long long t	= ns2usecs(iter->ts);
259*769b0441SFrederic Weisbecker 	unsigned long usec_rem	= do_div(t, USEC_PER_SEC);
260fc5e27aeSPekka Paalanen 	unsigned secs		= (unsigned long)t;
261fc5e27aeSPekka Paalanen 	int ret;
262fc5e27aeSPekka Paalanen 
263fc5e27aeSPekka Paalanen 	/* The trailing newline must be in the message. */
264*769b0441SFrederic Weisbecker 	ret = trace_seq_printf(s, "MARK %u.%06lu ", secs, usec_rem);
265*769b0441SFrederic Weisbecker 	if (!ret)
266*769b0441SFrederic Weisbecker 		return TRACE_TYPE_PARTIAL_LINE;
267*769b0441SFrederic Weisbecker 
268*769b0441SFrederic Weisbecker 	ret = trace_seq_bprintf(s, print->fmt, print->buf);
269fc5e27aeSPekka Paalanen 	if (!ret)
27007f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_PARTIAL_LINE;
271fc5e27aeSPekka Paalanen 
27207f4e4f7SFrederic Weisbecker 	return TRACE_TYPE_HANDLED;
273fc5e27aeSPekka Paalanen }
274fc5e27aeSPekka Paalanen 
27507f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_line(struct trace_iterator *iter)
276bd8ac686SPekka Paalanen {
277bd8ac686SPekka Paalanen 	switch (iter->ent->type) {
278bd8ac686SPekka Paalanen 	case TRACE_MMIO_RW:
279bd8ac686SPekka Paalanen 		return mmio_print_rw(iter);
280bd8ac686SPekka Paalanen 	case TRACE_MMIO_MAP:
281bd8ac686SPekka Paalanen 		return mmio_print_map(iter);
282fc5e27aeSPekka Paalanen 	case TRACE_PRINT:
283fc5e27aeSPekka Paalanen 		return mmio_print_mark(iter);
284bd8ac686SPekka Paalanen 	default:
28507f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_HANDLED; /* ignore unknown entries */
286bd8ac686SPekka Paalanen 	}
287bd8ac686SPekka Paalanen }
288f984b51eSPekka Paalanen 
289f984b51eSPekka Paalanen static struct tracer mmio_tracer __read_mostly =
290f984b51eSPekka Paalanen {
291f984b51eSPekka Paalanen 	.name		= "mmiotrace",
292f984b51eSPekka Paalanen 	.init		= mmio_trace_init,
293f984b51eSPekka Paalanen 	.reset		= mmio_trace_reset,
294bbf5b1a0SSteven Rostedt 	.start		= mmio_trace_start,
295d0a7e8caSPekka Paalanen 	.pipe_open	= mmio_pipe_open,
296d0a7e8caSPekka Paalanen 	.close		= mmio_close,
297d0a7e8caSPekka Paalanen 	.read		= mmio_read,
298bd8ac686SPekka Paalanen 	.print_line	= mmio_print_line,
299f984b51eSPekka Paalanen };
300f984b51eSPekka Paalanen 
301f984b51eSPekka Paalanen __init static int init_mmio_trace(void)
302f984b51eSPekka Paalanen {
303f984b51eSPekka Paalanen 	return register_tracer(&mmio_tracer);
304f984b51eSPekka Paalanen }
305f984b51eSPekka Paalanen device_initcall(init_mmio_trace);
306f984b51eSPekka Paalanen 
30745dcd8b8SPekka Paalanen static void __trace_mmiotrace_rw(struct trace_array *tr,
30845dcd8b8SPekka Paalanen 				struct trace_array_cpu *data,
30945dcd8b8SPekka Paalanen 				struct mmiotrace_rw *rw)
31045dcd8b8SPekka Paalanen {
3113928a8a2SSteven Rostedt 	struct ring_buffer_event *event;
312777e208dSSteven Rostedt 	struct trace_mmiotrace_rw *entry;
31351a763ddSArnaldo Carvalho de Melo 	int pc = preempt_count();
31445dcd8b8SPekka Paalanen 
31551a763ddSArnaldo Carvalho de Melo 	event = trace_buffer_lock_reserve(tr, TRACE_MMIO_RW,
31651a763ddSArnaldo Carvalho de Melo 					  sizeof(*entry), 0, pc);
317173ed24eSPekka Paalanen 	if (!event) {
318173ed24eSPekka Paalanen 		atomic_inc(&dropped_count);
3193928a8a2SSteven Rostedt 		return;
320173ed24eSPekka Paalanen 	}
3213928a8a2SSteven Rostedt 	entry	= ring_buffer_event_data(event);
322777e208dSSteven Rostedt 	entry->rw			= *rw;
32351a763ddSArnaldo Carvalho de Melo 	trace_buffer_unlock_commit(tr, event, 0, pc);
32445dcd8b8SPekka Paalanen }
32545dcd8b8SPekka Paalanen 
326bd8ac686SPekka Paalanen void mmio_trace_rw(struct mmiotrace_rw *rw)
327f984b51eSPekka Paalanen {
328f984b51eSPekka Paalanen 	struct trace_array *tr = mmio_trace_array;
329f984b51eSPekka Paalanen 	struct trace_array_cpu *data = tr->data[smp_processor_id()];
330bd8ac686SPekka Paalanen 	__trace_mmiotrace_rw(tr, data, rw);
331bd8ac686SPekka Paalanen }
332f984b51eSPekka Paalanen 
33345dcd8b8SPekka Paalanen static void __trace_mmiotrace_map(struct trace_array *tr,
33445dcd8b8SPekka Paalanen 				struct trace_array_cpu *data,
33545dcd8b8SPekka Paalanen 				struct mmiotrace_map *map)
33645dcd8b8SPekka Paalanen {
3373928a8a2SSteven Rostedt 	struct ring_buffer_event *event;
338777e208dSSteven Rostedt 	struct trace_mmiotrace_map *entry;
33951a763ddSArnaldo Carvalho de Melo 	int pc = preempt_count();
34045dcd8b8SPekka Paalanen 
34151a763ddSArnaldo Carvalho de Melo 	event = trace_buffer_lock_reserve(tr, TRACE_MMIO_MAP,
34251a763ddSArnaldo Carvalho de Melo 					  sizeof(*entry), 0, pc);
343173ed24eSPekka Paalanen 	if (!event) {
344173ed24eSPekka Paalanen 		atomic_inc(&dropped_count);
3453928a8a2SSteven Rostedt 		return;
346173ed24eSPekka Paalanen 	}
3473928a8a2SSteven Rostedt 	entry	= ring_buffer_event_data(event);
348777e208dSSteven Rostedt 	entry->map			= *map;
34951a763ddSArnaldo Carvalho de Melo 	trace_buffer_unlock_commit(tr, event, 0, pc);
35045dcd8b8SPekka Paalanen }
35145dcd8b8SPekka Paalanen 
352bd8ac686SPekka Paalanen void mmio_trace_mapping(struct mmiotrace_map *map)
353bd8ac686SPekka Paalanen {
354bd8ac686SPekka Paalanen 	struct trace_array *tr = mmio_trace_array;
355bd8ac686SPekka Paalanen 	struct trace_array_cpu *data;
356bd8ac686SPekka Paalanen 
357bd8ac686SPekka Paalanen 	preempt_disable();
358bd8ac686SPekka Paalanen 	data = tr->data[smp_processor_id()];
359bd8ac686SPekka Paalanen 	__trace_mmiotrace_map(tr, data, map);
360bd8ac686SPekka Paalanen 	preempt_enable();
361f984b51eSPekka Paalanen }
3629e57fb35SPekka Paalanen 
3639e57fb35SPekka Paalanen int mmio_trace_printk(const char *fmt, va_list args)
3649e57fb35SPekka Paalanen {
3651fd8f2a3SFrederic Weisbecker 	return trace_vprintk(0, -1, fmt, args);
3669e57fb35SPekka Paalanen }
367