Skip to contentSkip to conversation

ASoC: Intel: sst - add the merrifield DSP driver

PATCH Superseded Vinod Koul 2 participants 24 messages Jul 9, 2014 – Jul 19, 2014

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Vinod Koul

author
#0 lore raw

cover ASoC: Intel: sst - add the merrifield DSP driver

This path series add the Merrifield DSP driver which is used to load and managed the DSP along with sending and receiving IPCs for PCM and compressed audio

Vinod Koul (7):
ASoC: Intel: add sst shim register start-end variables
ASoC: Intel: mfld: add dsp error codes
ASoC: Intel: mrlfd - add generic parameter interface
ASoC: Intel: mrfld - add the dsp sst driver
ASoC: Intel: sst: add power management handling
ASoC: Intel: sst: load firmware using async callback
ASoC: Intel: sst - add compressed ops handling

 arch/x86/include/asm/platform_sst_audio.h |   33 +
 sound/soc/intel/Kconfig                   |    4 +
 sound/soc/intel/Makefile                  |    3 +
 sound/soc/intel/sst-dsp.h                 |    4 +
 sound/soc/intel/sst-mfld-dsp.h            |   15 +
 sound/soc/intel/sst-mfld-platform.h       |    5 +-
 sound/soc/intel/sst/Makefile              |    3 +
 sound/soc/intel/sst/sst.c                 |  586 ++++++++++++++++++
 sound/soc/intel/sst/sst.h                 |  666 ++++++++++++++++++++
 sound/soc/intel/sst/sst_drv_interface.c   |  819 +++++++++++++++++++++++++
 sound/soc/intel/sst/sst_ipc.c             |  368 +++++++++++
 sound/soc/intel/sst/sst_loader.c          |  951 +++++++++++++++++++++++++++++
 sound/soc/intel/sst/sst_pvt.c             |  208 +++++++
 sound/soc/intel/sst/sst_stream.c          |  534 ++++++++++++++++
 14 files changed, 4198 insertions(+), 1 deletions(-)
 create mode 100644 sound/soc/intel/sst/Makefile
 create mode 100644 sound/soc/intel/sst/sst.c
 create mode 100644 sound/soc/intel/sst/sst.h
 create mode 100644 sound/soc/intel/sst/sst_drv_interface.c
 create mode 100644 sound/soc/intel/sst/sst_ipc.c
 create mode 100644 sound/soc/intel/sst/sst_loader.c
 create mode 100644 sound/soc/intel/sst/sst_pvt.c
 create mode 100644 sound/soc/intel/sst/sst_stream.c
author
#1 lore raw

PATCH 1/7 ASoC: Intel: add sst shim register start-end variables

the shim registers start and end can be useful while parsing the shim addresses, so add these

---
 sound/soc/intel/sst-dsp.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
sound/soc/intel/sst-dsp.h +4 -0
index e44423b..967fb32 100644
@@ -53,6 +53,10 @@
 #define SST_CSR2		0x80
 #define SST_LTRC		0xE0
 #define SST_HDMC		0xE8
+
+#define SST_SHIM_BEGIN		SST_CSR
+#define SST_SHIM_END		SST_HDMC
+
 #define SST_DBGO		0xF0
 
 #define SST_SHIM_SIZE		0x100
Signature · 1 line
1.7.0.4
maintainer Applied
#2 lore raw

Re: [PATCH 1/7] ASoC: Intel: add sst shim register start-end variables

Quoted 2 lines · Vinod Koul

the shim registers start and end can be useful while parsing the shim addresses, so add these

Applied, thanks.

author
#3 lore raw

PATCH 2/7 ASoC: Intel: mfld: add dsp error codes

In reply to Vinod Koul

DSP returns error codes for IPC return so add them in driver

---
 sound/soc/intel/sst-mfld-dsp.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
sound/soc/intel/sst-mfld-dsp.h +15 -0
index 2c88785..4257263 100644
@@ -171,6 +171,21 @@ enum stream_type {
 	SST_STREAM_TYPE_MUSIC = 1,
 };
 
