cpu.c 3.7 KB

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