init.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. * Copyright (C) 2004-2006 Atmel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/gfp.h>
  10. #include <linux/mm.h>
  11. #include <linux/swap.h>
  12. #include <linux/init.h>
  13. #include <linux/mmzone.h>
  14. #include <linux/module.h>
  15. #include <linux/bootmem.h>
  16. #include <linux/pagemap.h>
  17. #include <linux/nodemask.h>
  18. #include <asm/page.h>
  19. #include <asm/mmu_context.h>
  20. #include <asm/tlb.h>
  21. #include <asm/io.h>
  22. #include <asm/dma.h>
  23. #include <asm/setup.h>
  24. #include <asm/sections.h>
  25. pgd_t swapper_pg_dir[PTRS_PER_PGD] __page_aligned_data;
  26. struct page *empty_zero_page;
  27. EXPORT_SYMBOL(empty_zero_page);
  28. /*
  29. * Cache of MMU context last used.
  30. */
  31. unsigned long mmu_context_cache = NO_CONTEXT;
  32. /*
  33. * paging_init() sets up the page tables
  34. *
  35. * This routine also unmaps the page at virtual kernel address 0, so
  36. * that we can trap those pesky NULL-reference errors in the kernel.
  37. */
  38. void __init paging_init(void)
  39. {
  40. extern unsigned long _evba;
  41. void *zero_page;
  42. int nid;
  43. /*
  44. * Make sure we can handle exceptions before enabling
  45. * paging. Not that we should ever _get_ any exceptions this
  46. * early, but you never know...
  47. */
  48. printk("Exception vectors start at %p\n", &_evba);
  49. sysreg_write(EVBA, (unsigned long)&_evba);
  50. /*
  51. * Since we are ready to handle exceptions now, we should let
  52. * the CPU generate them...
  53. */
  54. __asm__ __volatile__ ("csrf %0" : : "i"(SR_EM_BIT));
  55. /*
  56. * Allocate the zero page. The allocator will panic if it
  57. * can't satisfy the request, so no need to check.
  58. */
  59. zero_page = alloc_bootmem_low_pages_node(NODE_DATA(0),
  60. PAGE_SIZE);
  61. sysreg_write(PTBR, (unsigned long)swapper_pg_dir);
  62. enable_mmu();
  63. printk ("CPU: Paging enabled\n");
  64. for_each_online_node(nid) {
  65. pg_data_t *pgdat = NODE_DATA(nid);
  66. unsigned long zones_size[MAX_NR_ZONES];
  67. unsigned long low, start_pfn;
  68. start_pfn = pgdat->bdata->node_min_pfn;
  69. low = pgdat->bdata->node_low_pfn;
  70. memset(zones_size, 0, sizeof(zones_size));
  71. zones_size[ZONE_NORMAL] = low - start_pfn;
  72. printk("Node %u: start_pfn = 0x%lx, low = 0x%lx\n",
  73. nid, start_pfn, low);
  74. free_area_init_node(nid, zones_size, start_pfn, NULL);
  75. printk("Node %u: mem_map starts at %p\n",
  76. pgdat->node_id, pgdat->node_mem_map);
  77. }
  78. mem_map = NODE_DATA(0)->node_mem_map;
  79. empty_zero_page = virt_to_page(zero_page);
  80. flush_dcache_page(empty_zero_page);
  81. }
  82. void __init mem_init(void)
  83. {
  84. int codesize, reservedpages, datasize, initsize;
  85. int nid, i;
  86. reservedpages = 0;
  87. high_memory = NULL;
  88. /* this will put all low memory onto the freelists */
  89. for_each_online_node(nid) {
  90. pg_data_t *pgdat = NODE_DATA(nid);
  91. unsigned long node_pages = 0;
  92. void *node_high_memory;
  93. num_physpages += pgdat->node_present_pages;
  94. if (pgdat->node_spanned_pages != 0)
  95. node_pages = free_all_bootmem_node(pgdat);
  96. totalram_pages += node_pages;
  97. for (i = 0; i < node_pages; i++)
  98. if (PageReserved(pgdat->node_mem_map + i))
  99. reservedpages++;
  100. node_high_memory = (void *)((pgdat->node_start_pfn
  101. + pgdat->node_spanned_pages)
  102. << PAGE_SHIFT);
  103. if (node_high_memory > high_memory)
  104. high_memory = node_high_memory;
  105. }
  106. max_mapnr = MAP_NR(high_memory);
  107. codesize = (unsigned long)_etext - (unsigned long)_text;
  108. datasize = (unsigned long)_edata - (unsigned long)_data;
  109. initsize = (unsigned long)__init_end - (unsigned long)__init_begin;
  110. printk ("Memory: %luk/%luk available (%dk kernel code, "
  111. "%dk reserved, %dk data, %dk init)\n",
  112. nr_free_pages() << (PAGE_SHIFT - 10),
  113. totalram_pages << (PAGE_SHIFT - 10),
  114. codesize >> 10,
  115. reservedpages << (PAGE_SHIFT - 10),
  116. datasize >> 10,
  117. initsize >> 10);
  118. }
  119. static inline void free_area(unsigned long addr, unsigned long end, char *s)
  120. {
  121. unsigned int size = (end - addr) >> 10;
  122. for (; addr < end; addr += PAGE_SIZE) {
  123. struct page *page = virt_to_page(addr);
  124. ClearPageReserved(page);
  125. init_page_count(page);
  126. free_page(addr);
  127. totalram_pages++;
  128. }
  129. if (size && s)
  130. printk(KERN_INFO "Freeing %s memory: %dK (%lx - %lx)\n",
  131. s, size, end - (size << 10), end);
  132. }
  133. void free_initmem(void)
  134. {
  135. free_area((unsigned long)__init_begin, (unsigned long)__init_end,
  136. "init");
  137. }
  138. #ifdef CONFIG_BLK_DEV_INITRD
  139. void free_initrd_mem(unsigned long start, unsigned long end)
  140. {
  141. free_area(start, end, "initrd");
  142. }
  143. #endif