hw: rework mapping and page-flags

Ref #2092
This commit is contained in:
Stefan Kalkowski 2016-11-03 14:49:23 +01:00 committed by Christian Helmuth
parent b6490e913f
commit 8aa8423cfd
5 changed files with 94 additions and 88 deletions

View File

@ -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 <base/output.h>
#include <page_flags.h>
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_ */

View File

@ -15,13 +15,11 @@
#define _CORE__INCLUDE__PAGE_FLAGS_H_
#include <base/cache.h>
#include <base/output.h>
namespace Genode
{
/**
* Map app-specific mem attributes to a TLB-specific POD
*/
struct Page_flags
namespace Genode { struct Page_flags; }
struct Genode::Page_flags
{
bool writeable;
bool executable;
@ -45,7 +43,22 @@ namespace Genode
*/
static const Page_flags mode_transition() {
return Page_flags { true, true, true, true, false, CACHED }; }
void print(Output & out) const
{
using Genode::print;
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_ */

View File

@ -26,17 +26,12 @@
/* core-local includes */
#include <kernel/signal_receiver.h>
#include <mapping.h>
#include <object.h>
#include <rpc_cap_factory.h>
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:

View File

@ -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 **
***************/

View File

@ -81,13 +81,8 @@ void Pager_entrypoint::entry()
if (!locked_ptr.valid()) return;
Hw::Address_space * as = static_cast<Hw::Address_space*>(&*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 */