2008-02-23 15:58:20 +07:00
|
|
|
/*
|
|
|
|
* linux/arch/i386/kernel/head32.c -- prepare to run common code
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Andrea Arcangeli <andrea@suse.de> SuSE
|
|
|
|
* Copyright (C) 2007 Eric Biederman <ebiederm@xmission.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/start_kernel.h>
|
x86: Make sure free_init_pages() frees pages on page boundary
When CONFIG_NO_BOOTMEM=y, it could use memory more effiently, or
in a more compact fashion.
Example:
Allocated new RAMDISK: 00ec2000 - 0248ce57
Move RAMDISK from 000000002ea04000 - 000000002ffcee56 to 00ec2000 - 0248ce56
The new RAMDISK's end is not page aligned.
Last page could be shared with other users.
When free_init_pages are called for initrd or .init, the page
could be freed and we could corrupt other data.
code segment in free_init_pages():
| for (; addr < end; addr += PAGE_SIZE) {
| ClearPageReserved(virt_to_page(addr));
| init_page_count(virt_to_page(addr));
| memset((void *)(addr & ~(PAGE_SIZE-1)),
| POISON_FREE_INITMEM, PAGE_SIZE);
| free_page(addr);
| totalram_pages++;
| }
last half page could be used as one whole free page.
So page align the boundaries.
-v2: make the original initramdisk to be aligned, according to
Johannes, otherwise we have the chance to lose one page.
we still need to keep initrd_end not aligned, otherwise it could
confuse decompressor.
-v3: change to WARN_ON instead, suggested by Johannes.
-v4: use PAGE_ALIGN, suggested by Johannes.
We may fix that macro name later to PAGE_ALIGN_UP, and PAGE_ALIGN_DOWN
Add comments about assuming ramdisk start is aligned
in relocate_initrd(), change to re get ramdisk_image instead of save it
to make diff smaller. Add warning for wrong range, suggested by Johannes.
-v6: remove one WARN()
We need to align beginning in free_init_pages()
do not copy more than ramdisk_size, noticed by Johannes
Reported-by: Stanislaw Gruszka <sgruszka@redhat.com>
Tested-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Miller <davem@davemloft.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
LKML-Reference: <1269830604-26214-3-git-send-email-yinghai@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-03-29 09:42:55 +07:00
|
|
|
#include <linux/mm.h>
|
2008-02-23 15:58:20 +07:00
|
|
|
|
2008-05-18 15:18:57 +07:00
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
#include <asm/e820.h>
|
2009-08-19 19:36:27 +07:00
|
|
|
#include <asm/page.h>
|
2008-12-08 06:50:22 +07:00
|
|
|
#include <asm/trampoline.h>
|
2009-08-20 14:27:29 +07:00
|
|
|
#include <asm/apic.h>
|
|
|
|
#include <asm/io_apic.h>
|
2009-08-29 20:03:59 +07:00
|
|
|
#include <asm/bios_ebda.h>
|
|
|
|
|
|
|
|
static void __init i386_default_early_setup(void)
|
|
|
|
{
|
|
|
|
/* Initilize 32bit specific setup functions */
|
|
|
|
x86_init.resources.probe_roms = probe_roms;
|
|
|
|
x86_init.resources.reserve_resources = i386_reserve_resources;
|
|
|
|
x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
|
|
|
|
|
|
|
|
reserve_ebda_region();
|
|
|
|
}
|
2008-05-18 15:18:57 +07:00
|
|
|
|
2008-02-23 15:58:20 +07:00
|
|
|
void __init i386_start_kernel(void)
|
|
|
|
{
|
2010-02-10 16:20:23 +07:00
|
|
|
#ifdef CONFIG_X86_TRAMPOLINE
|
|
|
|
/*
|
|
|
|
* But first pinch a few for the stack/trampoline stuff
|
|
|
|
* FIXME: Don't need the extra page at 4K, but need to fix
|
|
|
|
* trampoline before removing it. (see the GDT stuff)
|
|
|
|
*/
|
|
|
|
reserve_early_overlap_ok(PAGE_SIZE, PAGE_SIZE + PAGE_SIZE,
|
|
|
|
"EX TRAMPOLINE");
|
|
|
|
#endif
|
|
|
|
|
x86: add brk allocation for very, very early allocations
Impact: new interface
Add a brk()-like allocator which effectively extends the bss in order
to allow very early code to do dynamic allocations. This is better than
using statically allocated arrays for data in subsystems which may never
get used.
The space for brk allocations is in the bss ELF segment, so that the
space is mapped properly by the code which maps the kernel, and so
that bootloaders keep the space free rather than putting a ramdisk or
something into it.
The bss itself, delimited by __bss_stop, ends before the brk area
(__brk_base to __brk_limit). The kernel text, data and bss is reserved
up to __bss_stop.
Any brk-allocated data is reserved separately just before the kernel
pagetable is built, as that code allocates from unreserved spaces
in the e820 map, potentially allocating from any unused brk memory.
Ultimately any unused memory in the brk area is used in the general
kernel memory pool.
Initially the brk space is set to 1MB, which is probably much larger
than any user needs (the largest current user is i386 head_32.S's code
to build the pagetables to map the kernel, which can get fairly large
with a big kernel image and no PSE support). So long as the system
has sufficient memory for the bootloader to reserve the kernel+1MB brk,
there are no bad effects resulting from an over-large brk.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-02-27 08:35:44 +07:00
|
|
|
reserve_early(__pa_symbol(&_text), __pa_symbol(&__bss_stop), "TEXT DATA BSS");
|
2008-05-18 15:18:57 +07:00
|
|
|
|
|
|
|
#ifdef CONFIG_BLK_DEV_INITRD
|
|
|
|
/* Reserve INITRD */
|
|
|
|
if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
|
x86: Make sure free_init_pages() frees pages on page boundary
When CONFIG_NO_BOOTMEM=y, it could use memory more effiently, or
in a more compact fashion.
Example:
Allocated new RAMDISK: 00ec2000 - 0248ce57
Move RAMDISK from 000000002ea04000 - 000000002ffcee56 to 00ec2000 - 0248ce56
The new RAMDISK's end is not page aligned.
Last page could be shared with other users.
When free_init_pages are called for initrd or .init, the page
could be freed and we could corrupt other data.
code segment in free_init_pages():
| for (; addr < end; addr += PAGE_SIZE) {
| ClearPageReserved(virt_to_page(addr));
| init_page_count(virt_to_page(addr));
| memset((void *)(addr & ~(PAGE_SIZE-1)),
| POISON_FREE_INITMEM, PAGE_SIZE);
| free_page(addr);
| totalram_pages++;
| }
last half page could be used as one whole free page.
So page align the boundaries.
-v2: make the original initramdisk to be aligned, according to
Johannes, otherwise we have the chance to lose one page.
we still need to keep initrd_end not aligned, otherwise it could
confuse decompressor.
-v3: change to WARN_ON instead, suggested by Johannes.
-v4: use PAGE_ALIGN, suggested by Johannes.
We may fix that macro name later to PAGE_ALIGN_UP, and PAGE_ALIGN_DOWN
Add comments about assuming ramdisk start is aligned
in relocate_initrd(), change to re get ramdisk_image instead of save it
to make diff smaller. Add warning for wrong range, suggested by Johannes.
-v6: remove one WARN()
We need to align beginning in free_init_pages()
do not copy more than ramdisk_size, noticed by Johannes
Reported-by: Stanislaw Gruszka <sgruszka@redhat.com>
Tested-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Miller <davem@davemloft.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
LKML-Reference: <1269830604-26214-3-git-send-email-yinghai@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-03-29 09:42:55 +07:00
|
|
|
/* Assume only end is not page aligned */
|
2008-05-18 15:18:57 +07:00
|
|
|
u64 ramdisk_image = boot_params.hdr.ramdisk_image;
|
|
|
|
u64 ramdisk_size = boot_params.hdr.ramdisk_size;
|
x86: Make sure free_init_pages() frees pages on page boundary
When CONFIG_NO_BOOTMEM=y, it could use memory more effiently, or
in a more compact fashion.
Example:
Allocated new RAMDISK: 00ec2000 - 0248ce57
Move RAMDISK from 000000002ea04000 - 000000002ffcee56 to 00ec2000 - 0248ce56
The new RAMDISK's end is not page aligned.
Last page could be shared with other users.
When free_init_pages are called for initrd or .init, the page
could be freed and we could corrupt other data.
code segment in free_init_pages():
| for (; addr < end; addr += PAGE_SIZE) {
| ClearPageReserved(virt_to_page(addr));
| init_page_count(virt_to_page(addr));
| memset((void *)(addr & ~(PAGE_SIZE-1)),
| POISON_FREE_INITMEM, PAGE_SIZE);
| free_page(addr);
| totalram_pages++;
| }
last half page could be used as one whole free page.
So page align the boundaries.
-v2: make the original initramdisk to be aligned, according to
Johannes, otherwise we have the chance to lose one page.
we still need to keep initrd_end not aligned, otherwise it could
confuse decompressor.
-v3: change to WARN_ON instead, suggested by Johannes.
-v4: use PAGE_ALIGN, suggested by Johannes.
We may fix that macro name later to PAGE_ALIGN_UP, and PAGE_ALIGN_DOWN
Add comments about assuming ramdisk start is aligned
in relocate_initrd(), change to re get ramdisk_image instead of save it
to make diff smaller. Add warning for wrong range, suggested by Johannes.
-v6: remove one WARN()
We need to align beginning in free_init_pages()
do not copy more than ramdisk_size, noticed by Johannes
Reported-by: Stanislaw Gruszka <sgruszka@redhat.com>
Tested-by: Stanislaw Gruszka <sgruszka@redhat.com>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Cc: David Miller <davem@davemloft.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
LKML-Reference: <1269830604-26214-3-git-send-email-yinghai@kernel.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2010-03-29 09:42:55 +07:00
|
|
|
u64 ramdisk_end = PAGE_ALIGN(ramdisk_image + ramdisk_size);
|
2008-05-18 15:18:57 +07:00
|
|
|
reserve_early(ramdisk_image, ramdisk_end, "RAMDISK");
|
|
|
|
}
|
|
|
|
#endif
|
2009-08-19 19:43:56 +07:00
|
|
|
|
2009-08-29 20:03:59 +07:00
|
|
|
/* Call the subarch specific early setup function */
|
|
|
|
switch (boot_params.hdr.hardware_subarch) {
|
2009-08-29 19:54:20 +07:00
|
|
|
case X86_SUBARCH_MRST:
|
|
|
|
x86_mrst_early_setup();
|
|
|
|
break;
|
2009-08-29 20:03:59 +07:00
|
|
|
default:
|
|
|
|
i386_default_early_setup();
|
|
|
|
break;
|
|
|
|
}
|
2008-05-18 15:18:57 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* At this point everything still needed from the boot loader
|
|
|
|
* or BIOS or kernel text should be early reserved or marked not
|
|
|
|
* RAM in e820. All other memory is free game.
|
|
|
|
*/
|
|
|
|
|
2008-02-23 15:58:20 +07:00
|
|
|
start_kernel();
|
|
|
|
}
|