Changeset 8b1e15ac in mainline for uspace/srv


Ignore:
Timestamp:
2011-02-11T22:26:36Z (14 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
68414f4a
Parents:
1b367b4
Message:

Finish splitting device node: devman client in C library, drv library. Update device drivers accordingly.

Location:
uspace/srv/devman
Files:
3 edited

Legend:

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

    r1b367b4 r8b1e15ac  
    709709
    710710/** Create devmap path and name for the function. */
    711 static void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
     711void devmap_register_tree_function(fun_node_t *fun, dev_tree_t *tree)
    712712{
    713713        char *devmap_pathname = NULL;
     
    777777        case EOK:
    778778                dev->state = DEVICE_USABLE;
    779                 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    780                 if (0) devmap_register_tree_function(NULL, tree);
    781                 // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    782779                break;
    783780        case ENOENT:
  • uspace/srv/devman/devman.h

    r1b367b4 r8b1e15ac  
    363363/* Devmap devices */
    364364
     365extern void devmap_register_tree_function(fun_node_t *, dev_tree_t *);
     366
    365367extern fun_node_t *find_devmap_tree_function(dev_tree_t *, devmap_handle_t);
    366368extern fun_node_t *find_devmap_class_function(class_list_t *, devmap_handle_t);
  • uspace/srv/devman/main.c

    r1b367b4 r8b1e15ac  
    204204}
    205205
    206 /** Handle child device registration.
     206/** Handle function registration.
    207207 *
    208208 * Child devices are registered by their parent's device driver.
    209209 */
    210 static void devman_add_child(ipc_callid_t callid, ipc_call_t *call)
    211 {
    212         devman_handle_t parent_handle = IPC_GET_ARG1(*call);
    213         sysarg_t match_count = IPC_GET_ARG2(*call);
     210static void devman_add_function(ipc_callid_t callid, ipc_call_t *call)
     211{
     212        fun_type_t ftype = (fun_type_t) IPC_GET_ARG1(*call);
     213        devman_handle_t dev_handle = IPC_GET_ARG2(*call);
     214        sysarg_t match_count = IPC_GET_ARG3(*call);
    214215        dev_tree_t *tree = &device_tree;
    215216       
    216217        fibril_rwlock_write_lock(&tree->rwlock);
    217         dev_node_t *pdev = find_dev_node_no_lock(&device_tree, parent_handle);
     218
     219        dev_node_t *dev = NULL;
     220        dev_node_t *pdev = find_dev_node_no_lock(&device_tree, dev_handle);
    218221       
    219222        if (pdev == NULL) {
    220223                fibril_rwlock_write_unlock(&tree->rwlock);
    221224                async_answer_0(callid, ENOENT);
     225                return;
     226        }
     227       
     228        if (ftype != fun_inner && ftype != fun_exposed) {
     229                /* Unknown function type */
     230                printf(NAME ": Error, unknown function type provided by driver!\n");
     231
     232                fibril_rwlock_write_unlock(&tree->rwlock);
     233                async_answer_0(callid, EINVAL);
    222234                return;
    223235        }
     
    239251        }
    240252
    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);
     253        if (ftype == fun_inner) {
     254                dev = create_dev_node();
     255                if (dev == NULL) {
     256                        fibril_rwlock_write_unlock(&tree->rwlock);
     257                        delete_fun_node(fun);
     258                        async_answer_0(callid, ENOMEM);
     259                        return;
     260                }
     261
     262                insert_dev_node(tree, dev, fun);
     263        }
    252264
    253265        fibril_rwlock_write_unlock(&tree->rwlock);
    254266       
    255         printf(NAME ": devman_add_child %s\n", fun->pathname);
     267        printf(NAME ": devman_add_function %s\n", fun->pathname);
    256268       
    257269        devman_receive_match_ids(match_count, &fun->match_ids);
    258270
    259         /*
    260          * Try to find a suitable driver and assign it to the device.  We do
    261          * not want to block the current fibril that is used for processing
    262          * incoming calls: we will launch a separate fibril to handle the
    263          * driver assigning. That is because assign_driver can actually include
    264          * task spawning which could take some time.
    265          */
    266         fid_t assign_fibril = fibril_create(assign_driver_fibril, dev);
    267         if (assign_fibril == 0) {
     271        if (ftype == fun_inner) {
     272                assert(dev != NULL);
    268273                /*
    269                  * Fallback in case we are out of memory.
    270                  * Probably not needed as we will die soon anyway ;-).
     274                 * Try to find a suitable driver and assign it to the device.  We do
     275                 * not want to block the current fibril that is used for processing
     276                 * incoming calls: we will launch a separate fibril to handle the
     277                 * driver assigning. That is because assign_driver can actually include
     278                 * task spawning which could take some time.
    271279                 */
    272                 (void) assign_driver_fibril(fun);
     280                fid_t assign_fibril = fibril_create(assign_driver_fibril, dev);
     281                if (assign_fibril == 0) {
     282                        /*
     283                         * Fallback in case we are out of memory.
     284                         * Probably not needed as we will die soon anyway ;-).
     285                         */
     286                        (void) assign_driver_fibril(fun);
     287                } else {
     288                        fibril_add_ready(assign_fibril);
     289                }
    273290        } else {
    274                 fibril_add_ready(assign_fibril);
    275         }
    276 
     291                devmap_register_tree_function(fun, tree);
     292        }
     293       
    277294        /* Return device handle to parent's driver. */
    278295        async_answer_1(callid, EOK, fun->handle);
     
    384401                        cont = false;
    385402                        continue;
    386                 case DEVMAN_ADD_CHILD_DEVICE:
    387                         devman_add_child(callid, &call);
     403                case DEVMAN_ADD_FUNCTION:
     404                        devman_add_function(callid, &call);
    388405                        break;
    389406                case DEVMAN_ADD_DEVICE_TO_CLASS:
     
    409426        }
    410427       
    411         fun_node_t * fun = find_fun_node_by_path(&device_tree, pathname);
     428        fun_node_t *fun = find_fun_node_by_path(&device_tree, pathname);
    412429       
    413430        free(pathname);
     
    417434                return;
    418435        }
    419        
     436
    420437        async_answer_1(iid, EOK, fun->handle);
    421438}
     
    450467{
    451468        devman_handle_t handle = IPC_GET_ARG2(*icall);
    452        
    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 "
     469        devman_handle_t fwd_h;
     470        fun_node_t *fun = NULL;
     471        dev_node_t *dev = NULL;
     472       
     473        fun = find_fun_node(&device_tree, handle);
     474        if (fun == NULL)
     475                dev = find_dev_node(&device_tree, handle);
     476        else
     477                dev = fun->dev;
     478
     479        if (fun == NULL && dev == NULL) {
     480                printf(NAME ": devman_forward error - no device or function with "
    456481                    "handle %" PRIun " was found.\n", handle);
    457482                async_answer_0(iid, ENOENT);
    458483                return;
    459484        }
     485
     486        if (fun == NULL && !drv_to_parent) {
     487                printf(NAME ": devman_forward error - cannot connect to "
     488                    "handle %d, refers to a device.\n", handle);
     489                async_answer_0(iid, ENOENT);
     490                return;
     491        }
    460492       
    461493        driver_t *driver = NULL;
    462494       
    463495        if (drv_to_parent) {
    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;
     496                /* Connect to parent function of a device (or device function). */
     497                if (dev->pfun->dev != NULL)
     498                        driver = dev->pfun->dev->drv;
     499                fwd_h = dev->pfun->handle;
     500        } else if (dev->state == DEVICE_USABLE) {
     501                /* Connect to the specified function */
     502                driver = dev->drv;
    468503                assert(driver != NULL);
     504
     505                fwd_h = handle;
    469506        }
    470507       
     
    490527        }
    491528
    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);
     529        if (fun != NULL) {
     530                printf(NAME ": devman_forward: forward connection to function %s to "
     531                    "driver %s.\n", fun->pathname, driver->name);
     532        } else {
     533                printf(NAME ": devman_forward: forward connection to device %s to "
     534                    "driver %s.\n", dev->pfun->pathname, driver->name);
     535        }
     536
     537        async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE);
    495538}
    496539
Note: See TracChangeset for help on using the changeset viewer.