2012-05-30 20:13:09 +02:00
|
|
|
/*
|
|
|
|
* \brief Platform interface
|
|
|
|
* \author Martin Stein
|
2014-04-28 21:31:57 +02:00
|
|
|
* \author Stefan Kalkowski
|
2012-05-30 20:13:09 +02:00
|
|
|
* \date 2011-12-21
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2011-2017 Genode Labs GmbH
|
2012-05-30 20:13:09 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2012-05-30 20:13:09 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#ifndef _CORE__PLATFORM_H_
|
|
|
|
#define _CORE__PLATFORM_H_
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
/* Genode includes */
|
2015-09-17 14:16:59 +02:00
|
|
|
#include <base/synced_allocator.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
#include <base/allocator_avl.h>
|
2013-10-30 13:56:57 +01:00
|
|
|
#include <irq_session/irq_session.h>
|
2019-04-17 12:51:39 +02:00
|
|
|
#include <util/xml_generator.h>
|
2013-11-14 17:29:34 +01:00
|
|
|
|
|
|
|
/* base-hw includes */
|
2017-02-21 13:46:59 +01:00
|
|
|
#include <hw/boot_info.h>
|
|
|
|
#include <hw/memory_region.h>
|
2019-09-26 14:24:28 +02:00
|
|
|
#include "../core/kernel/configuration.h"
|
|
|
|
#include "../core/kernel/core_interface.h"
|
|
|
|
#include "../core/kernel/pd.h"
|
2012-05-30 20:13:09 +02:00
|
|
|
|
|
|
|
/* core includes */
|
|
|
|
#include <platform_generic.h>
|
2016-04-15 15:19:22 +02:00
|
|
|
#include <core_region_map.h>
|
2014-04-28 21:31:57 +02:00
|
|
|
#include <core_mem_alloc.h>
|
2017-02-21 13:46:59 +01:00
|
|
|
#include <translation_table.h>
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
#include <assertion.h>
|
2019-05-16 14:20:39 +02:00
|
|
|
#include <board.h>
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2018-12-17 14:58:08 +01:00
|
|
|
namespace Genode {
|
|
|
|
class Address_space;
|
|
|
|
class Platform;
|
|
|
|
};
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
class Genode::Platform : public Genode::Platform_generic
|
|
|
|
{
|
|
|
|
private:
|
2012-05-30 20:13:09 +02:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 15:42:15 +01:00
|
|
|
Core_mem_allocator _core_mem_alloc { }; /* core-accessible memory */
|
|
|
|
Phys_allocator _io_mem_alloc; /* MMIO allocator */
|
|
|
|
Phys_allocator _io_port_alloc; /* I/O port allocator */
|
|
|
|
Phys_allocator _irq_alloc; /* IRQ allocator */
|
|
|
|
Rom_fs _rom_fs { }; /* ROM file system */
|
2014-10-10 16:13:52 +02:00
|
|
|
|
2019-05-16 14:20:39 +02:00
|
|
|
static Hw::Boot_info<Board::Boot_info> const &_boot_info();
|
2017-02-21 13:46:59 +01:00
|
|
|
static Hw::Memory_region_array const & _core_virt_regions();
|
2016-11-07 18:00:24 +01:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
/**
|
|
|
|
* Initialize I/O port allocator
|
|
|
|
*/
|
2017-08-17 16:20:56 +02:00
|
|
|
void _init_io_port_alloc();
|
2014-04-28 21:31:57 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2017-08-17 16:20:56 +02:00
|
|
|
void _init_io_mem_alloc();
|
2015-04-28 14:56:00 +02:00
|
|
|
|
2019-04-17 12:51:39 +02:00
|
|
|
/**
|
|
|
|
* Initialize platform_info ROM module
|
|
|
|
*/
|
|
|
|
void _init_platform_info();
|
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
/**
|
2019-04-17 12:51:39 +02:00
|
|
|
* Add additional platform-specific information.
|
2017-02-21 13:46:59 +01:00
|
|
|
*/
|
2019-04-17 12:51:39 +02:00
|
|
|
void _init_additional_platform_info(Genode::Xml_generator &);
|
2017-08-17 16:20:56 +02:00
|
|
|
|
|
|
|
void _init_rom_modules();
|
|
|
|
|
2017-06-20 15:25:04 +02:00
|
|
|
addr_t _rom_module_phys(addr_t virt);
|
2015-07-02 16:25:51 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
public:
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
Platform();
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
static addr_t mmio_to_virt(addr_t mmio);
|
2016-11-07 18:00:24 +01:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
/**
|
|
|
|
* Return platform IRQ-number for user IRQ-number 'user_irq'
|
|
|
|
*/
|
|
|
|
static long irq(long const user_irq);
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
/**
|
|
|
|
* Get MSI-related parameters from device PCI config space
|
|
|
|
*
|
|
|
|
* \param mmconf PCI config space address of device
|
|
|
|
* \param address MSI address register value to use
|
|
|
|
* \param data MSI data register value to use
|
|
|
|
* \param irq_number IRQ to use
|
|
|
|
*
|
|
|
|
* \return true if the device is MSI-capable, false if not
|
|
|
|
*/
|
|
|
|
static bool get_msi_params(const addr_t mmconf,
|
|
|
|
addr_t &address, addr_t &data,
|
|
|
|
unsigned &irq_number);
|
2015-06-25 15:53:39 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
static addr_t core_phys_addr(addr_t virt);
|
2016-11-07 18:00:24 +01:00
|
|
|
|
2017-06-20 15:25:04 +02:00
|
|
|
static addr_t core_page_table();
|
2017-02-21 13:46:59 +01:00
|
|
|
static Hw::Page_table::Allocator & core_page_table_allocator();
|
2016-11-07 18:00:24 +01:00
|
|
|
|
2016-10-06 20:07:16 +02:00
|
|
|
|
2017-02-21 13:46:59 +01:00
|
|
|
/********************************
|
|
|
|
** Platform_generic interface **
|
|
|
|
********************************/
|
2016-10-06 20:07:16 +02:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Range_allocator &core_mem_alloc() override { return _core_mem_alloc; }
|
|
|
|
Range_allocator &ram_alloc() override { return _core_mem_alloc.phys_alloc(); }
|
|
|
|
Range_allocator ®ion_alloc() override { return _core_mem_alloc.virt_alloc(); }
|
|
|
|
Range_allocator &io_mem_alloc() override { return _io_mem_alloc; }
|
|
|
|
Range_allocator &io_port_alloc() override { return _io_port_alloc; }
|
|
|
|
Range_allocator &irq_alloc() override { return _irq_alloc; }
|
|
|
|
addr_t vm_start() const override { return Hw::Mm::user().base; }
|
|
|
|
size_t vm_size() const override { return Hw::Mm::user().size; }
|
|
|
|
Rom_fs &rom_fs() override { return _rom_fs; }
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2020-01-22 16:58:21 +01:00
|
|
|
void wait_for_exit() override {
|
2017-02-21 13:46:59 +01:00
|
|
|
while (1) { Kernel::stop_thread(); } };
|
2012-05-30 20:13:09 +02:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
bool supports_direct_unmap() const override { return true; }
|
|
|
|
Address_space &core_pd() { ASSERT_NEVER_CALLED; }
|
2012-05-30 20:13:09 +02:00
|
|
|
|
base/core: use references instead of pointers
This patch replaces the former prominent use of pointers by references
wherever feasible. This has the following benefits:
* The contract between caller and callee becomes more obvious. When
passing a reference, the contract says that the argument cannot be
a null pointer. The caller is responsible to ensure that. Therefore,
the use of reference eliminates the need to add defensive null-pointer
checks at the callee site, which sometimes merely exist to be on the
safe side. The bottom line is that the code becomes easier to follow.
* Reference members must be initialized via an object initializer,
which promotes a programming style that avoids intermediate object-
construction states. Within core, there are still a few pointers
as member variables left though. E.g., caused by the late association
of 'Platform_thread' objects with their 'Platform_pd' objects.
* If no pointers are present as member variables, we don't need to
manually provide declarations of a private copy constructor and
an assignment operator to avoid -Weffc++ errors "class ... has
pointer data members [-Werror=effc++]".
This patch also changes a few system bindings on NOVA and Fiasco.OC,
e.g., the return value of the global 'cap_map' accessor has become a
reference. Hence, the patch touches a few places outside of core.
Fixes #3135
2019-01-24 22:00:01 +01:00
|
|
|
Affinity::Space affinity_space() const override {
|
2018-08-01 14:20:30 +02:00
|
|
|
return Affinity::Space(_boot_info().cpus); }
|
2017-05-07 22:44:15 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The system-wide maximum number of capabilities is constrained
|
|
|
|
* by core's local capability space.
|
|
|
|
*/
|
|
|
|
size_t max_caps() const override { return Kernel::Pd::max_cap_ids; }
|
2017-02-21 13:46:59 +01:00
|
|
|
};
|
2012-05-30 20:13:09 +02:00
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#endif /* _CORE__PLATFORM_H_ */
|