Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/devman/main.c

    r7e752b2 rffa2c8ef  
    7474       
    7575        iid = async_get_call(&icall);
    76         if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
    77                 ipc_answer_0(iid, EREFUSED);
     76        if (IPC_GET_IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) {
     77                async_answer_0(iid, EREFUSED);
    7878                return NULL;
    7979        }
     
    8484        int rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0);
    8585        if (rc != EOK) {
    86                 ipc_answer_0(iid, rc);
     86                async_answer_0(iid, rc);
    8787                return NULL;
    8888        }
     
    9898                free(drv_name);
    9999                drv_name = NULL;
    100                 ipc_answer_0(iid, ENOENT);
     100                async_answer_0(iid, ENOENT);
    101101                return NULL;
    102102        }
     
    109109        ipc_call_t call;
    110110        ipc_callid_t callid = async_get_call(&call);
    111         if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
    112                 ipc_answer_0(callid, ENOTSUP);
    113                 ipc_answer_0(iid, ENOTSUP);
     111        if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
     112                async_answer_0(callid, ENOTSUP);
     113                async_answer_0(iid, ENOTSUP);
    114114                return NULL;
    115115        }
     
    121121            driver->name);
    122122       
    123         ipc_answer_0(callid, EOK);
    124         ipc_answer_0(iid, EOK);
     123        async_answer_0(callid, EOK);
     124        async_answer_0(iid, EOK);
    125125       
    126126        return driver;
     
    141141       
    142142        callid = async_get_call(&call);
    143         if (DEVMAN_ADD_MATCH_ID != IPC_GET_METHOD(call)) {
     143        if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
    144144                printf(NAME ": ERROR: devman_receive_match_id - invalid "
    145145                    "protocol.\n");
    146                 ipc_answer_0(callid, EINVAL);
     146                async_answer_0(callid, EINVAL);
    147147                delete_match_id(match_id);
    148148                return EINVAL;
     
    152152                printf(NAME ": ERROR: devman_receive_match_id - failed to "
    153153                    "allocate match id.\n");
    154                 ipc_answer_0(callid, ENOMEM);
     154                async_answer_0(callid, ENOMEM);
    155155                return ENOMEM;
    156156        }
    157157       
    158         ipc_answer_0(callid, EOK);
     158        async_answer_0(callid, EOK);
    159159       
    160160        match_id->score = IPC_GET_ARG1(call);
     
    184184 * @return              Zero on success, negative error code otherwise.
    185185 */
    186 static int devman_receive_match_ids(ipcarg_t match_count,
     186static int devman_receive_match_ids(sysarg_t match_count,
    187187    match_id_list_t *match_ids)
    188188{
     
    197197}
    198198
     199static int assign_driver_fibril(void *arg)
     200{
     201        node_t *node = (node_t *) arg;
     202        assign_driver(node, &drivers_list, &device_tree);
     203        return EOK;
     204}
     205
    199206/** Handle child device registration.
    200207 *
     
    204211{
    205212        devman_handle_t parent_handle = IPC_GET_ARG1(*call);
    206         ipcarg_t match_count = IPC_GET_ARG2(*call);
     213        sysarg_t match_count = IPC_GET_ARG2(*call);
    207214        dev_tree_t *tree = &device_tree;
    208215       
     
    212219        if (parent == NULL) {
    213220                fibril_rwlock_write_unlock(&tree->rwlock);
    214                 ipc_answer_0(callid, ENOENT);
     221                async_answer_0(callid, ENOENT);
    215222                return;
    216223        }
     
    220227        if (rc != EOK) {
    221228                fibril_rwlock_write_unlock(&tree->rwlock);
    222                 ipc_answer_0(callid, rc);
     229                async_answer_0(callid, rc);
    223230                return;
    224231        }
     
    228235                fibril_rwlock_write_unlock(&tree->rwlock);
    229236                delete_dev_node(node);
    230                 ipc_answer_0(callid, ENOMEM);
     237                async_answer_0(callid, ENOMEM);
    231238                return;
    232239        }
     
    237244       
    238245        devman_receive_match_ids(match_count, &node->match_ids);
    239        
     246
     247        /*
     248         * Try to find a suitable driver and assign it to the device.  We do
     249         * not want to block the current fibril that is used for processing
     250         * incoming calls: we will launch a separate fibril to handle the
     251         * driver assigning. That is because assign_driver can actually include
     252         * task spawning which could take some time.
     253         */
     254        fid_t assign_fibril = fibril_create(assign_driver_fibril, node);
     255        if (assign_fibril == 0) {
     256                /*
     257                 * Fallback in case we are out of memory.
     258                 * Probably not needed as we will die soon anyway ;-).
     259                 */
     260                (void) assign_driver_fibril(node);
     261        } else {
     262                fibril_add_ready(assign_fibril);
     263        }
     264
    240265        /* Return device handle to parent's driver. */
    241         ipc_answer_1(callid, EOK, node->handle);
    242        
    243         /* Try to find suitable driver and assign it to the device. */
    244         assign_driver(node, &drivers_list, &device_tree);
     266        async_answer_1(callid, EOK, node->handle);
    245267}
    246268
     
    259281         * handle.
    260282         */
    261         devmap_device_register(devmap_pathname, &cli->devmap_handle);
     283        devmap_device_register_with_iface(devmap_pathname,
     284            &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
    262285       
    263286        /*
     
    279302            0, 0, 0, 0);
    280303        if (rc != EOK) {
    281                 ipc_answer_0(callid, rc);
     304                async_answer_0(callid, rc);
    282305                return;
    283306        }       
     
    285308        node_t *dev = find_dev_node(&device_tree, handle);
    286309        if (dev == NULL) {
    287                 ipc_answer_0(callid, ENOENT);
     310                async_answer_0(callid, ENOENT);
    288311                return;
    289312        }
     
    297320        printf(NAME ": device '%s' added to class '%s', class name '%s' was "
    298321            "asigned to it\n", dev->pathname, class_name, class_info->dev_name);
    299        
    300         ipc_answer_0(callid, EOK);
     322
     323        async_answer_0(callid, EOK);
    301324}
    302325
     
    320343{
    321344        /* Accept the connection. */
    322         ipc_answer_0(iid, EOK);
     345        async_answer_0(iid, EOK);
    323346       
    324347        driver_t *driver = devman_driver_register();
     
    345368                callid = async_get_call(&call);
    346369               
    347                 switch (IPC_GET_METHOD(call)) {
     370                switch (IPC_GET_IMETHOD(call)) {
    348371                case IPC_M_PHONE_HUNGUP:
    349372                        cont = false;
     
    356379                        break;
    357380                default:
    358                         ipc_answer_0(callid, EINVAL);
     381                        async_answer_0(callid, EINVAL);
    359382                        break;
    360383                }
     
    370393        int rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0);
    371394        if (rc != EOK) {
    372                 ipc_answer_0(iid, rc);
     395                async_answer_0(iid, rc);
    373396                return;
    374397        }
     
    379402
    380403        if (dev == NULL) {
    381                 ipc_answer_0(iid, ENOENT);
    382                 return;
    383         }
    384        
    385         ipc_answer_1(iid, EOK, dev->handle);
     404                async_answer_0(iid, ENOENT);
     405                return;
     406        }
     407       
     408        async_answer_1(iid, EOK, dev->handle);
    386409}
    387410
     
    391414{
    392415        /* Accept connection. */
    393         ipc_answer_0(iid, EOK);
     416        async_answer_0(iid, EOK);
    394417       
    395418        bool cont = true;
     
    398421                ipc_callid_t callid = async_get_call(&call);
    399422               
    400                 switch (IPC_GET_METHOD(call)) {
     423                switch (IPC_GET_IMETHOD(call)) {
    401424                case IPC_M_PHONE_HUNGUP:
    402425                        cont = false;
     
    406429                        break;
    407430                default:
    408                         ipc_answer_0(callid, ENOENT);
     431                        async_answer_0(callid, ENOENT);
    409432                }
    410433        }
     
    420443                printf(NAME ": devman_forward error - no device with handle %" PRIun
    421444                    " was found.\n", handle);
    422                 ipc_answer_0(iid, ENOENT);
     445                async_answer_0(iid, ENOENT);
    423446                return;
    424447        }
     
    437460                printf(NAME ": devman_forward error - the device is not in %" PRIun
    438461                    " usable state.\n", handle);
    439                 ipc_answer_0(iid, ENOENT);
     462                async_answer_0(iid, ENOENT);
    440463                return;
    441464        }
     
    451474                    driver->name);
    452475                printf("the driver's phone is %" PRIun ").\n", driver->phone);
    453                 ipc_answer_0(iid, EINVAL);
     476                async_answer_0(iid, EINVAL);
    454477                return;
    455478        }
     
    457480        printf(NAME ": devman_forward: forward connection to device %s to "
    458481            "driver %s.\n", dev->pathname, driver->name);
    459         ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);
     482        async_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);
    460483}
    461484
     
    464487static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall)
    465488{
    466         devmap_handle_t devmap_handle = IPC_GET_METHOD(*icall);
     489        devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
    467490        node_t *dev;
    468491
     
    472495       
    473496        if (dev == NULL || dev->drv == NULL) {
    474                 ipc_answer_0(iid, ENOENT);
     497                async_answer_0(iid, ENOENT);
    475498                return;
    476499        }
    477500       
    478501        if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
    479                 ipc_answer_0(iid, EINVAL);
    480                 return;
    481         }
    482        
    483         printf(NAME ": devman_connection_devmapper: forward connection to "
     502                async_answer_0(iid, EINVAL);
     503                return;
     504        }
     505       
     506        async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,
     507            IPC_FF_NONE);
     508        printf(NAME ": devman_connection_devmapper: forwarded connection to "
    484509            "device %s to driver %s.\n", dev->pathname, dev->drv->name);
    485         ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,
    486             IPC_FF_NONE);
    487510}
    488511
     
    490513static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
    491514{
    492         /*
    493          * Silly hack to enable the device manager to register as a driver by
    494          * the device mapper. If the ipc method is not IPC_M_CONNECT_ME_TO, this
    495          * is not the forwarded connection from naming service, so it must be a
    496          * connection from the devmapper which thinks this is a devmapper-style
    497          * driver. So pretend this is a devmapper-style driver. (This does not
    498          * work for device with handle == IPC_M_CONNECT_ME_TO, because devmapper
    499          * passes device handle to the driver as an ipc method.)
    500          */
    501         if (IPC_GET_METHOD(*icall) != IPC_M_CONNECT_ME_TO)
    502                 devman_connection_devmapper(iid, icall);
    503 
    504         /*
    505          * ipc method is IPC_M_CONNECT_ME_TO, so this is forwarded connection
    506          * from naming service by which we registered as device manager, so be
    507          * device manager.
    508          */
    509        
    510515        /* Select interface. */
    511         switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
     516        switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
    512517        case DEVMAN_DRIVER:
    513518                devman_connection_driver(iid, icall);
     
    520525                devman_forward(iid, icall, false);
    521526                break;
     527        case DEVMAN_CONNECT_FROM_DEVMAP:
     528                /* Someone connected through devmap node. */
     529                devman_connection_devmapper(iid, icall);
     530                break;
    522531        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
    523532                /* Connect client to selected device. */
     
    526535        default:
    527536                /* No such interface */
    528                 ipc_answer_0(iid, ENOENT);
     537                async_answer_0(iid, ENOENT);
    529538        }
    530539}
     
    577586
    578587        /* Register device manager at naming service. */
    579         ipcarg_t phonead;
    580         if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
     588        if (service_register(SERVICE_DEVMAN) != EOK)
    581589                return -1;
    582590
Note: See TracChangeset for help on using the changeset viewer.