source: mainline/uspace/lib/c/generic/ipc.c@ 28a5ebd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 28a5ebd was fafb8e5, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Mechanically lowercase IPC_SET_*/IPC_GET_*

  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 * Copyright (c) 2006 Ondrej Palkovsky
3 * Copyright (c) 2017 Jakub Jermar
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libc
31 * @{
32 * @}
33 */
34
35/** @addtogroup libcipc IPC
36 * @brief HelenOS uspace IPC
37 * @{
38 * @ingroup libc
39 */
40/** @file
41 */
42
43#include <ipc/ipc.h>
44#include <libc.h>
45#include <stdlib.h>
46#include <errno.h>
47#include <adt/list.h>
48#include <fibril.h>
49#include <macros.h>
50
51/** Fast asynchronous call.
52 *
53 * This function can only handle three arguments of payload. It is, however,
54 * faster than the more generic ipc_call_async_slow().
55 *
56 * Note that this function is a void function.
57 *
58 * During normal operation, answering this call will trigger the callback.
59 * In case of fatal error, the callback handler is called with the proper
60 * error code. If the call cannot be temporarily made, it is queued.
61 *
62 * @param phandle Phone handle for the call.
63 * @param imethod Requested interface and method.
64 * @param arg1 Service-defined payload argument.
65 * @param arg2 Service-defined payload argument.
66 * @param arg3 Service-defined payload argument.
67 * @param label A value to set to the label field of the answer.
68 */
69errno_t ipc_call_async_fast(cap_phone_handle_t phandle, sysarg_t imethod,
70 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, void *label)
71{
72 return __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST,
73 cap_handle_raw(phandle), imethod, arg1, arg2, arg3,
74 (sysarg_t) label);
75}
76
77/** Asynchronous call transmitting the entire payload.
78 *
79 * Note that this function is a void function.
80 *
81 * During normal operation, answering this call will trigger the callback.
82 * In case of fatal error, the callback handler is called with the proper
83 * error code. If the call cannot be temporarily made, it is queued.
84 *
85 * @param phandle Phone handle for the call.
86 * @param imethod Requested interface and method.
87 * @param arg1 Service-defined payload argument.
88 * @param arg2 Service-defined payload argument.
89 * @param arg3 Service-defined payload argument.
90 * @param arg4 Service-defined payload argument.
91 * @param arg5 Service-defined payload argument.
92 * @param label A value to set to the label field of the answer.
93 */
94errno_t ipc_call_async_slow(cap_phone_handle_t phandle, sysarg_t imethod,
95 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
96 void *label)
97{
98 ipc_call_t data;
99
100 ipc_set_imethod(&data, imethod);
101 ipc_set_arg1(&data, arg1);
102 ipc_set_arg2(&data, arg2);
103 ipc_set_arg3(&data, arg3);
104 ipc_set_arg4(&data, arg4);
105 ipc_set_arg5(&data, arg5);
106
107 return __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW,
108 cap_handle_raw(phandle), (sysarg_t) &data,
109 (sysarg_t) label);
110}
111
112/** Answer received call (fast version).
113 *
114 * The fast answer makes use of passing retval and first four arguments in
115 * registers. If you need to return more, use the ipc_answer_slow() instead.
116 *
117 * @param chandle Handle of the call being answered.
118 * @param retval Return value.
119 * @param arg1 First return argument.
120 * @param arg2 Second return argument.
121 * @param arg3 Third return argument.
122 * @param arg4 Fourth return argument.
123 *
124 * @return Zero on success.
125 * @return Value from @ref errno.h on failure.
126 *
127 */
128errno_t ipc_answer_fast(cap_call_handle_t chandle, errno_t retval,
129 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
130{
131 return (errno_t) __SYSCALL6(SYS_IPC_ANSWER_FAST,
132 cap_handle_raw(chandle), (sysarg_t) retval, arg1, arg2, arg3, arg4);
133}
134
135/** Answer received call (entire payload).
136 *
137 * @param chandle Handle of the call being answered.
138 * @param retval Return value.
139 * @param arg1 First return argument.
140 * @param arg2 Second return argument.
141 * @param arg3 Third return argument.
142 * @param arg4 Fourth return argument.
143 * @param arg5 Fifth return argument.
144 *
145 * @return Zero on success.
146 * @return Value from @ref errno.h on failure.
147 *
148 */
149errno_t ipc_answer_slow(cap_call_handle_t chandle, errno_t retval,
150 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
151{
152 ipc_call_t data;
153
154 ipc_set_retval(&data, retval);
155 ipc_set_arg1(&data, arg1);
156 ipc_set_arg2(&data, arg2);
157 ipc_set_arg3(&data, arg3);
158 ipc_set_arg4(&data, arg4);
159 ipc_set_arg5(&data, arg5);
160
161 return (errno_t) __SYSCALL2(SYS_IPC_ANSWER_SLOW,
162 cap_handle_raw(chandle), (sysarg_t) &data);
163}
164
165/** Interrupt one thread of this task from waiting for IPC.
166 *
167 */
168void ipc_poke(void)
169{
170 __SYSCALL0(SYS_IPC_POKE);
171}
172
173errno_t ipc_wait(ipc_call_t *call, sysarg_t usec, unsigned int flags)
174{
175 // TODO: Use expiration time instead of timeout.
176 return __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
177}
178
179/** Hang up a phone.
180 *
181 * @param phandle Handle of the phone to be hung up.
182 *
183 * @return Zero on success or an error code.
184 *
185 */
186errno_t ipc_hangup(cap_phone_handle_t phandle)
187{
188 return (errno_t) __SYSCALL1(SYS_IPC_HANGUP, cap_handle_raw(phandle));
189}
190
191/** Forward a received call to another destination.
192 *
193 * For non-system methods, the old method, arg1 and arg2 are rewritten by the
194 * new values. For system methods, the new method, arg1 and arg2 are written to
195 * the old arg1, arg2 and arg3, respectivelly. Calls with immutable methods are
196 * forwarded verbatim.
197 *
198 * @param chandle Handle of the call to forward.
199 * @param phandle Phone handle to use for forwarding.
200 * @param imethod New interface and method for the forwarded call.
201 * @param arg1 New value of the first argument for the forwarded call.
202 * @param arg2 New value of the second argument for the forwarded call.
203 * @param mode Flags specifying mode of the forward operation.
204 *
205 * @return Zero on success or an error code.
206 *
207 */
208errno_t ipc_forward_fast(cap_call_handle_t chandle, cap_phone_handle_t phandle,
209 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
210{
211 return (errno_t) __SYSCALL6(SYS_IPC_FORWARD_FAST,
212 cap_handle_raw(chandle), cap_handle_raw(phandle), imethod, arg1,
213 arg2, mode);
214}
215
216errno_t ipc_forward_slow(cap_call_handle_t chandle, cap_phone_handle_t phandle,
217 sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
218 sysarg_t arg4, sysarg_t arg5, unsigned int mode)
219{
220 ipc_call_t data;
221
222 ipc_set_imethod(&data, imethod);
223 ipc_set_arg1(&data, arg1);
224 ipc_set_arg2(&data, arg2);
225 ipc_set_arg3(&data, arg3);
226 ipc_set_arg4(&data, arg4);
227 ipc_set_arg5(&data, arg5);
228
229 return (errno_t) __SYSCALL4(SYS_IPC_FORWARD_SLOW,
230 cap_handle_raw(chandle), cap_handle_raw(phandle), (sysarg_t) &data,
231 mode);
232}
233
234/** Connect to a task specified by id.
235 *
236 */
237errno_t ipc_connect_kbox(task_id_t id, cap_phone_handle_t *phone)
238{
239 return (errno_t) __SYSCALL2(SYS_IPC_CONNECT_KBOX, (sysarg_t) &id, (sysarg_t) phone);
240}
241
242/** @}
243 */
Note: See TracBrowser for help on using the repository browser.