|
@@ -34,8 +34,9 @@
|
|
#include <sound/asound.h>
|
|
#include <sound/asound.h>
|
|
|
|
|
|
#include "sst-haswell-ipc.h"
|
|
#include "sst-haswell-ipc.h"
|
|
-#include "sst-dsp.h"
|
|
|
|
-#include "sst-dsp-priv.h"
|
|
|
|
|
|
+#include "../common/sst-dsp.h"
|
|
|
|
+#include "../common/sst-dsp-priv.h"
|
|
|
|
+#include "../common/sst-ipc.h"
|
|
|
|
|
|
/* Global Message - Generic */
|
|
/* Global Message - Generic */
|
|
#define IPC_GLB_TYPE_SHIFT 24
|
|
#define IPC_GLB_TYPE_SHIFT 24
|
|
@@ -79,6 +80,15 @@
|
|
#define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT)
|
|
#define IPC_LOG_ID_MASK (0xf << IPC_LOG_ID_SHIFT)
|
|
#define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT)
|
|
#define IPC_LOG_ID(x) (x << IPC_LOG_ID_SHIFT)
|
|
|
|
|
|
|
|
+/* Module Message */
|
|
|
|
+#define IPC_MODULE_OPERATION_SHIFT 20
|
|
|
|
+#define IPC_MODULE_OPERATION_MASK (0xf << IPC_MODULE_OPERATION_SHIFT)
|
|
|
|
+#define IPC_MODULE_OPERATION(x) (x << IPC_MODULE_OPERATION_SHIFT)
|
|
|
|
+
|
|
|
|
+#define IPC_MODULE_ID_SHIFT 16
|
|
|
|
+#define IPC_MODULE_ID_MASK (0xf << IPC_MODULE_ID_SHIFT)
|
|
|
|
+#define IPC_MODULE_ID(x) (x << IPC_MODULE_ID_SHIFT)
|
|
|
|
+
|
|
/* IPC message timeout (msecs) */
|
|
/* IPC message timeout (msecs) */
|
|
#define IPC_TIMEOUT_MSECS 300
|
|
#define IPC_TIMEOUT_MSECS 300
|
|
#define IPC_BOOT_MSECS 200
|
|
#define IPC_BOOT_MSECS 200
|
|
@@ -115,6 +125,7 @@ enum ipc_glb_type {
|
|
IPC_GLB_ENTER_DX_STATE = 12,
|
|
IPC_GLB_ENTER_DX_STATE = 12,
|
|
IPC_GLB_GET_MIXER_STREAM_INFO = 13, /* Request mixer stream params */
|
|
IPC_GLB_GET_MIXER_STREAM_INFO = 13, /* Request mixer stream params */
|
|
IPC_GLB_DEBUG_LOG_MESSAGE = 14, /* Message to or from the debug logger. */
|
|
IPC_GLB_DEBUG_LOG_MESSAGE = 14, /* Message to or from the debug logger. */
|
|
|
|
+ IPC_GLB_MODULE_OPERATION = 15, /* Message to loadable fw module */
|
|
IPC_GLB_REQUEST_TRANSFER = 16, /* < Request Transfer for host */
|
|
IPC_GLB_REQUEST_TRANSFER = 16, /* < Request Transfer for host */
|
|
IPC_GLB_MAX_IPC_MESSAGE_TYPE = 17, /* Maximum message number */
|
|
IPC_GLB_MAX_IPC_MESSAGE_TYPE = 17, /* Maximum message number */
|
|
};
|
|
};
|
|
@@ -133,6 +144,16 @@ enum ipc_glb_reply {
|
|
IPC_GLB_REPLY_SOURCE_NOT_STARTED = 10, /* Source was not started. */
|
|
IPC_GLB_REPLY_SOURCE_NOT_STARTED = 10, /* Source was not started. */
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+enum ipc_module_operation {
|
|
|
|
+ IPC_MODULE_NOTIFICATION = 0,
|
|
|
|
+ IPC_MODULE_ENABLE = 1,
|
|
|
|
+ IPC_MODULE_DISABLE = 2,
|
|
|
|
+ IPC_MODULE_GET_PARAMETER = 3,
|
|
|
|
+ IPC_MODULE_SET_PARAMETER = 4,
|
|
|
|
+ IPC_MODULE_GET_INFO = 5,
|
|
|
|
+ IPC_MODULE_MAX_MESSAGE
|
|
|
|
+};
|
|
|
|
+
|
|
/* Stream Message - Types */
|
|
/* Stream Message - Types */
|
|
enum ipc_str_operation {
|
|
enum ipc_str_operation {
|
|
IPC_STR_RESET = 0,
|
|
IPC_STR_RESET = 0,
|
|
@@ -190,23 +211,6 @@ struct sst_hsw_ipc_fw_ready {
|
|
u8 fw_info[IPC_MAX_MAILBOX_BYTES - 5 * sizeof(u32)];
|
|
u8 fw_info[IPC_MAX_MAILBOX_BYTES - 5 * sizeof(u32)];
|
|
} __attribute__((packed));
|
|
} __attribute__((packed));
|
|
|
|
|
|
-struct ipc_message {
|
|
|
|
- struct list_head list;
|
|
|
|
- u32 header;
|
|
|
|
-
|
|
|
|
- /* direction wrt host CPU */
|
|
|
|
- char tx_data[IPC_MAX_MAILBOX_BYTES];
|
|
|
|
- size_t tx_size;
|
|
|
|
- char rx_data[IPC_MAX_MAILBOX_BYTES];
|
|
|
|
- size_t rx_size;
|
|
|
|
-
|
|
|
|
- wait_queue_head_t waitq;
|
|
|
|
- bool pending;
|
|
|
|
- bool complete;
|
|
|
|
- bool wait;
|
|
|
|
- int errno;
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
struct sst_hsw_stream;
|
|
struct sst_hsw_stream;
|
|
struct sst_hsw;
|
|
struct sst_hsw;
|
|
|
|
|
|
@@ -305,18 +309,19 @@ struct sst_hsw {
|
|
bool shutdown;
|
|
bool shutdown;
|
|
|
|
|
|
/* IPC messaging */
|
|
/* IPC messaging */
|
|
- struct list_head tx_list;
|
|
|
|
- struct list_head rx_list;
|
|
|
|
- struct list_head empty_list;
|
|
|
|
- wait_queue_head_t wait_txq;
|
|
|
|
- struct task_struct *tx_thread;
|
|
|
|
- struct kthread_worker kworker;
|
|
|
|
- struct kthread_work kwork;
|
|
|
|
- bool pending;
|
|
|
|
- struct ipc_message *msg;
|
|
|
|
|
|
+ struct sst_generic_ipc ipc;
|
|
|
|
|
|
/* FW log stream */
|
|
/* FW log stream */
|
|
struct sst_hsw_log_stream log_stream;
|
|
struct sst_hsw_log_stream log_stream;
|
|
|
|
+
|
|
|
|
+ /* flags bit field to track module state when resume from RTD3,
|
|
|
|
+ * each bit represent state (enabled/disabled) of single module */
|
|
|
|
+ u32 enabled_modules_rtd3;
|
|
|
|
+
|
|
|
|
+ /* buffer to store parameter lines */
|
|
|
|
+ u32 param_idx_w; /* write index */
|
|
|
|
+ u32 param_idx_r; /* read index */
|
|
|
|
+ u8 param_buf[WAVES_PARAM_LINES][WAVES_PARAM_COUNT];
|
|
};
|
|
};
|
|
|
|
|
|
#define CREATE_TRACE_POINTS
|
|
#define CREATE_TRACE_POINTS
|
|
@@ -352,6 +357,16 @@ static inline u32 msg_get_notify_reason(u32 msg)
|
|
return (msg & IPC_STG_TYPE_MASK) >> IPC_STG_TYPE_SHIFT;
|
|
return (msg & IPC_STG_TYPE_MASK) >> IPC_STG_TYPE_SHIFT;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static inline u32 msg_get_module_operation(u32 msg)
|
|
|
|
+{
|
|
|
|
+ return (msg & IPC_MODULE_OPERATION_MASK) >> IPC_MODULE_OPERATION_SHIFT;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static inline u32 msg_get_module_id(u32 msg)
|
|
|
|
+{
|
|
|
|
+ return (msg & IPC_MODULE_ID_MASK) >> IPC_MODULE_ID_SHIFT;
|
|
|
|
+}
|
|
|
|
+
|
|
u32 create_channel_map(enum sst_hsw_channel_config config)
|
|
u32 create_channel_map(enum sst_hsw_channel_config config)
|
|
{
|
|
{
|
|
switch (config) {
|
|
switch (config) {
|
|
@@ -417,159 +432,6 @@ static struct sst_hsw_stream *get_stream_by_id(struct sst_hsw *hsw,
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
|
|
|
|
-static void ipc_shim_dbg(struct sst_hsw *hsw, const char *text)
|
|
|
|
-{
|
|
|
|
- struct sst_dsp *sst = hsw->dsp;
|
|
|
|
- u32 isr, ipcd, imrx, ipcx;
|
|
|
|
-
|
|
|
|
- ipcx = sst_dsp_shim_read_unlocked(sst, SST_IPCX);
|
|
|
|
- isr = sst_dsp_shim_read_unlocked(sst, SST_ISRX);
|
|
|
|
- ipcd = sst_dsp_shim_read_unlocked(sst, SST_IPCD);
|
|
|
|
- imrx = sst_dsp_shim_read_unlocked(sst, SST_IMRX);
|
|
|
|
-
|
|
|
|
- dev_err(hsw->dev, "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n",
|
|
|
|
- text, ipcx, isr, ipcd, imrx);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/* locks held by caller */
|
|
|
|
-static struct ipc_message *msg_get_empty(struct sst_hsw *hsw)
|
|
|
|
-{
|
|
|
|
- struct ipc_message *msg = NULL;
|
|
|
|
-
|
|
|
|
- if (!list_empty(&hsw->empty_list)) {
|
|
|
|
- msg = list_first_entry(&hsw->empty_list, struct ipc_message,
|
|
|
|
- list);
|
|
|
|
- list_del(&msg->list);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return msg;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void ipc_tx_msgs(struct kthread_work *work)
|
|
|
|
-{
|
|
|
|
- struct sst_hsw *hsw =
|
|
|
|
- container_of(work, struct sst_hsw, kwork);
|
|
|
|
- struct ipc_message *msg;
|
|
|
|
- unsigned long flags;
|
|
|
|
- u32 ipcx;
|
|
|
|
-
|
|
|
|
- spin_lock_irqsave(&hsw->dsp->spinlock, flags);
|
|
|
|
-
|
|
|
|
- if (list_empty(&hsw->tx_list) || hsw->pending) {
|
|
|
|
- spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /* if the DSP is busy, we will TX messages after IRQ.
|
|
|
|
- * also postpone if we are in the middle of procesing completion irq*/
|
|
|
|
- ipcx = sst_dsp_shim_read_unlocked(hsw->dsp, SST_IPCX);
|
|
|
|
- if (ipcx & (SST_IPCX_BUSY | SST_IPCX_DONE)) {
|
|
|
|
- spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- msg = list_first_entry(&hsw->tx_list, struct ipc_message, list);
|
|
|
|
-
|
|
|
|
- list_move(&msg->list, &hsw->rx_list);
|
|
|
|
-
|
|
|
|
- /* send the message */
|
|
|
|
- sst_dsp_outbox_write(hsw->dsp, msg->tx_data, msg->tx_size);
|
|
|
|
- sst_dsp_ipc_msg_tx(hsw->dsp, msg->header | SST_IPCX_BUSY);
|
|
|
|
-
|
|
|
|
- spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-/* locks held by caller */
|
|
|
|
-static void tx_msg_reply_complete(struct sst_hsw *hsw, struct ipc_message *msg)
|
|
|
|
-{
|
|
|
|
- msg->complete = true;
|
|
|
|
- trace_ipc_reply("completed", msg->header);
|
|
|
|
-
|
|
|
|
- if (!msg->wait)
|
|
|
|
- list_add_tail(&msg->list, &hsw->empty_list);
|
|
|
|
- else
|
|
|
|
- wake_up(&msg->waitq);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static int tx_wait_done(struct sst_hsw *hsw, struct ipc_message *msg,
|
|
|
|
- void *rx_data)
|
|
|
|
-{
|
|
|
|
- unsigned long flags;
|
|
|
|
- int ret;
|
|
|
|
-
|
|
|
|
- /* wait for DSP completion (in all cases atm inc pending) */
|
|
|
|
- ret = wait_event_timeout(msg->waitq, msg->complete,
|
|
|
|
- msecs_to_jiffies(IPC_TIMEOUT_MSECS));
|
|
|
|
-
|
|
|
|
- spin_lock_irqsave(&hsw->dsp->spinlock, flags);
|
|
|
|
- if (ret == 0) {
|
|
|
|
- ipc_shim_dbg(hsw, "message timeout");
|
|
|
|
-
|
|
|
|
- trace_ipc_error("error message timeout for", msg->header);
|
|
|
|
- list_del(&msg->list);
|
|
|
|
- ret = -ETIMEDOUT;
|
|
|
|
- } else {
|
|
|
|
-
|
|
|
|
- /* copy the data returned from DSP */
|
|
|
|
- if (msg->rx_size)
|
|
|
|
- memcpy(rx_data, msg->rx_data, msg->rx_size);
|
|
|
|
- ret = msg->errno;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- list_add_tail(&msg->list, &hsw->empty_list);
|
|
|
|
- spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
|
|
|
|
- return ret;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static int ipc_tx_message(struct sst_hsw *hsw, u32 header, void *tx_data,
|
|
|
|
- size_t tx_bytes, void *rx_data, size_t rx_bytes, int wait)
|
|
|
|
-{
|
|
|
|
- struct ipc_message *msg;
|
|
|
|
- unsigned long flags;
|
|
|
|
-
|
|
|
|
- spin_lock_irqsave(&hsw->dsp->spinlock, flags);
|
|
|
|
-
|
|
|
|
- msg = msg_get_empty(hsw);
|
|
|
|
- if (msg == NULL) {
|
|
|
|
- spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
|
|
|
|
- return -EBUSY;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (tx_bytes)
|
|
|
|
- memcpy(msg->tx_data, tx_data, tx_bytes);
|
|
|
|
-
|
|
|
|
- msg->header = header;
|
|
|
|
- msg->tx_size = tx_bytes;
|
|
|
|
- msg->rx_size = rx_bytes;
|
|
|
|
- msg->wait = wait;
|
|
|
|
- msg->errno = 0;
|
|
|
|
- msg->pending = false;
|
|
|
|
- msg->complete = false;
|
|
|
|
-
|
|
|
|
- list_add_tail(&msg->list, &hsw->tx_list);
|
|
|
|
- spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
|
|
|
|
-
|
|
|
|
- queue_kthread_work(&hsw->kworker, &hsw->kwork);
|
|
|
|
-
|
|
|
|
- if (wait)
|
|
|
|
- return tx_wait_done(hsw, msg, rx_data);
|
|
|
|
- else
|
|
|
|
- return 0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static inline int ipc_tx_message_wait(struct sst_hsw *hsw, u32 header,
|
|
|
|
- void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes)
|
|
|
|
-{
|
|
|
|
- return ipc_tx_message(hsw, header, tx_data, tx_bytes, rx_data,
|
|
|
|
- rx_bytes, 1);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static inline int ipc_tx_message_nowait(struct sst_hsw *hsw, u32 header,
|
|
|
|
- void *tx_data, size_t tx_bytes)
|
|
|
|
-{
|
|
|
|
- return ipc_tx_message(hsw, header, tx_data, tx_bytes, NULL, 0, 0);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static void hsw_fw_ready(struct sst_hsw *hsw, u32 header)
|
|
static void hsw_fw_ready(struct sst_hsw *hsw, u32 header)
|
|
{
|
|
{
|
|
struct sst_hsw_ipc_fw_ready fw_ready;
|
|
struct sst_hsw_ipc_fw_ready fw_ready;
|
|
@@ -604,7 +466,7 @@ static void hsw_fw_ready(struct sst_hsw *hsw, u32 header)
|
|
/* log the FW version info got from the mailbox here. */
|
|
/* log the FW version info got from the mailbox here. */
|
|
memcpy(fw_info, fw_ready.fw_info, fw_ready.fw_info_size);
|
|
memcpy(fw_info, fw_ready.fw_info, fw_ready.fw_info_size);
|
|
pinfo = &fw_info[0];
|
|
pinfo = &fw_info[0];
|
|
- for (i = 0; i < sizeof(tmp) / sizeof(char *); i++)
|
|
|
|
|
|
+ for (i = 0; i < ARRAY_SIZE(tmp); i++)
|
|
tmp[i] = strsep(&pinfo, " ");
|
|
tmp[i] = strsep(&pinfo, " ");
|
|
dev_info(hsw->dev, "FW loaded, mailbox readback FW info: type %s, - "
|
|
dev_info(hsw->dev, "FW loaded, mailbox readback FW info: type %s, - "
|
|
"version: %s.%s, build %s, source commit id: %s\n",
|
|
"version: %s.%s, build %s, source commit id: %s\n",
|
|
@@ -657,27 +519,6 @@ static void hsw_notification_work(struct work_struct *work)
|
|
sst_dsp_shim_update_bits(hsw->dsp, SST_IMRX, SST_IMRX_BUSY, 0);
|
|
sst_dsp_shim_update_bits(hsw->dsp, SST_IMRX, SST_IMRX_BUSY, 0);
|
|
}
|
|
}
|
|
|
|
|
|
-static struct ipc_message *reply_find_msg(struct sst_hsw *hsw, u32 header)
|
|
|
|
-{
|
|
|
|
- struct ipc_message *msg;
|
|
|
|
-
|
|
|
|
- /* clear reply bits & status bits */
|
|
|
|
- header &= ~(IPC_STATUS_MASK | IPC_GLB_REPLY_MASK);
|
|
|
|
-
|
|
|
|
- if (list_empty(&hsw->rx_list)) {
|
|
|
|
- dev_err(hsw->dev, "error: rx list empty but received 0x%x\n",
|
|
|
|
- header);
|
|
|
|
- return NULL;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- list_for_each_entry(msg, &hsw->rx_list, list) {
|
|
|
|
- if (msg->header == header)
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return NULL;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static void hsw_stream_update(struct sst_hsw *hsw, struct ipc_message *msg)
|
|
static void hsw_stream_update(struct sst_hsw *hsw, struct ipc_message *msg)
|
|
{
|
|
{
|
|
struct sst_hsw_stream *stream;
|
|
struct sst_hsw_stream *stream;
|
|
@@ -716,7 +557,7 @@ static int hsw_process_reply(struct sst_hsw *hsw, u32 header)
|
|
|
|
|
|
trace_ipc_reply("processing -->", header);
|
|
trace_ipc_reply("processing -->", header);
|
|
|
|
|
|
- msg = reply_find_msg(hsw, header);
|
|
|
|
|
|
+ msg = sst_ipc_reply_find_msg(&hsw->ipc, header);
|
|
if (msg == NULL) {
|
|
if (msg == NULL) {
|
|
trace_ipc_error("error: can't find message header", header);
|
|
trace_ipc_error("error: can't find message header", header);
|
|
return -EIO;
|
|
return -EIO;
|
|
@@ -727,14 +568,14 @@ static int hsw_process_reply(struct sst_hsw *hsw, u32 header)
|
|
case IPC_GLB_REPLY_PENDING:
|
|
case IPC_GLB_REPLY_PENDING:
|
|
trace_ipc_pending_reply("received", header);
|
|
trace_ipc_pending_reply("received", header);
|
|
msg->pending = true;
|
|
msg->pending = true;
|
|
- hsw->pending = true;
|
|
|
|
|
|
+ hsw->ipc.pending = true;
|
|
return 1;
|
|
return 1;
|
|
case IPC_GLB_REPLY_SUCCESS:
|
|
case IPC_GLB_REPLY_SUCCESS:
|
|
if (msg->pending) {
|
|
if (msg->pending) {
|
|
trace_ipc_pending_reply("completed", header);
|
|
trace_ipc_pending_reply("completed", header);
|
|
sst_dsp_inbox_read(hsw->dsp, msg->rx_data,
|
|
sst_dsp_inbox_read(hsw->dsp, msg->rx_data,
|
|
msg->rx_size);
|
|
msg->rx_size);
|
|
- hsw->pending = false;
|
|
|
|
|
|
+ hsw->ipc.pending = false;
|
|
} else {
|
|
} else {
|
|
/* copy data from the DSP */
|
|
/* copy data from the DSP */
|
|
sst_dsp_outbox_read(hsw->dsp, msg->rx_data,
|
|
sst_dsp_outbox_read(hsw->dsp, msg->rx_data,
|
|
@@ -790,11 +631,36 @@ static int hsw_process_reply(struct sst_hsw *hsw, u32 header)
|
|
|
|
|
|
/* wake up and return the error if we have waiters on this message ? */
|
|
/* wake up and return the error if we have waiters on this message ? */
|
|
list_del(&msg->list);
|
|
list_del(&msg->list);
|
|
- tx_msg_reply_complete(hsw, msg);
|
|
|
|
|
|
+ sst_ipc_tx_msg_reply_complete(&hsw->ipc, msg);
|
|
|
|
|
|
return 1;
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static int hsw_module_message(struct sst_hsw *hsw, u32 header)
|
|
|
|
+{
|
|
|
|
+ u32 operation, module_id;
|
|
|
|
+ int handled = 0;
|
|
|
|
+
|
|
|
|
+ operation = msg_get_module_operation(header);
|
|
|
|
+ module_id = msg_get_module_id(header);
|
|
|
|
+ dev_dbg(hsw->dev, "received module message header: 0x%8.8x\n",
|
|
|
|
+ header);
|
|
|
|
+ dev_dbg(hsw->dev, "operation: 0x%8.8x module_id: 0x%8.8x\n",
|
|
|
|
+ operation, module_id);
|
|
|
|
+
|
|
|
|
+ switch (operation) {
|
|
|
|
+ case IPC_MODULE_NOTIFICATION:
|
|
|
|
+ dev_dbg(hsw->dev, "module notification received");
|
|
|
|
+ handled = 1;
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ handled = hsw_process_reply(hsw, header);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return handled;
|
|
|
|
+}
|
|
|
|
+
|
|
static int hsw_stream_message(struct sst_hsw *hsw, u32 header)
|
|
static int hsw_stream_message(struct sst_hsw *hsw, u32 header)
|
|
{
|
|
{
|
|
u32 stream_msg, stream_id, stage_type;
|
|
u32 stream_msg, stream_id, stage_type;
|
|
@@ -890,6 +756,9 @@ static int hsw_process_notification(struct sst_hsw *hsw)
|
|
case IPC_GLB_DEBUG_LOG_MESSAGE:
|
|
case IPC_GLB_DEBUG_LOG_MESSAGE:
|
|
handled = hsw_log_message(hsw, header);
|
|
handled = hsw_log_message(hsw, header);
|
|
break;
|
|
break;
|
|
|
|
+ case IPC_GLB_MODULE_OPERATION:
|
|
|
|
+ handled = hsw_module_message(hsw, header);
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
dev_err(hsw->dev, "error: unexpected type %d hdr 0x%8.8x\n",
|
|
dev_err(hsw->dev, "error: unexpected type %d hdr 0x%8.8x\n",
|
|
type, header);
|
|
type, header);
|
|
@@ -903,6 +772,7 @@ static irqreturn_t hsw_irq_thread(int irq, void *context)
|
|
{
|
|
{
|
|
struct sst_dsp *sst = (struct sst_dsp *) context;
|
|
struct sst_dsp *sst = (struct sst_dsp *) context;
|
|
struct sst_hsw *hsw = sst_dsp_get_thread_context(sst);
|
|
struct sst_hsw *hsw = sst_dsp_get_thread_context(sst);
|
|
|
|
+ struct sst_generic_ipc *ipc = &hsw->ipc;
|
|
u32 ipcx, ipcd;
|
|
u32 ipcx, ipcd;
|
|
int handled;
|
|
int handled;
|
|
unsigned long flags;
|
|
unsigned long flags;
|
|
@@ -949,7 +819,7 @@ static irqreturn_t hsw_irq_thread(int irq, void *context)
|
|
spin_unlock_irqrestore(&sst->spinlock, flags);
|
|
spin_unlock_irqrestore(&sst->spinlock, flags);
|
|
|
|
|
|
/* continue to send any remaining messages... */
|
|
/* continue to send any remaining messages... */
|
|
- queue_kthread_work(&hsw->kworker, &hsw->kwork);
|
|
|
|
|
|
+ queue_kthread_work(&ipc->kworker, &ipc->kwork);
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
return IRQ_HANDLED;
|
|
}
|
|
}
|
|
@@ -959,7 +829,8 @@ int sst_hsw_fw_get_version(struct sst_hsw *hsw,
|
|
{
|
|
{
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION),
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc,
|
|
|
|
+ IPC_GLB_TYPE(IPC_GLB_GET_FW_VERSION),
|
|
NULL, 0, version, sizeof(*version));
|
|
NULL, 0, version, sizeof(*version));
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
dev_err(hsw->dev, "error: get version failed\n");
|
|
dev_err(hsw->dev, "error: get version failed\n");
|
|
@@ -1023,7 +894,8 @@ int sst_hsw_stream_set_volume(struct sst_hsw *hsw,
|
|
req->channel = channel;
|
|
req->channel = channel;
|
|
}
|
|
}
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, header, req, sizeof(*req), NULL, 0);
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, req,
|
|
|
|
+ sizeof(*req), NULL, 0);
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
dev_err(hsw->dev, "error: set stream volume failed\n");
|
|
dev_err(hsw->dev, "error: set stream volume failed\n");
|
|
return ret;
|
|
return ret;
|
|
@@ -1088,7 +960,8 @@ int sst_hsw_mixer_set_volume(struct sst_hsw *hsw, u32 stage_id, u32 channel,
|
|
req.curve_type = hsw->curve_type;
|
|
req.curve_type = hsw->curve_type;
|
|
req.target_volume = volume;
|
|
req.target_volume = volume;
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, header, &req, sizeof(req), NULL, 0);
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &req,
|
|
|
|
+ sizeof(req), NULL, 0);
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
dev_err(hsw->dev, "error: set mixer volume failed\n");
|
|
dev_err(hsw->dev, "error: set mixer volume failed\n");
|
|
return ret;
|
|
return ret;
|
|
@@ -1146,7 +1019,7 @@ int sst_hsw_stream_free(struct sst_hsw *hsw, struct sst_hsw_stream *stream)
|
|
stream->free_req.stream_id = stream->reply.stream_hw_id;
|
|
stream->free_req.stream_id = stream->reply.stream_hw_id;
|
|
header = IPC_GLB_TYPE(IPC_GLB_FREE_STREAM);
|
|
header = IPC_GLB_TYPE(IPC_GLB_FREE_STREAM);
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, header, &stream->free_req,
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &stream->free_req,
|
|
sizeof(stream->free_req), NULL, 0);
|
|
sizeof(stream->free_req), NULL, 0);
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
dev_err(hsw->dev, "error: free stream %d failed\n",
|
|
dev_err(hsw->dev, "error: free stream %d failed\n",
|
|
@@ -1338,8 +1211,8 @@ int sst_hsw_stream_commit(struct sst_hsw *hsw, struct sst_hsw_stream *stream)
|
|
|
|
|
|
header = IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM);
|
|
header = IPC_GLB_TYPE(IPC_GLB_ALLOCATE_STREAM);
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, header, str_req, sizeof(*str_req),
|
|
|
|
- reply, sizeof(*reply));
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, str_req,
|
|
|
|
+ sizeof(*str_req), reply, sizeof(*reply));
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
dev_err(hsw->dev, "error: stream commit failed\n");
|
|
dev_err(hsw->dev, "error: stream commit failed\n");
|
|
return ret;
|
|
return ret;
|
|
@@ -1388,7 +1261,8 @@ int sst_hsw_mixer_get_info(struct sst_hsw *hsw)
|
|
|
|
|
|
trace_ipc_request("get global mixer info", 0);
|
|
trace_ipc_request("get global mixer info", 0);
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, header, NULL, 0, reply, sizeof(*reply));
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, NULL, 0,
|
|
|
|
+ reply, sizeof(*reply));
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
dev_err(hsw->dev, "error: get stream info failed\n");
|
|
dev_err(hsw->dev, "error: get stream info failed\n");
|
|
return ret;
|
|
return ret;
|
|
@@ -1409,9 +1283,10 @@ static int sst_hsw_stream_operations(struct sst_hsw *hsw, int type,
|
|
header |= (stream_id << IPC_STR_ID_SHIFT);
|
|
header |= (stream_id << IPC_STR_ID_SHIFT);
|
|
|
|
|
|
if (wait)
|
|
if (wait)
|
|
- return ipc_tx_message_wait(hsw, header, NULL, 0, NULL, 0);
|
|
|
|
|
|
+ return sst_ipc_tx_message_wait(&hsw->ipc, header,
|
|
|
|
+ NULL, 0, NULL, 0);
|
|
else
|
|
else
|
|
- return ipc_tx_message_nowait(hsw, header, NULL, 0);
|
|
|
|
|
|
+ return sst_ipc_tx_message_nowait(&hsw->ipc, header, NULL, 0);
|
|
}
|
|
}
|
|
|
|
|
|
/* Stream ALSA trigger operations */
|
|
/* Stream ALSA trigger operations */
|
|
@@ -1538,8 +1413,8 @@ int sst_hsw_device_set_config(struct sst_hsw *hsw,
|
|
|
|
|
|
header = IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS);
|
|
header = IPC_GLB_TYPE(IPC_GLB_SET_DEVICE_FORMATS);
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, header, &config, sizeof(config),
|
|
|
|
- NULL, 0);
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &config,
|
|
|
|
+ sizeof(config), NULL, 0);
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
dev_err(hsw->dev, "error: set device formats failed\n");
|
|
dev_err(hsw->dev, "error: set device formats failed\n");
|
|
|
|
|
|
@@ -1559,8 +1434,8 @@ int sst_hsw_dx_set_state(struct sst_hsw *hsw,
|
|
|
|
|
|
trace_ipc_request("PM enter Dx state", state);
|
|
trace_ipc_request("PM enter Dx state", state);
|
|
|
|
|
|
- ret = ipc_tx_message_wait(hsw, header, &state_, sizeof(state_),
|
|
|
|
- dx, sizeof(*dx));
|
|
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, &state_,
|
|
|
|
+ sizeof(state_), dx, sizeof(*dx));
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
dev_err(hsw->dev, "ipc: error set dx state %d failed\n", state);
|
|
dev_err(hsw->dev, "ipc: error set dx state %d failed\n", state);
|
|
return ret;
|
|
return ret;
|
|
@@ -1703,32 +1578,6 @@ static int sst_hsw_dx_state_restore(struct sst_hsw *hsw)
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-static void sst_hsw_drop_all(struct sst_hsw *hsw)
|
|
|
|
-{
|
|
|
|
- struct ipc_message *msg, *tmp;
|
|
|
|
- unsigned long flags;
|
|
|
|
- int tx_drop_cnt = 0, rx_drop_cnt = 0;
|
|
|
|
-
|
|
|
|
- /* drop all TX and Rx messages before we stall + reset DSP */
|
|
|
|
- spin_lock_irqsave(&hsw->dsp->spinlock, flags);
|
|
|
|
-
|
|
|
|
- list_for_each_entry_safe(msg, tmp, &hsw->tx_list, list) {
|
|
|
|
- list_move(&msg->list, &hsw->empty_list);
|
|
|
|
- tx_drop_cnt++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- list_for_each_entry_safe(msg, tmp, &hsw->rx_list, list) {
|
|
|
|
- list_move(&msg->list, &hsw->empty_list);
|
|
|
|
- rx_drop_cnt++;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- spin_unlock_irqrestore(&hsw->dsp->spinlock, flags);
|
|
|
|
-
|
|
|
|
- if (tx_drop_cnt || rx_drop_cnt)
|
|
|
|
- dev_err(hsw->dev, "dropped IPC msg RX=%d, TX=%d\n",
|
|
|
|
- tx_drop_cnt, rx_drop_cnt);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
int sst_hsw_dsp_load(struct sst_hsw *hsw)
|
|
int sst_hsw_dsp_load(struct sst_hsw *hsw)
|
|
{
|
|
{
|
|
struct sst_dsp *dsp = hsw->dsp;
|
|
struct sst_dsp *dsp = hsw->dsp;
|
|
@@ -1808,7 +1657,7 @@ int sst_hsw_dsp_runtime_suspend(struct sst_hsw *hsw)
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
return ret;
|
|
return ret;
|
|
|
|
|
|
- sst_hsw_drop_all(hsw);
|
|
|
|
|
|
+ sst_ipc_drop_all(&hsw->ipc);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
@@ -1844,6 +1693,8 @@ int sst_hsw_dsp_runtime_resume(struct sst_hsw *hsw)
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
dev_err(dev, "error: audio DSP boot failure\n");
|
|
dev_err(dev, "error: audio DSP boot failure\n");
|
|
|
|
|
|
|
|
+ sst_hsw_init_module_state(hsw);
|
|
|
|
+
|
|
ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete,
|
|
ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete,
|
|
msecs_to_jiffies(IPC_BOOT_MSECS));
|
|
msecs_to_jiffies(IPC_BOOT_MSECS));
|
|
if (ret == 0) {
|
|
if (ret == 0) {
|
|
@@ -1864,26 +1715,345 @@ int sst_hsw_dsp_runtime_resume(struct sst_hsw *hsw)
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-static int msg_empty_list_init(struct sst_hsw *hsw)
|
|
|
|
|
|
+struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw)
|
|
{
|
|
{
|
|
- int i;
|
|
|
|
|
|
+ return hsw->dsp;
|
|
|
|
+}
|
|
|
|
|
|
- hsw->msg = kzalloc(sizeof(struct ipc_message) *
|
|
|
|
- IPC_EMPTY_LIST_SIZE, GFP_KERNEL);
|
|
|
|
- if (hsw->msg == NULL)
|
|
|
|
- return -ENOMEM;
|
|
|
|
|
|
+void sst_hsw_init_module_state(struct sst_hsw *hsw)
|
|
|
|
+{
|
|
|
|
+ struct sst_module *module;
|
|
|
|
+ enum sst_hsw_module_id id;
|
|
|
|
+
|
|
|
|
+ /* the base fw contains several modules */
|
|
|
|
+ for (id = SST_HSW_MODULE_BASE_FW; id < SST_HSW_MAX_MODULE_ID; id++) {
|
|
|
|
+ module = sst_module_get_from_id(hsw->dsp, id);
|
|
|
|
+ if (module) {
|
|
|
|
+ /* module waves is active only after being enabled */
|
|
|
|
+ if (id == SST_HSW_MODULE_WAVES)
|
|
|
|
+ module->state = SST_MODULE_STATE_INITIALIZED;
|
|
|
|
+ else
|
|
|
|
+ module->state = SST_MODULE_STATE_ACTIVE;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool sst_hsw_is_module_loaded(struct sst_hsw *hsw, u32 module_id)
|
|
|
|
+{
|
|
|
|
+ struct sst_module *module;
|
|
|
|
+
|
|
|
|
+ module = sst_module_get_from_id(hsw->dsp, module_id);
|
|
|
|
+ if (module == NULL || module->state == SST_MODULE_STATE_UNLOADED)
|
|
|
|
+ return false;
|
|
|
|
+ else
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool sst_hsw_is_module_active(struct sst_hsw *hsw, u32 module_id)
|
|
|
|
+{
|
|
|
|
+ struct sst_module *module;
|
|
|
|
+
|
|
|
|
+ module = sst_module_get_from_id(hsw->dsp, module_id);
|
|
|
|
+ if (module != NULL && module->state == SST_MODULE_STATE_ACTIVE)
|
|
|
|
+ return true;
|
|
|
|
+ else
|
|
|
|
+ return false;
|
|
|
|
+}
|
|
|
|
|
|
- for (i = 0; i < IPC_EMPTY_LIST_SIZE; i++) {
|
|
|
|
- init_waitqueue_head(&hsw->msg[i].waitq);
|
|
|
|
- list_add(&hsw->msg[i].list, &hsw->empty_list);
|
|
|
|
|
|
+void sst_hsw_set_module_enabled_rtd3(struct sst_hsw *hsw, u32 module_id)
|
|
|
|
+{
|
|
|
|
+ hsw->enabled_modules_rtd3 |= (1 << module_id);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void sst_hsw_set_module_disabled_rtd3(struct sst_hsw *hsw, u32 module_id)
|
|
|
|
+{
|
|
|
|
+ hsw->enabled_modules_rtd3 &= ~(1 << module_id);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool sst_hsw_is_module_enabled_rtd3(struct sst_hsw *hsw, u32 module_id)
|
|
|
|
+{
|
|
|
|
+ return hsw->enabled_modules_rtd3 & (1 << module_id);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void sst_hsw_reset_param_buf(struct sst_hsw *hsw)
|
|
|
|
+{
|
|
|
|
+ hsw->param_idx_w = 0;
|
|
|
|
+ hsw->param_idx_r = 0;
|
|
|
|
+ memset((void *)hsw->param_buf, 0, sizeof(hsw->param_buf));
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int sst_hsw_store_param_line(struct sst_hsw *hsw, u8 *buf)
|
|
|
|
+{
|
|
|
|
+ /* save line to the first available position of param buffer */
|
|
|
|
+ if (hsw->param_idx_w > WAVES_PARAM_LINES - 1) {
|
|
|
|
+ dev_warn(hsw->dev, "warning: param buffer overflow!\n");
|
|
|
|
+ return -EPERM;
|
|
|
|
+ }
|
|
|
|
+ memcpy(hsw->param_buf[hsw->param_idx_w], buf, WAVES_PARAM_COUNT);
|
|
|
|
+ hsw->param_idx_w++;
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int sst_hsw_load_param_line(struct sst_hsw *hsw, u8 *buf)
|
|
|
|
+{
|
|
|
|
+ u8 id = 0;
|
|
|
|
+
|
|
|
|
+ /* read the first matching line from param buffer */
|
|
|
|
+ while (hsw->param_idx_r < WAVES_PARAM_LINES) {
|
|
|
|
+ id = hsw->param_buf[hsw->param_idx_r][0];
|
|
|
|
+ hsw->param_idx_r++;
|
|
|
|
+ if (buf[0] == id) {
|
|
|
|
+ memcpy(buf, hsw->param_buf[hsw->param_idx_r],
|
|
|
|
+ WAVES_PARAM_COUNT);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ if (hsw->param_idx_r > WAVES_PARAM_LINES - 1) {
|
|
|
|
+ dev_dbg(hsw->dev, "end of buffer, roll to the beginning\n");
|
|
|
|
+ hsw->param_idx_r = 0;
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int sst_hsw_launch_param_buf(struct sst_hsw *hsw)
|
|
|
|
+{
|
|
|
|
+ int ret, idx;
|
|
|
|
|
|
|
|
+ if (!sst_hsw_is_module_active(hsw, SST_HSW_MODULE_WAVES)) {
|
|
|
|
+ dev_dbg(hsw->dev, "module waves is not active\n");
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* put all param lines to DSP through ipc */
|
|
|
|
+ for (idx = 0; idx < hsw->param_idx_w; idx++) {
|
|
|
|
+ ret = sst_hsw_module_set_param(hsw,
|
|
|
|
+ SST_HSW_MODULE_WAVES, 0, hsw->param_buf[idx][0],
|
|
|
|
+ WAVES_PARAM_COUNT, hsw->param_buf[idx]);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-struct sst_dsp *sst_hsw_get_dsp(struct sst_hsw *hsw)
|
|
|
|
|
|
+int sst_hsw_module_load(struct sst_hsw *hsw,
|
|
|
|
+ u32 module_id, u32 instance_id, char *name)
|
|
{
|
|
{
|
|
- return hsw->dsp;
|
|
|
|
|
|
+ int ret = 0;
|
|
|
|
+ const struct firmware *fw = NULL;
|
|
|
|
+ struct sst_fw *hsw_sst_fw;
|
|
|
|
+ struct sst_module *module;
|
|
|
|
+ struct device *dev = hsw->dev;
|
|
|
|
+ struct sst_dsp *dsp = hsw->dsp;
|
|
|
|
+
|
|
|
|
+ dev_dbg(dev, "sst_hsw_module_load id=%d, name='%s'", module_id, name);
|
|
|
|
+
|
|
|
|
+ module = sst_module_get_from_id(dsp, module_id);
|
|
|
|
+ if (module == NULL) {
|
|
|
|
+ /* loading for the first time */
|
|
|
|
+ if (module_id == SST_HSW_MODULE_BASE_FW) {
|
|
|
|
+ /* for base module: use fw requested in acpi probe */
|
|
|
|
+ fw = dsp->pdata->fw;
|
|
|
|
+ if (!fw) {
|
|
|
|
+ dev_err(dev, "request Base fw failed\n");
|
|
|
|
+ return -ENODEV;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ /* try and load any other optional modules if they are
|
|
|
|
+ * available. Use dev_info instead of dev_err in case
|
|
|
|
+ * request firmware failed */
|
|
|
|
+ ret = request_firmware(&fw, name, dev);
|
|
|
|
+ if (ret) {
|
|
|
|
+ dev_info(dev, "fw image %s not available(%d)\n",
|
|
|
|
+ name, ret);
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ hsw_sst_fw = sst_fw_new(dsp, fw, hsw);
|
|
|
|
+ if (hsw_sst_fw == NULL) {
|
|
|
|
+ dev_err(dev, "error: failed to load firmware\n");
|
|
|
|
+ ret = -ENOMEM;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+ module = sst_module_get_from_id(dsp, module_id);
|
|
|
|
+ if (module == NULL) {
|
|
|
|
+ dev_err(dev, "error: no module %d in firmware %s\n",
|
|
|
|
+ module_id, name);
|
|
|
|
+ }
|
|
|
|
+ } else
|
|
|
|
+ dev_info(dev, "module %d (%s) already loaded\n",
|
|
|
|
+ module_id, name);
|
|
|
|
+out:
|
|
|
|
+ /* release fw, but base fw should be released by acpi driver */
|
|
|
|
+ if (fw && module_id != SST_HSW_MODULE_BASE_FW)
|
|
|
|
+ release_firmware(fw);
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int sst_hsw_module_enable(struct sst_hsw *hsw,
|
|
|
|
+ u32 module_id, u32 instance_id)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+ u32 header = 0;
|
|
|
|
+ struct sst_hsw_ipc_module_config config;
|
|
|
|
+ struct sst_module *module;
|
|
|
|
+ struct sst_module_runtime *runtime;
|
|
|
|
+ struct device *dev = hsw->dev;
|
|
|
|
+ struct sst_dsp *dsp = hsw->dsp;
|
|
|
|
+
|
|
|
|
+ if (!sst_hsw_is_module_loaded(hsw, module_id)) {
|
|
|
|
+ dev_dbg(dev, "module %d not loaded\n", module_id);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (sst_hsw_is_module_active(hsw, module_id)) {
|
|
|
|
+ dev_info(dev, "module %d already enabled\n", module_id);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ module = sst_module_get_from_id(dsp, module_id);
|
|
|
|
+ if (module == NULL) {
|
|
|
|
+ dev_err(dev, "module %d not valid\n", module_id);
|
|
|
|
+ return -ENXIO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ runtime = sst_module_runtime_get_from_id(module, module_id);
|
|
|
|
+ if (runtime == NULL) {
|
|
|
|
+ dev_err(dev, "runtime %d not valid", module_id);
|
|
|
|
+ return -ENXIO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ header = IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION) |
|
|
|
|
+ IPC_MODULE_OPERATION(IPC_MODULE_ENABLE) |
|
|
|
|
+ IPC_MODULE_ID(module_id);
|
|
|
|
+ dev_dbg(dev, "module enable header: %x\n", header);
|
|
|
|
+
|
|
|
|
+ config.map.module_entries_count = 1;
|
|
|
|
+ config.map.module_entries[0].module_id = module->id;
|
|
|
|
+ config.map.module_entries[0].entry_point = module->entry;
|
|
|
|
+
|
|
|
|
+ config.persistent_mem.offset =
|
|
|
|
+ sst_dsp_get_offset(dsp,
|
|
|
|
+ runtime->persistent_offset, SST_MEM_DRAM);
|
|
|
|
+ config.persistent_mem.size = module->persistent_size;
|
|
|
|
+
|
|
|
|
+ config.scratch_mem.offset =
|
|
|
|
+ sst_dsp_get_offset(dsp,
|
|
|
|
+ dsp->scratch_offset, SST_MEM_DRAM);
|
|
|
|
+ config.scratch_mem.size = module->scratch_size;
|
|
|
|
+ dev_dbg(dev, "mod %d enable p:%d @ %x, s:%d @ %x, ep: %x",
|
|
|
|
+ config.map.module_entries[0].module_id,
|
|
|
|
+ config.persistent_mem.size,
|
|
|
|
+ config.persistent_mem.offset,
|
|
|
|
+ config.scratch_mem.size, config.scratch_mem.offset,
|
|
|
|
+ config.map.module_entries[0].entry_point);
|
|
|
|
+
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header,
|
|
|
|
+ &config, sizeof(config), NULL, 0);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ dev_err(dev, "ipc: module enable failed - %d\n", ret);
|
|
|
|
+ else
|
|
|
|
+ module->state = SST_MODULE_STATE_ACTIVE;
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int sst_hsw_module_disable(struct sst_hsw *hsw,
|
|
|
|
+ u32 module_id, u32 instance_id)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+ u32 header;
|
|
|
|
+ struct sst_module *module;
|
|
|
|
+ struct device *dev = hsw->dev;
|
|
|
|
+ struct sst_dsp *dsp = hsw->dsp;
|
|
|
|
+
|
|
|
|
+ if (!sst_hsw_is_module_loaded(hsw, module_id)) {
|
|
|
|
+ dev_dbg(dev, "module %d not loaded\n", module_id);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!sst_hsw_is_module_active(hsw, module_id)) {
|
|
|
|
+ dev_info(dev, "module %d already disabled\n", module_id);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ module = sst_module_get_from_id(dsp, module_id);
|
|
|
|
+ if (module == NULL) {
|
|
|
|
+ dev_err(dev, "module %d not valid\n", module_id);
|
|
|
|
+ return -ENXIO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ header = IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION) |
|
|
|
|
+ IPC_MODULE_OPERATION(IPC_MODULE_DISABLE) |
|
|
|
|
+ IPC_MODULE_ID(module_id);
|
|
|
|
+
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header, NULL, 0, NULL, 0);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ dev_err(dev, "module disable failed - %d\n", ret);
|
|
|
|
+ else
|
|
|
|
+ module->state = SST_MODULE_STATE_INITIALIZED;
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+int sst_hsw_module_set_param(struct sst_hsw *hsw,
|
|
|
|
+ u32 module_id, u32 instance_id, u32 parameter_id,
|
|
|
|
+ u32 param_size, char *param)
|
|
|
|
+{
|
|
|
|
+ int ret;
|
|
|
|
+ unsigned char *data = NULL;
|
|
|
|
+ u32 header = 0;
|
|
|
|
+ u32 payload_size = 0, transfer_parameter_size = 0;
|
|
|
|
+ dma_addr_t dma_addr = 0;
|
|
|
|
+ struct sst_hsw_transfer_parameter *parameter;
|
|
|
|
+ struct device *dev = hsw->dev;
|
|
|
|
+
|
|
|
|
+ header = IPC_GLB_TYPE(IPC_GLB_MODULE_OPERATION) |
|
|
|
|
+ IPC_MODULE_OPERATION(IPC_MODULE_SET_PARAMETER) |
|
|
|
|
+ IPC_MODULE_ID(module_id);
|
|
|
|
+ dev_dbg(dev, "sst_hsw_module_set_param header=%x\n", header);
|
|
|
|
+
|
|
|
|
+ payload_size = param_size +
|
|
|
|
+ sizeof(struct sst_hsw_transfer_parameter) -
|
|
|
|
+ sizeof(struct sst_hsw_transfer_list);
|
|
|
|
+ dev_dbg(dev, "parameter size : %d\n", param_size);
|
|
|
|
+ dev_dbg(dev, "payload size : %d\n", payload_size);
|
|
|
|
+
|
|
|
|
+ if (payload_size <= SST_HSW_IPC_MAX_SHORT_PARAMETER_SIZE) {
|
|
|
|
+ /* short parameter, mailbox can contain data */
|
|
|
|
+ dev_dbg(dev, "transfer parameter size : %d\n",
|
|
|
|
+ transfer_parameter_size);
|
|
|
|
+
|
|
|
|
+ transfer_parameter_size = ALIGN(payload_size, 4);
|
|
|
|
+ dev_dbg(dev, "transfer parameter aligned size : %d\n",
|
|
|
|
+ transfer_parameter_size);
|
|
|
|
+
|
|
|
|
+ parameter = kzalloc(transfer_parameter_size, GFP_KERNEL);
|
|
|
|
+ if (parameter == NULL)
|
|
|
|
+ return -ENOMEM;
|
|
|
|
+
|
|
|
|
+ memcpy(parameter->data, param, param_size);
|
|
|
|
+ } else {
|
|
|
|
+ dev_warn(dev, "transfer parameter size too large!");
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ parameter->parameter_id = parameter_id;
|
|
|
|
+ parameter->data_size = param_size;
|
|
|
|
+
|
|
|
|
+ ret = sst_ipc_tx_message_wait(&hsw->ipc, header,
|
|
|
|
+ parameter, transfer_parameter_size , NULL, 0);
|
|
|
|
+ if (ret < 0)
|
|
|
|
+ dev_err(dev, "ipc: module set parameter failed - %d\n", ret);
|
|
|
|
+
|
|
|
|
+ kfree(parameter);
|
|
|
|
+
|
|
|
|
+ if (data)
|
|
|
|
+ dma_free_coherent(hsw->dsp->dma_dev,
|
|
|
|
+ param_size, (void *)data, dma_addr);
|
|
|
|
+
|
|
|
|
+ return ret;
|
|
}
|
|
}
|
|
|
|
|
|
static struct sst_dsp_device hsw_dev = {
|
|
static struct sst_dsp_device hsw_dev = {
|
|
@@ -1891,10 +2061,48 @@ static struct sst_dsp_device hsw_dev = {
|
|
.ops = &haswell_ops,
|
|
.ops = &haswell_ops,
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+static void hsw_tx_msg(struct sst_generic_ipc *ipc, struct ipc_message *msg)
|
|
|
|
+{
|
|
|
|
+ /* send the message */
|
|
|
|
+ sst_dsp_outbox_write(ipc->dsp, msg->tx_data, msg->tx_size);
|
|
|
|
+ sst_dsp_ipc_msg_tx(ipc->dsp, msg->header);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void hsw_shim_dbg(struct sst_generic_ipc *ipc, const char *text)
|
|
|
|
+{
|
|
|
|
+ struct sst_dsp *sst = ipc->dsp;
|
|
|
|
+ u32 isr, ipcd, imrx, ipcx;
|
|
|
|
+
|
|
|
|
+ ipcx = sst_dsp_shim_read_unlocked(sst, SST_IPCX);
|
|
|
|
+ isr = sst_dsp_shim_read_unlocked(sst, SST_ISRX);
|
|
|
|
+ ipcd = sst_dsp_shim_read_unlocked(sst, SST_IPCD);
|
|
|
|
+ imrx = sst_dsp_shim_read_unlocked(sst, SST_IMRX);
|
|
|
|
+
|
|
|
|
+ dev_err(ipc->dev,
|
|
|
|
+ "ipc: --%s-- ipcx 0x%8.8x isr 0x%8.8x ipcd 0x%8.8x imrx 0x%8.8x\n",
|
|
|
|
+ text, ipcx, isr, ipcd, imrx);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void hsw_tx_data_copy(struct ipc_message *msg, char *tx_data,
|
|
|
|
+ size_t tx_size)
|
|
|
|
+{
|
|
|
|
+ memcpy(msg->tx_data, tx_data, tx_size);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static u64 hsw_reply_msg_match(u64 header, u64 *mask)
|
|
|
|
+{
|
|
|
|
+ /* clear reply bits & status bits */
|
|
|
|
+ header &= ~(IPC_STATUS_MASK | IPC_GLB_REPLY_MASK);
|
|
|
|
+ *mask = (u64)-1;
|
|
|
|
+
|
|
|
|
+ return header;
|
|
|
|
+}
|
|
|
|
+
|
|
int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
|
|
int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
|
|
{
|
|
{
|
|
struct sst_hsw_ipc_fw_version version;
|
|
struct sst_hsw_ipc_fw_version version;
|
|
struct sst_hsw *hsw;
|
|
struct sst_hsw *hsw;
|
|
|
|
+ struct sst_generic_ipc *ipc;
|
|
int ret;
|
|
int ret;
|
|
|
|
|
|
dev_dbg(dev, "initialising Audio DSP IPC\n");
|
|
dev_dbg(dev, "initialising Audio DSP IPC\n");
|
|
@@ -1903,39 +2111,30 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
|
|
if (hsw == NULL)
|
|
if (hsw == NULL)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
- hsw->dev = dev;
|
|
|
|
- INIT_LIST_HEAD(&hsw->stream_list);
|
|
|
|
- INIT_LIST_HEAD(&hsw->tx_list);
|
|
|
|
- INIT_LIST_HEAD(&hsw->rx_list);
|
|
|
|
- INIT_LIST_HEAD(&hsw->empty_list);
|
|
|
|
- init_waitqueue_head(&hsw->boot_wait);
|
|
|
|
- init_waitqueue_head(&hsw->wait_txq);
|
|
|
|
-
|
|
|
|
- ret = msg_empty_list_init(hsw);
|
|
|
|
- if (ret < 0)
|
|
|
|
- return -ENOMEM;
|
|
|
|
|
|
+ ipc = &hsw->ipc;
|
|
|
|
+ ipc->dev = dev;
|
|
|
|
+ ipc->ops.tx_msg = hsw_tx_msg;
|
|
|
|
+ ipc->ops.shim_dbg = hsw_shim_dbg;
|
|
|
|
+ ipc->ops.tx_data_copy = hsw_tx_data_copy;
|
|
|
|
+ ipc->ops.reply_msg_match = hsw_reply_msg_match;
|
|
|
|
|
|
- /* start the IPC message thread */
|
|
|
|
- init_kthread_worker(&hsw->kworker);
|
|
|
|
- hsw->tx_thread = kthread_run(kthread_worker_fn,
|
|
|
|
- &hsw->kworker, "%s",
|
|
|
|
- dev_name(hsw->dev));
|
|
|
|
- if (IS_ERR(hsw->tx_thread)) {
|
|
|
|
- ret = PTR_ERR(hsw->tx_thread);
|
|
|
|
- dev_err(hsw->dev, "error: failed to create message TX task\n");
|
|
|
|
- goto err_free_msg;
|
|
|
|
- }
|
|
|
|
- init_kthread_work(&hsw->kwork, ipc_tx_msgs);
|
|
|
|
|
|
+ ret = sst_ipc_init(ipc);
|
|
|
|
+ if (ret != 0)
|
|
|
|
+ goto ipc_init_err;
|
|
|
|
|
|
|
|
+ INIT_LIST_HEAD(&hsw->stream_list);
|
|
|
|
+ init_waitqueue_head(&hsw->boot_wait);
|
|
hsw_dev.thread_context = hsw;
|
|
hsw_dev.thread_context = hsw;
|
|
|
|
|
|
/* init SST shim */
|
|
/* init SST shim */
|
|
hsw->dsp = sst_dsp_new(dev, &hsw_dev, pdata);
|
|
hsw->dsp = sst_dsp_new(dev, &hsw_dev, pdata);
|
|
if (hsw->dsp == NULL) {
|
|
if (hsw->dsp == NULL) {
|
|
ret = -ENODEV;
|
|
ret = -ENODEV;
|
|
- goto dsp_err;
|
|
|
|
|
|
+ goto dsp_new_err;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ ipc->dsp = hsw->dsp;
|
|
|
|
+
|
|
/* allocate DMA buffer for context storage */
|
|
/* allocate DMA buffer for context storage */
|
|
hsw->dx_context = dma_alloc_coherent(hsw->dsp->dma_dev,
|
|
hsw->dx_context = dma_alloc_coherent(hsw->dsp->dma_dev,
|
|
SST_HSW_DX_CONTEXT_SIZE, &hsw->dx_context_paddr, GFP_KERNEL);
|
|
SST_HSW_DX_CONTEXT_SIZE, &hsw->dx_context_paddr, GFP_KERNEL);
|
|
@@ -1947,18 +2146,22 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
|
|
/* keep the DSP in reset state for base FW loading */
|
|
/* keep the DSP in reset state for base FW loading */
|
|
sst_dsp_reset(hsw->dsp);
|
|
sst_dsp_reset(hsw->dsp);
|
|
|
|
|
|
- hsw->sst_fw = sst_fw_new(hsw->dsp, pdata->fw, hsw);
|
|
|
|
- if (hsw->sst_fw == NULL) {
|
|
|
|
- ret = -ENODEV;
|
|
|
|
- dev_err(dev, "error: failed to load firmware\n");
|
|
|
|
|
|
+ /* load base module and other modules in base firmware image */
|
|
|
|
+ ret = sst_hsw_module_load(hsw, SST_HSW_MODULE_BASE_FW, 0, "Base");
|
|
|
|
+ if (ret < 0)
|
|
goto fw_err;
|
|
goto fw_err;
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ /* try to load module waves */
|
|
|
|
+ sst_hsw_module_load(hsw, SST_HSW_MODULE_WAVES, 0, "intel/IntcPP01.bin");
|
|
|
|
|
|
/* allocate scratch mem regions */
|
|
/* allocate scratch mem regions */
|
|
ret = sst_block_alloc_scratch(hsw->dsp);
|
|
ret = sst_block_alloc_scratch(hsw->dsp);
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
goto boot_err;
|
|
goto boot_err;
|
|
|
|
|
|
|
|
+ /* init param buffer */
|
|
|
|
+ sst_hsw_reset_param_buf(hsw);
|
|
|
|
+
|
|
/* wait for DSP boot completion */
|
|
/* wait for DSP boot completion */
|
|
sst_dsp_boot(hsw->dsp);
|
|
sst_dsp_boot(hsw->dsp);
|
|
ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete,
|
|
ret = wait_event_timeout(hsw->boot_wait, hsw->boot_complete,
|
|
@@ -1971,6 +2174,9 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
|
|
goto boot_err;
|
|
goto boot_err;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /* init module state after boot */
|
|
|
|
+ sst_hsw_init_module_state(hsw);
|
|
|
|
+
|
|
/* get the FW version */
|
|
/* get the FW version */
|
|
sst_hsw_fw_get_version(hsw, &version);
|
|
sst_hsw_fw_get_version(hsw, &version);
|
|
|
|
|
|
@@ -1986,17 +2192,16 @@ int sst_hsw_dsp_init(struct device *dev, struct sst_pdata *pdata)
|
|
|
|
|
|
boot_err:
|
|
boot_err:
|
|
sst_dsp_reset(hsw->dsp);
|
|
sst_dsp_reset(hsw->dsp);
|
|
- sst_fw_free(hsw->sst_fw);
|
|
|
|
|
|
+ sst_fw_free_all(hsw->dsp);
|
|
fw_err:
|
|
fw_err:
|
|
dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE,
|
|
dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE,
|
|
hsw->dx_context, hsw->dx_context_paddr);
|
|
hsw->dx_context, hsw->dx_context_paddr);
|
|
dma_err:
|
|
dma_err:
|
|
sst_dsp_free(hsw->dsp);
|
|
sst_dsp_free(hsw->dsp);
|
|
-dsp_err:
|
|
|
|
- kthread_stop(hsw->tx_thread);
|
|
|
|
-err_free_msg:
|
|
|
|
- kfree(hsw->msg);
|
|
|
|
-
|
|
|
|
|
|
+dsp_new_err:
|
|
|
|
+ sst_ipc_fini(ipc);
|
|
|
|
+ipc_init_err:
|
|
|
|
+ kfree(hsw);
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(sst_hsw_dsp_init);
|
|
EXPORT_SYMBOL_GPL(sst_hsw_dsp_init);
|
|
@@ -2010,7 +2215,6 @@ void sst_hsw_dsp_free(struct device *dev, struct sst_pdata *pdata)
|
|
dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE,
|
|
dma_free_coherent(hsw->dsp->dma_dev, SST_HSW_DX_CONTEXT_SIZE,
|
|
hsw->dx_context, hsw->dx_context_paddr);
|
|
hsw->dx_context, hsw->dx_context_paddr);
|
|
sst_dsp_free(hsw->dsp);
|
|
sst_dsp_free(hsw->dsp);
|
|
- kthread_stop(hsw->tx_thread);
|
|
|
|
- kfree(hsw->msg);
|
|
|
|
|
|
+ sst_ipc_fini(&hsw->ipc);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(sst_hsw_dsp_free);
|
|
EXPORT_SYMBOL_GPL(sst_hsw_dsp_free);
|