Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/drv_conn.c

    ra35b458 r5a6cc679  
    7070
    7171        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_driver_register");
    72 
     72       
    7373        /* Get driver name. */
    7474        errno_t rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0);
     
    8080        log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s' driver is trying to register.",
    8181            drv_name);
    82 
     82       
    8383        /* Find driver structure. */
    8484        driver = driver_find_by_name(&drivers_list, drv_name);
     
    9090                return NULL;
    9191        }
    92 
     92       
    9393        free(drv_name);
    9494        drv_name = NULL;
    95 
     95       
    9696        fibril_mutex_lock(&driver->driver_mutex);
    97 
     97       
    9898        if (driver->sess) {
    9999                /* We already have a connection to the driver. */
     
    104104                return NULL;
    105105        }
    106 
     106       
    107107        switch (driver->state) {
    108108        case DRIVER_NOT_STARTED:
     
    119119                assert(false);
    120120        }
    121 
     121       
    122122        /* Create connection to the driver. */
    123123        log_msg(LOG_DEFAULT, LVL_DEBUG, "Creating connection to the `%s' driver.",
     
    131131        /* FIXME: Work around problem with callback sessions */
    132132        async_sess_args_set(driver->sess, INTERFACE_DDF_DEVMAN, 0, 0);
    133 
     133       
    134134        log_msg(LOG_DEFAULT, LVL_NOTE,
    135135            "The `%s' driver was successfully registered as running.",
    136136            driver->name);
    137 
     137       
    138138        /*
    139139         * Initialize the driver as running (e.g. pass assigned devices to it)
     
    149149                return NULL;
    150150        }
    151 
     151       
    152152        fibril_add_ready(fid);
    153153        fibril_mutex_unlock(&driver->driver_mutex);
    154 
     154       
    155155        async_answer_0(callid, EOK);
    156156        return driver;
     
    169169        ipc_call_t call;
    170170        errno_t rc = 0;
    171 
     171       
    172172        callid = async_get_call(&call);
    173173        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
     
    178178                return EINVAL;
    179179        }
    180 
     180       
    181181        if (match_id == NULL) {
    182182                log_msg(LOG_DEFAULT, LVL_ERROR, "Failed to allocate match id.");
     
    184184                return ENOMEM;
    185185        }
    186 
     186       
    187187        async_answer_0(callid, EOK);
    188 
     188       
    189189        match_id->score = IPC_GET_ARG1(call);
    190 
     190       
    191191        char *match_id_str;
    192192        rc = async_data_write_accept((void **) &match_id_str, true, 0, 0, 0, 0);
     
    198198                return rc;
    199199        }
    200 
     200       
    201201        list_append(&match_id->link, &match_ids->ids);
    202 
     202       
    203203        log_msg(LOG_DEFAULT, LVL_DEBUG, "Received match id `%s', score %d.",
    204204            match_id->id, match_id->score);
     
    218218        errno_t ret = EOK;
    219219        size_t i;
    220 
     220       
    221221        for (i = 0; i < match_count; i++) {
    222222                if (EOK != (ret = devman_receive_match_id(match_ids)))
     
    236236        sysarg_t match_count = IPC_GET_ARG3(*call);
    237237        dev_tree_t *tree = &device_tree;
    238 
     238       
    239239        dev_node_t *pdev = find_dev_node(&device_tree, dev_handle);
    240240        if (pdev == NULL) {
     
    242242                return;
    243243        }
    244 
     244       
    245245        if (ftype != fun_inner && ftype != fun_exposed) {
    246246                /* Unknown function type */
     
    253253                return;
    254254        }
    255 
     255       
    256256        char *fun_name = NULL;
    257257        errno_t rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0);
     
    261261                return;
    262262        }
    263 
     263       
    264264        fibril_rwlock_write_lock(&tree->rwlock);
    265 
     265       
    266266        /* Check device state */
    267267        if (pdev->state == DEVICE_REMOVED) {
     
    271271                return;
    272272        }
    273 
     273       
    274274        /* Check that function with same name is not there already. */
    275275        fun_node_t *tfun = find_fun_node_in_device(tree, pdev, fun_name);
     
    284284                return;
    285285        }
    286 
     286       
    287287        fun_node_t *fun = create_fun_node();
    288288        /* One reference for creation, one for us */
     
    290290        fun_add_ref(fun);
    291291        fun->ftype = ftype;
    292 
     292       
    293293        /*
    294294         * We can lock the function here even when holding the tree because
     
    296296         */
    297297        fun_busy_lock(fun);
    298 
     298       
    299299        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
    300300                fibril_rwlock_write_unlock(&tree->rwlock);
     
    306306                return;
    307307        }
    308 
     308       
    309309        fibril_rwlock_write_unlock(&tree->rwlock);
    310310        dev_del_ref(pdev);
    311 
     311       
    312312        devman_receive_match_ids(match_count, &fun->match_ids);
    313 
     313       
    314314        rc = fun_online(fun);
    315315        if (rc != EOK) {
     
    320320                return;
    321321        }
    322 
     322       
    323323        fun_busy_unlock(fun);
    324324        fun_del_ref(fun);
    325 
     325       
    326326        /* Return device handle to parent's driver. */
    327327        async_answer_1(callid, EOK, fun->handle);
     
    333333        category_id_t cat_id;
    334334        errno_t rc;
    335 
     335       
    336336        /* Get category name. */
    337337        char *cat_name;
     
    342342                return;
    343343        }
    344 
     344       
    345345        fun_node_t *fun = find_fun_node(&device_tree, handle);
    346346        if (fun == NULL) {
     
    348348                return;
    349349        }
    350 
     350       
    351351        fibril_rwlock_read_lock(&device_tree.rwlock);
    352 
     352       
    353353        /* Check function state */
    354354        if (fun->state == FUN_REMOVED) {
     
    357357                return;
    358358        }
    359 
     359       
    360360        rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING);
    361361        if (rc == EOK) {
     
    367367                    "`%s'.", fun->pathname, cat_name);
    368368        }
    369 
     369       
    370370        fibril_rwlock_read_unlock(&device_tree.rwlock);
    371371        fun_del_ref(fun);
    372 
     372       
    373373        async_answer_0(callid, rc);
    374374}
     
    382382        fun_node_t *fun;
    383383        errno_t rc;
    384 
     384       
    385385        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_drv_fun_online()");
    386 
     386       
    387387        fun = find_fun_node(&device_tree, IPC_GET_ARG1(*icall));
    388388        if (fun == NULL) {
     
    390390                return;
    391391        }
    392 
     392       
    393393        fun_busy_lock(fun);
    394 
     394       
    395395        fibril_rwlock_read_lock(&device_tree.rwlock);
    396396        if (fun->dev == NULL || fun->dev->drv != drv) {
     
    402402        }
    403403        fibril_rwlock_read_unlock(&device_tree.rwlock);
    404 
     404       
    405405        rc = fun_online(fun);
    406406        if (rc != EOK) {
     
    410410                return;
    411411        }
    412 
     412       
    413413        fun_busy_unlock(fun);
    414414        fun_del_ref(fun);
    415 
     415       
    416416        async_answer_0(iid, EOK);
    417417}
     
    432432                return;
    433433        }
    434 
     434       
    435435        fun_busy_lock(fun);
    436 
     436       
    437437        fibril_rwlock_write_lock(&device_tree.rwlock);
    438438        if (fun->dev == NULL || fun->dev->drv != drv) {
     
    443443        }
    444444        fibril_rwlock_write_unlock(&device_tree.rwlock);
    445 
     445       
    446446        rc = fun_offline(fun);
    447447        if (rc != EOK) {
     
    451451                return;
    452452        }
    453 
     453       
    454454        fun_busy_unlock(fun);
    455455        fun_del_ref(fun);
     
    463463        dev_tree_t *tree = &device_tree;
    464464        errno_t rc;
    465 
     465       
    466466        fun_node_t *fun = find_fun_node(&device_tree, fun_handle);
    467467        if (fun == NULL) {
     
    469469                return;
    470470        }
    471 
     471       
    472472        fun_busy_lock(fun);
    473 
     473       
    474474        fibril_rwlock_write_lock(&tree->rwlock);
    475 
     475       
    476476        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);
    477 
     477       
    478478        /* Check function state */
    479479        if (fun->state == FUN_REMOVED) {
     
    484484                return;
    485485        }
    486 
     486       
    487487        if (fun->ftype == fun_inner) {
    488488                /* This is a surprise removal. Handle possible descendants */
     
    491491                        device_state_t dev_state;
    492492                        errno_t gone_rc;
    493 
     493                       
    494494                        dev_add_ref(dev);
    495495                        dev_state = dev->state;
    496 
     496                       
    497497                        fibril_rwlock_write_unlock(&device_tree.rwlock);
    498 
     498                       
    499499                        /* If device is owned by driver, inform driver it is gone. */
    500500                        if (dev_state == DEVICE_USABLE)
     
    502502                        else
    503503                                gone_rc = EOK;
    504 
     504                       
    505505                        fibril_rwlock_read_lock(&device_tree.rwlock);
    506 
     506                       
    507507                        /* Verify that driver succeeded and removed all functions */
    508508                        if (gone_rc != EOK || !list_empty(&dev->functions)) {
     
    510510                                    "functions for device that is gone. "
    511511                                    "Device node is now defunct.");
    512 
     512                               
    513513                                /*
    514514                                 * Not much we can do but mark the device
     
    526526                                return;
    527527                        }
    528 
     528                       
    529529                        driver_t *driver = dev->drv;
    530530                        fibril_rwlock_read_unlock(&device_tree.rwlock);
    531 
     531                       
    532532                        if (driver)
    533533                                detach_driver(&device_tree, dev);
    534 
     534                       
    535535                        fibril_rwlock_write_lock(&device_tree.rwlock);
    536536                        remove_dev_node(&device_tree, dev);
    537 
     537                       
    538538                        /* Delete ref created when node was inserted */
    539539                        dev_del_ref(dev);
     
    556556                }
    557557        }
    558 
     558       
    559559        remove_fun_node(&device_tree, fun);
    560560        fibril_rwlock_write_unlock(&tree->rwlock);
    561561        fun_busy_unlock(fun);
    562 
     562       
    563563        /* Delete ref added when inserting function into tree */
    564564        fun_del_ref(fun);
    565565        /* Delete ref added above when looking up function */
    566566        fun_del_ref(fun);
    567 
     567       
    568568        log_msg(LOG_DEFAULT, LVL_DEBUG, "devman_remove_function() succeeded.");
    569569        async_answer_0(callid, EOK);
     
    578578{
    579579        driver_t *driver = (driver_t *) drv;
    580 
     580       
    581581        initialize_running_driver(driver, &device_tree);
    582582        log_msg(LOG_DEFAULT, LVL_DEBUG, "The `%s` driver was successfully initialized.",
     
    590590        client_t *client;
    591591        driver_t *driver = NULL;
    592 
     592       
    593593        /* Accept the connection. */
    594594        async_answer_0(iid, EOK);
    595 
     595       
    596596        client = async_get_client_data();
    597597        if (client == NULL) {
     
    599599                return;
    600600        }
    601 
     601       
    602602        while (true) {
    603603                ipc_call_t call;
    604604                ipc_callid_t callid = async_get_call(&call);
    605 
     605               
    606606                if (!IPC_GET_IMETHOD(call))
    607607                        break;
    608 
     608               
    609609                if (IPC_GET_IMETHOD(call) != DEVMAN_DRIVER_REGISTER) {
    610610                        fibril_mutex_lock(&client->mutex);
     
    617617                        }
    618618                }
    619 
     619               
    620620                switch (IPC_GET_IMETHOD(call)) {
    621621                case DEVMAN_DRIVER_REGISTER:
Note: See TracChangeset for help on using the changeset viewer.