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