xref: /openbmc/linux/kernel/trace/trace_mmiotrace.c (revision bbf5b1a0cecb56de6236db8b01c5bfb7ab8ba8b2)
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>
12f984b51eSPekka Paalanen 
13f984b51eSPekka Paalanen #include "trace.h"
14f984b51eSPekka Paalanen 
15d0a7e8caSPekka Paalanen struct header_iter {
16d0a7e8caSPekka Paalanen 	struct pci_dev *dev;
17d0a7e8caSPekka Paalanen };
18d0a7e8caSPekka Paalanen 
19f984b51eSPekka Paalanen static struct trace_array *mmio_trace_array;
202039238bSPekka Paalanen static bool overrun_detected;
21f984b51eSPekka Paalanen 
22bd8ac686SPekka Paalanen static void mmio_reset_data(struct trace_array *tr)
23bd8ac686SPekka Paalanen {
24bd8ac686SPekka Paalanen 	int cpu;
25bd8ac686SPekka Paalanen 
262039238bSPekka Paalanen 	overrun_detected = false;
27bd8ac686SPekka Paalanen 	tr->time_start = ftrace_now(tr->cpu);
28bd8ac686SPekka Paalanen 
29bd8ac686SPekka Paalanen 	for_each_online_cpu(cpu)
303928a8a2SSteven Rostedt 		tracing_reset(tr, cpu);
31bd8ac686SPekka Paalanen }
32f984b51eSPekka Paalanen 
33f984b51eSPekka Paalanen static void mmio_trace_init(struct trace_array *tr)
34f984b51eSPekka Paalanen {
35f984b51eSPekka Paalanen 	pr_debug("in %s\n", __func__);
36f984b51eSPekka Paalanen 	mmio_trace_array = tr;
37bd8ac686SPekka Paalanen 	if (tr->ctrl) {
38bd8ac686SPekka Paalanen 		mmio_reset_data(tr);
39f984b51eSPekka Paalanen 		enable_mmiotrace();
40f984b51eSPekka Paalanen 	}
41bd8ac686SPekka Paalanen }
42f984b51eSPekka Paalanen 
43f984b51eSPekka Paalanen static void mmio_trace_reset(struct trace_array *tr)
44f984b51eSPekka Paalanen {
45f984b51eSPekka Paalanen 	pr_debug("in %s\n", __func__);
46f984b51eSPekka Paalanen 	if (tr->ctrl)
47f984b51eSPekka Paalanen 		disable_mmiotrace();
48bd8ac686SPekka Paalanen 	mmio_reset_data(tr);
49bd8ac686SPekka Paalanen 	mmio_trace_array = NULL;
50f984b51eSPekka Paalanen }
51f984b51eSPekka Paalanen 
52*bbf5b1a0SSteven Rostedt static void mmio_trace_start(struct trace_array *tr)
53f984b51eSPekka Paalanen {
54f984b51eSPekka Paalanen 	pr_debug("in %s\n", __func__);
55bd8ac686SPekka Paalanen 	mmio_reset_data(tr);
56bd8ac686SPekka Paalanen }
57bd8ac686SPekka Paalanen 
5813829537SPekka Paalanen static int mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev)
5913829537SPekka Paalanen {
6013829537SPekka Paalanen 	int ret = 0;
6113829537SPekka Paalanen 	int i;
6213829537SPekka Paalanen 	resource_size_t start, end;
6313829537SPekka Paalanen 	const struct pci_driver *drv = pci_dev_driver(dev);
6413829537SPekka Paalanen 
6513829537SPekka Paalanen 	/* XXX: incomplete checks for trace_seq_printf() return value */
6613829537SPekka Paalanen 	ret += trace_seq_printf(s, "PCIDEV %02x%02x %04x%04x %x",
6713829537SPekka Paalanen 				dev->bus->number, dev->devfn,
6813829537SPekka Paalanen 				dev->vendor, dev->device, dev->irq);
6913829537SPekka Paalanen 	/*
7013829537SPekka Paalanen 	 * XXX: is pci_resource_to_user() appropriate, since we are
7113829537SPekka Paalanen 	 * supposed to interpret the __ioremap() phys_addr argument based on
7213829537SPekka Paalanen 	 * these printed values?
7313829537SPekka Paalanen 	 */
7413829537SPekka Paalanen 	for (i = 0; i < 7; i++) {
7513829537SPekka Paalanen 		pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
7613829537SPekka Paalanen 		ret += trace_seq_printf(s, " %llx",
7713829537SPekka Paalanen 			(unsigned long long)(start |
7813829537SPekka Paalanen 			(dev->resource[i].flags & PCI_REGION_FLAG_MASK)));
7913829537SPekka Paalanen 	}
8013829537SPekka Paalanen 	for (i = 0; i < 7; i++) {
8113829537SPekka Paalanen 		pci_resource_to_user(dev, i, &dev->resource[i], &start, &end);
8213829537SPekka Paalanen 		ret += trace_seq_printf(s, " %llx",
8313829537SPekka Paalanen 			dev->resource[i].start < dev->resource[i].end ?
8413829537SPekka Paalanen 			(unsigned long long)(end - start) + 1 : 0);
8513829537SPekka Paalanen 	}
8613829537SPekka Paalanen 	if (drv)
8713829537SPekka Paalanen 		ret += trace_seq_printf(s, " %s\n", drv->name);
8813829537SPekka Paalanen 	else
8913829537SPekka Paalanen 		ret += trace_seq_printf(s, " \n");
9013829537SPekka Paalanen 	return ret;
9113829537SPekka Paalanen }
9213829537SPekka Paalanen 
93d0a7e8caSPekka Paalanen static void destroy_header_iter(struct header_iter *hiter)
94bd8ac686SPekka Paalanen {
95d0a7e8caSPekka Paalanen 	if (!hiter)
96d0a7e8caSPekka Paalanen 		return;
97d0a7e8caSPekka Paalanen 	pci_dev_put(hiter->dev);
98d0a7e8caSPekka Paalanen 	kfree(hiter);
99d0a7e8caSPekka Paalanen }
100d0a7e8caSPekka Paalanen 
101d0a7e8caSPekka Paalanen static void mmio_pipe_open(struct trace_iterator *iter)
102d0a7e8caSPekka Paalanen {
103d0a7e8caSPekka Paalanen 	struct header_iter *hiter;
104bd8ac686SPekka Paalanen 	struct trace_seq *s = &iter->seq;
10513829537SPekka Paalanen 
10613829537SPekka Paalanen 	trace_seq_printf(s, "VERSION 20070824\n");
10713829537SPekka Paalanen 
108d0a7e8caSPekka Paalanen 	hiter = kzalloc(sizeof(*hiter), GFP_KERNEL);
109d0a7e8caSPekka Paalanen 	if (!hiter)
110d0a7e8caSPekka Paalanen 		return;
111d0a7e8caSPekka Paalanen 
112d0a7e8caSPekka Paalanen 	hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
113d0a7e8caSPekka Paalanen 	iter->private = hiter;
114d0a7e8caSPekka Paalanen }
115d0a7e8caSPekka Paalanen 
116d0a7e8caSPekka Paalanen /* XXX: This is not called when the pipe is closed! */
117d0a7e8caSPekka Paalanen static void mmio_close(struct trace_iterator *iter)
118d0a7e8caSPekka Paalanen {
119d0a7e8caSPekka Paalanen 	struct header_iter *hiter = iter->private;
120d0a7e8caSPekka Paalanen 	destroy_header_iter(hiter);
121d0a7e8caSPekka Paalanen 	iter->private = NULL;
122d0a7e8caSPekka Paalanen }
123d0a7e8caSPekka Paalanen 
1242039238bSPekka Paalanen static unsigned long count_overruns(struct trace_iterator *iter)
1252039238bSPekka Paalanen {
1262039238bSPekka Paalanen 	int cpu;
1272039238bSPekka Paalanen 	unsigned long cnt = 0;
1283928a8a2SSteven Rostedt /* FIXME: */
1293928a8a2SSteven Rostedt #if 0
1302039238bSPekka Paalanen 	for_each_online_cpu(cpu) {
1312039238bSPekka Paalanen 		cnt += iter->overrun[cpu];
1322039238bSPekka Paalanen 		iter->overrun[cpu] = 0;
1332039238bSPekka Paalanen 	}
1343928a8a2SSteven Rostedt #endif
1353928a8a2SSteven Rostedt 	(void)cpu;
1362039238bSPekka Paalanen 	return cnt;
1372039238bSPekka Paalanen }
1382039238bSPekka Paalanen 
139d0a7e8caSPekka Paalanen static ssize_t mmio_read(struct trace_iterator *iter, struct file *filp,
140d0a7e8caSPekka Paalanen 				char __user *ubuf, size_t cnt, loff_t *ppos)
141d0a7e8caSPekka Paalanen {
142d0a7e8caSPekka Paalanen 	ssize_t ret;
143d0a7e8caSPekka Paalanen 	struct header_iter *hiter = iter->private;
144d0a7e8caSPekka Paalanen 	struct trace_seq *s = &iter->seq;
1452039238bSPekka Paalanen 	unsigned long n;
1462039238bSPekka Paalanen 
1472039238bSPekka Paalanen 	n = count_overruns(iter);
1482039238bSPekka Paalanen 	if (n) {
1492039238bSPekka Paalanen 		/* XXX: This is later than where events were lost. */
1502039238bSPekka Paalanen 		trace_seq_printf(s, "MARK 0.000000 Lost %lu events.\n", n);
1512039238bSPekka Paalanen 		if (!overrun_detected)
1522039238bSPekka Paalanen 			pr_warning("mmiotrace has lost events.\n");
1532039238bSPekka Paalanen 		overrun_detected = true;
1542039238bSPekka Paalanen 		goto print_out;
1552039238bSPekka Paalanen 	}
156d0a7e8caSPekka Paalanen 
157d0a7e8caSPekka Paalanen 	if (!hiter)
158d0a7e8caSPekka Paalanen 		return 0;
159d0a7e8caSPekka Paalanen 
160d0a7e8caSPekka Paalanen 	mmio_print_pcidev(s, hiter->dev);
161d0a7e8caSPekka Paalanen 	hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev);
162d0a7e8caSPekka Paalanen 
163d0a7e8caSPekka Paalanen 	if (!hiter->dev) {
164d0a7e8caSPekka Paalanen 		destroy_header_iter(hiter);
165d0a7e8caSPekka Paalanen 		iter->private = NULL;
166d0a7e8caSPekka Paalanen 	}
167d0a7e8caSPekka Paalanen 
1682039238bSPekka Paalanen print_out:
169d0a7e8caSPekka Paalanen 	ret = trace_seq_to_user(s, ubuf, cnt);
170d0a7e8caSPekka Paalanen 	return (ret == -EBUSY) ? 0 : ret;
171bd8ac686SPekka Paalanen }
172bd8ac686SPekka Paalanen 
17307f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_rw(struct trace_iterator *iter)
174bd8ac686SPekka Paalanen {
175bd8ac686SPekka Paalanen 	struct trace_entry *entry = iter->ent;
1767104f300SSteven Rostedt 	struct trace_mmiotrace_rw *field;
1777104f300SSteven Rostedt 	struct mmiotrace_rw *rw;
178bd8ac686SPekka Paalanen 	struct trace_seq *s	= &iter->seq;
1793928a8a2SSteven Rostedt 	unsigned long long t	= ns2usecs(iter->ts);
180bd8ac686SPekka Paalanen 	unsigned long usec_rem	= do_div(t, 1000000ULL);
181bd8ac686SPekka Paalanen 	unsigned secs		= (unsigned long)t;
182bd8ac686SPekka Paalanen 	int ret = 1;
183bd8ac686SPekka Paalanen 
1847104f300SSteven Rostedt 	trace_assign_type(field, entry);
1857104f300SSteven Rostedt 	rw = &field->rw;
1867104f300SSteven Rostedt 
187777e208dSSteven Rostedt 	switch (rw->opcode) {
188bd8ac686SPekka Paalanen 	case MMIO_READ:
189bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
190dee310d0SPekka Paalanen 			"R %d %lu.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
191dee310d0SPekka Paalanen 			rw->width, secs, usec_rem, rw->map_id,
192dee310d0SPekka Paalanen 			(unsigned long long)rw->phys,
193736ca61fSPekka Paalanen 			rw->value, rw->pc, 0);
194bd8ac686SPekka Paalanen 		break;
195bd8ac686SPekka Paalanen 	case MMIO_WRITE:
196bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
197dee310d0SPekka Paalanen 			"W %d %lu.%06lu %d 0x%llx 0x%lx 0x%lx %d\n",
198dee310d0SPekka Paalanen 			rw->width, secs, usec_rem, rw->map_id,
199dee310d0SPekka Paalanen 			(unsigned long long)rw->phys,
200736ca61fSPekka Paalanen 			rw->value, rw->pc, 0);
201bd8ac686SPekka Paalanen 		break;
202bd8ac686SPekka Paalanen 	case MMIO_UNKNOWN_OP:
203bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
204dee310d0SPekka Paalanen 			"UNKNOWN %lu.%06lu %d 0x%llx %02x,%02x,%02x 0x%lx %d\n",
205dee310d0SPekka Paalanen 			secs, usec_rem, rw->map_id,
206dee310d0SPekka Paalanen 			(unsigned long long)rw->phys,
207bd8ac686SPekka Paalanen 			(rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
208736ca61fSPekka Paalanen 			(rw->value >> 0) & 0xff, rw->pc, 0);
209bd8ac686SPekka Paalanen 		break;
210bd8ac686SPekka Paalanen 	default:
211bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s, "rw what?\n");
212bd8ac686SPekka Paalanen 		break;
213bd8ac686SPekka Paalanen 	}
214bd8ac686SPekka Paalanen 	if (ret)
21507f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_HANDLED;
21607f4e4f7SFrederic Weisbecker 	return TRACE_TYPE_PARTIAL_LINE;
217bd8ac686SPekka Paalanen }
218bd8ac686SPekka Paalanen 
21907f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_map(struct trace_iterator *iter)
220bd8ac686SPekka Paalanen {
221bd8ac686SPekka Paalanen 	struct trace_entry *entry = iter->ent;
2227104f300SSteven Rostedt 	struct trace_mmiotrace_map *field;
2237104f300SSteven Rostedt 	struct mmiotrace_map *m;
224bd8ac686SPekka Paalanen 	struct trace_seq *s	= &iter->seq;
2253928a8a2SSteven Rostedt 	unsigned long long t	= ns2usecs(iter->ts);
226bd8ac686SPekka Paalanen 	unsigned long usec_rem	= do_div(t, 1000000ULL);
227bd8ac686SPekka Paalanen 	unsigned secs		= (unsigned long)t;
22807f4e4f7SFrederic Weisbecker 	int ret;
229bd8ac686SPekka Paalanen 
2307104f300SSteven Rostedt 	trace_assign_type(field, entry);
2317104f300SSteven Rostedt 	m = &field->map;
2327104f300SSteven Rostedt 
233777e208dSSteven Rostedt 	switch (m->opcode) {
234bd8ac686SPekka Paalanen 	case MMIO_PROBE:
235bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
236dee310d0SPekka Paalanen 			"MAP %lu.%06lu %d 0x%llx 0x%lx 0x%lx 0x%lx %d\n",
237dee310d0SPekka Paalanen 			secs, usec_rem, m->map_id,
238dee310d0SPekka Paalanen 			(unsigned long long)m->phys, m->virt, m->len,
239e0fd5c2fSPekka Paalanen 			0UL, 0);
240bd8ac686SPekka Paalanen 		break;
241bd8ac686SPekka Paalanen 	case MMIO_UNPROBE:
242bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s,
243bd8ac686SPekka Paalanen 			"UNMAP %lu.%06lu %d 0x%lx %d\n",
244e0fd5c2fSPekka Paalanen 			secs, usec_rem, m->map_id, 0UL, 0);
245bd8ac686SPekka Paalanen 		break;
246bd8ac686SPekka Paalanen 	default:
247bd8ac686SPekka Paalanen 		ret = trace_seq_printf(s, "map what?\n");
248bd8ac686SPekka Paalanen 		break;
249bd8ac686SPekka Paalanen 	}
250bd8ac686SPekka Paalanen 	if (ret)
25107f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_HANDLED;
25207f4e4f7SFrederic Weisbecker 	return TRACE_TYPE_PARTIAL_LINE;
253bd8ac686SPekka Paalanen }
254bd8ac686SPekka Paalanen 
25507f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_mark(struct trace_iterator *iter)
256fc5e27aeSPekka Paalanen {
257fc5e27aeSPekka Paalanen 	struct trace_entry *entry = iter->ent;
258777e208dSSteven Rostedt 	struct print_entry *print = (struct print_entry *)entry;
259777e208dSSteven Rostedt 	const char *msg		= print->buf;
260fc5e27aeSPekka Paalanen 	struct trace_seq *s	= &iter->seq;
2613928a8a2SSteven Rostedt 	unsigned long long t	= ns2usecs(iter->ts);
262fc5e27aeSPekka Paalanen 	unsigned long usec_rem	= do_div(t, 1000000ULL);
263fc5e27aeSPekka Paalanen 	unsigned secs		= (unsigned long)t;
264fc5e27aeSPekka Paalanen 	int ret;
265fc5e27aeSPekka Paalanen 
266fc5e27aeSPekka Paalanen 	/* The trailing newline must be in the message. */
267fc5e27aeSPekka Paalanen 	ret = trace_seq_printf(s, "MARK %lu.%06lu %s", secs, usec_rem, msg);
268fc5e27aeSPekka Paalanen 	if (!ret)
26907f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_PARTIAL_LINE;
270fc5e27aeSPekka Paalanen 
271777e208dSSteven Rostedt 	if (entry->flags & TRACE_FLAG_CONT)
272fc5e27aeSPekka Paalanen 		trace_seq_print_cont(s, iter);
273fc5e27aeSPekka Paalanen 
27407f4e4f7SFrederic Weisbecker 	return TRACE_TYPE_HANDLED;
275fc5e27aeSPekka Paalanen }
276fc5e27aeSPekka Paalanen 
27707f4e4f7SFrederic Weisbecker static enum print_line_t mmio_print_line(struct trace_iterator *iter)
278bd8ac686SPekka Paalanen {
279bd8ac686SPekka Paalanen 	switch (iter->ent->type) {
280bd8ac686SPekka Paalanen 	case TRACE_MMIO_RW:
281bd8ac686SPekka Paalanen 		return mmio_print_rw(iter);
282bd8ac686SPekka Paalanen 	case TRACE_MMIO_MAP:
283bd8ac686SPekka Paalanen 		return mmio_print_map(iter);
284fc5e27aeSPekka Paalanen 	case TRACE_PRINT:
285fc5e27aeSPekka Paalanen 		return mmio_print_mark(iter);
286bd8ac686SPekka Paalanen 	default:
28707f4e4f7SFrederic Weisbecker 		return TRACE_TYPE_HANDLED; /* ignore unknown entries */
288bd8ac686SPekka Paalanen 	}
289bd8ac686SPekka Paalanen }
290f984b51eSPekka Paalanen 
291f984b51eSPekka Paalanen static struct tracer mmio_tracer __read_mostly =
292f984b51eSPekka Paalanen {
293f984b51eSPekka Paalanen 	.name		= "mmiotrace",
294f984b51eSPekka Paalanen 	.init		= mmio_trace_init,
295f984b51eSPekka Paalanen 	.reset		= mmio_trace_reset,
296*bbf5b1a0SSteven Rostedt 	.start		= mmio_trace_start,
297d0a7e8caSPekka Paalanen 	.pipe_open	= mmio_pipe_open,
298d0a7e8caSPekka Paalanen 	.close		= mmio_close,
299d0a7e8caSPekka Paalanen 	.read		= mmio_read,
300bd8ac686SPekka Paalanen 	.print_line	= mmio_print_line,
301f984b51eSPekka Paalanen };
302f984b51eSPekka Paalanen 
303f984b51eSPekka Paalanen __init static int init_mmio_trace(void)
304f984b51eSPekka Paalanen {
305f984b51eSPekka Paalanen 	return register_tracer(&mmio_tracer);
306f984b51eSPekka Paalanen }
307f984b51eSPekka Paalanen device_initcall(init_mmio_trace);
308f984b51eSPekka Paalanen 
30945dcd8b8SPekka Paalanen static void __trace_mmiotrace_rw(struct trace_array *tr,
31045dcd8b8SPekka Paalanen 				struct trace_array_cpu *data,
31145dcd8b8SPekka Paalanen 				struct mmiotrace_rw *rw)
31245dcd8b8SPekka Paalanen {
3133928a8a2SSteven Rostedt 	struct ring_buffer_event *event;
314777e208dSSteven Rostedt 	struct trace_mmiotrace_rw *entry;
31545dcd8b8SPekka Paalanen 	unsigned long irq_flags;
31645dcd8b8SPekka Paalanen 
3173928a8a2SSteven Rostedt 	event	= ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
3183928a8a2SSteven Rostedt 					   &irq_flags);
3193928a8a2SSteven Rostedt 	if (!event)
3203928a8a2SSteven Rostedt 		return;
3213928a8a2SSteven Rostedt 	entry	= ring_buffer_event_data(event);
32238697053SSteven Rostedt 	tracing_generic_entry_update(&entry->ent, 0, preempt_count());
323777e208dSSteven Rostedt 	entry->ent.type			= TRACE_MMIO_RW;
324777e208dSSteven Rostedt 	entry->rw			= *rw;
3253928a8a2SSteven Rostedt 	ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
32645dcd8b8SPekka Paalanen 
32745dcd8b8SPekka Paalanen 	trace_wake_up();
32845dcd8b8SPekka Paalanen }
32945dcd8b8SPekka Paalanen 
330bd8ac686SPekka Paalanen void mmio_trace_rw(struct mmiotrace_rw *rw)
331f984b51eSPekka Paalanen {
332f984b51eSPekka Paalanen 	struct trace_array *tr = mmio_trace_array;
333f984b51eSPekka Paalanen 	struct trace_array_cpu *data = tr->data[smp_processor_id()];
334bd8ac686SPekka Paalanen 	__trace_mmiotrace_rw(tr, data, rw);
335bd8ac686SPekka Paalanen }
336f984b51eSPekka Paalanen 
33745dcd8b8SPekka Paalanen static void __trace_mmiotrace_map(struct trace_array *tr,
33845dcd8b8SPekka Paalanen 				struct trace_array_cpu *data,
33945dcd8b8SPekka Paalanen 				struct mmiotrace_map *map)
34045dcd8b8SPekka Paalanen {
3413928a8a2SSteven Rostedt 	struct ring_buffer_event *event;
342777e208dSSteven Rostedt 	struct trace_mmiotrace_map *entry;
34345dcd8b8SPekka Paalanen 	unsigned long irq_flags;
34445dcd8b8SPekka Paalanen 
3453928a8a2SSteven Rostedt 	event	= ring_buffer_lock_reserve(tr->buffer, sizeof(*entry),
3463928a8a2SSteven Rostedt 					   &irq_flags);
3473928a8a2SSteven Rostedt 	if (!event)
3483928a8a2SSteven Rostedt 		return;
3493928a8a2SSteven Rostedt 	entry	= ring_buffer_event_data(event);
35038697053SSteven Rostedt 	tracing_generic_entry_update(&entry->ent, 0, preempt_count());
351777e208dSSteven Rostedt 	entry->ent.type			= TRACE_MMIO_MAP;
352777e208dSSteven Rostedt 	entry->map			= *map;
3533928a8a2SSteven Rostedt 	ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
35445dcd8b8SPekka Paalanen 
35545dcd8b8SPekka Paalanen 	trace_wake_up();
35645dcd8b8SPekka Paalanen }
35745dcd8b8SPekka Paalanen 
358bd8ac686SPekka Paalanen void mmio_trace_mapping(struct mmiotrace_map *map)
359bd8ac686SPekka Paalanen {
360bd8ac686SPekka Paalanen 	struct trace_array *tr = mmio_trace_array;
361bd8ac686SPekka Paalanen 	struct trace_array_cpu *data;
362bd8ac686SPekka Paalanen 
363bd8ac686SPekka Paalanen 	preempt_disable();
364bd8ac686SPekka Paalanen 	data = tr->data[smp_processor_id()];
365bd8ac686SPekka Paalanen 	__trace_mmiotrace_map(tr, data, map);
366bd8ac686SPekka Paalanen 	preempt_enable();
367f984b51eSPekka Paalanen }
3689e57fb35SPekka Paalanen 
3699e57fb35SPekka Paalanen int mmio_trace_printk(const char *fmt, va_list args)
3709e57fb35SPekka Paalanen {
3719e57fb35SPekka Paalanen 	return trace_vprintk(0, fmt, args);
3729e57fb35SPekka Paalanen }
373