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