Subversion Repositories HelenOS

Rev

Rev 2359 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
954 palkovsky 1
/*
2071 jermar 2
 * Copyright (c) 2006 Ondrej Palkovsky
954 palkovsky 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.
1653 cejka 27
 */
28
 
29
/** @addtogroup libc
30
 * @{
31
 * @}
32
 */
33
 
1866 jermar 34
/** @addtogroup libcipc IPC
1653 cejka 35
 * @brief HelenOS uspace IPC
36
 * @{
37
 * @ingroup libc
38
 */
39
/** @file
954 palkovsky 40
 */
41
 
1352 palkovsky 42
#include <ipc/ipc.h>
954 palkovsky 43
#include <libc.h>
999 palkovsky 44
#include <malloc.h>
45
#include <errno.h>
1352 palkovsky 46
#include <libadt/list.h>
999 palkovsky 47
#include <stdio.h>
48
#include <unistd.h>
1350 palkovsky 49
#include <futex.h>
1365 jermar 50
#include <kernel/synch/synch.h>
1463 palkovsky 51
#include <async.h>
52
#include <psthread.h>
954 palkovsky 53
 
2471 jermar 54
/** Structure used for keeping track of sent asynchronous calls and queing
55
 * unsent calls.
999 palkovsky 56
 */
57
typedef struct {
58
    link_t list;
59
 
60
    ipc_async_callback_t callback;
61
    void *private;
62
    union {
63
        ipc_callid_t callid;
64
        struct {
1091 palkovsky 65
            ipc_call_t data;
999 palkovsky 66
            int phoneid;
67
        } msg;
2471 jermar 68
    } u;
69
    pstid_t ptid;   /**< Pseudothread waiting for sending this call. */
999 palkovsky 70
} async_call_t;
71
 
72
LIST_INITIALIZE(dispatched_calls);
73
 
2471 jermar 74
/** List of asynchronous calls that were not accepted by kernel.
75
 *
76
 * It is protected by async_futex, because if the call cannot be sent into the
77
 * kernel, the async framework is used automatically.
1463 palkovsky 78
 */
2471 jermar 79
LIST_INITIALIZE(queued_calls);
1463 palkovsky 80
 
1392 palkovsky 81
static atomic_t ipc_futex = FUTEX_INITIALIZER;
1350 palkovsky 82
 
2471 jermar 83
/** Make a fast synchronous call.
84
 *
85
 * Only one payload argument can be passed using this function. However, this
86
 * function is faster than the generic ipc_call_sync_3().
87
 *
88
 * @param phoneid   Phone handle for the call.
89
 * @param method    Requested method.
90
 * @param arg1      Service-defined payload argument.
91
 * @param result    If non-NULL, the return ARG1 will be stored there.
92
 *
93
 * @return      Negative values represent errors returned by IPC.
94
 *          Otherwise the RETVAL of the answer is returned.
95
 */
96
int ipc_call_sync(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t *result)
954 palkovsky 97
{
1091 palkovsky 98
    ipc_call_t resdata;
966 palkovsky 99
    int callres;
100
 
999 palkovsky 101
    callres = __SYSCALL4(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
2471 jermar 102
        (sysarg_t) &resdata);
966 palkovsky 103
    if (callres)
104
        return callres;
105
    if (result)
106
        *result = IPC_GET_ARG1(resdata);
107
    return IPC_GET_RETVAL(resdata);
954 palkovsky 108
}
109
 
2471 jermar 110
/** Make a synchronous call transmitting 3 arguments of payload.
111
 *
112
 * @param phoneid   Phone handle for the call.
113
 * @param method    Requested method.
114
 * @param arg1      Service-defined payload argument.
115
 * @param arg2      Service-defined payload argument.
116
 * @param arg3      Service-defined payload argument.
117
 * @param result1   If non-NULL, storage for the first return argument.
118
 * @param result2   If non-NULL, storage for the second return argument.
119
 * @param result3   If non-NULL, storage for the third return argument.
120
 *
121
 * @return      Negative value means IPC error.
122
 *          Otherwise the RETVAL of the answer.
123
 */
124
int ipc_call_sync_3(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
125
    ipcarg_t arg3, ipcarg_t *result1, ipcarg_t *result2, ipcarg_t *result3)
