[b419162] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[7c0e1f5] | 3 | * Copyright (c) 2017 Jakub Jermar
|
---|
[b419162] | 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.
|
---|
[b2951e2] | 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libc
|
---|
| 31 | * @{
|
---|
| 32 | * @}
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[fadd381] | 35 | /** @addtogroup libcipc IPC
|
---|
[b2951e2] | 36 | * @brief HelenOS uspace IPC
|
---|
| 37 | * @{
|
---|
| 38 | * @ingroup libc
|
---|
| 39 | */
|
---|
| 40 | /** @file
|
---|
[6b10dab] | 41 | */
|
---|
[b419162] | 42 |
|
---|
[7ee6aff] | 43 | #include <ipc/ipc.h>
|
---|
[b419162] | 44 | #include <libc.h>
|
---|
[38d150e] | 45 | #include <stdlib.h>
|
---|
[936351c1] | 46 | #include <errno.h>
|
---|
[d9c8c81] | 47 | #include <adt/list.h>
|
---|
[bc1f1c2] | 48 | #include <fibril.h>
|
---|
[633bcc6] | 49 | #include <macros.h>
|
---|
[b419162] | 50 |
|
---|
[10477601] | 51 | /** Fast asynchronous call.
|
---|
[8b243f2] | 52 | *
|
---|
[7c0e1f5] | 53 | * This function can only handle three arguments of payload. It is, however,
|
---|
[3209923] | 54 | * faster than the more generic ipc_call_async_slow().
|
---|
[8b243f2] | 55 | *
|
---|
| 56 | * Note that this function is a void function.
|
---|
[10477601] | 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.
|
---|
[c1d2c9d] | 61 | *
|
---|
[01c3bb4] | 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.
|
---|
[d054ad3] | 67 | * @param label A value to set to the label field of the answer.
|
---|
[c1d2c9d] | 68 | */
|
---|
[d054ad3] | 69 | errno_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)
|
---|
[c1d2c9d] | 71 | {
|
---|
[d054ad3] | 72 | return __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST,
|
---|
[bb97118] | 73 | cap_handle_raw(phandle), imethod, arg1, arg2, arg3,
|
---|
[d054ad3] | 74 | (sysarg_t) label);
|
---|
[c1d2c9d] | 75 | }
|
---|
| 76 |
|
---|
[10477601] | 77 | /** Asynchronous call transmitting the entire payload.
|
---|
[8b243f2] | 78 | *
|
---|
| 79 | * Note that this function is a void function.
|
---|
[10477601] | 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.
|
---|
[8b243f2] | 84 | *
|
---|
[01c3bb4] | 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.
|
---|
[d054ad3] | 92 | * @param label A value to set to the label field of the answer.
|
---|
[c1d2c9d] | 93 | */
|
---|
[d054ad3] | 94 | errno_t ipc_call_async_slow(cap_phone_handle_t phandle, sysarg_t imethod,
|
---|
[eadaeae8] | 95 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
|
---|
[d054ad3] | 96 | void *label)
|
---|
[c1d2c9d] | 97 | {
|
---|
[d054ad3] | 98 | ipc_call_t data;
|
---|
[a35b458] | 99 |
|
---|
[d054ad3] | 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);
|
---|
[a35b458] | 106 |
|
---|
[d054ad3] | 107 | return __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW,
|
---|
[bb97118] | 108 | cap_handle_raw(phandle), (sysarg_t) &data,
|
---|
[d054ad3] | 109 | (sysarg_t) label);
|
---|
[b419162] | 110 | }
|
---|
| 111 |
|
---|
[10477601] | 112 | /** Answer received call (fast version).
|
---|
[250717cc] | 113 | *
|
---|
[b74959bd] | 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.
|
---|
[250717cc] | 116 | *
|
---|
[01c3bb4] | 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.
|
---|
[10477601] | 123 | *
|
---|
| 124 | * @return Zero on success.
|
---|
| 125 | * @return Value from @ref errno.h on failure.
|
---|
[250717cc] | 126 | *
|
---|
| 127 | */
|
---|
[eadaeae8] | 128 | errno_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)
|
---|
[b419162] | 130 | {
|
---|
[eadaeae8] | 131 | return (errno_t) __SYSCALL6(SYS_IPC_ANSWER_FAST,
|
---|
[bb97118] | 132 | cap_handle_raw(chandle), (sysarg_t) retval, arg1, arg2, arg3, arg4);
|
---|
[b419162] | 133 | }
|
---|
[06502f7d] | 134 |
|
---|
[10477601] | 135 | /** Answer received call (entire payload).
|
---|
| 136 | *
|
---|
[01c3bb4] | 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.
|
---|
[250717cc] | 144 | *
|
---|
[10477601] | 145 | * @return Zero on success.
|
---|
| 146 | * @return Value from @ref errno.h on failure.
|
---|
[250717cc] | 147 | *
|
---|
| 148 | */
|
---|
[eadaeae8] | 149 | errno_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)
|
---|
[250717cc] | 151 | {
|
---|
[b74959bd] | 152 | ipc_call_t data;
|
---|
[a35b458] | 153 |
|
---|
[b74959bd] | 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);
|
---|
[a35b458] | 160 |
|
---|
[eadaeae8] | 161 | return (errno_t) __SYSCALL2(SYS_IPC_ANSWER_SLOW,
|
---|
[bb97118] | 162 | cap_handle_raw(chandle), (sysarg_t) &data);
|
---|
[250717cc] | 163 | }
|
---|
| 164 |
|
---|
[10477601] | 165 | /** Interrupt one thread of this task from waiting for IPC.
|
---|
[04a73cdf] | 166 | *
|
---|
[10477601] | 167 | */
|
---|
| 168 | void ipc_poke(void)
|
---|
| 169 | {
|
---|
| 170 | __SYSCALL0(SYS_IPC_POKE);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[d054ad3] | 173 | errno_t ipc_wait(ipc_call_t *call, sysarg_t usec, unsigned int flags)
|
---|
[04a73cdf] | 174 | {
|
---|
[d054ad3] | 175 | // TODO: Use expiration time instead of timeout.
|
---|
| 176 | return __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
|
---|
[b419162] | 177 | }
|
---|
[5106e98] | 178 |
|
---|
[8b243f2] | 179 | /** Hang up a phone.
|
---|
| 180 | *
|
---|
[01c3bb4] | 181 | * @param phandle Handle of the phone to be hung up.
|
---|
[10477601] | 182 | *
|
---|
[cde999a] | 183 | * @return Zero on success or an error code.
|
---|
[8b243f2] | 184 | *
|
---|
| 185 | */
|
---|
[eadaeae8] | 186 | errno_t ipc_hangup(cap_phone_handle_t phandle)
|
---|
[7048773] | 187 | {
|
---|
[bb97118] | 188 | return (errno_t) __SYSCALL1(SYS_IPC_HANGUP, cap_handle_raw(phandle));
|
---|
[7048773] | 189 | }
|
---|
[6180b57] | 190 |
|
---|
[8b243f2] | 191 | /** Forward a received call to another destination.
|
---|
[10477601] | 192 | *
|
---|
[01c3bb4] | 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.
|
---|
[8b243f2] | 197 | *
|
---|
[01c3bb4] | 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.
|
---|
[8b243f2] | 204 | *
|
---|
[01c3bb4] | 205 | * @return Zero on success or an error code.
|
---|
[8b243f2] | 206 | *
|
---|
| 207 | */
|
---|
[eadaeae8] | 208 | errno_t ipc_forward_fast(cap_call_handle_t chandle, cap_phone_handle_t phandle,
|
---|
[01c3bb4] | 209 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
|
---|
[043dcc27] | 210 | {
|
---|
[eadaeae8] | 211 | return (errno_t) __SYSCALL6(SYS_IPC_FORWARD_FAST,
|
---|
[bb97118] | 212 | cap_handle_raw(chandle), cap_handle_raw(phandle), imethod, arg1,
|
---|
[90c35436] | 213 | arg2, mode);
|
---|
[043dcc27] | 214 | }
|
---|
| 215 |
|
---|
[eadaeae8] | 216 | errno_t ipc_forward_slow(cap_call_handle_t chandle, cap_phone_handle_t phandle,
|
---|
[01c3bb4] | 217 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
|
---|
| 218 | sysarg_t arg4, sysarg_t arg5, unsigned int mode)
|
---|
[48daf64] | 219 | {
|
---|
| 220 | ipc_call_t data;
|
---|
[a35b458] | 221 |
|
---|
[228e490] | 222 | IPC_SET_IMETHOD(data, imethod);
|
---|
[48daf64] | 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);
|
---|
[a35b458] | 228 |
|
---|
[eadaeae8] | 229 | return (errno_t) __SYSCALL4(SYS_IPC_FORWARD_SLOW,
|
---|
[bb97118] | 230 | cap_handle_raw(chandle), cap_handle_raw(phandle), (sysarg_t) &data,
|
---|
[eadaeae8] | 231 | mode);
|
---|
[48daf64] | 232 | }
|
---|
| 233 |
|
---|
[9a1b20c] | 234 | /** Connect to a task specified by id.
|
---|
[6b10dab] | 235 | *
|
---|
[9a1b20c] | 236 | */
|
---|
[eadaeae8] | 237 | errno_t ipc_connect_kbox(task_id_t id, cap_phone_handle_t *phone)
|
---|
[9a1b20c] | 238 | {
|
---|
[b7fd2a0] | 239 | return (errno_t) __SYSCALL2(SYS_IPC_CONNECT_KBOX, (sysarg_t) &id, (sysarg_t) phone);
|
---|
[9a1b20c] | 240 | }
|
---|
[6b10dab] | 241 |
|
---|
[fadd381] | 242 | /** @}
|
---|
[b2951e2] | 243 | */
|
---|