cpu.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2015 Google, Inc
  3. * Written by Simon Glass <sjg@chromium.org>
  4. * Copyright (c) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <cpu.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_platdata *plat = dev_get_parent_platdata(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->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(cmd_tbl_t *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(cmd_tbl_t *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. static cmd_tbl_t cmd_cpu_sub[] = {
  76. U_BOOT_CMD_MKENT(list, 2, 1, do_cpu_list, "", ""),
  77. U_BOOT_CMD_MKENT(detail, 4, 0, do_cpu_detail, "", ""),
  78. };
  79. /*
  80. * Process a cpu sub-command
  81. */
  82. static int do_cpu(cmd_tbl_t *cmdtp, int flag, int argc,
  83. char * const argv[])
  84. {
  85. cmd_tbl_t *c = NULL;
  86. /* Strip off leading 'cpu' command argument */
  87. argc--;
  88. argv++;
  89. if (argc)
  90. c = find_cmd_tbl(argv[0], cmd_cpu_sub,
  91. ARRAY_SIZE(cmd_cpu_sub));
  92. if (c)
  93. return c->cmd(cmdtp, flag, argc, argv);
  94. else
  95. return CMD_RET_USAGE;
  96. }
  97. U_BOOT_CMD(
  98. cpu, 2, 1, do_cpu,
  99. "display information about CPUs",
  100. "list - list available CPUs\n"
  101. "cpu detail - show CPU detail"
  102. );