2 * (c) 2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
11 #include <l4/sys/types.h>
12 #include <l4/cxx/avl_set>
16 #include <l4/cxx/ipc_stream>
17 #include <l4/vbus/vbus_types.h>
18 #include <cstdio> // dbg
36 virtual ~Dev_feature() {}
37 virtual bool match_hw_feature(Hw::Dev_feature const *) const = 0;
38 virtual int dispatch(l4_umword_t obj, l4_uint32_t func, L4::Ipc::Iostream &ios) = 0;
39 virtual Device *host() const = 0;
40 virtual void set_host(Device *d) = 0;
44 class Device : public Generic_device, public Device_tree_mixin<Device>
47 typedef Device_tree_mixin<Device>::iterator iterator;
48 using Device_tree_mixin<Device>::begin;
49 using Device_tree_mixin<Device>::end;
51 // disptach helper for server object
52 int vdevice_dispatch(l4_umword_t obj, l4_uint32_t func, L4::Ipc::Iostream &ios);
54 typedef std::vector<Dev_feature*> Feature_list;
56 Feature_list const *features() const { return &_features; }
58 void add_feature(Dev_feature *f)
61 _features.push_back(f);
64 template< typename FT >
67 for (Feature_list::const_iterator i = _features.begin();
68 i != _features.end(); ++i)
69 if (FT *r = dynamic_cast<FT*>(*i))
76 virtual l4_uint32_t adr() const
77 { return l4_uint32_t(~0); }
80 { __devs.erase(l4vbus_device_handle_t(this)); }
82 char const *name() const
83 { return _name.c_str(); }
85 bool name(cxx::String const &n)
87 _name = std::string(n.start(), n.end());
91 bool resource_allocated(Resource const *) const;
93 virtual int add_filter(cxx::String const &, cxx::String const &) { return -ENODEV; }
94 virtual int add_filter(cxx::String const &, unsigned long long) { return -ENODEV; }
95 virtual int add_filter(cxx::String const &, unsigned long long, unsigned long long) { return -ENODEV; }
96 virtual void finalize_setup() {}
98 Device *parent() const { return _dt.parent(); }
99 Device *children() const { return _dt.children(); }
100 Device *next() const { return _dt.next(); }
101 int depth() const { return _dt.depth(); }
105 int get_by_hid(L4::Ipc::Iostream &ios);
106 int vbus_get_device(L4::Ipc::Iostream &ios);
107 Device *get_dev_by_id(l4vbus_device_handle_t id);
110 Device() : _name("(noname)")
111 { __devs.insert(l4vbus_device_handle_t(this)); }
116 for (d = this; d->parent(); d = d->parent())
123 typedef cxx::Avl_set<l4vbus_device_handle_t> Dev_set;
124 //typedef std::set<l4vbus_device_handle_t> Dev_set;
125 static Dev_set __devs;
128 Feature_list _features;