Changeset 7a252ec8 in mainline for uspace/lib/drv/include/driver.h


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.