Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Memory mapped I/O tracing |
| 3 | * |
| 4 | * Copyright (C) 2008 Pekka Paalanen <pq@iki.fi> |
| 5 | */ |
| 6 | |
| 7 | #define DEBUG 1 |
| 8 | |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/mmiotrace.h> |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 11 | #include <linux/pci.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Li Zefan | a5dec55 | 2009-03-27 14:55:44 +0800 | [diff] [blame] | 13 | #include <linux/time.h> |
| 14 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 15 | #include <linux/atomic.h> |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 16 | |
| 17 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 18 | #include "trace_output.h" |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 19 | |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 20 | struct header_iter { |
| 21 | struct pci_dev *dev; |
| 22 | }; |
| 23 | |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 24 | static struct trace_array *mmio_trace_array; |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 25 | static bool overrun_detected; |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 26 | static unsigned long prev_overruns; |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 27 | static atomic_t dropped_count; |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 28 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 29 | static void mmio_reset_data(struct trace_array *tr) |
| 30 | { |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 31 | overrun_detected = false; |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 32 | prev_overruns = 0; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 33 | |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 34 | tracing_reset_online_cpus(&tr->trace_buffer); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 35 | } |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 36 | |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 37 | static int mmio_trace_init(struct trace_array *tr) |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 38 | { |
| 39 | pr_debug("in %s\n", __func__); |
| 40 | mmio_trace_array = tr; |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 41 | |
| 42 | mmio_reset_data(tr); |
| 43 | enable_mmiotrace(); |
Frederic Weisbecker | 1c80025 | 2008-11-16 05:57:26 +0100 | [diff] [blame] | 44 | return 0; |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void mmio_trace_reset(struct trace_array *tr) |
| 48 | { |
| 49 | pr_debug("in %s\n", __func__); |
Steven Rostedt | c76f069 | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 50 | |
| 51 | disable_mmiotrace(); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 52 | mmio_reset_data(tr); |
| 53 | mmio_trace_array = NULL; |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 56 | static void mmio_trace_start(struct trace_array *tr) |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 57 | { |
| 58 | pr_debug("in %s\n", __func__); |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 59 | mmio_reset_data(tr); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 62 | static int mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev) |
| 63 | { |
| 64 | int ret = 0; |
| 65 | int i; |
| 66 | resource_size_t start, end; |
| 67 | const struct pci_driver *drv = pci_dev_driver(dev); |
| 68 | |
| 69 | /* XXX: incomplete checks for trace_seq_printf() return value */ |
| 70 | ret += trace_seq_printf(s, "PCIDEV %02x%02x %04x%04x %x", |
| 71 | dev->bus->number, dev->devfn, |
| 72 | dev->vendor, dev->device, dev->irq); |
| 73 | /* |
| 74 | * XXX: is pci_resource_to_user() appropriate, since we are |
| 75 | * supposed to interpret the __ioremap() phys_addr argument based on |
| 76 | * these printed values? |
| 77 | */ |
| 78 | for (i = 0; i < 7; i++) { |
| 79 | pci_resource_to_user(dev, i, &dev->resource[i], &start, &end); |
| 80 | ret += trace_seq_printf(s, " %llx", |
| 81 | (unsigned long long)(start | |
| 82 | (dev->resource[i].flags & PCI_REGION_FLAG_MASK))); |
| 83 | } |
| 84 | for (i = 0; i < 7; i++) { |
| 85 | pci_resource_to_user(dev, i, &dev->resource[i], &start, &end); |
| 86 | ret += trace_seq_printf(s, " %llx", |
| 87 | dev->resource[i].start < dev->resource[i].end ? |
| 88 | (unsigned long long)(end - start) + 1 : 0); |
| 89 | } |
| 90 | if (drv) |
| 91 | ret += trace_seq_printf(s, " %s\n", drv->name); |
| 92 | else |
zhangwei(Jovi) | 146c344 | 2013-07-15 16:32:44 +0800 | [diff] [blame] | 93 | ret += trace_seq_puts(s, " \n"); |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 94 | return ret; |
| 95 | } |
| 96 | |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 97 | static void destroy_header_iter(struct header_iter *hiter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 98 | { |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 99 | if (!hiter) |
| 100 | return; |
| 101 | pci_dev_put(hiter->dev); |
| 102 | kfree(hiter); |
| 103 | } |
| 104 | |
| 105 | static void mmio_pipe_open(struct trace_iterator *iter) |
| 106 | { |
| 107 | struct header_iter *hiter; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 108 | struct trace_seq *s = &iter->seq; |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 109 | |
zhangwei(Jovi) | 146c344 | 2013-07-15 16:32:44 +0800 | [diff] [blame] | 110 | trace_seq_puts(s, "VERSION 20070824\n"); |
Pekka Paalanen | 1382953 | 2008-05-12 21:20:58 +0200 | [diff] [blame] | 111 | |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 112 | hiter = kzalloc(sizeof(*hiter), GFP_KERNEL); |
| 113 | if (!hiter) |
| 114 | return; |
| 115 | |
| 116 | hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); |
| 117 | iter->private = hiter; |
| 118 | } |
| 119 | |
| 120 | /* XXX: This is not called when the pipe is closed! */ |
| 121 | static void mmio_close(struct trace_iterator *iter) |
| 122 | { |
| 123 | struct header_iter *hiter = iter->private; |
| 124 | destroy_header_iter(hiter); |
| 125 | iter->private = NULL; |
| 126 | } |
| 127 | |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 128 | static unsigned long count_overruns(struct trace_iterator *iter) |
| 129 | { |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 130 | unsigned long cnt = atomic_xchg(&dropped_count, 0); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 131 | unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer); |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 132 | |
| 133 | if (over > prev_overruns) |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 134 | cnt += over - prev_overruns; |
Pekka Paalanen | 7ee1768 | 2008-11-23 21:24:30 +0200 | [diff] [blame] | 135 | prev_overruns = over; |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 136 | return cnt; |
| 137 | } |
| 138 | |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 139 | static ssize_t mmio_read(struct trace_iterator *iter, struct file *filp, |
| 140 | char __user *ubuf, size_t cnt, loff_t *ppos) |
| 141 | { |
| 142 | ssize_t ret; |
| 143 | struct header_iter *hiter = iter->private; |
| 144 | struct trace_seq *s = &iter->seq; |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 145 | unsigned long n; |
| 146 | |
| 147 | n = count_overruns(iter); |
| 148 | if (n) { |
| 149 | /* XXX: This is later than where events were lost. */ |
| 150 | trace_seq_printf(s, "MARK 0.000000 Lost %lu events.\n", n); |
| 151 | if (!overrun_detected) |
| 152 | pr_warning("mmiotrace has lost events.\n"); |
| 153 | overrun_detected = true; |
| 154 | goto print_out; |
| 155 | } |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 156 | |
| 157 | if (!hiter) |
| 158 | return 0; |
| 159 | |
| 160 | mmio_print_pcidev(s, hiter->dev); |
| 161 | hiter->dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, hiter->dev); |
| 162 | |
| 163 | if (!hiter->dev) { |
| 164 | destroy_header_iter(hiter); |
| 165 | iter->private = NULL; |
| 166 | } |
| 167 | |
Pekka Paalanen | 2039238 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 168 | print_out: |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 169 | ret = trace_seq_to_user(s, ubuf, cnt); |
| 170 | return (ret == -EBUSY) ? 0 : ret; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 171 | } |
| 172 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 173 | static enum print_line_t mmio_print_rw(struct trace_iterator *iter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 174 | { |
| 175 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 176 | struct trace_mmiotrace_rw *field; |
| 177 | struct mmiotrace_rw *rw; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 178 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 179 | unsigned long long t = ns2usecs(iter->ts); |
Li Zefan | a5dec55 | 2009-03-27 14:55:44 +0800 | [diff] [blame] | 180 | unsigned long usec_rem = do_div(t, USEC_PER_SEC); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 181 | unsigned secs = (unsigned long)t; |
| 182 | int ret = 1; |
| 183 | |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 184 | trace_assign_type(field, entry); |
| 185 | rw = &field->rw; |
| 186 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 187 | switch (rw->opcode) { |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 188 | case MMIO_READ: |
| 189 | ret = trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 190 | "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] | 191 | rw->width, secs, usec_rem, rw->map_id, |
| 192 | (unsigned long long)rw->phys, |
Pekka Paalanen | 736ca61 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 193 | rw->value, rw->pc, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 194 | break; |
| 195 | case MMIO_WRITE: |
| 196 | ret = trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 197 | "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] | 198 | rw->width, secs, usec_rem, rw->map_id, |
| 199 | (unsigned long long)rw->phys, |
Pekka Paalanen | 736ca61 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 200 | rw->value, rw->pc, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 201 | break; |
| 202 | case MMIO_UNKNOWN_OP: |
| 203 | ret = trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 204 | "UNKNOWN %u.%06lu %d 0x%llx %02lx,%02lx," |
| 205 | "%02lx 0x%lx %d\n", |
Pekka Paalanen | dee310d | 2008-05-12 21:21:03 +0200 | [diff] [blame] | 206 | secs, usec_rem, rw->map_id, |
| 207 | (unsigned long long)rw->phys, |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 208 | (rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff, |
Pekka Paalanen | 736ca61 | 2008-05-12 21:20:59 +0200 | [diff] [blame] | 209 | (rw->value >> 0) & 0xff, rw->pc, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 210 | break; |
| 211 | default: |
zhangwei(Jovi) | 146c344 | 2013-07-15 16:32:44 +0800 | [diff] [blame] | 212 | ret = trace_seq_puts(s, "rw what?\n"); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | if (ret) |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 216 | return TRACE_TYPE_HANDLED; |
| 217 | return TRACE_TYPE_PARTIAL_LINE; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 220 | static enum print_line_t mmio_print_map(struct trace_iterator *iter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 221 | { |
| 222 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 223 | struct trace_mmiotrace_map *field; |
| 224 | struct mmiotrace_map *m; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 225 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 226 | unsigned long long t = ns2usecs(iter->ts); |
Li Zefan | a5dec55 | 2009-03-27 14:55:44 +0800 | [diff] [blame] | 227 | unsigned long usec_rem = do_div(t, USEC_PER_SEC); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 228 | unsigned secs = (unsigned long)t; |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 229 | int ret; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 230 | |
Steven Rostedt | 7104f30 | 2008-10-01 10:52:51 -0400 | [diff] [blame] | 231 | trace_assign_type(field, entry); |
| 232 | m = &field->map; |
| 233 | |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 234 | switch (m->opcode) { |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 235 | case MMIO_PROBE: |
| 236 | ret = trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 237 | "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] | 238 | secs, usec_rem, m->map_id, |
| 239 | (unsigned long long)m->phys, m->virt, m->len, |
Pekka Paalanen | e0fd5c2 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 240 | 0UL, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 241 | break; |
| 242 | case MMIO_UNPROBE: |
| 243 | ret = trace_seq_printf(s, |
Steven Rostedt | 5e4abc9 | 2009-01-15 21:00:50 -0500 | [diff] [blame] | 244 | "UNMAP %u.%06lu %d 0x%lx %d\n", |
Pekka Paalanen | e0fd5c2 | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 245 | secs, usec_rem, m->map_id, 0UL, 0); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 246 | break; |
| 247 | default: |
zhangwei(Jovi) | 146c344 | 2013-07-15 16:32:44 +0800 | [diff] [blame] | 248 | ret = trace_seq_puts(s, "map what?\n"); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 249 | break; |
| 250 | } |
| 251 | if (ret) |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 252 | return TRACE_TYPE_HANDLED; |
| 253 | return TRACE_TYPE_PARTIAL_LINE; |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 256 | static enum print_line_t mmio_print_mark(struct trace_iterator *iter) |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 257 | { |
| 258 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 259 | struct print_entry *print = (struct print_entry *)entry; |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 260 | const char *msg = print->buf; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 261 | struct trace_seq *s = &iter->seq; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 262 | unsigned long long t = ns2usecs(iter->ts); |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 263 | unsigned long usec_rem = do_div(t, USEC_PER_SEC); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 264 | unsigned secs = (unsigned long)t; |
| 265 | int ret; |
| 266 | |
| 267 | /* The trailing newline must be in the message. */ |
Frederic Weisbecker | 48ead02 | 2009-03-12 18:24:49 +0100 | [diff] [blame] | 268 | ret = trace_seq_printf(s, "MARK %u.%06lu %s", secs, usec_rem, msg); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 269 | if (!ret) |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 270 | return TRACE_TYPE_PARTIAL_LINE; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 271 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 272 | return TRACE_TYPE_HANDLED; |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 273 | } |
| 274 | |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 275 | static enum print_line_t mmio_print_line(struct trace_iterator *iter) |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 276 | { |
| 277 | switch (iter->ent->type) { |
| 278 | case TRACE_MMIO_RW: |
| 279 | return mmio_print_rw(iter); |
| 280 | case TRACE_MMIO_MAP: |
| 281 | return mmio_print_map(iter); |
Pekka Paalanen | fc5e27a | 2008-09-16 22:02:27 +0300 | [diff] [blame] | 282 | case TRACE_PRINT: |
| 283 | return mmio_print_mark(iter); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 284 | default: |
Frederic Weisbecker | 07f4e4f | 2008-09-29 20:27:42 +0200 | [diff] [blame] | 285 | return TRACE_TYPE_HANDLED; /* ignore unknown entries */ |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 286 | } |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static struct tracer mmio_tracer __read_mostly = |
| 290 | { |
| 291 | .name = "mmiotrace", |
| 292 | .init = mmio_trace_init, |
| 293 | .reset = mmio_trace_reset, |
Steven Rostedt | bbf5b1a | 2008-11-07 22:36:02 -0500 | [diff] [blame] | 294 | .start = mmio_trace_start, |
Pekka Paalanen | d0a7e8c | 2008-05-12 21:21:02 +0200 | [diff] [blame] | 295 | .pipe_open = mmio_pipe_open, |
| 296 | .close = mmio_close, |
| 297 | .read = mmio_read, |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 298 | .print_line = mmio_print_line, |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 299 | }; |
| 300 | |
| 301 | __init static int init_mmio_trace(void) |
| 302 | { |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 303 | return register_tracer(&mmio_tracer); |
| 304 | } |
| 305 | device_initcall(init_mmio_trace); |
| 306 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 307 | static void __trace_mmiotrace_rw(struct trace_array *tr, |
| 308 | struct trace_array_cpu *data, |
| 309 | struct mmiotrace_rw *rw) |
| 310 | { |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 311 | struct ftrace_event_call *call = &event_mmiotrace_rw; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 312 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 313 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 314 | struct trace_mmiotrace_rw *entry; |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 315 | int pc = preempt_count(); |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 316 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 317 | event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 318 | sizeof(*entry), 0, pc); |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 319 | if (!event) { |
| 320 | atomic_inc(&dropped_count); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 321 | return; |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 322 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 323 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 324 | entry->rw = *rw; |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 325 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 326 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 327 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 328 | } |
| 329 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 330 | void mmio_trace_rw(struct mmiotrace_rw *rw) |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 331 | { |
| 332 | struct trace_array *tr = mmio_trace_array; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 333 | struct trace_array_cpu *data = per_cpu_ptr(tr->trace_buffer.data, smp_processor_id()); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 334 | __trace_mmiotrace_rw(tr, data, rw); |
| 335 | } |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 336 | |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 337 | static void __trace_mmiotrace_map(struct trace_array *tr, |
| 338 | struct trace_array_cpu *data, |
| 339 | struct mmiotrace_map *map) |
| 340 | { |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 341 | struct ftrace_event_call *call = &event_mmiotrace_map; |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 342 | struct ring_buffer *buffer = tr->trace_buffer.buffer; |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 343 | struct ring_buffer_event *event; |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 344 | struct trace_mmiotrace_map *entry; |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 345 | int pc = preempt_count(); |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 346 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 347 | event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP, |
Arnaldo Carvalho de Melo | 51a763d | 2009-02-05 16:14:13 -0200 | [diff] [blame] | 348 | sizeof(*entry), 0, pc); |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 349 | if (!event) { |
| 350 | atomic_inc(&dropped_count); |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 351 | return; |
Pekka Paalanen | 173ed24 | 2009-01-06 13:57:11 +0200 | [diff] [blame] | 352 | } |
Steven Rostedt | 3928a8a | 2008-09-29 23:02:41 -0400 | [diff] [blame] | 353 | entry = ring_buffer_event_data(event); |
Steven Rostedt | 777e208 | 2008-09-29 23:02:42 -0400 | [diff] [blame] | 354 | entry->map = *map; |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 355 | |
Tom Zanussi | f306cc8 | 2013-10-24 08:34:17 -0500 | [diff] [blame] | 356 | if (!call_filter_check_discard(call, entry, buffer, event)) |
Steven Rostedt | 60ba770 | 2009-09-12 23:34:04 -0400 | [diff] [blame] | 357 | trace_buffer_unlock_commit(buffer, event, 0, pc); |
Pekka Paalanen | 45dcd8b | 2008-09-16 21:56:41 +0300 | [diff] [blame] | 358 | } |
| 359 | |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 360 | void mmio_trace_mapping(struct mmiotrace_map *map) |
| 361 | { |
| 362 | struct trace_array *tr = mmio_trace_array; |
| 363 | struct trace_array_cpu *data; |
| 364 | |
| 365 | preempt_disable(); |
Steven Rostedt (Red Hat) | 12883ef | 2013-03-05 09:24:35 -0500 | [diff] [blame] | 366 | data = per_cpu_ptr(tr->trace_buffer.data, smp_processor_id()); |
Pekka Paalanen | bd8ac68 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 367 | __trace_mmiotrace_map(tr, data, map); |
| 368 | preempt_enable(); |
Pekka Paalanen | f984b51 | 2008-05-12 21:20:57 +0200 | [diff] [blame] | 369 | } |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 370 | |
| 371 | int mmio_trace_printk(const char *fmt, va_list args) |
| 372 | { |
Steven Rostedt | 40ce74f | 2009-03-19 14:03:53 -0400 | [diff] [blame] | 373 | return trace_vprintk(0, fmt, args); |
Pekka Paalanen | 9e57fb3 | 2008-09-16 22:00:34 +0300 | [diff] [blame] | 374 | } |