L4Re - L4 Runtime Environment
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vcpu.h
1 /*
2  * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>
3  * economic rights: Technische Universität Dresden (Germany)
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  *
9  * As a special exception, you may use this file as part of a free software
10  * library without restriction. Specifically, if other files instantiate
11  * templates or use macros or inline functions from this file, or you compile
12  * this file and link it with other files to produce an executable, this
13  * file does not by itself cause the resulting executable to be covered by
14  * the GNU General Public License. This exception does not however
15  * invalidate any other reasons why the executable file might be covered by
16  * the GNU General Public License.
17  */
18 #pragma once
19 
20 #include <l4/sys/vcpu.h>
21 #include <l4/sys/utcb.h>
22 
23 __BEGIN_DECLS
24 
44 typedef enum l4vcpu_irq_state_t
45 {
49 
50 typedef l4_umword_t l4vcpu_state_t;
51 typedef void (*l4vcpu_event_hndl_t)(l4_vcpu_state_t *vcpu);
52 typedef void (*l4vcpu_setup_ipc_t)(l4_utcb_t *utcb);
53 
60 L4_CV L4_INLINE
61 l4vcpu_state_t
63 
70 L4_CV L4_INLINE
71 void
73 
82 L4_CV L4_INLINE
85 
97 L4_CV L4_INLINE
98 void
100  l4vcpu_event_hndl_t do_event_work_cb,
101  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW;
102 
116 L4_CV L4_INLINE
117 void
119  l4_utcb_t *utcb,
120  l4vcpu_event_hndl_t do_event_work_cb,
121  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW;
122 
136 L4_CV L4_INLINE
137 void
138 l4vcpu_wait(l4_vcpu_state_t *vcpu, l4_utcb_t *utcb,
139  l4_timeout_t to,
140  l4vcpu_event_hndl_t do_event_work_cb,
141  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW;
142 
156 L4_CV L4_INLINE
157 void
159  l4vcpu_event_hndl_t do_event_work_cb,
160  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW;
161 
162 
170 L4_CV void
171 l4vcpu_print_state(l4_vcpu_state_t *vcpu, const char *prefix) L4_NOTHROW;
172 
176 L4_CV void
177 l4vcpu_print_state_arch(l4_vcpu_state_t *vcpu, const char *prefix) L4_NOTHROW;
178 
179 
188 L4_CV L4_INLINE
189 int
191 
200 L4_CV L4_INLINE
201 int
203 
215 L4_CV int
216 l4vcpu_ext_alloc(l4_vcpu_state_t **vcpu, l4_addr_t *ext_state,
217  l4_cap_idx_t task, l4_cap_idx_t regmgr) L4_NOTHROW;
218 
219 /* ===================================================================== */
220 /* Implementations */
221 
222 #include <l4/sys/ipc.h>
223 #include <l4/vcpu/vcpu_arch.h>
224 
225 L4_CV L4_INLINE
226 l4vcpu_state_t
228 {
229  return vcpu->state;
230 }
231 
232 L4_CV L4_INLINE
233 void
235 {
236  vcpu->state &= ~L4_VCPU_F_IRQ;
237  l4_barrier();
238 }
239 
240 L4_CV L4_INLINE
243 {
245  l4vcpu_irq_disable(vcpu);
246  return s;
247 }
248 
249 L4_CV L4_INLINE
250 void
251 l4vcpu_wait(l4_vcpu_state_t *vcpu, l4_utcb_t *utcb,
252  l4_timeout_t to,
253  l4vcpu_event_hndl_t do_event_work_cb,
254  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW
255 {
256  l4vcpu_irq_disable(vcpu);
257  setup_ipc(utcb);
258  vcpu->i.tag = l4_ipc_wait(utcb, &vcpu->i.label, to);
259  if (EXPECT_TRUE(!l4_msgtag_has_error(vcpu->i.tag)))
260  do_event_work_cb(vcpu);
261 }
262 
263 L4_CV L4_INLINE
264 void
266  l4vcpu_event_hndl_t do_event_work_cb,
267  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW
268 {
269  while (1)
270  {
271  vcpu->state |= L4_VCPU_F_IRQ;
272  l4_barrier();
273 
274  if (EXPECT_TRUE(!(vcpu->sticky_flags & L4_VCPU_SF_IRQ_PENDING)))
275  break;
276 
277  l4vcpu_wait(vcpu, utcb, L4_IPC_BOTH_TIMEOUT_0,
278  do_event_work_cb, setup_ipc);
279  }
280 }
281 
282 L4_CV L4_INLINE
283 void
285  l4_utcb_t *utcb,
286  l4vcpu_event_hndl_t do_event_work_cb,
287  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW
288 {
289  if (s & L4_VCPU_F_IRQ)
290  l4vcpu_irq_enable(vcpu, utcb, do_event_work_cb, setup_ipc);
291 }
292 
293 L4_CV L4_INLINE
294 void
296  l4vcpu_event_hndl_t do_event_work_cb,
297  l4vcpu_setup_ipc_t setup_ipc) L4_NOTHROW
298 {
299  l4vcpu_wait(vcpu, utcb, L4_IPC_NEVER, do_event_work_cb, setup_ipc);
300 }
301 
L4Re - L4 Runtime Environment