Ignore:
File:
1 edited

Legend:

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

    r63e0bdd r47a7174f  
    4646#include <str.h>
    4747#include <ipc/devmap.h>
    48 #include <assert.h>
    4948
    5049#define NAME          "devmap"
     
    123122static devmap_handle_t last_handle = 0;
    124123static 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);
    131124
    132125static devmap_handle_t devmap_create_handle(void)
     
    215208}
    216209
    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 */
    218216static devmap_namespace_t *devmap_namespace_find_name(const char *name)
    219217{
    220218        link_t *item;
    221        
    222         assert(fibril_mutex_is_locked(&devices_list_mutex));
    223        
    224219        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    225220                devmap_namespace_t *namespace =
     
    234229/** Find namespace with given handle.
    235230 *
     231 * The devices_list_mutex should be already held when
     232 * calling this function.
     233 *
    236234 * @todo: use hash table
    237235 *
     
    240238{
    241239        link_t *item;
    242        
    243         assert(fibril_mutex_is_locked(&devices_list_mutex));
    244        
    245240        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    246241                devmap_namespace_t *namespace =
     
    253248}
    254249
    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 */
    256256static devmap_device_t *devmap_device_find_name(const char *ns_name,
    257257    const char *name)
    258258{
    259259        link_t *item;
    260        
    261         assert(fibril_mutex_is_locked(&devices_list_mutex));
    262        
    263260        for (item = devices_list.next; item != &devices_list; item = item->next) {
    264261                devmap_device_t *device =
     
    274271/** Find device with given handle.
    275272 *
     273 * The devices_list_mutex should be already held when
     274 * calling this function.
     275 *
    276276 * @todo: use hash table
    277277 *
     
    280280{
    281281        link_t *item;
    282        
    283         assert(fibril_mutex_is_locked(&devices_list_mutex));
    284        
    285282        for (item = devices_list.next; item != &devices_list; item = item->next) {
    286283                devmap_device_t *device =
     
    293290}
    294291
    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 */
    296298static devmap_namespace_t *devmap_namespace_create(const char *ns_name)
    297299{
    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);
    303301        if (namespace != NULL)
    304302                return namespace;
     
    325323}
    326324
    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 */
    328331static void devmap_namespace_destroy(devmap_namespace_t *namespace)
    329332{
    330         assert(fibril_mutex_is_locked(&devices_list_mutex));
    331 
    332333        if (namespace->refcnt == 0) {
    333334                list_remove(&(namespace->namespaces));
     
    338339}
    339340
    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 */
    341347static void devmap_namespace_addref(devmap_namespace_t *namespace,
    342348    devmap_device_t *device)
    343349{
    344         assert(fibril_mutex_is_locked(&devices_list_mutex));
    345 
    346350        device->namespace = namespace;
    347351        namespace->refcnt++;
    348352}
    349353
    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 */
    351360static void devmap_namespace_delref(devmap_namespace_t *namespace)
    352361{
    353         assert(fibril_mutex_is_locked(&devices_list_mutex));
    354 
    355362        namespace->refcnt--;
    356363        devmap_namespace_destroy(namespace);
    357364}
    358365
    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 */
    360372static void devmap_device_unregister_core(devmap_device_t *device)
    361373{
    362         assert(fibril_mutex_is_locked(&devices_list_mutex));
    363 
    364374        devmap_namespace_delref(device->namespace);
    365375        list_remove(&(device->devices));
     
    380390       
    381391        if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) {
    382                 async_answer_0(iid, EREFUSED);
     392                ipc_answer_0(iid, EREFUSED);
    383393                return NULL;
    384394        }
     
    387397            (devmap_driver_t *) malloc(sizeof(devmap_driver_t));
    388398        if (driver == NULL) {
    389                 async_answer_0(iid, ENOMEM);
     399                ipc_answer_0(iid, ENOMEM);
    390400                return NULL;
    391401        }
     
    398408        if (rc != EOK) {
    399409                free(driver);
    400                 async_answer_0(iid, rc);
     410                ipc_answer_0(iid, rc);
    401411                return NULL;
    402412        }
     
    411421                free(driver->name);
    412422                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);
    415425                return NULL;
    416426        }
    417427       
    418428        driver->phone = IPC_GET_ARG5(call);
    419         async_answer_0(callid, EOK);
     429        ipc_answer_0(callid, EOK);
    420430       
    421431        /*
     
    429439         */
    430440        list_initialize(&driver->devices);
    431 
    432         link_initialize(&driver->drivers);
     441        list_initialize(&(driver->drivers));
    433442       
    434443        fibril_mutex_lock(&drivers_list_mutex);
     
    445454        fibril_mutex_unlock(&drivers_list_mutex);
    446455       
    447         async_answer_0(iid, EOK);
     456        ipc_answer_0(iid, EOK);
    448457       
    449458        return driver;
     
    463472       
    464473        if (driver->phone != 0)
    465                 async_hangup(driver->phone);
     474                ipc_hangup(driver->phone);
    466475       
    467476        /* Remove it from list of drivers */
     
    498507{
    499508        if (driver == NULL) {
    500                 async_answer_0(iid, EREFUSED);
     509                ipc_answer_0(iid, EREFUSED);
    501510                return;
    502511        }
     
    506515            (devmap_device_t *) malloc(sizeof(devmap_device_t));
    507516        if (device == NULL) {
    508                 async_answer_0(iid, ENOMEM);
     517                ipc_answer_0(iid, ENOMEM);
    509518                return;
    510519        }
     
    519528        if (rc != EOK) {
    520529                free(device);
    521                 async_answer_0(iid, rc);
     530                ipc_answer_0(iid, rc);
    522531                return;
    523532        }
     
    527536                free(fqdn);
    528537                free(device);
    529                 async_answer_0(iid, EINVAL);
     538                ipc_answer_0(iid, EINVAL);
    530539                return;
    531540        }
     
    541550                free(device->name);
    542551                free(device);
    543                 async_answer_0(iid, ENOMEM);
    544                 return;
    545         }
    546        
    547         link_initialize(&device->devices);
    548         link_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));
    549558       
    550559        /* Check that device is not already registered */
     
    556565                free(device->name);
    557566                free(device);
    558                 async_answer_0(iid, EEXISTS);
     567                ipc_answer_0(iid, EEXISTS);
    559568                return;
    560569        }
     
    578587        fibril_mutex_unlock(&devices_list_mutex);
    579588       
    580         async_answer_1(iid, EOK, device->handle);
     589        ipc_answer_1(iid, EOK, device->handle);
    581590}
    582591
     
    609618        if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
    610619                fibril_mutex_unlock(&devices_list_mutex);
    611                 async_answer_0(callid, ENOENT);
     620                ipc_answer_0(callid, ENOENT);
    612621                return;
    613622        }
    614623       
    615624        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,
    617629                    dev->handle, 0, 0,
    618630                    IPC_FF_NONE);
    619631        } else {
    620                 async_forward_fast(callid, dev->driver->phone,
     632                ipc_forward_fast(callid, dev->driver->phone,
    621633                    dev->forward_interface, dev->handle, 0,
    622634                    IPC_FF_NONE);
     
    640652            DEVMAP_NAME_MAXLEN, 0, NULL);
    641653        if (rc != EOK) {
    642                 async_answer_0(iid, rc);
     654                ipc_answer_0(iid, rc);
    643655                return;
    644656        }
     
    648660        if (!devmap_fqdn_split(fqdn, &ns_name, &name)) {
    649661                free(fqdn);
    650                 async_answer_0(iid, EINVAL);
     662                ipc_answer_0(iid, EINVAL);
    651663                return;
    652664        }
     
    675687                }
    676688               
    677                 async_answer_0(iid, ENOENT);
     689                ipc_answer_0(iid, ENOENT);
    678690                free(ns_name);
    679691                free(name);
     
    682694        }
    683695       
    684         async_answer_1(iid, EOK, dev->handle);
     696        ipc_answer_1(iid, EOK, dev->handle);
    685697       
    686698        fibril_mutex_unlock(&devices_list_mutex);
     
    703715            DEVMAP_NAME_MAXLEN, 0, NULL);
    704716        if (rc != EOK) {
    705                 async_answer_0(iid, rc);
     717                ipc_answer_0(iid, rc);
    706718                return;
    707719        }
     
    728740                }
    729741               
    730                 async_answer_0(iid, ENOENT);
     742                ipc_answer_0(iid, ENOENT);
    731743                free(name);
    732744                fibril_mutex_unlock(&devices_list_mutex);
     
    734746        }
    735747       
    736         async_answer_1(iid, EOK, namespace->handle);
     748        ipc_answer_1(iid, EOK, namespace->handle);
    737749       
    738750        fibril_mutex_unlock(&devices_list_mutex);
     
    750762                    devmap_device_find_handle(IPC_GET_ARG1(*icall));
    751763                if (dev == NULL)
    752                         async_answer_1(iid, EOK, DEV_HANDLE_NONE);
     764                        ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);
    753765                else
    754                         async_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
     766                        ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
    755767        } else
    756                 async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
     768                ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
    757769       
    758770        fibril_mutex_unlock(&devices_list_mutex);
     
    762774{
    763775        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));
    765777        fibril_mutex_unlock(&devices_list_mutex);
    766778}
     
    773785            devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
    774786        if (namespace == NULL)
    775                 async_answer_0(iid, EEXISTS);
     787                ipc_answer_0(iid, EEXISTS);
    776788        else
    777                 async_answer_1(iid, EOK, namespace->refcnt);
     789                ipc_answer_1(iid, EOK, namespace->refcnt);
    778790       
    779791        fibril_mutex_unlock(&devices_list_mutex);
     
    785797        size_t size;
    786798        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);
    789801                return;
    790802        }
    791803       
    792804        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);
    795807                return;
    796808        }
     
    801813        if (count != list_count(&namespaces_list)) {
    802814                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);
    805817                return;
    806818        }
     
    809821        if (desc == NULL) {
    810822                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);
    813825                return;
    814826        }
     
    831843        fibril_mutex_unlock(&devices_list_mutex);
    832844       
    833         async_answer_0(iid, retval);
     845        ipc_answer_0(iid, retval);
    834846}
    835847
     
    842854        size_t size;
    843855        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);
    846858                return;
    847859        }
    848860       
    849861        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);
    852864                return;
    853865        }
     
    859871        if (namespace == NULL) {
    860872                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);
    863875                return;
    864876        }
     
    867879        if (count != namespace->refcnt) {
    868880                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);
    871883                return;
    872884        }
     
    875887        if (desc == NULL) {
    876888                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);
    879891                return;
    880892        }
     
    898910        fibril_mutex_unlock(&devices_list_mutex);
    899911       
    900         async_answer_0(iid, retval);
     912        ipc_answer_0(iid, retval);
    901913}
    902914
     
    917929        if (!fnd) {
    918930                fibril_mutex_unlock(&null_devices_mutex);
    919                 async_answer_0(iid, ENOMEM);
     931                ipc_answer_0(iid, ENOMEM);
    920932                return;
    921933        }
     
    927939        if (dev_name == NULL) {
    928940                fibril_mutex_unlock(&null_devices_mutex);
    929                 async_answer_0(iid, ENOMEM);
     941                ipc_answer_0(iid, ENOMEM);
    930942                return;
    931943        }
     
    935947        if (device == NULL) {
    936948                fibril_mutex_unlock(&null_devices_mutex);
    937                 async_answer_0(iid, ENOMEM);
     949                ipc_answer_0(iid, ENOMEM);
    938950                return;
    939951        }
     
    945957                fibril_mutex_lock(&devices_list_mutex);
    946958                fibril_mutex_unlock(&null_devices_mutex);
    947                 async_answer_0(iid, ENOMEM);
    948                 return;
    949         }
    950        
    951         link_initialize(&device->devices);
    952         link_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));
    953965       
    954966        /* Get unique device handle */
     
    959971        device->name = dev_name;
    960972       
    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 */
    966975        list_append(&device->devices, &devices_list);
    967         list_append(&device->driver_devices, &dummy_null_driver_devices);
    968976        null_devices[i] = device;
    969977       
     
    971979        fibril_mutex_unlock(&null_devices_mutex);
    972980       
    973         async_answer_1(iid, EOK, (sysarg_t) i);
     981        ipc_answer_1(iid, EOK, (sysarg_t) i);
    974982}
    975983
     
    978986        sysarg_t i = IPC_GET_ARG1(*icall);
    979987        if (i >= NULL_DEVICES) {
    980                 async_answer_0(iid, ELIMIT);
     988                ipc_answer_0(iid, ELIMIT);
    981989                return;
    982990        }
     
    986994        if (null_devices[i] == NULL) {
    987995                fibril_mutex_unlock(&null_devices_mutex);
    988                 async_answer_0(iid, ENOENT);
     996                ipc_answer_0(iid, ENOENT);
    989997                return;
    990998        }
     
    9971005       
    9981006        fibril_mutex_unlock(&null_devices_mutex);
    999         async_answer_0(iid, EOK);
     1007        ipc_answer_0(iid, EOK);
    10001008}
    10011009
     
    10231031{
    10241032        /* Accept connection */
    1025         async_answer_0(iid, EOK);
     1033        ipc_answer_0(iid, EOK);
    10261034       
    10271035        devmap_driver_t *driver = devmap_driver_register();
     
    10401048                case DEVMAP_DRIVER_UNREGISTER:
    10411049                        if (NULL == driver)
    1042                                 async_answer_0(callid, ENOENT);
     1050                                ipc_answer_0(callid, ENOENT);
    10431051                        else
    1044                                 async_answer_0(callid, EOK);
     1052                                ipc_answer_0(callid, EOK);
    10451053                        break;
    10461054                case DEVMAP_DEVICE_REGISTER:
     
    10591067                        break;
    10601068                default:
    1061                         async_answer_0(callid, ENOENT);
     1069                        ipc_answer_0(callid, ENOENT);
    10621070                }
    10631071        }
     
    10781086{
    10791087        /* Accept connection */
    1080         async_answer_0(iid, EOK);
     1088        ipc_answer_0(iid, EOK);
    10811089       
    10821090        bool cont = true;
     
    11171125                        break;
    11181126                default:
    1119                         async_answer_0(callid, ENOENT);
     1127                        ipc_answer_0(callid, ENOENT);
    11201128                }
    11211129        }
     
    11411149        default:
    11421150                /* No such interface */
    1143                 async_answer_0(iid, ENOENT);
     1151                ipc_answer_0(iid, ENOENT);
    11441152        }
    11451153}
     
    11611169       
    11621170        /* 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)
    11641173                return -1;
    11651174       
Note: See TracChangeset for help on using the changeset viewer.