blob: 25f252e455ed95a761418c452b9f9cde53e95d9a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Eric Nelsonfaf4f052016-03-28 10:05:44 -07002/*
3 * Copyright (C) Nelson Integration, LLC 2016
4 * Author: Eric Nelson<eric@nelint.com>
5 *
Eric Nelsonfaf4f052016-03-28 10:05:44 -07006 */
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <command.h>
Eric Nelsonfaf4f052016-03-28 10:05:44 -07008#include <config.h>
9#include <common.h>
10#include <malloc.h>
11#include <part.h>
12
Simon Glassed38aef2020-05-10 11:40:03 -060013static int blkc_show(struct cmd_tbl *cmdtp, int flag,
14 int argc, char *const argv[])
Eric Nelsonfaf4f052016-03-28 10:05:44 -070015{
16 struct block_cache_stats stats;
17 blkcache_stats(&stats);
18
Eric Nelson00e339f2016-04-02 07:37:12 -070019 printf("hits: %u\n"
20 "misses: %u\n"
21 "entries: %u\n"
22 "max blocks/entry: %u\n"
23 "max cache entries: %u\n",
Eric Nelsonfaf4f052016-03-28 10:05:44 -070024 stats.hits, stats.misses, stats.entries,
25 stats.max_blocks_per_entry, stats.max_entries);
26 return 0;
27}
28
Simon Glassed38aef2020-05-10 11:40:03 -060029static int blkc_configure(struct cmd_tbl *cmdtp, int flag,
30 int argc, char *const argv[])
Eric Nelsonfaf4f052016-03-28 10:05:44 -070031{
32 unsigned blocks_per_entry, max_entries;
33 if (argc != 3)
34 return CMD_RET_USAGE;
35
36 blocks_per_entry = simple_strtoul(argv[1], 0, 0);
37 max_entries = simple_strtoul(argv[2], 0, 0);
38 blkcache_configure(blocks_per_entry, max_entries);
39 printf("changed to max of %u entries of %u blocks each\n",
40 max_entries, blocks_per_entry);
41 return 0;
42}
43
Simon Glassed38aef2020-05-10 11:40:03 -060044static struct cmd_tbl cmd_blkc_sub[] = {
Eric Nelsonfaf4f052016-03-28 10:05:44 -070045 U_BOOT_CMD_MKENT(show, 0, 0, blkc_show, "", ""),
46 U_BOOT_CMD_MKENT(configure, 3, 0, blkc_configure, "", ""),
47};
48
49static __maybe_unused void blkc_reloc(void)
50{
51 static int relocated;
52
53 if (!relocated) {
54 fixup_cmdtable(cmd_blkc_sub, ARRAY_SIZE(cmd_blkc_sub));
55 relocated = 1;
56 };
57}
58
Simon Glassed38aef2020-05-10 11:40:03 -060059static int do_blkcache(struct cmd_tbl *cmdtp, int flag,
60 int argc, char *const argv[])
Eric Nelsonfaf4f052016-03-28 10:05:44 -070061{
Simon Glassed38aef2020-05-10 11:40:03 -060062 struct cmd_tbl *c;
Eric Nelsonfaf4f052016-03-28 10:05:44 -070063
64#ifdef CONFIG_NEEDS_MANUAL_RELOC
65 blkc_reloc();
66#endif
67 if (argc < 2)
68 return CMD_RET_USAGE;
69
70 /* Strip off leading argument */
71 argc--;
72 argv++;
73
74 c = find_cmd_tbl(argv[0], &cmd_blkc_sub[0], ARRAY_SIZE(cmd_blkc_sub));
75
Eric Nelsonbb02a6e2016-04-02 07:37:13 -070076 if (!c)
Eric Nelsonfaf4f052016-03-28 10:05:44 -070077 return CMD_RET_USAGE;
78
Eric Nelsonbb02a6e2016-04-02 07:37:13 -070079 return c->cmd(cmdtp, flag, argc, argv);
Eric Nelsonfaf4f052016-03-28 10:05:44 -070080}
81
82U_BOOT_CMD(
83 blkcache, 4, 0, do_blkcache,
84 "block cache diagnostics and control",
85 "show - show and reset statistics\n"
86 "blkcache configure blocks entries\n"
87);