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


Ignore:
Timestamp:
2011-02-07T22:15:37Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1b367b4
Parents:
8b5690f
Message:

Split device tree node into dev_node_t (device node) and fun_node_t (function node).

File:
1 edited

Legend:

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

    r8b5690f rba38f72c  
    199199static int assign_driver_fibril(void *arg)
    200200{
    201         node_t *node = (node_t *) arg;
    202         assign_driver(node, &drivers_list, &device_tree);
     201        dev_node_t *dev_node = (dev_node_t *) arg;
     202        assign_driver(dev_node, &drivers_list, &device_tree);
    203203        return EOK;
    204204}
     
    215215       
    216216        fibril_rwlock_write_lock(&tree->rwlock);
    217         node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
    218        
    219         if (parent == NULL) {
     217        dev_node_t *pdev = find_dev_node_no_lock(&device_tree, parent_handle);
     218       
     219        if (pdev == NULL) {
    220220                fibril_rwlock_write_unlock(&tree->rwlock);
    221221                async_answer_0(callid, ENOENT);
     
    223223        }
    224224       
    225         char *dev_name = NULL;
    226         int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
     225        char *fun_name = NULL;
     226        int rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0);
    227227        if (rc != EOK) {
    228228                fibril_rwlock_write_unlock(&tree->rwlock);
     
    231231        }
    232232       
    233         node_t *node = create_dev_node();
    234         if (!insert_dev_node(&device_tree, node, dev_name, parent)) {
     233        fun_node_t *fun = create_fun_node();
     234        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
    235235                fibril_rwlock_write_unlock(&tree->rwlock);
    236                 delete_dev_node(node);
     236                delete_fun_node(fun);
    237237                async_answer_0(callid, ENOMEM);
    238238                return;
    239239        }
    240240
     241        dev_node_t *dev;
     242
     243        dev = create_dev_node();
     244        if (dev == NULL) {
     245                fibril_rwlock_write_unlock(&tree->rwlock);
     246                delete_fun_node(fun);
     247                async_answer_0(callid, ENOMEM);
     248                return;
     249        }
     250
     251        insert_dev_node(tree, dev, fun);
     252
    241253        fibril_rwlock_write_unlock(&tree->rwlock);
    242254       
    243         printf(NAME ": devman_add_child %s\n", node->pathname);
    244        
    245         devman_receive_match_ids(match_count, &node->match_ids);
     255        printf(NAME ": devman_add_child %s\n", fun->pathname);
     256       
     257        devman_receive_match_ids(match_count, &fun->match_ids);
    246258
    247259        /*
     
    252264         * task spawning which could take some time.
    253265         */
    254         fid_t assign_fibril = fibril_create(assign_driver_fibril, node);
     266        fid_t assign_fibril = fibril_create(assign_driver_fibril, dev);
    255267        if (assign_fibril == 0) {
    256268                /*
     
    258270                 * Probably not needed as we will die soon anyway ;-).
    259271                 */
    260                 (void) assign_driver_fibril(node);
     272                (void) assign_driver_fibril(fun);
    261273        } else {
    262274                fibril_add_ready(assign_fibril);
     
    264276
    265277        /* Return device handle to parent's driver. */
    266         async_answer_1(callid, EOK, node->handle);
     278        async_answer_1(callid, EOK, fun->handle);
    267279}
    268280
     
    288300         * mapper.
    289301         */
    290         class_add_devmap_device(&class_list, cli);
     302        class_add_devmap_function(&class_list, cli);
    291303       
    292304        free(devmap_pathname);
    293305}
    294306
    295 static void devman_add_device_to_class(ipc_callid_t callid, ipc_call_t *call)
     307static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call)
    296308{
    297309        devman_handle_t handle = IPC_GET_ARG1(*call);
     
    306318        }       
    307319       
    308         node_t *dev = find_dev_node(&device_tree, handle);
    309         if (dev == NULL) {
     320        fun_node_t *fun = find_fun_node(&device_tree, handle);
     321        if (fun == NULL) {
    310322                async_answer_0(callid, ENOENT);
    311323                return;
     
    313325       
    314326        dev_class_t *cl = get_dev_class(&class_list, class_name);
    315         dev_class_info_t *class_info = add_device_to_class(dev, cl, NULL);
     327        dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL);
    316328       
    317329        /* Register the device's class alias by devmapper. */
    318330        devmap_register_class_dev(class_info);
    319331       
    320         printf(NAME ": device '%s' added to class '%s', class name '%s' was "
    321             "asigned to it\n", dev->pathname, class_name, class_info->dev_name);
     332        printf(NAME ": function'%s' added to class '%s', class name '%s' was "
     333            "asigned to it\n", fun->pathname, class_name, class_info->dev_name);
    322334
    323335        async_answer_0(callid, EOK);
     
    376388                        break;
    377389                case DEVMAN_ADD_DEVICE_TO_CLASS:
    378                         devman_add_device_to_class(callid, &call);
     390                        devman_add_function_to_class(callid, &call);
    379391                        break;
    380392                default:
     
    387399/** Find handle for the device instance identified by the device's path in the
    388400 * device tree. */
    389 static void devman_device_get_handle(ipc_callid_t iid, ipc_call_t *icall)
     401static void devman_function_get_handle(ipc_callid_t iid, ipc_call_t *icall)
    390402{
    391403        char *pathname;
     
    397409        }
    398410       
    399         node_t * dev = find_dev_node_by_path(&device_tree, pathname);
     411        fun_node_t * fun = find_fun_node_by_path(&device_tree, pathname);
    400412       
    401413        free(pathname);
    402414
    403         if (dev == NULL) {
     415        if (fun == NULL) {
    404416                async_answer_0(iid, ENOENT);
    405417                return;
    406418        }
    407419       
    408         async_answer_1(iid, EOK, dev->handle);
     420        async_answer_1(iid, EOK, fun->handle);
    409421}
    410422
     
    426438                        continue;
    427439                case DEVMAN_DEVICE_GET_HANDLE:
    428                         devman_device_get_handle(callid, &call);
     440                        devman_function_get_handle(callid, &call);
    429441                        break;
    430442                default:
     
    439451        devman_handle_t handle = IPC_GET_ARG2(*icall);
    440452       
    441         node_t *dev = find_dev_node(&device_tree, handle);
    442         if (dev == NULL) {
    443                 printf(NAME ": devman_forward error - no device with handle %" PRIun
    444                     " was found.\n", handle);
     453        fun_node_t *fun = find_fun_node(&device_tree, handle);
     454        if (fun == NULL) {
     455                printf(NAME ": devman_forward error - no device function with "
     456                    "handle %" PRIun " was found.\n", handle);
    445457                async_answer_0(iid, ENOENT);
    446458                return;
     
    450462       
    451463        if (drv_to_parent) {
    452                 if (dev->parent != NULL)
    453                         driver = dev->parent->drv;
    454         } else if (dev->state == DEVICE_USABLE) {
    455                 driver = dev->drv;
     464                if (fun->dev->pfun != NULL)
     465                        driver = fun->dev->pfun->dev->drv;
     466        } else if (fun->dev->state == DEVICE_USABLE) {
     467                driver = fun->dev->drv;
    456468                assert(driver != NULL);
    457469        }
     
    478490        }
    479491
    480         printf(NAME ": devman_forward: forward connection to device %s to "
    481             "driver %s.\n", dev->pathname, driver->name);
    482         async_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);
     492        printf(NAME ": devman_forward: forward connection to function %s to "
     493            "driver %s.\n", fun->pathname, driver->name);
     494        async_forward_fast(iid, driver->phone, method, fun->handle, 0, IPC_FF_NONE);
    483495}
    484496
     
    488500{
    489501        devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
    490         node_t *dev;
    491 
    492         dev = find_devmap_tree_device(&device_tree, devmap_handle);
    493         if (dev == NULL)
    494                 dev = find_devmap_class_device(&class_list, devmap_handle);
    495        
    496         if (dev == NULL || dev->drv == NULL) {
     502        fun_node_t *fun;
     503        dev_node_t *dev;
     504
     505        fun = find_devmap_tree_function(&device_tree, devmap_handle);
     506        if (fun == NULL)
     507                fun = find_devmap_class_function(&class_list, devmap_handle);
     508       
     509        if (fun == NULL || fun->dev->drv == NULL) {
    497510                async_answer_0(iid, ENOENT);
    498511                return;
    499512        }
     513       
     514        dev = fun->dev;
    500515       
    501516        if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
     
    507522            IPC_FF_NONE);
    508523        printf(NAME ": devman_connection_devmapper: forwarded connection to "
    509             "device %s to driver %s.\n", dev->pathname, dev->drv->name);
     524            "device %s to driver %s.\n", fun->pathname, dev->drv->name);
    510525}
    511526
Note: See TracChangeset for help on using the changeset viewer.