Changes in uspace/srv/devmap/devmap.c [63e0bdd:47a7174f] in mainline
- File:
-
- 1 edited
-
uspace/srv/devmap/devmap.c (modified) (61 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devmap/devmap.c
r63e0bdd r47a7174f 46 46 #include <str.h> 47 47 #include <ipc/devmap.h> 48 #include <assert.h>49 48 50 49 #define NAME "devmap" … … 123 122 static devmap_handle_t last_handle = 0; 124 123 static devmap_device_t *null_devices[NULL_DEVICES]; 125 126 /*127 * Dummy list for null devices. This is necessary so that null devices can128 * be used just as any other devices, e.g. in devmap_device_unregister_core().129 */130 static LIST_INITIALIZE(dummy_null_driver_devices);131 124 132 125 static devmap_handle_t devmap_create_handle(void) … … 215 208 } 216 209 217 /** Find namespace with given name. */ 210 /** Find namespace with given name. 211 * 212 * The devices_list_mutex should be already held when 213 * calling this function. 214 * 215 */ 218 216 static devmap_namespace_t *devmap_namespace_find_name(const char *name) 219 217 { 220 218 link_t *item; 221 222 assert(fibril_mutex_is_locked(&devices_list_mutex));223 224 219 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 225 220 devmap_namespace_t *namespace = … … 234 229 /** Find namespace with given handle. 235 230 * 231 * The devices_list_mutex should be already held when 232 * calling this function. 233 * 236 234 * @todo: use hash table 237 235 * … … 240 238 { 241 239 link_t *item; 242 243 assert(fibril_mutex_is_locked(&devices_list_mutex));244 245 240 for (item = namespaces_list.next; item != &namespaces_list; item = item->next) { 246 241 devmap_namespace_t *namespace = … … 253 248 } 254 249 255 /** Find device with given name. */ 250 /** Find device with given name. 251 * 252 * The devices_list_mutex should be already held when 253 * calling this function. 254 * 255 */ 256 256 static devmap_device_t *devmap_device_find_name(const char *ns_name, 257 257 const char *name) 258 258 { 259 259 link_t *item; 260 261 assert(fibril_mutex_is_locked(&devices_list_mutex));262 263 260 for (item = devices_list.next; item != &devices_list; item = item->next) { 264 261 devmap_device_t *device = … … 274 271 /** Find device with given handle. 275 272 * 273 * The devices_list_mutex should be already held when 274 * calling this function. 275 * 276 276 * @todo: use hash table 277 277 * … … 280 280 { 281 281 link_t *item; 282 283 assert(fibril_mutex_is_locked(&devices_list_mutex));284 285 282 for (item = devices_list.next; item != &devices_list; item = item->next) { 286 283 devmap_device_t *device = … … 293 290 } 294 291 295 /** Create a namespace (if not already present). */ 292 /** Create a namespace (if not already present) 293 * 294 * The devices_list_mutex should be already held when 295 * calling this function. 296 * 297 */ 296 298 static devmap_namespace_t *devmap_namespace_create(const char *ns_name) 297 299 { 298 devmap_namespace_t *namespace; 299 300 assert(fibril_mutex_is_locked(&devices_list_mutex)); 301 302 namespace = devmap_namespace_find_name(ns_name); 300 devmap_namespace_t *namespace = devmap_namespace_find_name(ns_name); 303 301 if (namespace != NULL) 304 302 return namespace; … … 325 323 } 326 324 327 /** Destroy a namespace (if it is no longer needed). */ 325 /** Destroy a namespace (if it is no longer needed) 326 * 327 * The devices_list_mutex should be already held when 328 * calling this function. 329 * 330 */ 328 331 static void devmap_namespace_destroy(devmap_namespace_t *namespace) 329 332 { 330 assert(fibril_mutex_is_locked(&devices_list_mutex));331 332 333 if (namespace->refcnt == 0) { 333 334 list_remove(&(namespace->namespaces)); … … 338 339 } 339 340 340 /** Increase namespace reference count by including device. */ 341 /** Increase namespace reference count by including device 342 * 343 * The devices_list_mutex should be already held when 344 * calling this function. 345 * 346 */ 341 347 static void devmap_namespace_addref(devmap_namespace_t *namespace, 342 348 devmap_device_t *device) 343 349 { 344 assert(fibril_mutex_is_locked(&devices_list_mutex));345 346 350 device->namespace = namespace; 347 351 namespace->refcnt++; 348 352 } 349 353 350 /** Decrease namespace reference count. */ 354 /** Decrease namespace reference count 355 * 356 * The devices_list_mutex should be already held when 357 * calling this function. 358 * 359 */ 351 360 static void devmap_namespace_delref(devmap_namespace_t *namespace) 352 361 { 353 assert(fibril_mutex_is_locked(&devices_list_mutex));354 355 362 namespace->refcnt--; 356 363 devmap_namespace_destroy(namespace); 357 364 } 358 365 359 /** Unregister device and free it. */ 366 /** Unregister device and free it 367 * 368 * The devices_list_mutex should be already held when 369 * calling this function. 370 * 371 */ 360 372 static void devmap_device_unregister_core(devmap_device_t *device) 361 373 { 362 assert(fibril_mutex_is_locked(&devices_list_mutex));363 364 374 devmap_namespace_delref(device->namespace); 365 375 list_remove(&(device->devices)); … … 380 390 381 391 if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) { 382 async_answer_0(iid, EREFUSED);392 ipc_answer_0(iid, EREFUSED); 383 393 return NULL; 384 394 } … … 387 397 (devmap_driver_t *) malloc(sizeof(devmap_driver_t)); 388 398 if (driver == NULL) { 389 async_answer_0(iid, ENOMEM);399 ipc_answer_0(iid, ENOMEM); 390 400 return NULL; 391 401 } … … 398 408 if (rc != EOK) { 399 409 free(driver); 400 async_answer_0(iid, rc);410 ipc_answer_0(iid, rc); 401 411 return NULL; 402 412 } … … 411 421 free(driver->name); 412 422 free(driver); 413 async_answer_0(callid, ENOTSUP);414 async_answer_0(iid, ENOTSUP);423 ipc_answer_0(callid, ENOTSUP); 424 ipc_answer_0(iid, ENOTSUP); 415 425 return NULL; 416 426 } 417 427 418 428 driver->phone = IPC_GET_ARG5(call); 419 async_answer_0(callid, EOK);429 ipc_answer_0(callid, EOK); 420 430 421 431 /* … … 429 439 */ 430 440 list_initialize(&driver->devices); 431 432 link_initialize(&driver->drivers); 441 list_initialize(&(driver->drivers)); 433 442 434 443 fibril_mutex_lock(&drivers_list_mutex); … … 445 454 fibril_mutex_unlock(&drivers_list_mutex); 446 455 447 async_answer_0(iid, EOK);456 ipc_answer_0(iid, EOK); 448 457 449 458 return driver; … … 463 472 464 473 if (driver->phone != 0) 465 async_hangup(driver->phone);474 ipc_hangup(driver->phone); 466 475 467 476 /* Remove it from list of drivers */ … … 498 507 { 499 508 if (driver == NULL) { 500 async_answer_0(iid, EREFUSED);509 ipc_answer_0(iid, EREFUSED); 501 510 return; 502 511 } … … 506 515 (devmap_device_t *) malloc(sizeof(devmap_device_t)); 507 516 if (device == NULL) { 508 async_answer_0(iid, ENOMEM);517 ipc_answer_0(iid, ENOMEM); 509 518 return; 510 519 } … … 519 528 if (rc != EOK) { 520 529 free(device); 521 async_answer_0(iid, rc);530 ipc_answer_0(iid, rc); 522 531 return; 523 532 } … … 527 536 free(fqdn); 528 537 free(device); 529 async_answer_0(iid, EINVAL);538 ipc_answer_0(iid, EINVAL); 530 539 return; 531 540 } … … 541 550 free(device->name); 542 551 free(device); 543 async_answer_0(iid, ENOMEM);544 return; 545 } 546 547 li nk_initialize(&device->devices);548 li nk_initialize(&device->driver_devices);552 ipc_answer_0(iid, ENOMEM); 553 return; 554 } 555 556 list_initialize(&(device->devices)); 557 list_initialize(&(device->driver_devices)); 549 558 550 559 /* Check that device is not already registered */ … … 556 565 free(device->name); 557 566 free(device); 558 async_answer_0(iid, EEXISTS);567 ipc_answer_0(iid, EEXISTS); 559 568 return; 560 569 } … … 578 587 fibril_mutex_unlock(&devices_list_mutex); 579 588 580 async_answer_1(iid, EOK, device->handle);589 ipc_answer_1(iid, EOK, device->handle); 581 590 } 582 591 … … 609 618 if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) { 610 619 fibril_mutex_unlock(&devices_list_mutex); 611 async_answer_0(callid, ENOENT);620 ipc_answer_0(callid, ENOENT); 612 621 return; 613 622 } 614 623 615 624 if (dev->forward_interface == 0) { 616 async_forward_fast(callid, dev->driver->phone, 625 /* The IPC_GET_ARG3(*icall) would be always zero, 626 * wouldn't it? So why to pass it at all? 627 */ 628 ipc_forward_fast(callid, dev->driver->phone, 617 629 dev->handle, 0, 0, 618 630 IPC_FF_NONE); 619 631 } else { 620 async_forward_fast(callid, dev->driver->phone,632 ipc_forward_fast(callid, dev->driver->phone, 621 633 dev->forward_interface, dev->handle, 0, 622 634 IPC_FF_NONE); … … 640 652 DEVMAP_NAME_MAXLEN, 0, NULL); 641 653 if (rc != EOK) { 642 async_answer_0(iid, rc);654 ipc_answer_0(iid, rc); 643 655 return; 644 656 } … … 648 660 if (!devmap_fqdn_split(fqdn, &ns_name, &name)) { 649 661 free(fqdn); 650 async_answer_0(iid, EINVAL);662 ipc_answer_0(iid, EINVAL); 651 663 return; 652 664 } … … 675 687 } 676 688 677 async_answer_0(iid, ENOENT);689 ipc_answer_0(iid, ENOENT); 678 690 free(ns_name); 679 691 free(name); … … 682 694 } 683 695 684 async_answer_1(iid, EOK, dev->handle);696 ipc_answer_1(iid, EOK, dev->handle); 685 697 686 698 fibril_mutex_unlock(&devices_list_mutex); … … 703 715 DEVMAP_NAME_MAXLEN, 0, NULL); 704 716 if (rc != EOK) { 705 async_answer_0(iid, rc);717 ipc_answer_0(iid, rc); 706 718 return; 707 719 } … … 728 740 } 729 741 730 async_answer_0(iid, ENOENT);742 ipc_answer_0(iid, ENOENT); 731 743 free(name); 732 744 fibril_mutex_unlock(&devices_list_mutex); … … 734 746 } 735 747 736 async_answer_1(iid, EOK, namespace->handle);748 ipc_answer_1(iid, EOK, namespace->handle); 737 749 738 750 fibril_mutex_unlock(&devices_list_mutex); … … 750 762 devmap_device_find_handle(IPC_GET_ARG1(*icall)); 751 763 if (dev == NULL) 752 async_answer_1(iid, EOK, DEV_HANDLE_NONE);764 ipc_answer_1(iid, EOK, DEV_HANDLE_NONE); 753 765 else 754 async_answer_1(iid, EOK, DEV_HANDLE_DEVICE);766 ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE); 755 767 } else 756 async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);768 ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE); 757 769 758 770 fibril_mutex_unlock(&devices_list_mutex); … … 762 774 { 763 775 fibril_mutex_lock(&devices_list_mutex); 764 async_answer_1(iid, EOK, list_count(&namespaces_list));776 ipc_answer_1(iid, EOK, list_count(&namespaces_list)); 765 777 fibril_mutex_unlock(&devices_list_mutex); 766 778 } … … 773 785 devmap_namespace_find_handle(IPC_GET_ARG1(*icall)); 774 786 if (namespace == NULL) 775 async_answer_0(iid, EEXISTS);787 ipc_answer_0(iid, EEXISTS); 776 788 else 777 async_answer_1(iid, EOK, namespace->refcnt);789 ipc_answer_1(iid, EOK, namespace->refcnt); 778 790 779 791 fibril_mutex_unlock(&devices_list_mutex); … … 785 797 size_t size; 786 798 if (!async_data_read_receive(&callid, &size)) { 787 async_answer_0(callid, EREFUSED);788 async_answer_0(iid, EREFUSED);799 ipc_answer_0(callid, EREFUSED); 800 ipc_answer_0(iid, EREFUSED); 789 801 return; 790 802 } 791 803 792 804 if ((size % sizeof(dev_desc_t)) != 0) { 793 async_answer_0(callid, EINVAL);794 async_answer_0(iid, EINVAL);805 ipc_answer_0(callid, EINVAL); 806 ipc_answer_0(iid, EINVAL); 795 807 return; 796 808 } … … 801 813 if (count != list_count(&namespaces_list)) { 802 814 fibril_mutex_unlock(&devices_list_mutex); 803 async_answer_0(callid, EOVERFLOW);804 async_answer_0(iid, EOVERFLOW);815 ipc_answer_0(callid, EOVERFLOW); 816 ipc_answer_0(iid, EOVERFLOW); 805 817 return; 806 818 } … … 809 821 if (desc == NULL) { 810 822 fibril_mutex_unlock(&devices_list_mutex); 811 async_answer_0(callid, ENOMEM);812 async_answer_0(iid, ENOMEM);823 ipc_answer_0(callid, ENOMEM); 824 ipc_answer_0(iid, ENOMEM); 813 825 return; 814 826 } … … 831 843 fibril_mutex_unlock(&devices_list_mutex); 832 844 833 async_answer_0(iid, retval);845 ipc_answer_0(iid, retval); 834 846 } 835 847 … … 842 854 size_t size; 843 855 if (!async_data_read_receive(&callid, &size)) { 844 async_answer_0(callid, EREFUSED);845 async_answer_0(iid, EREFUSED);856 ipc_answer_0(callid, EREFUSED); 857 ipc_answer_0(iid, EREFUSED); 846 858 return; 847 859 } 848 860 849 861 if ((size % sizeof(dev_desc_t)) != 0) { 850 async_answer_0(callid, EINVAL);851 async_answer_0(iid, EINVAL);862 ipc_answer_0(callid, EINVAL); 863 ipc_answer_0(iid, EINVAL); 852 864 return; 853 865 } … … 859 871 if (namespace == NULL) { 860 872 fibril_mutex_unlock(&devices_list_mutex); 861 async_answer_0(callid, ENOENT);862 async_answer_0(iid, ENOENT);873 ipc_answer_0(callid, ENOENT); 874 ipc_answer_0(iid, ENOENT); 863 875 return; 864 876 } … … 867 879 if (count != namespace->refcnt) { 868 880 fibril_mutex_unlock(&devices_list_mutex); 869 async_answer_0(callid, EOVERFLOW);870 async_answer_0(iid, EOVERFLOW);881 ipc_answer_0(callid, EOVERFLOW); 882 ipc_answer_0(iid, EOVERFLOW); 871 883 return; 872 884 } … … 875 887 if (desc == NULL) { 876 888 fibril_mutex_unlock(&devices_list_mutex); 877 async_answer_0(callid, ENOMEM);878 async_answer_0(iid, EREFUSED);889 ipc_answer_0(callid, ENOMEM); 890 ipc_answer_0(iid, EREFUSED); 879 891 return; 880 892 } … … 898 910 fibril_mutex_unlock(&devices_list_mutex); 899 911 900 async_answer_0(iid, retval);912 ipc_answer_0(iid, retval); 901 913 } 902 914 … … 917 929 if (!fnd) { 918 930 fibril_mutex_unlock(&null_devices_mutex); 919 async_answer_0(iid, ENOMEM);931 ipc_answer_0(iid, ENOMEM); 920 932 return; 921 933 } … … 927 939 if (dev_name == NULL) { 928 940 fibril_mutex_unlock(&null_devices_mutex); 929 async_answer_0(iid, ENOMEM);941 ipc_answer_0(iid, ENOMEM); 930 942 return; 931 943 } … … 935 947 if (device == NULL) { 936 948 fibril_mutex_unlock(&null_devices_mutex); 937 async_answer_0(iid, ENOMEM);949 ipc_answer_0(iid, ENOMEM); 938 950 return; 939 951 } … … 945 957 fibril_mutex_lock(&devices_list_mutex); 946 958 fibril_mutex_unlock(&null_devices_mutex); 947 async_answer_0(iid, ENOMEM);948 return; 949 } 950 951 li nk_initialize(&device->devices);952 li nk_initialize(&device->driver_devices);959 ipc_answer_0(iid, ENOMEM); 960 return; 961 } 962 963 list_initialize(&(device->devices)); 964 list_initialize(&(device->driver_devices)); 953 965 954 966 /* Get unique device handle */ … … 959 971 device->name = dev_name; 960 972 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 */ 973 /* Insert device into list of all devices 974 and into null devices array */ 966 975 list_append(&device->devices, &devices_list); 967 list_append(&device->driver_devices, &dummy_null_driver_devices);968 976 null_devices[i] = device; 969 977 … … 971 979 fibril_mutex_unlock(&null_devices_mutex); 972 980 973 async_answer_1(iid, EOK, (sysarg_t) i);981 ipc_answer_1(iid, EOK, (sysarg_t) i); 974 982 } 975 983 … … 978 986 sysarg_t i = IPC_GET_ARG1(*icall); 979 987 if (i >= NULL_DEVICES) { 980 async_answer_0(iid, ELIMIT);988 ipc_answer_0(iid, ELIMIT); 981 989 return; 982 990 } … … 986 994 if (null_devices[i] == NULL) { 987 995 fibril_mutex_unlock(&null_devices_mutex); 988 async_answer_0(iid, ENOENT);996 ipc_answer_0(iid, ENOENT); 989 997 return; 990 998 } … … 997 1005 998 1006 fibril_mutex_unlock(&null_devices_mutex); 999 async_answer_0(iid, EOK);1007 ipc_answer_0(iid, EOK); 1000 1008 } 1001 1009 … … 1023 1031 { 1024 1032 /* Accept connection */ 1025 async_answer_0(iid, EOK);1033 ipc_answer_0(iid, EOK); 1026 1034 1027 1035 devmap_driver_t *driver = devmap_driver_register(); … … 1040 1048 case DEVMAP_DRIVER_UNREGISTER: 1041 1049 if (NULL == driver) 1042 async_answer_0(callid, ENOENT);1050 ipc_answer_0(callid, ENOENT); 1043 1051 else 1044 async_answer_0(callid, EOK);1052 ipc_answer_0(callid, EOK); 1045 1053 break; 1046 1054 case DEVMAP_DEVICE_REGISTER: … … 1059 1067 break; 1060 1068 default: 1061 async_answer_0(callid, ENOENT);1069 ipc_answer_0(callid, ENOENT); 1062 1070 } 1063 1071 } … … 1078 1086 { 1079 1087 /* Accept connection */ 1080 async_answer_0(iid, EOK);1088 ipc_answer_0(iid, EOK); 1081 1089 1082 1090 bool cont = true; … … 1117 1125 break; 1118 1126 default: 1119 async_answer_0(callid, ENOENT);1127 ipc_answer_0(callid, ENOENT); 1120 1128 } 1121 1129 } … … 1141 1149 default: 1142 1150 /* No such interface */ 1143 async_answer_0(iid, ENOENT);1151 ipc_answer_0(iid, ENOENT); 1144 1152 } 1145 1153 } … … 1161 1169 1162 1170 /* Register device mapper at naming service */ 1163 if (service_register(SERVICE_DEVMAP) != EOK) 1171 sysarg_t phonead; 1172 if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, &phonead) != 0) 1164 1173 return -1; 1165 1174
Note:
See TracChangeset
for help on using the changeset viewer.
