source: mainline/kernel/generic/src/ipc/sysipc.c@ 6b10dab

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 6b10dab was 6b10dab, checked in by Martin Decky <martin@…>, 15 years ago

ABI split: pass 64-bit task ID as plain 64-bit argument to SYS_IPC_CONNECT_KBOX, SYS_CAP_GRANT, SYS_CAP_REVOKE

  • Property mode set to 100644
File size: 30.9 KB
RevLine 
[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 <proc/task.h>
[e3c762cd]37#include <proc/thread.h>
[2d5a54f3]38#include <errno.h>
39#include <memstr.h>
40#include <debug.h>
41#include <ipc/ipc.h>
42#include <ipc/sysipc.h>
[162f919]43#include <ipc/irq.h>
[4e49572]44#include <ipc/ipcrsc.h>
[e028660]45#include <ipc/kbox.h>
[057d21a]46#include <synch/waitq.h>
[9a1b20c]47#include <udebug/udebug_ipc.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>
[7c23af9]52#include <mm/as.h>
[253f35a1]53#include <print.h>
[2d5a54f3]54
[36d852c]55/**
56 * Maximum buffer size allowed for IPC_M_DATA_WRITE and IPC_M_DATA_READ
57 * requests.
58 */
[da1bafb]59#define DATA_XFER_LIMIT (64 * 1024)
60
61#define STRUCT_TO_USPACE(dst, src) copy_to_uspace((dst), (src), sizeof(*(src)))
[7918fce]62
[c9fff17]63/** Get phone from the current task by ID.
64 *
[da1bafb]65 * @param phoneid Phone ID.
66 * @param phone Place to store pointer to phone.
67 *
68 * @return EOK on success, EINVAL if ID is invalid.
69 *
[c9fff17]70 */
[96b02eb9]71static int phone_get(sysarg_t phoneid, phone_t **phone)
[c9fff17]72{
73 if (phoneid >= IPC_MAX_PHONES)
74 return EINVAL;
[da1bafb]75
[c9fff17]76 *phone = &TASK->phones[phoneid];
77 return EOK;
[ba81cab]78}
79
[8b243f2]80/** Decide if the method is a system method.
81 *
[da1bafb]82 * @param method Method to be decided.
83 *
84 * @return true if the method is a system method.
[8b243f2]85 *
86 */
[96b02eb9]87static inline bool method_is_system(sysarg_t method)
[2ba7810]88{
89 if (method <= IPC_M_LAST_SYSTEM)
[da1bafb]90 return true;
91
92 return false;
[2ba7810]93}
94
[8b243f2]95/** Decide if the message with this method is forwardable.
[2ba7810]96 *
97 * - some system messages may be forwarded, for some of them
98 * it is useless
[8b243f2]99 *
[da1bafb]100 * @param method Method to be decided.
101 *
102 * @return true if the method is forwardable.
[8b243f2]103 *
[2ba7810]104 */
[96b02eb9]105static inline bool method_is_forwardable(sysarg_t method)
[2ba7810]106{
[7918fce]107 switch (method) {
[2c0e5d2]108 case IPC_M_CONNECTION_CLONE:
109 case IPC_M_CONNECT_ME:
[7918fce]110 case IPC_M_PHONE_HUNGUP:
111 /* This message is meant only for the original recipient. */
[da1bafb]112 return false;
[7918fce]113 default:
[da1bafb]114 return true;
[7918fce]115 }
[2ba7810]116}
117
[0dc4258]118/** Decide if the message with this method is immutable on forward.
119 *
[7c5bcc0]120 * - some system messages may be forwarded but their content cannot be altered
[0dc4258]121 *
[da1bafb]122 * @param method Method to be decided.
123 *
124 * @return true if the method is immutable on forward.
[0dc4258]125 *
126 */
[96b02eb9]127static inline bool method_is_immutable(sysarg_t method)
[0dc4258]128{
129 switch (method) {
[27d293a]130 case IPC_M_SHARE_OUT:
131 case IPC_M_SHARE_IN:
[36d852c]132 case IPC_M_DATA_WRITE:
133 case IPC_M_DATA_READ:
[da1bafb]134 return true;
[0dc4258]135 default:
[da1bafb]136 return false;
[0dc4258]137 }
138}
139
[2d5a54f3]140
[8b243f2]141/***********************************************************************
142 * Functions that preprocess answer before sending it to the recepient.
143 ***********************************************************************/
144
145/** Decide if the caller (e.g. ipc_answer()) should save the old call contents
146 * for answer_preprocess().
147 *
[da1bafb]148 * @param call Call structure to be decided.
149 *
150 * @return true if the old call contents should be saved.
[8b243f2]151 *
[2d5a54f3]152 */
[da1bafb]153static inline bool answer_need_old(call_t *call)
[2d5a54f3]154{
[7918fce]155 switch (IPC_GET_METHOD(call->data)) {
[2c0e5d2]156 case IPC_M_CONNECTION_CLONE:
157 case IPC_M_CONNECT_ME:
[7918fce]158 case IPC_M_CONNECT_TO_ME:
159 case IPC_M_CONNECT_ME_TO:
[27d293a]160 case IPC_M_SHARE_OUT:
161 case IPC_M_SHARE_IN:
[36d852c]162 case IPC_M_DATA_WRITE:
163 case IPC_M_DATA_READ:
[da1bafb]164 return true;
[7918fce]165 default:
[da1bafb]166 return false;
[7918fce]167 }
[2d5a54f3]168}
169
[8b243f2]170/** Interpret process answer as control information.
171 *
172 * This function is called directly after sys_ipc_answer().
[46fc2f9]173 *
[da1bafb]174 * @param answer Call structure with the answer.
175 * @param olddata Saved data of the request.
176 *
177 * @return Return 0 on success or an error code.
[8b243f2]178 *
[46fc2f9]179 */
[7c23af9]180static inline int answer_preprocess(call_t *answer, ipc_data_t *olddata)
[2d5a54f3]181{
[6c441cf8]182 if ((native_t) IPC_GET_RETVAL(answer->data) == EHANGUP) {
[ca687ad]183 /* In case of forward, hangup the forwared phone,
184 * not the originator
185 */
[ff48a15]186 mutex_lock(&answer->data.phone->lock);
[da1bafb]187 irq_spinlock_lock(&TASK->answerbox.lock, true);
[eb3d379]188 if (answer->data.phone->state == IPC_PHONE_CONNECTED) {
[c4e4507]189 list_remove(&answer->data.phone->link);
[eb3d379]190 answer->data.phone->state = IPC_PHONE_SLAMMED;
[ca687ad]191 }
[da1bafb]192 irq_spinlock_unlock(&TASK->answerbox.lock, true);
[ff48a15]193 mutex_unlock(&answer->data.phone->lock);
[9f22213]194 }
[da1bafb]195
[9f22213]196 if (!olddata)
[7c23af9]197 return 0;
[da1bafb]198
[2c0e5d2]199 if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECTION_CLONE) {
[da1bafb]200 int phoneid = IPC_GET_ARG1(*olddata);
201 phone_t *phone = &TASK->phones[phoneid];
202
[2c0e5d2]203 if (IPC_GET_RETVAL(answer->data) != EOK) {
204 /*
205 * The recipient of the cloned phone rejected the offer.
206 * In this case, the connection was established at the
207 * request time and therefore we need to slam the phone.
208 * We don't merely hangup as that would result in
209 * sending IPC_M_HUNGUP to the third party on the
210 * other side of the cloned phone.
211 */
212 mutex_lock(&phone->lock);
213 if (phone->state == IPC_PHONE_CONNECTED) {
[da1bafb]214 irq_spinlock_lock(&phone->callee->lock, true);
[2c0e5d2]215 list_remove(&phone->link);
216 phone->state = IPC_PHONE_SLAMMED;
[da1bafb]217 irq_spinlock_unlock(&phone->callee->lock, true);
[2c0e5d2]218 }
219 mutex_unlock(&phone->lock);
220 }
221 } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME) {
[da1bafb]222 phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
223
[2c0e5d2]224 if (IPC_GET_RETVAL(answer->data) != EOK) {
225 /*
226 * The other party on the cloned phoned rejected our
227 * request for connection on the protocol level.
228 * We need to break the connection without sending
229 * IPC_M_HUNGUP back.
230 */
231 mutex_lock(&phone->lock);
232 if (phone->state == IPC_PHONE_CONNECTED) {
[da1bafb]233 irq_spinlock_lock(&phone->callee->lock, true);
[2c0e5d2]234 list_remove(&phone->link);
235 phone->state = IPC_PHONE_SLAMMED;
[da1bafb]236 irq_spinlock_unlock(&phone->callee->lock, true);
[2c0e5d2]237 }
238 mutex_unlock(&phone->lock);
239 }
240 } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_TO_ME) {
[da1bafb]241 int phoneid = IPC_GET_ARG5(*olddata);
242
[2c0e5d2]243 if (IPC_GET_RETVAL(answer->data) != EOK) {
[2d5a54f3]244 /* The connection was not accepted */
245 phone_dealloc(phoneid);
[2ba7810]246 } else {
[7c7aae16]247 /* The connection was accepted */
[51ec40f]248 phone_connect(phoneid, &answer->sender->answerbox);
[6364d3c]249 /* Set 'phone hash' as arg5 of response */
[38c706cc]250 IPC_SET_ARG5(answer->data,
[96b02eb9]251 (sysarg_t) &TASK->phones[phoneid]);
[2d5a54f3]252 }
[fbcfd458]253 } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) {
[37c57f2]254 /* If the users accepted call, connect */
[2c0e5d2]255 if (IPC_GET_RETVAL(answer->data) == EOK) {
[b61d47d]256 ipc_phone_connect((phone_t *) IPC_GET_ARG5(*olddata),
[51ec40f]257 &TASK->answerbox);
[37c57f2]258 }
[27d293a]259 } else if (IPC_GET_METHOD(*olddata) == IPC_M_SHARE_OUT) {
[51ec40f]260 if (!IPC_GET_RETVAL(answer->data)) {
261 /* Accepted, handle as_area receipt */
[8d6bc2d5]262
[da1bafb]263 irq_spinlock_lock(&answer->sender->lock, true);
264 as_t *as = answer->sender->as;
265 irq_spinlock_unlock(&answer->sender->lock, true);
[8d6bc2d5]266
[da1bafb]267 int rc = as_area_share(as, IPC_GET_ARG1(*olddata),
[51ec40f]268 IPC_GET_ARG2(*olddata), AS,
269 IPC_GET_ARG1(answer->data), IPC_GET_ARG3(*olddata));
[76d7305]270 IPC_SET_RETVAL(answer->data, rc);
271 return rc;
[46fc2f9]272 }
[27d293a]273 } else if (IPC_GET_METHOD(*olddata) == IPC_M_SHARE_IN) {
[46fc2f9]274 if (!IPC_GET_RETVAL(answer->data)) {
[da1bafb]275 irq_spinlock_lock(&answer->sender->lock, true);
276 as_t *as = answer->sender->as;
277 irq_spinlock_unlock(&answer->sender->lock, true);
[46fc2f9]278
[da1bafb]279 int rc = as_area_share(AS, IPC_GET_ARG1(answer->data),
[51ec40f]280 IPC_GET_ARG2(*olddata), as, IPC_GET_ARG1(*olddata),
281 IPC_GET_ARG2(answer->data));
[d6e5cbc]282 IPC_SET_RETVAL(answer->data, rc);
[7c23af9]283 }
[a55d5f9f]284 } else if (IPC_GET_METHOD(*olddata) == IPC_M_DATA_READ) {
285 ASSERT(!answer->buffer);
286 if (!IPC_GET_RETVAL(answer->data)) {
287 /* The recipient agreed to send data. */
288 uintptr_t src = IPC_GET_ARG1(answer->data);
289 uintptr_t dst = IPC_GET_ARG1(*olddata);
290 size_t max_size = IPC_GET_ARG2(*olddata);
291 size_t size = IPC_GET_ARG2(answer->data);
[1a60feeb]292 if (size && size <= max_size) {
[a55d5f9f]293 /*
294 * Copy the destination VA so that this piece of
295 * information is not lost.
296 */
297 IPC_SET_ARG1(answer->data, dst);
[da1bafb]298
[a55d5f9f]299 answer->buffer = malloc(size, 0);
300 int rc = copy_from_uspace(answer->buffer,
301 (void *) src, size);
302 if (rc) {
303 IPC_SET_RETVAL(answer->data, rc);
304 free(answer->buffer);
305 answer->buffer = NULL;
306 }
[1a60feeb]307 } else if (!size) {
308 IPC_SET_RETVAL(answer->data, EOK);
[a55d5f9f]309 } else {
310 IPC_SET_RETVAL(answer->data, ELIMIT);
311 }
312 }
[36d852c]313 } else if (IPC_GET_METHOD(*olddata) == IPC_M_DATA_WRITE) {
[654b7db]314 ASSERT(answer->buffer);
[7918fce]315 if (!IPC_GET_RETVAL(answer->data)) {
[a55d5f9f]316 /* The recipient agreed to receive data. */
[da1bafb]317 uintptr_t dst = (uintptr_t)IPC_GET_ARG1(answer->data);
318 size_t size = (size_t)IPC_GET_ARG2(answer->data);
319 size_t max_size = (size_t)IPC_GET_ARG2(*olddata);
320
[a55d5f9f]321 if (size <= max_size) {
[da1bafb]322 int rc = copy_to_uspace((void *) dst,
[a55d5f9f]323 answer->buffer, size);
324 if (rc)
325 IPC_SET_RETVAL(answer->data, rc);
326 } else {
327 IPC_SET_RETVAL(answer->data, ELIMIT);
328 }
[7918fce]329 }
[654b7db]330 free(answer->buffer);
331 answer->buffer = NULL;
[2d5a54f3]332 }
[da1bafb]333
[7c23af9]334 return 0;
[2d5a54f3]335}
336
[bf1fb9f]337static void phones_lock(phone_t *p1, phone_t *p2)
338{
339 if (p1 < p2) {
340 mutex_lock(&p1->lock);
341 mutex_lock(&p2->lock);
342 } else if (p1 > p2) {
343 mutex_lock(&p2->lock);
344 mutex_lock(&p1->lock);
[da1bafb]345 } else
[bf1fb9f]346 mutex_lock(&p1->lock);
347}
348
349static void phones_unlock(phone_t *p1, phone_t *p2)
350{
351 mutex_unlock(&p1->lock);
352 if (p1 != p2)
353 mutex_unlock(&p2->lock);
354}
355
[8b243f2]356/** Called before the request is sent.
357 *
[da1bafb]358 * @param call Call structure with the request.
359 * @param phone Phone that the call will be sent through.
360 *
361 * @return Return 0 on success, ELIMIT or EPERM on error.
[7c7aae16]362 *
363 */
[9a1b20c]364static int request_preprocess(call_t *call, phone_t *phone)
[7c7aae16]365{
366 switch (IPC_GET_METHOD(call->data)) {
[2c0e5d2]367 case IPC_M_CONNECTION_CLONE: {
368 phone_t *cloned_phone;
[c9fff17]369 if (phone_get(IPC_GET_ARG1(call->data), &cloned_phone) != EOK)
370 return ENOENT;
[da1bafb]371
[bf1fb9f]372 phones_lock(cloned_phone, phone);
[da1bafb]373
[2c0e5d2]374 if ((cloned_phone->state != IPC_PHONE_CONNECTED) ||
375 phone->state != IPC_PHONE_CONNECTED) {
[bf1fb9f]376 phones_unlock(cloned_phone, phone);
[2c0e5d2]377 return EINVAL;
378 }
[da1bafb]379
[2c0e5d2]380 /*
381 * We can be pretty sure now that both tasks exist and we are
382 * connected to them. As we continue to hold the phone locks,
383 * we are effectively preventing them from finishing their
384 * potential cleanup.
[da1bafb]385 *
[2c0e5d2]386 */
[da1bafb]387 int newphid = phone_alloc(phone->callee->task);
[2c0e5d2]388 if (newphid < 0) {
[bf1fb9f]389 phones_unlock(cloned_phone, phone);
[2c0e5d2]390 return ELIMIT;
391 }
[da1bafb]392
[2c0e5d2]393 ipc_phone_connect(&phone->callee->task->phones[newphid],
394 cloned_phone->callee);
[bf1fb9f]395 phones_unlock(cloned_phone, phone);
[da1bafb]396
[2c0e5d2]397 /* Set the new phone for the callee. */
398 IPC_SET_ARG1(call->data, newphid);
399 break;
400 }
401 case IPC_M_CONNECT_ME:
[96b02eb9]402 IPC_SET_ARG5(call->data, (sysarg_t) phone);
[2c0e5d2]403 break;
[da1bafb]404 case IPC_M_CONNECT_ME_TO: {
405 int newphid = phone_alloc(TASK);
[7c7aae16]406 if (newphid < 0)
407 return ELIMIT;
[da1bafb]408
[6364d3c]409 /* Set arg5 for server */
[96b02eb9]410 IPC_SET_ARG5(call->data, (sysarg_t) &TASK->phones[newphid]);
[7c7aae16]411 call->flags |= IPC_CALL_CONN_ME_TO;
[0c1a5d8a]412 call->priv = newphid;
[7c7aae16]413 break;
[da1bafb]414 }
415 case IPC_M_SHARE_OUT: {
416 size_t size = as_area_get_size(IPC_GET_ARG1(call->data));
[8b243f2]417 if (!size)
[7c23af9]418 return EPERM;
[da1bafb]419
[fd4d8c0]420 IPC_SET_ARG2(call->data, size);
[7c23af9]421 break;
[da1bafb]422 }
423 case IPC_M_DATA_READ: {
424 size_t size = IPC_GET_ARG2(call->data);
[a55d5f9f]425 if ((size <= 0 || (size > DATA_XFER_LIMIT)))
426 return ELIMIT;
[da1bafb]427
[a55d5f9f]428 break;
[da1bafb]429 }
430 case IPC_M_DATA_WRITE: {
431 uintptr_t src = IPC_GET_ARG1(call->data);
432 size_t size = IPC_GET_ARG2(call->data);
[7918fce]433
[6b6e423a]434 if (size > DATA_XFER_LIMIT)
[7918fce]435 return ELIMIT;
436
437 call->buffer = (uint8_t *) malloc(size, 0);
[da1bafb]438 int rc = copy_from_uspace(call->buffer, (void *) src, size);
[7918fce]439 if (rc != 0) {
440 free(call->buffer);
441 return rc;
442 }
[da1bafb]443
[7918fce]444 break;
[da1bafb]445 }
[9a1b20c]446#ifdef CONFIG_UDEBUG
447 case IPC_M_DEBUG_ALL:
448 return udebug_request_preprocess(call, phone);
449#endif
[7c7aae16]450 default:
451 break;
452 }
[da1bafb]453
[7c7aae16]454 return 0;
455}
456
[8b243f2]457/*******************************************************************************
458 * Functions called to process received call/answer before passing it to uspace.
459 *******************************************************************************/
[2d5a54f3]460
[8b243f2]461/** Do basic kernel processing of received call answer.
462 *
[da1bafb]463 * @param call Call structure with the answer.
464 *
[8b243f2]465 */
[7c7aae16]466static void process_answer(call_t *call)
[2d5a54f3]467{
[6c441cf8]468 if (((native_t) IPC_GET_RETVAL(call->data) == EHANGUP) &&
[51ec40f]469 (call->flags & IPC_CALL_FORWARDED))
[9f22213]470 IPC_SET_RETVAL(call->data, EFORWARD);
[da1bafb]471
[7c7aae16]472 if (call->flags & IPC_CALL_CONN_ME_TO) {
473 if (IPC_GET_RETVAL(call->data))
[0c1a5d8a]474 phone_dealloc(call->priv);
[7c7aae16]475 else
[b61d47d]476 IPC_SET_ARG5(call->data, call->priv);
[7c7aae16]477 }
[da1bafb]478
[a55d5f9f]479 if (call->buffer) {
[da1bafb]480 /*
481 * This must be an affirmative answer to IPC_M_DATA_READ
482 * or IPC_M_DEBUG_ALL/UDEBUG_M_MEM_READ...
483 *
484 */
[a55d5f9f]485 uintptr_t dst = IPC_GET_ARG1(call->data);
486 size_t size = IPC_GET_ARG2(call->data);
487 int rc = copy_to_uspace((void *) dst, call->buffer, size);
488 if (rc)
489 IPC_SET_RETVAL(call->data, rc);
490 free(call->buffer);
491 call->buffer = NULL;
492 }
[2d5a54f3]493}
494
[8b243f2]495/** Do basic kernel processing of received call request.
496 *
[da1bafb]497 * @param box Destination answerbox structure.
498 * @param call Call structure with the request.
499 *
500 * @return 0 if the call should be passed to userspace.
501 * @return -1 if the call should be ignored.
[2d5a54f3]502 *
503 */
[51ec40f]504static int process_request(answerbox_t *box, call_t *call)
[2d5a54f3]505{
[fbcfd458]506 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) {
[da1bafb]507 int phoneid = phone_alloc(TASK);
[2d5a54f3]508 if (phoneid < 0) { /* Failed to allocate phone */
509 IPC_SET_RETVAL(call->data, ELIMIT);
[8b243f2]510 ipc_answer(box, call);
[2d5a54f3]511 return -1;
512 }
[da1bafb]513
[38c706cc]514 IPC_SET_ARG5(call->data, phoneid);
[9a1b20c]515 }
[da1bafb]516
[9a1b20c]517 switch (IPC_GET_METHOD(call->data)) {
518 case IPC_M_DEBUG_ALL:
519 return -1;
520 default:
521 break;
522 }
[da1bafb]523
[2d5a54f3]524 return 0;
525}
526
[8b243f2]527/** Make a fast call over IPC, wait for reply and return to user.
528 *
[2e51969]529 * This function can handle only three arguments of payload, but is faster than
530 * the generic function (i.e. sys_ipc_call_sync_slow()).
[2d5a54f3]531 *
[da1bafb]532 * @param phoneid Phone handle for the call.
533 * @param method Method of the call.
534 * @param arg1 Service-defined payload argument.
535 * @param arg2 Service-defined payload argument.
536 * @param arg3 Service-defined payload argument.
537 * @param data Address of userspace structure where the reply call will
538 * be stored.
539 *
540 * @return 0 on success.
541 * @return ENOENT if there is no such phone handle.
[8b243f2]542 *
[2d5a54f3]543 */
[96b02eb9]544sysarg_t sys_ipc_call_sync_fast(sysarg_t phoneid, sysarg_t method,
545 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, ipc_data_t *data)
[2d5a54f3]546{
547 phone_t *phone;
[c9fff17]548 if (phone_get(phoneid, &phone) != EOK)
549 return ENOENT;
[4e49572]550
[da1bafb]551 call_t *call = ipc_call_alloc(0);
[35bb2e7]552 IPC_SET_METHOD(call->data, method);
553 IPC_SET_ARG1(call->data, arg1);
554 IPC_SET_ARG2(call->data, arg2);
555 IPC_SET_ARG3(call->data, arg3);
[da1bafb]556
[8498915]557 /*
558 * To achieve deterministic behavior, zero out arguments that are beyond
559 * the limits of the fast version.
560 */
[35bb2e7]561 IPC_SET_ARG4(call->data, 0);
562 IPC_SET_ARG5(call->data, 0);
[da1bafb]563
564 int res = request_preprocess(call, phone);
565 int rc;
566
567 if (!res) {
[741fd16]568#ifdef CONFIG_UDEBUG
569 udebug_stoppable_begin();
570#endif
[35bb2e7]571 rc = ipc_call_sync(phone, call);
[741fd16]572#ifdef CONFIG_UDEBUG
573 udebug_stoppable_end();
574#endif
[da1bafb]575
[35bb2e7]576 if (rc != EOK) {
[33adc6ce]577 /* The call will be freed by ipc_cleanup(). */
[79872cd]578 return rc;
[35bb2e7]579 }
[da1bafb]580
[35bb2e7]581 process_answer(call);
[da1bafb]582
583 } else
[35bb2e7]584 IPC_SET_RETVAL(call->data, res);
[da1bafb]585
[35bb2e7]586 rc = STRUCT_TO_USPACE(&data->args, &call->data.args);
587 ipc_call_free(call);
[bc50fc42]588 if (rc != 0)
589 return rc;
[da1bafb]590
[2d5a54f3]591 return 0;
592}
593
[8b243f2]594/** Make a synchronous IPC call allowing to transmit the entire payload.
595 *
[da1bafb]596 * @param phoneid Phone handle for the call.
597 * @param question Userspace address of call data with the request.
598 * @param reply Userspace address of call data where to store the
599 * answer.
600 *
601 * @return Zero on success or an error code.
[8b243f2]602 *
603 */
[96b02eb9]604sysarg_t sys_ipc_call_sync_slow(sysarg_t phoneid, ipc_data_t *question,
[51ec40f]605 ipc_data_t *reply)
[2d5a54f3]606{
607 phone_t *phone;
[c9fff17]608 if (phone_get(phoneid, &phone) != EOK)
609 return ENOENT;
[35bb2e7]610
[da1bafb]611 call_t *call = ipc_call_alloc(0);
612 int rc = copy_from_uspace(&call->data.args, &question->args,
[35bb2e7]613 sizeof(call->data.args));
614 if (rc != 0) {
615 ipc_call_free(call);
[96b02eb9]616 return (sysarg_t) rc;
[35bb2e7]617 }
[da1bafb]618
619 int res = request_preprocess(call, phone);
620
621 if (!res) {
[741fd16]622#ifdef CONFIG_UDEBUG
623 udebug_stoppable_begin();
624#endif
[35bb2e7]625 rc = ipc_call_sync(phone, call);
[741fd16]626#ifdef CONFIG_UDEBUG
627 udebug_stoppable_end();
628#endif
[da1bafb]629
[35bb2e7]630 if (rc != EOK) {
[33adc6ce]631 /* The call will be freed by ipc_cleanup(). */
[79872cd]632 return rc;
[35bb2e7]633 }
[da1bafb]634
[35bb2e7]635 process_answer(call);
[da1bafb]636 } else
[35bb2e7]637 IPC_SET_RETVAL(call->data, res);
[da1bafb]638
[35bb2e7]639 rc = STRUCT_TO_USPACE(&reply->args, &call->data.args);
640 ipc_call_free(call);
[e3c762cd]641 if (rc != 0)
642 return rc;
[da1bafb]643
[2d5a54f3]644 return 0;
645}
646
[97d17fe]647/** Check that the task did not exceed the allowed limit of asynchronous calls
648 * made over a phone.
[2d5a54f3]649 *
[97d17fe]650 * @param phone Phone to check the limit against.
[da1bafb]651 * @return 0 if limit not reached or -1 if limit exceeded.
652 *
[2d5a54f3]653 */
[97d17fe]654static int check_call_limit(phone_t *phone)
[2d5a54f3]655{
[97d17fe]656 if (atomic_get(&phone->active_calls) >= IPC_MAX_ASYNC_CALLS)
[2d5a54f3]657 return -1;
[da1bafb]658
[2d5a54f3]659 return 0;
660}
661
[8b243f2]662/** Make a fast asynchronous call over IPC.
[2d5a54f3]663 *
[3209923]664 * This function can only handle four arguments of payload, but is faster than
665 * the generic function sys_ipc_call_async_slow().
[8b243f2]666 *
[da1bafb]667 * @param phoneid Phone handle for the call.
668 * @param method Method of the call.
669 * @param arg1 Service-defined payload argument.
670 * @param arg2 Service-defined payload argument.
671 * @param arg3 Service-defined payload argument.
672 * @param arg4 Service-defined payload argument.
673 *
674 * @return Call hash on success.
675 * @return IPC_CALLRET_FATAL in case of a fatal error.
676 * @return IPC_CALLRET_TEMPORARY if there are too many pending
677 * asynchronous requests; answers should be handled first.
678 *
[2d5a54f3]679 */
[96b02eb9]680sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t method,
681 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
[2d5a54f3]682{
[da1bafb]683 phone_t *phone;
[c9fff17]684 if (phone_get(phoneid, &phone) != EOK)
685 return IPC_CALLRET_FATAL;
[97d17fe]686
687 if (check_call_limit(phone))
688 return IPC_CALLRET_TEMPORARY;
[da1bafb]689
690 call_t *call = ipc_call_alloc(0);
[2d5a54f3]691 IPC_SET_METHOD(call->data, method);
692 IPC_SET_ARG1(call->data, arg1);
693 IPC_SET_ARG2(call->data, arg2);
[3209923]694 IPC_SET_ARG3(call->data, arg3);
695 IPC_SET_ARG4(call->data, arg4);
[da1bafb]696
[8498915]697 /*
698 * To achieve deterministic behavior, zero out arguments that are beyond
699 * the limits of the fast version.
700 */
701 IPC_SET_ARG5(call->data, 0);
[da1bafb]702
703 int res = request_preprocess(call, phone);
704
705 if (!res)
[7c7aae16]706 ipc_call(phone, call);
707 else
708 ipc_backsend_err(phone, call, res);
[da1bafb]709
[96b02eb9]710 return (sysarg_t) call;
[2d5a54f3]711}
712
[8b243f2]713/** Make an asynchronous IPC call allowing to transmit the entire payload.
714 *
[da1bafb]715 * @param phoneid Phone handle for the call.
716 * @param data Userspace address of call data with the request.
717 *
718 * @return See sys_ipc_call_async_fast().
[2d5a54f3]719 *
720 */
[96b02eb9]721sysarg_t sys_ipc_call_async_slow(sysarg_t phoneid, ipc_data_t *data)
[2d5a54f3]722{
[da1bafb]723 phone_t *phone;
[c9fff17]724 if (phone_get(phoneid, &phone) != EOK)
725 return IPC_CALLRET_FATAL;
[4e49572]726
[97d17fe]727 if (check_call_limit(phone))
728 return IPC_CALLRET_TEMPORARY;
729
[da1bafb]730 call_t *call = ipc_call_alloc(0);
731 int rc = copy_from_uspace(&call->data.args, &data->args,
[51ec40f]732 sizeof(call->data.args));
[f58af46]733 if (rc != 0) {
734 ipc_call_free(call);
[96b02eb9]735 return (sysarg_t) rc;
[f58af46]736 }
[da1bafb]737
738 int res = request_preprocess(call, phone);
739
740 if (!res)
[7c7aae16]741 ipc_call(phone, call);
742 else
743 ipc_backsend_err(phone, call, res);
[da1bafb]744
[96b02eb9]745 return (sysarg_t) call;
[2d5a54f3]746}
747
[da1bafb]748/** Forward a received call to another destination
749 *
750 * Common code for both the fast and the slow version.
751 *
752 * @param callid Hash of the call to forward.
753 * @param phoneid Phone handle to use for forwarding.
754 * @param method New method to use for the forwarded call.
755 * @param arg1 New value of the first argument for the forwarded call.
756 * @param arg2 New value of the second argument for the forwarded call.
757 * @param arg3 New value of the third argument for the forwarded call.
758 * @param arg4 New value of the fourth argument for the forwarded call.
759 * @param arg5 New value of the fifth argument for the forwarded call.
760 * @param mode Flags that specify mode of the forward operation.
761 * @param slow If true, arg3, arg4 and arg5 are considered. Otherwise
762 * the function considers only the fast version arguments:
763 * i.e. arg1 and arg2.
764 *
765 * @return 0 on succes, otherwise an error code.
766 *
767 * Warning: Make sure that ARG5 is not rewritten for certain system IPC
768 *
[2ba7810]769 */
[96b02eb9]770static sysarg_t sys_ipc_forward_common(sysarg_t callid, sysarg_t phoneid,
771 sysarg_t method, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
772 sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
[2ba7810]773{
[da1bafb]774 call_t *call = get_call(callid);
[2ba7810]775 if (!call)
776 return ENOENT;
[48daf64]777
[9f22213]778 call->flags |= IPC_CALL_FORWARDED;
[da1bafb]779
780 phone_t *phone;
[c9fff17]781 if (phone_get(phoneid, &phone) != EOK) {
[2ba7810]782 IPC_SET_RETVAL(call->data, EFORWARD);
783 ipc_answer(&TASK->answerbox, call);
784 return ENOENT;
[c9fff17]785 }
[da1bafb]786
[0dc4258]787 if (!method_is_forwardable(IPC_GET_METHOD(call->data))) {
[2ba7810]788 IPC_SET_RETVAL(call->data, EFORWARD);
789 ipc_answer(&TASK->answerbox, call);
790 return EPERM;
791 }
[da1bafb]792
[0dc4258]793 /*
794 * Userspace is not allowed to change method of system methods on
[48daf64]795 * forward, allow changing ARG1, ARG2, ARG3 and ARG4 by means of method,
796 * arg1, arg2 and arg3.
[0dc4258]797 * If the method is immutable, don't change anything.
[2ba7810]798 */
[0dc4258]799 if (!method_is_immutable(IPC_GET_METHOD(call->data))) {
800 if (method_is_system(IPC_GET_METHOD(call->data))) {
801 if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME)
[b61d47d]802 phone_dealloc(IPC_GET_ARG5(call->data));
[da1bafb]803
[0dc4258]804 IPC_SET_ARG1(call->data, method);
805 IPC_SET_ARG2(call->data, arg1);
[b61d47d]806 IPC_SET_ARG3(call->data, arg2);
[da1bafb]807
[48daf64]808 if (slow) {
809 IPC_SET_ARG4(call->data, arg3);
810 /*
811 * For system methods we deliberately don't
812 * overwrite ARG5.
813 */
814 }
[0dc4258]815 } else {
816 IPC_SET_METHOD(call->data, method);
817 IPC_SET_ARG1(call->data, arg1);
[b61d47d]818 IPC_SET_ARG2(call->data, arg2);
[48daf64]819 if (slow) {
820 IPC_SET_ARG3(call->data, arg3);
821 IPC_SET_ARG4(call->data, arg4);
822 IPC_SET_ARG5(call->data, arg5);
823 }
[0dc4258]824 }
[2ba7810]825 }
[da1bafb]826
[d40a8ff]827 return ipc_forward(call, phone, &TASK->answerbox, mode);
[2ba7810]828}
829
[48daf64]830/** Forward a received call to another destination - fast version.
831 *
832 * In case the original method is a system method, ARG1, ARG2 and ARG3 are
833 * overwritten in the forwarded message with the new method and the new
834 * arg1 and arg2, respectively. Otherwise the METHOD, ARG1 and ARG2 are
835 * rewritten with the new method, arg1 and arg2, respectively. Also note there
836 * is a set of immutable methods, for which the new method and arguments are not
837 * set and these values are ignored.
[da1bafb]838 *
839 * @param callid Hash of the call to forward.
840 * @param phoneid Phone handle to use for forwarding.
841 * @param method New method to use for the forwarded call.
842 * @param arg1 New value of the first argument for the forwarded call.
843 * @param arg2 New value of the second argument for the forwarded call.
844 * @param mode Flags that specify mode of the forward operation.
845 *
846 * @return 0 on succes, otherwise an error code.
847 *
[48daf64]848 */
[96b02eb9]849sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
850 sysarg_t method, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
[48daf64]851{
852 return sys_ipc_forward_common(callid, phoneid, method, arg1, arg2, 0, 0,
853 0, mode, false);
854}
855
856/** Forward a received call to another destination - slow version.
857 *
858 * This function is the slow verision of the sys_ipc_forward_fast interface.
859 * It can copy all five new arguments and the new method from the userspace.
860 * It naturally extends the functionality of the fast version. For system
861 * methods, it additionally stores the new value of arg3 to ARG4. For non-system
862 * methods, it additionally stores the new value of arg3, arg4 and arg5,
863 * respectively, to ARG3, ARG4 and ARG5, respectively.
[da1bafb]864 *
865 * @param callid Hash of the call to forward.
866 * @param phoneid Phone handle to use for forwarding.
867 * @param data Userspace address of the new IPC data.
868 * @param mode Flags that specify mode of the forward operation.
869 *
870 * @return 0 on succes, otherwise an error code.
871 *
[48daf64]872 */
[96b02eb9]873sysarg_t sys_ipc_forward_slow(sysarg_t callid, sysarg_t phoneid,
[da1bafb]874 ipc_data_t *data, unsigned int mode)
[48daf64]875{
876 ipc_data_t newdata;
[da1bafb]877 int rc = copy_from_uspace(&newdata.args, &data->args,
[48daf64]878 sizeof(newdata.args));
[da1bafb]879 if (rc != 0)
[96b02eb9]880 return (sysarg_t) rc;
[da1bafb]881
[48daf64]882 return sys_ipc_forward_common(callid, phoneid,
883 IPC_GET_METHOD(newdata), IPC_GET_ARG1(newdata),
884 IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
885 IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
886}
887
[8b243f2]888/** Answer an IPC call - fast version.
889 *
890 * This function can handle only two return arguments of payload, but is faster
891 * than the generic sys_ipc_answer().
892 *
[da1bafb]893 * @param callid Hash of the call to be answered.
894 * @param retval Return value of the answer.
895 * @param arg1 Service-defined return value.
896 * @param arg2 Service-defined return value.
897 * @param arg3 Service-defined return value.
898 * @param arg4 Service-defined return value.
899 *
900 * @return 0 on success, otherwise an error code.
[8b243f2]901 *
902 */
[96b02eb9]903sysarg_t sys_ipc_answer_fast(sysarg_t callid, sysarg_t retval,
904 sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
[2d5a54f3]905{
[897f2e76]906 /* Do not answer notification callids */
907 if (callid & IPC_CALLID_NOTIFICATION)
908 return 0;
[da1bafb]909
910 call_t *call = get_call(callid);
[2ba7810]911 if (!call)
912 return ENOENT;
[da1bafb]913
914 ipc_data_t saved_data;
915 bool saved;
916
[9f22213]917 if (answer_need_old(call)) {
[2ba7810]918 memcpy(&saved_data, &call->data, sizeof(call->data));
[da1bafb]919 saved = true;
920 } else
921 saved = false;
922
[2d5a54f3]923 IPC_SET_RETVAL(call->data, retval);
924 IPC_SET_ARG1(call->data, arg1);
925 IPC_SET_ARG2(call->data, arg2);
[b74959bd]926 IPC_SET_ARG3(call->data, arg3);
927 IPC_SET_ARG4(call->data, arg4);
[da1bafb]928
[8498915]929 /*
930 * To achieve deterministic behavior, zero out arguments that are beyond
931 * the limits of the fast version.
932 */
933 IPC_SET_ARG5(call->data, 0);
[da1bafb]934 int rc = answer_preprocess(call, saved ? &saved_data : NULL);
935
[2d5a54f3]936 ipc_answer(&TASK->answerbox, call);
[7c23af9]937 return rc;
[2d5a54f3]938}
939
[8b243f2]940/** Answer an IPC call.
941 *
[da1bafb]942 * @param callid Hash of the call to be answered.
943 * @param data Userspace address of call data with the answer.
944 *
945 * @return 0 on success, otherwise an error code.
[8b243f2]946 *
947 */
[96b02eb9]948sysarg_t sys_ipc_answer_slow(sysarg_t callid, ipc_data_t *data)
[2d5a54f3]949{
[897f2e76]950 /* Do not answer notification callids */
951 if (callid & IPC_CALLID_NOTIFICATION)
952 return 0;
[da1bafb]953
954 call_t *call = get_call(callid);
[2ba7810]955 if (!call)
956 return ENOENT;
[da1bafb]957
958 ipc_data_t saved_data;
959 bool saved;
960
[9f22213]961 if (answer_need_old(call)) {
[2ba7810]962 memcpy(&saved_data, &call->data, sizeof(call->data));
[da1bafb]963 saved = true;
964 } else
965 saved = false;
966
967 int rc = copy_from_uspace(&call->data.args, &data->args,
[51ec40f]968 sizeof(call->data.args));
[e3c762cd]969 if (rc != 0)
970 return rc;
[da1bafb]971
972 rc = answer_preprocess(call, saved ? &saved_data : NULL);
[2d5a54f3]973
974 ipc_answer(&TASK->answerbox, call);
[7c23af9]975 return rc;
[2d5a54f3]976}
977
[8b243f2]978/** Hang up a phone.
[2d5a54f3]979 *
[da1bafb]980 * @param Phone handle of the phone to be hung up.
981 *
982 * @return 0 on success or an error code.
[8b243f2]983 *
[fbcfd458]984 */
[96b02eb9]985sysarg_t sys_ipc_hangup(sysarg_t phoneid)
[fbcfd458]986{
987 phone_t *phone;
[da1bafb]988
[c9fff17]989 if (phone_get(phoneid, &phone) != EOK)
990 return ENOENT;
[da1bafb]991
[d8f7362]992 if (ipc_phone_hangup(phone))
[fbcfd458]993 return -1;
[da1bafb]994
[fbcfd458]995 return 0;
996}
997
[8b243f2]998/** Wait for an incoming IPC call or an answer.
[fbcfd458]999 *
[da1bafb]1000 * @param calldata Pointer to buffer where the call/answer data is stored.
1001 * @param usec Timeout. See waitq_sleep_timeout() for explanation.
1002 * @param flags Select mode of sleep operation. See waitq_sleep_timeout()
1003 * for explanation.
1004 *
1005 * @return Hash of the call.
1006 * If IPC_CALLID_NOTIFICATION bit is set in the hash, the
1007 * call is a notification. IPC_CALLID_ANSWERED denotes an
1008 * answer.
[bd5a663]1009 *
[2d5a54f3]1010 */
[96b02eb9]1011sysarg_t sys_ipc_wait_for_call(ipc_data_t *calldata, uint32_t usec,
[da1bafb]1012 unsigned int flags)
[2d5a54f3]1013{
1014 call_t *call;
[da1bafb]1015
[741fd16]1016restart:
[da1bafb]1017
[741fd16]1018#ifdef CONFIG_UDEBUG
1019 udebug_stoppable_begin();
[da1bafb]1020#endif
1021
[51ec40f]1022 call = ipc_wait_for_call(&TASK->answerbox, usec,
1023 flags | SYNCH_FLAGS_INTERRUPTIBLE);
[da1bafb]1024
[741fd16]1025#ifdef CONFIG_UDEBUG
1026 udebug_stoppable_end();
1027#endif
[da1bafb]1028
[9f22213]1029 if (!call)
1030 return 0;
[da1bafb]1031
[5626277]1032 if (call->flags & IPC_CALL_NOTIF) {
[43752b6]1033 /* Set in_phone_hash to the interrupt counter */
[0c1a5d8a]1034 call->data.phone = (void *) call->priv;
[43752b6]1035
1036 STRUCT_TO_USPACE(calldata, &call->data);
[da1bafb]1037
[5626277]1038 ipc_call_free(call);
1039
[96b02eb9]1040 return ((sysarg_t) call) | IPC_CALLID_NOTIFICATION;
[5626277]1041 }
[da1bafb]1042
[2d5a54f3]1043 if (call->flags & IPC_CALL_ANSWERED) {
[7c7aae16]1044 process_answer(call);
[da1bafb]1045
[fbcfd458]1046 if (call->flags & IPC_CALL_DISCARD_ANSWER) {
1047 ipc_call_free(call);
1048 goto restart;
1049 }
[da1bafb]1050
[fbcfd458]1051 STRUCT_TO_USPACE(&calldata->args, &call->data.args);
[2d5a54f3]1052 ipc_call_free(call);
[da1bafb]1053
[96b02eb9]1054 return ((sysarg_t) call) | IPC_CALLID_ANSWERED;
[2d5a54f3]1055 }
[da1bafb]1056
[2d5a54f3]1057 if (process_request(&TASK->answerbox, call))
1058 goto restart;
[da1bafb]1059
[7c7aae16]1060 /* Include phone address('id') of the caller in the request,
1061 * copy whole call->data, not only call->data.args */
[bd55bbb]1062 if (STRUCT_TO_USPACE(calldata, &call->data)) {
[e06da7e]1063 /*
1064 * The callee will not receive this call and no one else has
1065 * a chance to answer it. Reply with the EPARTY error code.
[b11ee88]1066 */
[e06da7e]1067 ipc_data_t saved_data;
[da1bafb]1068 bool saved;
1069
[e06da7e]1070 if (answer_need_old(call)) {
1071 memcpy(&saved_data, &call->data, sizeof(call->data));
[da1bafb]1072 saved = true;
1073 } else
1074 saved = false;
[e06da7e]1075
1076 IPC_SET_RETVAL(call->data, EPARTY);
[da1bafb]1077 (void) answer_preprocess(call, saved ? &saved_data : NULL);
[e06da7e]1078 ipc_answer(&TASK->answerbox, call);
[bd55bbb]1079 return 0;
1080 }
[da1bafb]1081
[96b02eb9]1082 return (sysarg_t) call;
[2d5a54f3]1083}
[5626277]1084
[da1bafb]1085/** Interrupt one thread from sys_ipc_wait_for_call().
1086 *
1087 */
[96b02eb9]1088sysarg_t sys_ipc_poke(void)
[057d21a]1089{
[da1bafb]1090 waitq_unsleep(&TASK->answerbox.wq);
[057d21a]1091 return EOK;
1092}
1093
[8b243f2]1094/** Connect an IRQ handler to a task.
[2b017ba]1095 *
[da1bafb]1096 * @param inr IRQ number.
1097 * @param devno Device number.
1098 * @param method Method to be associated with the notification.
1099 * @param ucode Uspace pointer to the top-half pseudocode.
1100 *
1101 * @return EPERM or a return code returned by ipc_irq_register().
[2b017ba]1102 *
1103 */
[96b02eb9]1104sysarg_t sys_ipc_register_irq(inr_t inr, devno_t devno, sysarg_t method,
[51ec40f]1105 irq_code_t *ucode)
[5626277]1106{
[2bb8648]1107 if (!(cap_get(TASK) & CAP_IRQ_REG))
1108 return EPERM;
[da1bafb]1109
[2b017ba]1110 return ipc_irq_register(&TASK->answerbox, inr, devno, method, ucode);
[5626277]1111}
1112
[8b243f2]1113/** Disconnect an IRQ handler from a task.
1114 *
[da1bafb]1115 * @param inr IRQ number.
1116 * @param devno Device number.
1117 *
1118 * @return Zero on success or EPERM on error.
[2b017ba]1119 *
1120 */
[96b02eb9]1121sysarg_t sys_ipc_unregister_irq(inr_t inr, devno_t devno)
[5626277]1122{
[2bb8648]1123 if (!(cap_get(TASK) & CAP_IRQ_REG))
1124 return EPERM;
[da1bafb]1125
[2b017ba]1126 ipc_irq_unregister(&TASK->answerbox, inr, devno);
[da1bafb]1127
[5626277]1128 return 0;
1129}
[b45c443]1130
[6b10dab]1131#ifdef __32_BITS__
[9a1b20c]1132
[6b10dab]1133/** Syscall connect to a task by ID (32 bits)
[da1bafb]1134 *
1135 * @return Phone id on success, or negative error code.
[9a1b20c]1136 *
1137 */
[6b10dab]1138sysarg_t sys_ipc_connect_kbox(sysarg64_t *uspace_taskid)
[9a1b20c]1139{
1140#ifdef CONFIG_UDEBUG
[6b10dab]1141 sysarg64_t taskid;
1142 int rc = copy_from_uspace(&taskid, uspace_taskid, sizeof(sysarg64_t));
[9a1b20c]1143 if (rc != 0)
[96b02eb9]1144 return (sysarg_t) rc;
[da1bafb]1145
[6b10dab]1146 return ipc_connect_kbox((task_id_t) taskid);
[9a1b20c]1147#else
[96b02eb9]1148 return (sysarg_t) ENOTSUP;
[9a1b20c]1149#endif
1150}
1151
[6b10dab]1152#endif /* __32_BITS__ */
1153
1154#ifdef __64_BITS__
1155
1156/** Syscall connect to a task by ID (64 bits)
1157 *
1158 * @return Phone id on success, or negative error code.
1159 *
1160 */
1161sysarg_t sys_ipc_connect_kbox(sysarg_t taskid)
1162{
1163#ifdef CONFIG_UDEBUG
1164 return ipc_connect_kbox((task_id_t) taskid);
1165#else
1166 return (sysarg_t) ENOTSUP;
1167#endif
1168}
1169
1170#endif /* __64_BITS__ */
1171
[cc73a8a1]1172/** @}
[b45c443]1173 */
Note: See TracBrowser for help on using the repository browser.