]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/l4sys/include/ipc_gate.h
update
[l4.git] / l4 / pkg / l4sys / include / ipc_gate.h
1 /**
2  * \file
3  * \brief IPC-Gate interface.
4  */
5 /*
6  * (c) 2009-2010 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/sys/utcb.h>
26 #include <l4/sys/types.h>
27
28 /**
29  * \brief Bind the IPC-gate to the thread.
30  * \ingroup l4_kernel_object_gate_api
31  *
32  * \param t     Thread to bind the IPC-gate to
33  * \param label Label to use
34  * \param utcb  UTCB to use.
35  *
36  * \return System call return tag.
37  */
38 L4_INLINE l4_msgtag_t
39 l4_ipc_gate_bind_thread(l4_cap_idx_t gate, l4_cap_idx_t thread,
40                         l4_umword_t label);
41
42 /**
43  * \internal
44  * \ingroup l4_kernel_object_gate_api
45  */
46 L4_INLINE l4_msgtag_t
47 l4_ipc_gate_bind_thread_u(l4_cap_idx_t gate, l4_cap_idx_t thread,
48                           l4_umword_t label, l4_utcb_t *utcb);
49
50 /**
51  * \brief Get information on the IPC-gate.
52  * \ingroup l4_kernel_object_gate_api
53  *
54  * \retval label   Label of the gate.
55  * \param  utcb    UTCb to use.
56  *
57  * \return System call return tag.
58  */
59 L4_INLINE l4_msgtag_t
60 l4_ipc_gate_get_infos(l4_cap_idx_t gate, l4_umword_t *label);
61
62 /**
63  * \internal
64  * \ingroup l4_kernel_object_gate_api
65  */
66 L4_INLINE l4_msgtag_t
67 l4_ipc_gate_get_infos_u(l4_cap_idx_t gate, l4_umword_t *label, l4_utcb_t *utcb);
68
69 /**
70  * \brief Operations on the IPC-gate.
71  * \ingroup l4_kernel_object_gate_api
72  * \hideinitializer
73  * \internal
74  */
75 enum L4_ipc_gate_ops
76 {
77   L4_IPC_GATE_OP_BIND     = 0x10, /**< Bind operation */
78   L4_IPC_GATE_OP_GET_INFO = 0x11, /**< Info operation */
79 };
80
81
82 /* IMPLEMENTATION -----------------------------------------------------------*/
83
84 #include <l4/sys/ipc.h>
85
86 L4_INLINE l4_msgtag_t
87 l4_ipc_gate_bind_thread_u(l4_cap_idx_t gate,
88                           l4_cap_idx_t thread, l4_umword_t label,
89                           l4_utcb_t *utcb)
90 {
91   l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
92   m->mr[0] = L4_IPC_GATE_OP_BIND;
93   m->mr[1] = label;
94   m->mr[2] = l4_map_obj_control(0, 0);
95   m->mr[3] = l4_obj_fpage(thread, 0, L4_FPAGE_RWX).raw;
96   return l4_ipc_call(gate, utcb, l4_msgtag(L4_PROTO_KOBJECT, 2, 1, 0),
97                      L4_IPC_NEVER);
98 }
99
100 L4_INLINE l4_msgtag_t
101 l4_ipc_gate_get_infos_u(l4_cap_idx_t gate, l4_umword_t *label, l4_utcb_t *utcb)
102 {
103   l4_msgtag_t tag;
104   l4_msg_regs_t *m = l4_utcb_mr_u(utcb);
105   m->mr[0] = L4_IPC_GATE_OP_GET_INFO;
106   tag = l4_ipc_call(gate, utcb, l4_msgtag(L4_PROTO_KOBJECT, 1, 0, 0),
107                     L4_IPC_NEVER);
108   if (!l4_msgtag_has_error(tag) && l4_msgtag_label(tag) >= 0)
109     *label = m->mr[0];
110
111   return tag;
112 }
113
114
115
116 L4_INLINE l4_msgtag_t
117 l4_ipc_gate_bind_thread(l4_cap_idx_t gate, l4_cap_idx_t thread,
118                         l4_umword_t label)
119 {
120   return l4_ipc_gate_bind_thread_u(gate, thread, label, l4_utcb());
121 }
122
123 L4_INLINE l4_msgtag_t
124 l4_ipc_gate_get_infos(l4_cap_idx_t gate, l4_umword_t *label)
125 {
126   return l4_ipc_gate_get_infos_u(gate, label, l4_utcb());
127 }