setup.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Nios2-specific parts of system setup
  3. *
  4. * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
  5. * Copyright (C) 2004 Microtronix Datacom Ltd.
  6. * Copyright (C) 2001 Vic Phillips <vic@microtronix.com>
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file "COPYING" in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/export.h>
  13. #include <linux/kernel.h>
  14. #include <linux/mm.h>
  15. #include <linux/sched.h>
  16. #include <linux/sched/task.h>
  17. #include <linux/console.h>
  18. #include <linux/memblock.h>
  19. #include <linux/initrd.h>
  20. #include <linux/of_fdt.h>
  21. #include <linux/screen_info.h>
  22. #include <asm/mmu_context.h>
  23. #include <asm/sections.h>
  24. #include <asm/setup.h>
  25. #include <asm/cpuinfo.h>
  26. unsigned long memory_start;
  27. EXPORT_SYMBOL(memory_start);
  28. unsigned long memory_end;
  29. EXPORT_SYMBOL(memory_end);
  30. unsigned long memory_size;
  31. static struct pt_regs fake_regs = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  32. 0, 0, 0, 0, 0, 0,
  33. 0};
  34. #ifdef CONFIG_VT
  35. struct screen_info screen_info;
  36. #endif
  37. /* Copy a short hook instruction sequence to the exception address */
  38. static inline void copy_exception_handler(unsigned int addr)
  39. {
  40. unsigned int start = (unsigned int) exception_handler_hook;
  41. volatile unsigned int tmp = 0;
  42. if (start == addr) {
  43. /* The CPU exception address already points to the handler. */
  44. return;
  45. }
  46. __asm__ __volatile__ (
  47. "ldw %2,0(%0)\n"
  48. "stw %2,0(%1)\n"
  49. "ldw %2,4(%0)\n"
  50. "stw %2,4(%1)\n"
  51. "ldw %2,8(%0)\n"
  52. "stw %2,8(%1)\n"
  53. "flushd 0(%1)\n"
  54. "flushd 4(%1)\n"
  55. "flushd 8(%1)\n"
  56. "flushi %1\n"
  57. "addi %1,%1,4\n"
  58. "flushi %1\n"
  59. "addi %1,%1,4\n"
  60. "flushi %1\n"
  61. "flushp\n"
  62. : /* no output registers */
  63. : "r" (start), "r" (addr), "r" (tmp)
  64. : "memory"
  65. );
  66. }
  67. /* Copy the fast TLB miss handler */
  68. static inline void copy_fast_tlb_miss_handler(unsigned int addr)
  69. {
  70. unsigned int start = (unsigned int) fast_handler;
  71. unsigned int end = (unsigned int) fast_handler_end;
  72. volatile unsigned int tmp = 0;
  73. __asm__ __volatile__ (
  74. "1:\n"
  75. " ldw %3,0(%0)\n"
  76. " stw %3,0(%1)\n"
  77. " flushd 0(%1)\n"
  78. " flushi %1\n"
  79. " flushp\n"
  80. " addi %0,%0,4\n"
  81. " addi %1,%1,4\n"
  82. " bne %0,%2,1b\n"
  83. : /* no output registers */
  84. : "r" (start), "r" (addr), "r" (end), "r" (tmp)
  85. : "memory"
  86. );
  87. }
  88. /*
  89. * save args passed from u-boot, called from head.S
  90. *
  91. * @r4: NIOS magic
  92. * @r5: initrd start
  93. * @r6: initrd end or fdt
  94. * @r7: kernel command line
  95. */
  96. asmlinkage void __init nios2_boot_init(unsigned r4, unsigned r5, unsigned r6,
  97. unsigned r7)
  98. {
  99. unsigned dtb_passed = 0;
  100. char cmdline_passed[COMMAND_LINE_SIZE] __maybe_unused = { 0, };
  101. #if defined(CONFIG_NIOS2_PASS_CMDLINE)
  102. if (r4 == 0x534f494e) { /* r4 is magic NIOS */
  103. #if defined(CONFIG_BLK_DEV_INITRD)
  104. if (r5) { /* initramfs */
  105. initrd_start = r5;
  106. initrd_end = r6;
  107. }
  108. #endif /* CONFIG_BLK_DEV_INITRD */
  109. dtb_passed = r6;
  110. if (r7)
  111. strncpy(cmdline_passed, (char *)r7, COMMAND_LINE_SIZE);
  112. }
  113. #endif
  114. early_init_devtree((void *)dtb_passed);
  115. #ifndef CONFIG_CMDLINE_FORCE
  116. if (cmdline_passed[0])
  117. strncpy(boot_command_line, cmdline_passed, COMMAND_LINE_SIZE);
  118. #ifdef CONFIG_NIOS2_CMDLINE_IGNORE_DTB
  119. else
  120. strncpy(boot_command_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
  121. #endif
  122. #endif
  123. parse_early_param();
  124. }
  125. void __init setup_arch(char **cmdline_p)
  126. {
  127. int dram_start;
  128. console_verbose();
  129. dram_start = memblock_start_of_DRAM();
  130. memory_size = memblock_phys_mem_size();
  131. memory_start = PAGE_ALIGN((unsigned long)__pa(_end));
  132. memory_end = (unsigned long) CONFIG_NIOS2_MEM_BASE + memory_size;
  133. init_mm.start_code = (unsigned long) _stext;
  134. init_mm.end_code = (unsigned long) _etext;
  135. init_mm.end_data = (unsigned long) _edata;
  136. init_mm.brk = (unsigned long) _end;
  137. init_task.thread.kregs = &fake_regs;
  138. /* Keep a copy of command line */
  139. *cmdline_p = boot_command_line;
  140. min_low_pfn = PFN_UP(memory_start);
  141. max_low_pfn = PFN_DOWN(memory_end);
  142. max_mapnr = max_low_pfn;
  143. memblock_reserve(dram_start, memory_start - dram_start);
  144. #ifdef CONFIG_BLK_DEV_INITRD
  145. if (initrd_start) {
  146. memblock_reserve(virt_to_phys((void *)initrd_start),
  147. initrd_end - initrd_start);
  148. }
  149. #endif /* CONFIG_BLK_DEV_INITRD */
  150. early_init_fdt_reserve_self();
  151. early_init_fdt_scan_reserved_mem();
  152. unflatten_and_copy_device_tree();
  153. setup_cpuinfo();
  154. copy_exception_handler(cpuinfo.exception_addr);
  155. mmu_init();
  156. copy_fast_tlb_miss_handler(cpuinfo.fast_tlb_miss_exc_addr);
  157. /*
  158. * Initialize MMU context handling here because data from cpuinfo is
  159. * needed for this.
  160. */
  161. mmu_context_init();
  162. /*
  163. * get kmalloc into gear
  164. */
  165. paging_init();
  166. #if defined(CONFIG_VT) && defined(CONFIG_DUMMY_CONSOLE)
  167. conswitchp = &dummy_con;
  168. #endif
  169. }