init.c 4.5 KB

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