setup.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. *
  3. * linux/arch/cris/kernel/setup.c
  4. *
  5. * Copyright (C) 1995 Linus Torvalds
  6. * Copyright (c) 2001 Axis Communications AB
  7. */
  8. /*
  9. * This file handles the architecture-dependent parts of initialization
  10. */
  11. #include <linux/init.h>
  12. #include <linux/mm.h>
  13. #include <linux/bootmem.h>
  14. #include <asm/pgtable.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/screen_info.h>
  17. #include <linux/utsname.h>
  18. #include <linux/pfn.h>
  19. #include <linux/cpu.h>
  20. #include <linux/of.h>
  21. #include <linux/of_fdt.h>
  22. #include <asm/setup.h>
  23. #include <arch/system.h>
  24. /*
  25. * Setup options
  26. */
  27. struct screen_info screen_info;
  28. extern int root_mountflags;
  29. extern char _etext, _edata, _end;
  30. char __initdata cris_command_line[COMMAND_LINE_SIZE] = { 0, };
  31. extern const unsigned long text_start, edata; /* set by the linker script */
  32. extern unsigned long dram_start, dram_end;
  33. extern unsigned long romfs_start, romfs_length, romfs_in_flash; /* from head.S */
  34. static struct cpu cpu_devices[NR_CPUS];
  35. extern void show_etrax_copyright(void); /* arch-vX/kernel/setup.c */
  36. /* This mainly sets up the memory area, and can be really confusing.
  37. *
  38. * The physical DRAM is virtually mapped into dram_start to dram_end
  39. * (usually c0000000 to c0000000 + DRAM size). The physical address is
  40. * given by the macro __pa().
  41. *
  42. * In this DRAM, the kernel code and data is loaded, in the beginning.
  43. * It really starts at c0004000 to make room for some special pages -
  44. * the start address is text_start. The kernel data ends at _end. After
  45. * this the ROM filesystem is appended (if there is any).
  46. *
  47. * Between this address and dram_end, we have RAM pages usable to the
  48. * boot code and the system.
  49. *
  50. */
  51. void __init setup_arch(char **cmdline_p)
  52. {
  53. extern void init_etrax_debug(void);
  54. unsigned long bootmap_size;
  55. unsigned long start_pfn, max_pfn;
  56. unsigned long memory_start;
  57. #ifdef CONFIG_OF
  58. early_init_dt_scan(__dtb_start);
  59. #endif
  60. /* register an initial console printing routine for printk's */
  61. init_etrax_debug();
  62. /* we should really poll for DRAM size! */
  63. high_memory = &dram_end;
  64. if(romfs_in_flash || !romfs_length) {
  65. /* if we have the romfs in flash, or if there is no rom filesystem,
  66. * our free area starts directly after the BSS
  67. */
  68. memory_start = (unsigned long) &_end;
  69. } else {
  70. /* otherwise the free area starts after the ROM filesystem */
  71. printk("ROM fs in RAM, size %lu bytes\n", romfs_length);
  72. memory_start = romfs_start + romfs_length;
  73. }
  74. /* process 1's initial memory region is the kernel code/data */
  75. init_mm.start_code = (unsigned long) &text_start;
  76. init_mm.end_code = (unsigned long) &_etext;
  77. init_mm.end_data = (unsigned long) &_edata;
  78. init_mm.brk = (unsigned long) &_end;
  79. /* min_low_pfn points to the start of DRAM, start_pfn points
  80. * to the first DRAM pages after the kernel, and max_low_pfn
  81. * to the end of DRAM.
  82. */
  83. /*
  84. * partially used pages are not usable - thus
  85. * we are rounding upwards:
  86. */
  87. start_pfn = PFN_UP(memory_start); /* usually c0000000 + kernel + romfs */
  88. max_pfn = PFN_DOWN((unsigned long)high_memory); /* usually c0000000 + dram size */
  89. /*
  90. * Initialize the boot-time allocator (start, end)
  91. *
  92. * We give it access to all our DRAM, but we could as well just have
  93. * given it a small slice. No point in doing that though, unless we
  94. * have non-contiguous memory and want the boot-stuff to be in, say,
  95. * the smallest area.
  96. *
  97. * It will put a bitmap of the allocated pages in the beginning
  98. * of the range we give it, but it won't mark the bitmaps pages
  99. * as reserved. We have to do that ourselves below.
  100. *
  101. * We need to use init_bootmem_node instead of init_bootmem
  102. * because our map starts at a quite high address (min_low_pfn).
  103. */
  104. max_low_pfn = max_pfn;
  105. min_low_pfn = PAGE_OFFSET >> PAGE_SHIFT;
  106. bootmap_size = init_bootmem_node(NODE_DATA(0), start_pfn,
  107. min_low_pfn,
  108. max_low_pfn);
  109. /* And free all memory not belonging to the kernel (addr, size) */
  110. free_bootmem(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn - start_pfn));
  111. /*
  112. * Reserve the bootmem bitmap itself as well. We do this in two
  113. * steps (first step was init_bootmem()) because this catches
  114. * the (very unlikely) case of us accidentally initializing the
  115. * bootmem allocator with an invalid RAM area.
  116. *
  117. * Arguments are start, size
  118. */
  119. reserve_bootmem(PFN_PHYS(start_pfn), bootmap_size, BOOTMEM_DEFAULT);
  120. unflatten_and_copy_device_tree();
  121. /* paging_init() sets up the MMU and marks all pages as reserved */
  122. paging_init();
  123. *cmdline_p = cris_command_line;
  124. #ifdef CONFIG_ETRAX_CMDLINE
  125. if (!strcmp(cris_command_line, "")) {
  126. strlcpy(cris_command_line, CONFIG_ETRAX_CMDLINE, COMMAND_LINE_SIZE);
  127. cris_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  128. }
  129. #endif
  130. /* Save command line for future references. */
  131. memcpy(boot_command_line, cris_command_line, COMMAND_LINE_SIZE);
  132. boot_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  133. /* give credit for the CRIS port */
  134. show_etrax_copyright();
  135. /* Setup utsname */
  136. strcpy(init_utsname()->machine, cris_machine_name);
  137. }
  138. #ifdef CONFIG_PROC_FS
  139. static void *c_start(struct seq_file *m, loff_t *pos)
  140. {
  141. return *pos < nr_cpu_ids ? (void *)(int)(*pos + 1) : NULL;
  142. }
  143. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  144. {
  145. ++*pos;
  146. return c_start(m, pos);
  147. }
  148. static void c_stop(struct seq_file *m, void *v)
  149. {
  150. }
  151. extern int show_cpuinfo(struct seq_file *m, void *v);
  152. const struct seq_operations cpuinfo_op = {
  153. .start = c_start,
  154. .next = c_next,
  155. .stop = c_stop,
  156. .show = show_cpuinfo,
  157. };
  158. #endif /* CONFIG_PROC_FS */
  159. static int __init topology_init(void)
  160. {
  161. int i;
  162. for_each_possible_cpu(i) {
  163. return register_cpu(&cpu_devices[i], i);
  164. }
  165. return 0;
  166. }
  167. subsys_initcall(topology_init);