954 palkovsky 126
{
1091 palkovsky 127
    ipc_call_t data;
966 palkovsky 128
    int callres;
129
 
130
    IPC_SET_METHOD(data, method);
131
    IPC_SET_ARG1(data, arg1);
132
    IPC_SET_ARG2(data, arg2);
133
    IPC_SET_ARG3(data, arg3);
134
 
2471 jermar 135
    callres = __SYSCALL3(SYS_IPC_CALL_SYNC, phoneid, (sysarg_t) &data,
136
        (sysarg_t) &data);
966 palkovsky 137
    if (callres)
138
        return callres;
139
 
140
    if (result1)
141
        *result1 = IPC_GET_ARG1(data);
142
    if (result2)
143
        *result2 = IPC_GET_ARG2(data);
144
    if (result3)
145
        *result3 = IPC_GET_ARG3(data);
146
    return IPC_GET_RETVAL(data);
147
}
148
 
2471 jermar 149
/** Syscall to send asynchronous message.
150
 *
151
 * @param phoneid   Phone handle for the call.
152
 * @param data      Call data with the request.
153
 *
154
 * @return      Hash of the call or an error code.
155
 */
156
static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
999 palkovsky 157
{
2471 jermar 158
    return __SYSCALL2(SYS_IPC_CALL_ASYNC, phoneid, (sysarg_t) data);
999 palkovsky 159
}
160
 
2471 jermar 161
/** Prolog to ipc_call_async_*() functions.
162
 *
163
 * @param private   Argument for the answer/error callback.
164
 * @param callback  Answer/error callback.
165
 *
166
 * @return      New, partially initialized async_call structure or NULL.
167
 */
168
static inline async_call_t *ipc_prepare_async(void *private,
169
    ipc_async_callback_t callback)
966 palkovsky 170
{
999 palkovsky 171
    async_call_t *call;
966 palkovsky 172
 
999 palkovsky 173
    call = malloc(sizeof(*call));
174
    if (!call) {
1443 palkovsky 175
        if (callback)
176
            callback(private, ENOMEM, NULL);
1489 palkovsky 177
        return NULL;
999 palkovsky 178
    }
1463 palkovsky 179
    call->callback = callback;
180
    call->private = private;
181
 
1489 palkovsky 182
    return call;
183
}
184
 
2471 jermar 185
/** Epilogue of ipc_call_async_*() functions.
186
 *
187
 * @param callid    Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
188
 * @param phoneid   Phone handle through which the call was made.
189
 * @param call      async_call structure returned by ipc_prepare_async().
190
 * @param can_preempt   If non-zero, the current pseudo thread can be preempted
191
 *          in this call.
192
 */
193
static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
194
    async_call_t *call, int can_preempt)
1489 palkovsky 195
{
1751 palkovsky 196
    if (!call) { /* Nothing to do regardless if failed or not */
197
        futex_up(&ipc_futex);
198
        return;
199
    }
200
 
966 palkovsky 201
    if (callid == IPC_CALLRET_FATAL) {
1463 palkovsky 202
        futex_up(&ipc_futex);
966 palkovsky 203
        /* Call asynchronous handler with error code */
1489 palkovsky 204
        if (call->callback)
205
            call->callback(call->private, ENOENT, NULL);
999 palkovsky 206
        free(call);
966 palkovsky 207
        return;
208
    }
999 palkovsky 209
 
1463 palkovsky 210
    if (callid == IPC_CALLRET_TEMPORARY) {
211
        futex_up(&ipc_futex);
999 palkovsky 212
 
213
        call->u.msg.phoneid = phoneid;
1518 palkovsky 214
 
1463 palkovsky 215
        futex_down(&async_futex);
999 palkovsky 216
        list_append(&call->list, &queued_calls);
1463 palkovsky 217
 
1518 palkovsky 218
        if (can_preempt) {
219
            call->ptid = psthread_get_id();
220
            psthread_schedule_next_adv(PS_TO_MANAGER);
221
            /* Async futex unlocked by previous call */
222
        } else {
223
            call->ptid = 0;
224
            futex_up(&async_futex);
225
        }
966 palkovsky 226
        return;
227
    }
999 palkovsky 228
    call->u.callid = callid;
2471 jermar 229
    /* Add call to the list of dispatched calls */
999 palkovsky 230
    list_append(&call->list, &dispatched_calls);
1350 palkovsky 231
    futex_up(&ipc_futex);
1489 palkovsky 232
 
954 palkovsky 233
}
234
 
