Changeset 0511549 in mainline
- Timestamp:
- 2013-09-10T23:11:34Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- de3d15b4
- Parents:
- 5df1963
- Location:
- uspace
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/devctl/devctl.c
r5df1963 r0511549 159 159 } 160 160 161 static int drv_list(void) 162 { 163 devman_handle_t *drvs; 164 size_t ndrvs; 165 size_t i; 166 int rc; 167 168 rc = devman_get_drivers(&drvs, &ndrvs); 169 if (rc != EOK) 170 return rc; 171 172 printf("Got %d handles\n", ndrvs); 173 for (i = 0; i < ndrvs; i++) { 174 rc = devman_driver_get_name(drvs[i], drv_name, MAX_NAME_LENGTH); 175 if (rc != EOK) 176 continue; 177 printf("%3d %s\n", (int)drvs[i], drv_name); 178 } 179 free(drvs); 180 181 return EOK; 182 } 183 161 184 static void print_syntax(void) 162 185 { 163 printf("syntax: devctl [(online|offline) <function>]\n"); 186 printf("syntax:\n"); 187 printf("\tdevctl\n"); 188 printf("\tdevctl online <function>]\n"); 189 printf("\tdevctl offline <function>]\n"); 190 printf("\tdevctl list-drv\n"); 164 191 } 165 192 … … 194 221 return 2; 195 222 } 223 } else if (str_cmp(argv[1], "list-drv") == 0) { 224 rc = drv_list(); 225 if (rc != EOK) 226 return 2; 196 227 } else { 197 228 printf(NAME ": Invalid argument '%s'.\n", argv[1]); -
uspace/lib/c/generic/devman.c
r5df1963 r0511549 592 592 } 593 593 594 int devman_get_drivers(devman_handle_t **drvs, 595 size_t *count) 596 { 597 return devman_get_handles_internal(DEVMAN_GET_DRIVERS, 0, drvs, count); 598 } 599 600 int devman_driver_get_name(devman_handle_t handle, char *buf, size_t buf_size) 601 { 602 return devman_get_str_internal(DEVMAN_DRIVER_GET_NAME, handle, buf, 603 buf_size); 604 } 605 594 606 /** @} 595 607 */ -
uspace/lib/c/include/devman.h
r5df1963 r0511549 71 71 extern int devman_add_device_to_category(devman_handle_t, const char *); 72 72 extern int devman_fun_sid_to_handle(service_id_t, devman_handle_t *); 73 extern int devman_get_drivers(devman_handle_t **, size_t *); 74 extern int devman_driver_get_name(devman_handle_t, char *, size_t); 73 75 74 76 #endif -
uspace/lib/c/include/ipc/devman.h
r5df1963 r0511549 161 161 DEVMAN_FUN_OFFLINE, 162 162 DEVMAN_FUN_GET_PATH, 163 DEVMAN_FUN_SID_TO_HANDLE 163 DEVMAN_FUN_SID_TO_HANDLE, 164 DEVMAN_GET_DRIVERS, 165 DEVMAN_DRIVER_GET_NAME 164 166 } client_to_devman_t; 165 167 -
uspace/srv/devman/client_conn.c
r5df1963 r0511549 317 317 } 318 318 319 320 319 /** Get handle for child device of a function. */ 321 320 static void devman_fun_get_child(ipc_callid_t iid, ipc_call_t *icall) … … 417 416 } 418 417 418 /** Get list of all registered drivers. */ 419 static void devman_get_drivers(ipc_callid_t iid, ipc_call_t *icall) 420 { 421 ipc_callid_t callid; 422 size_t size; 423 size_t act_size; 424 int rc; 425 426 if (!async_data_read_receive(&callid, &size)) { 427 async_answer_0(callid, EREFUSED); 428 async_answer_0(iid, EREFUSED); 429 return; 430 } 431 432 devman_handle_t *hdl_buf = (devman_handle_t *) malloc(size); 433 if (hdl_buf == NULL) { 434 async_answer_0(callid, ENOMEM); 435 async_answer_0(iid, ENOMEM); 436 return; 437 } 438 439 rc = driver_get_list(&drivers_list, hdl_buf, size, &act_size); 440 if (rc != EOK) { 441 async_answer_0(callid, rc); 442 async_answer_0(iid, rc); 443 return; 444 } 445 446 sysarg_t retval = async_data_read_finalize(callid, hdl_buf, size); 447 free(hdl_buf); 448 449 async_answer_1(iid, retval, act_size); 450 } 451 452 /** Get driver name. */ 453 static void devman_driver_get_name(ipc_callid_t iid, ipc_call_t *icall) 454 { 455 devman_handle_t handle = IPC_GET_ARG1(*icall); 456 457 driver_t *drv = driver_find(&drivers_list, handle); 458 if (drv == NULL) { 459 async_answer_0(iid, ENOMEM); 460 return; 461 } 462 463 ipc_callid_t data_callid; 464 size_t data_len; 465 if (!async_data_read_receive(&data_callid, &data_len)) { 466 async_answer_0(iid, EINVAL); 467 return; 468 } 469 470 void *buffer = malloc(data_len); 471 if (buffer == NULL) { 472 async_answer_0(data_callid, ENOMEM); 473 async_answer_0(iid, ENOMEM); 474 return; 475 } 476 477 fibril_mutex_lock(&drv->driver_mutex); 478 479 size_t sent_length = str_size(drv->name); 480 if (sent_length > data_len) { 481 sent_length = data_len; 482 } 483 484 async_data_read_finalize(data_callid, drv->name, sent_length); 485 async_answer_0(iid, EOK); 486 487 fibril_mutex_unlock(&drv->driver_mutex); 488 489 free(buffer); 490 } 491 419 492 /** Function for handling connections from a client to the device manager. */ 420 493 void devman_connection_client(ipc_callid_t iid, ipc_call_t *icall) … … 441 514 break; 442 515 case DEVMAN_FUN_GET_NAME: 516 printf("devman_fun_get_name\n"); 443 517 devman_fun_get_name(callid, &call); 444 518 break; … … 457 531 case DEVMAN_FUN_SID_TO_HANDLE: 458 532 devman_fun_sid_to_handle(callid, &call); 533 break; 534 case DEVMAN_GET_DRIVERS: 535 devman_get_drivers(callid, &call); 536 break; 537 case DEVMAN_DRIVER_GET_NAME: 538 printf("devman_get_driver_name\n"); 539 devman_driver_get_name(callid, &call); 459 540 break; 460 541 default: -
uspace/srv/devman/devman.h
r5df1963 r0511549 80 80 /** Pointers to previous and next drivers in a linked list. */ 81 81 link_t drivers; 82 /** Handle */ 83 devman_handle_t handle; 82 84 83 85 /** … … 110 112 /** Fibril mutex for list of drivers. */ 111 113 fibril_mutex_t drivers_mutex; 114 /** Next free handle */ 115 devman_handle_t next_handle; 112 116 } driver_list_t; 113 117 -
uspace/srv/devman/driver.c
r5df1963 r0511549 58 58 list_initialize(&drv_list->drivers); 59 59 fibril_mutex_initialize(&drv_list->drivers_mutex); 60 drv_list->next_handle = 1; 60 61 } 61 62 … … 81 82 fibril_mutex_lock(&drivers_list->drivers_mutex); 82 83 list_prepend(&drv->drivers, &drivers_list->drivers); 84 drv->handle = drivers_list->next_handle++; 83 85 fibril_mutex_unlock(&drivers_list->drivers_mutex); 84 86 … … 299 301 } 300 302 301 /** Find device driver in the list of device drivers. 303 /** Find device driver by handle. 304 * 305 * @param drv_list The list of device drivers 306 * @param handle Driver handle 307 * @return The device driver, if it is in the list, 308 * NULL otherwise. 309 */ 310 driver_t *driver_find(driver_list_t *drv_list, devman_handle_t handle) 311 { 312 driver_t *res = NULL; 313 314 fibril_mutex_lock(&drv_list->drivers_mutex); 315 316 list_foreach(drv_list->drivers, drivers, driver_t, drv) { 317 if (drv->handle == handle) { 318 res = drv; 319 break; 320 } 321 } 322 323 fibril_mutex_unlock(&drv_list->drivers_mutex); 324 325 return res; 326 } 327 328 329 /** Find device driver by name. 302 330 * 303 331 * @param drv_list The list of device drivers. … … 306 334 * list, NULL otherwise. 307 335 */ 308 driver_t * find_driver(driver_list_t *drv_list, const char *drv_name)336 driver_t *driver_find_by_name(driver_list_t *drv_list, const char *drv_name) 309 337 { 310 338 driver_t *res = NULL; … … 669 697 } 670 698 699 /** Get list of registered drivers. */ 700 int driver_get_list(driver_list_t *driver_list, devman_handle_t *hdl_buf, 701 size_t buf_size, size_t *act_size) 702 { 703 size_t act_cnt; 704 size_t buf_cnt; 705 706 fibril_mutex_lock(&driver_list->drivers_mutex); 707 708 buf_cnt = buf_size / sizeof(devman_handle_t); 709 710 act_cnt = list_count(&driver_list->drivers); 711 *act_size = act_cnt * sizeof(devman_handle_t); 712 713 if (buf_size % sizeof(devman_handle_t) != 0) { 714 fibril_mutex_unlock(&driver_list->drivers_mutex); 715 return EINVAL; 716 } 717 718 size_t pos = 0; 719 list_foreach(driver_list->drivers, drivers, driver_t, drv) { 720 if (pos < buf_cnt) { 721 hdl_buf[pos] = drv->handle; 722 } 723 724 pos++; 725 } 726 727 fibril_mutex_unlock(&driver_list->drivers_mutex); 728 return EOK; 729 } 730 671 731 /** @} 672 732 */ -
uspace/srv/devman/driver.h
r5df1963 r0511549 56 56 extern int driver_fun_offline(dev_tree_t *, fun_node_t *); 57 57 58 extern driver_t *find_driver(driver_list_t *, const char *); 58 extern driver_t *driver_find(driver_list_t *, devman_handle_t); 59 extern driver_t *driver_find_by_name(driver_list_t *, const char *); 59 60 extern void initialize_running_driver(driver_t *, dev_tree_t *); 60 61 … … 62 63 extern void clean_driver(driver_t *); 63 64 extern void delete_driver(driver_t *); 65 extern int driver_get_list(driver_list_t *, devman_handle_t *, size_t, size_t *); 64 66 65 67 #endif -
uspace/srv/devman/drv_conn.c
r5df1963 r0511549 83 83 84 84 /* Find driver structure. */ 85 driver = find_driver(&drivers_list, drv_name);85 driver = driver_find_by_name(&drivers_list, drv_name); 86 86 if (driver == NULL) { 87 87 log_msg(LOG_DEFAULT, LVL_ERROR, "No driver named `%s' was found.", drv_name);
Note:
See TracChangeset
for help on using the changeset viewer.