blob: fa6c68b19825a3f7c934712f3b173bae60e04a7c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassaa532332014-06-11 23:29:41 -06002/*
3 * Copyright (c) 2014 Google, Inc
Simon Glassaa532332014-06-11 23:29:41 -06004 */
5
6#include <common.h>
7#include <command.h>
8#include <iotrace.h>
9
10static void do_print_stats(void)
11{
Ramon Friede0212df2018-06-08 20:53:27 +030012 ulong start, size, needed_size, offset, count;
Simon Glassaa532332014-06-11 23:29:41 -060013
14 printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis");
Ramon Friede0212df2018-06-08 20:53:27 +030015 iotrace_get_buffer(&start, &size, &needed_size, &offset, &count);
Simon Glassaa532332014-06-11 23:29:41 -060016 printf("Start: %08lx\n", start);
Ramon Friede0212df2018-06-08 20:53:27 +030017 printf("Actual Size: %08lx\n", size);
18 printf("Needed Size: %08lx\n", needed_size);
Ramon Friedb559c4a2018-05-30 23:09:57 +030019 iotrace_get_region(&start, &size);
20 printf("Region: %08lx\n", start);
21 printf("Size: %08lx\n", size);
Simon Glassaa532332014-06-11 23:29:41 -060022 printf("Offset: %08lx\n", offset);
23 printf("Output: %08lx\n", start + offset);
24 printf("Count: %08lx\n", count);
25 printf("CRC32: %08lx\n", (ulong)iotrace_get_checksum());
26}
27
Ramon Fried501c89d2018-06-08 20:53:26 +030028static void do_print_trace(void)
29{
Ramon Friede0212df2018-06-08 20:53:27 +030030 ulong start, size, needed_size, offset, count;
Ramon Fried501c89d2018-06-08 20:53:26 +030031
32 struct iotrace_record *cur_record;
33
Ramon Friede0212df2018-06-08 20:53:27 +030034 iotrace_get_buffer(&start, &size, &needed_size, &offset, &count);
Ramon Fried501c89d2018-06-08 20:53:26 +030035
36 if (!start || !size || !count)
37 return;
38
39 printf("Timestamp Value Address\n");
40
41 cur_record = (struct iotrace_record *)start;
42 for (int i = 0; i < count; i++) {
43 if (cur_record->flags & IOT_WRITE)
44 printf("%08llu: 0x%08lx --> 0x%08llx\n",
45 cur_record->timestamp,
46 cur_record->value,
47 (unsigned long long)cur_record->addr);
48 else
49 printf("%08llu: 0x%08lx <-- 0x%08llx\n",
50 cur_record->timestamp,
51 cur_record->value,
52 (unsigned long long)cur_record->addr);
53
54 cur_record++;
55 }
56}
57
Simon Glassaa532332014-06-11 23:29:41 -060058static int do_set_buffer(int argc, char * const argv[])
59{
60 ulong addr = 0, size = 0;
61
62 if (argc == 2) {
63 addr = simple_strtoul(*argv++, NULL, 16);
64 size = simple_strtoul(*argv++, NULL, 16);
65 } else if (argc != 0) {
66 return CMD_RET_USAGE;
67 }
68
69 iotrace_set_buffer(addr, size);
70
71 return 0;
72}
73
Ramon Friedb559c4a2018-05-30 23:09:57 +030074static int do_set_region(int argc, char * const argv[])
75{
76 ulong addr = 0, size = 0;
77
78 if (argc == 2) {
79 addr = simple_strtoul(*argv++, NULL, 16);
80 size = simple_strtoul(*argv++, NULL, 16);
81 } else if (argc != 0) {
82 return CMD_RET_USAGE;
83 }
84
85 iotrace_set_region(addr, size);
86
87 return 0;
88}
89
Simon Glassaa532332014-06-11 23:29:41 -060090int do_iotrace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
91{
92 const char *cmd = argc < 2 ? NULL : argv[1];
93
94 if (!cmd)
95 return cmd_usage(cmdtp);
96 switch (*cmd) {
97 case 'b':
98 return do_set_buffer(argc - 2, argv + 2);
Ramon Friedb559c4a2018-05-30 23:09:57 +030099 case 'l':
100 return do_set_region(argc - 2, argv + 2);
Simon Glassaa532332014-06-11 23:29:41 -0600101 case 'p':
102 iotrace_set_enabled(0);
103 break;
104 case 'r':
105 iotrace_set_enabled(1);
106 break;
107 case 's':
108 do_print_stats();
109 break;
Ramon Fried501c89d2018-06-08 20:53:26 +0300110 case 'd':
111 do_print_trace();
112 break;
Simon Glassaa532332014-06-11 23:29:41 -0600113 default:
114 return CMD_RET_USAGE;
115 }
116
117 return 0;
118}
119
120U_BOOT_CMD(
121 iotrace, 4, 1, do_iotrace,
122 "iotrace utility commands",
123 "stats - display iotrace stats\n"
124 "iotrace buffer <address> <size> - set iotrace buffer\n"
Ramon Friedb559c4a2018-05-30 23:09:57 +0300125 "iotrace limit <address> <size> - set iotrace region limit\n"
Simon Glassaa532332014-06-11 23:29:41 -0600126 "iotrace pause - pause tracing\n"
Ramon Fried501c89d2018-06-08 20:53:26 +0300127 "iotrace resume - resume tracing\n"
128 "iotrace dump - dump iotrace buffer"
Simon Glassaa532332014-06-11 23:29:41 -0600129);