xref: /openbmc/u-boot/cmd/iotrace.c (revision 8ee59472)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2014 Google, Inc
4  */
5 
6 #include <common.h>
7 #include <command.h>
8 #include <iotrace.h>
9 
10 static 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);
18 	printf("Offset: %08lx\n", offset);
19 	printf("Output: %08lx\n", start + offset);
20 	printf("Count:  %08lx\n", count);
21 	printf("CRC32:  %08lx\n", (ulong)iotrace_get_checksum());
22 }
23 
24 static int do_set_buffer(int argc, char * const argv[])
25 {
26 	ulong addr = 0, size = 0;
27 
28 	if (argc == 2) {
29 		addr = simple_strtoul(*argv++, NULL, 16);
30 		size = simple_strtoul(*argv++, NULL, 16);
31 	} else if (argc != 0) {
32 		return CMD_RET_USAGE;
33 	}
34 
35 	iotrace_set_buffer(addr, size);
36 
37 	return 0;
38 }
39 
40 int do_iotrace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
41 {
42 	const char *cmd = argc < 2 ? NULL : argv[1];
43 
44 	if (!cmd)
45 		return cmd_usage(cmdtp);
46 	switch (*cmd) {
47 	case 'b':
48 		return do_set_buffer(argc - 2, argv + 2);
49 	case 'p':
50 		iotrace_set_enabled(0);
51 		break;
52 	case 'r':
53 		iotrace_set_enabled(1);
54 		break;
55 	case 's':
56 		do_print_stats();
57 		break;
58 	default:
59 		return CMD_RET_USAGE;
60 	}
61 
62 	return 0;
63 }
64 
65 U_BOOT_CMD(
66 	iotrace,	4,	1,	do_iotrace,
67 	"iotrace utility commands",
68 	"stats                        - display iotrace stats\n"
69 	"iotrace buffer <address> <size>      - set iotrace buffer\n"
70 	"iotrace pause                        - pause tracing\n"
71 	"iotrace resume                       - resume tracing"
72 );
73