Changeset 4c9b28a in mainline
- Timestamp:
- 2013-09-11T17:32:45Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5759975a
- Parents:
- 1db5669
- Location:
- uspace
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/devctl/devctl.c
r1db5669 r4c9b28a 35 35 #include <devman.h> 36 36 #include <errno.h> 37 #include <stdbool.h> 37 38 #include <stdio.h> 38 39 #include <stdlib.h> … … 44 45 #define MAX_NAME_LENGTH 1024 45 46 46 char name[MAX_NAME_LENGTH]; 47 char drv_name[MAX_NAME_LENGTH]; 47 static char name[MAX_NAME_LENGTH]; 48 static char drv_name[MAX_NAME_LENGTH]; 49 static bool verbose = false; 48 50 49 51 static const char *drv_state_str(driver_state_t state) … … 73 75 devman_handle_t *cfuns; 74 76 size_t count, i; 77 unsigned int score; 75 78 int rc; 76 79 int j; … … 94 97 else 95 98 printf("%s : %s\n", name, drv_name); 99 100 if (verbose) { 101 for (i = 0; true; i++) { 102 rc = devman_fun_get_match_id(funh, i, name, MAX_NAME_LENGTH, 103 &score); 104 if (rc != EOK) 105 break; 106 107 for (j = 0; j < lvl; j++) 108 printf(" "); 109 110 printf(" %u %s\n", score, name); 111 } 112 } 96 113 97 114 rc = devman_fun_get_child(funh, &devh); … … 226 243 driver_state_t state; 227 244 const char *sstate; 245 unsigned int score; 228 246 size_t ndevs; 229 247 size_t i; … … 252 270 printf("Driver: %s\n", drv_name); 253 271 printf("State: %s\n", sstate); 272 254 273 printf("Attached devices:\n"); 255 274 … … 263 282 goto error; 264 283 printf("\t%s\n", name); 284 } 285 286 printf("Match IDs:\n"); 287 288 for (i = 0; true; i++) { 289 rc = devman_driver_get_match_id(drvh, i, name, MAX_NAME_LENGTH, 290 &score); 291 if (rc != EOK) 292 break; 293 294 printf("\t%u %s\n", score, name); 265 295 } 266 296 … … 306 336 int rc; 307 337 308 if (argc == 1) { 338 if (argc == 1 || argv[1][0] == '-') { 339 if (argc > 1) { 340 if (str_cmp(argv[1], "-v") == 0) { 341 verbose = true; 342 } else { 343 printf(NAME ": Invalid argument '%s'\n", argv[1]); 344 print_syntax(); 345 return 1; 346 } 347 } 309 348 rc = fun_tree_print(); 310 349 if (rc != EOK) -
uspace/lib/c/generic/devman.c
r1db5669 r4c9b28a 1 1 /* 2 2 * Copyright (c) 2007 Josef Cejka 3 * Copyright (c) 201 1Jiri Svoboda3 * Copyright (c) 2013 Jiri Svoboda 4 4 * Copyright (c) 2010 Lenka Trochtova 5 5 * All rights reserved. … … 401 401 } 402 402 403 static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, char *buf,404 s ize_t buf_size)403 static int devman_get_str_internal(sysarg_t method, sysarg_t arg1, 404 sysarg_t arg2, sysarg_t *r1, char *buf, size_t buf_size) 405 405 { 406 406 async_exch_t *exch; … … 412 412 413 413 ipc_call_t answer; 414 aid_t req = async_send_ 1(exch, method, arg1, &answer);414 aid_t req = async_send_2(exch, method, arg1, arg2, &answer); 415 415 aid_t dreq = async_data_read(exch, buf, buf_size - 1, &dreply); 416 416 async_wait_for(dreq, &dretval); … … 430 430 } 431 431 432 if (r1 != NULL) 433 *r1 = IPC_GET_ARG1(answer); 432 434 act_size = IPC_GET_ARG2(dreply); 433 435 assert(act_size <= buf_size - 1); … … 439 441 int devman_fun_get_path(devman_handle_t handle, char *buf, size_t buf_size) 440 442 { 441 return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, buf, 442 buf_size); 443 return devman_get_str_internal(DEVMAN_FUN_GET_PATH, handle, 0, NULL, 444 buf, buf_size); 445 } 446 447 int devman_fun_get_match_id(devman_handle_t handle, size_t index, char *buf, 448 size_t buf_size, unsigned int *rscore) 449 { 450 int rc; 451 sysarg_t score = 0; 452 453 rc = devman_get_str_internal(DEVMAN_FUN_GET_MATCH_ID, handle, index, 454 &score, buf, buf_size); 455 if (rc != EOK) 456 return rc; 457 458 *rscore = score; 459 return rc; 443 460 } 444 461 445 462 int devman_fun_get_name(devman_handle_t handle, char *buf, size_t buf_size) 446 463 { 447 return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, buf,448 buf _size);464 return devman_get_str_internal(DEVMAN_FUN_GET_NAME, handle, 0, NULL, 465 buf, buf_size); 449 466 } 450 467 451 468 int devman_fun_get_driver_name(devman_handle_t handle, char *buf, size_t buf_size) 452 469 { 453 return devman_get_str_internal(DEVMAN_FUN_GET_DRIVER_NAME, handle, buf,454 buf_size);470 return devman_get_str_internal(DEVMAN_FUN_GET_DRIVER_NAME, handle, 0, 471 NULL, buf, buf_size); 455 472 } 456 473 … … 653 670 } 654 671 672 int devman_driver_get_match_id(devman_handle_t handle, size_t index, char *buf, 673 size_t buf_size, unsigned int *rscore) 674 { 675 int rc; 676 sysarg_t score = 0; 677 678 rc = devman_get_str_internal(DEVMAN_DRIVER_GET_MATCH_ID, handle, index, 679 &score, buf, buf_size); 680 if (rc != EOK) 681 return rc; 682 683 *rscore = score; 684 return rc; 685 } 686 655 687 int devman_driver_get_name(devman_handle_t handle, char *buf, size_t buf_size) 656 688 { 657 return devman_get_str_internal(DEVMAN_DRIVER_GET_NAME, handle, buf,658 buf _size);689 return devman_get_str_internal(DEVMAN_DRIVER_GET_NAME, handle, 0, NULL, 690 buf, buf_size); 659 691 } 660 692 -
uspace/lib/c/include/devman.h
r1db5669 r4c9b28a 64 64 extern int devman_dev_get_functions(devman_handle_t, devman_handle_t **, 65 65 size_t *); 66 extern int devman_fun_get_match_id(devman_handle_t, size_t, char *, size_t, 67 unsigned int *); 66 68 extern int devman_fun_get_name(devman_handle_t, char *, size_t); 67 69 extern int devman_fun_get_driver_name(devman_handle_t, char *, size_t); … … 76 78 size_t *); 77 79 extern int devman_driver_get_handle(const char *, devman_handle_t *); 80 extern int devman_driver_get_match_id(devman_handle_t, size_t, char *, size_t, 81 unsigned int *); 78 82 extern int devman_driver_get_name(devman_handle_t, char *, size_t); 79 83 extern int devman_driver_get_state(devman_handle_t, driver_state_t *); -
uspace/lib/c/include/ipc/devman.h
r1db5669 r4c9b28a 171 171 DEVMAN_DEV_GET_PARENT, 172 172 DEVMAN_FUN_GET_CHILD, 173 DEVMAN_FUN_GET_MATCH_ID, 173 174 DEVMAN_FUN_GET_NAME, 174 175 DEVMAN_FUN_GET_DRIVER_NAME, … … 180 181 DEVMAN_DRIVER_GET_DEVICES, 181 182 DEVMAN_DRIVER_GET_HANDLE, 183 DEVMAN_DRIVER_GET_MATCH_ID, 182 184 DEVMAN_DRIVER_GET_NAME, 183 185 DEVMAN_DRIVER_GET_STATE, -
uspace/srv/devman/client_conn.c
r1db5669 r4c9b28a 99 99 } 100 100 101 /** Get device match ID. */ 102 static void devman_fun_get_match_id(ipc_callid_t iid, ipc_call_t *icall) 103 { 104 devman_handle_t handle = IPC_GET_ARG1(*icall); 105 size_t index = IPC_GET_ARG2(*icall); 106 void *buffer = NULL; 107 108 fun_node_t *fun = find_fun_node(&device_tree, handle); 109 if (fun == NULL) { 110 async_answer_0(iid, ENOMEM); 111 return; 112 } 113 114 ipc_callid_t data_callid; 115 size_t data_len; 116 if (!async_data_read_receive(&data_callid, &data_len)) { 117 async_answer_0(iid, EINVAL); 118 fun_del_ref(fun); 119 return; 120 } 121 122 buffer = malloc(data_len); 123 if (buffer == NULL) { 124 async_answer_0(data_callid, ENOMEM); 125 async_answer_0(iid, ENOMEM); 126 fun_del_ref(fun); 127 return; 128 } 129 130 fibril_rwlock_read_lock(&device_tree.rwlock); 131 132 /* Check function state */ 133 if (fun->state == FUN_REMOVED) 134 goto error; 135 136 link_t *link = list_nth(&fun->match_ids.ids, index); 137 if (link == NULL) 138 goto error; 139 140 match_id_t *mid = list_get_instance(link, match_id_t, link); 141 142 size_t sent_length = str_size(mid->id); 143 if (sent_length > data_len) { 144 sent_length = data_len; 145 } 146 147 async_data_read_finalize(data_callid, mid->id, sent_length); 148 async_answer_1(iid, EOK, mid->score); 149 150 fibril_rwlock_read_unlock(&device_tree.rwlock); 151 fun_del_ref(fun); 152 free(buffer); 153 154 return; 155 error: 156 fibril_rwlock_read_unlock(&device_tree.rwlock); 157 free(buffer); 158 159 async_answer_0(data_callid, ENOENT); 160 async_answer_0(iid, ENOENT); 161 fun_del_ref(fun); 162 } 163 101 164 /** Get device name. */ 102 165 static void devman_fun_get_name(ipc_callid_t iid, ipc_call_t *icall) … … 539 602 } 540 603 604 /** Get driver match ID. */ 605 static void devman_driver_get_match_id(ipc_callid_t iid, ipc_call_t *icall) 606 { 607 devman_handle_t handle = IPC_GET_ARG1(*icall); 608 size_t index = IPC_GET_ARG2(*icall); 609 610 driver_t *drv = driver_find(&drivers_list, handle); 611 if (drv == NULL) { 612 async_answer_0(iid, ENOMEM); 613 return; 614 } 615 616 ipc_callid_t data_callid; 617 size_t data_len; 618 if (!async_data_read_receive(&data_callid, &data_len)) { 619 async_answer_0(iid, EINVAL); 620 return; 621 } 622 623 void *buffer = malloc(data_len); 624 if (buffer == NULL) { 625 async_answer_0(data_callid, ENOMEM); 626 async_answer_0(iid, ENOMEM); 627 return; 628 } 629 630 fibril_mutex_lock(&drv->driver_mutex); 631 link_t *link = list_nth(&drv->match_ids.ids, index); 632 if (link == NULL) { 633 fibril_mutex_unlock(&drv->driver_mutex); 634 async_answer_0(data_callid, ENOMEM); 635 async_answer_0(iid, ENOMEM); 636 return; 637 } 638 639 match_id_t *mid = list_get_instance(link, match_id_t, link); 640 641 size_t sent_length = str_size(mid->id); 642 if (sent_length > data_len) { 643 sent_length = data_len; 644 } 645 646 async_data_read_finalize(data_callid, mid->id, sent_length); 647 async_answer_1(iid, EOK, mid->score); 648 649 fibril_mutex_unlock(&drv->driver_mutex); 650 651 free(buffer); 652 } 653 541 654 /** Get driver name. */ 542 655 static void devman_driver_get_name(ipc_callid_t iid, ipc_call_t *icall) … … 638 751 devman_fun_get_child(callid, &call); 639 752 break; 753 case DEVMAN_FUN_GET_MATCH_ID: 754 devman_fun_get_match_id(callid, &call); 755 break; 640 756 case DEVMAN_FUN_GET_NAME: 641 757 devman_fun_get_name(callid, &call); … … 664 780 case DEVMAN_DRIVER_GET_HANDLE: 665 781 devman_driver_get_handle(callid, &call); 782 break; 783 case DEVMAN_DRIVER_GET_MATCH_ID: 784 devman_driver_get_match_id(callid, &call); 666 785 break; 667 786 case DEVMAN_DRIVER_GET_NAME:
Note:
See TracChangeset
for help on using the changeset viewer.