blob: 06425b340b459c36203ac733b3b34879f93a9dd5 [file] [log] [blame]
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +01001/*
2 * Copyright (c) 2016, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Intel Corporation nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
29 * Keyon Jie <yang.jie@linux.intel.com>
30 */
31
32#ifndef __INCLUDE_IPC_H__
33#define __INCLUDE_IPC_H__
34
35#include <stdint.h>
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050036#include <sof/trace.h>
37#include <sof/dai.h>
38#include <sof/lock.h>
Liam Girdwood425aa5e2017-06-06 20:34:10 +010039#include <platform/platform.h>
40#include <uapi/ipc.h>
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050041#include <sof/audio/pipeline.h>
42#include <sof/audio/component.h>
43#include <sof/dma-trace.h>
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010044
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -050045struct sof;
Liam Girdwood3488cce2017-08-10 11:59:08 +010046struct dai_config;
Liam Girdwood69222cf2017-06-06 16:41:07 +010047
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010048#define trace_ipc(__e) trace_event(TRACE_CLASS_IPC, __e)
49#define tracev_ipc(__e) tracev_event(TRACE_CLASS_IPC, __e)
50#define trace_ipc_error(__e) trace_error(TRACE_CLASS_IPC, __e)
51
Liam Girdwood425aa5e2017-06-06 20:34:10 +010052#define MSG_QUEUE_SIZE 12
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010053
Liam Girdwood3488cce2017-08-10 11:59:08 +010054#define COMP_TYPE_COMPONENT 1
55#define COMP_TYPE_BUFFER 2
56#define COMP_TYPE_PIPELINE 3
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010057
58/* IPC generic component device */
59struct ipc_comp_dev {
Liam Girdwood3488cce2017-08-10 11:59:08 +010060 uint16_t type; /* COMP_TYPE_ */
Liam Girdwood425aa5e2017-06-06 20:34:10 +010061 uint16_t state;
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010062
Liam Girdwood3488cce2017-08-10 11:59:08 +010063 /* component type data */
64 union {
65 struct comp_dev *cd;
66 struct comp_buffer *cb;
67 struct pipeline *pipeline;
68 };
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010069
Liam Girdwood425aa5e2017-06-06 20:34:10 +010070 /* lists */
71 struct list_item list; /* list in components */
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010072};
73
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010074struct ipc_msg {
75 uint32_t header; /* specific to platform */
76 uint32_t tx_size; /* payload size in bytes */
Liam Girdwood425aa5e2017-06-06 20:34:10 +010077 uint8_t tx_data[SOF_IPC_MSG_MAX_SIZE]; /* pointer to payload data */
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010078 uint32_t rx_size; /* payload size in bytes */
Liam Girdwood425aa5e2017-06-06 20:34:10 +010079 uint8_t rx_data[SOF_IPC_MSG_MAX_SIZE]; /* pointer to payload data */
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010080 struct list_item list;
81 void (*cb)(void *cb_data, void *mailbox_data);
82 void *cb_data;
83};
84
85struct ipc {
86 /* messaging */
87 uint32_t host_msg; /* current message from host */
88 struct ipc_msg *dsp_msg; /* current message to host */
89 uint32_t host_pending;
90 uint32_t dsp_pending;
91 struct list_item msg_list;
92 struct list_item empty_list;
93 spinlock_t lock;
94 struct ipc_msg message[MSG_QUEUE_SIZE];
Liam Girdwood425aa5e2017-06-06 20:34:10 +010095 void *comp_data;
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +010096
97 /* RX call back */
98 int (*cb)(struct ipc_msg *msg);
99
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100100 /* pipelines, components and buffers */
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100101 struct list_item comp_list; /* list of component devices */
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100102
Yan Wangfc6820e2017-09-18 11:23:55 +0800103 /* DMA for Trace*/
Liam Girdwood36e425e2018-02-25 20:33:22 +0000104 struct dma_trace_data *dmat;
Yan Wangfc6820e2017-09-18 11:23:55 +0800105
Pan Xiulie92ef972018-03-02 17:20:27 +0800106 /* mmap for posn_offset */
107 struct pipeline *posn_map[PLATFORM_MAX_STREAMS];
108
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100109 void *private;
110};
111
112#define ipc_set_drvdata(ipc, data) \
113 (ipc)->private = data
114#define ipc_get_drvdata(ipc) \
115 (ipc)->private;
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100116
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100117
Pierre-Louis Bossart81708a52018-04-04 18:46:50 -0500118int ipc_init(struct sof *sof);
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100119int platform_ipc_init(struct ipc *ipc);
120void ipc_free(struct ipc *ipc);
121
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100122int ipc_process_msg_queue(void);
123
Liam Girdwood14dee1a2017-08-15 16:18:19 +0100124int ipc_stream_send_position(struct comp_dev *cdev,
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100125 struct sof_ipc_stream_posn *posn);
Liam Girdwooda1da5bc2017-08-22 22:31:04 +0100126int ipc_stream_send_xrun(struct comp_dev *cdev,
127 struct sof_ipc_stream_posn *posn);
128
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100129int ipc_queue_host_message(struct ipc *ipc, uint32_t header,
130 void *tx_data, size_t tx_bytes, void *rx_data,
Yan Wang1611a0a2017-12-07 15:34:40 +0800131 size_t rx_bytes, void (*cb)(void*, void*), void *cb_data, uint32_t replace);
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100132int ipc_send_short_msg(uint32_t msg);
133
134void ipc_platform_do_cmd(struct ipc *ipc);
135void ipc_platform_send_msg(struct ipc *ipc);
136
Liam Girdwood78e7f302018-04-11 16:53:02 +0100137/* create a SG page table eme list from a compressed page table */
138int ipc_parse_page_descriptors(uint8_t *page_table,
139 struct sof_ipc_host_buffer *ring,
140 struct list_item *elem_list,
141 uint32_t direction);
142int ipc_get_page_descriptors(struct dma *dmac, uint8_t *page_table,
143 struct sof_ipc_host_buffer *ring);
144
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100145/*
146 * IPC Component creation and destruction.
147 */
148int ipc_comp_new(struct ipc *ipc, struct sof_ipc_comp *new);
Liam Girdwood3488cce2017-08-10 11:59:08 +0100149int ipc_comp_free(struct ipc *ipc, uint32_t comp_id);
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100150
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100151/*
152 * IPC Buffer creation and destruction.
153 */
154int ipc_buffer_new(struct ipc *ipc, struct sof_ipc_buffer *buffer);
Liam Girdwood3488cce2017-08-10 11:59:08 +0100155int ipc_buffer_free(struct ipc *ipc, uint32_t buffer_id);
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100156
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100157/*
158 * IPC Pipeline creation and destruction.
159 */
160int ipc_pipeline_new(struct ipc *ipc, struct sof_ipc_pipe_new *pipeline);
Liam Girdwood3488cce2017-08-10 11:59:08 +0100161int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id);
Liam Girdwood6506fd92017-09-23 23:04:34 +0100162int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id);
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100163
164/*
165 * Pipeline component and buffer connections.
166 */
167int ipc_comp_connect(struct ipc *ipc,
168 struct sof_ipc_pipe_comp_connect *connect);
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100169
Liam Girdwood3488cce2017-08-10 11:59:08 +0100170/*
171 * Get component by ID.
172 */
Liam Girdwood425aa5e2017-06-06 20:34:10 +0100173struct ipc_comp_dev *ipc_get_comp(struct ipc *ipc, uint32_t id);
Liam Girdwood3488cce2017-08-10 11:59:08 +0100174
175/*
176 * Configure all DAI components attached to DAI.
177 */
Liam Girdwoodec219862017-08-21 16:57:28 +0100178int ipc_comp_dai_config(struct ipc *ipc, struct sof_ipc_dai_config *config);
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100179
Yan Wanga3c73af2017-11-09 14:17:36 +0800180/* send DMA trace host buffer position to host */
181int ipc_dma_trace_send_position(void);
182
Pan Xiulie92ef972018-03-02 17:20:27 +0800183/* get posn offset by pipeline. */
184int ipc_get_posn_offset(struct ipc *ipc, struct pipeline *pipe);
Liam Girdwoodc0dfb4e2016-09-21 15:57:22 +0100185#endif