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

Changeset a32defa in mainline


Ignore:
Timestamp:
2010-06-01T20:53:07Z (11 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master
Children:
a6e54c5d
Parents:
ce89036b
Message:

Register devices in the device tree by the device mapper so the device hierarchy can be seen from devfs.

Location:
uspace/srv/devman
Files:
4 edited

Legend:

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

    rce89036b ra32defa  
    3636#include <ipc/driver.h>
    3737#include <ipc/devman.h>
     38#include <devmap.h>
    3839
    3940#include "devman.h"
     
    488489 * @param driver the driver to which the devices are passed.
    489490 */
    490 static void pass_devices_to_driver(driver_t *driver)
     491static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree)
    491492{       
    492493        printf(NAME ": pass_devices_to_driver\n");
     
    501502                while (link != &driver->devices) {
    502503                        dev = list_get_instance(link, node_t, driver_devices);
    503                         add_device(phone, driver, dev);
     504                        add_device(phone, driver, dev, tree);
    504505                        link = link->next;
    505506                }
     
    516517 * @param driver the driver which registered itself as running by the device manager.
    517518 */
    518 void initialize_running_driver(driver_t *driver)
     519void initialize_running_driver(driver_t *driver, dev_tree_t *tree)
    519520{       
    520521        printf(NAME ": initialize_running_driver\n");
     
    522523       
    523524        // pass devices which have been already assigned to the driver to the driver
    524         pass_devices_to_driver(driver);
     525        pass_devices_to_driver(driver, tree);   
    525526       
    526527        // change driver's state to running
     
    530531}
    531532
     533
     534static void devmap_register_tree_device(node_t *node, dev_tree_t *tree)
     535{
     536        // create devmap path and name for the device
     537        char *devmap_pathname = NULL;
     538        char *devmap_name = NULL;
     539       
     540        asprintf(&devmap_name, "%s", node->pathname);
     541        if (NULL == devmap_name) {
     542                return;
     543        }
     544       
     545        replace_char(devmap_name, '/', DEVMAP_SEPARATOR);
     546       
     547        asprintf(&devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE, devmap_name);
     548        if (NULL == devmap_pathname) {
     549                free(devmap_name);
     550                return;
     551        }       
     552       
     553        devmap_device_register(devmap_pathname, &node->devmap_handle);
     554       
     555        tree_add_devmap_device(tree, node);
     556       
     557        free(devmap_name);
     558        free(devmap_pathname); 
     559}
     560
     561
    532562/** Pass a device to running driver.
    533563 *
     
    535565 * @param node the device's node in the device tree.
    536566 */
    537 void add_device(int phone, driver_t *drv, node_t *node)
     567void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree)
    538568{
    539569        printf(NAME ": add_device\n");
     
    556586        case EOK:
    557587                node->state = DEVICE_USABLE;
     588                devmap_register_tree_device(node, tree);
    558589                break;
    559590        case ENOENT:
     
    575606 * @return true if the suitable driver is found and successfully assigned to the device, false otherwise.
    576607 */
    577 bool assign_driver(node_t *node, driver_list_t *drivers_list)
     608bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree)
    578609{
    579610        //printf(NAME ": assign_driver\n");
     
    598629                int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    599630                if (phone > 0) {
    600                         add_device(phone, drv, node);           
     631                        add_device(phone, drv, node, tree);             
    601632                        ipc_hangup(phone);
    602633                }
     
    632663
    633664        // find suitable driver and start it
    634         return assign_driver(tree->root_node, drivers_list);
     665        return assign_driver(tree->root_node, drivers_list, tree);
    635666}
    636667
  • uspace/srv/devman/devman.h

    rce89036b ra32defa  
    5555#define DEVMAP_CLASS_NAMESPACE "class"
    5656#define DEVMAP_DEVICE_NAMESPACE "devices"
    57 #define DEVMAP_SEPARATOR "\\"
     57#define DEVMAP_SEPARATOR '\\'
    5858
    5959struct node;
     
    230230
    231231driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node);
    232 bool assign_driver(node_t *node, driver_list_t *drivers_list);
     232bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree);
    233233
    234234void add_driver(driver_list_t *drivers_list, driver_t *drv);
    235235void attach_driver(node_t *node, driver_t *drv);
    236 void add_device(int phone, driver_t *drv, node_t *node);
     236void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree);
    237237bool start_driver(driver_t *drv);
    238238
    239239driver_t * find_driver(driver_list_t *drv_list, const char *drv_name);
    240240void set_driver_phone(driver_t *driver, ipcarg_t phone);
    241 void initialize_running_driver(driver_t *driver);
     241void initialize_running_driver(driver_t *driver, dev_tree_t *tree);
    242242
    243243/**
     
    427427node_t *find_devmap_class_device(class_list_t *classes, dev_handle_t devmap_handle);
    428428
     429
     430static inline void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli)
     431{
     432        unsigned long key = (unsigned long)cli->devmap_handle;
     433        fibril_rwlock_write_lock(&class_list->rwlock);
     434        hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link);
     435        fibril_rwlock_write_unlock(&class_list->rwlock);
     436}
     437
     438static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node)
     439{
     440        unsigned long key = (unsigned long)node->devmap_handle;
     441        fibril_rwlock_write_lock(&tree->rwlock);
     442        hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link);
     443        fibril_rwlock_write_unlock(&tree->rwlock);     
     444}
     445
    429446#endif
    430447
  • uspace/srv/devman/main.c

    rce89036b ra32defa  
    240240       
    241241        // try to find suitable driver and assign it to the device
    242         assign_driver(node, &drivers_list);     
     242        assign_driver(node, &drivers_list, &device_tree);       
    243243}
    244244
     
    247247        // create devmap path and name for the device
    248248        char *devmap_pathname = NULL;
    249         asprintf(&devmap_pathname, "%s/%s%s%s", DEVMAP_CLASS_NAMESPACE, cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
     249        asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE, cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);
    250250        if (NULL == devmap_pathname) {
    251251                return;
     
    254254        // register the device by the device mapper and remember its devmap handle
    255255        devmap_device_register(devmap_pathname, &cli->devmap_handle);   
     256       
     257        // add device to the hash map of class devices registered by device mapper
     258        class_add_devmap_device(&class_list, cli);
    256259       
    257260        free(devmap_pathname); 
     
    297300{
    298301        driver_t *driver = (driver_t *)drv;
    299         initialize_running_driver(driver);     
     302        initialize_running_driver(driver, &device_tree);       
    300303        printf(NAME ": the %s driver was successfully initialized. \n", driver->name);
    301304        return 0;
  • uspace/srv/devman/util.h

    rce89036b ra32defa  
    7777}
    7878
     79static inline void replace_char(char *str, char orig, char repl)
     80{
     81        while (*str) {
     82                if (orig == *str) {
     83                        *str = repl;
     84                }
     85                str++;
     86        }
     87}
     88
    7989#endif
Note: See TracChangeset for help on using the changeset viewer.