Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging-2.6
[pandora-kernel.git] / drivers / staging / tidspbridge / include / dspbridge / dspdefs.h
1 /*
2  * dspdefs.h
3  *
4  * DSP-BIOS Bridge driver support functions for TI OMAP processors.
5  *
6  * Bridge driver entry point and interface function declarations.
7  *
8  * Notes:
9  *   The DSP API obtains it's function interface to
10  *   the Bridge driver via a call to bridge_drv_entry().
11  *
12  *   Bridge services exported to Bridge drivers are initialized by the
13  *   DSP API on behalf of the Bridge driver.
14  *
15  *   Bridge function DBC Requires and Ensures are also made by the DSP API on
16  *   behalf of the Bridge driver, to simplify the Bridge driver code.
17  *
18  * Copyright (C) 2005-2006 Texas Instruments, Inc.
19  *
20  * This package is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License version 2 as
22  * published by the Free Software Foundation.
23  *
24  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
26  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27  */
28
29 #ifndef DSPDEFS_
30 #define DSPDEFS_
31
32 #include <dspbridge/brddefs.h>
33 #include <dspbridge/cfgdefs.h>
34 #include <dspbridge/chnlpriv.h>
35 #include <dspbridge/dehdefs.h>
36 #include <dspbridge/devdefs.h>
37 #include <dspbridge/iodefs.h>
38 #include <dspbridge/msgdefs.h>
39
40 /*
41  *  Any IOCTLS at or above this value are reserved for standard Bridge driver
42  *  interfaces.
43  */
44 #define BRD_RESERVEDIOCTLBASE   0x8000
45
46 /* Handle to Bridge driver's private device context. */
47 struct bridge_dev_context;
48
49 /*--------------------------------------------------------------------------- */
50 /* BRIDGE DRIVER FUNCTION TYPES */
51 /*--------------------------------------------------------------------------- */
52
53 /*
54  *  ======== bridge_brd_monitor ========
55  *  Purpose:
56  *      Bring the board to the BRD_IDLE (monitor) state.
57  *  Parameters:
58  *      dev_ctxt:    Handle to Bridge driver defined device context.
59  *  Returns:
60  *      0:        Success.
61  *      -ETIMEDOUT:  Timeout occured waiting for a response from hardware.
62  *      -EPERM:      Other, unspecified error.
63  *  Requires:
64  *      dev_ctxt != NULL
65  *  Ensures:
66  *      0:        Board is in BRD_IDLE state;
67  *      else:           Board state is indeterminate.
68  */
69 typedef int(*fxn_brd_monitor) (struct bridge_dev_context *dev_ctxt);
70
71 /*
72  *  ======== fxn_brd_setstate ========
73  *  Purpose:
74  *      Sets the Bridge driver state
75  *  Parameters:
76  *      dev_ctxt:    Handle to Bridge driver defined device info.
77  *      brd_state:      Board state
78  *  Returns:
79  *      0:        Success.
80  *      -EPERM:      Other, unspecified error.
81  *  Requires:
82  *      dev_ctxt != NULL;
83  *      brd_state  <= BRD_LASTSTATE.
84  *  Ensures:
85  *      brd_state  <= BRD_LASTSTATE.
86  *  Update the Board state to the specified state.
87  */
88 typedef int(*fxn_brd_setstate) (struct bridge_dev_context
89                                        * dev_ctxt, u32 brd_state);
90
91 /*
92  *  ======== bridge_brd_start ========
93  *  Purpose:
94  *      Bring board to the BRD_RUNNING (start) state.
95  *  Parameters:
96  *      dev_ctxt:    Handle to Bridge driver defined device context.
97  *      dsp_addr:       DSP address at which to start execution.
98  *  Returns:
99  *      0:        Success.
100  *      -ETIMEDOUT:  Timeout occured waiting for a response from hardware.
101  *      -EPERM:      Other, unspecified error.
102  *  Requires:
103  *      dev_ctxt != NULL
104  *      Board is in monitor (BRD_IDLE) state.
105  *  Ensures:
106  *      0:        Board is in BRD_RUNNING state.
107  *                      Interrupts to the PC are enabled.
108  *      else:           Board state is indeterminate.
109  */
110 typedef int(*fxn_brd_start) (struct bridge_dev_context
111                                     * dev_ctxt, u32 dsp_addr);
112
113 /*
114  *  ======== bridge_brd_mem_copy ========
115  *  Purpose:
116  *  Copy memory from one DSP address to another
117  *  Parameters:
118  *      dev_context:    Pointer to context handle
119  *  dsp_dest_addr:  DSP address to copy to
120  *  dsp_src_addr:   DSP address to copy from
121  *  ul_num_bytes: Number of bytes to copy
122  *  mem_type:   What section of memory to copy to
123  *  Returns:
124  *      0:        Success.
125  *      -EPERM:      Other, unspecified error.
126  *  Requires:
127  *      dev_context != NULL
128  *  Ensures:
129  *      0:        Board is in BRD_RUNNING state.
130  *                      Interrupts to the PC are enabled.
131  *      else:           Board state is indeterminate.
132  */
133 typedef int(*fxn_brd_memcopy) (struct bridge_dev_context
134                                       * dev_ctxt,
135                                       u32 dsp_dest_addr,
136                                       u32 dsp_src_addr,
137                                       u32 ul_num_bytes, u32 mem_type);
138 /*
139  *  ======== bridge_brd_mem_write ========
140  *  Purpose:
141  *      Write a block of host memory into a DSP address, into a given memory
142  *      space.  Unlike bridge_brd_write, this API does reset the DSP
143  *  Parameters:
144  *      dev_ctxt:    Handle to Bridge driver defined device info.
145  *      dsp_addr:       Address on DSP board (Destination).
146  *      host_buf:       Pointer to host buffer (Source).
147  *      ul_num_bytes:     Number of bytes to transfer.
148  *      mem_type:       Memory space on DSP to which to transfer.
149  *  Returns:
150  *      0:        Success.
151  *      -ETIMEDOUT:  Timeout occured waiting for a response from hardware.
152  *      -EPERM:      Other, unspecified error.
153  *  Requires:
154  *      dev_ctxt != NULL;
155  *      host_buf != NULL.
156  *  Ensures:
157  */
158 typedef int(*fxn_brd_memwrite) (struct bridge_dev_context
159                                        * dev_ctxt,
160                                        u8 *host_buf,
161                                        u32 dsp_addr, u32 ul_num_bytes,
162                                        u32 mem_type);
163
164 /*
165  *  ======== bridge_brd_stop ========
166  *  Purpose:
167  *      Bring board to the BRD_STOPPED state.
168  *  Parameters:
169  *      dev_ctxt:    Handle to Bridge driver defined device context.
170  *  Returns:
171  *      0:        Success.
172  *      -ETIMEDOUT:  Timeout occured waiting for a response from hardware.
173  *      -EPERM:      Other, unspecified error.
174  *  Requires:
175  *      dev_ctxt != NULL
176  *  Ensures:
177  *      0:        Board is in BRD_STOPPED (stop) state;
178  *                      Interrupts to the PC are disabled.
179  *      else:           Board state is indeterminate.
180  */
181 typedef int(*fxn_brd_stop) (struct bridge_dev_context *dev_ctxt);
182
183 /*
184  *  ======== bridge_brd_status ========
185  *  Purpose:
186  *      Report the current state of the board.
187  *  Parameters:
188  *      dev_ctxt:    Handle to Bridge driver defined device context.
189  *      board_state:    Ptr to BRD status variable.
190  *  Returns:
191  *      0:
192  *  Requires:
193  *      board_state != NULL;
194  *      dev_ctxt != NULL
195  *  Ensures:
196  *      *board_state is one of
197  *       {BRD_STOPPED, BRD_IDLE, BRD_RUNNING, BRD_UNKNOWN};
198  */
199 typedef int(*fxn_brd_status) (struct bridge_dev_context *dev_ctxt,
200                                      int *board_state);
201
202 /*
203  *  ======== bridge_brd_read ========
204  *  Purpose:
205  *      Read a block of DSP memory, from a given memory space, into a host
206  *      buffer.
207  *  Parameters:
208  *      dev_ctxt:    Handle to Bridge driver defined device info.
209  *      host_buf:       Pointer to host buffer (Destination).
210  *      dsp_addr:       Address on DSP board (Source).
211  *      ul_num_bytes:     Number of bytes to transfer.
212  *      mem_type:       Memory space on DSP from which to transfer.
213  *  Returns:
214  *      0:        Success.
215  *      -ETIMEDOUT:  Timeout occured waiting for a response from hardware.
216  *      -EPERM:      Other, unspecified error.
217  *  Requires:
218  *      dev_ctxt != NULL;
219  *      host_buf != NULL.
220  *  Ensures:
221  *  Will not write more than ul_num_bytes bytes into host_buf.
222  */
223 typedef int(*fxn_brd_read) (struct bridge_dev_context *dev_ctxt,
224                                    u8 *host_buf,
225                                    u32 dsp_addr,
226                                    u32 ul_num_bytes, u32 mem_type);
227
228 /*
229  *  ======== bridge_brd_write ========
230  *  Purpose:
231  *      Write a block of host memory into a DSP address, into a given memory
232  *      space.
233  *  Parameters:
234  *      dev_ctxt:    Handle to Bridge driver defined device info.
235  *      dsp_addr:       Address on DSP board (Destination).
236  *      host_buf:       Pointer to host buffer (Source).
237  *      ul_num_bytes:     Number of bytes to transfer.
238  *      mem_type:       Memory space on DSP to which to transfer.
239  *  Returns:
240  *      0:        Success.
241  *      -ETIMEDOUT:  Timeout occured waiting for a response from hardware.
242  *      -EPERM:      Other, unspecified error.
243  *  Requires:
244  *      dev_ctxt != NULL;
245  *      host_buf != NULL.
246  *  Ensures:
247  */
248 typedef int(*fxn_brd_write) (struct bridge_dev_context *dev_ctxt,
249                                     u8 *host_buf,
250                                     u32 dsp_addr,
251                                     u32 ul_num_bytes, u32 mem_type);
252
253 /*
254  *  ======== bridge_chnl_create ========
255  *  Purpose:
256  *      Create a channel manager object, responsible for opening new channels
257  *      and closing old ones for a given 'Bridge board.
258  *  Parameters:
259  *      channel_mgr:    Location to store a channel manager object on output.
260  *      hdev_obj:     Handle to a device object.
261  *      mgr_attrts:      Channel manager attributes.
262  *      mgr_attrts->max_channels: Max channels
263  *      mgr_attrts->birq:      Channel's I/O IRQ number.
264  *      mgr_attrts->irq_shared:   TRUE if the IRQ is shareable.
265  *      mgr_attrts->word_size: DSP Word size in equivalent PC bytes..
266  *      mgr_attrts->shm_base:  Base physical address of shared memory, if any.
267  *      mgr_attrts->usm_length: Bytes of shared memory block.
268  *  Returns:
269  *      0:            Success;
270  *      -ENOMEM:        Insufficient memory for requested resources.
271  *      -EIO:         Unable to plug ISR for given IRQ.
272  *      -EFAULT:    Couldn't map physical address to a virtual one.
273  *  Requires:
274  *      channel_mgr != NULL.
275  *      mgr_attrts != NULL
276  *      mgr_attrts field are all valid:
277  *          0 < max_channels <= CHNL_MAXCHANNELS.
278  *          birq <= 15.
279  *          word_size > 0.
280  *      hdev_obj != NULL
281  *      No channel manager exists for this board.
282  *  Ensures:
283  */
284 typedef int(*fxn_chnl_create) (struct chnl_mgr
285                                       **channel_mgr,
286                                       struct dev_object
287                                       * hdev_obj,
288                                       const struct
289                                       chnl_mgrattrs * mgr_attrts);
290
291 /*
292  *  ======== bridge_chnl_destroy ========
293  *  Purpose:
294  *      Close all open channels, and destroy the channel manager.
295  *  Parameters:
296  *      hchnl_mgr:       Channel manager object.
297  *  Returns:
298  *      0:        Success.
299  *      -EFAULT:    hchnl_mgr was invalid.
300  *  Requires:
301  *  Ensures:
302  *      0: Cancels I/O on each open channel. Closes each open channel.
303  *          chnl_create may subsequently be called for the same device.
304  */
305 typedef int(*fxn_chnl_destroy) (struct chnl_mgr *hchnl_mgr);
306 /*
307  *  ======== bridge_deh_notify ========
308  *  Purpose:
309  *      When notified of DSP error, take appropriate action.
310  *  Parameters:
311  *      hdeh_mgr:        Handle to DEH manager object.
312  *      evnt_mask:    Indicate the type of exception
313  *      error_info:    Error information
314  *  Returns:
315  *
316  *  Requires:
317  *      hdeh_mgr != NULL;
318  *     evnt_mask with a valid exception
319  *  Ensures:
320  */
321 typedef void (*fxn_deh_notify) (struct deh_mgr *hdeh_mgr,
322                                 u32 evnt_mask, u32 error_info);
323
324 /*
325  *  ======== bridge_chnl_open ========
326  *  Purpose:
327  *      Open a new half-duplex channel to the DSP board.
328  *  Parameters:
329  *      chnl:           Location to store a channel object handle.
330  *      hchnl_mgr:      Handle to channel manager, as returned by
331  *                      CHNL_GetMgr().
332  *      chnl_mode:          One of {CHNL_MODETODSP, CHNL_MODEFROMDSP} specifies
333  *                      direction of data transfer.
334  *      ch_id:        If CHNL_PICKFREE is specified, the channel manager will
335  *                      select a free channel id (default);
336  *                      otherwise this field specifies the id of the channel.
337  *      pattrs:         Channel attributes.  Attribute fields are as follows:
338  *      pattrs->uio_reqs: Specifies the maximum number of I/O requests which can
339  *                      be pending at any given time. All request packets are
340  *                      preallocated when the channel is opened.
341  *      pattrs->event_obj: This field allows the user to supply an auto reset
342  *                      event object for channel I/O completion notifications.
343  *                      It is the responsibility of the user to destroy this
344  *                      object AFTER closing the channel.
345  *                      This channel event object can be retrieved using
346  *                      CHNL_GetEventHandle().
347  *      pattrs->hReserved: The kernel mode handle of this event object.
348  *
349  *  Returns:
350  *      0:                Success.
351  *      -EFAULT:            hchnl_mgr is invalid.
352  *      -ENOMEM:            Insufficient memory for requested resources.
353  *      -EINVAL:        Invalid number of IOReqs.
354  *      -ENOSR:    No free channels available.
355  *      -ECHRNG:       Channel ID is out of range.
356  *      -EALREADY:        Channel is in use.
357  *      -EIO:         No free IO request packets available for
358  *                              queuing.
359  *  Requires:
360  *      chnl != NULL.
361  *      pattrs != NULL.
362  *      pattrs->event_obj is a valid event handle.
363  *      pattrs->hReserved is the kernel mode handle for pattrs->event_obj.
364  *  Ensures:
365  *      0:                *chnl is a valid channel.
366  *      else:                   *chnl is set to NULL if (chnl != NULL);
367  */
368 typedef int(*fxn_chnl_open) (struct chnl_object
369                                     **chnl,
370                                     struct chnl_mgr *hchnl_mgr,
371                                     s8 chnl_mode,
372                                     u32 ch_id,
373                                     const struct
374                                     chnl_attr * pattrs);
375
376 /*
377  *  ======== bridge_chnl_close ========
378  *  Purpose:
379  *      Ensures all pending I/O on this channel is cancelled, discards all
380  *      queued I/O completion notifications, then frees the resources allocated
381  *      for this channel, and makes the corresponding logical channel id
382  *      available for subsequent use.
383  *  Parameters:
384  *      chnl_obj:          Handle to a channel object.
385  *  Returns:
386  *      0:        Success;
387  *      -EFAULT:    Invalid chnl_obj.
388  *  Requires:
389  *      No thread must be blocked on this channel's I/O completion event.
390  *  Ensures:
391  *      0:        chnl_obj is no longer valid.
392  */
393 typedef int(*fxn_chnl_close) (struct chnl_object *chnl_obj);
394
395 /*
396  *  ======== bridge_chnl_add_io_req ========
397  *  Purpose:
398  *      Enqueue an I/O request for data transfer on a channel to the DSP.
399  *      The direction (mode) is specified in the channel object. Note the DSP
400  *      address is specified for channels opened in direct I/O mode.
401  *  Parameters:
402  *      chnl_obj:          Channel object handle.
403  *      host_buf:       Host buffer address source.
404  *      byte_size:      Number of PC bytes to transfer. A zero value indicates
405  *                      that this buffer is the last in the output channel.
406  *                      A zero value is invalid for an input channel.
407  *!     buf_size:       Actual buffer size in host bytes.
408  *      dw_dsp_addr:      DSP address for transfer.  (Currently ignored).
409  *      dw_arg:          A user argument that travels with the buffer.
410  *  Returns:
411  *      0:        Success;
412  *      -EFAULT: Invalid chnl_obj or host_buf.
413  *      -EPERM:   User cannot mark EOS on an input channel.
414  *      -ECANCELED: I/O has been cancelled on this channel.  No further
415  *                      I/O is allowed.
416  *      -EPIPE:     End of stream was already marked on a previous
417  *                      IORequest on this channel.  No further I/O is expected.
418  *      -EINVAL: Buffer submitted to this output channel is larger than
419  *                      the size of the physical shared memory output window.
420  *  Requires:
421  *  Ensures:
422  *      0: The buffer will be transferred if the channel is ready;
423  *          otherwise, will be queued for transfer when the channel becomes
424  *          ready.  In any case, notifications of I/O completion are
425  *          asynchronous.
426  *          If byte_size is 0 for an output channel, subsequent CHNL_AddIOReq's
427  *          on this channel will fail with error code -EPIPE.  The
428  *          corresponding IOC for this I/O request will have its status flag
429  *          set to CHNL_IOCSTATEOS.
430  */
431 typedef int(*fxn_chnl_addioreq) (struct chnl_object
432                                         * chnl_obj,
433                                         void *host_buf,
434                                         u32 byte_size,
435                                         u32 buf_size,
436                                         u32 dw_dsp_addr, u32 dw_arg);
437
438 /*
439  *  ======== bridge_chnl_get_ioc ========
440  *  Purpose:
441  *      Dequeue an I/O completion record, which contains information about the
442  *      completed I/O request.
443  *  Parameters:
444  *      chnl_obj:          Channel object handle.
445  *      timeout:        A value of CHNL_IOCNOWAIT will simply dequeue the
446  *                      first available IOC.
447  *      chan_ioc:       On output, contains host buffer address, bytes
448  *                      transferred, and status of I/O completion.
449  *      chan_ioc->status:   See chnldefs.h.
450  *  Returns:
451  *      0:        Success.
452  *      -EFAULT: Invalid chnl_obj or chan_ioc.
453  *      -EREMOTEIO:   CHNL_IOCNOWAIT was specified as the timeout parameter
454  *                      yet no I/O completions were queued.
455  *  Requires:
456  *      timeout == CHNL_IOCNOWAIT.
457  *  Ensures:
458  *      0: if there are any remaining IOC's queued before this call
459  *          returns, the channel event object will be left in a signalled
460  *          state.
461  */
462 typedef int(*fxn_chnl_getioc) (struct chnl_object *chnl_obj,
463                                       u32 timeout,
464                                       struct chnl_ioc *chan_ioc);
465
466 /*
467  *  ======== bridge_chnl_cancel_io ========
468  *  Purpose:
469  *      Return all I/O requests to the client which have not yet been
470  *      transferred.  The channel's I/O completion object is
471  *      signalled, and all the I/O requests are queued as IOC's, with the
472  *      status field set to CHNL_IOCSTATCANCEL.
473  *      This call is typically used in abort situations, and is a prelude to
474  *      chnl_close();
475  *  Parameters:
476  *      chnl_obj:          Channel object handle.
477  *  Returns:
478  *      0:        Success;
479  *      -EFAULT:    Invalid chnl_obj.
480  *  Requires:
481  *  Ensures:
482  *      Subsequent I/O requests to this channel will not be accepted.
483  */
484 typedef int(*fxn_chnl_cancelio) (struct chnl_object *chnl_obj);
485
486 /*
487  *  ======== bridge_chnl_flush_io ========
488  *  Purpose:
489  *      For an output stream (to the DSP), indicates if any IO requests are in
490  *      the output request queue.  For input streams (from the DSP), will
491  *      cancel all pending IO requests.
492  *  Parameters:
493  *      chnl_obj:              Channel object handle.
494  *      timeout:            Timeout value for flush operation.
495  *  Returns:
496  *      0:            Success;
497  *      S_CHNLIOREQUEST:    Returned if any IORequests are in the output queue.
498  *      -EFAULT:        Invalid chnl_obj.
499  *  Requires:
500  *  Ensures:
501  *      0:            No I/O requests will be pending on this channel.
502  */
503 typedef int(*fxn_chnl_flushio) (struct chnl_object *chnl_obj,
504                                        u32 timeout);
505
506 /*
507  *  ======== bridge_chnl_get_info ========
508  *  Purpose:
509  *      Retrieve information related to a channel.
510  *  Parameters:
511  *      chnl_obj:          Handle to a valid channel object, or NULL.
512  *      channel_info:   Location to store channel info.
513  *  Returns:
514  *      0:        Success;
515  *      -EFAULT: Invalid chnl_obj or channel_info.
516  *  Requires:
517  *  Ensures:
518  *      0:        channel_info points to a filled in chnl_info struct,
519  *                      if (channel_info != NULL).
520  */
521 typedef int(*fxn_chnl_getinfo) (struct chnl_object *chnl_obj,
522                                        struct chnl_info *channel_info);
523
524 /*
525  *  ======== bridge_chnl_get_mgr_info ========
526  *  Purpose:
527  *      Retrieve information related to the channel manager.
528  *  Parameters:
529  *      hchnl_mgr:           Handle to a valid channel manager, or NULL.
530  *      ch_id:            Channel ID.
531  *      mgr_info:           Location to store channel manager info.
532  *  Returns:
533  *      0:            Success;
534  *      -EFAULT: Invalid hchnl_mgr or mgr_info.
535  *      -ECHRNG:   Invalid channel ID.
536  *  Requires:
537  *  Ensures:
538  *      0:            mgr_info points to a filled in chnl_mgrinfo
539  *                          struct, if (mgr_info != NULL).
540  */
541 typedef int(*fxn_chnl_getmgrinfo) (struct chnl_mgr
542                                           * hchnl_mgr,
543                                           u32 ch_id,
544                                           struct chnl_mgrinfo *mgr_info);
545
546 /*
547  *  ======== bridge_chnl_idle ========
548  *  Purpose:
549  *      Idle a channel. If this is an input channel, or if this is an output
550  *      channel and flush_data is TRUE, all currently enqueued buffers will be
551  *      dequeued (data discarded for output channel).
552  *      If this is an output channel and flush_data is FALSE, this function
553  *      will block until all currently buffered data is output, or the timeout
554  *      specified has been reached.
555  *
556  *  Parameters:
557  *      chnl_obj:          Channel object handle.
558  *      timeout:        If output channel and flush_data is FALSE, timeout value
559  *                      to wait for buffers to be output. (Not used for
560  *                      input channel).
561  *      flush_data:     If output channel and flush_data is TRUE, discard any
562  *                      currently buffered data. If FALSE, wait for currently
563  *                      buffered data to be output, or timeout, whichever
564  *                      occurs first. flush_data is ignored for input channel.
565  *  Returns:
566  *      0:            Success;
567  *      -EFAULT:        Invalid chnl_obj.
568  *      -ETIMEDOUT: Timeout occured before channel could be idled.
569  *  Requires:
570  *  Ensures:
571  */
572 typedef int(*fxn_chnl_idle) (struct chnl_object *chnl_obj,
573                                     u32 timeout, bool flush_data);
574
575 /*
576  *  ======== bridge_chnl_register_notify ========
577  *  Purpose:
578  *      Register for notification of events on a channel.
579  *  Parameters:
580  *      chnl_obj:          Channel object handle.
581  *      event_mask:     Type of events to be notified about: IO completion
582  *                      (DSP_STREAMIOCOMPLETION) or end of stream
583  *                      (DSP_STREAMDONE).
584  *      notify_type:    DSP_SIGNALEVENT.
585  *      hnotification:  Handle of a dsp_notification object.
586  *  Returns:
587  *      0:        Success.
588  *      -ENOMEM:    Insufficient memory.
589  *      -EINVAL:     event_mask is 0 and hnotification was not
590  *                      previously registered.
591  *      -EFAULT:    NULL hnotification, hnotification event name
592  *                      too long, or hnotification event name NULL.
593  *  Requires:
594  *      Valid chnl_obj.
595  *      hnotification != NULL.
596  *      (event_mask & ~(DSP_STREAMIOCOMPLETION | DSP_STREAMDONE)) == 0.
597  *      notify_type == DSP_SIGNALEVENT.
598  *  Ensures:
599  */
600 typedef int(*fxn_chnl_registernotify)
601  (struct chnl_object *chnl_obj,
602   u32 event_mask, u32 notify_type, struct dsp_notification *hnotification);
603
604 /*
605  *  ======== bridge_dev_create ========
606  *  Purpose:
607  *      Complete creation of the device object for this board.
608  *  Parameters:
609  *      device_ctx:     Ptr to location to store a Bridge device context.
610  *      hdev_obj:     Handle to a Device Object, created and managed by DSP API.
611  *      config_param:        Ptr to configuration parameters provided by the
612  *                      Configuration Manager during device loading.
613  *      pDspConfig:     DSP resources, as specified in the registry key for this
614  *                      device.
615  *  Returns:
616  *      0:            Success.
617  *      -ENOMEM:        Unable to allocate memory for device context.
618  *  Requires:
619  *      device_ctx != NULL;
620  *      hdev_obj != NULL;
621  *      config_param != NULL;
622  *      pDspConfig != NULL;
623  *      Fields in config_param and pDspConfig contain valid values.
624  *  Ensures:
625  *      0:        All Bridge driver specific DSP resource and other
626  *                      board context has been allocated.
627  *      -ENOMEM:    Bridge failed to allocate resources.
628  *                      Any acquired resources have been freed.  The DSP API
629  *                      will not call bridge_dev_destroy() if
630  *                      bridge_dev_create() fails.
631  *  Details:
632  *      Called during the CONFIGMG's Device_Init phase. Based on host and
633  *      DSP configuration information, create a board context, a handle to
634  *      which is passed into other Bridge BRD and CHNL functions.  The
635  *      board context contains state information for the device. Since the
636  *      addresses of all pointer parameters may be invalid when this
637  *      function returns, they must not be stored into the device context
638  *      structure.
639  */
640 typedef int(*fxn_dev_create) (struct bridge_dev_context
641                                      **device_ctx,
642                                      struct dev_object
643                                      * hdev_obj,
644                                      struct cfg_hostres
645                                      * config_param);
646
647 /*
648  *  ======== bridge_dev_ctrl ========
649  *  Purpose:
650  *      Bridge driver specific interface.
651  *  Parameters:
652  *      dev_ctxt:    Handle to Bridge driver defined device info.
653  *      dw_cmd:          Bridge driver defined command code.
654  *      pargs:          Pointer to an arbitrary argument structure.
655  *  Returns:
656  *      0 or -EPERM. Actual command error codes should be passed back in
657  *      the pargs structure, and are defined by the Bridge driver implementor.
658  *  Requires:
659  *      All calls are currently assumed to be synchronous.  There are no
660  *      IOCTL completion routines provided.
661  *  Ensures:
662  */
663 typedef int(*fxn_dev_ctrl) (struct bridge_dev_context *dev_ctxt,
664                                    u32 dw_cmd, void *pargs);
665
666 /*
667  *  ======== bridge_dev_destroy ========
668  *  Purpose:
669  *      Deallocate Bridge device extension structures and all other resources
670  *      acquired by the Bridge driver.
671  *      No calls to other Bridge driver functions may subsequently
672  *      occur, except for bridge_dev_create().
673  *  Parameters:
674  *      dev_ctxt:    Handle to Bridge driver defined device information.
675  *  Returns:
676  *      0:        Success.
677  *      -EPERM:      Failed to release a resource previously acquired.
678  *  Requires:
679  *      dev_ctxt != NULL;
680  *  Ensures:
681  *      0: Device context is freed.
682  */
683 typedef int(*fxn_dev_destroy) (struct bridge_dev_context *dev_ctxt);
684
685 /*
686  *  ======== bridge_io_create ========
687  *  Purpose:
688  *      Create an object that manages I/O between CHNL and msg_ctrl.
689  *  Parameters:
690  *      io_man:         Location to store IO manager on output.
691  *      hchnl_mgr:       Handle to channel manager.
692  *      hmsg_mgr:        Handle to message manager.
693  *  Returns:
694  *      0:        Success.
695  *      -ENOMEM:    Memory allocation failure.
696  *      -EPERM:      Creation failed.
697  *  Requires:
698  *      hdev_obj != NULL;
699  *      Channel manager already created;
700  *      Message manager already created;
701  *      mgr_attrts != NULL;
702  *      io_man != NULL;
703  *  Ensures:
704  */
705 typedef int(*fxn_io_create) (struct io_mgr **io_man,
706                                     struct dev_object *hdev_obj,
707                                     const struct io_attrs *mgr_attrts);
708
709 /*
710  *  ======== bridge_io_destroy ========
711  *  Purpose:
712  *      Destroy object created in bridge_io_create.
713  *  Parameters:
714  *      hio_mgr:         IO Manager.
715  *  Returns:
716  *      0:        Success.
717  *      -ENOMEM:    Memory allocation failure.
718  *      -EPERM:      Creation failed.
719  *  Requires:
720  *      Valid hio_mgr;
721  *  Ensures:
722  */
723 typedef int(*fxn_io_destroy) (struct io_mgr *hio_mgr);
724
725 /*
726  *  ======== bridge_io_on_loaded ========
727  *  Purpose:
728  *      Called whenever a program is loaded to update internal data. For
729  *      example, if shared memory is used, this function would update the
730  *      shared memory location and address.
731  *  Parameters:
732  *      hio_mgr:     IO Manager.
733  *  Returns:
734  *      0:    Success.
735  *      -EPERM:  Internal failure occurred.
736  *  Requires:
737  *      Valid hio_mgr;
738  *  Ensures:
739  */
740 typedef int(*fxn_io_onloaded) (struct io_mgr *hio_mgr);
741
742 /*
743  *  ======== fxn_io_getprocload ========
744  *  Purpose:
745  *      Called to get the Processor's current and predicted load
746  *  Parameters:
747  *      hio_mgr:     IO Manager.
748  *      proc_load_stat   Processor Load statistics
749  *  Returns:
750  *      0:    Success.
751  *      -EPERM:  Internal failure occurred.
752  *  Requires:
753  *      Valid hio_mgr;
754  *  Ensures:
755  */
756 typedef int(*fxn_io_getprocload) (struct io_mgr *hio_mgr,
757                                          struct dsp_procloadstat *
758                                          proc_load_stat);
759
760 /*
761  *  ======== bridge_msg_create ========
762  *  Purpose:
763  *      Create an object to manage message queues. Only one of these objects
764  *      can exist per device object.
765  *  Parameters:
766  *      msg_man:            Location to store msg_ctrl manager on output.
767  *      hdev_obj:         Handle to a device object.
768  *      msg_callback:        Called whenever an RMS_EXIT message is received.
769  *  Returns:
770  *      0:            Success.
771  *      -ENOMEM:        Insufficient memory.
772  *  Requires:
773  *      msg_man != NULL.
774  *      msg_callback != NULL.
775  *      hdev_obj != NULL.
776  *  Ensures:
777  */
778 typedef int(*fxn_msg_create)
779  (struct msg_mgr **msg_man,
780   struct dev_object *hdev_obj, msg_onexit msg_callback);
781
782 /*
783  *  ======== bridge_msg_create_queue ========
784  *  Purpose:
785  *      Create a msg_ctrl queue for sending or receiving messages from a Message
786  *      node on the DSP.
787  *  Parameters:
788  *      hmsg_mgr:            msg_ctrl queue manager handle returned from
789  *                          bridge_msg_create.
790  *      msgq:               Location to store msg_ctrl queue on output.
791  *      msgq_id:            Identifier for messages (node environment pointer).
792  *      max_msgs:           Max number of simultaneous messages for the node.
793  *      h:                  Handle passed to hmsg_mgr->msg_callback().
794  *  Returns:
795  *      0:            Success.
796  *      -ENOMEM:        Insufficient memory.
797  *  Requires:
798  *      msgq != NULL.
799  *      h != NULL.
800  *      max_msgs > 0.
801  *  Ensures:
802  *      msgq !=NULL <==> 0.
803  */
804 typedef int(*fxn_msg_createqueue)
805  (struct msg_mgr *hmsg_mgr,
806   struct msg_queue **msgq, u32 msgq_id, u32 max_msgs, void *h);
807
808 /*
809  *  ======== bridge_msg_delete ========
810  *  Purpose:
811  *      Delete a msg_ctrl manager allocated in bridge_msg_create().
812  *  Parameters:
813  *      hmsg_mgr:    Handle returned from bridge_msg_create().
814  *  Returns:
815  *  Requires:
816  *      Valid hmsg_mgr.
817  *  Ensures:
818  */
819 typedef void (*fxn_msg_delete) (struct msg_mgr *hmsg_mgr);
820
821 /*
822  *  ======== bridge_msg_delete_queue ========
823  *  Purpose:
824  *      Delete a msg_ctrl queue allocated in bridge_msg_create_queue.
825  *  Parameters:
826  *      msg_queue_obj:  Handle to msg_ctrl queue returned from
827  *                  bridge_msg_create_queue.
828  *  Returns:
829  *  Requires:
830  *      Valid msg_queue_obj.
831  *  Ensures:
832  */
833 typedef void (*fxn_msg_deletequeue) (struct msg_queue *msg_queue_obj);
834
835 /*
836  *  ======== bridge_msg_get ========
837  *  Purpose:
838  *      Get a message from a msg_ctrl queue.
839  *  Parameters:
840  *      msg_queue_obj:     Handle to msg_ctrl queue returned from
841  *                     bridge_msg_create_queue.
842  *      pmsg:          Location to copy message into.
843  *      utimeout:      Timeout to wait for a message.
844  *  Returns:
845  *      0:       Success.
846  *      -ETIME:  Timeout occurred.
847  *      -EPERM:     No frames available for message (max_msgs too
848  *                     small).
849  *  Requires:
850  *      Valid msg_queue_obj.
851  *      pmsg != NULL.
852  *  Ensures:
853  */
854 typedef int(*fxn_msg_get) (struct msg_queue *msg_queue_obj,
855                                   struct dsp_msg *pmsg, u32 utimeout);
856
857 /*
858  *  ======== bridge_msg_put ========
859  *  Purpose:
860  *      Put a message onto a msg_ctrl queue.
861  *  Parameters:
862  *      msg_queue_obj:      Handle to msg_ctrl queue returned from
863  *                      bridge_msg_create_queue.
864  *      pmsg:           Pointer to message.
865  *      utimeout:       Timeout to wait for a message.
866  *  Returns:
867  *      0:        Success.
868  *      -ETIME:   Timeout occurred.
869  *      -EPERM:      No frames available for message (max_msgs too
870  *                      small).
871  *  Requires:
872  *      Valid msg_queue_obj.
873  *      pmsg != NULL.
874  *  Ensures:
875  */
876 typedef int(*fxn_msg_put) (struct msg_queue *msg_queue_obj,
877                                   const struct dsp_msg *pmsg, u32 utimeout);
878
879 /*
880  *  ======== bridge_msg_register_notify ========
881  *  Purpose:
882  *      Register notification for when a message is ready.
883  *  Parameters:
884  *      msg_queue_obj:      Handle to msg_ctrl queue returned from
885  *                      bridge_msg_create_queue.
886  *      event_mask:     Type of events to be notified about: Must be
887  *                      DSP_NODEMESSAGEREADY, or 0 to unregister.
888  *      notify_type:    DSP_SIGNALEVENT.
889  *      hnotification:  Handle of notification object.
890  *  Returns:
891  *      0:        Success.
892  *      -ENOMEM:    Insufficient memory.
893  *  Requires:
894  *      Valid msg_queue_obj.
895  *      hnotification != NULL.
896  *      notify_type == DSP_SIGNALEVENT.
897  *      event_mask == DSP_NODEMESSAGEREADY || event_mask == 0.
898  *  Ensures:
899  */
900 typedef int(*fxn_msg_registernotify)
901  (struct msg_queue *msg_queue_obj,
902   u32 event_mask, u32 notify_type, struct dsp_notification *hnotification);
903
904 /*
905  *  ======== bridge_msg_set_queue_id ========
906  *  Purpose:
907  *      Set message queue id to node environment. Allows bridge_msg_create_queue
908  *      to be called in node_allocate, before the node environment is known.
909  *  Parameters:
910  *      msg_queue_obj:  Handle to msg_ctrl queue returned from
911  *                  bridge_msg_create_queue.
912  *      msgq_id:       Node environment pointer.
913  *  Returns:
914  *  Requires:
915  *      Valid msg_queue_obj.
916  *      msgq_id != 0.
917  *  Ensures:
918  */
919 typedef void (*fxn_msg_setqueueid) (struct msg_queue *msg_queue_obj,
920                                     u32 msgq_id);
921
922 /*
923  *  Bridge Driver interface function table.
924  *
925  *  The information in this table is filled in by the specific Bridge driver,
926  *  and copied into the DSP API's own space.  If any interface
927  *  function field is set to a value of NULL, then the DSP API will
928  *  consider that function not implemented, and return the error code
929  *  -ENOSYS when a Bridge driver client attempts to call that function.
930  *
931  *  This function table contains DSP API version numbers, which are used by the
932  *  Bridge driver loader to help ensure backwards compatility between older
933  *  Bridge drivers and newer DSP API.  These must be set to
934  *  BRD_API_MAJOR_VERSION and BRD_API_MINOR_VERSION, respectively.
935  *
936  *  A Bridge driver need not export a CHNL interface.  In this case, *all* of
937  *  the bridge_chnl_* entries must be set to NULL.
938  */
939 struct bridge_drv_interface {
940         u32 brd_api_major_version;      /* Set to BRD_API_MAJOR_VERSION. */
941         u32 brd_api_minor_version;      /* Set to BRD_API_MINOR_VERSION. */
942         fxn_dev_create pfn_dev_create;  /* Create device context */
943         fxn_dev_destroy pfn_dev_destroy;        /* Destroy device context */
944         fxn_dev_ctrl pfn_dev_cntrl;     /* Optional vendor interface */
945         fxn_brd_monitor pfn_brd_monitor;        /* Load and/or start monitor */
946         fxn_brd_start pfn_brd_start;    /* Start DSP program. */
947         fxn_brd_stop pfn_brd_stop;      /* Stop/reset board. */
948         fxn_brd_status pfn_brd_status;  /* Get current board status. */
949         fxn_brd_read pfn_brd_read;      /* Read board memory */
950         fxn_brd_write pfn_brd_write;    /* Write board memory. */
951         fxn_brd_setstate pfn_brd_set_state;     /* Sets the Board State */
952         fxn_brd_memcopy pfn_brd_mem_copy;       /* Copies DSP Memory */
953         fxn_brd_memwrite pfn_brd_mem_write;     /* Write DSP Memory w/o halt */
954         fxn_chnl_create pfn_chnl_create;        /* Create channel manager. */
955         fxn_chnl_destroy pfn_chnl_destroy;      /* Destroy channel manager. */
956         fxn_chnl_open pfn_chnl_open;    /* Create a new channel. */
957         fxn_chnl_close pfn_chnl_close;  /* Close a channel. */
958         fxn_chnl_addioreq pfn_chnl_add_io_req;  /* Req I/O on a channel. */
959         fxn_chnl_getioc pfn_chnl_get_ioc;       /* Wait for I/O completion. */
960         fxn_chnl_cancelio pfn_chnl_cancel_io;   /* Cancl I/O on a channel. */
961         fxn_chnl_flushio pfn_chnl_flush_io;     /* Flush I/O. */
962         fxn_chnl_getinfo pfn_chnl_get_info;     /* Get channel specific info */
963         /* Get channel manager info. */
964         fxn_chnl_getmgrinfo pfn_chnl_get_mgr_info;
965         fxn_chnl_idle pfn_chnl_idle;    /* Idle the channel */
966         /* Register for notif. */
967         fxn_chnl_registernotify pfn_chnl_register_notify;
968         fxn_io_create pfn_io_create;    /* Create IO manager */
969         fxn_io_destroy pfn_io_destroy;  /* Destroy IO manager */
970         fxn_io_onloaded pfn_io_on_loaded;       /* Notify of program loaded */
971         /* Get Processor's current and predicted load */
972         fxn_io_getprocload pfn_io_get_proc_load;
973         fxn_msg_create pfn_msg_create;  /* Create message manager */
974         /* Create message queue */
975         fxn_msg_createqueue pfn_msg_create_queue;
976         fxn_msg_delete pfn_msg_delete;  /* Delete message manager */
977         /* Delete message queue */
978         fxn_msg_deletequeue pfn_msg_delete_queue;
979         fxn_msg_get pfn_msg_get;        /* Get a message */
980         fxn_msg_put pfn_msg_put;        /* Send a message */
981         /* Register for notif. */
982         fxn_msg_registernotify pfn_msg_register_notify;
983         /* Set message queue id */
984         fxn_msg_setqueueid pfn_msg_set_queue_id;
985 };
986
987 /*
988  *  ======== bridge_drv_entry ========
989  *  Purpose:
990  *      Registers Bridge driver functions with the DSP API. Called only once
991  *      by the DSP API.  The caller will first check DSP API version
992  *      compatibility, and then copy the interface functions into its own
993  *      memory space.
994  *  Parameters:
995  *      drv_intf  Pointer to a location to receive a pointer to the
996  *                      Bridge driver interface.
997  *  Returns:
998  *  Requires:
999  *      The code segment this function resides in must expect to be discarded
1000  *      after completion.
1001  *  Ensures:
1002  *      drv_intf pointer initialized to Bridge driver's function
1003  *      interface. No system resources are acquired by this function.
1004  *  Details:
1005  *      Called during the Device_Init phase.
1006  */
1007 void bridge_drv_entry(struct bridge_drv_interface **drv_intf,
1008                    const char *driver_file_name);
1009
1010 #endif /* DSPDEFS_ */