L4Re - L4 Runtime Environment
event
Go to the documentation of this file.
1 // vi:set ft=cpp: -*- Mode: C++ -*-
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  * Alexander Warg <warg@os.inf.tu-dresden.de>
8  * economic rights: Technische Universit├Ąt Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction. Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License. This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #pragma once
24 
25 #include <l4/re/cap_alloc>
26 #include <l4/re/util/cap_alloc>
27 #include <l4/re/util/unique_cap>
28 #include <l4/re/env>
29 #include <l4/re/rm>
30 #include <l4/re/util/event_buffer>
31 #include <l4/sys/factory>
32 #include <l4/cxx/type_traits>
33 
34 namespace L4Re { namespace Util {
35 
42 template< typename PAYLOAD >
43 class Event_t
44 {
45 public:
49  enum Mode
50  {
53  };
54 
69  template<typename IRQ_TYPE>
71  L4Re::Env const *env = L4Re::Env::env(),
73  {
74  Unique_cap<L4Re::Dataspace> ev_ds(ca->alloc<L4Re::Dataspace>());
75  if (!ev_ds.is_valid())
76  return -L4_ENOMEM;
77 
78  int r;
79 
80  Unique_del_cap<IRQ_TYPE> ev_irq(ca->alloc<IRQ_TYPE>());
81  if (!ev_irq.is_valid())
82  return -L4_ENOMEM;
83 
84  if ((r = l4_error(env->factory()->create(ev_irq.get()))))
85  return r;
86 
87  if ((r = l4_error(event->bind(0, ev_irq.get()))))
88  return r;
89 
90  if ((r = event->get_buffer(ev_ds.get())))
91  return r;
92 
93  long sz = ev_ds->size();
94  if (sz < 0)
95  return sz;
96 
97  Rm::Unique_region<void*> buf;
98 
99  if ((r = env->rm()->attach(&buf, sz,
100  L4Re::Rm::F::Search_addr | L4Re::Rm::F::RW,
101  L4::Ipc::make_cap_rw(ev_ds.get()))))
102  return r;
103 
104  _ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
105  _ev_ds = cxx::move(ev_ds);
106  _ev_irq = cxx::move(ev_irq);
107  _buf = cxx::move(buf);
108 
109  return 0;
110  }
111 
124  L4Re::Env const *env = L4Re::Env::env(),
126  {
127  Unique_cap<L4Re::Dataspace> ev_ds(ca->alloc<L4Re::Dataspace>());
128  if (!ev_ds.is_valid())
129  return -L4_ENOMEM;
130 
131  int r;
132 
133  if ((r = event->get_buffer(ev_ds.get())))
134  return r;
135 
136  long sz = ev_ds->size();
137  if (sz < 0)
138  return sz;
139 
140  Rm::Unique_region<void*> buf;
141 
142  if ((r = env->rm()->attach(&buf, sz,
143  L4Re::Rm::F::Search_addr | L4Re::Rm::F::RW,
144  L4::Ipc::make_cap_rw(ev_ds.get()))))
145  return r;
146 
147  _ev_buffer = L4Re::Event_buffer_t<PAYLOAD>(buf.get(), sz);
148  _ev_ds = cxx::move(ev_ds);
149  _buf = cxx::move(buf);
150 
151  return 0;
152  }
153 
159  L4Re::Event_buffer_t<PAYLOAD> &buffer() { return _ev_buffer; }
160 
166  L4::Cap<L4::Triggerable> irq() const { return _ev_irq.get(); }
167 
168 private:
172  Rm::Unique_region<void*> _buf;
173 };
174 
176 
177 }}
Unique_cap / Unique_del_cap.
Create an IRQ and attach, to get notifications.
Definition: event:51
Abstract capability-allocator interface.
L4Re::Event_buffer_t< PAYLOAD > & buffer()
Get event buffer.
Definition: event:159
Capability allocator interface.
Definition: cap_alloc:41
Event buffer class.
Definition: event:198
Mode
Modes of operation.
Definition: event:49
int init(L4::Cap< L4Re::Event > event, L4Re::Env const *env=L4Re::Env::env(), L4Re::Cap_alloc *ca=L4Re::Cap_alloc::get_cap_alloc(L4Re::Util::cap_alloc))
Initialise an event object.
Definition: event:70
C++ interface of the initial environment that is provided to an L4 task.
Definition: env:85
static L4Re::Cap_alloc * get_cap_alloc(CAP_ALLOC &ca)
Construct an instance of a capability allocator.
Definition: cap_alloc:90
l4_msgtag_t bind(unsigned irqnum, L4::Cap< Triggerable > irq, l4_utcb_t *utcb=l4_utcb()) noexcept
Bind an interrupt line of an interrupt controller to an interrupt object.
Definition: irq:312
L4Re C++ Interfaces.
Definition: cmd_control:15
L4::Detail::Unique_cap_impl< T, Smart_cap_auto< L4_FP_DELETE_OBJ > > Unique_del_cap
Unique capability that implements automatic free and unmap+delete of the capability selector...
Definition: unique_cap:97
Environment interface.
L4::Cap< L4::Triggerable > irq() const
Get event IRQ.
Definition: event:166
Interface for memory-like objects.
Definition: dataspace:60
L4::Detail::Unique_cap_impl< T, Smart_cap_auto< L4_FP_ALL_SPACES > > Unique_cap
Unique capability that implements automatic free and unmap of the capability selector.
Definition: unique_cap:54
Region mapper interface.
long get_buffer(L4::Ipc::Out< L4::Cap< Dataspace > > ds)
Get event signal buffer.
_Cap_alloc & cap_alloc
Capability allocator.
int init_poll(L4::Cap< L4Re::Event > event, L4Re::Env const *env=L4Re::Env::env(), L4Re::Cap_alloc *ca=L4Re::Cap_alloc::get_cap_alloc(L4Re::Util::cap_alloc))
Initialise an event object in polling mode.
Definition: event:123
No memory.
Definition: err.h:50
Do not use an IRQ.
Definition: event:52
long l4_error(l4_msgtag_t tag) L4_NOTHROW
Return error code of a system call return message tag or the tag label.
Definition: ipc.h:520
Common factory related definitions.
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition: env:103
Capability allocator.
Convenience wrapper for getting access to an event object.
Definition: event:43
C++ interface for capabilities.
Definition: capability.h:13
Search for a suitable address range.
Definition: rm:105
Cap< T > make_cap_rw(L4::Cap< T > cap) noexcept
Make an L4::Ipc::Cap<T> for the given capability with L4_CAP_FPAGE_RW rights.
Definition: ipc_types:634