diff --git a/repos/base-hw/src/core/include/platform.h b/repos/base-hw/src/core/include/platform.h index bbb0f80a8f..06d3718a49 100644 --- a/repos/base-hw/src/core/include/platform.h +++ b/repos/base-hw/src/core/include/platform.h @@ -31,6 +31,12 @@ namespace Genode { + /** + * Function pointer that provides accessor to a pool of address regions. + */ + typedef Native_region * (*Region_pool)(unsigned const); + + /** * Manages all platform ressources */ @@ -59,6 +65,16 @@ namespace Genode { */ void _init_io_port_alloc(); + /** + * Initialize IO memory allocator + * + * Use byte granularity for MMIO regions because on some platforms, + * devices driven by core share a physical page with devices + * driven outside of core. Using byte granularity allows handing + * out the MMIO page to trusted user-level device drivers. + */ + void _init_io_mem_alloc(); + public: /** @@ -71,7 +87,6 @@ namespace Genode { * on the current platform. */ static Native_region * _ram_regions(unsigned i); - static Native_region * _mmio_regions(unsigned i); /** * Get one of the consecutively numbered core regions diff --git a/repos/base-hw/src/core/platform.cc b/repos/base-hw/src/core/platform.cc index 2aeabb0650..c00e1659ee 100644 --- a/repos/base-hw/src/core/platform.cc +++ b/repos/base-hw/src/core/platform.cc @@ -51,11 +51,6 @@ extern Bm_header _boot_modules_headers_end; extern int _boot_modules_binaries_begin; extern int _boot_modules_binaries_end; -/** - * Functionpointer that provides accessor to a pool of address regions - */ -typedef Native_region * (*Region_pool)(unsigned const); - /** * Helper to initialise allocators through include/exclude region lists @@ -87,19 +82,6 @@ static void init_alloc(Range_allocator * const alloc, } -/** - * Helper to initialise allocators through include region lists - */ -static void init_alloc_core_mmio(Range_allocator * const alloc, - Region_pool incl_regions) -{ - /* make all include regions available */ - Native_region * r = incl_regions(0); - for (unsigned i = 0; r; r = incl_regions(++i)) - alloc->add_range(r->base, r->size); -} - - /************** ** Platform ** **************/ @@ -157,13 +139,7 @@ Platform::Platform() _irq_alloc.add_range(i, 1); } - /* - * Use byte granuarity for MMIO regions because on some platforms, devices - * driven by core share a physical page with devices driven outside of - * core. Using byte granuarlity allows handing out the MMIO page to trusted - * user-level device drivers. - */ - init_alloc_core_mmio(&_io_mem_alloc, _mmio_regions); + _init_io_mem_alloc(); /* add boot modules to ROM FS */ Bm_header * header = &_boot_modules_headers_begin; diff --git a/repos/base-hw/src/core/spec/arm/platform_support.cc b/repos/base-hw/src/core/spec/arm/platform_support.cc index 8666bb0002..3048168305 100644 --- a/repos/base-hw/src/core/spec/arm/platform_support.cc +++ b/repos/base-hw/src/core/spec/arm/platform_support.cc @@ -18,5 +18,15 @@ using namespace Genode; void Platform::_init_io_port_alloc() { }; +Native_region * mmio_regions(unsigned); -long Platform::irq(long const user_irq) { return user_irq; } \ No newline at end of file + +void Platform::_init_io_mem_alloc() +{ + Native_region * r = mmio_regions(0); + for (unsigned i = 0; r; r = mmio_regions(++i)) + _io_mem_alloc.add_range(r->base, r->size); +}; + + +long Platform::irq(long const user_irq) { return user_irq; } diff --git a/repos/base-hw/src/core/spec/exynos5/platform_support.cc b/repos/base-hw/src/core/spec/exynos5/platform_support.cc index 237445c535..f910494be0 100644 --- a/repos/base-hw/src/core/spec/exynos5/platform_support.cc +++ b/repos/base-hw/src/core/spec/exynos5/platform_support.cc @@ -31,7 +31,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { diff --git a/repos/base-hw/src/core/spec/imx53/platform_support.cc b/repos/base-hw/src/core/spec/imx53/platform_support.cc index fc58b47f0d..aebbcffecf 100644 --- a/repos/base-hw/src/core/spec/imx53/platform_support.cc +++ b/repos/base-hw/src/core/spec/imx53/platform_support.cc @@ -30,7 +30,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { diff --git a/repos/base-hw/src/core/spec/imx53/trustzone/platform_support.cc b/repos/base-hw/src/core/spec/imx53/trustzone/platform_support.cc index 9a0c639279..846bf9bdb8 100644 --- a/repos/base-hw/src/core/spec/imx53/trustzone/platform_support.cc +++ b/repos/base-hw/src/core/spec/imx53/trustzone/platform_support.cc @@ -71,7 +71,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { diff --git a/repos/base-hw/src/core/spec/imx6/platform_support.cc b/repos/base-hw/src/core/spec/imx6/platform_support.cc index b8cdf7b3b9..2a236e5c77 100644 --- a/repos/base-hw/src/core/spec/imx6/platform_support.cc +++ b/repos/base-hw/src/core/spec/imx6/platform_support.cc @@ -29,7 +29,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { diff --git a/repos/base-hw/src/core/spec/panda/platform_support.cc b/repos/base-hw/src/core/spec/panda/platform_support.cc index f1012a4178..b8822244bd 100644 --- a/repos/base-hw/src/core/spec/panda/platform_support.cc +++ b/repos/base-hw/src/core/spec/panda/platform_support.cc @@ -30,7 +30,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { diff --git a/repos/base-hw/src/core/spec/pbxa9/platform_support.cc b/repos/base-hw/src/core/spec/pbxa9/platform_support.cc index 19969c55b5..5ad01366fd 100644 --- a/repos/base-hw/src/core/spec/pbxa9/platform_support.cc +++ b/repos/base-hw/src/core/spec/pbxa9/platform_support.cc @@ -31,7 +31,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { diff --git a/repos/base-hw/src/core/spec/rpi/platform_support.cc b/repos/base-hw/src/core/spec/rpi/platform_support.cc index 86de095f2a..cc8947b3c8 100644 --- a/repos/base-hw/src/core/spec/rpi/platform_support.cc +++ b/repos/base-hw/src/core/spec/rpi/platform_support.cc @@ -28,7 +28,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { diff --git a/repos/base-hw/src/core/spec/vea9x4/platform_support.cc b/repos/base-hw/src/core/spec/vea9x4/platform_support.cc index 1511a89dcd..eb1ce3f733 100644 --- a/repos/base-hw/src/core/spec/vea9x4/platform_support.cc +++ b/repos/base-hw/src/core/spec/vea9x4/platform_support.cc @@ -32,7 +32,7 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) +Native_region * mmio_regions(unsigned const i) { static Native_region _regions[] = { 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 97811be405..8a824f0427 100644 --- a/repos/base-hw/src/core/spec/x86/platform_support.cc +++ b/repos/base-hw/src/core/spec/x86/platform_support.cc @@ -31,19 +31,6 @@ Native_region * Platform::_ram_regions(unsigned const i) } -Native_region * Platform::_mmio_regions(unsigned const i) -{ - static Native_region _regions[] = - { - { 0x00000000, 0x0001000 }, - { 0x000a0000, 0x0060000 }, - { 0xc0000000, 0x1000000 }, - { 0xfc000000, 0x1000000 }, - }; - return i < sizeof(_regions)/sizeof(_regions[0]) ? &_regions[i] : 0; -} - - Native_region * Platform::_core_only_mmio_regions(unsigned const i) { static Native_region _regions[] = @@ -61,6 +48,27 @@ void Platform::_init_io_port_alloc() } +/** + * Remove given exclude memory regions from specified allocator. + */ +static void alloc_exclude_regions(Range_allocator * const alloc, + Region_pool excl_regions) +{ + Native_region * r = excl_regions(0); + for (unsigned i = 0; r; r = excl_regions(++i)) + alloc->remove_range(r->base, r->size); +} + + +void Platform::_init_io_mem_alloc() +{ + /* add entire adress space minus the RAM memory regions */ + _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); +} + + long Platform::irq(long const user_irq) { /* remap IRQ requests to fit I/O APIC configuration */