cpu.c 3.6 KB

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