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/* ----------------------------------- OS Adaptation Layer */ 30#include <dspbridge/cfg.h> 31 32/* ----------------------------------- Platform Manager */ 33#include <dspbridge/dev.h> 34 35/* ----------------------------------- This */ 36#include <ioobj.h> 37#include <dspbridge/iodefs.h> 38#include <dspbridge/io.h> 39 40/* ----------------------------------- Globals */ 41static u32 refs; 42 43/* 44 * ======== io_create ======== 45 * Purpose: 46 * Create an IO manager object, responsible for managing IO between 47 * CHNL and msg_ctrl 48 */ 49int io_create(struct io_mgr **io_man, struct dev_object *hdev_obj, 50 const struct io_attrs *mgr_attrts) 51{ 52 struct bridge_drv_interface *intf_fxns; 53 struct io_mgr *hio_mgr = NULL; 54 struct io_mgr_ *pio_mgr = NULL; 55 int status = 0; 56 57 DBC_REQUIRE(refs > 0); 58 DBC_REQUIRE(io_man != NULL); 59 DBC_REQUIRE(mgr_attrts != NULL); 60 61 *io_man = NULL; 62 63 /* A memory base of 0 implies no memory base: */ 64 if ((mgr_attrts->shm_base != 0) && (mgr_attrts->usm_length == 0)) 65 status = -EINVAL; 66 67 if (mgr_attrts->word_size == 0) 68 status = -EINVAL; 69 70 if (!status) { 71 dev_get_intf_fxns(hdev_obj, &intf_fxns); 72 73 /* Let Bridge channel module finish the create: */ 74 status = (*intf_fxns->pfn_io_create) (&hio_mgr, hdev_obj, 75 mgr_attrts); 76 77 if (!status) { 78 pio_mgr = (struct io_mgr_ *)hio_mgr; 79 pio_mgr->intf_fxns = intf_fxns; 80 pio_mgr->hdev_obj = hdev_obj; 81 82 /* Return the new channel manager handle: */ 83 *io_man = hio_mgr; 84 } 85 } 86 87 return status; 88} 89 90/* 91 * ======== io_destroy ======== 92 * Purpose: 93 * Delete IO manager. 94 */ 95int io_destroy(struct io_mgr *hio_mgr) 96{ 97 struct bridge_drv_interface *intf_fxns; 98 struct io_mgr_ *pio_mgr = (struct io_mgr_ *)hio_mgr; 99 int status; 100 101 DBC_REQUIRE(refs > 0); 102 103 intf_fxns = pio_mgr->intf_fxns; 104 105 /* Let Bridge channel module destroy the io_mgr: */ 106 status = (*intf_fxns->pfn_io_destroy) (hio_mgr); 107 108 return status; 109} 110 111/* 112 * ======== io_exit ======== 113 * Purpose: 114 * Discontinue usage of the IO module. 115 */ 116void io_exit(void) 117{ 118 DBC_REQUIRE(refs > 0); 119 120 refs--; 121 122 DBC_ENSURE(refs >= 0); 123} 124 125/* 126 * ======== io_init ======== 127 * Purpose: 128 * Initialize the IO module's private state. 129 */ 130bool io_init(void) 131{ 132 bool ret = true; 133 134 DBC_REQUIRE(refs >= 0); 135 136 if (ret) 137 refs++; 138 139 DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0))); 140 141 return ret; 142} 143