Changeset 08d9c4e6 in mainline


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

device manager - initialization of the list of available drivers

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • boot/Makefile.common

    re2b9a993 r08d9c4e6  
    4747
    4848RD_SRVS = \
     49        $(USPACEDIR)/srv/devman/devman \
    4950        $(USPACEDIR)/srv/bd/file_bd/file_bd \
    5051        $(USPACEDIR)/srv/bd/part/guid_part/g_part \
  • uspace/app/init/init.c

    re2b9a993 r08d9c4e6  
    315315
    316316        usleep(1000000);
    317         spawn("/srv/dd");
     317        //spawn("/srv/dd");
     318       
     319        srv_start("/srv/devman");       
    318320       
    319321        return 0;
  • uspace/srv/devman/devman.c

    re2b9a993 r08d9c4e6  
    4141driver_t * create_driver()
    4242{
     43        printf(NAME ": create_driver\n");
     44       
    4345        driver_t *res = malloc(sizeof(driver_t));
    4446        if(res != NULL) {
    45                 clean_driver(res);
     47                init_driver(res);
    4648        }
    4749        return res;
     
    102104bool read_match_ids(const char *conf_path, match_id_list_t *ids)
    103105{       
     106        printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);
     107       
    104108        bool suc = false;       
    105109        char *buf = NULL;
     
    150154bool get_driver_info(const char *base_path, const char *name, driver_t *drv)
    151155{
     156        printf(NAME ": get_driver_info base_path = %s, name = %s.\n", base_path, name);
     157       
    152158        assert(base_path != NULL && name != NULL && drv != NULL);
    153159       
     
    160166                goto cleanup;
    161167        }       
     168       
     169        printf(NAME ": get_driver_info - path to match id list = %s.\n", match_path);
    162170       
    163171        if (!read_match_ids(match_path, &drv->match_ids)) {
     
    208216int lookup_available_drivers(link_t *drivers_list, const char *dir_path)
    209217{
     218        printf(NAME ": lookup_available_drivers \n");
     219       
    210220        int drv_cnt = 0;
    211221        DIR *dir = NULL;
     
    213223
    214224        dir = opendir(dir_path);
     225        printf(NAME ": lookup_available_drivers has opened directory %s for driver search.\n", dir_path);
     226       
    215227        if (dir != NULL) {
    216228                driver_t *drv = create_driver();
     229                printf(NAME ": lookup_available_drivers has created driver structure.\n");
    217230                while ((diren = readdir(dir))) {                       
    218231                        if (get_driver_info(dir_path, diren->d_name, drv)) {
    219232                                add_driver(drivers_list, drv);
     233                                drv_cnt++;
    220234                                drv = create_driver();
    221235                        }       
     
    318332bool init_device_tree(dev_tree_t *tree, link_t *drivers_list)
    319333{
     334        printf(NAME ": init_device_tree.");
    320335        // create root node and add it to the device tree
    321336        if (NULL == (tree->root_node = create_root_node())) {
  • uspace/srv/devman/devman.h

    re2b9a993 r08d9c4e6  
    3030 * @{
    3131 */
    32  
     32
    3333#ifndef DEVMAN_H_
    3434#define DEVMAN_H_
     
    4141#include <ipc/ipc.h>
    4242
     43#include "util.h"
    4344
    4445#define NAME "devman"
     
    9798        node_t *parent;
    9899        /** Pointers to previous and next child devices in the linked list of parent device's node.*/
    99         link_t sibling; 
     100        link_t sibling;
    100101        /** List of child device nodes. */
    101102        link_t children;
    102103        /** List of device ids for device-to-driver matching.*/
    103         match_id_list_t match_ids;     
     104        match_id_list_t match_ids;
    104105        /** Driver of this device.*/
    105         driver_t *drv; 
     106        driver_t *drv;
    106107        /** Pointer to the previous and next device in the list of devices
    107108            owned by one driver */
    108         link_t driver_devices; 
     109        link_t driver_devices;
    109110};
    110111
     
    130131
    131132
    132 static inline match_id_t * create_match_id() 
     133static inline match_id_t * create_match_id()
    133134{
    134135        match_id_t *id = malloc(sizeof(match_id_t));
    135136        memset(id, 0, sizeof(match_id_t));
    136         return id;     
    137 }
    138 
    139 static inline void delete_match_id(match_id_t *id)
    140 {
    141         free(id->id);
    142         free(id);
     137        return id;
     138}
     139
     140static inline void delete_match_id(match_id_t *id)
     141{
     142        if (id) {
     143                free_not_null(id->id);
     144                free(id);
     145        }
    143146}
    144147
     
    152155bool assign_driver(node_t *node, link_t *drivers_list);
    153156
    154 void attach_driver(node_t *node, driver_t *drv); 
     157void attach_driver(node_t *node, driver_t *drv);
    155158bool add_device(driver_t *drv, node_t *node);
    156159bool start_driver(driver_t *drv);
    157160
    158161
    159 static inline void init_driver(driver_t *drv)
    160 {
    161         assert(drv != NULL);   
    162        
    163         memset(drv, 0, sizeof(driver_t));       
     162static inline void init_driver(driver_t *drv)
     163{
     164        printf(NAME ": init_driver\n");
     165        assert(drv != NULL);
     166
     167        memset(drv, 0, sizeof(driver_t));
    164168        list_initialize(&drv->match_ids.ids);
    165169        list_initialize(&drv->devices);
    166170}
    167171
    168 static inline void clean_driver(driver_t *drv)
    169 {
     172static inline void clean_driver(driver_t *drv)
     173{
     174        printf(NAME ": clean_driver\n");
    170175        assert(drv != NULL);
     176
     177        free_not_null(drv->name);
     178        free_not_null(drv->binary_path);
     179
     180        clean_match_ids(&drv->match_ids);
     181
     182        init_driver(drv);
     183}
     184
     185static inline void delete_driver(driver_t *drv)
     186{
     187        printf(NAME ": delete_driver\n");
     188        assert(NULL != drv);
    171189       
    172         free(drv->name);
    173         free(drv->binary_path);
    174        
    175         clean_match_ids(&drv->match_ids);
    176        
    177         init_driver(drv);       
    178 }
    179 
    180 static inline void delete_driver(driver_t *drv)
    181 {
    182190        clean_driver(drv);
    183191        free(drv);
     
    187195{
    188196        list_prepend(&drv->drivers, drivers_list);
    189         printf(NAME": the '%s' driver was added to the list of available drivers.\n", drv->name);       
     197        printf(NAME": the '%s' driver was added to the list of available drivers.\n", drv->name);
    190198}
    191199
     
    198206        node_t *res = malloc(sizeof(node_t));
    199207        if (res != NULL) {
    200                 memset(res, 0, sizeof(node_t)); 
     208                memset(res, 0, sizeof(node_t));
    201209        }
    202210        return res;
    203211}
    204212
    205 static inline void init_dev_node(node_t *node, node_t *parent) 
     213static inline void init_dev_node(node_t *node, node_t *parent)
    206214{
    207215        assert(NULL != node);
    208        
     216
    209217        node->parent = parent;
    210218        if (NULL != parent) {
    211219                list_append(&node->sibling, &parent->children);
    212220        }
    213        
     221
    214222        list_initialize(&node->children);
    215        
    216         list_initialize(&node->match_ids.ids); 
     223
     224        list_initialize(&node->match_ids.ids);
    217225}
    218226
  • uspace/srv/devman/main.c

    re2b9a993 r08d9c4e6  
    9292static bool devman_init()
    9393{
     94        printf(NAME ": devman_init - looking for available drivers. \n");
     95       
    9496        // initialize list of available drivers
    9597        if (0 == lookup_available_drivers(&drivers_list, DRIVER_DEFAULT_STORE)) {
     
    9799                return false;
    98100        }
     101        printf(NAME ": devman_init  - list of drivers has been initialized. \n");
    99102
    100103        // create root device node
  • uspace/srv/devman/util.c

    re2b9a993 r08d9c4e6  
    4141        char *res;
    4242        int base_len = str_size(base_path);
    43         int size = base_len + str_size(name) + str_size(ext) + 3;       
     43        int size = base_len + 2*str_size(name) + str_size(ext) + 3;     
    4444       
    4545        res = malloc(size);
     
    5151                }
    5252                str_append(res, size, name);
     53                str_append(res, size, "/");
     54                str_append(res, size, name);
    5355                if(ext[0] != '.') {
    5456                        str_append(res, size, ".");
  • uspace/srv/devman/util.h

    re2b9a993 r08d9c4e6  
    5757}
    5858
     59static inline void free_not_null(void *ptr)
     60{
     61        if (NULL != ptr) {
     62                free(ptr);
     63        }
     64}
     65
    5966#endif
Note: See TracChangeset for help on using the changeset viewer.