2022-03-10 15:31:40 +00:00
|
|
|
/*
|
2014-11-13 14:44:15 +00:00
|
|
|
* \brief Client connection to USB server
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
* \author Stefan Kalkowski
|
2014-11-13 14:44:15 +00:00
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \date 2014-12-08
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
* Copyright (C) 2014-2024 Genode Labs GmbH
|
2014-11-13 14:44:15 +00:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 12:23:52 +00:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2014-11-13 14:44:15 +00:00
|
|
|
*/
|
|
|
|
#ifndef _INCLUDE__USB_SESSION__CONNECTION_H_
|
|
|
|
#define _INCLUDE__USB_SESSION__CONNECTION_H_
|
|
|
|
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
#include <base/attached_dataspace.h>
|
2014-11-13 14:44:15 +00:00
|
|
|
#include <base/connection.h>
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
#include <rom_session/client.h>
|
|
|
|
#include <usb_session/client.h>
|
2014-11-13 14:44:15 +00:00
|
|
|
|
2015-03-04 20:12:14 +00:00
|
|
|
namespace Usb { struct Connection; }
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
class Usb::Connection : public Genode::Connection<Session>, public Usb::Client
|
2014-11-13 14:44:15 +00:00
|
|
|
{
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
Env & _env;
|
|
|
|
Rom_session_client _rom { devices_rom() };
|
|
|
|
Constructible<Attached_dataspace> _ds {};
|
|
|
|
Io_signal_handler<Connection> _handler { _env.ep(), *this,
|
|
|
|
&Connection::_handle_io };
|
|
|
|
|
|
|
|
void _try_attach()
|
|
|
|
{
|
|
|
|
_ds.destruct();
|
|
|
|
try { _ds.construct(_env.rm(), _rom.dataspace()); }
|
|
|
|
catch (Attached_dataspace::Invalid_dataspace) {
|
|
|
|
warning("Invalid devices rom dataspace returned!");}
|
|
|
|
}
|
|
|
|
|
|
|
|
void _handle_io() { }
|
|
|
|
|
2024-05-22 15:22:53 +00:00
|
|
|
Device_capability _wait_for_device(auto const & fn)
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
{
|
|
|
|
for (;;) {
|
|
|
|
/* repeatedly check for availability of device */
|
|
|
|
Device_capability cap = fn();
|
|
|
|
if (cap.valid())
|
|
|
|
return cap;
|
|
|
|
|
|
|
|
_env.ep().wait_and_dispatch_one_io_signal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Connection(Genode::Env &env,
|
|
|
|
Genode::size_t ram_quota = RAM_QUOTA)
|
|
|
|
:
|
|
|
|
Genode::Connection<Session>(env, Label(),
|
|
|
|
Ram_quota { ram_quota }, Args()),
|
|
|
|
Client(cap()),
|
|
|
|
_env(env)
|
|
|
|
{
|
|
|
|
_try_attach();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initially register dummy handler, to be able to receive signals
|
|
|
|
* if _wait_for_device probes for a valid devices rom
|
|
|
|
*/
|
|
|
|
sigh(_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void update()
|
|
|
|
{
|
|
|
|
if (_ds.constructed() && _rom.update() == true)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_try_attach();
|
|
|
|
}
|
|
|
|
|
|
|
|
void sigh(Signal_context_capability sigh) { _rom.sigh(sigh); }
|
|
|
|
|
2024-05-22 15:22:53 +00:00
|
|
|
void with_xml(auto const & fn)
|
usb: session renewal & new client API
Replace the USB session API by one that provides a devices ROM only,
which contains information about all USB devices available for this client,
as well as methods to acquire and release a single device.
The acquisition of an USB device returns the capability to a device session
that includes a packet stream buffer to communicate control transfers
in between the client and the USB host controller driver. Moreover,
additional methods to acquire and release an USB interface can be used.
The acquisition of an USB interface returns the capability to an interface
session that includes a packet stream buffer to communicate either
bulk, interrupt, or isochronous transfers in between the client and the
USB host controller driver.
This commit implements the API changes in behalf of the Genode C API's
USB server and client side. Addtionally, it provides Usb::Device,
Usb::Interface, and Usb::Endpoint utilities that can be used by native
C++ clients to use the new API and hide the sophisticated packet stream API.
The adaptations necessary target the following areas:
* lx_emul layer for USB host and client side
* Linux USB host controller driver port for PC
* Linux USB client ports: usb_hid_drv and usb_net_drv, additionally
reduce the Linux tasks used inside these drivers
* Native usb_block_drv
* black_hole component
* Port of libusb, including smartcard and usb_webcam driver depending on it
* Port of Qemu XHCI model library, including vbox5 & vbox6 depending on it
* Adapt all run-scripts and drivers_interactive recipes to work
with the new policy rules of the USB host controller driver
Fix genodelabs/genode#5021
2023-09-14 08:55:11 +00:00
|
|
|
{
|
|
|
|
update();
|
|
|
|
try {
|
|
|
|
if (_ds.constructed() && _ds->local_addr<void const>()) {
|
|
|
|
Xml_node xml(_ds->local_addr<char>(), _ds->size());
|
|
|
|
fn(xml);
|
|
|
|
}
|
|
|
|
} catch (Xml_node::Invalid_syntax) {
|
|
|
|
warning("Devices rom has invalid XML syntax"); }
|
|
|
|
}
|
|
|
|
|
|
|
|
Device_capability acquire_device(Device_name const &name) override
|
|
|
|
{
|
|
|
|
Ram_quota ram_quota(Device_session::TX_BUFFER_SIZE + 4096);
|
|
|
|
return retry_with_upgrade(ram_quota, Cap_quota{6}, [&] () {
|
|
|
|
return Client::acquire_device(name); });
|
|
|
|
}
|
|
|
|
|
|
|
|
Device_capability acquire_device()
|
|
|
|
{
|
|
|
|
return _wait_for_device([&] () {
|
|
|
|
Ram_quota ram_quota(Device_session::TX_BUFFER_SIZE + 4096);
|
|
|
|
return retry_with_upgrade(ram_quota, Cap_quota{6}, [&] () {
|
|
|
|
return Client::acquire_single_device(); });
|
|
|
|
});
|
|
|
|
}
|
2014-11-13 14:44:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__USB_SESSION__CONNECTION_H_ */
|