[2d5a54f3] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2006 Ondrej Palkovsky
|
---|
[2d5a54f3] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
[cc73a8a1] | 29 | /** @addtogroup genericipc
|
---|
[b45c443] | 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
[2d5a54f3] | 35 | #include <arch.h>
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <memstr.h>
|
---|
| 38 | #include <ipc/ipc.h>
|
---|
[c0699467] | 39 | #include <abi/ipc/methods.h>
|
---|
[2d5a54f3] | 40 | #include <ipc/sysipc.h>
|
---|
[e8039a86] | 41 | #include <ipc/sysipc_ops.h>
|
---|
[5d3ed34] | 42 | #include <ipc/sysipc_priv.h>
|
---|
[162f919] | 43 | #include <ipc/irq.h>
|
---|
[4e49572] | 44 | #include <ipc/ipcrsc.h>
|
---|
[fdd4898] | 45 | #include <ipc/event.h>
|
---|
[e028660] | 46 | #include <ipc/kbox.h>
|
---|
[057d21a] | 47 | #include <synch/waitq.h>
|
---|
[5626277] | 48 | #include <arch/interrupt.h>
|
---|
[e3c762cd] | 49 | #include <syscall/copy.h>
|
---|
[2bb8648] | 50 | #include <security/cap.h>
|
---|
[6b10dab] | 51 | #include <console/console.h>
|
---|
[253f35a1] | 52 | #include <print.h>
|
---|
[e2ab36f1] | 53 | #include <macros.h>
|
---|
[2d5a54f3] | 54 |
|
---|
[da1bafb] | 55 | #define STRUCT_TO_USPACE(dst, src) copy_to_uspace((dst), (src), sizeof(*(src)))
|
---|
[7918fce] | 56 |
|
---|
[228e490] | 57 | /** Decide if the interface and method is a system method.
|
---|
[8b243f2] | 58 | *
|
---|
[228e490] | 59 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 60 | *
|
---|
[228e490] | 61 | * @return True if the interface and method is a system
|
---|
| 62 | * interface and method.
|
---|
[8b243f2] | 63 | *
|
---|
| 64 | */
|
---|
[228e490] | 65 | static inline bool method_is_system(sysarg_t imethod)
|
---|
[2ba7810] | 66 | {
|
---|
[228e490] | 67 | if (imethod <= IPC_M_LAST_SYSTEM)
|
---|
[da1bafb] | 68 | return true;
|
---|
| 69 |
|
---|
| 70 | return false;
|
---|
[2ba7810] | 71 | }
|
---|
| 72 |
|
---|
[228e490] | 73 | /** Decide if the message with this interface and method is forwardable.
|
---|
[2ba7810] | 74 | *
|
---|
[228e490] | 75 | * Some system messages may be forwarded, for some of them
|
---|
| 76 | * it is useless.
|
---|
[8b243f2] | 77 | *
|
---|
[228e490] | 78 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 79 | *
|
---|
[228e490] | 80 | * @return True if the interface and method is forwardable.
|
---|
[8b243f2] | 81 | *
|
---|
[2ba7810] | 82 | */
|
---|
[228e490] | 83 | static inline bool method_is_forwardable(sysarg_t imethod)
|
---|
[2ba7810] | 84 | {
|
---|
[228e490] | 85 | switch (imethod) {
|
---|
[2c0e5d2] | 86 | case IPC_M_CONNECTION_CLONE:
|
---|
[6aae539d] | 87 | case IPC_M_CLONE_ESTABLISH:
|
---|
[7918fce] | 88 | case IPC_M_PHONE_HUNGUP:
|
---|
| 89 | /* This message is meant only for the original recipient. */
|
---|
[da1bafb] | 90 | return false;
|
---|
[7918fce] | 91 | default:
|
---|
[da1bafb] | 92 | return true;
|
---|
[7918fce] | 93 | }
|
---|
[2ba7810] | 94 | }
|
---|
| 95 |
|
---|
[228e490] | 96 | /** Decide if the message with this interface and method is immutable on forward.
|
---|
[0dc4258] | 97 | *
|
---|
[228e490] | 98 | * Some system messages may be forwarded but their content cannot be altered.
|
---|
[0dc4258] | 99 | *
|
---|
[228e490] | 100 | * @param imethod Interface and method to be decided.
|
---|
[da1bafb] | 101 | *
|
---|
[228e490] | 102 | * @return True if the interface and method is immutable on forward.
|
---|
[0dc4258] | 103 | *
|
---|
| 104 | */
|
---|
[228e490] | 105 | static inline bool method_is_immutable(sysarg_t imethod)
|
---|
[0dc4258] | 106 | {
|
---|
[228e490] | 107 | switch (imethod) {
|
---|
[072607b] | 108 | case IPC_M_PAGE_IN:
|
---|
[27d293a] | 109 | case IPC_M_SHARE_OUT:
|
---|
| 110 | case IPC_M_SHARE_IN:
|
---|
[36d852c] | 111 | case IPC_M_DATA_WRITE:
|
---|
| 112 | case IPC_M_DATA_READ:
|
---|
[fdd4898] | 113 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
---|
[da1bafb] | 114 | return true;
|
---|
[0dc4258] | 115 | default:
|
---|
[da1bafb] | 116 | return false;
|
---|
[0dc4258] | 117 | }
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[2d5a54f3] | 120 |
|
---|
[8b243f2] | 121 | /***********************************************************************
|
---|
| 122 | * Functions that preprocess answer before sending it to the recepient.
|
---|
| 123 | ***********************************************************************/
|
---|
| 124 |
|
---|
| 125 | /** Decide if the caller (e.g. ipc_answer()) should save the old call contents
|
---|
| 126 | * for answer_preprocess().
|
---|
| 127 | *
|
---|
[da1bafb] | 128 | * @param call Call structure to be decided.
|
---|
| 129 | *
|
---|
| 130 | * @return true if the old call contents should be saved.
|
---|
[8b243f2] | 131 | *
|
---|
[2d5a54f3] | 132 | */
|
---|
[da1bafb] | 133 | static inline bool answer_need_old(call_t *call)
|
---|
[2d5a54f3] | 134 | {
|
---|
[228e490] | 135 | switch (IPC_GET_IMETHOD(call->data)) {
|
---|
[2c0e5d2] | 136 | case IPC_M_CONNECTION_CLONE:
|
---|
[6aae539d] | 137 | case IPC_M_CLONE_ESTABLISH:
|
---|
[7918fce] | 138 | case IPC_M_CONNECT_TO_ME:
|
---|
| 139 | case IPC_M_CONNECT_ME_TO:
|
---|
[072607b] | 140 | case IPC_M_PAGE_IN:
|
---|
[27d293a] | 141 | case IPC_M_SHARE_OUT:
|
---|
| 142 | case IPC_M_SHARE_IN:
|
---|
[36d852c] | 143 | case IPC_M_DATA_WRITE:
|
---|
| 144 | case IPC_M_DATA_READ:
|
---|
[fdd4898] | 145 | case IPC_M_STATE_CHANGE_AUTHORIZE:
|
---|
[da1bafb] | 146 | return true;
|
---|
[7918fce] | 147 | default:
|
---|
[da1bafb] | 148 | return false;
|
---|
[7918fce] | 149 | }
|
---|
[2d5a54f3] | 150 | }
|
---|
| 151 |
|
---|
[8b243f2] | 152 | /** Interpret process answer as control information.
|
---|
| 153 | *
|
---|
| 154 | * This function is called directly after sys_ipc_answer().
|
---|
[46fc2f9] | 155 | *
|
---|
[da1bafb] | 156 | * @param answer Call structure with the answer.
|
---|
| 157 | * @param olddata Saved data of the request.
|
---|
| 158 | *
|
---|
[9956fad9] | 159 | * @return Return EOK on success or a negative error code.
|
---|
[8b243f2] | 160 | *
|
---|
[46fc2f9] | 161 | */
|
---|
[5d3ed34] | 162 | int answer_preprocess(call_t *answer, ipc_data_t *olddata)
|
---|
[2d5a54f3] | 163 | {
|
---|
[9956fad9] | 164 | int rc = EOK;
|
---|
| 165 |
|
---|
[2405bb5] | 166 | spinlock_lock(&answer->forget_lock);
|
---|
| 167 | if (answer->forget) {
|
---|
| 168 | /*
|
---|
| 169 | * This is a forgotten call and answer->sender is not valid.
|
---|
| 170 | */
|
---|
| 171 | spinlock_unlock(&answer->forget_lock);
|
---|
[b1e6269] | 172 |
|
---|
[466e95f7] | 173 | SYSIPC_OP(answer_cleanup, answer, olddata);
|
---|
[2405bb5] | 174 | return rc;
|
---|
| 175 | } else {
|
---|
[20282ef3] | 176 | ASSERT(answer->active);
|
---|
| 177 |
|
---|
| 178 | /*
|
---|
| 179 | * Mark the call as inactive to prevent _ipc_answer_free_call()
|
---|
| 180 | * from attempting to remove the call from the active list
|
---|
| 181 | * itself.
|
---|
| 182 | */
|
---|
| 183 | answer->active = false;
|
---|
| 184 |
|
---|
| 185 | /*
|
---|
| 186 | * Remove the call from the sender's active call list.
|
---|
| 187 | * We enforce this locking order so that any potential
|
---|
| 188 | * concurrently executing forget operation is forced to
|
---|
| 189 | * release its active_calls_lock and lose the race to
|
---|
| 190 | * forget this soon to be answered call.
|
---|
| 191 | */
|
---|
| 192 | spinlock_lock(&answer->sender->active_calls_lock);
|
---|
| 193 | list_remove(&answer->ta_link);
|
---|
| 194 | spinlock_unlock(&answer->sender->active_calls_lock);
|
---|
[2405bb5] | 195 | }
|
---|
| 196 | spinlock_unlock(&answer->forget_lock);
|
---|
| 197 |
|
---|
[6c441cf8] | 198 | if ((native_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
|
---|
[2541646] | 199 | phone_t *phone = answer->caller_phone;
|
---|
| 200 | mutex_lock(&phone->lock);
|
---|
| 201 | if (phone->state == IPC_PHONE_CONNECTED) {
|
---|
| 202 | irq_spinlock_lock(&phone->callee->lock, true);
|
---|
| 203 | list_remove(&phone->link);
|
---|
| 204 | phone->state = IPC_PHONE_SLAMMED;
|
---|
| 205 | irq_spinlock_unlock(&phone->callee->lock, true);
|
---|
[ca687ad] | 206 | }
|
---|
[2541646] | 207 | mutex_unlock(&phone->lock);
|
---|
[9f22213] | 208 | }
|
---|
[da1bafb] | 209 |
|
---|
[53af6e8c] | 210 | if (!olddata)
|
---|
[9956fad9] | 211 | return rc;
|
---|
[e8039a86] | 212 |
|
---|
[466e95f7] | 213 | return SYSIPC_OP(answer_preprocess, answer, olddata);
|
---|
[2d5a54f3] | 214 | }
|
---|
| 215 |
|
---|
[8b243f2] | 216 | /** Called before the request is sent.
|
---|
| 217 | *
|
---|
[da1bafb] | 218 | * @param call Call structure with the request.
|
---|
| 219 | * @param phone Phone that the call will be sent through.
|
---|
| 220 | *
|
---|
| 221 | * @return Return 0 on success, ELIMIT or EPERM on error.
|
---|
[7c7aae16] | 222 | *
|
---|
| 223 | */
|
---|
[9a1b20c] | 224 | static int request_preprocess(call_t *call, phone_t *phone)
|
---|
[7c7aae16] | 225 | {
|
---|
[32e4643] | 226 | call->request_method = IPC_GET_IMETHOD(call->data);
|
---|
[466e95f7] | 227 | return SYSIPC_OP(request_preprocess, call, phone);
|
---|
[7c7aae16] | 228 | }
|
---|
| 229 |
|
---|
[8b243f2] | 230 | /*******************************************************************************
|
---|
| 231 | * Functions called to process received call/answer before passing it to uspace.
|
---|
| 232 | *******************************************************************************/
|
---|
[2d5a54f3] | 233 |
|
---|
[8b243f2] | 234 | /** Do basic kernel processing of received call answer.
|
---|
| 235 | *
|
---|
[da1bafb] | 236 | * @param call Call structure with the answer.
|
---|
| 237 | *
|
---|
[8b243f2] | 238 | */
|
---|
[7c7aae16] | 239 | static void process_answer(call_t *call)
|
---|
[2d5a54f3] | 240 | {
|
---|
[6c441cf8] | 241 | if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
|
---|
[51ec40f] | 242 | (call->flags & IPC_CALL_FORWARDED))
|
---|
[9f22213] | 243 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[da1bafb] | 244 |
|
---|
[466e95f7] | 245 | SYSIPC_OP(answer_process, call);
|
---|
[2d5a54f3] | 246 | }
|
---|
| 247 |
|
---|
[691d8d8] | 248 |
|
---|
[8b243f2] | 249 | /** Do basic kernel processing of received call request.
|
---|
| 250 | *
|
---|
[da1bafb] | 251 | * @param box Destination answerbox structure.
|
---|
| 252 | * @param call Call structure with the request.
|
---|
| 253 | *
|
---|
| 254 | * @return 0 if the call should be passed to userspace.
|
---|
| 255 | * @return -1 if the call should be ignored.
|
---|
[2d5a54f3] | 256 | *
|
---|
| 257 | */
|
---|
[51ec40f] | 258 | static int process_request(answerbox_t *box, call_t *call)
|
---|
[2d5a54f3] | 259 | {
|
---|
[466e95f7] | 260 | return SYSIPC_OP(request_process, call, box);
|
---|
[2d5a54f3] | 261 | }
|
---|
| 262 |
|
---|
[bc117a5] | 263 | /** Make a call over IPC and wait for reply.
|
---|
| 264 | *
|
---|
| 265 | * @param phoneid Phone handle for the call.
|
---|
| 266 | * @param data[inout] Structure with request/reply data.
|
---|
| 267 | *
|
---|
| 268 | * @return EOK on success.
|
---|
| 269 | * @return ENOENT if there is no such phone handle.
|
---|
| 270 | *
|
---|
| 271 | */
|
---|
| 272 | int ipc_req_internal(int phoneid, ipc_data_t *data)
|
---|
| 273 | {
|
---|
| 274 | phone_t *phone;
|
---|
| 275 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 276 | return ENOENT;
|
---|
| 277 |
|
---|
| 278 | call_t *call = ipc_call_alloc(0);
|
---|
| 279 | memcpy(call->data.args, data->args, sizeof(data->args));
|
---|
| 280 |
|
---|
| 281 | int rc = request_preprocess(call, phone);
|
---|
| 282 | if (!rc) {
|
---|
| 283 | #ifdef CONFIG_UDEBUG
|
---|
| 284 | udebug_stoppable_begin();
|
---|
| 285 | #endif
|
---|
| 286 |
|
---|
[43e2cbc] | 287 | ipc_call_hold(call);
|
---|
| 288 | rc = ipc_call_sync(phone, call);
|
---|
| 289 | spinlock_lock(&call->forget_lock);
|
---|
| 290 | bool forgotten = call->forget;
|
---|
| 291 | spinlock_unlock(&call->forget_lock);
|
---|
| 292 | ipc_call_release(call);
|
---|
[bc117a5] | 293 |
|
---|
| 294 | #ifdef CONFIG_UDEBUG
|
---|
| 295 | udebug_stoppable_end();
|
---|
| 296 | #endif
|
---|
| 297 |
|
---|
[43e2cbc] | 298 | if (rc != EOK) {
|
---|
| 299 | if (!forgotten) {
|
---|
| 300 | /*
|
---|
| 301 | * There was an error, but it did not result
|
---|
| 302 | * in the call being forgotten. In fact, the
|
---|
| 303 | * call was not even sent. We are still
|
---|
| 304 | * its owners and are responsible for its
|
---|
| 305 | * deallocation.
|
---|
| 306 | */
|
---|
| 307 | ipc_call_free(call);
|
---|
| 308 | } else {
|
---|
| 309 | /*
|
---|
| 310 | * The call was forgotten and it changed hands.
|
---|
| 311 | * We are no longer expected to free it.
|
---|
| 312 | */
|
---|
| 313 | ASSERT(rc == EINTR);
|
---|
| 314 | }
|
---|
| 315 | return rc;
|
---|
| 316 | }
|
---|
[bc117a5] | 317 |
|
---|
| 318 | process_answer(call);
|
---|
| 319 | } else
|
---|
| 320 | IPC_SET_RETVAL(call->data, rc);
|
---|
| 321 |
|
---|
| 322 | memcpy(data->args, call->data.args, sizeof(data->args));
|
---|
| 323 | ipc_call_free(call);
|
---|
| 324 |
|
---|
| 325 | return EOK;
|
---|
| 326 | }
|
---|
| 327 |
|
---|
[97d17fe] | 328 | /** Check that the task did not exceed the allowed limit of asynchronous calls
|
---|
| 329 | * made over a phone.
|
---|
[2d5a54f3] | 330 | *
|
---|
[228e490] | 331 | * @param phone Phone to check the limit against.
|
---|
| 332 | *
|
---|
[da1bafb] | 333 | * @return 0 if limit not reached or -1 if limit exceeded.
|
---|
| 334 | *
|
---|
[2d5a54f3] | 335 | */
|
---|
[97d17fe] | 336 | static int check_call_limit(phone_t *phone)
|
---|
[2d5a54f3] | 337 | {
|
---|
[97d17fe] | 338 | if (atomic_get(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
|
---|
[2d5a54f3] | 339 | return -1;
|
---|
[da1bafb] | 340 |
|
---|
[2d5a54f3] | 341 | return 0;
|
---|
| 342 | }
|
---|
| 343 |
|
---|
[8b243f2] | 344 | /** Make a fast asynchronous call over IPC.
|
---|
[2d5a54f3] | 345 | *
|
---|
[3209923] | 346 | * This function can only handle four arguments of payload, but is faster than
|
---|
| 347 | * the generic function sys_ipc_call_async_slow().
|
---|
[8b243f2] | 348 | *
|
---|
[da1bafb] | 349 | * @param phoneid Phone handle for the call.
|
---|
[228e490] | 350 | * @param imethod Interface and method of the call.
|
---|
[da1bafb] | 351 | * @param arg1 Service-defined payload argument.
|
---|
| 352 | * @param arg2 Service-defined payload argument.
|
---|
| 353 | * @param arg3 Service-defined payload argument.
|
---|
| 354 | * @param arg4 Service-defined payload argument.
|
---|
| 355 | *
|
---|
| 356 | * @return Call hash on success.
|
---|
| 357 | * @return IPC_CALLRET_FATAL in case of a fatal error.
|
---|
| 358 | * @return IPC_CALLRET_TEMPORARY if there are too many pending
|
---|
| 359 | * asynchronous requests; answers should be handled first.
|
---|
| 360 | *
|
---|
[2d5a54f3] | 361 | */
|
---|
[228e490] | 362 | sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
|
---|
[96b02eb9] | 363 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 364 | {
|
---|
[da1bafb] | 365 | phone_t *phone;
|
---|
[c9fff17] | 366 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 367 | return IPC_CALLRET_FATAL;
|
---|
[228e490] | 368 |
|
---|
[97d17fe] | 369 | if (check_call_limit(phone))
|
---|
| 370 | return IPC_CALLRET_TEMPORARY;
|
---|
[da1bafb] | 371 |
|
---|
| 372 | call_t *call = ipc_call_alloc(0);
|
---|
[228e490] | 373 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[2d5a54f3] | 374 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 375 | IPC_SET_ARG2(call->data, arg2);
|
---|
[3209923] | 376 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 377 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 378 |
|
---|
[8498915] | 379 | /*
|
---|
| 380 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 381 | * the limits of the fast version.
|
---|
| 382 | */
|
---|
| 383 | IPC_SET_ARG5(call->data, 0);
|
---|
[da1bafb] | 384 |
|
---|
| 385 | int res = request_preprocess(call, phone);
|
---|
| 386 |
|
---|
| 387 | if (!res)
|
---|
[7c7aae16] | 388 | ipc_call(phone, call);
|
---|
| 389 | else
|
---|
| 390 | ipc_backsend_err(phone, call, res);
|
---|
[da1bafb] | 391 |
|
---|
[96b02eb9] | 392 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 393 | }
|
---|
| 394 |
|
---|
[8b243f2] | 395 | /** Make an asynchronous IPC call allowing to transmit the entire payload.
|
---|
| 396 | *
|
---|
[da1bafb] | 397 | * @param phoneid Phone handle for the call.
|
---|
| 398 | * @param data Userspace address of call data with the request.
|
---|
| 399 | *
|
---|
| 400 | * @return See sys_ipc_call_async_fast().
|
---|
[2d5a54f3] | 401 | *
|
---|
| 402 | */
|
---|
[96b02eb9] | 403 | sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
|
---|
[2d5a54f3] | 404 | {
|
---|
[da1bafb] | 405 | phone_t *phone;
|
---|
[c9fff17] | 406 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 407 | return IPC_CALLRET_FATAL;
|
---|
[4e49572] | 408 |
|
---|
[97d17fe] | 409 | if (check_call_limit(phone))
|
---|
| 410 | return IPC_CALLRET_TEMPORARY;
|
---|
| 411 |
|
---|
[da1bafb] | 412 | call_t *call = ipc_call_alloc(0);
|
---|
| 413 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 414 | sizeof(call->data.args));
|
---|
[f58af46] | 415 | if (rc != 0) {
|
---|
| 416 | ipc_call_free(call);
|
---|
[96b02eb9] | 417 | return (sysarg_t) rc;
|
---|
[f58af46] | 418 | }
|
---|
[da1bafb] | 419 |
|
---|
| 420 | int res = request_preprocess(call, phone);
|
---|
| 421 |
|
---|
| 422 | if (!res)
|
---|
[7c7aae16] | 423 | ipc_call(phone, call);
|
---|
| 424 | else
|
---|
| 425 | ipc_backsend_err(phone, call, res);
|
---|
[da1bafb] | 426 |
|
---|
[96b02eb9] | 427 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 428 | }
|
---|
| 429 |
|
---|
[da1bafb] | 430 | /** Forward a received call to another destination
|
---|
| 431 | *
|
---|
| 432 | * Common code for both the fast and the slow version.
|
---|
| 433 | *
|
---|
| 434 | * @param callid Hash of the call to forward.
|
---|
| 435 | * @param phoneid Phone handle to use for forwarding.
|
---|
[228e490] | 436 | * @param imethod New interface and method to use for the forwarded call.
|
---|
[da1bafb] | 437 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 438 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 439 | * @param arg3 New value of the third argument for the forwarded call.
|
---|
| 440 | * @param arg4 New value of the fourth argument for the forwarded call.
|
---|
| 441 | * @param arg5 New value of the fifth argument for the forwarded call.
|
---|
| 442 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 443 | * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
|
---|
| 444 | * the function considers only the fast version arguments:
|
---|
| 445 | * i.e. arg1 and arg2.
|
---|
| 446 | *
|
---|
| 447 | * @return 0 on succes, otherwise an error code.
|
---|
| 448 | *
|
---|
| 449 | * Warning: Make sure that ARG5 is not rewritten for certain system IPC
|
---|
| 450 | *
|
---|
[2ba7810] | 451 | */
|
---|
[96b02eb9] | 452 | static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
|
---|
[228e490] | 453 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
|
---|
[96b02eb9] | 454 | sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
|
---|
[2ba7810] | 455 | {
|
---|
[da1bafb] | 456 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 457 | if (!call)
|
---|
| 458 | return ENOENT;
|
---|
[09024119] | 459 |
|
---|
| 460 | ipc_data_t old;
|
---|
| 461 | bool need_old = answer_need_old(call);
|
---|
[f9841e69] | 462 | if (need_old)
|
---|
| 463 | old = call->data;
|
---|
[48daf64] | 464 |
|
---|
[09024119] | 465 | bool after_forward = false;
|
---|
| 466 | int rc;
|
---|
| 467 | phone_t *phone;
|
---|
| 468 |
|
---|
[c9fff17] | 469 | if (phone_get(phoneid, &phone) != EOK) {
|
---|
[95a3082] | 470 | rc = ENOENT;
|
---|
| 471 | goto error;
|
---|
[c9fff17] | 472 | }
|
---|
[da1bafb] | 473 |
|
---|
[228e490] | 474 | if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
|
---|
[95a3082] | 475 | rc = EPERM;
|
---|
| 476 | goto error;
|
---|
[2ba7810] | 477 | }
|
---|
[09024119] | 478 |
|
---|
[95a3082] | 479 | call->flags |= IPC_CALL_FORWARDED;
|
---|
[da1bafb] | 480 |
|
---|
[0dc4258] | 481 | /*
|
---|
[4e5dabf] | 482 | * User space is not allowed to change interface and method of system
|
---|
[228e490] | 483 | * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
|
---|
[4e5dabf] | 484 | * means of imethod, arg1, arg2 and arg3.
|
---|
[228e490] | 485 | * If the interface and method is immutable, don't change anything.
|
---|
[2ba7810] | 486 | */
|
---|
[228e490] | 487 | if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
|
---|
| 488 | if (method_is_system(IPC_GET_IMETHOD(call->data))) {
|
---|
| 489 | if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
|
---|
[b61d47d] | 490 | phone_dealloc(IPC_GET_ARG5(call->data));
|
---|
[da1bafb] | 491 |
|
---|
[228e490] | 492 | IPC_SET_ARG1(call->data, imethod);
|
---|
[0dc4258] | 493 | IPC_SET_ARG2(call->data, arg1);
|
---|
[b61d47d] | 494 | IPC_SET_ARG3(call->data, arg2);
|
---|
[da1bafb] | 495 |
|
---|
[4e5dabf] | 496 | if (slow)
|
---|
[48daf64] | 497 | IPC_SET_ARG4(call->data, arg3);
|
---|
[4e5dabf] | 498 |
|
---|
| 499 | /*
|
---|
| 500 | * For system methods we deliberately don't
|
---|
| 501 | * overwrite ARG5.
|
---|
| 502 | */
|
---|
[0dc4258] | 503 | } else {
|
---|
[228e490] | 504 | IPC_SET_IMETHOD(call->data, imethod);
|
---|
[0dc4258] | 505 | IPC_SET_ARG1(call->data, arg1);
|
---|
[b61d47d] | 506 | IPC_SET_ARG2(call->data, arg2);
|
---|
[48daf64] | 507 | if (slow) {
|
---|
| 508 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 509 | IPC_SET_ARG4(call->data, arg4);
|
---|
| 510 | IPC_SET_ARG5(call->data, arg5);
|
---|
| 511 | }
|
---|
[0dc4258] | 512 | }
|
---|
[2ba7810] | 513 | }
|
---|
[da1bafb] | 514 |
|
---|
[f9841e69] | 515 | rc = ipc_forward(call, phone, &TASK->answerbox, mode);
|
---|
| 516 | if (rc != EOK) {
|
---|
| 517 | after_forward = true;
|
---|
| 518 | goto error;
|
---|
| 519 | }
|
---|
[95a3082] | 520 |
|
---|
[f9841e69] | 521 | return EOK;
|
---|
[95a3082] | 522 |
|
---|
[f9841e69] | 523 | error:
|
---|
[fcfa926b] | 524 | IPC_SET_RETVAL(call->data, EFORWARD);
|
---|
[9ef1b79b] | 525 | (void) answer_preprocess(call, need_old ? &old : NULL);
|
---|
[f9841e69] | 526 | if (after_forward)
|
---|
| 527 | _ipc_answer_free_call(call, false);
|
---|
| 528 | else
|
---|
| 529 | ipc_answer(&TASK->answerbox, call);
|
---|
| 530 |
|
---|
[95a3082] | 531 | return rc;
|
---|
[2ba7810] | 532 | }
|
---|
| 533 |
|
---|
[48daf64] | 534 | /** Forward a received call to another destination - fast version.
|
---|
| 535 | *
|
---|
[228e490] | 536 | * In case the original interface and method is a system method, ARG1, ARG2
|
---|
| 537 | * and ARG3 are overwritten in the forwarded message with the new method and
|
---|
| 538 | * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
|
---|
| 539 | * are rewritten with the new interface and method, arg1 and arg2, respectively.
|
---|
| 540 | * Also note there is a set of immutable methods, for which the new method and
|
---|
| 541 | * arguments are not set and these values are ignored.
|
---|
[da1bafb] | 542 | *
|
---|
| 543 | * @param callid Hash of the call to forward.
|
---|
| 544 | * @param phoneid Phone handle to use for forwarding.
|
---|
[228e490] | 545 | * @param imethod New interface and method to use for the forwarded call.
|
---|
[da1bafb] | 546 | * @param arg1 New value of the first argument for the forwarded call.
|
---|
| 547 | * @param arg2 New value of the second argument for the forwarded call.
|
---|
| 548 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 549 | *
|
---|
| 550 | * @return 0 on succes, otherwise an error code.
|
---|
| 551 | *
|
---|
[48daf64] | 552 | */
|
---|
[96b02eb9] | 553 | sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
|
---|
[228e490] | 554 | sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
|
---|
[48daf64] | 555 | {
|
---|
[228e490] | 556 | return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
|
---|
[48daf64] | 557 | 0, mode, false);
|
---|
| 558 | }
|
---|
| 559 |
|
---|
| 560 | /** Forward a received call to another destination - slow version.
|
---|
| 561 | *
|
---|
| 562 | * This function is the slow verision of the sys_ipc_forward_fast interface.
|
---|
[228e490] | 563 | * It can copy all five new arguments and the new interface and method from
|
---|
| 564 | * the userspace. It naturally extends the functionality of the fast version.
|
---|
| 565 | * For system methods, it additionally stores the new value of arg3 to ARG4.
|
---|
| 566 | * For non-system methods, it additionally stores the new value of arg3, arg4
|
---|
| 567 | * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
|
---|
[da1bafb] | 568 | *
|
---|
| 569 | * @param callid Hash of the call to forward.
|
---|
| 570 | * @param phoneid Phone handle to use for forwarding.
|
---|
| 571 | * @param data Userspace address of the new IPC data.
|
---|
| 572 | * @param mode Flags that specify mode of the forward operation.
|
---|
| 573 | *
|
---|
| 574 | * @return 0 on succes, otherwise an error code.
|
---|
| 575 | *
|
---|
[48daf64] | 576 | */
|
---|
[96b02eb9] | 577 | sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
|
---|
[da1bafb] | 578 | ipc_data_t *data, unsigned int mode)
|
---|
[48daf64] | 579 | {
|
---|
| 580 | ipc_data_t newdata;
|
---|
[da1bafb] | 581 | int rc = copy_from_uspace(&newdata.args, &data->args,
|
---|
[48daf64] | 582 | sizeof(newdata.args));
|
---|
[da1bafb] | 583 | if (rc != 0)
|
---|
[96b02eb9] | 584 | return (sysarg_t) rc;
|
---|
[da1bafb] | 585 |
|
---|
[48daf64] | 586 | return sys_ipc_forward_common(callid, phoneid,
|
---|
[228e490] | 587 | IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
|
---|
[48daf64] | 588 | IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
|
---|
| 589 | IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
|
---|
| 590 | }
|
---|
| 591 |
|
---|
[8b243f2] | 592 | /** Answer an IPC call - fast version.
|
---|
| 593 | *
|
---|
| 594 | * This function can handle only two return arguments of payload, but is faster
|
---|
| 595 | * than the generic sys_ipc_answer().
|
---|
| 596 | *
|
---|
[da1bafb] | 597 | * @param callid Hash of the call to be answered.
|
---|
| 598 | * @param retval Return value of the answer.
|
---|
| 599 | * @param arg1 Service-defined return value.
|
---|
| 600 | * @param arg2 Service-defined return value.
|
---|
| 601 | * @param arg3 Service-defined return value.
|
---|
| 602 | * @param arg4 Service-defined return value.
|
---|
| 603 | *
|
---|
| 604 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 605 | *
|
---|
| 606 | */
|
---|
[96b02eb9] | 607 | sysarg_t sys_ipc_answer_fast(sysarg_t callid, sysarg_t retval,
|
---|
| 608 | sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
|
---|
[2d5a54f3] | 609 | {
|
---|
[897f2e76] | 610 | /* Do not answer notification callids */
|
---|
| 611 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 612 | return 0;
|
---|
[da1bafb] | 613 |
|
---|
| 614 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 615 | if (!call)
|
---|
| 616 | return ENOENT;
|
---|
[da1bafb] | 617 |
|
---|
| 618 | ipc_data_t saved_data;
|
---|
| 619 | bool saved;
|
---|
| 620 |
|
---|
[9f22213] | 621 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 622 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 623 | saved = true;
|
---|
| 624 | } else
|
---|
| 625 | saved = false;
|
---|
| 626 |
|
---|
[2d5a54f3] | 627 | IPC_SET_RETVAL(call->data, retval);
|
---|
| 628 | IPC_SET_ARG1(call->data, arg1);
|
---|
| 629 | IPC_SET_ARG2(call->data, arg2);
|
---|
[b74959bd] | 630 | IPC_SET_ARG3(call->data, arg3);
|
---|
| 631 | IPC_SET_ARG4(call->data, arg4);
|
---|
[da1bafb] | 632 |
|
---|
[8498915] | 633 | /*
|
---|
| 634 | * To achieve deterministic behavior, zero out arguments that are beyond
|
---|
| 635 | * the limits of the fast version.
|
---|
| 636 | */
|
---|
| 637 | IPC_SET_ARG5(call->data, 0);
|
---|
[da1bafb] | 638 | int rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
| 639 |
|
---|
[2d5a54f3] | 640 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 641 | return rc;
|
---|
[2d5a54f3] | 642 | }
|
---|
| 643 |
|
---|
[8b243f2] | 644 | /** Answer an IPC call.
|
---|
| 645 | *
|
---|
[da1bafb] | 646 | * @param callid Hash of the call to be answered.
|
---|
| 647 | * @param data Userspace address of call data with the answer.
|
---|
| 648 | *
|
---|
| 649 | * @return 0 on success, otherwise an error code.
|
---|
[8b243f2] | 650 | *
|
---|
| 651 | */
|
---|
[96b02eb9] | 652 | sysarg_t sys_ipc_answer_slow(sysarg_t callid, ipc_data_t *data)
|
---|
[2d5a54f3] | 653 | {
|
---|
[897f2e76] | 654 | /* Do not answer notification callids */
|
---|
| 655 | if (callid & IPC_CALLID_NOTIFICATION)
|
---|
| 656 | return 0;
|
---|
[da1bafb] | 657 |
|
---|
| 658 | call_t *call = get_call(callid);
|
---|
[2ba7810] | 659 | if (!call)
|
---|
| 660 | return ENOENT;
|
---|
[da1bafb] | 661 |
|
---|
| 662 | ipc_data_t saved_data;
|
---|
| 663 | bool saved;
|
---|
| 664 |
|
---|
[9f22213] | 665 | if (answer_need_old(call)) {
|
---|
[2ba7810] | 666 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 667 | saved = true;
|
---|
| 668 | } else
|
---|
| 669 | saved = false;
|
---|
| 670 |
|
---|
| 671 | int rc = copy_from_uspace(&call->data.args, &data->args,
|
---|
[51ec40f] | 672 | sizeof(call->data.args));
|
---|
[e3c762cd] | 673 | if (rc != 0)
|
---|
| 674 | return rc;
|
---|
[da1bafb] | 675 |
|
---|
| 676 | rc = answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[2d5a54f3] | 677 |
|
---|
| 678 | ipc_answer(&TASK->answerbox, call);
|
---|
[7c23af9] | 679 | return rc;
|
---|
[2d5a54f3] | 680 | }
|
---|
| 681 |
|
---|
[8b243f2] | 682 | /** Hang up a phone.
|
---|
[2d5a54f3] | 683 | *
|
---|
[da1bafb] | 684 | * @param Phone handle of the phone to be hung up.
|
---|
| 685 | *
|
---|
| 686 | * @return 0 on success or an error code.
|
---|
[8b243f2] | 687 | *
|
---|
[fbcfd458] | 688 | */
|
---|
[96b02eb9] | 689 | sysarg_t sys_ipc_hangup(sysarg_t phoneid)
|
---|
[fbcfd458] | 690 | {
|
---|
| 691 | phone_t *phone;
|
---|
[da1bafb] | 692 |
|
---|
[c9fff17] | 693 | if (phone_get(phoneid, &phone) != EOK)
|
---|
| 694 | return ENOENT;
|
---|
[da1bafb] | 695 |
|
---|
[d8f7362] | 696 | if (ipc_phone_hangup(phone))
|
---|
[fbcfd458] | 697 | return -1;
|
---|
[da1bafb] | 698 |
|
---|
[fbcfd458] | 699 | return 0;
|
---|
| 700 | }
|
---|
| 701 |
|
---|
[8b243f2] | 702 | /** Wait for an incoming IPC call or an answer.
|
---|
[fbcfd458] | 703 | *
|
---|
[da1bafb] | 704 | * @param calldata Pointer to buffer where the call/answer data is stored.
|
---|
| 705 | * @param usec Timeout. See waitq_sleep_timeout() for explanation.
|
---|
| 706 | * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
|
---|
| 707 | * for explanation.
|
---|
| 708 | *
|
---|
| 709 | * @return Hash of the call.
|
---|
| 710 | * If IPC_CALLID_NOTIFICATION bit is set in the hash, the
|
---|
| 711 | * call is a notification. IPC_CALLID_ANSWERED denotes an
|
---|
| 712 | * answer.
|
---|
[bd5a663] | 713 | *
|
---|
[2d5a54f3] | 714 | */
|
---|
[96b02eb9] | 715 | sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
|
---|
[da1bafb] | 716 | unsigned int flags)
|
---|
[2d5a54f3] | 717 | {
|
---|
| 718 | call_t *call;
|
---|
[da1bafb] | 719 |
|
---|
[741fd16] | 720 | restart:
|
---|
[da1bafb] | 721 |
|
---|
[741fd16] | 722 | #ifdef CONFIG_UDEBUG
|
---|
| 723 | udebug_stoppable_begin();
|
---|
[da1bafb] | 724 | #endif
|
---|
| 725 |
|
---|
[51ec40f] | 726 | call = ipc_wait_for_call(&TASK->answerbox, usec,
|
---|
| 727 | flags | SYNCH_FLAGS_INTERRUPTIBLE);
|
---|
[da1bafb] | 728 |
|
---|
[741fd16] | 729 | #ifdef CONFIG_UDEBUG
|
---|
| 730 | udebug_stoppable_end();
|
---|
| 731 | #endif
|
---|
[da1bafb] | 732 |
|
---|
[9f22213] | 733 | if (!call)
|
---|
| 734 | return 0;
|
---|
[da1bafb] | 735 |
|
---|
[5626277] | 736 | if (call->flags & IPC_CALL_NOTIF) {
|
---|
[43752b6] | 737 | /* Set in_phone_hash to the interrupt counter */
|
---|
[0c1a5d8a] | 738 | call->data.phone = (void *) call->priv;
|
---|
[43752b6] | 739 |
|
---|
| 740 | STRUCT_TO_USPACE(calldata, &call->data);
|
---|
[da1bafb] | 741 |
|
---|
[5626277] | 742 | ipc_call_free(call);
|
---|
| 743 |
|
---|
[96b02eb9] | 744 | return ((sysarg_t) call) | IPC_CALLID_NOTIFICATION;
|
---|
[5626277] | 745 | }
|
---|
[da1bafb] | 746 |
|
---|
[2d5a54f3] | 747 | if (call->flags & IPC_CALL_ANSWERED) {
|
---|
[7c7aae16] | 748 | process_answer(call);
|
---|
[da1bafb] | 749 |
|
---|
[fbcfd458] | 750 | if (call->flags & IPC_CALL_DISCARD_ANSWER) {
|
---|
| 751 | ipc_call_free(call);
|
---|
| 752 | goto restart;
|
---|
| 753 | }
|
---|
[da1bafb] | 754 |
|
---|
[fbcfd458] | 755 | STRUCT_TO_USPACE(&calldata->args, &call->data.args);
|
---|
[2d5a54f3] | 756 | ipc_call_free(call);
|
---|
[da1bafb] | 757 |
|
---|
[96b02eb9] | 758 | return ((sysarg_t) call) | IPC_CALLID_ANSWERED;
|
---|
[2d5a54f3] | 759 | }
|
---|
[da1bafb] | 760 |
|
---|
[2d5a54f3] | 761 | if (process_request(&TASK->answerbox, call))
|
---|
| 762 | goto restart;
|
---|
[da1bafb] | 763 |
|
---|
[7c7aae16] | 764 | /* Include phone address('id') of the caller in the request,
|
---|
| 765 | * copy whole call->data, not only call->data.args */
|
---|
[bd55bbb] | 766 | if (STRUCT_TO_USPACE(calldata, &call->data)) {
|
---|
[e06da7e] | 767 | /*
|
---|
| 768 | * The callee will not receive this call and no one else has
|
---|
| 769 | * a chance to answer it. Reply with the EPARTY error code.
|
---|
[b11ee88] | 770 | */
|
---|
[e06da7e] | 771 | ipc_data_t saved_data;
|
---|
[da1bafb] | 772 | bool saved;
|
---|
| 773 |
|
---|
[e06da7e] | 774 | if (answer_need_old(call)) {
|
---|
| 775 | memcpy(&saved_data, &call->data, sizeof(call->data));
|
---|
[da1bafb] | 776 | saved = true;
|
---|
| 777 | } else
|
---|
| 778 | saved = false;
|
---|
[e06da7e] | 779 |
|
---|
| 780 | IPC_SET_RETVAL(call->data, EPARTY);
|
---|
[da1bafb] | 781 | (void) answer_preprocess(call, saved ? &saved_data : NULL);
|
---|
[e06da7e] | 782 | ipc_answer(&TASK->answerbox, call);
|
---|
[bd55bbb] | 783 | return 0;
|
---|
| 784 | }
|
---|
[da1bafb] | 785 |
|
---|
[96b02eb9] | 786 | return (sysarg_t) call;
|
---|
[2d5a54f3] | 787 | }
|
---|
[5626277] | 788 |
|
---|
[da1bafb] | 789 | /** Interrupt one thread from sys_ipc_wait_for_call().
|
---|
| 790 | *
|
---|
| 791 | */
|
---|
[96b02eb9] | 792 | sysarg_t sys_ipc_poke(void)
|
---|
[057d21a] | 793 | {
|
---|
[da1bafb] | 794 | waitq_unsleep(&TASK->answerbox.wq);
|
---|
[057d21a] | 795 | return EOK;
|
---|
| 796 | }
|
---|
| 797 |
|
---|
[8b243f2] | 798 | /** Connect an IRQ handler to a task.
|
---|
[2b017ba] | 799 | *
|
---|
[228e490] | 800 | * @param inr IRQ number.
|
---|
| 801 | * @param devno Device number.
|
---|
| 802 | * @param imethod Interface and method to be associated with the notification.
|
---|
| 803 | * @param ucode Uspace pointer to the top-half pseudocode.
|
---|
[da1bafb] | 804 | *
|
---|
[8820544] | 805 | * @return EPERM or a return code returned by ipc_irq_subscribe().
|
---|
[2b017ba] | 806 | *
|
---|
| 807 | */
|
---|
[8820544] | 808 | sysarg_t sys_ipc_irq_subscribe(inr_t inr, devno_t devno, sysarg_t imethod,
|
---|
[51ec40f] | 809 | irq_code_t *ucode)
|
---|
[5626277] | 810 | {
|
---|
[2bb8648] | 811 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
---|
| 812 | return EPERM;
|
---|
[da1bafb] | 813 |
|
---|
[8820544] | 814 | return ipc_irq_subscribe(&TASK->answerbox, inr, devno, imethod, ucode);
|
---|
[5626277] | 815 | }
|
---|
| 816 |
|
---|
[8b243f2] | 817 | /** Disconnect an IRQ handler from a task.
|
---|
| 818 | *
|
---|
[da1bafb] | 819 | * @param inr IRQ number.
|
---|
| 820 | * @param devno Device number.
|
---|
| 821 | *
|
---|
| 822 | * @return Zero on success or EPERM on error.
|
---|
[2b017ba] | 823 | *
|
---|
| 824 | */
|
---|
[8820544] | 825 | sysarg_t sys_ipc_irq_unsubscribe(inr_t inr, devno_t devno)
|
---|
[5626277] | 826 | {
|
---|
[2bb8648] | 827 | if (!(cap_get(TASK) & CAP_IRQ_REG))
|
---|
| 828 | return EPERM;
|
---|
[da1bafb] | 829 |
|
---|
[8820544] | 830 | ipc_irq_unsubscribe(&TASK->answerbox, inr, devno);
|
---|
[da1bafb] | 831 |
|
---|
[5626277] | 832 | return 0;
|
---|
| 833 | }
|
---|
[b45c443] | 834 |
|
---|
[6b10dab] | 835 | #ifdef __32_BITS__
|
---|
[9a1b20c] | 836 |
|
---|
[6b10dab] | 837 | /** Syscall connect to a task by ID (32 bits)
|
---|
[da1bafb] | 838 | *
|
---|
| 839 | * @return Phone id on success, or negative error code.
|
---|
[9a1b20c] | 840 | *
|
---|
| 841 | */
|
---|
[6b10dab] | 842 | sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
|
---|
[9a1b20c] | 843 | {
|
---|
| 844 | #ifdef CONFIG_UDEBUG
|
---|
[6b10dab] | 845 | sysarg64_t taskid;
|
---|
| 846 | int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
|
---|
[9a1b20c] | 847 | if (rc != 0)
|
---|
[96b02eb9] | 848 | return (sysarg_t) rc;
|
---|
[da1bafb] | 849 |
|
---|
[6b10dab] | 850 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
[9a1b20c] | 851 | #else
|
---|
[96b02eb9] | 852 | return (sysarg_t) ENOTSUP;
|
---|
[9a1b20c] | 853 | #endif
|
---|
| 854 | }
|
---|
| 855 |
|
---|
[6b10dab] | 856 | #endif /* __32_BITS__ */
|
---|
| 857 |
|
---|
| 858 | #ifdef __64_BITS__
|
---|
| 859 |
|
---|
| 860 | /** Syscall connect to a task by ID (64 bits)
|
---|
| 861 | *
|
---|
| 862 | * @return Phone id on success, or negative error code.
|
---|
| 863 | *
|
---|
| 864 | */
|
---|
| 865 | sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
|
---|
| 866 | {
|
---|
| 867 | #ifdef CONFIG_UDEBUG
|
---|
| 868 | return ipc_connect_kbox((task_id_t) taskid);
|
---|
| 869 | #else
|
---|
| 870 | return (sysarg_t) ENOTSUP;
|
---|
| 871 | #endif
|
---|
| 872 | }
|
---|
| 873 |
|
---|
| 874 | #endif /* __64_BITS__ */
|
---|
| 875 |
|
---|
[cc73a8a1] | 876 | /** @}
|
---|
[b45c443] | 877 | */
|
---|