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
35 virtual ~Dev_feature() {}
36 virtual bool match_hw_feature(Hw::Dev_feature const *) const = 0;
37 virtual int dispatch(l4_umword_t obj, l4_uint32_t func, L4::Ipc_iostream &ios) = 0;
38 virtual Device *host() const = 0;
39 virtual void set_host(Device *d) = 0;
43 class Device : public Generic_device, public Device_tree_mixin<Device>
46 typedef Device_tree_mixin<Device>::iterator iterator;
47 using Device_tree_mixin<Device>::begin;
48 using Device_tree_mixin<Device>::end;
50 // disptach helper for server object
51 int vdevice_dispatch(l4_umword_t obj, l4_uint32_t func, L4::Ipc_iostream &ios);
53 typedef std::vector<Dev_feature*> Feature_list;
55 Feature_list const *features() const { return &_features; }
57 void add_feature(Dev_feature *f)
60 _features.push_back(f);
63 template< typename FT >
66 for (Feature_list::const_iterator i = _features.begin();
67 i != _features.end(); ++i)
68 if (FT *r = dynamic_cast<FT*>(*i))
75 virtual l4_uint32_t adr() const
76 { return l4_uint32_t(~0); }
79 { __devs.erase(l4vbus_device_handle_t(this)); }
81 char const *name() const
82 { return _name.c_str(); }
84 bool name(cxx::String const &n)
86 _name = std::string(n.start(), n.end());
90 bool resource_allocated(Resource const *) const;
92 virtual void finalize_setup() {}
94 Device *parent() const { return _dt.parent(); }
95 Device *children() const { return _dt.children(); }
96 Device *next() const { return _dt.next(); }
97 int depth() const { return _dt.depth(); }
101 int get_by_hid(L4::Ipc_iostream &ios);
102 int vbus_get_device(L4::Ipc_iostream &ios);
103 Device *get_dev_by_id(l4vbus_device_handle_t id);
106 Device() : _name("(noname)")
107 { __devs.insert(l4vbus_device_handle_t(this)); }
112 for (d = this; d->parent(); d = d->parent())
119 typedef cxx::Avl_set<l4vbus_device_handle_t> Dev_set;
120 //typedef std::set<l4vbus_device_handle_t> Dev_set;
121 static Dev_set __devs;
124 Feature_list _features;