Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Google, Inc |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <command.h> |
| 8 | #include <iotrace.h> |
| 9 | |
| 10 | static void do_print_stats(void) |
| 11 | { |
Ramon Fried | e0212df | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 12 | ulong start, size, needed_size, offset, count; |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 13 | |
| 14 | printf("iotrace is %sabled\n", iotrace_get_enabled() ? "en" : "dis"); |
Ramon Fried | e0212df | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 15 | iotrace_get_buffer(&start, &size, &needed_size, &offset, &count); |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 16 | printf("Start: %08lx\n", start); |
Ramon Fried | e0212df | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 17 | printf("Actual Size: %08lx\n", size); |
| 18 | printf("Needed Size: %08lx\n", needed_size); |
Ramon Fried | b559c4a | 2018-05-30 23:09:57 +0300 | [diff] [blame] | 19 | iotrace_get_region(&start, &size); |
| 20 | printf("Region: %08lx\n", start); |
| 21 | printf("Size: %08lx\n", size); |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 22 | 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 Fried | 501c89d | 2018-06-08 20:53:26 +0300 | [diff] [blame] | 28 | static void do_print_trace(void) |
| 29 | { |
Ramon Fried | e0212df | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 30 | ulong start, size, needed_size, offset, count; |
Ramon Fried | 501c89d | 2018-06-08 20:53:26 +0300 | [diff] [blame] | 31 | |
| 32 | struct iotrace_record *cur_record; |
| 33 | |
Ramon Fried | e0212df | 2018-06-08 20:53:27 +0300 | [diff] [blame] | 34 | iotrace_get_buffer(&start, &size, &needed_size, &offset, &count); |
Ramon Fried | 501c89d | 2018-06-08 20:53:26 +0300 | [diff] [blame] | 35 | |
| 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 Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 58 | static int do_set_buffer(int argc, char *const argv[]) |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 59 | { |
| 60 | ulong addr = 0, size = 0; |
| 61 | |
| 62 | if (argc == 2) { |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 63 | addr = hextoul(*argv++, NULL); |
| 64 | size = hextoul(*argv++, NULL); |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 65 | } else if (argc != 0) { |
| 66 | return CMD_RET_USAGE; |
| 67 | } |
| 68 | |
| 69 | iotrace_set_buffer(addr, size); |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 74 | static int do_set_region(int argc, char *const argv[]) |
Ramon Fried | b559c4a | 2018-05-30 23:09:57 +0300 | [diff] [blame] | 75 | { |
| 76 | ulong addr = 0, size = 0; |
| 77 | |
| 78 | if (argc == 2) { |
Simon Glass | 7e5f460 | 2021-07-24 09:03:29 -0600 | [diff] [blame] | 79 | addr = hextoul(*argv++, NULL); |
| 80 | size = hextoul(*argv++, NULL); |
Ramon Fried | b559c4a | 2018-05-30 23:09:57 +0300 | [diff] [blame] | 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 Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 90 | int do_iotrace(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 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 Fried | b559c4a | 2018-05-30 23:09:57 +0300 | [diff] [blame] | 99 | case 'l': |
| 100 | return do_set_region(argc - 2, argv + 2); |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 101 | 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 Fried | 501c89d | 2018-06-08 20:53:26 +0300 | [diff] [blame] | 110 | case 'd': |
| 111 | do_print_trace(); |
| 112 | break; |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 113 | default: |
| 114 | return CMD_RET_USAGE; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | U_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 Fried | b559c4a | 2018-05-30 23:09:57 +0300 | [diff] [blame] | 125 | "iotrace limit <address> <size> - set iotrace region limit\n" |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 126 | "iotrace pause - pause tracing\n" |
Ramon Fried | 501c89d | 2018-06-08 20:53:26 +0300 | [diff] [blame] | 127 | "iotrace resume - resume tracing\n" |
| 128 | "iotrace dump - dump iotrace buffer" |
Simon Glass | aa53233 | 2014-06-11 23:29:41 -0600 | [diff] [blame] | 129 | ); |