2 * Intel SST Haswell/Broadwell IPC Support
4 * Copyright (C) 2013, Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
17 #include <linux/types.h>
18 #include <linux/kernel.h>
19 #include <linux/list.h>
20 #include <linux/device.h>
21 #include <linux/wait.h>
22 #include <linux/spinlock.h>
23 #include <linux/workqueue.h>
24 #include <linux/export.h>
25 #include <linux/slab.h>
26 #include <linux/delay.h>
27 #include <linux/sched.h>
28 #include <linux/platform_device.h>
29 #include <linux/kthread.h>
30 #include <linux/firmware.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/debugfs.h>
33 #include <linux/pm_runtime.h>
34 #include <sound/asound.h>
36 #include "sst-haswell-ipc.h"
38 #include "sst-dsp-priv.h"
40 /* Global Message - Generic */
41 #define IPC_GLB_TYPE_SHIFT 24
42 #define IPC_GLB_TYPE_MASK (0x1f << IPC_GLB_TYPE_SHIFT)
43 #define IPC_GLB_TYPE(x) (x << IPC_GLB_TYPE_SHIFT)
45 /* Global Message - Reply */
46 #define IPC_GLB_REPLY_SHIFT 0
47 #define IPC_GLB_REPLY_MASK (0x1f << IPC_GLB_REPLY_SHIFT)
48 #define IPC_GLB_REPLY_TYPE(x) (x << IPC_GLB_REPLY_TYPE_SHIFT)
50 /* Stream Message - Generic */
51 #define IPC_STR_TYPE_SHIFT 20
52 #define IPC_STR_TYPE_MASK (0xf << IPC_STR_TYPE_SHIFT)
53 #define IPC_STR_TYPE(x) (x << IPC_STR_TYPE_SHIFT)
54 #define IPC_STR_ID_SHIFT 16
55 #define IPC_STR_ID_MASK (0xf << IPC_STR_ID_SHIFT)
56 #define IPC_STR_ID(x) (x << IPC_STR_ID_SHIFT)
58 /* Stream Message - Reply */
59 #define IPC_STR_REPLY_SHIFT 0
60 #define IPC_STR_REPLY_MASK (0x1f << IPC_STR_REPLY_SHIFT)
62 /* Stream Stage Message - Generic */
63 #define IPC_STG_TYPE_SHIFT 12
64 #define IPC_STG_TYPE_MASK (0xf << IPC_STG_TYPE_SHIFT)
65 #define IPC_STG_TYPE(x) (x << IPC_STG_TYPE_SHIFT)
66 #define IPC_STG_ID_SHIFT 10
67 #define IPC_STG_ID_MASK (0x3 << IPC_STG_ID_SHIFT)
68 #define IPC_STG_ID(x) (x << IPC_STG_ID_SHIFT)
70 /* Stream Stage Message - Reply */
71 #define IPC_STG_REPLY_SHIFT 0
72 #define IPC_STG_REPLY_MASK (0x1f << IPC_STG_REPLY_SHIFT)
74 /* Debug Log Message - Generic */
75 #define IPC_LOG_OP_SHIFT 20
76 #define IPC_LOG_OP_MASK (0xf << IPC_LOG_OP_SHIFT)
77 #define IPC_LOG_OP_TYPE(x) (x << IPC_LOG_OP_SHIFT)
78 #define IPC_LOG_ID_SHIFT 16
79 #define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT)
80 #define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT)
83 #define IPC_MODULE_OPERATION_SHIFT 20
84 #define IPC_MODULE_OPERATION_MASK (0xf << IPC_MODULE_OPERATION_SHIFT)
85 #define IPC_MODULE_OPERATION(x) (x << IPC_MODULE_OPERATION_SHIFT)
87 #define IPC_MODULE_ID_SHIFT 16
88 #define IPC_MODULE_ID_MASK (0xf << IPC_MODULE_ID_SHIFT)
89 #define IPC_MODULE_ID(x) (x << IPC_MODULE_ID_SHIFT)
91 /* IPC message timeout (msecs) */
92 #define IPC_TIMEOUT_MSECS 300
93 #define IPC_BOOT_MSECS 200
94 #define IPC_MSG_WAIT 0
95 #define IPC_MSG_NOWAIT 1
97 /* Firmware Ready Message */
98 #define IPC_FW_READY (0x1 << 29)
99 #define IPC_STATUS_MASK (0x3 << 30)
101 #define IPC_EMPTY_LIST_SIZE 8
102 #define IPC_MAX_STREAMS 4
105 #define IPC_MAX_MAILBOX_BYTES 256
107 #define INVALID_STREAM_HW_ID 0xffffffff
109 /* Global Message - Types and Replies */
111 IPC_GLB_GET_FW_VERSION
= 0, /* Retrieves firmware version */
112 IPC_GLB_PERFORMANCE_MONITOR
= 1, /* Performance monitoring actions */
113 IPC_GLB_ALLOCATE_STREAM
= 3, /* Request to allocate new stream */
114 IPC_GLB_FREE_STREAM
= 4, /* Request to free stream */
115 IPC_GLB_GET_FW_CAPABILITIES
= 5, /* Retrieves firmware capabilities */
116 IPC_GLB_STREAM_MESSAGE
= 6, /* Message directed to stream or its stages */
117 /* Request to store firmware context during D0->D3 transition */
118 IPC_GLB_REQUEST_DUMP
= 7,
119 /* Request to restore firmware context during D3->D0 transition */
120 IPC_GLB_RESTORE_CONTEXT
= 8,
121 IPC_GLB_GET_DEVICE_FORMATS
= 9, /* Set device format */
122 IPC_GLB_SET_DEVICE_FORMATS
= 10, /* Get device format */
123 IPC_GLB_SHORT_REPLY
= 11,
124 IPC_GLB_ENTER_DX_STATE
= 12,
125 IPC_GLB_GET_MIXER_STREAM_INFO
= 13, /* Request mixer stream params */
126 IPC_GLB_DEBUG_LOG_MESSAGE
= 14, /* Message to or from the debug logger. */
127 IPC_GLB_MODULE_OPERATION
= 15, /* Message to loadable fw module */
128 IPC_GLB_REQUEST_TRANSFER
= 16, /* < Request Transfer for host */
129 IPC_GLB_MAX_IPC_MESSAGE_TYPE
= 17, /* Maximum message number */
133 IPC_GLB_REPLY_SUCCESS
= 0, /* The operation was successful. */
134 IPC_GLB_REPLY_ERROR_INVALID_PARAM
= 1, /* Invalid parameter was passed. */
135 IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE
= 2, /* Uknown message type was resceived. */
136 IPC_GLB_REPLY_OUT_OF_RESOURCES
= 3, /* No resources to satisfy the request. */
137 IPC_GLB_REPLY_BUSY
= 4, /* The system or resource is busy. */
138 IPC_GLB_REPLY_PENDING
= 5, /* The action was scheduled for processing. */
139 IPC_GLB_REPLY_FAILURE
= 6, /* Critical error happened. */
140 IPC_GLB_REPLY_INVALID_REQUEST
= 7, /* Request can not be completed. */
141 IPC_GLB_REPLY_STAGE_UNINITIALIZED
= 8, /* Processing stage was uninitialized. */
142 IPC_GLB_REPLY_NOT_FOUND
= 9, /* Required resource can not be found. */
143 IPC_GLB_REPLY_SOURCE_NOT_STARTED
= 10, /* Source was not started. */
146 enum ipc_module_operation
{
147 IPC_MODULE_NOTIFICATION
= 0,
148 IPC_MODULE_ENABLE
= 1,
149 IPC_MODULE_DISABLE
= 2,
150 IPC_MODULE_GET_PARAMETER
= 3,
151 IPC_MODULE_SET_PARAMETER
= 4,
152 IPC_MODULE_GET_INFO
= 5,
153 IPC_MODULE_MAX_MESSAGE
156 /* Stream Message - Types */
157 enum ipc_str_operation
{
161 IPC_STR_STAGE_MESSAGE
= 3,
162 IPC_STR_NOTIFICATION
= 4,
166 /* Stream Stage Message Types */
167 enum ipc_stg_operation
{
168 IPC_STG_GET_VOLUME
= 0,
170 IPC_STG_SET_WRITE_POSITION
,
171 IPC_STG_SET_FX_ENABLE
,
172 IPC_STG_SET_FX_DISABLE
,
173 IPC_STG_SET_FX_GET_PARAM
,
174 IPC_STG_SET_FX_SET_PARAM
,
175 IPC_STG_SET_FX_GET_INFO
,
176 IPC_STG_MUTE_LOOPBACK
,
180 /* Stream Stage Message Types For Notification*/
181 enum ipc_stg_operation_notify
{
182 IPC_POSITION_CHANGED
= 0,
187 enum ipc_glitch_type
{
188 IPC_GLITCH_UNDERRUN
= 1,
189 IPC_GLITCH_DECODER_ERROR
,
190 IPC_GLITCH_DOUBLED_WRITE_POS
,
195 enum ipc_debug_operation
{
196 IPC_DEBUG_ENABLE_LOG
= 0,
197 IPC_DEBUG_DISABLE_LOG
= 1,
198 IPC_DEBUG_REQUEST_LOG_DUMP
= 2,
199 IPC_DEBUG_NOTIFY_LOG_DUMP
= 3,
200 IPC_DEBUG_MAX_DEBUG_LOG
204 struct sst_hsw_ipc_fw_ready
{
210 u8 fw_info
[IPC_MAX_MAILBOX_BYTES
- 5 * sizeof(u32
)];
211 } __attribute__((packed
));
214 struct list_head list
;
217 /* direction wrt host CPU */
218 char tx_data
[IPC_MAX_MAILBOX_BYTES
];
220 char rx_data
[IPC_MAX_MAILBOX_BYTES
];
223 wait_queue_head_t waitq
;
230 struct sst_hsw_stream
;
233 /* Stream infomation */
234 struct sst_hsw_stream
{
236 struct sst_hsw_ipc_stream_alloc_req request
;
237 struct sst_hsw_ipc_stream_alloc_reply reply
;
238 struct sst_hsw_ipc_stream_free_req free_req
;
241 u32 mute_volume
[SST_HSW_NO_CHANNELS
];
242 u32 mute
[SST_HSW_NO_CHANNELS
];
250 /* Notification work */
251 struct work_struct notify_work
;
254 /* Position info from DSP */
255 struct sst_hsw_ipc_stream_set_position wpos
;
256 struct sst_hsw_ipc_stream_get_position rpos
;
257 struct sst_hsw_ipc_stream_glitch_position glitch
;
260 struct sst_hsw_ipc_volume_req vol_req
;
262 /* driver callback */
263 u32 (*notify_position
)(struct sst_hsw_stream
*stream
, void *data
);
266 /* record the fw read position when playback */
267 snd_pcm_uframes_t old_position
;
269 struct list_head node
;
272 /* FW log ring information */
273 struct sst_hsw_log_stream
{
275 unsigned char *dma_area
;
276 unsigned char *ring_descr
;
280 /* Notification work */
281 struct work_struct notify_work
;
282 wait_queue_head_t readers_wait_q
;
283 struct mutex rw_mutex
;
290 u32 config
[SST_HSW_FW_LOG_CONFIG_DWORDS
];
295 /* SST Haswell IPC data */
299 struct platform_device
*pdev_pcm
;
302 struct sst_hsw_ipc_fw_ready fw_ready
;
303 struct sst_hsw_ipc_fw_version version
;
305 struct sst_fw
*sst_fw
;
308 struct list_head stream_list
;
311 struct sst_hsw_ipc_stream_info_reply mixer_info
;
312 enum sst_hsw_volume_curve curve_type
;
314 u32 mute
[SST_HSW_NO_CHANNELS
];
315 u32 mute_volume
[SST_HSW_NO_CHANNELS
];
318 struct sst_hsw_ipc_dx_reply dx
;
320 dma_addr_t dx_context_paddr
;
323 wait_queue_head_t boot_wait
;
328 struct list_head tx_list
;
329 struct list_head rx_list
;
330 struct list_head empty_list
;
331 wait_queue_head_t wait_txq
;
332 struct task_struct
*tx_thread
;
333 struct kthread_worker kworker
;
334 struct kthread_work kwork
;
336 struct ipc_message
*msg
;
339 struct sst_hsw_log_stream log_stream
;
341 /* flags bit field to track module state when resume from RTD3,
342 * each bit represent state (enabled/disabled) of single module */
343 u32 enabled_modules_rtd3
;
346 #define CREATE_TRACE_POINTS
347 #include <trace/events/hswadsp.h>
349 static inline u32
msg_get_global_type(u32 msg
)
351 return (msg
& IPC_GLB_TYPE_MASK
) >> IPC_GLB_TYPE_SHIFT
;
354 static inline u32
msg_get_global_reply(u32 msg
)
356 return (msg
& IPC_GLB_REPLY_MASK
) >> IPC_GLB_REPLY_SHIFT
;
359 static inline u32
msg_get_stream_type(u32 msg
)
361 return (msg
& IPC_STR_TYPE_MASK
) >> IPC_STR_TYPE_SHIFT
;
364 static inline u32
msg_get_stage_type(u32 msg
)
366 return (msg
& IPC_STG_TYPE_MASK
) >> IPC_STG_TYPE_SHIFT
;
369 static inline u32
msg_get_stream_id(u32 msg
)
371 return (msg
& IPC_STR_ID_MASK
) >> IPC_STR_ID_SHIFT
;
374 static inline u32
msg_get_notify_reason(u32 msg
)
376 return (msg
& IPC_STG_TYPE_MASK
) >> IPC_STG_TYPE_SHIFT
;
379 static inline u32
msg_get_module_operation(u32 msg
)
381 return (msg
& IPC_MODULE_OPERATION_MASK
) >> IPC_MODULE_OPERATION_SHIFT
;
384 static inline u32
msg_get_module_id(u32 msg
)
386 return (msg
& IPC_MODULE_ID_MASK
) >> IPC_MODULE_ID_SHIFT
;
389 u32
create_channel_map(enum sst_hsw_channel_config config
)
392 case SST_HSW_CHANNEL_CONFIG_MONO
:
393 return (0xFFFFFFF0 | SST_HSW_CHANNEL_CENTER
);
394 case SST_HSW_CHANNEL_CONFIG_STEREO
:
395 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
396 | (SST_HSW_CHANNEL_RIGHT
<< 4));
397 case SST_HSW_CHANNEL_CONFIG_2_POINT_1
:
398 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
399 | (SST_HSW_CHANNEL_RIGHT
<< 4)
400 | (SST_HSW_CHANNEL_LFE
<< 8 ));
401 case SST_HSW_CHANNEL_CONFIG_3_POINT_0
:
402 return (0xFFFFF000 | SST_HSW_CHANNEL_LEFT
403 | (SST_HSW_CHANNEL_CENTER
<< 4)
404 | (SST_HSW_CHANNEL_RIGHT
<< 8));
405 case SST_HSW_CHANNEL_CONFIG_3_POINT_1
:
406 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
407 | (SST_HSW_CHANNEL_CENTER
<< 4)
408 | (SST_HSW_CHANNEL_RIGHT
<< 8)
409 | (SST_HSW_CHANNEL_LFE
<< 12));
410 case SST_HSW_CHANNEL_CONFIG_QUATRO
:
411 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
412 | (SST_HSW_CHANNEL_RIGHT
<< 4)
413 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 8)
414 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 12));
415 case SST_HSW_CHANNEL_CONFIG_4_POINT_0
:
416 return (0xFFFF0000 | SST_HSW_CHANNEL_LEFT
417 | (SST_HSW_CHANNEL_CENTER
<< 4)
418 | (SST_HSW_CHANNEL_RIGHT
<< 8)
419 | (SST_HSW_CHANNEL_CENTER_SURROUND
<< 12));
420 case SST_HSW_CHANNEL_CONFIG_5_POINT_0
:
421 return (0xFFF00000 | SST_HSW_CHANNEL_LEFT
422 | (SST_HSW_CHANNEL_CENTER
<< 4)
423 | (SST_HSW_CHANNEL_RIGHT
<< 8)
424 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 12)
425 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 16));
426 case SST_HSW_CHANNEL_CONFIG_5_POINT_1
:
427 return (0xFF000000 | SST_HSW_CHANNEL_CENTER
428 | (SST_HSW_CHANNEL_LEFT
<< 4)
429 | (SST_HSW_CHANNEL_RIGHT
<< 8)
430 | (SST_HSW_CHANNEL_LEFT_SURROUND
<< 12)
431 | (SST_HSW_CHANNEL_RIGHT_SURROUND
<< 16)
432 | (SST_HSW_CHANNEL_LFE
<< 20));
433 case SST_HSW_CHANNEL_CONFIG_DUAL_MONO
:
434 return (0xFFFFFF00 | SST_HSW_CHANNEL_LEFT
435 | (SST_HSW_CHANNEL_LEFT
<< 4));
441 static struct sst_hsw_stream
*get_stream_by_id(struct sst_hsw
*hsw
,
444 struct sst_hsw_stream
*stream
;
446 list_for_each_entry(stream
, &hsw
->stream_list
, node
) {
447 if (stream
->reply
.stream_hw_id
== stream_id
)
454 static void ipc_shim_dbg(struct sst_hsw
*hsw
, const char *text
)
456 struct sst_dsp
*sst
= hsw
->dsp
;
457 u32 isr
, ipcd
, imrx
, ipcx
;
459 ipcx
= sst_dsp_shim_read_unlocked(sst
, SST_IPCX
);
460 isr
= sst_dsp_shim_read_unlocked(sst
, SST_ISRX
);
461 ipcd
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
462 imrx
= sst_dsp_shim_read_unlocked(sst
, SST_IMRX
);
464 dev_err(hsw
->dev
, "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n",
465 text
, ipcx
, isr
, ipcd
, imrx
);
468 /* locks held by caller */
469 static struct ipc_message
*msg_get_empty(struct sst_hsw
*hsw
)
471 struct ipc_message
*msg
= NULL
;
473 if (!list_empty(&hsw
->empty_list
)) {
474 msg
= list_first_entry(&hsw
->empty_list
, struct ipc_message
,
476 list_del(&msg
->list
);
482 static void ipc_tx_msgs(struct kthread_work
*work
)
484 struct sst_hsw
*hsw
=
485 container_of(work
, struct sst_hsw
, kwork
);
486 struct ipc_message
*msg
;
490 spin_lock_irqsave(&hsw
->dsp
->spinlock
, flags
);
492 if (list_empty(&hsw
->tx_list
) || hsw
->pending
) {
493 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
497 /* if the DSP is busy, we will TX messages after IRQ.
498 * also postpone if we are in the middle of procesing completion irq*/
499 ipcx
= sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCX
);
500 if (ipcx
& (SST_IPCX_BUSY
| SST_IPCX_DONE
)) {
501 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
505 msg
= list_first_entry(&hsw
->tx_list
, struct ipc_message
, list
);
507 list_move(&msg
->list
, &hsw
->rx_list
);
509 /* send the message */
510 sst_dsp_outbox_write(hsw
->dsp
, msg
->tx_data
, msg
->tx_size
);
511 sst_dsp_ipc_msg_tx(hsw
->dsp
, msg
->header
| SST_IPCX_BUSY
);
513 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
516 /* locks held by caller */
517 static void tx_msg_reply_complete(struct sst_hsw
*hsw
, struct ipc_message
*msg
)
519 msg
->complete
= true;
520 trace_ipc_reply("completed", msg
->header
);
523 list_add_tail(&msg
->list
, &hsw
->empty_list
);
525 wake_up(&msg
->waitq
);
528 static int tx_wait_done(struct sst_hsw
*hsw
, struct ipc_message
*msg
,
534 /* wait for DSP completion (in all cases atm inc pending) */
535 ret
= wait_event_timeout(msg
->waitq
, msg
->complete
,
536 msecs_to_jiffies(IPC_TIMEOUT_MSECS
));
538 spin_lock_irqsave(&hsw
->dsp
->spinlock
, flags
);
540 ipc_shim_dbg(hsw
, "message timeout");
542 trace_ipc_error("error message timeout for", msg
->header
);
543 list_del(&msg
->list
);
547 /* copy the data returned from DSP */
549 memcpy(rx_data
, msg
->rx_data
, msg
->rx_size
);
553 list_add_tail(&msg
->list
, &hsw
->empty_list
);
554 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
558 static int ipc_tx_message(struct sst_hsw
*hsw
, u32 header
, void *tx_data
,
559 size_t tx_bytes
, void *rx_data
, size_t rx_bytes
, int wait
)
561 struct ipc_message
*msg
;
564 spin_lock_irqsave(&hsw
->dsp
->spinlock
, flags
);
566 msg
= msg_get_empty(hsw
);
568 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
573 memcpy(msg
->tx_data
, tx_data
, tx_bytes
);
575 msg
->header
= header
;
576 msg
->tx_size
= tx_bytes
;
577 msg
->rx_size
= rx_bytes
;
580 msg
->pending
= false;
581 msg
->complete
= false;
583 list_add_tail(&msg
->list
, &hsw
->tx_list
);
584 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
586 queue_kthread_work(&hsw
->kworker
, &hsw
->kwork
);
589 return tx_wait_done(hsw
, msg
, rx_data
);
594 static inline int ipc_tx_message_wait(struct sst_hsw
*hsw
, u32 header
,
595 void *tx_data
, size_t tx_bytes
, void *rx_data
, size_t rx_bytes
)
597 return ipc_tx_message(hsw
, header
, tx_data
, tx_bytes
, rx_data
,
601 static inline int ipc_tx_message_nowait(struct sst_hsw
*hsw
, u32 header
,
602 void *tx_data
, size_t tx_bytes
)
604 return ipc_tx_message(hsw
, header
, tx_data
, tx_bytes
, NULL
, 0, 0);
607 static void hsw_fw_ready(struct sst_hsw
*hsw
, u32 header
)
609 struct sst_hsw_ipc_fw_ready fw_ready
;
611 u8 fw_info
[IPC_MAX_MAILBOX_BYTES
- 5 * sizeof(u32
)];
612 char *tmp
[5], *pinfo
;
615 offset
= (header
& 0x1FFFFFFF) << 3;
617 dev_dbg(hsw
->dev
, "ipc: DSP is ready 0x%8.8x offset %d\n",
620 /* copy data from the DSP FW ready offset */
621 sst_dsp_read(hsw
->dsp
, &fw_ready
, offset
, sizeof(fw_ready
));
623 sst_dsp_mailbox_init(hsw
->dsp
, fw_ready
.inbox_offset
,
624 fw_ready
.inbox_size
, fw_ready
.outbox_offset
,
625 fw_ready
.outbox_size
);
627 hsw
->boot_complete
= true;
628 wake_up(&hsw
->boot_wait
);
630 dev_dbg(hsw
->dev
, " mailbox upstream 0x%x - size 0x%x\n",
631 fw_ready
.inbox_offset
, fw_ready
.inbox_size
);
632 dev_dbg(hsw
->dev
, " mailbox downstream 0x%x - size 0x%x\n",
633 fw_ready
.outbox_offset
, fw_ready
.outbox_size
);
634 if (fw_ready
.fw_info_size
< sizeof(fw_ready
.fw_info
)) {
635 fw_ready
.fw_info
[fw_ready
.fw_info_size
] = 0;
636 dev_dbg(hsw
->dev
, " Firmware info: %s \n", fw_ready
.fw_info
);
638 /* log the FW version info got from the mailbox here. */
639 memcpy(fw_info
, fw_ready
.fw_info
, fw_ready
.fw_info_size
);
641 for (i
= 0; i
< sizeof(tmp
) / sizeof(char *); i
++)
642 tmp
[i
] = strsep(&pinfo
, " ");
643 dev_info(hsw
->dev
, "FW loaded, mailbox readback FW info: type %s, - "
644 "version: %s.%s, build %s, source commit id: %s\n",
645 tmp
[0], tmp
[1], tmp
[2], tmp
[3], tmp
[4]);
649 static void hsw_notification_work(struct work_struct
*work
)
651 struct sst_hsw_stream
*stream
= container_of(work
,
652 struct sst_hsw_stream
, notify_work
);
653 struct sst_hsw_ipc_stream_glitch_position
*glitch
= &stream
->glitch
;
654 struct sst_hsw_ipc_stream_get_position
*pos
= &stream
->rpos
;
655 struct sst_hsw
*hsw
= stream
->hsw
;
658 reason
= msg_get_notify_reason(stream
->header
);
662 trace_ipc_notification("DSP stream under/overrun",
663 stream
->reply
.stream_hw_id
);
664 sst_dsp_inbox_read(hsw
->dsp
, glitch
, sizeof(*glitch
));
666 dev_err(hsw
->dev
, "glitch %d pos 0x%x write pos 0x%x\n",
667 glitch
->glitch_type
, glitch
->present_pos
,
671 case IPC_POSITION_CHANGED
:
672 trace_ipc_notification("DSP stream position changed for",
673 stream
->reply
.stream_hw_id
);
674 sst_dsp_inbox_read(hsw
->dsp
, pos
, sizeof(*pos
));
676 if (stream
->notify_position
)
677 stream
->notify_position(stream
, stream
->pdata
);
681 dev_err(hsw
->dev
, "error: unknown notification 0x%x\n",
686 /* tell DSP that notification has been handled */
687 sst_dsp_shim_update_bits(hsw
->dsp
, SST_IPCD
,
688 SST_IPCD_BUSY
| SST_IPCD_DONE
, SST_IPCD_DONE
);
690 /* unmask busy interrupt */
691 sst_dsp_shim_update_bits(hsw
->dsp
, SST_IMRX
, SST_IMRX_BUSY
, 0);
694 static struct ipc_message
*reply_find_msg(struct sst_hsw
*hsw
, u32 header
)
696 struct ipc_message
*msg
;
698 /* clear reply bits & status bits */
699 header
&= ~(IPC_STATUS_MASK
| IPC_GLB_REPLY_MASK
);
701 if (list_empty(&hsw
->rx_list
)) {
702 dev_err(hsw
->dev
, "error: rx list empty but received 0x%x\n",
707 list_for_each_entry(msg
, &hsw
->rx_list
, list
) {
708 if (msg
->header
== header
)
715 static void hsw_stream_update(struct sst_hsw
*hsw
, struct ipc_message
*msg
)
717 struct sst_hsw_stream
*stream
;
718 u32 header
= msg
->header
& ~(IPC_STATUS_MASK
| IPC_GLB_REPLY_MASK
);
719 u32 stream_id
= msg_get_stream_id(header
);
720 u32 stream_msg
= msg_get_stream_type(header
);
722 stream
= get_stream_by_id(hsw
, stream_id
);
726 switch (stream_msg
) {
727 case IPC_STR_STAGE_MESSAGE
:
728 case IPC_STR_NOTIFICATION
:
731 trace_ipc_notification("stream reset", stream
->reply
.stream_hw_id
);
734 stream
->running
= false;
735 trace_ipc_notification("stream paused",
736 stream
->reply
.stream_hw_id
);
739 stream
->running
= true;
740 trace_ipc_notification("stream running",
741 stream
->reply
.stream_hw_id
);
746 static int hsw_process_reply(struct sst_hsw
*hsw
, u32 header
)
748 struct ipc_message
*msg
;
749 u32 reply
= msg_get_global_reply(header
);
751 trace_ipc_reply("processing -->", header
);
753 msg
= reply_find_msg(hsw
, header
);
755 trace_ipc_error("error: can't find message header", header
);
759 /* first process the header */
761 case IPC_GLB_REPLY_PENDING
:
762 trace_ipc_pending_reply("received", header
);
766 case IPC_GLB_REPLY_SUCCESS
:
768 trace_ipc_pending_reply("completed", header
);
769 sst_dsp_inbox_read(hsw
->dsp
, msg
->rx_data
,
771 hsw
->pending
= false;
773 /* copy data from the DSP */
774 sst_dsp_outbox_read(hsw
->dsp
, msg
->rx_data
,
778 /* these will be rare - but useful for debug */
779 case IPC_GLB_REPLY_UNKNOWN_MESSAGE_TYPE
:
780 trace_ipc_error("error: unknown message type", header
);
781 msg
->errno
= -EBADMSG
;
783 case IPC_GLB_REPLY_OUT_OF_RESOURCES
:
784 trace_ipc_error("error: out of resources", header
);
785 msg
->errno
= -ENOMEM
;
787 case IPC_GLB_REPLY_BUSY
:
788 trace_ipc_error("error: reply busy", header
);
791 case IPC_GLB_REPLY_FAILURE
:
792 trace_ipc_error("error: reply failure", header
);
793 msg
->errno
= -EINVAL
;
795 case IPC_GLB_REPLY_STAGE_UNINITIALIZED
:
796 trace_ipc_error("error: stage uninitialized", header
);
797 msg
->errno
= -EINVAL
;
799 case IPC_GLB_REPLY_NOT_FOUND
:
800 trace_ipc_error("error: reply not found", header
);
801 msg
->errno
= -EINVAL
;
803 case IPC_GLB_REPLY_SOURCE_NOT_STARTED
:
804 trace_ipc_error("error: source not started", header
);
805 msg
->errno
= -EINVAL
;
807 case IPC_GLB_REPLY_INVALID_REQUEST
:
808 trace_ipc_error("error: invalid request", header
);
809 msg
->errno
= -EINVAL
;
811 case IPC_GLB_REPLY_ERROR_INVALID_PARAM
:
812 trace_ipc_error("error: invalid parameter", header
);
813 msg
->errno
= -EINVAL
;
816 trace_ipc_error("error: unknown reply", header
);
817 msg
->errno
= -EINVAL
;
821 /* update any stream states */
822 if (msg_get_global_type(header
) == IPC_GLB_STREAM_MESSAGE
)
823 hsw_stream_update(hsw
, msg
);
825 /* wake up and return the error if we have waiters on this message ? */
826 list_del(&msg
->list
);
827 tx_msg_reply_complete(hsw
, msg
);
832 static int hsw_module_message(struct sst_hsw
*hsw
, u32 header
)
834 u32 operation
, module_id
;
837 operation
= msg_get_module_operation(header
);
838 module_id
= msg_get_module_id(header
);
839 dev_dbg(hsw
->dev
, "received module message header: 0x%8.8x\n",
841 dev_dbg(hsw
->dev
, "operation: 0x%8.8x module_id: 0x%8.8x\n",
842 operation
, module_id
);
845 case IPC_MODULE_NOTIFICATION
:
846 dev_dbg(hsw
->dev
, "module notification received");
850 handled
= hsw_process_reply(hsw
, header
);
857 static int hsw_stream_message(struct sst_hsw
*hsw
, u32 header
)
859 u32 stream_msg
, stream_id
, stage_type
;
860 struct sst_hsw_stream
*stream
;
863 stream_msg
= msg_get_stream_type(header
);
864 stream_id
= msg_get_stream_id(header
);
865 stage_type
= msg_get_stage_type(header
);
867 stream
= get_stream_by_id(hsw
, stream_id
);
871 stream
->header
= header
;
873 switch (stream_msg
) {
874 case IPC_STR_STAGE_MESSAGE
:
875 dev_err(hsw
->dev
, "error: stage msg not implemented 0x%8.8x\n",
878 case IPC_STR_NOTIFICATION
:
879 schedule_work(&stream
->notify_work
);
882 /* handle pending message complete request */
883 handled
= hsw_process_reply(hsw
, header
);
890 static int hsw_log_message(struct sst_hsw
*hsw
, u32 header
)
892 u32 operation
= (header
& IPC_LOG_OP_MASK
) >> IPC_LOG_OP_SHIFT
;
893 struct sst_hsw_log_stream
*stream
= &hsw
->log_stream
;
896 if (operation
!= IPC_DEBUG_REQUEST_LOG_DUMP
) {
898 "error: log msg not implemented 0x%8.8x\n", header
);
902 mutex_lock(&stream
->rw_mutex
);
903 stream
->last_pos
= stream
->curr_pos
;
905 hsw
->dsp
, &stream
->curr_pos
, sizeof(stream
->curr_pos
));
906 mutex_unlock(&stream
->rw_mutex
);
908 schedule_work(&stream
->notify_work
);
913 static int hsw_process_notification(struct sst_hsw
*hsw
)
915 struct sst_dsp
*sst
= hsw
->dsp
;
919 header
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
920 type
= msg_get_global_type(header
);
922 trace_ipc_request("processing -->", header
);
924 /* FW Ready is a special case */
925 if (!hsw
->boot_complete
&& header
& IPC_FW_READY
) {
926 hsw_fw_ready(hsw
, header
);
931 case IPC_GLB_GET_FW_VERSION
:
932 case IPC_GLB_ALLOCATE_STREAM
:
933 case IPC_GLB_FREE_STREAM
:
934 case IPC_GLB_GET_FW_CAPABILITIES
:
935 case IPC_GLB_REQUEST_DUMP
:
936 case IPC_GLB_GET_DEVICE_FORMATS
:
937 case IPC_GLB_SET_DEVICE_FORMATS
:
938 case IPC_GLB_ENTER_DX_STATE
:
939 case IPC_GLB_GET_MIXER_STREAM_INFO
:
940 case IPC_GLB_MAX_IPC_MESSAGE_TYPE
:
941 case IPC_GLB_RESTORE_CONTEXT
:
942 case IPC_GLB_SHORT_REPLY
:
943 dev_err(hsw
->dev
, "error: message type %d header 0x%x\n",
946 case IPC_GLB_STREAM_MESSAGE
:
947 handled
= hsw_stream_message(hsw
, header
);
949 case IPC_GLB_DEBUG_LOG_MESSAGE
:
950 handled
= hsw_log_message(hsw
, header
);
952 case IPC_GLB_MODULE_OPERATION
:
953 handled
= hsw_module_message(hsw
, header
);
956 dev_err(hsw
->dev
, "error: unexpected type %d hdr 0x%8.8x\n",
964 static irqreturn_t
hsw_irq_thread(int irq
, void *context
)
966 struct sst_dsp
*sst
= (struct sst_dsp
*) context
;
967 struct sst_hsw
*hsw
= sst_dsp_get_thread_context(sst
);
972 spin_lock_irqsave(&sst
->spinlock
, flags
);
974 ipcx
= sst_dsp_ipc_msg_rx(hsw
->dsp
);
975 ipcd
= sst_dsp_shim_read_unlocked(sst
, SST_IPCD
);
977 /* reply message from DSP */
978 if (ipcx
& SST_IPCX_DONE
) {
980 /* Handle Immediate reply from DSP Core */
981 handled
= hsw_process_reply(hsw
, ipcx
);
984 /* clear DONE bit - tell DSP we have completed */
985 sst_dsp_shim_update_bits_unlocked(sst
, SST_IPCX
,
988 /* unmask Done interrupt */
989 sst_dsp_shim_update_bits_unlocked(sst
, SST_IMRX
,
994 /* new message from DSP */
995 if (ipcd
& SST_IPCD_BUSY
) {
997 /* Handle Notification and Delayed reply from DSP Core */
998 handled
= hsw_process_notification(hsw
);
1000 /* clear BUSY bit and set DONE bit - accept new messages */
1002 sst_dsp_shim_update_bits_unlocked(sst
, SST_IPCD
,
1003 SST_IPCD_BUSY
| SST_IPCD_DONE
, SST_IPCD_DONE
);
1005 /* unmask busy interrupt */
1006 sst_dsp_shim_update_bits_unlocked(sst
, SST_IMRX
,
1011 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
1013 /* continue to send any remaining messages... */
1014 queue_kthread_work(&hsw
->kworker
, &hsw
->kwork
);
1019 int sst_hsw_fw_get_version(struct sst_hsw
*hsw
,
1020 struct sst_hsw_ipc_fw_version
*version
)
1024 ret
= ipc_tx_message_wait(hsw
, IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION
),
1025 NULL
, 0, version
, sizeof(*version
));
1027 dev_err(hsw
->dev
, "error: get version failed\n");
1032 /* Mixer Controls */
1033 int sst_hsw_stream_get_volume(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1034 u32 stage_id
, u32 channel
, u32
*volume
)
1039 sst_dsp_read(hsw
->dsp
, volume
,
1040 stream
->reply
.volume_register_address
[channel
],
1047 int sst_hsw_stream_set_volume(struct sst_hsw
*hsw
,
1048 struct sst_hsw_stream
*stream
, u32 stage_id
, u32 channel
, u32 volume
)
1050 struct sst_hsw_ipc_volume_req
*req
;
1054 trace_ipc_request("set stream volume", stream
->reply
.stream_hw_id
);
1056 if (channel
>= 2 && channel
!= SST_HSW_CHANNELS_ALL
)
1059 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) |
1060 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE
);
1061 header
|= (stream
->reply
.stream_hw_id
<< IPC_STR_ID_SHIFT
);
1062 header
|= (IPC_STG_SET_VOLUME
<< IPC_STG_TYPE_SHIFT
);
1063 header
|= (stage_id
<< IPC_STG_ID_SHIFT
);
1065 req
= &stream
->vol_req
;
1066 req
->target_volume
= volume
;
1068 /* set both at same time ? */
1069 if (channel
== SST_HSW_CHANNELS_ALL
) {
1070 if (hsw
->mute
[0] && hsw
->mute
[1]) {
1071 hsw
->mute_volume
[0] = hsw
->mute_volume
[1] = volume
;
1073 } else if (hsw
->mute
[0])
1075 else if (hsw
->mute
[1])
1078 req
->channel
= SST_HSW_CHANNELS_ALL
;
1080 /* set only 1 channel */
1081 if (hsw
->mute
[channel
]) {
1082 hsw
->mute_volume
[channel
] = volume
;
1085 req
->channel
= channel
;
1088 ret
= ipc_tx_message_wait(hsw
, header
, req
, sizeof(*req
), NULL
, 0);
1090 dev_err(hsw
->dev
, "error: set stream volume failed\n");
1097 int sst_hsw_mixer_get_volume(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
,
1103 sst_dsp_read(hsw
->dsp
, volume
,
1104 hsw
->mixer_info
.volume_register_address
[channel
],
1110 /* global mixer volume */
1111 int sst_hsw_mixer_set_volume(struct sst_hsw
*hsw
, u32 stage_id
, u32 channel
,
1114 struct sst_hsw_ipc_volume_req req
;
1118 trace_ipc_request("set mixer volume", volume
);
1120 if (channel
>= 2 && channel
!= SST_HSW_CHANNELS_ALL
)
1123 /* set both at same time ? */
1124 if (channel
== SST_HSW_CHANNELS_ALL
) {
1125 if (hsw
->mute
[0] && hsw
->mute
[1]) {
1126 hsw
->mute_volume
[0] = hsw
->mute_volume
[1] = volume
;
1128 } else if (hsw
->mute
[0])
1130 else if (hsw
->mute
[1])
1133 req
.channel
= SST_HSW_CHANNELS_ALL
;
1135 /* set only 1 channel */
1136 if (hsw
->mute
[channel
]) {
1137 hsw
->mute_volume
[channel
] = volume
;
1140 req
.channel
= channel
;
1143 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) |
1144 IPC_STR_TYPE(IPC_STR_STAGE_MESSAGE
);
1145 header
|= (hsw
->mixer_info
.mixer_hw_id
<< IPC_STR_ID_SHIFT
);
1146 header
|= (IPC_STG_SET_VOLUME
<< IPC_STG_TYPE_SHIFT
);
1147 header
|= (stage_id
<< IPC_STG_ID_SHIFT
);
1149 req
.curve_duration
= hsw
->curve_duration
;
1150 req
.curve_type
= hsw
->curve_type
;
1151 req
.target_volume
= volume
;
1153 ret
= ipc_tx_message_wait(hsw
, header
, &req
, sizeof(req
), NULL
, 0);
1155 dev_err(hsw
->dev
, "error: set mixer volume failed\n");
1163 struct sst_hsw_stream
*sst_hsw_stream_new(struct sst_hsw
*hsw
, int id
,
1164 u32 (*notify_position
)(struct sst_hsw_stream
*stream
, void *data
),
1167 struct sst_hsw_stream
*stream
;
1168 struct sst_dsp
*sst
= hsw
->dsp
;
1169 unsigned long flags
;
1171 stream
= kzalloc(sizeof(*stream
), GFP_KERNEL
);
1175 spin_lock_irqsave(&sst
->spinlock
, flags
);
1176 stream
->reply
.stream_hw_id
= INVALID_STREAM_HW_ID
;
1177 list_add(&stream
->node
, &hsw
->stream_list
);
1178 stream
->notify_position
= notify_position
;
1179 stream
->pdata
= data
;
1181 stream
->host_id
= id
;
1183 /* work to process notification messages */
1184 INIT_WORK(&stream
->notify_work
, hsw_notification_work
);
1185 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
1190 int sst_hsw_stream_free(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1194 struct sst_dsp
*sst
= hsw
->dsp
;
1195 unsigned long flags
;
1198 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to free, ignore it.\n");
1202 /* dont free DSP streams that are not commited */
1203 if (!stream
->commited
)
1206 trace_ipc_request("stream free", stream
->host_id
);
1208 stream
->free_req
.stream_id
= stream
->reply
.stream_hw_id
;
1209 header
= IPC_GLB_TYPE(IPC_GLB_FREE_STREAM
);
1211 ret
= ipc_tx_message_wait(hsw
, header
, &stream
->free_req
,
1212 sizeof(stream
->free_req
), NULL
, 0);
1214 dev_err(hsw
->dev
, "error: free stream %d failed\n",
1215 stream
->free_req
.stream_id
);
1219 trace_hsw_stream_free_req(stream
, &stream
->free_req
);
1222 cancel_work_sync(&stream
->notify_work
);
1223 spin_lock_irqsave(&sst
->spinlock
, flags
);
1224 list_del(&stream
->node
);
1226 spin_unlock_irqrestore(&sst
->spinlock
, flags
);
1231 int sst_hsw_stream_set_bits(struct sst_hsw
*hsw
,
1232 struct sst_hsw_stream
*stream
, enum sst_hsw_bitdepth bits
)
1234 if (stream
->commited
) {
1235 dev_err(hsw
->dev
, "error: stream committed for set bits\n");
1239 stream
->request
.format
.bitdepth
= bits
;
1243 int sst_hsw_stream_set_channels(struct sst_hsw
*hsw
,
1244 struct sst_hsw_stream
*stream
, int channels
)
1246 if (stream
->commited
) {
1247 dev_err(hsw
->dev
, "error: stream committed for set channels\n");
1251 stream
->request
.format
.ch_num
= channels
;
1255 int sst_hsw_stream_set_rate(struct sst_hsw
*hsw
,
1256 struct sst_hsw_stream
*stream
, int rate
)
1258 if (stream
->commited
) {
1259 dev_err(hsw
->dev
, "error: stream committed for set rate\n");
1263 stream
->request
.format
.frequency
= rate
;
1267 int sst_hsw_stream_set_map_config(struct sst_hsw
*hsw
,
1268 struct sst_hsw_stream
*stream
, u32 map
,
1269 enum sst_hsw_channel_config config
)
1271 if (stream
->commited
) {
1272 dev_err(hsw
->dev
, "error: stream committed for set map\n");
1276 stream
->request
.format
.map
= map
;
1277 stream
->request
.format
.config
= config
;
1281 int sst_hsw_stream_set_style(struct sst_hsw
*hsw
,
1282 struct sst_hsw_stream
*stream
, enum sst_hsw_interleaving style
)
1284 if (stream
->commited
) {
1285 dev_err(hsw
->dev
, "error: stream committed for set style\n");
1289 stream
->request
.format
.style
= style
;
1293 int sst_hsw_stream_set_valid(struct sst_hsw
*hsw
,
1294 struct sst_hsw_stream
*stream
, u32 bits
)
1296 if (stream
->commited
) {
1297 dev_err(hsw
->dev
, "error: stream committed for set valid bits\n");
1301 stream
->request
.format
.valid_bit
= bits
;
1305 /* Stream Configuration */
1306 int sst_hsw_stream_format(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1307 enum sst_hsw_stream_path_id path_id
,
1308 enum sst_hsw_stream_type stream_type
,
1309 enum sst_hsw_stream_format format_id
)
1311 if (stream
->commited
) {
1312 dev_err(hsw
->dev
, "error: stream committed for set format\n");
1316 stream
->request
.path_id
= path_id
;
1317 stream
->request
.stream_type
= stream_type
;
1318 stream
->request
.format_id
= format_id
;
1320 trace_hsw_stream_alloc_request(stream
, &stream
->request
);
1325 int sst_hsw_stream_buffer(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1326 u32 ring_pt_address
, u32 num_pages
,
1327 u32 ring_size
, u32 ring_offset
, u32 ring_first_pfn
)
1329 if (stream
->commited
) {
1330 dev_err(hsw
->dev
, "error: stream committed for buffer\n");
1334 stream
->request
.ringinfo
.ring_pt_address
= ring_pt_address
;
1335 stream
->request
.ringinfo
.num_pages
= num_pages
;
1336 stream
->request
.ringinfo
.ring_size
= ring_size
;
1337 stream
->request
.ringinfo
.ring_offset
= ring_offset
;
1338 stream
->request
.ringinfo
.ring_first_pfn
= ring_first_pfn
;
1340 trace_hsw_stream_buffer(stream
);
1345 int sst_hsw_stream_set_module_info(struct sst_hsw
*hsw
,
1346 struct sst_hsw_stream
*stream
, struct sst_module_runtime
*runtime
)
1348 struct sst_hsw_module_map
*map
= &stream
->request
.map
;
1349 struct sst_dsp
*dsp
= sst_hsw_get_dsp(hsw
);
1350 struct sst_module
*module
= runtime
->module
;
1352 if (stream
->commited
) {
1353 dev_err(hsw
->dev
, "error: stream committed for set module\n");
1357 /* only support initial module atm */
1358 map
->module_entries_count
= 1;
1359 map
->module_entries
[0].module_id
= module
->id
;
1360 map
->module_entries
[0].entry_point
= module
->entry
;
1362 stream
->request
.persistent_mem
.offset
=
1363 sst_dsp_get_offset(dsp
, runtime
->persistent_offset
, SST_MEM_DRAM
);
1364 stream
->request
.persistent_mem
.size
= module
->persistent_size
;
1366 stream
->request
.scratch_mem
.offset
=
1367 sst_dsp_get_offset(dsp
, dsp
->scratch_offset
, SST_MEM_DRAM
);
1368 stream
->request
.scratch_mem
.size
= dsp
->scratch_size
;
1370 dev_dbg(hsw
->dev
, "module %d runtime %d using:\n", module
->id
,
1372 dev_dbg(hsw
->dev
, " persistent offset 0x%x bytes 0x%x\n",
1373 stream
->request
.persistent_mem
.offset
,
1374 stream
->request
.persistent_mem
.size
);
1375 dev_dbg(hsw
->dev
, " scratch offset 0x%x bytes 0x%x\n",
1376 stream
->request
.scratch_mem
.offset
,
1377 stream
->request
.scratch_mem
.size
);
1382 int sst_hsw_stream_commit(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1384 struct sst_hsw_ipc_stream_alloc_req
*str_req
= &stream
->request
;
1385 struct sst_hsw_ipc_stream_alloc_reply
*reply
= &stream
->reply
;
1390 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to commit, ignore it.\n");
1394 if (stream
->commited
) {
1395 dev_warn(hsw
->dev
, "warning: stream is already committed, ignore it.\n");
1399 trace_ipc_request("stream alloc", stream
->host_id
);
1401 header
= IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM
);
1403 ret
= ipc_tx_message_wait(hsw
, header
, str_req
, sizeof(*str_req
),
1404 reply
, sizeof(*reply
));
1406 dev_err(hsw
->dev
, "error: stream commit failed\n");
1410 stream
->commited
= 1;
1411 trace_hsw_stream_alloc_reply(stream
);
1416 snd_pcm_uframes_t
sst_hsw_stream_get_old_position(struct sst_hsw
*hsw
,
1417 struct sst_hsw_stream
*stream
)
1419 return stream
->old_position
;
1422 void sst_hsw_stream_set_old_position(struct sst_hsw
*hsw
,
1423 struct sst_hsw_stream
*stream
, snd_pcm_uframes_t val
)
1425 stream
->old_position
= val
;
1428 bool sst_hsw_stream_get_silence_start(struct sst_hsw
*hsw
,
1429 struct sst_hsw_stream
*stream
)
1431 return stream
->play_silence
;
1434 void sst_hsw_stream_set_silence_start(struct sst_hsw
*hsw
,
1435 struct sst_hsw_stream
*stream
, bool val
)
1437 stream
->play_silence
= val
;
1440 /* Stream Information - these calls could be inline but we want the IPC
1441 ABI to be opaque to client PCM drivers to cope with any future ABI changes */
1442 int sst_hsw_mixer_get_info(struct sst_hsw
*hsw
)
1444 struct sst_hsw_ipc_stream_info_reply
*reply
;
1448 reply
= &hsw
->mixer_info
;
1449 header
= IPC_GLB_TYPE(IPC_GLB_GET_MIXER_STREAM_INFO
);
1451 trace_ipc_request("get global mixer info", 0);
1453 ret
= ipc_tx_message_wait(hsw
, header
, NULL
, 0, reply
, sizeof(*reply
));
1455 dev_err(hsw
->dev
, "error: get stream info failed\n");
1459 trace_hsw_mixer_info_reply(reply
);
1464 /* Send stream command */
1465 static int sst_hsw_stream_operations(struct sst_hsw
*hsw
, int type
,
1466 int stream_id
, int wait
)
1470 header
= IPC_GLB_TYPE(IPC_GLB_STREAM_MESSAGE
) | IPC_STR_TYPE(type
);
1471 header
|= (stream_id
<< IPC_STR_ID_SHIFT
);
1474 return ipc_tx_message_wait(hsw
, header
, NULL
, 0, NULL
, 0);
1476 return ipc_tx_message_nowait(hsw
, header
, NULL
, 0);
1479 /* Stream ALSA trigger operations */
1480 int sst_hsw_stream_pause(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1486 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to pause, ignore it.\n");
1490 trace_ipc_request("stream pause", stream
->reply
.stream_hw_id
);
1492 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_PAUSE
,
1493 stream
->reply
.stream_hw_id
, wait
);
1495 dev_err(hsw
->dev
, "error: failed to pause stream %d\n",
1496 stream
->reply
.stream_hw_id
);
1501 int sst_hsw_stream_resume(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
,
1507 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to resume, ignore it.\n");
1511 trace_ipc_request("stream resume", stream
->reply
.stream_hw_id
);
1513 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_RESUME
,
1514 stream
->reply
.stream_hw_id
, wait
);
1516 dev_err(hsw
->dev
, "error: failed to resume stream %d\n",
1517 stream
->reply
.stream_hw_id
);
1522 int sst_hsw_stream_reset(struct sst_hsw
*hsw
, struct sst_hsw_stream
*stream
)
1524 int ret
, tries
= 10;
1527 dev_warn(hsw
->dev
, "warning: stream is NULL, no stream to reset, ignore it.\n");
1531 /* dont reset streams that are not commited */
1532 if (!stream
->commited
)
1535 /* wait for pause to complete before we reset the stream */
1536 while (stream
->running
&& tries
--)
1539 dev_err(hsw
->dev
, "error: reset stream %d still running\n",
1540 stream
->reply
.stream_hw_id
);
1544 trace_ipc_request("stream reset", stream
->reply
.stream_hw_id
);
1546 ret
= sst_hsw_stream_operations(hsw
, IPC_STR_RESET
,
1547 stream
->reply
.stream_hw_id
, 1);
1549 dev_err(hsw
->dev
, "error: failed to reset stream %d\n",
1550 stream
->reply
.stream_hw_id
);
1554 /* Stream pointer positions */
1555 u32
sst_hsw_get_dsp_position(struct sst_hsw
*hsw
,
1556 struct sst_hsw_stream
*stream
)
1560 sst_dsp_read(hsw
->dsp
, &rpos
,
1561 stream
->reply
.read_position_register_address
, sizeof(rpos
));
1566 /* Stream presentation (monotonic) positions */
1567 u64
sst_hsw_get_dsp_presentation_position(struct sst_hsw
*hsw
,
1568 struct sst_hsw_stream
*stream
)
1572 sst_dsp_read(hsw
->dsp
, &ppos
,
1573 stream
->reply
.presentation_position_register_address
,
1579 /* physical BE config */
1580 int sst_hsw_device_set_config(struct sst_hsw
*hsw
,
1581 enum sst_hsw_device_id dev
, enum sst_hsw_device_mclk mclk
,
1582 enum sst_hsw_device_mode mode
, u32 clock_divider
)
1584 struct sst_hsw_ipc_device_config_req config
;
1588 trace_ipc_request("set device config", dev
);
1590 config
.ssp_interface
= dev
;
1591 config
.clock_frequency
= mclk
;
1593 config
.clock_divider
= clock_divider
;
1594 if (mode
== SST_HSW_DEVICE_TDM_CLOCK_MASTER
)
1595 config
.channels
= 4;
1597 config
.channels
= 2;
1599 trace_hsw_device_config_req(&config
);
1601 header
= IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS
);
1603 ret
= ipc_tx_message_wait(hsw
, header
, &config
, sizeof(config
),
1606 dev_err(hsw
->dev
, "error: set device formats failed\n");
1610 EXPORT_SYMBOL_GPL(sst_hsw_device_set_config
);
1613 int sst_hsw_dx_set_state(struct sst_hsw
*hsw
,
1614 enum sst_hsw_dx_state state
, struct sst_hsw_ipc_dx_reply
*dx
)
1619 header
= IPC_GLB_TYPE(IPC_GLB_ENTER_DX_STATE
);
1622 trace_ipc_request("PM enter Dx state", state
);
1624 ret
= ipc_tx_message_wait(hsw
, header
, &state_
, sizeof(state_
),
1627 dev_err(hsw
->dev
, "ipc: error set dx state %d failed\n", state
);
1631 for (item
= 0; item
< dx
->entries_no
; item
++) {
1633 "Item[%d] offset[%x] - size[%x] - source[%x]\n",
1634 item
, dx
->mem_info
[item
].offset
,
1635 dx
->mem_info
[item
].size
,
1636 dx
->mem_info
[item
].source
);
1638 dev_dbg(hsw
->dev
, "ipc: got %d entry numbers for state %d\n",
1639 dx
->entries_no
, state
);
1644 struct sst_module_runtime
*sst_hsw_runtime_module_create(struct sst_hsw
*hsw
,
1645 int mod_id
, int offset
)
1647 struct sst_dsp
*dsp
= hsw
->dsp
;
1648 struct sst_module
*module
;
1649 struct sst_module_runtime
*runtime
;
1652 module
= sst_module_get_from_id(dsp
, mod_id
);
1653 if (module
== NULL
) {
1654 dev_err(dsp
->dev
, "error: failed to get module %d for pcm\n",
1659 runtime
= sst_module_runtime_new(module
, mod_id
, NULL
);
1660 if (runtime
== NULL
) {
1661 dev_err(dsp
->dev
, "error: failed to create module %d runtime\n",
1666 err
= sst_module_runtime_alloc_blocks(runtime
, offset
);
1668 dev_err(dsp
->dev
, "error: failed to alloc blocks for module %d runtime\n",
1670 sst_module_runtime_free(runtime
);
1674 dev_dbg(dsp
->dev
, "runtime id %d created for module %d\n", runtime
->id
,
1679 void sst_hsw_runtime_module_free(struct sst_module_runtime
*runtime
)
1681 sst_module_runtime_free_blocks(runtime
);
1682 sst_module_runtime_free(runtime
);
1686 static int sst_hsw_dx_state_dump(struct sst_hsw
*hsw
)
1688 struct sst_dsp
*sst
= hsw
->dsp
;
1689 u32 item
, offset
, size
;
1692 trace_ipc_request("PM state dump. Items #", SST_HSW_MAX_DX_REGIONS
);
1694 if (hsw
->dx
.entries_no
> SST_HSW_MAX_DX_REGIONS
) {
1696 "error: number of FW context regions greater than %d\n",
1697 SST_HSW_MAX_DX_REGIONS
);
1698 memset(&hsw
->dx
, 0, sizeof(hsw
->dx
));
1702 ret
= sst_dsp_dma_get_channel(sst
, 0);
1704 dev_err(hsw
->dev
, "error: cant allocate dma channel %d\n", ret
);
1708 /* set on-demond mode on engine 0 channel 3 */
1709 sst_dsp_shim_update_bits(sst
, SST_HMDC
,
1710 SST_HMDC_HDDA_E0_ALLCH
| SST_HMDC_HDDA_E1_ALLCH
,
1711 SST_HMDC_HDDA_E0_ALLCH
| SST_HMDC_HDDA_E1_ALLCH
);
1713 for (item
= 0; item
< hsw
->dx
.entries_no
; item
++) {
1714 if (hsw
->dx
.mem_info
[item
].source
== SST_HSW_DX_TYPE_MEMORY_DUMP
1715 && hsw
->dx
.mem_info
[item
].offset
> DSP_DRAM_ADDR_OFFSET
1716 && hsw
->dx
.mem_info
[item
].offset
<
1717 DSP_DRAM_ADDR_OFFSET
+ SST_HSW_DX_CONTEXT_SIZE
) {
1719 offset
= hsw
->dx
.mem_info
[item
].offset
1720 - DSP_DRAM_ADDR_OFFSET
;
1721 size
= (hsw
->dx
.mem_info
[item
].size
+ 3) & (~3);
1723 ret
= sst_dsp_dma_copyfrom(sst
, hsw
->dx_context_paddr
+ offset
,
1724 sst
->addr
.lpe_base
+ offset
, size
);
1727 "error: FW context dump failed\n");
1728 memset(&hsw
->dx
, 0, sizeof(hsw
->dx
));
1735 sst_dsp_dma_put_channel(sst
);
1739 static int sst_hsw_dx_state_restore(struct sst_hsw
*hsw
)
1741 struct sst_dsp
*sst
= hsw
->dsp
;
1742 u32 item
, offset
, size
;
1745 for (item
= 0; item
< hsw
->dx
.entries_no
; item
++) {
1746 if (hsw
->dx
.mem_info
[item
].source
== SST_HSW_DX_TYPE_MEMORY_DUMP
1747 && hsw
->dx
.mem_info
[item
].offset
> DSP_DRAM_ADDR_OFFSET
1748 && hsw
->dx
.mem_info
[item
].offset
<
1749 DSP_DRAM_ADDR_OFFSET
+ SST_HSW_DX_CONTEXT_SIZE
) {
1751 offset
= hsw
->dx
.mem_info
[item
].offset
1752 - DSP_DRAM_ADDR_OFFSET
;
1753 size
= (hsw
->dx
.mem_info
[item
].size
+ 3) & (~3);
1755 ret
= sst_dsp_dma_copyto(sst
, sst
->addr
.lpe_base
+ offset
,
1756 hsw
->dx_context_paddr
+ offset
, size
);
1759 "error: FW context restore failed\n");
1768 static void sst_hsw_drop_all(struct sst_hsw
*hsw
)
1770 struct ipc_message
*msg
, *tmp
;
1771 unsigned long flags
;
1772 int tx_drop_cnt
= 0, rx_drop_cnt
= 0;
1774 /* drop all TX and Rx messages before we stall + reset DSP */
1775 spin_lock_irqsave(&hsw
->dsp
->spinlock
, flags
);
1777 list_for_each_entry_safe(msg
, tmp
, &hsw
->tx_list
, list
) {
1778 list_move(&msg
->list
, &hsw
->empty_list
);
1782 list_for_each_entry_safe(msg
, tmp
, &hsw
->rx_list
, list
) {
1783 list_move(&msg
->list
, &hsw
->empty_list
);
1787 spin_unlock_irqrestore(&hsw
->dsp
->spinlock
, flags
);
1789 if (tx_drop_cnt
|| rx_drop_cnt
)
1790 dev_err(hsw
->dev
, "dropped IPC msg RX=%d, TX=%d\n",
1791 tx_drop_cnt
, rx_drop_cnt
);
1794 int sst_hsw_dsp_load(struct sst_hsw
*hsw
)
1796 struct sst_dsp
*dsp
= hsw
->dsp
;
1797 struct sst_fw
*sst_fw
, *t
;
1800 dev_dbg(hsw
->dev
, "loading audio DSP....");
1802 ret
= sst_dsp_wake(dsp
);
1804 dev_err(hsw
->dev
, "error: failed to wake audio DSP\n");
1808 ret
= sst_dsp_dma_get_channel(dsp
, 0);
1810 dev_err(hsw
->dev
, "error: cant allocate dma channel %d\n", ret
);
1814 list_for_each_entry_safe_reverse(sst_fw
, t
, &dsp
->fw_list
, list
) {
1815 ret
= sst_fw_reload(sst_fw
);
1817 dev_err(hsw
->dev
, "error: SST FW reload failed\n");
1818 sst_dsp_dma_put_channel(dsp
);
1822 ret
= sst_block_alloc_scratch(hsw
->dsp
);
1826 sst_dsp_dma_put_channel(dsp
);
1830 static int sst_hsw_dsp_restore(struct sst_hsw
*hsw
)
1832 struct sst_dsp
*dsp
= hsw
->dsp
;
1835 dev_dbg(hsw
->dev
, "restoring audio DSP....");
1837 ret
= sst_dsp_dma_get_channel(dsp
, 0);
1839 dev_err(hsw
->dev
, "error: cant allocate dma channel %d\n", ret
);
1843 ret
= sst_hsw_dx_state_restore(hsw
);
1845 dev_err(hsw
->dev
, "error: SST FW context restore failed\n");
1846 sst_dsp_dma_put_channel(dsp
);
1849 sst_dsp_dma_put_channel(dsp
);
1851 /* wait for DSP boot completion */
1857 int sst_hsw_dsp_runtime_suspend(struct sst_hsw
*hsw
)
1861 dev_dbg(hsw
->dev
, "audio dsp runtime suspend\n");
1863 ret
= sst_hsw_dx_set_state(hsw
, SST_HSW_DX_STATE_D3
, &hsw
->dx
);
1867 sst_dsp_stall(hsw
->dsp
);
1869 ret
= sst_hsw_dx_state_dump(hsw
);
1873 sst_hsw_drop_all(hsw
);
1878 int sst_hsw_dsp_runtime_sleep(struct sst_hsw
*hsw
)
1880 struct sst_fw
*sst_fw
, *t
;
1881 struct sst_dsp
*dsp
= hsw
->dsp
;
1883 list_for_each_entry_safe(sst_fw
, t
, &dsp
->fw_list
, list
) {
1884 sst_fw_unload(sst_fw
);
1886 sst_block_free_scratch(dsp
);
1888 hsw
->boot_complete
= false;
1895 int sst_hsw_dsp_runtime_resume(struct sst_hsw
*hsw
)
1897 struct device
*dev
= hsw
->dev
;
1900 dev_dbg(dev
, "audio dsp runtime resume\n");
1902 if (hsw
->boot_complete
)
1903 return 1; /* tell caller no action is required */
1905 ret
= sst_hsw_dsp_restore(hsw
);
1907 dev_err(dev
, "error: audio DSP boot failure\n");
1909 sst_hsw_init_module_state(hsw
);
1911 ret
= wait_event_timeout(hsw
->boot_wait
, hsw
->boot_complete
,
1912 msecs_to_jiffies(IPC_BOOT_MSECS
));
1914 dev_err(hsw
->dev
, "error: audio DSP boot timeout IPCD 0x%x IPCX 0x%x\n",
1915 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCD
),
1916 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCX
));
1920 /* Set ADSP SSP port settings */
1921 ret
= sst_hsw_device_set_config(hsw
, SST_HSW_DEVICE_SSP_0
,
1922 SST_HSW_DEVICE_MCLK_FREQ_24_MHZ
,
1923 SST_HSW_DEVICE_CLOCK_MASTER
, 9);
1925 dev_err(dev
, "error: SSP re-initialization failed\n");
1931 static int msg_empty_list_init(struct sst_hsw
*hsw
)
1935 hsw
->msg
= kzalloc(sizeof(struct ipc_message
) *
1936 IPC_EMPTY_LIST_SIZE
, GFP_KERNEL
);
1937 if (hsw
->msg
== NULL
)
1940 for (i
= 0; i
< IPC_EMPTY_LIST_SIZE
; i
++) {
1941 init_waitqueue_head(&hsw
->msg
[i
].waitq
);
1942 list_add(&hsw
->msg
[i
].list
, &hsw
->empty_list
);
1948 struct sst_dsp
*sst_hsw_get_dsp(struct sst_hsw
*hsw
)
1953 void sst_hsw_init_module_state(struct sst_hsw
*hsw
)
1955 struct sst_module
*module
;
1956 enum sst_hsw_module_id id
;
1958 /* the base fw contains several modules */
1959 for (id
= SST_HSW_MODULE_BASE_FW
; id
< SST_HSW_MAX_MODULE_ID
; id
++) {
1960 module
= sst_module_get_from_id(hsw
->dsp
, id
);
1962 /* module waves is active only after being enabled */
1963 if (id
== SST_HSW_MODULE_WAVES
)
1964 module
->state
= SST_MODULE_STATE_INITIALIZED
;
1966 module
->state
= SST_MODULE_STATE_ACTIVE
;
1971 bool sst_hsw_is_module_loaded(struct sst_hsw
*hsw
, u32 module_id
)
1973 struct sst_module
*module
;
1975 module
= sst_module_get_from_id(hsw
->dsp
, module_id
);
1976 if (module
== NULL
|| module
->state
== SST_MODULE_STATE_UNLOADED
)
1982 bool sst_hsw_is_module_active(struct sst_hsw
*hsw
, u32 module_id
)
1984 struct sst_module
*module
;
1986 module
= sst_module_get_from_id(hsw
->dsp
, module_id
);
1987 if (module
!= NULL
&& module
->state
== SST_MODULE_STATE_ACTIVE
)
1993 void sst_hsw_set_module_enabled_rtd3(struct sst_hsw
*hsw
, u32 module_id
)
1995 hsw
->enabled_modules_rtd3
|= (1 << module_id
);
1998 void sst_hsw_set_module_disabled_rtd3(struct sst_hsw
*hsw
, u32 module_id
)
2000 hsw
->enabled_modules_rtd3
&= ~(1 << module_id
);
2003 bool sst_hsw_is_module_enabled_rtd3(struct sst_hsw
*hsw
, u32 module_id
)
2005 return hsw
->enabled_modules_rtd3
& (1 << module_id
);
2008 int sst_hsw_module_load(struct sst_hsw
*hsw
,
2009 u32 module_id
, u32 instance_id
, char *name
)
2012 const struct firmware
*fw
= NULL
;
2013 struct sst_fw
*hsw_sst_fw
;
2014 struct sst_module
*module
;
2015 struct device
*dev
= hsw
->dev
;
2016 struct sst_dsp
*dsp
= hsw
->dsp
;
2018 dev_dbg(dev
, "sst_hsw_module_load id=%d, name='%s'", module_id
, name
);
2020 module
= sst_module_get_from_id(dsp
, module_id
);
2021 if (module
== NULL
) {
2022 /* loading for the first time */
2023 if (module_id
== SST_HSW_MODULE_BASE_FW
) {
2024 /* for base module: use fw requested in acpi probe */
2025 fw
= dsp
->pdata
->fw
;
2027 dev_err(dev
, "request Base fw failed\n");
2031 /* try and load any other optional modules if they are
2032 * available. Use dev_info instead of dev_err in case
2033 * request firmware failed */
2034 ret
= request_firmware(&fw
, name
, dev
);
2036 dev_info(dev
, "fw image %s not available(%d)\n",
2041 hsw_sst_fw
= sst_fw_new(dsp
, fw
, hsw
);
2042 if (hsw_sst_fw
== NULL
) {
2043 dev_err(dev
, "error: failed to load firmware\n");
2047 module
= sst_module_get_from_id(dsp
, module_id
);
2048 if (module
== NULL
) {
2049 dev_err(dev
, "error: no module %d in firmware %s\n",
2053 dev_info(dev
, "module %d (%s) already loaded\n",
2056 /* release fw, but base fw should be released by acpi driver */
2057 if (fw
&& module_id
!= SST_HSW_MODULE_BASE_FW
)
2058 release_firmware(fw
);
2063 int sst_hsw_module_enable(struct sst_hsw
*hsw
,
2064 u32 module_id
, u32 instance_id
)
2068 struct sst_hsw_ipc_module_config config
;
2069 struct sst_module
*module
;
2070 struct sst_module_runtime
*runtime
;
2071 struct device
*dev
= hsw
->dev
;
2072 struct sst_dsp
*dsp
= hsw
->dsp
;
2074 if (!sst_hsw_is_module_loaded(hsw
, module_id
)) {
2075 dev_dbg(dev
, "module %d not loaded\n", module_id
);
2079 if (sst_hsw_is_module_active(hsw
, module_id
)) {
2080 dev_info(dev
, "module %d already enabled\n", module_id
);
2084 module
= sst_module_get_from_id(dsp
, module_id
);
2085 if (module
== NULL
) {
2086 dev_err(dev
, "module %d not valid\n", module_id
);
2090 runtime
= sst_module_runtime_get_from_id(module
, module_id
);
2091 if (runtime
== NULL
) {
2092 dev_err(dev
, "runtime %d not valid", module_id
);
2096 header
= IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION
) |
2097 IPC_MODULE_OPERATION(IPC_MODULE_ENABLE
) |
2098 IPC_MODULE_ID(module_id
);
2099 dev_dbg(dev
, "module enable header: %x\n", header
);
2101 config
.map
.module_entries_count
= 1;
2102 config
.map
.module_entries
[0].module_id
= module
->id
;
2103 config
.map
.module_entries
[0].entry_point
= module
->entry
;
2105 config
.persistent_mem
.offset
=
2106 sst_dsp_get_offset(dsp
,
2107 runtime
->persistent_offset
, SST_MEM_DRAM
);
2108 config
.persistent_mem
.size
= module
->persistent_size
;
2110 config
.scratch_mem
.offset
=
2111 sst_dsp_get_offset(dsp
,
2112 dsp
->scratch_offset
, SST_MEM_DRAM
);
2113 config
.scratch_mem
.size
= module
->scratch_size
;
2114 dev_dbg(dev
, "mod %d enable p:%d @ %x, s:%d @ %x, ep: %x",
2115 config
.map
.module_entries
[0].module_id
,
2116 config
.persistent_mem
.size
,
2117 config
.persistent_mem
.offset
,
2118 config
.scratch_mem
.size
, config
.scratch_mem
.offset
,
2119 config
.map
.module_entries
[0].entry_point
);
2121 ret
= ipc_tx_message_wait(hsw
, header
,
2122 &config
, sizeof(config
), NULL
, 0);
2124 dev_err(dev
, "ipc: module enable failed - %d\n", ret
);
2126 module
->state
= SST_MODULE_STATE_ACTIVE
;
2131 int sst_hsw_module_disable(struct sst_hsw
*hsw
,
2132 u32 module_id
, u32 instance_id
)
2136 struct sst_module
*module
;
2137 struct device
*dev
= hsw
->dev
;
2138 struct sst_dsp
*dsp
= hsw
->dsp
;
2140 if (!sst_hsw_is_module_loaded(hsw
, module_id
)) {
2141 dev_dbg(dev
, "module %d not loaded\n", module_id
);
2145 if (!sst_hsw_is_module_active(hsw
, module_id
)) {
2146 dev_info(dev
, "module %d already disabled\n", module_id
);
2150 module
= sst_module_get_from_id(dsp
, module_id
);
2151 if (module
== NULL
) {
2152 dev_err(dev
, "module %d not valid\n", module_id
);
2156 header
= IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION
) |
2157 IPC_MODULE_OPERATION(IPC_MODULE_DISABLE
) |
2158 IPC_MODULE_ID(module_id
);
2160 ret
= ipc_tx_message_wait(hsw
, header
, NULL
, 0, NULL
, 0);
2162 dev_err(dev
, "module disable failed - %d\n", ret
);
2164 module
->state
= SST_MODULE_STATE_INITIALIZED
;
2169 int sst_hsw_module_set_param(struct sst_hsw
*hsw
,
2170 u32 module_id
, u32 instance_id
, u32 parameter_id
,
2171 u32 param_size
, char *param
)
2174 unsigned char *data
= NULL
;
2176 u32 payload_size
= 0, transfer_parameter_size
= 0;
2177 dma_addr_t dma_addr
= 0;
2178 struct sst_hsw_transfer_parameter
*parameter
;
2179 struct device
*dev
= hsw
->dev
;
2181 header
= IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION
) |
2182 IPC_MODULE_OPERATION(IPC_MODULE_SET_PARAMETER
) |
2183 IPC_MODULE_ID(module_id
);
2184 dev_dbg(dev
, "sst_hsw_module_set_param header=%x\n", header
);
2186 payload_size
= param_size
+
2187 sizeof(struct sst_hsw_transfer_parameter
) -
2188 sizeof(struct sst_hsw_transfer_list
);
2189 dev_dbg(dev
, "parameter size : %d\n", param_size
);
2190 dev_dbg(dev
, "payload size : %d\n", payload_size
);
2192 if (payload_size
<= SST_HSW_IPC_MAX_SHORT_PARAMETER_SIZE
) {
2193 /* short parameter, mailbox can contain data */
2194 dev_dbg(dev
, "transfer parameter size : %d\n",
2195 transfer_parameter_size
);
2197 transfer_parameter_size
= ALIGN(payload_size
, 4);
2198 dev_dbg(dev
, "transfer parameter aligned size : %d\n",
2199 transfer_parameter_size
);
2201 parameter
= kzalloc(transfer_parameter_size
, GFP_KERNEL
);
2202 if (parameter
== NULL
)
2205 memcpy(parameter
->data
, param
, param_size
);
2207 dev_warn(dev
, "transfer parameter size too large!");
2211 parameter
->parameter_id
= parameter_id
;
2212 parameter
->data_size
= param_size
;
2214 ret
= ipc_tx_message_wait(hsw
, header
,
2215 parameter
, transfer_parameter_size
, NULL
, 0);
2217 dev_err(dev
, "ipc: module set parameter failed - %d\n", ret
);
2222 dma_free_coherent(hsw
->dsp
->dma_dev
,
2223 param_size
, (void *)data
, dma_addr
);
2228 static struct sst_dsp_device hsw_dev
= {
2229 .thread
= hsw_irq_thread
,
2230 .ops
= &haswell_ops
,
2233 int sst_hsw_dsp_init(struct device
*dev
, struct sst_pdata
*pdata
)
2235 struct sst_hsw_ipc_fw_version version
;
2236 struct sst_hsw
*hsw
;
2239 dev_dbg(dev
, "initialising Audio DSP IPC\n");
2241 hsw
= devm_kzalloc(dev
, sizeof(*hsw
), GFP_KERNEL
);
2246 INIT_LIST_HEAD(&hsw
->stream_list
);
2247 INIT_LIST_HEAD(&hsw
->tx_list
);
2248 INIT_LIST_HEAD(&hsw
->rx_list
);
2249 INIT_LIST_HEAD(&hsw
->empty_list
);
2250 init_waitqueue_head(&hsw
->boot_wait
);
2251 init_waitqueue_head(&hsw
->wait_txq
);
2253 ret
= msg_empty_list_init(hsw
);
2257 /* start the IPC message thread */
2258 init_kthread_worker(&hsw
->kworker
);
2259 hsw
->tx_thread
= kthread_run(kthread_worker_fn
,
2260 &hsw
->kworker
, "%s",
2261 dev_name(hsw
->dev
));
2262 if (IS_ERR(hsw
->tx_thread
)) {
2263 ret
= PTR_ERR(hsw
->tx_thread
);
2264 dev_err(hsw
->dev
, "error: failed to create message TX task\n");
2267 init_kthread_work(&hsw
->kwork
, ipc_tx_msgs
);
2269 hsw_dev
.thread_context
= hsw
;
2272 hsw
->dsp
= sst_dsp_new(dev
, &hsw_dev
, pdata
);
2273 if (hsw
->dsp
== NULL
) {
2278 /* allocate DMA buffer for context storage */
2279 hsw
->dx_context
= dma_alloc_coherent(hsw
->dsp
->dma_dev
,
2280 SST_HSW_DX_CONTEXT_SIZE
, &hsw
->dx_context_paddr
, GFP_KERNEL
);
2281 if (hsw
->dx_context
== NULL
) {
2286 /* keep the DSP in reset state for base FW loading */
2287 sst_dsp_reset(hsw
->dsp
);
2289 /* load base module and other modules in base firmware image */
2290 ret
= sst_hsw_module_load(hsw
, SST_HSW_MODULE_BASE_FW
, 0, "Base");
2294 /* try to load module waves */
2295 sst_hsw_module_load(hsw
, SST_HSW_MODULE_WAVES
, 0, "intel/IntcPP01.bin");
2297 /* allocate scratch mem regions */
2298 ret
= sst_block_alloc_scratch(hsw
->dsp
);
2302 /* wait for DSP boot completion */
2303 sst_dsp_boot(hsw
->dsp
);
2304 ret
= wait_event_timeout(hsw
->boot_wait
, hsw
->boot_complete
,
2305 msecs_to_jiffies(IPC_BOOT_MSECS
));
2308 dev_err(hsw
->dev
, "error: audio DSP boot timeout IPCD 0x%x IPCX 0x%x\n",
2309 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCD
),
2310 sst_dsp_shim_read_unlocked(hsw
->dsp
, SST_IPCX
));
2314 /* init module state after boot */
2315 sst_hsw_init_module_state(hsw
);
2317 /* get the FW version */
2318 sst_hsw_fw_get_version(hsw
, &version
);
2320 /* get the globalmixer */
2321 ret
= sst_hsw_mixer_get_info(hsw
);
2323 dev_err(hsw
->dev
, "error: failed to get stream info\n");
2331 sst_dsp_reset(hsw
->dsp
);
2332 sst_fw_free_all(hsw
->dsp
);
2334 dma_free_coherent(hsw
->dsp
->dma_dev
, SST_HSW_DX_CONTEXT_SIZE
,
2335 hsw
->dx_context
, hsw
->dx_context_paddr
);
2337 sst_dsp_free(hsw
->dsp
);
2339 kthread_stop(hsw
->tx_thread
);
2345 EXPORT_SYMBOL_GPL(sst_hsw_dsp_init
);
2347 void sst_hsw_dsp_free(struct device
*dev
, struct sst_pdata
*pdata
)
2349 struct sst_hsw
*hsw
= pdata
->dsp
;
2351 sst_dsp_reset(hsw
->dsp
);
2352 sst_fw_free_all(hsw
->dsp
);
2353 dma_free_coherent(hsw
->dsp
->dma_dev
, SST_HSW_DX_CONTEXT_SIZE
,
2354 hsw
->dx_context
, hsw
->dx_context_paddr
);
2355 sst_dsp_free(hsw
->dsp
);
2356 kthread_stop(hsw
->tx_thread
);
2359 EXPORT_SYMBOL_GPL(sst_hsw_dsp_free
);