2014-11-13 14:44:15 +00:00
|
|
|
/**
|
|
|
|
* \brief USB session wrapper
|
|
|
|
* \author Sebastian Sumpf
|
|
|
|
* \date 2014-12-08
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 12:23:52 +00:00
|
|
|
* Copyright (C) 2014-2017 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__USB_H_
|
|
|
|
#define _INCLUDE__USB__USB_H_
|
|
|
|
|
|
|
|
#include <base/allocator.h>
|
2016-06-21 10:59:11 +00:00
|
|
|
#include <base/entrypoint.h>
|
2014-11-13 14:44:15 +00:00
|
|
|
#include <usb/types.h>
|
|
|
|
#include <usb/packet_handler.h>
|
|
|
|
#include <usb_session/connection.h>
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
#include <base/log.h>
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
namespace Usb {
|
|
|
|
|
|
|
|
/* debugging */
|
|
|
|
bool constexpr verbose_descr = false;
|
|
|
|
|
|
|
|
class Device;
|
|
|
|
class Config;
|
|
|
|
class Alternate_interface;
|
|
|
|
class Interface;
|
|
|
|
class Endpoint;
|
|
|
|
class Meta_data;
|
|
|
|
class Sync_completion;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Usb::Meta_data
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Genode::Allocator * const _md_alloc;
|
|
|
|
Connection &_connection;
|
|
|
|
Packet_handler &_handler;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Meta_data(Genode::Allocator * const md_alloc, Connection &device,
|
|
|
|
Packet_handler &handler)
|
|
|
|
: _md_alloc(md_alloc), _connection(device), _handler(handler) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Completion for synchronous calls
|
|
|
|
*/
|
|
|
|
class Usb::Sync_completion : Completion
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
bool _completed = false;
|
|
|
|
Packet_descriptor &_p;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Sync_completion(Packet_handler &handler, Packet_descriptor &p)
|
|
|
|
: _p(p)
|
|
|
|
{
|
|
|
|
Completion *c = p.completion;
|
|
|
|
p.completion = this;
|
|
|
|
|
|
|
|
handler.submit(p);
|
|
|
|
|
|
|
|
while (!_completed)
|
|
|
|
handler.wait_for_packet();
|
|
|
|
|
|
|
|
if (c)
|
|
|
|
c->complete(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void complete(Packet_descriptor &p) override
|
|
|
|
{
|
|
|
|
_p = p;
|
|
|
|
_completed = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Usb::Endpoint : public Endpoint_descriptor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Endpoint(Endpoint_descriptor &endpoint_descr)
|
|
|
|
: Endpoint_descriptor(endpoint_descr) { }
|
|
|
|
|
2016-05-11 16:21:47 +00:00
|
|
|
bool bulk() const { return (attributes & 0x3) == ENDPOINT_BULK; }
|
|
|
|
bool interrupt() const { return (attributes & 0x3) == ENDPOINT_INTERRUPT; }
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
void dump()
|
|
|
|
{
|
|
|
|
if (verbose_descr)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::log("\tEndpoint: "
|
|
|
|
"len: ", Genode::Hex(length), " "
|
|
|
|
"type: ", Genode::Hex(type), " "
|
|
|
|
"address: ", Genode::Hex(address), " "
|
|
|
|
"attributes: ", Genode::Hex(attributes));
|
2014-11-13 14:44:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Usb::Alternate_interface : public Interface_descriptor,
|
|
|
|
public Meta_data
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
enum { MAX_ENDPOINTS = 16 };
|
|
|
|
Endpoint *_endpoints[MAX_ENDPOINTS];
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Alternate_interface(Alternate_interface const &);
|
|
|
|
Alternate_interface &operator = (Alternate_interface const &);
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
public:
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
String interface_string { };
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
Alternate_interface(Interface_descriptor &interface_desc,
|
|
|
|
Meta_data &md)
|
|
|
|
: Interface_descriptor(interface_desc), Meta_data(md)
|
|
|
|
{
|
|
|
|
dump();
|
|
|
|
|
|
|
|
for (Genode::uint8_t i = 0; i < num_endpoints; i++)
|
|
|
|
{
|
|
|
|
Endpoint_descriptor descr;
|
|
|
|
_connection.endpoint_descriptor(number, alt_settings, i, &descr);
|
|
|
|
_endpoints[i] = new (_md_alloc) Endpoint(descr);
|
|
|
|
_endpoints[i]->dump();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Alternate_interface()
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < num_endpoints; i++)
|
|
|
|
destroy(_md_alloc, _endpoints[i]);
|
|
|
|
|
|
|
|
interface_string.free(_md_alloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Endpoint &endpoint(unsigned index)
|
|
|
|
{
|
|
|
|
if (index >= num_endpoints)
|
|
|
|
throw Session::Invalid_endpoint();
|
|
|
|
|
|
|
|
return *_endpoints[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump()
|
|
|
|
{
|
|
|
|
if (!verbose_descr)
|
|
|
|
return;
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::warning("Interface: "
|
|
|
|
"len: ", Genode::Hex(length), " "
|
|
|
|
"type: ", Genode::Hex(type), " "
|
|
|
|
"number: ", Genode::Hex(number), " "
|
|
|
|
"alt_settings: ", Genode::Hex(alt_settings));
|
|
|
|
Genode::warning(" "
|
|
|
|
"num_endpoints: ", Genode::Hex(num_endpoints), " "
|
|
|
|
"class: ", Genode::Hex(iclass), " ",
|
|
|
|
"subclass: ", Genode::Hex(isubclass), " "
|
|
|
|
"protocol: ", Genode::Hex(iprotocol));
|
2014-11-13 14:44:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Usb::Interface : public Meta_data
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
friend class Config;
|
|
|
|
|
|
|
|
enum { MAX_ALT = 10 };
|
|
|
|
|
|
|
|
Alternate_interface *_interface[MAX_ALT];
|
|
|
|
unsigned _count = 0;
|
|
|
|
Alternate_interface *_current = nullptr;
|
|
|
|
bool _claimed = false;
|
|
|
|
|
|
|
|
|
|
|
|
void _check()
|
|
|
|
{
|
|
|
|
if (!_claimed)
|
|
|
|
throw Session::Interface_not_claimed();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void _add(Alternate_interface *iface)
|
|
|
|
{
|
|
|
|
_interface[_count++] = iface;
|
|
|
|
|
|
|
|
if (iface->active)
|
|
|
|
_current = iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Interface(Meta_data &md)
|
|
|
|
: Meta_data(md) { }
|
|
|
|
|
|
|
|
|
|
|
|
/***************
|
|
|
|
** Accessors **
|
|
|
|
***************/
|
|
|
|
|
|
|
|
unsigned alternate_count() const { return _count; }
|
|
|
|
Alternate_interface ¤t() { return *_current; }
|
|
|
|
|
|
|
|
Alternate_interface &alternate_interface(unsigned index)
|
|
|
|
{
|
|
|
|
if (index >= _count)
|
|
|
|
throw Session::Interface_not_found();
|
|
|
|
|
|
|
|
return *_interface[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
Endpoint &endpoint(unsigned index) { return _current->endpoint(index); }
|
|
|
|
|
|
|
|
|
|
|
|
/***************************
|
|
|
|
** Packet stream helpers **
|
|
|
|
***************************/
|
|
|
|
|
|
|
|
Packet_descriptor alloc(size_t size)
|
|
|
|
{
|
|
|
|
return _handler.alloc(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
void submit(Packet_descriptor &p)
|
|
|
|
{
|
|
|
|
_handler.submit(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void release(Packet_descriptor &p)
|
|
|
|
{
|
|
|
|
_handler.release(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void *content(Packet_descriptor &p)
|
|
|
|
{
|
|
|
|
return _handler.content(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************
|
|
|
|
** Interface to USB service **
|
|
|
|
******************************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Claim interface
|
|
|
|
*/
|
|
|
|
void claim()
|
|
|
|
{
|
|
|
|
_connection.claim_interface(_interface[0]->number);
|
|
|
|
_claimed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release interface
|
|
|
|
*/
|
|
|
|
void release()
|
|
|
|
{
|
|
|
|
if (_claimed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Packet_descriptor p = alloc(0);
|
|
|
|
p.type = Packet_descriptor::RELEASE_IF;
|
|
|
|
p.number = _interface[0]->number;
|
|
|
|
p.succeded = false;
|
|
|
|
|
|
|
|
Sync_completion sync(_handler, p);
|
|
|
|
|
|
|
|
if (p.succeded)
|
|
|
|
_claimed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_alternate_interface(Alternate_interface &alternate)
|
|
|
|
{
|
|
|
|
_check();
|
|
|
|
|
|
|
|
Packet_descriptor p = alloc(0);
|
|
|
|
p.type = Packet_descriptor::ALT_SETTING;
|
|
|
|
p.succeded = false;
|
|
|
|
p.interface.number = alternate.number;
|
|
|
|
p.interface.alt_setting = alternate.alt_settings;
|
|
|
|
|
|
|
|
Sync_completion sync(_handler, p);
|
|
|
|
|
|
|
|
if (p.succeded)
|
|
|
|
_current = _interface[p.interface.alt_setting];
|
|
|
|
}
|
|
|
|
|
|
|
|
void control_transfer(Packet_descriptor &p, uint8_t request_type, uint8_t request,
|
|
|
|
uint16_t value, uint16_t index, int timeout,
|
|
|
|
bool block = true, Completion *c = nullptr)
|
|
|
|
{
|
|
|
|
_check();
|
|
|
|
|
|
|
|
p.type = Usb::Packet_descriptor::CTRL;
|
|
|
|
p.succeded = false;
|
|
|
|
p.control.request = request;
|
|
|
|
p.control.request_type = request_type;
|
|
|
|
p.control.value = value;
|
|
|
|
p.control.index = index;
|
|
|
|
p.control.timeout = timeout;
|
|
|
|
p.completion = c;
|
|
|
|
|
|
|
|
if(block) Sync_completion sync(_handler, p);
|
|
|
|
else _handler.submit(p);
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:13:51 +00:00
|
|
|
void bulk_transfer(Packet_descriptor &p, Endpoint &ep,
|
2014-11-13 14:44:15 +00:00
|
|
|
bool block = true, Completion *c = nullptr)
|
|
|
|
{
|
|
|
|
_check();
|
|
|
|
|
2019-01-30 16:27:46 +00:00
|
|
|
if (!ep.bulk())
|
2014-11-13 14:44:15 +00:00
|
|
|
throw Session::Invalid_endpoint();
|
|
|
|
|
|
|
|
p.type = Usb::Packet_descriptor::BULK;
|
|
|
|
p.succeded = false;
|
|
|
|
p.transfer.ep = ep.address;
|
|
|
|
p.completion = c;
|
|
|
|
|
|
|
|
if(block) Sync_completion sync(_handler, p);
|
|
|
|
else _handler.submit(p);
|
|
|
|
}
|
|
|
|
|
2016-10-17 12:13:51 +00:00
|
|
|
void interrupt_transfer(Packet_descriptor &p, Endpoint &ep,
|
|
|
|
int polling_interval =
|
|
|
|
Usb::Packet_descriptor::DEFAULT_POLLING_INTERVAL,
|
2014-11-13 14:44:15 +00:00
|
|
|
bool block = true, Completion *c = nullptr)
|
|
|
|
{
|
|
|
|
_check();
|
|
|
|
|
2019-01-30 16:27:46 +00:00
|
|
|
if (!ep.interrupt())
|
2014-11-13 14:44:15 +00:00
|
|
|
throw Session::Invalid_endpoint();
|
|
|
|
|
2016-10-17 12:13:51 +00:00
|
|
|
p.type = Usb::Packet_descriptor::IRQ;
|
|
|
|
p.succeded = false;
|
|
|
|
p.transfer.ep = ep.address;
|
|
|
|
p.transfer.polling_interval = polling_interval;
|
|
|
|
p.completion = c;
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
if(block) Sync_completion sync(_handler, p);
|
|
|
|
else _handler.submit(p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Usb::Config : public Config_descriptor,
|
|
|
|
public Meta_data
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
enum { MAX_INTERFACES = 32 };
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Config(Config const &);
|
|
|
|
Config &operator = (Config const &);
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
Interface *_interfaces[MAX_INTERFACES];
|
|
|
|
unsigned _total_interfaces = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
String config_string { };
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
Config(Config_descriptor &config_desc, Meta_data &md)
|
|
|
|
: Config_descriptor(config_desc), Meta_data(md)
|
|
|
|
{
|
|
|
|
dump();
|
|
|
|
|
|
|
|
for (Genode::uint8_t i = 0; i < num_interfaces; i++) {
|
|
|
|
|
|
|
|
Interface_descriptor descr;
|
|
|
|
_connection.interface_descriptor(i, 0, &descr);
|
|
|
|
_interfaces[descr.number] = new(_md_alloc) Interface(md);
|
|
|
|
|
|
|
|
/* read number of alternative settings */
|
|
|
|
unsigned alt_settings = _connection.alt_settings(i);
|
|
|
|
_total_interfaces += alt_settings;
|
|
|
|
|
|
|
|
/* alt settings */
|
|
|
|
for (unsigned j = 0; j < alt_settings; j++) {
|
|
|
|
_connection.interface_descriptor(i, j, &descr);
|
|
|
|
if (descr.number != i)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
error("Interface number != index");
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
_interfaces[descr.number]->_add(new(_md_alloc) Alternate_interface(descr, md));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~Config()
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < num_interfaces; i++)
|
|
|
|
destroy(_md_alloc, _interfaces[i]);
|
|
|
|
|
|
|
|
config_string.free(_md_alloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
Interface &interface(unsigned num)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (num >= num_interfaces)
|
|
|
|
throw Session::Interface_not_found();
|
|
|
|
|
|
|
|
return *_interfaces[num];
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump()
|
|
|
|
{
|
|
|
|
if (verbose_descr)
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
log("Config: "
|
|
|
|
"len: ", Genode::Hex(length), " "
|
|
|
|
"type: ", Genode::Hex(type), " "
|
|
|
|
"total_length: ", Genode::Hex(total_length), " "
|
|
|
|
"num_intf: ", Genode::Hex(num_interfaces), " "
|
|
|
|
"config_value: ", Genode::Hex(config_value));
|
2014-11-13 14:44:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Usb::Device : public Meta_data
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
/*
|
|
|
|
* Noncopyable
|
|
|
|
*/
|
|
|
|
Device(Device const &);
|
|
|
|
Device &operator = (Device const &);
|
|
|
|
|
2014-11-13 14:44:15 +00:00
|
|
|
Packet_handler _handler;
|
|
|
|
|
|
|
|
void _clear()
|
|
|
|
{
|
|
|
|
if (!config)
|
|
|
|
return;
|
|
|
|
|
|
|
|
manufactorer_string.free(_md_alloc);
|
|
|
|
product_string.free(_md_alloc);
|
|
|
|
serial_number_string.free(_md_alloc);
|
|
|
|
destroy(_md_alloc, config);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Speed {
|
|
|
|
SPEED_UNKNOWN = 0, /* enumerating */
|
|
|
|
SPEED_LOW,
|
|
|
|
SPEED_FULL, /* usb 1.1 */
|
|
|
|
SPEED_HIGH, /* usb 2.0 */
|
|
|
|
SPEED_WIRELESS, /* wireless (usb 2.5) */
|
|
|
|
SPEED_SUPER, /* usb 3.0 */
|
|
|
|
};
|
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
Device_descriptor device_descr { };
|
|
|
|
|
|
|
|
Config *config = nullptr;
|
2014-11-13 14:44:15 +00:00
|
|
|
|
Follow practices suggested by "Effective C++"
The patch adjust the code of the base, base-<kernel>, and os repository.
To adapt existing components to fix violations of the best practices
suggested by "Effective C++" as reported by the -Weffc++ compiler
argument. The changes follow the patterns outlined below:
* A class with virtual functions can no longer publicly inherit base
classed without a vtable. The inherited object may either be moved
to a member variable, or inherited privately. The latter would be
used for classes that inherit 'List::Element' or 'Avl_node'. In order
to enable the 'List' and 'Avl_tree' to access the meta data, the
'List' must become a friend.
* Instead of adding a virtual destructor to abstract base classes,
we inherit the new 'Interface' class, which contains a virtual
destructor. This way, single-line abstract base classes can stay
as compact as they are now. The 'Interface' utility resides in
base/include/util/interface.h.
* With the new warnings enabled, all member variables must be explicitly
initialized. Basic types may be initialized with '='. All other types
are initialized with braces '{ ... }' or as class initializers. If
basic types and non-basic types appear in a row, it is nice to only
use the brace syntax (also for basic types) and align the braces.
* If a class contains pointers as members, it must now also provide a
copy constructor and assignment operator. In the most cases, one
would make them private, effectively disallowing the objects to be
copied. Unfortunately, this warning cannot be fixed be inheriting
our existing 'Noncopyable' class (the compiler fails to detect that
the inheriting class cannot be copied and still gives the error).
For now, we have to manually add declarations for both the copy
constructor and assignment operator as private class members. Those
declarations should be prepended with a comment like this:
/*
* Noncopyable
*/
Thread(Thread const &);
Thread &operator = (Thread const &);
In the future, we should revisit these places and try to replace
the pointers with references. In the presence of at least one
reference member, the compiler would no longer implicitly generate
a copy constructor. So we could remove the manual declaration.
Issue #465
2017-12-21 14:42:15 +00:00
|
|
|
String manufactorer_string { };
|
|
|
|
String product_string { };
|
|
|
|
String serial_number_string { };
|
2014-11-13 14:44:15 +00:00
|
|
|
|
|
|
|
Device(Genode::Allocator * const md_alloc, Connection &connection,
|
2016-06-21 10:59:11 +00:00
|
|
|
Genode::Entrypoint &ep)
|
2014-11-13 14:44:15 +00:00
|
|
|
: Meta_data(md_alloc, connection, _handler), _handler(connection, ep)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
Device_descriptor const *descriptor() { return &device_descr; }
|
|
|
|
Config *config_descriptor() { return config; }
|
|
|
|
|
|
|
|
char const *speed_string(unsigned speed)
|
|
|
|
{
|
|
|
|
switch (speed) {
|
|
|
|
case SPEED_LOW : return "LOW";
|
|
|
|
case SPEED_FULL : return "FULL";
|
|
|
|
case SPEED_HIGH : return "HIGH";
|
|
|
|
case SPEED_WIRELESS: return "WIRELESS";
|
|
|
|
case SPEED_SUPER : return "SUPER";
|
|
|
|
|
|
|
|
default: return "<unknown>";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void string_descriptor(uint8_t index, String *target)
|
|
|
|
{
|
|
|
|
Packet_descriptor p = _handler.alloc(128);
|
|
|
|
p.type = Packet_descriptor::STRING;
|
|
|
|
p.string.index = index;
|
|
|
|
p.string.length = 128;
|
|
|
|
|
|
|
|
Sync_completion sync(_handler, p);
|
|
|
|
target->copy(p.string.length, _handler.content(p), _md_alloc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-read all descriptors (device, config, interface, and endpoints)
|
|
|
|
* Must be called before Usb::Device can be used (asynchronous)
|
|
|
|
*/
|
|
|
|
void update_config()
|
|
|
|
{
|
|
|
|
/* free info from previous call */
|
|
|
|
_clear();
|
|
|
|
|
|
|
|
Config_descriptor config_descr;
|
|
|
|
|
|
|
|
_connection.config_descriptor(&device_descr, &config_descr);
|
|
|
|
dump();
|
|
|
|
|
|
|
|
config = new (_md_alloc) Config(config_descr, *this);
|
|
|
|
|
|
|
|
/* retrieve string descriptors */
|
|
|
|
string_descriptor(device_descr.manufactorer_index, &manufactorer_string);
|
|
|
|
string_descriptor(device_descr.product_index, &product_string);
|
|
|
|
string_descriptor(device_descr.serial_number_index, &serial_number_string);
|
|
|
|
string_descriptor(config->config_index, &config->config_string);
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < config->num_interfaces; i++) {
|
|
|
|
Interface &iface = config->interface(i);
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < iface.alternate_count(); j++)
|
|
|
|
string_descriptor(iface.alternate_interface(j).interface_index,
|
|
|
|
&iface.alternate_interface(j).interface_string);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set configuration, no interfaces can be claimed (asynchronous)
|
|
|
|
*/
|
|
|
|
void set_configuration(uint8_t num)
|
|
|
|
{
|
|
|
|
if (!config) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("No current configuration found");
|
2014-11-13 14:44:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!num || num > device_descr.num_configs) {
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
Genode::error("Valid configuration values: 1 ... ", device_descr.num_configs);
|
2014-11-13 14:44:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config && num == config->config_value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Packet_descriptor p = _handler.alloc(0);
|
|
|
|
p.type = Packet_descriptor::CONFIG;
|
|
|
|
p.number = num;
|
|
|
|
|
|
|
|
Sync_completion sync(_handler, p);
|
|
|
|
|
|
|
|
if (p.succeded)
|
|
|
|
update_config();
|
|
|
|
}
|
|
|
|
|
|
|
|
Interface &interface(unsigned interface_num)
|
|
|
|
{
|
|
|
|
return config->interface(interface_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dump()
|
|
|
|
{
|
|
|
|
if (!verbose_descr)
|
|
|
|
return;
|
|
|
|
|
base: avoid use of deprecated base/printf.h
Besides adapting the components to the use of base/log.h, the patch
cleans up a few base headers, i.e., it removes unused includes from
root/component.h, specifically base/heap.h and
ram_session/ram_session.h. Hence, components that relied on the implicit
inclusion of those headers have to manually include those headers now.
While adjusting the log messages, I repeatedly stumbled over the problem
that printing char * arguments is ambiguous. It is unclear whether to
print the argument as pointer or null-terminated string. To overcome
this problem, the patch introduces a new type 'Cstring' that allows the
caller to express that the argument should be handled as null-terminated
string. As a nice side effect, with this type in place, the optional len
argument of the 'String' class could be removed. Instead of supplying a
pair of (char const *, size_t), the constructor accepts a 'Cstring'.
This, in turn, clears the way let the 'String' constructor use the new
output mechanism to assemble a string from multiple arguments (and
thereby getting rid of snprintf within Genode in the near future).
To enforce the explicit resolution of the char * ambiguity, the 'char *'
overload of the 'print' function is marked as deleted.
Issue #1987
2016-07-13 17:07:09 +00:00
|
|
|
using Genode::Hex;
|
|
|
|
|
|
|
|
Genode::log("Device: "
|
|
|
|
"len: ", Hex(device_descr.length), " "
|
|
|
|
"type: " , Hex(device_descr.type), " "
|
|
|
|
"class: ", Hex(device_descr.dclass), " "
|
|
|
|
"sub-class: ", Hex(device_descr.dsubclass), " "
|
|
|
|
"proto: ", Hex(device_descr.dprotocol), " "
|
|
|
|
"max_packet: ", Hex(device_descr.max_packet_size));
|
|
|
|
Genode::log(" "
|
|
|
|
"vendor: ", Hex(device_descr.vendor_id), " "
|
|
|
|
"product: ", Hex(device_descr.product_id), " "
|
|
|
|
"configs: ", Hex(device_descr.num_configs));
|
2014-11-13 14:44:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__USB__USB_H_ */
|