Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 1 | /* |
| 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 Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 36 | #include <sof/trace.h> |
| 37 | #include <sof/dai.h> |
| 38 | #include <sof/lock.h> |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 39 | #include <platform/platform.h> |
| 40 | #include <uapi/ipc.h> |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 41 | #include <sof/audio/pipeline.h> |
| 42 | #include <sof/audio/component.h> |
| 43 | #include <sof/dma-trace.h> |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 44 | |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 45 | struct sof; |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 46 | struct dai_config; |
Liam Girdwood | 69222cf | 2017-06-06 16:41:07 +0100 | [diff] [blame] | 47 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 48 | #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 Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 52 | #define MSG_QUEUE_SIZE 12 |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 53 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 54 | #define COMP_TYPE_COMPONENT 1 |
| 55 | #define COMP_TYPE_BUFFER 2 |
| 56 | #define COMP_TYPE_PIPELINE 3 |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 57 | |
| 58 | /* IPC generic component device */ |
| 59 | struct ipc_comp_dev { |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 60 | uint16_t type; /* COMP_TYPE_ */ |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 61 | uint16_t state; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 62 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 63 | /* component type data */ |
| 64 | union { |
| 65 | struct comp_dev *cd; |
| 66 | struct comp_buffer *cb; |
| 67 | struct pipeline *pipeline; |
| 68 | }; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 69 | |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 70 | /* lists */ |
| 71 | struct list_item list; /* list in components */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 74 | struct ipc_msg { |
| 75 | uint32_t header; /* specific to platform */ |
| 76 | uint32_t tx_size; /* payload size in bytes */ |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 77 | uint8_t tx_data[SOF_IPC_MSG_MAX_SIZE]; /* pointer to payload data */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 78 | uint32_t rx_size; /* payload size in bytes */ |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 79 | uint8_t rx_data[SOF_IPC_MSG_MAX_SIZE]; /* pointer to payload data */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 80 | struct list_item list; |
| 81 | void (*cb)(void *cb_data, void *mailbox_data); |
| 82 | void *cb_data; |
| 83 | }; |
| 84 | |
| 85 | struct 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 Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 95 | void *comp_data; |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 96 | |
| 97 | /* RX call back */ |
| 98 | int (*cb)(struct ipc_msg *msg); |
| 99 | |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 100 | /* pipelines, components and buffers */ |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 101 | struct list_item comp_list; /* list of component devices */ |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 102 | |
Yan Wang | fc6820e | 2017-09-18 11:23:55 +0800 | [diff] [blame] | 103 | /* DMA for Trace*/ |
Liam Girdwood | 36e425e | 2018-02-25 20:33:22 +0000 | [diff] [blame] | 104 | struct dma_trace_data *dmat; |
Yan Wang | fc6820e | 2017-09-18 11:23:55 +0800 | [diff] [blame] | 105 | |
Pan Xiuli | e92ef97 | 2018-03-02 17:20:27 +0800 | [diff] [blame] | 106 | /* mmap for posn_offset */ |
| 107 | struct pipeline *posn_map[PLATFORM_MAX_STREAMS]; |
| 108 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 109 | 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 Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 116 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 117 | |
Pierre-Louis Bossart | 81708a5 | 2018-04-04 18:46:50 -0500 | [diff] [blame] | 118 | int ipc_init(struct sof *sof); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 119 | int platform_ipc_init(struct ipc *ipc); |
| 120 | void ipc_free(struct ipc *ipc); |
| 121 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 122 | int ipc_process_msg_queue(void); |
| 123 | |
Liam Girdwood | 14dee1a | 2017-08-15 16:18:19 +0100 | [diff] [blame] | 124 | int ipc_stream_send_position(struct comp_dev *cdev, |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 125 | struct sof_ipc_stream_posn *posn); |
Liam Girdwood | a1da5bc | 2017-08-22 22:31:04 +0100 | [diff] [blame] | 126 | int ipc_stream_send_xrun(struct comp_dev *cdev, |
| 127 | struct sof_ipc_stream_posn *posn); |
| 128 | |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 129 | int ipc_queue_host_message(struct ipc *ipc, uint32_t header, |
| 130 | void *tx_data, size_t tx_bytes, void *rx_data, |
Yan Wang | 1611a0a | 2017-12-07 15:34:40 +0800 | [diff] [blame] | 131 | size_t rx_bytes, void (*cb)(void*, void*), void *cb_data, uint32_t replace); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 132 | int ipc_send_short_msg(uint32_t msg); |
| 133 | |
| 134 | void ipc_platform_do_cmd(struct ipc *ipc); |
| 135 | void ipc_platform_send_msg(struct ipc *ipc); |
| 136 | |
Liam Girdwood | 78e7f30 | 2018-04-11 16:53:02 +0100 | [diff] [blame] | 137 | /* create a SG page table eme list from a compressed page table */ |
| 138 | int 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); |
| 142 | int ipc_get_page_descriptors(struct dma *dmac, uint8_t *page_table, |
| 143 | struct sof_ipc_host_buffer *ring); |
| 144 | |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 145 | /* |
| 146 | * IPC Component creation and destruction. |
| 147 | */ |
| 148 | int ipc_comp_new(struct ipc *ipc, struct sof_ipc_comp *new); |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 149 | int ipc_comp_free(struct ipc *ipc, uint32_t comp_id); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 150 | |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 151 | /* |
| 152 | * IPC Buffer creation and destruction. |
| 153 | */ |
| 154 | int ipc_buffer_new(struct ipc *ipc, struct sof_ipc_buffer *buffer); |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 155 | int ipc_buffer_free(struct ipc *ipc, uint32_t buffer_id); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 156 | |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 157 | /* |
| 158 | * IPC Pipeline creation and destruction. |
| 159 | */ |
| 160 | int ipc_pipeline_new(struct ipc *ipc, struct sof_ipc_pipe_new *pipeline); |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 161 | int ipc_pipeline_free(struct ipc *ipc, uint32_t comp_id); |
Liam Girdwood | 6506fd9 | 2017-09-23 23:04:34 +0100 | [diff] [blame] | 162 | int ipc_pipeline_complete(struct ipc *ipc, uint32_t comp_id); |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 163 | |
| 164 | /* |
| 165 | * Pipeline component and buffer connections. |
| 166 | */ |
| 167 | int ipc_comp_connect(struct ipc *ipc, |
| 168 | struct sof_ipc_pipe_comp_connect *connect); |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 169 | |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 170 | /* |
| 171 | * Get component by ID. |
| 172 | */ |
Liam Girdwood | 425aa5e | 2017-06-06 20:34:10 +0100 | [diff] [blame] | 173 | struct ipc_comp_dev *ipc_get_comp(struct ipc *ipc, uint32_t id); |
Liam Girdwood | 3488cce | 2017-08-10 11:59:08 +0100 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * Configure all DAI components attached to DAI. |
| 177 | */ |
Liam Girdwood | ec21986 | 2017-08-21 16:57:28 +0100 | [diff] [blame] | 178 | int ipc_comp_dai_config(struct ipc *ipc, struct sof_ipc_dai_config *config); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 179 | |
Yan Wang | a3c73af | 2017-11-09 14:17:36 +0800 | [diff] [blame] | 180 | /* send DMA trace host buffer position to host */ |
| 181 | int ipc_dma_trace_send_position(void); |
| 182 | |
Pan Xiuli | e92ef97 | 2018-03-02 17:20:27 +0800 | [diff] [blame] | 183 | /* get posn offset by pipeline. */ |
| 184 | int ipc_get_posn_offset(struct ipc *ipc, struct pipeline *pipe); |
Liam Girdwood | c0dfb4e | 2016-09-21 15:57:22 +0100 | [diff] [blame] | 185 | #endif |