Changeset a35b458 in mainline for uspace/srv/devman/driver.c
- Timestamp:
- 2018-03-02T20:10:49Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/driver.c
r3061bc1 ra35b458 54 54 { 55 55 assert(drv_list != NULL); 56 56 57 57 list_initialize(&drv_list->drivers); 58 58 fibril_mutex_initialize(&drv_list->drivers_mutex); … … 112 112 log_msg(LOG_DEFAULT, LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")", 113 113 base_path, name); 114 114 115 115 assert(base_path != NULL && name != NULL && drv != NULL); 116 116 117 117 bool suc = false; 118 118 char *match_path = NULL; 119 119 size_t name_size = 0; 120 120 121 121 /* Read the list of match ids from the driver's configuration file. */ 122 122 match_path = get_abs_path(base_path, name, MATCH_EXT); 123 123 if (match_path == NULL) 124 124 goto cleanup; 125 125 126 126 if (!read_match_ids(match_path, &drv->match_ids)) 127 127 goto cleanup; 128 128 129 129 /* Allocate and fill driver's name. */ 130 130 name_size = str_size(name) + 1; … … 133 133 goto cleanup; 134 134 str_cpy(drv->name, name_size, name); 135 135 136 136 /* Initialize path with driver's binary. */ 137 137 drv->binary_path = get_abs_path(base_path, name, ""); 138 138 if (drv->binary_path == NULL) 139 139 goto cleanup; 140 140 141 141 /* Check whether the driver's binary exists. */ 142 142 vfs_stat_t s; … … 146 146 goto cleanup; 147 147 } 148 148 149 149 suc = true; 150 150 151 151 cleanup: 152 152 if (!suc) { … … 156 156 init_driver(drv); 157 157 } 158 158 159 159 free(match_path); 160 160 161 161 return suc; 162 162 } … … 171 171 { 172 172 log_msg(LOG_DEFAULT, LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path); 173 173 174 174 int drv_cnt = 0; 175 175 DIR *dir = NULL; … … 177 177 178 178 dir = opendir(dir_path); 179 179 180 180 if (dir != NULL) { 181 181 driver_t *drv = create_driver(); … … 190 190 closedir(dir); 191 191 } 192 192 193 193 return drv_cnt; 194 194 } … … 213 213 driver_t *best_drv = NULL; 214 214 int best_score = 0, score = 0; 215 215 216 216 fibril_mutex_lock(&drivers_list->drivers_mutex); 217 217 218 218 list_foreach(drivers_list->drivers, drivers, driver_t, drv) { 219 219 score = get_match_score(drv, node); … … 223 223 } 224 224 } 225 225 226 226 fibril_mutex_unlock(&drivers_list->drivers_mutex); 227 227 228 228 return best_drv; 229 229 } … … 239 239 log_msg(LOG_DEFAULT, LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")", 240 240 dev->pfun->pathname, drv->name); 241 241 242 242 fibril_mutex_lock(&drv->driver_mutex); 243 243 fibril_rwlock_write_lock(&tree->rwlock); 244 244 245 245 dev->drv = drv; 246 246 list_append(&dev->driver_devices, &drv->devices); 247 247 248 248 fibril_rwlock_write_unlock(&tree->rwlock); 249 249 fibril_mutex_unlock(&drv->driver_mutex); … … 259 259 { 260 260 driver_t *drv = dev->drv; 261 261 262 262 assert(drv != NULL); 263 263 264 264 log_msg(LOG_DEFAULT, LVL_DEBUG, "detach_driver(dev=\"%s\",drv=\"%s\")", 265 265 dev->pfun->pathname, drv->name); 266 266 267 267 fibril_mutex_lock(&drv->driver_mutex); 268 268 fibril_rwlock_write_lock(&tree->rwlock); 269 269 270 270 dev->drv = NULL; 271 271 list_remove(&dev->driver_devices); 272 272 273 273 fibril_rwlock_write_unlock(&tree->rwlock); 274 274 fibril_mutex_unlock(&drv->driver_mutex); … … 286 286 287 287 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 288 288 289 289 log_msg(LOG_DEFAULT, LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name); 290 290 291 291 rc = task_spawnl(NULL, NULL, drv->binary_path, drv->binary_path, NULL); 292 292 if (rc != EOK) { … … 295 295 return false; 296 296 } 297 297 298 298 drv->state = DRIVER_STARTING; 299 299 return true; … … 310 310 async_exch_t *exch; 311 311 errno_t retval; 312 312 313 313 log_msg(LOG_DEFAULT, LVL_DEBUG, "stop_driver(drv=\"%s\")", drv->name); 314 314 … … 316 316 retval = async_req_0_0(exch, DRIVER_STOP); 317 317 loc_exchange_end(exch); 318 318 319 319 if (retval != EOK) 320 320 return retval; 321 321 322 322 drv->state = DRIVER_NOT_STARTED; 323 323 async_hangup(drv->sess); … … 336 336 { 337 337 driver_t *res = NULL; 338 338 339 339 fibril_mutex_lock(&drv_list->drivers_mutex); 340 340 341 341 list_foreach(drv_list->drivers, drivers, driver_t, drv) { 342 342 if (drv->handle == handle) { … … 345 345 } 346 346 } 347 347 348 348 fibril_mutex_unlock(&drv_list->drivers_mutex); 349 349 350 350 return res; 351 351 } … … 362 362 { 363 363 driver_t *res = NULL; 364 364 365 365 fibril_mutex_lock(&drv_list->drivers_mutex); 366 366 367 367 list_foreach(drv_list->drivers, drivers, driver_t, drv) { 368 368 if (str_cmp(drv->name, drv_name) == 0) { … … 371 371 } 372 372 } 373 373 374 374 fibril_mutex_unlock(&drv_list->drivers_mutex); 375 375 376 376 return res; 377 377 } … … 399 399 dev = list_get_instance(link, dev_node_t, driver_devices); 400 400 fibril_rwlock_write_lock(&tree->rwlock); 401 401 402 402 if (dev->passed_to_driver) { 403 403 fibril_rwlock_write_unlock(&tree->rwlock); … … 461 461 log_msg(LOG_DEFAULT, LVL_DEBUG, "initialize_running_driver(driver=\"%s\")", 462 462 driver->name); 463 463 464 464 /* 465 465 * Pass devices which have been already assigned to the driver to the … … 507 507 { 508 508 assert(drv != NULL); 509 509 510 510 clean_driver(drv); 511 511 free(drv); … … 525 525 assert(drivers_list != NULL); 526 526 assert(tree != NULL); 527 527 528 528 /* 529 529 * Find the driver which is the most suitable for handling this device. … … 535 535 return false; 536 536 } 537 537 538 538 /* Attach the driver to the device. */ 539 539 attach_driver(tree, dev, drv); 540 540 541 541 fibril_mutex_lock(&drv->driver_mutex); 542 542 if (drv->state == DRIVER_NOT_STARTED) { … … 550 550 if (is_running) 551 551 add_device(drv, dev, tree); 552 552 553 553 fibril_mutex_lock(&drv->driver_mutex); 554 554 fibril_mutex_unlock(&drv->driver_mutex); … … 575 575 log_msg(LOG_DEFAULT, LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")", 576 576 drv->name, dev->pfun->name); 577 577 578 578 /* Send the device to the driver. */ 579 579 devman_handle_t parent_handle; … … 583 583 parent_handle = 0; 584 584 } 585 585 586 586 async_exch_t *exch = async_exchange_begin(drv->sess); 587 587 588 588 ipc_call_t answer; 589 589 aid_t req = async_send_2(exch, DRIVER_DEV_ADD, dev->handle, 590 590 parent_handle, &answer); 591 591 592 592 /* Send the device name to the driver. */ 593 593 errno_t rc = async_data_write_start(exch, dev->pfun->name, 594 594 str_size(dev->pfun->name) + 1); 595 595 596 596 async_exchange_end(exch); 597 597 598 598 if (rc != EOK) { 599 599 async_forget(req); … … 614 614 break; 615 615 } 616 616 617 617 dev->passed_to_driver = true; 618 618 } … … 624 624 driver_t *drv; 625 625 devman_handle_t handle; 626 626 627 627 assert(dev != NULL); 628 628 629 629 log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_remove(%p)", dev); 630 630 631 631 fibril_rwlock_read_lock(&tree->rwlock); 632 632 drv = dev->drv; 633 633 handle = dev->handle; 634 634 fibril_rwlock_read_unlock(&tree->rwlock); 635 635 636 636 exch = async_exchange_begin(drv->sess); 637 637 retval = async_req_1_0(exch, DRIVER_DEV_REMOVE, handle); 638 638 async_exchange_end(exch); 639 639 640 640 return retval; 641 641 } … … 647 647 driver_t *drv; 648 648 devman_handle_t handle; 649 649 650 650 assert(dev != NULL); 651 651 652 652 log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_dev_gone(%p)", dev); 653 653 654 654 fibril_rwlock_read_lock(&tree->rwlock); 655 655 drv = dev->drv; 656 656 handle = dev->handle; 657 657 fibril_rwlock_read_unlock(&tree->rwlock); 658 658 659 659 exch = async_exchange_begin(drv->sess); 660 660 retval = async_req_1_0(exch, DRIVER_DEV_GONE, handle); 661 661 async_exchange_end(exch); 662 662 663 663 return retval; 664 664 } … … 670 670 driver_t *drv; 671 671 devman_handle_t handle; 672 672 673 673 log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_online(%p)", fun); 674 674 675 675 fibril_rwlock_read_lock(&tree->rwlock); 676 676 677 677 if (fun->dev == NULL) { 678 678 /* XXX root function? */ … … 680 680 return EINVAL; 681 681 } 682 682 683 683 drv = fun->dev->drv; 684 684 handle = fun->handle; 685 685 fibril_rwlock_read_unlock(&tree->rwlock); 686 686 687 687 exch = async_exchange_begin(drv->sess); 688 688 retval = async_req_1_0(exch, DRIVER_FUN_ONLINE, handle); 689 689 loc_exchange_end(exch); 690 690 691 691 return retval; 692 692 } … … 698 698 driver_t *drv; 699 699 devman_handle_t handle; 700 700 701 701 log_msg(LOG_DEFAULT, LVL_DEBUG, "driver_fun_offline(%p)", fun); 702 702 … … 707 707 return EINVAL; 708 708 } 709 709 710 710 drv = fun->dev->drv; 711 711 handle = fun->handle; 712 712 fibril_rwlock_read_unlock(&tree->rwlock); 713 713 714 714 exch = async_exchange_begin(drv->sess); 715 715 retval = async_req_1_0(exch, DRIVER_FUN_OFFLINE, handle); 716 716 loc_exchange_end(exch); 717 717 718 718 return retval; 719 719
Note:
See TracChangeset
for help on using the changeset viewer.