Changeset c3d9aaf5 in mainline


Ignore:
Timestamp:
2025-02-03T15:52:08Z (16 hours ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
b1490d2
Parents:
a796812c
Message:

Determine when device (sub)tree is stable.

Devman will only return value when the entire device tree is stable.

Location:
uspace/srv/devman
Files:
7 edited

Legend:

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

    ra796812c rc3d9aaf5  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    34 * All rights reserved.
     
    5051        refcount_init(&dev->refcnt);
    5152        list_initialize(&dev->functions);
     53        fibril_mutex_initialize(&dev->state_lock);
     54        fibril_condvar_initialize(&dev->state_cv);
    5255        link_initialize(&dev->driver_devices);
    5356
     
    8790        if (refcount_down(&dev->refcnt))
    8891                delete_dev_node(dev);
     92}
     93
     94/** Wait until the device node enters stable state.
     95 *
     96 * @param dev Device node
     97 */
     98void dev_wait_stable(dev_node_t *dev)
     99{
     100        fibril_mutex_lock(&dev->state_lock);
     101        while (dev->state == DEVICE_ATTACHING)
     102                fibril_condvar_wait(&dev->state_cv, &dev->state_lock);
     103        fibril_mutex_unlock(&dev->state_lock);
    89104}
    90105
  • uspace/srv/devman/dev.h

    ra796812c rc3d9aaf5  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    3  * Copyright (c) 2013 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    4141extern void dev_add_ref(dev_node_t *);
    4242extern void dev_del_ref(dev_node_t *);
     43extern void dev_wait_stable(dev_node_t *);
    4344
    4445extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree,
  • uspace/srv/devman/devman.h

    ra796812c rc3d9aaf5  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    3  * Copyright (c) 2011 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    105105typedef enum {
    106106        DEVICE_NOT_INITIALIZED = 0,
     107        DEVICE_ATTACHING,
    107108        DEVICE_USABLE,
    108109        DEVICE_NOT_PRESENT,
     
    129130        /** The state of the device. */
    130131        device_state_t state;
     132        /** Protect device state field */
     133        fibril_mutex_t state_lock;
     134        /** Signalled when device state changes */
     135        fibril_condvar_t state_cv;
    131136        /** Link to list of devices owned by driver (driver_t.devices) */
    132137        link_t driver_devices;
  • uspace/srv/devman/devtree.c

    ra796812c rc3d9aaf5  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    34 * All rights reserved.
     
    314315}
    315316
     317/** Wait for device tree to stabilize.
     318 *
     319 * Blocks until the entire device tree had a chance to finish attaching
     320 * all devices.
     321 *
     322 * @param tree Device tree
     323 */
     324void dev_tree_wait_stable(dev_tree_t *tree)
     325{
     326        dev_wait_stable(tree->root_node->child);
     327}
     328
    316329/** @}
    317330 */
  • uspace/srv/devman/devtree.h

    ra796812c rc3d9aaf5  
    11/*
     2 * Copyright (c) 2025 Jiri Svoboda
    23 * Copyright (c) 2010 Lenka Trochtova
    3  * Copyright (c) 2013 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    4545extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *);
    4646extern void remove_fun_node(dev_tree_t *, fun_node_t *);
     47extern void dev_tree_wait_stable(dev_tree_t *);
    4748
    4849#endif
  • uspace/srv/devman/driver.c

    ra796812c rc3d9aaf5  
    11/*
    2  * Copyright (c) 2018 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * Copyright (c) 2010 Lenka Trochtova
    44 * All rights reserved.
     
    284284        dev->drv = drv;
    285285        dev->passed_to_driver = false;
    286         dev->state = DEVICE_NOT_INITIALIZED;
     286        fibril_mutex_lock(&dev->state_lock);
     287        dev->state = DEVICE_ATTACHING;
     288        fibril_mutex_unlock(&dev->state_lock);
     289        fibril_condvar_broadcast(&dev->state_cv);
    287290        list_append(&dev->driver_devices, &drv->devices);
    288291
     
    631634void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
    632635{
     636        link_t *link;
     637        fun_node_t *fun;
     638
    633639        /*
    634640         * We do not expect to have driver's mutex locked as we do not
     
    664670                async_wait_for(req, &rc);
    665671        }
     672
     673        if (rc == EOK) {
     674                log_msg(LOG_DEFAULT, LVL_DEBUG, "Device was added. Wait for "
     675                    "child functions' devices to stabilize.");
     676                fibril_rwlock_read_lock(&tree->rwlock);
     677                link = list_first(&dev->functions);
     678                while (link != NULL) {
     679                        fun = list_get_instance(link, fun_node_t,
     680                            dev_functions);
     681
     682                        if (fun->child != NULL) {
     683                                log_msg(LOG_DEFAULT, LVL_DEBUG2, "Wait for "
     684                                    "child device %p.", (void *)fun->child);
     685                                fun_add_ref(fun);
     686                                fibril_rwlock_read_unlock(&tree->rwlock);
     687                                dev_wait_stable(fun->child);
     688                                fibril_rwlock_read_lock(&tree->rwlock);
     689                                fun_del_ref(fun);
     690                        }
     691
     692                        link = list_next(link, &dev->functions);
     693                }
     694
     695                fibril_rwlock_read_unlock(&tree->rwlock);
     696                log_msg(LOG_DEFAULT, LVL_DEBUG,
     697                    "Finished waiting for children.");
     698        }
     699
     700        fibril_mutex_lock(&dev->state_lock);
    666701
    667702        switch (rc) {
     
    677712        }
    678713
     714        fibril_mutex_unlock(&dev->state_lock);
     715        fibril_condvar_broadcast(&dev->state_cv);
     716
    679717        dev->passed_to_driver = true;
    680718}
  • uspace/srv/devman/main.c

    ra796812c rc3d9aaf5  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2025 Jiri Svoboda
    33 * Copyright (c) 2010 Lenka Trochtova
    44 * All rights reserved.
     
    369369
    370370        printf("%s: Accepting connections.\n", NAME);
     371        log_msg(LOG_DEFAULT, LVL_NOTE, "Wait for device tree to stabilize.");
     372        dev_tree_wait_stable(&device_tree);
     373        log_msg(LOG_DEFAULT, LVL_NOTE, "Device tree stable.");
    371374        task_retval(0);
    372375        async_manager();
Note: See TracChangeset for help on using the changeset viewer.