L4Re - L4 Runtime Environment
vbus
1 // vi:ft=cpp
2 /*
3  * (c) 2011 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
4  * economic rights: Technische Universität Dresden (Germany)
5  *
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.
9  */
10 #pragma once
11 
12 #include <l4/vbus/vbus.h>
13 #include <l4/vbus/vbus_pm.h>
14 #include <l4/sys/icu>
15 
16 #include <l4/re/dataspace>
17 #include <l4/re/dma_space>
18 #include <l4/re/event>
19 #include <l4/re/inhibitor>
20 
38 namespace L4vbus {
39 
40 class Vbus;
41 
46 template<typename DEC>
47 class Pm
48 {
49 private:
50  DEC const *self() const { return static_cast<DEC const *>(this); }
51  DEC *self() { return static_cast<DEC *>(this); }
52 public:
56  int pm_suspend() const
57  { return l4vbus_pm_suspend(self()->bus_cap().cap(), self()->dev_handle()); }
58 
62  int pm_resume() const
63  { return l4vbus_pm_resume(self()->bus_cap().cap(), self()->dev_handle()); }
64 };
65 
66 
71 class Device : public Pm<Device>
72 {
73 public:
74  Device() : _dev(L4VBUS_NULL) {}
75 
76  Device(L4::Cap<Vbus> bus, l4vbus_device_handle_t dev)
77  : _bus(bus), _dev(dev) {}
78 
83  L4::Cap<Vbus> bus_cap() const { return _bus; }
84 
92  l4vbus_device_handle_t dev_handle() const { return _dev; }
93 
94 
124  int device_by_hid(Device *child, char const *hid,
125  int depth = L4VBUS_MAX_DEPTH,
126  l4vbus_device_t *devinfo = 0) const
127  {
128  child->_bus = _bus;
129  return l4vbus_get_device_by_hid(_bus.cap(), _dev, &child->_dev, hid,
130  depth, devinfo);
131  }
132 
145  int next_device(Device *child, int depth = L4VBUS_MAX_DEPTH,
146  l4vbus_device_t *devinfo = 0) const
147  {
148  child->_bus = _bus;
149  return l4vbus_get_next_device(_bus.cap(), _dev, &child->_dev, depth,
150  devinfo);
151  }
152 
164  int device(l4vbus_device_t *devinfo) const
165  { return l4vbus_get_device(_bus.cap(), _dev, devinfo); }
166 
184  int get_resource(int res_idx, l4vbus_resource_t *res) const
185  {
186  return l4vbus_get_resource(_bus.cap(), _dev, res_idx, res);
187  }
188 
198  int is_compatible(char const *cid) const
199  { return l4vbus_is_compatible(_bus.cap(), _dev, cid); }
200 
205  bool operator == (Device const &o) const
206  {
207  return _bus == o._bus && _dev == o._dev;
208  }
209 
214  bool operator != (Device const &o) const
215  {
216  return _bus != o._bus || _dev != o._dev;
217  }
218 
219 protected:
222  l4vbus_device_handle_t _dev;
223 };
224 
234 class Icu : public Device
235 {
236 public:
240  int vicu(L4::Cap<L4::Icu> icu) const
241  {
242  return l4vbus_vicu_get_cap(_bus.cap(), _dev, icu.cap());
243  }
244 };
245 
253 class Vbus : public L4::Kobject_3t<Vbus, L4Re::Dataspace, L4Re::Inhibitor, L4Re::Event>
254 {
255 public:
256 
263  int request_resource(l4vbus_resource_t *res, int flags = 0) const
264  {
265  return l4vbus_request_resource(cap(), res, flags);
266  }
267 
274  {
275  return l4vbus_release_resource(cap(), res);
276  }
277 
282  Device root() const
283  {
284  return Device(L4::Cap<Vbus>(cap()), L4VBUS_ROOT_BUS);
285  }
286 
303  int assign_dma_domain(unsigned domain_id, unsigned flags,
304  L4::Cap<L4Re::Dma_space> dma_space) const
305  {
308  return l4vbus_assign_dma_domain(cap(), domain_id, flags, dma_space.cap());
309  }
310 
328  int assign_dma_domain(unsigned domain_id, unsigned flags,
329  L4::Cap<L4::Task> dma_space) const
330  {
332  flags &= ~L4VBUS_DMAD_L4RE_DMA_SPACE;
333  return l4vbus_assign_dma_domain(cap(), domain_id, flags, dma_space.cap());
334  }
335 
337 };
338 
339 } // namespace L4vbus
NULL device.
Definition: vbus.h:23
Device root() const
Get the root device of the device tree of this bus.
Definition: vbus:282
int device_by_hid(Device *child, char const *hid, int depth=L4VBUS_MAX_DEPTH, l4vbus_device_t *devinfo=0) const
Find a device by the human interface identifier (HID).
Definition: vbus:124
Helper class to create an L4Re interface class that is derived from three base classes (see L4::Kobje...
Definition: __typeinfo.h:935
int l4vbus_assign_dma_domain(l4_cap_idx_t vbus, unsigned domain_id, unsigned flags, l4_cap_idx_t dma_space)
Bind or unbind a kernel DMA space (L4::Task) or a L4Re::Dma_space to a DMA domain.
Power-management API mixin.
Definition: vbus:47
int l4vbus_get_device_by_hid(l4_cap_idx_t vbus, l4vbus_device_handle_t parent, l4vbus_device_handle_t *child, char const *hid, int depth, l4vbus_device_t *devinfo)
Find a device by the human interface identifier (HID).
int next_device(Device *child, int depth=L4VBUS_MAX_DEPTH, l4vbus_device_t *devinfo=0) const
Find next child following child.
Definition: vbus:145
int assign_dma_domain(unsigned domain_id, unsigned flags, L4::Cap< L4Re::Dma_space > dma_space) const
Assign an L4Re::Dma_space to a DMA domain.
Definition: vbus:303
int assign_dma_domain(unsigned domain_id, unsigned flags, L4::Cap< L4::Task > dma_space) const
Assign a kernel DMA space to a DMA domain.
Definition: vbus:328
RPCs list for passing raw incoming IPC to the server object.
Definition: __typeinfo.h:422
Interrupt controller.
int device(l4vbus_device_t *devinfo) const
Obtain detailed information about a Vbus device.
Definition: vbus:164
Root device on the vbus.
Definition: vbus.h:24
Description of the vbus C API.
int is_compatible(char const *cid) const
Check if the given device has a compatibility ID (CID) or HID that matches cid.
Definition: vbus:198
Description of a single vbus resource.
Definition: vbus_types.h:23
l4vbus_device_handle_t dev_handle() const
Access the device handle of this device.
Definition: vbus:92
int l4vbus_get_resource(l4_cap_idx_t vbus, l4vbus_device_handle_t dev, int res_idx, l4vbus_resource_t *res)
Obtain the resource description of an individual device resource.
Device on a L4vbus::Vbus.
Definition: vbus:71
int pm_suspend() const
Suspend the module.
Definition: vbus:56
int get_resource(int res_idx, l4vbus_resource_t *res) const
Obtain the resource description of an individual device resource.
Definition: vbus:184
int l4vbus_vicu_get_cap(l4_cap_idx_t vbus, l4vbus_device_handle_t icu, l4_cap_idx_t cap)
Get capability of ICU.
l4_cap_idx_t cap() const
Return capability selector.
Definition: capability.h:52
Detailed information about a vbus device.
Definition: vbus_types.h:56
int l4vbus_request_resource(l4_cap_idx_t vbus, l4vbus_resource_t const *res, int flags)
Request a resource of a specific type.
l4vbus_device_handle_t _dev
The device handle for this device.
Definition: vbus:222
int l4vbus_is_compatible(l4_cap_idx_t vbus, l4vbus_device_handle_t dev, char const *cid)
Check if the given device has a compatibility ID (CID) or HID that matches cid.
int l4vbus_get_device(l4_cap_idx_t vbus, l4vbus_device_handle_t dev, l4vbus_device_t *devinfo)
Obtain detailed information about a Vbus device.
L4::Cap< Vbus > _bus
Definition: vbus:220
Definition: vbus:38
int l4vbus_release_resource(l4_cap_idx_t vbus, l4vbus_resource_t const *res)
Release a previously requested resource.
int l4vbus_get_next_device(l4_cap_idx_t vbus, l4vbus_device_handle_t parent, l4vbus_device_handle_t *child, int depth, l4vbus_device_t *devinfo)
Find next child following child.
int release_resource(l4vbus_resource_t *res) const
Release the given resource from the bus.
Definition: vbus:273
Vbus Interrupt controller API.
Definition: vbus:234
Dataspace interface.
The given DMA space is an L4Re::Dma_space.
Definition: vbus.h:160
C++ interface for capabilities.
Definition: capability.h:13
The virtual bus (Vbus) interface.
Definition: vbus:253
int request_resource(l4vbus_resource_t *res, int flags=0) const
Request the given resource from the bus.
Definition: vbus:263
L4::Cap< Vbus > bus_cap() const
Access the Vbus capability of the underlying virtual bus.
Definition: vbus:83
The given DMA space is a kernel DMA space (L4::Task)
Definition: vbus.h:162
int pm_resume() const
Resume the module.
Definition: vbus:62
int vicu(L4::Cap< L4::Icu > icu) const
Request the L4::Icu capability for this Vbus ICU.
Definition: vbus:240