setup.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2007-2009 PetaLogix
  4. * Copyright (C) 2006 Atmark Techno, Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/clocksource.h>
  12. #include <linux/string.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/cpu.h>
  15. #include <linux/initrd.h>
  16. #include <linux/console.h>
  17. #include <linux/debugfs.h>
  18. #include <asm/setup.h>
  19. #include <asm/sections.h>
  20. #include <asm/page.h>
  21. #include <linux/io.h>
  22. #include <linux/bug.h>
  23. #include <linux/param.h>
  24. #include <linux/pci.h>
  25. #include <linux/cache.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/dma-mapping.h>
  28. #include <asm/cacheflush.h>
  29. #include <asm/entry.h>
  30. #include <asm/cpuinfo.h>
  31. #include <asm/prom.h>
  32. #include <asm/pgtable.h>
  33. DEFINE_PER_CPU(unsigned int, KSP); /* Saved kernel stack pointer */
  34. DEFINE_PER_CPU(unsigned int, KM); /* Kernel/user mode */
  35. DEFINE_PER_CPU(unsigned int, ENTRY_SP); /* Saved SP on kernel entry */
  36. DEFINE_PER_CPU(unsigned int, R11_SAVE); /* Temp variable for entry */
  37. DEFINE_PER_CPU(unsigned int, CURRENT_SAVE); /* Saved current pointer */
  38. unsigned int boot_cpuid;
  39. /*
  40. * Placed cmd_line to .data section because can be initialized from
  41. * ASM code. Default position is BSS section which is cleared
  42. * in machine_early_init().
  43. */
  44. char cmd_line[COMMAND_LINE_SIZE] __attribute__ ((section(".data")));
  45. void __init setup_arch(char **cmdline_p)
  46. {
  47. *cmdline_p = cmd_line;
  48. console_verbose();
  49. unflatten_device_tree();
  50. setup_cpuinfo();
  51. microblaze_cache_init();
  52. setup_memory();
  53. #ifdef CONFIG_EARLY_PRINTK
  54. /* remap early console to virtual address */
  55. remap_early_printk();
  56. #endif
  57. xilinx_pci_init();
  58. #ifdef CONFIG_VT
  59. #if defined(CONFIG_XILINX_CONSOLE)
  60. conswitchp = &xil_con;
  61. #elif defined(CONFIG_DUMMY_CONSOLE)
  62. conswitchp = &dummy_con;
  63. #endif
  64. #endif
  65. }
  66. #ifdef CONFIG_MTD_UCLINUX
  67. /* Handle both romfs and cramfs types, without generating unnecessary
  68. code (ie no point checking for CRAMFS if it's not even enabled) */
  69. inline unsigned get_romfs_len(unsigned *addr)
  70. {
  71. #ifdef CONFIG_ROMFS_FS
  72. if (memcmp(&addr[0], "-rom1fs-", 8) == 0) /* romfs */
  73. return be32_to_cpu(addr[2]);
  74. #endif
  75. #ifdef CONFIG_CRAMFS
  76. if (addr[0] == le32_to_cpu(0x28cd3d45)) /* cramfs */
  77. return le32_to_cpu(addr[1]);
  78. #endif
  79. return 0;
  80. }
  81. #endif /* CONFIG_MTD_UCLINUX_EBSS */
  82. unsigned long kernel_tlb;
  83. void __init machine_early_init(const char *cmdline, unsigned int ram,
  84. unsigned int fdt, unsigned int msr, unsigned int tlb0,
  85. unsigned int tlb1)
  86. {
  87. unsigned long *src, *dst;
  88. unsigned int offset = 0;
  89. /* If CONFIG_MTD_UCLINUX is defined, assume ROMFS is at the
  90. * end of kernel. There are two position which we want to check.
  91. * The first is __init_end and the second __bss_start.
  92. */
  93. #ifdef CONFIG_MTD_UCLINUX
  94. int romfs_size;
  95. unsigned int romfs_base;
  96. char *old_klimit = klimit;
  97. romfs_base = (ram ? ram : (unsigned int)&__init_end);
  98. romfs_size = PAGE_ALIGN(get_romfs_len((unsigned *)romfs_base));
  99. if (!romfs_size) {
  100. romfs_base = (unsigned int)&__bss_start;
  101. romfs_size = PAGE_ALIGN(get_romfs_len((unsigned *)romfs_base));
  102. }
  103. /* Move ROMFS out of BSS before clearing it */
  104. if (romfs_size > 0) {
  105. memmove(&__bss_stop, (int *)romfs_base, romfs_size);
  106. klimit += romfs_size;
  107. }
  108. #endif
  109. /* clearing bss section */
  110. memset(__bss_start, 0, __bss_stop-__bss_start);
  111. memset(_ssbss, 0, _esbss-_ssbss);
  112. lockdep_init();
  113. /* initialize device tree for usage in early_printk */
  114. early_init_devtree((void *)_fdt_start);
  115. #ifdef CONFIG_EARLY_PRINTK
  116. setup_early_printk(NULL);
  117. #endif
  118. /* setup kernel_tlb after BSS cleaning
  119. * Maybe worth to move to asm code */
  120. kernel_tlb = tlb0 + tlb1;
  121. /* printk("TLB1 0x%08x, TLB0 0x%08x, tlb 0x%x\n", tlb0,
  122. tlb1, kernel_tlb); */
  123. pr_info("Ramdisk addr 0x%08x, ", ram);
  124. if (fdt)
  125. pr_info("FDT at 0x%08x\n", fdt);
  126. else
  127. pr_info("Compiled-in FDT at 0x%08x\n",
  128. (unsigned int)_fdt_start);
  129. #ifdef CONFIG_MTD_UCLINUX
  130. pr_info("Found romfs @ 0x%08x (0x%08x)\n",
  131. romfs_base, romfs_size);
  132. pr_info("#### klimit %p ####\n", old_klimit);
  133. BUG_ON(romfs_size < 0); /* What else can we do? */
  134. pr_info("Moved 0x%08x bytes from 0x%08x to 0x%08x\n",
  135. romfs_size, romfs_base, (unsigned)&__bss_stop);
  136. pr_info("New klimit: 0x%08x\n", (unsigned)klimit);
  137. #endif
  138. #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
  139. if (msr) {
  140. pr_info("!!!Your kernel has setup MSR instruction but ");
  141. pr_cont("CPU don't have it %x\n", msr);
  142. }
  143. #else
  144. if (!msr) {
  145. pr_info("!!!Your kernel not setup MSR instruction but ");
  146. pr_cont"CPU have it %x\n", msr);
  147. }
  148. #endif
  149. /* Do not copy reset vectors. offset = 0x2 means skip the first
  150. * two instructions. dst is pointer to MB vectors which are placed
  151. * in block ram. If you want to copy reset vector setup offset to 0x0 */
  152. #if !CONFIG_MANUAL_RESET_VECTOR
  153. offset = 0x2;
  154. #endif
  155. dst = (unsigned long *) (offset * sizeof(u32));
  156. for (src = __ivt_start + offset; src < __ivt_end; src++, dst++)
  157. *dst = *src;
  158. /* Initialize global data */
  159. per_cpu(KM, 0) = 0x1; /* We start in kernel mode */
  160. per_cpu(CURRENT_SAVE, 0) = (unsigned long)current;
  161. }
  162. void __init time_init(void)
  163. {
  164. clocksource_of_init();
  165. }
  166. #ifdef CONFIG_DEBUG_FS
  167. struct dentry *of_debugfs_root;
  168. static int microblaze_debugfs_init(void)
  169. {
  170. of_debugfs_root = debugfs_create_dir("microblaze", NULL);
  171. return of_debugfs_root == NULL;
  172. }
  173. arch_initcall(microblaze_debugfs_init);
  174. # ifdef CONFIG_MMU
  175. static int __init debugfs_tlb(void)
  176. {
  177. struct dentry *d;
  178. if (!of_debugfs_root)
  179. return -ENODEV;
  180. d = debugfs_create_u32("tlb_skip", S_IRUGO, of_debugfs_root, &tlb_skip);
  181. if (!d)
  182. return -ENOMEM;
  183. return 0;
  184. }
  185. device_initcall(debugfs_tlb);
  186. # endif
  187. #endif
  188. static int dflt_bus_notify(struct notifier_block *nb,
  189. unsigned long action, void *data)
  190. {
  191. struct device *dev = data;
  192. /* We are only intereted in device addition */
  193. if (action != BUS_NOTIFY_ADD_DEVICE)
  194. return 0;
  195. set_dma_ops(dev, &dma_direct_ops);
  196. return NOTIFY_DONE;
  197. }
  198. static struct notifier_block dflt_plat_bus_notifier = {
  199. .notifier_call = dflt_bus_notify,
  200. .priority = INT_MAX,
  201. };
  202. static int __init setup_bus_notifier(void)
  203. {
  204. bus_register_notifier(&platform_bus_type, &dflt_plat_bus_notifier);
  205. return 0;
  206. }
  207. arch_initcall(setup_bus_notifier);