]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
e40cf34a EN |
2 | /* |
3 | * Copyright (C) Nelson Integration, LLC 2016 | |
4 | * Author: Eric Nelson<eric@nelint.com> | |
5 | * | |
e40cf34a EN |
6 | */ |
7 | #include <config.h> | |
8 | #include <common.h> | |
9 | #include <malloc.h> | |
10 | #include <part.h> | |
11 | ||
12 | static 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 | ||
7e872146 EN |
18 | printf("hits: %u\n" |
19 | "misses: %u\n" | |
20 | "entries: %u\n" | |
21 | "max blocks/entry: %u\n" | |
22 | "max cache entries: %u\n", | |
e40cf34a EN |
23 | stats.hits, stats.misses, stats.entries, |
24 | stats.max_blocks_per_entry, stats.max_entries); | |
25 | return 0; | |
26 | } | |
27 | ||
28 | static 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 | ||
43 | static 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 | ||
48 | static __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 | ||
58 | static 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 | ||
195c94a2 | 75 | if (!c) |
e40cf34a EN |
76 | return CMD_RET_USAGE; |
77 | ||
195c94a2 | 78 | return c->cmd(cmdtp, flag, argc, argv); |
e40cf34a EN |
79 | } |
80 | ||
81 | U_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 | ); |