Changeset a32defa in mainline
- Timestamp:
- 2010-06-01T20:53:07Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a6e54c5d
- Parents:
- ce89036b
- Location:
- uspace/srv/devman
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
rce89036b ra32defa 36 36 #include <ipc/driver.h> 37 37 #include <ipc/devman.h> 38 #include <devmap.h> 38 39 39 40 #include "devman.h" … … 488 489 * @param driver the driver to which the devices are passed. 489 490 */ 490 static void pass_devices_to_driver(driver_t *driver )491 static void pass_devices_to_driver(driver_t *driver, dev_tree_t *tree) 491 492 { 492 493 printf(NAME ": pass_devices_to_driver\n"); … … 501 502 while (link != &driver->devices) { 502 503 dev = list_get_instance(link, node_t, driver_devices); 503 add_device(phone, driver, dev );504 add_device(phone, driver, dev, tree); 504 505 link = link->next; 505 506 } … … 516 517 * @param driver the driver which registered itself as running by the device manager. 517 518 */ 518 void initialize_running_driver(driver_t *driver )519 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 519 520 { 520 521 printf(NAME ": initialize_running_driver\n"); … … 522 523 523 524 // pass devices which have been already assigned to the driver to the driver 524 pass_devices_to_driver(driver );525 pass_devices_to_driver(driver, tree); 525 526 526 527 // change driver's state to running … … 530 531 } 531 532 533 534 static void devmap_register_tree_device(node_t *node, dev_tree_t *tree) 535 { 536 // create devmap path and name for the device 537 char *devmap_pathname = NULL; 538 char *devmap_name = NULL; 539 540 asprintf(&devmap_name, "%s", node->pathname); 541 if (NULL == devmap_name) { 542 return; 543 } 544 545 replace_char(devmap_name, '/', DEVMAP_SEPARATOR); 546 547 asprintf(&devmap_pathname, "%s/%s", DEVMAP_DEVICE_NAMESPACE, devmap_name); 548 if (NULL == devmap_pathname) { 549 free(devmap_name); 550 return; 551 } 552 553 devmap_device_register(devmap_pathname, &node->devmap_handle); 554 555 tree_add_devmap_device(tree, node); 556 557 free(devmap_name); 558 free(devmap_pathname); 559 } 560 561 532 562 /** Pass a device to running driver. 533 563 * … … 535 565 * @param node the device's node in the device tree. 536 566 */ 537 void add_device(int phone, driver_t *drv, node_t *node )567 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree) 538 568 { 539 569 printf(NAME ": add_device\n"); … … 556 586 case EOK: 557 587 node->state = DEVICE_USABLE; 588 devmap_register_tree_device(node, tree); 558 589 break; 559 590 case ENOENT: … … 575 606 * @return true if the suitable driver is found and successfully assigned to the device, false otherwise. 576 607 */ 577 bool assign_driver(node_t *node, driver_list_t *drivers_list )608 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree) 578 609 { 579 610 //printf(NAME ": assign_driver\n"); … … 598 629 int phone = ipc_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0); 599 630 if (phone > 0) { 600 add_device(phone, drv, node );631 add_device(phone, drv, node, tree); 601 632 ipc_hangup(phone); 602 633 } … … 632 663 633 664 // find suitable driver and start it 634 return assign_driver(tree->root_node, drivers_list );665 return assign_driver(tree->root_node, drivers_list, tree); 635 666 } 636 667 -
uspace/srv/devman/devman.h
rce89036b ra32defa 55 55 #define DEVMAP_CLASS_NAMESPACE "class" 56 56 #define DEVMAP_DEVICE_NAMESPACE "devices" 57 #define DEVMAP_SEPARATOR "\\"57 #define DEVMAP_SEPARATOR '\\' 58 58 59 59 struct node; … … 230 230 231 231 driver_t * find_best_match_driver(driver_list_t *drivers_list, node_t *node); 232 bool assign_driver(node_t *node, driver_list_t *drivers_list );232 bool assign_driver(node_t *node, driver_list_t *drivers_list, dev_tree_t *tree); 233 233 234 234 void add_driver(driver_list_t *drivers_list, driver_t *drv); 235 235 void attach_driver(node_t *node, driver_t *drv); 236 void add_device(int phone, driver_t *drv, node_t *node );236 void add_device(int phone, driver_t *drv, node_t *node, dev_tree_t *tree); 237 237 bool start_driver(driver_t *drv); 238 238 239 239 driver_t * find_driver(driver_list_t *drv_list, const char *drv_name); 240 240 void set_driver_phone(driver_t *driver, ipcarg_t phone); 241 void initialize_running_driver(driver_t *driver );241 void initialize_running_driver(driver_t *driver, dev_tree_t *tree); 242 242 243 243 /** … … 427 427 node_t *find_devmap_class_device(class_list_t *classes, dev_handle_t devmap_handle); 428 428 429 430 static inline void class_add_devmap_device(class_list_t *class_list, dev_class_info_t *cli) 431 { 432 unsigned long key = (unsigned long)cli->devmap_handle; 433 fibril_rwlock_write_lock(&class_list->rwlock); 434 hash_table_insert(&class_list->devmap_devices, &key, &cli->devmap_link); 435 fibril_rwlock_write_unlock(&class_list->rwlock); 436 } 437 438 static inline void tree_add_devmap_device(dev_tree_t *tree, node_t *node) 439 { 440 unsigned long key = (unsigned long)node->devmap_handle; 441 fibril_rwlock_write_lock(&tree->rwlock); 442 hash_table_insert(&tree->devmap_devices, &key, &node->devmap_link); 443 fibril_rwlock_write_unlock(&tree->rwlock); 444 } 445 429 446 #endif 430 447 -
uspace/srv/devman/main.c
rce89036b ra32defa 240 240 241 241 // try to find suitable driver and assign it to the device 242 assign_driver(node, &drivers_list );242 assign_driver(node, &drivers_list, &device_tree); 243 243 } 244 244 … … 247 247 // create devmap path and name for the device 248 248 char *devmap_pathname = NULL; 249 asprintf(&devmap_pathname, "%s/%s% s%s", DEVMAP_CLASS_NAMESPACE, cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name);249 asprintf(&devmap_pathname, "%s/%s%c%s", DEVMAP_CLASS_NAMESPACE, cli->dev_class->name, DEVMAP_SEPARATOR, cli->dev_name); 250 250 if (NULL == devmap_pathname) { 251 251 return; … … 254 254 // register the device by the device mapper and remember its devmap handle 255 255 devmap_device_register(devmap_pathname, &cli->devmap_handle); 256 257 // add device to the hash map of class devices registered by device mapper 258 class_add_devmap_device(&class_list, cli); 256 259 257 260 free(devmap_pathname); … … 297 300 { 298 301 driver_t *driver = (driver_t *)drv; 299 initialize_running_driver(driver );302 initialize_running_driver(driver, &device_tree); 300 303 printf(NAME ": the %s driver was successfully initialized. \n", driver->name); 301 304 return 0; -
uspace/srv/devman/util.h
rce89036b ra32defa 77 77 } 78 78 79 static inline void replace_char(char *str, char orig, char repl) 80 { 81 while (*str) { 82 if (orig == *str) { 83 *str = repl; 84 } 85 str++; 86 } 87 } 88 79 89 #endif
Note:
See TracChangeset
for help on using the changeset viewer.