Changeset 7a252ec8 in mainline


Ignore:
Timestamp:
2010-10-21T20:13:40Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
848e3d15
Parents:
a79d88d
Message:

Cstyle fixes in libdrv.

Location:
uspace/lib/drv
Files:
10 edited

Legend:

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

    ra79d88d r7a252ec8  
    3535/** @file
    3636 */
    37  
     37
    3838#include "dev_iface.h"
    3939#include "remote_res.h"
    4040#include "remote_char.h"
    41  
     41
    4242static iface_dipatch_table_t remote_ifaces = {
    4343        .ifaces = {
     
    4949remote_iface_t* get_remote_iface(int idx)
    5050{       
    51         assert(is_valid_iface_idx(idx));       
    52         return remote_ifaces.ifaces[idx];       
     51        assert(is_valid_iface_idx(idx));
     52        return remote_ifaces.ifaces[idx];
    5353}
    5454
    55 remote_iface_func_ptr_t get_remote_method(remote_iface_t *rem_iface, ipcarg_t iface_method_idx)
     55remote_iface_func_ptr_t
     56get_remote_method(remote_iface_t *rem_iface, ipcarg_t iface_method_idx)
    5657{
    5758        if (iface_method_idx >= rem_iface->method_count) {
     
    6061        return rem_iface->methods[iface_method_idx];
    6162}
    62  
    63  
    64  
     63
    6564/**
    6665 * @}
  • uspace/lib/drv/generic/driver.c

    ra79d88d r7a252ec8  
    5353#include "driver.h"
    5454
    55 // driver structure
     55/* driver structure */
    5656
    5757static driver_t *driver;
    5858
    59 // devices
     59/* devices */
    6060
    6161LIST_INITIALIZE(devices);
    6262FIBRIL_MUTEX_INITIALIZE(devices_mutex);
    6363
    64 // interrupts
     64/* interrupts */
    6565
    6666static interrupt_context_list_t interrupt_contexts;
     
    7979
    8080static void driver_irq_handler(ipc_callid_t iid, ipc_call_t *icall)
    81 {       
     81{
    8282        int id = (int)IPC_GET_METHOD(*icall);
    83         interrupt_context_t *ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
    84         if (NULL != ctx && NULL != ctx->handler) {
    85                 (*ctx->handler)(ctx->dev, iid, icall);         
    86         }
    87 }
    88 
    89 int register_interrupt_handler(device_t *dev, int irq, interrupt_handler_t *handler, irq_code_t *pseudocode)
     83        interrupt_context_t *ctx;
     84       
     85        ctx = find_interrupt_context_by_id(&interrupt_contexts, id);
     86        if (NULL != ctx && NULL != ctx->handler)
     87                (*ctx->handler)(ctx->dev, iid, icall);
     88}
     89
     90int
     91register_interrupt_handler(device_t *dev, int irq, interrupt_handler_t *handler,
     92    irq_code_t *pseudocode)
    9093{
    9194        interrupt_context_t *ctx = create_interrupt_context();
     
    97100        add_interrupt_context(&interrupt_contexts, ctx);
    98101       
    99         if (NULL == pseudocode) {
     102        if (NULL == pseudocode)
    100103                pseudocode = &default_pseudocode;
    101         }
    102104       
    103105        int res = ipc_register_irq(irq, dev->handle, ctx->id, pseudocode);
     
    106108                delete_interrupt_context(ctx);
    107109        }
    108         return res;     
     110
     111        return res;
    109112}
    110113
    111114int unregister_interrupt_handler(device_t *dev, int irq)
    112115{
    113         interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts, dev, irq);
     116        interrupt_context_t *ctx = find_interrupt_context(&interrupt_contexts,
     117            dev, irq);
    114118        int res = ipc_unregister_irq(irq, dev->handle);
     119
    115120        if (NULL != ctx) {
    116121                remove_interrupt_context(&interrupt_contexts, ctx);
    117                 delete_interrupt_context(ctx);         
     122                delete_interrupt_context(ctx);
    118123        }
    119124        return res;
     
    138143        device_t *dev = NULL;
    139144       
    140         fibril_mutex_lock(&devices_mutex);     
     145        fibril_mutex_lock(&devices_mutex);
    141146        link_t *link = devices->next;
    142147        while (link != devices) {
     
    162167        dev->handle = dev_handle;
    163168       
    164         async_data_write_accept((void **)&dev_name, true, 0, 0, 0, 0);
     169        async_data_write_accept((void **) &dev_name, true, 0, 0, 0, 0);
    165170        dev->name = dev_name;
    166171       
    167         add_to_devices_list(dev);               
     172        add_to_devices_list(dev);
    168173        res = driver->driver_ops->add_device(dev);
    169174        if (0 == res) {
    170                 printf("%s: new device with handle = %x was added.\n", driver->name, dev_handle);
     175                printf("%s: new device with handle = %x was added.\n",
     176                    driver->name, dev_handle);
    171177        } else {
    172                 printf("%s: failed to add a new device with handle = %d.\n", driver->name, dev_handle);
     178                printf("%s: failed to add a new device with handle = %d.\n",
     179                    driver->name, dev_handle);
    173180                remove_from_devices_list(dev);
    174                 delete_device(dev);     
     181                delete_device(dev);
    175182        }
    176183       
     
    205212 * Generic client connection handler both for applications and drivers.
    206213 *
    207  * @param drv true for driver client, false for other clients (applications, services etc.).
     214 * @param drv           True for driver client, false for other clients
     215 *                      (applications, services etc.).
    208216 */
    209217static void driver_connection_gen(ipc_callid_t iid, ipc_call_t *icall, bool drv)
    210218{
    211         // Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of the device to which the client connected.
     219        /*
     220         * Answer the first IPC_M_CONNECT_ME_TO call and remember the handle of
     221         * the device to which the client connected.
     222         */
    212223        device_handle_t handle = IPC_GET_ARG2(*icall);
    213224        device_t *dev = driver_get_device(&devices, handle);
    214225
    215226        if (dev == NULL) {
    216                 printf("%s: driver_connection_gen error - no device with handle %x was found.\n", driver->name, handle);
     227                printf("%s: driver_connection_gen error - no device with handle"
     228                    " %x was found.\n", driver->name, handle);
    217229                ipc_answer_0(iid, ENOENT);
    218230                return;
     
    220232       
    221233       
    222         // TODO - if the client is not a driver, check whether it is allowed to use the device
     234        /*
     235         * TODO - if the client is not a driver, check whether it is allowed to
     236         * use the device.
     237         */
    223238
    224239        int ret = EOK;
    225         // open the device
    226         if (NULL != dev->ops && NULL != dev->ops->open) {
     240        /* open the device */
     241        if (NULL != dev->ops && NULL != dev->ops->open)
    227242                ret = (*dev->ops->open)(dev);
    228         }
    229243       
    230244        ipc_answer_0(iid, ret);
    231         if (EOK != ret) {
     245        if (EOK != ret)
    232246                return;
    233         }
    234247
    235248        while (1) {
     
    242255                switch  (method) {
    243256                case IPC_M_PHONE_HUNGUP:               
    244                         // close the device
    245                         if (NULL != dev->ops && NULL != dev->ops->close) {
     257                        /* close the device */
     258                        if (NULL != dev->ops && NULL != dev->ops->close)
    246259                                (*dev->ops->close)(dev);
    247                         }                       
    248260                        ipc_answer_0(callid, EOK);
    249261                        return;
    250262                default:               
    251                         // convert ipc interface id to interface index
     263                        /* convert ipc interface id to interface index */
    252264                       
    253265                        iface_idx = DEV_IFACE_IDX(method);
    254266                       
    255267                        if (!is_valid_iface_idx(iface_idx)) {
    256                                 remote_handler_t *default_handler;
    257                                 if (NULL != (default_handler = device_get_default_handler(dev))) {
     268                                remote_handler_t *default_handler =
     269                                    device_get_default_handler(dev);
     270                                if (NULL != default_handler) {
    258271                                        (*default_handler)(dev, callid, &call);
    259272                                        break;
    260273                                }
    261                                 // this is not device's interface and the default handler is not provided
    262                                 printf("%s: driver_connection_gen error - invalid interface id %d.", driver->name, iface_idx);
     274                                /*
     275                                 * This is not device's interface and the
     276                                 * default handler is not provided.
     277                                 */
     278                                printf("%s: driver_connection_gen error - "
     279                                    "invalid interface id %d.",
     280                                    driver->name, iface_idx);
    263281                                ipc_answer_0(callid, ENOTSUP);
    264282                                break;
    265283                        }
    266284
    267                         // calling one of the device's interfaces
     285                        /* calling one of the device's interfaces */
    268286                       
    269                         // get the device interface structure
     287                        /* get the device interface structure */
    270288                        void *iface = device_get_iface(dev, iface_idx);
    271289                        if (NULL == iface) {
    272                                 printf("%s: driver_connection_gen error - ", driver->name);
    273                                 printf("device with handle %d has no interface with id %d.\n", handle, iface_idx);
     290                                printf("%s: driver_connection_gen error - ",
     291                                    driver->name);
     292                                printf("device with handle %d has no interface "
     293                                    "with id %d.\n", handle, iface_idx);
    274294                                ipc_answer_0(callid, ENOTSUP);
    275295                                break;
    276296                        }
    277297
    278                         // get the corresponding interface for remote request handling ("remote interface")
     298                        /*
     299                         * Get the corresponding interface for remote request
     300                         * handling ("remote interface").
     301                         */
    279302                        remote_iface_t* rem_iface = get_remote_iface(iface_idx);
    280303                        assert(NULL != rem_iface);
    281304
    282                         // get the method of the remote interface
     305                        /* get the method of the remote interface */
    283306                        ipcarg_t iface_method_idx = IPC_GET_ARG1(call);
    284                         remote_iface_func_ptr_t iface_method_ptr = get_remote_method(rem_iface, iface_method_idx);
     307                        remote_iface_func_ptr_t iface_method_ptr =
     308                            get_remote_method(rem_iface, iface_method_idx);
    285309                        if (NULL == iface_method_ptr) {
    286310                                // the interface has not such method
    287                                 printf("%s: driver_connection_gen error - invalid interface method.", driver->name);
     311                                printf("%s: driver_connection_gen error - "
     312                                    "invalid interface method.", driver->name);
    288313                                ipc_answer_0(callid, ENOTSUP);
    289314                                break;
    290315                        }
    291316                       
    292                         // call the remote interface's method, which will receive parameters from the remote client
    293                         // and it will pass it to the corresponding local interface method associated with the device
    294                         // by its driver
     317                        /*
     318                         * Call the remote interface's method, which will
     319                         * receive parameters from the remote client and it will
     320                         * pass it to the corresponding local interface method
     321                         * associated with the device by its driver.
     322                         */
    295323                        (*iface_method_ptr)(dev, iface, callid, &call);
    296324                        break;
     
    310338
    311339
    312 /** Function for handling connections to device driver.
    313  *
    314  */
     340/** Function for handling connections to device driver. */
    315341static void driver_connection(ipc_callid_t iid, ipc_call_t *icall)
    316342{
     
    318344        switch ((ipcarg_t) (IPC_GET_ARG1(*icall))) {
    319345        case DRIVER_DEVMAN:
    320                 // handle PnP events from device manager
     346                /* handle PnP events from device manager */
    321347                driver_connection_devman(iid, icall);
    322348                break;
    323349        case DRIVER_DRIVER:
    324                 // handle request from drivers of child devices
     350                /* handle request from drivers of child devices */
    325351                driver_connection_driver(iid, icall);
    326352                break;
    327353        case DRIVER_CLIENT:
    328                 // handle requests from client applications
     354                /* handle requests from client applications */
    329355                driver_connection_client(iid, icall);
    330356                break;
     
    338364int child_device_register(device_t *child, device_t *parent)
    339365{
    340         // printf("%s: child_device_register\n", driver->name);
    341 
    342366        assert(NULL != child->name);
    343367
     
    345369       
    346370        add_to_devices_list(child);
    347         if (EOK == (res = devman_child_device_register(child->name, &child->match_ids, parent->handle, &child->handle))) {
     371        res = devman_child_device_register(child->name, &child->match_ids,
     372            parent->handle, &child->handle);
     373        if (EOK == res)
    348374                return res;
    349         }
    350375        remove_from_devices_list(child);       
    351376        return res;
     
    354379int driver_main(driver_t *drv)
    355380{
    356         // remember the driver structure - driver_ops will be called by generic handler for incoming connections
     381        /*
     382         * Remember the driver structure - driver_ops will be called by generic
     383         * handler for incoming connections.
     384         */
    357385        driver = drv;
    358386
    359         // initialize the list of interrupt contexts
     387        /* Initialize the list of interrupt contexts. */
    360388        init_interrupt_context_list(&interrupt_contexts);
    361389       
    362         // set generic interrupt handler
     390        /* Set generic interrupt handler. */
    363391        async_set_interrupt_received(driver_irq_handler);
    364392       
    365         // register driver by device manager with generic handler for incoming connections
     393        /*
     394         * Register driver by device manager with generic handler for incoming
     395         * connections.
     396         */
    366397        devman_driver_register(driver->name, driver_connection);
    367398
    368399        async_manager();
    369400
    370         // Never reached
     401        /* Never reached. */
    371402        return 0;
    372403}
  • uspace/lib/drv/generic/remote_char.c

    ra79d88d r7a252ec8  
    11/*
    2  * Copyright (c) 2010 Lenka Trochtova 
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    4242#define MAX_CHAR_RW_COUNT 256
    4343
    44 static void remote_char_read(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call);
    45 static void remote_char_write(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call);
     44static void remote_char_read(device_t *, void *, ipc_callid_t, ipc_call_t *);
     45static void remote_char_write(device_t *, void *, ipc_callid_t, ipc_call_t *);
    4646
    47 /** Remote character interface operations.
    48  */
     47/** Remote character interface operations. */
    4948static remote_iface_func_ptr_t remote_char_iface_ops [] = {
    5049        &remote_char_read,
    51         &remote_char_write     
    52 };
    53  
    54 /** Remote character interface structure.
    55  * Interface for processing request from remote clients addressed to the character interface.
     50        &remote_char_write
     51};
     52
     53/** Remote character interface structure.
     54 *
     55 * Interface for processing request from remote clients addressed to the
     56 * character interface.
    5657 */
    5758remote_iface_t remote_char_iface = {
    58         .method_count = sizeof(remote_char_iface_ops) / sizeof(remote_iface_func_ptr_t),
     59        .method_count = sizeof(remote_char_iface_ops) /
     60            sizeof(remote_iface_func_ptr_t),
    5961        .methods = remote_char_iface_ops
    6062};
    6163
    6264/** Process the read request from the remote client.
    63  *
    64  * Receive the read request's parameters from the remote client and pass them to the local interface.
    65  * Return the result of the operation processed by the local interface to the remote client.
    66  *
    67  * @param dev the device from which the data are read.
    68  * @param iface the local interface structure.
     65 *
     66 * Receive the read request's parameters from the remote client and pass them
     67 * to the local interface. Return the result of the operation processed by the
     68 * local interface to the remote client.
     69 *
     70 * @param dev           The device from which the data are read.
     71 * @param iface         The local interface structure.
    6972 */
    70 static void remote_char_read(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call)
     73static void
     74remote_char_read(device_t *dev, void *iface, ipc_callid_t callid,
     75    ipc_call_t *call)
    7176{       
    72         char_iface_t *char_iface = (char_iface_t *)iface;
     77        char_iface_t *char_iface = (char_iface_t *) iface;
    7378        ipc_callid_t cid;
    7479       
    7580        size_t len;
    7681        if (!async_data_read_receive(&cid, &len)) {
    77                 // TODO handle protocol error
     82                /* TODO handle protocol error. */
    7883                ipc_answer_0(callid, EINVAL);
    7984                return;
     
    8691        }
    8792       
    88         if (len > MAX_CHAR_RW_COUNT) {
     93        if (len > MAX_CHAR_RW_COUNT)
    8994                len = MAX_CHAR_RW_COUNT;
    90         }
    9195       
    9296        char buf[MAX_CHAR_RW_COUNT];
    9397        int ret = (*char_iface->read)(dev, buf, len);
    9498       
    95         if (ret < 0) { // some error occured
     99        if (ret < 0) {
     100                /* Some error occured. */
    96101                async_data_read_finalize(cid, buf, 0);
    97102                ipc_answer_0(callid, ret);
     
    99104        }
    100105       
    101         // the operation was successful, return the number of data read
     106        /* The operation was successful, return the number of data read. */
    102107        async_data_read_finalize(cid, buf, ret);
    103         ipc_answer_1(callid, EOK, ret); 
     108        ipc_answer_1(callid, EOK, ret);
    104109}
    105110
    106111/** Process the write request from the remote client.
    107  *
    108  * Receive the write request's parameters from the remote client and pass them to the local interface.
    109  * Return the result of the operation processed by the local interface to the remote client.
    110  *
    111  * @param dev the device to which the data are written.
    112  * @param iface the local interface structure.
     112 *
     113 * Receive the write request's parameters from the remote client and pass them
     114 * to the local interface. Return the result of the operation processed by the
     115 * local interface to the remote client.
     116 *
     117 * @param dev           The device to which the data are written.
     118 * @param iface         The local interface structure.
    113119 */
    114 static void remote_char_write(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call)
     120static void
     121remote_char_write(device_t *dev, void *iface, ipc_callid_t callid,
     122    ipc_call_t *call)
    115123{
    116         char_iface_t *char_iface = (char_iface_t *)iface;
     124        char_iface_t *char_iface = (char_iface_t *) iface;
    117125        ipc_callid_t cid;
    118126        size_t len;
    119127       
    120128        if (!async_data_write_receive(&cid, &len)) {
    121                 // TODO handle protocol error
     129                /* TODO handle protocol error. */
    122130                ipc_answer_0(callid, EINVAL);
    123131                return;
    124     }
     132        }
    125133       
    126134        if (!char_iface->write) {
     
    130138        }       
    131139       
    132         if (len > MAX_CHAR_RW_COUNT) {
     140        if (len > MAX_CHAR_RW_COUNT)
    133141                len = MAX_CHAR_RW_COUNT;
    134         }
    135142       
    136143        char buf[MAX_CHAR_RW_COUNT];
     
    139146       
    140147        int ret = (*char_iface->write)(dev, buf, len);
    141         if (ret < 0) { // some error occured
     148        if (ret < 0) {
     149                /* Some error occured. */
    142150                ipc_answer_0(callid, ret);
    143151        } else {
    144                 // the operation was successful, return the number of data written
     152                /*
     153                 * The operation was successful, return the number of data
     154                 * written.
     155                 */
    145156                ipc_answer_1(callid, EOK, ret);
    146157        }
    147158}
    148159
    149  /**
     160/**
    150161 * @}
    151162 */
  • uspace/lib/drv/generic/remote_res.c

    ra79d88d r7a252ec8  
    11/*
    2  * Copyright (c) 2010 Lenka Trochtova 
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    4040#include "resource.h"
    4141
    42  
    43 static void remote_res_get_resources(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call);
    44 static void remote_res_enable_interrupt(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call);
     42static void remote_res_get_resources(device_t *, void *, ipc_callid_t,
     43    ipc_call_t *);
     44static void remote_res_enable_interrupt(device_t *, void *, ipc_callid_t,
     45    ipc_call_t *);
    4546
    4647static remote_iface_func_ptr_t remote_res_iface_ops [] = {
    4748        &remote_res_get_resources,
    48         &remote_res_enable_interrupt   
    49 }; 
    50  
     49        &remote_res_enable_interrupt
     50};
     51
    5152remote_iface_t remote_res_iface = {
    52         .method_count = sizeof(remote_res_iface_ops) / sizeof(remote_iface_func_ptr_t),
     53        .method_count = sizeof(remote_res_iface_ops) /
     54            sizeof(remote_iface_func_ptr_t),
    5355        .methods = remote_res_iface_ops
    5456};
    5557
    56 static void remote_res_enable_interrupt(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call)
     58static void remote_res_enable_interrupt(device_t *dev, void *iface,
     59    ipc_callid_t callid, ipc_call_t *call)
    5760{
    58         resource_iface_t *ires = (resource_iface_t *)iface;
     61        resource_iface_t *ires = (resource_iface_t *) iface;
    5962       
    60         if (NULL == ires->enable_interrupt) {
     63        if (NULL == ires->enable_interrupt)
    6164                ipc_answer_0(callid, ENOTSUP);
    62         } else if (ires->enable_interrupt(dev)) {
     65        else if (ires->enable_interrupt(dev))
    6366                ipc_answer_0(callid, EOK);
    64         } else {
     67        else
    6568                ipc_answer_0(callid, EREFUSED);
    66         }       
    6769}
    6870
    69 static void remote_res_get_resources(device_t *dev, void *iface, ipc_callid_t callid, ipc_call_t *call)
     71static void remote_res_get_resources(device_t *dev, void *iface,
     72    ipc_callid_t callid, ipc_call_t *call)
    7073{
    71         resource_iface_t *ires = (resource_iface_t *)iface;     
     74        resource_iface_t *ires = (resource_iface_t *) iface;
    7275        if (NULL == ires->get_resources) {
    7376                ipc_answer_0(callid, ENOTSUP);
     
    7578        }
    7679       
    77         hw_resource_list_t *hw_resources = ires->get_resources(dev);   
     80        hw_resource_list_t *hw_resources = ires->get_resources(dev);
    7881        if (NULL == hw_resources){
    7982                ipc_answer_0(callid, ENOENT);
     
    8588        size_t len;
    8689        if (!async_data_read_receive(&callid, &len)) {
    87                 // protocol error - the recipient is not accepting data
     90                /* protocol error - the recipient is not accepting data */
    8891                return;
    8992        }
    9093        async_data_read_finalize(callid, hw_resources->resources, len);
    9194}
    92  
    93  
    94  /**
     95
     96/**
    9597 * @}
    9698 */
  • uspace/lib/drv/include/char.h

    ra79d88d r7a252ec8  
    11/*
    2  * Copyright (c) 2010 Lenka Trochtova 
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    3232/** @file
    3333 */
     34
    3435#ifndef LIBDRV_CHAR_H_
    3536#define LIBDRV_CHAR_H_
     
    3839
    3940typedef struct char_iface {
    40         int (*read)(device_t *dev, char *buf, size_t count);
    41         int (*write)(device_t *dev, char *buf, size_t count);   
     41        int (*read)(device_t *, char *, size_t);
     42        int (*write)(device_t *, char *, size_t);
    4243} char_iface_t;
    4344
  • uspace/lib/drv/include/dev_iface.h

    ra79d88d r7a252ec8  
    11/*
    2  * Copyright (c) 2010 Lenka Trochtova 
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    3232/** @file
    3333 */
     34
    3435#ifndef LIBDRV_DEV_IFACE_H_
    3536#define LIBDRV_DEV_IFACE_H_
     
    3738#include "driver.h"
    3839
    39 
    40 // TODO declare device interface structures here
     40/* TODO declare device interface structures here */
    4141
    4242#endif
  • uspace/lib/drv/include/driver.h

    ra79d88d r7a252ec8  
    3232/** @file
    3333 */
     34
    3435#ifndef LIBDRV_DRIVER_H_
    3536#define LIBDRV_DRIVER_H_
    36 
    3737
    3838#include <adt/list.h>
     
    5252typedef struct device device_t;
    5353
    54 // device interface
    55 
    56 // first two parameters: device and interface structure registered by the devices driver
    57 typedef void remote_iface_func_t(device_t*, void *, ipc_callid_t, ipc_call_t *);
     54/* device interface */
     55
     56/*
     57 * First two parameters: device and interface structure registered by the
     58 * devices driver.
     59 */
     60typedef void remote_iface_func_t(device_t *, void *, ipc_callid_t,
     61    ipc_call_t *);
    5862typedef remote_iface_func_t *remote_iface_func_ptr_t;
    59 typedef void remote_handler_t(device_t*, ipc_callid_t, ipc_call_t *);
     63typedef void remote_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
    6064
    6165typedef struct {
     
    6569
    6670typedef struct {
    67         remote_iface_t * ifaces[DEV_IFACE_COUNT];
     71        remote_iface_t *ifaces[DEV_IFACE_COUNT];
    6872} iface_dipatch_table_t;
    6973
     
    7478}
    7579
    76 remote_iface_t* get_remote_iface(int idx);
    77 remote_iface_func_ptr_t get_remote_method(remote_iface_t *rem_iface, ipcarg_t iface_method_idx);
    78 
    79 
    80 // device class
     80remote_iface_t *get_remote_iface(int);
     81remote_iface_func_ptr_t get_remote_method(remote_iface_t *, ipcarg_t);
     82
     83
     84/* device class */
    8185
    8286/** Devices operations. */
    8387typedef struct device_ops {
    84         /** Optional callback function called when a client is connecting to the device. */
    85         int (*open)(device_t *dev);
    86         /** Optional callback function called when a client is disconnecting from the device. */
    87         void (*close)(device_t *dev);
     88        /**
     89         * Optional callback function called when a client is connecting to the
     90         * device.
     91         */
     92        int (*open)(device_t *);
     93       
     94        /**
     95         * Optional callback function called when a client is disconnecting from
     96         * the device.
     97         */
     98        void (*close)(device_t *);
     99       
    88100        /** The table of standard interfaces implemented by the device. */
    89         void *interfaces[DEV_IFACE_COUNT];     
    90         /** The default handler of remote client requests. If the client's remote request cannot be handled
    91          * by any of the standard interfaces, the default handler is used.*/
     101        void *interfaces[DEV_IFACE_COUNT];
     102       
     103        /**
     104         * The default handler of remote client requests. If the client's remote
     105         * request cannot be handled by any of the standard interfaces, the
     106         * default handler is used.
     107         */
    92108        remote_handler_t *default_handler;
    93109} device_ops_t;
    94110
    95111
    96 // device
     112/* device */
    97113
    98114/** The device. */
    99115struct device {
    100         /** Globally unique device identifier (assigned to the device by the device manager). */
     116        /**
     117         * Globally unique device identifier (assigned to the device by the
     118         * device manager).
     119         */
    101120        device_handle_t handle;
    102         /** The phone to the parent device driver (if it is different from this driver).*/
     121       
     122        /**
     123         * The phone to the parent device driver (if it is different from this
     124         * driver).
     125         */
    103126        int parent_phone;
     127       
    104128        /** Parent device if handled by this driver, NULL otherwise. */
    105129        device_t *parent;
    106         /** The device's name.*/
     130        /** The device's name. */
    107131        const char *name;
    108         /** The list of device ids for device-to-driver matching.*/
     132        /** The list of device ids for device-to-driver matching. */
    109133        match_id_list_t match_ids;
    110         /** The device driver's data associated with this device.*/
     134        /** The device driver's data associated with this device. */
    111135        void *driver_data;
    112         /** The implementation of operations provided by this device.*/
     136        /** The implementation of operations provided by this device. */
    113137        device_ops_t *ops;
    114         /** Pointer to the previous and next device in the list of devices handled by the driver */
     138       
     139        /**
     140         * Pointer to the previous and next device in the list of devices
     141         * handled by the driver.
     142         */
    115143        link_t link;
    116144};
    117145
    118146
    119 // driver
     147/* driver */
    120148
    121149/** Generic device driver operations. */
     
    123151        /** Callback method for passing a new device to the device driver.*/
    124152        int (*add_device)(device_t *dev);
    125         // TODO add other generic driver operations
     153        /* TODO add other generic driver operations */
    126154} driver_ops_t;
    127155
     
    134162} driver_t;
    135163
    136 int driver_main(driver_t *drv);
    137 
    138 /** Create new device structure. 
    139  * 
    140  * @return the device structure.
    141  */
    142 static inline device_t * create_device()
     164int driver_main(driver_t *);
     165
     166/** Create new device structure.
     167 *
     168 * @return              The device structure.
     169 */
     170static inline device_t *create_device(void)
    143171{
    144172        device_t *dev = malloc(sizeof(device_t));
     
    150178}
    151179
    152 /** Delete device structure. 
    153  * 
    154  * @param dev the device structure.
     180/** Delete device structure.
     181 *
     182 * @param dev           The device structure.
    155183 */
    156184static inline void delete_device(device_t *dev)
    157185{
    158186        clean_match_ids(&dev->match_ids);
    159         if (NULL != dev->name) {
     187        if (NULL != dev->name)
    160188                free(dev->name);
    161         }
    162189        free(dev);
    163190}
    164191
    165 static inline void * device_get_iface(device_t *dev, dev_inferface_idx_t idx)
    166 {
    167         assert(is_valid_iface_idx(idx));       
    168         if (NULL == dev->ops) {
     192static inline void *device_get_iface(device_t *dev, dev_inferface_idx_t idx)
     193{
     194        assert(is_valid_iface_idx(idx));
     195        if (NULL == dev->ops)
    169196                return NULL;
    170         }
    171         return dev->ops->interfaces[idx];       
    172 }
    173 
    174 int child_device_register(device_t *child, device_t *parent);
    175 
    176 // interrupts
    177 
    178 typedef void interrupt_handler_t(device_t *dev, ipc_callid_t iid, ipc_call_t *icall);
     197        return dev->ops->interfaces[idx];
     198}
     199
     200int child_device_register(device_t *, device_t *);
     201
     202
     203/* interrupts */
     204
     205typedef void interrupt_handler_t(device_t *, ipc_callid_t, ipc_call_t *);
    179206
    180207typedef struct interrupt_context {
     
    192219} interrupt_context_list_t;
    193220
    194 static inline interrupt_context_t * create_interrupt_context()
    195 {
    196         interrupt_context_t *ctx = (interrupt_context_t *)malloc(sizeof(interrupt_context_t));
    197         if (NULL != ctx) {
     221static inline interrupt_context_t *create_interrupt_context(void)
     222{
     223        interrupt_context_t *ctx;
     224       
     225        ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
     226        if (NULL != ctx)
    198227                memset(ctx, 0, sizeof(interrupt_context_t));
    199         }
     228       
    200229        return ctx;
    201230}
     
    203232static inline void delete_interrupt_context(interrupt_context_t *ctx)
    204233{
    205         if (NULL != ctx) {
     234        if (NULL != ctx)
    206235                free(ctx);
    207         }
    208236}
    209237
     
    212240        memset(list, 0, sizeof(interrupt_context_list_t));
    213241        fibril_mutex_initialize(&list->mutex);
    214         list_initialize(&list->contexts);       
    215 }
    216 
    217 static inline void add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
     242        list_initialize(&list->contexts);
     243}
     244
     245static inline void
     246add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
    218247{
    219248        fibril_mutex_lock(&list->mutex);
    220        
    221249        ctx->id = list->curr_id++;
    222250        list_append(&ctx->link, &list->contexts);
    223        
    224251        fibril_mutex_unlock(&list->mutex);
    225252}
    226253
    227 static inline void remove_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
     254static inline void
     255remove_interrupt_context(interrupt_context_list_t *list,
     256    interrupt_context_t *ctx)
    228257{
    229258        fibril_mutex_lock(&list->mutex);
    230        
    231259        list_remove(&ctx->link);
    232        
    233260        fibril_mutex_unlock(&list->mutex);
    234261}
    235262
    236 static inline interrupt_context_t *find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    237 {
    238         fibril_mutex_lock(&list->mutex);       
     263static inline interrupt_context_t *
     264find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
     265{
     266        fibril_mutex_lock(&list->mutex);
     267       
    239268        link_t *link = list->contexts.next;
    240269        interrupt_context_t *ctx;
     
    247276                }
    248277                link = link->next;
    249         }       
    250         fibril_mutex_unlock(&list->mutex);     
     278        }
     279       
     280        fibril_mutex_unlock(&list->mutex);
    251281        return NULL;
    252282}
    253283
    254 static inline interrupt_context_t *find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq)
    255 {
    256         fibril_mutex_lock(&list->mutex);       
     284static inline interrupt_context_t *
     285find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq)
     286{
     287        fibril_mutex_lock(&list->mutex);
     288       
    257289        link_t *link = list->contexts.next;
    258290        interrupt_context_t *ctx;
     
    265297                }
    266298                link = link->next;
    267         }       
    268         fibril_mutex_unlock(&list->mutex);     
     299        }
     300       
     301        fibril_mutex_unlock(&list->mutex);
    269302        return NULL;
    270303}
    271304
    272 int register_interrupt_handler(device_t *dev, int irq, interrupt_handler_t *handler, irq_code_t *pseudocode);
    273 int unregister_interrupt_handler(device_t *dev, int irq);
    274 
    275 
    276 // default handler for client requests
    277 
    278 static inline remote_handler_t * device_get_default_handler(device_t *dev)
    279 {
    280         if (NULL == dev->ops) {
     305int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
     306    irq_code_t *);
     307int unregister_interrupt_handler(device_t *, int);
     308
     309
     310/* default handler for client requests */
     311
     312static inline remote_handler_t *device_get_default_handler(device_t *dev)
     313{
     314        if (NULL == dev->ops)
    281315                return NULL;
    282         }
    283        
    284         return dev->ops->default_handler;       
     316        return dev->ops->default_handler;
    285317}
    286318
  • uspace/lib/drv/include/remote_char.h

    ra79d88d r7a252ec8  
    11/*
    2  * Copyright (c) 2010 Lenka Trochtova 
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    3232/** @file
    3333 */
     34
    3435#ifndef LIBDRV_REMOTE_CHAR_H_
    3536#define LIBDRV_REMOTE_CHAR_H_
  • uspace/lib/drv/include/remote_res.h

    ra79d88d r7a252ec8  
    11/*
    2  * Copyright (c) 2010 Lenka Trochtova 
     2 * Copyright (c) 2010 Lenka Trochtova
    33 * All rights reserved.
    44 *
     
    3232/** @file
    3333 */
     34
    3435#ifndef LIBDRV_REMOTE_RES_H_
    3536#define LIBDRV_REMOTE_RES_H_
  • uspace/lib/drv/include/resource.h

    ra79d88d r7a252ec8  
    3232/** @file
    3333 */
     34
    3435#ifndef LIBDRV_RESOURCE_H_
    3536#define LIBDRV_RESOURCE_H_
     
    3839
    3940typedef struct resource_iface {
    40          hw_resource_list_t * (*get_resources)(device_t *dev);
    41          bool (*enable_interrupt)(device_t *dev);       
     41         hw_resource_list_t *(* get_resources)(device_t *);
     42         bool (*enable_interrupt)(device_t *);
    4243} resource_iface_t;
    4344
Note: See TracChangeset for help on using the changeset viewer.