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_types.h>
21 Device::Dev_set Device::__devs;
24 Device::resource_allocated(Resource const *r) const
29 return parent()->resource_allocated(r);
34 Device::get_dev_by_id(l4vbus_device_handle_t id)
38 else if (__devs.find(id) != __devs.end())
49 int operator () (Device *d) const
51 char const *h = d->hid();
52 if (h && strcmp(h, hid) == 0)
62 Device::get_by_hid(L4::Ipc_iostream &ios)
64 l4vbus_device_handle_t child;
70 ios >> child >> depth >> L4::ipc_buf_in(hid, sz);
72 //printf("look for '%s' in %p(%x) from %x\n", hid, this, _id, start);
79 else if ((c = iterator(this, get_dev_by_id(child), depth)) != end())
90 for (; c != end(); ++c)
93 ios << l4vbus_device_handle_t(mh.dev);
102 Device::vbus_get_device(L4::Ipc_iostream &ios)
105 inf.num_resources = resources()->size();
108 strncpy(inf.name, hid(), sizeof(inf.name));
109 inf.name[sizeof(inf.name) - 1] = 0;
116 inf.flags |= L4VBUS_DEVICE_F_CHILDREN;
118 ios << l4vbus_device_handle_t(this);
124 Device::vdevice_dispatch(l4_umword_t obj, l4_uint32_t func, L4::Ipc_iostream &ios)
126 if (func & L4vbus_vdevice_generic)
130 case L4vbus_vdevice_hid:
132 char const *h = hid();
139 case L4vbus_vdevice_adr:
141 l4_uint32_t a = adr();
142 if (a == l4_uint32_t(~0))
148 case L4vbus_vdevice_get_by_hid:
149 return get_by_hid(ios);
151 case L4vbus_vdevice_get_next:
153 l4vbus_device_handle_t child;
155 ios >> child >> depth;
161 c = ++iterator(this, get_dev_by_id(child), depth);
166 return dynamic_cast<Device*>(*c)->vbus_get_device(ios);
169 case L4vbus_vdevice_get_resource:
173 Adr_resource *r = dynamic_cast<Adr_resource*>(resources()->elem(res_idx));
178 l4vbus_resource_t res;
179 Adr_resource::Data d = r->data();
180 res.start = d.start();
182 res.type = r->type();
188 default: return -L4_ENOSYS;
192 for (Feature_list::const_iterator i = _features.begin();
193 i != _features.end(); ++i)
195 int e = (*i)->dispatch(obj, func, ios);