cpu.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2015 Google, Inc
  4. * Written by Simon Glass <sjg@chromium.org>
  5. * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
  6. */
  7. #include <common.h>
  8. #include <command.h>
  9. #include <cpu.h>
  10. #include <dm.h>
  11. #include <errno.h>
  12. static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
  13. "L1 cache",
  14. "MMU",
  15. "Microcode",
  16. "Device ID",
  17. };
  18. static int print_cpu_list(bool detail)
  19. {
  20. struct udevice *dev;
  21. char buf[100];
  22. for (uclass_first_device(UCLASS_CPU, &dev);
  23. dev;
  24. uclass_next_device(&dev)) {
  25. struct cpu_plat *plat = dev_get_parent_plat(dev);
  26. struct cpu_info info;
  27. bool first = true;
  28. int ret, i;
  29. ret = cpu_get_desc(dev, buf, sizeof(buf));
  30. printf("%3d: %-10s %s\n", dev_seq(dev), dev->name,
  31. ret ? "<no description>" : buf);
  32. if (!detail)
  33. continue;
  34. ret = cpu_get_info(dev, &info);
  35. if (ret) {
  36. printf("\t(no detail available");
  37. if (ret != -ENOSYS)
  38. printf(": err=%d", ret);
  39. printf(")\n");
  40. continue;
  41. }
  42. printf("\tID = %d, freq = ", plat->cpu_id);
  43. print_freq(info.cpu_freq, "");
  44. for (i = 0; i < CPU_FEAT_COUNT; i++) {
  45. if (info.features & (1 << i)) {
  46. printf("%s%s", first ? ": " : ", ",
  47. cpu_feature_name[i]);
  48. first = false;
  49. }
  50. }
  51. printf("\n");
  52. if (info.features & (1 << CPU_FEAT_UCODE))
  53. printf("\tMicrocode version %#x\n",
  54. plat->ucode_version);
  55. if (info.features & (1 << CPU_FEAT_DEVICE_ID))
  56. printf("\tDevice ID %#lx\n", plat->device_id);
  57. }
  58. return 0;
  59. }
  60. static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
  61. char *const argv[])
  62. {
  63. if (print_cpu_list(false))
  64. return CMD_RET_FAILURE;
  65. return 0;
  66. }
  67. static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
  68. char *const argv[])
  69. {
  70. if (print_cpu_list(true))
  71. return CMD_RET_FAILURE;
  72. return 0;
  73. }
  74. static struct cmd_tbl cmd_cpu_sub[] = {
  75. U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
  76. U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
  77. };
  78. /*
  79. * Process a cpu sub-command
  80. */
  81. static int do_cpu(struct cmd_tbl *cmdtp, int flag, int argc,
  82. char *const argv[])
  83. {
  84. struct cmd_tbl *c = NULL;
  85. /* Strip off leading 'cpu' command argument */
  86. argc--;
  87. argv++;
  88. if (argc)
  89. c = find_cmd_tbl(argv[0], cmd_cpu_sub,
  90. ARRAY_SIZE(cmd_cpu_sub));
  91. if (c)
  92. return c->cmd(cmdtp, flag, argc, argv);
  93. else
  94. return CMD_RET_USAGE;
  95. }
  96. U_BOOT_CMD(
  97. cpu, 2, 1, do_cpu,
  98. "display information about CPUs",
  99. "list - list available CPUs\n"
  100. "cpu detail - show CPU detail"
  101. );