blob: 601b8c8e32acd308517df820d9e479072a0fa4eb [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{
12 ulong start, size, offset, count;
13
14 printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis");
15 iotrace_get_buffer(&start, &size, &offset, &count);
16 printf("Start: %08lx\n", start);
17 printf("Size: %08lx\n", size);
Ramon Friedb559c4a2018-05-30 23:09:57 +030018 iotrace_get_region(&start, &size);
19 printf("Region: %08lx\n", start);
20 printf("Size: %08lx\n", size);
Simon Glassaa532332014-06-11 23:29:41 -060021 printf("Offset: %08lx\n", offset);
22 printf("Output: %08lx\n", start + offset);
23 printf("Count: %08lx\n", count);
24 printf("CRC32: %08lx\n", (ulong)iotrace_get_checksum());
25}
26
27static int do_set_buffer(int argc, char * const argv[])
28{
29 ulong addr = 0, size = 0;
30
31 if (argc == 2) {
32 addr = simple_strtoul(*argv++, NULL, 16);
33 size = simple_strtoul(*argv++, NULL, 16);
34 } else if (argc != 0) {
35 return CMD_RET_USAGE;
36 }
37
38 iotrace_set_buffer(addr, size);
39
40 return 0;
41}
42
Ramon Friedb559c4a2018-05-30 23:09:57 +030043static int do_set_region(int argc, char * const argv[])
44{
45 ulong addr = 0, size = 0;
46
47 if (argc == 2) {
48 addr = simple_strtoul(*argv++, NULL, 16);
49 size = simple_strtoul(*argv++, NULL, 16);
50 } else if (argc != 0) {
51 return CMD_RET_USAGE;
52 }
53
54 iotrace_set_region(addr, size);
55
56 return 0;
57}
58
Simon Glassaa532332014-06-11 23:29:41 -060059int do_iotrace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
60{
61 const char *cmd = argc < 2 ? NULL : argv[1];
62
63 if (!cmd)
64 return cmd_usage(cmdtp);
65 switch (*cmd) {
66 case 'b':
67 return do_set_buffer(argc - 2, argv + 2);
Ramon Friedb559c4a2018-05-30 23:09:57 +030068 case 'l':
69 return do_set_region(argc - 2, argv + 2);
Simon Glassaa532332014-06-11 23:29:41 -060070 case 'p':
71 iotrace_set_enabled(0);
72 break;
73 case 'r':
74 iotrace_set_enabled(1);
75 break;
76 case 's':
77 do_print_stats();
78 break;
79 default:
80 return CMD_RET_USAGE;
81 }
82
83 return 0;
84}
85
86U_BOOT_CMD(
87 iotrace, 4, 1, do_iotrace,
88 "iotrace utility commands",
89 "stats - display iotrace stats\n"
90 "iotrace buffer <address> <size> - set iotrace buffer\n"
Ramon Friedb559c4a2018-05-30 23:09:57 +030091 "iotrace limit <address> <size> - set iotrace region limit\n"
Simon Glassaa532332014-06-11 23:29:41 -060092 "iotrace pause - pause tracing\n"
93 "iotrace resume - resume tracing"
94);