setup.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*
  2. * arch/v850/kernel/setup.c -- Arch-dependent initialization functions
  3. *
  4. * Copyright (C) 2001,02,03 NEC Electronics Corporation
  5. * Copyright (C) 2001,02,03 Miles Bader <miles@gnu.org>
  6. *
  7. * This file is subject to the terms and conditions of the GNU General
  8. * Public License. See the file COPYING in the main directory of this
  9. * archive for more details.
  10. *
  11. * Written by Miles Bader <miles@gnu.org>
  12. */
  13. #include <linux/mm.h>
  14. #include <linux/bootmem.h>
  15. #include <linux/swap.h> /* we don't have swap, but for nr_free_pages */
  16. #include <linux/irq.h>
  17. #include <linux/reboot.h>
  18. #include <linux/personality.h>
  19. #include <linux/major.h>
  20. #include <linux/root_dev.h>
  21. #include <linux/mtd/mtd.h>
  22. #include <linux/init.h>
  23. #include <asm/irq.h>
  24. #include <asm/setup.h>
  25. #include "mach.h"
  26. /* These symbols are all defined in the linker map to delineate various
  27. statically allocated regions of memory. */
  28. extern char _intv_start, _intv_end;
  29. /* `kram' is only used if the kernel uses part of normal user RAM. */
  30. extern char _kram_start __attribute__ ((__weak__));
  31. extern char _kram_end __attribute__ ((__weak__));
  32. extern char _init_start, _init_end;
  33. extern char _bootmap;
  34. extern char _stext, _etext, _sdata, _edata, _sbss, _ebss;
  35. /* Many platforms use an embedded root image. */
  36. extern char _root_fs_image_start __attribute__ ((__weak__));
  37. extern char _root_fs_image_end __attribute__ ((__weak__));
  38. char command_line[COMMAND_LINE_SIZE];
  39. /* Memory not used by the kernel. */
  40. static unsigned long total_ram_pages;
  41. /* System RAM. */
  42. static unsigned long ram_start = 0, ram_len = 0;
  43. #define ADDR_TO_PAGE_UP(x) ((((unsigned long)x) + PAGE_SIZE-1) >> PAGE_SHIFT)
  44. #define ADDR_TO_PAGE(x) (((unsigned long)x) >> PAGE_SHIFT)
  45. #define PAGE_TO_ADDR(x) (((unsigned long)x) << PAGE_SHIFT)
  46. static void init_mem_alloc (unsigned long ram_start, unsigned long ram_len);
  47. void set_mem_root (void *addr, size_t len, char *cmd_line);
  48. void __init setup_arch (char **cmdline)
  49. {
  50. /* Keep a copy of command line */
  51. *cmdline = command_line;
  52. memcpy (saved_command_line, command_line, COMMAND_LINE_SIZE);
  53. saved_command_line[COMMAND_LINE_SIZE - 1] = '\0';
  54. console_verbose ();
  55. init_mm.start_code = (unsigned long) &_stext;
  56. init_mm.end_code = (unsigned long) &_etext;
  57. init_mm.end_data = (unsigned long) &_edata;
  58. init_mm.brk = (unsigned long) &_kram_end;
  59. /* Find out what mem this machine has. */
  60. mach_get_physical_ram (&ram_start, &ram_len);
  61. /* ... and tell the kernel about it. */
  62. init_mem_alloc (ram_start, ram_len);
  63. printk (KERN_INFO "CPU: %s\nPlatform: %s\n",
  64. CPU_MODEL_LONG, PLATFORM_LONG);
  65. /* do machine-specific setups. */
  66. mach_setup (cmdline);
  67. #ifdef CONFIG_MTD
  68. if (!ROOT_DEV && &_root_fs_image_end > &_root_fs_image_start)
  69. set_mem_root (&_root_fs_image_start,
  70. &_root_fs_image_end - &_root_fs_image_start,
  71. *cmdline);
  72. #endif
  73. }
  74. void __init trap_init (void)
  75. {
  76. }
  77. #ifdef CONFIG_MTD
  78. /* Set the root filesystem to be the given memory region.
  79. Some parameter may be appended to CMD_LINE. */
  80. void set_mem_root (void *addr, size_t len, char *cmd_line)
  81. {
  82. /* The only way to pass info to the MTD slram driver is via
  83. the command line. */
  84. if (*cmd_line) {
  85. cmd_line += strlen (cmd_line);
  86. *cmd_line++ = ' ';
  87. }
  88. sprintf (cmd_line, "slram=root,0x%x,+0x%x", (u32)addr, (u32)len);
  89. ROOT_DEV = MKDEV (MTD_BLOCK_MAJOR, 0);
  90. }
  91. #endif
  92. static void irq_nop (unsigned irq) { }
  93. static unsigned irq_zero (unsigned irq) { return 0; }
  94. static void nmi_end (unsigned irq)
  95. {
  96. if (irq != IRQ_NMI (0)) {
  97. printk (KERN_CRIT "NMI %d is unrecoverable; restarting...",
  98. irq - IRQ_NMI (0));
  99. machine_restart (0);
  100. }
  101. }
  102. static struct hw_interrupt_type nmi_irq_type = {
  103. "NMI",
  104. irq_zero, /* startup */
  105. irq_nop, /* shutdown */
  106. irq_nop, /* enable */
  107. irq_nop, /* disable */
  108. irq_nop, /* ack */
  109. nmi_end, /* end */
  110. };
  111. void __init init_IRQ (void)
  112. {
  113. init_irq_handlers (0, NUM_MACH_IRQS, 1, 0);
  114. init_irq_handlers (IRQ_NMI (0), NUM_NMIS, 1, &nmi_irq_type);
  115. mach_init_irqs ();
  116. }
  117. void __init mem_init (void)
  118. {
  119. max_mapnr = MAP_NR (ram_start + ram_len);
  120. num_physpages = ADDR_TO_PAGE (ram_len);
  121. total_ram_pages = free_all_bootmem ();
  122. printk (KERN_INFO
  123. "Memory: %luK/%luK available"
  124. " (%luK kernel code, %luK data)\n",
  125. PAGE_TO_ADDR (nr_free_pages()) / 1024,
  126. ram_len / 1024,
  127. ((unsigned long)&_etext - (unsigned long)&_stext) / 1024,
  128. ((unsigned long)&_ebss - (unsigned long)&_sdata) / 1024);
  129. }
  130. void free_initmem (void)
  131. {
  132. unsigned long ram_end = ram_start + ram_len;
  133. unsigned long start = PAGE_ALIGN ((unsigned long)(&_init_start));
  134. if (start >= ram_start && start < ram_end) {
  135. unsigned long addr;
  136. unsigned long end = PAGE_ALIGN ((unsigned long)(&_init_end));
  137. if (end > ram_end)
  138. end = ram_end;
  139. printk("Freeing unused kernel memory: %ldK freed\n",
  140. (end - start) / 1024);
  141. for (addr = start; addr < end; addr += PAGE_SIZE) {
  142. struct page *page = virt_to_page (addr);
  143. ClearPageReserved (page);
  144. set_page_count (page, 1);
  145. __free_page (page);
  146. total_ram_pages++;
  147. }
  148. }
  149. }
  150. /* Initialize the `bootmem allocator'. RAM_START and RAM_LEN identify
  151. what RAM may be used. */
  152. static void __init
  153. init_bootmem_alloc (unsigned long ram_start, unsigned long ram_len)
  154. {
  155. /* The part of the kernel that's in the same managed RAM space
  156. used for general allocation. */
  157. unsigned long kram_start = (unsigned long)&_kram_start;
  158. unsigned long kram_end = (unsigned long)&_kram_end;
  159. /* End of the managed RAM space. */
  160. unsigned long ram_end = ram_start + ram_len;
  161. /* Address range of the interrupt vector table. */
  162. unsigned long intv_start = (unsigned long)&_intv_start;
  163. unsigned long intv_end = (unsigned long)&_intv_end;
  164. /* True if the interrupt vectors are in the managed RAM area. */
  165. int intv_in_ram = (intv_end > ram_start && intv_start < ram_end);
  166. /* True if the interrupt vectors are inside the kernel's RAM. */
  167. int intv_in_kram = (intv_end > kram_start && intv_start < kram_end);
  168. /* A pointer to an optional function that reserves platform-specific
  169. memory regions. We declare the pointer `volatile' to avoid gcc
  170. turning the call into a static call (the problem is that since
  171. it's a weak symbol, a static call may end up trying to reference
  172. the location 0x0, which is not always reachable). */
  173. void (*volatile mrb) (void) = mach_reserve_bootmem;
  174. /* The bootmem allocator's allocation bitmap. */
  175. unsigned long bootmap = (unsigned long)&_bootmap;
  176. unsigned long bootmap_len;
  177. /* Round bootmap location up to next page. */
  178. bootmap = PAGE_TO_ADDR (ADDR_TO_PAGE_UP (bootmap));
  179. /* Initialize bootmem allocator. */
  180. bootmap_len = init_bootmem_node (NODE_DATA (0),
  181. ADDR_TO_PAGE (bootmap),
  182. ADDR_TO_PAGE (PAGE_OFFSET),
  183. ADDR_TO_PAGE (ram_end));
  184. /* Now make the RAM actually allocatable (it starts out `reserved'). */
  185. free_bootmem (ram_start, ram_len);
  186. if (kram_end > kram_start)
  187. /* Reserve the RAM part of the kernel's address space, so it
  188. doesn't get allocated. */
  189. reserve_bootmem (kram_start, kram_end - kram_start);
  190. if (intv_in_ram && !intv_in_kram)
  191. /* Reserve the interrupt vector space. */
  192. reserve_bootmem (intv_start, intv_end - intv_start);
  193. if (bootmap >= ram_start && bootmap < ram_end)
  194. /* Reserve the bootmap space. */
  195. reserve_bootmem (bootmap, bootmap_len);
  196. /* Reserve the memory used by the root filesystem image if it's
  197. in RAM. */
  198. if (&_root_fs_image_end > &_root_fs_image_start
  199. && (unsigned long)&_root_fs_image_start >= ram_start
  200. && (unsigned long)&_root_fs_image_start < ram_end)
  201. reserve_bootmem ((unsigned long)&_root_fs_image_start,
  202. &_root_fs_image_end - &_root_fs_image_start);
  203. /* Let the platform-dependent code reserve some too. */
  204. if (mrb)
  205. (*mrb) ();
  206. }
  207. /* Tell the kernel about what RAM it may use for memory allocation. */
  208. static void __init
  209. init_mem_alloc (unsigned long ram_start, unsigned long ram_len)
  210. {
  211. unsigned i;
  212. unsigned long zones_size[MAX_NR_ZONES];
  213. init_bootmem_alloc (ram_start, ram_len);
  214. for (i = 0; i < MAX_NR_ZONES; i++)
  215. zones_size[i] = 0;
  216. /* We stuff all the memory into one area, which includes the
  217. initial gap from PAGE_OFFSET to ram_start. */
  218. zones_size[ZONE_DMA]
  219. = ADDR_TO_PAGE (ram_len + (ram_start - PAGE_OFFSET));
  220. /* The allocator is very picky about the address of the first
  221. allocatable page -- it must be at least as aligned as the
  222. maximum allocation -- so try to detect cases where it will get
  223. confused and signal them at compile time (this is a common
  224. problem when porting to a new platform with ). There is a
  225. similar runtime check in free_area_init_core. */
  226. #if ((PAGE_OFFSET >> PAGE_SHIFT) & ((1UL << (MAX_ORDER - 1)) - 1))
  227. #error MAX_ORDER is too large for given PAGE_OFFSET (use CONFIG_FORCE_MAX_ZONEORDER to change it)
  228. #endif
  229. NODE_DATA(0)->node_mem_map = NULL;
  230. free_area_init_node (0, NODE_DATA(0), zones_size,
  231. ADDR_TO_PAGE (PAGE_OFFSET), 0);
  232. }