Changes in uspace/srv/devman/devman.c [8b1e15ac:c7bbf029] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r8b1e15ac rc7bbf029 34 34 #include <fcntl.h> 35 35 #include <sys/stat.h> 36 #include <io/log.h> 36 37 #include <ipc/driver.h> 37 38 #include <ipc/devman.h> 38 39 #include <devmap.h> 39 40 #include <str_error.h> 41 #include <stdio.h> 40 42 41 43 #include "devman.h" … … 146 148 fibril_mutex_unlock(&drivers_list->drivers_mutex); 147 149 148 printf(NAME": the '%s' driverwas added to the list of available "149 "drivers. \n", drv->name);150 log_msg(LVL_NOTE, "Driver `%s' was added to the list of available " 151 "drivers.", drv->name); 150 152 } 151 153 … … 237 239 bool read_match_ids(const char *conf_path, match_id_list_t *ids) 238 240 { 239 printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);241 log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path); 240 242 241 243 bool suc = false; … … 247 249 fd = open(conf_path, O_RDONLY); 248 250 if (fd < 0) { 249 printf(NAME ": unable to open %s\n", conf_path); 251 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.", 252 conf_path, str_error(fd)); 250 253 goto cleanup; 251 254 } … … 255 258 lseek(fd, 0, SEEK_SET); 256 259 if (len == 0) { 257 printf(NAME ": configuration file '%s' is empty.\n", conf_path); 260 log_msg(LVL_ERROR, "Configuration file '%s' is empty.", 261 conf_path); 258 262 goto cleanup; 259 263 } … … 261 265 buf = malloc(len + 1); 262 266 if (buf == NULL) { 263 printf(NAME ": memory allocation failed when parsing file "264 "'%s'. \n", conf_path);267 log_msg(LVL_ERROR, "Memory allocation failed when parsing file " 268 "'%s'.", conf_path); 265 269 goto cleanup; 266 270 } 267 271 268 if (read(fd, buf, len) <= 0) { 269 printf(NAME ": unable to read file '%s'.\n", conf_path); 272 ssize_t read_bytes = safe_read(fd, buf, len); 273 if (read_bytes <= 0) { 274 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); 270 275 goto cleanup; 271 276 } 272 buf[ len] = 0;277 buf[read_bytes] = 0; 273 278 274 279 suc = parse_match_ids(buf, ids); … … 305 310 bool get_driver_info(const char *base_path, const char *name, driver_t *drv) 306 311 { 307 printf(NAME ": get_driver_info base_path = %s, name = %s.\n",312 log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")", 308 313 base_path, name); 309 314 … … 337 342 struct stat s; 338 343 if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */ 339 printf(NAME ": driver not found at path %s.", drv->binary_path); 344 log_msg(LVL_ERROR, "Driver not found at path `%s'.", 345 drv->binary_path); 340 346 goto cleanup; 341 347 } … … 364 370 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path) 365 371 { 366 printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);372 log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path); 367 373 368 374 int drv_cnt = 0; … … 398 404 dev_node_t *dev; 399 405 400 printf(NAME ": create_root_nodes\n");406 log_msg(LVL_DEBUG, "create_root_nodes()"); 401 407 402 408 fibril_rwlock_write_lock(&tree->rwlock); … … 483 489 void attach_driver(dev_node_t *dev, driver_t *drv) 484 490 { 485 printf(NAME ": attach_driver %s to device %s\n",486 d rv->name, dev->pfun->pathname);491 log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")", 492 dev->pfun->pathname, drv->name); 487 493 488 494 fibril_mutex_lock(&drv->driver_mutex); … … 506 512 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 507 513 508 printf(NAME ": start_driver '%s'\n", drv->name);514 log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name); 509 515 510 516 rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL); 511 517 if (rc != EOK) { 512 printf(NAME ": error spawning %s (%s)\n",513 drv->name, str_error(rc));518 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.", 519 drv->name, drv->binary_path, str_error(rc)); 514 520 return false; 515 521 } … … 550 556 } 551 557 552 /** Remember the driver's phone.553 *554 * @param driver The driver.555 * @param phone The phone to the driver.556 */557 void set_driver_phone(driver_t *driver, sysarg_t phone)558 {559 fibril_mutex_lock(&driver->driver_mutex);560 assert(driver->state == DRIVER_STARTING);561 driver->phone = phone;562 fibril_mutex_unlock(&driver->driver_mutex);563 }564 565 558 /** Notify driver about the devices to which it was assigned. 566 559 * … … 573 566 int phone; 574 567 575 printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name); 568 log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")", 569 driver->name); 576 570 577 571 fibril_mutex_lock(&driver->driver_mutex); … … 640 634 * immediately and possibly started here as well. 641 635 */ 642 printf(NAME ": driver %s goes into running state.\n", driver->name);636 log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name); 643 637 driver->state = DRIVER_RUNNING; 644 638 … … 657 651 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 658 652 { 659 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 653 log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")", 654 driver->name); 660 655 661 656 /* … … 678 673 list_initialize(&drv->devices); 679 674 fibril_mutex_initialize(&drv->driver_mutex); 675 drv->phone = -1; 680 676 } 681 677 … … 747 743 * access any structures that would affect driver_t. 748 744 */ 749 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,750 d ev->pfun->name);745 log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")", 746 drv->name, dev->pfun->name); 751 747 752 748 sysarg_t rc; … … 809 805 driver_t *drv = find_best_match_driver(drivers_list, dev); 810 806 if (drv == NULL) { 811 printf(NAME ": no driver found for device '%s'.\n",807 log_msg(LVL_ERROR, "No driver found for device `%s'.", 812 808 dev->pfun->pathname); 813 809 return false; … … 847 843 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list) 848 844 { 849 printf(NAME ": init_device_tree.\n");845 log_msg(LVL_DEBUG, "init_device_tree()"); 850 846 851 847 tree->current_handle = 0; … … 1026 1022 fun->pathname = (char *) malloc(pathsize); 1027 1023 if (fun->pathname == NULL) { 1028 printf(NAME ": failed to allocate device path.\n");1024 log_msg(LVL_ERROR, "Failed to allocate device path."); 1029 1025 return false; 1030 1026 } … … 1057 1053 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1058 1054 1055 log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])", 1056 dev, pfun, pfun->pathname); 1057 1059 1058 /* Add the node to the handle-to-node map. */ 1060 1059 dev->handle = ++tree->current_handle; … … 1063 1062 1064 1063 /* Add the node to the list of its parent's children. */ 1065 printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);1066 1064 dev->pfun = pfun; 1067 1065 pfun->child = dev; … … 1123 1121 fun_node_t *find_fun_node_by_path(dev_tree_t *tree, char *path) 1124 1122 { 1123 assert(path != NULL); 1124 1125 bool is_absolute = path[0] == '/'; 1126 if (!is_absolute) { 1127 return NULL; 1128 } 1129 1125 1130 fibril_rwlock_read_lock(&tree->rwlock); 1126 1131 … … 1132 1137 char *rel_path = path; 1133 1138 char *next_path_elem = NULL; 1134 bool cont = (rel_path[0] == '/');1139 bool cont = true; 1135 1140 1136 1141 while (cont && fun != NULL) { … … 1157 1162 } 1158 1163 1164 /** Find function with a specified name belonging to given device. 1165 * 1166 * Device tree rwlock should be held at least for reading. 1167 * 1168 * @param dev Device the function belongs to. 1169 * @param name Function name (not path). 1170 * @return Function node. 1171 * @retval NULL No function with given name. 1172 */ 1173 fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name) 1174 { 1175 assert(dev != NULL); 1176 assert(name != NULL); 1177 1178 fun_node_t *fun; 1179 link_t *link; 1180 1181 for (link = dev->functions.next; 1182 link != &dev->functions; 1183 link = link->next) { 1184 fun = list_get_instance(link, fun_node_t, dev_functions); 1185 1186 if (str_cmp(name, fun->name) == 0) 1187 return fun; 1188 } 1189 1190 return NULL; 1191 } 1192 1193 /** Find function node by its class name and index. */ 1194 fun_node_t *find_fun_node_by_class(class_list_t *class_list, 1195 const char *class_name, const char *dev_name) 1196 { 1197 assert(class_list != NULL); 1198 assert(class_name != NULL); 1199 assert(dev_name != NULL); 1200 1201 fibril_rwlock_read_lock(&class_list->rwlock); 1202 1203 dev_class_t *cl = find_dev_class_no_lock(class_list, class_name); 1204 if (cl == NULL) { 1205 fibril_rwlock_read_unlock(&class_list->rwlock); 1206 return NULL; 1207 } 1208 1209 dev_class_info_t *dev = find_dev_in_class(cl, dev_name); 1210 if (dev == NULL) { 1211 fibril_rwlock_read_unlock(&class_list->rwlock); 1212 return NULL; 1213 } 1214 1215 fun_node_t *fun = dev->fun; 1216 1217 fibril_rwlock_read_unlock(&class_list->rwlock); 1218 1219 return fun; 1220 } 1221 1222 1159 1223 /** Find child function node with a specified name. 1160 1224 * … … 1167 1231 fun_node_t *find_node_child(fun_node_t *pfun, const char *name) 1168 1232 { 1169 fun_node_t *fun; 1170 link_t *link; 1171 1172 link = pfun->child->functions.next; 1173 1174 while (link != &pfun->child->functions) { 1175 fun = list_get_instance(link, fun_node_t, dev_functions); 1176 1177 if (str_cmp(name, fun->name) == 0) 1178 return fun; 1179 1180 link = link->next; 1181 } 1182 1183 return NULL; 1233 return find_fun_node_in_device(pfun->child, name); 1184 1234 } 1185 1235 … … 1215 1265 if (info != NULL) { 1216 1266 memset(info, 0, sizeof(dev_class_info_t)); 1217 li st_initialize(&info->dev_classes);1218 li st_initialize(&info->devmap_link);1219 li st_initialize(&info->link);1267 link_initialize(&info->dev_classes); 1268 link_initialize(&info->devmap_link); 1269 link_initialize(&info->link); 1220 1270 } 1221 1271 … … 1343 1393 } 1344 1394 1395 dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name) 1396 { 1397 assert(dev_class != NULL); 1398 assert(dev_name != NULL); 1399 1400 link_t *link; 1401 for (link = dev_class->devices.next; 1402 link != &dev_class->devices; 1403 link = link->next) { 1404 dev_class_info_t *dev = list_get_instance(link, 1405 dev_class_info_t, link); 1406 1407 if (str_cmp(dev->dev_name, dev_name) == 0) { 1408 return dev; 1409 } 1410 } 1411 1412 return NULL; 1413 } 1414 1345 1415 void init_class_list(class_list_t *class_list) 1346 1416 {
Note:
See TracChangeset
for help on using the changeset viewer.