genode/repos/base/src/core/include/io_mem_session_component.h

150 lines
3.9 KiB
C
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Core-specific instance of the IO_MEM session interface
* \author Christian Helmuth
* \date 2006-09-14
*/
/*
* Copyright (C) 2006-2017 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
2011-12-22 16:19:25 +01:00
*/
#ifndef _CORE__INCLUDE__IO_MEM_SESSION_COMPONENT_H_
#define _CORE__INCLUDE__IO_MEM_SESSION_COMPONENT_H_
/* Genode includes */
#include <base/allocator.h>
#include <base/rpc_server.h>
#include <io_mem_session/io_mem_session.h>
/* core includes */
#include <dataspace_component.h>
namespace Genode {
class Io_mem_session_component : public Rpc_object<Io_mem_session>
{
private:
/*
* Helper class used to pass the dataspace attributes as
* parameters from the _prepare_io_mem function to the
* constructor of Dataspace_component.
*/
struct Dataspace_attr
{
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
size_t size { 0 };
addr_t core_local_addr { 0 };
addr_t phys_addr { 0 };
Cache_attribute cacheable { UNCACHED };
2011-12-22 16:19:25 +01:00
/**
* Base address of request used for freeing mem-ranges
*/
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
addr_t req_base { 0 };
2011-12-22 16:19:25 +01:00
/**
* Default constructor
*
* This constructor enables Dataspace_attr objects to be
* returned from the '_prepare_io_mem' function.
*/
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
Dataspace_attr() { }
2011-12-22 16:19:25 +01:00
/**
* Constructor
*
* An invalid dataspace is represented by setting all
* arguments to zero.
*/
Dataspace_attr(size_t s, addr_t cla, addr_t pa, Cache_attribute c,
addr_t req_base)
:
size(s), core_local_addr(cla), phys_addr(pa),
cacheable(c), req_base(req_base) { }
};
2011-12-22 16:19:25 +01:00
struct Io_dataspace_component : Dataspace_component
2011-12-22 16:19:25 +01:00
{
addr_t req_base;
/**
* Constructor
*/
Io_dataspace_component(Dataspace_attr da)
:
Dataspace_component(da.size, da.core_local_addr,
da.phys_addr, da.cacheable,
true, 0),
req_base(da.req_base) { }
2011-12-22 16:19:25 +01:00
bool valid() { return size() != 0; }
2011-12-22 16:19:25 +01:00
};
Range_allocator &_io_mem_alloc;
2011-12-22 16:19:25 +01:00
Io_dataspace_component _ds;
Rpc_entrypoint &_ds_ep;
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
Io_mem_dataspace_capability _ds_cap { };
Cache_attribute _cacheable { UNCACHED };
2011-12-22 16:19:25 +01:00
Dataspace_attr _prepare_io_mem(const char *args, Range_allocator &ram_alloc);
2011-12-22 16:19:25 +01:00
/********************************************
** Platform-implemented support functions **
********************************************/
/* FIXME Could this be merged with Dataspace::unmap() and friends? */
/**
* Map region locally and return local base address
*
* Both parameters - base and size - must be page-aligned.
*/
addr_t _map_local(addr_t base, size_t size);
/**
* Unmap Core-local mapping of region
*
* Both parameters - base and size - must be page-aligned.
*/
void _unmap_local(addr_t base, size_t size);
public:
/**
* Constructor
*
* \param io_mem_alloc MMIO region allocator
* \param ram_alloc RAM allocator that will be checked for
* region collisions
* \param ds_ep entry point to manage the dataspace
* corresponding the io_mem session
* \param args session construction arguments, in
* particular MMIO region base, size and
* caching demands
*/
Io_mem_session_component(Range_allocator &io_mem_alloc,
Range_allocator &ram_alloc,
Rpc_entrypoint &ds_ep,
2011-12-22 16:19:25 +01:00
const char *args);
/**
* Destructor
*/
~Io_mem_session_component();
/******************************
** Io-mem session interface **
******************************/
Io_mem_dataspace_capability dataspace() override { return _ds_cap; }
2011-12-22 16:19:25 +01:00
};
}
#endif /* _CORE__INCLUDE__IO_MEM_SESSION_COMPONENT_H_ */