Ignore:
File:
1 edited

Legend:

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

    r991f645 r01b87dc5  
    4646#include <str.h>
    4747#include <ipc/devmap.h>
     48#include <assert.h>
    4849
    4950#define NAME          "devmap"
     
    6162        link_t devices;
    6263        /** Phone asociated with this driver */
    63         ipcarg_t phone;
     64        sysarg_t phone;
    6465        /** Device driver name */
    6566        char *name;
     
    99100        /** Device driver handling this device */
    100101        devmap_driver_t *driver;
     102        /** Use this interface when forwarding to driver. */
     103        sysarg_t forward_interface;
    101104} devmap_device_t;
    102105
     
    206209}
    207210
    208 /** Find namespace with given name.
    209  *
    210  * The devices_list_mutex should be already held when
    211  * calling this function.
    212  *
    213  */
     211/** Find namespace with given name. */
    214212static devmap_namespace_t *devmap_namespace_find_name(const char *name)
    215213{
    216214        link_t *item;
     215       
     216        assert(fibril_mutex_is_locked(&devices_list_mutex));
     217       
    217218        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    218219                devmap_namespace_t *namespace =
     
    227228/** Find namespace with given handle.
    228229 *
    229  * The devices_list_mutex should be already held when
    230  * calling this function.
    231  *
    232230 * @todo: use hash table
    233231 *
     
    236234{
    237235        link_t *item;
     236       
     237        assert(fibril_mutex_is_locked(&devices_list_mutex));
     238       
    238239        for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
    239240                devmap_namespace_t *namespace =
     
    246247}
    247248
    248 /** Find device with given name.
    249  *
    250  * The devices_list_mutex should be already held when
    251  * calling this function.
    252  *
    253  */
     249/** Find device with given name. */
    254250static devmap_device_t *devmap_device_find_name(const char *ns_name,
    255251    const char *name)
    256252{
    257253        link_t *item;
     254       
     255        assert(fibril_mutex_is_locked(&devices_list_mutex));
     256       
    258257        for (item = devices_list.next; item != &devices_list; item = item->next) {
    259258                devmap_device_t *device =
     
    269268/** Find device with given handle.
    270269 *
    271  * The devices_list_mutex should be already held when
    272  * calling this function.
    273  *
    274270 * @todo: use hash table
    275271 *
     
    278274{
    279275        link_t *item;
     276       
     277        assert(fibril_mutex_is_locked(&devices_list_mutex));
     278       
    280279        for (item = devices_list.next; item != &devices_list; item = item->next) {
    281280                devmap_device_t *device =
     
    288287}
    289288
    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  */
     289/** Create a namespace (if not already present). */
    296290static devmap_namespace_t *devmap_namespace_create(const char *ns_name)
    297291{
    298         devmap_namespace_t *namespace = devmap_namespace_find_name(ns_name);
     292        devmap_namespace_t *namespace;
     293       
     294        assert(fibril_mutex_is_locked(&devices_list_mutex));
     295       
     296        namespace = devmap_namespace_find_name(ns_name);
    299297        if (namespace != NULL)
    300298                return namespace;
     
    321319}
    322320
    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  */
     321/** Destroy a namespace (if it is no longer needed). */
    329322static void devmap_namespace_destroy(devmap_namespace_t *namespace)
    330323{
     324        assert(fibril_mutex_is_locked(&devices_list_mutex));
     325
    331326        if (namespace->refcnt == 0) {
    332327                list_remove(&(namespace->namespaces));
     
    337332}
    338333
    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  */
     334/** Increase namespace reference count by including device. */
    345335static void devmap_namespace_addref(devmap_namespace_t *namespace,
    346336    devmap_device_t *device)
    347337{
     338        assert(fibril_mutex_is_locked(&devices_list_mutex));
     339
    348340        device->namespace = namespace;
    349341        namespace->refcnt++;
    350342}
    351343
    352 /** Decrease namespace reference count
    353  *
    354  * The devices_list_mutex should be already held when
    355  * calling this function.
    356  *
    357  */
     344/** Decrease namespace reference count. */
    358345static void devmap_namespace_delref(devmap_namespace_t *namespace)
    359346{
     347        assert(fibril_mutex_is_locked(&devices_list_mutex));
     348
    360349        namespace->refcnt--;
    361350        devmap_namespace_destroy(namespace);
    362351}
    363352
    364 /** Unregister device and free it
    365  *
    366  * The devices_list_mutex should be already held when
    367  * calling this function.
    368  *
    369  */
     353/** Unregister device and free it. */
    370354static void devmap_device_unregister_core(devmap_device_t *device)
    371355{
     356        assert(fibril_mutex_is_locked(&devices_list_mutex));
     357
    372358        devmap_namespace_delref(device->namespace);
    373359        list_remove(&(device->devices));
     
    387373        ipc_callid_t iid = async_get_call(&icall);
    388374       
    389         if (IPC_GET_METHOD(icall) != DEVMAP_DRIVER_REGISTER) {
     375        if (IPC_GET_IMETHOD(icall) != DEVMAP_DRIVER_REGISTER) {
    390376                ipc_answer_0(iid, EREFUSED);
    391377                return NULL;
     
    416402        ipc_callid_t callid = async_get_call(&call);
    417403       
    418         if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
     404        if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
    419405                free(driver->name);
    420406                free(driver);
     
    517503        }
    518504       
     505        /* Set the interface, if any. */
     506        device->forward_interface = IPC_GET_ARG1(*icall);
     507
    519508        /* Get fqdn */
    520509        char *fqdn;
     
    555544        if (devmap_device_find_name(namespace->name, device->name) != NULL) {
    556545                printf("%s: Device '%s/%s' already registered\n", NAME,
    557                     device->namespace, device->name);
     546                    device->namespace->name, device->name);
    558547                devmap_namespace_destroy(namespace);
    559548                fibril_mutex_unlock(&devices_list_mutex);
     
    566555        /* Get unique device handle */
    567556        device->handle = devmap_create_handle();
    568        
     557
    569558        devmap_namespace_addref(namespace, device);
    570559        device->driver = driver;
     
    617606        }
    618607       
    619         ipc_forward_fast(callid, dev->driver->phone, dev->handle,
    620             IPC_GET_ARG3(*call), 0, IPC_FF_NONE);
     608        if (dev->forward_interface == 0) {
     609                ipc_forward_fast(callid, dev->driver->phone,
     610                    dev->handle, 0, 0,
     611                    IPC_FF_NONE);
     612        } else {
     613                ipc_forward_fast(callid, dev->driver->phone,
     614                    dev->forward_interface, dev->handle, 0,
     615                    IPC_FF_NONE);
     616        }
    621617       
    622618        fibril_mutex_unlock(&devices_list_mutex);
     
    823819        }
    824820       
    825         ipcarg_t retval = async_data_read_finalize(callid, desc, size);
     821        sysarg_t retval = async_data_read_finalize(callid, desc, size);
    826822       
    827823        free(desc);
     
    890886        }
    891887       
    892         ipcarg_t retval = async_data_read_finalize(callid, desc, size);
     888        sysarg_t retval = async_data_read_finalize(callid, desc, size);
    893889       
    894890        free(desc);
     
    964960        fibril_mutex_unlock(&null_devices_mutex);
    965961       
    966         ipc_answer_1(iid, EOK, (ipcarg_t) i);
     962        ipc_answer_1(iid, EOK, (sysarg_t) i);
    967963}
    968964
    969965static void devmap_null_destroy(ipc_callid_t iid, ipc_call_t *icall)
    970966{
    971         ipcarg_t i = IPC_GET_ARG1(*icall);
     967        sysarg_t i = IPC_GET_ARG1(*icall);
    972968        if (i >= NULL_DEVICES) {
    973969                ipc_answer_0(iid, ELIMIT);
     
    10271023                ipc_callid_t callid = async_get_call(&call);
    10281024               
    1029                 switch (IPC_GET_METHOD(call)) {
     1025                switch (IPC_GET_IMETHOD(call)) {
    10301026                case IPC_M_PHONE_HUNGUP:
    10311027                        cont = false;
     
    10521048                        break;
    10531049                default:
    1054                         if (!(callid & IPC_CALLID_NOTIFICATION))
    1055                                 ipc_answer_0(callid, ENOENT);
     1050                        ipc_answer_0(callid, ENOENT);
    10561051                }
    10571052        }
     
    10791074                ipc_callid_t callid = async_get_call(&call);
    10801075               
    1081                 switch (IPC_GET_METHOD(call)) {
     1076                switch (IPC_GET_IMETHOD(call)) {
    10821077                case IPC_M_PHONE_HUNGUP:
    10831078                        cont = false;
     
    11111106                        break;
    11121107                default:
    1113                         if (!(callid & IPC_CALLID_NOTIFICATION))
    1114                                 ipc_answer_0(callid, ENOENT);
     1108                        ipc_answer_0(callid, ENOENT);
    11151109                }
    11161110        }
     
    11231117{
    11241118        /* Select interface */
    1125         switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
     1119        switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
    11261120        case DEVMAP_DRIVER:
    11271121                devmap_connection_driver(iid, icall);
     
    11561150       
    11571151        /* Register device mapper at naming service */
    1158         ipcarg_t phonead;
     1152        sysarg_t phonead;
    11591153        if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAP, 0, 0, &phonead) != 0)
    11601154                return -1;
Note: See TracChangeset for help on using the changeset viewer.