Changeset c3d9aaf5 in mainline
- Timestamp:
- 2025-02-03T15:52:08Z (16 hours ago)
- Branches:
- master
- Children:
- b1490d2
- Parents:
- a796812c
- Location:
- uspace/srv/devman
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/dev.c
ra796812c rc3d9aaf5 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2010 Lenka Trochtova 3 4 * All rights reserved. … … 50 51 refcount_init(&dev->refcnt); 51 52 list_initialize(&dev->functions); 53 fibril_mutex_initialize(&dev->state_lock); 54 fibril_condvar_initialize(&dev->state_cv); 52 55 link_initialize(&dev->driver_devices); 53 56 … … 87 90 if (refcount_down(&dev->refcnt)) 88 91 delete_dev_node(dev); 92 } 93 94 /** Wait until the device node enters stable state. 95 * 96 * @param dev Device node 97 */ 98 void 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); 89 104 } 90 105 -
uspace/srv/devman/dev.h
ra796812c rc3d9aaf5 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2013 Jiri Svoboda4 4 * All rights reserved. 5 5 * … … 41 41 extern void dev_add_ref(dev_node_t *); 42 42 extern void dev_del_ref(dev_node_t *); 43 extern void dev_wait_stable(dev_node_t *); 43 44 44 45 extern dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, -
uspace/srv/devman/devman.h
ra796812c rc3d9aaf5 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2011 Jiri Svoboda4 4 * All rights reserved. 5 5 * … … 105 105 typedef enum { 106 106 DEVICE_NOT_INITIALIZED = 0, 107 DEVICE_ATTACHING, 107 108 DEVICE_USABLE, 108 109 DEVICE_NOT_PRESENT, … … 129 130 /** The state of the device. */ 130 131 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; 131 136 /** Link to list of devices owned by driver (driver_t.devices) */ 132 137 link_t driver_devices; -
uspace/srv/devman/devtree.c
ra796812c rc3d9aaf5 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2010 Lenka Trochtova 3 4 * All rights reserved. … … 314 315 } 315 316 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 */ 324 void dev_tree_wait_stable(dev_tree_t *tree) 325 { 326 dev_wait_stable(tree->root_node->child); 327 } 328 316 329 /** @} 317 330 */ -
uspace/srv/devman/devtree.h
ra796812c rc3d9aaf5 1 1 /* 2 * Copyright (c) 2025 Jiri Svoboda 2 3 * Copyright (c) 2010 Lenka Trochtova 3 * Copyright (c) 2013 Jiri Svoboda4 4 * All rights reserved. 5 5 * … … 45 45 extern bool insert_fun_node(dev_tree_t *, fun_node_t *, char *, dev_node_t *); 46 46 extern void remove_fun_node(dev_tree_t *, fun_node_t *); 47 extern void dev_tree_wait_stable(dev_tree_t *); 47 48 48 49 #endif -
uspace/srv/devman/driver.c
ra796812c rc3d9aaf5 1 1 /* 2 * Copyright (c) 20 18Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * Copyright (c) 2010 Lenka Trochtova 4 4 * All rights reserved. … … 284 284 dev->drv = drv; 285 285 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); 287 290 list_append(&dev->driver_devices, &drv->devices); 288 291 … … 631 634 void add_device(driver_t *drv, dev_node_t *dev, dev_tree_t *tree) 632 635 { 636 link_t *link; 637 fun_node_t *fun; 638 633 639 /* 634 640 * We do not expect to have driver's mutex locked as we do not … … 664 670 async_wait_for(req, &rc); 665 671 } 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); 666 701 667 702 switch (rc) { … … 677 712 } 678 713 714 fibril_mutex_unlock(&dev->state_lock); 715 fibril_condvar_broadcast(&dev->state_cv); 716 679 717 dev->passed_to_driver = true; 680 718 } -
uspace/srv/devman/main.c
ra796812c rc3d9aaf5 1 1 /* 2 * Copyright (c) 202 3Jiri Svoboda2 * Copyright (c) 2025 Jiri Svoboda 3 3 * Copyright (c) 2010 Lenka Trochtova 4 4 * All rights reserved. … … 369 369 370 370 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."); 371 374 task_retval(0); 372 375 async_manager();
Note:
See TracChangeset
for help on using the changeset viewer.