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