init.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Port on Texas Instruments TMS320C6x architecture
  3. *
  4. * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
  5. * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/mm.h>
  12. #include <linux/swap.h>
  13. #include <linux/module.h>
  14. #include <linux/bootmem.h>
  15. #ifdef CONFIG_BLK_DEV_RAM
  16. #include <linux/blkdev.h>
  17. #endif
  18. #include <linux/initrd.h>
  19. #include <asm/sections.h>
  20. /*
  21. * ZERO_PAGE is a special page that is used for zero-initialized
  22. * data and COW.
  23. */
  24. unsigned long empty_zero_page;
  25. EXPORT_SYMBOL(empty_zero_page);
  26. /*
  27. * paging_init() continues the virtual memory environment setup which
  28. * was begun by the code in arch/head.S.
  29. * The parameters are pointers to where to stick the starting and ending
  30. * addresses of available kernel virtual memory.
  31. */
  32. void __init paging_init(void)
  33. {
  34. struct pglist_data *pgdat = NODE_DATA(0);
  35. unsigned long zones_size[MAX_NR_ZONES] = {0, };
  36. empty_zero_page = (unsigned long) alloc_bootmem_pages(PAGE_SIZE);
  37. memset((void *)empty_zero_page, 0, PAGE_SIZE);
  38. /*
  39. * Set up user data space
  40. */
  41. set_fs(KERNEL_DS);
  42. /*
  43. * Define zones
  44. */
  45. zones_size[ZONE_NORMAL] = (memory_end - PAGE_OFFSET) >> PAGE_SHIFT;
  46. pgdat->node_zones[ZONE_NORMAL].zone_start_pfn =
  47. __pa(PAGE_OFFSET) >> PAGE_SHIFT;
  48. free_area_init(zones_size);
  49. }
  50. void __init mem_init(void)
  51. {
  52. int codek, datak;
  53. unsigned long tmp;
  54. unsigned long len = memory_end - memory_start;
  55. high_memory = (void *)(memory_end & PAGE_MASK);
  56. /* this will put all memory onto the freelists */
  57. totalram_pages = free_all_bootmem();
  58. codek = (_etext - _stext) >> 10;
  59. datak = (_end - _sdata) >> 10;
  60. tmp = nr_free_pages() << PAGE_SHIFT;
  61. printk(KERN_INFO "Memory: %luk/%luk RAM (%dk kernel code, %dk data)\n",
  62. tmp >> 10, len >> 10, codek, datak);
  63. }
  64. #ifdef CONFIG_BLK_DEV_INITRD
  65. void __init free_initrd_mem(unsigned long start, unsigned long end)
  66. {
  67. int pages = 0;
  68. for (; start < end; start += PAGE_SIZE) {
  69. ClearPageReserved(virt_to_page(start));
  70. init_page_count(virt_to_page(start));
  71. free_page(start);
  72. totalram_pages++;
  73. pages++;
  74. }
  75. printk(KERN_INFO "Freeing initrd memory: %luk freed\n",
  76. (pages * PAGE_SIZE) >> 10);
  77. }
  78. #endif
  79. void __init free_initmem(void)
  80. {
  81. unsigned long addr;
  82. /*
  83. * The following code should be cool even if these sections
  84. * are not page aligned.
  85. */
  86. addr = PAGE_ALIGN((unsigned long)(__init_begin));
  87. /* next to check that the page we free is not a partial page */
  88. for (; addr + PAGE_SIZE < (unsigned long)(__init_end);
  89. addr += PAGE_SIZE) {
  90. ClearPageReserved(virt_to_page(addr));
  91. init_page_count(virt_to_page(addr));
  92. free_page(addr);
  93. totalram_pages++;
  94. }
  95. printk(KERN_INFO "Freeing unused kernel memory: %dK freed\n",
  96. (int) ((addr - PAGE_ALIGN((long) &__init_begin)) >> 10));
  97. }