1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2e40cf34aSEric Nelson /*
3e40cf34aSEric Nelson * Copyright (C) Nelson Integration, LLC 2016
4e40cf34aSEric Nelson * Author: Eric Nelson<eric@nelint.com>
5e40cf34aSEric Nelson *
6e40cf34aSEric Nelson */
7e40cf34aSEric Nelson #include <config.h>
8e40cf34aSEric Nelson #include <common.h>
9e40cf34aSEric Nelson #include <malloc.h>
10e40cf34aSEric Nelson #include <part.h>
11e40cf34aSEric Nelson
blkc_show(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])12e40cf34aSEric Nelson static int blkc_show(cmd_tbl_t *cmdtp, int flag,
13e40cf34aSEric Nelson int argc, char * const argv[])
14e40cf34aSEric Nelson {
15e40cf34aSEric Nelson struct block_cache_stats stats;
16e40cf34aSEric Nelson blkcache_stats(&stats);
17e40cf34aSEric Nelson
18e40cf34aSEric Nelson printf("hits: %u\n"
19e40cf34aSEric Nelson "misses: %u\n"
20e40cf34aSEric Nelson "entries: %u\n"
21e40cf34aSEric Nelson "max blocks/entry: %u\n"
22e40cf34aSEric Nelson "max cache entries: %u\n",
23e40cf34aSEric Nelson stats.hits, stats.misses, stats.entries,
24e40cf34aSEric Nelson stats.max_blocks_per_entry, stats.max_entries);
25e40cf34aSEric Nelson return 0;
26e40cf34aSEric Nelson }
27e40cf34aSEric Nelson
blkc_configure(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])28e40cf34aSEric Nelson static int blkc_configure(cmd_tbl_t *cmdtp, int flag,
29e40cf34aSEric Nelson int argc, char * const argv[])
30e40cf34aSEric Nelson {
31e40cf34aSEric Nelson unsigned blocks_per_entry, max_entries;
32e40cf34aSEric Nelson if (argc != 3)
33e40cf34aSEric Nelson return CMD_RET_USAGE;
34e40cf34aSEric Nelson
35e40cf34aSEric Nelson blocks_per_entry = simple_strtoul(argv[1], 0, 0);
36e40cf34aSEric Nelson max_entries = simple_strtoul(argv[2], 0, 0);
37e40cf34aSEric Nelson blkcache_configure(blocks_per_entry, max_entries);
38e40cf34aSEric Nelson printf("changed to max of %u entries of %u blocks each\n",
39e40cf34aSEric Nelson max_entries, blocks_per_entry);
40e40cf34aSEric Nelson return 0;
41e40cf34aSEric Nelson }
42e40cf34aSEric Nelson
43e40cf34aSEric Nelson static cmd_tbl_t cmd_blkc_sub[] = {
44e40cf34aSEric Nelson U_BOOT_CMD_MKENT(show, 0, 0, blkc_show, "", ""),
45e40cf34aSEric Nelson U_BOOT_CMD_MKENT(configure, 3, 0, blkc_configure, "", ""),
46e40cf34aSEric Nelson };
47e40cf34aSEric Nelson
blkc_reloc(void)48e40cf34aSEric Nelson static __maybe_unused void blkc_reloc(void)
49e40cf34aSEric Nelson {
50e40cf34aSEric Nelson static int relocated;
51e40cf34aSEric Nelson
52e40cf34aSEric Nelson if (!relocated) {
53e40cf34aSEric Nelson fixup_cmdtable(cmd_blkc_sub, ARRAY_SIZE(cmd_blkc_sub));
54e40cf34aSEric Nelson relocated = 1;
55e40cf34aSEric Nelson };
56e40cf34aSEric Nelson }
57e40cf34aSEric Nelson
do_blkcache(cmd_tbl_t * cmdtp,int flag,int argc,char * const argv[])58e40cf34aSEric Nelson static int do_blkcache(cmd_tbl_t *cmdtp, int flag,
59e40cf34aSEric Nelson int argc, char * const argv[])
60e40cf34aSEric Nelson {
61e40cf34aSEric Nelson cmd_tbl_t *c;
62e40cf34aSEric Nelson
63e40cf34aSEric Nelson #ifdef CONFIG_NEEDS_MANUAL_RELOC
64e40cf34aSEric Nelson blkc_reloc();
65e40cf34aSEric Nelson #endif
66e40cf34aSEric Nelson if (argc < 2)
67e40cf34aSEric Nelson return CMD_RET_USAGE;
68e40cf34aSEric Nelson
69e40cf34aSEric Nelson /* Strip off leading argument */
70e40cf34aSEric Nelson argc--;
71e40cf34aSEric Nelson argv++;
72e40cf34aSEric Nelson
73e40cf34aSEric Nelson c = find_cmd_tbl(argv[0], &cmd_blkc_sub[0], ARRAY_SIZE(cmd_blkc_sub));
74e40cf34aSEric Nelson
75195c94a2SEric Nelson if (!c)
76e40cf34aSEric Nelson return CMD_RET_USAGE;
77e40cf34aSEric Nelson
78195c94a2SEric Nelson return c->cmd(cmdtp, flag, argc, argv);
79e40cf34aSEric Nelson }
80e40cf34aSEric Nelson
81e40cf34aSEric Nelson U_BOOT_CMD(
82e40cf34aSEric Nelson blkcache, 4, 0, do_blkcache,
83e40cf34aSEric Nelson "block cache diagnostics and control",
84e40cf34aSEric Nelson "show - show and reset statistics\n"
85e40cf34aSEric Nelson "blkcache configure blocks entries\n"
86e40cf34aSEric Nelson );
87