Changeset 969585f in mainline for uspace/srv/devman/devman.c
- Timestamp:
- 2011-04-01T20:49:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0053fa38, 5542b83, c6ba274
- Parents:
- 8e7d724 (diff), ebcb05a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
r8e7d724 r969585f 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> … … 146 147 fibril_mutex_unlock(&drivers_list->drivers_mutex); 147 148 148 printf(NAME": the '%s' driver was added to the list of available " 149 "drivers.\n", drv->name); 150 151 printf(NAME ": match ids:"); 152 link_t *cur; 153 for (cur = drv->match_ids.ids.next; cur != &drv->match_ids.ids; cur = cur->next) { 154 match_id_t *match_id = list_get_instance(cur, match_id_t, link); 155 printf(" %d:%s", match_id->score, match_id->id); 156 } 157 printf("\n"); 149 log_msg(LVL_NOTE, "Driver `%s' was added to the list of available " 150 "drivers.", drv->name); 158 151 } 159 152 … … 245 238 bool read_match_ids(const char *conf_path, match_id_list_t *ids) 246 239 { 247 printf(NAME ": read_match_ids conf_path = %s.\n", conf_path);240 log_msg(LVL_DEBUG, "read_match_ids(conf_path=\"%s\")", conf_path); 248 241 249 242 bool suc = false; … … 255 248 fd = open(conf_path, O_RDONLY); 256 249 if (fd < 0) { 257 printf(NAME ": unable to open %s\n", conf_path); 250 log_msg(LVL_ERROR, "Unable to open `%s' for reading: %s.", 251 conf_path, str_error(fd)); 258 252 goto cleanup; 259 253 } … … 263 257 lseek(fd, 0, SEEK_SET); 264 258 if (len == 0) { 265 printf(NAME ": configuration file '%s' is empty.\n", conf_path); 259 log_msg(LVL_ERROR, "Configuration file '%s' is empty.", 260 conf_path); 266 261 goto cleanup; 267 262 } … … 269 264 buf = malloc(len + 1); 270 265 if (buf == NULL) { 271 printf(NAME ": memory allocation failed when parsing file "272 "'%s'. \n", conf_path);266 log_msg(LVL_ERROR, "Memory allocation failed when parsing file " 267 "'%s'.", conf_path); 273 268 goto cleanup; 274 269 } … … 276 271 ssize_t read_bytes = safe_read(fd, buf, len); 277 272 if (read_bytes <= 0) { 278 printf(NAME ": unable to read file '%s'.\n", conf_path);273 log_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path); 279 274 goto cleanup; 280 275 } … … 314 309 bool get_driver_info(const char *base_path, const char *name, driver_t *drv) 315 310 { 316 printf(NAME ": get_driver_info base_path = %s, name = %s.\n",311 log_msg(LVL_DEBUG, "get_driver_info(base_path=\"%s\", name=\"%s\")", 317 312 base_path, name); 318 313 … … 346 341 struct stat s; 347 342 if (stat(drv->binary_path, &s) == ENOENT) { /* FIXME!! */ 348 printf(NAME ": driver not found at path %s.", drv->binary_path); 343 log_msg(LVL_ERROR, "Driver not found at path `%s'.", 344 drv->binary_path); 349 345 goto cleanup; 350 346 } … … 373 369 int lookup_available_drivers(driver_list_t *drivers_list, const char *dir_path) 374 370 { 375 printf(NAME ": lookup_available_drivers, dir = %s \n", dir_path);371 log_msg(LVL_DEBUG, "lookup_available_drivers(dir=\"%s\")", dir_path); 376 372 377 373 int drv_cnt = 0; … … 407 403 dev_node_t *dev; 408 404 409 printf(NAME ": create_root_nodes\n");405 log_msg(LVL_DEBUG, "create_root_nodes()"); 410 406 411 407 fibril_rwlock_write_lock(&tree->rwlock); … … 492 488 void attach_driver(dev_node_t *dev, driver_t *drv) 493 489 { 494 printf(NAME ": attach_driver %s to device %s\n",495 d rv->name, dev->pfun->pathname);490 log_msg(LVL_DEBUG, "attach_driver(dev=\"%s\",drv=\"%s\")", 491 dev->pfun->pathname, drv->name); 496 492 497 493 fibril_mutex_lock(&drv->driver_mutex); … … 515 511 assert(fibril_mutex_is_locked(&drv->driver_mutex)); 516 512 517 printf(NAME ": start_driver '%s'\n", drv->name);513 log_msg(LVL_DEBUG, "start_driver(drv=\"%s\")", drv->name); 518 514 519 515 rc = task_spawnl(NULL, drv->binary_path, drv->binary_path, NULL); 520 516 if (rc != EOK) { 521 printf(NAME ": error spawning %s (%s)\n",522 drv->name, str_error(rc));517 log_msg(LVL_ERROR, "Spawning driver `%s' (%s) failed: %s.", 518 drv->name, drv->binary_path, str_error(rc)); 523 519 return false; 524 520 } … … 582 578 int phone; 583 579 584 printf(NAME ": pass_devices_to_driver(`%s')\n", driver->name); 580 log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")", 581 driver->name); 585 582 586 583 fibril_mutex_lock(&driver->driver_mutex); … … 649 646 * immediately and possibly started here as well. 650 647 */ 651 printf(NAME ": driver %s goes into running state.\n", driver->name);648 log_msg(LVL_DEBUG, "Driver `%s' enters running state.", driver->name); 652 649 driver->state = DRIVER_RUNNING; 653 650 … … 666 663 void initialize_running_driver(driver_t *driver, dev_tree_t *tree) 667 664 { 668 printf(NAME ": initialize_running_driver (`%s')\n", driver->name); 665 log_msg(LVL_DEBUG, "initialize_running_driver(driver=\"%s\")", 666 driver->name); 669 667 670 668 /* … … 756 754 * access any structures that would affect driver_t. 757 755 */ 758 printf(NAME ": add_device (driver `%s', device `%s')\n", drv->name,759 d ev->pfun->name);756 log_msg(LVL_DEBUG, "add_device(drv=\"%s\", dev=\"%s\")", 757 drv->name, dev->pfun->name); 760 758 761 759 sysarg_t rc; … … 818 816 driver_t *drv = find_best_match_driver(drivers_list, dev); 819 817 if (drv == NULL) { 820 printf(NAME ": no driver found for device '%s'.\n",818 log_msg(LVL_ERROR, "No driver found for device `%s'.", 821 819 dev->pfun->pathname); 822 820 return false; … … 856 854 bool init_device_tree(dev_tree_t *tree, driver_list_t *drivers_list) 857 855 { 858 printf(NAME ": init_device_tree.\n");856 log_msg(LVL_DEBUG, "init_device_tree()"); 859 857 860 858 tree->current_handle = 0; … … 1035 1033 fun->pathname = (char *) malloc(pathsize); 1036 1034 if (fun->pathname == NULL) { 1037 printf(NAME ": failed to allocate device path.\n");1035 log_msg(LVL_ERROR, "Failed to allocate device path."); 1038 1036 return false; 1039 1037 } … … 1066 1064 assert(fibril_rwlock_is_write_locked(&tree->rwlock)); 1067 1065 1066 log_msg(LVL_DEBUG, "insert_dev_node(dev=%p, pfun=%p [\"%s\"])", 1067 dev, pfun, pfun->pathname); 1068 1068 1069 /* Add the node to the handle-to-node map. */ 1069 1070 dev->handle = ++tree->current_handle; … … 1072 1073 1073 1074 /* Add the node to the list of its parent's children. */ 1074 printf("insert_dev_node: dev=%p, dev->pfun := %p\n", dev, pfun);1075 1075 dev->pfun = pfun; 1076 1076 pfun->child = dev; … … 1173 1173 } 1174 1174 1175 /** Find function with a specified name belonging to given device. 1176 * 1177 * Device tree rwlock should be held at least for reading. 1178 * 1179 * @param dev Device the function belongs to. 1180 * @param name Function name (not path). 1181 * @return Function node. 1182 * @retval NULL No function with given name. 1183 */ 1184 fun_node_t *find_fun_node_in_device(dev_node_t *dev, const char *name) 1185 { 1186 assert(dev != NULL); 1187 assert(name != NULL); 1188 1189 fun_node_t *fun; 1190 link_t *link; 1191 1192 for (link = dev->functions.next; 1193 link != &dev->functions; 1194 link = link->next) { 1195 fun = list_get_instance(link, fun_node_t, dev_functions); 1196 1197 if (str_cmp(name, fun->name) == 0) 1198 return fun; 1199 } 1200 1201 return NULL; 1202 } 1203 1204 /** Find function node by its class name and index. */ 1205 fun_node_t *find_fun_node_by_class(class_list_t *class_list, 1206 const char *class_name, const char *dev_name) 1207 { 1208 assert(class_list != NULL); 1209 assert(class_name != NULL); 1210 assert(dev_name != NULL); 1211 1212 fibril_rwlock_read_lock(&class_list->rwlock); 1213 1214 dev_class_t *cl = find_dev_class_no_lock(class_list, class_name); 1215 if (cl == NULL) { 1216 fibril_rwlock_read_unlock(&class_list->rwlock); 1217 return NULL; 1218 } 1219 1220 dev_class_info_t *dev = find_dev_in_class(cl, dev_name); 1221 if (dev == NULL) { 1222 fibril_rwlock_read_unlock(&class_list->rwlock); 1223 return NULL; 1224 } 1225 1226 fun_node_t *fun = dev->fun; 1227 1228 fibril_rwlock_read_unlock(&class_list->rwlock); 1229 1230 return fun; 1231 } 1232 1233 1175 1234 /** Find child function node with a specified name. 1176 1235 * … … 1183 1242 fun_node_t *find_node_child(fun_node_t *pfun, const char *name) 1184 1243 { 1185 fun_node_t *fun; 1186 link_t *link; 1187 1188 link = pfun->child->functions.next; 1189 1190 while (link != &pfun->child->functions) { 1191 fun = list_get_instance(link, fun_node_t, dev_functions); 1192 1193 if (str_cmp(name, fun->name) == 0) 1194 return fun; 1195 1196 link = link->next; 1197 } 1198 1199 return NULL; 1244 return find_fun_node_in_device(pfun->child, name); 1200 1245 } 1201 1246 … … 1359 1404 } 1360 1405 1406 dev_class_info_t *find_dev_in_class(dev_class_t *dev_class, const char *dev_name) 1407 { 1408 assert(dev_class != NULL); 1409 assert(dev_name != NULL); 1410 1411 link_t *link; 1412 for (link = dev_class->devices.next; 1413 link != &dev_class->devices; 1414 link = link->next) { 1415 dev_class_info_t *dev = list_get_instance(link, 1416 dev_class_info_t, link); 1417 1418 if (str_cmp(dev->dev_name, dev_name) == 0) { 1419 return dev; 1420 } 1421 } 1422 1423 return NULL; 1424 } 1425 1361 1426 void init_class_list(class_list_t *class_list) 1362 1427 {
Note:
See TracChangeset
for help on using the changeset viewer.