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 
146  int next_device(Device *child, int depth = L4VBUS_MAX_DEPTH,
147  l4vbus_device_t *devinfo = 0) const
148  {
149  child->_bus = _bus;
150  return l4vbus_get_next_device(_bus.cap(), _dev, &child->_dev, depth,
151  devinfo);
152  }
153 
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:
239  {
247  Src_dev_handle = L4VBUS_ICU_SRC_DEV_HANDLE
248  };
249 
253  int vicu(L4::Cap<L4::Icu> icu) const
254  {
255  return l4vbus_vicu_get_cap(_bus.cap(), _dev, icu.cap());
256  }
257 };
258 
266 class Vbus : public L4::Kobject_3t<Vbus, L4Re::Dataspace, L4Re::Inhibitor, L4Re::Event>
267 {
268 public:
269 
280  {
281  return l4vbus_request_ioport(cap(), res);
282  }
283 
295  int
296  L4_DEPRECATED("use L4Vbus::Vbus::request_ioport")
297  request_resource(l4vbus_resource_t *res, int /*flags*/ = 0) const
298  {
299  return l4vbus_request_ioport(cap(), res);
300  }
301 
310  {
311  return l4vbus_release_ioport(cap(), res);
312  }
313 
324  int
325  L4_DEPRECATED("use L4Vbus::Vbus::release_ioport")
326  release_resource(l4vbus_resource_t *res) const
327  {
328  return l4vbus_release_ioport(cap(), res);
329  }
330 
335  Device root() const
336  {
337  return Device(L4::Cap<Vbus>(cap()), L4VBUS_ROOT_BUS);
338  }
339 
356  int assign_dma_domain(unsigned domain_id, unsigned flags,
357  L4::Cap<L4Re::Dma_space> dma_space) const
358  {
361  return l4vbus_assign_dma_domain(cap(), domain_id, flags, dma_space.cap());
362  }
363 
381  int assign_dma_domain(unsigned domain_id, unsigned flags,
382  L4::Cap<L4::Task> dma_space) const
383  {
385  flags &= ~L4VBUS_DMAD_L4RE_DMA_SPACE;
386  return l4vbus_assign_dma_domain(cap(), domain_id, flags, dma_space.cap());
387  }
388 
390 };
391 
392 } // namespace L4vbus
Device root() const
Get the root device of the device tree of this bus.
Definition: vbus:335
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition: capability.h:52
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 hardware 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:936
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 release_ioport(l4vbus_resource_t *res) const
Release the given IO port resource from the bus.
Definition: vbus:309
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 hardware 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:146
Src_types
Flags that can be used with the ICU on a vbus device.
Definition: vbus:238
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:356
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:381
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
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
List of RPCs typically used for kernel interfaces.
Definition: __typeinfo.h:475
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.
int l4vbus_request_ioport(l4_cap_idx_t vbus, l4vbus_resource_t const *res)
Request an IO port resource.
Detailed information about a vbus device.
Definition: vbus_types.h:69
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_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 request_ioport(l4vbus_resource_t *res) const
Request the given IO port resource from the bus.
Definition: vbus:279
Vbus Interrupt controller API.
Definition: vbus:234
Dataspace interface.
Root device on the vbus.
Definition: vbus.h:24
The given DMA space is an L4Re::Dma_space.
Definition: vbus.h:190
C++ interface for capabilities.
Definition: capability.h:13
Flag to denote that the value should be interpreted as a device handle.
Definition: vbus.h:35
NULL device.
Definition: vbus.h:23
int l4vbus_release_ioport(l4_cap_idx_t vbus, l4vbus_resource_t const *res)
Release a previously requested IO port resource.
The virtual bus (Vbus) interface.
Definition: vbus:266
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:192
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:253
#define L4_DEPRECATED(s)
Mark symbol deprecated.
Definition: compiler.h:243