2471 jermar 235
/** Make a fast asynchronous call.
1489 palkovsky 236
 *
2471 jermar 237
 * This function can only handle two arguments of payload. It is, however,
238
 * faster than the more generic ipc_call_async_3().
239
 *
240
 * Note that this function is a void function.
241
 * During normal opertation, answering this call will trigger the callback.
242
 * In case of fatal error, call the callback handler with the proper error code.
243
 * If the call cannot be temporarily made, queue it.
244
 *
245
 * @param phoneid   Phone handle for the call.
246
 * @param method    Requested method.
247
 * @param arg1      Service-defined payload argument.
248
 * @param arg2      Service-defined payload argument.
249
 * @param private   Argument to be passed to the answer/error callback.
250
 * @param callback  Answer or error callback.
251
 * @param can_preempt   If non-zero, the current pseudo thread will be preempted
252
 *          in case the kernel temporarily refuses to accept more
253
 *          asynchronous calls.
1489 palkovsky 254
 */
255
void ipc_call_async_2(int phoneid, ipcarg_t method, ipcarg_t arg1,
2471 jermar 256
    ipcarg_t arg2, void *private, ipc_async_callback_t callback,
257
    int can_preempt)
1489 palkovsky 258
{
1751 palkovsky 259
    async_call_t *call = NULL;
1489 palkovsky 260
    ipc_callid_t callid;
966 palkovsky 261
 
1751 palkovsky 262
    if (callback) {
263
        call = ipc_prepare_async(private, callback);
264
        if (!call)
265
            return;
266
    }
1489 palkovsky 267
 
2471 jermar 268
    /*
269
     * We need to make sure that we get callid before another thread
270
     * accesses the queue again.
271
     */
1489 palkovsky 272
    futex_down(&ipc_futex);
2471 jermar 273
    callid = __SYSCALL4(SYS_IPC_CALL_ASYNC_FAST, phoneid, method, arg1,
274
        arg2);
1489 palkovsky 275
 
276
    if (callid == IPC_CALLRET_TEMPORARY) {
1751 palkovsky 277
        if (!call) {
278
            call = ipc_prepare_async(private, callback);
279
            if (!call)
280
                return;
281
        }
1489 palkovsky 282
        IPC_SET_METHOD(call->u.msg.data, method);
283
        IPC_SET_ARG1(call->u.msg.data, arg1);
284
        IPC_SET_ARG2(call->u.msg.data, arg2);
285
    }
1518 palkovsky 286
    ipc_finish_async(callid, phoneid, call, can_preempt);
1489 palkovsky 287
}
288
 
2471 jermar 289
/** Make an asynchronous call transmitting the entire payload.
1489 palkovsky 290
 *
2471 jermar 291
 * Note that this function is a void function.
292
 * During normal opertation, answering this call will trigger the callback.
293
 * In case of fatal error, call the callback handler with the proper error code.
294
 * If the call cannot be temporarily made, queue it.
295
 *
296
 * @param phoneid   Phone handle for the call.
297
 * @param method    Requested method.
298
 * @param arg1      Service-defined payload argument.
299
 * @param arg2      Service-defined payload argument.
300
 * @param arg3      Service-defined payload argument.
301
 * @param private   Argument to be passed to the answer/error callback.
302
 * @param callback  Answer or error callback.
303
 * @param can_preempt   If non-zero, the current pseudo thread will be preempted
304
 *          in case the kernel temporarily refuses to accept more
305
 *          asynchronous calls.
306
 *
1489 palkovsky 307
 */
308
void ipc_call_async_3(int phoneid, ipcarg_t method, ipcarg_t arg1,
2471 jermar 309
    ipcarg_t arg2, ipcarg_t arg3, void *private, ipc_async_callback_t callback,
310
    int can_preempt)
