2 * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3 * Alexander Warg <warg@os.inf.tu-dresden.de>
4 * economic rights: Technische Universität Dresden (Germany)
6 * This file is part of TUD:OS and distributed under the terms of the
7 * GNU General Public License 2.
8 * Please see the COPYING-GPL-2 file for details.
16 #include <l4/vbus/vdevice-ops.h>
17 #include <l4/vbus/vbus_pm-ops.h>
18 #include <l4/vbus/vbus_types.h>
22 Device::Dev_set Device::__devs;
25 Device::dump(int indent) const
27 printf("%*.s%s: [%s]\n", indent, " ", name(), typeid(*this).name());
31 Device::resource_allocated(Resource const *r) const
36 return parent()->resource_allocated(r);
41 Device::get_dev_by_id(l4vbus_device_handle_t id)
45 else if (__devs.find(id) != __devs.end())
56 int operator () (Device *d) const
58 char const *h = d->hid();
59 if (h && strcmp(h, hid) == 0)
69 Device::get_by_hid(L4::Ipc::Iostream &ios)
71 l4vbus_device_handle_t child;
77 ios >> child >> depth >> L4::Ipc::buf_in(hid, sz);
79 //printf("look for '%s' in %p(%x) from %x\n", hid, this, _id, start);
86 else if ((c = iterator(this, get_dev_by_id(child), depth)) != end())
97 for (; c != end(); ++c)
99 return dynamic_cast<Device*>(*c)->vbus_get_device(ios);
106 Device::vbus_get_device(L4::Ipc::Iostream &ios)
109 inf.num_resources = resources()->size();
112 strncpy(inf.name, name(), sizeof(inf.name));
113 inf.name[sizeof(inf.name) - 1] = 0;
120 inf.flags |= L4VBUS_DEVICE_F_CHILDREN;
122 ios << l4vbus_device_handle_t(this);
128 Device::vdevice_dispatch(l4_umword_t obj, l4_uint32_t func, L4::Ipc::Iostream &ios)
130 if (func & L4vbus_vdevice_generic)
134 case L4vbus_vdevice_hid:
136 char const *h = hid();
143 case L4vbus_vdevice_adr:
145 l4_uint32_t a = adr();
146 if (a == l4_uint32_t(~0))
152 case L4vbus_vdevice_get_by_hid:
153 return get_by_hid(ios);
155 case L4vbus_vdevice_get_next:
157 l4vbus_device_handle_t child;
159 ios >> child >> depth;
165 c = ++iterator(this, get_dev_by_id(child), depth);
170 return dynamic_cast<Device*>(*c)->vbus_get_device(ios);
173 case L4vbus_vdevice_get_resource:
177 if (res_idx < 0 || (unsigned)res_idx >= resources()->size())
180 Resource *r = resources()->at(res_idx);
181 l4vbus_resource_t res;
182 res.start = r->start();
184 res.type = r->type();
186 res.provider = r->provider_device_handle();
192 case L4vbus_vdevice_is_compatible:
196 ios >> L4::Ipc::buf_in(cid, sz);
197 return match_cid(cxx::String(cid, strnlen(cid, sz))) ? 1 : 0;
200 case L4vbus_vdevice_get_hid:
201 if (char const *_hid = hid())
208 case L4VBUS_PM_OP_SUSPEND:
211 case L4VBUS_PM_OP_RESUME:
214 default: return -L4_ENOSYS;
218 for (Feature_list::const_iterator i = _features.begin();
219 i != _features.end(); ++i)
221 int e = (*i)->dispatch(obj, func, ios);