Changeset 5cd136ab in mainline for uspace/srv/devman


Ignore:
Timestamp:
2010-04-02T13:37:58Z (16 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9a66bc2e
Parents:
57937dd
Message:

device interfaces and driver cooperation - parts of code

Location:
uspace/srv/devman
Files:
5 edited

Legend:

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

    r57937dd r5cd136ab  
    506506        if (rc != EOK) {
    507507                // TODO handle error
    508                 return false;
     508                return;
    509509        }
    510510       
    511511        // TODO inspect return value (ret) to find out whether the device was successfully probed and added
    512512       
    513         return true;
     513        return;
    514514}
    515515
     
    618618 * @return true on success, false otherwise (insufficient resources etc.).
    619619 */
    620 bool insert_dev_node(dev_tree_t *tree, node_t *node, const char *dev_name, node_t *parent)
     620bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent)
    621621{
    622622        printf(NAME ": insert_dev_node\n");
     
    650650}
    651651
     652/**
     653 * Find device node with a specified path in the device tree.
     654 *
     655 * @param path the path of the device node in the device tree.
     656 * @param tree the device tree.
     657 *
     658 * @return the device node if it is present in the tree, NULL otherwise.
     659 */
     660node_t * find_dev_node_by_path(dev_tree_t *tree, char *path)
     661{
     662        node_t *dev = tree->root_node;
     663        char *rel_path = path;
     664        char *next_path_elem = NULL;
     665        size_t elem_size = 0;
     666        bool cont = '/' == rel_path[0];
     667       
     668        while (cont && NULL != dev) {           
     669                next_path_elem  = get_path_elem_end(rel_path+1);               
     670                if ('/' == next_path_elem[0]) {
     671                        cont = true;
     672                        next_path_elem[0] = 0;
     673                } else {
     674                        cont = false;
     675                }
     676               
     677                dev = find_node_child(dev, rel_path);           
     678               
     679                if (cont) {
     680                        next_path_elem[0] = '/';
     681                }
     682                rel_path = next_path_elem;             
     683        }
     684       
     685        return dev;
     686}
     687
     688/**
     689 * Find child device node with a specified name.
     690 *
     691 * @param parent the parent device node.
     692 * @param name the name of the child device node.
     693 *
     694 * @return the child device node.
     695 */
     696node_t *find_node_child(node_t *parent, const char *name)
     697{
     698        node_t *dev;
     699        link_t *link;
     700       
     701        fibril_mutex_lock(&parent->children_mutex);             
     702        link = parent->children.next;
     703       
     704        while (link != &parent->children) {
     705                dev = list_get_instance(link, node_t, sibling);
     706               
     707                if (0 == str_cmp(name, dev->name)) {
     708                        fibril_mutex_unlock(&parent->children_mutex);
     709                        return dev;                     
     710                }
     711        }       
     712       
     713        fibril_mutex_unlock(&parent->children_mutex);   
     714        return NULL;
     715}
     716
    652717/** @}
    653718 */
  • uspace/srv/devman/devman.h

    r57937dd r5cd136ab  
    238238}
    239239
     240/**
     241 * Delete a device node.
     242 *
     243 * @param node a device node structure.
     244 *
     245 */
    240246static inline void delete_dev_node(node_t *node)
    241247{
     
    263269}
    264270
     271node_t * find_dev_node_by_path(dev_tree_t *tree, char *path);
     272node_t *find_node_child(node_t *parent, const char *name);
     273
    265274// Device tree
    266275
    267276bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list);
    268277bool create_root_node(dev_tree_t *tree);
    269 bool insert_dev_node(dev_tree_t *tree, node_t *node, const char *dev_name, node_t *parent);
     278bool insert_dev_node(dev_tree_t *tree, node_t *node, char *dev_name, node_t *parent);
    270279
    271280#endif
  • uspace/srv/devman/main.c

    r57937dd r5cd136ab  
    5151#include <ctype.h>
    5252#include <ipc/devman.h>
     53#include <ipc/driver.h>
    5354#include <thread.h>
    5455
     
    158159{
    159160        int ret = EOK;
    160         int i;
     161        size_t i;
    161162        for (i = 0; i < match_count; i++) {
    162163                if (EOK != (ret = devman_receive_match_id(match_ids))) {
     
    257258}
    258259
     260static void devman_forward(ipc_callid_t iid, ipc_call_t *icall, bool drv_to_parent) {
     261        device_handle_t handle;
     262        node_t *dev = find_dev_node(&device_tree, handle);
     263        if (NULL == dev) {
     264                ipc_answer_0(iid, ENOENT);
     265                return;
     266        }
     267       
     268        driver_t *driver = NULL;
     269       
     270        if (drv_to_parent) {
     271                driver = dev->parent->drv;
     272        } else {
     273                driver = dev->drv;             
     274        }
     275       
     276        if (NULL == driver) {           
     277                ipc_answer_0(iid, ENOENT);
     278                return;
     279        }
     280       
     281        int method;     
     282        if (drv_to_parent) {
     283                method = DRIVER_DRIVER;
     284        } else {
     285                method = DRIVER_CLIENT;
     286        }
     287       
     288        ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);     
     289}
     290
    259291/** Function for handling connections to device manager.
    260292 *
     
    269301        /*case DEVMAN_CLIENT:
    270302                devmap_connection_client(iid, icall);
    271                 break;
     303                break;*/
    272304        case DEVMAN_CONNECT_TO_DEVICE:
    273305                // Connect client to selected device
    274                 devmap_forward(iid, icall);
    275                 break;*/
     306                devman_forward(iid, icall, false);
     307                break;
     308        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
     309                // Connect client to selected device
     310                devman_forward(iid, icall, true);
     311                break;         
    276312        default:
    277313                /* No such interface */
  • uspace/srv/devman/util.c

    r57937dd r5cd136ab  
    6161        return res;
    6262}
     63
     64const char * get_path_elem_end(const char *path)
     65{
     66        while (0 != *path && '/' != *path) {
     67                path++;
     68        }
     69        return path;
     70}
  • uspace/srv/devman/util.h

    r57937dd r5cd136ab  
    3838
    3939char * get_abs_path(const char *base_path, const char *name, const char *ext);
     40const char * get_path_elem_end(const char *path);
    4041
    4142static inline bool skip_spaces(const char **buf)
Note: See TracChangeset for help on using the changeset viewer.