From 58e9856eb8cf1177bab11d5ee3caf7237bab7f7d Mon Sep 17 00:00:00 2001 From: Benjamin Lamowski Date: Tue, 14 May 2024 10:54:07 +0200 Subject: [PATCH] base: move page flags interface to base On hw, `Page_flags` is used throughout architectures. At the same time, it is used by the Intel IOMMU page table implementation in the pc platform driver. Consolidate the definition in base so it is available for all users. Issue #5217 --- repos/base-hw/src/bootstrap/platform.cc | 8 +- repos/base-hw/src/core/map_local.h | 6 +- repos/base-hw/src/core/platform.cc | 2 +- repos/base-hw/src/include/hw/mapping.h | 14 +++- repos/base-hw/src/include/hw/memory_map.h | 2 +- repos/base-hw/src/include/hw/page_flags.h | 74 ------------------- repos/base-hw/src/include/hw/spec/arm/lpae.h | 5 +- .../src/include/hw/spec/arm/page_table.h | 8 +- .../src/include/hw/spec/riscv/page_table.h | 16 ++-- .../src/include/hw/spec/x86_64/page_table.h | 3 +- .../x86_64/page_table => cpu}/page_flags.h | 6 +- .../spec/x86_64/page_table/page_table_base.h | 2 +- .../drivers/platform/pc/intel/page_table.h | 1 + 13 files changed, 45 insertions(+), 102 deletions(-) delete mode 100644 repos/base-hw/src/include/hw/page_flags.h rename repos/base/include/{spec/x86_64/page_table => cpu}/page_flags.h (91%) diff --git a/repos/base-hw/src/bootstrap/platform.cc b/repos/base-hw/src/bootstrap/platform.cc index d5d39978ba..4b818933de 100644 --- a/repos/base-hw/src/bootstrap/platform.cc +++ b/repos/base-hw/src/bootstrap/platform.cc @@ -66,9 +66,9 @@ Platform::Pd::Pd(Platform::Ram_allocator & alloc) using namespace Genode; addr_t const table_virt_base = Hw::Mm::core_page_tables().base; map_insert(Mapping((addr_t)table_base, table_virt_base, - sizeof(Table), Hw::PAGE_FLAGS_KERN_DATA)); + sizeof(Table), Genode::PAGE_FLAGS_KERN_DATA)); map_insert(Mapping((addr_t)array_base, table_virt_base + sizeof(Table), - sizeof(Table_array), Hw::PAGE_FLAGS_KERN_DATA)); + sizeof(Table_array), Genode::PAGE_FLAGS_KERN_DATA)); } @@ -183,7 +183,7 @@ Platform::Platform() /* temporarily map all bootstrap memory 1:1 for transition to core */ // FIXME do not insert as mapping for core core_pd->map_insert(Mapping(bootstrap_region.base, bootstrap_region.base, - (addr_t)&_bss_end - (addr_t)&_prog_img_beg, Hw::PAGE_FLAGS_KERN_TEXT)); + (addr_t)&_bss_end - (addr_t)&_prog_img_beg, Genode::PAGE_FLAGS_KERN_TEXT)); /* map memory-mapped I/O for core */ board.core_mmio.for_each_mapping([&] (Mapping const & m) { @@ -195,7 +195,7 @@ Platform::Platform() /* setup boot info page */ void * bi_base = ram_alloc.alloc(sizeof(Boot_info)); core_pd->map_insert(Mapping((addr_t)bi_base, Hw::Mm::boot_info().base, - sizeof(Boot_info), Hw::PAGE_FLAGS_KERN_TEXT)); + sizeof(Boot_info), Genode::PAGE_FLAGS_KERN_TEXT)); Boot_info & bootinfo = *construct_at(bi_base, (addr_t)&core_pd->table, (addr_t)&core_pd->array, diff --git a/repos/base-hw/src/core/map_local.h b/repos/base-hw/src/core/map_local.h index 214a91077e..c48f879d1d 100644 --- a/repos/base-hw/src/core/map_local.h +++ b/repos/base-hw/src/core/map_local.h @@ -16,11 +16,11 @@ /* core includes */ #include -#include +#include namespace Core { - using Hw::Page_flags; + using Genode::Page_flags; /** * Map physical pages to core-local virtual address range @@ -33,7 +33,7 @@ namespace Core { * \return true on success */ bool map_local(addr_t from_phys, addr_t to_virt, size_t num_pages, - Page_flags flags = Hw::PAGE_FLAGS_KERN_DATA); + Page_flags flags = Genode::PAGE_FLAGS_KERN_DATA); /** * Unmap pages from core's address space diff --git a/repos/base-hw/src/core/platform.cc b/repos/base-hw/src/core/platform.cc index ca04b87276..6392184c56 100644 --- a/repos/base-hw/src/core/platform.cc +++ b/repos/base-hw/src/core/platform.cc @@ -24,7 +24,7 @@ #include /* base-hw internal includes */ -#include +#include #include #include diff --git a/repos/base-hw/src/include/hw/mapping.h b/repos/base-hw/src/include/hw/mapping.h index f8b89ddb77..4903850e37 100644 --- a/repos/base-hw/src/include/hw/mapping.h +++ b/repos/base-hw/src/include/hw/mapping.h @@ -15,9 +15,19 @@ #define _SRC__LIB__HW__MAPPING_H_ #include -#include +#include + +namespace Hw { + using Genode::Page_flags; + using Genode::RO; + using Genode::NO_EXEC; + using Genode::KERN; + using Genode::NO_GLOBAL; + using Genode::RAM; + + class Mapping; +} -namespace Hw { class Mapping; } class Hw::Mapping diff --git a/repos/base-hw/src/include/hw/memory_map.h b/repos/base-hw/src/include/hw/memory_map.h index de4454e0e1..0503e1af4a 100644 --- a/repos/base-hw/src/include/hw/memory_map.h +++ b/repos/base-hw/src/include/hw/memory_map.h @@ -46,7 +46,7 @@ struct Hw::Mmio_space : Hw::Memory_region_array { addr_t virt_base = Mm::core_mmio().base; auto lambda = [&] (unsigned, Memory_region const & r) { - f(Mapping { r.base, virt_base, r.size, PAGE_FLAGS_KERN_IO }); + f(Mapping { r.base, virt_base, r.size, Genode::PAGE_FLAGS_KERN_IO }); virt_base += r.size + get_page_size(); }; for_each(lambda); diff --git a/repos/base-hw/src/include/hw/page_flags.h b/repos/base-hw/src/include/hw/page_flags.h deleted file mode 100644 index 0622577f90..0000000000 --- a/repos/base-hw/src/include/hw/page_flags.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * \brief Generic page flags - * \author Stefan Kalkowski - * \date 2014-02-24 - */ - -/* - * Copyright (C) 2014-2017 Genode Labs GmbH - * - * This file is part of the Genode OS framework, which is distributed - * under the terms of the GNU Affero General Public License version 3. - */ - -#ifndef _SRC__LIB__HW__PAGE_FLAGS_H_ -#define _SRC__LIB__HW__PAGE_FLAGS_H_ - -#include -#include - -namespace Hw { - - enum Writeable { RO, RW }; - enum Executeable { NO_EXEC, EXEC }; - enum Privileged { USER, KERN }; - enum Global { NO_GLOBAL, GLOBAL }; - enum Type { RAM, DEVICE }; - - struct Page_flags; -} - - -struct Hw::Page_flags -{ - Writeable writeable; - Executeable executable; - Privileged privileged; - Global global; - Type type; - Genode::Cache cacheable; - - void print(Genode::Output & out) const - { - using Genode::print; - using namespace Genode; - - print(out, (writeable == RW) ? "writeable, " : "readonly, ", - (executable ==EXEC) ? "exec, " : "noexec, "); - if (privileged == KERN) print(out, "privileged, "); - if (global == GLOBAL) print(out, "global, "); - if (type == 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; - }; - } -}; - - -namespace Hw { - - static constexpr Page_flags PAGE_FLAGS_KERN_IO - { RW, NO_EXEC, KERN, GLOBAL, DEVICE, Genode::UNCACHED }; - static constexpr Page_flags PAGE_FLAGS_KERN_DATA - { RW, EXEC, KERN, GLOBAL, RAM, Genode::CACHED }; - static constexpr Page_flags PAGE_FLAGS_KERN_TEXT - { RW, EXEC, KERN, GLOBAL, RAM, Genode::CACHED }; - static constexpr Page_flags PAGE_FLAGS_KERN_EXCEP - { RW, EXEC, KERN, GLOBAL, RAM, Genode::CACHED }; - static constexpr Page_flags PAGE_FLAGS_UTCB - { RW, NO_EXEC, USER, NO_GLOBAL, RAM, Genode::CACHED }; -} - -#endif /* _SRC__LIB__HW__PAGE_FLAGS_H_ */ diff --git a/repos/base-hw/src/include/hw/spec/arm/lpae.h b/repos/base-hw/src/include/hw/spec/arm/lpae.h index 0ea415d3c7..60b5826066 100644 --- a/repos/base-hw/src/include/hw/spec/arm/lpae.h +++ b/repos/base-hw/src/include/hw/spec/arm/lpae.h @@ -16,10 +16,11 @@ #include #include -#include +#include #include namespace Hw { + using Genode::Page_flags; enum { SIZE_LOG2_4KB = 12, @@ -206,7 +207,7 @@ class Hw::Long_translation_table static typename Descriptor::access_t create(Page_flags const &f) { - if (f.type == Hw::DEVICE) + if (f.type == Genode::DEVICE) return Attribute_index::bits(DEVICE); switch (f.cacheable) { diff --git a/repos/base-hw/src/include/hw/spec/arm/page_table.h b/repos/base-hw/src/include/hw/spec/arm/page_table.h index 3d66e031a3..dfda058bb7 100644 --- a/repos/base-hw/src/include/hw/spec/arm/page_table.h +++ b/repos/base-hw/src/include/hw/spec/arm/page_table.h @@ -15,13 +15,17 @@ #ifndef _SRC__LIB__HW__SPEC__ARM__PAGE_TABLE_H_ #define _SRC__LIB__HW__SPEC__ARM__PAGE_TABLE_H_ +#include #include #include -#include #include #include -namespace Hw { class Page_table; } +namespace Hw { + using namespace Genode; + + class Page_table; +} class Hw::Page_table diff --git a/repos/base-hw/src/include/hw/spec/riscv/page_table.h b/repos/base-hw/src/include/hw/spec/riscv/page_table.h index d95504b5c7..5d94406d3d 100644 --- a/repos/base-hw/src/include/hw/spec/riscv/page_table.h +++ b/repos/base-hw/src/include/hw/spec/riscv/page_table.h @@ -15,7 +15,7 @@ #define _SRC__LIB__HW__SPEC__RISCV__PAGE_TABLE_H_ #include -#include +#include #include #include #include @@ -73,7 +73,7 @@ struct Sv39::Descriptor : Register<64> struct Ppn : Bitfield<10, 38> { }; /* physical address 10 bit aligned */ struct Base : Bitfield<12, 38> { }; /* physical address page aligned */ - static access_t permission_bits(Hw::Page_flags const &f) + static access_t permission_bits(Genode::Page_flags const &f) { access_t rights = 0; R::set(rights, 1); @@ -125,7 +125,7 @@ struct Sv39::Table_descriptor : Descriptor struct Sv39::Block_descriptor : Descriptor { - static access_t create(Hw::Page_flags const &f, addr_t const pa) + static access_t create(Genode::Page_flags const &f, addr_t const pa) { access_t base = Base::get(pa); access_t desc = 0; @@ -219,10 +219,10 @@ class Sv39::Level_x_translation_table template struct Insert_func { - Hw::Page_flags const & flags; + Genode::Page_flags const & flags; Allocator & alloc; - Insert_func(Hw::Page_flags const & flags, Allocator & alloc) + Insert_func(Genode::Page_flags const & flags, Allocator & alloc) : flags(flags), alloc(alloc) { } void operator () (addr_t const vo, @@ -333,7 +333,7 @@ class Sv39::Level_x_translation_table * \param alloc level allocator */ void insert_translation(addr_t vo, addr_t pa, size_t size, - Hw::Page_flags const & flags, + Genode::Page_flags const & flags, Allocator & alloc ) { _range_op(vo, pa, size, Insert_func(flags, alloc)); @@ -367,9 +367,9 @@ namespace Sv39 { template <> template <> struct Level_3_translation_table::Insert_func { - Hw::Page_flags const & flags; + Genode::Page_flags const & flags; - Insert_func(Hw::Page_flags const & flags, Allocator &) + Insert_func(Genode::Page_flags const & flags, Allocator &) : flags(flags) { } void operator () (addr_t const vo, diff --git a/repos/base-hw/src/include/hw/spec/x86_64/page_table.h b/repos/base-hw/src/include/hw/spec/x86_64/page_table.h index 81d194d5e6..f85a64dc90 100644 --- a/repos/base-hw/src/include/hw/spec/x86_64/page_table.h +++ b/repos/base-hw/src/include/hw/spec/x86_64/page_table.h @@ -16,13 +16,14 @@ #include #include -#include +#include #include #include #include #include namespace Hw { + using namespace Genode; /** * IA-32e paging translates 48-bit linear addresses to 52-bit physical diff --git a/repos/base/include/spec/x86_64/page_table/page_flags.h b/repos/base/include/cpu/page_flags.h similarity index 91% rename from repos/base/include/spec/x86_64/page_table/page_flags.h rename to repos/base/include/cpu/page_flags.h index 5b4c871e4f..741a3c8fe4 100644 --- a/repos/base/include/spec/x86_64/page_table/page_flags.h +++ b/repos/base/include/cpu/page_flags.h @@ -11,8 +11,8 @@ * under the terms of the GNU Affero General Public License version 3. */ -#ifndef _INCLUDE__SPEC__X86_64__PAGE_TABLE__PAGE_FLAGS_H_ -#define _INCLUDE__SPEC__X86_64__PAGE_TABLE__PAGE_FLAGS_H_ +#ifndef _INCLUDE__CPU__PAGE_FLAGS_H_ +#define _INCLUDE__CPU__PAGE_FLAGS_H_ #include #include @@ -71,4 +71,4 @@ namespace Genode { { RW, NO_EXEC, USER, NO_GLOBAL, RAM, Genode::CACHED }; } -#endif /* _INCLUDE__SPEC__X86_64__PAGE_TABLE__PAGE_FLAGS_H_ */ +#endif /* _INCLUDE__CPU__PAGE_FLAGS_H_ */ diff --git a/repos/base/include/spec/x86_64/page_table/page_table_base.h b/repos/base/include/spec/x86_64/page_table/page_table_base.h index 278cff14f3..43b362fc82 100644 --- a/repos/base/include/spec/x86_64/page_table/page_table_base.h +++ b/repos/base/include/spec/x86_64/page_table/page_table_base.h @@ -16,7 +16,7 @@ #define _INCLUDE__SPEC__X86_64__PAGE_TABLE__PAGE_TABLE_BASE_H_ #include -#include +#include #include #include diff --git a/repos/pc/src/drivers/platform/pc/intel/page_table.h b/repos/pc/src/drivers/platform/pc/intel/page_table.h index b028299015..332c76e0a9 100644 --- a/repos/pc/src/drivers/platform/pc/intel/page_table.h +++ b/repos/pc/src/drivers/platform/pc/intel/page_table.h @@ -14,6 +14,7 @@ #ifndef _SRC__DRIVERS__PLATFORM__PC__INTEL__PAGE_TABLE_H_ #define _SRC__DRIVERS__PLATFORM__PC__INTEL__PAGE_TABLE_H_ +#include #include #include