Changeset 7a252ec8 in mainline for uspace/lib/drv/generic


Ignore:
Timestamp:
2010-10-21T20:13:40Z (15 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/generic
Files:
4 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 */
Note: See TracChangeset for help on using the changeset viewer.