Changeset 6a44ee4 in mainline for uspace/srv/devman


Ignore:
Timestamp:
2011-07-20T15:26:21Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
efcebe1
Parents:
25bef0ff (diff), a701812 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge mainline changes.

Location:
uspace/srv/devman
Files:
4 edited

Legend:

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

    r25bef0ff r6a44ee4  
    466466        fibril_mutex_lock(&drivers_list->drivers_mutex);
    467467       
    468         link_t *link = drivers_list->drivers.next;
    469         while (link != &drivers_list->drivers) {
     468        list_foreach(drivers_list->drivers, link) {
    470469                drv = list_get_instance(link, driver_t, drivers);
    471470                score = get_match_score(drv, node);
     
    474473                        best_drv = drv;
    475474                }
    476                 link = link->next;
    477475        }
    478476       
     
    536534        driver_t *res = NULL;
    537535        driver_t *drv = NULL;
    538         link_t *link;
    539536       
    540537        fibril_mutex_lock(&drv_list->drivers_mutex);
    541538       
    542         link = drv_list->drivers.next;
    543         while (link != &drv_list->drivers) {
     539        list_foreach(drv_list->drivers, link) {
    544540                drv = list_get_instance(link, driver_t, drivers);
    545541                if (str_cmp(drv->name, drv_name) == 0) {
     
    547543                        break;
    548544                }
    549 
    550                 link = link->next;
    551545        }
    552546       
     
    564558        dev_node_t *dev;
    565559        link_t *link;
    566         int phone;
    567560
    568561        log_msg(LVL_DEBUG, "pass_devices_to_driver(driver=\"%s\")",
     
    570563
    571564        fibril_mutex_lock(&driver->driver_mutex);
    572 
    573         phone = async_connect_me_to(driver->phone, DRIVER_DEVMAN, 0, 0);
    574 
    575         if (phone < 0) {
     565       
     566        async_exch_t *exch = async_exchange_begin(driver->sess);
     567        async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,
     568            DRIVER_DEVMAN, 0, 0);
     569        async_exchange_end(exch);
     570
     571        if (!sess) {
    576572                fibril_mutex_unlock(&driver->driver_mutex);
    577573                return;
     
    582578         * that has not been passed to the driver.
    583579         */
    584         link = driver->devices.next;
    585         while (link != &driver->devices) {
     580        link = driver->devices.head.next;
     581        while (link != &driver->devices.head) {
    586582                dev = list_get_instance(link, dev_node_t, driver_devices);
    587583                if (dev->passed_to_driver) {
     
    602598                fibril_mutex_unlock(&driver->driver_mutex);
    603599
    604                 add_device(phone, driver, dev, tree);
     600                add_device(sess, driver, dev, tree);
    605601
    606602                /*
     
    620616                 * Restart the cycle to go through all devices again.
    621617                 */
    622                 link = driver->devices.next;
    623         }
    624 
    625         async_hangup(phone);
     618                link = driver->devices.head.next;
     619        }
     620
     621        async_hangup(sess);
    626622
    627623        /*
     
    673669        list_initialize(&drv->devices);
    674670        fibril_mutex_initialize(&drv->driver_mutex);
    675         drv->phone = -1;
     671        drv->sess = NULL;
    676672}
    677673
     
    737733 * @param node          The device's node in the device tree.
    738734 */
    739 void add_device(int phone, driver_t *drv, dev_node_t *dev, dev_tree_t *tree)
     735void add_device(async_sess_t *sess, driver_t *drv, dev_node_t *dev,
     736    dev_tree_t *tree)
    740737{
    741738        /*
     
    746743            drv->name, dev->pfun->name);
    747744       
    748         sysarg_t rc;
    749         ipc_call_t answer;
    750        
    751745        /* Send the device to the driver. */
    752746        devman_handle_t parent_handle;
     
    756750                parent_handle = 0;
    757751        }
    758 
    759         aid_t req = async_send_2(phone, DRIVER_ADD_DEVICE, dev->handle,
     752       
     753        async_exch_t *exch = async_exchange_begin(sess);
     754       
     755        ipc_call_t answer;
     756        aid_t req = async_send_2(exch, DRIVER_ADD_DEVICE, dev->handle,
    760757            parent_handle, &answer);
    761758       
    762         /* Send the device's name to the driver. */
    763         rc = async_data_write_start(phone, dev->pfun->name,
     759        /* Send the device name to the driver. */
     760        sysarg_t rc = async_data_write_start(exch, dev->pfun->name,
    764761            str_size(dev->pfun->name) + 1);
     762       
     763        async_exchange_end(exch);
     764       
    765765        if (rc != EOK) {
    766766                /* TODO handle error */
     
    823823        if (is_running) {
    824824                /* 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);
     825                async_exch_t *exch = async_exchange_begin(drv->sess);
     826                async_sess_t *sess = async_connect_me_to(EXCHANGE_SERIALIZE, exch,
     827                    DRIVER_DEVMAN, 0, 0);
     828                async_exchange_end(exch);
     829               
     830                if (sess) {
     831                        add_device(sess, drv, dev, tree);
     832                        async_hangup(sess);
    829833                }
    830834        }
     
    11771181
    11781182        fun_node_t *fun;
    1179         link_t *link;
    1180 
    1181         for (link = dev->functions.next;
    1182             link != &dev->functions;
    1183             link = link->next) {
     1183
     1184        list_foreach(dev->functions, link) {
    11841185                fun = list_get_instance(link, fun_node_t, dev_functions);
    11851186
     
    13751376{
    13761377        dev_class_t *cl;
    1377         link_t *link = class_list->classes.next;
    1378        
    1379         while (link != &class_list->classes) {
     1378       
     1379        list_foreach(class_list->classes, link) {
    13801380                cl = list_get_instance(link, dev_class_t, link);
    13811381                if (str_cmp(cl->name, class_name) == 0) {
    13821382                        return cl;
    13831383                }
    1384                 link = link->next;
    13851384        }
    13861385       
     
    13981397        assert(dev_name != NULL);
    13991398
    1400         link_t *link;
    1401         for (link = dev_class->devices.next;
    1402             link != &dev_class->devices;
    1403             link = link->next) {
     1399        list_foreach(dev_class->devices, link) {
    14041400                dev_class_info_t *dev = list_get_instance(link,
    14051401                    dev_class_info_t, link);
  • uspace/srv/devman/devman.h

    r25bef0ff r6a44ee4  
    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;
     
    9596        /** List of device ids for device-to-driver matching. */
    9697        match_id_list_t match_ids;
    97         /** Pointer to the linked list of devices controlled by this driver. */
    98         link_t devices;
    99        
    100         /**
    101          * Fibril mutex for this driver - driver state, list of devices, phone.
     98        /** List of devices controlled by this driver. */
     99        list_t devices;
     100       
     101        /**
     102         * Fibril mutex for this driver - driver state, list of devices, session.
    102103         */
    103104        fibril_mutex_t driver_mutex;
     
    107108typedef struct driver_list {
    108109        /** List of drivers */
    109         link_t drivers;
     110        list_t drivers;
    110111        /** Fibril mutex for list of drivers. */
    111112        fibril_mutex_t drivers_mutex;
     
    129130       
    130131        /** List of device functions. */
    131         link_t functions;
     132        list_t functions;
    132133        /** Driver of this device. */
    133134        driver_t *drv;
     
    169170        match_id_list_t match_ids;
    170171       
    171         /** The list of device classes to which this device function belongs. */
    172         link_t classes;
     172        /** List of device classes to which this device function belongs. */
     173        list_t classes;
    173174        /** Devmap handle if the device function is registered by devmap. */
    174175        devmap_handle_t devmap_handle;
     
    227228         * this class.
    228229         */
    229         link_t devices;
     230        list_t devices;
    230231       
    231232        /**
     
    279280typedef struct class_list {
    280281        /** List of classes. */
    281         link_t classes;
     282        list_t classes;
    282283       
    283284        /**
     
    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

    r25bef0ff r6a44ee4  
    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);
     
    515507}
    516508
     509/** Find device path by its handle. */
     510static void devman_get_device_path_by_handle(ipc_callid_t iid,
     511    ipc_call_t *icall)
     512{
     513        devman_handle_t handle = IPC_GET_ARG1(*icall);
     514
     515        fun_node_t *fun = find_fun_node(&device_tree, handle);
     516        if (fun == NULL) {
     517                async_answer_0(iid, ENOMEM);
     518                return;
     519        }
     520
     521        ipc_callid_t data_callid;
     522        size_t data_len;
     523        if (!async_data_read_receive(&data_callid, &data_len)) {
     524                async_answer_0(iid, EINVAL);
     525                return;
     526        }
     527
     528        void *buffer = malloc(data_len);
     529        if (buffer == NULL) {
     530                async_answer_0(data_callid, ENOMEM);
     531                async_answer_0(iid, ENOMEM);
     532                return;
     533        }
     534
     535        size_t sent_length = str_size(fun->pathname);
     536        if (sent_length > data_len) {
     537                sent_length = data_len;
     538        }
     539
     540        async_data_read_finalize(data_callid, fun->pathname, sent_length);
     541        async_answer_0(iid, EOK);
     542
     543        free(buffer);
     544}
     545
    517546
    518547/** Function for handling connections from a client to the device manager. */
     
    522551        async_answer_0(iid, EOK);
    523552       
    524         bool cont = true;
    525         while (cont) {
     553        while (true) {
    526554                ipc_call_t call;
    527555                ipc_callid_t callid = async_get_call(&call);
    528556               
     557                if (!IPC_GET_IMETHOD(call))
     558                        break;
     559               
    529560                switch (IPC_GET_IMETHOD(call)) {
    530                 case IPC_M_PHONE_HUNGUP:
    531                         cont = false;
    532                         continue;
    533561                case DEVMAN_DEVICE_GET_HANDLE:
    534562                        devman_function_get_handle(callid, &call);
     
    536564                case DEVMAN_DEVICE_GET_HANDLE_BY_CLASS:
    537565                        devman_function_get_handle_by_class(callid, &call);
     566                        break;
     567                case DEVMAN_DEVICE_GET_DEVICE_PATH:
     568                        devman_get_device_path_by_handle(callid, &call);
    538569                        break;
    539570                default:
     
    606637                method = DRIVER_CLIENT;
    607638       
    608         if (driver->phone < 0) {
    609                 log_msg(LVL_ERROR,
    610                     "Could not forward to driver `%s' (phone is %d).",
    611                     driver->name, (int) driver->phone);
     639        if (!driver->sess) {
     640                log_msg(LVL_ERROR,
     641                    "Could not forward to driver `%s'.", driver->name);
    612642                async_answer_0(iid, EINVAL);
    613643                return;
     
    623653                    dev->pfun->pathname, driver->name);
    624654        }
    625 
    626         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);
    627659}
    628660
     
    646678        dev = fun->dev;
    647679       
    648         if (dev->state != DEVICE_USABLE || dev->drv->phone < 0) {
     680        if ((dev->state != DEVICE_USABLE) || (!dev->drv->sess)) {
    649681                async_answer_0(iid, EINVAL);
    650682                return;
    651683        }
    652684       
    653         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,
    654687            IPC_FF_NONE);
    655         log_msg(LVL_DEBUG,
     688        async_exchange_end(exch);
     689       
     690        log_msg(LVL_DEBUG,
    656691            "Forwarding devmapper request for `%s' function to driver `%s'.",
    657692            fun->pathname, dev->drv->name);
     
    659694
    660695/** Function for handling connections to device manager. */
    661 static void devman_connection(ipc_callid_t iid, ipc_call_t *icall)
     696static void devman_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    662697{
    663698        /* Select interface. */
     
    745780
    746781        printf(NAME ": Accepting connections.\n");
     782        task_retval(0);
    747783        async_manager();
    748784
  • uspace/srv/devman/match.c

    r25bef0ff r6a44ee4  
    5959int get_match_score(driver_t *drv, dev_node_t *dev)
    6060{
    61         link_t *drv_head = &drv->match_ids.ids;
    62         link_t *dev_head = &dev->pfun->match_ids.ids;
     61        link_t *drv_head = &drv->match_ids.ids.head;
     62        link_t *dev_head = &dev->pfun->match_ids.ids.head;
    6363       
    64         if (list_empty(drv_head) || list_empty(dev_head))
     64        if (list_empty(&drv->match_ids.ids) ||
     65            list_empty(&dev->pfun->match_ids.ids)) {
    6566                return 0;
     67        }
    6668       
    6769        /*
     
    7072        int highest_score = 0;
    7173       
    72         link_t *drv_link = drv->match_ids.ids.next;
     74        link_t *drv_link = drv->match_ids.ids.head.next;
    7375        while (drv_link != drv_head) {
    7476                link_t *dev_link = dev_head->next;
Note: See TracChangeset for help on using the changeset viewer.