cpu.c 3.5 KB

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