cpu.c 3.6 KB

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