Ignore:
File:
1 edited

Legend:

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

    r96b02eb9 r0b5a4131  
    498498 * @param phone         The phone to the driver.
    499499 */
    500 void set_driver_phone(driver_t *driver, sysarg_t phone)
     500void set_driver_phone(driver_t *driver, ipcarg_t phone)
    501501{
    502502        fibril_mutex_lock(&driver->driver_mutex);
     
    508508/** Notify driver about the devices to which it was assigned.
    509509 *
     510 * The driver's mutex must be locked.
     511 *
    510512 * @param driver        The driver to which the devices are passed.
    511513 */
     
    516518        int phone;
    517519
    518         printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
    519 
    520         fibril_mutex_lock(&driver->driver_mutex);
    521 
    522         phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
    523 
    524         if (phone < 0) {
    525                 fibril_mutex_unlock(&driver->driver_mutex);
    526                 return;
    527         }
    528 
    529         /*
    530          * Go through devices list as long as there is some device
    531          * that has not been passed to the driver.
    532          */
    533         link = driver->devices.next;
    534         while (link != &driver->devices) {
    535                 dev = list_get_instance(link, node_t, driver_devices);
    536                 if (dev->passed_to_driver) {
     520        printf(NAME ": pass_devices_to_driver\n");
     521
     522        phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
     523        if (phone > 0) {
     524               
     525                link = driver->devices.next;
     526                while (link != &driver->devices) {
     527                        dev = list_get_instance(link, node_t, driver_devices);
     528                        add_device(phone, driver, dev, tree);
    537529                        link = link->next;
    538                         continue;
    539530                }
    540 
    541                 /*
    542                  * We remove the device from the list to allow safe adding
    543                  * of new devices (no one will touch our item this way).
    544                  */
    545                 list_remove(link);
    546 
    547                 /*
    548                  * Unlock to avoid deadlock when adding device
    549                  * handled by itself.
    550                  */
    551                 fibril_mutex_unlock(&driver->driver_mutex);
    552 
    553                 add_device(phone, driver, dev, tree);
    554 
    555                 /*
    556                  * Lock again as we will work with driver's
    557                  * structure.
    558                  */
    559                 fibril_mutex_lock(&driver->driver_mutex);
    560 
    561                 /*
    562                  * Insert the device back.
    563                  * The order is not relevant here so no harm is done
    564                  * (actually, the order would be preserved in most cases).
    565                  */
    566                 list_append(link, &driver->devices);
    567 
    568                 /*
    569                  * Restart the cycle to go through all devices again.
    570                  */
    571                 link = driver->devices.next;
    572         }
    573 
    574         ipc_hangup(phone);
    575 
    576         /*
    577          * Once we passed all devices to the driver, we need to mark the
    578          * driver as running.
    579          * It is vital to do it here and inside critical section.
    580          *
    581          * If we would change the state earlier, other devices added to
    582          * the driver would be added to the device list and started
    583          * immediately and possibly started here as well.
    584          */
    585         printf(NAME ": driver %s goes into running state.\n", driver->name);
    586         driver->state = DRIVER_RUNNING;
    587 
    588         fibril_mutex_unlock(&driver->driver_mutex);
     531               
     532                ipc_hangup(phone);
     533        }
    589534}
    590535
     
    600545void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    601546{
    602         printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
     547        printf(NAME ": initialize_running_driver\n");
     548        fibril_mutex_lock(&driver->driver_mutex);
    603549       
    604550        /*
     
    607553         */
    608554        pass_devices_to_driver(driver, tree);
     555       
     556        /* Change driver's state to running. */
     557        driver->state = DRIVER_RUNNING;
     558       
     559        fibril_mutex_unlock(&driver->driver_mutex);
    609560}
    610561
     
    678629}
    679630
     631
    680632/** Pass a device to running driver.
    681633 *
     
    685637void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
    686638{
    687         /*
    688          * We do not expect to have driver's mutex locked as we do not
    689          * access any structures that would affect driver_t.
    690          */
    691         printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
    692             node->name);
    693        
    694         sysarg_t rc;
     639        printf(NAME ": add_device\n");
     640       
     641        ipcarg_t rc;
    695642        ipc_call_t answer;
    696643       
    697644        /* Send the device to the driver. */
    698         devman_handle_t parent_handle;
    699         if (node->parent) {
    700                 parent_handle = node->parent->handle;
    701         } else {
    702                 parent_handle = 0;
    703         }
    704 
    705         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle,
    706             parent_handle, &answer);
     645        aid_t req = async_send_1(phone, DRIVER_ADD_DEVICE, node->handle,
     646            &answer);
    707647       
    708648        /* Send the device's name to the driver. */
     
    712652                /* TODO handle error */
    713653        }
    714 
     654       
    715655        /* Wait for answer from the driver. */
    716656        async_wait_for(req, &rc);
    717 
    718657        switch(rc) {
    719658        case EOK:
     
    728667        }
    729668       
    730         node->passed_to_driver = true;
    731 
    732669        return;
    733670}
     
    755692        attach_driver(node, drv);
    756693       
    757         fibril_mutex_lock(&drv->driver_mutex);
    758694        if (drv->state == DRIVER_NOT_STARTED) {
    759695                /* Start the driver. */
    760696                start_driver(drv);
    761697        }
    762         bool is_running = drv->state == DRIVER_RUNNING;
    763         fibril_mutex_unlock(&drv->driver_mutex);
    764 
    765         if (is_running) {
     698       
     699        if (drv->state == DRIVER_RUNNING) {
    766700                /* Notify the driver about the new device. */
    767                 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
     701                int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    768702                if (phone > 0) {
    769703                        add_device(phone, drv, node, tree);
     
    927861        node->name = dev_name;
    928862        if (!set_dev_path(node, parent)) {
     863                fibril_rwlock_write_unlock(&tree->rwlock);
    929864                return false;
    930865        }
     
    10791014       
    10801015        size_t idx = get_new_class_dev_idx(cl);
    1081         asprintf(&dev_name, "%s%zu", base_name, idx);
     1016        asprintf(&dev_name, "%s%d", base_name, idx);
    10821017       
    10831018        return dev_name;
     
    11481083        while (link != &class_list->classes) {
    11491084                cl = list_get_instance(link, dev_class_t, link);
    1150                 if (str_cmp(cl->name, class_name) == 0) {
     1085                if (str_cmp(cl->name, class_name) == 0)
    11511086                        return cl;
    1152                 }
    1153                 link = link->next;
    11541087        }
    11551088       
Note: See TracChangeset for help on using the changeset viewer.