linux/drivers/staging/tidspbridge/pmgr/io.c
<<
>>
Prefs
   1/*
   2 * io.c
   3 *
   4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
   5 *
   6 * IO manager interface: Manages IO between CHNL and msg_ctrl.
   7 *
   8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
   9 *
  10 * This package is free software; you can redistribute it and/or modify
  11 * it under the terms of the GNU General Public License version 2 as
  12 * published by the Free Software Foundation.
  13 *
  14 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  16 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  17 */
  18#include <linux/types.h>
  19
  20/*  ----------------------------------- Host OS */
  21#include <dspbridge/host_os.h>
  22
  23/*  ----------------------------------- DSP/BIOS Bridge */
  24#include <dspbridge/dbdefs.h>
  25
  26/*  ----------------------------------- Trace & Debug */
  27#include <dspbridge/dbc.h>
  28
  29/*  ----------------------------------- Platform Manager */
  30#include <dspbridge/dev.h>
  31
  32/*  ----------------------------------- This */
  33#include <ioobj.h>
  34#include <dspbridge/iodefs.h>
  35#include <dspbridge/io.h>
  36
  37/*  ----------------------------------- Globals */
  38static u32 refs;
  39
  40/*
  41 *  ======== io_create ========
  42 *  Purpose:
  43 *      Create an IO manager object, responsible for managing IO between
  44 *      CHNL and msg_ctrl
  45 */
  46int io_create(struct io_mgr **io_man, struct dev_object *hdev_obj,
  47                     const struct io_attrs *mgr_attrts)
  48{
  49        struct bridge_drv_interface *intf_fxns;
  50        struct io_mgr *hio_mgr = NULL;
  51        struct io_mgr_ *pio_mgr = NULL;
  52        int status = 0;
  53
  54        DBC_REQUIRE(refs > 0);
  55        DBC_REQUIRE(io_man != NULL);
  56        DBC_REQUIRE(mgr_attrts != NULL);
  57
  58        *io_man = NULL;
  59
  60        /* A memory base of 0 implies no memory base: */
  61        if ((mgr_attrts->shm_base != 0) && (mgr_attrts->usm_length == 0))
  62                status = -EINVAL;
  63
  64        if (mgr_attrts->word_size == 0)
  65                status = -EINVAL;
  66
  67        if (!status) {
  68                dev_get_intf_fxns(hdev_obj, &intf_fxns);
  69
  70                /* Let Bridge channel module finish the create: */
  71                status = (*intf_fxns->pfn_io_create) (&hio_mgr, hdev_obj,
  72                                                      mgr_attrts);
  73
  74                if (!status) {
  75                        pio_mgr = (struct io_mgr_ *)hio_mgr;
  76                        pio_mgr->intf_fxns = intf_fxns;
  77                        pio_mgr->hdev_obj = hdev_obj;
  78
  79                        /* Return the new channel manager handle: */
  80                        *io_man = hio_mgr;
  81                }
  82        }
  83
  84        return status;
  85}
  86
  87/*
  88 *  ======== io_destroy ========
  89 *  Purpose:
  90 *      Delete IO manager.
  91 */
  92int io_destroy(struct io_mgr *hio_mgr)
  93{
  94        struct bridge_drv_interface *intf_fxns;
  95        struct io_mgr_ *pio_mgr = (struct io_mgr_ *)hio_mgr;
  96        int status;
  97
  98        DBC_REQUIRE(refs > 0);
  99
 100        intf_fxns = pio_mgr->intf_fxns;
 101
 102        /* Let Bridge channel module destroy the io_mgr: */
 103        status = (*intf_fxns->pfn_io_destroy) (hio_mgr);
 104
 105        return status;
 106}
 107
 108/*
 109 *  ======== io_exit ========
 110 *  Purpose:
 111 *      Discontinue usage of the IO module.
 112 */
 113void io_exit(void)
 114{
 115        DBC_REQUIRE(refs > 0);
 116
 117        refs--;
 118
 119        DBC_ENSURE(refs >= 0);
 120}
 121
 122/*
 123 *  ======== io_init ========
 124 *  Purpose:
 125 *      Initialize the IO module's private state.
 126 */
 127bool io_init(void)
 128{
 129        bool ret = true;
 130
 131        DBC_REQUIRE(refs >= 0);
 132
 133        if (ret)
 134                refs++;
 135
 136        DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));
 137
 138        return ret;
 139}
 140