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.
10 #include <libc-symbols.h>
13 #include "hw_device.h"
23 printf("Hw::Device::plug(this=%p, name='%s', hid='%s')\n",
32 Device::discover_secondary_bus()
35 printf("Hw::Device::discover_secondary_bus(this=%p, name='%s', hid='%s')\n",
40 for (iterator c = begin(0); c != end(); ++c)
43 for (iterator c = begin(0); c != end(); ++c)
45 (*c)->discover_secondary_bus();
52 discover_secondary_bus();
53 allocate_pending_resources();
58 Device_factory::dump()
60 for (Name_map::const_iterator i = nm().begin(); i != nm().end(); ++i)
61 printf("HW: '%s'\n", (*i).first.c_str());
65 Device_factory::create(cxx::String const &name)
67 Name_map::const_iterator i = nm().find(std::string(name.start(), name.end()));
69 return i->second->create();
75 Device::resource_allocated(Resource const *r) const
81 Device::discover_devices()
83 if (discover_bus_if())
84 discover_bus_if()->scan_bus();
88 Device::discover_resources()
90 for (Discover_res_list::const_iterator d = _resource_discovery_chain.begin();
91 d != _resource_discovery_chain.end(); ++d)
92 (*d)->discover_resources(this);
96 Device::setup_resources()
98 for (Discover_res_list::const_iterator d = _resource_discovery_chain.begin();
99 d != _resource_discovery_chain.end(); ++d)
100 (*d)->setup_resources(this);
102 // take care for children
103 for (Hw::Device::iterator i = begin(0); i != end(); ++i)
104 i->setup_resources();
108 Device::get_child_dev_adr(l4_uint32_t adr, bool create)
110 for (Device *c = children(); c; c = c->next())
117 Device *c = new Device(adr);
118 _dt.add_child(c, this);
123 Device::get_child_dev_uid(l4_umword_t uid, l4_uint32_t adr, bool create)
125 for (Device *c = children(); c; c = c->next())
132 Device *c = new Device(uid, adr);
133 _dt.add_child(c, this);
138 Device::set_property(cxx::String const &prop, Prop_val const &val)
142 if (val.type != Prop_val::String)
145 cxx::String const v = val.get_string();
146 _hid = std::string(v.start(), v.start() + v.len());
149 else if (prop == "name")
151 if (val.type != Prop_val::String)
154 cxx::String const v = val.get_string();
155 _name = std::string(v.start(), v.start() + v.len());
158 else if (prop == "adr")
160 if (val.type != Prop_val::Int)
163 _adr = val.val.integer;
171 Device::match_cid(cxx::String const &cid) const
174 char cid_cstr[cid.len() + 1];
175 __builtin_memcpy(cid_cstr, cid.start(), cid.len());
176 cid_cstr[cid.len()] = 0;
177 if (!fnmatch(cid_cstr, hid(), 0))
181 for (Cid_list::const_iterator i = _cid.begin(); i != _cid.end(); ++i)
182 if (cid == (*i).c_str())
185 for (Feature_list::const_iterator i = _features.begin();
186 i != _features.end(); ++i)
187 if ((*i)->match_cid(cid))
194 Device::dump(int indent) const
196 printf("%*.sHw::Device[%s]\n", indent, " ", name());
197 if (Io_config::cfg->verbose() > 2)
199 for (Feature_list::const_iterator i = _features.begin();
200 i != _features.end(); ++i)
201 (*i)->dump(indent + 2);
206 static Device_factory_t<Device> __hw_pf_factory("Device");