cpu.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <display_options.h>
  11. #include <dm.h>
  12. #include <errno.h>
  13. static const char *cpu_feature_name[CPU_FEAT_COUNT] = {
  14. "L1 cache",
  15. "MMU",
  16. "Microcode",
  17. "Device ID",
  18. };
  19. static int print_cpu_list(bool detail)
  20. {
  21. struct udevice *dev;
  22. char buf[100];
  23. for (uclass_first_device(UCLASS_CPU, &dev);
  24. dev;
  25. uclass_next_device(&dev)) {
  26. struct cpu_plat *plat = dev_get_parent_plat(dev);
  27. struct cpu_info info;
  28. bool first = true;
  29. int ret, i;
  30. ret = cpu_get_desc(dev, buf, sizeof(buf));
  31. printf("%3d: %-10s %s\n", dev_seq(dev), dev->name,
  32. ret ? "<no description>" : buf);
  33. if (!detail)
  34. continue;
  35. ret = cpu_get_info(dev, &info);
  36. if (ret) {
  37. printf("\t(no detail available");
  38. if (ret != -ENOSYS)
  39. printf(": err=%d", ret);
  40. printf(")\n");
  41. continue;
  42. }
  43. printf("\tID = %d, freq = ", plat->cpu_id);
  44. print_freq(info.cpu_freq, "");
  45. for (i = 0; i < CPU_FEAT_COUNT; i++) {
  46. if (info.features & (1 << i)) {
  47. printf("%s%s", first ? ": " : ", ",
  48. cpu_feature_name[i]);
  49. first = false;
  50. }
  51. }
  52. printf("\n");
  53. if (info.features & (1 << CPU_FEAT_UCODE))
  54. printf("\tMicrocode version %#x\n",
  55. plat->ucode_version);
  56. if (info.features & (1 << CPU_FEAT_DEVICE_ID))
  57. printf("\tDevice ID %#lx\n", plat->device_id);
  58. }
  59. return 0;
  60. }
  61. static int do_cpu_list(struct cmd_tbl *cmdtp, int flag, int argc,
  62. char *const argv[])
  63. {
  64. if (print_cpu_list(false))
  65. return CMD_RET_FAILURE;
  66. return 0;
  67. }
  68. static int do_cpu_detail(struct cmd_tbl *cmdtp, int flag, int argc,
  69. char *const argv[])
  70. {
  71. if (print_cpu_list(true))
  72. return CMD_RET_FAILURE;
  73. return 0;
  74. }
  75. #if IS_ENABLED(CONFIG_SYS_LONGHELP)
  76. static char cpu_help_text[] =
  77. "list - list available CPUs\n"
  78. "cpu detail - show CPU detail"
  79. ;
  80. #endif
  81. U_BOOT_CMD_WITH_SUBCMDS(cpu, "display information about CPUs", cpu_help_text,
  82. U_BOOT_SUBCMD_MKENT(list, 1, 1, do_cpu_list),
  83. U_BOOT_SUBCMD_MKENT(detail, 1, 0, do_cpu_detail));