Changes in uspace/srv/devmap/devmap.c [7e752b2:ca2a18e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r7e752b2 rca2a18e 46 46 #include <str.h> 47 47 #include <ipc/devmap.h> 48 #include <assert.h> 48 49 49 50 #define NAME "devmap" … … 61 62 link_t devices; 62 63 /** Phone asociated with this driver */ 63 ipcarg_t phone;64 sysarg_t phone; 64 65 /** Device driver name */ 65 66 char *name; … … 99 100 /** Device driver handling this device */ 100 101 devmap_driver_t *driver; 102 /** Use this interface when forwarding to driver. */ 103 sysarg_t forward_interface; 101 104 } devmap_device_t; 102 105 … … 206 209 } 207 210 208 /** Find namespace with given name. 209 * 210 * The devices_list_mutex should be already held when 211 * calling this function. 212 * 213 */ 211 /** Find namespace with given name. */ 214 212 static devmap_namespace_t *devmap_namespace_find_name(const char *name) 215 213 { 216 214 link_t *item; 215 216 assert(fibril_mutex_is_locked(&devices_list_mutex)); 217 217 218 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 218 219 devmap_namespace_t *namespace = … … 227 228 /** Find namespace with given handle. 228 229 * 229 * The devices_list_mutex should be already held when230 * calling this function.231 *232 230 * @todo: use hash table 233 231 * … … 236 234 { 237 235 link_t *item; 236 237 assert(fibril_mutex_is_locked(&devices_list_mutex)); 238 238 239 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 239 240 devmap_namespace_t *namespace = … … 246 247 } 247 248 248 /** Find device with given name. 249 * 250 * The devices_list_mutex should be already held when 251 * calling this function. 252 * 253 */ 249 /** Find device with given name. */ 254 250 static devmap_device_t *devmap_device_find_name(const char *ns_name, 255 251 const char *name) 256 252 { 257 253 link_t *item; 254 255 assert(fibril_mutex_is_locked(&devices_list_mutex)); 256 258 257 for (item = devices_list.next; item != &devices_list; item = item->next) { 259 258 devmap_device_t *device = … … 269 268 /** Find device with given handle. 270 269 * 271 * The devices_list_mutex should be already held when272 * calling this function.273 *274 270 * @todo: use hash table 275 271 * … … 278 274 { 279 275 link_t *item; 276 277 assert(fibril_mutex_is_locked(&devices_list_mutex)); 278 280 279 for (item = devices_list.next; item != &devices_list; item = item->next) { 281 280 devmap_device_t *device = … … 288 287 } 289 288 290 /** Create a namespace (if not already present) 291 * 292 * The devices_list_mutex should be already held when 293 * calling this function. 294 * 295 */ 289 /** Create a namespace (if not already present). */ 296 290 static devmap_namespace_t *devmap_namespace_create(const char *ns_name) 297 291 { 298 devmap_namespace_t *namespace = devmap_namespace_find_name(ns_name); 292 devmap_namespace_t *namespace; 293 294 assert(fibril_mutex_is_locked(&devices_list_mutex)); 295 296 namespace = devmap_namespace_find_name(ns_name); 299 297 if (namespace != NULL) 300 298 return namespace; … … 321 319 } 322 320 323 /** Destroy a namespace (if it is no longer needed) 324 * 325 * The devices_list_mutex should be already held when 326 * calling this function. 327 * 328 */ 321 /** Destroy a namespace (if it is no longer needed). */ 329 322 static void devmap_namespace_destroy(devmap_namespace_t *namespace) 330 323 { 324 assert(fibril_mutex_is_locked(&devices_list_mutex)); 325 331 326 if (namespace->refcnt == 0) { 332 327 list_remove(&(namespace->namespaces)); … … 337 332 } 338 333 339 /** Increase namespace reference count by including device 340 * 341 * The devices_list_mutex should be already held when 342 * calling this function. 343 * 344 */ 334 /** Increase namespace reference count by including device. */ 345 335 static void devmap_namespace_addref(devmap_namespace_t *namespace, 346 336 devmap_device_t *device) 347 337 { 338 assert(fibril_mutex_is_locked(&devices_list_mutex)); 339 348 340 device->namespace = namespace; 349 341 namespace->refcnt++; 350 342 } 351 343 352 /** Decrease namespace reference count 353 * 354 * The devices_list_mutex should be already held when 355 * calling this function. 356 * 357 */ 344 /** Decrease namespace reference count. */ 358 345 static void devmap_namespace_delref(devmap_namespace_t *namespace) 359 346 { 347 assert(fibril_mutex_is_locked(&devices_list_mutex)); 348 360 349 namespace->refcnt--; 361 350 devmap_namespace_destroy(namespace); 362 351 } 363 352 364 /** Unregister device and free it 365 * 366 * The devices_list_mutex should be already held when 367 * calling this function. 368 * 369 */ 353 /** Unregister device and free it. */ 370 354 static void devmap_device_unregister_core(devmap_device_t *device) 371 355 { 356 assert(fibril_mutex_is_locked(&devices_list_mutex)); 357 372 358 devmap_namespace_delref(device->namespace); 373 359 list_remove(&(device->devices)); … … 387 373 ipc_callid_t iid = async_get_call(&icall); 388 374 389 if (IPC_GET_ METHOD(icall) != DEVMAP_DRIVER_REGISTER) {390 ipc_answer_0(iid, EREFUSED);375 if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) { 376 async_answer_0(iid, EREFUSED); 391 377 return NULL; 392 378 } … … 395 381 (devmap_driver_t *) malloc(sizeof(devmap_driver_t)); 396 382 if (driver == NULL) { 397 ipc_answer_0(iid, ENOMEM);383 async_answer_0(iid, ENOMEM); 398 384 return NULL; 399 385 } … … 406 392 if (rc != EOK) { 407 393 free(driver); 408 ipc_answer_0(iid, rc);394 async_answer_0(iid, rc); 409 395 return NULL; 410 396 } … … 416 402 ipc_callid_t callid = async_get_call(&call); 417 403 418 if (IPC_GET_ METHOD(call) != IPC_M_CONNECT_TO_ME) {404 if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) { 419 405 free(driver->name); 420 406 free(driver); 421 ipc_answer_0(callid, ENOTSUP);422 ipc_answer_0(iid, ENOTSUP);407 async_answer_0(callid, ENOTSUP); 408 async_answer_0(iid, ENOTSUP); 423 409 return NULL; 424 410 } 425 411 426 412 driver->phone = IPC_GET_ARG5(call); 427 ipc_answer_0(callid, EOK);413 async_answer_0(callid, EOK); 428 414 429 415 /* … … 437 423 */ 438 424 list_initialize(&driver->devices); 439 list_initialize(&(driver->drivers)); 425 426 link_initialize(&driver->drivers); 440 427 441 428 fibril_mutex_lock(&drivers_list_mutex); … … 452 439 fibril_mutex_unlock(&drivers_list_mutex); 453 440 454 ipc_answer_0(iid, EOK);441 async_answer_0(iid, EOK); 455 442 456 443 return driver; … … 470 457 471 458 if (driver->phone != 0) 472 ipc_hangup(driver->phone);459 async_hangup(driver->phone); 473 460 474 461 /* Remove it from list of drivers */ … … 505 492 { 506 493 if (driver == NULL) { 507 ipc_answer_0(iid, EREFUSED);494 async_answer_0(iid, EREFUSED); 508 495 return; 509 496 } … … 513 500 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 514 501 if (device == NULL) { 515 ipc_answer_0(iid, ENOMEM); 516 return; 517 } 518 502 async_answer_0(iid, ENOMEM); 503 return; 504 } 505 506 /* Set the interface, if any. */ 507 device->forward_interface = IPC_GET_ARG1(*icall); 508 519 509 /* Get fqdn */ 520 510 char *fqdn; … … 523 513 if (rc != EOK) { 524 514 free(device); 525 ipc_answer_0(iid, rc);515 async_answer_0(iid, rc); 526 516 return; 527 517 } … … 531 521 free(fqdn); 532 522 free(device); 533 ipc_answer_0(iid, EINVAL);523 async_answer_0(iid, EINVAL); 534 524 return; 535 525 } … … 545 535 free(device->name); 546 536 free(device); 547 ipc_answer_0(iid, ENOMEM);548 return; 549 } 550 551 li st_initialize(&(device->devices));552 li st_initialize(&(device->driver_devices));537 async_answer_0(iid, ENOMEM); 538 return; 539 } 540 541 link_initialize(&device->devices); 542 link_initialize(&device->driver_devices); 553 543 554 544 /* Check that device is not already registered */ … … 560 550 free(device->name); 561 551 free(device); 562 ipc_answer_0(iid, EEXISTS);552 async_answer_0(iid, EEXISTS); 563 553 return; 564 554 } … … 566 556 /* Get unique device handle */ 567 557 device->handle = devmap_create_handle(); 568 558 569 559 devmap_namespace_addref(namespace, device); 570 560 device->driver = driver; … … 582 572 fibril_mutex_unlock(&devices_list_mutex); 583 573 584 ipc_answer_1(iid, EOK, device->handle);574 async_answer_1(iid, EOK, device->handle); 585 575 } 586 576 … … 613 603 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 614 604 fibril_mutex_unlock(&devices_list_mutex); 615 ipc_answer_0(callid, ENOENT); 616 return; 617 } 618 619 ipc_forward_fast(callid, dev->driver->phone, dev->handle, 620 IPC_GET_ARG3(*call), 0, IPC_FF_NONE); 605 async_answer_0(callid, ENOENT); 606 return; 607 } 608 609 if (dev->forward_interface == 0) { 610 async_forward_fast(callid, dev->driver->phone, 611 dev->handle, 0, 0, 612 IPC_FF_NONE); 613 } else { 614 async_forward_fast(callid, dev->driver->phone, 615 dev->forward_interface, dev->handle, 0, 616 IPC_FF_NONE); 617 } 621 618 622 619 fibril_mutex_unlock(&devices_list_mutex); … … 637 634 DEVMAP_NAME_MAXLEN, 0, NULL); 638 635 if (rc != EOK) { 639 ipc_answer_0(iid, rc);636 async_answer_0(iid, rc); 640 637 return; 641 638 } … … 645 642 if (!devmap_fqdn_split(fqdn, &ns_name, &name)) { 646 643 free(fqdn); 647 ipc_answer_0(iid, EINVAL);644 async_answer_0(iid, EINVAL); 648 645 return; 649 646 } … … 672 669 } 673 670 674 ipc_answer_0(iid, ENOENT);671 async_answer_0(iid, ENOENT); 675 672 free(ns_name); 676 673 free(name); … … 679 676 } 680 677 681 ipc_answer_1(iid, EOK, dev->handle);678 async_answer_1(iid, EOK, dev->handle); 682 679 683 680 fibril_mutex_unlock(&devices_list_mutex); … … 700 697 DEVMAP_NAME_MAXLEN, 0, NULL); 701 698 if (rc != EOK) { 702 ipc_answer_0(iid, rc);699 async_answer_0(iid, rc); 703 700 return; 704 701 } … … 725 722 } 726 723 727 ipc_answer_0(iid, ENOENT);724 async_answer_0(iid, ENOENT); 728 725 free(name); 729 726 fibril_mutex_unlock(&devices_list_mutex); … … 731 728 } 732 729 733 ipc_answer_1(iid, EOK, namespace->handle);730 async_answer_1(iid, EOK, namespace->handle); 734 731 735 732 fibril_mutex_unlock(&devices_list_mutex); … … 747 744 devmap_device_find_handle(IPC_GET_ARG1(*icall)); 748 745 if (dev == NULL) 749 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);746 async_answer_1(iid, EOK, DEV_HANDLE_NONE); 750 747 else 751 ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE);748 async_answer_1(iid, EOK, DEV_HANDLE_DEVICE); 752 749 } else 753 ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);750 async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE); 754 751 755 752 fibril_mutex_unlock(&devices_list_mutex); … … 759 756 { 760 757 fibril_mutex_lock(&devices_list_mutex); 761 ipc_answer_1(iid, EOK, list_count(&namespaces_list));758 async_answer_1(iid, EOK, list_count(&namespaces_list)); 762 759 fibril_mutex_unlock(&devices_list_mutex); 763 760 } … … 770 767 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 771 768 if (namespace == NULL) 772 ipc_answer_0(iid, EEXISTS);769 async_answer_0(iid, EEXISTS); 773 770 else 774 ipc_answer_1(iid, EOK, namespace->refcnt);771 async_answer_1(iid, EOK, namespace->refcnt); 775 772 776 773 fibril_mutex_unlock(&devices_list_mutex); … … 782 779 size_t size; 783 780 if (!async_data_read_receive(&callid, &size)) { 784 ipc_answer_0(callid, EREFUSED);785 ipc_answer_0(iid, EREFUSED);781 async_answer_0(callid, EREFUSED); 782 async_answer_0(iid, EREFUSED); 786 783 return; 787 784 } 788 785 789 786 if ((size % sizeof(dev_desc_t)) != 0) { 790 ipc_answer_0(callid, EINVAL);791 ipc_answer_0(iid, EINVAL);787 async_answer_0(callid, EINVAL); 788 async_answer_0(iid, EINVAL); 792 789 return; 793 790 } … … 798 795 if (count != list_count(&namespaces_list)) { 799 796 fibril_mutex_unlock(&devices_list_mutex); 800 ipc_answer_0(callid, EOVERFLOW);801 ipc_answer_0(iid, EOVERFLOW);797 async_answer_0(callid, EOVERFLOW); 798 async_answer_0(iid, EOVERFLOW); 802 799 return; 803 800 } … … 806 803 if (desc == NULL) { 807 804 fibril_mutex_unlock(&devices_list_mutex); 808 ipc_answer_0(callid, ENOMEM);809 ipc_answer_0(iid, ENOMEM);805 async_answer_0(callid, ENOMEM); 806 async_answer_0(iid, ENOMEM); 810 807 return; 811 808 } … … 823 820 } 824 821 825 ipcarg_t retval = async_data_read_finalize(callid, desc, size);822 sysarg_t retval = async_data_read_finalize(callid, desc, size); 826 823 827 824 free(desc); 828 825 fibril_mutex_unlock(&devices_list_mutex); 829 826 830 ipc_answer_0(iid, retval);827 async_answer_0(iid, retval); 831 828 } 832 829 … … 839 836 size_t size; 840 837 if (!async_data_read_receive(&callid, &size)) { 841 ipc_answer_0(callid, EREFUSED);842 ipc_answer_0(iid, EREFUSED);838 async_answer_0(callid, EREFUSED); 839 async_answer_0(iid, EREFUSED); 843 840 return; 844 841 } 845 842 846 843 if ((size % sizeof(dev_desc_t)) != 0) { 847 ipc_answer_0(callid, EINVAL);848 ipc_answer_0(iid, EINVAL);844 async_answer_0(callid, EINVAL); 845 async_answer_0(iid, EINVAL); 849 846 return; 850 847 } … … 856 853 if (namespace == NULL) { 857 854 fibril_mutex_unlock(&devices_list_mutex); 858 ipc_answer_0(callid, ENOENT);859 ipc_answer_0(iid, ENOENT);855 async_answer_0(callid, ENOENT); 856 async_answer_0(iid, ENOENT); 860 857 return; 861 858 } … … 864 861 if (count != namespace->refcnt) { 865 862 fibril_mutex_unlock(&devices_list_mutex); 866 ipc_answer_0(callid, EOVERFLOW);867 ipc_answer_0(iid, EOVERFLOW);863 async_answer_0(callid, EOVERFLOW); 864 async_answer_0(iid, EOVERFLOW); 868 865 return; 869 866 } … … 872 869 if (desc == NULL) { 873 870 fibril_mutex_unlock(&devices_list_mutex); 874 ipc_answer_0(callid, ENOMEM);875 ipc_answer_0(iid, EREFUSED);871 async_answer_0(callid, ENOMEM); 872 async_answer_0(iid, EREFUSED); 876 873 return; 877 874 } … … 890 887 } 891 888 892 ipcarg_t retval = async_data_read_finalize(callid, desc, size);889 sysarg_t retval = async_data_read_finalize(callid, desc, size); 893 890 894 891 free(desc); 895 892 fibril_mutex_unlock(&devices_list_mutex); 896 893 897 ipc_answer_0(iid, retval);894 async_answer_0(iid, retval); 898 895 } 899 896 … … 914 911 if (!fnd) { 915 912 fibril_mutex_unlock(&null_devices_mutex); 916 ipc_answer_0(iid, ENOMEM);913 async_answer_0(iid, ENOMEM); 917 914 return; 918 915 } … … 924 921 if (dev_name == NULL) { 925 922 fibril_mutex_unlock(&null_devices_mutex); 926 ipc_answer_0(iid, ENOMEM);923 async_answer_0(iid, ENOMEM); 927 924 return; 928 925 } … … 932 929 if (device == NULL) { 933 930 fibril_mutex_unlock(&null_devices_mutex); 934 ipc_answer_0(iid, ENOMEM);931 async_answer_0(iid, ENOMEM); 935 932 return; 936 933 } … … 942 939 fibril_mutex_lock(&devices_list_mutex); 943 940 fibril_mutex_unlock(&null_devices_mutex); 944 ipc_answer_0(iid, ENOMEM);945 return; 946 } 947 948 li st_initialize(&(device->devices));949 li st_initialize(&(device->driver_devices));941 async_answer_0(iid, ENOMEM); 942 return; 943 } 944 945 link_initialize(&device->devices); 946 link_initialize(&device->driver_devices); 950 947 951 948 /* Get unique device handle */ … … 964 961 fibril_mutex_unlock(&null_devices_mutex); 965 962 966 ipc_answer_1(iid, EOK, (ipcarg_t) i);963 async_answer_1(iid, EOK, (sysarg_t) i); 967 964 } 968 965 969 966 static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall) 970 967 { 971 ipcarg_t i = IPC_GET_ARG1(*icall);968 sysarg_t i = IPC_GET_ARG1(*icall); 972 969 if (i >= NULL_DEVICES) { 973 ipc_answer_0(iid, ELIMIT);970 async_answer_0(iid, ELIMIT); 974 971 return; 975 972 } … … 979 976 if (null_devices[i] == NULL) { 980 977 fibril_mutex_unlock(&null_devices_mutex); 981 ipc_answer_0(iid, ENOENT);978 async_answer_0(iid, ENOENT); 982 979 return; 983 980 } … … 990 987 991 988 fibril_mutex_unlock(&null_devices_mutex); 992 ipc_answer_0(iid, EOK);989 async_answer_0(iid, EOK); 993 990 } 994 991 … … 1016 1013 { 1017 1014 /* Accept connection */ 1018 ipc_answer_0(iid, EOK);1015 async_answer_0(iid, EOK); 1019 1016 1020 1017 devmap_driver_t *driver = devmap_driver_register(); … … 1027 1024 ipc_callid_t callid = async_get_call(&call); 1028 1025 1029 switch (IPC_GET_ METHOD(call)) {1026 switch (IPC_GET_IMETHOD(call)) { 1030 1027 case IPC_M_PHONE_HUNGUP: 1031 1028 cont = false; … … 1033 1030 case DEVMAP_DRIVER_UNREGISTER: 1034 1031 if (NULL == driver) 1035 ipc_answer_0(callid, ENOENT);1032 async_answer_0(callid, ENOENT); 1036 1033 else 1037 ipc_answer_0(callid, EOK);1034 async_answer_0(callid, EOK); 1038 1035 break; 1039 1036 case DEVMAP_DEVICE_REGISTER: … … 1052 1049 break; 1053 1050 default: 1054 ipc_answer_0(callid, ENOENT);1051 async_answer_0(callid, ENOENT); 1055 1052 } 1056 1053 } … … 1071 1068 { 1072 1069 /* Accept connection */ 1073 ipc_answer_0(iid, EOK);1070 async_answer_0(iid, EOK); 1074 1071 1075 1072 bool cont = true; … … 1078 1075 ipc_callid_t callid = async_get_call(&call); 1079 1076 1080 switch (IPC_GET_ METHOD(call)) {1077 switch (IPC_GET_IMETHOD(call)) { 1081 1078 case IPC_M_PHONE_HUNGUP: 1082 1079 cont = false; … … 1110 1107 break; 1111 1108 default: 1112 ipc_answer_0(callid, ENOENT);1109 async_answer_0(callid, ENOENT); 1113 1110 } 1114 1111 } … … 1121 1118 { 1122 1119 /* Select interface */ 1123 switch (( ipcarg_t) (IPC_GET_ARG1(*icall))) {1120 switch ((sysarg_t) (IPC_GET_ARG1(*icall))) { 1124 1121 case DEVMAP_DRIVER: 1125 1122 devmap_connection_driver(iid, icall); … … 1134 1131 default: 1135 1132 /* No such interface */ 1136 ipc_answer_0(iid, ENOENT);1133 async_answer_0(iid, ENOENT); 1137 1134 } 1138 1135 } … … 1154 1151 1155 1152 /* Register device mapper at naming service */ 1156 ipcarg_t phonead; 1157 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, &phonead) != 0) 1153 if (service_register(SERVICE_DEVMAP) != EOK) 1158 1154 return -1; 1159 1155
Note:
See TracChangeset
for help on using the changeset viewer.