Changeset 8b655705 in mainline for uspace/srv/devman/main.c


Ignore:
Timestamp:
2011-04-15T19:38:07Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9dd730d1
Parents:
6b9e85b (diff), b2fb47f (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

    r6b9e85b r8b655705  
    4343#include <stdio.h>
    4444#include <errno.h>
     45#include <str_error.h>
    4546#include <bool.h>
    4647#include <fibril_synch.h>
     
    5152#include <sys/stat.h>
    5253#include <ctype.h>
     54#include <io/log.h>
    5355#include <ipc/devman.h>
    5456#include <ipc/driver.h>
     
    7173        driver_t *driver = NULL;
    7274
    73         printf(NAME ": devman_driver_register \n");
     75        log_msg(LVL_DEBUG, "devman_driver_register");
    7476       
    7577        iid = async_get_call(&icall);
    7678        if (IPC_GET_IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) {
    77                 ipc_answer_0(iid, EREFUSED);
     79                async_answer_0(iid, EREFUSED);
    7880                return NULL;
    7981        }
     
    8486        int rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0);
    8587        if (rc != EOK) {
    86                 ipc_answer_0(iid, rc);
     88                async_answer_0(iid, rc);
    8789                return NULL;
    8890        }
    8991
    90         printf(NAME ": the %s driver is trying to register by the service.\n",
     92        log_msg(LVL_DEBUG, "The `%s' driver is trying to register.",
    9193            drv_name);
    9294       
    9395        /* Find driver structure. */
    9496        driver = find_driver(&drivers_list, drv_name);
    95        
    9697        if (driver == NULL) {
    97                 printf(NAME ": no driver named %s was found.\n", drv_name);
     98                log_msg(LVL_ERROR, "No driver named `%s' was found.", drv_name);
    9899                free(drv_name);
    99100                drv_name = NULL;
    100                 ipc_answer_0(iid, ENOENT);
     101                async_answer_0(iid, ENOENT);
    101102                return NULL;
    102103        }
     
    105106        drv_name = NULL;
    106107       
     108        fibril_mutex_lock(&driver->driver_mutex);
     109       
     110        if (driver->phone >= 0) {
     111                /* We already have a connection to the driver. */
     112                log_msg(LVL_ERROR, "Driver '%s' already started.\n",
     113                    driver->name);
     114                fibril_mutex_unlock(&driver->driver_mutex);
     115                async_answer_0(iid, EEXISTS);
     116                return NULL;
     117        }
     118       
     119        switch (driver->state) {
     120        case DRIVER_NOT_STARTED:
     121                /* Somebody started the driver manually. */
     122                log_msg(LVL_NOTE, "Driver '%s' started manually.\n",
     123                    driver->name);
     124                driver->state = DRIVER_STARTING;
     125                break;
     126        case DRIVER_STARTING:
     127                /* The expected case */
     128                break;
     129        case DRIVER_RUNNING:
     130                /* Should not happen since we do not have a connected phone */
     131                assert(false);
     132        }
     133       
    107134        /* Create connection to the driver. */
    108         printf(NAME ":  creating connection to the %s driver.\n", driver->name);
     135        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
     136            driver->name);
    109137        ipc_call_t call;
    110138        ipc_callid_t callid = async_get_call(&call);
    111139        if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
    112                 ipc_answer_0(callid, ENOTSUP);
    113                 ipc_answer_0(iid, ENOTSUP);
     140                fibril_mutex_unlock(&driver->driver_mutex);
     141                async_answer_0(callid, ENOTSUP);
     142                async_answer_0(iid, ENOTSUP);
    114143                return NULL;
    115144        }
    116145       
    117146        /* Remember driver's phone. */
    118         set_driver_phone(driver, IPC_GET_ARG5(call));
    119        
    120         printf(NAME ": the %s driver was successfully registered as running.\n",
     147        driver->phone = IPC_GET_ARG5(call);
     148       
     149        fibril_mutex_unlock(&driver->driver_mutex);
     150       
     151        log_msg(LVL_NOTE,
     152            "The `%s' driver was successfully registered as running.",
    121153            driver->name);
    122154       
    123         ipc_answer_0(callid, EOK);
    124         ipc_answer_0(iid, EOK);
     155        async_answer_0(callid, EOK);
     156        async_answer_0(iid, EOK);
    125157       
    126158        return driver;
     
    142174        callid = async_get_call(&call);
    143175        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    144                 printf(NAME ": ERROR: devman_receive_match_id - invalid "
    145                     "protocol.\n");
    146                 ipc_answer_0(callid, EINVAL);
     176                log_msg(LVL_ERROR,
     177                    "Invalid protocol when trying to receive match id.");
     178                async_answer_0(callid, EINVAL);
    147179                delete_match_id(match_id);
    148180                return EINVAL;
     
    150182       
    151183        if (match_id == NULL) {
    152                 printf(NAME ": ERROR: devman_receive_match_id - failed to "
    153                     "allocate match id.\n");
    154                 ipc_answer_0(callid, ENOMEM);
     184                log_msg(LVL_ERROR, "Failed to allocate match id.");
     185                async_answer_0(callid, ENOMEM);
    155186                return ENOMEM;
    156187        }
    157188       
    158         ipc_answer_0(callid, EOK);
     189        async_answer_0(callid, EOK);
    159190       
    160191        match_id->score = IPC_GET_ARG1(call);
     
    165196        if (rc != EOK) {
    166197                delete_match_id(match_id);
    167                 printf(NAME ": devman_receive_match_id - failed to receive "
    168                     "match id string.\n");
     198                log_msg(LVL_ERROR, "Failed to receive match id string: %s.",
     199                    str_error(rc));
    169200                return rc;
    170201        }
     
    172203        list_append(&match_id->link, &match_ids->ids);
    173204       
    174         printf(NAME ": received match id '%s', score = %d \n",
     205        log_msg(LVL_DEBUG, "Received match id `%s', score %d.",
    175206            match_id->id, match_id->score);
    176207        return rc;
     
    199230static int assign_driver_fibril(void *arg)
    200231{
    201         node_t *node = (node_t *) arg;
    202         assign_driver(node, &drivers_list, &device_tree);
     232        dev_node_t *dev_node = (dev_node_t *) arg;
     233        assign_driver(dev_node, &drivers_list, &device_tree);
    203234        return EOK;
    204235}
    205236
    206 /** Handle child device registration.
     237/** Handle function registration.
    207238 *
    208239 * Child devices are registered by their parent's device driver.
    209240 */
    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);
     241static void devman_add_function(ipc_callid_t callid, ipc_call_t *call)
     242{
     243        fun_type_t ftype = (fun_type_t) IPC_GET_ARG1(*call);
     244        devman_handle_t dev_handle = IPC_GET_ARG2(*call);
     245        sysarg_t match_count = IPC_GET_ARG3(*call);
    214246        dev_tree_t *tree = &device_tree;
    215247       
    216248        fibril_rwlock_write_lock(&tree->rwlock);
    217         node_t *parent = find_dev_node_no_lock(&device_tree, parent_handle);
    218        
    219         if (parent == NULL) {
     249
     250        dev_node_t *dev = NULL;
     251        dev_node_t *pdev = find_dev_node_no_lock(&device_tree, dev_handle);
     252       
     253        if (pdev == NULL) {
    220254                fibril_rwlock_write_unlock(&tree->rwlock);
    221                 ipc_answer_0(callid, ENOENT);
    222                 return;
    223         }
    224        
    225         char *dev_name = NULL;
    226         int rc = async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
     255                async_answer_0(callid, ENOENT);
     256                return;
     257        }
     258       
     259        if (ftype != fun_inner && ftype != fun_exposed) {
     260                /* Unknown function type */
     261                log_msg(LVL_ERROR,
     262                    "Unknown function type %d provided by driver.",
     263                    (int) ftype);
     264
     265                fibril_rwlock_write_unlock(&tree->rwlock);
     266                async_answer_0(callid, EINVAL);
     267                return;
     268        }
     269       
     270        char *fun_name = NULL;
     271        int rc = async_data_write_accept((void **)&fun_name, true, 0, 0, 0, 0);
    227272        if (rc != EOK) {
    228273                fibril_rwlock_write_unlock(&tree->rwlock);
    229                 ipc_answer_0(callid, rc);
    230                 return;
    231         }
    232        
    233         node_t *node = create_dev_node();
    234         if (!insert_dev_node(&device_tree, node, dev_name, parent)) {
     274                async_answer_0(callid, rc);
     275                return;
     276        }
     277       
     278        /* Check that function with same name is not there already. */
     279        if (find_fun_node_in_device(pdev, fun_name) != NULL) {
    235280                fibril_rwlock_write_unlock(&tree->rwlock);
    236                 delete_dev_node(node);
    237                 ipc_answer_0(callid, ENOMEM);
    238                 return;
     281                async_answer_0(callid, EEXISTS);
     282                printf(NAME ": Warning, driver tried to register `%s' twice.\n",
     283                    fun_name);
     284                free(fun_name);
     285                return;
     286        }
     287
     288        fun_node_t *fun = create_fun_node();
     289        if (!insert_fun_node(&device_tree, fun, fun_name, pdev)) {
     290                fibril_rwlock_write_unlock(&tree->rwlock);
     291                delete_fun_node(fun);
     292                async_answer_0(callid, ENOMEM);
     293                return;
     294        }
     295
     296        if (ftype == fun_inner) {
     297                dev = create_dev_node();
     298                if (dev == NULL) {
     299                        fibril_rwlock_write_unlock(&tree->rwlock);
     300                        delete_fun_node(fun);
     301                        async_answer_0(callid, ENOMEM);
     302                        return;
     303                }
     304
     305                insert_dev_node(tree, dev, fun);
    239306        }
    240307
    241308        fibril_rwlock_write_unlock(&tree->rwlock);
    242309       
    243         printf(NAME ": devman_add_child %s\n", node->pathname);
    244        
    245         devman_receive_match_ids(match_count, &node->match_ids);
    246 
    247         /*
    248          * Try to find a suitable driver and assign it to the device.  We do
    249          * not want to block the current fibril that is used for processing
    250          * incoming calls: we will launch a separate fibril to handle the
    251          * driver assigning. That is because assign_driver can actually include
    252          * task spawning which could take some time.
    253          */
    254         fid_t assign_fibril = fibril_create(assign_driver_fibril, node);
    255         if (assign_fibril == 0) {
     310        log_msg(LVL_DEBUG, "devman_add_function(fun=\"%s\")", fun->pathname);
     311       
     312        devman_receive_match_ids(match_count, &fun->match_ids);
     313
     314        if (ftype == fun_inner) {
     315                assert(dev != NULL);
    256316                /*
    257                  * Fallback in case we are out of memory.
    258                  * Probably not needed as we will die soon anyway ;-).
     317                 * Try to find a suitable driver and assign it to the device.  We do
     318                 * not want to block the current fibril that is used for processing
     319                 * incoming calls: we will launch a separate fibril to handle the
     320                 * driver assigning. That is because assign_driver can actually include
     321                 * task spawning which could take some time.
    259322                 */
    260                 (void) assign_driver_fibril(node);
     323                fid_t assign_fibril = fibril_create(assign_driver_fibril, dev);
     324                if (assign_fibril == 0) {
     325                        /*
     326                         * Fallback in case we are out of memory.
     327                         * Probably not needed as we will die soon anyway ;-).
     328                         */
     329                        (void) assign_driver_fibril(fun);
     330                } else {
     331                        fibril_add_ready(assign_fibril);
     332                }
    261333        } else {
    262                 fibril_add_ready(assign_fibril);
    263         }
    264 
     334                devmap_register_tree_function(fun, tree);
     335        }
     336       
    265337        /* Return device handle to parent's driver. */
    266         ipc_answer_1(callid, EOK, node->handle);
     338        async_answer_1(callid, EOK, fun->handle);
    267339}
    268340
     
    288360         * mapper.
    289361         */
    290         class_add_devmap_device(&class_list, cli);
     362        class_add_devmap_function(&class_list, cli);
    291363       
    292364        free(devmap_pathname);
    293365}
    294366
    295 static void devman_add_device_to_class(ipc_callid_t callid, ipc_call_t *call)
     367static void devman_add_function_to_class(ipc_callid_t callid, ipc_call_t *call)
    296368{
    297369        devman_handle_t handle = IPC_GET_ARG1(*call);
     
    302374            0, 0, 0, 0);
    303375        if (rc != EOK) {
    304                 ipc_answer_0(callid, rc);
     376                async_answer_0(callid, rc);
    305377                return;
    306378        }       
    307379       
    308         node_t *dev = find_dev_node(&device_tree, handle);
    309         if (dev == NULL) {
    310                 ipc_answer_0(callid, ENOENT);
     380        fun_node_t *fun = find_fun_node(&device_tree, handle);
     381        if (fun == NULL) {
     382                async_answer_0(callid, ENOENT);
    311383                return;
    312384        }
    313385       
    314386        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);
     387        dev_class_info_t *class_info = add_function_to_class(fun, cl, NULL);
    316388       
    317389        /* Register the device's class alias by devmapper. */
    318390        devmap_register_class_dev(class_info);
    319391       
    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);
    322 
    323         ipc_answer_0(callid, EOK);
     392        log_msg(LVL_NOTE, "Function `%s' added to class `%s' as `%s'.",
     393            fun->pathname, class_name, class_info->dev_name);
     394
     395        async_answer_0(callid, EOK);
    324396}
    325397
     
    334406       
    335407        initialize_running_driver(driver, &device_tree);
    336         printf(NAME ": the %s driver was successfully initialized. \n",
     408        log_msg(LVL_DEBUG, "The `%s` driver was successfully initialized.",
    337409            driver->name);
    338410        return 0;
     
    343415{
    344416        /* Accept the connection. */
    345         ipc_answer_0(iid, EOK);
     417        async_answer_0(iid, EOK);
    346418       
    347419        driver_t *driver = devman_driver_register();
     
    356428        fid_t fid = fibril_create(init_running_drv, driver);
    357429        if (fid == 0) {
    358                 printf(NAME ": Error creating fibril for the initialization of "
    359                     "the newly registered running driver.\n");
     430                log_msg(LVL_ERROR, "Failed to create initialization fibril " \
     431                    "for driver `%s'.", driver->name);
    360432                return;
    361433        }
     
    372444                        cont = false;
    373445                        continue;
    374                 case DEVMAN_ADD_CHILD_DEVICE:
    375                         devman_add_child(callid, &call);
     446                case DEVMAN_ADD_FUNCTION:
     447                        devman_add_function(callid, &call);
    376448                        break;
    377449                case DEVMAN_ADD_DEVICE_TO_CLASS:
    378                         devman_add_device_to_class(callid, &call);
     450                        devman_add_function_to_class(callid, &call);
    379451                        break;
    380452                default:
    381                         ipc_answer_0(callid, EINVAL);
     453                        async_answer_0(callid, EINVAL);
    382454                        break;
    383455                }
     
    387459/** Find handle for the device instance identified by the device's path in the
    388460 * device tree. */
    389 static void devman_device_get_handle(ipc_callid_t iid, ipc_call_t *icall)
     461static void devman_function_get_handle(ipc_callid_t iid, ipc_call_t *icall)
    390462{
    391463        char *pathname;
     
    393465        int rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0);
    394466        if (rc != EOK) {
    395                 ipc_answer_0(iid, rc);
    396                 return;
    397         }
    398        
    399         node_t * dev = find_dev_node_by_path(&device_tree, pathname);
     467                async_answer_0(iid, rc);
     468                return;
     469        }
     470       
     471        fun_node_t *fun = find_fun_node_by_path(&device_tree, pathname);
    400472       
    401473        free(pathname);
    402474
    403         if (dev == NULL) {
    404                 ipc_answer_0(iid, ENOENT);
    405                 return;
    406         }
    407        
    408         ipc_answer_1(iid, EOK, dev->handle);
     475        if (fun == NULL) {
     476                async_answer_0(iid, ENOENT);
     477                return;
     478        }
     479
     480        async_answer_1(iid, EOK, fun->handle);
     481}
     482
     483/** Find handle for the device instance identified by device class name. */
     484static void devman_function_get_handle_by_class(ipc_callid_t iid,
     485    ipc_call_t *icall)
     486{
     487        char *classname;
     488        char *devname;
     489
     490        int rc = async_data_write_accept((void **) &classname, true, 0, 0, 0, 0);
     491        if (rc != EOK) {
     492                async_answer_0(iid, rc);
     493                return;
     494        }
     495        rc = async_data_write_accept((void **) &devname, true, 0, 0, 0, 0);
     496        if (rc != EOK) {
     497                free(classname);
     498                async_answer_0(iid, rc);
     499                return;
     500        }
     501
     502
     503        fun_node_t *fun = find_fun_node_by_class(&class_list,
     504            classname, devname);
     505
     506        free(classname);
     507        free(devname);
     508
     509        if (fun == NULL) {
     510                async_answer_0(iid, ENOENT);
     511                return;
     512        }
     513
     514        async_answer_1(iid, EOK, fun->handle);
    409515}
    410516
     
    414520{
    415521        /* Accept connection. */
    416         ipc_answer_0(iid, EOK);
     522        async_answer_0(iid, EOK);
    417523       
    418524        bool cont = true;
     
    426532                        continue;
    427533                case DEVMAN_DEVICE_GET_HANDLE:
    428                         devman_device_get_handle(callid, &call);
     534                        devman_function_get_handle(callid, &call);
     535                        break;
     536                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
     537                        devman_function_get_handle_by_class(callid, &call);
    429538                        break;
    430539                default:
    431                         ipc_answer_0(callid, ENOENT);
     540                        async_answer_0(callid, ENOENT);
    432541                }
    433542        }
     
    438547{
    439548        devman_handle_t handle = IPC_GET_ARG2(*icall);
    440        
    441         node_t *dev = find_dev_node(&device_tree, handle);
     549        devman_handle_t fwd_h;
     550        fun_node_t *fun = NULL;
     551        dev_node_t *dev = NULL;
     552       
     553        fun = find_fun_node(&device_tree, handle);
     554        if (fun == NULL)
     555                dev = find_dev_node(&device_tree, handle);
     556        else
     557                dev = fun->dev;
     558
     559        /*
     560         * For a valid function to connect to we need a device. The root
     561         * function, for example, has no device and cannot be connected to.
     562         * This means @c dev needs to be valid regardless whether we are
     563         * connecting to a device or to a function.
     564         */
    442565        if (dev == NULL) {
    443                 printf(NAME ": devman_forward error - no device with handle %" PRIun
    444                     " was found.\n", handle);
    445                 ipc_answer_0(iid, ENOENT);
     566                log_msg(LVL_ERROR, "IPC forwarding failed - no device or "
     567                    "function with handle %" PRIun " was found.", handle);
     568                async_answer_0(iid, ENOENT);
     569                return;
     570        }
     571
     572        if (fun == NULL && !drv_to_parent) {
     573                log_msg(LVL_ERROR, NAME ": devman_forward error - cannot "
     574                    "connect to handle %" PRIun ", refers to a device.",
     575                    handle);
     576                async_answer_0(iid, ENOENT);
    446577                return;
    447578        }
     
    450581       
    451582        if (drv_to_parent) {
    452                 if (dev->parent != NULL)
    453                         driver = dev->parent->drv;
     583                /* Connect to parent function of a device (or device function). */
     584                if (dev->pfun->dev != NULL)
     585                        driver = dev->pfun->dev->drv;
     586                fwd_h = dev->pfun->handle;
    454587        } else if (dev->state == DEVICE_USABLE) {
     588                /* Connect to the specified function */
    455589                driver = dev->drv;
    456590                assert(driver != NULL);
     591
     592                fwd_h = handle;
    457593        }
    458594       
    459595        if (driver == NULL) {
    460                 printf(NAME ": devman_forward error - the device is not in %" PRIun
    461                     " usable state.\n", handle);
    462                 ipc_answer_0(iid, ENOENT);
     596                log_msg(LVL_ERROR, "IPC forwarding refused - " \
     597                    "the device %" PRIun " is not in usable state.", handle);
     598                async_answer_0(iid, ENOENT);
    463599                return;
    464600        }
     
    470606                method = DRIVER_CLIENT;
    471607       
    472         if (driver->phone <= 0) {
    473                 printf(NAME ": devman_forward: cound not forward to driver %s ",
    474                     driver->name);
    475                 printf("the driver's phone is %" PRIun ").\n", driver->phone);
    476                 ipc_answer_0(iid, EINVAL);
    477                 return;
    478         }
    479 
    480         printf(NAME ": devman_forward: forward connection to device %s to "
    481             "driver %s.\n", dev->pathname, driver->name);
    482         ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);
     608        if (driver->phone < 0) {
     609                log_msg(LVL_ERROR,
     610                    "Could not forward to driver `%s' (phone is %d).",
     611                    driver->name, (int) driver->phone);
     612                async_answer_0(iid, EINVAL);
     613                return;
     614        }
     615
     616        if (fun != NULL) {
     617                log_msg(LVL_DEBUG,
     618                    "Forwarding request for `%s' function to driver `%s'.",
     619                    fun->pathname, driver->name);
     620        } else {
     621                log_msg(LVL_DEBUG,
     622                    "Forwarding request for `%s' device to driver `%s'.",
     623                    dev->pfun->pathname, driver->name);
     624        }
     625
     626        async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE);
    483627}
    484628
     
    488632{
    489633        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) {
    497                 ipc_answer_0(iid, ENOENT);
    498                 return;
    499         }
    500        
    501         if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
    502                 ipc_answer_0(iid, EINVAL);
    503                 return;
    504         }
    505        
    506         ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,
     634        fun_node_t *fun;
     635        dev_node_t *dev;
     636
     637        fun = find_devmap_tree_function(&device_tree, devmap_handle);
     638        if (fun == NULL)
     639                fun = find_devmap_class_function(&class_list, devmap_handle);
     640       
     641        if (fun == NULL || fun->dev->drv == NULL) {
     642                async_answer_0(iid, ENOENT);
     643                return;
     644        }
     645       
     646        dev = fun->dev;
     647       
     648        if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {
     649                async_answer_0(iid, EINVAL);
     650                return;
     651        }
     652       
     653        async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
    507654            IPC_FF_NONE);
    508         printf(NAME ": devman_connection_devmapper: forwarded connection to "
    509             "device %s to driver %s.\n", dev->pathname, dev->drv->name);
     655        log_msg(LVL_DEBUG,
     656            "Forwarding devmapper request for `%s' function to driver `%s'.",
     657            fun->pathname, dev->drv->name);
    510658}
    511659
     
    535683        default:
    536684                /* No such interface */
    537                 ipc_answer_0(iid, ENOENT);
     685                async_answer_0(iid, ENOENT);
    538686        }
    539687}
     
    542690static bool devman_init(void)
    543691{
    544         printf(NAME ": devman_init - looking for available drivers.\n");
     692        log_msg(LVL_DEBUG, "devman_init - looking for available drivers.");
    545693       
    546694        /* Initialize list of available drivers. */
     
    548696        if (lookup_available_drivers(&drivers_list,
    549697            DRIVER_DEFAULT_STORE) == 0) {
    550                 printf(NAME " no drivers found.");
     698                log_msg(LVL_FATAL, "No drivers found.");
    551699                return false;
    552700        }
    553701
    554         printf(NAME ": devman_init  - list of drivers has been initialized.\n");
     702        log_msg(LVL_DEBUG, "devman_init - list of drivers has been initialized.");
    555703
    556704        /* Create root device node. */
    557705        if (!init_device_tree(&device_tree, &drivers_list)) {
    558                 printf(NAME " failed to initialize device tree.");
     706                log_msg(LVL_FATAL, "Failed to initialize device tree.");
    559707                return false;
    560708        }
     
    577725        printf(NAME ": HelenOS Device Manager\n");
    578726
     727        if (log_init(NAME, LVL_ERROR) != EOK) {
     728                printf(NAME ": Error initializing logging subsystem.\n");
     729                return -1;
     730        }
     731
    579732        if (!devman_init()) {
    580                 printf(NAME ": Error while initializing service\n");
     733                log_msg(LVL_ERROR, "Error while initializing service.");
    581734                return -1;
    582735        }
     
    586739
    587740        /* Register device manager at naming service. */
    588         sysarg_t phonead;
    589         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
     741        if (service_register(SERVICE_DEVMAN) != EOK) {
     742                log_msg(LVL_ERROR, "Failed registering as a service.");
    590743                return -1;
    591 
    592         printf(NAME ": Accepting connections\n");
     744        }
     745
     746        printf(NAME ": Accepting connections.\n");
    593747        async_manager();
    594748
Note: See TracChangeset for help on using the changeset viewer.