Changes in uspace/srv/devmap/devmap.c [01b87dc5:4ae90f9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r01b87dc5 r4ae90f9 123 123 static devmap_handle_t last_handle = 0; 124 124 static devmap_device_t *null_devices[NULL_DEVICES]; 125 126 /* 127 * Dummy list for null devices. This is necessary so that null devices can 128 * be used just as any other devices, e.g. in devmap_device_unregister_core(). 129 */ 130 static LIST_INITIALIZE(dummy_null_driver_devices); 125 131 126 132 static devmap_handle_t devmap_create_handle(void) … … 374 380 375 381 if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) { 376 ipc_answer_0(iid, EREFUSED);382 async_answer_0(iid, EREFUSED); 377 383 return NULL; 378 384 } … … 381 387 (devmap_driver_t *) malloc(sizeof(devmap_driver_t)); 382 388 if (driver == NULL) { 383 ipc_answer_0(iid, ENOMEM);389 async_answer_0(iid, ENOMEM); 384 390 return NULL; 385 391 } … … 392 398 if (rc != EOK) { 393 399 free(driver); 394 ipc_answer_0(iid, rc);400 async_answer_0(iid, rc); 395 401 return NULL; 396 402 } … … 405 411 free(driver->name); 406 412 free(driver); 407 ipc_answer_0(callid, ENOTSUP);408 ipc_answer_0(iid, ENOTSUP);413 async_answer_0(callid, ENOTSUP); 414 async_answer_0(iid, ENOTSUP); 409 415 return NULL; 410 416 } 411 417 412 418 driver->phone = IPC_GET_ARG5(call); 413 ipc_answer_0(callid, EOK);419 async_answer_0(callid, EOK); 414 420 415 421 /* … … 423 429 */ 424 430 list_initialize(&driver->devices); 425 list_initialize(&(driver->drivers)); 431 432 link_initialize(&driver->drivers); 426 433 427 434 fibril_mutex_lock(&drivers_list_mutex); … … 438 445 fibril_mutex_unlock(&drivers_list_mutex); 439 446 440 ipc_answer_0(iid, EOK);447 async_answer_0(iid, EOK); 441 448 442 449 return driver; … … 456 463 457 464 if (driver->phone != 0) 458 ipc_hangup(driver->phone);465 async_hangup(driver->phone); 459 466 460 467 /* Remove it from list of drivers */ … … 491 498 { 492 499 if (driver == NULL) { 493 ipc_answer_0(iid, EREFUSED);500 async_answer_0(iid, EREFUSED); 494 501 return; 495 502 } … … 499 506 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 500 507 if (device == NULL) { 501 ipc_answer_0(iid, ENOMEM);508 async_answer_0(iid, ENOMEM); 502 509 return; 503 510 } … … 512 519 if (rc != EOK) { 513 520 free(device); 514 ipc_answer_0(iid, rc);521 async_answer_0(iid, rc); 515 522 return; 516 523 } … … 520 527 free(fqdn); 521 528 free(device); 522 ipc_answer_0(iid, EINVAL);529 async_answer_0(iid, EINVAL); 523 530 return; 524 531 } … … 534 541 free(device->name); 535 542 free(device); 536 ipc_answer_0(iid, ENOMEM);537 return; 538 } 539 540 li st_initialize(&(device->devices));541 li st_initialize(&(device->driver_devices));543 async_answer_0(iid, ENOMEM); 544 return; 545 } 546 547 link_initialize(&device->devices); 548 link_initialize(&device->driver_devices); 542 549 543 550 /* Check that device is not already registered */ 544 551 if (devmap_device_find_name(namespace->name, device->name) != NULL) { 545 552 printf("%s: Device '%s/%s' already registered\n", NAME, 546 device->namespace->name, device->name);553 namespace->name, device->name); 547 554 devmap_namespace_destroy(namespace); 548 555 fibril_mutex_unlock(&devices_list_mutex); 549 556 free(device->name); 550 557 free(device); 551 ipc_answer_0(iid, EEXISTS);558 async_answer_0(iid, EEXISTS); 552 559 return; 553 560 } … … 571 578 fibril_mutex_unlock(&devices_list_mutex); 572 579 573 ipc_answer_1(iid, EOK, device->handle);580 async_answer_1(iid, EOK, device->handle); 574 581 } 575 582 … … 602 609 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 603 610 fibril_mutex_unlock(&devices_list_mutex); 604 ipc_answer_0(callid, ENOENT);611 async_answer_0(callid, ENOENT); 605 612 return; 606 613 } 607 614 608 615 if (dev->forward_interface == 0) { 609 ipc_forward_fast(callid, dev->driver->phone,616 async_forward_fast(callid, dev->driver->phone, 610 617 dev->handle, 0, 0, 611 618 IPC_FF_NONE); 612 619 } else { 613 ipc_forward_fast(callid, dev->driver->phone,620 async_forward_fast(callid, dev->driver->phone, 614 621 dev->forward_interface, dev->handle, 0, 615 622 IPC_FF_NONE); … … 633 640 DEVMAP_NAME_MAXLEN, 0, NULL); 634 641 if (rc != EOK) { 635 ipc_answer_0(iid, rc);642 async_answer_0(iid, rc); 636 643 return; 637 644 } … … 641 648 if (!devmap_fqdn_split(fqdn, &ns_name, &name)) { 642 649 free(fqdn); 643 ipc_answer_0(iid, EINVAL);650 async_answer_0(iid, EINVAL); 644 651 return; 645 652 } … … 668 675 } 669 676 670 ipc_answer_0(iid, ENOENT);677 async_answer_0(iid, ENOENT); 671 678 free(ns_name); 672 679 free(name); … … 675 682 } 676 683 677 ipc_answer_1(iid, EOK, dev->handle);684 async_answer_1(iid, EOK, dev->handle); 678 685 679 686 fibril_mutex_unlock(&devices_list_mutex); … … 696 703 DEVMAP_NAME_MAXLEN, 0, NULL); 697 704 if (rc != EOK) { 698 ipc_answer_0(iid, rc);705 async_answer_0(iid, rc); 699 706 return; 700 707 } … … 721 728 } 722 729 723 ipc_answer_0(iid, ENOENT);730 async_answer_0(iid, ENOENT); 724 731 free(name); 725 732 fibril_mutex_unlock(&devices_list_mutex); … … 727 734 } 728 735 729 ipc_answer_1(iid, EOK, namespace->handle);736 async_answer_1(iid, EOK, namespace->handle); 730 737 731 738 fibril_mutex_unlock(&devices_list_mutex); … … 743 750 devmap_device_find_handle(IPC_GET_ARG1(*icall)); 744 751 if (dev == NULL) 745 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);752 async_answer_1(iid, EOK, DEV_HANDLE_NONE); 746 753 else 747 ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE);754 async_answer_1(iid, EOK, DEV_HANDLE_DEVICE); 748 755 } else 749 ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);756 async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE); 750 757 751 758 fibril_mutex_unlock(&devices_list_mutex); … … 755 762 { 756 763 fibril_mutex_lock(&devices_list_mutex); 757 ipc_answer_1(iid, EOK, list_count(&namespaces_list));764 async_answer_1(iid, EOK, list_count(&namespaces_list)); 758 765 fibril_mutex_unlock(&devices_list_mutex); 759 766 } … … 766 773 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 767 774 if (namespace == NULL) 768 ipc_answer_0(iid, EEXISTS);775 async_answer_0(iid, EEXISTS); 769 776 else 770 ipc_answer_1(iid, EOK, namespace->refcnt);777 async_answer_1(iid, EOK, namespace->refcnt); 771 778 772 779 fibril_mutex_unlock(&devices_list_mutex); … … 778 785 size_t size; 779 786 if (!async_data_read_receive(&callid, &size)) { 780 ipc_answer_0(callid, EREFUSED);781 ipc_answer_0(iid, EREFUSED);787 async_answer_0(callid, EREFUSED); 788 async_answer_0(iid, EREFUSED); 782 789 return; 783 790 } 784 791 785 792 if ((size % sizeof(dev_desc_t)) != 0) { 786 ipc_answer_0(callid, EINVAL);787 ipc_answer_0(iid, EINVAL);793 async_answer_0(callid, EINVAL); 794 async_answer_0(iid, EINVAL); 788 795 return; 789 796 } … … 794 801 if (count != list_count(&namespaces_list)) { 795 802 fibril_mutex_unlock(&devices_list_mutex); 796 ipc_answer_0(callid, EOVERFLOW);797 ipc_answer_0(iid, EOVERFLOW);803 async_answer_0(callid, EOVERFLOW); 804 async_answer_0(iid, EOVERFLOW); 798 805 return; 799 806 } … … 802 809 if (desc == NULL) { 803 810 fibril_mutex_unlock(&devices_list_mutex); 804 ipc_answer_0(callid, ENOMEM);805 ipc_answer_0(iid, ENOMEM);811 async_answer_0(callid, ENOMEM); 812 async_answer_0(iid, ENOMEM); 806 813 return; 807 814 } … … 824 831 fibril_mutex_unlock(&devices_list_mutex); 825 832 826 ipc_answer_0(iid, retval);833 async_answer_0(iid, retval); 827 834 } 828 835 … … 835 842 size_t size; 836 843 if (!async_data_read_receive(&callid, &size)) { 837 ipc_answer_0(callid, EREFUSED);838 ipc_answer_0(iid, EREFUSED);844 async_answer_0(callid, EREFUSED); 845 async_answer_0(iid, EREFUSED); 839 846 return; 840 847 } 841 848 842 849 if ((size % sizeof(dev_desc_t)) != 0) { 843 ipc_answer_0(callid, EINVAL);844 ipc_answer_0(iid, EINVAL);850 async_answer_0(callid, EINVAL); 851 async_answer_0(iid, EINVAL); 845 852 return; 846 853 } … … 852 859 if (namespace == NULL) { 853 860 fibril_mutex_unlock(&devices_list_mutex); 854 ipc_answer_0(callid, ENOENT);855 ipc_answer_0(iid, ENOENT);861 async_answer_0(callid, ENOENT); 862 async_answer_0(iid, ENOENT); 856 863 return; 857 864 } … … 860 867 if (count != namespace->refcnt) { 861 868 fibril_mutex_unlock(&devices_list_mutex); 862 ipc_answer_0(callid, EOVERFLOW);863 ipc_answer_0(iid, EOVERFLOW);869 async_answer_0(callid, EOVERFLOW); 870 async_answer_0(iid, EOVERFLOW); 864 871 return; 865 872 } … … 868 875 if (desc == NULL) { 869 876 fibril_mutex_unlock(&devices_list_mutex); 870 ipc_answer_0(callid, ENOMEM);871 ipc_answer_0(iid, EREFUSED);877 async_answer_0(callid, ENOMEM); 878 async_answer_0(iid, EREFUSED); 872 879 return; 873 880 } … … 891 898 fibril_mutex_unlock(&devices_list_mutex); 892 899 893 ipc_answer_0(iid, retval);900 async_answer_0(iid, retval); 894 901 } 895 902 … … 910 917 if (!fnd) { 911 918 fibril_mutex_unlock(&null_devices_mutex); 912 ipc_answer_0(iid, ENOMEM);919 async_answer_0(iid, ENOMEM); 913 920 return; 914 921 } … … 920 927 if (dev_name == NULL) { 921 928 fibril_mutex_unlock(&null_devices_mutex); 922 ipc_answer_0(iid, ENOMEM);929 async_answer_0(iid, ENOMEM); 923 930 return; 924 931 } … … 928 935 if (device == NULL) { 929 936 fibril_mutex_unlock(&null_devices_mutex); 930 ipc_answer_0(iid, ENOMEM);937 async_answer_0(iid, ENOMEM); 931 938 return; 932 939 } … … 938 945 fibril_mutex_lock(&devices_list_mutex); 939 946 fibril_mutex_unlock(&null_devices_mutex); 940 ipc_answer_0(iid, ENOMEM);941 return; 942 } 943 944 li st_initialize(&(device->devices));945 li st_initialize(&(device->driver_devices));947 async_answer_0(iid, ENOMEM); 948 return; 949 } 950 951 link_initialize(&device->devices); 952 link_initialize(&device->driver_devices); 946 953 947 954 /* Get unique device handle */ … … 952 959 device->name = dev_name; 953 960 954 /* Insert device into list of all devices 955 and into null devices array */ 961 /* 962 * Insert device into list of all devices and into null devices array. 963 * Insert device into a dummy list of null driver's devices so that it 964 * can be safely removed later. 965 */ 956 966 list_append(&device->devices, &devices_list); 967 list_append(&device->driver_devices, &dummy_null_driver_devices); 957 968 null_devices[i] = device; 958 969 … … 960 971 fibril_mutex_unlock(&null_devices_mutex); 961 972 962 ipc_answer_1(iid, EOK, (sysarg_t) i);973 async_answer_1(iid, EOK, (sysarg_t) i); 963 974 } 964 975 … … 967 978 sysarg_t i = IPC_GET_ARG1(*icall); 968 979 if (i >= NULL_DEVICES) { 969 ipc_answer_0(iid, ELIMIT);980 async_answer_0(iid, ELIMIT); 970 981 return; 971 982 } … … 975 986 if (null_devices[i] == NULL) { 976 987 fibril_mutex_unlock(&null_devices_mutex); 977 ipc_answer_0(iid, ENOENT);988 async_answer_0(iid, ENOENT); 978 989 return; 979 990 } … … 986 997 987 998 fibril_mutex_unlock(&null_devices_mutex); 988 ipc_answer_0(iid, EOK);999 async_answer_0(iid, EOK); 989 1000 } 990 1001 … … 1012 1023 { 1013 1024 /* Accept connection */ 1014 ipc_answer_0(iid, EOK);1025 async_answer_0(iid, EOK); 1015 1026 1016 1027 devmap_driver_t *driver = devmap_driver_register(); … … 1029 1040 case DEVMAP_DRIVER_UNREGISTER: 1030 1041 if (NULL == driver) 1031 ipc_answer_0(callid, ENOENT);1042 async_answer_0(callid, ENOENT); 1032 1043 else 1033 ipc_answer_0(callid, EOK);1044 async_answer_0(callid, EOK); 1034 1045 break; 1035 1046 case DEVMAP_DEVICE_REGISTER: … … 1048 1059 break; 1049 1060 default: 1050 ipc_answer_0(callid, ENOENT);1061 async_answer_0(callid, ENOENT); 1051 1062 } 1052 1063 } … … 1067 1078 { 1068 1079 /* Accept connection */ 1069 ipc_answer_0(iid, EOK);1080 async_answer_0(iid, EOK); 1070 1081 1071 1082 bool cont = true; … … 1106 1117 break; 1107 1118 default: 1108 ipc_answer_0(callid, ENOENT);1119 async_answer_0(callid, ENOENT); 1109 1120 } 1110 1121 } … … 1130 1141 default: 1131 1142 /* No such interface */ 1132 ipc_answer_0(iid, ENOENT);1143 async_answer_0(iid, ENOENT); 1133 1144 } 1134 1145 } … … 1150 1161 1151 1162 /* Register device mapper at naming service */ 1152 sysarg_t phonead; 1153 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, &phonead) != 0) 1163 if (service_register(SERVICE_DEVMAP) != EOK) 1154 1164 return -1; 1155 1165
Note:
See TracChangeset
for help on using the changeset viewer.