4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Node Dispatcher interface. Communicates with Resource Manager Server
7 * (RMS) on DSP. Access to RMS is synchronized in NODE.
9 * Copyright (C) 2005-2006 Texas Instruments, Inc.
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.
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.
19 #include <linux/types.h>
21 /* ----------------------------------- Host OS */
22 #include <dspbridge/host_os.h>
24 /* ----------------------------------- DSP/BIOS Bridge */
25 #include <dspbridge/dbdefs.h>
27 /* ----------------------------------- Trace & Debug */
28 #include <dspbridge/dbc.h>
30 /* ----------------------------------- OS Adaptation Layer */
31 #include <dspbridge/sync.h>
33 /* ----------------------------------- Link Driver */
34 #include <dspbridge/dspdefs.h>
36 /* ----------------------------------- Platform Manager */
37 #include <dspbridge/dev.h>
38 #include <dspbridge/chnldefs.h>
40 /* ----------------------------------- Resource Manager */
41 #include <dspbridge/nodedefs.h>
42 #include <dspbridge/nodepriv.h>
43 #include <dspbridge/rms_sh.h>
45 /* ----------------------------------- This */
46 #include <dspbridge/disp.h>
48 /* Size of a reply from RMS */
49 #define REPLYSIZE (3 * sizeof(rms_word))
51 /* Reserved channel offsets for communication with RMS */
52 #define CHNLTORMSOFFSET 0
53 #define CHNLFROMRMSOFFSET 1
58 * ======== disp_object ========
61 struct dev_object
*dev_obj
; /* Device for this processor */
62 /* Function interface to Bridge driver */
63 struct bridge_drv_interface
*intf_fxns
;
64 struct chnl_mgr
*chnl_mgr
; /* Channel manager */
65 struct chnl_object
*chnl_to_dsp
; /* Chnl for commands to RMS */
66 struct chnl_object
*chnl_from_dsp
; /* Chnl for replies from RMS */
67 u8
*buf
; /* Buffer for commands, replies */
68 u32 bufsize
; /* buf size in bytes */
69 u32 bufsize_rms
; /* buf size in RMS words */
70 u32 char_size
; /* Size of DSP character */
71 u32 word_size
; /* Size of DSP word */
72 u32 data_mau_size
; /* Size of DSP Data MAU */
77 static void delete_disp(struct disp_object
*disp_obj
);
78 static int fill_stream_def(rms_word
*pdw_buf
, u32
*ptotal
, u32 offset
,
79 struct node_strmdef strm_def
, u32 max
,
80 u32 chars_in_rms_word
);
81 static int send_message(struct disp_object
*disp_obj
, u32 timeout
,
82 u32 ul_bytes
, u32
*pdw_arg
);
85 * ======== disp_create ========
86 * Create a NODE Dispatcher object.
88 int disp_create(struct disp_object
**dispatch_obj
,
89 struct dev_object
*hdev_obj
,
90 const struct disp_attr
*disp_attrs
)
92 struct disp_object
*disp_obj
;
93 struct bridge_drv_interface
*intf_fxns
;
95 struct chnl_attr chnl_attr_obj
;
99 DBC_REQUIRE(refs
> 0);
100 DBC_REQUIRE(dispatch_obj
!= NULL
);
101 DBC_REQUIRE(disp_attrs
!= NULL
);
102 DBC_REQUIRE(hdev_obj
!= NULL
);
104 *dispatch_obj
= NULL
;
106 /* Allocate Node Dispatcher object */
107 disp_obj
= kzalloc(sizeof(struct disp_object
), GFP_KERNEL
);
108 if (disp_obj
== NULL
)
111 disp_obj
->dev_obj
= hdev_obj
;
113 /* Get Channel manager and Bridge function interface */
115 status
= dev_get_chnl_mgr(hdev_obj
, &(disp_obj
->chnl_mgr
));
117 (void)dev_get_intf_fxns(hdev_obj
, &intf_fxns
);
118 disp_obj
->intf_fxns
= intf_fxns
;
122 /* check device type and decide if streams or messag'ing is used for
127 status
= dev_get_dev_type(hdev_obj
, &dev_type
);
132 if (dev_type
!= DSP_UNIT
) {
137 disp_obj
->char_size
= DSPWORDSIZE
;
138 disp_obj
->word_size
= DSPWORDSIZE
;
139 disp_obj
->data_mau_size
= DSPWORDSIZE
;
140 /* Open channels for communicating with the RMS */
141 chnl_attr_obj
.uio_reqs
= CHNLIOREQS
;
142 chnl_attr_obj
.event_obj
= NULL
;
143 ul_chnl_id
= disp_attrs
->chnl_offset
+ CHNLTORMSOFFSET
;
144 status
= (*intf_fxns
->chnl_open
) (&(disp_obj
->chnl_to_dsp
),
146 CHNL_MODETODSP
, ul_chnl_id
,
150 ul_chnl_id
= disp_attrs
->chnl_offset
+ CHNLFROMRMSOFFSET
;
152 (*intf_fxns
->chnl_open
) (&(disp_obj
->chnl_from_dsp
),
154 CHNL_MODEFROMDSP
, ul_chnl_id
,
158 /* Allocate buffer for commands, replies */
159 disp_obj
->bufsize
= disp_attrs
->chnl_buf_size
;
160 disp_obj
->bufsize_rms
= RMS_COMMANDBUFSIZE
;
161 disp_obj
->buf
= kzalloc(disp_obj
->bufsize
, GFP_KERNEL
);
162 if (disp_obj
->buf
== NULL
)
167 *dispatch_obj
= disp_obj
;
169 delete_disp(disp_obj
);
171 DBC_ENSURE((status
&& *dispatch_obj
== NULL
) ||
172 (!status
&& *dispatch_obj
));
177 * ======== disp_delete ========
178 * Delete the NODE Dispatcher.
180 void disp_delete(struct disp_object
*disp_obj
)
182 DBC_REQUIRE(refs
> 0);
183 DBC_REQUIRE(disp_obj
);
185 delete_disp(disp_obj
);
189 * ======== disp_exit ========
190 * Discontinue usage of DISP module.
194 DBC_REQUIRE(refs
> 0);
198 DBC_ENSURE(refs
>= 0);
202 * ======== disp_init ========
203 * Initialize the DISP module.
209 DBC_REQUIRE(refs
>= 0);
214 DBC_ENSURE((ret
&& (refs
> 0)) || (!ret
&& (refs
>= 0)));
219 * ======== disp_node_change_priority ========
220 * Change the priority of a node currently running on the target.
222 int disp_node_change_priority(struct disp_object
*disp_obj
,
223 struct node_object
*hnode
,
224 u32 rms_fxn
, nodeenv node_env
, s32 prio
)
227 struct rms_command
*rms_cmd
;
230 DBC_REQUIRE(refs
> 0);
231 DBC_REQUIRE(disp_obj
);
232 DBC_REQUIRE(hnode
!= NULL
);
234 /* Send message to RMS to change priority */
235 rms_cmd
= (struct rms_command
*)(disp_obj
->buf
);
236 rms_cmd
->fxn
= (rms_word
) (rms_fxn
);
237 rms_cmd
->arg1
= (rms_word
) node_env
;
238 rms_cmd
->arg2
= prio
;
239 status
= send_message(disp_obj
, node_get_timeout(hnode
),
240 sizeof(struct rms_command
), &dw_arg
);
246 * ======== disp_node_create ========
247 * Create a node on the DSP by remotely calling the node's create function.
249 int disp_node_create(struct disp_object
*disp_obj
,
250 struct node_object
*hnode
, u32 rms_fxn
,
252 const struct node_createargs
*pargs
,
255 struct node_msgargs node_msg_args
;
256 struct node_taskargs task_arg_obj
;
257 struct rms_command
*rms_cmd
;
258 struct rms_msg_args
*pmsg_args
;
259 struct rms_more_task_args
*more_task_args
;
260 enum node_type node_type
;
262 rms_word
*pdw_buf
= NULL
;
266 u32 chars_in_rms_word
;
267 s32 task_args_offset
;
268 s32 sio_in_def_offset
;
269 s32 sio_out_def_offset
;
271 s32 args_offset
= -1;
273 struct node_strmdef strm_def
;
276 struct dsp_nodeinfo node_info
;
279 DBC_REQUIRE(refs
> 0);
280 DBC_REQUIRE(disp_obj
);
281 DBC_REQUIRE(hnode
!= NULL
);
282 DBC_REQUIRE(node_get_type(hnode
) != NODE_DEVICE
);
283 DBC_REQUIRE(node_env
!= NULL
);
285 status
= dev_get_dev_type(disp_obj
->dev_obj
, &dev_type
);
290 if (dev_type
!= DSP_UNIT
) {
291 dev_dbg(bridge
, "%s: unknown device type = 0x%x\n",
295 DBC_REQUIRE(pargs
!= NULL
);
296 node_type
= node_get_type(hnode
);
297 node_msg_args
= pargs
->asa
.node_msg_args
;
298 max
= disp_obj
->bufsize_rms
; /*Max # of RMS words that can be sent */
299 DBC_ASSERT(max
== RMS_COMMANDBUFSIZE
);
300 chars_in_rms_word
= sizeof(rms_word
) / disp_obj
->char_size
;
301 /* Number of RMS words needed to hold arg data */
303 (node_msg_args
.arg_length
+ chars_in_rms_word
-
304 1) / chars_in_rms_word
;
305 /* Make sure msg args and command fit in buffer */
306 total
= sizeof(struct rms_command
) / sizeof(rms_word
) +
307 sizeof(struct rms_msg_args
)
308 / sizeof(rms_word
) - 1 + dw_length
;
311 dev_dbg(bridge
, "%s: Message args too large for buffer! size "
312 "= %d, max = %d\n", __func__
, total
, max
);
315 * Fill in buffer to send to RMS.
316 * The buffer will have the following format:
319 * Address of RMS_CreateNode()
320 * Address of node's create function
325 * max number of messages
326 * segid for message buffer allocation
327 * notification type to use when message is received
328 * length of message arg data
331 * Task Args (if task or socket node):
337 * number of input streams
338 * pSTRMInDef[] - offsets of STRM definitions for input streams
339 * number of output streams
340 * pSTRMOutDef[] - offsets of STRM definitions for output
342 * STRMInDef[] - array of STRM definitions for input streams
343 * STRMOutDef[] - array of STRM definitions for output streams
345 * Socket Args (if DAIS socket node):
349 total
= 0; /* Total number of words in buffer so far */
350 pdw_buf
= (rms_word
*) disp_obj
->buf
;
351 rms_cmd
= (struct rms_command
*)pdw_buf
;
352 rms_cmd
->fxn
= (rms_word
) (rms_fxn
);
353 rms_cmd
->arg1
= (rms_word
) (ul_create_fxn
);
354 if (node_get_load_type(hnode
) == NLDR_DYNAMICLOAD
) {
355 /* Flush ICACHE on Load */
356 rms_cmd
->arg2
= 1; /* dummy argument */
358 /* Do not flush ICACHE */
359 rms_cmd
->arg2
= 0; /* dummy argument */
361 rms_cmd
->data
= node_get_type(hnode
);
363 * args_offset is the offset of the data field in struct
364 * rms_command structure. We need this to calculate stream
365 * definition offsets.
368 total
+= sizeof(struct rms_command
) / sizeof(rms_word
);
370 pmsg_args
= (struct rms_msg_args
*)(pdw_buf
+ total
);
371 pmsg_args
->max_msgs
= node_msg_args
.max_msgs
;
372 pmsg_args
->segid
= node_msg_args
.seg_id
;
373 pmsg_args
->notify_type
= node_msg_args
.notify_type
;
374 pmsg_args
->arg_length
= node_msg_args
.arg_length
;
375 total
+= sizeof(struct rms_msg_args
) / sizeof(rms_word
) - 1;
376 memcpy(pdw_buf
+ total
, node_msg_args
.pdata
,
377 node_msg_args
.arg_length
);
383 /* If node is a task node, copy task create arguments into buffer */
384 if (node_type
== NODE_TASK
|| node_type
== NODE_DAISSOCKET
) {
385 task_arg_obj
= pargs
->asa
.task_arg_obj
;
386 task_args_offset
= total
;
387 total
+= sizeof(struct rms_more_task_args
) / sizeof(rms_word
) +
388 1 + task_arg_obj
.num_inputs
+ task_arg_obj
.num_outputs
;
389 /* Copy task arguments */
391 total
= task_args_offset
;
392 more_task_args
= (struct rms_more_task_args
*)(pdw_buf
+
395 * Get some important info about the node. Note that we
396 * don't just reach into the hnode struct because
397 * that would break the node object's abstraction.
399 get_node_info(hnode
, &node_info
);
400 more_task_args
->priority
= node_info
.execution_priority
;
401 more_task_args
->stack_size
= task_arg_obj
.stack_size
;
402 more_task_args
->sysstack_size
=
403 task_arg_obj
.sys_stack_size
;
404 more_task_args
->stack_seg
= task_arg_obj
.stack_seg
;
405 more_task_args
->heap_addr
= task_arg_obj
.dsp_heap_addr
;
406 more_task_args
->heap_size
= task_arg_obj
.heap_size
;
407 more_task_args
->misc
= task_arg_obj
.dais_arg
;
408 more_task_args
->num_input_streams
=
409 task_arg_obj
.num_inputs
;
411 sizeof(struct rms_more_task_args
) /
413 dev_dbg(bridge
, "%s: dsp_heap_addr %x, heap_size %x\n",
414 __func__
, task_arg_obj
.dsp_heap_addr
,
415 task_arg_obj
.heap_size
);
416 /* Keep track of pSIOInDef[] and pSIOOutDef[]
417 * positions in the buffer, since this needs to be
418 * filled in later. */
419 sio_in_def_offset
= total
;
420 total
+= task_arg_obj
.num_inputs
;
421 pdw_buf
[total
++] = task_arg_obj
.num_outputs
;
422 sio_out_def_offset
= total
;
423 total
+= task_arg_obj
.num_outputs
;
424 sio_defs_offset
= total
;
425 /* Fill SIO defs and offsets */
426 offset
= sio_defs_offset
;
427 for (i
= 0; i
< task_arg_obj
.num_inputs
; i
++) {
431 pdw_buf
[sio_in_def_offset
+ i
] =
432 (offset
- args_offset
)
433 * (sizeof(rms_word
) / DSPWORDSIZE
);
434 strm_def
= task_arg_obj
.strm_in_def
[i
];
436 fill_stream_def(pdw_buf
, &total
, offset
,
441 for (i
= 0; (i
< task_arg_obj
.num_outputs
) &&
443 pdw_buf
[sio_out_def_offset
+ i
] =
444 (offset
- args_offset
)
445 * (sizeof(rms_word
) / DSPWORDSIZE
);
446 strm_def
= task_arg_obj
.strm_out_def
[i
];
448 fill_stream_def(pdw_buf
, &total
, offset
,
459 ul_bytes
= total
* sizeof(rms_word
);
460 DBC_ASSERT(ul_bytes
< (RMS_COMMANDBUFSIZE
* sizeof(rms_word
)));
461 status
= send_message(disp_obj
, node_get_timeout(hnode
),
469 * ======== disp_node_delete ========
471 * Delete a node on the DSP by remotely calling the node's delete function.
474 int disp_node_delete(struct disp_object
*disp_obj
,
475 struct node_object
*hnode
, u32 rms_fxn
,
476 u32 ul_delete_fxn
, nodeenv node_env
)
479 struct rms_command
*rms_cmd
;
483 DBC_REQUIRE(refs
> 0);
484 DBC_REQUIRE(disp_obj
);
485 DBC_REQUIRE(hnode
!= NULL
);
487 status
= dev_get_dev_type(disp_obj
->dev_obj
, &dev_type
);
491 if (dev_type
== DSP_UNIT
) {
494 * Fill in buffer to send to RMS
496 rms_cmd
= (struct rms_command
*)disp_obj
->buf
;
497 rms_cmd
->fxn
= (rms_word
) (rms_fxn
);
498 rms_cmd
->arg1
= (rms_word
) node_env
;
499 rms_cmd
->arg2
= (rms_word
) (ul_delete_fxn
);
500 rms_cmd
->data
= node_get_type(hnode
);
502 status
= send_message(disp_obj
, node_get_timeout(hnode
),
503 sizeof(struct rms_command
),
511 * ======== disp_node_run ========
513 * Start execution of a node's execute phase, or resume execution of a node
514 * that has been suspended (via DISP_NodePause()) on the DSP.
516 int disp_node_run(struct disp_object
*disp_obj
,
517 struct node_object
*hnode
, u32 rms_fxn
,
518 u32 ul_execute_fxn
, nodeenv node_env
)
521 struct rms_command
*rms_cmd
;
524 DBC_REQUIRE(refs
> 0);
525 DBC_REQUIRE(disp_obj
);
526 DBC_REQUIRE(hnode
!= NULL
);
528 status
= dev_get_dev_type(disp_obj
->dev_obj
, &dev_type
);
532 if (dev_type
== DSP_UNIT
) {
535 * Fill in buffer to send to RMS.
537 rms_cmd
= (struct rms_command
*)disp_obj
->buf
;
538 rms_cmd
->fxn
= (rms_word
) (rms_fxn
);
539 rms_cmd
->arg1
= (rms_word
) node_env
;
540 rms_cmd
->arg2
= (rms_word
) (ul_execute_fxn
);
541 rms_cmd
->data
= node_get_type(hnode
);
543 status
= send_message(disp_obj
, node_get_timeout(hnode
),
544 sizeof(struct rms_command
),
553 * ======== delete_disp ========
555 * Frees the resources allocated for the dispatcher.
557 static void delete_disp(struct disp_object
*disp_obj
)
560 struct bridge_drv_interface
*intf_fxns
;
563 intf_fxns
= disp_obj
->intf_fxns
;
565 /* Free Node Dispatcher resources */
566 if (disp_obj
->chnl_from_dsp
) {
567 /* Channel close can fail only if the channel handle
569 status
= (*intf_fxns
->chnl_close
)
570 (disp_obj
->chnl_from_dsp
);
572 dev_dbg(bridge
, "%s: Failed to close channel "
573 "from RMS: 0x%x\n", __func__
, status
);
576 if (disp_obj
->chnl_to_dsp
) {
578 (*intf_fxns
->chnl_close
) (disp_obj
->
581 dev_dbg(bridge
, "%s: Failed to close channel to"
582 " RMS: 0x%x\n", __func__
, status
);
585 kfree(disp_obj
->buf
);
592 * ======== fill_stream_def ========
594 * Fills stream definitions.
596 static int fill_stream_def(rms_word
*pdw_buf
, u32
*ptotal
, u32 offset
,
597 struct node_strmdef strm_def
, u32 max
,
598 u32 chars_in_rms_word
)
600 struct rms_strm_def
*strm_def_obj
;
606 if (total
+ sizeof(struct rms_strm_def
) / sizeof(rms_word
) >= max
) {
609 strm_def_obj
= (struct rms_strm_def
*)(pdw_buf
+ total
);
610 strm_def_obj
->bufsize
= strm_def
.buf_size
;
611 strm_def_obj
->nbufs
= strm_def
.num_bufs
;
612 strm_def_obj
->segid
= strm_def
.seg_id
;
613 strm_def_obj
->align
= strm_def
.buf_alignment
;
614 strm_def_obj
->timeout
= strm_def
.timeout
;
619 * Since we haven't added the device name yet, subtract
622 total
+= sizeof(struct rms_strm_def
) / sizeof(rms_word
) - 1;
623 DBC_REQUIRE(strm_def
.sz_device
);
624 dw_length
= strlen(strm_def
.sz_device
) + 1;
626 /* Number of RMS_WORDS needed to hold device name */
628 (dw_length
+ chars_in_rms_word
- 1) / chars_in_rms_word
;
630 if (total
+ name_len
>= max
) {
634 * Zero out last word, since the device name may not
635 * extend to completely fill this word.
637 pdw_buf
[total
+ name_len
- 1] = 0;
638 /** TODO USE SERVICES * */
639 memcpy(pdw_buf
+ total
, strm_def
.sz_device
, dw_length
);
649 * ======== send_message ======
650 * Send command message to RMS, get reply from RMS.
652 static int send_message(struct disp_object
*disp_obj
, u32 timeout
,
653 u32 ul_bytes
, u32
*pdw_arg
)
655 struct bridge_drv_interface
*intf_fxns
;
656 struct chnl_object
*chnl_obj
;
659 struct chnl_ioc chnl_ioc_obj
;
662 DBC_REQUIRE(pdw_arg
!= NULL
);
664 *pdw_arg
= (u32
) NULL
;
665 intf_fxns
= disp_obj
->intf_fxns
;
666 chnl_obj
= disp_obj
->chnl_to_dsp
;
667 pbuf
= disp_obj
->buf
;
669 /* Send the command */
670 status
= (*intf_fxns
->chnl_add_io_req
) (chnl_obj
, pbuf
, ul_bytes
, 0,
676 (*intf_fxns
->chnl_get_ioc
) (chnl_obj
, timeout
, &chnl_ioc_obj
);
678 if (!CHNL_IS_IO_COMPLETE(chnl_ioc_obj
)) {
679 if (CHNL_IS_TIMED_OUT(chnl_ioc_obj
))
689 chnl_obj
= disp_obj
->chnl_from_dsp
;
690 ul_bytes
= REPLYSIZE
;
691 status
= (*intf_fxns
->chnl_add_io_req
) (chnl_obj
, pbuf
, ul_bytes
,
697 (*intf_fxns
->chnl_get_ioc
) (chnl_obj
, timeout
, &chnl_ioc_obj
);
699 if (CHNL_IS_TIMED_OUT(chnl_ioc_obj
)) {
701 } else if (chnl_ioc_obj
.byte_size
< ul_bytes
) {
702 /* Did not get all of the reply from the RMS */
705 if (CHNL_IS_IO_COMPLETE(chnl_ioc_obj
)) {
706 DBC_ASSERT(chnl_ioc_obj
.buf
== pbuf
);
707 if (*((int *)chnl_ioc_obj
.buf
) < 0) {
708 /* Translate DSP's to kernel error */
710 dev_dbg(bridge
, "%s: DSP-side failed:"
711 " DSP errcode = 0x%x, Kernel "
712 "errcode = %d\n", __func__
,
713 *(int *)pbuf
, status
);
716 (((rms_word
*) (chnl_ioc_obj
.buf
))[1]);