Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Memory mapped I/O tracing |
| 4 | * |
| 5 | * Copyright (C) 2008 Pekka Paalanen <pq@iki.fi> |
| 6 | */ |
| 7 | |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 8 | #include <linux/kernel.h> |
| 9 | #include <linux/mmiotrace.h> |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 10 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Li Zefan | a5dec55 | 2009-03-27 14:55:44 +0800 | [diff] [blame] | 12 | #include <linux/time.h> |
| 13 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 14 | #include <linux/atomic.h> |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 15 | |
| 16 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 17 | #include "trace_output.h" |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 18 | |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 19 | struct header_iter { |
| 20 | struct pci_dev *dev; |
| 21 | }; |
| 22 | |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 23 | static struct trace_array *mmio_trace_array; |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 24 | static bool overrun_detected; |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 25 | static unsigned long prev_overruns; |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 26 | static atomic_t dropped_count; |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 27 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 28 | static void mmio_reset_data(struct trace_array *tr) |
| 29 | { |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 30 | overrun_detected = false; |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 31 | prev_overruns = 0; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 32 | |
Steven Rostedt (VMware) | 1c5eb44 | 2020-01-09 18:53:48 -0500 | [diff] [blame] | 33 | tracing_reset_online_cpus(&tr->array_buffer); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 34 | } |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 35 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 36 | static int mmio_trace_init(struct trace_array *tr) |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 37 | { |
| 38 | pr_debug("in %s\n", __func__); |
| 39 | mmio_trace_array = tr; |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 40 | |
| 41 | mmio_reset_data(tr); |
| 42 | enable_mmiotrace(); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 43 | return 0; |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static void mmio_trace_reset(struct trace_array *tr) |
| 47 | { |
| 48 | pr_debug("in %s\n", __func__); |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 49 | |
| 50 | disable_mmiotrace(); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 51 | mmio_reset_data(tr); |
| 52 | mmio_trace_array = NULL; |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 55 | static void mmio_trace_start(struct trace_array *tr) |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 56 | { |
| 57 | pr_debug("in %s\n", __func__); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 58 | mmio_reset_data(tr); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 59 | } |
| 60 | |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 61 | static void mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev) |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 62 | { |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 63 | int i; |
| 64 | resource_size_t start, end; |
| 65 | const struct pci_driver *drv = pci_dev_driver(dev); |
| 66 | |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 67 | trace_seq_printf(s, "PCIDEV %02x%02x %04x%04x %x", |
| 68 | dev->bus->number, dev->devfn, |
| 69 | dev->vendor, dev->device, dev->irq); |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 70 | for (i = 0; i < 7; i++) { |
Bjorn Helgaas | 9a51933 | 2016-05-11 14:06:57 -0500 | [diff] [blame] | 71 | start = dev->resource[i].start; |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 72 | trace_seq_printf(s, " %llx", |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 73 | (unsigned long long)(start | |
| 74 | (dev->resource[i].flags & PCI_REGION_FLAG_MASK))); |
| 75 | } |
| 76 | for (i = 0; i < 7; i++) { |
Bjorn Helgaas | 9a51933 | 2016-05-11 14:06:57 -0500 | [diff] [blame] | 77 | start = dev->resource[i].start; |
| 78 | end = dev->resource[i].end; |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 79 | trace_seq_printf(s, " %llx", |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 80 | dev->resource[i].start < dev->resource[i].end ? |
| 81 | (unsigned long long)(end - start) + 1 : 0); |
| 82 | } |
| 83 | if (drv) |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 84 | trace_seq_printf(s, " %s\n", drv->name); |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 85 | else |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 86 | trace_seq_puts(s, " \n"); |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 87 | } |
| 88 | |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 89 | static void destroy_header_iter(struct header_iter *hiter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 90 | { |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 91 | if (!hiter) |
| 92 | return; |
| 93 | pci_dev_put(hiter->dev); |
| 94 | kfree(hiter); |
| 95 | } |
| 96 | |
| 97 | static void mmio_pipe_open(struct trace_iterator *iter) |
| 98 | { |
| 99 | struct header_iter *hiter; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 100 | struct trace_seq *s = &iter->seq; |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 101 | |
zhangwei(Jovi) | 146c344 | 2013-07-15 16:32:44 +0800 | [diff] [blame] | 102 | trace_seq_puts(s, "VERSION 20070824\n"); |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 103 | |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 104 | 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! */ |
| 113 | static 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 Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 120 | static unsigned long count_overruns(struct trace_iterator *iter) |
| 121 | { |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 122 | unsigned long cnt = atomic_xchg(&dropped_count, 0); |
Steven Rostedt (VMware) | 1c5eb44 | 2020-01-09 18:53:48 -0500 | [diff] [blame] | 123 | unsigned long over = ring_buffer_overruns(iter->array_buffer->buffer); |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 124 | |
| 125 | if (over > prev_overruns) |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 126 | cnt += over - prev_overruns; |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 127 | prev_overruns = over; |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 128 | return cnt; |
| 129 | } |
| 130 | |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 131 | static 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 Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 137 | 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 Perches | a395d6a | 2016-03-22 14:28:09 -0700 | [diff] [blame] | 144 | pr_warn("mmiotrace has lost events\n"); |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 145 | overrun_detected = true; |
| 146 | goto print_out; |
| 147 | } |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 148 | |
| 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 Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 160 | print_out: |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 161 | ret = trace_seq_to_user(s, ubuf, cnt); |
| 162 | return (ret == -EBUSY) ? 0 : ret; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 165 | static enum print_line_t mmio_print_rw(struct trace_iterator *iter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 166 | { |
| 167 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 168 | struct trace_mmiotrace_rw *field; |
| 169 | struct mmiotrace_rw *rw; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 170 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 171 | unsigned long long t = ns2usecs(iter->ts); |
Li Zefan | a5dec55 | 2009-03-27 14:55:44 +0800 | [diff] [blame] | 172 | unsigned long usec_rem = do_div(t, USEC_PER_SEC); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 173 | unsigned secs = (unsigned long)t; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 174 | |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 175 | trace_assign_type(field, entry); |
| 176 | rw = &field->rw; |
| 177 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 178 | switch (rw->opcode) { |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 179 | case MMIO_READ: |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 180 | trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 181 | "R %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n", |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 182 | rw->width, secs, usec_rem, rw->map_id, |
| 183 | (unsigned long long)rw->phys, |
Pekka Paalanen | 736ca61 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 184 | rw->value, rw->pc, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 185 | break; |
| 186 | case MMIO_WRITE: |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 187 | trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 188 | "W %d %u.%06lu %d 0x%llx 0x%lx 0x%lx %d\n", |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 189 | rw->width, secs, usec_rem, rw->map_id, |
| 190 | (unsigned long long)rw->phys, |
Pekka Paalanen | 736ca61 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 191 | rw->value, rw->pc, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 192 | break; |
| 193 | case MMIO_UNKNOWN_OP: |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 194 | trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 195 | "UNKNOWN %u.%06lu %d 0x%llx %02lx,%02lx," |
| 196 | "%02lx 0x%lx %d\n", |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 197 | secs, usec_rem, rw->map_id, |
| 198 | (unsigned long long)rw->phys, |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 199 | (rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff, |
Pekka Paalanen | 736ca61 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 200 | (rw->value >> 0) & 0xff, rw->pc, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 201 | break; |
| 202 | default: |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 203 | trace_seq_puts(s, "rw what?\n"); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 204 | break; |
| 205 | } |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 206 | |
| 207 | return trace_handle_return(s); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 208 | } |
| 209 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 210 | static enum print_line_t mmio_print_map(struct trace_iterator *iter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 211 | { |
| 212 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 213 | struct trace_mmiotrace_map *field; |
| 214 | struct mmiotrace_map *m; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 215 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 216 | unsigned long long t = ns2usecs(iter->ts); |
Li Zefan | a5dec55 | 2009-03-27 14:55:44 +0800 | [diff] [blame] | 217 | unsigned long usec_rem = do_div(t, USEC_PER_SEC); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 218 | unsigned secs = (unsigned long)t; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 219 | |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 220 | trace_assign_type(field, entry); |
| 221 | m = &field->map; |
| 222 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 223 | switch (m->opcode) { |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 224 | case MMIO_PROBE: |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 225 | trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 226 | "MAP %u.%06lu %d 0x%llx 0x%lx 0x%lx 0x%lx %d\n", |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 227 | secs, usec_rem, m->map_id, |
| 228 | (unsigned long long)m->phys, m->virt, m->len, |
Pekka Paalanen | e0fd5c2 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 229 | 0UL, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 230 | break; |
| 231 | case MMIO_UNPROBE: |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 232 | trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 233 | "UNMAP %u.%06lu %d 0x%lx %d\n", |
Pekka Paalanen | e0fd5c2 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 234 | secs, usec_rem, m->map_id, 0UL, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 235 | break; |
| 236 | default: |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 237 | trace_seq_puts(s, "map what?\n"); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 238 | break; |
| 239 | } |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 240 | |
| 241 | return trace_handle_return(s); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 242 | } |
| 243 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 244 | static enum print_line_t mmio_print_mark(struct trace_iterator *iter) |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 245 | { |
| 246 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 247 | struct print_entry *print = (struct print_entry *)entry; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 248 | const char *msg = print->buf; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 249 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 250 | unsigned long long t = ns2usecs(iter->ts); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 251 | unsigned long usec_rem = do_div(t, USEC_PER_SEC); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 252 | unsigned secs = (unsigned long)t; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 253 | |
| 254 | /* The trailing newline must be in the message. */ |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 255 | trace_seq_printf(s, "MARK %u.%06lu %s", secs, usec_rem, msg); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 256 | |
Steven Rostedt (Red Hat) | a72e10a | 2014-11-12 16:26:06 -0500 | [diff] [blame] | 257 | return trace_handle_return(s); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 258 | } |
| 259 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 260 | static enum print_line_t mmio_print_line(struct trace_iterator *iter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 261 | { |
| 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 Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 267 | case TRACE_PRINT: |
| 268 | return mmio_print_mark(iter); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 269 | default: |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 270 | return TRACE_TYPE_HANDLED; /* ignore unknown entries */ |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 271 | } |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static struct tracer mmio_tracer __read_mostly = |
| 275 | { |
| 276 | .name = "mmiotrace", |
| 277 | .init = mmio_trace_init, |
| 278 | .reset = mmio_trace_reset, |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 279 | .start = mmio_trace_start, |
Pekka Paalanen | d0a7e8ca | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 280 | .pipe_open = mmio_pipe_open, |
| 281 | .close = mmio_close, |
| 282 | .read = mmio_read, |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 283 | .print_line = mmio_print_line, |
Ziqian SUN (Zamir) | c7b3ae0 | 2017-09-11 14:26:35 +0800 | [diff] [blame] | 284 | .noboot = true, |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 285 | }; |
| 286 | |
| 287 | __init static int init_mmio_trace(void) |
| 288 | { |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 289 | return register_tracer(&mmio_tracer); |
| 290 | } |
| 291 | device_initcall(init_mmio_trace); |
| 292 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 293 | static void __trace_mmiotrace_rw(struct trace_array *tr, |
| 294 | struct trace_array_cpu *data, |
| 295 | struct mmiotrace_rw *rw) |
| 296 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 297 | struct trace_event_call *call = &event_mmiotrace_rw; |
Steven Rostedt (VMware) | 1329249 | 2019-12-13 13:58:57 -0500 | [diff] [blame] | 298 | struct trace_buffer *buffer = tr->array_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 299 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 300 | struct trace_mmiotrace_rw *entry; |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 301 | unsigned int trace_ctx; |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 302 | |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 303 | trace_ctx = tracing_gen_ctx_flags(0); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 304 | event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW, |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 305 | sizeof(*entry), trace_ctx); |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 306 | if (!event) { |
| 307 | atomic_inc(&dropped_count); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 308 | return; |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 309 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 310 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 311 | entry->rw = *rw; |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 312 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 313 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 314 | trace_buffer_unlock_commit(tr, buffer, event, trace_ctx); |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 315 | } |
| 316 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 317 | void mmio_trace_rw(struct mmiotrace_rw *rw) |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 318 | { |
| 319 | struct trace_array *tr = mmio_trace_array; |
Steven Rostedt (VMware) | 1c5eb44 | 2020-01-09 18:53:48 -0500 | [diff] [blame] | 320 | struct trace_array_cpu *data = per_cpu_ptr(tr->array_buffer.data, smp_processor_id()); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 321 | __trace_mmiotrace_rw(tr, data, rw); |
| 322 | } |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 323 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 324 | static void __trace_mmiotrace_map(struct trace_array *tr, |
| 325 | struct trace_array_cpu *data, |
| 326 | struct mmiotrace_map *map) |
| 327 | { |
Steven Rostedt (Red Hat) | 2425bcb | 2015-05-05 11:45:27 -0400 | [diff] [blame] | 328 | struct trace_event_call *call = &event_mmiotrace_map; |
Steven Rostedt (VMware) | 1329249 | 2019-12-13 13:58:57 -0500 | [diff] [blame] | 329 | struct trace_buffer *buffer = tr->array_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 330 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 331 | struct trace_mmiotrace_map *entry; |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 332 | unsigned int trace_ctx; |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 333 | |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 334 | trace_ctx = tracing_gen_ctx_flags(0); |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 335 | event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP, |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 336 | sizeof(*entry), trace_ctx); |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 337 | if (!event) { |
| 338 | atomic_inc(&dropped_count); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 339 | return; |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 340 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 341 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 342 | entry->map = *map; |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 343 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 344 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Sebastian Andrzej Siewior | 36590c50 | 2021-01-25 20:45:08 +0100 | [diff] [blame] | 345 | trace_buffer_unlock_commit(tr, buffer, event, trace_ctx); |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 346 | } |
| 347 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 348 | void 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) | 1c5eb44 | 2020-01-09 18:53:48 -0500 | [diff] [blame] | 354 | data = per_cpu_ptr(tr->array_buffer.data, smp_processor_id()); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 355 | __trace_mmiotrace_map(tr, data, map); |
| 356 | preempt_enable(); |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 357 | } |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 358 | |
| 359 | int mmio_trace_printk(const char *fmt, va_list args) |
| 360 | { |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 361 | return trace_vprintk(0, fmt, args); |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 362 | } |