19 #include <linux/types.h>
20 #include <linux/bitmap.h>
21 #include <linux/list.h>
69 #define HOSTPREFIX "/host"
70 #define PIPEPREFIX "/dbpipe"
72 #define MAX_INPUTS(h) \
73 ((h)->dcd_props.obj_data.node_obj.ndb_props.num_input_streams)
74 #define MAX_OUTPUTS(h) \
75 ((h)->dcd_props.obj_data.node_obj.ndb_props.num_output_streams)
77 #define NODE_GET_PRIORITY(h) ((h)->prio)
78 #define NODE_SET_PRIORITY(hnode, prio) ((hnode)->prio = prio)
79 #define NODE_SET_STATE(hnode, state) ((hnode)->node_state = state)
82 #define MAXDEVSUFFIXLEN 2
84 #define PIPENAMELEN (sizeof(PIPEPREFIX) + MAXDEVSUFFIXLEN)
85 #define HOSTNAMELEN (sizeof(HOSTPREFIX) + MAXDEVSUFFIXLEN)
87 #define MAXDEVNAMELEN 32
89 #define EXECUTEPHASE 2
97 #define DEFAULTBUFSIZE 32
98 #define DEFAULTNBUFS 2
99 #define DEFAULTSEGID 0
100 #define DEFAULTALIGNMENT 0
101 #define DEFAULTTIMEOUT 10000
103 #define RMSQUERYSERVER 0
104 #define RMSCONFIGURESERVER 1
105 #define RMSCREATENODE 2
106 #define RMSEXECUTENODE 3
107 #define RMSDELETENODE 4
108 #define RMSCHANGENODEPRIORITY 5
109 #define RMSREADMEMORY 6
110 #define RMSWRITEMEMORY 7
112 #define MAXTIMEOUT 2000
116 #define PWR_TIMEOUT 500
118 #define STACKSEGLABEL "L1DSRAM_HEAP"
241 static void delete_node_mgr(
struct node_mgr *hnode_mgr);
242 static void fill_stream_connect(
struct node_object *node1,
245 static void fill_stream_def(
struct node_object *hnode,
249 static int get_fxn_address(
struct node_object *hnode,
u32 * fxn_addr,
251 static int get_node_props(
struct dcd_manager *hdcd_mgr,
255 static int get_proc_props(
struct node_mgr *hnode_mgr,
257 static int get_rms_fxns(
struct node_mgr *hnode_mgr);
258 static u32 ovly(
void *priv_ref,
u32 dsp_run_addr,
u32 dsp_load_addr,
259 u32 ul_num_bytes,
u32 mem_space);
260 static u32 mem_write(
void *priv_ref,
u32 dsp_add,
void *pbuf,
261 u32 ul_num_bytes,
u32 mem_space);
307 u32 ul_stack_seg_val;
330 if (hnode_mgr ==
NULL)
339 if (!pbridge_context) {
358 pr_err(
"%s: Failed, no RMS in base image\n", __func__);
383 status = get_node_props(hnode_mgr->
dcd_mgr, pnode, node_uuid,
390 pnode->
ntype = pnode->
dcd_props.obj_data.node_obj.ndb_props.ntype;
392 pnode->
prio = pnode->
dcd_props.obj_data.node_obj.ndb_props.prio;
397 pnode->
create_args.asa.task_arg_obj.dsp_heap_addr = 0;
398 pnode->
create_args.asa.task_arg_obj.dsp_heap_res_addr = 0;
399 pnode->
create_args.asa.task_arg_obj.gpp_heap_addr = 0;
409 pr_err(
"%s: node heap size not aligned to 4K, size = 0x%x \n",
415 pnode->
create_args.asa.task_arg_obj.gpp_heap_addr =
425 task_arg_obj.dsp_heap_res_addr),
428 pr_err(
"%s: Failed to reserve memory for heap: 0x%x\n",
435 status = DSP_EHANDLE;
439 dmm_mem_map_dump(dmm_mgr);
448 dsp_heap_res_addr, (
void **)&mapped_addr, map_attrs,
451 pr_err(
"%s: Failed to map memory for Heap: 0x%x\n",
454 pnode->
create_args.asa.task_arg_obj.dsp_heap_addr =
459 if (attr_in !=
NULL) {
487 if (!status && (node_type ==
NODE_TASK ||
494 ptask_args = &(pnode->
create_args.asa.task_arg_obj);
557 node_msg_args.max_msgs,
578 (
char *)pnode->
dcd_props.obj_data.node_obj.ndb_props.
579 stack_seg_name !=
NULL) {
581 pnode->
dcd_props.obj_data.node_obj.ndb_props.
591 pr_err(
"%s: Failed to get addr for DYNEXT_BEG"
592 " status = 0x%x\n", __func__, status);
597 "L1DSRAM_HEAP", &pul_value);
600 pr_err(
"%s: Failed to get addr for L1DSRAM_HEAP"
601 " status = 0x%x\n", __func__, status);
608 pr_err(
"%s: Failed to get host resource, status"
609 " = 0x%x\n", __func__, status);
613 off_set = pul_value - dynext_base;
614 stack_seg_pa = host_res->
mem_phys[1] + off_set;
621 ul_stack_seg_val =
readl(stack_seg);
626 " 0x%x\n", __func__, ul_stack_seg_val,
657 delete_node(pnode, pr_ctxt);
664 delete_node(pnode, pr_ctxt);
673 dev_dbg(
bridge,
"%s: hprocessor: %p pNodeId: %p pargs: %p attr_in: %p "
674 "node_res: %p status: 0x%x\n", __func__, hprocessor,
675 node_uuid, pargs, attr_in, noderes, status);
690 bool va_flag =
false;
703 pattr = &node_dfltbufattrs;
724 if (!status && (!va_flag)) {
748 if (*pbuffer ==
NULL) {
749 pr_err(
"%s: error - Out of shared memory\n",
829 char *pstr_dev_name =
NULL;
845 if (!node1 || !node2)
917 task_arg_obj.strm_out_def[stream1]);
926 task_arg_obj.strm_in_def[stream2]);
943 set_bit(pipe_id, hnode_mgr->pipe_map);
946 node1->
outputs[stream1].dev_id = pipe_id;
947 node2->
inputs[stream2].dev_id = pipe_id;
965 if (!pstr_dev_name) {
970 chnl_mode = (node1_type ==
NODE_GPP) ?
985 set_bit(chnl_id, hnode_mgr->dma_chnl_map);
988 chnl_id = chnl_id + hnode_mgr->
num_chnls;
995 set_bit(chnl_id, hnode_mgr->zc_chnl_map);
1006 set_bit(chnl_id, hnode_mgr->chnl_map);
1019 node2->
inputs[stream2].dev_id = chnl_id;
1023 node1->
outputs[stream1].dev_id = chnl_id;
1032 dev_node_obj = node2;
1034 pstream = &(node1->
outputs[stream1]);
1038 dev_node_obj = node1;
1040 pstream = &(node2->
inputs[stream2]);
1047 pstrm_def->
sz_device = kzalloc(dw_length + 1 +
1051 pstrm_def->
sz_device = kzalloc(dw_length + 1,
1068 node1->
create_args.asa.task_arg_obj.num_outputs++;
1069 fill_stream_def(node1, output, pattrs);
1073 fill_stream_def(node2, input, pattrs);
1088 fill_stream_connect(node1, node2, stream1, stream2);
1092 if (status && pstr_dev_name)
1093 kfree(pstr_dev_name);
1095 dev_dbg(
bridge,
"%s: node1: %p stream1: %d node2: %p stream2: %d"
1096 "pattrs: %p status: 0x%x\n", __func__, node1,
1097 stream1, node2, stream2, pattrs, status);
1119 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1120 struct dspbridge_platform_data *
pdata =
1170 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1171 if (pdata->cpu_set_freq)
1172 (*pdata->cpu_set_freq) (pdata->mpu_speed[VDD1_OPP3]);
1180 status = get_fxn_address(hnode, &ul_create_fxn,
1184 pr_err(
"%s: failed to load create code: 0x%x\n",
1188 #if defined(CONFIG_TIDSPBRIDGE_DVFS) && !defined(CONFIG_CPU_FREQ)
1189 if (pdata->cpu_set_freq)
1190 (*pdata->cpu_set_freq) (pdata->mpu_speed[VDD1_OPP1]);
1195 status = hnode_mgr->
nldr_fxns.get_fxn_addr
1200 task_arg_obj.dais_arg);
1232 pr_err(
"%s: Failed to unload create code: 0x%x\n",
1241 if (status != -
EBADR) {
1270 char *sz_zl_file =
"";
1281 node_mgr_obj->
dev_obj = hdev_obj;
1291 INIT_LIST_HEAD(&node_mgr_obj->
node_list);
1299 status = get_proc_props(node_mgr_obj, hdev_obj);
1325 set_bit(i, node_mgr_obj->chnl_map);
1334 status = get_rms_fxns(node_mgr_obj);
1343 nldr_attrs_obj.
write = mem_write;
1352 *node_man = node_mgr_obj;
1356 delete_node_mgr(node_mgr_obj);
1383 void *node_res = noderes;
1441 pr_err(
"%s: fail - load delete code:"
1442 " 0x%x\n", __func__, status);
1452 status = get_fxn_address(pnode, &ul_delete_fxn,
1482 pr_err(
"%s: fail - unload execute code:"
1483 " 0x%x\n", __func__, status1);
1491 pr_err(
"%s: fail - unload delete code: "
1492 "0x%x\n", __func__, status1);
1507 delete_node(pnode, pr_ctxt);
1519 dev_dbg(
bridge,
"%s: pnode: %p status 0x%x\n", __func__, pnode, status);
1533 delete_node_mgr(hnode_mgr);
1544 u32 node_tab_size,
u32 *pu_num_nodes,
1558 if (hnode_mgr->
num_nodes > node_tab_size) {
1564 node_tab[i++] = hnode;
1565 *pu_allocated = *pu_num_nodes = hnode_mgr->
num_nodes;
1593 if (pattr ==
NULL) {
1595 pattr = &node_dfltbufattrs;
1638 hnode->
create_args.asa.task_arg_obj.gpp_heap_addr;
1741 (
void *)(message->
arg1 *
1744 if (tmp_buf !=
NULL) {
1748 if (tmp_buf !=
NULL) {
1750 message->
arg1 = (
u32) tmp_buf;
1759 dev_dbg(
bridge,
"%s: hnode: %p message: %p utimeout: 0x%x\n", __func__,
1760 hnode, message, utimeout);
1771 struct node_mgr *node_mgr_obj = hnode_mgr;
1776 *nldr_ovlyobj = node_mgr_obj->
nldr_obj;
1794 *strm_man = hnode->
node_mgr->strm_mgr_obj;
1805 dev_dbg(
bridge,
"%s: Failed. hnode: %p\n", __func__, hnode);
1808 return hnode->
dcd_props.obj_data.node_obj.load_type;
1820 dev_dbg(
bridge,
"%s: failed. hnode: %p\n", __func__, hnode);
1842 node_type = hnode->
ntype;
1947 dev_dbg(
bridge,
"%s: hnode: %p status 0x%x\n", __func__, hnode, status);
2017 (
void *)new_msg.
arg1,
2019 if (tmp_buf !=
NULL) {
2021 if (hnode->
node_mgr->dsp_word_size != 0) {
2029 pr_err(
"%s: dsp_word_size is zero!\n",
2040 &new_msg, utimeout);
2044 "status 0x%x\n", __func__, hnode, pmsg, utimeout, status);
2078 status = ntfy_register(hnode->
ntfy_obj, hnotification,
2083 intf_fxns = hnode->
node_mgr->intf_fxns;
2091 dev_dbg(
bridge,
"%s: hnode: %p event_mask: 0x%x notify_type: 0x%x "
2092 "hnotification: %p status 0x%x\n", __func__, hnode,
2093 event_mask, notify_type, hnotification, status);
2169 pr_err(
"%s: fail - load execute code: 0x%x\n",
2178 status = get_fxn_address(hnode, &ul_execute_fxn,
2186 ul_fxn_addr, ul_execute_fxn,
2192 ul_fxn_addr, hnode->node_env,
2211 dev_dbg(bridge,
"%s: hnode: %p status 0x%x\n", __func__, hnode,
status);
2292 kill_time_out = (hnode->
timeout) * 2;
2305 status = sync_wait_on_event(hnode->
sync_done,
2307 if (status !=
ETIME)
2314 status = sync_wait_on_event(hnode->
sync_done,
2339 __func__, hnode, hnode->
node_env, status);
2352 static void delete_node(
struct node_object *hnode,
2362 #ifdef DSP_DMM_DEBUG
2376 node_msg_args = hnode->
create_args.asa.node_msg_args;
2377 kfree(node_msg_args.pdata);
2393 free_stream(hnode_mgr, stream);
2401 free_stream(hnode_mgr, stream);
2406 task_arg_obj = hnode->
create_args.asa.task_arg_obj;
2407 if (task_arg_obj.strm_in_def) {
2409 kfree(task_arg_obj.strm_in_def[i].sz_device);
2410 task_arg_obj.strm_in_def[
i].sz_device =
NULL;
2412 kfree(task_arg_obj.strm_in_def);
2413 task_arg_obj.strm_in_def =
NULL;
2415 if (task_arg_obj.strm_out_def) {
2417 kfree(task_arg_obj.strm_out_def[i].sz_device);
2418 task_arg_obj.strm_out_def[
i].sz_device =
NULL;
2420 kfree(task_arg_obj.strm_out_def);
2421 task_arg_obj.strm_out_def =
NULL;
2423 if (task_arg_obj.dsp_heap_res_addr) {
2425 task_arg_obj.dsp_heap_addr,
2433 #ifdef DSP_DMM_DEBUG
2436 dmm_mem_map_dump(dmm_mgr);
2457 hnode->
dcd_props.obj_data.node_obj.str_create_phase_fxn =
NULL;
2460 hnode->
dcd_props.obj_data.node_obj.str_execute_phase_fxn =
NULL;
2463 hnode->
dcd_props.obj_data.node_obj.str_delete_phase_fxn =
NULL;
2484 static void delete_node_mgr(
struct node_mgr *hnode_mgr)
2497 delete_node(hnode,
NULL);
2524 static void fill_stream_connect(
struct node_object *node1,
2526 u32 stream1,
u32 stream2)
2583 static void fill_stream_def(
struct node_object *hnode,
2589 if (pattrs !=
NULL) {
2629 hnode_mgr->dma_chnl_map);
2633 hnode_mgr->zc_chnl_map);
2643 static int get_fxn_address(
struct node_object *hnode,
u32 * fxn_addr,
2646 char *pstr_fxn_name =
NULL;
2653 hnode->
dcd_props.obj_data.node_obj.str_create_phase_fxn;
2657 hnode->
dcd_props.obj_data.node_obj.str_execute_phase_fxn;
2661 hnode->
dcd_props.obj_data.node_obj.str_delete_phase_fxn;
2670 pstr_fxn_name, fxn_addr);
2686 hnode->
dcd_props.obj_data.node_obj.ndb_props;
2705 static int get_node_props(
struct dcd_manager *hdcd_mgr,
2723 hnode->
ntype = node_type = pndb_props->
ntype;
2727 dev_dbg(bridge,
"(node) UUID: %s\n", sz_uuid);
2731 pmsg_args = &(hnode->
create_args.asa.node_msg_args);
2737 dev_dbg(bridge,
"(node) Max Number of Messages: 0x%x\n",
2754 task_arg_obj = &(hnode->
create_args.asa.task_arg_obj);
2755 task_arg_obj->
prio = pndb_props->
prio;
2760 dev_dbg(bridge,
"(node) Priority: 0x%x Stack Size: "
2761 "0x%x words System Stack Size: 0x%x words "
2762 "Stack Segment: 0x%x profile count : 0x%x\n",
2778 static int get_proc_props(
struct node_mgr *hnode_mgr,
2786 if (!pbridge_context)
2829 if (hprocessor ==
NULL || node_uuid ==
NULL) {
2847 if (hnode_mgr ==
NULL) {
2891 static int get_rms_fxns(
struct node_mgr *hnode_mgr)
2899 "RMS_configureServer",
2903 "RMS_changeNodePriority",
2918 dev_dbg(bridge,
"%s: RMS function: %s currently"
2919 " not loaded\n", __func__, psz_fxns[i]);
2921 dev_dbg(bridge,
"%s: Symbol not found: %s "
2922 "status = 0x%x\n", __func__,
2923 psz_fxns[i], status);
2937 static u32 ovly(
void *priv_ref,
u32 dsp_run_addr,
u32 dsp_load_addr,
2938 u32 ul_num_bytes,
u32 mem_space)
2961 dsp_run_addr, dsp_load_addr,
2962 ul_num_bytes, (
u32) mem_space);
2964 ul_bytes = ul_num_bytes;
2966 pr_debug(
"%s: failed to copy brd memory, status 0x%x\n",
2969 pr_debug(
"%s: failed to get Bridge context, status 0x%x\n",
2979 static u32 mem_write(
void *priv_ref,
u32 dsp_add,
void *pbuf,
2980 u32 ul_num_bytes,
u32 mem_space)
2999 status = (*intf_fxns->
brd_mem_write) (hbridge_context, pbuf,
3000 dsp_add, ul_num_bytes, mem_sect_type);
3002 return ul_num_bytes;
3005 #ifdef CONFIG_TIDSPBRIDGE_BACKTRACE
3010 u32 offset_range,
void *sym_addr_output,
char *
sym_name)
3015 pr_debug(
"%s(0x%x, 0x%x, 0x%x, 0x%x, %s)\n", __func__,
3016 (
unsigned int) node_mgr,
3017 sym_addr, offset_range,
3018 (
unsigned int) sym_addr_output, sym_name);
3022 offset_range, sym_addr_output, sym_name);