Changeset 8013637 in mainline for uspace/srv/devman/main.c


Ignore:
Timestamp:
2012-07-20T13:51:28Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8fccd42
Parents:
c5bff3c (diff), 7030bc9 (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:

More mainline changes.

File:
1 edited

Legend:

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

    rc5bff3c r8013637  
    245245       
    246246        fibril_rwlock_write_lock(&device_tree.rwlock);
    247 
     247       
    248248        if (fun->state == FUN_ON_LINE) {
    249249                fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    259259                        return ENOMEM;
    260260                }
    261 
     261               
    262262                insert_dev_node(&device_tree, dev, fun);
    263263                dev_add_ref(dev);
     
    272272                /* Give one reference over to assign_driver_fibril(). */
    273273                dev_add_ref(dev);
     274               
    274275                /*
    275276                 * Try to find a suitable driver and assign it to the device.  We do
     
    288289                }
    289290                fibril_add_ready(assign_fibril);
    290         } else {
     291        } else
    291292                loc_register_tree_function(fun, &device_tree);
    292         }
    293293       
    294294        fibril_rwlock_write_unlock(&device_tree.rwlock);
     
    419419       
    420420        /* Check that function with same name is not there already. */
    421         if (find_fun_node_in_device(tree, pdev, fun_name) != NULL) {
     421        fun_node_t *tfun = find_fun_node_in_device(tree, pdev, fun_name);
     422        if (tfun) {
     423                fun_del_ref(tfun);      /* drop the new unwanted reference */
    422424                fibril_rwlock_write_unlock(&tree->rwlock);
    423425                dev_del_ref(pdev);
     
    855857}
    856858
     859/** Get function driver name. */
     860static void devman_fun_get_driver_name(ipc_callid_t iid, ipc_call_t *icall)
     861{
     862        devman_handle_t handle = IPC_GET_ARG1(*icall);
     863
     864        fun_node_t *fun = find_fun_node(&device_tree, handle);
     865        if (fun == NULL) {
     866                async_answer_0(iid, ENOMEM);
     867                return;
     868        }
     869
     870        ipc_callid_t data_callid;
     871        size_t data_len;
     872        if (!async_data_read_receive(&data_callid, &data_len)) {
     873                async_answer_0(iid, EINVAL);
     874                fun_del_ref(fun);
     875                return;
     876        }
     877
     878        void *buffer = malloc(data_len);
     879        if (buffer == NULL) {
     880                async_answer_0(data_callid, ENOMEM);
     881                async_answer_0(iid, ENOMEM);
     882                fun_del_ref(fun);
     883                return;
     884        }
     885
     886        fibril_rwlock_read_lock(&device_tree.rwlock);
     887
     888        /* Check function state */
     889        if (fun->state == FUN_REMOVED) {
     890                fibril_rwlock_read_unlock(&device_tree.rwlock);
     891                free(buffer);
     892
     893                async_answer_0(data_callid, ENOENT);
     894                async_answer_0(iid, ENOENT);
     895                fun_del_ref(fun);
     896                return;
     897        }
     898
     899        /* Check whether function has a driver */
     900        if (fun->child == NULL || fun->child->drv == NULL) {
     901                fibril_rwlock_read_unlock(&device_tree.rwlock);
     902                free(buffer);
     903
     904                async_answer_0(data_callid, EINVAL);
     905                async_answer_0(iid, EINVAL);
     906                fun_del_ref(fun);
     907                return;
     908        }
     909
     910        size_t sent_length = str_size(fun->child->drv->name);
     911        if (sent_length > data_len) {
     912                sent_length = data_len;
     913        }
     914
     915        async_data_read_finalize(data_callid, fun->child->drv->name,
     916            sent_length);
     917        async_answer_0(iid, EOK);
     918
     919        fibril_rwlock_read_unlock(&device_tree.rwlock);
     920        fun_del_ref(fun);
     921        free(buffer);
     922}
    857923
    858924/** Get device path. */
     
    10831149                        devman_fun_get_name(callid, &call);
    10841150                        break;
     1151                case DEVMAN_FUN_GET_DRIVER_NAME:
     1152                        devman_fun_get_driver_name(callid, &call);
     1153                        break;
    10851154                case DEVMAN_FUN_GET_PATH:
    10861155                        devman_fun_get_path(callid, &call);
     
    11491218                if (dev->pfun->dev != NULL)
    11501219                        driver = dev->pfun->dev->drv;
     1220               
    11511221                fwd_h = dev->pfun->handle;
    11521222        } else if (dev->state == DEVICE_USABLE) {
     
    11541224                driver = dev->drv;
    11551225                assert(driver != NULL);
    1156 
     1226               
    11571227                fwd_h = handle;
    11581228        }
     
    11811251
    11821252        if (fun != NULL) {
    1183                 log_msg(LVL_DEBUG, 
     1253                log_msg(LVL_DEBUG,
    11841254                    "Forwarding request for `%s' function to driver `%s'.",
    11851255                    fun->pathname, driver->name);
    11861256        } else {
    1187                 log_msg(LVL_DEBUG, 
     1257                log_msg(LVL_DEBUG,
    11881258                    "Forwarding request for `%s' device to driver `%s'.",
    11891259                    dev->pfun->pathname, driver->name);
     
    11931263        async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE);
    11941264        async_exchange_end(exch);
    1195 
     1265       
    11961266cleanup:
    11971267        if (dev != NULL)
    11981268                dev_del_ref(dev);
     1269       
    11991270        if (fun != NULL)
    12001271                fun_del_ref(fun);
     
    12991370                return false;
    13001371        }
    1301 
     1372       
    13021373        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    1303 
     1374       
    13041375        /* Create root device node. */
    13051376        if (!init_device_tree(&device_tree, &drivers_list)) {
     
    13071378                return false;
    13081379        }
    1309 
     1380       
    13101381        /*
    13111382         * Caution: As the device manager is not a real loc
     
    13221393int main(int argc, char *argv[])
    13231394{
    1324         printf(NAME ": HelenOS Device Manager\n");
    1325 
    1326         if (log_init(NAME, LVL_WARN) != EOK) {
    1327                 printf(NAME ": Error initializing logging subsystem.\n");
    1328                 return -1;
     1395        printf("%s: HelenOS Device Manager\n", NAME);
     1396       
     1397        int rc = log_init(NAME, LVL_WARN);
     1398        if (rc != EOK) {
     1399                printf("%s: Error initializing logging subsystem.\n", NAME);
     1400                return rc;
    13291401        }
    13301402       
     
    13331405        async_set_client_data_destructor(devman_client_data_destroy);
    13341406        async_set_client_connection(devman_connection);
    1335 
     1407       
    13361408        if (!devman_init()) {
    13371409                log_msg(LVL_ERROR, "Error while initializing service.");
    13381410                return -1;
    13391411        }
    1340 
     1412       
    13411413        /* Register device manager at naming service. */
    1342         if (service_register(SERVICE_DEVMAN) != EOK) {
     1414        rc = service_register(SERVICE_DEVMAN);
     1415        if (rc != EOK) {
    13431416                log_msg(LVL_ERROR, "Failed registering as a service.");
    1344                 return -1;
    1345         }
    1346 
    1347         printf(NAME ": Accepting connections.\n");
     1417                return rc;
     1418        }
     1419       
     1420        printf("%s: Accepting connections.\n", NAME);
    13481421        task_retval(0);
    13491422        async_manager();
    1350 
     1423       
    13511424        /* Never reached. */
    13521425        return 0;
Note: See TracChangeset for help on using the changeset viewer.