From 8aa8423cfd6fc5bf55cecc870249d3b3ef3be77c Mon Sep 17 00:00:00 2001 From: Stefan Kalkowski Date: Thu, 3 Nov 2016 14:49:23 +0100 Subject: [PATCH] hw: rework mapping and page-flags Ref #2092 --- repos/base-hw/src/core/include/mapping.h | 52 ++++++++++++++++ repos/base-hw/src/core/include/page_flags.h | 65 ++++++++++++-------- repos/base-hw/src/core/include/pager.h | 33 +--------- repos/base-hw/src/core/pager.cc | 23 ------- repos/base-hw/src/core/region_map_support.cc | 9 +-- 5 files changed, 94 insertions(+), 88 deletions(-) create mode 100644 repos/base-hw/src/core/include/mapping.h diff --git a/repos/base-hw/src/core/include/mapping.h b/repos/base-hw/src/core/include/mapping.h new file mode 100644 index 000000000..bb4d483de --- /dev/null +++ b/repos/base-hw/src/core/include/mapping.h @@ -0,0 +1,52 @@ +/* + * \brief Representation of physical to virtual memory mappings + * \author Stefan Kalkowski + * \date 2016-11-03 + */ + +/* + * Copyright (C) 2016 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU General Public License version 2. + */ + +#ifndef _MAPPING_H_ +#define _MAPPING_H_ + +#include +#include + +namespace Genode { struct Mapping; } + +struct Genode::Mapping +{ + addr_t phys = 0; + addr_t virt = 0; + size_t size = 0; + Page_flags flags; + + Mapping() {} + + Mapping(addr_t virt, addr_t phys, Cache_attribute cacheable, + bool io, unsigned size_log2, bool writeable) + : phys(phys), virt(virt), size(1 << size_log2), + flags{ writeable, true, false, false, io, cacheable } {} + + Mapping(addr_t phys, addr_t virt, size_t size, Page_flags flags) + : phys(phys), virt(virt), size(size), flags(flags) {} + + void print(Output & out) const + { + Genode::print(out, "phys=", (void*)phys, " => virt=", (void*) virt, + " (size=", Hex(size, Hex::PREFIX, Hex::PAD), + " page-flags: ", flags, ")"); + } + + /** + * Dummy implementation used by generic region_map code + */ + void prepare_map_operation() {} +}; + +#endif /* _MAPPING_H_ */ diff --git a/repos/base-hw/src/core/include/page_flags.h b/repos/base-hw/src/core/include/page_flags.h index 891d041d4..a83377657 100644 --- a/repos/base-hw/src/core/include/page_flags.h +++ b/repos/base-hw/src/core/include/page_flags.h @@ -15,37 +15,50 @@ #define _CORE__INCLUDE__PAGE_FLAGS_H_ #include +#include -namespace Genode +namespace Genode { struct Page_flags; } + +struct Genode::Page_flags { + bool writeable; + bool executable; + bool privileged; + bool global; + bool device; + Cache_attribute cacheable; + /** - * Map app-specific mem attributes to a TLB-specific POD + * Create flag POD for Genode pagers */ - struct Page_flags + static const Page_flags + apply_mapping(bool const writeable, + Cache_attribute const cacheable, + bool const io_mem) { + return Page_flags { writeable, true, false, false, + io_mem, cacheable }; } + + /** + * Create flag POD for the mode transition region + */ + static const Page_flags mode_transition() { + return Page_flags { true, true, true, true, false, CACHED }; } + + void print(Output & out) const { - bool writeable; - bool executable; - bool privileged; - bool global; - bool device; - Cache_attribute cacheable; + using Genode::print; - /** - * Create flag POD for Genode pagers - */ - static const Page_flags - apply_mapping(bool const writeable, - Cache_attribute const cacheable, - bool const io_mem) { - return Page_flags { writeable, true, false, false, - io_mem, cacheable }; } - - /** - * Create flag POD for the mode transition region - */ - static const Page_flags mode_transition() { - return Page_flags { true, true, true, true, false, CACHED }; } - }; -} + print(out, writeable ? "writeable, " : "readonly, ", + executable ? "exec, " : "noexec, "); + if (privileged) print(out, "privileged, "); + if (global) print(out, "global, "); + if (device) print(out, "iomem, "); + switch (cacheable) { + case UNCACHED: print(out, "uncached"); break; + case CACHED: print(out, "cached"); break; + case WRITE_COMBINED: print(out, "write-combined"); break; + }; + } +}; #endif /* _CORE__INCLUDE__PAGE_FLAGS_H_ */ diff --git a/repos/base-hw/src/core/include/pager.h b/repos/base-hw/src/core/include/pager.h index 5b9b4c651..520538cc2 100644 --- a/repos/base-hw/src/core/include/pager.h +++ b/repos/base-hw/src/core/include/pager.h @@ -26,17 +26,12 @@ /* core-local includes */ #include +#include #include #include namespace Genode { - - /** - * Translation of a virtual page frame - */ - struct Mapping; - /** * Interface between the generic paging system and the base-hw backend */ @@ -55,32 +50,6 @@ namespace Genode enum { PAGER_EP_STACK_SIZE = sizeof(addr_t) * 2048 }; } -struct Genode::Mapping -{ - addr_t virt_address; - addr_t phys_address; - Cache_attribute cacheable; - bool io_mem; - unsigned size_log2; - bool writable; - - /** - * Constructor for invalid mappings - */ - Mapping(); - - /** - * Constructor for valid mappings - */ - Mapping(addr_t const va, addr_t const pa, Cache_attribute const c, - bool const io, unsigned const sl2, bool const w); - - /** - * Prepare for the application of the mapping - */ - void prepare_map_operation(); -}; - class Genode::Ipc_pager { protected: diff --git a/repos/base-hw/src/core/pager.cc b/repos/base-hw/src/core/pager.cc index 8bafbde4e..db25a4ea8 100644 --- a/repos/base-hw/src/core/pager.cc +++ b/repos/base-hw/src/core/pager.cc @@ -25,29 +25,6 @@ using namespace Genode; -/************* - ** Mapping ** - *************/ - -Mapping::Mapping(addr_t const va, addr_t const pa, - Cache_attribute const c, bool const io, - unsigned const sl2, bool const w) -: - virt_address(va), phys_address(pa), cacheable(c), - io_mem(io), size_log2(sl2), writable(w) -{ } - - -Mapping::Mapping() -: -virt_address(0), phys_address(0), cacheable(CACHED), - io_mem(0), size_log2(0), writable(0) -{ } - - -void Mapping::prepare_map_operation() { } - - /*************** ** Ipc_pager ** ***************/ diff --git a/repos/base-hw/src/core/region_map_support.cc b/repos/base-hw/src/core/region_map_support.cc index 7ff832012..75badc1ae 100644 --- a/repos/base-hw/src/core/region_map_support.cc +++ b/repos/base-hw/src/core/region_map_support.cc @@ -81,13 +81,8 @@ void Pager_entrypoint::entry() if (!locked_ptr.valid()) return; Hw::Address_space * as = static_cast(&*locked_ptr); - Page_flags const flags = - Page_flags::apply_mapping(_mapping.writable, - _mapping.cacheable, - _mapping.io_mem); - as->insert_translation(_mapping.virt_address, - _mapping.phys_address, - 1 << _mapping.size_log2, flags); + as->insert_translation(_mapping.virt, _mapping.phys, + _mapping.size, _mapping.flags); } /* let pager object go back to no-fault state */