Working minimal interception of PD + CPU
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
#ifndef __swcr_services_cpu_h__
|
||||
#define __swcr_services_cpu_h__
|
||||
|
||||
#include <root/component.h>
|
||||
#include <cpu_session/connection.h>
|
||||
|
||||
#include <swcr/services/pd.h>
|
||||
|
||||
namespace SWCR
|
||||
{
|
||||
class Cpu_session_component;
|
||||
@@ -11,37 +16,98 @@ using namespace Genode;
|
||||
|
||||
class SWCR::Cpu_session_component : public Genode::Rpc_object<Genode::Cpu_session>
|
||||
{
|
||||
private:
|
||||
Genode::Env &_env;
|
||||
Genode::Cpu_connection _real_cpu;
|
||||
SWCR::Pd_session_component &_psc;
|
||||
|
||||
public:
|
||||
Cpu_session_component() { }
|
||||
~Cpu_session_component() { }
|
||||
Cpu_session_component(Genode::Env &env, Pd_session_component &psc) : _env(env),
|
||||
_real_cpu(_env),
|
||||
_psc(psc)
|
||||
{
|
||||
_env.ep().rpc_ep().manage(this);
|
||||
}
|
||||
|
||||
~Cpu_session_component()
|
||||
{
|
||||
_env.ep().rpc_ep().dissolve(this);
|
||||
}
|
||||
|
||||
Thread_capability create_thread(Capability<Pd_session> pd,
|
||||
Name const &name,
|
||||
Affinity::Location affinity,
|
||||
Weight weight,
|
||||
addr_t utcb = 0) { };
|
||||
void kill_thread(Thread_capability thread) { };
|
||||
void exception_sigh(Signal_context_capability) { };
|
||||
Affinity::Space affinity_space() const { };
|
||||
Dataspace_capability trace_control() { };
|
||||
int ref_account(Cpu_session_capability cpu_session) { };
|
||||
int transfer_quota(Cpu_session_capability cpu_session, size_t amount) { };
|
||||
Quota quota() { };
|
||||
Capability<Native_cpu> native_cpu() { };
|
||||
addr_t utcb = 0)
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
return _real_cpu.create_thread(_psc.parent_pd_cap(), name, affinity, weight, utcb);
|
||||
};
|
||||
|
||||
void kill_thread(Thread_capability thread)
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
_real_cpu.kill_thread(thread);
|
||||
};
|
||||
|
||||
void exception_sigh(Signal_context_capability sigh)
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
_real_cpu.exception_sigh(sigh);
|
||||
};
|
||||
|
||||
Affinity::Space affinity_space() const
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
return _real_cpu.affinity_space();
|
||||
};
|
||||
|
||||
Dataspace_capability trace_control()
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
return _real_cpu.trace_control();
|
||||
};
|
||||
|
||||
int ref_account(Cpu_session_capability cpu_session)
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
return _real_cpu.ref_account(cpu_session);
|
||||
};
|
||||
|
||||
int transfer_quota(Cpu_session_capability cpu_session, size_t amount)
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
return _real_cpu.transfer_quota(cpu_session, amount);
|
||||
};
|
||||
|
||||
Quota quota()
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
return _real_cpu.quota();
|
||||
};
|
||||
|
||||
Capability<Native_cpu> native_cpu()
|
||||
{
|
||||
Genode::log("CPU::\033[33m", __func__, "\033[0m");
|
||||
return _real_cpu.native_cpu();
|
||||
};
|
||||
};
|
||||
|
||||
class SWCR::Cpu_session_factory : public Genode::Local_service<Cpu_session_component>::Factory
|
||||
{
|
||||
private:
|
||||
Genode::Env &_env;
|
||||
Genode::Allocator &_alloc;
|
||||
|
||||
Pd_session_component &_psc;
|
||||
|
||||
public:
|
||||
Cpu_session_factory(Genode::Allocator &alloc) : _alloc(alloc) { }
|
||||
Cpu_session_factory(Genode::Env &env, Genode::Allocator &alloc, Pd_session_component &psc) : _env(env), _alloc(alloc), _psc(psc) { }
|
||||
~Cpu_session_factory() { }
|
||||
|
||||
Cpu_session_component &create(Args const &, Genode::Affinity) override
|
||||
{
|
||||
return *new (_alloc) Cpu_session_component();
|
||||
return *new (_alloc) Cpu_session_component(_env, _psc);
|
||||
}
|
||||
|
||||
void upgrade(Cpu_session_component &, Args const &) override { }
|
||||
@@ -51,3 +117,5 @@ class SWCR::Cpu_session_factory : public Genode::Local_service<Cpu_session_compo
|
||||
Genode::destroy(_alloc, &session);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*__swcr_services_cpu_h__*/
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __swcr_pd_h__
|
||||
#define __swcr_pd_h__
|
||||
#ifndef __swcr_services_pd_h__
|
||||
#define __swcr_services_pd_h__
|
||||
|
||||
#include <root/component.h>
|
||||
#include <pd_session/connection.h>
|
||||
@@ -30,147 +30,152 @@ class SWCR::Pd_session_component : public Genode::Rpc_object<Genode::Pd_session>
|
||||
|
||||
Ram_dataspace_capability alloc(size_t size, Cache_attribute cached = CACHED)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.alloc(size, cached);
|
||||
};
|
||||
|
||||
void free(Ram_dataspace_capability ds)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.free(ds);
|
||||
};
|
||||
|
||||
size_t dataspace_size(Ram_dataspace_capability ds) const
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.dataspace_size(ds);
|
||||
};
|
||||
|
||||
void assign_parent(Capability<Parent> parent)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.assign_parent(parent);
|
||||
};
|
||||
|
||||
bool assign_pci(addr_t pci_config_memory_address, uint16_t bdf)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.assign_pci(pci_config_memory_address, bdf);
|
||||
};
|
||||
|
||||
void map(addr_t virt, addr_t size)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.map(virt, size);
|
||||
};
|
||||
|
||||
Signal_source_capability alloc_signal_source()
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.alloc_signal_source();
|
||||
};
|
||||
|
||||
void free_signal_source(Signal_source_capability cap)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.free_signal_source(cap);
|
||||
};
|
||||
|
||||
Capability<Signal_context> alloc_context(Signal_source_capability source, unsigned long imprint)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.alloc_context(source, imprint);
|
||||
};
|
||||
|
||||
void free_context(Capability<Signal_context> cap)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.free_context(cap);
|
||||
};
|
||||
|
||||
void submit(Capability<Signal_context> context, unsigned cnt = 1)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.submit(context, cnt);
|
||||
};
|
||||
|
||||
Native_capability alloc_rpc_cap(Native_capability ep)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.alloc_rpc_cap(ep);
|
||||
};
|
||||
|
||||
void free_rpc_cap(Native_capability cap)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.free_rpc_cap(cap);
|
||||
};
|
||||
|
||||
Capability<Region_map> address_space()
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.address_space();
|
||||
};
|
||||
|
||||
Capability<Region_map> stack_area()
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.stack_area();
|
||||
};
|
||||
|
||||
Capability<Region_map> linker_area()
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.linker_area();
|
||||
};
|
||||
|
||||
void ref_account(Capability<Pd_session> pd)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.ref_account(pd);
|
||||
};
|
||||
|
||||
void transfer_quota(Capability<Pd_session> to, Cap_quota amount)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.transfer_quota(to, amount);
|
||||
};
|
||||
|
||||
Cap_quota cap_quota() const
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.cap_quota();
|
||||
};
|
||||
|
||||
Cap_quota used_caps() const
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.used_caps();
|
||||
};
|
||||
|
||||
void transfer_quota(Capability<Pd_session> to, Ram_quota amount)
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
_real_pd.transfer_quota(to, amount);
|
||||
};
|
||||
|
||||
Ram_quota ram_quota() const
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.ram_quota();
|
||||
};
|
||||
|
||||
Ram_quota used_ram() const
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.used_ram();
|
||||
};
|
||||
|
||||
Capability<Native_pd> native_pd()
|
||||
{
|
||||
Genode::log("Pd::\033[33m", __func__, "\033[0m");
|
||||
Genode::log("PD::\033[33m", __func__, "\033[0m");
|
||||
return _real_pd.native_pd();
|
||||
};
|
||||
|
||||
Pd_session_capability parent_pd_cap()
|
||||
{
|
||||
return _real_pd.cap();
|
||||
}
|
||||
};
|
||||
|
||||
class SWCR::Pd_session_factory : public Genode::Local_service<Pd_session_component>::Factory
|
||||
@@ -180,13 +185,16 @@ class SWCR::Pd_session_factory : public Genode::Local_service<Pd_session_compone
|
||||
Genode::Allocator &_alloc;
|
||||
const char *_label;
|
||||
|
||||
Pd_session_component *_cpsc;
|
||||
|
||||
public:
|
||||
Pd_session_factory(Genode::Env &env, Genode::Allocator &alloc, const char *label) : _env(env), _alloc(alloc), _label(label) { }
|
||||
~Pd_session_factory() { }
|
||||
|
||||
Pd_session_component &create(Args const &, Genode::Affinity) override
|
||||
{
|
||||
return *new (_alloc) Pd_session_component(_env, _label);
|
||||
_cpsc = new (_alloc) Pd_session_component(_env, _label);
|
||||
return *_cpsc;
|
||||
}
|
||||
|
||||
void upgrade(Pd_session_component &, Args const &) override { }
|
||||
@@ -195,6 +203,11 @@ class SWCR::Pd_session_factory : public Genode::Local_service<Pd_session_compone
|
||||
{
|
||||
Genode::destroy(_alloc, &session);
|
||||
}
|
||||
|
||||
Pd_session_component &custom_pd_session_component()
|
||||
{
|
||||
return *_cpsc;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*__swcr_pd_h__*/
|
||||
#endif /*__swcr_services_pd_h__*/
|
||||
@@ -1,5 +1,9 @@
|
||||
#ifndef __swcr_target_child_h__
|
||||
#define __swcr_target_child_h__
|
||||
|
||||
#include <base/child.h>
|
||||
#include <swcr/services/pd.h>
|
||||
#include <swcr/services/cpu.h>
|
||||
|
||||
namespace SWCR
|
||||
{
|
||||
@@ -12,12 +16,17 @@ class SWCR::Target_child : public Genode::Child_policy
|
||||
{
|
||||
private:
|
||||
Genode::Env &_env;
|
||||
Genode::Heap _heap;
|
||||
Genode::Cap_quota const _cap_quota { 50 };
|
||||
Genode::Ram_quota const _ram_quota { 1 * 1024 * 1024 };
|
||||
Genode::Ram_quota const _ram_quota { 8 * 1024 * 1024 };
|
||||
|
||||
Parent_services &_parent_services;
|
||||
|
||||
Genode::Local_service<Pd_session_component> &_swcr_pd;
|
||||
SWCR::Pd_session_factory _psf;
|
||||
Genode::Local_service<Pd_session_component> _pls;
|
||||
|
||||
SWCR::Cpu_session_factory *_csf;
|
||||
Genode::Local_service<Cpu_session_component> *_cls;
|
||||
|
||||
Genode::Child _child;
|
||||
|
||||
@@ -44,14 +53,23 @@ class SWCR::Target_child : public Genode::Child_policy
|
||||
|
||||
Genode::Service *service = nullptr;
|
||||
if (!Genode::strcmp("PD", service_name.string()))
|
||||
service = &_swcr_pd;
|
||||
service = &_pls;
|
||||
else if (!Genode::strcmp("CPU", service_name.string()))
|
||||
service = _cls;
|
||||
else
|
||||
service = _find_service(_parent_services, service_name);
|
||||
return route(*service);
|
||||
}
|
||||
|
||||
public:
|
||||
Target_child(Genode::Env &env, Parent_services &parent_services, Genode::Local_service<Pd_session_component> &swcr_pd) : _env(env), _parent_services(parent_services), _swcr_pd(swcr_pd), _child(_env.rm(), _env.ep().rpc_ep(), *this) { }
|
||||
Target_child(Genode::Env &env,
|
||||
Parent_services &parent_services) : _env(env),
|
||||
_heap(_env.ram(), _env.rm()),
|
||||
_parent_services(parent_services),
|
||||
_psf(_env, _heap, "hello"),
|
||||
_pls(_psf),
|
||||
_child(_env.rm(), _env.ep().rpc_ep(), *this)
|
||||
{ }
|
||||
~Target_child() { };
|
||||
|
||||
Name name() const override { return "hello"; };
|
||||
@@ -59,10 +77,19 @@ class SWCR::Target_child : public Genode::Child_policy
|
||||
Genode::Pd_session &ref_pd() override { return _env.pd(); }
|
||||
Genode::Pd_session_capability ref_pd_cap() const override { return _env.pd_session_cap(); }
|
||||
|
||||
void init(Genode::Pd_session &pd, Genode::Pd_session_capability pd_cap) override
|
||||
void init(Genode::Pd_session &custom_pd, Genode::Pd_session_capability pd_cap) override
|
||||
{
|
||||
pd.ref_account(ref_pd_cap());
|
||||
ref_pd().transfer_quota(pd_cap, _cap_quota);
|
||||
ref_pd().transfer_quota(pd_cap, _ram_quota);
|
||||
custom_pd.ref_account(ref_pd_cap());
|
||||
Genode::log("transfering");
|
||||
Pd_session_component &pdsc = _psf.custom_pd_session_component();
|
||||
_csf = new (_heap) SWCR::Cpu_session_factory(_env, _heap, pdsc);
|
||||
_cls = new (_heap) Genode::Local_service<SWCR::Cpu_session_component>(*_csf);
|
||||
ref_pd().transfer_quota(pdsc.parent_pd_cap(), _cap_quota);
|
||||
ref_pd().transfer_quota(pdsc.parent_pd_cap(), _ram_quota);
|
||||
Genode::log("done");
|
||||
/*ref_pd().transfer_quota(_cpsc.parent_pd_cap(), _cap_quota);
|
||||
ref_pd().transfer_quota(_cpsc.parent_pd_cap(), _ram_quota);*/
|
||||
}
|
||||
};
|
||||
|
||||
#endif /*__swcr_target_child_h__*/
|
||||
@@ -54,7 +54,7 @@ set config {
|
||||
<provides> <service name="Timer"/> </provides>
|
||||
</start>
|
||||
<start name="swcr" caps="300">
|
||||
<resource name="RAM" quantum="8M"/>
|
||||
<resource name="RAM" quantum="16M"/>
|
||||
</start>}
|
||||
|
||||
append_if [have_spec gpio] config "
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include <base/component.h>
|
||||
#include <swcr/target_child.h>
|
||||
#include <swcr/services/pd.h>
|
||||
//#include <swcr/services/cpu.h>
|
||||
|
||||
namespace SWCR
|
||||
{
|
||||
@@ -24,13 +22,7 @@ struct SWCR::Main
|
||||
new (_heap) Parent_service(_parent_services, env, names[i]);
|
||||
}
|
||||
|
||||
/* custom services */
|
||||
SWCR::Pd_session_factory _psf { _env, _heap, "hello" };
|
||||
Genode::Local_service<SWCR::Pd_session_component> _pls { _psf };
|
||||
|
||||
Genode::log("creating child...");
|
||||
new (_heap) Target_child(_env, _parent_services, _pls);
|
||||
Genode::log("done");
|
||||
new (_heap) Target_child(_env, _parent_services);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user