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

Changeset c1a0488 in mainline


Ignore:
Timestamp:
2011-09-02T15:58:02Z (10 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
e2b9b341
Parents:
aff587f
Message:

Track basic device and function states.

Location:
uspace/srv/devman
Files:
3 edited

Legend:

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

    raff587f rc1a0488  
    846846                add_device(drv, dev, tree);
    847847       
     848        fibril_mutex_lock(&drv->driver_mutex);
     849        fibril_mutex_unlock(&drv->driver_mutex);
     850
     851        fibril_rwlock_write_lock(&tree->rwlock);
     852        if (dev->pfun != NULL) {
     853                dev->pfun->state = FUN_ON_LINE;
     854        }
     855        fibril_rwlock_write_unlock(&tree->rwlock);
    848856        return true;
    849857}
     
    11061114                return NULL;
    11071115       
     1116        fun->state = FUN_INIT;
    11081117        atomic_set(&fun->refcnt, 0);
    11091118        link_initialize(&fun->dev_functions);
     
    12751284        dev->pfun->child = NULL;
    12761285        dev->pfun = NULL;
     1286       
     1287        dev->state = DEVICE_REMOVED;
    12771288}
    12781289
     
    13381349       
    13391350        fun->dev = NULL;
     1351        fun->state = FUN_REMOVED;
    13401352}
    13411353
  • uspace/srv/devman/devman.h

    raff587f rc1a0488  
    118118} driver_list_t;
    119119
    120 /** The state of the device. */
     120/** Device state */
    121121typedef enum {
    122122        DEVICE_NOT_INITIALIZED = 0,
    123123        DEVICE_USABLE,
    124124        DEVICE_NOT_PRESENT,
    125         DEVICE_INVALID
     125        DEVICE_INVALID,
     126        /** Device node has been removed from the tree */
     127        DEVICE_REMOVED
    126128} device_state_t;
    127129
     
    157159};
    158160
     161/** Function state */
     162typedef enum {
     163        FUN_INIT = 0,
     164        FUN_OFF_LINE,
     165        FUN_ON_LINE,
     166        /** Function node has been removed from the tree */
     167        FUN_REMOVED
     168} fun_state_t;
     169
    159170/** Function node in the device tree. */
    160171struct fun_node {
    161172        /** Reference count */
    162173        atomic_t refcnt;
     174        /** State */
     175        fun_state_t state;
    163176       
    164177        /** The global unique identifier of the function */
  • uspace/srv/devman/main.c

    raff587f rc1a0488  
    234234        dev_node_t *dev_node = (dev_node_t *) arg;
    235235        assign_driver(dev_node, &drivers_list, &device_tree);
     236
     237        /* Delete one reference we got from the caller. */
     238        dev_del_ref(dev_node);
    236239        return EOK;
    237240}
     
    243246        fibril_rwlock_write_lock(&device_tree.rwlock);
    244247
     248        if (fun->state == FUN_ON_LINE) {
     249                fibril_rwlock_write_unlock(&device_tree.rwlock);
     250                log_msg(LVL_WARN, "Function %s is already on line.",
     251                    fun->pathname);
     252                return EOK;
     253        }
     254       
    245255        if (fun->ftype == fun_inner) {
    246256                dev = create_dev_node();
     
    260270                assert(dev != NULL);
    261271               
     272                /* Give one reference over to assign_driver_fibril(). */
     273                dev_add_ref(dev);
    262274                /*
    263275                 * Try to find a suitable driver and assign it to the device.  We do
     
    269281                fid_t assign_fibril = fibril_create(assign_driver_fibril, dev);
    270282                if (assign_fibril == 0) {
    271                         /*
    272                          * Fallback in case we are out of memory.
    273                          * Probably not needed as we will die soon anyway ;-).
    274                          */
    275                         (void) assign_driver_fibril(fun);
    276                 } else {
    277                         fibril_add_ready(assign_fibril);
     283                        log_msg(LVL_ERROR, "Failed to create fibril for "
     284                            "assigning driver.");
     285                        /* XXX Cleanup */
     286                        fibril_rwlock_write_unlock(&device_tree.rwlock);
     287                        return ENOMEM;
    278288                }
     289                fibril_add_ready(assign_fibril);
    279290        } else {
    280291                loc_register_tree_function(fun, &device_tree);
     
    291302       
    292303        fibril_rwlock_write_lock(&device_tree.rwlock);
     304       
     305        if (fun->state == FUN_OFF_LINE) {
     306                fibril_rwlock_write_unlock(&device_tree.rwlock);
     307                log_msg(LVL_WARN, "Function %s is already off line.",
     308                    fun->pathname);
     309                return EOK;
     310        }
    293311       
    294312        if (fun->ftype == fun_inner) {
     
    329347        }
    330348       
     349        fun->state = FUN_OFF_LINE;
    331350        fibril_rwlock_write_unlock(&device_tree.rwlock);
    332351       
Note: See TracChangeset for help on using the changeset viewer.