Changeset 0c3666d in mainline for uspace/srv/devman/devman.c


Ignore:
Timestamp:
2010-02-19T14:51:15Z (15 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
924c75e1
Parents:
e85920d
Message:

parts of device manager (unstable)

File:
1 edited

Legend:

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

    re85920d r0c3666d  
    3838#include "util.h"
    3939
    40 
     40/** Allocate and initialize a new driver structure.
     41 *
     42 * @return driver structure.
     43 */
    4144driver_t * create_driver()
    4245{
     
    5053}
    5154
    52 char * read_id(const char **buf)
     55/** Add a driver to the list of drivers.
     56 *
     57 * @param drivers_list the list of drivers.
     58 * @param drv the driver's structure.
     59 */
     60void add_driver(driver_list_t *drivers_list, driver_t *drv)
     61{
     62        fibril_mutex_lock(&drivers_list->drivers_mutex);
     63        list_prepend(&drv->drivers, &drivers_list->drivers);
     64        fibril_mutex_unlock(&drivers_list->drivers_mutex);
     65       
     66        printf(NAME": the '%s' driver was added to the list of available drivers.\n", drv->name);
     67}
     68
     69/** Read match id at the specified position of a string and set
     70 * the position in the string to the first character following the id.
     71 *
     72 * @param buf the position in the input string.
     73 *
     74 * @return the match id.
     75 */
     76char * read_match_id(const char **buf)
    5377{
    5478        char *res = NULL;
     
    6488}
    6589
     90/**
     91 * Read match ids and associated match scores from a string.
     92 *
     93 * Each match score in the string is followed by its match id.
     94 * The match ids and match scores are separated by whitespaces.
     95 * Neither match ids nor match scores can contain whitespaces.
     96 *
     97 * @param buf the string from which the match ids are read.
     98 * @param ids the list of match ids into which the match ids and scores are added.
     99 *
     100 * @return true if at least one match id and associated match score was successfully read, false otherwise.
     101 */
    66102bool parse_match_ids(const char *buf, match_id_list_t *ids)
    67103{
     
    84120               
    85121                // read id
    86                 if (NULL == (id = read_id(&buf))) {
     122                if (NULL == (id = read_match_id(&buf))) {
    87123                        break;                 
    88124                }
     
    102138}
    103139
     140/**
     141 * Read match ids and associated match scores from a file.
     142 *
     143 * Each match score in the file is followed by its match id.
     144 * The match ids and match scores are separated by whitespaces.
     145 * Neither match ids nor match scores can contain whitespaces.
     146 *
     147 * @param buf the path to the file from which the match ids are read.
     148 * @param ids the list of match ids into which the match ids and scores are added.
     149 *
     150 * @return true if at least one match id and associated match score was successfully read, false otherwise.
     151 */
    104152bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    105153{       
     
    151199}
    152200
    153 
     201/**
     202 * Get information about a driver.
     203 *
     204 * Each driver has its own directory in the base directory.
     205 * The name of the driver's directory is the same as the name of the driver.
     206 * The driver's directory contains driver's binary (named as the driver without extension)
     207 * and the configuration file with match ids for device-to-driver matching
     208 * (named as the driver with a special extension).
     209 *
     210 * This function searches for the driver's directory and containing configuration files.
     211 * If all the files needed are found, they are parsed and
     212 * the information about the driver is stored to the driver's structure.
     213 *
     214 * @param base_path the base directory, in which we look for driver's subdirectory.
     215 * @param name the name of the driver.
     216 * @param drv the driver structure to fill information in.
     217 *
     218 * @return true on success, false otherwise.
     219 */
    154220bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    155221{
     
    213279 * @param drivers_list the list of available drivers.
    214280 * @param dir_path the path to the directory where we search for drivers.
     281 *
     282 * @return number of drivers which were found.
    215283 */
    216 int lookup_available_drivers(link_t *drivers_list, const char *dir_path)
     284int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    217285{
    218286        printf(NAME ": lookup_available_drivers \n");
     
    242310}
    243311
     312/** Create root device node of the device tree.
     313 *
     314 * @return root device node.
     315 */
    244316node_t * create_root_node()
    245317{
     
    256328}
    257329
    258 driver_t * find_best_match_driver(link_t *drivers_list, node_t *node)
     330/** Lookup the best matching driver for the specified device in the list of drivers.
     331 *
     332 * A match between a device and a driver is found
     333 * if one of the driver's match ids match one of the device's match ids.
     334 * The score of the match is the product of the driver's and device's score associated with the matching id.
     335 * The best matching driver for a device is the driver
     336 * with the highest score of the match between the device and the driver.
     337 *
     338 * @param drivers_list the list of drivers, where we look for the driver suitable for handling the device.
     339 * @param node the device node structure of the device.
     340 *
     341 * @return the best matching driver or NULL if no matching driver is found.
     342 */
     343driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node)
    259344{
    260345        printf(NAME ": find_best_match_driver\n");
    261346        driver_t *best_drv = NULL, *drv = NULL;
    262347        int best_score = 0, score = 0;
    263         link_t *link = drivers_list->next;     
    264        
    265         while (link != drivers_list) {
     348       
     349        fibril_mutex_lock(&drivers_list->drivers_mutex);
     350        link_t *link = drivers_list->drivers.next;             
     351        while (link != &drivers_list->drivers) {
    266352                drv = list_get_instance(link, driver_t, drivers);
    267353                score = get_match_score(drv, node);
     
    271357                }       
    272358                link = link->next;
    273         }       
     359        }
     360        fibril_mutex_unlock(&drivers_list->drivers_mutex);
    274361       
    275362        return best_drv;       
    276363}
    277364
     365/**
     366 * Assign a driver to a device.
     367 *
     368 * @param node the device's node in the device tree.
     369 * @param drv the driver.
     370 */
    278371void attach_driver(node_t *node, driver_t *drv)
    279372{
     373        fibril_mutex_lock(&drv->driver_mutex);
     374       
    280375        node->drv = drv;
    281376        list_append(&node->driver_devices, &drv->devices);
    282 }
    283 
     377       
     378        fibril_mutex_unlock(&drv->driver_mutex);
     379}
     380
     381/** Start a driver.
     382 *
     383 * The driver's mutex is assumed to be locked.
     384 *
     385 * @param drv the driver's structure.
     386 * @return true if the driver's task is successfully spawned, false otherwise.
     387 */
    284388bool start_driver(driver_t *drv)
    285389{
     
    302406}
    303407
     408/** Pass a device to running driver.
     409 *
     410 * @param drv the driver's structure.
     411 * @param node the device's node in the device tree.
     412 *
     413 * @return true on success, false otherwise.
     414 */
    304415bool add_device(driver_t *drv, node_t *node)
    305416{
     
    316427}
    317428
    318 bool assign_driver(node_t *node, link_t *drivers_list)
     429/**
     430 * Find suitable driver for a device and assign the driver to it.
     431 *
     432 * @param node the device node of the device in the device tree.
     433 * @param drivers_list the list of available drivers.
     434 *
     435 * @return true if the suitable driver is found and successfully assigned to the device, false otherwise.
     436 */
     437bool assign_driver(node_t *node, driver_list_t *drivers_list)
    319438{
    320439        printf(NAME ": assign_driver\n");
     
    343462}
    344463
    345 bool init_device_tree(dev_tree_t *tree, link_t *drivers_list)
     464/**
     465 * Initialize the device tree.
     466 *
     467 * Create root device node of the tree and assign driver to it.
     468 *
     469 * @param tree the device tree.
     470 * @param the list of available drivers.
     471 * @return true on success, false otherwise.
     472 */
     473bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list)
    346474{
    347475        printf(NAME ": init_device_tree.\n");
     476       
    348477        // create root node and add it to the device tree
    349478        if (NULL == (tree->root_node = create_root_node())) {
Note: See TracChangeset for help on using the changeset viewer.