Changeset 5fdd7c3 in mainline for uspace/lib/drv/generic/driver.c


Ignore:
Timestamp:
2011-01-09T20:41:07Z (14 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.

File:
1 edited

Legend:

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