net-next:asix: V2 Update VERSION
[zen-stable.git] / drivers / staging / tidspbridge / pmgr / io.c
blob65245f310f89946cebf7dbdd25edfb6a050ef85e
1 /*
2 * io.c
4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * IO manager interface: Manages IO between CHNL and msg_ctrl.
8 * Copyright (C) 2005-2006 Texas Instruments, Inc.
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.
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.
18 #include <linux/types.h>
20 /* ----------------------------------- Host OS */
21 #include <dspbridge/host_os.h>
23 /* ----------------------------------- DSP/BIOS Bridge */
24 #include <dspbridge/dbdefs.h>
26 /* ----------------------------------- Trace & Debug */
27 #include <dspbridge/dbc.h>
29 /* ----------------------------------- Platform Manager */
30 #include <dspbridge/dev.h>
32 /* ----------------------------------- This */
33 #include <ioobj.h>
34 #include <dspbridge/io.h>
36 /* ----------------------------------- Globals */
37 static u32 refs;
40 * ======== io_create ========
41 * Purpose:
42 * Create an IO manager object, responsible for managing IO between
43 * CHNL and msg_ctrl
45 int io_create(struct io_mgr **io_man, struct dev_object *hdev_obj,
46 const struct io_attrs *mgr_attrts)
48 struct bridge_drv_interface *intf_fxns;
49 struct io_mgr *hio_mgr = NULL;
50 struct io_mgr_ *pio_mgr = NULL;
51 int status = 0;
53 DBC_REQUIRE(refs > 0);
54 DBC_REQUIRE(io_man != NULL);
55 DBC_REQUIRE(mgr_attrts != NULL);
57 *io_man = NULL;
59 /* A memory base of 0 implies no memory base: */
60 if ((mgr_attrts->shm_base != 0) && (mgr_attrts->sm_length == 0))
61 status = -EINVAL;
63 if (mgr_attrts->word_size == 0)
64 status = -EINVAL;
66 if (!status) {
67 dev_get_intf_fxns(hdev_obj, &intf_fxns);
69 /* Let Bridge channel module finish the create: */
70 status = (*intf_fxns->io_create) (&hio_mgr, hdev_obj,
71 mgr_attrts);
73 if (!status) {
74 pio_mgr = (struct io_mgr_ *)hio_mgr;
75 pio_mgr->intf_fxns = intf_fxns;
76 pio_mgr->dev_obj = hdev_obj;
78 /* Return the new channel manager handle: */
79 *io_man = hio_mgr;
83 return status;
87 * ======== io_destroy ========
88 * Purpose:
89 * Delete IO manager.
91 int io_destroy(struct io_mgr *hio_mgr)
93 struct bridge_drv_interface *intf_fxns;
94 struct io_mgr_ *pio_mgr = (struct io_mgr_ *)hio_mgr;
95 int status;
97 DBC_REQUIRE(refs > 0);
99 intf_fxns = pio_mgr->intf_fxns;
101 /* Let Bridge channel module destroy the io_mgr: */
102 status = (*intf_fxns->io_destroy) (hio_mgr);
104 return status;
108 * ======== io_exit ========
109 * Purpose:
110 * Discontinue usage of the IO module.
112 void io_exit(void)
114 DBC_REQUIRE(refs > 0);
116 refs--;
118 DBC_ENSURE(refs >= 0);
122 * ======== io_init ========
123 * Purpose:
124 * Initialize the IO module's private state.
126 bool io_init(void)
128 bool ret = true;
130 DBC_REQUIRE(refs >= 0);
132 if (ret)
133 refs++;
135 DBC_ENSURE((ret && (refs > 0)) || (!ret && (refs >= 0)));
137 return ret;