Changeset 5fdd7c3 in mainline


Ignore:
Timestamp:
2011-01-09T20:41:07Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
22027b6e
Parents:
97adec8
Message:

Say no to static functions.

Location:
uspace/lib/drv
Files:
4 edited

Legend:

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

    r97adec8 r5fdd7c3  
    6363}
    6464
     65bool is_valid_iface_idx(int idx)
     66{
     67        return (0 <= idx) && (idx < DEV_IFACE_MAX);
     68}
     69
    6570/**
    6671 * @}
  • uspace/lib/drv/generic/driver.c

    r97adec8 r5fdd7c3  
    5252#include <ipc/driver.h>
    5353
     54#include "dev_iface.h"
    5455#include "driver.h"
    5556
     
    8586                (*ctx->handler)(ctx->dev, iid, icall);
    8687}
     88
     89interrupt_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
     100void delete_interrupt_context(interrupt_context_t *ctx)
     101{
     102        if (ctx != NULL)
     103                free(ctx);
     104}
     105
     106void 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
     113void
     114add_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
     122void 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
     130interrupt_context_t *
     131find_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
     151interrupt_context_t *
     152find_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
    87172
    88173int
     
    365450}
    366451
     452/** Create new device structure.
     453 *
     454 * @return              The device structure.
     455 */
     456device_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 */
     472void 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
     480void *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
    367488int child_device_register(device_t *child, device_t *parent)
    368489{
     
    435556}
    436557
     558/** Get default handler for client requests */
     559remote_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
     566int add_device_to_class(device_t *dev, const char *class_name)
     567{
     568        return devman_add_device_to_class(dev->handle, class_name);
     569}
     570
    437571int driver_main(driver_t *drv)
    438572{
  • uspace/lib/drv/include/dev_iface.h

    r97adec8 r5fdd7c3  
    4040/* TODO declare device interface structures here */
    4141
     42extern bool is_valid_iface_idx(int);
     43
     44
    4245#endif
    4346
  • uspace/lib/drv/include/driver.h

    r97adec8 r5fdd7c3  
    7272} iface_dipatch_table_t;
    7373
    74 
    75 static inline bool is_valid_iface_idx(int idx)
    76 {
    77         return (0 <= idx) && (idx < DEV_IFACE_MAX);
    78 }
    79 
    80 remote_iface_t *get_remote_iface(int);
    81 remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t);
    82 
     74extern remote_iface_t *get_remote_iface(int);
     75extern remote_iface_func_ptr_t get_remote_method(remote_iface_t *, sysarg_t);
    8376
    8477/*
     
    171164 * @return              The device structure.
    172165 */
    173 static inline device_t *create_device(void)
    174 {
    175         device_t *dev = malloc(sizeof(device_t));
    176 
    177         if (dev != NULL) {
    178                 memset(dev, 0, sizeof(device_t));
    179                 init_match_ids(&dev->match_ids);
    180         }
    181 
    182         return dev;
    183 }
    184 
    185 /** Delete device structure.
    186  *
    187  * @param dev           The device structure.
    188  */
    189 static inline void delete_device(device_t *dev)
    190 {
    191         clean_match_ids(&dev->match_ids);
    192         if (dev->name != NULL)
    193                 free(dev->name);
    194         free(dev);
    195 }
    196 
    197 static inline void *device_get_ops(device_t *dev, dev_inferface_idx_t idx)
    198 {
    199         assert(is_valid_iface_idx(idx));
    200         if (dev->ops == NULL)
    201                 return NULL;
    202         return dev->ops->interfaces[idx];
    203 }
    204 
    205 int child_device_register(device_t *, device_t *);
    206 int child_device_register_wrapper(device_t *, const char *, const char *, int);
     166extern device_t *create_device(void);
     167extern void delete_device(device_t *);
     168extern void *device_get_ops(device_t *, dev_inferface_idx_t);
     169
     170extern int child_device_register(device_t *, device_t *);
     171extern int child_device_register_wrapper(device_t *, const char *, const char *,
     172    int);
    207173
    208174/*
     
    226192} interrupt_context_list_t;
    227193
    228 static inline interrupt_context_t *create_interrupt_context(void)
    229 {
    230         interrupt_context_t *ctx;
    231        
    232         ctx = (interrupt_context_t *) malloc(sizeof(interrupt_context_t));
    233         if (ctx != NULL)
    234                 memset(ctx, 0, sizeof(interrupt_context_t));
    235        
    236         return ctx;
    237 }
    238 
    239 static inline void delete_interrupt_context(interrupt_context_t *ctx)
    240 {
    241         if (ctx != NULL)
    242                 free(ctx);
    243 }
    244 
    245 static inline void init_interrupt_context_list(interrupt_context_list_t *list)
    246 {
    247         memset(list, 0, sizeof(interrupt_context_list_t));
    248         fibril_mutex_initialize(&list->mutex);
    249         list_initialize(&list->contexts);
    250 }
    251 
    252 static inline void
    253 add_interrupt_context(interrupt_context_list_t *list, interrupt_context_t *ctx)
    254 {
    255         fibril_mutex_lock(&list->mutex);
    256         ctx->id = list->curr_id++;
    257         list_append(&ctx->link, &list->contexts);
    258         fibril_mutex_unlock(&list->mutex);
    259 }
    260 
    261 static inline void
    262 remove_interrupt_context(interrupt_context_list_t *list,
    263     interrupt_context_t *ctx)
    264 {
    265         fibril_mutex_lock(&list->mutex);
    266         list_remove(&ctx->link);
    267         fibril_mutex_unlock(&list->mutex);
    268 }
    269 
    270 static inline interrupt_context_t *
    271 find_interrupt_context_by_id(interrupt_context_list_t *list, int id)
    272 {
    273         fibril_mutex_lock(&list->mutex);
    274        
    275         link_t *link = list->contexts.next;
    276         interrupt_context_t *ctx;
    277        
    278         while (link != &list->contexts) {
    279                 ctx = list_get_instance(link, interrupt_context_t, link);
    280                 if (ctx->id == id) {
    281                         fibril_mutex_unlock(&list->mutex);
    282                         return ctx;
    283                 }
    284                 link = link->next;
    285         }
    286        
    287         fibril_mutex_unlock(&list->mutex);
    288         return NULL;
    289 }
    290 
    291 static inline interrupt_context_t *
    292 find_interrupt_context(interrupt_context_list_t *list, device_t *dev, int irq)
    293 {
    294         fibril_mutex_lock(&list->mutex);
    295        
    296         link_t *link = list->contexts.next;
    297         interrupt_context_t *ctx;
    298        
    299         while (link != &list->contexts) {
    300                 ctx = list_get_instance(link, interrupt_context_t, link);
    301                 if (ctx->irq == irq && ctx->dev == dev) {
    302                         fibril_mutex_unlock(&list->mutex);
    303                         return ctx;
    304                 }
    305                 link = link->next;
    306         }
    307        
    308         fibril_mutex_unlock(&list->mutex);
    309         return NULL;
    310 }
    311 
    312 int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
     194extern interrupt_context_t *create_interrupt_context(void);
     195extern void delete_interrupt_context(interrupt_context_t *);
     196extern void init_interrupt_context_list(interrupt_context_list_t *);
     197extern void add_interrupt_context(interrupt_context_list_t *,
     198    interrupt_context_t *);
     199extern void remove_interrupt_context(interrupt_context_list_t *,
     200    interrupt_context_t *);
     201extern interrupt_context_t *find_interrupt_context_by_id(
     202    interrupt_context_list_t *, int);
     203extern interrupt_context_t *find_interrupt_context(
     204    interrupt_context_list_t *, device_t *, int);
     205
     206extern int register_interrupt_handler(device_t *, int, interrupt_handler_t *,
    313207    irq_code_t *);
    314 int unregister_interrupt_handler(device_t *, int);
    315 
    316 
    317 /** Get default handler for client requests */
    318 static inline remote_handler_t *device_get_default_handler(device_t *dev)
    319 {
    320         if (dev->ops == NULL)
    321                 return NULL;
    322         return dev->ops->default_handler;
    323 }
    324 
    325 static inline int add_device_to_class(device_t *dev, const char *class_name)
    326 {
    327         return devman_add_device_to_class(dev->handle, class_name);
    328 }
     208extern int unregister_interrupt_handler(device_t *, int);
     209
     210extern remote_handler_t *device_get_default_handler(device_t *);
     211extern int add_device_to_class(device_t *, const char *);
    329212
    330213#endif
Note: See TracChangeset for help on using the changeset viewer.