2 * Memory mapped I/O tracing
4 * Copyright (C) 2008 Pekka Paalanen <pq@iki.fi>
9 #include <linux/kernel.h>
10 #include <linux/mmiotrace.h>
14 static struct trace_array *mmio_trace_array;
16 static void mmio_reset_data(struct trace_array *tr)
20 tr->time_start = ftrace_now(tr->cpu);
22 for_each_online_cpu(cpu)
23 tracing_reset(tr->data[cpu]);
26 static void mmio_trace_init(struct trace_array *tr)
28 pr_debug("in %s\n", __func__);
29 mmio_trace_array = tr;
36 static void mmio_trace_reset(struct trace_array *tr)
38 pr_debug("in %s\n", __func__);
42 mmio_trace_array = NULL;
45 static void mmio_trace_ctrl_update(struct trace_array *tr)
47 pr_debug("in %s\n", __func__);
56 /* XXX: This is not called for trace_pipe file! */
57 void mmio_print_header(struct trace_iterator *iter)
59 struct trace_seq *s = &iter->seq;
60 trace_seq_printf(s, "VERSION broken 20070824\n");
61 /* TODO: print /proc/bus/pci/devices contents as PCIDEV lines */
64 static int mmio_print_rw(struct trace_iterator *iter)
66 struct trace_entry *entry = iter->ent;
67 struct mmiotrace_rw *rw = &entry->mmiorw;
68 struct trace_seq *s = &iter->seq;
69 unsigned long long t = ns2usecs(entry->t);
70 unsigned long usec_rem = do_div(t, 1000000ULL);
71 unsigned secs = (unsigned long)t;
74 switch (entry->mmiorw.opcode) {
76 ret = trace_seq_printf(s,
77 "R %d %lu.%06lu %d 0x%lx 0x%lx 0x%lx %d\n",
78 rw->width, secs, usec_rem, rw->map_id, rw->phys,
79 rw->value, rw->pc, entry->pid);
82 ret = trace_seq_printf(s,
83 "W %d %lu.%06lu %d 0x%lx 0x%lx 0x%lx %d\n",
84 rw->width, secs, usec_rem, rw->map_id, rw->phys,
85 rw->value, rw->pc, entry->pid);
88 ret = trace_seq_printf(s,
89 "UNKNOWN %lu.%06lu %d 0x%lx %02x,%02x,%02x 0x%lx %d\n",
90 secs, usec_rem, rw->map_id, rw->phys,
91 (rw->value >> 16) & 0xff, (rw->value >> 8) & 0xff,
92 (rw->value >> 0) & 0xff, rw->pc, entry->pid);
95 ret = trace_seq_printf(s, "rw what?\n");
103 static int mmio_print_map(struct trace_iterator *iter)
105 struct trace_entry *entry = iter->ent;
106 struct mmiotrace_map *m = &entry->mmiomap;
107 struct trace_seq *s = &iter->seq;
108 unsigned long long t = ns2usecs(entry->t);
109 unsigned long usec_rem = do_div(t, 1000000ULL);
110 unsigned secs = (unsigned long)t;
113 switch (entry->mmiorw.opcode) {
115 ret = trace_seq_printf(s,
116 "MAP %lu.%06lu %d 0x%lx 0x%lx 0x%lx 0x%lx %d\n",
117 secs, usec_rem, m->map_id, m->phys, m->virt, m->len,
121 ret = trace_seq_printf(s,
122 "UNMAP %lu.%06lu %d 0x%lx %d\n",
123 secs, usec_rem, m->map_id, 0UL, entry->pid);
126 ret = trace_seq_printf(s, "map what?\n");
134 /* return 0 to abort printing without consuming current entry in pipe mode */
135 static int mmio_print_line(struct trace_iterator *iter)
137 switch (iter->ent->type) {
139 return mmio_print_rw(iter);
141 return mmio_print_map(iter);
143 return 1; /* ignore unknown entries */
147 static struct tracer mmio_tracer __read_mostly =
150 .init = mmio_trace_init,
151 .reset = mmio_trace_reset,
152 .open = mmio_print_header,
153 .ctrl_update = mmio_trace_ctrl_update,
154 .print_line = mmio_print_line,
157 __init static int init_mmio_trace(void)
159 return register_tracer(&mmio_tracer);
161 device_initcall(init_mmio_trace);
163 void mmio_trace_rw(struct mmiotrace_rw *rw)
165 struct trace_array *tr = mmio_trace_array;
166 struct trace_array_cpu *data = tr->data[smp_processor_id()];
167 __trace_mmiotrace_rw(tr, data, rw);
170 void mmio_trace_mapping(struct mmiotrace_map *map)
172 struct trace_array *tr = mmio_trace_array;
173 struct trace_array_cpu *data;
176 data = tr->data[smp_processor_id()];
177 __trace_mmiotrace_map(tr, data, map);