3 * \brief Common IPC interface.
7 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8 * Alexander Warg <warg@os.inf.tu-dresden.de>,
9 * Björn Döbel <doebel@os.inf.tu-dresden.de>,
10 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
11 * economic rights: Technische Universität Dresden (Germany)
13 * This file is part of TUD:OS and distributed under the terms of the
14 * GNU General Public License 2.
15 * Please see the COPYING-GPL-2 file for details.
17 * As a special exception, you may use this file as part of a free software
18 * library without restriction. Specifically, if other files instantiate
19 * templates or use macros or inline functions from this file, or you compile
20 * this file and link it with other files to produce an executable, this
21 * file does not by itself cause the resulting executable to be covered by
22 * the GNU General Public License. This exception does not however
23 * invalidate any other reasons why the executable file might be covered by
24 * the GNU General Public License.
26 #ifndef __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__
27 #define __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__
29 #include <l4/sys/types.h>
30 #include <l4/sys/utcb.h>
31 #include <l4/sys/err.h>
34 * \defgroup l4_ipc_api Object Invocation
36 * \brief API for L4 object invocation.
38 * <c>\#include <l4/sys/ipc.h></c>
40 * General abstractions for L4 object invocation. The basic principle is that
41 * all objects are denoted by a capability that is accessed via a capability
42 * selector (see \link l4_cap_api Capabilities \endlink).
44 * This set of functions is common to all kinds of objects provided by the
45 * L4 micro kernel. The concrete semantics of an invocation depends on the
46 * object that shall be invoked.
48 * Objects may be invoked in various ways, the most common way is to use
49 * a \em call operation (l4_ipc_call()). However, there are a lot more
50 * flavours available that have a semantics depending on the object.
52 * \see \ref l4_kernel_object_gate_api
56 /*****************************************************************************
57 *** IPC result checking
58 *****************************************************************************/
61 * \defgroup l4_ipc_err_api Error Handling
63 * \brief Error handling for L4 object invocation.
65 * <c>\#include <l4/sys/ipc.h></c>
69 * \brief Error codes in the \em error TCR.
70 * \ingroup l4_ipc_err_api
72 * The error codes are accessible via the \em error TCR, see
73 * #l4_thread_regs_t.error.
75 enum l4_ipc_tcr_error_t
77 L4_IPC_ERROR_MASK = 0x1F, /**< Mask for error bits. */
78 L4_IPC_SND_ERR_MASK = 0x01, /**< Send error mask. */
80 L4_IPC_ENOT_EXISTENT = 0x04, /**< Non-existing destination or source.
81 ** \ingroup l4_ipc_api
83 L4_IPC_RETIMEOUT = 0x03, /**< Timeout during receive operation.
84 ** \ingroup l4_ipc_api
86 L4_IPC_SETIMEOUT = 0x02, /**< Timeout during send operation.
87 ** \ingroup l4_ipc_api
89 L4_IPC_RECANCELED = 0x07, /**< Receive operation canceled.
90 ** \ingroup l4_ipc_api
92 L4_IPC_SECANCELED = 0x06, /**< Send operation canceled.
93 ** \ingroup l4_ipc_api
95 L4_IPC_REMAPFAILED = 0x11, /**< Map flexpage failed in receive
97 ** \ingroup l4_ipc_api
99 L4_IPC_SEMAPFAILED = 0x10, /**< Map flexpage failed in send operation.
100 ** \ingroup l4_ipc_api
102 L4_IPC_RESNDPFTO = 0x0b, /**< Send-pagefault timeout in receive
104 ** \ingroup l4_ipc_api
106 L4_IPC_SESNDPFTO = 0x0a, /**< Send-pagefault timeout in send
108 ** \ingroup l4_ipc_api
110 L4_IPC_RERCVPFTO = 0x0d, /**< Receive-pagefault timeout in receive
112 ** \ingroup l4_ipc_api
114 L4_IPC_SERCVPFTO = 0x0c, /**< Receive-pagefault timeout in send
116 ** \ingroup l4_ipc_api
118 L4_IPC_REABORTED = 0x0f, /**< Receive operation aborted.
119 ** \ingroup l4_ipc_api
121 L4_IPC_SEABORTED = 0x0e, /**< Send operation aborted.
122 ** \ingroup l4_ipc_api
124 L4_IPC_REMSGCUT = 0x09, /**< Cut receive message, due to
125 ** message buffer is too small.
126 ** \ingroup l4_ipc_api
128 L4_IPC_SEMSGCUT = 0x08, /**< Cut send message. due to
129 ** message buffer is too small,
130 ** \ingroup l4_ipc_api
136 * \brief Get the error code for an object invocation.
137 * \ingroup l4_ipc_err_api
139 * \param tag Return value of the invocation.
140 * \param utcb UTCB that was used for the invocation.
142 * \return 0 if no error condition is set,
143 * error code otherwise (see #l4_ipc_tcr_error_t).
145 L4_INLINE l4_umword_t
146 l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW;
150 * \brief Return error code of a system call return message tag.
151 * \ingroup l4_ipc_err_api
152 * \param tag System call return message type
153 * \return 0 for no error, error number in case of error
156 l4_error(l4_msgtag_t tag) L4_NOTHROW;
159 l4_error_u(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW;
161 /*****************************************************************************
163 *****************************************************************************/
166 * \brief Returns whether an error occurred in send phase of an invocation.
167 * \ingroup l4_ipc_err_api
169 * \pre l4_msgtag_has_error(tag) == true
170 * \param utcb UTCB to check.
172 * \return Boolean value.
174 L4_INLINE int l4_ipc_is_snd_error(l4_utcb_t *utcb) L4_NOTHROW;
177 * \brief Returns whether an error occurred in receive phase of an invocation.
178 * \ingroup l4_ipc_err_api
180 * \pre l4_msgtag_has_error(tag) == true
181 * \param utcb UTCB to check.
183 * \return Boolean value.
185 L4_INLINE int l4_ipc_is_rcv_error(l4_utcb_t *utcb) L4_NOTHROW;
188 * \brief Get the error condition of the last invocation from the TCR.
189 * \ingroup l4_ipc_err_api
191 * \pre l4_msgtag_has_error(tag) == true
192 * \param utcb UTCB to check.
194 * \return Error condition of type l4_ipc_tcr_error_t.
196 L4_INLINE int l4_ipc_error_code(l4_utcb_t *utcb) L4_NOTHROW;
199 /*****************************************************************************
201 *****************************************************************************/
204 * \brief Send a message to an object (do \b not wait for a reply).
205 * \ingroup l4_ipc_api
207 * \param dest Capability selector for the destination object.
208 * \param utcb UTCB of the caller.
209 * \param tag Descriptor for the message to be sent.
210 * \param timeout Timeout pair (see #l4_timeout_t) only send part is relevant.
214 * A message is sent to the destination object. There is no receive phase
215 * included. The invoker continues working after sending the message.
217 * \attention This is a special-purpose message transfer, objects usually
218 * support only invocation via l4_ipc_call().
220 L4_INLINE l4_msgtag_t
221 l4_ipc_send(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag,
222 l4_timeout_t timeout) L4_NOTHROW;
226 * \brief Wait for an incoming message from any possible sender.
227 * \ingroup l4_ipc_api
229 * \param utcb UTCB of the caller.
230 * \retval label Label assigned to the source object (IPC gate or IRQ).
231 * \param timeout Timeout pair (see #l4_timeout_t, only the receive part is
236 * This operation does an open wait, and therefore needs no capability to
237 * denote the possible source of a message. This means the calling thread
238 * waits for an incoming message from any possible source.
239 * There is no send phase included in this operation.
241 * The usual usage of this function is to call that function when entering a
242 * server loop in a user-level server that implements user-level objects,
243 * see also #l4_ipc_reply_and_wait().
245 L4_INLINE l4_msgtag_t
246 l4_ipc_wait(l4_utcb_t *utcb, l4_umword_t *label,
247 l4_timeout_t timeout) L4_NOTHROW;
251 * \brief Wait for a message from a specific source.
252 * \ingroup l4_ipc_api
254 * \param object Object to receive a message from.
255 * \param timeout Timeout pair (see #l4_timeout_t, only the receive part
257 * \param utcb UTCB of the caller.
259 * \return result tag.
261 * This operation waits for a message from the specified object. Messages from
262 * other sources are not accepted by this operation. The operation does not
263 * include a send phase, this means no message is sent to the object.
265 * \note This operation is usually used to receive messages from a specific IRQ
266 * or thread. However, it is not common to use this operation for normal
269 L4_INLINE l4_msgtag_t
270 l4_ipc_receive(l4_cap_idx_t object, l4_utcb_t *utcb,
271 l4_timeout_t timeout) L4_NOTHROW;
274 * \brief Object call (usual invocation).
275 * \ingroup l4_ipc_api
277 * \param object Capability selector for the object to call.
278 * \param utcb UTCB of the caller.
279 * \param tag Message tag to describe the message to be sent.
280 * \param timeout Timeout pair for send an receive phase (see #l4_timeout_t).
284 * A message is sent to the object and the invoker waits for a
285 * reply from the object. Messages from other sources are not accepted.
286 * \note The send-to-receive transition needs no time, the object can reply
287 * with a send timeout of zero.
289 L4_INLINE l4_msgtag_t
290 l4_ipc_call(l4_cap_idx_t object, l4_utcb_t *utcb, l4_msgtag_t tag,
291 l4_timeout_t timeout) L4_NOTHROW;
295 * \brief Reply and wait operation (uses the \em reply capability).
296 * \ingroup l4_ipc_api
298 * \param tag Describes the message to be sent as reply.
299 * \param utcb UTCB of the caller.
300 * \retval label Label assigned to the source object of the received message.
301 * \param timeout Timeout pair (see #l4_timeout_t).
304 * A message is sent to the previous caller using the implicit reply
305 * capability. Afterwards the invoking thread waits for a message from any
307 * \note This is the standard server operation: it sends a reply to the actual
308 * client and waits for the next incoming request, which may come from
311 L4_INLINE l4_msgtag_t
312 l4_ipc_reply_and_wait(l4_utcb_t *utcb, l4_msgtag_t tag,
313 l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW;
316 * \brief Send a message and do an open wait.
317 * \ingroup l4_ipc_api
319 * \param dest Object to send a message to.
320 * \param utcb UTCB of the caller.
321 * \param tag Describes the message that shall be sent.
322 * \retval label Label assigned to the source object of the receive phase.
323 * \param timeout Timeout pair (see #l4_timeout_t).
326 * A message is sent to the destination object and the invoking thread waits
327 * for a reply from any source.
329 * \note This is a special-purpose operation and shall not be used in general
332 L4_INLINE l4_msgtag_t
333 l4_ipc_send_and_wait(l4_cap_idx_t dest, l4_utcb_t *utcb, l4_msgtag_t tag,
334 l4_umword_t *label, l4_timeout_t timeout) L4_NOTHROW;
337 * \defgroup l4_ipc_rt_api Realtime API
338 * \ingroup l4_ipc_api
344 * Wait for next period.
345 * \ingroup l4_ipc_rt_api
347 * \param utcb UTCB of the caller.
349 * \param timeout IPC timeout (see #l4_ipc_timeout).
353 L4_INLINE l4_msgtag_t
354 l4_ipc_wait_next_period(l4_utcb_t *utcb,
356 l4_timeout_t timeout);
361 * \brief Generic L4 object invocation.
362 * \ingroup l4_ipc_api
364 * \param dest Destination object.
365 * \param utcb UTCB of the caller.
366 * \param flags Invocation flags (see #l4_syscall_flags_t).
367 * \param slabel Send label if applicable (may be seen by the receiver).
368 * \param tag Sending message tag.
369 * \retval rlabel Receiving label.
370 * \param timeout Timeout pair (see #l4_timeout_t).
374 L4_INLINE l4_msgtag_t
375 l4_ipc(l4_cap_idx_t dest,
381 l4_timeout_t timeout) L4_NOTHROW;
384 * \brief Sleep for an amount of time.
385 * \ingroup l4_ipc_api
387 * \param timeout Timeout pair (see #l4_timeout_t, the receive part matters).
389 * \return error code:
390 * - #L4_IPC_RETIMEOUT: success
391 * - #L4_IPC_RECANCELED woken up by a different thread
392 * (l4_thread_ex_regs()).
394 * The invoking thread waits until the timeout
395 * is expired or the wait was aborted by another thread by l4_thread_ex_regs().
397 L4_INLINE l4_msgtag_t
398 l4_ipc_sleep(l4_timeout_t timeout) L4_NOTHROW;
401 * \brief Add a flex-page to be sent to the UTCB
402 * \ingroup l4_ipc_api
404 * \param snd_fpage Flex-page.
405 * \param snd_base Send base.
406 * \param tag Tag to be modified.
407 * \retval tag Modified tag, the number of items will be increased,
408 * all other values in the tag will be retained.
410 * \return 0 on success, negative error code otherwise
413 l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
414 l4_msgtag_t *tag) L4_NOTHROW;
418 * \ingroup l4_ipc_api
421 l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
422 l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW;
425 /************************************************************************
427 **********************/
429 L4_INLINE l4_umword_t
430 l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
432 if (!l4_msgtag_has_error(tag))
434 return l4_utcb_tcr_u(utcb)->error & L4_IPC_ERROR_MASK;
438 l4_error_u(l4_msgtag_t tag, l4_utcb_t *u) L4_NOTHROW
440 if (l4_msgtag_has_error(tag))
441 return -(L4_EIPC_LO + (l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK));
443 return l4_msgtag_label(tag);
447 l4_error(l4_msgtag_t tag) L4_NOTHROW
449 return l4_error_u(tag, l4_utcb());
453 L4_INLINE int l4_ipc_is_snd_error(l4_utcb_t *u) L4_NOTHROW
454 { return !(l4_utcb_tcr_u(u)->error & 1) == 0; }
456 L4_INLINE int l4_ipc_is_rcv_error(l4_utcb_t *u) L4_NOTHROW
457 { return l4_utcb_tcr_u(u)->error & 1; }
459 L4_INLINE int l4_ipc_error_code(l4_utcb_t *u) L4_NOTHROW
460 { return l4_utcb_tcr_u(u)->error & L4_IPC_ERROR_MASK; }
465 * \ingroup l4_ipc_api
468 l4_sndfpage_add_u(l4_fpage_t const snd_fpage, unsigned long snd_base,
469 l4_msgtag_t *tag, l4_utcb_t *utcb) L4_NOTHROW
471 l4_msg_regs_t *v = l4_utcb_mr_u(utcb);
472 int i = l4_msgtag_words(*tag) + 2 * l4_msgtag_items(*tag);
474 if (i >= L4_UTCB_GENERIC_DATA_SIZE - 1)
477 v->mr[i] = snd_base | L4_ITEM_MAP | L4_ITEM_CONT;
478 v->mr[i + 1] = snd_fpage.raw;
480 *tag = l4_msgtag(l4_msgtag_label(*tag), l4_msgtag_words(*tag),
481 l4_msgtag_items(*tag) + 1, l4_msgtag_flags(*tag));
486 l4_sndfpage_add(l4_fpage_t const snd_fpage, unsigned long snd_base,
487 l4_msgtag_t *tag) L4_NOTHROW
489 return l4_sndfpage_add_u(snd_fpage, snd_base, tag, l4_utcb());
493 #endif /* ! __L4SYS__INCLUDE__L4API_FIASCO__IPC_H__ */