Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devmap/devmap.c

    r01b87dc5 r4ae90f9  
    123123static devmap_handle_t last_handle = 0;
    124124static 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 */
     130static LIST_INITIALIZE(dummy_null_driver_devices);
    125131
    126132static devmap_handle_t devmap_create_handle(void)
     
    374380       
    375381        if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) {
    376                 ipc_answer_0(iid, EREFUSED);
     382                async_answer_0(iid, EREFUSED);
    377383                return NULL;
    378384        }
     
    381387            (devmap_driver_t *) malloc(sizeof(devmap_driver_t));
    382388        if (driver == NULL) {
    383                 ipc_answer_0(iid, ENOMEM);
     389                async_answer_0(iid, ENOMEM);
    384390                return NULL;
    385391        }
     
    392398        if (rc != EOK) {
    393399                free(driver);
    394                 ipc_answer_0(iid, rc);
     400                async_answer_0(iid, rc);
    395401                return NULL;
    396402        }
     
    405411                free(driver->name);
    406412                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);
    409415                return NULL;
    410416        }
    411417       
    412418        driver->phone = IPC_GET_ARG5(call);
    413         ipc_answer_0(callid, EOK);
     419        async_answer_0(callid, EOK);
    414420       
    415421        /*
     
    423429         */
    424430        list_initialize(&driver->devices);
    425         list_initialize(&(driver->drivers));
     431
     432        link_initialize(&driver->drivers);
    426433       
    427434        fibril_mutex_lock(&drivers_list_mutex);
     
    438445        fibril_mutex_unlock(&drivers_list_mutex);
    439446       
    440         ipc_answer_0(iid, EOK);
     447        async_answer_0(iid, EOK);
    441448       
    442449        return driver;
     
    456463       
    457464        if (driver->phone != 0)
    458                 ipc_hangup(driver->phone);
     465                async_hangup(driver->phone);
    459466       
    460467        /* Remove it from list of drivers */
     
    491498{
    492499        if (driver == NULL) {
    493                 ipc_answer_0(iid, EREFUSED);
     500                async_answer_0(iid, EREFUSED);
    494501                return;
    495502        }
     
    499506            (devmap_device_t *) malloc(sizeof(devmap_device_t));
    500507        if (device == NULL) {
    501                 ipc_answer_0(iid, ENOMEM);
     508                async_answer_0(iid, ENOMEM);
    502509                return;
    503510        }
     
    512519        if (rc != EOK) {
    513520                free(device);
    514                 ipc_answer_0(iid, rc);
     521                async_answer_0(iid, rc);
    515522                return;
    516523        }
     
    520527                free(fqdn);
    521528                free(device);
    522                 ipc_answer_0(iid, EINVAL);
     529                async_answer_0(iid, EINVAL);
    523530                return;
    524531        }
     
    534541                free(device->name);
    535542                free(device);
    536                 ipc_answer_0(iid, ENOMEM);
    537                 return;
    538         }
    539        
    540         list_initialize(&(device->devices));
    541         list_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);
    542549       
    543550        /* Check that device is not already registered */
    544551        if (devmap_device_find_name(namespace->name, device->name) != NULL) {
    545552                printf("%s: Device '%s/%s' already registered\n", NAME,
    546                     device->namespace->name, device->name);
     553                    namespace->name, device->name);
    547554                devmap_namespace_destroy(namespace);
    548555                fibril_mutex_unlock(&devices_list_mutex);
    549556                free(device->name);
    550557                free(device);
    551                 ipc_answer_0(iid, EEXISTS);
     558                async_answer_0(iid, EEXISTS);
    552559                return;
    553560        }
     
    571578        fibril_mutex_unlock(&devices_list_mutex);
    572579       
    573         ipc_answer_1(iid, EOK, device->handle);
     580        async_answer_1(iid, EOK, device->handle);
    574581}
    575582
     
    602609        if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
    603610                fibril_mutex_unlock(&devices_list_mutex);
    604                 ipc_answer_0(callid, ENOENT);
     611                async_answer_0(callid, ENOENT);
    605612                return;
    606613        }
    607614       
    608615        if (dev->forward_interface == 0) {
    609                 ipc_forward_fast(callid, dev->driver->phone,
     616                async_forward_fast(callid, dev->driver->phone,
    610617                    dev->handle, 0, 0,
    611618                    IPC_FF_NONE);
    612619        } else {
    613                 ipc_forward_fast(callid, dev->driver->phone,
     620                async_forward_fast(callid, dev->driver->phone,
    614621                    dev->forward_interface, dev->handle, 0,
    615622                    IPC_FF_NONE);
     
    633640            DEVMAP_NAME_MAXLEN, 0, NULL);
    634641        if (rc != EOK) {
    635                 ipc_answer_0(iid, rc);
     642                async_answer_0(iid, rc);
    636643                return;
    637644        }
     
    641648        if (!devmap_fqdn_split(fqdn, &ns_name, &name)) {
    642649                free(fqdn);
    643                 ipc_answer_0(iid, EINVAL);
     650                async_answer_0(iid, EINVAL);
    644651                return;
    645652        }
     
    668675                }
    669676               
    670                 ipc_answer_0(iid, ENOENT);
     677                async_answer_0(iid, ENOENT);
    671678                free(ns_name);
    672679                free(name);
     
    675682        }
    676683       
    677         ipc_answer_1(iid, EOK, dev->handle);
     684        async_answer_1(iid, EOK, dev->handle);
    678685       
    679686        fibril_mutex_unlock(&devices_list_mutex);
     
    696703            DEVMAP_NAME_MAXLEN, 0, NULL);
    697704        if (rc != EOK) {
    698                 ipc_answer_0(iid, rc);
     705                async_answer_0(iid, rc);
    699706                return;
    700707        }
     
    721728                }
    722729               
    723                 ipc_answer_0(iid, ENOENT);
     730                async_answer_0(iid, ENOENT);
    724731                free(name);
    725732                fibril_mutex_unlock(&devices_list_mutex);
     
    727734        }
    728735       
    729         ipc_answer_1(iid, EOK, namespace->handle);
     736        async_answer_1(iid, EOK, namespace->handle);
    730737       
    731738        fibril_mutex_unlock(&devices_list_mutex);
     
    743750                    devmap_device_find_handle(IPC_GET_ARG1(*icall));
    744751                if (dev == NULL)
    745                         ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);
     752                        async_answer_1(iid, EOK, DEV_HANDLE_NONE);
    746753                else
    747                         ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
     754                        async_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
    748755        } else
    749                 ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
     756                async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
    750757       
    751758        fibril_mutex_unlock(&devices_list_mutex);
     
    755762{
    756763        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));
    758765        fibril_mutex_unlock(&devices_list_mutex);
    759766}
     
    766773            devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
    767774        if (namespace == NULL)
    768                 ipc_answer_0(iid, EEXISTS);
     775                async_answer_0(iid, EEXISTS);
    769776        else
    770                 ipc_answer_1(iid, EOK, namespace->refcnt);
     777                async_answer_1(iid, EOK, namespace->refcnt);
    771778       
    772779        fibril_mutex_unlock(&devices_list_mutex);
     
    778785        size_t size;
    779786        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);
    782789                return;
    783790        }
    784791       
    785792        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);
    788795                return;
    789796        }
     
    794801        if (count != list_count(&namespaces_list)) {
    795802                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);
    798805                return;
    799806        }
     
    802809        if (desc == NULL) {
    803810                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);
    806813                return;
    807814        }
     
    824831        fibril_mutex_unlock(&devices_list_mutex);
    825832       
    826         ipc_answer_0(iid, retval);
     833        async_answer_0(iid, retval);
    827834}
    828835
     
    835842        size_t size;
    836843        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);
    839846                return;
    840847        }
    841848       
    842849        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);
    845852                return;
    846853        }
     
    852859        if (namespace == NULL) {
    853860                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);
    856863                return;
    857864        }
     
    860867        if (count != namespace->refcnt) {
    861868                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);
    864871                return;
    865872        }
     
    868875        if (desc == NULL) {
    869876                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);
    872879                return;
    873880        }
     
    891898        fibril_mutex_unlock(&devices_list_mutex);
    892899       
    893         ipc_answer_0(iid, retval);
     900        async_answer_0(iid, retval);
    894901}
    895902
     
    910917        if (!fnd) {
    911918                fibril_mutex_unlock(&null_devices_mutex);
    912                 ipc_answer_0(iid, ENOMEM);
     919                async_answer_0(iid, ENOMEM);
    913920                return;
    914921        }
     
    920927        if (dev_name == NULL) {
    921928                fibril_mutex_unlock(&null_devices_mutex);
    922                 ipc_answer_0(iid, ENOMEM);
     929                async_answer_0(iid, ENOMEM);
    923930                return;
    924931        }
     
    928935        if (device == NULL) {
    929936                fibril_mutex_unlock(&null_devices_mutex);
    930                 ipc_answer_0(iid, ENOMEM);
     937                async_answer_0(iid, ENOMEM);
    931938                return;
    932939        }
     
    938945                fibril_mutex_lock(&devices_list_mutex);
    939946                fibril_mutex_unlock(&null_devices_mutex);
    940                 ipc_answer_0(iid, ENOMEM);
    941                 return;
    942         }
    943        
    944         list_initialize(&(device->devices));
    945         list_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);
    946953       
    947954        /* Get unique device handle */
     
    952959        device->name = dev_name;
    953960       
    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         */
    956966        list_append(&device->devices, &devices_list);
     967        list_append(&device->driver_devices, &dummy_null_driver_devices);
    957968        null_devices[i] = device;
    958969       
     
    960971        fibril_mutex_unlock(&null_devices_mutex);
    961972       
    962         ipc_answer_1(iid, EOK, (sysarg_t) i);
     973        async_answer_1(iid, EOK, (sysarg_t) i);
    963974}
    964975
     
    967978        sysarg_t i = IPC_GET_ARG1(*icall);
    968979        if (i >= NULL_DEVICES) {
    969                 ipc_answer_0(iid, ELIMIT);
     980                async_answer_0(iid, ELIMIT);
    970981                return;
    971982        }
     
    975986        if (null_devices[i] == NULL) {
    976987                fibril_mutex_unlock(&null_devices_mutex);
    977                 ipc_answer_0(iid, ENOENT);
     988                async_answer_0(iid, ENOENT);
    978989                return;
    979990        }
     
    986997       
    987998        fibril_mutex_unlock(&null_devices_mutex);
    988         ipc_answer_0(iid, EOK);
     999        async_answer_0(iid, EOK);
    9891000}
    9901001
     
    10121023{
    10131024        /* Accept connection */
    1014         ipc_answer_0(iid, EOK);
     1025        async_answer_0(iid, EOK);
    10151026       
    10161027        devmap_driver_t *driver = devmap_driver_register();
     
    10291040                case DEVMAP_DRIVER_UNREGISTER:
    10301041                        if (NULL == driver)
    1031                                 ipc_answer_0(callid, ENOENT);
     1042                                async_answer_0(callid, ENOENT);
    10321043                        else
    1033                                 ipc_answer_0(callid, EOK);
     1044                                async_answer_0(callid, EOK);
    10341045                        break;
    10351046                case DEVMAP_DEVICE_REGISTER:
     
    10481059                        break;
    10491060                default:
    1050                         ipc_answer_0(callid, ENOENT);
     1061                        async_answer_0(callid, ENOENT);
    10511062                }
    10521063        }
     
    10671078{
    10681079        /* Accept connection */
    1069         ipc_answer_0(iid, EOK);
     1080        async_answer_0(iid, EOK);
    10701081       
    10711082        bool cont = true;
     
    11061117                        break;
    11071118                default:
    1108                         ipc_answer_0(callid, ENOENT);
     1119                        async_answer_0(callid, ENOENT);
    11091120                }
    11101121        }
     
    11301141        default:
    11311142                /* No such interface */
    1132                 ipc_answer_0(iid, ENOENT);
     1143                async_answer_0(iid, ENOENT);
    11331144        }
    11341145}
     
    11501161       
    11511162        /* 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)
    11541164                return -1;
    11551165       
Note: See TracChangeset for help on using the changeset viewer.