linux/drivers/staging/tidspbridge/pmgr/chnl.c
<<
>>
Prefs
   1/*
   2 * chnl.c
   3 *
   4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
   5 *
   6 * DSP API channel interface: multiplexes data streams through the single
   7 * physical link managed by a Bridge Bridge driver.
   8 *
   9 * Copyright (C) 2005-2006 Texas Instruments, Inc.
  10 *
  11 * This package is free software; you can redistribute it and/or modify
  12 * it under the terms of the GNU General Public License version 2 as
  13 * published by the Free Software Foundation.
  14 *
  15 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  16 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  17 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  18 */
  19
  20#include <linux/types.h>
  21/*  ----------------------------------- Host OS */
  22#include <dspbridge/host_os.h>
  23
  24/*  ----------------------------------- DSP/BIOS Bridge */
  25#include <dspbridge/dbdefs.h>
  26
  27/*  ----------------------------------- OS Adaptation Layer */
  28#include <dspbridge/sync.h>
  29
  30/*  ----------------------------------- Platform Manager */
  31#include <dspbridge/proc.h>
  32#include <dspbridge/dev.h>
  33
  34/*  ----------------------------------- Others */
  35#include <dspbridge/chnlpriv.h>
  36#include <chnlobj.h>
  37
  38/*  ----------------------------------- This */
  39#include <dspbridge/chnl.h>
  40
  41/*
  42 *  ======== chnl_create ========
  43 *  Purpose:
  44 *      Create a channel manager object, responsible for opening new channels
  45 *      and closing old ones for a given 'Bridge board.
  46 */
  47int chnl_create(struct chnl_mgr **channel_mgr,
  48                       struct dev_object *hdev_obj,
  49                       const struct chnl_mgrattrs *mgr_attrts)
  50{
  51        int status;
  52        struct chnl_mgr *hchnl_mgr;
  53        struct chnl_mgr_ *chnl_mgr_obj = NULL;
  54
  55        *channel_mgr = NULL;
  56
  57        /* Validate args: */
  58        if ((0 < mgr_attrts->max_channels) &&
  59            (mgr_attrts->max_channels <= CHNL_MAXCHANNELS))
  60                status = 0;
  61        else if (mgr_attrts->max_channels == 0)
  62                status = -EINVAL;
  63        else
  64                status = -ECHRNG;
  65
  66        if (mgr_attrts->word_size == 0)
  67                status = -EINVAL;
  68
  69        if (!status) {
  70                status = dev_get_chnl_mgr(hdev_obj, &hchnl_mgr);
  71                if (!status && hchnl_mgr != NULL)
  72                        status = -EEXIST;
  73
  74        }
  75
  76        if (!status) {
  77                struct bridge_drv_interface *intf_fxns;
  78                dev_get_intf_fxns(hdev_obj, &intf_fxns);
  79                /* Let Bridge channel module finish the create: */
  80                status = (*intf_fxns->chnl_create) (&hchnl_mgr, hdev_obj,
  81                                                        mgr_attrts);
  82                if (!status) {
  83                        /* Fill in DSP API channel module's fields of the
  84                         * chnl_mgr structure */
  85                        chnl_mgr_obj = (struct chnl_mgr_ *)hchnl_mgr;
  86                        chnl_mgr_obj->intf_fxns = intf_fxns;
  87                        /* Finally, return the new channel manager handle: */
  88                        *channel_mgr = hchnl_mgr;
  89                }
  90        }
  91
  92        return status;
  93}
  94
  95/*
  96 *  ======== chnl_destroy ========
  97 *  Purpose:
  98 *      Close all open channels, and destroy the channel manager.
  99 */
 100int chnl_destroy(struct chnl_mgr *hchnl_mgr)
 101{
 102        struct chnl_mgr_ *chnl_mgr_obj = (struct chnl_mgr_ *)hchnl_mgr;
 103        struct bridge_drv_interface *intf_fxns;
 104        int status;
 105
 106        if (chnl_mgr_obj) {
 107                intf_fxns = chnl_mgr_obj->intf_fxns;
 108                /* Let Bridge channel module destroy the chnl_mgr: */
 109                status = (*intf_fxns->chnl_destroy) (hchnl_mgr);
 110        } else {
 111                status = -EFAULT;
 112        }
 113
 114        return status;
 115}
 116