1489 palkovsky 311
{
312
    async_call_t *call;
313
    ipc_callid_t callid;
314
 
315
    call = ipc_prepare_async(private, callback);
316
    if (!call)
317
        return;
318
 
319
    IPC_SET_METHOD(call->u.msg.data, method);
320
    IPC_SET_ARG1(call->u.msg.data, arg1);
321
    IPC_SET_ARG2(call->u.msg.data, arg2);
322
    IPC_SET_ARG3(call->u.msg.data, arg3);
2471 jermar 323
    /*
324
     * We need to make sure that we get callid before another thread accesses
325
     * the queue again.
326
     */
1489 palkovsky 327
    futex_down(&ipc_futex);
328
    callid = _ipc_call_async(phoneid, &call->u.msg.data);
329
 
1518 palkovsky 330
    ipc_finish_async(callid, phoneid, call, can_preempt);
1489 palkovsky 331
}
332
 
333
 
2471 jermar 334
/** Answer a received call - fast version.
1343 jermar 335
 *
2471 jermar 336
 * The fast answer makes use of passing retval and first two arguments in
337
 * registers. If you need to return more, use the ipc_answer() instead.
1343 jermar 338
 *
2471 jermar 339
 * @param callid    Hash of the call being answered.
340
 * @param retval    Return value.
341
 * @param arg1      First return argument.
342
 * @param arg2      Second return argument.
1343 jermar 343
 *
2471 jermar 344
 * @return      Zero on success or a value from @ref errno.h on failure.
1343 jermar 345
 */
346
ipcarg_t ipc_answer_fast(ipc_callid_t callid, ipcarg_t retval, ipcarg_t arg1,
2471 jermar 347
    ipcarg_t arg2)
954 palkovsky 348
{
1330 palkovsky 349
    return __SYSCALL4(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2);
954 palkovsky 350
}
351
 
2471 jermar 352
/** Answer a received call - full version.
1343 jermar 353
 *
2471 jermar 354
 * @param callid    Hash of the call being answered.
355
 * @param call      Call structure with the answer.
356
 *          Must be already initialized by the responder.
1343 jermar 357
 *
2471 jermar 358
 * @return      Zero on success or a value from @ref errno.h on failure.
1343 jermar 359
 */
360
ipcarg_t ipc_answer(ipc_callid_t callid, ipc_call_t *call)
361
{
362
    return __SYSCALL2(SYS_IPC_ANSWER, callid, (sysarg_t) call);
363
}
364
 
365
 
2471 jermar 366
/** Try to dispatch queued calls from the async queue. */
999 palkovsky 367
static void try_dispatch_queued_calls(void)
368
{
369
    async_call_t *call;
370
    ipc_callid_t callid;
371
 
2471 jermar 372
    /** @todo
373
     * Integrate intelligently ipc_futex, so that it is locked during
374
     * ipc_call_async_*(), until it is added to dispatched_calls.
1463 palkovsky 375
     */
376
    futex_down(&async_futex);
999 palkovsky 377
    while (!list_empty(&queued_calls)) {
2471 jermar 378
        call = list_get_instance(queued_calls.next, async_call_t, list);
379
        callid = _ipc_call_async(call->u.msg.phoneid, &call->u.msg.data);
1463 palkovsky 380
        if (callid == IPC_CALLRET_TEMPORARY) {
999 palkovsky 381
            break;
1463 palkovsky 382
        }
999 palkovsky 383
        list_remove(&call->list);
1350 palkovsky 384
 
1463 palkovsky 385
        futex_up(&async_futex);
1518 palkovsky 386
        if (call->ptid)
387
            psthread_add_ready(call->ptid);
1463 palkovsky 388
 
999 palkovsky 389
        if (callid == IPC_CALLRET_FATAL) {
1443 palkovsky 390
            if (call->callback)
391
                call->callback(call->private, ENOENT, NULL);
999 palkovsky 392
            free(call);
393
        } else {
394
            call->u.callid = callid;
1463 palkovsky 395
            futex_down(&ipc_futex);
999 palkovsky 396
            list_append(&call->list, &dispatched_calls);
1463 palkovsky 397
            futex_up(&ipc_futex);
999 palkovsky 398
        }
1463 palkovsky 399
        futex_down(&async_futex);
999 palkovsky 400
    }
1463 palkovsky 401
    futex_up(&async_futex);
999 palkovsky 402
}
403
 
