Changeset 1affcdf3 in mainline for uspace/lib/drv/generic/driver.c


Ignore:
Timestamp:
2011-06-10T19:33:41Z (13 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1878386
Parents:
13ecdac9 (diff), 79a141a (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/drv/generic/driver.c

    r13ecdac9 r1affcdf3  
    285285        async_answer_0(iid, EOK);
    286286       
    287         bool cont = true;
    288         while (cont) {
     287        while (true) {
    289288                ipc_call_t call;
    290289                ipc_callid_t callid = async_get_call(&call);
    291290               
     291                if (!IPC_GET_IMETHOD(call))
     292                        break;
     293               
    292294                switch (IPC_GET_IMETHOD(call)) {
    293                 case IPC_M_PHONE_HUNGUP:
    294                         cont = false;
    295                         continue;
    296295                case DRIVER_ADD_DEVICE:
    297296                        driver_add_device(callid, &call);
     
    303302}
    304303
    305 /**
    306  * Generic client connection handler both for applications and drivers.
    307  *
    308  * @param drv           True for driver client, false for other clients
    309  *                      (applications, services etc.).
     304/** Generic client connection handler both for applications and drivers.
     305 *
     306 * @param drv True for driver client, false for other clients
     307 *            (applications, services, etc.).
     308 *
    310309 */
    311310static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
     
    317316        devman_handle_t handle = IPC_GET_ARG2(*icall);
    318317        ddf_fun_t *fun = driver_get_function(&functions, handle);
    319 
     318       
    320319        if (fun == NULL) {
    321320                printf("%s: driver_connection_gen error - no function with handle"
     
    325324        }
    326325       
    327        
    328326        /*
    329327         * TODO - if the client is not a driver, check whether it is allowed to
     
    340338                return;
    341339       
    342         while (1) {
     340        while (true) {
    343341                ipc_callid_t callid;
    344342                ipc_call_t call;
    345343                callid = async_get_call(&call);
    346344                sysarg_t method = IPC_GET_IMETHOD(call);
    347                 int iface_idx;
    348                
    349                 switch  (method) {
    350                 case IPC_M_PHONE_HUNGUP:
     345               
     346                if (!method) {
    351347                        /* Close device function */
    352348                        if (fun->ops != NULL && fun->ops->close != NULL)
     
    354350                        async_answer_0(callid, EOK);
    355351                        return;
    356                 default:
    357                         /* convert ipc interface id to interface index */
    358                        
    359                         iface_idx = DEV_IFACE_IDX(method);
    360                        
    361                         if (!is_valid_iface_idx(iface_idx)) {
    362                                 remote_handler_t *default_handler =
    363                                     function_get_default_handler(fun);
    364                                 if (default_handler != NULL) {
    365                                         (*default_handler)(fun, callid, &call);
    366                                         break;
    367                                 }
    368                                
    369                                 /*
    370                                  * Function has no such interface and
    371                                  * default handler is not provided.
    372                                  */
    373                                 printf("%s: driver_connection_gen error - "
    374                                     "invalid interface id %d.",
    375                                     driver->name, iface_idx);
    376                                 async_answer_0(callid, ENOTSUP);
    377                                 break;
    378                         }
    379                        
    380                         /* calling one of the function's interfaces */
    381                        
    382                         /* Get the interface ops structure. */
    383                         void *ops = function_get_ops(fun, iface_idx);
    384                         if (ops == NULL) {
    385                                 printf("%s: driver_connection_gen error - ",
    386                                     driver->name);
    387                                 printf("Function with handle %" PRIun " has no interface "
    388                                     "with id %d.\n", handle, iface_idx);
    389                                 async_answer_0(callid, ENOTSUP);
    390                                 break;
     352                }
     353               
     354                /* Convert ipc interface id to interface index */
     355               
     356                int iface_idx = DEV_IFACE_IDX(method);
     357               
     358                if (!is_valid_iface_idx(iface_idx)) {
     359                        remote_handler_t *default_handler =
     360                            function_get_default_handler(fun);
     361                        if (default_handler != NULL) {
     362                                (*default_handler)(fun, callid, &call);
     363                                continue;
    391364                        }
    392365                       
    393366                        /*
    394                          * Get the corresponding interface for remote request
    395                          * handling ("remote interface").
     367                         * Function has no such interface and
     368                         * default handler is not provided.
    396369                         */
    397                         remote_iface_t *rem_iface = get_remote_iface(iface_idx);
    398                         assert(rem_iface != NULL);
    399                        
    400                         /* get the method of the remote interface */
    401                         sysarg_t iface_method_idx = IPC_GET_ARG1(call);
    402                         remote_iface_func_ptr_t iface_method_ptr =
    403                             get_remote_method(rem_iface, iface_method_idx);
    404                         if (iface_method_ptr == NULL) {
    405                                 /* The interface has not such method */
    406                                 printf("%s: driver_connection_gen error - "
    407                                     "invalid interface method.", driver->name);
    408                                 async_answer_0(callid, ENOTSUP);
    409                                 break;
    410                         }
    411                        
    412                         /*
    413                          * Call the remote interface's method, which will
    414                          * receive parameters from the remote client and it will
    415                          * pass it to the corresponding local interface method
    416                          * associated with the function by its driver.
    417                          */
    418                         (*iface_method_ptr)(fun, ops, callid, &call);
    419                         break;
    420                 }
     370                        printf("%s: driver_connection_gen error - "
     371                            "invalid interface id %d.",
     372                            driver->name, iface_idx);
     373                        async_answer_0(callid, ENOTSUP);
     374                        continue;
     375                }
     376               
     377                /* Calling one of the function's interfaces */
     378               
     379                /* Get the interface ops structure. */
     380                void *ops = function_get_ops(fun, iface_idx);
     381                if (ops == NULL) {
     382                        printf("%s: driver_connection_gen error - ", driver->name);
     383                        printf("Function with handle %" PRIun " has no interface "
     384                            "with id %d.\n", handle, iface_idx);
     385                        async_answer_0(callid, ENOTSUP);
     386                        continue;
     387                }
     388               
     389                /*
     390                 * Get the corresponding interface for remote request
     391                 * handling ("remote interface").
     392                 */
     393                remote_iface_t *rem_iface = get_remote_iface(iface_idx);
     394                assert(rem_iface != NULL);
     395               
     396                /* get the method of the remote interface */
     397                sysarg_t iface_method_idx = IPC_GET_ARG1(call);
     398                remote_iface_func_ptr_t iface_method_ptr =
     399                    get_remote_method(rem_iface, iface_method_idx);
     400                if (iface_method_ptr == NULL) {
     401                        /* The interface has not such method */
     402                        printf("%s: driver_connection_gen error - "
     403                            "invalid interface method.", driver->name);
     404                        async_answer_0(callid, ENOTSUP);
     405                        continue;
     406                }
     407               
     408                /*
     409                 * Call the remote interface's method, which will
     410                 * receive parameters from the remote client and it will
     411                 * pass it to the corresponding local interface method
     412                 * associated with the function by its driver.
     413                 */
     414                (*iface_method_ptr)(fun, ops, callid, &call);
    421415        }
    422416}
Note: See TracChangeset for help on using the changeset viewer.