Merge branch 'spi/merge' of git://git.secretlab.ca/git/linux-2.6
[pandora-kernel.git] / drivers / staging / tidspbridge / include / dspbridge / io_sm.h
1 /*
2  * io_sm.h
3  *
4  * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5  *
6  * IO dispatcher for a shared memory channel driver.
7  * Also, includes macros to simulate shm via port io calls.
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 #ifndef IOSM_
21 #define IOSM_
22
23 #include <dspbridge/_chnl_sm.h>
24 #include <dspbridge/host_os.h>
25
26 #include <dspbridge/iodefs.h>
27
28 #define IO_INPUT            0
29 #define IO_OUTPUT           1
30 #define IO_SERVICE          2
31 #define IO_MAXSERVICE       IO_SERVICE
32
33 #ifdef CONFIG_TIDSPBRIDGE_DVFS
34 /* The maximum number of OPPs that are supported */
35 extern s32 dsp_max_opps;
36 /* The Vdd1 opp table information */
37 extern u32 vdd1_dsp_freq[6][4];
38 #endif
39
40 /*
41  *  ======== io_cancel_chnl ========
42  *  Purpose:
43  *      Cancel IO on a given channel.
44  *  Parameters:
45  *      hio_mgr:     IO Manager.
46  *      chnl:       Index of channel to cancel IO on.
47  *  Returns:
48  *  Requires:
49  *      Valid hio_mgr.
50  *  Ensures:
51  */
52 extern void io_cancel_chnl(struct io_mgr *hio_mgr, u32 chnl);
53
54 /*
55  *  ======== io_dpc ========
56  *  Purpose:
57  *      Deferred procedure call for shared memory channel driver ISR.  Carries
58  *      out the dispatch of I/O.
59  *  Parameters:
60  *      ref_data:   Pointer to reference data registered via a call to
61  *                  DPC_Create().
62  *  Returns:
63  *  Requires:
64  *      Must not block.
65  *      Must not acquire resources.
66  *      All data touched must be locked in memory if running in kernel mode.
67  *  Ensures:
68  *      Non-preemptible (but interruptible).
69  */
70 extern void io_dpc(unsigned long ref_data);
71
72 /*
73  *  ======== io_mbox_msg ========
74  *  Purpose:
75  *      Main message handler for the shared memory Bridge channel manager.
76  *      Determine if this message is ours, then schedules a DPC to
77  *      dispatch I/O.
78  *  Parameters:
79  *      self:   Pointer to its own notifier_block struct.
80  *      len:    Length of message.
81  *      msg:    Message code received.
82  *  Returns:
83  *      NOTIFY_OK if handled; NOTIFY_BAD otherwise.
84  */
85 int io_mbox_msg(struct notifier_block *self, unsigned long len, void *msg);
86
87 /*
88  *  ======== io_request_chnl ========
89  *  Purpose:
90  *      Request I/O from the DSP. Sets flags in shared memory, then interrupts
91  *      the DSP.
92  *  Parameters:
93  *      hio_mgr:     IO manager handle.
94  *      pchnl:      Ptr to the channel requesting I/O.
95  *      io_mode:      Mode of channel: {IO_INPUT | IO_OUTPUT}.
96  *  Returns:
97  *  Requires:
98  *      pchnl != NULL
99  *  Ensures:
100  */
101 extern void io_request_chnl(struct io_mgr *io_manager,
102                             struct chnl_object *pchnl,
103                             u8 io_mode, u16 *mbx_val);
104
105 /*
106  *  ======== iosm_schedule ========
107  *  Purpose:
108  *      Schedule DPC for IO.
109  *  Parameters:
110  *      pio_mgr:     Ptr to a I/O manager.
111  *  Returns:
112  *  Requires:
113  *      pchnl != NULL
114  *  Ensures:
115  */
116 extern void iosm_schedule(struct io_mgr *io_manager);
117
118 /*
119  * DSP-DMA IO functions
120  */
121
122 /*
123  *  ======== io_ddma_init_chnl_desc ========
124  *  Purpose:
125  *      Initialize DSP DMA channel descriptor.
126  *  Parameters:
127  *      hio_mgr:         Handle to a I/O manager.
128  *      ddma_chnl_id:    DDMA channel identifier.
129  *      num_desc:       Number of buffer descriptors(equals # of IOReqs &
130  *                      Chirps)
131  *      dsp:           Dsp address;
132  *  Returns:
133  *  Requires:
134  *     ddma_chnl_id < DDMA_MAXDDMACHNLS
135  *     num_desc > 0
136  *     pVa != NULL
137  *     pDspPa != NULL
138  *
139  *  Ensures:
140  */
141 extern void io_ddma_init_chnl_desc(struct io_mgr *hio_mgr, u32 ddma_chnl_id,
142                                    u32 num_desc, void *dsp);
143
144 /*
145  *  ======== io_ddma_clear_chnl_desc ========
146  *  Purpose:
147  *      Clear DSP DMA channel descriptor.
148  *  Parameters:
149  *      hio_mgr:         Handle to a I/O manager.
150  *      ddma_chnl_id:    DDMA channel identifier.
151  *  Returns:
152  *  Requires:
153  *     ddma_chnl_id < DDMA_MAXDDMACHNLS
154  *  Ensures:
155  */
156 extern void io_ddma_clear_chnl_desc(struct io_mgr *hio_mgr, u32 ddma_chnl_id);
157
158 /*
159  *  ======== io_ddma_request_chnl ========
160  *  Purpose:
161  *      Request channel DSP-DMA from the DSP. Sets up SM descriptors and
162  *      control fields in shared memory.
163  *  Parameters:
164  *      hio_mgr:     Handle to a I/O manager.
165  *      pchnl:      Ptr to channel object
166  *      chnl_packet_obj:     Ptr to channel i/o request packet.
167  *  Returns:
168  *  Requires:
169  *      pchnl != NULL
170  *      pchnl->cio_reqs > 0
171  *      chnl_packet_obj != NULL
172  *  Ensures:
173  */
174 extern void io_ddma_request_chnl(struct io_mgr *hio_mgr,
175                                  struct chnl_object *pchnl,
176                                  struct chnl_irp *chnl_packet_obj,
177                                  u16 *mbx_val);
178
179 /*
180  * Zero-copy IO functions
181  */
182
183 /*
184  *  ======== io_ddzc_init_chnl_desc ========
185  *  Purpose:
186  *      Initialize ZCPY channel descriptor.
187  *  Parameters:
188  *      hio_mgr:     Handle to a I/O manager.
189  *      zid:        zero-copy channel identifier.
190  *  Returns:
191  *  Requires:
192  *     ddma_chnl_id < DDMA_MAXZCPYCHNLS
193  *     hio_mgr != Null
194  *  Ensures:
195  */
196 extern void io_ddzc_init_chnl_desc(struct io_mgr *hio_mgr, u32 zid);
197
198 /*
199  *  ======== io_ddzc_clear_chnl_desc ========
200  *  Purpose:
201  *      Clear DSP ZC channel descriptor.
202  *  Parameters:
203  *      hio_mgr:         Handle to a I/O manager.
204  *      ch_id:        ZC channel identifier.
205  *  Returns:
206  *  Requires:
207  *      hio_mgr is valid
208  *      ch_id < DDMA_MAXZCPYCHNLS
209  *  Ensures:
210  */
211 extern void io_ddzc_clear_chnl_desc(struct io_mgr *hio_mgr, u32 ch_id);
212
213 /*
214  *  ======== io_ddzc_request_chnl ========
215  *  Purpose:
216  *      Request zero-copy channel transfer. Sets up SM descriptors and
217  *      control fields in shared memory.
218  *  Parameters:
219  *      hio_mgr:         Handle to a I/O manager.
220  *      pchnl:          Ptr to channel object
221  *      chnl_packet_obj:         Ptr to channel i/o request packet.
222  *  Returns:
223  *  Requires:
224  *      pchnl != NULL
225  *      pchnl->cio_reqs > 0
226  *      chnl_packet_obj != NULL
227  *  Ensures:
228  */
229 extern void io_ddzc_request_chnl(struct io_mgr *hio_mgr,
230                                  struct chnl_object *pchnl,
231                                  struct chnl_irp *chnl_packet_obj,
232                                  u16 *mbx_val);
233
234 /*
235  *  ======== io_sh_msetting ========
236  *  Purpose:
237  *      Sets the shared memory setting
238  *  Parameters:
239  *      hio_mgr:         Handle to a I/O manager.
240  *      desc:             Shared memory type
241  *      pargs:          Ptr to shm setting
242  *  Returns:
243  *  Requires:
244  *      hio_mgr != NULL
245  *      pargs != NULL
246  *  Ensures:
247  */
248 extern int io_sh_msetting(struct io_mgr *hio_mgr, u8 desc, void *pargs);
249
250 /*
251  *  Misc functions for the CHNL_IO shared memory library:
252  */
253
254 /* Maximum channel bufsize that can be used. */
255 extern u32 io_buf_size(struct io_mgr *hio_mgr);
256
257 extern u32 io_read_value(struct bridge_dev_context *dev_ctxt, u32 dsp_addr);
258
259 extern void io_write_value(struct bridge_dev_context *dev_ctxt,
260                            u32 dsp_addr, u32 value);
261
262 extern u32 io_read_value_long(struct bridge_dev_context *dev_ctxt,
263                               u32 dsp_addr);
264
265 extern void io_write_value_long(struct bridge_dev_context *dev_ctxt,
266                                 u32 dsp_addr, u32 value);
267
268 extern void io_or_set_value(struct bridge_dev_context *dev_ctxt,
269                             u32 dsp_addr, u32 value);
270
271 extern void io_and_set_value(struct bridge_dev_context *dev_ctxt,
272                              u32 dsp_addr, u32 value);
273
274 extern void io_sm_init(void);
275
276 #ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
277 /*
278  *  ========print_dsp_trace_buffer ========
279  *      Print DSP tracebuffer.
280  */
281 extern int print_dsp_trace_buffer(struct bridge_dev_context
282                                          *hbridge_context);
283
284 int dump_dsp_stack(struct bridge_dev_context *bridge_context);
285
286 void dump_dl_modules(struct bridge_dev_context *bridge_context);
287
288 #endif
289 #if defined(CONFIG_TIDSPBRIDGE_BACKTRACE) || defined(CONFIG_TIDSPBRIDGE_DEBUG)
290 void print_dsp_debug_trace(struct io_mgr *hio_mgr);
291 #endif
292
293 #endif /* IOSM_ */