Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
| 4 | * |
| 5 | * (C) Copyright 2012 |
| 6 | * Marek Vasut <marex@denx.de> |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
Tom Rini | 23415e5 | 2015-12-07 08:23:29 -0500 | [diff] [blame] | 9 | #include <command.h> |
Simon Glass | c8b5e22 | 2022-05-08 04:39:26 -0600 | [diff] [blame] | 10 | #include <dm/root.h> |
Simon Glass | d9f9a89 | 2015-06-23 15:38:35 -0600 | [diff] [blame] | 11 | #include <dm/util.h> |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 12 | |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 13 | static int do_dm_dump_driver_compat(struct cmd_tbl *cmdtp, int flag, int argc, |
| 14 | char * const argv[]) |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 15 | { |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 16 | dm_dump_driver_compat(); |
Simon Glass | c267cf7 | 2014-02-26 15:59:22 -0700 | [diff] [blame] | 17 | |
| 18 | return 0; |
| 19 | } |
| 20 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 21 | static int do_dm_dump_devres(struct cmd_tbl *cmdtp, int flag, int argc, |
| 22 | char *const argv[]) |
Masahiro Yamada | f929c0b | 2015-07-25 21:52:38 +0900 | [diff] [blame] | 23 | { |
| 24 | dm_dump_devres(); |
| 25 | |
| 26 | return 0; |
| 27 | } |
| 28 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 29 | static int do_dm_dump_drivers(struct cmd_tbl *cmdtp, int flag, int argc, |
| 30 | char *const argv[]) |
Sean Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 31 | { |
| 32 | dm_dump_drivers(); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
Simon Glass | c8b5e22 | 2022-05-08 04:39:26 -0600 | [diff] [blame] | 37 | #if CONFIG_IS_ENABLED(DM_STATS) |
| 38 | static int do_dm_dump_mem(struct cmd_tbl *cmdtp, int flag, int argc, |
| 39 | char *const argv[]) |
| 40 | { |
| 41 | struct dm_stats mem; |
| 42 | |
| 43 | dm_get_mem(&mem); |
| 44 | dm_dump_mem(&mem); |
| 45 | |
| 46 | return 0; |
| 47 | } |
| 48 | #endif /* DM_STATS */ |
| 49 | |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 50 | static int do_dm_dump_static_driver_info(struct cmd_tbl *cmdtp, int flag, |
| 51 | int argc, char * const argv[]) |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 52 | { |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 53 | dm_dump_static_driver_info(); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 54 | |
| 55 | return 0; |
| 56 | } |
| 57 | |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 58 | static int do_dm_dump_tree(struct cmd_tbl *cmdtp, int flag, int argc, |
| 59 | char *const argv[]) |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 60 | { |
AKASHI Takahiro | f06f082 | 2023-08-23 10:49:47 +0900 | [diff] [blame] | 61 | bool extended = false, sort = false; |
| 62 | char *device = NULL; |
Simon Glass | e5314c1 | 2023-01-17 10:47:12 -0700 | [diff] [blame] | 63 | |
AKASHI Takahiro | f06f082 | 2023-08-23 10:49:47 +0900 | [diff] [blame] | 64 | for (; argc > 1; argc--, argv++) { |
| 65 | if (argv[1][0] != '-') |
| 66 | break; |
Simon Glass | e5314c1 | 2023-01-17 10:47:12 -0700 | [diff] [blame] | 67 | |
AKASHI Takahiro | f06f082 | 2023-08-23 10:49:47 +0900 | [diff] [blame] | 68 | if (!strcmp(argv[1], "-e")) { |
| 69 | extended = true; |
| 70 | } else if (!strcmp(argv[1], "-s")) { |
| 71 | sort = true; |
| 72 | } else { |
| 73 | printf("Unknown parameter: %s\n", argv[1]); |
| 74 | return 0; |
| 75 | } |
| 76 | } |
| 77 | if (argc > 1) |
| 78 | device = argv[1]; |
| 79 | |
| 80 | dm_dump_tree(device, extended, sort); |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 81 | |
| 82 | return 0; |
| 83 | } |
| 84 | |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 85 | static int do_dm_dump_uclass(struct cmd_tbl *cmdtp, int flag, int argc, |
| 86 | char *const argv[]) |
| 87 | { |
AKASHI Takahiro | f06f082 | 2023-08-23 10:49:47 +0900 | [diff] [blame] | 88 | bool extended = false; |
| 89 | char *uclass = NULL; |
| 90 | |
| 91 | if (argc > 1) { |
| 92 | if (!strcmp(argv[1], "-e")) { |
| 93 | extended = true; |
| 94 | argc--; |
| 95 | argv++; |
| 96 | } |
| 97 | if (argc > 1) |
| 98 | uclass = argv[1]; |
| 99 | } |
| 100 | |
| 101 | dm_dump_uclass(uclass, extended); |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Simon Glass | c8b5e22 | 2022-05-08 04:39:26 -0600 | [diff] [blame] | 106 | #if CONFIG_IS_ENABLED(DM_STATS) |
| 107 | #define DM_MEM_HELP "dm mem Provide a summary of memory usage\n" |
| 108 | #define DM_MEM U_BOOT_SUBCMD_MKENT(mem, 1, 1, do_dm_dump_mem), |
| 109 | #else |
| 110 | #define DM_MEM_HELP |
| 111 | #define DM_MEM |
| 112 | #endif |
| 113 | |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 114 | U_BOOT_LONGHELP(dm, |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 115 | "compat Dump list of drivers with compatibility strings\n" |
Sean Anderson | 0282757 | 2020-01-17 14:48:09 -0500 | [diff] [blame] | 116 | "dm devres Dump list of device resources for each device\n" |
Niel Fourie | 39832fb | 2020-03-24 16:17:05 +0100 | [diff] [blame] | 117 | "dm drivers Dump list of drivers with uclass and instances\n" |
Simon Glass | c8b5e22 | 2022-05-08 04:39:26 -0600 | [diff] [blame] | 118 | DM_MEM_HELP |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 119 | "dm static Dump list of drivers with static platform data\n" |
AKASHI Takahiro | f06f082 | 2023-08-23 10:49:47 +0900 | [diff] [blame] | 120 | "dm tree [-s][-e][name] Dump tree of driver model devices (-s=sort)\n" |
Tom Rini | 03f146c | 2023-10-07 15:13:08 -0400 | [diff] [blame] | 121 | "dm uclass [-e][name] Dump list of instances for each uclass"); |
Ovidiu Panait | e4c5b79 | 2022-05-08 13:01:42 +0300 | [diff] [blame] | 122 | |
| 123 | U_BOOT_CMD_WITH_SUBCMDS(dm, "Driver model low level access", dm_help_text, |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 124 | U_BOOT_SUBCMD_MKENT(compat, 1, 1, do_dm_dump_driver_compat), |
Ovidiu Panait | e4c5b79 | 2022-05-08 13:01:42 +0300 | [diff] [blame] | 125 | U_BOOT_SUBCMD_MKENT(devres, 1, 1, do_dm_dump_devres), |
| 126 | U_BOOT_SUBCMD_MKENT(drivers, 1, 1, do_dm_dump_drivers), |
Simon Glass | c8b5e22 | 2022-05-08 04:39:26 -0600 | [diff] [blame] | 127 | DM_MEM |
Simon Glass | e9daa5d | 2022-05-08 04:39:20 -0600 | [diff] [blame] | 128 | U_BOOT_SUBCMD_MKENT(static, 1, 1, do_dm_dump_static_driver_info), |
AKASHI Takahiro | f06f082 | 2023-08-23 10:49:47 +0900 | [diff] [blame] | 129 | U_BOOT_SUBCMD_MKENT(tree, 4, 1, do_dm_dump_tree), |
| 130 | U_BOOT_SUBCMD_MKENT(uclass, 3, 1, do_dm_dump_uclass)); |