aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/mm/init.c
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2012-11-16 19:39:01 -0800
committerH. Peter Anvin <hpa@linux.intel.com>2012-11-17 11:59:23 -0800
commit5c51bdbe4c74dce7996d0bbfa39974775cc3f13c (patch)
tree42c95d78f80b73307c4df17c80c03b2e701e7372 /arch/x86/mm/init.c
parent868bf4d6b94c980d3ad87f892a5e528b8ee2c320 (diff)
x86, mm: Merge alloc_low_page between 64bit and 32bit
They are almost same except 64 bit need to handle after_bootmem case. Add mm_internal.h to make that alloc_low_page() only to be accessible from arch/x86/mm/init*.c Signed-off-by: Yinghai Lu <yinghai@kernel.org> Link: http://lkml.kernel.org/r/1353123563-3103-25-git-send-email-yinghai@kernel.org Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'arch/x86/mm/init.c')
-rw-r--r--arch/x86/mm/init.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
index 2393d0099e7..848189229b2 100644
--- a/arch/x86/mm/init.c
+++ b/arch/x86/mm/init.c
@@ -17,10 +17,44 @@
#include <asm/proto.h>
#include <asm/dma.h> /* for MAX_DMA_PFN */
+#include "mm_internal.h"
+
unsigned long __initdata pgt_buf_start;
unsigned long __meminitdata pgt_buf_end;
unsigned long __meminitdata pgt_buf_top;
+__ref void *alloc_low_page(void)
+{
+ unsigned long pfn;
+ void *adr;
+
+#ifdef CONFIG_X86_64
+ if (after_bootmem) {
+ adr = (void *)get_zeroed_page(GFP_ATOMIC | __GFP_NOTRACK);
+
+ return adr;
+ }
+#endif
+
+ if ((pgt_buf_end + 1) >= pgt_buf_top) {
+ unsigned long ret;
+ if (min_pfn_mapped >= max_pfn_mapped)
+ panic("alloc_low_page: ran out of memory");
+ ret = memblock_find_in_range(min_pfn_mapped << PAGE_SHIFT,
+ max_pfn_mapped << PAGE_SHIFT,
+ PAGE_SIZE, PAGE_SIZE);
+ if (!ret)
+ panic("alloc_low_page: can not alloc memory");
+ memblock_reserve(ret, PAGE_SIZE);
+ pfn = ret >> PAGE_SHIFT;
+ } else
+ pfn = pgt_buf_end++;
+
+ adr = __va(pfn * PAGE_SIZE);
+ clear_page(adr);
+ return adr;
+}
+
/* need 4 4k for initial PMD_SIZE, 4k for 0-ISA_END_ADDRESS */
#define INIT_PGT_BUF_SIZE (5 * PAGE_SIZE)
RESERVE_BRK(early_pgt_alloc, INIT_PGT_BUF_SIZE);