Changeset c028b22 in mainline for uspace/srv/devmap/devmap.c


Ignore:
Timestamp:
2011-07-08T17:01:01Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
cc1a727
Parents:
4e36219 (diff), 026793d (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

File:
1 edited

Legend:

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

    r4e36219 rc028b22  
    3737
    3838#include <ipc/services.h>
    39 #include <ipc/ns.h>
     39#include <ns.h>
    4040#include <async.h>
    4141#include <stdio.h>
     
    5757 */
    5858typedef struct {
    59         /** Pointers to previous and next drivers in linked list */
     59        /** Link to drivers_list */
    6060        link_t drivers;
    61         /** Pointer to the linked list of devices controlled by this driver */
    62         link_t devices;
    63         /** Phone asociated with this driver */
    64         sysarg_t phone;
     61       
     62        /** List of devices controlled by this driver */
     63        list_t devices;
     64       
     65        /** Session asociated with this driver */
     66        async_sess_t *sess;
     67       
    6568        /** Device driver name */
    6669        char *name;
     70       
    6771        /** Fibril mutex for list of devices owned by this driver */
    6872        fibril_mutex_t devices_mutex;
     
    7377 */
    7478typedef struct {
    75         /** Pointer to the previous and next device in the list of all namespaces */
     79        /** Link to namespaces_list */
    7680        link_t namespaces;
     81       
    7782        /** Unique namespace identifier */
    7883        devmap_handle_t handle;
     84       
    7985        /** Namespace name */
    8086        char *name;
     87       
    8188        /** Reference count */
    8289        size_t refcnt;
     
    8794 */
    8895typedef struct {
    89         /** Pointer to the previous and next device in the list of all devices */
     96        /** Link to global list of devices (devices_list) */
    9097        link_t devices;
    91         /** Pointer to the previous and next device in the list of devices
    92             owned by one driver */
     98        /** Link to driver list of devices (devmap_driver_t.devices) */
    9399        link_t driver_devices;
    94100        /** Unique device identifier */
     
    218224static devmap_namespace_t *devmap_namespace_find_name(const char *name)
    219225{
    220         link_t *item;
    221        
    222226        assert(fibril_mutex_is_locked(&devices_list_mutex));
    223227       
    224         for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
     228        list_foreach(namespaces_list, item) {
    225229                devmap_namespace_t *namespace =
    226230                    list_get_instance(item, devmap_namespace_t, namespaces);
     
    239243static devmap_namespace_t *devmap_namespace_find_handle(devmap_handle_t handle)
    240244{
    241         link_t *item;
    242        
    243245        assert(fibril_mutex_is_locked(&devices_list_mutex));
    244246       
    245         for (item = namespaces_list.next; item != &namespaces_list; item = item->next) {
     247        list_foreach(namespaces_list, item) {
    246248                devmap_namespace_t *namespace =
    247249                    list_get_instance(item, devmap_namespace_t, namespaces);
     
    257259    const char *name)
    258260{
    259         link_t *item;
    260        
    261261        assert(fibril_mutex_is_locked(&devices_list_mutex));
    262262       
    263         for (item = devices_list.next; item != &devices_list; item = item->next) {
     263        list_foreach(devices_list, item) {
    264264                devmap_device_t *device =
    265265                    list_get_instance(item, devmap_device_t, devices);
     
    279279static devmap_device_t *devmap_device_find_handle(devmap_handle_t handle)
    280280{
    281         link_t *item;
    282        
    283281        assert(fibril_mutex_is_locked(&devices_list_mutex));
    284282       
    285         for (item = devices_list.next; item != &devices_list; item = item->next) {
     283        list_foreach(devices_list, item) {
    286284                devmap_device_t *device =
    287285                    list_get_instance(item, devmap_device_t, devices);
     
    405403         * Create connection to the driver
    406404         */
    407         ipc_call_t call;
    408         ipc_callid_t callid = async_get_call(&call);
    409        
    410         if (IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) {
     405        driver->sess = async_callback_receive(EXCHANGE_SERIALIZE);
     406        if (!driver->sess) {
    411407                free(driver->name);
    412408                free(driver);
    413                 async_answer_0(callid, ENOTSUP);
    414409                async_answer_0(iid, ENOTSUP);
    415410                return NULL;
    416411        }
    417        
    418         driver->phone = IPC_GET_ARG5(call);
    419         async_answer_0(callid, EOK);
    420412       
    421413        /*
     
    462454        fibril_mutex_lock(&drivers_list_mutex);
    463455       
    464         if (driver->phone != 0)
    465                 async_hangup(driver->phone);
     456        if (driver->sess)
     457                async_hangup(driver->sess);
    466458       
    467459        /* Remove it from list of drivers */
     
    472464        fibril_mutex_lock(&driver->devices_mutex);
    473465       
    474         while (!list_empty(&(driver->devices))) {
    475                 devmap_device_t *device = list_get_instance(driver->devices.next,
    476                     devmap_device_t, driver_devices);
     466        while (!list_empty(&driver->devices)) {
     467                devmap_device_t *device = list_get_instance(
     468                    list_first(&driver->devices), devmap_device_t,
     469                    driver_devices);
    477470                devmap_device_unregister_core(device);
    478471        }
     
    607600        devmap_device_t *dev = devmap_device_find_handle(handle);
    608601       
    609         if ((dev == NULL) || (dev->driver == NULL) || (dev->driver->phone == 0)) {
     602        if ((dev == NULL) || (dev->driver == NULL) || (!dev->driver->sess)) {
    610603                fibril_mutex_unlock(&devices_list_mutex);
    611604                async_answer_0(callid, ENOENT);
     
    613606        }
    614607       
    615         if (dev->forward_interface == 0) {
    616                 async_forward_fast(callid, dev->driver->phone,
    617                     dev->handle, 0, 0,
    618                     IPC_FF_NONE);
    619         } else {
    620                 async_forward_fast(callid, dev->driver->phone,
    621                     dev->forward_interface, dev->handle, 0,
    622                     IPC_FF_NONE);
    623         }
     608        async_exch_t *exch = async_exchange_begin(dev->driver->sess);
     609       
     610        if (dev->forward_interface == 0)
     611                async_forward_fast(callid, exch, dev->handle, 0, 0, IPC_FF_NONE);
     612        else
     613                async_forward_fast(callid, exch, dev->forward_interface,
     614                    dev->handle, 0, IPC_FF_NONE);
     615       
     616        async_exchange_end(exch);
    624617       
    625618        fibril_mutex_unlock(&devices_list_mutex);
     
    814807        }
    815808       
    816         link_t *item;
    817809        size_t pos = 0;
    818         for (item = namespaces_list.next; item != &namespaces_list;
    819             item = item->next) {
     810        list_foreach(namespaces_list, item) {
    820811                devmap_namespace_t *namespace =
    821812                    list_get_instance(item, devmap_namespace_t, namespaces);
     
    880871        }
    881872       
    882         link_t *item;
    883873        size_t pos = 0;
    884         for (item = devices_list.next; item != &devices_list; item = item->next) {
     874        list_foreach(devices_list, item) {
    885875                devmap_device_t *device =
    886876                    list_get_instance(item, devmap_device_t, devices);
     
    10291019                return;
    10301020       
    1031         bool cont = true;
    1032         while (cont) {
     1021        while (true) {
    10331022                ipc_call_t call;
    10341023                ipc_callid_t callid = async_get_call(&call);
    10351024               
     1025                if (!IPC_GET_IMETHOD(call))
     1026                        break;
     1027               
    10361028                switch (IPC_GET_IMETHOD(call)) {
    1037                 case IPC_M_PHONE_HUNGUP:
    1038                         cont = false;
    1039                         continue;
    10401029                case DEVMAP_DRIVER_UNREGISTER:
    10411030                        if (NULL == driver)
     
    10801069        async_answer_0(iid, EOK);
    10811070       
    1082         bool cont = true;
    1083         while (cont) {
     1071        while (true) {
    10841072                ipc_call_t call;
    10851073                ipc_callid_t callid = async_get_call(&call);
    10861074               
     1075                if (!IPC_GET_IMETHOD(call))
     1076                        break;
     1077               
    10871078                switch (IPC_GET_IMETHOD(call)) {
    1088                 case IPC_M_PHONE_HUNGUP:
    1089                         cont = false;
    1090                         continue;
    10911079                case DEVMAP_DEVICE_GET_HANDLE:
    10921080                        devmap_device_get_handle(callid, &call);
     
    11251113 *
    11261114 */
    1127 static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall)
     1115static void devmap_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)
    11281116{
    11291117        /* Select interface */
Note: See TracChangeset for help on using the changeset viewer.