Changeset 903bac0a in mainline for uspace/srv/devman/main.c


Ignore:
Timestamp:
2011-08-19T09:00:38Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2ab36f1
Parents:
d894fbd (diff), 42a619b (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/srv/devman/main.c

    rd894fbd r903bac0a  
    5656#include <ipc/driver.h>
    5757#include <thread.h>
    58 #include <devmap.h>
     58#include <loc.h>
    5959
    6060#include "devman.h"
     
    6464static driver_list_t drivers_list;
    6565static dev_tree_t device_tree;
    66 static class_list_t class_list;
    6766
    6867/** Register running driver. */
     
    279278                return;
    280279        }
    281 
     280       
    282281        fun_node_t *fun = create_fun_node();
     282        fun->ftype = ftype;
     283       
    283284        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
    284285                fibril_rwlock_write_unlock(&tree->rwlock);
     
    326327                }
    327328        } else {
    328                 devmap_register_tree_function(fun, tree);
     329                loc_register_tree_function(fun, tree);
    329330        }
    330331       
     
    333334}
    334335
    335 static void devmap_register_class_dev(dev_class_info_t *cli)
    336 {
    337         /* Create devmap path and name for the device. */
    338         char *devmap_pathname = NULL;
    339 
    340         asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE,
    341             cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
    342         if (devmap_pathname == NULL)
    343                 return;
    344        
    345         /*
    346          * Register the device by the device mapper and remember its devmap
    347          * handle.
    348          */
    349         devmap_device_register_with_iface(devmap_pathname,
    350             &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    351        
    352         /*
    353          * Add device to the hash map of class devices registered by device
    354          * mapper.
    355          */
    356         class_add_devmap_function(&class_list, cli);
    357        
    358         free(devmap_pathname);
    359 }
    360 
    361 static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call)
     336static void devman_add_function_to_cat(ipc_callid_t callid, ipc_call_t *call)
    362337{
    363338        devman_handle_t handle = IPC_GET_ARG1(*call);
    364        
    365         /* Get class name. */
    366         char *class_name;
    367         int rc = async_data_write_accept((void **) &class_name, true,
     339        category_id_t cat_id;
     340        int rc;
     341       
     342        /* Get category name. */
     343        char *cat_name;
     344        rc = async_data_write_accept((void **) &cat_name, true,
    368345            0, 0, 0, 0);
    369346        if (rc != EOK) {
     
    378355        }
    379356       
    380         dev_class_t *cl = get_dev_class(&class_list, class_name);
    381         dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL);
    382        
    383         /* Register the device's class alias by devmapper. */
    384         devmap_register_class_dev(class_info);
    385        
    386         log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
    387             fun->pathname, class_name, class_info->dev_name);
    388 
     357        rc = loc_category_get_id(cat_name, &cat_id, IPC_FLAG_BLOCKING);
     358        if (rc == EOK) {
     359                loc_service_add_to_cat(fun->service_id, cat_id);
     360        } else {
     361                log_msg(LVL_ERROR, "Failed adding function `%s' to category "
     362                    "`%s'.", fun->pathname, cat_name);
     363        }
     364       
     365        log_msg(LVL_NOTE, "Function `%s' added to category `%s'.",
     366            fun->pathname, cat_name);
     367
     368        async_answer_0(callid, EOK);
     369}
     370
     371/** Remove function. */
     372static void devman_remove_function(ipc_callid_t callid, ipc_call_t *call)
     373{
     374        devman_handle_t fun_handle = IPC_GET_ARG1(*call);
     375        dev_tree_t *tree = &device_tree;
     376        int rc;
     377       
     378        fibril_rwlock_write_lock(&tree->rwlock);
     379       
     380        fun_node_t *fun = find_fun_node_no_lock(&device_tree, fun_handle);
     381        if (fun == NULL) {
     382                fibril_rwlock_write_unlock(&tree->rwlock);
     383                async_answer_0(callid, ENOENT);
     384                return;
     385        }
     386       
     387        log_msg(LVL_DEBUG, "devman_remove_function(fun='%s')", fun->pathname);
     388       
     389        if (fun->ftype == fun_inner) {
     390                /* Handle possible descendants */
     391                /* TODO */
     392                log_msg(LVL_WARN, "devman_remove_function(): not handling "
     393                    "descendants\n");
     394        } else {
     395                /* Unregister from location service */
     396                rc = loc_service_unregister(fun->service_id);
     397                if (rc != EOK) {
     398                        log_msg(LVL_ERROR, "Failed unregistering tree service.");
     399                        fibril_rwlock_write_unlock(&tree->rwlock);
     400                        async_answer_0(callid, EIO);
     401                        return;
     402                }
     403        }
     404       
     405        remove_fun_node(&device_tree, fun);
     406        fibril_rwlock_write_unlock(&tree->rwlock);
     407        delete_fun_node(fun);
     408       
     409        log_msg(LVL_DEBUG, "devman_remove_function() succeeded.");
    389410        async_answer_0(callid, EOK);
    390411}
     
    439460                        devman_add_function(callid, &call);
    440461                        break;
    441                 case DEVMAN_ADD_DEVICE_TO_CLASS:
    442                         devman_add_function_to_class(callid, &call);
     462                case DEVMAN_ADD_DEVICE_TO_CATEGORY:
     463                        devman_add_function_to_cat(callid, &call);
     464                        break;
     465                case DEVMAN_REMOVE_FUNCTION:
     466                        devman_remove_function(callid, &call);
    443467                        break;
    444468                default:
     
    464488       
    465489        free(pathname);
    466 
    467         if (fun == NULL) {
    468                 async_answer_0(iid, ENOENT);
    469                 return;
    470         }
    471 
    472         async_answer_1(iid, EOK, fun->handle);
    473 }
    474 
    475 /** Find handle for the device instance identified by device class name. */
    476 static void devman_function_get_handle_by_class(ipc_callid_t iid,
    477     ipc_call_t *icall)
    478 {
    479         char *classname;
    480         char *devname;
    481 
    482         int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
    483         if (rc != EOK) {
    484                 async_answer_0(iid, rc);
    485                 return;
    486         }
    487         rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
    488         if (rc != EOK) {
    489                 free(classname);
    490                 async_answer_0(iid, rc);
    491                 return;
    492         }
    493 
    494 
    495         fun_node_t *fun = find_fun_node_by_class(&class_list,
    496             classname, devname);
    497 
    498         free(classname);
    499         free(devname);
    500490
    501491        if (fun == NULL) {
     
    544534}
    545535
     536/** Find handle for the function instance identified by its service ID. */
     537static void devman_fun_sid_to_handle(ipc_callid_t iid, ipc_call_t *icall)
     538{
     539        fun_node_t *fun;
     540
     541        fun = find_loc_tree_function(&device_tree, IPC_GET_ARG1(*icall));
     542       
     543        if (fun == NULL) {
     544                async_answer_0(iid, ENOENT);
     545                return;
     546        }
     547
     548        async_answer_1(iid, EOK, fun->handle);
     549}
    546550
    547551/** Function for handling connections from a client to the device manager. */
     
    562566                        devman_function_get_handle(callid, &call);
    563567                        break;
    564                 case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
    565                         devman_function_get_handle_by_class(callid, &call);
    566                         break;
    567568                case DEVMAN_DEVICE_GET_DEVICE_PATH:
    568569                        devman_get_device_path_by_handle(callid, &call);
     570                        break;
     571                case DEVMAN_FUN_SID_TO_HANDLE:
     572                        devman_fun_sid_to_handle(callid, &call);
    569573                        break;
    570574                default:
     
    659663}
    660664
    661 /** Function for handling connections from a client forwarded by the device
    662  * mapper to the device manager. */
    663 static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall)
    664 {
    665         devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
     665/** Function for handling connections from a client forwarded by the location
     666 * service to the device manager. */
     667static void devman_connection_loc(ipc_callid_t iid, ipc_call_t *icall)
     668{
     669        service_id_t service_id = IPC_GET_ARG2(*icall);
    666670        fun_node_t *fun;
    667671        dev_node_t *dev;
    668672
    669         fun = find_devmap_tree_function(&device_tree, devmap_handle);
    670         if (fun == NULL)
    671                 fun = find_devmap_class_function(&class_list, devmap_handle);
     673        fun = find_loc_tree_function(&device_tree, service_id);
    672674       
    673675        if (fun == NULL || fun->dev->drv == NULL) {
     676                log_msg(LVL_WARN, "devman_connection_loc(): function "
     677                    "not found.\n");
    674678                async_answer_0(iid, ENOENT);
    675679                return;
     
    677681       
    678682        dev = fun->dev;
    679        
    680         if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {
    681                 async_answer_0(iid, EINVAL);
    682                 return;
    683         }
    684683       
    685684        async_exch_t *exch = async_exchange_begin(dev->drv->sess);
     
    689688       
    690689        log_msg(LVL_DEBUG,
    691             "Forwarding devmapper request for `%s' function to driver `%s'.",
     690            "Forwarding loc service request for `%s' function to driver `%s'.",
    692691            fun->pathname, dev->drv->name);
    693692}
     
    708707                devman_forward(iid, icall, false);
    709708                break;
    710         case DEVMAN_CONNECT_FROM_DEVMAP:
    711                 /* Someone connected through devmap node. */
    712                 devman_connection_devmapper(iid, icall);
     709        case DEVMAN_CONNECT_FROM_LOC:
     710                /* Someone connected through loc node. */
     711                devman_connection_loc(iid, icall);
    713712                break;
    714713        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
     
    743742        }
    744743
    745         init_class_list(&class_list);
    746        
    747744        /*
    748          * !!! devman_connection ... as the device manager is not a real devmap
     745         * !!! devman_connection ... as the device manager is not a real loc
    749746         * driver (it uses a completely different ipc protocol than an ordinary
    750          * devmap driver) forwarding a connection from client to the devman by
    751          * devmapper would not work.
     747         * loc driver) forwarding a connection from client to the devman by
     748         * location service would not work.
    752749         */
    753         devmap_driver_register(NAME, devman_connection);
     750        loc_server_register(NAME, devman_connection);
    754751       
    755752        return true;
     
    760757        printf(NAME ": HelenOS Device Manager\n");
    761758
    762         if (log_init(NAME, LVL_ERROR) != EOK) {
     759        if (log_init(NAME, LVL_WARN) != EOK) {
    763760                printf(NAME ": Error initializing logging subsystem.\n");
    764761                return -1;
Note: See TracChangeset for help on using the changeset viewer.