cpu.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
  4. * Scott McNutt <smcnutt@psyent.com>
  5. */
  6. #include <common.h>
  7. #include <cpu.h>
  8. #include <dm.h>
  9. #include <errno.h>
  10. #include <asm/cache.h>
  11. DECLARE_GLOBAL_DATA_PTR;
  12. #ifdef CONFIG_DISPLAY_CPUINFO
  13. int print_cpuinfo(void)
  14. {
  15. printf("CPU: Nios-II\n");
  16. return 0;
  17. }
  18. #endif /* CONFIG_DISPLAY_CPUINFO */
  19. #ifdef CONFIG_ALTERA_SYSID
  20. int checkboard(void)
  21. {
  22. display_sysid();
  23. return 0;
  24. }
  25. #endif
  26. int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  27. {
  28. disable_interrupts();
  29. /* indirect call to go beyond 256MB limitation of toolchain */
  30. nios2_callr(gd->arch.reset_addr);
  31. return 0;
  32. }
  33. /*
  34. * COPY EXCEPTION TRAMPOLINE -- copy the tramp to the
  35. * exception address. Define CONFIG_ROM_STUBS to prevent
  36. * the copy (e.g. exception in flash or in other
  37. * softare/firmware component).
  38. */
  39. #ifndef CONFIG_ROM_STUBS
  40. static void copy_exception_trampoline(void)
  41. {
  42. extern int _except_start, _except_end;
  43. void *except_target = (void *)gd->arch.exception_addr;
  44. if (&_except_start != except_target) {
  45. memcpy(except_target, &_except_start,
  46. &_except_end - &_except_start);
  47. flush_cache(gd->arch.exception_addr,
  48. &_except_end - &_except_start);
  49. }
  50. }
  51. #endif
  52. int arch_cpu_init_dm(void)
  53. {
  54. struct udevice *dev;
  55. int ret;
  56. ret = uclass_first_device_err(UCLASS_CPU, &dev);
  57. if (ret)
  58. return ret;
  59. gd->ram_size = CONFIG_SYS_SDRAM_SIZE;
  60. #ifndef CONFIG_ROM_STUBS
  61. copy_exception_trampoline();
  62. #endif
  63. return 0;
  64. }
  65. static int altera_nios2_get_desc(struct udevice *dev, char *buf, int size)
  66. {
  67. const char *cpu_name = "Nios-II";
  68. if (size < strlen(cpu_name))
  69. return -ENOSPC;
  70. strcpy(buf, cpu_name);
  71. return 0;
  72. }
  73. static int altera_nios2_get_info(struct udevice *dev, struct cpu_info *info)
  74. {
  75. info->cpu_freq = gd->cpu_clk;
  76. info->features = (1 << CPU_FEAT_L1_CACHE) |
  77. (gd->arch.has_mmu ? (1 << CPU_FEAT_MMU) : 0);
  78. return 0;
  79. }
  80. static int altera_nios2_get_count(struct udevice *dev)
  81. {
  82. return 1;
  83. }
  84. static int altera_nios2_probe(struct udevice *dev)
  85. {
  86. const void *blob = gd->fdt_blob;
  87. int node = dev_of_offset(dev);
  88. gd->cpu_clk = fdtdec_get_int(blob, node,
  89. "clock-frequency", 0);
  90. gd->arch.dcache_line_size = fdtdec_get_int(blob, node,
  91. "dcache-line-size", 0);
  92. gd->arch.icache_line_size = fdtdec_get_int(blob, node,
  93. "icache-line-size", 0);
  94. gd->arch.dcache_size = fdtdec_get_int(blob, node,
  95. "dcache-size", 0);
  96. gd->arch.icache_size = fdtdec_get_int(blob, node,
  97. "icache-size", 0);
  98. gd->arch.reset_addr = fdtdec_get_int(blob, node,
  99. "altr,reset-addr", 0);
  100. gd->arch.exception_addr = fdtdec_get_int(blob, node,
  101. "altr,exception-addr", 0);
  102. gd->arch.has_initda = fdtdec_get_int(blob, node,
  103. "altr,has-initda", 0);
  104. gd->arch.has_mmu = fdtdec_get_int(blob, node,
  105. "altr,has-mmu", 0);
  106. gd->arch.io_region_base = gd->arch.has_mmu ? 0xe0000000 : 0x80000000;
  107. gd->arch.mem_region_base = gd->arch.has_mmu ? 0xc0000000 : 0x00000000;
  108. gd->arch.physaddr_mask = gd->arch.has_mmu ? 0x1fffffff : 0x7fffffff;
  109. return 0;
  110. }
  111. static const struct cpu_ops altera_nios2_ops = {
  112. .get_desc = altera_nios2_get_desc,
  113. .get_info = altera_nios2_get_info,
  114. .get_count = altera_nios2_get_count,
  115. };
  116. static const struct udevice_id altera_nios2_ids[] = {
  117. { .compatible = "altr,nios2-1.0" },
  118. { .compatible = "altr,nios2-1.1" },
  119. { }
  120. };
  121. U_BOOT_DRIVER(altera_nios2) = {
  122. .name = "altera_nios2",
  123. .id = UCLASS_CPU,
  124. .of_match = altera_nios2_ids,
  125. .probe = altera_nios2_probe,
  126. .ops = &altera_nios2_ops,
  127. .flags = DM_FLAG_PRE_RELOC,
  128. };
  129. /* This is a dummy function on nios2 */
  130. int dram_init(void)
  131. {
  132. return 0;
  133. }