aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/mm
diff options
context:
space:
mode:
authorPekka Enberg <penberg@cs.helsinki.fi>2009-03-03 06:15:06 -0500
committerIngo Molnar <mingo@elte.hu>2009-03-03 06:21:18 -0500
commite5b2bb552706ca0e30795ee84caacbb37cec5705 (patch)
tree7f34ac3dcb658df87ac6f88e52c3fcaed261d50e /arch/x86/mm
parente087edd8c056292191bb989baf49f83ee509e624 (diff)
x86: unify free_init_pages() and free_initmem()
Impact: unification This patch introduces a common arch/x86/mm/init.c and moves the identical free_init_pages() and free_initmem() functions to the file. Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi> LKML-Reference: <1236078906.2675.18.camel@penberg-laptop> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch/x86/mm')
-rw-r--r--arch/x86/mm/Makefile2
-rw-r--r--arch/x86/mm/init.c49
-rw-r--r--arch/x86/mm/init_32.c44
-rw-r--r--arch/x86/mm/init_64.c44
4 files changed, 50 insertions, 89 deletions
diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
index 2b938a384910..08537747cb58 100644
--- a/arch/x86/mm/Makefile
+++ b/arch/x86/mm/Makefile
@@ -1,4 +1,4 @@
1obj-y := init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \ 1obj-y := init.o init_$(BITS).o fault.o ioremap.o extable.o pageattr.o mmap.o \
2 pat.o pgtable.o gup.o 2 pat.o pgtable.o gup.o
3 3
4obj-$(CONFIG_SMP) += tlb.o 4obj-$(CONFIG_SMP) += tlb.o
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
new file mode 100644
index 000000000000..ce6a722587d8
--- /dev/null
+++ b/arch/x86/mm/init.c
@@ -0,0 +1,49 @@
1#include <linux/swap.h>
2#include <asm/cacheflush.h>
3#include <asm/page.h>
4#include <asm/sections.h>
5#include <asm/system.h>
6
7void free_init_pages(char *what, unsigned long begin, unsigned long end)
8{
9 unsigned long addr = begin;
10
11 if (addr >= end)
12 return;
13
14 /*
15 * If debugging page accesses then do not free this memory but
16 * mark them not present - any buggy init-section access will
17 * create a kernel page fault:
18 */
19#ifdef CONFIG_DEBUG_PAGEALLOC
20 printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
21 begin, PAGE_ALIGN(end));
22 set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
23#else
24 /*
25 * We just marked the kernel text read only above, now that
26 * we are going to free part of that, we need to make that
27 * writeable first.
28 */
29 set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
30
31 printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
32
33 for (; addr < end; addr += PAGE_SIZE) {
34 ClearPageReserved(virt_to_page(addr));
35 init_page_count(virt_to_page(addr));
36 memset((void *)(addr & ~(PAGE_SIZE-1)),
37 POISON_FREE_INITMEM, PAGE_SIZE);
38 free_page(addr);
39 totalram_pages++;
40 }
41#endif
42}
43
44void free_initmem(void)
45{
46 free_init_pages("unused kernel memory",
47 (unsigned long)(&__init_begin),
48 (unsigned long)(&__init_end));
49}
diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
index 1570a822c18a..cd8d67326138 100644
--- a/arch/x86/mm/init_32.c
+++ b/arch/x86/mm/init_32.c
@@ -1212,50 +1212,6 @@ void mark_rodata_ro(void)
1212} 1212}
1213#endif 1213#endif
1214 1214
1215void free_init_pages(char *what, unsigned long begin, unsigned long end)
1216{
1217 unsigned long addr = begin;
1218
1219 if (addr >= end)
1220 return;
1221
1222 /*
1223 * If debugging page accesses then do not free this memory but
1224 * mark them not present - any buggy init-section access will
1225 * create a kernel page fault:
1226 */
1227#ifdef CONFIG_DEBUG_PAGEALLOC
1228 printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
1229 begin, PAGE_ALIGN(end));
1230 set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
1231#else
1232 /*
1233 * We just marked the kernel text read only above, now that
1234 * we are going to free part of that, we need to make that
1235 * writeable first.
1236 */
1237 set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
1238
1239 printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
1240
1241 for (; addr < end; addr += PAGE_SIZE) {
1242 ClearPageReserved(virt_to_page(addr));
1243 init_page_count(virt_to_page(addr));
1244 memset((void *)(addr & ~(PAGE_SIZE-1)),
1245 POISON_FREE_INITMEM, PAGE_SIZE);
1246 free_page(addr);
1247 totalram_pages++;
1248 }
1249#endif
1250}
1251
1252void free_initmem(void)
1253{
1254 free_init_pages("unused kernel memory",
1255 (unsigned long)(&__init_begin),
1256 (unsigned long)(&__init_end));
1257}
1258
1259#ifdef CONFIG_BLK_DEV_INITRD 1215#ifdef CONFIG_BLK_DEV_INITRD
1260void free_initrd_mem(unsigned long start, unsigned long end) 1216void free_initrd_mem(unsigned long start, unsigned long end)
1261{ 1217{
diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
index 03da9030d0ee..aae87456d930 100644
--- a/arch/x86/mm/init_64.c
+++ b/arch/x86/mm/init_64.c
@@ -945,50 +945,6 @@ void __init mem_init(void)
945 initsize >> 10); 945 initsize >> 10);
946} 946}
947 947
948void free_init_pages(char *what, unsigned long begin, unsigned long end)
949{
950 unsigned long addr = begin;
951
952 if (addr >= end)
953 return;
954
955 /*
956 * If debugging page accesses then do not free this memory but
957 * mark them not present - any buggy init-section access will
958 * create a kernel page fault:
959 */
960#ifdef CONFIG_DEBUG_PAGEALLOC
961 printk(KERN_INFO "debug: unmapping init memory %08lx..%08lx\n",
962 begin, PAGE_ALIGN(end));
963 set_memory_np(begin, (end - begin) >> PAGE_SHIFT);
964#else
965 /*
966 * We just marked the kernel text read only above, now that
967 * we are going to free part of that, we need to make that
968 * writeable first.
969 */
970 set_memory_rw(begin, (end - begin) >> PAGE_SHIFT);
971
972 printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
973
974 for (; addr < end; addr += PAGE_SIZE) {
975 ClearPageReserved(virt_to_page(addr));
976 init_page_count(virt_to_page(addr));
977 memset((void *)(addr & ~(PAGE_SIZE-1)),
978 POISON_FREE_INITMEM, PAGE_SIZE);
979 free_page(addr);
980 totalram_pages++;
981 }
982#endif
983}
984
985void free_initmem(void)
986{
987 free_init_pages("unused kernel memory",
988 (unsigned long)(&__init_begin),
989 (unsigned long)(&__init_end));
990}
991
992#ifdef CONFIG_DEBUG_RODATA 948#ifdef CONFIG_DEBUG_RODATA
993const int rodata_test_data = 0xC3; 949const int rodata_test_data = 0xC3;
994EXPORT_SYMBOL_GPL(rodata_test_data); 950EXPORT_SYMBOL_GPL(rodata_test_data);