Changeset e29e09cf in mainline for uspace/lib/c/generic/ipc.c


Ignore:
Timestamp:
2011-02-04T21:00:56Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
474afc9, 960ff451
Parents:
400575c5 (diff), 17aca1c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/ipc.c

    r400575c5 re29e09cf  
    4545#include <errno.h>
    4646#include <adt/list.h>
    47 #include <stdio.h>
    48 #include <unistd.h>
    4947#include <futex.h>
    50 #include <kernel/synch/synch.h>
    51 #include <async.h>
    5248#include <fibril.h>
    53 #include <assert.h>
    5449
    5550/**
    56  * Structures of this type are used for keeping track of sent asynchronous calls
    57  * and queing unsent calls.
     51 * Structures of this type are used for keeping track
     52 * of sent asynchronous calls and queing unsent calls.
    5853 */
    5954typedef struct {
    6055        link_t list;
    61 
     56       
    6257        ipc_async_callback_t callback;
    6358        void *private;
     59       
    6460        union {
    6561                ipc_callid_t callid;
     
    6965                } msg;
    7066        } u;
    71         fid_t fid;      /**< Fibril waiting for sending this call. */
     67       
     68        /** Fibril waiting for sending this call. */
     69        fid_t fid;
    7270} async_call_t;
    7371
     
    7674/** List of asynchronous calls that were not accepted by kernel.
    7775 *
    78  * It is protected by async_futex, because if the call cannot be sent into the
    79  * kernel, the async framework is used automatically.
     76 * Protected by async_futex, because if the call is not accepted
     77 * by the kernel, the async framework is used automatically.
     78 *
    8079 */
    8180LIST_INITIALIZE(queued_calls);
     
    8382static atomic_t ipc_futex = FUTEX_INITIALIZER;
    8483
    85 /** Make a fast synchronous call.
    86  *
    87  * Only three payload arguments can be passed using this function. However, this
    88  * function is faster than the generic ipc_call_sync_slow() because the payload
    89  * is passed directly in registers.
    90  *
    91  * @param phoneid       Phone handle for the call.
    92  * @param method        Requested method.
    93  * @param arg1          Service-defined payload argument.
    94  * @param arg2          Service-defined payload argument.
    95  * @param arg3          Service-defined payload argument.
    96  * @param result1       If non-NULL, the return ARG1 will be stored there.
    97  * @param result2       If non-NULL, the return ARG2 will be stored there.
    98  * @param result3       If non-NULL, the return ARG3 will be stored there.
    99  * @param result4       If non-NULL, the return ARG4 will be stored there.
    100  * @param result5       If non-NULL, the return ARG5 will be stored there.
    101  *
    102  * @return              Negative values represent errors returned by IPC.
    103  *                      Otherwise the RETVAL of the answer is returned.
    104  */
    105 int
    106 ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1, sysarg_t arg2,
    107     sysarg_t arg3, sysarg_t *result1, sysarg_t *result2, sysarg_t *result3,
    108     sysarg_t *result4, sysarg_t *result5)
     84/** Fast synchronous call.
     85 *
     86 * Only three payload arguments can be passed using this function. However,
     87 * this function is faster than the generic ipc_call_sync_slow() because
     88 * the payload is passed directly in registers.
     89 *
     90 * @param phoneid Phone handle for the call.
     91 * @param method  Requested method.
     92 * @param arg1    Service-defined payload argument.
     93 * @param arg2    Service-defined payload argument.
     94 * @param arg3    Service-defined payload argument.
     95 * @param result1 If non-NULL, the return ARG1 will be stored there.
     96 * @param result2 If non-NULL, the return ARG2 will be stored there.
     97 * @param result3 If non-NULL, the return ARG3 will be stored there.
     98 * @param result4 If non-NULL, the return ARG4 will be stored there.
     99 * @param result5 If non-NULL, the return ARG5 will be stored there.
     100 *
     101 * @return Negative values representing IPC errors.
     102 * @return Otherwise the RETVAL of the answer.
     103 *
     104 */
     105int ipc_call_sync_fast(int phoneid, sysarg_t method, sysarg_t arg1,
     106    sysarg_t arg2, sysarg_t arg3, sysarg_t *result1, sysarg_t *result2,
     107    sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
    109108{
    110109        ipc_call_t resdata;
    111         int callres;
    112        
    113         callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
     110        int callres = __SYSCALL6(SYS_IPC_CALL_SYNC_FAST, phoneid, method, arg1,
    114111            arg2, arg3, (sysarg_t) &resdata);
    115112        if (callres)
    116113                return callres;
     114       
    117115        if (result1)
    118116                *result1 = IPC_GET_ARG1(resdata);
     
    125123        if (result5)
    126124                *result5 = IPC_GET_ARG5(resdata);
    127 
     125       
    128126        return IPC_GET_RETVAL(resdata);
    129127}
    130128
    131 /** Make a synchronous call transmitting 5 arguments of payload.
     129/** Synchronous call transmitting 5 arguments of payload.
    132130 *
    133131 * @param phoneid Phone handle for the call.
     
    144142 * @param result5 If non-NULL, storage for the fifth return argument.
    145143 *
    146  * @return Negative value means IPC error.
    147  *         Otherwise the RETVAL of the answer.
    148  *
    149  */
    150 int
    151 ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1, sysarg_t arg2,
    152     sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *result1,
    153     sysarg_t *result2, sysarg_t *result3, sysarg_t *result4, sysarg_t *result5)
     144 * @return Negative values representing IPC errors.
     145 * @return Otherwise the RETVAL of the answer.
     146 *
     147 */
     148int ipc_call_sync_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
     149    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
     150    sysarg_t *result1, sysarg_t *result2, sysarg_t *result3, sysarg_t *result4,
     151    sysarg_t *result5)
    154152{
    155153        ipc_call_t data;
     
    181179}
    182180
    183 /** Syscall to send asynchronous message.
     181/** Send asynchronous message via syscall.
    184182 *
    185183 * @param phoneid Phone handle for the call.
     
    189187 *
    190188 */
    191 static ipc_callid_t _ipc_call_async(int phoneid, ipc_call_t *data)
     189static ipc_callid_t ipc_call_async_internal(int phoneid, ipc_call_t *data)
    192190{
    193191        return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data);
    194192}
    195193
    196 /** Prolog to ipc_call_async_*() functions.
    197  *
    198  * @param private       Argument for the answer/error callback.
    199  * @param callback      Answer/error callback.
    200  *
    201  * @return              New, partially initialized async_call structure or NULL.
     194/** Prolog for ipc_call_async_*() functions.
     195 *
     196 * @param private  Argument for the answer/error callback.
     197 * @param callback Answer/error callback.
     198 *
     199 * @return New, partially initialized async_call structure or NULL.
     200 *
    202201 */
    203202static inline async_call_t *ipc_prepare_async(void *private,
    204203    ipc_async_callback_t callback)
    205204{
    206         async_call_t *call;
    207 
    208         call = malloc(sizeof(*call));
     205        async_call_t *call =
     206            (async_call_t *) malloc(sizeof(async_call_t));
    209207        if (!call) {
    210208                if (callback)
    211209                        callback(private, ENOMEM, NULL);
     210               
    212211                return NULL;
    213212        }
     213       
    214214        call->callback = callback;
    215215        call->private = private;
    216 
     216       
    217217        return call;
    218218}
    219219
    220 /** Epilogue of ipc_call_async_*() functions.
    221  *
    222  * @param callid        Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
    223  * @param phoneid       Phone handle through which the call was made.
    224  * @param call          async_call structure returned by ipc_prepare_async().
    225  * @param can_preempt   If non-zero, the current fibril can be preempted in this
    226  *                      call.
     220/** Epilog for ipc_call_async_*() functions.
     221 *
     222 * @param callid      Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
     223 * @param phoneid     Phone handle through which the call was made.
     224 * @param call        Structure returned by ipc_prepare_async().
     225 * @param can_preempt If true, the current fibril can be preempted
     226 *                    in this call.
     227 *
    227228 */
    228229static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
    229     async_call_t *call, int can_preempt)
    230 {
    231         if (!call) { /* Nothing to do regardless if failed or not */
     230    async_call_t *call, bool can_preempt)
     231{
     232        if (!call) {
     233                /* Nothing to do regardless if failed or not */
    232234                futex_up(&ipc_futex);
    233235                return;
    234236        }
    235 
     237       
    236238        if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
    237239                futex_up(&ipc_futex);
     240               
    238241                /* Call asynchronous handler with error code */
    239242                if (call->callback)
    240243                        call->callback(call->private, ENOENT, NULL);
     244               
    241245                free(call);
    242246                return;
    243247        }
    244 
     248       
    245249        if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
    246250                futex_up(&ipc_futex);
    247 
     251               
    248252                call->u.msg.phoneid = phoneid;
    249253               
    250254                futex_down(&async_futex);
    251255                list_append(&call->list, &queued_calls);
    252 
     256               
    253257                if (can_preempt) {
    254258                        call->fid = fibril_get_id();
     
    259263                        futex_up(&async_futex);
    260264                }
     265               
    261266                return;
    262267        }
     268       
    263269        call->u.callid = callid;
     270       
    264271        /* Add call to the list of dispatched calls */
    265272        list_append(&call->list, &dispatched_calls);
    266273        futex_up(&ipc_futex);
    267        
    268 }
    269 
    270 /** Make a fast asynchronous call.
     274}
     275
     276/** Fast asynchronous call.
    271277 *
    272278 * This function can only handle four arguments of payload. It is, however,
     
    274280 *
    275281 * Note that this function is a void function.
    276  * During normal opertation, answering this call will trigger the callback.
    277  * In case of fatal error, call the callback handler with the proper error code.
    278  * If the call cannot be temporarily made, queue it.
     282 *
     283 * During normal operation, answering this call will trigger the callback.
     284 * In case of fatal error, the callback handler is called with the proper
     285 * error code. If the call cannot be temporarily made, it is queued.
    279286 *
    280287 * @param phoneid     Phone handle for the call.
     
    286293 * @param private     Argument to be passed to the answer/error callback.
    287294 * @param callback    Answer or error callback.
    288  * @param can_preempt If non-zero, the current fibril will be preempted in
     295 * @param can_preempt If true, the current fibril will be preempted in
    289296 *                    case the kernel temporarily refuses to accept more
    290297 *                    asynchronous calls.
     
    293300void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
    294301    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, void *private,
    295     ipc_async_callback_t callback, int can_preempt)
     302    ipc_async_callback_t callback, bool can_preempt)
    296303{
    297304        async_call_t *call = NULL;
     
    304311       
    305312        /*
    306          * We need to make sure that we get callid before another thread
    307          * accesses the queue again.
     313         * We need to make sure that we get callid
     314         * before another thread accesses the queue again.
    308315         */
     316       
    309317        futex_down(&ipc_futex);
    310318        ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
     
    317325                                return;
    318326                }
     327               
    319328                IPC_SET_IMETHOD(call->u.msg.data, imethod);
    320329                IPC_SET_ARG1(call->u.msg.data, arg1);
     
    322331                IPC_SET_ARG3(call->u.msg.data, arg3);
    323332                IPC_SET_ARG4(call->u.msg.data, arg4);
     333               
    324334                /*
    325335                 * To achieve deterministic behavior, we always zero out the
    326336                 * arguments that are beyond the limits of the fast version.
    327337                 */
     338               
    328339                IPC_SET_ARG5(call->u.msg.data, 0);
    329340        }
     341       
    330342        ipc_finish_async(callid, phoneid, call, can_preempt);
    331343}
    332344
    333 /** Make an asynchronous call transmitting the entire payload.
     345/** Asynchronous call transmitting the entire payload.
    334346 *
    335347 * Note that this function is a void function.
    336  * During normal opertation, answering this call will trigger the callback.
    337  * In case of fatal error, call the callback handler with the proper error code.
    338  * If the call cannot be temporarily made, queue it.
     348 *
     349 * During normal operation, answering this call will trigger the callback.
     350 * In case of fatal error, the callback handler is called with the proper
     351 * error code. If the call cannot be temporarily made, it is queued.
    339352 *
    340353 * @param phoneid     Phone handle for the call.
     
    347360 * @param private     Argument to be passed to the answer/error callback.
    348361 * @param callback    Answer or error callback.
    349  * @param can_preempt If non-zero, the current fibril will be preempted in
     362 * @param can_preempt If true, the current fibril will be preempted in
    350363 *                    case the kernel temporarily refuses to accept more
    351364 *                    asynchronous calls.
     
    354367void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
    355368    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
    356     ipc_async_callback_t callback, int can_preempt)
    357 {
    358         async_call_t *call;
    359         ipc_callid_t callid;
    360 
    361         call = ipc_prepare_async(private, callback);
     369    ipc_async_callback_t callback, bool can_preempt)
     370{
     371        async_call_t *call = ipc_prepare_async(private, callback);
    362372        if (!call)
    363373                return;
    364 
     374       
    365375        IPC_SET_IMETHOD(call->u.msg.data, imethod);
    366376        IPC_SET_ARG1(call->u.msg.data, arg1);
     
    369379        IPC_SET_ARG4(call->u.msg.data, arg4);
    370380        IPC_SET_ARG5(call->u.msg.data, arg5);
     381       
    371382        /*
    372          * We need to make sure that we get callid before another thread
    373          * accesses the queue again.
     383         * We need to make sure that we get callid
     384         * before another threadaccesses the queue again.
    374385         */
     386       
    375387        futex_down(&ipc_futex);
    376         callid = _ipc_call_async(phoneid, &call->u.msg.data);
    377 
     388        ipc_callid_t callid =
     389            ipc_call_async_internal(phoneid, &call->u.msg.data);
     390       
    378391        ipc_finish_async(callid, phoneid, call, can_preempt);
    379392}
    380393
    381 
    382 /** Answer a received call - fast version.
     394/** Answer received call (fast version).
    383395 *
    384396 * The fast answer makes use of passing retval and first four arguments in
    385397 * registers. If you need to return more, use the ipc_answer_slow() instead.
    386398 *
    387  * @param callid        Hash of the call being answered.
    388  * @param retval        Return value.
    389  * @param arg1          First return argument.
    390  * @param arg2          Second return argument.
    391  * @param arg3          Third return argument.
    392  * @param arg4          Fourth return argument.
    393  *
    394  * @return              Zero on success or a value from @ref errno.h on failure.
     399 * @param callid Hash of the call being answered.
     400 * @param retval Return value.
     401 * @param arg1   First return argument.
     402 * @param arg2   Second return argument.
     403 * @param arg3   Third return argument.
     404 * @param arg4   Fourth return argument.
     405 *
     406 * @return Zero on success.
     407 * @return Value from @ref errno.h on failure.
     408 *
    395409 */
    396410sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     
    401415}
    402416
    403 /** Answer a received call - slow full version.
    404  *
    405  * @param callid        Hash of the call being answered.
    406  * @param retval        Return value.
    407  * @param arg1          First return argument.
    408  * @param arg2          Second return argument.
    409  * @param arg3          Third return argument.
    410  * @param arg4          Fourth return argument.
    411  * @param arg5          Fifth return argument.
    412  *
    413  * @return              Zero on success or a value from @ref errno.h on failure.
     417/** Answer received call (entire payload).
     418 *
     419 * @param callid Hash of the call being answered.
     420 * @param retval Return value.
     421 * @param arg1   First return argument.
     422 * @param arg2   Second return argument.
     423 * @param arg3   Third return argument.
     424 * @param arg4   Fourth return argument.
     425 * @param arg5   Fifth return argument.
     426 *
     427 * @return Zero on success.
     428 * @return Value from @ref errno.h on failure.
     429 *
    414430 */
    415431sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
     
    417433{
    418434        ipc_call_t data;
    419 
     435       
    420436        IPC_SET_RETVAL(data, retval);
    421437        IPC_SET_ARG1(data, arg1);
     
    424440        IPC_SET_ARG4(data, arg4);
    425441        IPC_SET_ARG5(data, arg5);
    426 
     442       
    427443        return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
    428444}
    429445
    430 
    431 /** Try to dispatch queued calls from the async queue. */
    432 static void try_dispatch_queued_calls(void)
    433 {
    434         async_call_t *call;
    435         ipc_callid_t callid;
    436 
     446/** Try to dispatch queued calls from the async queue.
     447 *
     448 */
     449static void dispatch_queued_calls(void)
     450{
    437451        /** @todo
    438          * Integrate intelligently ipc_futex, so that it is locked during
    439          * ipc_call_async_*(), until it is added to dispatched_calls.
     452         * Integrate intelligently ipc_futex so that it is locked during
     453         * ipc_call_async_*() until it is added to dispatched_calls.
    440454         */
     455       
    441456        futex_down(&async_futex);
     457       
    442458        while (!list_empty(&queued_calls)) {
    443                 call = list_get_instance(queued_calls.next, async_call_t, list);
    444                 callid = _ipc_call_async(call->u.msg.phoneid,
    445                     &call->u.msg.data);
    446                 if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY) {
     459                async_call_t *call =
     460                    list_get_instance(queued_calls.next, async_call_t, list);
     461                ipc_callid_t callid =
     462                    ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data);
     463               
     464                if (callid == (ipc_callid_t) IPC_CALLRET_TEMPORARY)
    447465                        break;
    448                 }
     466               
    449467                list_remove(&call->list);
    450 
     468               
    451469                futex_up(&async_futex);
     470               
    452471                if (call->fid)
    453472                        fibril_add_ready(call->fid);
     
    456475                        if (call->callback)
    457476                                call->callback(call->private, ENOENT, NULL);
     477                       
    458478                        free(call);
    459479                } else {
    460480                        call->u.callid = callid;
     481                       
    461482                        futex_down(&ipc_futex);
    462483                        list_append(&call->list, &dispatched_calls);
    463484                        futex_up(&ipc_futex);
    464485                }
     486               
    465487                futex_down(&async_futex);
    466488        }
     489       
    467490        futex_up(&async_futex);
    468491}
    469492
    470 /** Handle a received answer.
     493/** Handle received answer.
    471494 *
    472495 * Find the hash of the answer and call the answer callback.
    473496 *
    474  * @todo Make it use hash table.
    475  *
    476  * @param callid        Hash of the received answer.
    477  *                      The answer has the same hash as the request OR'ed with
    478  *                      the IPC_CALLID_ANSWERED bit.
    479  * @param data          Call data of the answer.
     497 * The answer has the same hash as the request OR'ed with
     498 * the IPC_CALLID_ANSWERED bit.
     499 *
     500 * @todo Use hash table.
     501 *
     502 * @param callid Hash of the received answer.
     503 * @param data   Call data of the answer.
     504 *
    480505 */
    481506static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
    482507{
     508        callid &= ~IPC_CALLID_ANSWERED;
     509       
     510        futex_down(&ipc_futex);
     511       
    483512        link_t *item;
    484         async_call_t *call;
    485 
    486         callid &= ~IPC_CALLID_ANSWERED;
    487        
    488         futex_down(&ipc_futex);
    489513        for (item = dispatched_calls.next; item != &dispatched_calls;
    490514            item = item->next) {
    491                 call = list_get_instance(item, async_call_t, list);
     515                async_call_t *call =
     516                    list_get_instance(item, async_call_t, list);
     517               
    492518                if (call->u.callid == callid) {
    493519                        list_remove(&call->list);
     520                       
    494521                        futex_up(&ipc_futex);
     522                       
    495523                        if (call->callback)
    496                                 call->callback(call->private, 
     524                                call->callback(call->private,
    497525                                    IPC_GET_RETVAL(*data), data);
     526                       
    498527                        free(call);
    499528                        return;
    500529                }
    501530        }
     531       
    502532        futex_up(&ipc_futex);
    503533}
    504534
    505 
    506 /** Wait for a first call to come.
    507  *
    508  * @param call          Storage where the incoming call data will be stored.
    509  * @param usec          Timeout in microseconds
    510  * @param flags         Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
    511  *
    512  * @return              Hash of the call. Note that certain bits have special
    513  *                      meaning. IPC_CALLID_ANSWERED will be set in an answer
    514  *                      and IPC_CALLID_NOTIFICATION is used for notifications.
    515  *                     
    516  */
    517 ipc_callid_t ipc_wait_cycle(ipc_call_t *call, uint32_t usec, int flags)
    518 {
    519         ipc_callid_t callid;
    520 
    521         callid = __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
     535/** Wait for first IPC call to come.
     536 *
     537 * @param call  Incoming call storage.
     538 * @param usec  Timeout in microseconds
     539 * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
     540 *
     541 * @return Hash of the call. Note that certain bits have special
     542 *         meaning: IPC_CALLID_ANSWERED is set in an answer
     543 *         and IPC_CALLID_NOTIFICATION is used for notifications.
     544 *
     545 */
     546ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec,
     547    unsigned int flags)
     548{
     549        ipc_callid_t callid =
     550            __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
     551       
    522552        /* Handle received answers */
    523553        if (callid & IPC_CALLID_ANSWERED) {
    524554                handle_answer(callid, call);
    525                 try_dispatch_queued_calls();
     555                dispatch_queued_calls();
    526556        }
    527 
     557       
    528558        return callid;
    529559}
    530560
    531 /** Wait some time for an IPC call.
    532  *
    533  * The call will return after an answer is received.
    534  *
    535  * @param call          Storage where the incoming call data will be stored.
    536  * @param usec          Timeout in microseconds.
    537  *
    538  * @return              Hash of the answer.
    539  */
    540 ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, uint32_t usec)
     561/** Interrupt one thread of this task from waiting for IPC.
     562 *
     563 */
     564void ipc_poke(void)
     565{
     566        __SYSCALL0(SYS_IPC_POKE);
     567}
     568
     569/** Wait for first IPC call to come.
     570 *
     571 * Only requests are returned, answers are processed internally.
     572 *
     573 * @param call Incoming call storage.
     574 * @param usec Timeout in microseconds
     575 *
     576 * @return Hash of the call.
     577 *
     578 */
     579ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
    541580{
    542581        ipc_callid_t callid;
    543 
     582       
    544583        do {
    545584                callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
    546585        } while (callid & IPC_CALLID_ANSWERED);
    547 
     586       
    548587        return callid;
    549588}
     
    551590/** Check if there is an IPC call waiting to be picked up.
    552591 *
    553  * @param call          Storage where the incoming call will be stored.
    554  * @return              Hash of the answer.
     592 * Only requests are returned, answers are processed internally.
     593 *
     594 * @param call Incoming call storage.
     595 *
     596 * @return Hash of the call.
     597 *
    555598 */
    556599ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
    557600{
    558601        ipc_callid_t callid;
    559 
     602       
    560603        do {
    561604                callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
    562605                    SYNCH_FLAGS_NON_BLOCKING);
    563606        } while (callid & IPC_CALLID_ANSWERED);
    564 
     607       
    565608        return callid;
    566609}
    567610
    568 /** Interrupt one thread of this task from waiting for IPC. */
    569 void ipc_poke(void)
    570 {
    571         __SYSCALL0(SYS_IPC_POKE);
    572 }
    573 
    574 /** Ask destination to do a callback connection.
    575  *
    576  * @param phoneid       Phone handle used for contacting the other side.
    577  * @param arg1          Service-defined argument.
    578  * @param arg2          Service-defined argument.
    579  * @param arg3          Service-defined argument.
    580  * @param taskhash      Storage where the kernel will store an opaque
    581  *                      identifier of the client task.
    582  * @param phonehash     Storage where the kernel will store an opaque
    583  *                      identifier of the phone that will be used for incoming
    584  *                      calls. This identifier can be used for connection
    585  *                      tracking.
    586  *
    587  * @return              Zero on success or a negative error code.
    588  */
    589 int ipc_connect_to_me(int phoneid, int arg1, int arg2, int arg3,
     611/** Request callback connection.
     612 *
     613 * The @a taskhash and @a phonehash identifiers returned
     614 * by the kernel can be used for connection tracking.
     615 *
     616 * @param phoneid   Phone handle used for contacting the other side.
     617 * @param arg1      User defined argument.
     618 * @param arg2      User defined argument.
     619 * @param arg3      User defined argument.
     620 * @param taskhash  Opaque identifier of the client task.
     621 * @param phonehash Opaque identifier of the phone that will
     622 *                  be used for incoming calls.
     623 *
     624 * @return Zero on success or a negative error code.
     625 *
     626 */
     627int ipc_connect_to_me(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    590628    sysarg_t *taskhash, sysarg_t *phonehash)
    591629{
     
    594632}
    595633
    596 /** Ask through phone for a new connection to some service.
    597  *
    598  * @param phoneid       Phone handle used for contacting the other side.
    599  * @param arg1          User defined argument.
    600  * @param arg2          User defined argument.
    601  * @param arg3          User defined argument.
    602  *
    603  * @return              New phone handle on success or a negative error code.
    604  */
    605 int ipc_connect_me_to(int phoneid, int arg1, int arg2, int arg3)
     634/** Request new connection.
     635 *
     636 * @param phoneid Phone handle used for contacting the other side.
     637 * @param arg1    User defined argument.
     638 * @param arg2    User defined argument.
     639 * @param arg3    User defined argument.
     640 *
     641 * @return New phone handle on success or a negative error code.
     642 *
     643 */
     644int ipc_connect_me_to(int phoneid, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3)
    606645{
    607646        sysarg_t newphid;
    608         int res;
    609 
    610         res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     647        int res = ipc_call_sync_3_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    611648            NULL, NULL, NULL, NULL, &newphid);
    612649        if (res)
    613650                return res;
     651       
    614652        return newphid;
    615653}
    616654
    617 /** Ask through phone for a new connection to some service.
     655/** Request new connection (blocking)
    618656 *
    619657 * If the connection is not available at the moment, the
    620  * call will block.
    621  *
    622  * @param phoneid       Phone handle used for contacting the other side.
    623  * @param arg1          User defined argument.
    624  * @param arg2          User defined argument.
    625  * @param arg3          User defined argument.
    626  *
    627  * @return              New phone handle on success or a negative error code.
    628  */
    629 int ipc_connect_me_to_blocking(int phoneid, int arg1, int arg2, int arg3)
     658 * call should block. This has to be, however, implemented
     659 * on the server side.
     660 *
     661 * @param phoneid Phone handle used for contacting the other side.
     662 * @param arg1    User defined argument.
     663 * @param arg2    User defined argument.
     664 * @param arg3    User defined argument.
     665 *
     666 * @return New phone handle on success or a negative error code.
     667 *
     668 */
     669int ipc_connect_me_to_blocking(int phoneid, sysarg_t arg1, sysarg_t arg2,
     670    sysarg_t arg3)
    630671{
    631672        sysarg_t newphid;
    632         int res;
    633 
    634         res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
     673        int res = ipc_call_sync_4_5(phoneid, IPC_M_CONNECT_ME_TO, arg1, arg2, arg3,
    635674            IPC_FLAG_BLOCKING, NULL, NULL, NULL, NULL, &newphid);
    636675        if (res)
    637676                return res;
     677       
    638678        return newphid;
    639679}
     
    641681/** Hang up a phone.
    642682 *
    643  * @param phoneid       Handle of the phone to be hung up.
    644  *
    645  * @return              Zero on success or a negative error code.
     683 * @param phoneid Handle of the phone to be hung up.
     684 *
     685 * @return Zero on success or a negative error code.
     686 *
    646687 */
    647688int ipc_hangup(int phoneid)
     
    650691}
    651692
    652 /** Register IRQ notification.
    653  *
    654  * @param inr           IRQ number.
    655  * @param devno         Device number of the device generating inr.
    656  * @param method        Use this method for notifying me.
    657  * @param ucode         Top-half pseudocode handler.
    658  *
    659  * @return              Value returned by the kernel.
    660  */
    661 int ipc_register_irq(int inr, int devno, int method, irq_code_t *ucode)
    662 {
    663         return __SYSCALL4(SYS_IPC_REGISTER_IRQ, inr, devno, method,
    664             (sysarg_t) ucode);
    665 }
    666 
    667 /** Unregister IRQ notification.
    668  *
    669  * @param inr           IRQ number.
    670  * @param devno         Device number of the device generating inr.
    671  *
    672  * @return              Value returned by the kernel.
    673  */
    674 int ipc_unregister_irq(int inr, int devno)
    675 {
    676         return __SYSCALL2(SYS_IPC_UNREGISTER_IRQ, inr, devno);
    677 }
    678 
    679693/** Forward a received call to another destination.
     694 *
     695 * For non-system methods, the old method, arg1 and arg2 are rewritten
     696 * by the new values. For system methods, the new method, arg1 and arg2
     697 * are written to the old arg1, arg2 and arg3, respectivelly. Calls with
     698 * immutable methods are forwarded verbatim.
    680699 *
    681700 * @param callid  Hash of the call to forward.
     
    688707 * @return Zero on success or an error code.
    689708 *
    690  * For non-system methods, the old method, arg1 and arg2 are rewritten by the
    691  * new values. For system methods, the new method, arg1 and arg2 are written
    692  * to the old arg1, arg2 and arg3, respectivelly. Calls with immutable
    693  * methods are forwarded verbatim.
    694  */
    695 int ipc_forward_fast(ipc_callid_t callid, int phoneid, int imethod,
    696     sysarg_t arg1, sysarg_t arg2, int mode)
     709 */
     710int ipc_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
     711    sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    697712{
    698713        return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1,
     
    700715}
    701716
    702 
    703 int ipc_forward_slow(ipc_callid_t callid, int phoneid, int imethod,
     717int ipc_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
    704718    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
    705     int mode)
     719    unsigned int mode)
    706720{
    707721        ipc_call_t data;
     
    714728        IPC_SET_ARG5(data, arg5);
    715729       
    716         return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data, mode);
    717 }
    718 
    719 /** Wrapper for making IPC_M_SHARE_IN calls.
    720  *
    721  * @param phoneid       Phone that will be used to contact the receiving side.
    722  * @param dst           Destination address space area base.
    723  * @param size          Size of the destination address space area.
    724  * @param arg           User defined argument.
    725  * @param flags         Storage where the received flags will be stored. Can be
    726  *                      NULL.
    727  *
    728  * @return              Zero on success or a negative error code from errno.h.
     730        return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data,
     731            mode);
     732}
     733
     734/** Wrapper for IPC_M_SHARE_IN calls.
     735 *
     736 * @param phoneid Phone that will be used to contact the receiving side.
     737 * @param dst     Destination address space area base.
     738 * @param size    Size of the destination address space area.
     739 * @param arg     User defined argument.
     740 * @param flags   Storage for received flags. Can be NULL.
     741 *
     742 * @return Zero on success or a negative error code from errno.h.
     743 *
    729744 */
    730745int ipc_share_in_start(int phoneid, void *dst, size_t size, sysarg_t arg,
    731     int *flags)
     746    unsigned int *flags)
    732747{
    733748        sysarg_t tmp_flags = 0;
     
    736751       
    737752        if (flags)
    738                 *flags = tmp_flags;
     753                *flags = (unsigned int) tmp_flags;
    739754       
    740755        return res;
     
    743758/** Wrapper for answering the IPC_M_SHARE_IN calls.
    744759 *
    745  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
    746  * so that the user doesn't have to remember the meaning of each IPC argument.
    747  *
    748  * @param callid        Hash of the IPC_M_DATA_READ call to answer.
    749  * @param src           Source address space base.
    750  * @param flags         Flags to be used for sharing. Bits can be only cleared.
    751  *
    752  * @return              Zero on success or a value from @ref errno.h on failure.
    753  */
    754 int ipc_share_in_finalize(ipc_callid_t callid, void *src, int flags)
     760 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     761 * calls so that the user doesn't have to remember the meaning of each
     762 * IPC argument.
     763 *
     764 * @param callid Hash of the IPC_M_DATA_READ call to answer.
     765 * @param src    Source address space base.
     766 * @param flags Flags to be used for sharing. Bits can be only cleared.
     767 *
     768 * @return Zero on success or a value from @ref errno.h on failure.
     769 *
     770 */
     771int ipc_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
    755772{
    756773        return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) flags);
    757774}
    758775
    759 /** Wrapper for making IPC_M_SHARE_OUT calls.
    760  *
    761  * @param phoneid       Phone that will be used to contact the receiving side.
    762  * @param src           Source address space area base address.
    763  * @param flags         Flags to be used for sharing. Bits can be only cleared.
    764  *
    765  * @return              Zero on success or a negative error code from errno.h.
    766  */
    767 int ipc_share_out_start(int phoneid, void *src, int flags)
     776/** Wrapper for IPC_M_SHARE_OUT calls.
     777 *
     778 * @param phoneid Phone that will be used to contact the receiving side.
     779 * @param src     Source address space area base address.
     780 * @param flags   Flags to be used for sharing. Bits can be only cleared.
     781 *
     782 * @return Zero on success or a negative error code from errno.h.
     783 *
     784 */
     785int ipc_share_out_start(int phoneid, void *src, unsigned int flags)
    768786{
    769787        return ipc_call_sync_3_0(phoneid, IPC_M_SHARE_OUT, (sysarg_t) src, 0,
     
    773791/** Wrapper for answering the IPC_M_SHARE_OUT calls.
    774792 *
    775  * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT calls
    776  * so that the user doesn't have to remember the meaning of each IPC argument.
    777  *
    778  * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
    779  * @param dst           Destination address space area base address.   
    780  *
    781  * @return              Zero on success or a value from @ref errno.h on failure.
     793 * This wrapper only makes it more comfortable to answer IPC_M_SHARE_OUT
     794 * calls so that the user doesn't have to remember the meaning of each
     795 * IPC argument.
     796 *
     797 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     798 * @param dst    Destination address space area base address.
     799 *
     800 * @return Zero on success or a value from @ref errno.h on failure.
     801 *
    782802 */
    783803int ipc_share_out_finalize(ipc_callid_t callid, void *dst)
     
    786806}
    787807
    788 
    789 /** Wrapper for making IPC_M_DATA_READ calls.
    790  *
    791  * @param phoneid       Phone that will be used to contact the receiving side.
    792  * @param dst           Address of the beginning of the destination buffer.
    793  * @param size          Size of the destination buffer.
    794  *
    795  * @return              Zero on success or a negative error code from errno.h.
     808/** Wrapper for IPC_M_DATA_READ calls.
     809 *
     810 * @param phoneid Phone that will be used to contact the receiving side.
     811 * @param dst     Address of the beginning of the destination buffer.
     812 * @param size    Size of the destination buffer.
     813 *
     814 * @return Zero on success or a negative error code from errno.h.
     815 *
    796816 */
    797817int ipc_data_read_start(int phoneid, void *dst, size_t size)
     
    803823/** Wrapper for answering the IPC_M_DATA_READ calls.
    804824 *
    805  * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ calls
    806  * so that the user doesn't have to remember the meaning of each IPC argument.
    807  *
    808  * @param callid        Hash of the IPC_M_DATA_READ call to answer.
    809  * @param src           Source address for the IPC_M_DATA_READ call.
    810  * @param size          Size for the IPC_M_DATA_READ call. Can be smaller than
    811  *                      the maximum size announced by the sender.
    812  *
    813  * @return              Zero on success or a value from @ref errno.h on failure.
     825 * This wrapper only makes it more comfortable to answer IPC_M_DATA_READ
     826 * calls so that the user doesn't have to remember the meaning of each
     827 * IPC argument.
     828 *
     829 * @param callid Hash of the IPC_M_DATA_READ call to answer.
     830 * @param src    Source address for the IPC_M_DATA_READ call.
     831 * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
     832 *               the maximum size announced by the sender.
     833 *
     834 * @return Zero on success or a value from @ref errno.h on failure.
     835 *
    814836 */
    815837int ipc_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
     
    818840}
    819841
    820 /** Wrapper for making IPC_M_DATA_WRITE calls.
    821  *
    822  * @param phoneid       Phone that will be used to contact the receiving side.
    823  * @param src           Address of the beginning of the source buffer.
    824  * @param size          Size of the source buffer.
    825  *
    826  * @return              Zero on success or a negative error code from errno.h.
     842/** Wrapper for IPC_M_DATA_WRITE calls.
     843 *
     844 * @param phoneid Phone that will be used to contact the receiving side.
     845 * @param src     Address of the beginning of the source buffer.
     846 * @param size    Size of the source buffer.
     847 *
     848 * @return Zero on success or a negative error code from errno.h.
     849 *
    827850 */
    828851int ipc_data_write_start(int phoneid, const void *src, size_t size)
     
    834857/** Wrapper for answering the IPC_M_DATA_WRITE calls.
    835858 *
    836  * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE calls
    837  * so that the user doesn't have to remember the meaning of each IPC argument.
    838  *
    839  * @param callid        Hash of the IPC_M_DATA_WRITE call to answer.
    840  * @param dst           Final destination address for the IPC_M_DATA_WRITE call.
    841  * @param size          Final size for the IPC_M_DATA_WRITE call.
    842  *
    843  * @return              Zero on success or a value from @ref errno.h on failure.
     859 * This wrapper only makes it more comfortable to answer IPC_M_DATA_WRITE
     860 * calls so that the user doesn't have to remember the meaning of each
     861 * IPC argument.
     862 *
     863 * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
     864 * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
     865 * @param size   Final size for the IPC_M_DATA_WRITE call.
     866 *
     867 * @return Zero on success or a value from @ref errno.h on failure.
     868 *
    844869 */
    845870int ipc_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
Note: See TracChangeset for help on using the changeset viewer.