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


Ignore:
Timestamp:
2012-06-03T20:45:58Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
90478727
Parents:
f7e69f5 (diff), 3123d2a (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

    rf7e69f5 re1e4192  
    125125static void driver_dev_add(ipc_callid_t iid, ipc_call_t *icall)
    126126{
    127         char *dev_name = NULL;
    128         int res;
    129        
    130127        devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
    131128        devman_handle_t parent_fun_handle = IPC_GET_ARG2(*icall);
    132129       
    133130        ddf_dev_t *dev = create_device();
    134 
     131       
    135132        /* Add one reference that will be dropped by driver_dev_remove() */
    136133        dev_add_ref(dev);
    137134        dev->handle = dev_handle;
    138 
     135       
     136        char *dev_name = NULL;
    139137        async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
    140138        dev->name = dev_name;
    141 
     139       
    142140        /*
    143141         * Currently not used, parent fun handle is stored in context
     
    146144        (void) parent_fun_handle;
    147145       
    148         res = driver->driver_ops->dev_add(dev);
     146        int res = driver->driver_ops->dev_add(dev);
    149147       
    150148        if (res != EOK) {
     
    163161static void driver_dev_remove(ipc_callid_t iid, ipc_call_t *icall)
    164162{
    165         devman_handle_t devh;
    166         ddf_dev_t *dev;
    167         int rc;
    168        
    169         devh = IPC_GET_ARG1(*icall);
     163        devman_handle_t devh = IPC_GET_ARG1(*icall);
    170164       
    171165        fibril_mutex_lock(&devices_mutex);
    172         dev = driver_get_device(devh);
     166        ddf_dev_t *dev = driver_get_device(devh);
    173167        if (dev != NULL)
    174168                dev_add_ref(dev);
     
    179173                return;
    180174        }
     175       
     176        int rc;
    181177       
    182178        if (driver->driver_ops->dev_remove != NULL)
     
    193189static void driver_dev_gone(ipc_callid_t iid, ipc_call_t *icall)
    194190{
    195         devman_handle_t devh;
    196         ddf_dev_t *dev;
    197         int rc;
    198        
    199         devh = IPC_GET_ARG1(*icall);
     191        devman_handle_t devh = IPC_GET_ARG1(*icall);
    200192       
    201193        fibril_mutex_lock(&devices_mutex);
    202         dev = driver_get_device(devh);
     194        ddf_dev_t *dev = driver_get_device(devh);
    203195        if (dev != NULL)
    204196                dev_add_ref(dev);
     
    209201                return;
    210202        }
     203       
     204        int rc;
    211205       
    212206        if (driver->driver_ops->dev_gone != NULL)
     
    223217static void driver_fun_online(ipc_callid_t iid, ipc_call_t *icall)
    224218{
    225         devman_handle_t funh;
    226         ddf_fun_t *fun;
    227         int rc;
    228        
    229         funh = IPC_GET_ARG1(*icall);
     219        devman_handle_t funh = IPC_GET_ARG1(*icall);
    230220       
    231221        /*
     
    236226        fibril_mutex_lock(&functions_mutex);
    237227       
    238         fun = driver_get_function(funh);
     228        ddf_fun_t *fun = driver_get_function(funh);
    239229        if (fun != NULL)
    240230                fun_add_ref(fun);
     
    248238       
    249239        /* Call driver entry point */
     240        int rc;
     241       
    250242        if (driver->driver_ops->fun_online != NULL)
    251243                rc = driver->driver_ops->fun_online(fun);
     
    260252static void driver_fun_offline(ipc_callid_t iid, ipc_call_t *icall)
    261253{
    262         devman_handle_t funh;
    263         ddf_fun_t *fun;
    264         int rc;
    265        
    266         funh = IPC_GET_ARG1(*icall);
     254        devman_handle_t funh = IPC_GET_ARG1(*icall);
    267255       
    268256        /*
     
    273261        fibril_mutex_lock(&functions_mutex);
    274262       
    275         fun = driver_get_function(funh);
     263        ddf_fun_t *fun = driver_get_function(funh);
    276264        if (fun != NULL)
    277265                fun_add_ref(fun);
     
    285273       
    286274        /* Call driver entry point */
     275        int rc;
     276       
    287277        if (driver->driver_ops->fun_offline != NULL)
    288278                rc = driver->driver_ops->fun_offline(fun);
     
    597587void *ddf_dev_data_alloc(ddf_dev_t *dev, size_t size)
    598588{
    599         void *data;
    600 
    601589        assert(dev->driver_data == NULL);
    602 
    603         data = calloc(1, size);
     590       
     591        void *data = calloc(1, size);
    604592        if (data == NULL)
    605593                return NULL;
    606 
     594       
    607595        dev->driver_data = data;
    608596        return data;
     
    634622ddf_fun_t *ddf_fun_create(ddf_dev_t *dev, fun_type_t ftype, const char *name)
    635623{
    636         ddf_fun_t *fun;
    637 
    638         fun = create_function();
     624        ddf_fun_t *fun = create_function();
    639625        if (fun == NULL)
    640626                return NULL;
    641 
     627       
    642628        /* Add one reference that will be dropped by ddf_fun_destroy() */
    643629        fun->dev = dev;
    644630        fun_add_ref(fun);
    645 
     631       
    646632        fun->bound = false;
    647633        fun->ftype = ftype;
    648 
     634       
    649635        fun->name = str_dup(name);
    650636        if (fun->name == NULL) {
     
    652638                return NULL;
    653639        }
    654 
     640       
    655641        return fun;
    656642}
     
    659645void *ddf_fun_data_alloc(ddf_fun_t *fun, size_t size)
    660646{
    661         void *data;
    662 
    663647        assert(fun->bound == false);
    664648        assert(fun->driver_data == NULL);
    665 
    666         data = calloc(1, size);
     649       
     650        void *data = calloc(1, size);
    667651        if (data == NULL)
    668652                return NULL;
    669 
     653       
    670654        fun->driver_data = data;
    671655        return data;
     
    677661 * must not be bound.
    678662 *
    679  * @param fun           Function to destroy
     663 * @param fun Function to destroy
     664 *
    680665 */
    681666void ddf_fun_destroy(ddf_fun_t *fun)
    682667{
    683668        assert(fun->bound == false);
    684 
     669       
    685670        /*
    686671         * Drop the reference added by ddf_fun_create(). This will deallocate
     
    697682        if (fun->ops == NULL)
    698683                return NULL;
     684       
    699685        return fun->ops->interfaces[idx];
    700686}
     
    709695 * the same name.
    710696 *
    711  * @param fun           Function to bind
    712  * @return              EOK on success or negative error code
     697 * @param fun Function to bind
     698 *
     699 * @return EOK on success or negative error code
     700 *
    713701 */
    714702int ddf_fun_bind(ddf_fun_t *fun)
     
    717705        assert(fun->name != NULL);
    718706       
    719         int res;
    720        
    721707        add_to_functions_list(fun);
    722         res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
     708        int res = devman_add_function(fun->name, fun->ftype, &fun->match_ids,
    723709            fun->dev->handle, &fun->handle);
    724710        if (res != EOK) {
     
    736722 * the function invisible to the system.
    737723 *
    738  * @param fun           Function to unbind
    739  * @return              EOK on success or negative error code
     724 * @param fun Function to unbind
     725 *
     726 * @return EOK on success or negative error code
     727 *
    740728 */
    741729int ddf_fun_unbind(ddf_fun_t *fun)
    742730{
    743         int res;
    744        
    745731        assert(fun->bound == true);
    746732       
    747         res = devman_remove_function(fun->handle);
     733        int res = devman_remove_function(fun->handle);
    748734        if (res != EOK)
    749735                return res;
    750 
     736       
    751737        remove_from_functions_list(fun);
    752738       
     
    757743/** Online function.
    758744 *
    759  * @param fun           Function to online
    760  * @return              EOK on success or negative error code
     745 * @param fun Function to online
     746 *
     747 * @return EOK on success or negative error code
     748 *
    761749 */
    762750int ddf_fun_online(ddf_fun_t *fun)
    763751{
    764         int res;
    765        
    766752        assert(fun->bound == true);
    767753       
    768         res = devman_drv_fun_online(fun->handle);
     754        int res = devman_drv_fun_online(fun->handle);
    769755        if (res != EOK)
    770756                return res;
     
    775761/** Offline function.
    776762 *
    777  * @param fun           Function to offline
    778  * @return              EOK on success or negative error code
     763 * @param fun Function to offline
     764 *
     765 * @return EOK on success or negative error code
     766 *
    779767 */
    780768int ddf_fun_offline(ddf_fun_t *fun)
    781769{
    782         int res;
    783        
    784770        assert(fun->bound == true);
    785771       
    786         res = devman_drv_fun_offline(fun->handle);
     772        int res = devman_drv_fun_offline(fun->handle);
    787773        if (res != EOK)
    788774                return res;
     
    796782 * Cannot be called when the function node is bound.
    797783 *
    798  * @param fun                   Function
    799  * @param match_id_str          Match string
    800  * @param match_score           Match score
    801  * @return                      EOK on success, ENOMEM if out of memory.
     784 * @param fun          Function
     785 * @param match_id_str Match string
     786 * @param match_score  Match score
     787 *
     788 * @return EOK on success.
     789 * @return ENOMEM if out of memory.
     790 *
    802791 */
    803792int ddf_fun_add_match_id(ddf_fun_t *fun, const char *match_id_str,
    804793    int match_score)
    805794{
    806         match_id_t *match_id;
    807        
    808795        assert(fun->bound == false);
    809796        assert(fun->ftype == fun_inner);
    810797       
    811         match_id = create_match_id();
     798        match_id_t *match_id = create_match_id();
    812799        if (match_id == NULL)
    813800                return ENOMEM;
     
    831818 *
    832819 * Must only be called when the function is bound.
     820 *
    833821 */
    834822int ddf_fun_add_to_category(ddf_fun_t *fun, const char *cat_name)
     
    842830int ddf_driver_main(driver_t *drv)
    843831{
    844         int rc;
    845 
    846832        /*
    847833         * Remember the driver structure - driver_ops will be called by generic
     
    858844         */
    859845        async_set_client_connection(driver_connection);
    860         rc = devman_driver_register(driver->name);
     846        int rc = devman_driver_register(driver->name);
    861847        if (rc != EOK) {
    862848                printf("Error: Failed to register driver with device manager "
     
    864850                    str_error(rc));
    865851               
    866                 return 1;
     852                return rc;
    867853        }
    868854       
     
    870856        rc = task_retval(0);
    871857        if (rc != EOK)
    872                 return 1;
    873 
     858                return rc;
     859       
    874860        async_manager();
    875861       
    876862        /* Never reached. */
    877         return 0;
     863        return EOK;
    878864}
    879865
Note: See TracChangeset for help on using the changeset viewer.