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