Changeset 79ae36dd in mainline for uspace/srv/devman


Ignore:
Timestamp:
2011-06-08T19:01:55Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0eff68e
Parents:
764d71e
Message:

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
Location:
uspace/srv/devman
Files:
3 edited

Legend:

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

    r764d71e r79ae36dd  
    564564        dev_node_t *dev;
    565565        link_t *link;
    566         int phone;
    567566
    568567        log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     
    570569
    571570        fibril_mutex_lock(&driver->driver_mutex);
    572 
    573         phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
    574 
    575         if (phone < 0) {
     571       
     572        async_exch_t *exch = async_exchange_begin(driver->sess);
     573        async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,
     574            DRIVER_DEVMAN, 0, 0);
     575        async_exchange_end(exch);
     576
     577        if (!sess) {
    576578                fibril_mutex_unlock(&driver->driver_mutex);
    577579                return;
     
    602604                fibril_mutex_unlock(&driver->driver_mutex);
    603605
    604                 add_device(phone, driver, dev, tree);
     606                add_device(sess, driver, dev, tree);
    605607
    606608                /*
     
    623625        }
    624626
    625         async_hangup(phone);
     627        async_hangup(sess);
    626628
    627629        /*
     
    673675        list_initialize(&drv->devices);
    674676        fibril_mutex_initialize(&drv->driver_mutex);
    675         drv->phone = -1;
     677        drv->sess = NULL;
    676678}
    677679
     
    737739 * @param node          The device's node in the device tree.
    738740 */
    739 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
     741void add_device(async_sess_t *sess, driver_t *drv, dev_node_t *dev,
     742    dev_tree_t *tree)
    740743{
    741744        /*
     
    746749            drv->name, dev->pfun->name);
    747750       
    748         sysarg_t rc;
    749         ipc_call_t answer;
    750        
    751751        /* Send the device to the driver. */
    752752        devman_handle_t parent_handle;
     
    756756                parent_handle = 0;
    757757        }
    758 
    759         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
     758       
     759        async_exch_t *exch = async_exchange_begin(sess);
     760       
     761        ipc_call_t answer;
     762        aid_t req = async_send_2(exch, DRIVER_ADD_DEVICE, dev->handle,
    760763            parent_handle, &answer);
    761764       
    762         /* Send the device's name to the driver. */
    763         rc = async_data_write_start(phone, dev->pfun->name,
     765        /* Send the device name to the driver. */
     766        sysarg_t rc = async_data_write_start(exch, dev->pfun->name,
    764767            str_size(dev->pfun->name) + 1);
     768       
     769        async_exchange_end(exch);
     770       
    765771        if (rc != EOK) {
    766772                /* TODO handle error */
     
    823829        if (is_running) {
    824830                /* Notify the driver about the new device. */
    825                 int phone = async_connect_me_to(drv->phone, DRIVER_DEVMAN, 0, 0);
    826                 if (phone >= 0) {
    827                         add_device(phone, drv, dev, tree);
    828                         async_hangup(phone);
     831                async_exch_t *exch = async_exchange_begin(drv->sess);
     832                async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,
     833                    DRIVER_DEVMAN, 0, 0);
     834                async_exchange_end(exch);
     835               
     836                if (sess) {
     837                        add_device(sess, drv, dev, tree);
     838                        async_hangup(sess);
    829839                }
    830840        }
  • uspace/srv/devman/devman.h

    r764d71e r79ae36dd  
    4444#include <fibril_synch.h>
    4545#include <atomic.h>
     46#include <async.h>
    4647
    4748#include "util.h"
     
    8788        int state;
    8889       
    89         /** Phone asociated with this driver. */
    90         int phone;
     90        /** Session asociated with this driver. */
     91        async_sess_t *sess;
    9192        /** Name of the device driver. */
    9293        char *name;
     
    99100       
    100101        /**
    101          * Fibril mutex for this driver - driver state, list of devices, phone.
     102         * Fibril mutex for this driver - driver state, list of devices, session.
    102103         */
    103104        fibril_mutex_t driver_mutex;
     
    312313extern void add_driver(driver_list_t *, driver_t *);
    313314extern void attach_driver(dev_node_t *, driver_t *);
    314 extern void add_device(int, driver_t *, dev_node_t *, dev_tree_t *);
     315extern void add_device(async_sess_t *, driver_t *, dev_node_t *, dev_tree_t *);
    315316extern bool start_driver(driver_t *);
    316317
  • uspace/srv/devman/main.c

    r764d71e r79ae36dd  
    3939#include <assert.h>
    4040#include <ipc/services.h>
    41 #include <ipc/ns.h>
     41#include <ns.h>
    4242#include <async.h>
    4343#include <stdio.h>
     
    108108        fibril_mutex_lock(&driver->driver_mutex);
    109109       
    110         if (driver->phone >= 0) {
     110        if (driver->sess) {
    111111                /* We already have a connection to the driver. */
    112112                log_msg(LVL_ERROR, "Driver '%s' already started.\n",
     
    128128                break;
    129129        case DRIVER_RUNNING:
    130                 /* Should not happen since we do not have a connected phone */
     130                /* Should not happen since we do not have a connected session */
    131131                assert(false);
    132132        }
     
    135135        log_msg(LVL_DEBUG, "Creating connection to the `%s' driver.",
    136136            driver->name);
    137         ipc_call_t call;
    138         ipc_callid_t callid = async_get_call(&call);
    139         if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
     137        driver->sess = async_callback_receive(EXCHANGE_SERIALIZE);
     138        if (!driver->sess) {
    140139                fibril_mutex_unlock(&driver->driver_mutex);
    141                 async_answer_0(callid, ENOTSUP);
    142140                async_answer_0(iid, ENOTSUP);
    143141                return NULL;
    144142        }
    145143       
    146         /* Remember driver's phone. */
    147         driver->phone = IPC_GET_ARG5(call);
    148        
    149144        fibril_mutex_unlock(&driver->driver_mutex);
    150145       
    151         log_msg(LVL_NOTE, 
     146        log_msg(LVL_NOTE,
    152147            "The `%s' driver was successfully registered as running.",
    153148            driver->name);
    154149       
    155         async_answer_0(callid, EOK);
    156150        async_answer_0(iid, EOK);
    157151       
     
    434428        fibril_add_ready(fid);
    435429       
    436         ipc_callid_t callid;
    437         ipc_call_t call;
    438         bool cont = true;
    439         while (cont) {
    440                 callid = async_get_call(&call);
     430        while (true) {
     431                ipc_call_t call;
     432                ipc_callid_t callid = async_get_call(&call);
     433               
     434                if (!IPC_GET_IMETHOD(call))
     435                        break;
    441436               
    442437                switch (IPC_GET_IMETHOD(call)) {
    443                 case IPC_M_PHONE_HUNGUP:
    444                         cont = false;
    445                         continue;
    446438                case DEVMAN_ADD_FUNCTION:
    447439                        devman_add_function(callid, &call);
     
    559551        async_answer_0(iid, EOK);
    560552       
    561         bool cont = true;
    562         while (cont) {
     553        while (true) {
    563554                ipc_call_t call;
    564555                ipc_callid_t callid = async_get_call(&call);
    565556               
     557                if (!IPC_GET_IMETHOD(call))
     558                        break;
     559               
    566560                switch (IPC_GET_IMETHOD(call)) {
    567                 case IPC_M_PHONE_HUNGUP:
    568                         cont = false;
    569                         continue;
    570561                case DEVMAN_DEVICE_GET_HANDLE:
    571562                        devman_function_get_handle(callid, &call);
     
    635626        if (driver == NULL) {
    636627                log_msg(LVL_ERROR, "IPC forwarding refused - " \
    637                     "the device %" PRIun "(%s) is not in usable state.",
    638                     handle, dev->pfun->pathname);
     628                    "the device %" PRIun " is not in usable state.", handle);
    639629                async_answer_0(iid, ENOENT);
    640630                return;
     
    647637                method = DRIVER_CLIENT;
    648638       
    649         if (driver->phone < 0) {
    650                 log_msg(LVL_ERROR,
    651                     "Could not forward to driver `%s' (phone is %d).",
    652                     driver->name, (int) driver->phone);
     639        if (!driver->sess) {
     640                log_msg(LVL_ERROR,
     641                    "Could not forward to driver `%s'.", driver->name);
    653642                async_answer_0(iid, EINVAL);
    654643                return;
     
    664653                    dev->pfun->pathname, driver->name);
    665654        }
    666 
    667         async_forward_fast(iid, driver->phone, method, fwd_h, 0, IPC_FF_NONE);
     655       
     656        async_exch_t *exch = async_exchange_begin(driver->sess);
     657        async_forward_fast(iid, exch, method, fwd_h, 0, IPC_FF_NONE);
     658        async_exchange_end(exch);
    668659}
    669660
     
    687678        dev = fun->dev;
    688679       
    689         if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {
     680        if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {
    690681                async_answer_0(iid, EINVAL);
    691682                return;
    692683        }
    693684       
    694         async_forward_fast(iid, dev->drv->phone, DRIVER_CLIENT, fun->handle, 0,
     685        async_exch_t *exch = async_exchange_begin(dev->drv->sess);
     686        async_forward_fast(iid, exch, DRIVER_CLIENT, fun->handle, 0,
    695687            IPC_FF_NONE);
    696         log_msg(LVL_DEBUG,
     688        async_exchange_end(exch);
     689       
     690        log_msg(LVL_DEBUG,
    697691            "Forwarding devmapper request for `%s' function to driver `%s'.",
    698692            fun->pathname, dev->drv->name);
     
    786780
    787781        printf(NAME ": Accepting connections.\n");
     782        task_retval(0);
    788783        async_manager();
    789784
Note: See TracChangeset for help on using the changeset viewer.