Changeset 228e490 in mainline for kernel/generic/src/ipc/sysipc.c


Ignore:
Timestamp:
2010-12-14T17:00:02Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a9b6bec, eb221e5
Parents:
dd8d5a7
Message:

initial modifications for supporting declarative IPC interfaces

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/sysipc.c

    rdd8d5a7 r228e490  
    7878}
    7979
    80 /** Decide if the method is a system method.
    81  *
    82  * @param method Method to be decided.
    83  *
    84  * @return true if the method is a system method.
    85  *
    86  */
    87 static inline bool method_is_system(sysarg_t method)
    88 {
    89         if (method <= IPC_M_LAST_SYSTEM)
     80/** Decide if the interface and method is a system method.
     81 *
     82 * @param imethod Interface and method to be decided.
     83 *
     84 * @return True if the interface and method is a system
     85 *         interface and method.
     86 *
     87 */
     88static inline bool method_is_system(sysarg_t imethod)
     89{
     90        if (imethod <= IPC_M_LAST_SYSTEM)
    9091                return true;
    9192       
     
    9394}
    9495
    95 /** Decide if the message with this method is forwardable.
    96  *
    97  * - some system messages may be forwarded, for some of them
    98  *   it is useless
    99  *
    100  * @param method Method to be decided.
    101  *
    102  * @return true if the method is forwardable.
    103  *
    104  */
    105 static inline bool method_is_forwardable(sysarg_t method)
    106 {
    107         switch (method) {
     96/** Decide if the message with this interface and method is forwardable.
     97 *
     98 * Some system messages may be forwarded, for some of them
     99 * it is useless.
     100 *
     101 * @param imethod Interface and method to be decided.
     102 *
     103 * @return True if the interface and method is forwardable.
     104 *
     105 */
     106static inline bool method_is_forwardable(sysarg_t imethod)
     107{
     108        switch (imethod) {
    108109        case IPC_M_CONNECTION_CLONE:
    109110        case IPC_M_CONNECT_ME:
     
    116117}
    117118
    118 /** Decide if the message with this method is immutable on forward.
    119  *
    120  * - some system messages may be forwarded but their content cannot be altered
    121  *
    122  * @param method Method to be decided.
    123  *
    124  * @return true if the method is immutable on forward.
    125  *
    126  */
    127 static inline bool method_is_immutable(sysarg_t method)
    128 {
    129         switch (method) {
     119/** Decide if the message with this interface and method is immutable on forward.
     120 *
     121 * Some system messages may be forwarded but their content cannot be altered.
     122 *
     123 * @param imethod Interface and method to be decided.
     124 *
     125 * @return True if the interface and method is immutable on forward.
     126 *
     127 */
     128static inline bool method_is_immutable(sysarg_t imethod)
     129{
     130        switch (imethod) {
    130131        case IPC_M_SHARE_OUT:
    131132        case IPC_M_SHARE_IN:
     
    153154static inline bool answer_need_old(call_t *call)
    154155{
    155         switch (IPC_GET_METHOD(call->data)) {
     156        switch (IPC_GET_IMETHOD(call->data)) {
    156157        case IPC_M_CONNECTION_CLONE:
    157158        case IPC_M_CONNECT_ME:
     
    197198                return 0;
    198199       
    199         if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECTION_CLONE) {
     200        if (IPC_GET_IMETHOD(*olddata) == IPC_M_CONNECTION_CLONE) {
    200201                int phoneid = IPC_GET_ARG1(*olddata);
    201202                phone_t *phone = &TASK->phones[phoneid];
     
    219220                        mutex_unlock(&phone->lock);
    220221                }
    221         } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME) {
     222        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CONNECT_ME) {
    222223                phone_t *phone = (phone_t *) IPC_GET_ARG5(*olddata);
    223224               
     
    238239                        mutex_unlock(&phone->lock);
    239240                }
    240         } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_TO_ME) {
     241        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CONNECT_TO_ME) {
    241242                int phoneid = IPC_GET_ARG5(*olddata);
    242243               
     
    251252                            (sysarg_t) &TASK->phones[phoneid]);
    252253                }
    253         } else if (IPC_GET_METHOD(*olddata) == IPC_M_CONNECT_ME_TO) {
     254        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_CONNECT_ME_TO) {
    254255                /* If the users accepted call, connect */
    255256                if (IPC_GET_RETVAL(answer->data) == EOK) {
     
    257258                            &TASK->answerbox);
    258259                }
    259         } else if (IPC_GET_METHOD(*olddata) == IPC_M_SHARE_OUT) {
     260        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_SHARE_OUT) {
    260261                if (!IPC_GET_RETVAL(answer->data)) {
    261262                        /* Accepted, handle as_area receipt */
     
    271272                        return rc;
    272273                }
    273         } else if (IPC_GET_METHOD(*olddata) == IPC_M_SHARE_IN) {
     274        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_SHARE_IN) {
    274275                if (!IPC_GET_RETVAL(answer->data)) {
    275276                        irq_spinlock_lock(&answer->sender->lock, true);
     
    282283                        IPC_SET_RETVAL(answer->data, rc);
    283284                }
    284         } else if (IPC_GET_METHOD(*olddata) == IPC_M_DATA_READ) {
     285        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_DATA_READ) {
    285286                ASSERT(!answer->buffer);
    286287                if (!IPC_GET_RETVAL(answer->data)) {
     
    311312                        }
    312313                }
    313         } else if (IPC_GET_METHOD(*olddata) == IPC_M_DATA_WRITE) {
     314        } else if (IPC_GET_IMETHOD(*olddata) == IPC_M_DATA_WRITE) {
    314315                ASSERT(answer->buffer);
    315316                if (!IPC_GET_RETVAL(answer->data)) {
     
    364365static int request_preprocess(call_t *call, phone_t *phone)
    365366{
    366         switch (IPC_GET_METHOD(call->data)) {
     367        switch (IPC_GET_IMETHOD(call->data)) {
    367368        case IPC_M_CONNECTION_CLONE: {
    368369                phone_t *cloned_phone;
     
    504505static int process_request(answerbox_t *box, call_t *call)
    505506{
    506         if (IPC_GET_METHOD(call->data) == IPC_M_CONNECT_TO_ME) {
     507        if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME) {
    507508                int phoneid = phone_alloc(TASK);
    508509                if (phoneid < 0) { /* Failed to allocate phone */
     
    515516        }
    516517       
    517         switch (IPC_GET_METHOD(call->data)) {
     518        switch (IPC_GET_IMETHOD(call->data)) {
    518519        case IPC_M_DEBUG_ALL:
    519520                return -1;
     
    531532 *
    532533 * @param phoneid Phone handle for the call.
    533  * @param method  Method of the call.
     534 * @param imethod Interface and method of the call.
    534535 * @param arg1    Service-defined payload argument.
    535536 * @param arg2    Service-defined payload argument.
    536537 * @param arg3    Service-defined payload argument.
    537  * @param data    Address of userspace structure where the reply call will
     538 * @param data    Address of user-space structure where the reply call will
    538539 *                be stored.
    539540 *
     
    542543 *
    543544 */
    544 sysarg_t sys_ipc_call_sync_fast(sysarg_t phoneid, sysarg_t method,
     545sysarg_t sys_ipc_call_sync_fast(sysarg_t phoneid, sysarg_t imethod,
    545546    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, ipc_data_t *data)
    546547{
     
    548549        if (phone_get(phoneid, &phone) != EOK)
    549550                return ENOENT;
    550 
     551       
    551552        call_t *call = ipc_call_alloc(0);
    552         IPC_SET_METHOD(call->data, method);
     553        IPC_SET_IMETHOD(call->data, imethod);
    553554        IPC_SET_ARG1(call->data, arg1);
    554555        IPC_SET_ARG2(call->data, arg2);
     
    580581               
    581582                process_answer(call);
    582                
    583583        } else
    584584                IPC_SET_RETVAL(call->data, res);
     
    594594/** Make a synchronous IPC call allowing to transmit the entire payload.
    595595 *
    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.
     596 * @param phoneid Phone handle for the call.
     597 * @param request User-space address of call data with the request.
     598 * @param reply   User-space address of call data where to store the
     599 *                answer.
    600600 *
    601601 * @return Zero on success or an error code.
    602602 *
    603603 */
    604 sysarg_t sys_ipc_call_sync_slow(sysarg_t phoneid, ipc_data_t *question,
     604sysarg_t sys_ipc_call_sync_slow(sysarg_t phoneid, ipc_data_t *request,
    605605    ipc_data_t *reply)
    606606{
     
    608608        if (phone_get(phoneid, &phone) != EOK)
    609609                return ENOENT;
    610 
     610       
    611611        call_t *call = ipc_call_alloc(0);
    612         int rc = copy_from_uspace(&call->data.args, &question->args,
     612        int rc = copy_from_uspace(&call->data.args, &request->args,
    613613            sizeof(call->data.args));
    614614        if (rc != 0) {
     
    648648 * made over a phone.
    649649 *
    650  * @param phone Phone to check the limit against.
     650 * @param phone Phone to check the limit against.
     651 *
    651652 * @return 0 if limit not reached or -1 if limit exceeded.
    652653 *
     
    666667 *
    667668 * @param phoneid Phone handle for the call.
    668  * @param method  Method of the call.
     669 * @param imethod Interface and method of the call.
    669670 * @param arg1    Service-defined payload argument.
    670671 * @param arg2    Service-defined payload argument.
     
    678679 *
    679680 */
    680 sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t method,
     681sysarg_t sys_ipc_call_async_fast(sysarg_t phoneid, sysarg_t imethod,
    681682    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
    682683{
     
    684685        if (phone_get(phoneid, &phone) != EOK)
    685686                return IPC_CALLRET_FATAL;
    686 
     687       
    687688        if (check_call_limit(phone))
    688689                return IPC_CALLRET_TEMPORARY;
    689690       
    690691        call_t *call = ipc_call_alloc(0);
    691         IPC_SET_METHOD(call->data, method);
     692        IPC_SET_IMETHOD(call->data, imethod);
    692693        IPC_SET_ARG1(call->data, arg1);
    693694        IPC_SET_ARG2(call->data, arg2);
     
    752753 * @param callid  Hash of the call to forward.
    753754 * @param phoneid Phone handle to use for forwarding.
    754  * @param method  New method to use for the forwarded call.
     755 * @param imethod New interface and method to use for the forwarded call.
    755756 * @param arg1    New value of the first argument for the forwarded call.
    756757 * @param arg2    New value of the second argument for the forwarded call.
     
    769770 */
    770771static 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 imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
    772773    sysarg_t arg4, sysarg_t arg5, unsigned int mode, bool slow)
    773774{
     
    785786        }
    786787       
    787         if (!method_is_forwardable(IPC_GET_METHOD(call->data))) {
     788        if (!method_is_forwardable(IPC_GET_IMETHOD(call->data))) {
    788789                IPC_SET_RETVAL(call->data, EFORWARD);
    789790                ipc_answer(&TASK->answerbox, call);
     
    792793       
    793794        /*
    794          * Userspace is not allowed to change method of system methods on
    795          * forward, allow changing ARG1, ARG2, ARG3 and ARG4 by means of method,
    796          * arg1, arg2 and arg3.
    797          * If the method is immutable, don't change anything.
     795         * Userspace is not allowed to change interface and method of system
     796         * methods on forward, allow changing ARG1, ARG2, ARG3 and ARG4 by
     797         * means of method, arg1, arg2 and arg3.
     798         * If the interface and method is immutable, don't change anything.
    798799         */
    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)
     800        if (!method_is_immutable(IPC_GET_IMETHOD(call->data))) {
     801                if (method_is_system(IPC_GET_IMETHOD(call->data))) {
     802                        if (IPC_GET_IMETHOD(call->data) == IPC_M_CONNECT_TO_ME)
    802803                                phone_dealloc(IPC_GET_ARG5(call->data));
    803804                       
    804                         IPC_SET_ARG1(call->data, method);
     805                        IPC_SET_ARG1(call->data, imethod);
    805806                        IPC_SET_ARG2(call->data, arg1);
    806807                        IPC_SET_ARG3(call->data, arg2);
     
    814815                        }
    815816                } else {
    816                         IPC_SET_METHOD(call->data, method);
     817                        IPC_SET_IMETHOD(call->data, imethod);
    817818                        IPC_SET_ARG1(call->data, arg1);
    818819                        IPC_SET_ARG2(call->data, arg2);
     
    830831/** Forward a received call to another destination - fast version.
    831832 *
    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.
     833 * In case the original interface and method is a system method, ARG1, ARG2
     834 * and ARG3 are overwritten in the forwarded message with the new method and
     835 * the new arg1 and arg2, respectively. Otherwise the IMETHOD, ARG1 and ARG2
     836 * are rewritten with the new interface and method, arg1 and arg2, respectively.
     837 * Also note there is a set of immutable methods, for which the new method and
     838 * arguments are not set and these values are ignored.
    838839 *
    839840 * @param callid  Hash of the call to forward.
    840841 * @param phoneid Phone handle to use for forwarding.
    841  * @param method  New method to use for the forwarded call.
     842 * @param imethod New interface and method to use for the forwarded call.
    842843 * @param arg1    New value of the first argument for the forwarded call.
    843844 * @param arg2    New value of the second argument for the forwarded call.
     
    848849 */
    849850sysarg_t sys_ipc_forward_fast(sysarg_t callid, sysarg_t phoneid,
    850     sysarg_t method, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
    851 {
    852         return sys_ipc_forward_common(callid, phoneid, method, arg1, arg2, 0, 0,
     851    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
     852{
     853        return sys_ipc_forward_common(callid, phoneid, imethod, arg1, arg2, 0, 0,
    853854            0, mode, false);
    854855}
     
    857858 *
    858859 * 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.
     860 * It can copy all five new arguments and the new interface and method from
     861 * the userspace. It naturally extends the functionality of the fast version.
     862 * For system methods, it additionally stores the new value of arg3 to ARG4.
     863 * For non-system methods, it additionally stores the new value of arg3, arg4
     864 * and arg5, respectively, to ARG3, ARG4 and ARG5, respectively.
    864865 *
    865866 * @param callid  Hash of the call to forward.
     
    881882       
    882883        return sys_ipc_forward_common(callid, phoneid,
    883             IPC_GET_METHOD(newdata), IPC_GET_ARG1(newdata),
     884            IPC_GET_IMETHOD(newdata), IPC_GET_ARG1(newdata),
    884885            IPC_GET_ARG2(newdata), IPC_GET_ARG3(newdata),
    885886            IPC_GET_ARG4(newdata), IPC_GET_ARG5(newdata), mode, true);
     
    10941095/** Connect an IRQ handler to a task.
    10951096 *
    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.
     1097 * @param inr     IRQ number.
     1098 * @param devno   Device number.
     1099 * @param imethod Interface and method to be associated with the notification.
     1100 * @param ucode   Uspace pointer to the top-half pseudocode.
    11001101 *
    11011102 * @return EPERM or a return code returned by ipc_irq_register().
    11021103 *
    11031104 */
    1104 sysarg_t sys_ipc_register_irq(inr_t inr, devno_t devno, sysarg_t method,
     1105sysarg_t sys_ipc_register_irq(inr_t inr, devno_t devno, sysarg_t imethod,
    11051106    irq_code_t *ucode)
    11061107{
     
    11081109                return EPERM;
    11091110       
    1110         return ipc_irq_register(&TASK->answerbox, inr, devno, method, ucode);
     1111        return ipc_irq_register(&TASK->answerbox, inr, devno, imethod, ucode);
    11111112}
    11121113
Note: See TracChangeset for help on using the changeset viewer.