u32 strmwrap_register_notify(union trapped_args *args, void *pr_ctxt)
{
    int status = 0;
    struct dsp_notification notification;
    struct strm_res_object *strm_res;

    find_strm_handle(&strm_res, pr_ctxt,
                     args->args_strm_registernotify.stream);

    if (!strm_res)
        return -EFAULT;


    notification.name = NULL;
    notification.handle = NULL;

    status = strm_register_notify(strm_res->stream,
                                  args->args_strm_registernotify.event_mask,
                                  args->args_strm_registernotify.
                                  notify_type, &notification);
    CP_TO_USR(args->args_strm_registernotify.notification, &notification,
              status, 1);

    return status;
}
u32 strmwrap_select(union trapped_args *args, void *pr_ctxt)
{
    u32 mask;
    struct strm_object *strm_tab[MAX_STREAMS];
    int status = 0;
    struct strm_res_object *strm_res;
    int *ids[MAX_STREAMS];
    int i;

    if (args->args_strm_select.strm_num > MAX_STREAMS)
        return -EINVAL;

    CP_FM_USR(ids, args->args_strm_select.stream_tab, status,
              args->args_strm_select.strm_num);

    if (status)
        return status;

    for (i = 0; i < args->args_strm_select.strm_num; i++) {
        find_strm_handle(&strm_res, pr_ctxt, ids[i]);

        if (!strm_res)
            return -EFAULT;

        strm_tab[i] = strm_res->stream;
    }

    if (!status) {
        status = strm_select(strm_tab, args->args_strm_select.strm_num,
                             &mask, args->args_strm_select.timeout);
    }
    CP_TO_USR(args->args_strm_select.mask, &mask, status, 1);
    return status;
}
u32 strmwrap_get_info(union trapped_args *args, void *pr_ctxt)
{
    int status = 0;
    struct stream_info strm_info;
    struct dsp_streaminfo user;
    struct dsp_streaminfo *temp;
    struct strm_res_object *strm_res;

    find_strm_handle(&strm_res, pr_ctxt,
                     args->args_strm_getinfo.stream);

    if (!strm_res)
        return -EFAULT;

    CP_FM_USR(&strm_info, args->args_strm_getinfo.stream_info, status, 1);
    temp = strm_info.user_strm;

    strm_info.user_strm = &user;

    if (!status) {
        status = strm_get_info(strm_res->stream,
                               &strm_info,
                               args->args_strm_getinfo.
                               stream_info_size);
    }
    CP_TO_USR(temp, strm_info.user_strm, status, 1);
    strm_info.user_strm = temp;
    CP_TO_USR(args->args_strm_getinfo.stream_info, &strm_info, status, 1);
    return status;
}
u32 strmwrap_reclaim(union trapped_args *args, void *pr_ctxt)
{
    int status = 0;
    u8 *buf_ptr;
    u32 ul_bytes;
    u32 dw_arg;
    u32 ul_buf_size;
    struct strm_res_object *strm_res;

    find_strm_handle(&strm_res, pr_ctxt, args->args_strm_reclaim.stream);

    if (!strm_res)
        return -EFAULT;

    status = strm_reclaim(strm_res->stream, &buf_ptr,
                          &ul_bytes, &ul_buf_size, &dw_arg);
    CP_TO_USR(args->args_strm_reclaim.buf_ptr, &buf_ptr, status, 1);
    CP_TO_USR(args->args_strm_reclaim.bytes, &ul_bytes, status, 1);
    CP_TO_USR(args->args_strm_reclaim.arg, &dw_arg, status, 1);

    if (args->args_strm_reclaim.buf_size_ptr != NULL) {
        CP_TO_USR(args->args_strm_reclaim.buf_size_ptr, &ul_buf_size,
                  status, 1);
    }

    return status;
}
u32 strmwrap_free_buffer(union trapped_args *args, void *pr_ctxt)
{
    int status = 0;
    u8 **ap_buffer = NULL;
    u32 num_bufs = args->args_strm_freebuffer.num_bufs;
    struct strm_res_object *strm_res;

    find_strm_handle(&strm_res, pr_ctxt,
                     args->args_strm_freebuffer.stream);

    if (!strm_res)
        return -EFAULT;

    if (num_bufs > MAX_BUFS)
        return -EINVAL;

    ap_buffer = kmalloc((num_bufs * sizeof(u8 *)), GFP_KERNEL);
    if (ap_buffer == NULL)
        return -ENOMEM;

    CP_FM_USR(ap_buffer, args->args_strm_freebuffer.ap_buffer, status,
              num_bufs);

    if (!status)
        status = strm_free_buffer(strm_res,
                                  ap_buffer, num_bufs, pr_ctxt);

    CP_TO_USR(args->args_strm_freebuffer.ap_buffer, ap_buffer, status,
              num_bufs);
    kfree(ap_buffer);

    return status;
}
u32 strmwrap_close(union trapped_args *args, void *pr_ctxt)
{
    struct strm_res_object *strm_res;

    find_strm_handle(&strm_res, pr_ctxt, args->args_strm_close.stream);

    if (!strm_res)
        return -EFAULT;

    return strm_close(strm_res, pr_ctxt);
}
u32 strmwrap_idle(union trapped_args *args, void *pr_ctxt)
{
    u32 ret;
    struct strm_res_object *strm_res;

    find_strm_handle(&strm_res, pr_ctxt, args->args_strm_idle.stream);

    if (!strm_res)
        return -EFAULT;

    ret = strm_idle(strm_res->stream, args->args_strm_idle.flush_flag);

    return ret;
}
u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt)
{
    int status = 0;
    struct strm_res_object *strm_res;

    find_strm_handle(&strm_res, pr_ctxt, args->args_strm_issue.stream);

    if (!strm_res)
        return -EFAULT;

    if (!args->args_strm_issue.buffer)
        return -EFAULT;

    status = strm_issue(strm_res->stream,
                        args->args_strm_issue.buffer,
                        args->args_strm_issue.bytes,
                        args->args_strm_issue.buf_size,
                        args->args_strm_issue.arg);

    return status;
}
/*
 * ======== strmwrap_issue ========
 */
u32 strmwrap_issue(union trapped_args *args, void *pr_ctxt)
{
	int status = 0;
	struct strm_res_object *strm_res;

	find_strm_handle(&strm_res, pr_ctxt, args->args_strm_issue.stream);

	if (!strm_res)
		return -EFAULT;

	if (!args->args_strm_issue.buffer)
		return -EFAULT;

	/* No need of doing CP_FM_USR for the user buffer (pbuffer)
	   as this is done in Bridge internal function bridge_chnl_add_io_req
	   in chnl_sm.c */
	status = strm_issue(strm_res->stream,
			    args->args_strm_issue.buffer,
			    args->args_strm_issue.bytes,
			    args->args_strm_issue.buf_size,
			    args->args_strm_issue.arg);

	return status;
}