Ignore:
File:
1 edited

Legend:

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

    rca2a18e r7e752b2  
    4646#include <str.h>
    4747#include <ipc/devmap.h>
    48 #include <assert.h>
    4948
    5049#define NAME          "devmap"
     
    6261        link_t devices;
    6362        /** Phone asociated with this driver */
    64         sysarg_t phone;
     63        ipcarg_t phone;
    6564        /** Device driver name */
    6665        char *name;
     
    10099        /** Device driver handling this device */
    101100        devmap_driver_t *driver;
    102         /** Use this interface when forwarding to driver. */
    103         sysarg_t forward_interface;
    104101} devmap_device_t;
    105102
     
    209206}
    210207
    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 */
    212214static devmap_namespace_t *devmap_namespace_find_name(const char *name)
    213215{
    214216        link_t *item;
    215        
    216         assert(fibril_mutex_is_locked(&devices_list_mutex));
    217        
    218217        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    219218                devmap_namespace_t *namespace =
     
    228227/** Find namespace with given handle.
    229228 *
     229 * The devices_list_mutex should be already held when
     230 * calling this function.
     231 *
    230232 * @todo: use hash table
    231233 *
     
    234236{
    235237        link_t *item;
    236        
    237         assert(fibril_mutex_is_locked(&devices_list_mutex));
    238        
    239238        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    240239                devmap_namespace_t *namespace =
     
    247246}
    248247
    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 */
    250254static devmap_device_t *devmap_device_find_name(const char *ns_name,
    251255    const char *name)
    252256{
    253257        link_t *item;
    254        
    255         assert(fibril_mutex_is_locked(&devices_list_mutex));
    256        
    257258        for (item = devices_list.next; item != &devices_list; item = item->next) {
    258259                devmap_device_t *device =
     
    268269/** Find device with given handle.
    269270 *
     271 * The devices_list_mutex should be already held when
     272 * calling this function.
     273 *
    270274 * @todo: use hash table
    271275 *
     
    274278{
    275279        link_t *item;
    276        
    277         assert(fibril_mutex_is_locked(&devices_list_mutex));
    278        
    279280        for (item = devices_list.next; item != &devices_list; item = item->next) {
    280281                devmap_device_t *device =
     
    287288}
    288289
    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 */
    290296static devmap_namespace_t *devmap_namespace_create(const char *ns_name)
    291297{
    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);
    297299        if (namespace != NULL)
    298300                return namespace;
     
    319321}
    320322
    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 */
    322329static void devmap_namespace_destroy(devmap_namespace_t *namespace)
    323330{
    324         assert(fibril_mutex_is_locked(&devices_list_mutex));
    325 
    326331        if (namespace->refcnt == 0) {
    327332                list_remove(&(namespace->namespaces));
     
    332337}
    333338
    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 */
    335345static void devmap_namespace_addref(devmap_namespace_t *namespace,
    336346    devmap_device_t *device)
    337347{
    338         assert(fibril_mutex_is_locked(&devices_list_mutex));
    339 
    340348        device->namespace = namespace;
    341349        namespace->refcnt++;
    342350}
    343351
    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 */
    345358static void devmap_namespace_delref(devmap_namespace_t *namespace)
    346359{
    347         assert(fibril_mutex_is_locked(&devices_list_mutex));
    348 
    349360        namespace->refcnt--;
    350361        devmap_namespace_destroy(namespace);
    351362}
    352363
    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 */
    354370static void devmap_device_unregister_core(devmap_device_t *device)
    355371{
    356         assert(fibril_mutex_is_locked(&devices_list_mutex));
    357 
    358372        devmap_namespace_delref(device->namespace);
    359373        list_remove(&(device->devices));
     
    373387        ipc_callid_t iid = async_get_call(&icall);
    374388       
    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);
    377391                return NULL;
    378392        }
     
    381395            (devmap_driver_t *) malloc(sizeof(devmap_driver_t));
    382396        if (driver == NULL) {
    383                 async_answer_0(iid, ENOMEM);
     397                ipc_answer_0(iid, ENOMEM);
    384398                return NULL;
    385399        }
     
    392406        if (rc != EOK) {
    393407                free(driver);
    394                 async_answer_0(iid, rc);
     408                ipc_answer_0(iid, rc);
    395409                return NULL;
    396410        }
     
    402416        ipc_callid_t callid = async_get_call(&call);
    403417       
    404         if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
     418        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
    405419                free(driver->name);
    406420                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);
    409423                return NULL;
    410424        }
    411425       
    412426        driver->phone = IPC_GET_ARG5(call);
    413         async_answer_0(callid, EOK);
     427        ipc_answer_0(callid, EOK);
    414428       
    415429        /*
     
    423437         */
    424438        list_initialize(&driver->devices);
    425 
    426         link_initialize(&driver->drivers);
     439        list_initialize(&(driver->drivers));
    427440       
    428441        fibril_mutex_lock(&drivers_list_mutex);
     
    439452        fibril_mutex_unlock(&drivers_list_mutex);
    440453       
    441         async_answer_0(iid, EOK);
     454        ipc_answer_0(iid, EOK);
    442455       
    443456        return driver;
     
    457470       
    458471        if (driver->phone != 0)
    459                 async_hangup(driver->phone);
     472                ipc_hangup(driver->phone);
    460473       
    461474        /* Remove it from list of drivers */
     
    492505{
    493506        if (driver == NULL) {
    494                 async_answer_0(iid, EREFUSED);
     507                ipc_answer_0(iid, EREFUSED);
    495508                return;
    496509        }
     
    500513            (devmap_device_t *) malloc(sizeof(devmap_device_t));
    501514        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       
    509519        /* Get fqdn */
    510520        char *fqdn;
     
    513523        if (rc != EOK) {
    514524                free(device);
    515                 async_answer_0(iid, rc);
     525                ipc_answer_0(iid, rc);
    516526                return;
    517527        }
     
    521531                free(fqdn);
    522532                free(device);
    523                 async_answer_0(iid, EINVAL);
     533                ipc_answer_0(iid, EINVAL);
    524534                return;
    525535        }
     
    535545                free(device->name);
    536546                free(device);
    537                 async_answer_0(iid, ENOMEM);
    538                 return;
    539         }
    540        
    541         link_initialize(&device->devices);
    542         link_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));
    543553       
    544554        /* Check that device is not already registered */
     
    550560                free(device->name);
    551561                free(device);
    552                 async_answer_0(iid, EEXISTS);
     562                ipc_answer_0(iid, EEXISTS);
    553563                return;
    554564        }
     
    556566        /* Get unique device handle */
    557567        device->handle = devmap_create_handle();
    558 
     568       
    559569        devmap_namespace_addref(namespace, device);
    560570        device->driver = driver;
     
    572582        fibril_mutex_unlock(&devices_list_mutex);
    573583       
    574         async_answer_1(iid, EOK, device->handle);
     584        ipc_answer_1(iid, EOK, device->handle);
    575585}
    576586
     
    603613        if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
    604614                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);
    618621       
    619622        fibril_mutex_unlock(&devices_list_mutex);
     
    634637            DEVMAP_NAME_MAXLEN, 0, NULL);
    635638        if (rc != EOK) {
    636                 async_answer_0(iid, rc);
     639                ipc_answer_0(iid, rc);
    637640                return;
    638641        }
     
    642645        if (!devmap_fqdn_split(fqdn, &ns_name, &name)) {
    643646                free(fqdn);
    644                 async_answer_0(iid, EINVAL);
     647                ipc_answer_0(iid, EINVAL);
    645648                return;
    646649        }
     
    669672                }
    670673               
    671                 async_answer_0(iid, ENOENT);
     674                ipc_answer_0(iid, ENOENT);
    672675                free(ns_name);
    673676                free(name);
     
    676679        }
    677680       
    678         async_answer_1(iid, EOK, dev->handle);
     681        ipc_answer_1(iid, EOK, dev->handle);
    679682       
    680683        fibril_mutex_unlock(&devices_list_mutex);
     
    697700            DEVMAP_NAME_MAXLEN, 0, NULL);
    698701        if (rc != EOK) {
    699                 async_answer_0(iid, rc);
     702                ipc_answer_0(iid, rc);
    700703                return;
    701704        }
     
    722725                }
    723726               
    724                 async_answer_0(iid, ENOENT);
     727                ipc_answer_0(iid, ENOENT);
    725728                free(name);
    726729                fibril_mutex_unlock(&devices_list_mutex);
     
    728731        }
    729732       
    730         async_answer_1(iid, EOK, namespace->handle);
     733        ipc_answer_1(iid, EOK, namespace->handle);
    731734       
    732735        fibril_mutex_unlock(&devices_list_mutex);
     
    744747                    devmap_device_find_handle(IPC_GET_ARG1(*icall));
    745748                if (dev == NULL)
    746                         async_answer_1(iid, EOK, DEV_HANDLE_NONE);
     749                        ipc_answer_1(iid, EOK, DEV_HANDLE_NONE);
    747750                else
    748                         async_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
     751                        ipc_answer_1(iid, EOK, DEV_HANDLE_DEVICE);
    749752        } else
    750                 async_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
     753                ipc_answer_1(iid, EOK, DEV_HANDLE_NAMESPACE);
    751754       
    752755        fibril_mutex_unlock(&devices_list_mutex);
     
    756759{
    757760        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));
    759762        fibril_mutex_unlock(&devices_list_mutex);
    760763}
     
    767770            devmap_namespace_find_handle(IPC_GET_ARG1(*icall));
    768771        if (namespace == NULL)
    769                 async_answer_0(iid, EEXISTS);
     772                ipc_answer_0(iid, EEXISTS);
    770773        else
    771                 async_answer_1(iid, EOK, namespace->refcnt);
     774                ipc_answer_1(iid, EOK, namespace->refcnt);
    772775       
    773776        fibril_mutex_unlock(&devices_list_mutex);
     
    779782        size_t size;
    780783        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);
    783786                return;
    784787        }
    785788       
    786789        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);
    789792                return;
    790793        }
     
    795798        if (count != list_count(&namespaces_list)) {
    796799                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);
    799802                return;
    800803        }
     
    803806        if (desc == NULL) {
    804807                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);
    807810                return;
    808811        }
     
    820823        }
    821824       
    822         sysarg_t retval = async_data_read_finalize(callid, desc, size);
     825        ipcarg_t retval = async_data_read_finalize(callid, desc, size);
    823826       
    824827        free(desc);
    825828        fibril_mutex_unlock(&devices_list_mutex);
    826829       
    827         async_answer_0(iid, retval);
     830        ipc_answer_0(iid, retval);
    828831}
    829832
     
    836839        size_t size;
    837840        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);
    840843                return;
    841844        }
    842845       
    843846        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);
    846849                return;
    847850        }
     
    853856        if (namespace == NULL) {
    854857                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);
    857860                return;
    858861        }
     
    861864        if (count != namespace->refcnt) {
    862865                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);
    865868                return;
    866869        }
     
    869872        if (desc == NULL) {
    870873                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);
    873876                return;
    874877        }
     
    887890        }
    888891       
    889         sysarg_t retval = async_data_read_finalize(callid, desc, size);
     892        ipcarg_t retval = async_data_read_finalize(callid, desc, size);
    890893       
    891894        free(desc);
    892895        fibril_mutex_unlock(&devices_list_mutex);
    893896       
    894         async_answer_0(iid, retval);
     897        ipc_answer_0(iid, retval);
    895898}
    896899
     
    911914        if (!fnd) {
    912915                fibril_mutex_unlock(&null_devices_mutex);
    913                 async_answer_0(iid, ENOMEM);
     916                ipc_answer_0(iid, ENOMEM);
    914917                return;
    915918        }
     
    921924        if (dev_name == NULL) {
    922925                fibril_mutex_unlock(&null_devices_mutex);
    923                 async_answer_0(iid, ENOMEM);
     926                ipc_answer_0(iid, ENOMEM);
    924927                return;
    925928        }
     
    929932        if (device == NULL) {
    930933                fibril_mutex_unlock(&null_devices_mutex);
    931                 async_answer_0(iid, ENOMEM);
     934                ipc_answer_0(iid, ENOMEM);
    932935                return;
    933936        }
     
    939942                fibril_mutex_lock(&devices_list_mutex);
    940943                fibril_mutex_unlock(&null_devices_mutex);
    941                 async_answer_0(iid, ENOMEM);
    942                 return;
    943         }
    944        
    945         link_initialize(&device->devices);
    946         link_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));
    947950       
    948951        /* Get unique device handle */
     
    961964        fibril_mutex_unlock(&null_devices_mutex);
    962965       
    963         async_answer_1(iid, EOK, (sysarg_t) i);
     966        ipc_answer_1(iid, EOK, (ipcarg_t) i);
    964967}
    965968
    966969static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall)
    967970{
    968         sysarg_t i = IPC_GET_ARG1(*icall);
     971        ipcarg_t i = IPC_GET_ARG1(*icall);
    969972        if (i >= NULL_DEVICES) {
    970                 async_answer_0(iid, ELIMIT);
     973                ipc_answer_0(iid, ELIMIT);
    971974                return;
    972975        }
     
    976979        if (null_devices[i] == NULL) {
    977980                fibril_mutex_unlock(&null_devices_mutex);
    978                 async_answer_0(iid, ENOENT);
     981                ipc_answer_0(iid, ENOENT);
    979982                return;
    980983        }
     
    987990       
    988991        fibril_mutex_unlock(&null_devices_mutex);
    989         async_answer_0(iid, EOK);
     992        ipc_answer_0(iid, EOK);
    990993}
    991994
     
    10131016{
    10141017        /* Accept connection */
    1015         async_answer_0(iid, EOK);
     1018        ipc_answer_0(iid, EOK);
    10161019       
    10171020        devmap_driver_t *driver = devmap_driver_register();
     
    10241027                ipc_callid_t callid = async_get_call(&call);
    10251028               
    1026                 switch (IPC_GET_IMETHOD(call)) {
     1029                switch (IPC_GET_METHOD(call)) {
    10271030                case IPC_M_PHONE_HUNGUP:
    10281031                        cont = false;
     
    10301033                case DEVMAP_DRIVER_UNREGISTER:
    10311034                        if (NULL == driver)
    1032                                 async_answer_0(callid, ENOENT);
     1035                                ipc_answer_0(callid, ENOENT);
    10331036                        else
    1034                                 async_answer_0(callid, EOK);
     1037                                ipc_answer_0(callid, EOK);
    10351038                        break;
    10361039                case DEVMAP_DEVICE_REGISTER:
     
    10491052                        break;
    10501053                default:
    1051                         async_answer_0(callid, ENOENT);
     1054                        ipc_answer_0(callid, ENOENT);
    10521055                }
    10531056        }
     
    10681071{
    10691072        /* Accept connection */
    1070         async_answer_0(iid, EOK);
     1073        ipc_answer_0(iid, EOK);
    10711074       
    10721075        bool cont = true;
     
    10751078                ipc_callid_t callid = async_get_call(&call);
    10761079               
    1077                 switch (IPC_GET_IMETHOD(call)) {
     1080                switch (IPC_GET_METHOD(call)) {
    10781081                case IPC_M_PHONE_HUNGUP:
    10791082                        cont = false;
     
    11071110                        break;
    11081111                default:
    1109                         async_answer_0(callid, ENOENT);
     1112                        ipc_answer_0(callid, ENOENT);
    11101113                }
    11111114        }
     
    11181121{
    11191122        /* Select interface */
    1120         switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
     1123        switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
    11211124        case DEVMAP_DRIVER:
    11221125                devmap_connection_driver(iid, icall);
     
    11311134        default:
    11321135                /* No such interface */
    1133                 async_answer_0(iid, ENOENT);
     1136                ipc_answer_0(iid, ENOENT);
    11341137        }
    11351138}
     
    11511154       
    11521155        /* 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)
    11541158                return -1;
    11551159       
Note: See TracChangeset for help on using the changeset viewer.