init.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <linux/ioport.h>
  2. #include <linux/swap.h>
  3. #include <asm/cacheflush.h>
  4. #include <asm/page.h>
  5. #include <asm/page_types.h>
  6. #include <asm/sections.h>
  7. #include <asm/system.h>
  8. /*
  9. * devmem_is_allowed() checks to see if /dev/mem access to a certain address
  10. * is valid. The argument is a physical page number.
  11. *
  12. *
  13. * On x86, access has to be given to the first megabyte of ram because that area
  14. * contains bios code and data regions used by X and dosemu and similar apps.
  15. * Access has to be given to non-kernel-ram areas as well, these contain the PCI
  16. * mmio resources as well as potential bios/acpi data regions.
  17. */
  18. int devmem_is_allowed(unsigned long pagenr)
  19. {
  20. if (pagenr <= 256)
  21. return 1;
  22. if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
  23. return 0;
  24. if (!page_is_ram(pagenr))
  25. return 1;
  26. return 0;
  27. }
  28. void free_init_pages(char *what, unsigned long begin, unsigned long end)
  29. {
  30. unsigned long addr = begin;
  31. if (addr >= end)
  32. return;
  33. /*
  34. * If debugging page accesses then do not free this memory but
  35. * mark them not present - any buggy init-section access will
  36. * create a kernel page fault:
  37. */
  38. #ifdef CONFIG_DEBUG_PAGEALLOC
  39. printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
  40. begin, PAGE_ALIGN(end));
  41. set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
  42. #else
  43. /*
  44. * We just marked the kernel text read only above, now that
  45. * we are going to free part of that, we need to make that
  46. * writeable first.
  47. */
  48. set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
  49. printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
  50. for (; addr < end; addr += PAGE_SIZE) {
  51. ClearPageReserved(virt_to_page(addr));
  52. init_page_count(virt_to_page(addr));
  53. memset((void *)(addr & ~(PAGE_SIZE-1)),
  54. POISON_FREE_INITMEM, PAGE_SIZE);
  55. free_page(addr);
  56. totalram_pages++;
  57. }
  58. #endif
  59. }
  60. void free_initmem(void)
  61. {
  62. free_init_pages("unused kernel memory",
  63. (unsigned long)(&__init_begin),
  64. (unsigned long)(&__init_end));
  65. }
  66. #ifdef CONFIG_BLK_DEV_INITRD
  67. void free_initrd_mem(unsigned long start, unsigned long end)
  68. {
  69. free_init_pages("initrd memory", start, end);
  70. }
  71. #endif