Skip to content

Commit

Permalink
core: pass ram, rm, io-ports to local services
Browse files Browse the repository at this point in the history
This patch replaces the use of 'core_env()' in 'platform_services.cc' by
the function arguments 'core_ram', 'core_rm', and 'io_port_ranges'.

It also removes the 'Pd_session' argument from 'Io_port_root' and
'Irq_root' to avoid the reliance on the 'Pd_session' interface within
core,

Issue genodelabs#5408
  • Loading branch information
nfeske committed Dec 18, 2024
1 parent f9e6c3a commit 404e210
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 99 deletions.
11 changes: 5 additions & 6 deletions repos/base-foc/src/core/spec/x86/platform_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

/* core includes */
#include <core_env.h>
#include <platform_services.h>
#include <vm_root.h>
#include <io_port_root.h>
Expand All @@ -24,15 +23,15 @@ void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &heap,
Registry<Service> &services,
Trace::Source_registry &trace_sources,
Ram_allocator &)
Ram_allocator &core_ram,
Region_map &core_rm,
Range_allocator &io_port_ranges)
{
static Vm_root vm_root(ep, heap, core_env().ram_allocator(),
core_env().local_rm(), trace_sources);
static Vm_root vm_root(ep, heap, core_ram, core_rm, trace_sources);

static Core_service<Vm_session_component> vm(services, vm_root);

static Io_port_root io_root(*core_env().pd_session(),
platform().io_port_alloc(), heap);
static Io_port_root io_root(io_port_ranges, heap);

static Core_service<Io_port_session_component> io_port(services, io_root);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

/* core includes */
#include <platform.h>
#include <platform_pd.h>
#include <platform_services.h>
#include <core_env.h>
#include <core_service.h>
#include <map_local.h>
#include <vm_root.h>
#include <platform.h>

using namespace Core;

Expand All @@ -32,11 +31,13 @@ extern addr_t hypervisor_exception_vector;
/*
* Add ARM virtualization specific vm service
*/
void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &sh,
Registry<Service> &services,
Core::Trace::Source_registry &trace_sources,
Ram_allocator &)
void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &sh,
Registry<Service> &services,
Trace::Source_registry &trace_sources,
Ram_allocator &core_ram,
Region_map &core_rm,
Range_allocator &)
{
map_local(Platform::core_phys_addr((addr_t)&hypervisor_exception_vector),
Hw::Mm::hypervisor_exception_vector().base,
Expand All @@ -51,8 +52,7 @@ void Core::platform_add_local_services(Rpc_entrypoint &ep,
Hw::Mm::hypervisor_stack().size / get_page_size(),
Hw::PAGE_FLAGS_KERN_DATA);

static Vm_root vm_root(ep, sh, core_env().ram_allocator(),
core_env().local_rm(), trace_sources);
static Vm_root vm_root(ep, sh, core_ram, core_rm, trace_sources);
static Core_service<Vm_session_component> vm_service(services, vm_root);
},
[&] (Range_allocator::Alloc_error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
/* core includes */
#include <platform.h>
#include <platform_services.h>
#include <core_env.h>
#include <core_service.h>
#include <vm_root.h>
#include <map_local.h>
Expand All @@ -29,20 +28,21 @@ extern int monitor_mode_exception_vector;
/*
* Add TrustZone specific vm service
*/
void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &sliced_heap,
Registry<Service> &local_services,
Core::Trace::Source_registry &trace_sources,
Ram_allocator &)
void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &sliced_heap,
Registry<Service> &services,
Trace::Source_registry &trace_sources,
Ram_allocator &core_ram,
Region_map &core_rm,
Range_allocator &)
{
static addr_t const phys_base =
Platform::core_phys_addr((addr_t)&monitor_mode_exception_vector);

map_local(phys_base, Hw::Mm::system_exception_vector().base, 1,
Hw::PAGE_FLAGS_KERN_TEXT);

static Vm_root vm_root(ep, sliced_heap, core_env().ram_allocator(),
core_env().local_rm(), trace_sources);
static Vm_root vm_root(ep, sliced_heap, core_ram, core_rm, trace_sources);

static Core_service<Vm_session_component> vm_service(local_services, vm_root);
static Core_service<Vm_session_component> vm_service(services, vm_root);
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
#include <base/service.h>

/* core includes */
#include <core_env.h>
#include <platform.h>
#include <platform_services.h>
#include <vm_root.h>
Expand All @@ -30,16 +29,15 @@ void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &sliced_heap,
Registry<Service> &local_services,
Trace::Source_registry &trace_sources,
Ram_allocator &)
Ram_allocator &core_ram,
Region_map &core_rm,
Range_allocator &io_port_ranges)
{
static Io_port_root io_port_root(*core_env().pd_session(),
platform().io_port_alloc(), sliced_heap);
static Io_port_root io_port_root(io_port_ranges, sliced_heap);

static Vm_root vm_root(ep, sliced_heap, core_env().ram_allocator(),
core_env().local_rm(), trace_sources);
static Vm_root vm_root(ep, sliced_heap, core_ram, core_rm, trace_sources);

static Core_service<Vm_session_component> vm_service(local_services, vm_root);

static Core_service<Io_port_session_component>
io_port_ls(local_services, io_port_root);
static Core_service<Io_port_session_component> io_port_ls(local_services, io_port_root);
}
4 changes: 3 additions & 1 deletion repos/base-linux/src/core/spec/linux/platform_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ void Core::platform_add_local_services(Rpc_entrypoint &,
Sliced_heap &,
Registry<Service> &,
Trace::Source_registry &,
Ram_allocator &)
Ram_allocator &,
Region_map &,
Range_allocator &)
{ }
21 changes: 10 additions & 11 deletions repos/base-linux/src/core/spec/pc/platform_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

