blkcache.c 1.9 KB

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