Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 243cb86 in mainline for uspace/srv/devman/devman.c


Ignore:
Timestamp:
2010-12-12T10:50:19Z (11 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master
Children:
8365533
Parents:
101ef25c (diff), ebb98c5 (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 from development + several changes to hid driver.

Changes to hid driver:

  • copied some code to usbkbd_get_descriptors() function
  • base structure for hid descriptor and report parser (files uspace/lib/usb/include/usb/classes/hidparser.h

and uspace/lib/usb/src/hidparser.c)

File:
1 edited

Legend:

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

    r101ef25c r243cb86  
    516516/** Notify driver about the devices to which it was assigned.
    517517 *
    518  * The driver's mutex must be locked.
    519  *
    520518 * @param driver        The driver to which the devices are passed.
    521519 */
     
    526524        int phone;
    527525
    528         printf(NAME ": pass_devices_to_driver\n");
    529 
    530         phone = ipc_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
    531         if (phone > 0) {
    532                
     526        printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name);
     527
     528        fibril_mutex_lock(&driver->driver_mutex);
     529
     530        phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
     531
     532        if (phone < 0) {
     533                fibril_mutex_unlock(&driver->driver_mutex);
     534                return;
     535        }
     536
     537        /*
     538         * Go through devices list as long as there is some device
     539         * that has not been passed to the driver.
     540         */
     541        link = driver->devices.next;
     542        while (link != &driver->devices) {
     543                dev = list_get_instance(link, node_t, driver_devices);
     544                if (dev->passed_to_driver) {
     545                        link = link->next;
     546                        continue;
     547                }
     548
     549                /*
     550                 * We remove the device from the list to allow safe adding
     551                 * of new devices (no one will touch our item this way).
     552                 */
     553                list_remove(link);
     554
     555                /*
     556                 * Unlock to avoid deadlock when adding device
     557                 * handled by itself.
     558                 */
     559                fibril_mutex_unlock(&driver->driver_mutex);
     560
     561                add_device(phone, driver, dev, tree);
     562
     563                /*
     564                 * Lock again as we will work with driver's
     565                 * structure.
     566                 */
     567                fibril_mutex_lock(&driver->driver_mutex);
     568
     569                /*
     570                 * Insert the device back.
     571                 * The order is not relevant here so no harm is done
     572                 * (actually, the order would be preserved in most cases).
     573                 */
     574                list_append(link, &driver->devices);
     575
     576                /*
     577                 * Restart the cycle to go through all devices again.
     578                 */
    533579                link = driver->devices.next;
    534                 while (link != &driver->devices) {
    535                         dev = list_get_instance(link, node_t, driver_devices);
    536                         add_device(phone, driver, dev, tree);
    537                         link = link->next;
    538                 }
    539                
    540                 ipc_hangup(phone);
    541         }
     580        }
     581
     582        ipc_hangup(phone);
     583
     584        /*
     585         * Once we passed all devices to the driver, we need to mark the
     586         * driver as running.
     587         * It is vital to do it here and inside critical section.
     588         *
     589         * If we would change the state earlier, other devices added to
     590         * the driver would be added to the device list and started
     591         * immediately and possibly started here as well.
     592         */
     593        printf(NAME ": driver %s goes into running state.\n", driver->name);
     594        driver->state = DRIVER_RUNNING;
     595
     596        fibril_mutex_unlock(&driver->driver_mutex);
    542597}
    543598
     
    553608void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    554609{
    555         printf(NAME ": initialize_running_driver\n");
    556         fibril_mutex_lock(&driver->driver_mutex);
     610        printf(NAME ": initialize_running_driver (`%s')\n", driver->name);
    557611       
    558612        /*
     
    561615         */
    562616        pass_devices_to_driver(driver, tree);
    563        
    564         /* Change driver's state to running. */
    565         driver->state = DRIVER_RUNNING;
    566        
    567         fibril_mutex_unlock(&driver->driver_mutex);
    568617}
    569618
     
    637686}
    638687
     688static FIBRIL_MUTEX_INITIALIZE(add_device_guard);
    639689
    640690/** Pass a device to running driver.
     
    645695void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
    646696{
    647         printf(NAME ": add_device\n");
     697        fibril_mutex_lock(&add_device_guard);
     698
     699        /*
     700         * We do not expect to have driver's mutex locked as we do not
     701         * access any structures that would affect driver_t.
     702         */
     703        printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,
     704            node->name);
    648705       
    649706        ipcarg_t rc;
     
    657714                parent_handle = 0;
    658715        }
     716
    659717        aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, node->handle,
    660718            parent_handle, &answer);
     
    666724                /* TODO handle error */
    667725        }
    668        
     726
    669727        /* Wait for answer from the driver. */
    670728        async_wait_for(req, &rc);
     729
     730        fibril_mutex_unlock(&add_device_guard);
     731
    671732        switch(rc) {
    672733        case EOK:
     
    681742        }
    682743       
     744        node->passed_to_driver = true;
     745
    683746        return;
    684747}
     
    706769        attach_driver(node, drv);
    707770       
     771        fibril_mutex_lock(&drv->driver_mutex);
    708772        if (drv->state == DRIVER_NOT_STARTED) {
    709773                /* Start the driver. */
    710774                start_driver(drv);
    711775        }
    712        
    713         if (drv->state == DRIVER_RUNNING) {
     776        bool is_running = drv->state == DRIVER_RUNNING;
     777        fibril_mutex_unlock(&drv->driver_mutex);
     778
     779        if (is_running) {
    714780                /* Notify the driver about the new device. */
    715                 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
     781                int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    716782                if (phone > 0) {
    717783                        add_device(phone, drv, node, tree);
     
    875941        node->name = dev_name;
    876942        if (!set_dev_path(node, parent)) {
    877                 fibril_rwlock_write_unlock(&tree->rwlock);
    878943                return false;
    879944        }
     
    10971162        while (link != &class_list->classes) {
    10981163                cl = list_get_instance(link, dev_class_t, link);
    1099                 if (str_cmp(cl->name, class_name) == 0)
     1164                if (str_cmp(cl->name, class_name) == 0) {
    11001165                        return cl;
     1166                }
     1167                link = link->next;
    11011168        }
    11021169       
Note: See TracChangeset for help on using the changeset viewer.