/* Genode includes */
#include <base/service.h>
#include <base/heap.h>

/* core includes */
#include <core_env.h>
#include <platform.h>
#include <platform_services.h>
#include <io_port_root.h>
Expand All @@ -25,18 +25,17 @@
using namespace Core;


void Core::platform_add_local_services(Rpc_entrypoint &,
Sliced_heap &md,
Registry<Service> &reg,
Core::Trace::Source_registry &,
Ram_allocator &)
void Core::platform_add_local_services(Rpc_entrypoint &,
Sliced_heap &md,
Registry<Service> &services,
Trace::Source_registry &,
Ram_allocator &,
Region_map &,
Range_allocator &io_port_ranges)
{
if (!lx_iopl(3)) {
static Io_port_root io_port_root(*core_env().pd_session(),
platform().io_port_alloc(), md);
static Io_port_root io_port_root(io_port_ranges, md);

static Core_service<Io_port_session_component>

io_port_ls(reg, io_port_root);
static Core_service<Io_port_session_component> io_port_ls(services, io_port_root);
}
}
1 change: 1 addition & 0 deletions repos/base-nova/src/core/include/vm_session_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/* core includes */
#include <types.h>
#include <pd_session_component.h>

namespace Core { class Vm_session_component; }

Expand Down
11 changes: 5 additions & 6 deletions repos/base-nova/src/core/platform_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

/* core includes */
#include <core_env.h>
#include <platform_services.h>
#include <vm_root.h>
#include <io_port_root.h>
Expand All @@ -24,14 +23,14 @@ void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &heap,
Registry<Service> &services,
Trace::Source_registry &trace_sources,
Ram_allocator &)
Ram_allocator &core_ram,
Region_map &core_rm,
Range_allocator &io_port_ranges)
{
static Vm_root vm_root(ep, heap, core_env().ram_allocator(),
core_env().local_rm(), trace_sources);
static Vm_root vm_root(ep, heap, core_ram, core_rm, trace_sources);
static Core_service<Vm_session_component> vm(services, vm_root);

static Io_port_root io_root(*core_env().pd_session(),
platform().io_port_alloc(), heap);
static Io_port_root io_root(io_port_ranges, heap);

static Core_service<Io_port_session_component> io_port(services, io_root);
}
20 changes: 10 additions & 10 deletions repos/base-sel4/src/core/spec/x86/platform_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@
*/

/* core includes */
#include <core_env.h>
#include <platform_services.h>
#include <vm_root.h>
#include <io_port_root.h>

/*
* Add x86 specific services
*/
void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &heap,
Registry<Service> &services,
Core::Trace::Source_registry &trace_sources,
Ram_allocator &)
void Core::platform_add_local_services(Rpc_entrypoint &ep,
Sliced_heap &heap,
Registry<Service> &services,
Trace::Source_registry &trace_sources,
Ram_allocator &core_ram,
Region_map &core_rm,
Range_allocator &io_port_ranges)
{
static Vm_root vm_root(ep, heap, core_env().ram_allocator(),
core_env().local_rm(), trace_sources);
static Vm_root vm_root(ep, heap, core_ram, core_rm, trace_sources);

static Core_service<Vm_session_component> vm(services, vm_root);

static Io_port_root io_root(*core_env().pd_session(),
platform().io_port_alloc(), heap);
static Io_port_root io_root(io_port_ranges, heap);

static Core_service<Io_port_session_component> io_port(services, io_root);
}
27 changes: 7 additions & 20 deletions repos/base/src/core/include/io_port_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,17 @@ namespace Core {
}


class Core::Io_port_handler
struct Core::Io_port_handler
{
private:

enum { STACK_SIZE = 4096 };
Rpc_entrypoint _ep;

public:
static constexpr size_t STACK_SIZE = 4096;

Io_port_handler(Pd_session &pd_session) :
_ep(&pd_session, STACK_SIZE, "ioport", Affinity::Location())
{ }

Rpc_entrypoint &entrypoint() { return _ep; }
Rpc_entrypoint handler_ep { nullptr, STACK_SIZE, "ioport", Affinity::Location() };
};