2471 jermar 404
/** Handle a received answer.
999 palkovsky 405
 *
2471 jermar 406
 * Find the hash of the answer and call the answer callback.
999 palkovsky 407
 *
2471 jermar 408
 * @todo Make it use hash table.
409
 *
410
 * @param callid    Hash of the received answer.
411
 *          The answer has the same hash as the request OR'ed with
412
 *          the IPC_CALLID_ANSWERED bit.
413
 * @param data      Call data of the answer.
999 palkovsky 414
 */
1091 palkovsky 415
static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
999 palkovsky 416
{
417
    link_t *item;
418
    async_call_t *call;
419
 
420
    callid &= ~IPC_CALLID_ANSWERED;
421
 
1350 palkovsky 422
    futex_down(&ipc_futex);
999 palkovsky 423
    for (item = dispatched_calls.next; item != &dispatched_calls;
2471 jermar 424
        item = item->next) {
999 palkovsky 425
        call = list_get_instance(item, async_call_t, list);
426
        if (call->u.callid == callid) {
427
            list_remove(&call->list);
1350 palkovsky 428
            futex_up(&ipc_futex);
1443 palkovsky 429
            if (call->callback)
430
                call->callback(call->private,
2471 jermar 431
                    IPC_GET_RETVAL(*data), data);
1443 palkovsky 432
            free(call);
999 palkovsky 433
            return;
434
        }
435
    }
1350 palkovsky 436
    futex_up(&ipc_futex);
999 palkovsky 437
}
438
 
439
 
2471 jermar 440
/** Wait for a first call to come.
954 palkovsky 441
 *
2471 jermar 442
 * @param call      Storage where the incoming call data will be stored.
443
 * @param usec      Timeout in microseconds
444
 * @param flags     Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
445
 *
446
 * @return      Hash of the call. Note that certain bits have special
447
 *          meaning. IPC_CALLID_ANSWERED will be set in an answer
448
 *          and IPC_CALLID_NOTIFICATION is used for notifications.
449
 *         
954 palkovsky 450
 */
1392 palkovsky 451
ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
954 palkovsky 452
{
453
    ipc_callid_t callid;
454
 
1392 palkovsky 455
    callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
456
    /* Handle received answers */
1463 palkovsky 457
    if (callid & IPC_CALLID_ANSWERED) {
1392 palkovsky 458
        handle_answer(callid, call);
1463 palkovsky 459
        try_dispatch_queued_calls();
460
    }
999 palkovsky 461
 
954 palkovsky 462
    return callid;
463
}
1028 palkovsky 464
 
1365 jermar 465
/** Wait some time for an IPC call.
466
 *
2471 jermar 467
 * The call will return after an answer is received.
1709 jermar 468
 *
2471 jermar 469
 * @param call      Storage where the incoming call data will be stored.
470
 * @param usec      Timeout in microseconds.
471
 *
472
 * @return      Hash of the answer.
1365 jermar 473
 */
474
ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
475
{
476
    ipc_callid_t callid;
477
 
478
    do {
1503 jermar 479
        callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
1365 jermar 480
    } while (callid & IPC_CALLID_ANSWERED);
481
 
482
    return callid;
483
}
484
 
485
/** Check if there is an IPC call waiting to be picked up.
486
 *
2471 jermar 487
 * @param call      Storage where the incoming call will be stored.
488
 * @return      Hash of the answer.
1365 jermar 489
 */
490
ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
491
{
492
    ipc_callid_t callid;
493
 
494
    do {
2471 jermar 495
        callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
496
            SYNCH_FLAGS_NON_BLOCKING);
1365 jermar 497
    } while (callid & IPC_CALLID_ANSWERED);
498
 
499
    return callid;
500
}
501
 
