Changes in / [80bffdb0:d6b1359] in mainline


Ignore:
Location:
uspace/lib/drv
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/dev_iface.c

    r80bffdb0 rd6b1359  
    3636 */
    3737
    38 #include <assert.h>
    39 
    4038#include "dev_iface.h"
    4139#include "remote_hw_res.h"
     
    4947};
    5048
    51 remote_iface_t *get_remote_iface(int idx)
     49remote_iface_t* get_remote_iface(int idx)
    5250{
    5351        assert(is_valid_iface_idx(idx));
     
    6159                return NULL;
    6260        }
    63 
    6461        return rem_iface->methods[iface_method_idx];
    65 }
    66 
    67 bool is_valid_iface_idx(int idx)
    68 {
    69         return (0 <= idx) && (idx < DEV_IFACE_MAX);
    7062}
    7163
  • uspace/lib/drv/generic/driver.c

    r80bffdb0 rd6b1359  
    5252#include <ipc/driver.h>
    5353
    54 #include "dev_iface.h"
    5554#include "driver.h"
    5655
    57 /** Driver structure */
     56/* driver structure */
     57
    5858static driver_t *driver;
    5959
    60 /** Devices */
     60/* devices */
     61
    6162LIST_INITIALIZE(devices);
    6263FIBRIL_MUTEX_INITIALIZE(devices_mutex);
    6364
    64 /** Interrupts */
     65/* interrupts */
     66
    6567static interrupt_context_list_t interrupt_contexts;
    6668
     
    8385       
    8486        ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
    85         if (ctx != NULL && ctx->handler != NULL)
     87        if (NULL != ctx && NULL != ctx->handler)
    8688                (*ctx->handler)(ctx->dev, iid, icall);
    8789}
    88 
    89 interrupt_context_t *create_interrupt_context(void)
    90 {
    91         interrupt_context_t *ctx;
    92        
    93         ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
    94         if (ctx != NULL)
    95                 memset(ctx, 0, sizeof(interrupt_context_t));
    96        
    97         return ctx;
    98 }
    99 
    100 void delete_interrupt_context(interrupt_context_t *ctx)
    101 {
    102         if (ctx != NULL)
    103                 free(ctx);
    104 }
    105 
    106 void init_interrupt_context_list(interrupt_context_list_t *list)
    107 {
    108         memset(list, 0, sizeof(interrupt_context_list_t));
    109         fibril_mutex_initialize(&list->mutex);
    110         list_initialize(&list->contexts);
    111 }
    112 
    113 void
    114 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
    115 {
    116         fibril_mutex_lock(&list->mutex);
    117         ctx->id = list->curr_id++;
    118         list_append(&ctx->link, &list->contexts);
    119         fibril_mutex_unlock(&list->mutex);
    120 }
    121 
    122 void remove_interrupt_context(interrupt_context_list_t *list,
    123     interrupt_context_t *ctx)
    124 {
    125         fibril_mutex_lock(&list->mutex);
    126         list_remove(&ctx->link);
    127         fibril_mutex_unlock(&list->mutex);
    128 }
    129 
    130 interrupt_context_t *
    131 find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    132 {
    133         fibril_mutex_lock(&list->mutex);
    134        
    135         link_t *link = list->contexts.next;
    136         interrupt_context_t *ctx;
    137        
    138         while (link != &list->contexts) {
    139                 ctx = list_get_instance(link, interrupt_context_t, link);
    140                 if (ctx->id == id) {
    141                         fibril_mutex_unlock(&list->mutex);
    142                         return ctx;
    143                 }
    144                 link = link->next;
    145         }
    146        
    147         fibril_mutex_unlock(&list->mutex);
    148         return NULL;
    149 }
    150 
    151 interrupt_context_t *
    152 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq)
    153 {
    154         fibril_mutex_lock(&list->mutex);
    155        
    156         link_t *link = list->contexts.next;
    157         interrupt_context_t *ctx;
    158        
    159         while (link != &list->contexts) {
    160                 ctx = list_get_instance(link, interrupt_context_t, link);
    161                 if (ctx->irq == irq && ctx->dev == dev) {
    162                         fibril_mutex_unlock(&list->mutex);
    163                         return ctx;
    164                 }
    165                 link = link->next;
    166         }
    167        
    168         fibril_mutex_unlock(&list->mutex);
    169         return NULL;
    170 }
    171 
    17290
    17391int
     
    183101        add_interrupt_context(&interrupt_contexts, ctx);
    184102       
    185         if (pseudocode == NULL)
     103        if (NULL == pseudocode)
    186104                pseudocode = &default_pseudocode;
    187105       
    188106        int res = ipc_register_irq(irq, dev->handle, ctx->id, pseudocode);
    189         if (res != EOK) {
     107        if (0 != res) {
    190108                remove_interrupt_context(&interrupt_contexts, ctx);
    191109                delete_interrupt_context(ctx);
     
    200118            dev, irq);
    201119        int res = ipc_unregister_irq(irq, dev->handle);
    202        
    203         if (ctx != NULL) {
     120
     121        if (NULL != ctx) {
    204122                remove_interrupt_context(&interrupt_contexts, ctx);
    205123                delete_interrupt_context(ctx);
    206124        }
    207        
    208125        return res;
    209126}
     
    223140}
    224141
    225 static device_t *driver_get_device(link_t *devices, devman_handle_t handle)
     142static device_t * driver_get_device(link_t *devices, devman_handle_t handle)
    226143{
    227144        device_t *dev = NULL;
     
    229146        fibril_mutex_lock(&devices_mutex);
    230147        link_t *link = devices->next;
    231        
    232148        while (link != devices) {
    233149                dev = list_get_instance(link, device_t, link);
    234                 if (dev->handle == handle) {
     150                if (handle == dev->handle) {
    235151                        fibril_mutex_unlock(&devices_mutex);
    236152                        return dev;
     
    238154                link = link->next;
    239155        }
    240        
    241156        fibril_mutex_unlock(&devices_mutex);
    242        
     157
    243158        return NULL;
    244159}
     
    247162{
    248163        char *dev_name = NULL;
    249         int res;
    250        
    251         devman_handle_t dev_handle = IPC_GET_ARG1(*icall);
     164        int res = EOK;
     165       
     166        devman_handle_t dev_handle =  IPC_GET_ARG1(*icall);
    252167        devman_handle_t parent_dev_handle = IPC_GET_ARG2(*icall);
    253        
     168   
    254169        device_t *dev = create_device();
    255170        dev->handle = dev_handle;
     
    262177       
    263178        res = driver->driver_ops->add_device(dev);
    264         if (res == EOK) {
     179        if (0 == res) {
    265180                printf("%s: new device with handle=%" PRIun " was added.\n",
    266181                    driver->name, dev_handle);
     
    279194        /* Accept connection */
    280195        ipc_answer_0(iid, EOK);
    281        
     196
    282197        bool cont = true;
    283198        while (cont) {
    284199                ipc_call_t call;
    285200                ipc_callid_t callid = async_get_call(&call);
    286                
     201
    287202                switch (IPC_GET_IMETHOD(call)) {
    288203                case IPC_M_PHONE_HUNGUP:
     
    325240         * use the device.
    326241         */
    327        
     242
    328243        int ret = EOK;
    329244        /* open the device */
    330         if (dev->ops != NULL && dev->ops->open != NULL)
     245        if (NULL != dev->ops && NULL != dev->ops->open)
    331246                ret = (*dev->ops->open)(dev);
    332247       
    333         ipc_answer_0(iid, ret);
    334         if (ret != EOK)
     248        ipc_answer_0(iid, ret); 
     249        if (EOK != ret)
    335250                return;
    336        
     251
    337252        while (1) {
    338253                ipc_callid_t callid;
     
    343258               
    344259                switch  (method) {
    345                 case IPC_M_PHONE_HUNGUP:
     260                case IPC_M_PHONE_HUNGUP:               
    346261                        /* close the device */
    347                         if (dev->ops != NULL && dev->ops->close != NULL)
     262                        if (NULL != dev->ops && NULL != dev->ops->close)
    348263                                (*dev->ops->close)(dev);
    349264                        ipc_answer_0(callid, EOK);
    350265                        return;
    351                 default:
     266                default:               
    352267                        /* convert ipc interface id to interface index */
    353268                       
     
    357272                                remote_handler_t *default_handler =
    358273                                    device_get_default_handler(dev);
    359                                 if (default_handler != NULL) {
     274                                if (NULL != default_handler) {
    360275                                        (*default_handler)(dev, callid, &call);
    361276                                        break;
     
    371286                                break;
    372287                        }
    373                        
     288
    374289                        /* calling one of the device's interfaces */
    375290                       
    376                         /* Get the interface ops structure. */
    377                         void *ops = device_get_ops(dev, iface_idx);
    378                         if (ops == NULL) {
     291                        /* get the device interface structure */
     292                        void *iface = device_get_iface(dev, iface_idx);
     293                        if (NULL == iface) {
    379294                                printf("%s: driver_connection_gen error - ",
    380295                                    driver->name);
     
    384299                                break;
    385300                        }
    386                        
     301
    387302                        /*
    388303                         * Get the corresponding interface for remote request
    389304                         * handling ("remote interface").
    390305                         */
    391                         remote_iface_t *rem_iface = get_remote_iface(iface_idx);
    392                         assert(rem_iface != NULL);
    393                        
     306                        remote_iface_t* rem_iface = get_remote_iface(iface_idx);
     307                        assert(NULL != rem_iface);
     308
    394309                        /* get the method of the remote interface */
    395310                        sysarg_t iface_method_idx = IPC_GET_ARG1(call);
    396311                        remote_iface_func_ptr_t iface_method_ptr =
    397312                            get_remote_method(rem_iface, iface_method_idx);
    398                         if (iface_method_ptr == NULL) {
     313                        if (NULL == iface_method_ptr) {
    399314                                // the interface has not such method
    400315                                printf("%s: driver_connection_gen error - "
     
    410325                         * associated with the device by its driver.
    411326                         */
    412                         (*iface_method_ptr)(dev, ops, callid, &call);
     327                        (*iface_method_ptr)(dev, iface, callid, &call);
    413328                        break;
    414329                }
     
    433348        switch ((sysarg_t) (IPC_GET_ARG1(*icall))) {
    434349        case DRIVER_DEVMAN:
    435                 /* Handle request from device manager */
     350                /* handle PnP events from device manager */
    436351                driver_connection_devman(iid, icall);
    437352                break;
    438353        case DRIVER_DRIVER:
    439                 /* Handle request from drivers of child devices */
     354                /* handle request from drivers of child devices */
    440355                driver_connection_driver(iid, icall);
    441356                break;
    442357        case DRIVER_CLIENT:
    443                 /* Handle request from client applications */
     358                /* handle requests from client applications */
    444359                driver_connection_client(iid, icall);
    445360                break;
     361
    446362        default:
    447363                /* No such interface */
     
    450366}
    451367
    452 /** Create new device structure.
    453  *
    454  * @return              The device structure.
    455  */
    456 device_t *create_device(void)
    457 {
    458         device_t *dev = malloc(sizeof(device_t));
    459 
    460         if (dev != NULL) {
    461                 memset(dev, 0, sizeof(device_t));
    462                 init_match_ids(&dev->match_ids);
    463         }
    464 
    465         return dev;
    466 }
    467 
    468 /** Delete device structure.
    469  *
    470  * @param dev           The device structure.
    471  */
    472 void delete_device(device_t *dev)
    473 {
    474         clean_match_ids(&dev->match_ids);
    475         if (dev->name != NULL)
    476                 free(dev->name);
    477         free(dev);
    478 }
    479 
    480 void *device_get_ops(device_t *dev, dev_inferface_idx_t idx)
    481 {
    482         assert(is_valid_iface_idx(idx));
    483         if (dev->ops == NULL)
    484                 return NULL;
    485         return dev->ops->interfaces[idx];
    486 }
    487 
    488368int child_device_register(device_t *child, device_t *parent)
    489369{
    490         assert(child->name != NULL);
    491        
     370        assert(NULL != child->name);
     371
    492372        int res;
    493373       
     
    495375        res = devman_child_device_register(child->name, &child->match_ids,
    496376            parent->handle, &child->handle);
    497         if (res != EOK) {
    498                 remove_from_devices_list(child);
     377        if (EOK == res)
    499378                return res;
    500         }
    501        
     379        remove_from_devices_list(child);       
    502380        return res;
    503381}
     
    517395        match_id_t *match_id = NULL;
    518396        int rc;
    519        
     397
    520398        child = create_device();
    521399        if (child == NULL) {
     
    523401                goto failure;
    524402        }
    525        
     403
    526404        child->name = child_name;
    527        
     405
    528406        match_id = create_match_id();
    529407        if (match_id == NULL) {
     
    531409                goto failure;
    532410        }
    533        
     411
    534412        match_id->id = child_match_id;
    535413        match_id->score = child_match_score;
    536414        add_match_id(&child->match_ids, match_id);
    537        
     415
    538416        rc = child_device_register(child, parent);
    539         if (rc != EOK)
     417        if (EOK != rc)
    540418                goto failure;
    541        
     419
    542420        return EOK;
    543        
     421
    544422failure:
    545423        if (match_id != NULL) {
     
    547425                delete_match_id(match_id);
    548426        }
    549        
     427
    550428        if (child != NULL) {
    551429                child->name = NULL;
    552430                delete_device(child);
    553431        }
    554        
     432
    555433        return rc;
    556 }
    557 
    558 /** Get default handler for client requests */
    559 remote_handler_t *device_get_default_handler(device_t *dev)
    560 {
    561         if (dev->ops == NULL)
    562                 return NULL;
    563         return dev->ops->default_handler;
    564 }
    565 
    566 int add_device_to_class(device_t *dev, const char *class_name)
    567 {
    568         return devman_add_device_to_class(dev->handle, class_name);
    569434}
    570435
     
    576441         */
    577442        driver = drv;
    578        
     443
    579444        /* Initialize the list of interrupt contexts. */
    580445        init_interrupt_context_list(&interrupt_contexts);
     
    588453         */
    589454        devman_driver_register(driver->name, driver_connection);
    590        
     455
    591456        async_manager();
    592        
     457
    593458        /* Never reached. */
    594459        return 0;
  • uspace/lib/drv/generic/remote_char_dev.c

    r80bffdb0 rd6b1359  
    6969 *
    7070 * @param dev           The device from which the data are read.
    71  * @param ops           The local ops structure.
     71 * @param iface         The local interface structure.
    7272 */
    7373static void
    74 remote_char_read(device_t *dev, void *ops, ipc_callid_t callid,
     74remote_char_read(device_t *dev, void *iface, ipc_callid_t callid,
    7575    ipc_call_t *call)
    7676{
    77         char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops;
     77        char_dev_ops_t *char_iface = (char_dev_ops_t *) iface;
    7878        ipc_callid_t cid;
    7979       
     
    8585        }
    8686       
    87         if (!char_dev_ops->read) {
     87        if (!char_iface->read) {
    8888                async_data_read_finalize(cid, NULL, 0);
    8989                ipc_answer_0(callid, ENOTSUP);
     
    9595       
    9696        char buf[MAX_CHAR_RW_COUNT];
    97         int ret = (*char_dev_ops->read)(dev, buf, len);
     97        int ret = (*char_iface->read)(dev, buf, len);
    9898       
    9999        if (ret < 0) {
     
    116116 *
    117117 * @param dev           The device to which the data are written.
    118  * @param ops           The local ops structure.
     118 * @param iface         The local interface structure.
    119119 */
    120120static void
    121 remote_char_write(device_t *dev, void *ops, ipc_callid_t callid,
     121remote_char_write(device_t *dev, void *iface, ipc_callid_t callid,
    122122    ipc_call_t *call)
    123123{
    124         char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops;
     124        char_dev_ops_t *char_iface = (char_dev_ops_t *) iface;
    125125        ipc_callid_t cid;
    126126        size_t len;
     
    132132        }
    133133       
    134         if (!char_dev_ops->write) {
     134        if (!char_iface->write) {
    135135                async_data_write_finalize(cid, NULL, 0);
    136136                ipc_answer_0(callid, ENOTSUP);
     
    145145        async_data_write_finalize(cid, buf, len);
    146146       
    147         int ret = (*char_dev_ops->write)(dev, buf, len);
     147        int ret = (*char_iface->write)(dev, buf, len);
    148148        if (ret < 0) {
    149149                /* Some error occured. */
  • uspace/lib/drv/generic/remote_hw_res.c

    r80bffdb0 rd6b1359  
    4040#include "driver.h"
    4141
    42 static void remote_hw_res_get_resource_list(device_t *, void *, ipc_callid_t,
     42static void remote_res_get_resource_list(device_t *, void *, ipc_callid_t,
    4343    ipc_call_t *);
    44 static void remote_hw_res_enable_interrupt(device_t *, void *, ipc_callid_t,
     44static void remote_res_enable_interrupt(device_t *, void *, ipc_callid_t,
    4545    ipc_call_t *);
    4646
    4747static remote_iface_func_ptr_t remote_hw_res_iface_ops [] = {
    48         &remote_hw_res_get_resource_list,
    49         &remote_hw_res_enable_interrupt
     48        &remote_res_get_resource_list,
     49        &remote_res_enable_interrupt
    5050};
    5151
     
    5656};
    5757
    58 static void remote_hw_res_enable_interrupt(device_t *dev, void *ops,
     58static void remote_res_enable_interrupt(device_t *dev, void *iface,
    5959    ipc_callid_t callid, ipc_call_t *call)
    6060{
    61         hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
     61        hw_res_ops_t *ires = (hw_res_ops_t *) iface;
    6262       
    63         if (hw_res_ops->enable_interrupt == NULL)
     63        if (NULL == ires->enable_interrupt)
    6464                ipc_answer_0(callid, ENOTSUP);
    65         else if (hw_res_ops->enable_interrupt(dev))
     65        else if (ires->enable_interrupt(dev))
    6666                ipc_answer_0(callid, EOK);
    6767        else
     
    6969}
    7070
    71 static void remote_hw_res_get_resource_list(device_t *dev, void *ops,
     71static void remote_res_get_resource_list(device_t *dev, void *iface,
    7272    ipc_callid_t callid, ipc_call_t *call)
    7373{
    74         hw_res_ops_t *hw_res_ops = (hw_res_ops_t *) ops;
    75 
    76         if (hw_res_ops->get_resource_list == NULL) {
     74        hw_res_ops_t *ires = (hw_res_ops_t *) iface;
     75        if (NULL == ires->get_resource_list) {
    7776                ipc_answer_0(callid, ENOTSUP);
    7877                return;
    7978        }
    8079       
    81         hw_resource_list_t *hw_resources = hw_res_ops->get_resource_list(dev);
    82         if (hw_resources == NULL){
     80        hw_resource_list_t *hw_resources = ires->get_resource_list(dev);
     81        if (NULL == hw_resources){
    8382                ipc_answer_0(callid, ENOENT);
    8483                return;
    85         }
     84        }       
    8685       
    87         ipc_answer_1(callid, EOK, hw_resources->count);
     86        ipc_answer_1(callid, EOK, hw_resources->count); 
    8887
    8988        size_t len;
    9089        if (!async_data_read_receive(&callid, &len)) {
    91                 /* Protocol error - the recipient is not accepting data */
     90                /* protocol error - the recipient is not accepting data */
    9291                return;
    9392        }
  • uspace/lib/drv/include/dev_iface.h

    r80bffdb0 rd6b1359  
    3636#define LIBDRV_DEV_IFACE_H_
    3737
    38 #include <ipc/dev_iface.h>
     38#include "driver.h"
    3939
    40 /*
    41  * Device interface
    42  */
    43 
    44 struct device;
    45 
    46 /*
    47  * First two parameters: device and interface structure registered by the
    48  * devices driver.
    49  */
    50 typedef void remote_iface_func_t(struct device *, void *, ipc_callid_t,
    51     ipc_call_t *);
    52 typedef remote_iface_func_t *remote_iface_func_ptr_t;
    53 typedef void remote_handler_t(struct device *, ipc_callid_t, ipc_call_t *);
    54 
    55 typedef struct {
    56         size_t method_count;
    57         remote_iface_func_ptr_t *methods;
    58 } remote_iface_t;
    59 
    60 typedef struct {
    61         remote_iface_t *ifaces[DEV_IFACE_COUNT];
    62 } iface_dipatch_table_t;
    63 
    64 extern remote_iface_t *get_remote_iface(int);
    65 extern remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t);
    66 
    67 
    68 extern bool is_valid_iface_idx(int);
     40/* TODO declare device interface structures here */
    6941
    7042#endif
  • uspace/lib/drv/include/driver.h

    r80bffdb0 rd6b1359  
    4747#include <malloc.h>
    4848
    49 #include "dev_iface.h"
    50 
    5149struct device;
    5250typedef struct device device_t;
    5351
     52/* device interface */
     53
    5454/*
    55  * Device class
    56  */
    57 
    58 /** Devices operations */
     55 * First two parameters: device and interface structure registered by the
     56 * devices driver.
     57 */
     58typedef void remote_iface_func_t(device_t *, void *, ipc_callid_t,
     59    ipc_call_t *);
     60typedef remote_iface_func_t *remote_iface_func_ptr_t;
     61typedef void remote_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
     62
     63typedef struct {
     64        size_t method_count;
     65        remote_iface_func_ptr_t *methods;
     66} remote_iface_t;
     67
     68typedef struct {
     69        remote_iface_t *ifaces[DEV_IFACE_COUNT];
     70} iface_dipatch_table_t;
     71
     72
     73static inline bool is_valid_iface_idx(int idx)
     74{
     75        return 0 <= idx && idx < DEV_IFACE_MAX;
     76}
     77
     78remote_iface_t *get_remote_iface(int);
     79remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t);
     80
     81
     82/* device class */
     83
     84/** Devices operations. */
    5985typedef struct device_ops {
    6086        /**
     
    82108
    83109
    84 /*
    85  * Device
    86  */
    87 
    88 /** Device structure */
     110/* device */
     111
     112/** The device. */
    89113struct device {
    90114        /**
     
    95119       
    96120        /**
    97          * Phone to the parent device driver (if it is different from this
    98          * driver)
     121         * The phone to the parent device driver (if it is different from this
     122         * driver).
    99123         */
    100124        int parent_phone;
    101125       
    102         /** Parent device if handled by this driver, NULL otherwise */
     126        /** Parent device if handled by this driver, NULL otherwise. */
    103127        device_t *parent;
    104         /** Device name */
     128        /** The device's name. */
    105129        const char *name;
    106         /** List of device ids for device-to-driver matching */
     130        /** The list of device ids for device-to-driver matching. */
    107131        match_id_list_t match_ids;
    108         /** Driver-specific data associated with this device */
     132        /** The device driver's data associated with this device. */
    109133        void *driver_data;
    110         /** The implementation of operations provided by this device */
     134        /** The implementation of operations provided by this device. */
    111135        device_ops_t *ops;
    112136       
    113         /** Link in the list of devices handled by the driver */
     137        /**
     138         * Pointer to the previous and next device in the list of devices
     139         * handled by the driver.
     140         */
    114141        link_t link;
    115142};
    116143
    117 /*
    118  * Driver
    119  */
    120 
    121 /** Generic device driver operations */
     144
     145/* driver */
     146
     147/** Generic device driver operations. */
    122148typedef struct driver_ops {
    123         /** Callback method for passing a new device to the device driver */
     149        /** Callback method for passing a new device to the device driver.*/
    124150        int (*add_device)(device_t *dev);
    125         /* TODO: add other generic driver operations */
     151        /* TODO add other generic driver operations */
    126152} driver_ops_t;
    127153
    128 /** Driver structure */
     154/** The driver structure.*/
    129155typedef struct driver {
    130         /** Name of the device driver */
     156        /** The name of the device driver. */
    131157        const char *name;
    132         /** Generic device driver operations */
     158        /** Generic device driver operations. */
    133159        driver_ops_t *driver_ops;
    134160} driver_t;
     
    140166 * @return              The device structure.
    141167 */
    142 extern device_t *create_device(void);
    143 extern void delete_device(device_t *);
    144 extern void *device_get_ops(device_t *, dev_inferface_idx_t);
    145 
    146 extern int child_device_register(device_t *, device_t *);
    147 extern int child_device_register_wrapper(device_t *, const char *, const char *,
    148     int);
    149 
    150 /*
    151  * Interrupts
    152  */
     168static inline device_t *create_device(void)
     169{
     170        device_t *dev = malloc(sizeof(device_t));
     171        if (NULL != dev) {
     172                memset(dev, 0, sizeof(device_t));
     173                init_match_ids(&dev->match_ids);
     174        }       
     175        return dev;
     176}
     177
     178/** Delete device structure.
     179 *
     180 * @param dev           The device structure.
     181 */
     182static inline void delete_device(device_t *dev)
     183{
     184        clean_match_ids(&dev->match_ids);
     185        if (NULL != dev->name)
     186                free(dev->name);
     187        free(dev);
     188}
     189
     190static inline void *device_get_iface(device_t *dev, dev_inferface_idx_t idx)
     191{
     192        assert(is_valid_iface_idx(idx));
     193        if (NULL == dev->ops)
     194                return NULL;
     195        return dev->ops->interfaces[idx];
     196}
     197
     198int child_device_register(device_t *, device_t *);
     199int child_device_register_wrapper(device_t *, const char *, const char *, int);
     200
     201
     202/* interrupts */
    153203
    154204typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
     
    168218} interrupt_context_list_t;
    169219
    170 extern interrupt_context_t *create_interrupt_context(void);
    171 extern void delete_interrupt_context(interrupt_context_t *);
    172 extern void init_interrupt_context_list(interrupt_context_list_t *);
    173 extern void add_interrupt_context(interrupt_context_list_t *,
    174     interrupt_context_t *);
    175 extern void remove_interrupt_context(interrupt_context_list_t *,
    176     interrupt_context_t *);
    177 extern interrupt_context_t *find_interrupt_context_by_id(
    178     interrupt_context_list_t *, int);
    179 extern interrupt_context_t *find_interrupt_context(
    180     interrupt_context_list_t *, device_t *, int);
    181 
    182 extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
     220static inline interrupt_context_t *create_interrupt_context(void)
     221{
     222        interrupt_context_t *ctx;
     223       
     224        ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
     225        if (NULL != ctx)
     226                memset(ctx, 0, sizeof(interrupt_context_t));
     227       
     228        return ctx;
     229}
     230
     231static inline void delete_interrupt_context(interrupt_context_t *ctx)
     232{
     233        if (NULL != ctx)
     234                free(ctx);
     235}
     236
     237static inline void init_interrupt_context_list(interrupt_context_list_t *list)
     238{
     239        memset(list, 0, sizeof(interrupt_context_list_t));
     240        fibril_mutex_initialize(&list->mutex);
     241        list_initialize(&list->contexts);
     242}
     243
     244static inline void
     245add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
     246{
     247        fibril_mutex_lock(&list->mutex);
     248        ctx->id = list->curr_id++;
     249        list_append(&ctx->link, &list->contexts);
     250        fibril_mutex_unlock(&list->mutex);
     251}
     252
     253static inline void
     254remove_interrupt_context(interrupt_context_list_t *list,
     255    interrupt_context_t *ctx)
     256{
     257        fibril_mutex_lock(&list->mutex);
     258        list_remove(&ctx->link);
     259        fibril_mutex_unlock(&list->mutex);
     260}
     261
     262static inline interrupt_context_t *
     263find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
     264{
     265        fibril_mutex_lock(&list->mutex);
     266       
     267        link_t *link = list->contexts.next;
     268        interrupt_context_t *ctx;
     269       
     270        while (link != &list->contexts) {
     271                ctx = list_get_instance(link, interrupt_context_t, link);
     272                if (id == ctx->id) {
     273                        fibril_mutex_unlock(&list->mutex);
     274                        return ctx;
     275                }
     276                link = link->next;
     277        }
     278       
     279        fibril_mutex_unlock(&list->mutex);
     280        return NULL;
     281}
     282
     283static inline interrupt_context_t *
     284find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq)
     285{
     286        fibril_mutex_lock(&list->mutex);
     287       
     288        link_t *link = list->contexts.next;
     289        interrupt_context_t *ctx;
     290       
     291        while (link != &list->contexts) {
     292                ctx = list_get_instance(link, interrupt_context_t, link);
     293                if (irq == ctx->irq && dev == ctx->dev) {
     294                        fibril_mutex_unlock(&list->mutex);
     295                        return ctx;
     296                }
     297                link = link->next;
     298        }
     299       
     300        fibril_mutex_unlock(&list->mutex);
     301        return NULL;
     302}
     303
     304int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
    183305    irq_code_t *);
    184 extern int unregister_interrupt_handler(device_t *, int);
    185 
    186 extern remote_handler_t *device_get_default_handler(device_t *);
    187 extern int add_device_to_class(device_t *, const char *);
     306int unregister_interrupt_handler(device_t *, int);
     307
     308
     309/* default handler for client requests */
     310
     311static inline remote_handler_t *device_get_default_handler(device_t *dev)
     312{
     313        if (NULL == dev->ops)
     314                return NULL;
     315        return dev->ops->default_handler;
     316}
     317
     318static inline int add_device_to_class(device_t *dev, const char *class_name)
     319{
     320        return devman_add_device_to_class(dev->handle, class_name);
     321}
    188322
    189323#endif
Note: See TracChangeset for help on using the changeset viewer.