pc/usb: defer startup until config is available

The commit also adds lx_kit/initial_config.h as utility.
This commit is contained in:
Christian Helmuth 2022-03-09 15:00:31 +01:00 committed by Norman Feske
parent e3706837b9
commit 7da691b52a
2 changed files with 62 additions and 4 deletions

View File

@ -0,0 +1,56 @@
/*
* \brief Lx_kit initial config utility
* \author Christian Helmuth
* \author Norman Feske
* \date 2022-03-11
*/
/*
* Copyright (C) 2022 Genode Labs GmbH
*
* This file is distributed under the terms of the GNU General Public License
* version 2.
*/
#ifndef _LX_KIT__INITIAL_CONFIG_H_
#define _LX_KIT__INITIAL_CONFIG_H_
#include <base/env.h>
#include <base/attached_rom_dataspace.h>
namespace Lx_kit {
using namespace Genode;
struct Initial_config;
}
struct Lx_kit::Initial_config
{
Attached_rom_dataspace rom;
void _handle_signal() { rom.update(); }
Initial_config(Genode::Env &env) : rom(env, "config")
{
/*
* Defer the startup of the USB driver until the first configuration
* becomes available. This is needed in scenarios where the configuration
* is dynamically generated and supplied to the USB driver via the
* report-ROM service.
*/
Io_signal_handler<Initial_config> sigh {
env.ep(), *this, &Initial_config::_handle_signal };
rom.sigh(sigh);
_handle_signal();
while (rom.xml().type() != "config")
env.ep().wait_and_dispatch_one_io_signal();
rom.sigh(Signal_context_capability());
}
};
#endif /* _LX_KIT__INITIAL_CONFIG_H_ */

View File

@ -11,7 +11,6 @@
* version 2.
*/
#include <base/attached_rom_dataspace.h>
#include <base/component.h>
#include <base/env.h>
@ -19,6 +18,7 @@
#include <lx_emul/usb.h>
#include <lx_kit/env.h>
#include <lx_kit/init.h>
#include <lx_kit/initial_config.h>
#include <lx_user/io.h>
#include <genode_c_api/usb.h>
@ -50,8 +50,6 @@ struct Main : private Entrypoint::Io_progress_handler
&Main::handle_signal };
Sliced_heap sliced_heap { env.ram(), env.rm() };
Attached_rom_dataspace config_rom { env, "config" };
/**
* Entrypoint::Io_progress_handler
*/
@ -68,7 +66,11 @@ struct Main : private Entrypoint::Io_progress_handler
Main(Env & env) : env(env)
{
_bios_handoff = config_rom.xml().attribute_value("bios_handoff", true);
{
Lx_kit::Initial_config config { env };
_bios_handoff = config.rom.xml().attribute_value("bios_handoff", true);
}
Lx_kit::initialize(env);