1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
33
34#include <linux/pci.h>
35#include <linux/fs.h>
36#include <linux/firmware.h>
37#include <linux/sched.h>
38#include "intel_sst.h"
39#include "intel_sst_ioctl.h"
40#include "intel_sst_fw_ipc.h"
41#include "intel_sst_common.h"
42
43
44
45
46
47
48
49
50
51
52int sst_get_block_stream(struct intel_sst_drv *sst_drv_ctx)
53{
54 int i;
55
56 for (i = 0; i < MAX_ACTIVE_STREAM; i++) {
57 if (sst_drv_ctx->alloc_block[i].sst_id == BLOCK_UNINIT) {
58 sst_drv_ctx->alloc_block[i].ops_block.condition = false;
59 sst_drv_ctx->alloc_block[i].ops_block.ret_code = 0;
60 sst_drv_ctx->alloc_block[i].sst_id = 0;
61 break;
62 }
63 }
64 if (i == MAX_ACTIVE_STREAM) {
65 pr_err("max alloc_stream reached\n");
66 i = -EBUSY;
67 }
68 return i;
69}
70
71
72
73
74
75
76
77
78
79
80int sst_wait_interruptible(struct intel_sst_drv *sst_drv_ctx,
81 struct sst_block *block)
82{
83 int retval = 0;
84
85 if (!wait_event_interruptible(sst_drv_ctx->wait_queue,
86 block->condition)) {
87
88 if (block->ret_code < 0) {
89 pr_err("stream failed %d\n", block->ret_code);
90 retval = -EBUSY;
91 } else {
92 pr_debug("event up\n");
93 retval = 0;
94 }
95 } else {
96 pr_err("signal interrupted\n");
97 retval = -EINTR;
98 }
99 return retval;
100
101}
102
103
104
105
106
107
108
109
110
111
112
113
114int sst_wait_interruptible_timeout(
115 struct intel_sst_drv *sst_drv_ctx,
116 struct sst_block *block, int timeout)
117{
118 int retval = 0;
119
120 pr_debug("sst_wait_interruptible_timeout - waiting....\n");
121 if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue,
122 block->condition,
123 msecs_to_jiffies(timeout))) {
124 if (block->ret_code < 0)
125 pr_err("stream failed %d\n", block->ret_code);
126 else
127 pr_debug("event up\n");
128 retval = block->ret_code;
129 } else {
130 block->on = false;
131 pr_err("timeout occurred...\n");
132
133
134
135
136
137 retval = -EBUSY;
138 }
139 return retval;
140
141}
142
143
144
145
146
147
148
149
150
151
152
153int sst_wait_timeout(struct intel_sst_drv *sst_drv_ctx,
154 struct stream_alloc_block *block)
155{
156 int retval = 0;
157
158
159
160
161 pr_debug("waiting for %x, condition %x\n",
162 block->sst_id, block->ops_block.condition);
163 if (wait_event_interruptible_timeout(sst_drv_ctx->wait_queue,
164 block->ops_block.condition,
165 msecs_to_jiffies(SST_BLOCK_TIMEOUT))) {
166
167 pr_debug("Event wake %x\n", block->ops_block.condition);
168 pr_debug("message ret: %d\n", block->ops_block.ret_code);
169 retval = block->ops_block.ret_code;
170 } else {
171 block->ops_block.on = false;
172 pr_err("Wait timed-out %x\n", block->ops_block.condition);
173
174
175
176
177
178 retval = -EBUSY;
179 }
180 return retval;
181
182}
183
184
185
186
187
188
189
190
191int sst_create_large_msg(struct ipc_post **arg)
192{
193 struct ipc_post *msg;
194
195 msg = kzalloc(sizeof(struct ipc_post), GFP_ATOMIC);
196 if (!msg) {
197 pr_err("kzalloc msg failed\n");
198 return -ENOMEM;
199 }
200
201 msg->mailbox_data = kzalloc(SST_MAILBOX_SIZE, GFP_ATOMIC);
202 if (!msg->mailbox_data) {
203 kfree(msg);
204 pr_err("kzalloc mailbox_data failed");
205 return -ENOMEM;
206 };
207 *arg = msg;
208 return 0;
209}
210
211
212
213
214
215
216
217
218int sst_create_short_msg(struct ipc_post **arg)
219{
220 struct ipc_post *msg;
221
222 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
223 if (!msg) {
224 pr_err("kzalloc msg failed\n");
225 return -ENOMEM;
226 }
227 msg->mailbox_data = NULL;
228 *arg = msg;
229 return 0;
230}
231
232
233
234
235
236
237
238
239
240void sst_clean_stream(struct stream_info *stream)
241{
242 struct sst_stream_bufs *bufs = NULL, *_bufs;
243 stream->status = STREAM_UN_INIT;
244 stream->prev = STREAM_UN_INIT;
245 mutex_lock(&stream->lock);
246 list_for_each_entry_safe(bufs, _bufs, &stream->bufs, node) {
247 list_del(&bufs->node);
248 kfree(bufs);
249 }
250 mutex_unlock(&stream->lock);
251
252 if (stream->ops != STREAM_OPS_PLAYBACK_DRM)
253 kfree(stream->decode_ibuf);
254}
255
256
257
258
259
260
261
262
263
264
265
266void sst_wake_up_alloc_block(struct intel_sst_drv *sst_drv_ctx,
267 u8 sst_id, int status, void *data)
268{
269 int i;
270
271
272 for (i = 0; i < MAX_ACTIVE_STREAM; i++) {
273 if (sst_id == sst_drv_ctx->alloc_block[i].sst_id) {
274 sst_drv_ctx->alloc_block[i].ops_block.condition = true;
275 sst_drv_ctx->alloc_block[i].ops_block.ret_code = status;
276 sst_drv_ctx->alloc_block[i].ops_block.data = data;
277 wake_up(&sst_drv_ctx->wait_queue);
278 break;
279 }
280 }
281}
282
283
284
285
286
287
288
289int sst_enable_rx_timeslot(int status)
290{
291 int retval = 0;
292 struct ipc_post *msg = NULL;
293
294 if (sst_create_short_msg(&msg)) {
295 pr_err("mem allocation failed\n");
296 return -ENOMEM;
297 }
298 pr_debug("ipc message sending: ENABLE_RX_TIME_SLOT\n");
299 sst_fill_header(&msg->header, IPC_IA_ENABLE_RX_TIME_SLOT, 0, 0);
300 msg->header.part.data = status;
301 sst_drv_ctx->hs_info_blk.condition = false;
302 sst_drv_ctx->hs_info_blk.ret_code = 0;
303 sst_drv_ctx->hs_info_blk.on = true;
304 spin_lock(&sst_drv_ctx->list_spin_lock);
305 list_add_tail(&msg->node,
306 &sst_drv_ctx->ipc_dispatch_list);
307 spin_unlock(&sst_drv_ctx->list_spin_lock);
308 sst_post_message(&sst_drv_ctx->ipc_post_msg_wq);
309 retval = sst_wait_interruptible_timeout(sst_drv_ctx,
310 &sst_drv_ctx->hs_info_blk, SST_BLOCK_TIMEOUT);
311 return retval;
312}
313
314