+enum sst_error_codes {
+	/* Error code,response to msgId: Description */
+	/* Common error codes */
+	SST_SUCCESS = 0,        /* Success */
+	SST_ERR_INVALID_STREAM_ID = 1,
+	SST_ERR_INVALID_MSG_ID = 2,
+	SST_ERR_INVALID_STREAM_OP = 3,
+	SST_ERR_INVALID_PARAMS = 4,
+	SST_ERR_INVALID_CODEC = 5,
+	SST_ERR_INVALID_MEDIA_TYPE = 6,
+	SST_ERR_STREAM_ERR = 7,
+
+	SST_ERR_STREAM_IN_USE = 15,
+};
+
 struct ipc_dsp_hdr {
 	u16 mod_index_id:8;		/*!< DSP Command ID specific to tasks */
 	u16 pipe_id:8;	/*!< instance of the module in the pipeline */
Signature · 1 line
1.7.0.4
maintainer Applied
#4 lore raw

Re: [PATCH 2/7] ASoC: Intel: mfld: add dsp error codes

Quoted 1 line · Vinod Koul

DSP returns error codes for IPC return so add them in driver

Applied, thanks.

author
#5 lore raw

PATCH 3/7 ASoC: Intel: mrlfd - add generic parameter interface

In reply to Vinod Koul

This interface will be used by subsequent patches to set/get parameters from DSP

---
 sound/soc/intel/sst-mfld-platform.h |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
sound/soc/intel/sst-mfld-platform.h +4 -1
index 9dc962f..6c6a42c 100644
@@ -63,7 +63,9 @@ enum sst_controls {
 	SST_SND_BUFFER_POINTER =	0x05,
 	SST_SND_STREAM_INIT =		0x06,
 	SST_SND_START	 =		0x07,
-	SST_MAX_CONTROLS =		0x07,
+	SST_SET_BYTE_STREAM =           0x100A,
+	SST_GET_BYTE_STREAM =           0x100B,
+	SST_MAX_CONTROLS = SST_GET_BYTE_STREAM,
 };
 
 enum sst_stream_ops {
@@ -127,6 +129,7 @@ struct compress_sst_ops {
 struct sst_ops {
 	int (*open) (struct snd_sst_params *str_param);
 	int (*device_control) (int cmd, void *arg);
+	int (*set_generic_params)(enum sst_controls cmd, void *arg);
 	int (*close) (unsigned int str_id);
 };
 
Signature · 1 line
1.7.0.4
maintainer Applied
#6 lore raw

Re: [PATCH 3/7] ASoC: Intel: mrlfd - add generic parameter interface

Quoted 1 line · Vinod Koul

This interface will be used by subsequent patches to set/get parameters from DSP

Applied, thanks. Please try to keep your subject lines consistent and word wrap your changelogs a bit more (they look like they go to exactly 80 columns which isn't good for replying).

author
#7 lore raw

Re: [PATCH 3/7] ASoC: Intel: mrlfd - add generic parameter interface

Quoted 6 lines · Mark Brown
Quoted 1 line · Vinod Koul

This interface will be used by subsequent patches to set/get parameters from DSP

Applied, thanks. Please try to keep your subject lines consistent and word wrap your changelogs a bit more (they look like they go to exactly 80 columns which isn't good for replying).

Yes set it to 80, i agree it cause issues while replying. What do you set, 76??

Signature · 1 line
~Vinod
maintainer
#8 lore raw

Re: [PATCH 3/7] ASoC: Intel: mrlfd - add generic parameter interface

Quoted 7 lines · Vinod Koul
Quoted 3 lines · Mark Brown

Applied, thanks. Please try to keep your subject lines consistent and word wrap your changelogs a bit more (they look like they go to exactly 80 columns which isn't good for replying).

Yes set it to 80, i agree it cause issues while replying. What do you set, 76??

Something like that (I actually do it by eye a lot of the time).

author
#9 lore raw

PATCH 4/7 ASoC: Intel: mrfld - add the dsp sst driver

In reply to Vinod Koul

The SST driver is the missing piece in our driver stack not upstreamed, so push it now :) This driver currently supports PCI device on Merrifield. Future updates will bring support for ACPI device as well as future update to PCI devices as well

This driver currently supports DSP loading suing memcpy, pcm operations and compressed ops (subsequent patch)

---
 arch/x86/include/asm/platform_sst_audio.h |   33 +
 sound/soc/intel/Kconfig                   |    4 +
 sound/soc/intel/Makefile                  |    3 +
 sound/soc/intel/sst/Makefile              |    3 +
 sound/soc/intel/sst/sst.c                 |  439 +++++++++++++
 sound/soc/intel/sst/sst.h                 |  666 ++++++++++++++++++++
 sound/soc/intel/sst/sst_drv_interface.c   |  543 ++++++++++++++++
 sound/soc/intel/sst/sst_ipc.c             |  368 +++++++++++
 sound/soc/intel/sst/sst_loader.c          |  951 +++++++++++++++++++++++++++++
 sound/soc/intel/sst/sst_pvt.c             |  208 +++++++
 sound/soc/intel/sst/sst_stream.c          |  534 ++++++++++++++++
 11 files changed, 3752 insertions(+), 0 deletions(-)
 create mode 100644 sound/soc/intel/sst/Makefile
 create mode 100644 sound/soc/intel/sst/sst.c
 create mode 100644 sound/soc/intel/sst/sst.h
 create mode 100644 sound/soc/intel/sst/sst_drv_interface.c
 create mode 100644 sound/soc/intel/sst/sst_ipc.c
 create mode 100644 sound/soc/intel/sst/sst_loader.c
 create mode 100644 sound/soc/intel/sst/sst_pvt.c
 create mode 100644 sound/soc/intel/sst/sst_stream.c
arch/x86/include/asm/platform_sst_audio.h +33 -0
index 0a4e140..565a617 100644
@@ -16,6 +16,9 @@
 
 #include <linux/sfi.h>
 
+#define MAX_NUM_STREAMS_MRFLD	25
+#define MAX_NUM_STREAMS	MAX_NUM_STREAMS_MRFLD
+
 enum sst_audio_task_id_mrfld {
 	SST_TASK_ID_NONE = 0,
 	SST_TASK_ID_SBA = 1,
@@ -73,6 +76,36 @@ struct sst_platform_data {
 	unsigned int strm_map_size;
 };
 
+struct sst_info {
+	u32 iram_start;
+	u32 iram_end;
+	bool iram_use;
+	u32 dram_start;
+	u32 dram_end;
+	bool dram_use;
+	u32 imr_start;
+	u32 imr_end;
+	bool imr_use;
+	u32 mailbox_start;
+	bool use_elf;
+	bool lpe_viewpt_rqd;
+	unsigned int max_streams;
+	u32 dma_max_len;
+	u8 num_probes;
+};
+
+struct sst_lib_dnld_info {
+	unsigned int mod_base;
+	unsigned int mod_end;
+	unsigned int mod_table_offset;
+	unsigned int mod_table_size;
+	bool mod_ddr_dnld;
+};
+
+struct sst_platform_info {
+	const struct sst_ipc_info *ipc_info;
+	const struct sst_lib_dnld_info *lib_info;
+};
 int add_sst_platform_device(void);
 #endif
 
sound/soc/intel/Kconfig +4 -0
index c30fedb..e978a47 100644
@@ -3,6 +3,7 @@ config SND_MFLD_MACHINE
 	depends on INTEL_SCU_IPC
 	select SND_SOC_SN95031
 	select SND_SST_MFLD_PLATFORM
+	select SND_SST_IPC
 	help
           This adds support for ASoC machine driver for Intel(R) MID Medfield platform
           used as alsa device in audio substem in Intel(R) MID devices
@@ -12,6 +13,9 @@ config SND_MFLD_MACHINE
 config SND_SST_MFLD_PLATFORM
 	tristate
 
+config SND_SST_IPC
+	tristate
+
 config SND_SOC_INTEL_SST
 	tristate "ASoC support for Intel(R) Smart Sound Technology"
 	select SND_SOC_INTEL_SST_ACPI if ACPI
sound/soc/intel/Makefile +3 -0
index 4bfca79..6f4cefe 100644
@@ -28,3 +28,6 @@ snd-soc-sst-byt-max98090-mach-objs := byt-max98090.o
 obj-$(CONFIG_SND_SOC_INTEL_HASWELL_MACH) += snd-soc-sst-haswell.o
 obj-$(CONFIG_SND_SOC_INTEL_BYT_RT5640_MACH) += snd-soc-sst-byt-rt5640-mach.o
 obj-$(CONFIG_SND_SOC_INTEL_BYT_MAX98090_MACH) += snd-soc-sst-byt-max98090-mach.o
+
+# DSP driver
+obj-$(CONFIG_SND_SST_IPC) += sst/
sound/soc/intel/sst/Makefile new file +3 -0
new file mode 100644
index 0000000..4d0e79b
@@ -0,0 +1,3 @@
+snd-intel-sst-objs := sst.o sst_ipc.o sst_stream.o sst_drv_interface.o sst_loader.o sst_pvt.o
+
+obj-$(CONFIG_SND_SST_IPC) += snd-intel-sst.o
sound/soc/intel/sst/sst.c new file +439 -0

439 lines not on this page · raw message

sound/soc/intel/sst/sst.h new file +666 -0

666 lines not on this page · raw message

sound/soc/intel/sst/sst_drv_interface.c new file +543 -0

543 lines not on this page · raw message

sound/soc/intel/sst/sst_ipc.c new file +368 -0

368 lines not on this page · raw message

sound/soc/intel/sst/sst_loader.c new file +951 -0

914 lines not on this page · raw message

sound/soc/intel/sst/sst_pvt.c new file +208 -0

208 lines not on this page · raw message

sound/soc/intel/sst/sst_stream.c new file +534 -0

534 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
1.7.0.4

Part of the diff is not shown here. View the raw message.

maintainer
#10 lore raw

Re: [PATCH 4/7] ASoC: Intel: mrfld - add the dsp sst driver

Quoted 4 lines · Vinod Koul

The SST driver is the missing piece in our driver stack not upstreamed, so push it now :) This driver currently supports PCI device on Merrifield. Future updates will bring support for ACPI device as well as future update to PCI devices as well

I've started reviewing this several times now but it's a really big change to review, and not just huge data tables but actual code. It'd really benefit from being split up a bit further.

Have you looked at the mailbox framework (not merged yet but hopefully getting close to it)?

Quoted 1 line

+MODULE_VERSION(SST_DRIVER_VERSION);

Probably better to drop driver versions from mainline.

sound/soc/intel/sst/sst.c line 54

Quoted 2 lines
sound/soc/intel/sst/sst.c new file +2 -0
+#define SST_IS_PROCESS_REPLY(header) ((header & PROCESS_MSG) ? true : false)
+#define SST_VALIDATE_MAILBOX_SIZE(size) ((size <= SST_MAILBOX_SIZE) ? true : false)

Inline functions please.

sound/soc/intel/sst/sst.c line 123

Quoted 8 lines
sound/soc/intel/sst/sst.c new file +8 -0
+static irqreturn_t intel_sst_irq_thread_mrfld(int irq, void *context)
+{
+	struct intel_sst_drv *drv = (struct intel_sst_drv *) context;
+	struct ipc_post *__msg, *msg = NULL;
+	unsigned long irq_flags;
+
+	if (list_empty(&drv->rx_list))
+		return IRQ_HANDLED;

Why would the IRQ thread be running with nothing to do, and if it can be...

sound/soc/intel/sst/sst.c line 126

Quoted 2 lines
sound/soc/intel/sst/sst.c new file +2 -0
+	spin_lock_irqsave(&drv->rx_msg_lock, irq_flags);
+	list_for_each_entry_safe(msg, __msg, &drv->rx_list, node) {

...won't we handle that gracefully anyway?

sound/soc/intel/sst/sst.c line 183

Quoted 12 lines
sound/soc/intel/sst/sst.c new file +12 -0
+int sst_alloc_drv_context(struct device *dev)
+{
+	struct intel_sst_drv *ctx;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx) {
+		pr_err("malloc fail\n");
+		return -ENOMEM;
+	}
+	sst_drv_ctx = ctx;
+	return 0;
+}

As others were saying I'd really like to see some sort of case being made for a global variable, and if we really do need a global variable why not just declare it rather than dynamically allocating?

sound/soc/intel/sst/sst.c line 214

Quoted 2 lines
sound/soc/intel/sst/sst.c new file +2 -0
+	if (0 != sst_driver_ops(sst_drv_ctx))
+		return -EINVAL;

if (!sst_driver_ops())

Quoted 1 line

+#define SST_DRIVER_VERSION "5.0.0"

Generally better to drop these from mainline, the kernel version should be enough.

sound/soc/intel/sst/sst.h line 518

Quoted 13 lines
sound/soc/intel/sst/sst.h new file +13 -0
+static inline int sst_pm_runtime_put(struct intel_sst_drv *sst_drv)
+{
+	int ret;
+
+	ret = pm_runtime_put_sync(sst_drv->dev);
+	if (ret < 0)
+		return ret;
+	atomic_dec(&sst_drv->pm_usage_count);
+
+	pr_debug("%s: count is %d now..\n", __func__,
+			atomic_read(&sst_drv->pm_usage_count));
+	return 0;
+}

I'm not entirely clear why this is here but if it's to provide trace just instrument the runtime PM core.

Quoted 7 lines

+ * @sst_drv_ctx : driver context
+ *
+ * this inline function assigns a private id for calls that dont have stream
+ * context yet, should be called with lock held
+ */

sound/soc/intel/sst/sst.h new file +2 -0
+static inline unsigned int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx)
+{

sound/soc/intel/sst/sst.h line 562

Quoted 10 lines
sound/soc/intel/sst/sst.h new file +10 -0
+	unsigned int local;
+
+	spin_lock(&sst_drv_ctx->block_lock);
+	sst_drv_ctx->pvt_id++;
+	if (sst_drv_ctx->pvt_id > MAX_BLOCKS)
+		sst_drv_ctx->pvt_id = 1;
+	local = sst_drv_ctx->pvt_id;
+	spin_unlock(&sst_drv_ctx->block_lock);
+	return local;
+}

I would expect this to be checking to see if the IDs are free but it just hands them out in sequence? There appears to be an array of streams statically allocated, why not look there for an unused one?

sound/soc/intel/sst/sst.h line 624

Quoted 7 lines
sound/soc/intel/sst/sst.h new file +7 -0
+static inline void
+sst_set_fw_state_locked(struct intel_sst_drv *sst_drv_ctx, int sst_state)
+{
+	mutex_lock(&sst_drv_ctx->sst_lock);
+	sst_drv_ctx->sst_state = sst_state;
+	mutex_unlock(&sst_drv_ctx->sst_lock);
+}

I can't see any references to this in the code which is good as it seems a little odd to have a function like this.

sound/soc/intel/sst/sst.h line 646

Quoted 2 lines
sound/soc/intel/sst/sst.h new file +2 -0
+int register_sst(struct device *);
+int unregister_sst(struct device *);

Everything else is sst_

Quoted 4 lines
sound/soc/intel/sst/sst_drv_interface.c new file +4 -0
+int sst_download_fw(void)
+{
+	int retval = 0;
+

sound/soc/intel/sst/sst_drv_interface.c line 67

Quoted 10 lines
sound/soc/intel/sst/sst_drv_interface.c new file +10 -0
+	retval = sst_load_fw();
+	if (retval)
+		return retval;
+	pr_debug("fw loaded successful!!!\n");
+
+	if (sst_drv_ctx->ops->restore_dsp_context)
+		sst_drv_ctx->ops->restore_dsp_context();
+	sst_drv_ctx->sst_state = SST_FW_RUNNING;
+	return retval;
+}

So sst_load_fw() is wrapped with this function sst_download_fw() which does a tiny bit of extra stuff which might be mostly better done in the core function...

sound/soc/intel/sst/sst_drv_interface.c line 75

Quoted 7 lines
sound/soc/intel/sst/sst_drv_interface.c new file +7 -0
+int free_stream_context(unsigned int str_id)
+{
+	struct stream_info *stream;
+	int ret = 0;
+
+	stream = get_stream_info(str_id);
+	if (stream) {

It's a bit scary that this might be used with an invalid ID - what happens if the ID got reallocated?

Review

Quoted 2 lines
(quoted diff) +2 -0
+	retval = sst_drv_ctx->ops->alloc_stream((char *) str_param, block);
+	str_id = retval;

This cast is scary... should alloc_stream() be taking a void?

sound/soc/intel/sst/sst_drv_interface.c line 140

Quoted 5 lines
sound/soc/intel/sst/sst_drv_interface.c new file +4 -0
+	/* Block the call for reply */
+	retval = sst_wait_timeout(sst_drv_ctx, block);
+	if (block->data) {
 
+	} else if (retval != 0) {

It'd be less surprising if the first check were for retval.

sound/soc/intel/sst/sst_drv_interface.c line 204

Quoted 5 lines
sound/soc/intel/sst/sst_drv_interface.c new file +5 -0
+	pr_debug("In %s\n", __func__);
+	/* stream is not allocated, we are allocating */
+	retval = sst_get_stream_allocated(str_param, &lib_dnld);
+
+	if  (retval <= 0) {

Coding style (there's quite a bit of odd coding styles throughout this code, slightly odd indentation, missing blanks and so on - it generally doesn't quite look like Linux code).

sound/soc/intel/sst/sst_drv_interface.c line 222

Quoted 7 lines
sound/soc/intel/sst/sst_drv_interface.c new file +7 -0
+/**
+* intel_sst_check_device - checks SST device
+*
+* This utility function checks the state of SST device and downlaods FW if
+* not done, or resumes the device if suspended
+*/
+int intel_sst_check_device(void)

Can we have a better name please? But this all seems very odd, why is runtime PM not causing the firmware to be loaded?

sound/soc/intel/sst/sst_drv_interface.c line 324

Quoted 5 lines
sound/soc/intel/sst/sst_drv_interface.c new file +5 -0
+	/* The free_stream will return a error if there is no stream to free,
+	(i.e. the alloc failure case). And in this case the open does a put in
+	the error scenario, so skip in this case.
+		In the close we need to handle put in the success scenario and
+	the timeout error(EBUSY) scenario. */

Another weird coding style thing.

sound/soc/intel/sst/sst_drv_interface.c line 408

Quoted 9 lines
sound/soc/intel/sst/sst_drv_interface.c new file +9 -0
+static int sst_device_control(int cmd, void *arg)
+{
+	int retval = 0, str_id = 0;
+
+	if (sst_drv_ctx->sst_state != SST_FW_RUNNING)
+		return 0;
+
+	switch (cmd) {
+	case SST_SND_START: {

Eew, ioctl(). This would be clearer if it were a series of functions, there's nothing shared here.

sound/soc/intel/sst/sst_drv_interface.c line 491

Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c new file +6 -0
+static int sst_set_generic_params(enum sst_controls cmd, void *arg)
+{
+	int ret_val = 0;
+
+	if (NULL == arg)
+		return -EINVAL;

Again an ioctl()...

sound/soc/intel/sst/sst_ipc.c line 170

Quoted 12 lines
sound/soc/intel/sst/sst_ipc.c new file +12 -0
+	/* check busy bit */
+	header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
+	while (header.p.header_high.part.busy) {
+		if (loop_count > 10) {
+			pr_err("sst: Busy wait failed, cant send this msg\n");
+			retval = -EBUSY;
+			goto out;
+		}
+		udelay(500);
+		loop_count++;
+		header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
+	}

Throw a cpu_relax() in there if we need to spin...

sound/soc/intel/sst/sst_ipc.c line 242

Quoted 5 lines
sound/soc/intel/sst/sst_ipc.c new file +5 -0
+	pr_info("FW Version %02x.%02x.%02x.%02x\n",
+		init->fw_version.type, init->fw_version.major,
+		init->fw_version.minor, init->fw_version.build);
+	pr_info("Build date %s Time %s\n",
+			init->build_info.date, init->build_info.time);

Same comment as for some of the other firmwares - consider providing this via /proc or sysfs as well.

Quoted 15 lines
sound/soc/intel/sst/sst_loader.c new file +15 -0
+static inline int sst_validate_elf(const struct firmware *sst_bin, bool dynamic)
+{
+	Elf32_Ehdr *elf;
+
+	BUG_ON(!sst_bin);
+
+	pr_debug("IN %s\n", __func__);
+
+	elf = (Elf32_Ehdr *)sst_bin->data;
+
+	if ((elf->e_ident[0] != 0x7F) || (elf->e_ident[1] != 'E') ||
+	    (elf->e_ident[2] != 'L') || (elf->e_ident[3] != 'F')) {
+		pr_debug("ELF Header Not found!%zu\n", sst_bin->size);
+		return -EINVAL;
+	}

sound/soc/intel/sst/sst_loader.c line 198

Quoted 10 lines
sound/soc/intel/sst/sst_loader.c new file +10 -0
+
+	if (dynamic == true) {
+		if (elf->e_type != ET_DYN) {
+			pr_err("Not a dynamic loadable library\n");
+			return -EINVAL;
+		}
+	}
+	pr_debug("Valid ELF Header...%zu\n", sst_bin->size);
+	return 0;
+}

We have generic ELF handling code in the kernel, should this go there?

sound/soc/intel/sst/sst_loader.c line 203

Quoted 2 lines
sound/soc/intel/sst/sst_loader.c new file +2 -0
+{
+	struct fw_header *header;

struct fw_header should probably be better namespaced?

Quoted 6 lines
sound/soc/intel/sst/sst_loader.c new file +6 -0
+void sst_memcpy_free_resources(void)
+{
+	struct sst_memcpy_list *listnode, *tmplistnode;
+
+	pr_debug("entry:%s\n", __func__);
+

sound/soc/intel/sst/sst_loader.c line 444

Quoted 10 lines
sound/soc/intel/sst/sst_loader.c new file +10 -0
+	/*Free the list*/
+	if (!list_empty(&sst_drv_ctx->memcpy_list)) {
+		list_for_each_entry_safe(listnode, tmplistnode,
+				&sst_drv_ctx->memcpy_list, memcpylist) {
+			list_del(&listnode->memcpylist);
+			kfree(listnode);
+		}
+	}
+	sst_memcpy_free_lib_resources();
+}

I'm having a hard time seeing why we don't just copy the data as we go rather than allocating this list? It seems to just be making the code more complex.

sound/soc/intel/sst/sst_stream.c line 407

Quoted 12 lines
sound/soc/intel/sst/sst_stream.c new file +12 -0
+/**
+ * sst_next_track: notify next track
+ * @str_id:		stream ID
+ *
+ * This function is called by any function which wants to
+ * set next track. Current this is NOP as FW doest care
+ */
+int sst_next_track(void)
+{
+	pr_debug("SST DBG: next_track");
+	return 0;
+}

Shouldn't the operation just be made optional then, obviously the upper layers don't care either?

author
#11 lore raw

Re: [PATCH 4/7] ASoC: Intel: mrfld - add the dsp sst driver

Quoted 9 lines · Mark Brown
Quoted 4 lines · Vinod Koul

The SST driver is the missing piece in our driver stack not upstreamed, so push it now :) This driver currently supports PCI device on Merrifield. Future updates will bring support for ACPI device as well as future update to PCI devices as well

I've started reviewing this several times now but it's a really big change to review, and not just huge data tables but actual code. It'd really benefit from being split up a bit further.

well I tried a lot of split up. But further split could have caused lots of bisect issues. One way to do so was to add makefile last. I can try that next time if you are fine

Quoted 7 lines

Have you looked at the mailbox framework (not merged yet but hopefully getting close to it)?

Quoted 1 line

+MODULE_VERSION(SST_DRIVER_VERSION);

Probably better to drop driver versions from mainline.

Sure thing!

Quoted 6 lines

sound/soc/intel/sst/sst.c line 54

Quoted 3 lines
sound/soc/intel/sst/sst.c new file +2 -0
+#define SST_IS_PROCESS_REPLY(header) ((header & PROCESS_MSG) ? true : false)
+#define SST_VALIDATE_MAILBOX_SIZE(size) ((size <= SST_MAILBOX_SIZE) ? true : false)

Inline functions please.

Quoted 11 lines

sound/soc/intel/sst/sst.c line 123

Quoted 8 lines
sound/soc/intel/sst/sst.c new file +8 -0
+static irqreturn_t intel_sst_irq_thread_mrfld(int irq, void *context)
+{
+	struct intel_sst_drv *drv = (struct intel_sst_drv *) context;
+	struct ipc_post *__msg, *msg = NULL;
+	unsigned long irq_flags;
+
+	if (list_empty(&drv->rx_list))
+		return IRQ_HANDLED;

Why would the IRQ thread be running with nothing to do, and if it can be...

Cant think of, we need to remove this!

Quoted 5 lines

sound/soc/intel/sst/sst.c line 126

Quoted 3 lines
sound/soc/intel/sst/sst.c new file +2 -0
+	spin_lock_irqsave(&drv->rx_msg_lock, irq_flags);
+	list_for_each_entry_safe(msg, __msg, &drv->rx_list, node) {

...won't we handle that gracefully anyway?

Are you referring to lock + irqsave?

Quoted 8 lines
Quoted 8 lines
sound/soc/intel/sst/sst.c new file +8 -0
+int sst_alloc_drv_context(struct device *dev)
+{
+	struct intel_sst_drv *ctx;
+
+	ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
+	if (!ctx) {
+		pr_err("malloc fail\n");
+		return -ENOMEM;
Quoted 8 lines

sound/soc/intel/sst/sst.c line 183

Quoted 4 lines
sound/soc/intel/sst/sst.c new file +4 -0
+	}
+	sst_drv_ctx = ctx;
+	return 0;
+}

As others were saying I'd really like to see some sort of case being made for a global variable, and if we really do need a global variable why not just declare it rather than dynamically allocating?

For this case none, we can try removing this which was more for legacy reasons when we had pvt ioctls for offload

Quoted 10 lines

sound/soc/intel/sst/sst.c line 214

Quoted 2 lines
sound/soc/intel/sst/sst.c new file +2 -0
+	if (0 != sst_driver_ops(sst_drv_ctx))
+		return -EINVAL;

if (!sst_driver_ops())

Quoted 1 line

+#define SST_DRIVER_VERSION "5.0.0"

Generally better to drop these from mainline, the kernel version should be enough.

Quoted 16 lines

sound/soc/intel/sst/sst.h line 518

Quoted 13 lines
sound/soc/intel/sst/sst.h new file +13 -0
+static inline int sst_pm_runtime_put(struct intel_sst_drv *sst_drv)
+{
+	int ret;
+
+	ret = pm_runtime_put_sync(sst_drv->dev);
+	if (ret < 0)
+		return ret;
+	atomic_dec(&sst_drv->pm_usage_count);
+
+	pr_debug("%s: count is %d now..\n", __func__,
+			atomic_read(&sst_drv->pm_usage_count));
+	return 0;
+}

I'm not entirely clear why this is here but if it's to provide trace just instrument the runtime PM core.

Well the only usage of pm_usage_count locally is to check in runtime pm suspend to S3 transitions. When we are runtime suspended and S3 triggers, the device usage count goes up to 1. Then runtime resume and classic suspend is invoked in that order. So if we are in this scenario we can't rely on checks using frameworks count.

Quoted 14 lines
Quoted 14 lines

+ * @sst_drv_ctx : driver context
+ *
+ * this inline function assigns a private id for calls that dont have stream
+ * context yet, should be called with lock held
+ */

sound/soc/intel/sst/sst.h new file +8 -0
+static inline unsigned int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx)
+{
+	unsigned int local;
+
+	spin_lock(&sst_drv_ctx->block_lock);
+	sst_drv_ctx->pvt_id++;
+	if (sst_drv_ctx->pvt_id > MAX_BLOCKS)
+		sst_drv_ctx->pvt_id = 1;
Quoted 8 lines

sound/soc/intel/sst/sst.h line 562

Quoted 4 lines
sound/soc/intel/sst/sst.h new file +4 -0
+	local = sst_drv_ctx->pvt_id;
+	spin_unlock(&sst_drv_ctx->block_lock);
+	return local;
+}

I would expect this to be checking to see if the IDs are free but it just hands them out in sequence? There appears to be an array of streams statically allocated, why not look there for an unused one?

we use these incrementally. The driver stamps each IPC to DSP with a number. The size is limited by bits in the IPCs. So we keep going till we hit max, that time we set it back to 1

These ids are not freed or allocated as IPC latency is small enough and IPCs less. We haven't hot scenarios where we go complete round but IPC is still pending :)

Quoted 11 lines

sound/soc/intel/sst/sst.h line 624

Quoted 8 lines
sound/soc/intel/sst/sst.h new file +7 -0
+static inline void
+sst_set_fw_state_locked(struct intel_sst_drv *sst_drv_ctx, int sst_state)
+{
+	mutex_lock(&sst_drv_ctx->sst_lock);
+	sst_drv_ctx->sst_state = sst_state;
+	mutex_unlock(&sst_drv_ctx->sst_lock);
+}

I can't see any references to this in the code which is good as it seems a little odd to have a function like this.

My bad, this was to be removed :(

Quoted 4 lines

sound/soc/intel/sst/sst.h line 646

Quoted 2 lines
sound/soc/intel/sst/sst.h new file +2 -0
+int register_sst(struct device *);
+int unregister_sst(struct device *);

Everything else is sst_

Hmmm fair point!

Quoted 11 lines
Quoted 11 lines
sound/soc/intel/sst/sst_drv_interface.c new file +10 -0
+int sst_download_fw(void)
+{
+	int retval = 0;
+
+	retval = sst_load_fw();
+	if (retval)
+		return retval;
+	pr_debug("fw loaded successful!!!\n");
+
+	if (sst_drv_ctx->ops->restore_dsp_context)
Quoted 8 lines

sound/soc/intel/sst/sst_drv_interface.c line 67

Quoted 4 lines
sound/soc/intel/sst/sst_drv_interface.c new file +4 -0
+		sst_drv_ctx->ops->restore_dsp_context();
+	sst_drv_ctx->sst_state = SST_FW_RUNNING;
+	return retval;
+}

So sst_load_fw() is wrapped with this function sst_download_fw() which does a tiny bit of extra stuff which might be mostly better done in the core function...

ok

Quoted 11 lines

sound/soc/intel/sst/sst_drv_interface.c line 75

Quoted 8 lines
sound/soc/intel/sst/sst_drv_interface.c new file +7 -0
+int free_stream_context(unsigned int str_id)
+{
+	struct stream_info *stream;
+	int ret = 0;
+
+	stream = get_stream_info(str_id);
+	if (stream) {

It's a bit scary that this might be used with an invalid ID - what happens if the ID got reallocated?

The free routine checks for valid ID first

Quoted 5 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	retval = sst_drv_ctx->ops->alloc_stream((char *) str_param, block);
+	str_id = retval;

This cast is scary... should alloc_stream() be taking a void?

Well we had two versions die to tow gens of DSP FW, we mught be able to clean this up, will give it a shot!

Quoted 8 lines

sound/soc/intel/sst/sst_drv_interface.c line 140

Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c new file +4 -0
+	/* Block the call for reply */
+	retval = sst_wait_timeout(sst_drv_ctx, block);
+	if (block->data) {
 
+	} else if (retval != 0) {

It'd be less surprising if the first check were for retval.

ok

Quoted 10 lines

sound/soc/intel/sst/sst_drv_interface.c line 204

Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c new file +5 -0
+	pr_debug("In %s\n", __func__);
+	/* stream is not allocated, we are allocating */
+	retval = sst_get_stream_allocated(str_param, &lib_dnld);
+
+	if  (retval <= 0) {

Coding style (there's quite a bit of odd coding styles throughout this code, slightly odd indentation, missing blanks and so on - it generally doesn't quite look like Linux code).

well this was started off in 2008, never got to a point to push upstream though tried few times!. Will fix these

Quoted 11 lines

sound/soc/intel/sst/sst_drv_interface.c line 222

Quoted 8 lines
sound/soc/intel/sst/sst_drv_interface.c new file +7 -0
+/**
+* intel_sst_check_device - checks SST device
+*
+* This utility function checks the state of SST device and downlaods FW if
+* not done, or resumes the device if suspended
+*/
+int intel_sst_check_device(void)

Can we have a better name please? But this all seems very odd, why is runtime PM not causing the firmware to be loaded?

well as previously stated runtime resume might be invoked during S3, so we wnat to load fw after calling _get_sync() so rather than calling _get_sync() and download everywhere we wrapped it here

Quoted 8 lines

sound/soc/intel/sst/sst_drv_interface.c line 324

Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c new file +5 -0
+	/* The free_stream will return a error if there is no stream to free,
+	(i.e. the alloc failure case). And in this case the open does a put in
+	the error scenario, so skip in this case.
+		In the close we need to handle put in the success scenario and
+	the timeout error(EBUSY) scenario. */

Another weird coding style thing.

will fix

Quoted 14 lines

sound/soc/intel/sst/sst_drv_interface.c line 408

Quoted 10 lines
sound/soc/intel/sst/sst_drv_interface.c new file +9 -0
+static int sst_device_control(int cmd, void *arg)
+{
+	int retval = 0, str_id = 0;
+
+	if (sst_drv_ctx->sst_state != SST_FW_RUNNING)
+		return 0;
+
+	switch (cmd) {
+	case SST_SND_START: {

Eew, ioctl(). This would be clearer if it were a series of functions, there's nothing shared here.

Quoted 8 lines

sound/soc/intel/sst/sst_drv_interface.c line 491

Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c new file +6 -0
+static int sst_set_generic_params(enum sst_controls cmd, void *arg)
+{
+	int ret_val = 0;
+
+	if (NULL == arg)
+		return -EINVAL;

Again an ioctl()...

okay will move to series of functions

Quoted 15 lines

sound/soc/intel/sst/sst_ipc.c line 170

Quoted 13 lines
sound/soc/intel/sst/sst_ipc.c new file +12 -0
+	/* check busy bit */
+	header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
+	while (header.p.header_high.part.busy) {
+		if (loop_count > 10) {
+			pr_err("sst: Busy wait failed, cant send this msg\n");
+			retval = -EBUSY;
+			goto out;
+		}
+		udelay(500);
+		loop_count++;
+		header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
+	}

Throw a cpu_relax() in there if we need to spin...

its more busy wait for the bit to be freed. Since IPC latency is supposed to be minimal checking like this helps to minimize.

Quoted 9 lines

sound/soc/intel/sst/sst_ipc.c line 242

Quoted 6 lines
sound/soc/intel/sst/sst_ipc.c new file +5 -0
+	pr_info("FW Version %02x.%02x.%02x.%02x\n",
+		init->fw_version.type, init->fw_version.major,
+		init->fw_version.minor, init->fw_version.build);
+	pr_info("Build date %s Time %s\n",
+			init->build_info.date, init->build_info.time);

Same comment as for some of the other firmwares - consider providing this via /proc or sysfs as well.

ok

Quoted 20 lines
Quoted 20 lines
sound/soc/intel/sst/sst_loader.c new file +19 -0
+static inline int sst_validate_elf(const struct firmware *sst_bin, bool dynamic)
+{
+	Elf32_Ehdr *elf;
+
+	BUG_ON(!sst_bin);
+
+	pr_debug("IN %s\n", __func__);
+
+	elf = (Elf32_Ehdr *)sst_bin->data;
+
+	if ((elf->e_ident[0] != 0x7F) || (elf->e_ident[1] != 'E') ||
+	    (elf->e_ident[2] != 'L') || (elf->e_ident[3] != 'F')) {
+		pr_debug("ELF Header Not found!%zu\n", sst_bin->size);
+		return -EINVAL;
+	}
+
+	if (dynamic == true) {
+		if (elf->e_type != ET_DYN) {
+			pr_err("Not a dynamic loadable library\n");
Quoted 8 lines

sound/soc/intel/sst/sst_loader.c line 198

Quoted 6 lines
sound/soc/intel/sst/sst_loader.c new file +6 -0
+			return -EINVAL;
+		}
+	}
+	pr_debug("Valid ELF Header...%zu\n", sst_bin->size);
+	return 0;
+}

We have generic ELF handling code in the kernel, should this go there?

will check that

Quoted 18 lines

sound/soc/intel/sst/sst_loader.c line 203

Quoted 3 lines
sound/soc/intel/sst/sst_loader.c new file +2 -0
+{
+	struct fw_header *header;

struct fw_header should probably be better namespaced?

Quoted 12 lines
sound/soc/intel/sst/sst_loader.c new file +12 -0
+void sst_memcpy_free_resources(void)
+{
+	struct sst_memcpy_list *listnode, *tmplistnode;
+
+	pr_debug("entry:%s\n", __func__);
+
+	/*Free the list*/
+	if (!list_empty(&sst_drv_ctx->memcpy_list)) {
+		list_for_each_entry_safe(listnode, tmplistnode,
+				&sst_drv_ctx->memcpy_list, memcpylist) {
+			list_del(&listnode->memcpylist);
+			kfree(listnode);
Quoted 8 lines

sound/soc/intel/sst/sst_loader.c line 444

Quoted 4 lines
sound/soc/intel/sst/sst_loader.c new file +4 -0
+		}
+	}
+	sst_memcpy_free_lib_resources();
+}

I'm having a hard time seeing why we don't just copy the data as we go rather than allocating this list? It seems to just be making the code more complex.

because we support DMA too. so common parsing and then later we either do memcpy and dma. Will push DMA bits after this series.

Quoted 7 lines
Quoted 7 lines

+/**
+ * sst_next_track: notify next track
+ * @str_id: stream ID
+ *
+ * This function is called by any function which wants to
+ * set next track. Current this is NOP as FW doest care
+ */

Quoted 8 lines

sound/soc/intel/sst/sst_stream.c line 407

Quoted 5 lines
sound/soc/intel/sst/sst_stream.c new file +5 -0
+int sst_next_track(void)
+{
+	pr_debug("SST DBG: next_track");
+	return 0;
+}

Shouldn't the operation just be made optional then, obviously the upper layers don't care either?

Sure

Signature · 1 line
~Vinod
maintainer
#12 lore raw

Re: [PATCH 4/7] ASoC: Intel: mrfld - add the dsp sst driver

Quoted 5 lines · Vinod Koul
Quoted 4 lines · Mark Brown

On Wed, Jul 09, 2014 at 02:57:52PM +0530, Vinod Koul wrote:

Have you looked at the mailbox framework (not merged yet but hopefully getting close to it)?

Not seeing an answer to this...

Quoted 6 lines
Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	if (list_empty(&drv->rx_list))
+		return IRQ_HANDLED;

Why would the IRQ thread be running with nothing to do, and if it can be...

Quoted 8 lines

Cant think of, we need to remove this!

Quoted 4 lines

sound/soc/intel/sst/sst.c line 126

Quoted 2 lines
sound/soc/intel/sst/sst.c new file +2 -0
+	spin_lock_irqsave(&drv->rx_msg_lock, irq_flags);
+	list_for_each_entry_safe(msg, __msg, &drv->rx_list, node) {

...won't we handle that gracefully anyway?

Are you referring to lock + irqsave?

This is part of the thing about the list_empty() check being redundant.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/intel/sst/sst.h new file +8 -0
+static inline int sst_pm_runtime_put(struct intel_sst_drv *sst_drv)
+{
+	int ret;
+
+	ret = pm_runtime_put_sync(sst_drv->dev);
+	if (ret < 0)
+		return ret;
+	atomic_dec(&sst_drv->pm_usage_count);
Quoted 8 lines

sound/soc/intel/sst/sst.h line 518

Quoted 5 lines
sound/soc/intel/sst/sst.h new file +5 -0
+
+	pr_debug("%s: count is %d now..\n", __func__,
+			atomic_read(&sst_drv->pm_usage_count));
+	return 0;
+}

I'm not entirely clear why this is here but if it's to provide trace just instrument the runtime PM core.

Quoted 5 lines

Well the only usage of pm_usage_count locally is to check in runtime pm suspend to S3 transitions. When we are runtime suspended and S3 triggers, the device usage count goes up to 1. Then runtime resume and classic suspend is invoked in that order. So if we are in this scenario we can't rely on checks using frameworks count.

Yes, you can. You can check to see if the device is runtime suspended and really this isn't at all specific to this driver - it's a general thing that affects lots of drivers so shouldn't be open coded in this one. IIRC you're looking for pm_runtime_is_suspended().

Essentially any time you need to use atomic variables in a driver you're probably doing something wrong.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/intel/sst/sst.h new file +8 -0
+static inline unsigned int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx)
+{
+	unsigned int local;
+
+	spin_lock(&sst_drv_ctx->block_lock);
+	sst_drv_ctx->pvt_id++;
+	if (sst_drv_ctx->pvt_id > MAX_BLOCKS)
+		sst_drv_ctx->pvt_id = 1;
Quoted 8 lines

sound/soc/intel/sst/sst.h line 562

Quoted 4 lines
sound/soc/intel/sst/sst.h new file +4 -0
+	local = sst_drv_ctx->pvt_id;
+	spin_unlock(&sst_drv_ctx->block_lock);
+	return local;
+}

I would expect this to be checking to see if the IDs are free but it just hands them out in sequence? There appears to be an array of streams statically allocated, why not look there for an unused one?

Quoted 7 lines

we use these incrementally. The driver stamps each IPC to DSP with a number. The size is limited by bits in the IPCs. So we keep going till we hit max, that time we set it back to 1

These ids are not freed or allocated as IPC latency is small enough and IPCs less. We haven't hot scenarios where we go complete round but IPC is still pending :)

Yet.

Quoted 11 lines
Quoted 10 lines

sound/soc/intel/sst/sst_drv_interface.c line 75

Quoted 7 lines
sound/soc/intel/sst/sst_drv_interface.c new file +7 -0
+int free_stream_context(unsigned int str_id)
+{
+	struct stream_info *stream;
+	int ret = 0;
+
+	stream = get_stream_info(str_id);
+	if (stream) {

It's a bit scary that this might be used with an invalid ID - what happens if the ID got reallocated?

Quoted 1 line

The free routine checks for valid ID first

That's not the point - the point is that if you're freeing what might be an invalid ID I don't see any guarantee that the ID hasn't been allocated to something else. It's different if there's a specific ID that can be used for an invalid ID but this looks like it's working around double frees.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
sound/soc/intel/sst/sst_ipc.c new file +4 -0
+	while (header.p.header_high.part.busy) {
+		if (loop_count > 10) {
+			pr_err("sst: Busy wait failed, cant send this msg\n");
+			retval = -EBUSY;
Quoted 8 lines

sound/soc/intel/sst/sst_ipc.c line 170

Quoted 6 lines
sound/soc/intel/sst/sst_ipc.c new file +6 -0
+			goto out;
+		}
+		udelay(500);
+		loop_count++;
+		header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
+	}

Throw a cpu_relax() in there if we need to spin...

Quoted 2 lines

its more busy wait for the bit to be freed. Since IPC latency is supposed to be minimal checking like this helps to minimize.

It's a udelay(500) which is pretty long for a busy wait...

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
sound/soc/intel/sst/sst_loader.c new file +5 -0
+	if (!list_empty(&sst_drv_ctx->memcpy_list)) {
+		list_for_each_entry_safe(listnode, tmplistnode,
+				&sst_drv_ctx->memcpy_list, memcpylist) {
+			list_del(&listnode->memcpylist);
+			kfree(listnode);
Quoted 8 lines

sound/soc/intel/sst/sst_loader.c line 444

Quoted 4 lines
sound/soc/intel/sst/sst_loader.c new file +4 -0
+		}
+	}
+	sst_memcpy_free_lib_resources();
+}

I'm having a hard time seeing why we don't just copy the data as we go rather than allocating this list? It seems to just be making the code more complex.

Quoted 2 lines

because we support DMA too. so common parsing and then later we either do memcpy and dma. Will push DMA bits after this series.

Keep it simple for now and just memcpy() directly, leaving the functions that select I/O vs memcpy() - you can always go back and add the DMA later.

author
#13 lore raw

Re: [PATCH 4/7] ASoC: Intel: mrfld - add the dsp sst driver

Quoted 8 lines · Mark Brown
Quoted 5 lines · Vinod Koul
Quoted 4 lines · Mark Brown

On Wed, Jul 09, 2014 at 02:57:52PM +0530, Vinod Koul wrote:

Have you looked at the mailbox framework (not merged yet but hopefully getting close to it)?

Not seeing an answer to this...

Oops.. I had seen one of the revs.

We have single channel, single user system. The DSP driver and DAPM will push messages into a queue and we will keep posting.
The framework would have helped if we had multiple channels, multiple users but for now seems a bit heavy for our usage. Am open to revist this if things get simplfied here. The IPC code here is least complex.

Quoted 9 lines
Quoted 8 lines
Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+	if (list_empty(&drv->rx_list))
+		return IRQ_HANDLED;

Why would the IRQ thread be running with nothing to do, and if it can be...

Cant think of, we need to remove this!

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

sound/soc/intel/sst/sst.c line 126

Quoted 2 lines
sound/soc/intel/sst/sst.c new file +2 -0
+	spin_lock_irqsave(&drv->rx_msg_lock, irq_flags);
+	list_for_each_entry_safe(msg, __msg, &drv->rx_list, node) {

...won't we handle that gracefully anyway?

Are you referring to lock + irqsave?

This is part of the thing about the list_empty() check being redundant.

Okay

Quoted 23 lines
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/intel/sst/sst.h new file +8 -0
+static inline int sst_pm_runtime_put(struct intel_sst_drv *sst_drv)
+{
+	int ret;
+
+	ret = pm_runtime_put_sync(sst_drv->dev);
+	if (ret < 0)
+		return ret;
+	atomic_dec(&sst_drv->pm_usage_count);
Quoted 8 lines

sound/soc/intel/sst/sst.h line 518

Quoted 5 lines
sound/soc/intel/sst/sst.h new file +5 -0
+
+	pr_debug("%s: count is %d now..\n", __func__,
+			atomic_read(&sst_drv->pm_usage_count));
+	return 0;
+}

I'm not entirely clear why this is here but if it's to provide trace just instrument the runtime PM core.

Quoted 5 lines

Well the only usage of pm_usage_count locally is to check in runtime pm suspend to S3 transitions. When we are runtime suspended and S3 triggers, the device usage count goes up to 1. Then runtime resume and classic suspend is invoked in that order. So if we are in this scenario we can't rely on checks using frameworks count.

Quoted 4 lines

Yes, you can. You can check to see if the device is runtime suspended and really this isn't at all specific to this driver - it's a general thing that affects lots of drivers so shouldn't be open coded in this one. IIRC you're looking for pm_runtime_is_suspended().

sorry didnt find the symbol, was it removed

Quoted 3 lines

Essentially any time you need to use atomic variables in a driver you're probably doing something wrong.

No issue, i think i can clean this bit up

Quoted 21 lines
Quoted 20 lines
Quoted 8 lines
Quoted 8 lines
sound/soc/intel/sst/sst.h new file +8 -0
+static inline unsigned int sst_assign_pvt_id(struct intel_sst_drv *sst_drv_ctx)
+{
+	unsigned int local;
+
+	spin_lock(&sst_drv_ctx->block_lock);
+	sst_drv_ctx->pvt_id++;
+	if (sst_drv_ctx->pvt_id > MAX_BLOCKS)
+		sst_drv_ctx->pvt_id = 1;
Quoted 8 lines

sound/soc/intel/sst/sst.h line 562

Quoted 4 lines
sound/soc/intel/sst/sst.h new file +4 -0
+	local = sst_drv_ctx->pvt_id;
+	spin_unlock(&sst_drv_ctx->block_lock);
+	return local;
+}

I would expect this to be checking to see if the IDs are free but it just hands them out in sequence? There appears to be an array of streams statically allocated, why not look there for an unused one?

we use these incrementally. The driver stamps each IPC to DSP with a number. The size is limited by bits in the IPCs. So we keep going till we hit max, that time we set it back to 1

Quoted 5 lines
Quoted 3 lines

These ids are not freed or allocated as IPC latency is small enough and IPCs less. We haven't hot scenarios where we go complete round but IPC is still pending :)

Yet.

For this genertaion of HW :) Next gen has different interface though so not worried :)

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines

sound/soc/intel/sst/sst_drv_interface.c line 75

Quoted 7 lines
sound/soc/intel/sst/sst_drv_interface.c new file +7 -0
+int free_stream_context(unsigned int str_id)
+{
+	struct stream_info *stream;
+	int ret = 0;
+
+	stream = get_stream_info(str_id);
+	if (stream) {

It's a bit scary that this might be used with an invalid ID - what happens if the ID got reallocated?

Quoted 7 lines
Quoted 1 line

The free routine checks for valid ID first

That's not the point - the point is that if you're freeing what might be an invalid ID I don't see any guarantee that the ID hasn't been allocated to something else. It's different if there's a specific ID that can be used for an invalid ID but this looks like it's working around double frees.

The chances of that are remote as ID is unique for a FE. For first device we will always use ID 1. The same device close will not request again, so doble free situation shouldn't arise.

Quoted 13 lines
Quoted 12 lines
Quoted 12 lines

sound/soc/intel/sst/sst_ipc.c line 170

Quoted 10 lines
sound/soc/intel/sst/sst_ipc.c new file +10 -0
+	while (header.p.header_high.part.busy) {
+		if (loop_count > 10) {
+			pr_err("sst: Busy wait failed, cant send this msg\n");
+			retval = -EBUSY;
+			goto out;
+		}
+		udelay(500);
+		loop_count++;
+		header.full = sst_shim_read64(sst_drv_ctx->shim, SST_IPCX);
+	}

Throw a cpu_relax() in there if we need to spin...

Quoted 4 lines
Quoted 2 lines

its more busy wait for the bit to be freed. Since IPC latency is supposed to be minimal checking like this helps to minimize.

It's a udelay(500) which is pretty long for a busy wait...

ok

Quoted 15 lines
Quoted 14 lines
Quoted 14 lines

sound/soc/intel/sst/sst_loader.c line 444

Quoted 10 lines
sound/soc/intel/sst/sst_loader.c new file +9 -0
+	if (!list_empty(&sst_drv_ctx->memcpy_list)) {
+		list_for_each_entry_safe(listnode, tmplistnode,
+				&sst_drv_ctx->memcpy_list, memcpylist) {
+			list_del(&listnode->memcpylist);
+			kfree(listnode);
+		}
+	}
+	sst_memcpy_free_lib_resources();
+}

I'm having a hard time seeing why we don't just copy the data as we go rather than allocating this list? It seems to just be making the code more complex.

Quoted 6 lines
Quoted 2 lines

because we support DMA too. so common parsing and then later we either do memcpy and dma. Will push DMA bits after this series.

Keep it simple for now and just memcpy() directly, leaving the functions that select I/O vs memcpy() - you can always go back and add the DMA later.

well wont help to change code now and rework once this series is posted. I have DMA patches as well, want to send them after this series :) as latency is important.

Signature · 1 line
~Vinod
author
#14 lore raw

PATCH 5/7 ASoC: Intel: sst: add power management handling

In reply to Vinod Koul

This patch adds the runtime pm handlers and legacy pm handlers for this driver.

The runtime and legacy handlers are quite similar in nature as we follow same patch for both

---
 sound/soc/intel/sst/sst.c |  126 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 126 insertions(+), 0 deletions(-)
sound/soc/intel/sst/sst.c +126 -0
index 916b38c..cb9863c 100644
@@ -141,6 +141,47 @@ static irqreturn_t intel_sst_irq_thread_mrfld(int irq, void *context)
 	return IRQ_HANDLED;
 }
 
+static int sst_save_dsp_context_v2(struct intel_sst_drv *sst)
+{
+	unsigned int pvt_id;
+	struct ipc_post *msg = NULL;
+	struct ipc_dsp_hdr dsp_hdr;
+	struct sst_block *block;
+
+	/*send msg to fw*/
+	pvt_id = sst_assign_pvt_id(sst);
+	if (sst_create_block_and_ipc_msg(&msg, true, sst, &block,
+				IPC_CMD, pvt_id)) {
+		pr_err("msg/block alloc failed. Not proceeding with context save\n");
+		return 0;
+	}
+
+	sst_fill_header_mrfld(&msg->mrfld_header, IPC_CMD,
+			      SST_TASK_ID_MEDIA, 1, pvt_id);
+	msg->mrfld_header.p.header_low_payload = sizeof(dsp_hdr);
+	msg->mrfld_header.p.header_high.part.res_rqd = 1;
+	sst_fill_header_dsp(&dsp_hdr, IPC_PREP_D3, PIPE_RSVD, pvt_id);
+	memcpy(msg->mailbox_data, &dsp_hdr, sizeof(dsp_hdr));
+
+	sst_add_to_dispatch_list_and_post(sst, msg);
+	/*wait for reply*/
+	if (sst_wait_timeout(sst, block)) {
+		pr_err("sst: err fw context save timeout  ...\n");
+		pr_err("not suspending FW!!!");
+		sst_free_block(sst, block);
+		return -EIO;
+	}
+	if (block->ret_code) {
+		pr_err("fw responded w/ error %d", block->ret_code);
+		sst_free_block(sst, block);
+		return -EIO;
+	}
+
+	sst_free_block(sst, block);
+	return 0;
+}
+
+
 static struct intel_sst_ops mrfld_ops = {
 	.interrupt = intel_sst_interrupt_mrfld,
 	.irq_thread = intel_sst_irq_thread_mrfld,
@@ -150,6 +191,7 @@ static struct intel_sst_ops mrfld_ops = {
 	.post_message = sst_post_message_mrfld,
 	.sync_post_message = sst_sync_post_message_mrfld,
 	.process_reply = sst_process_reply_mrfld,
+	.save_dsp_context =  sst_save_dsp_context_v2,
 	.alloc_stream = sst_alloc_stream_mrfld,
 	.post_download = sst_post_download_mrfld,
 };
@@ -423,6 +465,85 @@ static void intel_sst_remove(struct pci_dev *pci)
 	pci_set_drvdata(pci, NULL);
 }
 
+/*
+ * The runtime_suspend/resume is pretty much similar to the legacy
+ * suspend/resume with the noted exception below: The PCI core takes care of
+ * taking the system through D3hot and restoring it back to D0 and so there is
+ * no need to duplicate that here.
+ */
+static int intel_sst_runtime_suspend(struct device *dev)
+{
+	int ret = 0;
+	struct intel_sst_drv *ctx = dev_get_drvdata(dev);
+
+	pr_info("runtime_suspend called\n");
+	if (ctx->sst_state == SST_RESET) {
+		pr_debug("LPE is already in RESET state, No action");
+		return 0;
+	}
+	/*save fw context*/
+	if (ctx->ops->save_dsp_context(ctx))
+		return -EBUSY;
+
+	/* Move the SST state to Reset */
+	sst_set_fw_state_locked(ctx, SST_RESET);
+
+	flush_workqueue(ctx->post_msg_wq);
+	synchronize_irq(ctx->irq_num);
+
+	return ret;
+}
+
+static int intel_sst_runtime_resume(struct device *dev)
+{
+	int ret = 0;
+	struct intel_sst_drv *ctx = dev_get_drvdata(dev);
+
+	pr_info("runtime_resume called\n");
+
+	/* When fw_clear_cache is set, clear the cached firmware copy */
+	/* fw_clear_cache is set through debugfs support */
+	if (atomic_read(&ctx->fw_clear_cache) && ctx->fw_in_mem) {
+		pr_debug("Clearing the cached firmware\n");
+		kfree(ctx->fw_in_mem);
+		ctx->fw_in_mem = NULL;
+		atomic_set(&ctx->fw_clear_cache, 0);
+	}
+
+	sst_set_fw_state_locked(ctx, SST_RESET);
+
+	return ret;
+}
+
+static int intel_sst_suspend(struct device *dev)
+{
+
+	return intel_sst_runtime_suspend(dev);
+}
+
+static int intel_sst_runtime_idle(struct device *dev)
+{
+	struct intel_sst_drv *ctx = dev_get_drvdata(dev);
+
+	pr_info("runtime_idle called\n");
+	if (ctx->sst_state != SST_RESET) {
+		pm_schedule_suspend(dev, SST_SUSPEND_DELAY);
+		return -EBUSY;
+	} else {
+		return 0;
+	}
+	return -EBUSY;
+
+}
+
+static const struct dev_pm_ops intel_sst_pm = {
+	.suspend = intel_sst_suspend,
+	.resume = intel_sst_runtime_resume,
+	.runtime_suspend = intel_sst_runtime_suspend,
+	.runtime_resume = intel_sst_runtime_resume,
+	.runtime_idle = intel_sst_runtime_idle,
+};
+
 /* PCI Routines */
 static struct pci_device_id intel_sst_ids[] = {
 	{ PCI_VDEVICE(INTEL, SST_MRFLD_PCI_ID), 0},
@@ -434,6 +555,11 @@ static struct pci_driver sst_driver = {
 	.id_table = intel_sst_ids,
 	.probe = intel_sst_probe,
 	.remove = intel_sst_remove,
+#ifdef CONFIG_PM
+	.driver = {
+		.pm = &intel_sst_pm,
+	},
+#endif
 };
 
 module_pci_driver(sst_driver);
Signature · 1 line
1.7.0.4
maintainer
#15 lore raw

Re: [PATCH 5/7] ASoC: Intel: sst: add power management handling

Quoted 1 line · Vinod Koul

+static int sst_save_dsp_context_v2(struct intel_sst_drv *sst)

_v2?

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 479

Quoted 6 lines
sound/soc/intel/sst/sst.c +6 -0
+static int intel_sst_runtime_suspend(struct device *dev)
+{
+	int ret = 0;
+	struct intel_sst_drv *ctx = dev_get_drvdata(dev);
+
+	pr_info("runtime_suspend called\n");

This is way too noisy.

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 492

Quoted 13 lines
sound/soc/intel/sst/sst.c +13 -0
+	if (ctx->sst_state == SST_RESET) {
+		pr_debug("LPE is already in RESET state, No action");
+		return 0;
+	}
+	/*save fw context*/
+	if (ctx->ops->save_dsp_context(ctx))
+		return -EBUSY;
+
+	/* Move the SST state to Reset */
+	sst_set_fw_state_locked(ctx, SST_RESET);
+
+	flush_workqueue(ctx->post_msg_wq);
+	synchronize_irq(ctx->irq_num);

This is very strange - we're flushing the work *after* resetting the DSP which suggests there might be something else trying to access the DSP while it is being put into reset. Presumably that'd be bad.

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 506

Quoted 3 lines
sound/soc/intel/sst/sst.c +3 -0
+	/* When fw_clear_cache is set, clear the cached firmware copy */
+	/* fw_clear_cache is set through debugfs support */
+	if (atomic_read(&ctx->fw_clear_cache) && ctx->fw_in_mem) {

Why? It'd seem more direct to just have the debugfs write trigger trashing of the firmware on demand...

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 522

Quoted 5 lines
sound/soc/intel/sst/sst.c +5 -0
+static int intel_sst_suspend(struct device *dev)
+{
+
+	return intel_sst_runtime_suspend(dev);
+}

You currently need to check that the device isn't runtime suspended before you try to reuse runtime PM ops in suspend.

Quoted 4 lines
sound/soc/intel/sst/sst.c +4 -0
+static int intel_sst_runtime_idle(struct device *dev)
+{
+	struct intel_sst_drv *ctx = dev_get_drvdata(dev);
+

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 537

Quoted 10 lines
sound/soc/intel/sst/sst.c +10 -0
+	pr_info("runtime_idle called\n");
+	if (ctx->sst_state != SST_RESET) {
+		pm_schedule_suspend(dev, SST_SUSPEND_DELAY);
+		return -EBUSY;
+	} else {
+		return 0;
+	}
+	return -EBUSY;
+
+}

This is very strange, what is going on?

author
#16 lore raw

Re: [PATCH 5/7] ASoC: Intel: sst: add power management handling

Quoted 5 lines · Mark Brown
Quoted 1 line · Vinod Koul

+static int sst_save_dsp_context_v2(struct intel_sst_drv *sst)

_v2?

v1 support older moorestown platforms. SO v2 here :)

Quoted 19 lines

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 479

Quoted 7 lines
sound/soc/intel/sst/sst.c +6 -0
+static int intel_sst_runtime_suspend(struct device *dev)
+{
+	int ret = 0;
+	struct intel_sst_drv *ctx = dev_get_drvdata(dev);
+
+	pr_info("runtime_suspend called\n");

This is way too noisy.

Quoted 9 lines
sound/soc/intel/sst/sst.c +9 -0
+	if (ctx->sst_state == SST_RESET) {
+		pr_debug("LPE is already in RESET state, No action");
+		return 0;
+	}
+	/*save fw context*/
+	if (ctx->ops->save_dsp_context(ctx))
+		return -EBUSY;
+
+	/* Move the SST state to Reset */
Quoted 8 lines

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 492

Quoted 4 lines
sound/soc/intel/sst/sst.c +4 -0
+	sst_set_fw_state_locked(ctx, SST_RESET);
+
+	flush_workqueue(ctx->post_msg_wq);
+	synchronize_irq(ctx->irq_num);

This is very strange - we're flushing the work *after* resetting the DSP which suggests there might be something else trying to access the DSP while it is being put into reset. Presumably that'd be bad.

the macro sst_set_fw_state_locked is used here :)

And state is marked reset, we dont do HW reset, so this is okay. After we return the suspend handler, PCI will put the device to D3.

Quoted 6 lines

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 506

Quoted 3 lines
sound/soc/intel/sst/sst.c +3 -0
+	/* When fw_clear_cache is set, clear the cached firmware copy */
+	/* fw_clear_cache is set through debugfs support */
+	if (atomic_read(&ctx->fw_clear_cache) && ctx->fw_in_mem) {

Why? It'd seem more direct to just have the debugfs write trigger trashing of the firmware on demand...

That would work too but then sequencing the DSP while running would cause issues elsewhere. Since we dont have debugs support in the series we cna push this bits later when we send debugfs series amoung others :)

Quoted 8 lines

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 522

Quoted 5 lines
sound/soc/intel/sst/sst.c +5 -0
+static int intel_sst_suspend(struct device *dev)
+{
+
+	return intel_sst_runtime_suspend(dev);
+}

You currently need to check that the device isn't runtime suspended before you try to reuse runtime PM ops in suspend.

Sorry didnt quite get why?

Quoted 17 lines
Quoted 5 lines
sound/soc/intel/sst/sst.c +4 -0
+static int intel_sst_runtime_idle(struct device *dev)
+{
+	struct intel_sst_drv *ctx = dev_get_drvdata(dev);
+

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 537

Quoted 10 lines
sound/soc/intel/sst/sst.c +10 -0
+	pr_info("runtime_idle called\n");
+	if (ctx->sst_state != SST_RESET) {
+		pm_schedule_suspend(dev, SST_SUSPEND_DELAY);
+		return -EBUSY;
+	} else {
+		return 0;
+	}
+	return -EBUSY;
+
+}

This is very strange, what is going on?

schedule suspend after SST_SUSPEND_DELAY. This should be updated with PM framework calls for delay, will update

Signature · 1 line
~Vinod
maintainer
#17 lore raw

Re: [PATCH 5/7] ASoC: Intel: sst: add power management handling

Quoted 12 lines · Vinod Koul
Quoted 9 lines · Mark Brown

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 492

Quoted 5 lines
sound/soc/intel/sst/sst.c +4 -0
+	/* Move the SST state to Reset */
+	sst_set_fw_state_locked(ctx, SST_RESET);
 
+	flush_workqueue(ctx->post_msg_wq);
+	synchronize_irq(ctx->irq_num);

This is very strange - we're flushing the work *after* resetting the DSP which suggests there might be something else trying to access the DSP while it is being put into reset. Presumably that'd be bad.

Quoted 4 lines

the macro sst_set_fw_state_locked is used here :)

And state is marked reset, we dont do HW reset, so this is okay. After we return the suspend handler, PCI will put the device to D3.

It's still setting off alarm bells from a code review point of view - having the DSP marked as in reset may well break something that some of the other activity that's going on is doing.

Quoted 10 lines
Quoted 8 lines

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 522

Quoted 5 lines
sound/soc/intel/sst/sst.c +5 -0
+static int intel_sst_suspend(struct device *dev)
+{
+
+	return intel_sst_runtime_suspend(dev);
+}

You currently need to check that the device isn't runtime suspended before you try to reuse runtime PM ops in suspend.

Sorry didnt quite get why?

The driver should be restoring the device to the state it was in prior to suspend, and not repeating work that's already been done.

author
#18 lore raw

Re: [PATCH 5/7] ASoC: Intel: sst: add power management handling

Quoted 13 lines · Mark Brown
Quoted 11 lines · Vinod Koul
Quoted 9 lines · Mark Brown

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 492

Quoted 5 lines
sound/soc/intel/sst/sst.c +4 -0
+	/* Move the SST state to Reset */
+	sst_set_fw_state_locked(ctx, SST_RESET);
 
+	flush_workqueue(ctx->post_msg_wq);
+	synchronize_irq(ctx->irq_num);

This is very strange - we're flushing the work *after* resetting the DSP which suggests there might be something else trying to access the DSP while it is being put into reset. Presumably that'd be bad.

Quoted 8 lines
Quoted 4 lines

the macro sst_set_fw_state_locked is used here :)

And state is marked reset, we dont do HW reset, so this is okay. After we return the suspend handler, PCI will put the device to D3.

It's still setting off alarm bells from a code review point of view - having the DSP marked as in reset may well break something that some of the other activity that's going on is doing.

yes that is a fair argument. But the next two calls will push any pending messages to DSP. The reset will stop any client calls.

But then we have runtime code too, so while we are suspending that will be waiting, so yes will move reset later.

Quoted 10 lines
Quoted 9 lines
Quoted 9 lines

sound/soc/intel/sst/sst.c static void intel_sst_remove(struct pci_dev *pci) · line 522

Quoted 6 lines
sound/soc/intel/sst/sst.c +5 -0
+static int intel_sst_suspend(struct device *dev)
+{
+
+	return intel_sst_runtime_suspend(dev);
+}

You currently need to check that the device isn't runtime suspended before you try to reuse runtime PM ops in suspend.

Quoted 4 lines
Quoted 1 line

Sorry didnt quite get why?

The driver should be restoring the device to the state it was in prior to suspend, and not repeating work that's already been done.

we dont support suspending when active. The Android usage model is that system will not be S3 if audio is running. So no extra save work is required here.

Moreover it needs active DSP FW support in order to save and restore, so we cant do yet. Yes it will make sense to check device acticty and complain loudly if we are in such a state, will add that.

Signature · 1 line
~Vinod
author
#19 lore raw

PATCH 6/7 ASoC: Intel: sst: load firmware using async callback

In reply to Vinod Koul

We would like the DSP firmware to be availble in driver as soon as possible. So use the async callback in driver to probe to load the firmware as soon as usermode is up

---
 sound/soc/intel/sst/sst.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
sound/soc/intel/sst/sst.c +21 -0
index cb9863c..ae1f0eb 100644
@@ -224,6 +224,22 @@ int sst_alloc_drv_context(struct device *dev)
 	return 0;
 }
 
+int sst_request_firmware_async(struct intel_sst_drv *ctx)
+{
+	int ret = 0;
+
+	snprintf(ctx->firmware_name, sizeof(ctx->firmware_name),
+			"%s%04x%s", "fw_sst_",
+			ctx->pci_id, ".bin");
+	pr_debug("Requesting FW %s now...\n", ctx->firmware_name);
+
+	ret = request_firmware_nowait(THIS_MODULE, 1, ctx->firmware_name,
+			ctx->dev, GFP_KERNEL, ctx, sst_firmware_load_cb);
+	if (ret)
+		pr_err("could not load firmware %s error %d\n", ctx->firmware_name, ret);
+
+	return ret;
+}
 /*
 * intel_sst_probe - PCI probe function
 *
@@ -293,6 +309,11 @@ static int intel_sst_probe(struct pci_dev *pci,
 		mutex_init(&stream->lock);
 	}
 
+	ret = sst_request_firmware_async(sst_drv_ctx);
+	if (ret) {
+		pr_err("Firmware download failed:%d\n", ret);
+		goto do_free_mem;
+	}
 	/* Init the device */
 	ret = pci_enable_device(pci);
 	if (ret) {
Signature · 1 line
1.7.0.4
author
#20 lore raw

PATCH 7/7 ASoC: Intel: sst - add compressed ops handling

In reply to Vinod Koul

This patch add low level IPC handling for compressed stream operations

---
 sound/soc/intel/sst/sst_drv_interface.c |  276 +++++++++++++++++++++++++++++++
 1 files changed, 276 insertions(+), 0 deletions(-)
sound/soc/intel/sst/sst_drv_interface.c +276 -0
index 1ad3083..c3d025d 100644
@@ -282,6 +282,269 @@ static int sst_open_pcm_stream(struct snd_sst_params *str_param)
 	return retval;
 }
 
+static int sst_cdev_open(struct snd_sst_params *str_params,
+		struct sst_compress_cb *cb)
+{
+	int str_id, retval;
+	struct stream_info *stream;
+
+	pr_debug("%s: doing rtpm_get\n", __func__);
+
+	retval = intel_sst_check_device();
+	if (retval)
+		return retval;
+
+	str_id = sst_get_stream(str_params);
+	if (str_id > 0) {
+		pr_debug("stream allocated in sst_cdev_open %d\n", str_id);
+		stream = &sst_drv_ctx->streams[str_id];
+		stream->compr_cb = cb->compr_cb;
+		stream->compr_cb_param = cb->param;
+		stream->drain_notify = cb->drain_notify;
+		stream->drain_cb_param = cb->drain_cb_param;
+	} else {
+		pr_err("stream encountered error during alloc %d\n", str_id);
+		str_id = -EINVAL;
+		sst_pm_runtime_put(sst_drv_ctx);
+	}
+	return str_id;
+}
+
+static int sst_cdev_close(unsigned int str_id)
+{
+	int retval;
+	struct stream_info *stream;
+
+	pr_debug("%s: Entry\n", __func__);
+	stream = get_stream_info(str_id);
+	if (!stream) {
+		pr_err("stream info is NULL for str %d!!!\n", str_id);
+		return -EINVAL;
+	}
+
+	if (stream->status == STREAM_RESET) {
+		/* silently fail here as we have cleaned the stream */
+		pr_debug("stream in reset state...\n");
+		stream->status = STREAM_UN_INIT;
+
+		retval = 0;
+		goto put;
+	}
+
+	retval = sst_free_stream(str_id);
+put:
+	stream->compr_cb_param = NULL;
+	stream->compr_cb = NULL;
+
+	/* The free_stream will return a error if there is no stream to free,
+	(i.e. the alloc failure case). And in this case the open does a put in
+	the error scenario, so skip in this case.
+		In the close we need to handle put in the success scenario and
+	the timeout error(EBUSY) scenario. */
+	if (!retval || (retval == -EBUSY))
+		sst_pm_runtime_put(sst_drv_ctx);
+	else
+		pr_err("%s: free stream returned err %d\n", __func__, retval);
+
+	pr_debug("%s: End\n", __func__);
+	return retval;
+
+}
+
+static int sst_cdev_ack(unsigned int str_id, unsigned long bytes)
+{
+	struct stream_info *stream;
+	struct snd_sst_tstamp fw_tstamp = {0,};
+	int offset;
+	void __iomem *addr;
+
+	pr_debug("sst:  ackfor %d\n", str_id);
+	stream = get_stream_info(str_id);
+	if (!stream)
+		return -EINVAL;
+
+	/* update bytes sent */
+	stream->cumm_bytes += bytes;
+	pr_debug("bytes copied %d inc by %ld\n", stream->cumm_bytes, bytes);
+
+	memcpy_fromio(&fw_tstamp,
+		((void *)(sst_drv_ctx->mailbox + sst_drv_ctx->tstamp)
+		+(str_id * sizeof(fw_tstamp))),
+		sizeof(fw_tstamp));
+
+	fw_tstamp.bytes_copied = stream->cumm_bytes;
+	pr_debug("bytes sent to fw %llu inc by %ld\n", fw_tstamp.bytes_copied,
+							 bytes);
+
+	addr =  ((void *)(sst_drv_ctx->mailbox + sst_drv_ctx->tstamp)) +
+			(str_id * sizeof(fw_tstamp));
+	offset =  offsetof(struct snd_sst_tstamp, bytes_copied);
+	sst_shim_write(addr, offset, fw_tstamp.bytes_copied);
+	return 0;
+
+}
+
+static int sst_cdev_set_metadata(unsigned int str_id,
+				struct snd_compr_metadata *metadata)
+{
+	int retval = 0, pvt_id, len;
+	struct ipc_post *msg = NULL;
+	struct stream_info *str_info;
+	struct ipc_dsp_hdr dsp_hdr;
+
+	pr_debug("set metadata for stream %d\n", str_id);
+
+	str_info = get_stream_info(str_id);
+	if (!str_info)
+		return -EINVAL;
+
+	if (sst_create_ipc_msg(&msg, 1))
+		return -ENOMEM;
+
+	pvt_id = sst_assign_pvt_id(sst_drv_ctx);
+	pr_debug("pvt id = %d\n", pvt_id);
+	pr_debug("pipe id = %d\n", str_info->pipe_id);
+	sst_fill_header_mrfld(&msg->mrfld_header,
+		IPC_CMD, str_info->task_id, 1, pvt_id);
+
+	len = sizeof(*metadata) + sizeof(dsp_hdr);
+	msg->mrfld_header.p.header_low_payload = len;
+	sst_fill_header_dsp(&dsp_hdr, IPC_IA_SET_STREAM_PARAMS_MRFLD,
+			str_info->pipe_id, sizeof(*metadata));
+	memcpy(msg->mailbox_data, &dsp_hdr, sizeof(dsp_hdr));
+	memcpy(msg->mailbox_data + sizeof(dsp_hdr),
+			metadata, sizeof(*metadata));
+
+	sst_drv_ctx->ops->sync_post_message(msg);
+	return retval;
+}
+
+static int sst_cdev_control(unsigned int cmd, unsigned int str_id)
+{
+	pr_debug("recieved cmd %d on stream %d\n", cmd, str_id);
+
+	if (sst_drv_ctx->sst_state != SST_FW_RUNNING)
+		return 0;
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+		return sst_pause_stream(str_id);
+	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+		return sst_resume_stream(str_id);
+	case SNDRV_PCM_TRIGGER_START: {
+		struct stream_info *str_info;
+
+		str_info = get_stream_info(str_id);
+		if (!str_info)
+			return -EINVAL;
+		str_info->prev = str_info->status;
+		str_info->status = STREAM_RUNNING;
+		return sst_start_stream(str_id);
+	}
+	case SNDRV_PCM_TRIGGER_STOP:
+		return sst_drop_stream(str_id);
+	case SND_COMPR_TRIGGER_DRAIN:
+		return sst_drain_stream(str_id, false);
+	case SND_COMPR_TRIGGER_NEXT_TRACK:
+		return sst_next_track();
+	case SND_COMPR_TRIGGER_PARTIAL_DRAIN:
+		return sst_drain_stream(str_id, true);
+	default:
+		return -EINVAL;
+	}
+}
+
+static int sst_cdev_tstamp(unsigned int str_id, struct snd_compr_tstamp *tstamp)
+{
+	struct snd_sst_tstamp fw_tstamp = {0,};
+	struct stream_info *stream;
+
+	memcpy_fromio(&fw_tstamp,
+		((void *)(sst_drv_ctx->mailbox + sst_drv_ctx->tstamp)
+		+(str_id * sizeof(fw_tstamp))),
+		sizeof(fw_tstamp));
+
+	stream = get_stream_info(str_id);
+	if (!stream)
+		return -EINVAL;
+	pr_debug("rb_counter %llu in bytes\n", fw_tstamp.ring_buffer_counter);
+
+	tstamp->copied_total = fw_tstamp.ring_buffer_counter;
+	tstamp->pcm_frames = fw_tstamp.frames_decoded;
+	tstamp->pcm_io_frames = div_u64(fw_tstamp.hardware_counter,
+			(u64)((stream->num_ch) * SST_GET_BYTES_PER_SAMPLE(24)));
+	tstamp->sampling_rate = fw_tstamp.sampling_frequency;
+	pr_debug("PCM  = %u\n", tstamp->pcm_io_frames);
+	pr_debug("Pointer Query on strid = %d  copied_total %d, decodec %d\n",
+		str_id, tstamp->copied_total, tstamp->pcm_frames);
+	pr_debug("rendered %d\n", tstamp->pcm_io_frames);
+	return 0;
+}
+
+static int sst_cdev_caps(struct snd_compr_caps *caps)
+{
+	caps->num_codecs = NUM_CODEC;
+	caps->min_fragment_size = MIN_FRAGMENT_SIZE;  /* 50KB */
+	caps->max_fragment_size = MAX_FRAGMENT_SIZE;  /* 1024KB */
+	caps->min_fragments = MIN_FRAGMENT;
+	caps->max_fragments = MAX_FRAGMENT;
+	caps->codecs[0] = SND_AUDIOCODEC_MP3;
+	caps->codecs[1] = SND_AUDIOCODEC_AAC;
+	return 0;
+}
+
+static int sst_cdev_codec_caps(struct snd_compr_codec_caps *codec)
+{
+
+	if (codec->codec == SND_AUDIOCODEC_MP3) {
+		codec->num_descriptors = 2;
+		codec->descriptor[0].max_ch = 2;
+		codec->descriptor[0].sample_rates[0] = 48000;
+		codec->descriptor[0].sample_rates[1] = 44100;
+		codec->descriptor[0].sample_rates[2] = 32000;
+		codec->descriptor[0].sample_rates[3] = 16000;
+		codec->descriptor[0].sample_rates[4] = 8000;
+		codec->descriptor[0].num_sample_rates = 5;
+		codec->descriptor[0].bit_rate[0] = 320; /* 320kbps */
+		codec->descriptor[0].bit_rate[1] = 192;
+		codec->descriptor[0].num_bitrates = 2;
+		codec->descriptor[0].profiles = 0;
+		codec->descriptor[0].modes = SND_AUDIOCHANMODE_MP3_STEREO;
+		codec->descriptor[0].formats = 0;
+	} else if (codec->codec == SND_AUDIOCODEC_AAC) {
+		codec->num_descriptors = 2;
+		codec->descriptor[1].max_ch = 2;
+		codec->descriptor[0].sample_rates[0] = 48000;
+		codec->descriptor[0].sample_rates[1] = 44100;
+		codec->descriptor[0].sample_rates[2] = 32000;
+		codec->descriptor[0].sample_rates[3] = 16000;
+		codec->descriptor[0].sample_rates[4] = 8000;
+		codec->descriptor[0].num_sample_rates = 5;
+		codec->descriptor[1].bit_rate[0] = 320; /* 320kbps */
+		codec->descriptor[1].bit_rate[1] = 192;
+		codec->descriptor[1].num_bitrates = 2;
+		codec->descriptor[1].profiles = 0;
+		codec->descriptor[1].modes = 0;
+		codec->descriptor[1].formats =
+			(SND_AUDIOSTREAMFORMAT_MP4ADTS |
+				SND_AUDIOSTREAMFORMAT_RAW);
+	} else {
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+void sst_cdev_fragment_elapsed(int str_id)
+{
+	struct stream_info *stream;
+
+	pr_debug("fragment elapsed from firmware for str_id %d\n", str_id);
+	stream = &sst_drv_ctx->streams[str_id];
+	if (stream->compr_cb)
+		stream->compr_cb(stream->compr_cb_param);
+}
+
 /*
  * sst_close_pcm_stream - Close PCM interface
  *
@@ -514,10 +777,23 @@ static struct sst_ops pcm_ops = {
 	.close = sst_close_pcm_stream,
 };
 
+static struct compress_sst_ops compr_ops = {
+	.open = sst_cdev_open,
+	.close = sst_cdev_close,
+	.control = sst_cdev_control,
+	.tstamp = sst_cdev_tstamp,
+	.ack = sst_cdev_ack,
+	.get_caps = sst_cdev_caps,
+	.get_codec_caps = sst_cdev_codec_caps,
+	.set_metadata = sst_cdev_set_metadata,
+};
+
+
 static struct sst_device sst_dsp_device = {
 	.name = "Intel(R) SST LPE",
 	.dev = NULL,
 	.ops = &pcm_ops,
+	.compr_ops = &compr_ops,
 };
 
 /*
Signature · 1 line
1.7.0.4
maintainer
#21 lore raw

Re: [PATCH 7/7] ASoC: Intel: sst - add compressed ops handling

Quoted 5 lines · Vinod Koul
sound/soc/intel/sst/sst_drv_interface.c +5 -0
+	if (codec->codec == SND_AUDIOCODEC_MP3) {
+		codec->num_descriptors = 2;
+		codec->descriptor[0].max_ch = 2;
+		codec->descriptor[0].sample_rates[0] = 48000;
+		codec->descriptor[0].sample_rates[1] = 44100;

sound/soc/intel/sst/sst_drv_interface.c static int sst_open_pcm_stream(struct snd_sst_params *str_param) · line 513

Quoted 10 lines
sound/soc/intel/sst/sst_drv_interface.c +10 -0
+		codec->descriptor[0].sample_rates[2] = 32000;
+		codec->descriptor[0].sample_rates[3] = 16000;
+		codec->descriptor[0].sample_rates[4] = 8000;
+		codec->descriptor[0].num_sample_rates = 5;
+		codec->descriptor[0].bit_rate[0] = 320; /* 320kbps */
+		codec->descriptor[0].bit_rate[1] = 192;
+		codec->descriptor[0].num_bitrates = 2;
+		codec->descriptor[0].profiles = 0;
+		codec->descriptor[0].modes = SND_AUDIOCHANMODE_MP3_STEREO;
+		codec->descriptor[0].formats = 0;

It'd be more idiomatic to copy a static variable.

author
#22 lore raw

Re: [PATCH 7/7] ASoC: Intel: sst - add compressed ops handling

Quoted 11 lines · Mark Brown
Quoted 9 lines · Vinod Koul
sound/soc/intel/sst/sst_drv_interface.c +9 -0
+	if (codec->codec == SND_AUDIOCODEC_MP3) {
+		codec->num_descriptors = 2;
+		codec->descriptor[0].max_ch = 2;
+		codec->descriptor[0].sample_rates[0] = 48000;
+		codec->descriptor[0].sample_rates[1] = 44100;
+		codec->descriptor[0].sample_rates[2] = 32000;
+		codec->descriptor[0].sample_rates[3] = 16000;
+		codec->descriptor[0].sample_rates[4] = 8000;
+		codec->descriptor[0].num_sample_rates = 5;
Quoted 8 lines

sound/soc/intel/sst/sst_drv_interface.c static int sst_open_pcm_stream(struct snd_sst_params *str_param) · line 513

Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c +6 -0
+		codec->descriptor[0].bit_rate[0] = 320; /* 320kbps */
+		codec->descriptor[0].bit_rate[1] = 192;
+		codec->descriptor[0].num_bitrates = 2;
+		codec->descriptor[0].profiles = 0;
+		codec->descriptor[0].modes = SND_AUDIOCHANMODE_MP3_STEREO;
+		codec->descriptor[0].formats = 0;

It'd be more idiomatic to copy a static variable.

will update...

Signature · 1 line
~Vinod
author
#23 lore raw

cover ASoC: Intel: sst - add the merrifield DSP driver

In reply to Vinod Koul

This path series add the Merrifield DSP driver which is used to load and managed the DSP along with sending and receiving IPCs for PCM and compressed audio

Vinod Koul (8):
ASoC: Intel: add sst shim register start-end variables
ASoC: Intel: mfld: add dsp error codes
ASoC: Intel: mrlfd - add generic parameter interface
ASoC: Intel: mrfld - add the dsp sst driver
ASoC: Intel: sst: add power management handling
ASoC: Intel: sst: load firmware using async callback
ASoC: Intel: sst - add compressed ops handling compile

 arch/x86/include/asm/platform_sst_audio.h |   33 +
 sound/soc/intel/Kconfig                   |    6 +-
 sound/soc/intel/Makefile                  |    3 +
 sound/soc/intel/sst-dsp.h                 |    4 +
 sound/soc/intel/sst-mfld-dsp.h            |   15 +
 sound/soc/intel/sst-mfld-platform.h       |    5 +-
 sound/soc/intel/sst/Makefile              |    3 +
 sound/soc/intel/sst/sst.c                 |  586 ++++++++++++++++++
 sound/soc/intel/sst/sst.h                 |  666 ++++++++++++++++++++
 sound/soc/intel/sst/sst_drv_interface.c   |  819 +++++++++++++++++++++++++
 sound/soc/intel/sst/sst_ipc.c             |  368 +++++++++++
 sound/soc/intel/sst/sst_loader.c          |  951 +++++++++++++++++++++++++++++
 sound/soc/intel/sst/sst_pvt.c             |  208 +++++++
 sound/soc/intel/sst/sst_stream.c          |  534 ++++++++++++++++
 14 files changed, 4199 insertions(+), 2 deletions(-)
 create mode 100644 sound/soc/intel/sst/Makefile
 create mode 100644 sound/soc/intel/sst/sst.c
 create mode 100644 sound/soc/intel/sst/sst.h
 create mode 100644 sound/soc/intel/sst/sst_drv_interface.c
 create mode 100644 sound/soc/intel/sst/sst_ipc.c
 create mode 100644 sound/soc/intel/sst/sst_loader.c
 create mode 100644 sound/soc/intel/sst/sst_pvt.c
 create mode 100644 sound/soc/intel/sst/sst_stream.c