[Sound-open-firmware] [PATCH V4 1/2] ASoc: SOF: Add memory window for all platform
From: Pan Xiuli xiuli.pan@linux.intel.com
Add memory window handler for BYT, HSW and BDW.
Signed-off-by: Pan Xiuli xiuli.pan@linux.intel.com --- v1: rebase and some typo fix v2: rebase and fix window setting v3: rebase v4: rebase and add err handler for get_window function Test with: Mininow max rt5651 SOF master: e92ef97834489f52c0f20445d401a8c6e0aaed62 SOF-Tool master: 5b8dfd13019cfd29999503b56c902f56209000ed https://github.com/plbossart/sound/tree/topic/sof-v4.14: d919ea06b7f79c95ab4eb68baf05e9faf3a894c1 --- sound/soc/sof/hw-apl.c | 23 +++++++++--- sound/soc/sof/hw-bdw.c | 97 +++++++++++++++++++++++++++++++++++++++++++++---- sound/soc/sof/hw-byt.c | 98 +++++++++++++++++++++++++++++++++++++++++++++----- sound/soc/sof/hw-hsw.c | 97 +++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 289 insertions(+), 26 deletions(-)
diff --git a/sound/soc/sof/hw-apl.c b/sound/soc/sof/hw-apl.c index bfbdd915..1823153 100644 --- a/sound/soc/sof/hw-apl.c +++ b/sound/soc/sof/hw-apl.c @@ -1089,12 +1089,18 @@ static int apl_prepare(struct snd_sof_dev *sdev, unsigned int format, static void apl_get_windows(struct snd_sof_dev *sdev) { struct sof_ipc_window_elem *elem; + u32 outbox_offset = 0; + u32 stream_offset = 0; + u32 inbox_offset = 0; + u32 outbox_size = 0; + u32 stream_size = 0; + u32 inbox_size = 0; int i; - u32 inbox_offset = 0, outbox_offset = 0; - u32 inbox_size = 0, outbox_size = 0;
- if (!sdev->info_window) + if (!sdev->info_window) { + dev_err(sdev->dev, "error: have no window info\n"); return; + }
for (i = 0; i < sdev->info_window->num_windows; i++) { elem = &sdev->info_window->window[i]; @@ -1135,6 +1141,9 @@ static void apl_get_windows(struct snd_sof_dev *sdev) elem->size, "debug"); break; case SOF_IPC_REGION_STREAM: + stream_offset = + elem->offset + SRAM_WINDOW_OFFSET(elem->id); + stream_size = elem->size; snd_sof_debugfs_create_item(sdev, sdev->bar[APL_DSP_BAR] + elem->offset + @@ -1151,10 +1160,16 @@ static void apl_get_windows(struct snd_sof_dev *sdev) elem->size, "regs"); break; default: - break; + dev_err(sdev->dev, "error: get illegal window info\n"); + return; } }
+ if (outbox_size == 0 || inbox_size == 0) { + dev_err(sdev->dev, "error: get illegal mailbox window\n"); + return; + } + snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, outbox_offset, outbox_size);
diff --git a/sound/soc/sof/hw-bdw.c b/sound/soc/sof/hw-bdw.c index b1c9508..1fe2807 100644 --- a/sound/soc/sof/hw-bdw.c +++ b/sound/soc/sof/hw-bdw.c @@ -66,7 +66,6 @@ static const struct snd_sof_debugfs_map bdw_debugfs[] = { {"iram", BDW_DSP_BAR, IRAM_OFFSET, BDW_IRAM_SIZE}, {"dram", BDW_DSP_BAR, DRAM_OFFSET, BDW_DRAM_SIZE}, {"shim", BDW_DSP_BAR, SHIM_OFFSET, SHIM_SIZE}, - {"mbox", BDW_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
/* @@ -389,6 +388,88 @@ static irqreturn_t bdw_irq_thread(int irq, void *context) /* * IPC Firmware ready. */ +static void bdw_get_windows(struct snd_sof_dev *sdev) +{ + struct sof_ipc_window_elem *elem; + u32 outbox_offset = 0; + u32 stream_offset = 0; + u32 inbox_offset = 0; + u32 outbox_size = 0; + u32 stream_size = 0; + u32 inbox_size = 0; + int i; + + if (!sdev->info_window) { + dev_err(sdev->dev, "error: have no window info\n"); + return; + } + + for (i = 0; i < sdev->info_window->num_windows; i++) { + elem = &sdev->info_window->window[i]; + + switch (elem->type) { + case SOF_IPC_REGION_UPBOX: + inbox_offset = elem->offset + MBOX_OFFSET; + inbox_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[BDW_DSP_BAR] + + inbox_offset, + elem->size, "inbox"); + break; + case SOF_IPC_REGION_DOWNBOX: + outbox_offset = elem->offset + MBOX_OFFSET; + outbox_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[BDW_DSP_BAR] + + outbox_offset, + elem->size, "outbox"); + break; + case SOF_IPC_REGION_TRACE: + snd_sof_debugfs_create_item(sdev, + sdev->bar[BDW_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "etrace"); + break; + case SOF_IPC_REGION_DEBUG: + snd_sof_debugfs_create_item(sdev, + sdev->bar[BDW_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "debug"); + break; + case SOF_IPC_REGION_STREAM: + stream_offset = elem->offset + MBOX_OFFSET; + stream_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[BDW_DSP_BAR] + + stream_offset, + elem->size, "stream"); + break; + case SOF_IPC_REGION_REGS: + snd_sof_debugfs_create_item(sdev, + sdev->bar[BDW_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "regs"); + break; + default: + dev_err(sdev->dev, "error: get illegal window info\n"); + return; + } + } + + if (outbox_size == 0 || inbox_size == 0) { + dev_err(sdev->dev, "error: get illegal mailbox window\n"); + return; + } + + snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, + outbox_offset, outbox_size); + + dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", + inbox_offset, inbox_size); + dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", + outbox_offset, outbox_size); +} + static int bdw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) { struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready; @@ -409,14 +490,16 @@ static int bdw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_dbg(sdev->dev, " mailbox DSP initiated 0x%x - size 0x%x\n", - fw_ready->dspbox_offset, fw_ready->dspbox_size); - dev_dbg(sdev->dev, " mailbox Host initiated 0x%x - size 0x%x\n", - fw_ready->hostbox_offset, fw_ready->hostbox_size); - - dev_info(sdev->dev, " Firmware info: version %d:%d-%s build %d on %s:%s\n", + dev_info(sdev->dev, + " Firmware info: version %d:%d-%s build %d on %s:%s\n", v->major, v->minor, v->tag, v->build, v->date, v->time);
+ /* now check for extended data */ + snd_sof_fw_parse_ext_data(sdev, MBOX_OFFSET + + sizeof(struct sof_ipc_fw_ready)); + + bdw_get_windows(sdev); + return 0; }
diff --git a/sound/soc/sof/hw-byt.c b/sound/soc/sof/hw-byt.c index 367fab9..8d27e18 100644 --- a/sound/soc/sof/hw-byt.c +++ b/sound/soc/sof/hw-byt.c @@ -76,7 +76,6 @@ static const struct snd_sof_debugfs_map byt_debugfs[] = { {"iram", BYT_DSP_BAR, IRAM_OFFSET, IRAM_SIZE}, {"dram", BYT_DSP_BAR, DRAM_OFFSET, DRAM_SIZE}, {"shim", BYT_DSP_BAR, SHIM_OFFSET, SHIM_SIZE}, - {"mbox", BYT_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
static const struct snd_sof_debugfs_map cht_debugfs[] = { @@ -92,7 +91,6 @@ static const struct snd_sof_debugfs_map cht_debugfs[] = { {"iram", BYT_DSP_BAR, IRAM_OFFSET, IRAM_SIZE}, {"dram", BYT_DSP_BAR, DRAM_OFFSET, DRAM_SIZE}, {"shim", BYT_DSP_BAR, SHIM_OFFSET, SHIM_SIZE}, - {"mbox", BYT_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
/* @@ -160,6 +158,88 @@ static void byt_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, /* * IPC Firmware ready. */ +static void byt_get_windows(struct snd_sof_dev *sdev) +{ + struct sof_ipc_window_elem *elem; + u32 outbox_offset = 0; + u32 stream_offset = 0; + u32 inbox_offset = 0; + u32 outbox_size = 0; + u32 stream_size = 0; + u32 inbox_size = 0; + int i; + + if (!sdev->info_window) { + dev_err(sdev->dev, "error: have no window info\n"); + return; + } + + for (i = 0; i < sdev->info_window->num_windows; i++) { + elem = &sdev->info_window->window[i]; + + switch (elem->type) { + case SOF_IPC_REGION_UPBOX: + inbox_offset = elem->offset + MBOX_OFFSET; + inbox_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[BYT_DSP_BAR] + + inbox_offset, + elem->size, "inbox"); + break; + case SOF_IPC_REGION_DOWNBOX: + outbox_offset = elem->offset + MBOX_OFFSET; + outbox_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[BYT_DSP_BAR] + + outbox_offset, + elem->size, "outbox"); + break; + case SOF_IPC_REGION_TRACE: + snd_sof_debugfs_create_item(sdev, + sdev->bar[BYT_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "etrace"); + break; + case SOF_IPC_REGION_DEBUG: + snd_sof_debugfs_create_item(sdev, + sdev->bar[BYT_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "debug"); + break; + case SOF_IPC_REGION_STREAM: + stream_offset = elem->offset + MBOX_OFFSET; + stream_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[BYT_DSP_BAR] + + stream_offset, + elem->size, "stream"); + break; + case SOF_IPC_REGION_REGS: + snd_sof_debugfs_create_item(sdev, + sdev->bar[BYT_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "regs"); + break; + default: + dev_err(sdev->dev, "error: get illegal window info\n"); + return; + } + } + + if (outbox_size == 0 || inbox_size == 0) { + dev_err(sdev->dev, "error: get illegal mailbox window\n"); + return; + } + + snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, + outbox_offset, outbox_size); + + dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", + inbox_offset, inbox_size); + dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", + outbox_offset, outbox_size); +} + static int byt_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) { struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready; @@ -180,14 +260,16 @@ static int byt_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_dbg(sdev->dev, " mailbox DSP initiated 0x%x - size 0x%x\n", - fw_ready->dspbox_offset, fw_ready->dspbox_size); - dev_dbg(sdev->dev, " mailbox Host initiated 0x%x - size 0x%x\n", - fw_ready->hostbox_offset, fw_ready->hostbox_size); - - dev_info(sdev->dev, " Firmware info: version %d:%d-%s build %d on %s:%s\n", + dev_info(sdev->dev, + " Firmware info: version %d:%d-%s build %d on %s:%s\n", v->major, v->minor, v->tag, v->build, v->date, v->time);
+ /* now check for extended data */ + snd_sof_fw_parse_ext_data(sdev, MBOX_OFFSET + + sizeof(struct sof_ipc_fw_ready)); + + byt_get_windows(sdev); + return 0; }
diff --git a/sound/soc/sof/hw-hsw.c b/sound/soc/sof/hw-hsw.c index 495009a..f636ce4 100644 --- a/sound/soc/sof/hw-hsw.c +++ b/sound/soc/sof/hw-hsw.c @@ -66,7 +66,6 @@ static const struct snd_sof_debugfs_map hsw_debugfs[] = { {"iram", HSW_DSP_BAR, IRAM_OFFSET, HSW_IRAM_SIZE}, {"dram", HSW_DSP_BAR, DRAM_OFFSET, HSW_DRAM_SIZE}, {"shim", HSW_DSP_BAR, SHIM_OFFSET, SHIM_SIZE}, - {"mbox", HSW_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
/* @@ -389,6 +388,88 @@ static irqreturn_t hsw_irq_thread(int irq, void *context) /* * IPC Firmware ready. */ +static void hsw_get_windows(struct snd_sof_dev *sdev) +{ + struct sof_ipc_window_elem *elem; + u32 outbox_offset = 0; + u32 stream_offset = 0; + u32 inbox_offset = 0; + u32 outbox_size = 0; + u32 stream_size = 0; + u32 inbox_size = 0; + int i; + + if (!sdev->info_window) { + dev_err(sdev->dev, "error: have no window info\n"); + return; + } + + for (i = 0; i < sdev->info_window->num_windows; i++) { + elem = &sdev->info_window->window[i]; + + switch (elem->type) { + case SOF_IPC_REGION_UPBOX: + inbox_offset = elem->offset + MBOX_OFFSET; + inbox_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[HSW_DSP_BAR] + + inbox_offset, + elem->size, "inbox"); + break; + case SOF_IPC_REGION_DOWNBOX: + outbox_offset = elem->offset + MBOX_OFFSET; + outbox_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[HSW_DSP_BAR] + + outbox_offset, + elem->size, "outbox"); + break; + case SOF_IPC_REGION_TRACE: + snd_sof_debugfs_create_item(sdev, + sdev->bar[HSW_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "etrace"); + break; + case SOF_IPC_REGION_DEBUG: + snd_sof_debugfs_create_item(sdev, + sdev->bar[HSW_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "debug"); + break; + case SOF_IPC_REGION_STREAM: + stream_offset = elem->offset + MBOX_OFFSET; + stream_size = elem->size; + snd_sof_debugfs_create_item(sdev, + sdev->bar[HSW_DSP_BAR] + + stream_offset, + elem->size, "stream"); + break; + case SOF_IPC_REGION_REGS: + snd_sof_debugfs_create_item(sdev, + sdev->bar[HSW_DSP_BAR] + + elem->offset + MBOX_OFFSET, + elem->size, "regs"); + break; + default: + dev_err(sdev->dev, "error: get illegal window info\n"); + return; + } + } + + if (outbox_size == 0 || inbox_size == 0) { + dev_err(sdev->dev, "error: get illegal mailbox window\n"); + return; + } + + snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, + outbox_offset, outbox_size); + + dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", + inbox_offset, inbox_size); + dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", + outbox_offset, outbox_size); +} + static int hsw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) { struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready; @@ -409,14 +490,16 @@ static int hsw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_dbg(sdev->dev, " mailbox DSP initiated 0x%x - size 0x%x\n", - fw_ready->dspbox_offset, fw_ready->dspbox_size); - dev_dbg(sdev->dev, " mailbox Host initiated 0x%x - size 0x%x\n", - fw_ready->hostbox_offset, fw_ready->hostbox_size); - - dev_info(sdev->dev, " Firmware info: version %d:%d-%s build %d on %s:%s\n", + dev_info(sdev->dev, + " Firmware info: version %d:%d-%s build %d on %s:%s\n", v->major, v->minor, v->tag, v->build, v->date, v->time);
+ /* now check for extended data */ + snd_sof_fw_parse_ext_data(sdev, MBOX_OFFSET + + sizeof(struct sof_ipc_fw_ready)); + + hsw_get_windows(sdev); + return 0; }
From: Pan Xiuli xiuli.pan@linux.intel.com
Use memory window to store position data, use old IPC as a notify.
Add memory window handler for BYT, HSW, BDW and APL.
Signed-off-by: Pan Xiuli xiuli.pan@linux.intel.com --- v4: rebase and add comment about msg id usage use stream box to dynamic check where to read posn info fix posn_offset validate Test with: Mininow max rt5651 SOF master: e92ef97834489f52c0f20445d401a8c6e0aaed62 SOF-Tool master: 5b8dfd13019cfd29999503b56c902f56209000ed https://github.com/plbossart/sound/tree/topic/sof-v4.14: d919ea06b7f79c95ab4eb68baf05e9faf3a894c1 --- sound/soc/sof/hw-apl.c | 4 +++ sound/soc/sof/hw-bdw.c | 4 +++ sound/soc/sof/hw-byt.c | 4 +++ sound/soc/sof/hw-hsw.c | 4 +++ sound/soc/sof/ipc.c | 73 +++++++++++++++++++++++++++++++++++++----------- sound/soc/sof/pcm.c | 16 +++++++++-- sound/soc/sof/sof-priv.h | 2 ++ 7 files changed, 88 insertions(+), 19 deletions(-)
diff --git a/sound/soc/sof/hw-apl.c b/sound/soc/sof/hw-apl.c index 1823153..09ebaa9 100644 --- a/sound/soc/sof/hw-apl.c +++ b/sound/soc/sof/hw-apl.c @@ -1172,11 +1172,15 @@ static void apl_get_windows(struct snd_sof_dev *sdev)
snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, outbox_offset, outbox_size); + sdev->stream_box.offset = stream_offset; + sdev->stream_box.size = stream_size;
dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", inbox_offset, inbox_size); dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", outbox_offset, outbox_size); + dev_dbg(sdev->dev, " stream region 0x%x - size 0x%x\n", + stream_offset, stream_size); }
static int apl_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) diff --git a/sound/soc/sof/hw-bdw.c b/sound/soc/sof/hw-bdw.c index 1fe2807..c50e4ca 100644 --- a/sound/soc/sof/hw-bdw.c +++ b/sound/soc/sof/hw-bdw.c @@ -463,11 +463,15 @@ static void bdw_get_windows(struct snd_sof_dev *sdev)
snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, outbox_offset, outbox_size); + sdev->stream_box.offset = stream_offset; + sdev->stream_box.size = stream_size;
dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", inbox_offset, inbox_size); dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", outbox_offset, outbox_size); + dev_dbg(sdev->dev, " stream region 0x%x - size 0x%x\n", + stream_offset, stream_size); }
static int bdw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) diff --git a/sound/soc/sof/hw-byt.c b/sound/soc/sof/hw-byt.c index 8d27e18..c7a88a2 100644 --- a/sound/soc/sof/hw-byt.c +++ b/sound/soc/sof/hw-byt.c @@ -233,11 +233,15 @@ static void byt_get_windows(struct snd_sof_dev *sdev)
snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, outbox_offset, outbox_size); + sdev->stream_box.offset = stream_offset; + sdev->stream_box.size = stream_size;
dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", inbox_offset, inbox_size); dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", outbox_offset, outbox_size); + dev_dbg(sdev->dev, " stream region 0x%x - size 0x%x\n", + stream_offset, stream_size); }
static int byt_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) diff --git a/sound/soc/sof/hw-hsw.c b/sound/soc/sof/hw-hsw.c index f636ce4..7a40806 100644 --- a/sound/soc/sof/hw-hsw.c +++ b/sound/soc/sof/hw-hsw.c @@ -463,11 +463,15 @@ static void hsw_get_windows(struct snd_sof_dev *sdev)
snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, outbox_offset, outbox_size); + sdev->stream_box.offset = stream_offset; + sdev->stream_box.size = stream_size;
dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n", inbox_offset, inbox_size); dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n", outbox_offset, outbox_size); + dev_dbg(sdev->dev, " stream region 0x%x - size 0x%x\n", + stream_offset, stream_size); }
static int hsw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) diff --git a/sound/soc/sof/ipc.c b/sound/soc/sof/ipc.c index da427d1..d9dc36b 100644 --- a/sound/soc/sof/ipc.c +++ b/sound/soc/sof/ipc.c @@ -249,44 +249,80 @@ EXPORT_SYMBOL(snd_sof_dsp_mailbox_init);
static void ipc_period_elapsed(struct snd_sof_dev *sdev, u32 msg_id) { - struct snd_sof_pcm *spcm; struct sof_ipc_stream_posn posn; + struct snd_sof_pcm *spcm; + u32 posn_offset; int direction;
- /* read back full message */ - snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, &posn, - sizeof(posn)); - dev_dbg(sdev->dev, "posn: host 0x%llx dai 0x%llx wall 0x%llx\n", - posn.host_posn, posn.dai_posn, posn.wallclock); + /* check if we have stream box */ + if (sdev->stream_box.size == 0) { + /* read back full message */ + snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, &posn, + sizeof(posn)); + + spcm = snd_sof_find_spcm_comp(sdev, posn.comp_id, &direction); + } else { + spcm = snd_sof_find_spcm_comp(sdev, msg_id, &direction); + }
- spcm = snd_sof_find_spcm_comp(sdev, posn.comp_id, &direction); if (!spcm) { - dev_err(sdev->dev, "error: period elapsed for unknown component %d\n", + dev_err(sdev->dev, + "error: period elapsed for unknown component %d\n", posn.comp_id); return; }
+ /* have stream box read from stream box */ + if (sdev->stream_box.size != 0) { + posn_offset = spcm->posn_offset[direction]; + snd_sof_dsp_mailbox_read(sdev, posn_offset, &posn, + sizeof(posn)); + + dev_dbg(sdev->dev, "posn mailbox: posn offset is 0x%x", + posn_offset); + } + + dev_dbg(sdev->dev, "posn : host 0x%llx dai 0x%llx wall 0x%llx\n", + posn.host_posn, posn.dai_posn, posn.wallclock); + memcpy(&spcm->stream[direction].posn, &posn, sizeof(posn)); snd_pcm_period_elapsed(spcm->stream[direction].substream); }
static void ipc_xrun(struct snd_sof_dev *sdev, u32 msg_id) { - struct snd_sof_pcm *spcm; struct sof_ipc_stream_posn posn; + struct snd_sof_pcm *spcm; + u32 posn_offset; int direction;
- /* read back full message */ - snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, &posn, - sizeof(posn)); + /* check if we have stream box */ + if (sdev->stream_box.size == 0) { + /* read back full message */ + snd_sof_dsp_mailbox_read(sdev, sdev->dsp_box.offset, &posn, + sizeof(posn)); + + spcm = snd_sof_find_spcm_comp(sdev, posn.comp_id, &direction); + } else { + spcm = snd_sof_find_spcm_comp(sdev, msg_id, &direction); + }
- spcm = snd_sof_find_spcm_comp(sdev, posn.comp_id, &direction); if (!spcm) { dev_err(sdev->dev, "error: XRUN for unknown component %d\n", posn.comp_id); return; }
+ /* have stream box read from stream box */ + if (sdev->stream_box.size != 0) { + posn_offset = spcm->posn_offset[direction]; + snd_sof_dsp_mailbox_read(sdev, posn_offset, &posn, + sizeof(posn)); + + dev_dbg(sdev->dev, "posn mailbox: posn offset is 0x%x", + posn_offset); + } + dev_dbg(sdev->dev, "posn XRUN: host %llx comp %d size %d\n", posn.host_posn, posn.xrun_comp_id, posn.xrun_size);
@@ -296,9 +332,13 @@ static void ipc_xrun(struct snd_sof_dev *sdev, u32 msg_id) snd_pcm_stop_xrun(spcm->stream[direction].substream); }
-static void ipc_stream_message(struct snd_sof_dev *sdev, u32 msg_id) +static void ipc_stream_message(struct snd_sof_dev *sdev, u32 msg_cmd) { - switch (msg_id) { + /* get msg cmd type and msd id */ + u32 msg_type = msg_cmd & SOF_CMD_TYPE_MASK; + u32 msg_id = SOF_IPC_MESSAGE_ID(msg_cmd); + + switch (msg_type) { case SOF_IPC_STREAM_POSITION: ipc_period_elapsed(sdev, msg_id); break; @@ -372,7 +412,8 @@ static void ipc_msgs_rx(struct work_struct *work) case SOF_IPC_GLB_COMP_MSG: break; case SOF_IPC_GLB_STREAM_MSG: - ipc_stream_message(sdev, type); + /* need to pass msg id into the function */ + ipc_stream_message(sdev, hdr.cmd); break; case SOF_IPC_GLB_TRACE_MSG: ipc_trace_message(sdev, type); diff --git a/sound/soc/sof/pcm.c b/sound/soc/sof/pcm.c index 771625f..34b4935 100644 --- a/sound/soc/sof/pcm.c +++ b/sound/soc/sof/pcm.c @@ -53,6 +53,7 @@ static int sof_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_sof_pcm *spcm = rtd->sof; struct sof_ipc_pcm_params pcm; struct sof_ipc_pcm_params_reply ipc_params_reply; + int posn_offset; int ret;
/* nothing todo for BE */ @@ -132,9 +133,6 @@ static int sof_pcm_hw_params(struct snd_pcm_substream *substream, return -EINVAL; }
- /* copy offset */ - //spcm->posn_offset[substream->stream] = ipc_params_reply.posn_offset; - /* firmware already configured host stream */ if (ops && ops->host_stream_prepare) { pcm.params.stream_tag = @@ -147,6 +145,18 @@ static int sof_pcm_hw_params(struct snd_pcm_substream *substream, pcm.hdr.cmd, &pcm, sizeof(pcm), &ipc_params_reply, sizeof(ipc_params_reply));
+ /* validate offset */ + posn_offset = ipc_params_reply.posn_offset; + /* check if offset is overflow or it is not aligned */ + if (posn_offset > sdev->stream_box.size || + posn_offset % sizeof(struct sof_ipc_stream_posn) != 0) { + dev_err(sdev->dev, "error: got wrong posn offset 0x%x for PCM %d\n", + posn_offset, ret); + return ret; + } + spcm->posn_offset[substream->stream] = + sdev->stream_box.offset + posn_offset; + return ret; }
diff --git a/sound/soc/sof/sof-priv.h b/sound/soc/sof/sof-priv.h index a096595..ecf0012 100644 --- a/sound/soc/sof/sof-priv.h +++ b/sound/soc/sof/sof-priv.h @@ -173,6 +173,7 @@ struct snd_sof_pcm { struct snd_sof_dev *sdev; struct snd_soc_tplg_pcm pcm; struct snd_sof_pcm_stream stream[2]; + u32 posn_offset[2]; struct mutex mutex; /* TODO: not used ? remove ? */ struct list_head list; /* list in sdev pcm list */ }; @@ -321,6 +322,7 @@ struct snd_sof_dev { struct snd_sof_ipc *ipc; struct snd_sof_mailbox dsp_box; /* DSP initiated IPC */ struct snd_sof_mailbox host_box; /* Host initiated IPC */ + struct snd_sof_mailbox stream_box; /* Stream position update */ u64 irq_status; int ipc_irq; u32 next_comp_id; /* monotonic - reset during S3 */
This looks much better, thanks.
To make the integration and upstream process smoother, can you split/squash the two patches in this series into:
- 4 separate patches for each platform
- core patch (for sof-priv.h)
- patch for pcm.c
- patch for ipc.c
7 patches total. this will help Liam and me prepare the kernel upstream patches. I know it's boring work, but it's safer if you do those changes and retest on your side.
On 03/06/2018 12:25 AM, Xiuli Pan wrote:
From: Pan Xiuli xiuli.pan@linux.intel.com
Add memory window handler for BYT, HSW and BDW.
Signed-off-by: Pan Xiuli xiuli.pan@linux.intel.com
v1: rebase and some typo fix v2: rebase and fix window setting v3: rebase v4: rebase and add err handler for get_window function Test with: Mininow max rt5651 SOF master: e92ef97834489f52c0f20445d401a8c6e0aaed62 SOF-Tool master: 5b8dfd13019cfd29999503b56c902f56209000ed https://github.com/plbossart/sound/tree/topic/sof-v4.14: d919ea06b7f79c95ab4eb68baf05e9faf3a894c1
sound/soc/sof/hw-apl.c | 23 +++++++++--- sound/soc/sof/hw-bdw.c | 97 +++++++++++++++++++++++++++++++++++++++++++++---- sound/soc/sof/hw-byt.c | 98 +++++++++++++++++++++++++++++++++++++++++++++----- sound/soc/sof/hw-hsw.c | 97 +++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 289 insertions(+), 26 deletions(-)
diff --git a/sound/soc/sof/hw-apl.c b/sound/soc/sof/hw-apl.c index bfbdd915..1823153 100644 --- a/sound/soc/sof/hw-apl.c +++ b/sound/soc/sof/hw-apl.c @@ -1089,12 +1089,18 @@ static int apl_prepare(struct snd_sof_dev *sdev, unsigned int format, static void apl_get_windows(struct snd_sof_dev *sdev) { struct sof_ipc_window_elem *elem;
- u32 outbox_offset = 0;
- u32 stream_offset = 0;
- u32 inbox_offset = 0;
- u32 outbox_size = 0;
- u32 stream_size = 0;
- u32 inbox_size = 0; int i;
u32 inbox_offset = 0, outbox_offset = 0;
u32 inbox_size = 0, outbox_size = 0;
if (!sdev->info_window)
if (!sdev->info_window) {
dev_err(sdev->dev, "error: have no window info\n");
return;
}
for (i = 0; i < sdev->info_window->num_windows; i++) { elem = &sdev->info_window->window[i];
@@ -1135,6 +1141,9 @@ static void apl_get_windows(struct snd_sof_dev *sdev) elem->size, "debug"); break; case SOF_IPC_REGION_STREAM:
stream_offset =
elem->offset + SRAM_WINDOW_OFFSET(elem->id);
stream_size = elem->size; snd_sof_debugfs_create_item(sdev, sdev->bar[APL_DSP_BAR] + elem->offset +
@@ -1151,10 +1160,16 @@ static void apl_get_windows(struct snd_sof_dev *sdev) elem->size, "regs"); break; default:
break;
dev_err(sdev->dev, "error: get illegal window info\n");
return;
} }
if (outbox_size == 0 || inbox_size == 0) {
dev_err(sdev->dev, "error: get illegal mailbox window\n");
return;
}
snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size, outbox_offset, outbox_size);
diff --git a/sound/soc/sof/hw-bdw.c b/sound/soc/sof/hw-bdw.c index b1c9508..1fe2807 100644 --- a/sound/soc/sof/hw-bdw.c +++ b/sound/soc/sof/hw-bdw.c @@ -66,7 +66,6 @@ static const struct snd_sof_debugfs_map bdw_debugfs[] = { {"iram", BDW_DSP_BAR, IRAM_OFFSET, BDW_IRAM_SIZE}, {"dram", BDW_DSP_BAR, DRAM_OFFSET, BDW_DRAM_SIZE}, {"shim", BDW_DSP_BAR, SHIM_OFFSET, SHIM_SIZE},
{"mbox", BDW_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
/*
@@ -389,6 +388,88 @@ static irqreturn_t bdw_irq_thread(int irq, void *context) /*
- IPC Firmware ready.
*/ +static void bdw_get_windows(struct snd_sof_dev *sdev) +{
- struct sof_ipc_window_elem *elem;
- u32 outbox_offset = 0;
- u32 stream_offset = 0;
- u32 inbox_offset = 0;
- u32 outbox_size = 0;
- u32 stream_size = 0;
- u32 inbox_size = 0;
- int i;
- if (!sdev->info_window) {
dev_err(sdev->dev, "error: have no window info\n");
return;
- }
- for (i = 0; i < sdev->info_window->num_windows; i++) {
elem = &sdev->info_window->window[i];
switch (elem->type) {
case SOF_IPC_REGION_UPBOX:
inbox_offset = elem->offset + MBOX_OFFSET;
inbox_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[BDW_DSP_BAR] +
inbox_offset,
elem->size, "inbox");
break;
case SOF_IPC_REGION_DOWNBOX:
outbox_offset = elem->offset + MBOX_OFFSET;
outbox_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[BDW_DSP_BAR] +
outbox_offset,
elem->size, "outbox");
break;
case SOF_IPC_REGION_TRACE:
snd_sof_debugfs_create_item(sdev,
sdev->bar[BDW_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "etrace");
break;
case SOF_IPC_REGION_DEBUG:
snd_sof_debugfs_create_item(sdev,
sdev->bar[BDW_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "debug");
break;
case SOF_IPC_REGION_STREAM:
stream_offset = elem->offset + MBOX_OFFSET;
stream_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[BDW_DSP_BAR] +
stream_offset,
elem->size, "stream");
break;
case SOF_IPC_REGION_REGS:
snd_sof_debugfs_create_item(sdev,
sdev->bar[BDW_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "regs");
break;
default:
dev_err(sdev->dev, "error: get illegal window info\n");
return;
}
- }
- if (outbox_size == 0 || inbox_size == 0) {
dev_err(sdev->dev, "error: get illegal mailbox window\n");
return;
- }
- snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size,
outbox_offset, outbox_size);
- dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n",
inbox_offset, inbox_size);
- dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n",
outbox_offset, outbox_size);
+}
- static int bdw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) { struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready;
@@ -409,14 +490,16 @@ static int bdw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_dbg(sdev->dev, " mailbox DSP initiated 0x%x - size 0x%x\n",
fw_ready->dspbox_offset, fw_ready->dspbox_size);
- dev_dbg(sdev->dev, " mailbox Host initiated 0x%x - size 0x%x\n",
fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_info(sdev->dev, " Firmware info: version %d:%d-%s build %d on %s:%s\n",
dev_info(sdev->dev,
" Firmware info: version %d:%d-%s build %d on %s:%s\n",
v->major, v->minor, v->tag, v->build, v->date, v->time);
/* now check for extended data */
snd_sof_fw_parse_ext_data(sdev, MBOX_OFFSET +
sizeof(struct sof_ipc_fw_ready));
bdw_get_windows(sdev);
return 0; }
diff --git a/sound/soc/sof/hw-byt.c b/sound/soc/sof/hw-byt.c index 367fab9..8d27e18 100644 --- a/sound/soc/sof/hw-byt.c +++ b/sound/soc/sof/hw-byt.c @@ -76,7 +76,6 @@ static const struct snd_sof_debugfs_map byt_debugfs[] = { {"iram", BYT_DSP_BAR, IRAM_OFFSET, IRAM_SIZE}, {"dram", BYT_DSP_BAR, DRAM_OFFSET, DRAM_SIZE}, {"shim", BYT_DSP_BAR, SHIM_OFFSET, SHIM_SIZE},
{"mbox", BYT_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
static const struct snd_sof_debugfs_map cht_debugfs[] = {
@@ -92,7 +91,6 @@ static const struct snd_sof_debugfs_map cht_debugfs[] = { {"iram", BYT_DSP_BAR, IRAM_OFFSET, IRAM_SIZE}, {"dram", BYT_DSP_BAR, DRAM_OFFSET, DRAM_SIZE}, {"shim", BYT_DSP_BAR, SHIM_OFFSET, SHIM_SIZE},
{"mbox", BYT_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
/*
@@ -160,6 +158,88 @@ static void byt_block_read(struct snd_sof_dev *sdev, u32 offset, void *dest, /*
- IPC Firmware ready.
*/ +static void byt_get_windows(struct snd_sof_dev *sdev) +{
- struct sof_ipc_window_elem *elem;
- u32 outbox_offset = 0;
- u32 stream_offset = 0;
- u32 inbox_offset = 0;
- u32 outbox_size = 0;
- u32 stream_size = 0;
- u32 inbox_size = 0;
- int i;
- if (!sdev->info_window) {
dev_err(sdev->dev, "error: have no window info\n");
return;
- }
- for (i = 0; i < sdev->info_window->num_windows; i++) {
elem = &sdev->info_window->window[i];
switch (elem->type) {
case SOF_IPC_REGION_UPBOX:
inbox_offset = elem->offset + MBOX_OFFSET;
inbox_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[BYT_DSP_BAR] +
inbox_offset,
elem->size, "inbox");
break;
case SOF_IPC_REGION_DOWNBOX:
outbox_offset = elem->offset + MBOX_OFFSET;
outbox_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[BYT_DSP_BAR] +
outbox_offset,
elem->size, "outbox");
break;
case SOF_IPC_REGION_TRACE:
snd_sof_debugfs_create_item(sdev,
sdev->bar[BYT_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "etrace");
break;
case SOF_IPC_REGION_DEBUG:
snd_sof_debugfs_create_item(sdev,
sdev->bar[BYT_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "debug");
break;
case SOF_IPC_REGION_STREAM:
stream_offset = elem->offset + MBOX_OFFSET;
stream_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[BYT_DSP_BAR] +
stream_offset,
elem->size, "stream");
break;
case SOF_IPC_REGION_REGS:
snd_sof_debugfs_create_item(sdev,
sdev->bar[BYT_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "regs");
break;
default:
dev_err(sdev->dev, "error: get illegal window info\n");
return;
}
- }
- if (outbox_size == 0 || inbox_size == 0) {
dev_err(sdev->dev, "error: get illegal mailbox window\n");
return;
- }
- snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size,
outbox_offset, outbox_size);
- dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n",
inbox_offset, inbox_size);
- dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n",
outbox_offset, outbox_size);
+}
- static int byt_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) { struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready;
@@ -180,14 +260,16 @@ static int byt_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_dbg(sdev->dev, " mailbox DSP initiated 0x%x - size 0x%x\n",
fw_ready->dspbox_offset, fw_ready->dspbox_size);
- dev_dbg(sdev->dev, " mailbox Host initiated 0x%x - size 0x%x\n",
fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_info(sdev->dev, " Firmware info: version %d:%d-%s build %d on %s:%s\n",
dev_info(sdev->dev,
" Firmware info: version %d:%d-%s build %d on %s:%s\n",
v->major, v->minor, v->tag, v->build, v->date, v->time);
/* now check for extended data */
snd_sof_fw_parse_ext_data(sdev, MBOX_OFFSET +
sizeof(struct sof_ipc_fw_ready));
byt_get_windows(sdev);
return 0; }
diff --git a/sound/soc/sof/hw-hsw.c b/sound/soc/sof/hw-hsw.c index 495009a..f636ce4 100644 --- a/sound/soc/sof/hw-hsw.c +++ b/sound/soc/sof/hw-hsw.c @@ -66,7 +66,6 @@ static const struct snd_sof_debugfs_map hsw_debugfs[] = { {"iram", HSW_DSP_BAR, IRAM_OFFSET, HSW_IRAM_SIZE}, {"dram", HSW_DSP_BAR, DRAM_OFFSET, HSW_DRAM_SIZE}, {"shim", HSW_DSP_BAR, SHIM_OFFSET, SHIM_SIZE},
{"mbox", HSW_DSP_BAR, MBOX_OFFSET, MBOX_SIZE}, };
/*
@@ -389,6 +388,88 @@ static irqreturn_t hsw_irq_thread(int irq, void *context) /*
- IPC Firmware ready.
*/ +static void hsw_get_windows(struct snd_sof_dev *sdev) +{
- struct sof_ipc_window_elem *elem;
- u32 outbox_offset = 0;
- u32 stream_offset = 0;
- u32 inbox_offset = 0;
- u32 outbox_size = 0;
- u32 stream_size = 0;
- u32 inbox_size = 0;
- int i;
- if (!sdev->info_window) {
dev_err(sdev->dev, "error: have no window info\n");
return;
- }
- for (i = 0; i < sdev->info_window->num_windows; i++) {
elem = &sdev->info_window->window[i];
switch (elem->type) {
case SOF_IPC_REGION_UPBOX:
inbox_offset = elem->offset + MBOX_OFFSET;
inbox_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[HSW_DSP_BAR] +
inbox_offset,
elem->size, "inbox");
break;
case SOF_IPC_REGION_DOWNBOX:
outbox_offset = elem->offset + MBOX_OFFSET;
outbox_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[HSW_DSP_BAR] +
outbox_offset,
elem->size, "outbox");
break;
case SOF_IPC_REGION_TRACE:
snd_sof_debugfs_create_item(sdev,
sdev->bar[HSW_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "etrace");
break;
case SOF_IPC_REGION_DEBUG:
snd_sof_debugfs_create_item(sdev,
sdev->bar[HSW_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "debug");
break;
case SOF_IPC_REGION_STREAM:
stream_offset = elem->offset + MBOX_OFFSET;
stream_size = elem->size;
snd_sof_debugfs_create_item(sdev,
sdev->bar[HSW_DSP_BAR] +
stream_offset,
elem->size, "stream");
break;
case SOF_IPC_REGION_REGS:
snd_sof_debugfs_create_item(sdev,
sdev->bar[HSW_DSP_BAR] +
elem->offset + MBOX_OFFSET,
elem->size, "regs");
break;
default:
dev_err(sdev->dev, "error: get illegal window info\n");
return;
}
- }
- if (outbox_size == 0 || inbox_size == 0) {
dev_err(sdev->dev, "error: get illegal mailbox window\n");
return;
- }
- snd_sof_dsp_mailbox_init(sdev, inbox_offset, inbox_size,
outbox_offset, outbox_size);
- dev_dbg(sdev->dev, " mailbox upstream 0x%x - size 0x%x\n",
inbox_offset, inbox_size);
- dev_dbg(sdev->dev, " mailbox downstream 0x%x - size 0x%x\n",
outbox_offset, outbox_size);
+}
- static int hsw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) { struct sof_ipc_fw_ready *fw_ready = &sdev->fw_ready;
@@ -409,14 +490,16 @@ static int hsw_fw_ready(struct snd_sof_dev *sdev, u32 msg_id) fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_dbg(sdev->dev, " mailbox DSP initiated 0x%x - size 0x%x\n",
fw_ready->dspbox_offset, fw_ready->dspbox_size);
- dev_dbg(sdev->dev, " mailbox Host initiated 0x%x - size 0x%x\n",
fw_ready->hostbox_offset, fw_ready->hostbox_size);
- dev_info(sdev->dev, " Firmware info: version %d:%d-%s build %d on %s:%s\n",
dev_info(sdev->dev,
" Firmware info: version %d:%d-%s build %d on %s:%s\n",
v->major, v->minor, v->tag, v->build, v->date, v->time);
/* now check for extended data */
snd_sof_fw_parse_ext_data(sdev, MBOX_OFFSET +
sizeof(struct sof_ipc_fw_ready));
hsw_get_windows(sdev);
return 0; }
participants (2)
-
Pierre-Louis Bossart
-
Xiuli Pan