2359 jermar 502
/** Ask destination to do a callback connection.
1091 palkovsky 503
 *
2471 jermar 504
 * @param phoneid   Phone handle used for contacting the other side.
505
 * @param arg1      Service-defined argument.
506
 * @param arg2      Service-defined argument.
507
 * @param phonehash Storage where the library will store an opaque
2359 jermar 508
 *          identifier of the phone that will be used for incoming
2471 jermar 509
 *          calls. This identifier can be used for connection
510
 *          tracking.
511
 *
512
 * @return      Zero on success or a negative error code.
1091 palkovsky 513
 */
2359 jermar 514
int ipc_connect_to_me(int phoneid, int arg1, int arg2, ipcarg_t *phonehash)
1028 palkovsky 515
{
2359 jermar 516
    return ipc_call_sync_3(phoneid, IPC_M_CONNECT_TO_ME, arg1, arg2, 0, 0, 0,
517
        phonehash);
1028 palkovsky 518
}
1061 palkovsky 519
 
2359 jermar 520
/** Ask through phone for a new connection to some service.
1091 palkovsky 521
 *
2471 jermar 522
 * @param phoneid   Phone handle used for contacting the other side.
2359 jermar 523
 * @param arg1      User defined argument.
524
 * @param arg2      User defined argument.
525
 *
2471 jermar 526
 * @return      New phone handle on success or a negative error code.
1091 palkovsky 527
 */
1061 palkovsky 528
int ipc_connect_me_to(int phoneid, int arg1, int arg2)
529
{
1092 palkovsky 530
    ipcarg_t newphid;
1091 palkovsky 531
    int res;
532
 
2359 jermar 533
    res =  ipc_call_sync_3(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, 0, 0, 0,
534
        &newphid);
1091 palkovsky 535
    if (res)
536
        return res;
537
    return newphid;
1061 palkovsky 538
}
539
 
2471 jermar 540
/** Hang up a phone.
541
 *
542
 * @param phoneid   Handle of the phone to be hung up.
543
 *
544
 * @return      Zero on success or a negative error code.
545
 */
1089 palkovsky 546
int ipc_hangup(int phoneid)
547
{
548
    return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
549
}
1259 palkovsky 550
 
1923 jermar 551
/** Register IRQ notification.
552
 *
2471 jermar 553
 * @param inr       IRQ number.
554
 * @param devno     Device number of the device generating inr.
555
 * @param method    Use this method for notifying me.
556
 * @param ucode     Top-half pseudocode handler.
1923 jermar 557
 *
2471 jermar 558
 * @return      Value returned by the kernel.
1923 jermar 559
 */
560
int ipc_register_irq(int inr, int devno, int method, irq_code_t *ucode)
1259 palkovsky 561
{
2471 jermar 562
    return __SYSCALL4(SYS_IPC_REGISTER_IRQ, inr, devno, method,
563
        (sysarg_t) ucode);
1259 palkovsky 564
}
565
 
1923 jermar 566
/** Unregister IRQ notification.
567
 *
2471 jermar 568
 * @param inr       IRQ number.
569
 * @param devno     Device number of the device generating inr.
1923 jermar 570
 *
2471 jermar 571
 * @return      Value returned by the kernel.
1923 jermar 572
 */
573
int ipc_unregister_irq(int inr, int devno)
1259 palkovsky 574
{
1923 jermar 575
    return __SYSCALL2(SYS_IPC_UNREGISTER_IRQ, inr, devno);
1259 palkovsky 576
}
1330 palkovsky 577
 
2471 jermar 578
/** Forward a received call to another destination.
579
 *
580
 * @param callid    Hash of the call to forward.
581
 * @param phoneid   Phone handle to use for forwarding.
582
 * @param method    New method for the forwarded call.
583
 * @param arg1      New value of the first argument for the forwarded call.
584
 *
585
 * @return      Zero on success or an error code.
586
 *
587
 * For non-system methods, the old method and arg1 are rewritten by the new
588
 * values. For system methods, the new method and arg1 are written to the old
589
 * arg1 and arg2, respectivelly.
590
 */
1336 jermar 591
int ipc_forward_fast(ipc_callid_t callid, int phoneid, int method, ipcarg_t arg1)
592
{
593
    return __SYSCALL4(SYS_IPC_FORWARD_FAST, callid, phoneid, method, arg1);
594
}
595
 
1866 jermar 596
/** @}
1653 cejka 597
 */