Changeset d347b53 in mainline


Ignore:
Timestamp:
2010-03-21T19:33:58Z (15 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
66babbd
Parents:
bda60d9
Message:

child device registration - parts of code

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • .bzrignore

    rbda60d9 rd347b53  
    11HelenOS.sparc64.simics
     2make_settings
  • uspace/lib/libc/generic/devman.c

    rbda60d9 rd347b53  
    108108int devman_child_device_register(
    109109        const char *name, match_id_list_t *match_ids, device_handle_t parent_handle, device_handle_t *handle)
    110 {       
     110{              
    111111        int phone = devman_get_phone(DEVMAN_DRIVER, IPC_FLAG_BLOCKING);
    112112       
  • uspace/lib/libdrv/generic/driver.c

    rbda60d9 rd347b53  
    7272        // result of the operation - device was added, device is not present etc.
    7373        ipcarg_t ret = 0;       
    74         device_handle_t dev_handle =  IPC_GET_ARG1(*icall);
    75        
    76         printf("%s: adding device with handle = %x \n", driver->name, dev_handle);
    77        
     74        device_handle_t dev_handle =  IPC_GET_ARG1(*icall);     
    7875        device_t *dev = driver_create_device();
    7976        dev->handle = dev_handle;
     
    8279                // TODO set return value
    8380        }
     81        printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle);
    8482       
    85         ipc_answer_1(iid, EOK, ret);
     83        ipcarg_t r = ipc_answer_1(iid, EOK, ret);
    8684}
    8785
     
    168166       
    169167        // register driver by device manager with generic handler for incoming connections
    170         printf("%s: sending registration request to devman.\n", driver->name);
    171168        devman_driver_register(driver->name, driver_connection);               
    172169
  • uspace/srv/devman/devman.c

    rbda60d9 rd347b53  
    233233        }       
    234234       
    235         printf(NAME ": get_driver_info - path to match id list = %s.\n", match_path);
    236        
    237235        if (!read_match_ids(match_path, &drv->match_ids)) {
    238236                goto cleanup;
     
    284282int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path)
    285283{
    286         printf(NAME ": lookup_available_drivers \n");
     284        printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);
    287285       
    288286        int drv_cnt = 0;
     
    291289
    292290        dir = opendir(dir_path);
    293         printf(NAME ": lookup_available_drivers has opened directory %s for driver search.\n", dir_path);
    294291       
    295292        if (dir != NULL) {
    296293                driver_t *drv = create_driver();
    297                 printf(NAME ": lookup_available_drivers has created driver structure.\n");
    298294                while ((diren = readdir(dir))) {                       
    299295                        if (get_driver_info(dir_path, diren->d_name, drv)) {
     
    345341driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node)
    346342{
    347         printf(NAME ": find_best_match_driver\n");
     343        printf(NAME ": find_best_match_driver for device '%s' \n", node->pathname);
    348344        driver_t *best_drv = NULL, *drv = NULL;
    349345        int best_score = 0, score = 0;
     
    392388bool start_driver(driver_t *drv)
    393389{
    394         printf(NAME ": start_driver\n");
     390        printf(NAME ": start_driver '%s'\n", drv->name);
    395391       
    396392        char *argv[2];
    397        
    398         printf(NAME ": spawning driver %s\n", drv->name);
    399393       
    400394        argv[0] = drv->name;
     
    459453static void pass_devices_to_driver(driver_t *driver)
    460454{       
     455        printf(NAME ": pass_devices_to_driver\n");
    461456        node_t *dev;
    462457        link_t *link;
     
    486481void initialize_running_driver(driver_t *driver)
    487482{       
     483        printf(NAME ": initialize_running_driver\n");
    488484        fibril_mutex_lock(&driver->driver_mutex);
    489485       
     
    533529        driver_t *drv = find_best_match_driver(drivers_list, node);
    534530        if (NULL == drv) {
    535                 printf(NAME ": no driver found for device.\n");
     531                printf(NAME ": no driver found for device '%s'.\n", node->pathname);
    536532                return false;           
    537533        }
     
    626622        printf(NAME ": insert_dev_node\n");
    627623       
    628         assert(NULL != node && NULL != tree && dev_name != NULL);
     624        assert(NULL != node && NULL != tree && NULL != dev_name);
    629625       
    630626        node->name = dev_name;
  • uspace/srv/devman/devman.h

    rbda60d9 rd347b53  
    141141// Drivers
    142142
     143/**
     144 * Initialize the list of device driver's.
     145 *
     146 * @param drv_list the list of device driver's.
     147 *
     148 */
    143149static inline void init_driver_list(driver_list_t *drv_list)
    144150{
     
    165171void initialize_running_driver(driver_t *driver);
    166172
    167 
     173/**
     174 * Initialize device driver structure.
     175 *
     176 * @param drv the device driver structure.
     177 *
     178 */
    168179static inline void init_driver(driver_t *drv)
    169180{
     
    176187}
    177188
     189/**
     190 * Device driver structure clean-up.
     191 *
     192 * @param drv the device driver structure.
     193 */
    178194static inline void clean_driver(driver_t *drv)
    179195{
     
    188204}
    189205
     206/**
     207 * Delete device driver structure.
     208 *
     209 *  @param drv the device driver structure.*
     210 */
    190211static inline void delete_driver(driver_t *drv)
    191212{
     
    197218
    198219// Device nodes
    199 
     220/**
     221 * Create a new device node.
     222 *
     223 * @return a device node structure.
     224 *
     225 */
    200226static inline node_t * create_dev_node()
    201227{
     
    207233        list_initialize(&res->children);
    208234        list_initialize(&res->match_ids.ids);
     235        fibril_mutex_initialize(&res->children_mutex);
    209236       
    210237        return res;
    211238}
    212239
     240static inline void delete_dev_node(node_t *node)
     241{
     242        assert(list_empty(&node->children) && NULL == node->parent && NULL == node->drv);
     243       
     244        clean_match_ids(&node->match_ids);
     245        free_not_null(node->name);
     246        free_not_null(node->pathname);
     247        free(node);     
     248}
     249
     250/**
     251 * Find the device node structure of the device witch has the specified handle.
     252 *
     253 * @param tree the device tree where we look for the device node.
     254 * @param handle the handle of the device.
     255 * @return the device node.
     256 */
    213257static inline node_t * find_dev_node(dev_tree_t *tree, long handle)
    214258{
  • uspace/srv/devman/main.c

    rbda60d9 rd347b53  
    5151#include <ctype.h>
    5252#include <ipc/devman.h>
     53#include <thread.h>
    5354
    5455#include "devman.h"
     
    9697                return NULL;
    9798        }
    98         printf(NAME ": registering the running instance of the %s driver.\n", driver->name);
    9999       
    100100        // Create connection to the driver
     
    123123{
    124124        printf(NAME ": devman_add_child\n");
    125        
    126         // TODO
    127        
     125
     126        device_handle_t parent_handle = IPC_GET_ARG1(*call);
     127        node_t *parent =  find_dev_node(&device_tree, parent_handle);
     128       
     129        if (NULL == parent) {
     130                ipc_answer_0(callid, ENOENT);
     131                return;
     132        }
     133       
     134        char *dev_name = NULL;
     135        int rc = async_string_receive(&dev_name, DEVMAN_NAME_MAXLEN, NULL);     
     136        if (rc != EOK) {
     137                ipc_answer_0(callid, rc);
     138                return;
     139        }
     140        printf(NAME ": newly added child device's name is '%s'.\n", dev_name);
     141       
     142        node_t *node = create_dev_node();
     143        if (!insert_dev_node(&device_tree, node, dev_name, parent)) {
     144                delete_dev_node(node);
     145                ipc_answer_0(callid, ENOMEM);
     146                return;
     147        }       
     148       
     149        // TODO match ids
     150       
     151        // return device handle to parent's driver
     152        ipc_answer_1(callid, EOK, node->handle);
     153       
     154        // try to find suitable driver and assign it to the device     
     155        assign_driver(node, &drivers_list);
     156}
     157
     158static int init_running_drv(void *drv)
     159{
     160        driver_t *driver = (driver_t *)drv;
     161        initialize_running_driver(driver);     
     162        printf(NAME ": the %s driver was successfully initialized. \n", driver->name);
     163        return 0;
    128164}
    129165
     
    137173       
    138174        driver_t *driver = devman_driver_register();
    139         if (driver == NULL)
    140                 return;
    141                
    142         initialize_running_driver(driver);
     175        if (NULL == driver)
     176                return;
     177       
     178        fid_t fid = fibril_create(init_running_drv, driver);
     179        if (fid == 0) {
     180                printf(NAME ": Error creating fibril for the initialization of the newly registered running driver.\n");
     181                exit(1);
     182        }
     183        fibril_add_ready(fid);
     184       
     185        /*thread_id_t tid;
     186        if (0 != thread_create(init_running_drv, driver, "init_running_drv", &tid)) {
     187                printf(NAME ": failed to start the initialization of the newly registered running driver.\n");
     188        }*/
    143189       
    144190        ipc_callid_t callid;
  • uspace/srv/drivers/root/root.c

    rbda60d9 rd347b53  
    7575        }
    7676       
    77         // TODO - replace this with some better solution
     77        // TODO - replace this with some better solution (sysinfo ?)
    7878        platform->name = STRING(UARCH);
    7979        printf(NAME ": the new device's name is %s.\n", platform->name);
     
    113113        // register root device's children     
    114114        if (!add_platform_child(dev)) {
     115                printf(NAME ": failed to add child device for platform.\n");
    115116                return false;
    116117        }
Note: See TracChangeset for help on using the changeset viewer.