blob: 0a041ed8652a661aefccefa2dbef83f767d21ad8 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass4dc47ca2014-06-11 23:29:41 -06002/*
3 * Copyright (c) 2014 Google, Inc
Simon Glass4dc47ca2014-06-11 23:29:41 -06004 */
5
Simon Glass4dc47ca2014-06-11 23:29:41 -06006#include <command.h>
7#include <iotrace.h>
Tom Rini5c1444f2024-04-27 08:10:59 -06008#include <vsprintf.h>
Simon Glass4dc47ca2014-06-11 23:29:41 -06009
10static void do_print_stats(void)
11{
Ramon Fried75aa8982018-06-08 20:53:27 +030012 ulong start, size, needed_size, offset, count;
Simon Glass4dc47ca2014-06-11 23:29:41 -060013
14 printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis");
Ramon Fried75aa8982018-06-08 20:53:27 +030015 iotrace_get_buffer(&start, &size, &needed_size, &offset, &count);
Simon Glass4dc47ca2014-06-11 23:29:41 -060016 printf("Start: %08lx\n", start);
Ramon Fried75aa8982018-06-08 20:53:27 +030017 printf("Actual Size: %08lx\n", size);
18 printf("Needed Size: %08lx\n", needed_size);
Ramon Fried06048b02018-05-30 23:09:57 +030019 iotrace_get_region(&start, &size);
20 printf("Region: %08lx\n", start);
21 printf("Size: %08lx\n", size);
Simon Glass4dc47ca2014-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 Friedf015eb52018-06-08 20:53:26 +030028static void do_print_trace(void)
29{
Ramon Fried75aa8982018-06-08 20:53:27 +030030 ulong start, size, needed_size, offset, count;
Ramon Friedf015eb52018-06-08 20:53:26 +030031
32 struct iotrace_record *cur_record;
33
Ramon Fried75aa8982018-06-08 20:53:27 +030034 iotrace_get_buffer(&start, &size, &needed_size, &offset, &count);
Ramon Friedf015eb52018-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 Glassed38aef2020-05-10 11:40:03 -060058static int do_set_buffer(int argc, char *const argv[])
Simon Glass4dc47ca2014-06-11 23:29:41 -060059{
60 ulong addr = 0, size = 0;
61
62 if (argc == 2) {
Simon Glass3ff49ec2021-07-24 09:03:29 -060063 addr = hextoul(*argv++, NULL);
64 size = hextoul(*argv++, NULL);
Simon Glass4dc47ca2014-06-11 23:29:41 -060065 } else if (argc != 0) {
66 return CMD_RET_USAGE;
67 }
68
69 iotrace_set_buffer(addr, size);
70
71 return 0;
72}
73
Simon Glassed38aef2020-05-10 11:40:03 -060074static int do_set_region(int argc, char *const argv[])
Ramon Fried06048b02018-05-30 23:09:57 +030075{
76 ulong addr = 0, size = 0;
77
78 if (argc == 2) {
Simon Glass3ff49ec2021-07-24 09:03:29 -060079 addr = hextoul(*argv++, NULL);
80 size = hextoul(*argv++, NULL);
Ramon Fried06048b02018-05-30 23:09:57 +030081 } else if (argc != 0) {
82 return CMD_RET_USAGE;
83 }
84
85 iotrace_set_region(addr, size);
86
87 return 0;
88}
89
Simon Glassed38aef2020-05-10 11:40:03 -060090int do_iotrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Simon Glass4dc47ca2014-06-11 23:29:41 -060091{
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 Fried06048b02018-05-30 23:09:57 +030099 case 'l':
100 return do_set_region(argc - 2, argv + 2);
Simon Glass4dc47ca2014-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 Friedf015eb52018-06-08 20:53:26 +0300110 case 'd':
111 do_print_trace();
112 break;
Simon Glass4dc47ca2014-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 Fried06048b02018-05-30 23:09:57 +0300125 "iotrace limit <address> <size> - set iotrace region limit\n"
Simon Glass4dc47ca2014-06-11 23:29:41 -0600126 "iotrace pause - pause tracing\n"
Ramon Friedf015eb52018-06-08 20:53:26 +0300127 "iotrace resume - resume tracing\n"
128 "iotrace dump - dump iotrace buffer"
Simon Glass4dc47ca2014-06-11 23:29:41 -0600129);