Ignore:
File:
1 edited

Legend:

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

    rffa2c8ef r7e752b2  
    7474       
    7575        iid = async_get_call(&icall);
    76         if (IPC_GET_IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) {
    77                 async_answer_0(iid, EREFUSED);
     76        if (IPC_GET_METHOD(icall) != DEVMAN_DRIVER_REGISTER) {
     77                ipc_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                 async_answer_0(iid, rc);
     86                ipc_answer_0(iid, rc);
    8787                return NULL;
    8888        }
     
    9898                free(drv_name);
    9999                drv_name = NULL;
    100                 async_answer_0(iid, ENOENT);
     100                ipc_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_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
    112                 async_answer_0(callid, ENOTSUP);
    113                 async_answer_0(iid, ENOTSUP);
     111        if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) {
     112                ipc_answer_0(callid, ENOTSUP);
     113                ipc_answer_0(iid, ENOTSUP);
    114114                return NULL;
    115115        }
     
    121121            driver->name);
    122122       
    123         async_answer_0(callid, EOK);
    124         async_answer_0(iid, EOK);
     123        ipc_answer_0(callid, EOK);
     124        ipc_answer_0(iid, EOK);
    125125       
    126126        return driver;
     
    141141       
    142142        callid = async_get_call(&call);
    143         if (DEVMAN_ADD_MATCH_ID != IPC_GET_IMETHOD(call)) {
     143        if (DEVMAN_ADD_MATCH_ID != IPC_GET_METHOD(call)) {
    144144                printf(NAME ": ERROR: devman_receive_match_id - invalid "
    145145                    "protocol.\n");
    146                 async_answer_0(callid, EINVAL);
     146                ipc_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                 async_answer_0(callid, ENOMEM);
     154                ipc_answer_0(callid, ENOMEM);
    155155                return ENOMEM;
    156156        }
    157157       
    158         async_answer_0(callid, EOK);
     158        ipc_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(sysarg_t match_count,
     186static int devman_receive_match_ids(ipcarg_t match_count,
    187187    match_id_list_t *match_ids)
    188188{
     
    197197}
    198198
    199 static 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 
    206199/** Handle child device registration.
    207200 *
     
    211204{
    212205        devman_handle_t parent_handle = IPC_GET_ARG1(*call);
    213         sysarg_t match_count = IPC_GET_ARG2(*call);
     206        ipcarg_t match_count = IPC_GET_ARG2(*call);
    214207        dev_tree_t *tree = &device_tree;
    215208       
     
    219212        if (parent == NULL) {
    220213                fibril_rwlock_write_unlock(&tree->rwlock);
    221                 async_answer_0(callid, ENOENT);
     214                ipc_answer_0(callid, ENOENT);
    222215                return;
    223216        }
     
    227220        if (rc != EOK) {
    228221                fibril_rwlock_write_unlock(&tree->rwlock);
    229                 async_answer_0(callid, rc);
     222                ipc_answer_0(callid, rc);
    230223                return;
    231224        }
     
    235228                fibril_rwlock_write_unlock(&tree->rwlock);
    236229                delete_dev_node(node);
    237                 async_answer_0(callid, ENOMEM);
     230                ipc_answer_0(callid, ENOMEM);
    238231                return;
    239232        }
     
    244237       
    245238        devman_receive_match_ids(match_count, &node->match_ids);
    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 
     239       
    265240        /* Return device handle to parent's driver. */
    266         async_answer_1(callid, EOK, node->handle);
     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);
    267245}
    268246
     
    281259         * handle.
    282260         */
    283         devmap_device_register_with_iface(devmap_pathname,
    284             &cli->devmap_handle, DEVMAN_CONNECT_FROM_DEVMAP);
     261        devmap_device_register(devmap_pathname, &cli->devmap_handle);
    285262       
    286263        /*
     
    302279            0, 0, 0, 0);
    303280        if (rc != EOK) {
    304                 async_answer_0(callid, rc);
     281                ipc_answer_0(callid, rc);
    305282                return;
    306283        }       
     
    308285        node_t *dev = find_dev_node(&device_tree, handle);
    309286        if (dev == NULL) {
    310                 async_answer_0(callid, ENOENT);
     287                ipc_answer_0(callid, ENOENT);
    311288                return;
    312289        }
     
    320297        printf(NAME ": device '%s' added to class '%s', class name '%s' was "
    321298            "asigned to it\n", dev->pathname, class_name, class_info->dev_name);
    322 
    323         async_answer_0(callid, EOK);
     299       
     300        ipc_answer_0(callid, EOK);
    324301}
    325302
     
    343320{
    344321        /* Accept the connection. */
    345         async_answer_0(iid, EOK);
     322        ipc_answer_0(iid, EOK);
    346323       
    347324        driver_t *driver = devman_driver_register();
     
    368345                callid = async_get_call(&call);
    369346               
    370                 switch (IPC_GET_IMETHOD(call)) {
     347                switch (IPC_GET_METHOD(call)) {
    371348                case IPC_M_PHONE_HUNGUP:
    372349                        cont = false;
     
    379356                        break;
    380357                default:
    381                         async_answer_0(callid, EINVAL);
     358                        ipc_answer_0(callid, EINVAL);
    382359                        break;
    383360                }
     
    393370        int rc = async_data_write_accept((void **) &pathname, true, 0, 0, 0, 0);
    394371        if (rc != EOK) {
    395                 async_answer_0(iid, rc);
     372                ipc_answer_0(iid, rc);
    396373                return;
    397374        }
     
    402379
    403380        if (dev == NULL) {
    404                 async_answer_0(iid, ENOENT);
    405                 return;
    406         }
    407        
    408         async_answer_1(iid, EOK, dev->handle);
     381                ipc_answer_0(iid, ENOENT);
     382                return;
     383        }
     384       
     385        ipc_answer_1(iid, EOK, dev->handle);
    409386}
    410387
     
    414391{
    415392        /* Accept connection. */
    416         async_answer_0(iid, EOK);
     393        ipc_answer_0(iid, EOK);
    417394       
    418395        bool cont = true;
     
    421398                ipc_callid_t callid = async_get_call(&call);
    422399               
    423                 switch (IPC_GET_IMETHOD(call)) {
     400                switch (IPC_GET_METHOD(call)) {
    424401                case IPC_M_PHONE_HUNGUP:
    425402                        cont = false;
     
    429406                        break;
    430407                default:
    431                         async_answer_0(callid, ENOENT);
     408                        ipc_answer_0(callid, ENOENT);
    432409                }
    433410        }
     
    443420                printf(NAME ": devman_forward error - no device with handle %" PRIun
    444421                    " was found.\n", handle);
    445                 async_answer_0(iid, ENOENT);
     422                ipc_answer_0(iid, ENOENT);
    446423                return;
    447424        }
     
    460437                printf(NAME ": devman_forward error - the device is not in %" PRIun
    461438                    " usable state.\n", handle);
    462                 async_answer_0(iid, ENOENT);
     439                ipc_answer_0(iid, ENOENT);
    463440                return;
    464441        }
     
    474451                    driver->name);
    475452                printf("the driver's phone is %" PRIun ").\n", driver->phone);
    476                 async_answer_0(iid, EINVAL);
     453                ipc_answer_0(iid, EINVAL);
    477454                return;
    478455        }
     
    480457        printf(NAME ": devman_forward: forward connection to device %s to "
    481458            "driver %s.\n", dev->pathname, driver->name);
    482         async_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);
     459        ipc_forward_fast(iid, driver->phone, method, dev->handle, 0, IPC_FF_NONE);
    483460}
    484461
     
    487464static void devman_connection_devmapper(ipc_callid_t iid, ipc_call_t *icall)
    488465{
    489         devmap_handle_t devmap_handle = IPC_GET_ARG2(*icall);
     466        devmap_handle_t devmap_handle = IPC_GET_METHOD(*icall);
    490467        node_t *dev;
    491468
     
    495472       
    496473        if (dev == NULL || dev->drv == NULL) {
    497                 async_answer_0(iid, ENOENT);
     474                ipc_answer_0(iid, ENOENT);
    498475                return;
    499476        }
    500477       
    501478        if (dev->state != DEVICE_USABLE || dev->drv->phone <= 0) {
    502                 async_answer_0(iid, EINVAL);
    503                 return;
    504         }
    505        
    506         async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,
     479                ipc_answer_0(iid, EINVAL);
     480                return;
     481        }
     482       
     483        printf(NAME ": devman_connection_devmapper: forward connection to "
     484            "device %s to driver %s.\n", dev->pathname, dev->drv->name);
     485        ipc_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, dev->handle, 0,
    507486            IPC_FF_NONE);
    508         printf(NAME ": devman_connection_devmapper: forwarded connection to "
    509             "device %s to driver %s.\n", dev->pathname, dev->drv->name);
    510487}
    511488
     
    513490static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
    514491{
     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       
    515510        /* Select interface. */
    516         switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
     511        switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
    517512        case DEVMAN_DRIVER:
    518513                devman_connection_driver(iid, icall);
     
    525520                devman_forward(iid, icall, false);
    526521                break;
    527         case DEVMAN_CONNECT_FROM_DEVMAP:
    528                 /* Someone connected through devmap node. */
    529                 devman_connection_devmapper(iid, icall);
    530                 break;
    531522        case DEVMAN_CONNECT_TO_PARENTS_DEVICE:
    532523                /* Connect client to selected device. */
     
    535526        default:
    536527                /* No such interface */
    537                 async_answer_0(iid, ENOENT);
     528                ipc_answer_0(iid, ENOENT);
    538529        }
    539530}
     
    586577
    587578        /* Register device manager at naming service. */
    588         if (service_register(SERVICE_DEVMAN) != EOK)
     579        ipcarg_t phonead;
     580        if (ipc_connect_to_me(PHONE_NS, SERVICE_DEVMAN, 0, 0, &phonead) != 0)
    589581                return -1;
    590582
Note: See TracChangeset for help on using the changeset viewer.