From 826c81ac180e5b868e6f42928fa0c5fbf55f88c0 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Tue, 27 Oct 2015 14:26:40 +0100 Subject: [PATCH] hw_x86: discover all physical memory in core Fixes #1741 --- .../src/core/spec/x86/platform_support.cc | 16 ++----- .../src/core/spec/x86_64/kernel/crt0.s | 6 +++ .../core/spec/x86_64/muen/platform_support.cc | 10 +++++ .../src/core/spec/x86_64/platform_support.cc | 44 ++++++++++++++++++- tool/run/power_on/qemu | 4 -- 5 files changed, 63 insertions(+), 17 deletions(-) diff --git a/repos/base-hw/src/core/spec/x86/platform_support.cc b/repos/base-hw/src/core/spec/x86/platform_support.cc index 146b54fa90..973d04d3aa 100644 --- a/repos/base-hw/src/core/spec/x86/platform_support.cc +++ b/repos/base-hw/src/core/spec/x86/platform_support.cc @@ -3,8 +3,6 @@ * \author Norman Feske * \author Reto Buerki * \date 2013-04-05 - * - * XXX dimension allocators according to the available physical memory */ /* @@ -21,16 +19,6 @@ using namespace Genode; -Native_region * Platform::_ram_regions(unsigned const i) -{ - static Native_region _regions[] = - { - { 2*1024*1024, 1024*1024*254 } - }; - return i < sizeof(_regions)/sizeof(_regions[0]) ? &_regions[i] : 0; -} - - void Platform::_init_io_port_alloc() { _io_port_alloc.add_range(0, 0x10000); @@ -55,6 +43,10 @@ void Platform::_init_io_mem_alloc() _io_mem_alloc.add_range(0, ~0x0UL); alloc_exclude_regions(&_io_mem_alloc, _ram_regions); alloc_exclude_regions(&_io_mem_alloc, _core_only_ram_regions); + alloc_exclude_regions(&_io_mem_alloc, _core_only_mmio_regions); + + /* exclude all mmio regions from virt allocator of core */ + alloc_exclude_regions(_core_mem_alloc.virt_alloc(), _core_only_mmio_regions); } diff --git a/repos/base-hw/src/core/spec/x86_64/kernel/crt0.s b/repos/base-hw/src/core/spec/x86_64/kernel/crt0.s index 5dffb5add4..3968ce6915 100644 --- a/repos/base-hw/src/core/spec/x86_64/kernel/crt0.s +++ b/repos/base-hw/src/core/spec/x86_64/kernel/crt0.s @@ -91,6 +91,9 @@ leaq _stack_high@GOTPCREL(%rip),%rax movq (%rax), %rsp + movq __initial_bx@GOTPCREL(%rip),%rax + movq %rbx, (%rax) + /* uniprocessor kernel-initialization which activates multiprocessor */ call init_kernel_up @@ -121,3 +124,6 @@ .p2align 8 .space 32 * 1024 _stack_high: + .globl __initial_bx + __initial_bx: + .space 8 diff --git a/repos/base-hw/src/core/spec/x86_64/muen/platform_support.cc b/repos/base-hw/src/core/spec/x86_64/muen/platform_support.cc index d8b2fbd2af..33893c029a 100644 --- a/repos/base-hw/src/core/spec/x86_64/muen/platform_support.cc +++ b/repos/base-hw/src/core/spec/x86_64/muen/platform_support.cc @@ -30,3 +30,13 @@ Native_region * Platform::_core_only_mmio_regions(unsigned const i) } void Platform::setup_irq_mode(unsigned, unsigned, unsigned) { } + + +Native_region * Platform::_ram_regions(unsigned const i) +{ + static Native_region _regions[] = + { + { 2*1024*1024, 1024*1024*254 } + }; + return i < sizeof(_regions)/sizeof(_regions[0]) ? &_regions[i] : 0; +} diff --git a/repos/base-hw/src/core/spec/x86_64/platform_support.cc b/repos/base-hw/src/core/spec/x86_64/platform_support.cc index 81aab63545..c9820e0955 100644 --- a/repos/base-hw/src/core/spec/x86_64/platform_support.cc +++ b/repos/base-hw/src/core/spec/x86_64/platform_support.cc @@ -16,17 +16,29 @@ #include #include #include +#include using namespace Genode; +/* contains physical pointer to multiboot */ +extern "C" Genode::addr_t __initial_bx; + + Native_region * Platform::_core_only_mmio_regions(unsigned const i) { static Native_region _regions[] = { { Board::MMIO_LAPIC_BASE, Board::MMIO_LAPIC_SIZE }, { Board::MMIO_IOAPIC_BASE, Board::MMIO_IOAPIC_SIZE }, + { 0, 0} }; - return i < sizeof(_regions)/sizeof(_regions[0]) ? &_regions[i] : 0; + + unsigned const max = sizeof(_regions) / sizeof(_regions[0]); + + if (!_regions[max - 1].size) + _regions[max - 1] = { __initial_bx & ~0xFFFUL, get_page_size() }; + + return i < max ? &_regions[i] : nullptr; } @@ -35,3 +47,33 @@ void Platform::setup_irq_mode(unsigned irq_number, unsigned trigger, { Kernel::pic()->ioapic.setup_irq_mode(irq_number, trigger, polarity); } + + +Native_region * Platform::_ram_regions(unsigned const i) +{ + static Native_region _regions[16]; + + Multiboot_info::Mmap v = Genode::Multiboot_info(__initial_bx).phys_ram(i); + if (!v.base) + return nullptr; + + Multiboot_info::Mmap::Addr::access_t base = v.read(); + Multiboot_info::Mmap::Length::access_t size = v.read(); + + unsigned const max = sizeof(_regions) / sizeof(_regions[0]); + + if (i < max && _regions[i].size == 0) { + if (base == 0 && size >= get_page_size()) { + /* + * Exclude first physical page, so that it will become part of the + * MMIO allocator. The framebuffer requests this page as MMIO. + */ + base = get_page_size(); + size -= get_page_size(); + } + _regions[i] = { base, size }; + } else if (i >= max) + PWRN("physical ram region 0x%llx+0x%llx will be not used", base, size); + + return i < max ? &_regions[i] : nullptr; +} diff --git a/tool/run/power_on/qemu b/tool/run/power_on/qemu index 80761c9062..8cbac78f32 100644 --- a/tool/run/power_on/qemu +++ b/tool/run/power_on/qemu @@ -51,10 +51,6 @@ proc run_power_on { } { } if {[have_spec vpb926]} { append qemu_args " -M versatilepb -m 128 " } if {[have_spec zynq_qemu]} { append qemu_args " -M xilinx-zynq-a9 -cpu cortex-a9 -m 256 " } - if {[have_spec hw_x86_64]} { - regsub -all {\-m ([0-9])+} $qemu_args "" qemu_args - append qemu_args " -m 512 " - } # add devices for specific platforms if {[have_spec zynq] && [have_spec cadence_gem]} { append qemu_args " -net nic,model=cadence_gem" }