Ignore:
File:
1 edited

Legend:

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

    r422722e r7beb220  
    6565static dev_tree_t device_tree;
    6666
    67 static int init_running_drv(void *drv);
    68 
    6967/** Register running driver. */
    70 static driver_t *devman_driver_register(ipc_callid_t callid, ipc_call_t *call)
    71 {
     68static driver_t *devman_driver_register(void)
     69{
     70        ipc_call_t icall;
     71        ipc_callid_t iid;
    7272        driver_t *driver = NULL;
     73
     74        log_msg(LVL_DEBUG, "devman_driver_register");
     75       
     76        iid = async_get_call(&icall);
     77        if (IPC_GET_IMETHOD(icall) != DEVMAN_DRIVER_REGISTER) {
     78                async_answer_0(iid, EREFUSED);
     79                return NULL;
     80        }
     81       
    7382        char *drv_name = NULL;
    74 
    75         log_msg(LVL_DEBUG, "devman_driver_register");
    7683       
    7784        /* Get driver name. */
    7885        int rc = async_data_write_accept((void **) &drv_name, true, 0, 0, 0, 0);
    7986        if (rc != EOK) {
    80                 async_answer_0(callid, rc);
     87                async_answer_0(iid, rc);
    8188                return NULL;
    8289        }
     
    9198                free(drv_name);
    9299                drv_name = NULL;
    93                 async_answer_0(callid, ENOENT);
     100                async_answer_0(iid, ENOENT);
    94101                return NULL;
    95102        }
     
    105112                    driver->name);
    106113                fibril_mutex_unlock(&driver->driver_mutex);
    107                 async_answer_0(callid, EEXISTS);
     114                async_answer_0(iid, EEXISTS);
    108115                return NULL;
    109116        }
     
    127134        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
    128135            driver->name);
    129         driver->sess = async_callback_receive(EXCHANGE_PARALLEL);
     136        driver->sess = async_callback_receive(EXCHANGE_SERIALIZE);
    130137        if (!driver->sess) {
    131138                fibril_mutex_unlock(&driver->driver_mutex);
    132                 async_answer_0(callid, ENOTSUP);
     139                async_answer_0(iid, ENOTSUP);
    133140                return NULL;
    134141        }
    135         /* FIXME: Work around problem with callback sessions */
    136         async_sess_args_set(driver->sess, DRIVER_DEVMAN, 0, 0);
     142       
     143        fibril_mutex_unlock(&driver->driver_mutex);
    137144       
    138145        log_msg(LVL_NOTE,
     
    140147            driver->name);
    141148       
    142         /*
    143          * Initialize the driver as running (e.g. pass assigned devices to it)
    144          * in a separate fibril; the separate fibril is used to enable the
    145          * driver to use devman service during the driver's initialization.
    146          */
    147         fid_t fid = fibril_create(init_running_drv, driver);
    148         if (fid == 0) {
    149                 log_msg(LVL_ERROR, "Failed to create initialization fibril " \
    150                     "for driver `%s'.", driver->name);
    151                 fibril_mutex_unlock(&driver->driver_mutex);
    152                 async_answer_0(callid, ENOMEM);
    153                 return NULL;
    154         }
    155        
    156         fibril_add_ready(fid);
    157         fibril_mutex_unlock(&driver->driver_mutex);
    158        
    159         async_answer_0(callid, EOK);
     149        async_answer_0(iid, EOK);
     150       
    160151        return driver;
    161152}
     
    438429static void devman_connection_driver(ipc_callid_t iid, ipc_call_t *icall)
    439430{
    440         client_t *client;
    441         driver_t *driver;
    442        
    443431        /* Accept the connection. */
    444432        async_answer_0(iid, EOK);
    445433       
    446         client = async_get_client_data();
    447         if (client == NULL) {
    448                 log_msg(LVL_ERROR, "Failed to allocate client data.");
    449                 return;
    450         }
     434        driver_t *driver = devman_driver_register();
     435        if (driver == NULL)
     436                return;
     437       
     438        /*
     439         * Initialize the driver as running (e.g. pass assigned devices to it)
     440         * in a separate fibril; the separate fibril is used to enable the
     441         * driver to use devman service during the driver's initialization.
     442         */
     443        fid_t fid = fibril_create(init_running_drv, driver);
     444        if (fid == 0) {
     445                log_msg(LVL_ERROR, "Failed to create initialization fibril " \
     446                    "for driver `%s'.", driver->name);
     447                return;
     448        }
     449        fibril_add_ready(fid);
    451450       
    452451        while (true) {
     
    457456                        break;
    458457               
    459                 if (IPC_GET_IMETHOD(call) != DEVMAN_DRIVER_REGISTER) {
    460                         fibril_mutex_lock(&client->mutex);
    461                         driver = client->driver;
    462                         fibril_mutex_unlock(&client->mutex);
    463                         if (driver == NULL) {
    464                                 /* First call must be to DEVMAN_DRIVER_REGISTER */
    465                                 async_answer_0(callid, ENOTSUP);
    466                                 continue;
    467                         }
    468                 }
    469                
    470458                switch (IPC_GET_IMETHOD(call)) {
    471                 case DEVMAN_DRIVER_REGISTER:
    472                         fibril_mutex_lock(&client->mutex);
    473                         if (client->driver != NULL) {
    474                                 fibril_mutex_unlock(&client->mutex);
    475                                 async_answer_0(callid, EINVAL);
    476                                 continue;
    477                         }
    478                         client->driver = devman_driver_register(callid, &call);
    479                         fibril_mutex_unlock(&client->mutex);
    480                         break;
    481459                case DEVMAN_ADD_FUNCTION:
    482460                        devman_add_function(callid, &call);
     
    836814static void devman_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    837815{
    838         /* Select port. */
     816        /* Select interface. */
    839817        switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
    840818        case DEVMAN_DRIVER:
     
    862840}
    863841
    864 static void *devman_client_data_create(void)
    865 {
    866         client_t *client;
    867        
    868         client = calloc(1, sizeof(client_t));
    869         if (client == NULL)
    870                 return NULL;
    871        
    872         fibril_mutex_initialize(&client->mutex);
    873         return client;
    874 }
    875 
    876 static void devman_client_data_destroy(void *data)
    877 {
    878         free(data);
    879 }
    880 
    881842/** Initialize device manager internal structures. */
    882843static bool devman_init(void)
     
    925886        }
    926887       
    927         /* Set handlers for incoming connections. */
    928         async_set_client_data_constructor(devman_client_data_create);
    929         async_set_client_data_destructor(devman_client_data_destroy);
     888        /* Set a handler of incomming connections. */
    930889        async_set_client_connection(devman_connection);
    931890
Note: See TracChangeset for help on using the changeset viewer.