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 
42 namespace L4vbus {
43 
44 class Vbus;
45 
50 template<typename DEC>
51 class Pm
52 {
53 private:
54  DEC const *self() const { return static_cast<DEC const *>(this); }
55  DEC *self() { return static_cast<DEC *>(this); }
56 public:
60  int pm_suspend() const
61  { return l4vbus_pm_suspend(self()->bus_cap().cap(), self()->dev_handle()); }
62 
66  int pm_resume() const
67  { return l4vbus_pm_resume(self()->bus_cap().cap(), self()->dev_handle()); }
68 };
69 
70 
75 class Device : public Pm<Device>
76 {
77 public:
78  Device() : _dev(L4VBUS_NULL) {}
79 
80  Device(L4::Cap<Vbus> bus, l4vbus_device_handle_t dev)
81  : _bus(bus), _dev(dev) {}
82 
87  L4::Cap<Vbus> bus_cap() const { return _bus; }
88 
96  l4vbus_device_handle_t dev_handle() const { return _dev; }
97 
98 
128  int device_by_hid(Device *child, char const *hid,
129  int depth = L4VBUS_MAX_DEPTH,
130  l4vbus_device_t *devinfo = 0) const
131  {
132  child->_bus = _bus;
133  return l4vbus_get_device_by_hid(_bus.cap(), _dev, &child->_dev, hid,
134  depth, devinfo);
135  }
136 
150  int next_device(Device *child, int depth = L4VBUS_MAX_DEPTH,
151  l4vbus_device_t *devinfo = 0) const
152  {
153  child->_bus = _bus;
154  return l4vbus_get_next_device(_bus.cap(), _dev, &child->_dev, depth,
155  devinfo);
156  }
157 
168  int device(l4vbus_device_t *devinfo) const
169  { return l4vbus_get_device(_bus.cap(), _dev, devinfo); }
170 
188  int get_resource(int res_idx, l4vbus_resource_t *res) const
189  {
190  return l4vbus_get_resource(_bus.cap(), _dev, res_idx, res);
191  }
192 
202  int is_compatible(char const *cid) const
203  { return l4vbus_is_compatible(_bus.cap(), _dev, cid); }
204 
209  bool operator == (Device const &o) const
210  {
211  return _bus == o._bus && _dev == o._dev;
212  }
213 
218  bool operator != (Device const &o) const
219  {
220  return _bus != o._bus || _dev != o._dev;
221  }
222 
223 protected:
226  l4vbus_device_handle_t _dev;
227 };
228 
238 class Icu : public Device
239 {
240 public:
243  {
252  };
253 
257  int vicu(L4::Cap<L4::Icu> icu) const
258  {
259  return l4vbus_vicu_get_cap(_bus.cap(), _dev, icu.cap());
260  }
261 };
262 
270 class Vbus : public L4::Kobject_3t<Vbus, L4Re::Dataspace, L4Re::Inhibitor, L4Re::Event>
271 {
272 public:
273 
284  {
285  return l4vbus_request_ioport(cap(), res);
286  }
287 
299  int
300  L4_DEPRECATED("use L4Vbus::Vbus::request_ioport")
301  request_resource(l4vbus_resource_t *res, int /*flags*/ = 0) const
302  {
303  return l4vbus_request_ioport(cap(), res);
304  }
305 
314  {
315  return l4vbus_release_ioport(cap(), res);
316  }
317 
328  int
329  L4_DEPRECATED("use L4Vbus::Vbus::release_ioport")
331  {
332  return l4vbus_release_ioport(cap(), res);
333  }
334 
339  Device root() const
340  {
341  return Device(L4::Cap<Vbus>(cap()), L4VBUS_ROOT_BUS);
342  }
343 
360  int assign_dma_domain(unsigned domain_id, unsigned flags,
361  L4::Cap<L4Re::Dma_space> dma_space) const
362  {
365  return l4vbus_assign_dma_domain(cap(), domain_id, flags, dma_space.cap());
366  }
367 
385  int assign_dma_domain(unsigned domain_id, unsigned flags,
386  L4::Cap<L4::Task> dma_space) const
387  {
390  return l4vbus_assign_dma_domain(cap(), domain_id, flags, dma_space.cap());
391  }
392 
393  typedef L4::Typeid::Raw_ipc<Vbus> Rpcs;
394 };
395 
396 } // namespace L4vbus
Flags flags() const noexcept
Get flags of the dataspace.
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition: capability.h:52
C++ interface for capabilities.
Definition: capability.h:219
Device on a L4vbus::Vbus.
Definition: vbus:76
int device(l4vbus_device_t *devinfo) const
Obtain detailed information about a Vbus device.
Definition: vbus:168
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:128
l4vbus_device_handle_t dev_handle() const
Access the device handle of this device.
Definition: vbus:96
bool operator==(Device const &o) const
Test if two devices are the same Vbus device.
Definition: vbus:209
int get_resource(int res_idx, l4vbus_resource_t *res) const
Obtain the resource description of an individual device resource.
Definition: vbus:188
L4::Cap< Vbus > bus_cap() const
Access the Vbus capability of the underlying virtual bus.
Definition: vbus:87
bool operator!=(Device const &o) const
Test if two devices are not the same.
Definition: vbus:218
int next_device(Device *child, int depth=L4VBUS_MAX_DEPTH, l4vbus_device_t *devinfo=0) const
Find next child following child.
Definition: vbus:150
l4vbus_device_handle_t _dev
The device handle for this device.
Definition: vbus:226
L4::Cap< Vbus > _bus
Definition: vbus:224
int is_compatible(char const *cid) const
Check if the given device has a compatibility ID (CID) or HID that matches cid.
Definition: vbus:202
Vbus Interrupt controller API.
Definition: vbus:239
Src_types
Flags that can be used with the ICU on a vbus device.
Definition: vbus:243
@ Src_dev_handle
Flag to denote that the value should be interpreted as a device handle.
Definition: vbus:251
int vicu(L4::Cap< L4::Icu > icu) const
Request the L4::Icu capability for this Vbus ICU.
Definition: vbus:257
Power-management API mixin.
Definition: vbus:52
int pm_suspend() const
Suspend the module.
Definition: vbus:60
int pm_resume() const
Resume the module.
Definition: vbus:66
The virtual bus (Vbus) interface.
Definition: vbus:271
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:360
Device root() const
Get the root device of the device tree of this bus.
Definition: vbus:339
int request_ioport(l4vbus_resource_t *res) const
Request the given IO port resource from the bus.
Definition: vbus:283
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:385
int release_ioport(l4vbus_resource_t *res) const
Release the given IO port resource from the bus.
Definition: vbus:313
int release_resource(l4vbus_resource_t *res) const
Release the given resource from the bus.
Definition: vbus:330
int request_resource(l4vbus_resource_t *res, int=0) const
Request the given resource from the bus.
Definition: vbus:301
#define L4_DEPRECATED(s)
Mark symbol deprecated.
Definition: compiler.h:243
Dataspace interface.
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 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.
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.
int l4vbus_request_ioport(l4_cap_idx_t vbus, l4vbus_resource_t const *res)
Request an IO port resource.
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.
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 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_vicu_get_cap(l4_cap_idx_t vbus, l4vbus_device_handle_t icu, l4_cap_idx_t cap)
Get capability of ICU.
int l4vbus_release_ioport(l4_cap_idx_t vbus, l4vbus_resource_t const *res)
Release a previously requested IO port resource.
@ L4VBUS_DMAD_L4RE_DMA_SPACE
The given DMA space is an L4Re::Dma_space.
Definition: vbus.h:190
@ L4VBUS_DMAD_KERNEL_DMA_SPACE
The given DMA space is a kernel DMA space (L4::Task)
Definition: vbus.h:192
Interrupt controller.
C++ interface of the Vbus API.
Definition: vbus:42
Helper class to create an L4Re interface class that is derived from three base classes (see L4::Kobje...
Definition: __typeinfo.h:937
RPCs list for passing raw incoming IPC to the server object.
Definition: __typeinfo.h:423
Detailed information about a vbus device.
Definition: vbus_types.h:69
Description of a single vbus resource.
Definition: vbus_types.h:23
Description of the vbus C API.
@ L4VBUS_NULL
NULL device.
Definition: vbus.h:23
@ L4VBUS_ROOT_BUS
Root device on the vbus.
Definition: vbus.h:24
@ L4VBUS_ICU_SRC_DEV_HANDLE
Flag to denote that the value should be interpreted as a device handle.
Definition: vbus.h:35