2 * (c) 2010 Technische Universität Dresden
3 * This file is part of TUD:OS and distributed under the terms of the
4 * GNU General Public License 2.
5 * Please see the COPYING-GPL-2 file for details.
13 #include <l4/vbus/vdevice-ops.h>
14 #include <l4/vbus/vbus_types.h>
18 Device::Dev_set Device::__devs;
21 Device::resource_allocated(Resource const *r) const
26 return parent()->resource_allocated(r);
31 Device::get_dev_by_id(l4vbus_device_handle_t id)
35 else if (__devs.find(id) != __devs.end())
46 int operator () (Device *d) const
48 char const *h = d->hid();
49 if (h && strcmp(h, hid) == 0)
59 Device::get_by_hid(L4::Ipc_iostream &ios)
61 l4vbus_device_handle_t child;
67 ios >> child >> depth >> L4::ipc_buf_in(hid, sz);
69 //printf("look for '%s' in %p(%x) from %x\n", hid, this, _id, start);
76 else if ((c = iterator(this, get_dev_by_id(child), depth)) != end())
87 for (; c != end(); ++c)
90 ios << l4vbus_device_handle_t(mh.dev);
99 Device::vbus_get_device(L4::Ipc_iostream &ios)
102 inf.num_resources = resources()->size();
105 strncpy(inf.name, hid(), sizeof(inf.name));
106 inf.name[sizeof(inf.name) - 1] = 0;
113 inf.flags |= L4VBUS_DEVICE_F_CHILDREN;
115 ios << l4vbus_device_handle_t(this);
121 Device::vdevice_dispatch(l4_umword_t obj, l4_uint32_t func, L4::Ipc_iostream &ios)
123 if (func & L4vbus_vdevice_generic)
127 case L4vbus_vdevice_hid:
129 char const *h = hid();
136 case L4vbus_vdevice_adr:
138 l4_uint32_t a = adr();
139 if (a == l4_uint32_t(~0))
145 case L4vbus_vdevice_get_by_hid:
146 return get_by_hid(ios);
148 case L4vbus_vdevice_get_next:
150 l4vbus_device_handle_t child;
152 ios >> child >> depth;
158 c = ++iterator(this, get_dev_by_id(child), depth);
163 return dynamic_cast<Device*>(*c)->vbus_get_device(ios);
166 case L4vbus_vdevice_get_resource:
170 Adr_resource *r = dynamic_cast<Adr_resource*>(resources()->elem(res_idx));
175 l4vbus_resource_t res;
176 Adr_resource::Data d = r->data();
177 res.start = d.start();
179 res.type = r->type();
185 default: return -L4_ENOSYS;
189 for (Feature_list::const_iterator i = _features.begin();
190 i != _features.end(); ++i)
192 int e = (*i)->dispatch(obj, func, ios);