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