microblaze_cpu.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2022, Ovidiu Panait <ovpanait@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <cpu.h>
  7. #include <dm.h>
  8. #include <asm/cpuinfo.h>
  9. #include <asm/global_data.h>
  10. #include <asm/pvr.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. #define update_cpuinfo_pvr(pvr, ci, name) \
  13. { \
  14. u32 tmp = PVR_##name(pvr); \
  15. if (ci != tmp) \
  16. printf("PVR value for " #name " does not match static data!\n");\
  17. ci = tmp; \
  18. }
  19. static int microblaze_cpu_probe_all(void *ctx, struct event *event)
  20. {
  21. int ret;
  22. ret = cpu_probe_all();
  23. if (ret)
  24. return log_msg_ret("Microblaze cpus probe failed\n", ret);
  25. return 0;
  26. }
  27. EVENT_SPY(EVT_DM_POST_INIT_F, microblaze_cpu_probe_all);
  28. static void microblaze_set_cpuinfo_pvr(struct microblaze_cpuinfo *ci)
  29. {
  30. u32 pvr[PVR_FULL_COUNT];
  31. microblaze_get_all_pvrs(pvr);
  32. update_cpuinfo_pvr(pvr, ci->icache_size, ICACHE_BYTE_SIZE);
  33. update_cpuinfo_pvr(pvr, ci->icache_line_length, ICACHE_LINE_LEN);
  34. update_cpuinfo_pvr(pvr, ci->dcache_size, DCACHE_BYTE_SIZE);
  35. update_cpuinfo_pvr(pvr, ci->dcache_line_length, DCACHE_LINE_LEN);
  36. update_cpuinfo_pvr(pvr, ci->use_mmu, USE_MMU);
  37. update_cpuinfo_pvr(pvr, ci->ver_code, VERSION);
  38. update_cpuinfo_pvr(pvr, ci->fpga_code, TARGET_FAMILY);
  39. }
  40. static void microblaze_set_cpuinfo_static(struct udevice *dev,
  41. struct microblaze_cpuinfo *ci)
  42. {
  43. const char *hw_ver = CONFIG_XILINX_MICROBLAZE0_HW_VER;
  44. const char *fpga_family = CONFIG_XILINX_MICROBLAZE0_FPGA_FAMILY;
  45. ci->icache_size = dev_read_u32_default(dev, "i-cache-size", 0);
  46. ci->icache_line_length = dev_read_u32_default(dev,
  47. "i-cache-line-size", 0);
  48. ci->dcache_size = dev_read_u32_default(dev, "d-cache-size", 0);
  49. ci->dcache_line_length = dev_read_u32_default(dev,
  50. "d-cache-line-size", 0);
  51. ci->cpu_freq = dev_read_u32_default(dev, "clock-frequency", 0);
  52. ci->addr_size = dev_read_u32_default(dev, "xlnx,addr-size", 32);
  53. ci->use_mmu = dev_read_u32_default(dev, "xlnx,use-mmu", 0);
  54. ci->ver_code = microblaze_lookup_cpu_version_code(hw_ver);
  55. ci->fpga_code = microblaze_lookup_fpga_family_code(fpga_family);
  56. }
  57. static int microblaze_cpu_probe(struct udevice *dev)
  58. {
  59. microblaze_set_cpuinfo_static(dev, gd_cpuinfo());
  60. if (microblaze_cpu_has_pvr_full())
  61. microblaze_set_cpuinfo_pvr(gd_cpuinfo());
  62. else
  63. debug("No PVR support. Using only static CPU info.\n");
  64. return 0;
  65. }
  66. static int microblaze_cpu_get_desc(const struct udevice *dev, char *buf,
  67. int size)
  68. {
  69. struct microblaze_cpuinfo *ci = gd_cpuinfo();
  70. const char *cpu_ver, *fpga_family;
  71. u32 cpu_freq_mhz;
  72. int ret;
  73. cpu_freq_mhz = ci->cpu_freq / 1000000;
  74. cpu_ver = microblaze_lookup_cpu_version_string(ci->ver_code);
  75. fpga_family = microblaze_lookup_fpga_family_string(ci->fpga_code);
  76. ret = snprintf(buf, size,
  77. "MicroBlaze @ %uMHz, Rev: %s, FPGA family: %s",
  78. cpu_freq_mhz, cpu_ver, fpga_family);
  79. if (ret < 0)
  80. return ret;
  81. return (ret >= size) ? -ENOSPC : 0;
  82. }
  83. static int microblaze_cpu_get_info(const struct udevice *dev,
  84. struct cpu_info *info)
  85. {
  86. struct microblaze_cpuinfo *ci = gd_cpuinfo();
  87. info->cpu_freq = ci->cpu_freq;
  88. info->address_width = ci->addr_size;
  89. if (ci->icache_size || ci->dcache_size)
  90. info->features |= BIT(CPU_FEAT_L1_CACHE);
  91. if (ci->use_mmu)
  92. info->features |= BIT(CPU_FEAT_MMU);
  93. return 0;
  94. }
  95. static int microblaze_cpu_get_count(const struct udevice *dev)
  96. {
  97. return 1;
  98. }
  99. static const struct cpu_ops microblaze_cpu_ops = {
  100. .get_desc = microblaze_cpu_get_desc,
  101. .get_info = microblaze_cpu_get_info,
  102. .get_count = microblaze_cpu_get_count,
  103. };
  104. static const struct udevice_id microblaze_cpu_ids[] = {
  105. { .compatible = "xlnx,microblaze-11.0" },
  106. { .compatible = "xlnx,microblaze-10.0" },
  107. { .compatible = "xlnx,microblaze-9.6" },
  108. { .compatible = "xlnx,microblaze-9.5" },
  109. { .compatible = "xlnx,microblaze-9.4" },
  110. { .compatible = "xlnx,microblaze-9.3" },
  111. { .compatible = "xlnx,microblaze-9.2" },
  112. { .compatible = "xlnx,microblaze-9.1" },
  113. { .compatible = "xlnx,microblaze-9.0" },
  114. { .compatible = "xlnx,microblaze-8.50.c" },
  115. { .compatible = "xlnx,microblaze-8.50.b" },
  116. { .compatible = "xlnx,microblaze-8.50.a" },
  117. { .compatible = "xlnx,microblaze-8.40.b" },
  118. { .compatible = "xlnx,microblaze-8.40.a" },
  119. { .compatible = "xlnx,microblaze-8.30.a" },
  120. { .compatible = "xlnx,microblaze-8.20.b" },
  121. { .compatible = "xlnx,microblaze-8.20.a" },
  122. { .compatible = "xlnx,microblaze-8.10.a" },
  123. { .compatible = "xlnx,microblaze-8.00.b" },
  124. { .compatible = "xlnx,microblaze-8.00.a" },
  125. { .compatible = "xlnx,microblaze-7.30.b" },
  126. { .compatible = "xlnx,microblaze-7.30.a" },
  127. { .compatible = "xlnx,microblaze-7.20.d" },
  128. { .compatible = "xlnx,microblaze-7.20.c" },
  129. { .compatible = "xlnx,microblaze-7.20.b" },
  130. { .compatible = "xlnx,microblaze-7.20.a" },
  131. { .compatible = "xlnx,microblaze-7.10.d" },
  132. { .compatible = "xlnx,microblaze-7.10.c" },
  133. { .compatible = "xlnx,microblaze-7.10.b" },
  134. { .compatible = "xlnx,microblaze-7.10.a" },
  135. { .compatible = "xlnx,microblaze-7.00.b" },
  136. { .compatible = "xlnx,microblaze-7.00.a" },
  137. { .compatible = "xlnx,microblaze-6.00.b" },
  138. { .compatible = "xlnx,microblaze-6.00.a" },
  139. { .compatible = "xlnx,microblaze-5.00.c" },
  140. { .compatible = "xlnx,microblaze-5.00.b" },
  141. { .compatible = "xlnx,microblaze-5.00.a" },
  142. { }
  143. };
  144. U_BOOT_DRIVER(microblaze_cpu) = {
  145. .name = "microblaze_cpu",
  146. .id = UCLASS_CPU,
  147. .of_match = microblaze_cpu_ids,
  148. .probe = microblaze_cpu_probe,
  149. .ops = &microblaze_cpu_ops,
  150. .flags = DM_FLAG_PRE_RELOC,
  151. };