class Core::Io_port_root : private Io_port_handler,
public Root_component<Io_port_session_component>
{

private:

Range_allocator &_io_port_alloc; /* I/O port allocator */
Expand All @@ -60,17 +50,14 @@ class Core::Io_port_root : private Io_port_handler,
/**
* Constructor
*
* \param cap_session capability allocator
* \param io_port_alloc platform IO_PORT allocator
* \param md_alloc meta-data allocator to be used by root component
*/
Io_port_root(Pd_session &pd_session,
Range_allocator &io_port_alloc,
Allocator &md_alloc)
Io_port_root(Range_allocator &io_port_alloc, Allocator &md_alloc)
:
Io_port_handler(pd_session),
Root_component<Io_port_session_component>(&entrypoint(), &md_alloc),
_io_port_alloc(io_port_alloc) { }
Root_component<Io_port_session_component>(&handler_ep, &md_alloc),
_io_port_alloc(io_port_alloc)
{ }
};

#endif /* _CORE__INCLUDE__IO_PORT_ROOT_H_ */
6 changes: 2 additions & 4 deletions repos/base/src/core/include/irq_root.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ class Core::Irq_root : public Root_component<Irq_session_component>
/**
* Constructor
*
* \param pd_session capability allocator
* \param irq_alloc IRQ range that can be assigned to clients
* \param md_alloc meta-data allocator to be used by root component
*/
Irq_root(Pd_session &pd_session,
Range_allocator &irq_alloc, Allocator &md_alloc)
Irq_root(Range_allocator &irq_alloc, Allocator &md_alloc)
:
Root_component<Irq_session_component>(&_session_ep, &md_alloc),
_session_ep(&pd_session, STACK_SIZE, "irq", Affinity::Location()),
_session_ep(nullptr, STACK_SIZE, "irq", Affinity::Location()),
_irq_alloc(irq_alloc)
{ }
};
Expand Down
11 changes: 7 additions & 4 deletions repos/base/src/core/include/platform_services.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
#ifndef _CORE__INCLUDE__PLATFORM_SERVICES_H_
#define _CORE__INCLUDE__PLATFORM_SERVICES_H_

/* Genode includes */
#include <base/ram_allocator.h>

/* core includes */
#include "base/ram_allocator.h"
#include <core_service.h>
#include <trace/source_registry.h>

Expand All @@ -28,8 +30,7 @@ namespace Genode {
namespace Core {

/**
* Register platform-specific services at entrypoint, and service
* registry
* Register platform-specific services at entrypoint, and service registry
*
* \param ep entrypoint used for session components of platform-services
* \param md metadata allocator for session components
Expand All @@ -40,7 +41,9 @@ namespace Core {
Sliced_heap &md,
Registry<Service> &reg,
Trace::Source_registry &trace,
Ram_allocator &core_ram_alloc);
Ram_allocator &core_ram,
Region_map &core_rm,
Range_allocator &io_port_ranges);
}

#endif /* _CORE__INCLUDE__PLATFORM_SERVICES_H_ */
6 changes: 3 additions & 3 deletions repos/base/src/core/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,7 @@ void Genode::bootstrap_component(Genode::Platform &)
static Log_root log_root (ep, sliced_heap);
static Io_mem_root io_mem_root (ep, ep, platform().io_mem_alloc(),
platform().ram_alloc(), sliced_heap);
static Irq_root irq_root (*core_env().pd_session(),
platform().irq_alloc(), sliced_heap);
static Irq_root irq_root (platform().irq_alloc(), sliced_heap);
static Trace_root trace_root (core_ram_alloc, local_rm, ep, sliced_heap,
Core::Trace::sources(), trace_policies);

Expand All @@ -291,7 +290,8 @@ void Genode::bootstrap_component(Genode::Platform &)
static Core_service<Trace_session_component> trace_service (services, trace_root);

/* make platform-specific services known to service pool */
platform_add_local_services(ep, sliced_heap, services, Core::Trace::sources(), core_ram_alloc);
platform_add_local_services(ep, sliced_heap, services, Core::Trace::sources(),
core_ram_alloc, local_rm, platform().io_port_alloc());

size_t const avail_ram_quota = core_pd.avail_ram().value;
size_t const avail_cap_quota = core_pd.avail_caps().value;
Expand Down
7 changes: 5 additions & 2 deletions repos/base/src/core/platform_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@


void Core::platform_add_local_services(Rpc_entrypoint &, Sliced_heap &,
Registry<Service> &,
Registry<Service> &,
Trace::Source_registry &,
Ram_allocator &) { }
Ram_allocator &,
Region_map &,
Range_allocator &)
{ }
Loading

0 comments on commit 404e210

Please sign in to comment.