init.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. pg_data_t *pgdat;
  85. high_memory = NULL;
  86. for_each_online_pgdat(pgdat)
  87. high_memory = max_t(void *, high_memory,
  88. __va(pgdat_end_pfn(pgdat) << PAGE_SHIFT));
  89. set_max_mapnr(MAP_NR(high_memory));
  90. free_all_bootmem();
  91. mem_init_print_info(NULL);
  92. }
  93. void free_initmem(void)
  94. {
  95. free_initmem_default(-1);
  96. }
  97. #ifdef CONFIG_BLK_DEV_INITRD
  98. void free_initrd_mem(unsigned long start, unsigned long end)
  99. {
  100. free_reserved_area((void *)start, (void *)end, -1, "initrd");
  101. }
  102. #endif