black_hole: provide ROM service

Ref #4419
This commit is contained in:
Martin Stein 2022-03-11 22:34:57 +01:00 committed by Christian Helmuth
parent bb26a986e6
commit 046ebc3d34
7 changed files with 150 additions and 15 deletions

View File

@ -7,6 +7,7 @@
<event/>
<nic/>
<uplink/>
<rom/>
</provides>
<config>
@ -16,6 +17,7 @@
<event/>
<nic/>
<uplink/>
<rom/>
</config>
<content>

View File

@ -30,6 +30,7 @@
<start name="black_hole" caps="100">
<resource name="RAM" quantum="1M"/>
<provides>
<service name="ROM"/>
<service name="Uplink"/>
<service name="Nic"/>
<service name="Event"/>
@ -38,6 +39,7 @@
<service name="Audio_out"/>
</provides>
<config>
<rom/>
<uplink/>
<nic/>
<event/>
@ -57,16 +59,17 @@
<start name="test-black_hole" caps="100">
<resource name="RAM" quantum="10M"/>
<route>
<service name="Uplink"> <child name="black_hole"/> </service>
<service name="Nic"> <child name="black_hole"/> </service>
<service name="Event"> <child name="black_hole"/> </service>
<service name="Capture"> <child name="black_hole"/> </service>
<service name="Audio_in"> <child name="black_hole"/> </service>
<service name="Audio_out"> <child name="black_hole"/> </service>
<service name="ROM"> <parent/> </service>
<service name="PD"> <parent/> </service>
<service name="LOG"> <parent/> </service>
<service name="CPU"> <parent/> </service>
<service name="ROM" label="any_label"> <child name="black_hole"/> </service>
<service name="Uplink"> <child name="black_hole"/> </service>
<service name="Nic"> <child name="black_hole"/> </service>
<service name="Event"> <child name="black_hole"/> </service>
<service name="Capture"> <child name="black_hole"/> </service>
<service name="Audio_in"> <child name="black_hole"/> </service>
<service name="Audio_out"> <child name="black_hole"/> </service>
<service name="ROM" > <parent/> </service>
<service name="PD"> <parent/> </service>
<service name="LOG"> <parent/> </service>
<service name="CPU"> <parent/> </service>
</route>
</start>

View File

@ -10,6 +10,7 @@ in the configuration of the component:
* Event
* Nic
* Uplink
* ROM
<config>
<audio_in/>
@ -18,4 +19,5 @@ in the configuration of the component:
<event/>
<nic/>
<uplink/>
<rom/>
</config>

View File

@ -4,6 +4,7 @@
<xs:element name="config">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="rom"/>
<xs:element name="uplink"/>
<xs:element name="nic"/>
<xs:element name="event"/>

View File

@ -27,6 +27,7 @@
#include "event.h"
#include "nic.h"
#include "uplink.h"
#include "rom.h"
/***************
@ -47,6 +48,7 @@ struct Black_hole::Main
Genode::Constructible<Event_root> event_root { };
Genode::Constructible<Nic_root> nic_root { };
Genode::Constructible<Uplink_root> uplink_root { };
Genode::Constructible<Rom_root> rom_root { };
Main(Genode::Env &env) : env(env)
{
@ -56,12 +58,10 @@ struct Black_hole::Main
audio_in_root.construct(env, heap);
env.parent().announce(env.ep().manage(*audio_in_root));
}
if (_config_rom.xml().has_sub_node("audio_out")) {
audio_out_root.construct(env, heap);
env.parent().announce(env.ep().manage(*audio_out_root));
}
if (_config_rom.xml().has_sub_node("capture")) {
capture_root.construct(env, heap);
env.parent().announce(env.ep().manage(*capture_root));
@ -70,16 +70,18 @@ struct Black_hole::Main
event_root.construct(env, heap);
env.parent().announce(env.ep().manage(*event_root));
}
if (_config_rom.xml().has_sub_node("nic")) {
nic_root.construct(env, heap);
env.parent().announce(env.ep().manage(*nic_root));
}
if (_config_rom.xml().has_sub_node("uplink")) {
uplink_root.construct(env, heap);
env.parent().announce(env.ep().manage(*uplink_root));
}
if (_config_rom.xml().has_sub_node("rom")) {
rom_root.construct(env, heap);
env.parent().announce(env.ep().manage(*rom_root));
}
}
};

View File

@ -0,0 +1,91 @@
/*
* \brief ROM session component and root
* \author Martin Stein
* \date 2022-03-11
*/
/*
* Copyright (C) 2022 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 _ROM_H_
#define _ROM_H_
/* base includes */
#include <base/attached_ram_dataspace.h>
#include <rom_session/rom_session.h>
#include <root/component.h>
namespace Black_hole {
using namespace Genode;
class Rom_session;
class Rom_root;
}
class Black_hole::Rom_session : public Session_object<Genode::Rom_session>
{
private:
enum { RAM_DS_SIZE = 16 };
Env &_env;
Attached_ram_dataspace _ram_ds { _env.ram(), _env.rm(), RAM_DS_SIZE };
public:
Rom_session(Env &env,
Resources const &resources,
Label const &label,
Diag const &diag)
:
Session_object(env.ep(), resources, label, diag),
_env { env }
{
copy_cstring(_ram_ds.local_addr<char>(), "<empty/>", RAM_DS_SIZE);
}
Rom_dataspace_capability dataspace() override
{
return
static_cap_cast<Rom_dataspace>(
static_cap_cast<Dataspace>(_ram_ds.cap()));
}
void sigh(Signal_context_capability /* sigh */) override { }
};
class Black_hole::Rom_root : public Root_component<Rom_session>
{
private:
Env &_env;
protected:
Rom_session *_create_session(const char *args) override
{
return new (md_alloc())
Rom_session {
_env, session_resources_from_args(args),
session_label_from_args(args),
session_diag_from_args(args) };
}
public:
Rom_root(Env &env,
Allocator &alloc)
:
Root_component<Rom_session> { &env.ep().rpc_ep(), &alloc },
_env { env }
{ }
};
#endif /* _ROM_H_ */

View File

@ -19,6 +19,8 @@
#include <base/component.h>
#include <base/heap.h>
#include <util/reconstructible.h>
#include <rom_session/connection.h>
#include <base/attached_rom_dataspace.h>
/* os includes */
#include <event_session/connection.h>
@ -38,6 +40,7 @@ namespace Black_hole_test {
class Uplink_test;
class Capture_test;
class Event_test;
class Rom_test;
class Main;
}
@ -295,6 +298,35 @@ class Black_hole_test::Event_test
};
class Black_hole_test::Rom_test
{
private:
Env &_env;
Attached_rom_dataspace _rom_ds { _env, "any_label" };
bool _finished { false };
public:
Rom_test(Env &env)
:
_env { env }
{
String<16> const str { Cstring { _rom_ds.local_addr<char>() } };
if (str != "<empty/>") {
class Unexpected_rom_content { };
throw Unexpected_rom_content { };
}
_finished = true;
}
bool finished() const
{
return _finished;
}
};
class Black_hole_test::Main
{
private:
@ -308,6 +340,7 @@ class Black_hole_test::Main
Uplink_test _uplink_test { _env, _heap, _signal_handler };
Capture_test _capture_test { _env };
Event_test _event_test { _env };
Rom_test _rom_test { _env };
void _handle_signal()
{
@ -321,7 +354,8 @@ class Black_hole_test::Main
if (_nic_test.finished() &&
_uplink_test.finished() &&
_capture_test.finished() &&
_event_test.finished()) {
_event_test.finished() &&
_rom_test.finished()) {
log("Finished");
}