Changeset 6a44ee4 in mainline for uspace/lib/drv/generic/driver.c


Ignore:
Timestamp:
2011-07-20T15:26:21Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efcebe1
Parents:
25bef0ff (diff), a701812 (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

    r25bef0ff r6a44ee4  
    139139find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    140140{
     141        interrupt_context_t *ctx;
     142       
    141143        fibril_mutex_lock(&list->mutex);
    142144       
    143         link_t *link = list->contexts.next;
    144         interrupt_context_t *ctx;
    145        
    146         while (link != &list->contexts) {
     145        list_foreach(list->contexts, link) {
    147146                ctx = list_get_instance(link, interrupt_context_t, link);
    148147                if (ctx->id == id) {
     
    150149                        return ctx;
    151150                }
    152                 link = link->next;
    153151        }
    154152       
     
    160158find_interrupt_context(interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    161159{
     160        interrupt_context_t *ctx;
     161       
    162162        fibril_mutex_lock(&list->mutex);
    163163       
    164         link_t *link = list->contexts.next;
    165         interrupt_context_t *ctx;
    166        
    167         while (link != &list->contexts) {
     164        list_foreach(list->contexts, link) {
    168165                ctx = list_get_instance(link, interrupt_context_t, link);
    169166                if (ctx->irq == irq && ctx->dev == dev) {
     
    171168                        return ctx;
    172169                }
    173                 link = link->next;
    174170        }
    175171       
     
    231227}
    232228
    233 static ddf_fun_t *driver_get_function(link_t *functions, devman_handle_t handle)
     229static ddf_fun_t *driver_get_function(list_t *functions, devman_handle_t handle)
    234230{
    235231        ddf_fun_t *fun = NULL;
    236232       
    237233        fibril_mutex_lock(&functions_mutex);
    238         link_t *link = functions->next;
    239        
    240         while (link != functions) {
     234       
     235        list_foreach(*functions, link) {
    241236                fun = list_get_instance(link, ddf_fun_t, link);
    242237                if (fun->handle == handle) {
     
    244239                        return fun;
    245240                }
    246                
    247                 link = link->next;
    248241        }
    249242       
     
    285278        async_answer_0(iid, EOK);
    286279       
    287         bool cont = true;
    288         while (cont) {
     280        while (true) {
    289281                ipc_call_t call;
    290282                ipc_callid_t callid = async_get_call(&call);
    291283               
     284                if (!IPC_GET_IMETHOD(call))
     285                        break;
     286               
    292287                switch (IPC_GET_IMETHOD(call)) {
    293                 case IPC_M_PHONE_HUNGUP:
    294                         cont = false;
    295                         continue;
    296288                case DRIVER_ADD_DEVICE:
    297289                        driver_add_device(callid, &call);
     
    303295}
    304296
    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.).
     297/** Generic client connection handler both for applications and drivers.
     298 *
     299 * @param drv True for driver client, false for other clients
     300 *            (applications, services, etc.).
     301 *
    310302 */
    311303static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
     
    317309        devman_handle_t handle = IPC_GET_ARG2(*icall);
    318310        ddf_fun_t *fun = driver_get_function(&functions, handle);
    319 
     311       
    320312        if (fun == NULL) {
    321313                printf("%s: driver_connection_gen error - no function with handle"
     
    325317        }
    326318       
     319        if (fun->conn_handler != NULL) {
     320                /* Driver has a custom connection handler. */
     321                (*fun->conn_handler)(iid, icall, (void *)fun);
     322                return;
     323        }
    327324       
    328325        /*
     
    340337                return;
    341338       
    342         while (1) {
     339        while (true) {
    343340                ipc_callid_t callid;
    344341                ipc_call_t call;
    345342                callid = async_get_call(&call);
    346343                sysarg_t method = IPC_GET_IMETHOD(call);
    347                 int iface_idx;
    348                
    349                 switch  (method) {
    350                 case IPC_M_PHONE_HUNGUP:
     344               
     345                if (!method) {
    351346                        /* Close device function */
    352347                        if (fun->ops != NULL && fun->ops->close != NULL)
     
    354349                        async_answer_0(callid, EOK);
    355350                        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;
     351                }
     352               
     353                /* Convert ipc interface id to interface index */
     354               
     355                int iface_idx = DEV_IFACE_IDX(method);
     356               
     357                if (!is_valid_iface_idx(iface_idx)) {
     358                        remote_handler_t *default_handler =
     359                            function_get_default_handler(fun);
     360                        if (default_handler != NULL) {
     361                                (*default_handler)(fun, callid, &call);
     362                                continue;
    391363                        }
    392364                       
    393365                        /*
    394                          * Get the corresponding interface for remote request
    395                          * handling ("remote interface").
     366                         * Function has no such interface and
     367                         * default handler is not provided.
    396368                         */
    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                 }
     369                        printf("%s: driver_connection_gen error - "
     370                            "invalid interface id %d.",
     371                            driver->name, iface_idx);
     372                        async_answer_0(callid, ENOTSUP);
     373                        continue;
     374                }
     375               
     376                /* Calling one of the function's interfaces */
     377               
     378                /* Get the interface ops structure. */
     379                void *ops = function_get_ops(fun, iface_idx);
     380                if (ops == NULL) {
     381                        printf("%s: driver_connection_gen error - ", driver->name);
     382                        printf("Function with handle %" PRIun " has no interface "
     383                            "with id %d.\n", handle, iface_idx);
     384                        async_answer_0(callid, ENOTSUP);
     385                        continue;
     386                }
     387               
     388                /*
     389                 * Get the corresponding interface for remote request
     390                 * handling ("remote interface").
     391                 */
     392                remote_iface_t *rem_iface = get_remote_iface(iface_idx);
     393                assert(rem_iface != NULL);
     394               
     395                /* get the method of the remote interface */
     396                sysarg_t iface_method_idx = IPC_GET_ARG1(call);
     397                remote_iface_func_ptr_t iface_method_ptr =
     398                    get_remote_method(rem_iface, iface_method_idx);
     399                if (iface_method_ptr == NULL) {
     400                        /* The interface has not such method */
     401                        printf("%s: driver_connection_gen error - "
     402                            "invalid interface method.", driver->name);
     403                        async_answer_0(callid, ENOTSUP);
     404                        continue;
     405                }
     406               
     407                /*
     408                 * Call the remote interface's method, which will
     409                 * receive parameters from the remote client and it will
     410                 * pass it to the corresponding local interface method
     411                 * associated with the function by its driver.
     412                 */
     413                (*iface_method_ptr)(fun, ops, callid, &call);
    421414        }
    422415}
     
    433426
    434427/** Function for handling connections to device driver. */
    435 static void driver_connection(ipc_callid_t iid, ipc_call_t *icall)
     428static void driver_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    436429{
    437430        /* Select interface */
     
    627620                return ENOMEM;
    628621       
    629         match_id->id = match_id_str;
     622        match_id->id = str_dup(match_id_str);
    630623        match_id->score = 90;
    631624       
Note: See TracChangeset for help on using the changeset viewer.