4 * DSP-BIOS Bridge driver support functions for TI OMAP processors.
6 * Common DSP API functions, also includes the wrapper
7 * functions called directly by the DeviceIOControl interface.
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 /* ----------------------------------- OS Adaptation Layer */
28 #include <dspbridge/ntfy.h>
30 /* ----------------------------------- Platform Manager */
31 #include <dspbridge/chnl.h>
32 #include <dspbridge/dev.h>
33 #include <dspbridge/drv.h>
35 #include <dspbridge/proc.h>
36 #include <dspbridge/strm.h>
38 /* ----------------------------------- Resource Manager */
39 #include <dspbridge/disp.h>
40 #include <dspbridge/mgr.h>
41 #include <dspbridge/node.h>
42 #include <dspbridge/rmm.h>
44 /* ----------------------------------- Others */
45 #include <dspbridge/msg.h>
46 #include <dspbridge/cmm.h>
47 #include <dspbridge/io.h>
49 /* ----------------------------------- This */
50 #include <dspbridge/dspapi.h>
51 #include <dspbridge/dbdcd.h>
53 #include <dspbridge/resourcecleanup.h>
55 /* ----------------------------------- Defines, Data Structures, Typedefs */
56 #define MAX_TRACEBUFLEN 255
57 #define MAX_LOADARGS 16
59 #define MAX_STREAMS 16
62 /* Used to get dspbridge ioctl table */
63 #define DB_GET_IOC_TABLE(cmd) (DB_GET_MODULE(cmd) >> DB_MODULE_SHIFT)
65 /* Device IOCtl function pointer */
67 u32(*fxn) (union trapped_args *args, void *pr_ctxt);
71 /* ----------------------------------- Globals */
72 static u32 api_c_refs;
76 * The order of these functions MUST be the same as the order of the command
77 * numbers defined in dspapi-ioctl.h This is how an IOCTL number in user mode
78 * turns into a function call in kernel mode.
81 /* MGR wrapper functions */
82 static struct api_cmd mgr_cmd[] = {
83 {mgrwrap_enum_node_info}, /* MGR_ENUMNODE_INFO */
84 {mgrwrap_enum_proc_info}, /* MGR_ENUMPROC_INFO */
85 {mgrwrap_register_object}, /* MGR_REGISTEROBJECT */
86 {mgrwrap_unregister_object}, /* MGR_UNREGISTEROBJECT */
87 {mgrwrap_wait_for_bridge_events}, /* MGR_WAIT */
88 {mgrwrap_get_process_resources_info}, /* MGR_GET_PROC_RES */
91 /* PROC wrapper functions */
92 static struct api_cmd proc_cmd[] = {
93 {procwrap_attach}, /* PROC_ATTACH */
94 {procwrap_ctrl}, /* PROC_CTRL */
95 {procwrap_detach}, /* PROC_DETACH */
96 {procwrap_enum_node_info}, /* PROC_ENUMNODE */
97 {procwrap_enum_resources}, /* PROC_ENUMRESOURCES */
98 {procwrap_get_state}, /* PROC_GET_STATE */
99 {procwrap_get_trace}, /* PROC_GET_TRACE */
100 {procwrap_load}, /* PROC_LOAD */
101 {procwrap_register_notify}, /* PROC_REGISTERNOTIFY */
102 {procwrap_start}, /* PROC_START */
103 {procwrap_reserve_memory}, /* PROC_RSVMEM */
104 {procwrap_un_reserve_memory}, /* PROC_UNRSVMEM */
105 {procwrap_map}, /* PROC_MAPMEM */
106 {procwrap_un_map}, /* PROC_UNMAPMEM */
107 {procwrap_flush_memory}, /* PROC_FLUSHMEMORY */
108 {procwrap_stop}, /* PROC_STOP */
109 {procwrap_invalidate_memory}, /* PROC_INVALIDATEMEMORY */
110 {procwrap_begin_dma}, /* PROC_BEGINDMA */
111 {procwrap_end_dma}, /* PROC_ENDDMA */
114 /* NODE wrapper functions */
115 static struct api_cmd node_cmd[] = {
116 {nodewrap_allocate}, /* NODE_ALLOCATE */
117 {nodewrap_alloc_msg_buf}, /* NODE_ALLOCMSGBUF */
118 {nodewrap_change_priority}, /* NODE_CHANGEPRIORITY */
119 {nodewrap_connect}, /* NODE_CONNECT */
120 {nodewrap_create}, /* NODE_CREATE */
121 {nodewrap_delete}, /* NODE_DELETE */
122 {nodewrap_free_msg_buf}, /* NODE_FREEMSGBUF */
123 {nodewrap_get_attr}, /* NODE_GETATTR */
124 {nodewrap_get_message}, /* NODE_GETMESSAGE */
125 {nodewrap_pause}, /* NODE_PAUSE */
126 {nodewrap_put_message}, /* NODE_PUTMESSAGE */
127 {nodewrap_register_notify}, /* NODE_REGISTERNOTIFY */
128 {nodewrap_run}, /* NODE_RUN */
129 {nodewrap_terminate}, /* NODE_TERMINATE */
130 {nodewrap_get_uuid_props}, /* NODE_GETUUIDPROPS */
133 /* STRM wrapper functions */
134 static struct api_cmd strm_cmd[] = {
135 {strmwrap_allocate_buffer}, /* STRM_ALLOCATEBUFFER */
136 {strmwrap_close}, /* STRM_CLOSE */
137 {strmwrap_free_buffer}, /* STRM_FREEBUFFER */
138 {strmwrap_get_event_handle}, /* STRM_GETEVENTHANDLE */
139 {strmwrap_get_info}, /* STRM_GETINFO */
140 {strmwrap_idle}, /* STRM_IDLE */
141 {strmwrap_issue}, /* STRM_ISSUE */
142 {strmwrap_open}, /* STRM_OPEN */
143 {strmwrap_reclaim}, /* STRM_RECLAIM */
144 {strmwrap_register_notify}, /* STRM_REGISTERNOTIFY */
145 {strmwrap_select}, /* STRM_SELECT */
148 /* CMM wrapper functions */
149 static struct api_cmd cmm_cmd[] = {
150 {cmmwrap_calloc_buf}, /* CMM_ALLOCBUF */
151 {cmmwrap_free_buf}, /* CMM_FREEBUF */
152 {cmmwrap_get_handle}, /* CMM_GETHANDLE */
153 {cmmwrap_get_info}, /* CMM_GETINFO */
156 /* Array used to store ioctl table sizes. It can hold up to 8 entries */
157 static u8 size_cmd[] = {
159 ARRAY_SIZE(proc_cmd),
160 ARRAY_SIZE(node_cmd),
161 ARRAY_SIZE(strm_cmd),
165 static inline void _cp_fm_usr(void *to, const void __user * from,
166 int *err, unsigned long bytes)
171 if (unlikely(!from)) {
176 if (unlikely(copy_from_user(to, from, bytes)))
180 #define CP_FM_USR(to, from, err, n) \
181 _cp_fm_usr(to, from, &(err), (n) * sizeof(*(to)))
183 static inline void _cp_to_usr(void __user *to, const void *from,
184 int *err, unsigned long bytes)
194 if (unlikely(copy_to_user(to, from, bytes)))
198 #define CP_TO_USR(to, from, err, n) \
199 _cp_to_usr(to, from, &(err), (n) * sizeof(*(from)))
202 * ======== api_call_dev_ioctl ========
204 * Call the (wrapper) function for the corresponding API IOCTL.
206 inline int api_call_dev_ioctl(u32 cmd, union trapped_args *args,
207 u32 *result, void *pr_ctxt)
209 u32(*ioctl_cmd) (union trapped_args *args, void *pr_ctxt) = NULL;
212 if (_IOC_TYPE(cmd) != DB) {
213 pr_err("%s: Incompatible dspbridge ioctl number\n", __func__);
217 if (DB_GET_IOC_TABLE(cmd) > ARRAY_SIZE(size_cmd)) {
218 pr_err("%s: undefined ioctl module\n", __func__);
222 /* Check the size of the required cmd table */
224 if (i > size_cmd[DB_GET_IOC_TABLE(cmd)]) {
225 pr_err("%s: requested ioctl %d out of bounds for table %d\n",
226 __func__, i, DB_GET_IOC_TABLE(cmd));
230 switch (DB_GET_MODULE(cmd)) {
232 ioctl_cmd = mgr_cmd[i].fxn;
235 ioctl_cmd = proc_cmd[i].fxn;
238 ioctl_cmd = node_cmd[i].fxn;
241 ioctl_cmd = strm_cmd[i].fxn;
244 ioctl_cmd = cmm_cmd[i].fxn;
249 pr_err("%s: requested ioctl not defined\n", __func__);
252 *result = (*ioctl_cmd) (args, pr_ctxt);
262 * ======== api_exit ========
268 if (api_c_refs == 0) {
269 /* Release all modules initialized in api_init(). */
279 * ======== api_init ========
281 * Module initialization used by Bridge API.
286 bool fdev, fchnl, fmsg, fio;
289 if (api_c_refs == 0) {
290 /* initialize driver and other modules */
293 fmsg = msg_mod_init();
296 ret = fdev && fchnl && fmsg && fio;
323 * ======== api_init_complete2 ========
325 * Perform any required bridge initialization which cannot
326 * be performed in api_init() or dev_start_device() due
327 * to the fact that some services are not yet
328 * completely initialized.
331 * 0: Allow this device to load
334 * Bridge API initialized.
337 int api_init_complete2(void)
340 struct cfg_devnode *dev_node;
341 struct dev_object *hdev_obj;
342 struct drv_data *drv_datap;
345 /* Walk the list of DevObjects, get each devnode, and attempting to
346 * autostart the board. Note that this requires COF loading, which
348 for (hdev_obj = dev_get_first(); hdev_obj != NULL;
349 hdev_obj = dev_get_next(hdev_obj)) {
350 if (dev_get_dev_node(hdev_obj, &dev_node))
353 if (dev_get_dev_type(hdev_obj, &dev_type))
356 if ((dev_type == DSP_UNIT) || (dev_type == IVA_UNIT)) {
357 drv_datap = dev_get_drvdata(bridge);
359 if (drv_datap && drv_datap->base_img)
360 proc_auto_start(dev_node, hdev_obj);
367 /* TODO: Remove deprecated and not implemented ioctl wrappers */
370 * ======== mgrwrap_enum_node_info ========
372 u32 mgrwrap_enum_node_info(union trapped_args *args, void *pr_ctxt)
377 u32 size = args->args_mgr_enumnode_info.ndb_props_size;
379 if (size < sizeof(struct dsp_ndbprops))
382 pndb_props = kmalloc(size, GFP_KERNEL);
383 if (pndb_props == NULL)
388 mgr_enum_node_info(args->args_mgr_enumnode_info.node_id,
389 (struct dsp_ndbprops *)pndb_props, size,
392 CP_TO_USR(args->args_mgr_enumnode_info.ndb_props, pndb_props, status,
394 CP_TO_USR(args->args_mgr_enumnode_info.num_nodes, &num_nodes, status,
402 * ======== mgrwrap_enum_proc_info ========
404 u32 mgrwrap_enum_proc_info(union trapped_args *args, void *pr_ctxt)
409 u32 size = args->args_mgr_enumproc_info.processor_info_size;
411 if (size < sizeof(struct dsp_processorinfo))
414 processor_info = kmalloc(size, GFP_KERNEL);
415 if (processor_info == NULL)
420 mgr_enum_processor_info(args->args_mgr_enumproc_info.
422 (struct dsp_processorinfo *)
423 processor_info, size, &num_procs);
425 CP_TO_USR(args->args_mgr_enumproc_info.processor_info, processor_info,
427 CP_TO_USR(args->args_mgr_enumproc_info.num_procs, &num_procs,
429 kfree(processor_info);
434 #define WRAP_MAP2CALLER(x) x
436 * ======== mgrwrap_register_object ========
438 u32 mgrwrap_register_object(union trapped_args *args, void *pr_ctxt)
441 struct dsp_uuid uuid_obj;
443 char *psz_path_name = NULL;
446 CP_FM_USR(&uuid_obj, args->args_mgr_registerobject.uuid_obj, status, 1);
449 /* path_size is increased by 1 to accommodate NULL */
450 path_size = strlen_user((char *)
451 args->args_mgr_registerobject.sz_path_name) +
453 psz_path_name = kmalloc(path_size, GFP_KERNEL);
454 if (!psz_path_name) {
458 ret = strncpy_from_user(psz_path_name,
459 (char *)args->args_mgr_registerobject.
460 sz_path_name, path_size);
466 if (args->args_mgr_registerobject.obj_type >= DSP_DCDMAXOBJTYPE) {
471 status = dcd_register_object(&uuid_obj,
472 args->args_mgr_registerobject.obj_type,
473 (char *)psz_path_name);
475 kfree(psz_path_name);
480 * ======== mgrwrap_unregister_object ========
482 u32 mgrwrap_unregister_object(union trapped_args *args, void *pr_ctxt)
485 struct dsp_uuid uuid_obj;
487 CP_FM_USR(&uuid_obj, args->args_mgr_registerobject.uuid_obj, status, 1);
491 status = dcd_unregister_object(&uuid_obj,
492 args->args_mgr_unregisterobject.
500 * ======== mgrwrap_wait_for_bridge_events ========
502 u32 mgrwrap_wait_for_bridge_events(union trapped_args *args, void *pr_ctxt)
505 struct dsp_notification *anotifications[MAX_EVENTS];
506 struct dsp_notification notifications[MAX_EVENTS];
508 u32 count = args->args_mgr_wait.count;
510 if (count > MAX_EVENTS)
513 /* get the array of pointers to user structures */
514 CP_FM_USR(anotifications, args->args_mgr_wait.anotifications,
517 for (i = 0; i < count; i++) {
518 CP_FM_USR(¬ifications[i], anotifications[i], status, 1);
519 if (status || !notifications[i].handle) {
523 /* set the array of pointers to kernel structures */
524 anotifications[i] = ¬ifications[i];
527 status = mgr_wait_for_bridge_events(anotifications, count,
532 CP_TO_USR(args->args_mgr_wait.index, &index, status, 1);
537 * ======== MGRWRAP_GetProcessResourceInfo ========
539 u32 __deprecated mgrwrap_get_process_resources_info(union trapped_args * args,
542 pr_err("%s: deprecated dspbridge ioctl\n", __func__);
547 * ======== procwrap_attach ========
549 u32 procwrap_attach(union trapped_args *args, void *pr_ctxt)
553 struct dsp_processorattrin proc_attr_in, *attr_in = NULL;
555 /* Optional argument */
556 if (args->args_proc_attach.attr_in) {
557 CP_FM_USR(&proc_attr_in, args->args_proc_attach.attr_in, status,
560 attr_in = &proc_attr_in;
565 status = proc_attach(args->args_proc_attach.processor_id, attr_in,
566 &processor, pr_ctxt);
567 CP_TO_USR(args->args_proc_attach.ph_processor, &processor, status, 1);
573 * ======== procwrap_ctrl ========
575 u32 procwrap_ctrl(union trapped_args *args, void *pr_ctxt)
577 u32 cb_data_size, __user * psize = (u32 __user *)
578 args->args_proc_ctrl.args;
581 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
584 if (get_user(cb_data_size, psize)) {
588 cb_data_size += sizeof(u32);
589 pargs = kmalloc(cb_data_size, GFP_KERNEL);
595 CP_FM_USR(pargs, args->args_proc_ctrl.args, status,
599 status = proc_ctrl(hprocessor,
600 args->args_proc_ctrl.cmd,
601 (struct dsp_cbdata *)pargs);
604 /* CP_TO_USR(args->args_proc_ctrl.args, pargs, status, 1); */
611 * ======== procwrap_detach ========
613 u32 __deprecated procwrap_detach(union trapped_args * args, void *pr_ctxt)
615 /* proc_detach called at bridge_release only */
616 pr_err("%s: deprecated dspbridge ioctl\n", __func__);
621 * ======== procwrap_enum_node_info ========
623 u32 procwrap_enum_node_info(union trapped_args *args, void *pr_ctxt)
626 void *node_tab[MAX_NODES];
629 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
631 if (!args->args_proc_enumnode_info.node_tab_size)
634 status = proc_enum_nodes(hprocessor,
636 args->args_proc_enumnode_info.node_tab_size,
637 &num_nodes, &alloc_cnt);
638 CP_TO_USR(args->args_proc_enumnode_info.node_tab, node_tab, status,
640 CP_TO_USR(args->args_proc_enumnode_info.num_nodes, &num_nodes,
642 CP_TO_USR(args->args_proc_enumnode_info.allocated, &alloc_cnt,
647 u32 procwrap_end_dma(union trapped_args *args, void *pr_ctxt)
651 if (args->args_proc_dma.dir >= DMA_NONE)
654 status = proc_end_dma(pr_ctxt,
655 args->args_proc_dma.mpu_addr,
656 args->args_proc_dma.size,
657 args->args_proc_dma.dir);
661 u32 procwrap_begin_dma(union trapped_args *args, void *pr_ctxt)
665 if (args->args_proc_dma.dir >= DMA_NONE)
668 status = proc_begin_dma(pr_ctxt,
669 args->args_proc_dma.mpu_addr,
670 args->args_proc_dma.size,
671 args->args_proc_dma.dir);
676 * ======== procwrap_flush_memory ========
678 u32 procwrap_flush_memory(union trapped_args *args, void *pr_ctxt)
682 if (args->args_proc_flushmemory.flags >
683 PROC_WRITEBACK_INVALIDATE_MEM)
686 status = proc_flush_memory(pr_ctxt,
687 args->args_proc_flushmemory.mpu_addr,
688 args->args_proc_flushmemory.size,
689 args->args_proc_flushmemory.flags);
694 * ======== procwrap_invalidate_memory ========
696 u32 procwrap_invalidate_memory(union trapped_args *args, void *pr_ctxt)
701 proc_invalidate_memory(pr_ctxt,
702 args->args_proc_invalidatememory.mpu_addr,
703 args->args_proc_invalidatememory.size);
708 * ======== procwrap_enum_resources ========
710 u32 procwrap_enum_resources(union trapped_args *args, void *pr_ctxt)
713 struct dsp_resourceinfo resource_info;
714 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
716 if (args->args_proc_enumresources.resource_info_size <
717 sizeof(struct dsp_resourceinfo))
721 proc_get_resource_info(hprocessor,
722 args->args_proc_enumresources.resource_type,
724 args->args_proc_enumresources.
727 CP_TO_USR(args->args_proc_enumresources.resource_info, &resource_info,
735 * ======== procwrap_get_state ========
737 u32 procwrap_get_state(union trapped_args *args, void *pr_ctxt)
740 struct dsp_processorstate proc_state;
741 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
743 if (args->args_proc_getstate.state_info_size <
744 sizeof(struct dsp_processorstate))
747 status = proc_get_state(hprocessor, &proc_state,
748 args->args_proc_getstate.state_info_size);
749 CP_TO_USR(args->args_proc_getstate.proc_state_obj, &proc_state, status,
756 * ======== procwrap_get_trace ========
758 u32 procwrap_get_trace(union trapped_args *args, void *pr_ctxt)
762 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
764 if (args->args_proc_gettrace.max_size > MAX_TRACEBUFLEN)
767 pbuf = kzalloc(args->args_proc_gettrace.max_size, GFP_KERNEL);
769 status = proc_get_trace(hprocessor, pbuf,
770 args->args_proc_gettrace.max_size);
774 CP_TO_USR(args->args_proc_gettrace.buf, pbuf, status,
775 args->args_proc_gettrace.max_size);
782 * ======== procwrap_load ========
784 u32 procwrap_load(union trapped_args *args, void *pr_ctxt)
789 s32 count = args->args_proc_load.argc_index;
790 u8 **argv = NULL, **envp = NULL;
791 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
793 if (count <= 0 || count > MAX_LOADARGS) {
798 argv = kmalloc(count * sizeof(u8 *), GFP_KERNEL);
804 CP_FM_USR(argv, args->args_proc_load.user_args, status, count);
811 for (i = 0; i < count; i++) {
813 /* User space pointer to argument */
814 temp = (char *)argv[i];
815 /* len is increased by 1 to accommodate NULL */
816 len = strlen_user((char *)temp) + 1;
817 /* Kernel space pointer to argument */
818 argv[i] = kmalloc(len, GFP_KERNEL);
820 CP_FM_USR(argv[i], temp, status, len);
832 /* TODO: validate this */
833 if (args->args_proc_load.user_envp) {
834 /* number of elements in the envp array including NULL */
838 args->args_proc_load.user_envp + count)) {
844 envp = kmalloc(count * sizeof(u8 *), GFP_KERNEL);
850 CP_FM_USR(envp, args->args_proc_load.user_envp, status, count);
856 for (i = 0; envp[i]; i++) {
857 /* User space pointer to argument */
858 temp = (char *)envp[i];
859 /* len is increased by 1 to accommodate NULL */
860 len = strlen_user((char *)temp) + 1;
861 /* Kernel space pointer to argument */
862 envp[i] = kmalloc(len, GFP_KERNEL);
864 CP_FM_USR(envp[i], temp, status, len);
878 status = proc_load(hprocessor,
879 args->args_proc_load.argc_index,
880 (const char **)argv, (const char **)envp);
892 count = args->args_proc_load.argc_index;
893 for (i = 0; (i < count) && argv[i]; i++)
903 * ======== procwrap_map ========
905 u32 procwrap_map(union trapped_args *args, void *pr_ctxt)
909 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
911 if (!args->args_proc_mapmem.size)
914 status = proc_map(args->args_proc_mapmem.processor,
915 args->args_proc_mapmem.mpu_addr,
916 args->args_proc_mapmem.size,
917 args->args_proc_mapmem.req_addr, &map_addr,
918 args->args_proc_mapmem.map_attr, pr_ctxt);
920 if (put_user(map_addr, args->args_proc_mapmem.map_addr)) {
922 proc_un_map(hprocessor, map_addr, pr_ctxt);
930 * ======== procwrap_register_notify ========
932 u32 procwrap_register_notify(union trapped_args *args, void *pr_ctxt)
935 struct dsp_notification notification;
936 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
938 /* Initialize the notification data structure */
939 notification.name = NULL;
940 notification.handle = NULL;
942 status = proc_register_notify(hprocessor,
943 args->args_proc_register_notify.event_mask,
944 args->args_proc_register_notify.notify_type,
946 CP_TO_USR(args->args_proc_register_notify.notification, ¬ification,
952 * ======== procwrap_reserve_memory ========
954 u32 procwrap_reserve_memory(union trapped_args *args, void *pr_ctxt)
958 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
960 if ((args->args_proc_rsvmem.size <= 0) ||
961 (args->args_proc_rsvmem.size & (PG_SIZE4K - 1)) != 0)
964 status = proc_reserve_memory(hprocessor,
965 args->args_proc_rsvmem.size, &prsv_addr,
968 if (put_user(prsv_addr, args->args_proc_rsvmem.rsv_addr)) {
970 proc_un_reserve_memory(args->args_proc_rsvmem.
971 processor, prsv_addr, pr_ctxt);
978 * ======== procwrap_start ========
980 u32 procwrap_start(union trapped_args *args, void *pr_ctxt)
984 ret = proc_start(((struct process_context *)pr_ctxt)->processor);
989 * ======== procwrap_un_map ========
991 u32 procwrap_un_map(union trapped_args *args, void *pr_ctxt)
995 status = proc_un_map(((struct process_context *)pr_ctxt)->processor,
996 args->args_proc_unmapmem.map_addr, pr_ctxt);
1001 * ======== procwrap_un_reserve_memory ========
1003 u32 procwrap_un_reserve_memory(union trapped_args *args, void *pr_ctxt)
1006 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
1008 status = proc_un_reserve_memory(hprocessor,
1009 args->args_proc_unrsvmem.rsv_addr,
1015 * ======== procwrap_stop ========
1017 u32 procwrap_stop(union trapped_args *args, void *pr_ctxt)
1021 ret = proc_stop(((struct process_context *)pr_ctxt)->processor);
1027 * ======== find_handle =========
1029 inline void find_node_handle(struct node_res_object **noderes,
1030 void *pr_ctxt, void *hnode)
1033 *noderes = idr_find(((struct process_context *)pr_ctxt)->node_id,
1041 * ======== nodewrap_allocate ========
1043 u32 nodewrap_allocate(union trapped_args *args, void *pr_ctxt)
1046 struct dsp_uuid node_uuid;
1047 u32 cb_data_size = 0;
1048 u32 __user *psize = (u32 __user *) args->args_node_allocate.args;
1050 struct dsp_nodeattrin proc_attr_in, *attr_in = NULL;
1051 struct node_res_object *node_res;
1053 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
1055 /* Optional argument */
1057 if (get_user(cb_data_size, psize))
1060 cb_data_size += sizeof(u32);
1062 pargs = kmalloc(cb_data_size, GFP_KERNEL);
1067 CP_FM_USR(pargs, args->args_node_allocate.args, status,
1070 CP_FM_USR(&node_uuid, args->args_node_allocate.node_id_ptr, status, 1);
1073 /* Optional argument */
1074 if (args->args_node_allocate.attr_in) {
1075 CP_FM_USR(&proc_attr_in, args->args_node_allocate.attr_in,
1078 attr_in = &proc_attr_in;
1084 status = node_allocate(hprocessor,
1085 &node_uuid, (struct dsp_cbdata *)pargs,
1086 attr_in, &node_res, pr_ctxt);
1089 nodeid = node_res->id + 1;
1090 CP_TO_USR(args->args_node_allocate.node, &nodeid,
1094 node_delete(node_res, pr_ctxt);
1104 * ======== nodewrap_alloc_msg_buf ========
1106 u32 nodewrap_alloc_msg_buf(union trapped_args *args, void *pr_ctxt)
1109 struct dsp_bufferattr *pattr = NULL;
1110 struct dsp_bufferattr attr;
1112 struct node_res_object *node_res;
1114 find_node_handle(&node_res, pr_ctxt,
1115 args->args_node_allocmsgbuf.node);
1120 if (!args->args_node_allocmsgbuf.size)
1123 if (args->args_node_allocmsgbuf.attr) { /* Optional argument */
1124 CP_FM_USR(&attr, args->args_node_allocmsgbuf.attr, status, 1);
1130 CP_FM_USR(&pbuffer, args->args_node_allocmsgbuf.buffer, status, 1);
1132 status = node_alloc_msg_buf(node_res->node,
1133 args->args_node_allocmsgbuf.size,
1136 CP_TO_USR(args->args_node_allocmsgbuf.buffer, &pbuffer, status, 1);
1141 * ======== nodewrap_change_priority ========
1143 u32 nodewrap_change_priority(union trapped_args *args, void *pr_ctxt)
1146 struct node_res_object *node_res;
1148 find_node_handle(&node_res, pr_ctxt,
1149 args->args_node_changepriority.node);
1154 ret = node_change_priority(node_res->node,
1155 args->args_node_changepriority.prio);
1161 * ======== nodewrap_connect ========
1163 u32 nodewrap_connect(union trapped_args *args, void *pr_ctxt)
1166 struct dsp_strmattr attrs;
1167 struct dsp_strmattr *pattrs = NULL;
1169 u32 __user *psize = (u32 __user *) args->args_node_connect.conn_param;
1171 struct node_res_object *node_res1, *node_res2;
1172 struct node_object *node1 = NULL, *node2 = NULL;
1174 if ((int)args->args_node_connect.node != DSP_HGPPNODE) {
1175 find_node_handle(&node_res1, pr_ctxt,
1176 args->args_node_connect.node);
1178 node1 = node_res1->node;
1180 node1 = args->args_node_connect.node;
1183 if ((int)args->args_node_connect.other_node != DSP_HGPPNODE) {
1184 find_node_handle(&node_res2, pr_ctxt,
1185 args->args_node_connect.other_node);
1187 node2 = node_res2->node;
1189 node2 = args->args_node_connect.other_node;
1192 if (!node1 || !node2)
1195 /* Optional argument */
1197 if (get_user(cb_data_size, psize))
1200 cb_data_size += sizeof(u32);
1202 pargs = kmalloc(cb_data_size, GFP_KERNEL);
1203 if (pargs == NULL) {
1209 CP_FM_USR(pargs, args->args_node_connect.conn_param, status,
1214 if (args->args_node_connect.attrs) { /* Optional argument */
1215 CP_FM_USR(&attrs, args->args_node_connect.attrs, status, 1);
1221 status = node_connect(node1,
1222 args->args_node_connect.stream_id,
1224 args->args_node_connect.other_stream,
1225 pattrs, (struct dsp_cbdata *)pargs);
1234 * ======== nodewrap_create ========
1236 u32 nodewrap_create(union trapped_args *args, void *pr_ctxt)
1239 struct node_res_object *node_res;
1241 find_node_handle(&node_res, pr_ctxt, args->args_node_create.node);
1246 ret = node_create(node_res->node);
1252 * ======== nodewrap_delete ========
1254 u32 nodewrap_delete(union trapped_args *args, void *pr_ctxt)
1257 struct node_res_object *node_res;
1259 find_node_handle(&node_res, pr_ctxt, args->args_node_delete.node);
1264 ret = node_delete(node_res, pr_ctxt);
1270 * ======== nodewrap_free_msg_buf ========
1272 u32 nodewrap_free_msg_buf(union trapped_args *args, void *pr_ctxt)
1275 struct dsp_bufferattr *pattr = NULL;
1276 struct dsp_bufferattr attr;
1277 struct node_res_object *node_res;
1279 find_node_handle(&node_res, pr_ctxt, args->args_node_freemsgbuf.node);
1284 if (args->args_node_freemsgbuf.attr) { /* Optional argument */
1285 CP_FM_USR(&attr, args->args_node_freemsgbuf.attr, status, 1);
1291 if (!args->args_node_freemsgbuf.buffer)
1295 status = node_free_msg_buf(node_res->node,
1296 args->args_node_freemsgbuf.buffer,
1304 * ======== nodewrap_get_attr ========
1306 u32 nodewrap_get_attr(union trapped_args *args, void *pr_ctxt)
1309 struct dsp_nodeattr attr;
1310 struct node_res_object *node_res;
1312 find_node_handle(&node_res, pr_ctxt, args->args_node_getattr.node);
1317 status = node_get_attr(node_res->node, &attr,
1318 args->args_node_getattr.attr_size);
1319 CP_TO_USR(args->args_node_getattr.attr, &attr, status, 1);
1325 * ======== nodewrap_get_message ========
1327 u32 nodewrap_get_message(union trapped_args *args, void *pr_ctxt)
1331 struct node_res_object *node_res;
1333 find_node_handle(&node_res, pr_ctxt, args->args_node_getmessage.node);
1338 status = node_get_message(node_res->node, &msg,
1339 args->args_node_getmessage.timeout);
1341 CP_TO_USR(args->args_node_getmessage.message, &msg, status, 1);
1347 * ======== nodewrap_pause ========
1349 u32 nodewrap_pause(union trapped_args *args, void *pr_ctxt)
1352 struct node_res_object *node_res;
1354 find_node_handle(&node_res, pr_ctxt, args->args_node_pause.node);
1359 ret = node_pause(node_res->node);
1365 * ======== nodewrap_put_message ========
1367 u32 nodewrap_put_message(union trapped_args *args, void *pr_ctxt)
1371 struct node_res_object *node_res;
1373 find_node_handle(&node_res, pr_ctxt, args->args_node_putmessage.node);
1378 CP_FM_USR(&msg, args->args_node_putmessage.message, status, 1);
1382 node_put_message(node_res->node, &msg,
1383 args->args_node_putmessage.timeout);
1390 * ======== nodewrap_register_notify ========
1392 u32 nodewrap_register_notify(union trapped_args *args, void *pr_ctxt)
1395 struct dsp_notification notification;
1396 struct node_res_object *node_res;
1398 find_node_handle(&node_res, pr_ctxt,
1399 args->args_node_registernotify.node);
1404 /* Initialize the notification data structure */
1405 notification.name = NULL;
1406 notification.handle = NULL;
1408 if (!args->args_proc_register_notify.event_mask)
1409 CP_FM_USR(¬ification,
1410 args->args_proc_register_notify.notification,
1413 status = node_register_notify(node_res->node,
1414 args->args_node_registernotify.event_mask,
1415 args->args_node_registernotify.
1416 notify_type, ¬ification);
1417 CP_TO_USR(args->args_node_registernotify.notification, ¬ification,
1423 * ======== nodewrap_run ========
1425 u32 nodewrap_run(union trapped_args *args, void *pr_ctxt)
1428 struct node_res_object *node_res;
1430 find_node_handle(&node_res, pr_ctxt, args->args_node_run.node);
1435 ret = node_run(node_res->node);
1441 * ======== nodewrap_terminate ========
1443 u32 nodewrap_terminate(union trapped_args *args, void *pr_ctxt)
1447 struct node_res_object *node_res;
1449 find_node_handle(&node_res, pr_ctxt, args->args_node_terminate.node);
1454 status = node_terminate(node_res->node, &tempstatus);
1456 CP_TO_USR(args->args_node_terminate.status, &tempstatus, status, 1);
1462 * ======== nodewrap_get_uuid_props ========
1464 u32 nodewrap_get_uuid_props(union trapped_args *args, void *pr_ctxt)
1467 struct dsp_uuid node_uuid;
1468 struct dsp_ndbprops *pnode_props = NULL;
1469 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
1471 CP_FM_USR(&node_uuid, args->args_node_getuuidprops.node_id_ptr, status,
1475 pnode_props = kmalloc(sizeof(struct dsp_ndbprops), GFP_KERNEL);
1476 if (pnode_props != NULL) {
1478 node_get_uuid_props(hprocessor, &node_uuid, pnode_props);
1479 CP_TO_USR(args->args_node_getuuidprops.node_props, pnode_props,
1489 * ======== find_strm_handle =========
1491 inline void find_strm_handle(struct strm_res_object **strmres,
1492 void *pr_ctxt, void *hstream)
1495 *strmres = idr_find(((struct process_context *)pr_ctxt)->stream_id,
1502 * ======== strmwrap_allocate_buffer ========
1504 u32 strmwrap_allocate_buffer(union trapped_args *args, void *pr_ctxt)
1507 u8 **ap_buffer = NULL;
1508 u32 num_bufs = args->args_strm_allocatebuffer.num_bufs;
1509 struct strm_res_object *strm_res;
1511 find_strm_handle(&strm_res, pr_ctxt,
1512 args->args_strm_allocatebuffer.stream);
1517 if (num_bufs > MAX_BUFS)
1520 ap_buffer = kmalloc((num_bufs * sizeof(u8 *)), GFP_KERNEL);
1521 if (ap_buffer == NULL)
1524 status = strm_allocate_buffer(strm_res,
1525 args->args_strm_allocatebuffer.size,
1526 ap_buffer, num_bufs, pr_ctxt);
1528 CP_TO_USR(args->args_strm_allocatebuffer.ap_buffer, ap_buffer,
1532 strm_free_buffer(strm_res,
1533 ap_buffer, num_bufs, pr_ctxt);
1542 * ======== strmwrap_close ========
1544 u32 strmwrap_close(union trapped_args *args, void *pr_ctxt)
1546 struct strm_res_object *strm_res;
1548 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_close.stream);
1553 return strm_close(strm_res, pr_ctxt);
1557 * ======== strmwrap_free_buffer ========
1559 u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt)
1562 u8 **ap_buffer = NULL;
1563 u32 num_bufs = args->args_strm_freebuffer.num_bufs;
1564 struct strm_res_object *strm_res;
1566 find_strm_handle(&strm_res, pr_ctxt,
1567 args->args_strm_freebuffer.stream);
1572 if (num_bufs > MAX_BUFS)
1575 ap_buffer = kmalloc((num_bufs * sizeof(u8 *)), GFP_KERNEL);
1576 if (ap_buffer == NULL)
1579 CP_FM_USR(ap_buffer, args->args_strm_freebuffer.ap_buffer, status,
1583 status = strm_free_buffer(strm_res,
1584 ap_buffer, num_bufs, pr_ctxt);
1586 CP_TO_USR(args->args_strm_freebuffer.ap_buffer, ap_buffer, status,
1594 * ======== strmwrap_get_event_handle ========
1596 u32 __deprecated strmwrap_get_event_handle(union trapped_args * args,
1599 pr_err("%s: deprecated dspbridge ioctl\n", __func__);
1604 * ======== strmwrap_get_info ========
1606 u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
1609 struct stream_info strm_info;
1610 struct dsp_streaminfo user;
1611 struct dsp_streaminfo *temp;
1612 struct strm_res_object *strm_res;
1614 find_strm_handle(&strm_res, pr_ctxt,
1615 args->args_strm_getinfo.stream);
1620 CP_FM_USR(&strm_info, args->args_strm_getinfo.stream_info, status, 1);
1621 temp = strm_info.user_strm;
1623 strm_info.user_strm = &user;
1626 status = strm_get_info(strm_res->stream,
1628 args->args_strm_getinfo.
1631 CP_TO_USR(temp, strm_info.user_strm, status, 1);
1632 strm_info.user_strm = temp;
1633 CP_TO_USR(args->args_strm_getinfo.stream_info, &strm_info, status, 1);
1638 * ======== strmwrap_idle ========
1640 u32 strmwrap_idle(union trapped_args *args, void *pr_ctxt)
1643 struct strm_res_object *strm_res;
1645 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_idle.stream);
1650 ret = strm_idle(strm_res->stream, args->args_strm_idle.flush_flag);
1656 * ======== strmwrap_issue ========
1658 u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt)
1661 struct strm_res_object *strm_res;
1663 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_issue.stream);
1668 if (!args->args_strm_issue.buffer)
1671 /* No need of doing CP_FM_USR for the user buffer (pbuffer)
1672 as this is done in Bridge internal function bridge_chnl_add_io_req
1674 status = strm_issue(strm_res->stream,
1675 args->args_strm_issue.buffer,
1676 args->args_strm_issue.bytes,
1677 args->args_strm_issue.buf_size,
1678 args->args_strm_issue.arg);
1684 * ======== strmwrap_open ========
1686 u32 strmwrap_open(union trapped_args *args, void *pr_ctxt)
1689 struct strm_attr attr;
1690 struct strm_res_object *strm_res_obj;
1691 struct dsp_streamattrin strm_attr_in;
1692 struct node_res_object *node_res;
1695 find_node_handle(&node_res, pr_ctxt, args->args_strm_open.node);
1700 CP_FM_USR(&attr, args->args_strm_open.attr_in, status, 1);
1702 if (attr.stream_attr_in != NULL) { /* Optional argument */
1703 CP_FM_USR(&strm_attr_in, attr.stream_attr_in, status, 1);
1705 attr.stream_attr_in = &strm_attr_in;
1706 if (attr.stream_attr_in->strm_mode == STRMMODE_LDMA)
1711 status = strm_open(node_res->node,
1712 args->args_strm_open.direction,
1713 args->args_strm_open.index, &attr, &strm_res_obj,
1716 strmid = strm_res_obj->id + 1;
1717 CP_TO_USR(args->args_strm_open.stream, &strmid, status, 1);
1723 * ======== strmwrap_reclaim ========
1725 u32 strmwrap_reclaim(union trapped_args *args, void *pr_ctxt)
1732 struct strm_res_object *strm_res;
1734 find_strm_handle(&strm_res, pr_ctxt, args->args_strm_reclaim.stream);
1739 status = strm_reclaim(strm_res->stream, &buf_ptr,
1740 &ul_bytes, &ul_buf_size, &dw_arg);
1741 CP_TO_USR(args->args_strm_reclaim.buf_ptr, &buf_ptr, status, 1);
1742 CP_TO_USR(args->args_strm_reclaim.bytes, &ul_bytes, status, 1);
1743 CP_TO_USR(args->args_strm_reclaim.arg, &dw_arg, status, 1);
1745 if (args->args_strm_reclaim.buf_size_ptr != NULL) {
1746 CP_TO_USR(args->args_strm_reclaim.buf_size_ptr, &ul_buf_size,
1754 * ======== strmwrap_register_notify ========
1756 u32 strmwrap_register_notify(union trapped_args *args, void *pr_ctxt)
1759 struct dsp_notification notification;
1760 struct strm_res_object *strm_res;
1762 find_strm_handle(&strm_res, pr_ctxt,
1763 args->args_strm_registernotify.stream);
1768 /* Initialize the notification data structure */
1769 notification.name = NULL;
1770 notification.handle = NULL;
1772 status = strm_register_notify(strm_res->stream,
1773 args->args_strm_registernotify.event_mask,
1774 args->args_strm_registernotify.
1775 notify_type, ¬ification);
1776 CP_TO_USR(args->args_strm_registernotify.notification, ¬ification,
1783 * ======== strmwrap_select ========
1785 u32 strmwrap_select(union trapped_args *args, void *pr_ctxt)
1788 struct strm_object *strm_tab[MAX_STREAMS];
1790 struct strm_res_object *strm_res;
1791 int *ids[MAX_STREAMS];
1794 if (args->args_strm_select.strm_num > MAX_STREAMS)
1797 CP_FM_USR(ids, args->args_strm_select.stream_tab, status,
1798 args->args_strm_select.strm_num);
1803 for (i = 0; i < args->args_strm_select.strm_num; i++) {
1804 find_strm_handle(&strm_res, pr_ctxt, ids[i]);
1809 strm_tab[i] = strm_res->stream;
1813 status = strm_select(strm_tab, args->args_strm_select.strm_num,
1814 &mask, args->args_strm_select.timeout);
1816 CP_TO_USR(args->args_strm_select.mask, &mask, status, 1);
1823 * ======== cmmwrap_calloc_buf ========
1825 u32 __deprecated cmmwrap_calloc_buf(union trapped_args * args, void *pr_ctxt)
1827 /* This operation is done in kernel */
1828 pr_err("%s: deprecated dspbridge ioctl\n", __func__);
1833 * ======== cmmwrap_free_buf ========
1835 u32 __deprecated cmmwrap_free_buf(union trapped_args * args, void *pr_ctxt)
1837 /* This operation is done in kernel */
1838 pr_err("%s: deprecated dspbridge ioctl\n", __func__);
1843 * ======== cmmwrap_get_handle ========
1845 u32 cmmwrap_get_handle(union trapped_args *args, void *pr_ctxt)
1848 struct cmm_object *hcmm_mgr;
1849 void *hprocessor = ((struct process_context *)pr_ctxt)->processor;
1851 status = cmm_get_handle(hprocessor, &hcmm_mgr);
1853 CP_TO_USR(args->args_cmm_gethandle.cmm_mgr, &hcmm_mgr, status, 1);
1859 * ======== cmmwrap_get_info ========
1861 u32 cmmwrap_get_info(union trapped_args *args, void *pr_ctxt)
1864 struct cmm_info cmm_info_obj;
1866 status = cmm_get_info(args->args_cmm_getinfo.cmm_mgr, &cmm_info_obj);
1868 CP_TO_USR(args->args_cmm_getinfo.cmm_info_obj, &cmm_info_obj, status,