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