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