ASoC: Intel: sst - add the merrifield IPC driver
Subsystems (4)
v4 cover ASoC: Intel: sst - add the merrifield IPC driver
This path series adds the Merrifield IPC driver which is used to load and manage the DSP along with sending and receiving IPCs for PCM and compressed audio.
v4 updates:
- fix the comment style issues
- fix for id allocation handling
- modularize the code to remove few repated patterns
- comments from previos rev (hopefully didnt miss anything)
Vinod Koul (7):
ASoC: Intel: mrfld - add the dsp sst driver
ASoC: Intel: mrfld - Add DSP load and management
ASoC: Intel: sst - add pcm ops handling
ASoC: Intel: sst: Add IPC handling
ASoC: Intel: sst: add stream operations
ASoC: Intel: sst: Add some helper functions
ASoC: Intel: sst: Add makefile and kconfig changes
arch/x86/include/asm/platform_sst_audio.h | 34 ++ sound/soc/intel/Kconfig | 4 + sound/soc/intel/Makefile | 3 + sound/soc/intel/sst/Makefile | 3 + sound/soc/intel/sst/sst.c | 434 +++++++++++++++++++++++ sound/soc/intel/sst/sst.h | 539 +++++++++++++++++++++++++++++ sound/soc/intel/sst/sst_drv_interface.c | 403 +++++++++++++++++++++ sound/soc/intel/sst/sst_ipc.c | 358 +++++++++++++++++++ sound/soc/intel/sst/sst_loader.c | 461 ++++++++++++++++++++++++ sound/soc/intel/sst/sst_pvt.c | 446 ++++++++++++++++++++++++ sound/soc/intel/sst/sst_stream.c | 437 +++++++++++++++++++++++ 11 files changed, 3122 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
PATCH v4 1/7 ASoC: Intel: mrfld - add the dsp sst driver
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
In subsequent patches support is added for DSP loading using memcpy, pcm operations and compressed ops.
--- arch/x86/include/asm/platform_sst_audio.h | 34 ++ sound/soc/intel/sst/sst.c | 434 +++++++++++++++++++++++ sound/soc/intel/sst/sst.h | 539 +++++++++++++++++++++++++++++ 3 files changed, 1007 insertions(+), 0 deletions(-) create mode 100644 sound/soc/intel/sst/sst.c create mode 100644 sound/soc/intel/sst/sst.h
arch/x86/include/asm/platform_sst_audio.h +34 -0
@@ -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,37 @@ 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_info *probe_data; +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/sst/sst.c new file +434 -0
434 lines not on this page · raw message
sound/soc/intel/sst/sst.h new file +539 -0
539 lines not on this page · raw message
Signature · 1 line
1.7.0.4
Re: [PATCH v4 1/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
Applied, thanks.
PATCH v4 2/7 ASoC: Intel: mrfld - Add DSP load and management
In reply to Vinod KoulThis patch contains all dsp controlling functions like firmware download, setting/resetting dsp cores, etc.
--- sound/soc/intel/sst/sst_loader.c | 461 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 461 insertions(+), 0 deletions(-) create mode 100644 sound/soc/intel/sst/sst_loader.c
sound/soc/intel/sst/sst_loader.c new file +461 -0
@@ -0,0 +1,461 @@ +/* +* sst_dsp.c - Intel SST Driver for audio engine +* +* Copyright (C) 2008-14 Intel Corp +* Authors: Vinod Koul <[email protected]> +* Harsha Priya <[email protected]> +* Dharageswari R <[email protected]> +* KP Jeeja <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This file contains all dsp controlling functions like firmware download, +* setting/resetting dsp cores, etc +*/ +#include <linux/pci.h> +#include <linux/delay.h> +#include <linux/fs.h> +#include <linux/sched.h> +#include <linux/firmware.h> +#include <linux/dmaengine.h> +#include <linux/pm_runtime.h> +#include <linux/pm_qos.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/compress_driver.h> +#include <asm/platform_sst_audio.h> +#include "../sst-mfld-platform.h" +#include "sst.h" +#include "../sst-dsp.h" + +static void memcpy32_toio (void __iomem *dst,const void *src,int count) +{ +int i; +const u32 *src_32 = src; +u32 *dst_32 = dst; + +for (i =0 ; i < count/sizeof (u32); i++) +writel (*src_32++, dst_32++); +} + +/** +* intel_sst_reset_dsp_mrfld - Resetting SST DSP +* +* This resets DSP in case of MRFLD platfroms +*/ +int intel_sst_reset_dsp_mrfld (struct intel_sst_drv *sst_drv_ctx) +{ +union config_status_reg_mrfld csr; + +dev_dbg (sst_drv_ctx->dev,"sst: Resetting the DSP in mrfld\n" ); + csr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_CSR ); + +dev_dbg (sst_drv_ctx->dev,"value:0x%llx\n" , csr.full); + + csr.full |=0x7 ; +sst_shim_write64 (sst_drv_ctx->shim,SST_CSR , csr.full); + csr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_CSR ); + +dev_dbg (sst_drv_ctx->dev,"value:0x%llx\n" , csr.full); + + csr.full &= ~(0x1 ); +sst_shim_write64 (sst_drv_ctx->shim,SST_CSR , csr.full); + + csr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_CSR ); +dev_dbg (sst_drv_ctx->dev,"value:0x%llx\n" , csr.full); +return 0 ; +} + +/** +* sst_start_merrifield - Start the SST DSP processor +* +* This starts the DSP in MERRIFIELD platfroms +*/ +int sst_start_mrfld (struct intel_sst_drv *sst_drv_ctx) +{ +union config_status_reg_mrfld csr; + +dev_dbg (sst_drv_ctx->dev,"sst: Starting the DSP in mrfld LALALALA\n" ); + csr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_CSR ); +dev_dbg (sst_drv_ctx->dev,"value:0x%llx\n" , csr.full); + + csr.full |=0x7 ; +sst_shim_write64 (sst_drv_ctx->shim,SST_CSR , csr.full); + + csr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_CSR ); +dev_dbg (sst_drv_ctx->dev,"value:0x%llx\n" , csr.full); + + csr.part.xt_snoop =1 ; + csr.full &= ~(0x5 ); +sst_shim_write64 (sst_drv_ctx->shim,SST_CSR , csr.full); + + csr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_CSR ); +dev_dbg (sst_drv_ctx->dev,"sst: Starting the DSP_merrifield:%llx\n" , + csr.full); +return 0 ; +} + +static int sst_validate_fw_image (struct intel_sst_drv *ctx,unsigned long size, +struct fw_module_header **module,u32 *num_modules) +{ +struct sst_fw_header *header; +const void *sst_fw_in_mem = ctx->fw_in_mem; + +dev_dbg (ctx->dev,"Enter\n" ); + +/* Read the header information from the data pointer */ + header = (struct sst_fw_header *)sst_fw_in_mem; +dev_dbg (ctx->dev, +"header sign=%s size=%x modules=%x fmt=%x size=%zx\n" , + header->signature, header->file_size, header->modules, + header->file_format,sizeof (*header)); + +/* verify FW */ +if ((strncmp (header->signature,SST_FW_SIGN ,4 ) !=0 ) || + (size != header->file_size +sizeof (*header))) { +/* Invalid FW signature */ +dev_err (ctx->dev,"InvalidFW sign/filesize mismatch\n" ); +return -EINVAL ; + } + *num_modules = header->modules; + *module = (void *)sst_fw_in_mem +sizeof (*header); + +return 0 ; +} + +/* +* sst_fill_memcpy_list - Fill the memcpy list +* +* @memcpy_list: List to be filled +* @destn: Destination addr to be filled in the list +* @src: Source addr to be filled in the list +* @size: Size to be filled in the list +* +* Adds the node to the list after required fields +* are populated in the node +*/ +static int sst_fill_memcpy_list (struct list_head *memcpy_list, +void *destn,const void *src,u32 size,bool is_io) +{ +struct sst_memcpy_list *listnode; + + listnode =kzalloc (sizeof (*listnode),GFP_KERNEL ); +if (listnode ==NULL ) +return -ENOMEM ; + listnode->dstn = destn; + listnode->src = src; + listnode->size = size; + listnode->is_io = is_io; +list_add_tail (&listnode->memcpylist, memcpy_list); + +return 0 ; +} + +/** +* sst_parse_module_memcpy - Parse audio FW modules and populate the memcpy list +* +* @sst_drv_ctx : driver context +* @module : FW module header +* @memcpy_list : Pointer to the list to be populated +* Create the memcpy list as the number of block to be copied +* returns error or 0 if module sizes are proper +*/ +static int sst_parse_module_memcpy (struct intel_sst_drv *sst_drv_ctx, +struct fw_module_header *module,struct list_head *memcpy_list) +{ +struct fw_block_info *block; +u32 count; +int ret_val =0 ; +void __iomem *ram_iomem; + +dev_dbg (sst_drv_ctx->dev,"module sign %s size %x blocks %x type %x\n" , + module->signature, module->mod_size, + module->blocks, module->type); +dev_dbg (sst_drv_ctx->dev,"module entrypoint 0x%x\n" , module->entry_point); + + block = (void *)module +sizeof (*module); + +for (count =0 ; count < module->blocks; count++) { +if (block->size <=0 ) { +dev_err (sst_drv_ctx->dev,"block size invalid\n" ); +return -EINVAL ; + } +switch (block->type) { +case SST_IRAM : + ram_iomem = sst_drv_ctx->iram; +break ; +case SST_DRAM : + ram_iomem = sst_drv_ctx->dram; +break ; +case SST_DDR : + ram_iomem = sst_drv_ctx->ddr; +break ; +case SST_CUSTOM_INFO : + block = (void *)block +sizeof (*block) + block->size; +continue ; +default : +dev_err (sst_drv_ctx->dev,"wrong ram type0x%x in block0x%x\n" , + block->type, count); +return -EINVAL ; + } + + ret_val =sst_fill_memcpy_list (memcpy_list, + ram_iomem + block->ram_offset, + (void *)block +sizeof (*block), block->size,1 ); +if (ret_val) +return ret_val; + + block = (void *)block +sizeof (*block) + block->size; + } +return 0 ; +} + +/** +* sst_parse_fw_memcpy - parse the firmware image & populate the list for memcpy +* +* @ctx : pointer to drv context +* @size : size of the firmware +* @fw_list : pointer to list_head to be populated +* This function parses the FW image and saves the parsed image in the list +* for memcpy +*/ +static int sst_parse_fw_memcpy (struct intel_sst_drv *ctx,unsigned long size, +struct list_head *fw_list) +{ +struct fw_module_header *module; +u32 count, num_modules; +int ret_val; + + ret_val =sst_validate_fw_image (ctx, size, &module, &num_modules); +if (ret_val) +return ret_val; + +for (count =0 ; count < num_modules; count++) { + ret_val =sst_parse_module_memcpy (ctx, module, fw_list); +if (ret_val) +return ret_val; + module = (void *)module +sizeof (*module) + module->mod_size; + } + +return 0 ; +} + +/** +* sst_do_memcpy - function initiates the memcpy +* +* @memcpy_list: Pter to memcpy list on which the memcpy needs to be initiated +* +* Triggers the memcpy +*/ +static void sst_do_memcpy (struct list_head *memcpy_list) +{ +struct sst_memcpy_list *listnode; + +list_for_each_entry (listnode, memcpy_list, memcpylist) { +if (listnode->is_io == true) +memcpy32_toio ((void __iomem *)listnode->dstn, + listnode->src, listnode->size); +else +memcpy (listnode->dstn, listnode->src, listnode->size); + } +} + +void sst_memcpy_free_resources (struct intel_sst_drv *sst_drv_ctx) +{ +struct sst_memcpy_list *listnode, *tmplistnode; + +/* 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); + } + } +} + +static int sst_cache_and_parse_fw (struct intel_sst_drv *sst, +const struct firmware *fw) +{ +int retval =0 ; + + sst->fw_in_mem =kzalloc (fw->size,GFP_KERNEL ); +if (!sst->fw_in_mem) { + retval = -ENOMEM ; + goto end_release; + } +dev_dbg (sst->dev,"copied fw to %p" , sst->fw_in_mem); +dev_dbg (sst->dev,"phys: %lx" , (unsigned long )virt_to_phys (sst->fw_in_mem)); +memcpy (sst->fw_in_mem, fw->data, fw->size); + retval =sst_parse_fw_memcpy (sst, fw->size, &sst->memcpy_list); +if (retval) { +dev_err (sst->dev,"Failed to parse fw\n" ); +kfree (sst->fw_in_mem); + sst->fw_in_mem =NULL ; + } + +end_release: +release_firmware (fw); +return retval; + +} + +void sst_firmware_load_cb (const struct firmware *fw,void *context) +{ +struct intel_sst_drv *ctx = context; + +dev_dbg (ctx->dev,"Enter\n" ); + +if (fw ==NULL ) { +dev_err (ctx->dev,"request fw failed\n" ); +return ; + } + +mutex_lock (&ctx->sst_lock); + +if (ctx->sst_state !=SST_RESET || + ctx->fw_in_mem !=NULL ) { +if (fw !=NULL ) +release_firmware (fw); +mutex_unlock (&ctx->sst_lock); +return ; + } + +dev_dbg (ctx->dev,"Request Fw completed\n" ); +sst_cache_and_parse_fw (ctx, fw); +mutex_unlock (&ctx->sst_lock); +} + +/* +* sst_request_fw - requests audio fw from kernel and saves a copy +* +* This function requests the SST FW from the kernel, parses it and +* saves a copy in the driver context +*/ +static int sst_request_fw (struct intel_sst_drv *sst) +{ +int retval =0 ; +char name[20 ]; +const struct firmware *fw; + +dev_dbg (sst->dev,"Requesting FW %s now...\n" , name); + + retval =request_firmware (&fw, name, sst->dev); +if (fw ==NULL ) { +dev_err (sst->dev,"fw is returning as null\n" ); +return -EINVAL ; + } +if (retval) { +dev_err (sst->dev,"request fw failed %d\n" , retval); +return retval; + } +mutex_lock (&sst->sst_lock); + retval =sst_cache_and_parse_fw (sst, fw); +mutex_unlock (&sst->sst_lock); + +return retval; +} + +/* +* Writing the DDR physical base to DCCM offset +* so that FW can use it to setup TLB +*/ +static void sst_dccm_config_write (void __iomem *dram_base, +unsigned int ddr_base) +{ +void __iomem *addr; +u32 bss_reset =0 ; + + addr = (void __iomem *)(dram_base +MRFLD_FW_DDR_BASE_OFFSET ); +memcpy32_toio (addr, (void *)&ddr_base,sizeof (u32)); + bss_reset |= (1 <<MRFLD_FW_BSS_RESET_BIT ); + addr = (void __iomem *)(dram_base +MRFLD_FW_FEATURE_BASE_OFFSET ); +memcpy32_toio (addr, &bss_reset,sizeof (u32)); + +} + +void sst_post_download_mrfld (struct intel_sst_drv *ctx) +{ +sst_dccm_config_write (ctx->dram, ctx->ddr_base); +dev_dbg (ctx->dev,"config written to DCCM\n" ); +} + +/** +* sst_load_fw - function to load FW into DSP +* Transfers the FW to DSP using dma/memcpy +*/ +int sst_load_fw (struct intel_sst_drv *sst_drv_ctx) +{ +int ret_val =0 ; +struct sst_block *block; + +dev_dbg (sst_drv_ctx->dev,"sst_load_fw\n" ); + +if (sst_drv_ctx->sst_state !=SST_RESET || + sst_drv_ctx->sst_state ==SST_SHUTDOWN ) +return -EAGAIN ; + +if (!sst_drv_ctx->fw_in_mem) { +dev_dbg (sst_drv_ctx->dev,"sst: FW not in memory retry to download\n" ); + ret_val =sst_request_fw (sst_drv_ctx); +if (ret_val) +return ret_val; + } + +BUG_ON (!sst_drv_ctx->fw_in_mem); + block =sst_create_block (sst_drv_ctx,0 ,FW_DWNL_ID ); +if (block ==NULL ) +return -ENOMEM ; + +/* Prevent C-states beyond C6 */ +pm_qos_update_request (sst_drv_ctx->qos,0 ); + + sst_drv_ctx->sst_state =SST_FW_LOADING ; + + ret_val = sst_drv_ctx->ops->reset (sst_drv_ctx); +if (ret_val) + goto restore; + +sst_do_memcpy (&sst_drv_ctx->memcpy_list); + +/* Write the DRAM/DCCM config before enabling FW */ +if (sst_drv_ctx->ops->post_download) + sst_drv_ctx->ops->post_download (sst_drv_ctx); + +/* bring sst out of reset */ + ret_val = sst_drv_ctx->ops->start (sst_drv_ctx); +if (ret_val) + goto restore; + + ret_val =sst_wait_timeout (sst_drv_ctx, block); +if (ret_val) { +dev_err (sst_drv_ctx->dev,"fw download failed %d\n" , ret_val); +/* FW download failed due to timeout */ + ret_val = -EBUSY ; + + } + + +restore: +/* Re-enable Deeper C-states beyond C6 */ +pm_qos_update_request (sst_drv_ctx->qos,PM_QOS_DEFAULT_VALUE ); +sst_free_block (sst_drv_ctx, block); +dev_dbg (sst_drv_ctx->dev,"fw load 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 ret_val; +} +
Signature · 1 line
1.7.0.4
Mark Brown
maintainerRe: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
sound/soc/intel/sst/sst_loader.c line 50
Quoted 9 lines · Vinod Koul
sound/soc/intel/sst/sst_loader.c new file +9
-0+static void memcpy32_toio (void __iomem *dst,const void *src,int count) +{ +int i; +const u32 *src_32 = src; +u32 *dst_32 = dst; + +for (i =0 ; i < count/sizeof (u32); i++) +writel (*src_32++, dst_32++); +}
We also have a memcpy32_toio in atmel_nand.c which I pointed out before and now another in mxc_nand.c. All of which use different writel variants. This isn't awesome, we should at least try to clean this up rather than add another duplicate - by the time we're onto the third user there's a clear need for something generic. Do you have any thoughts on dealing with this?
Otherwise the patch looks good.
Re: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
Quoted 18 lines · Mark Brown
sound/soc/intel/sst/sst_loader.c line 50
Quoted 9 lines · Vinod Koul
sound/soc/intel/sst/sst_loader.c new file +9
-0+static void memcpy32_toio (void __iomem *dst,const void *src,int count) +{ +int i; +const u32 *src_32 = src; +u32 *dst_32 = dst; + +for (i =0 ; i < count/sizeof (u32); i++) +writel (*src_32++, dst_32++); +}We also have a
memcpy32_toioinatmel_nand.cwhich I pointed out before and now another inmxc_nand.c. All of which use different writel variants. This isn't awesome, we should at least try to clean this up rather than add another duplicate - by the time we're onto the third user there's a clear need for something generic. Do you have any thoughts on dealing with this?
I dont mind moving this and other users to common handler. I can send a patch to add that. I think Subranshu did send one but that needs to be improved upon. Also this should be in BYT driver as well.
But creates dependency for us
Quoted 2 lines
Otherwise the patch looks good.
Thanks, since the size is bit on higher size and no other issues, would it be okay to merge this.
I will work on moving memcpy32_toio to core and move users as well :)
Thanks
Signature · 1 line
~Vinod
Re: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
At Fri, 17 Oct 2014 14:48:16 +0530,
Quoted 24 lines · Vinod Koul
Quoted 18 lines · Mark Brown
sound/soc/intel/sst/sst_loader.c line 50
Quoted 9 lines · Vinod Koul
sound/soc/intel/sst/sst_loader.c new file +9
-0+static void memcpy32_toio (void __iomem *dst,const void *src,int count) +{ +int i; +const u32 *src_32 = src; +u32 *dst_32 = dst; + +for (i =0 ; i < count/sizeof (u32); i++) +writel (*src_32++, dst_32++); +}We also have a
memcpy32_toioinatmel_nand.cwhich I pointed out before and now another inmxc_nand.c. All of which use different writel variants. This isn't awesome, we should at least try to clean this up rather than add another duplicate - by the time we're onto the third user there's a clear need for something generic. Do you have any thoughts on dealing with this?I dont mind moving this and other users to common handler. I can send a patch to add that. I think Subranshu did send one but that needs to be improved upon. Also this should be in BYT driver as well.
Quoted 7 lines
But creates dependency for us
Quoted 2 lines
Otherwise the patch looks good.
Thanks, since the size is bit on higher size and no other issues, would it be okay to merge this.
I will work on moving
memcpy32_toioto core and move users as well :)
We can move them into sound/core/memory.c. They are pretty small and useful.
Takashi
Mark Brown
maintainerRe: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
Quoted 6 lines · Takashi Iwai
Quoted 1 line · Vinod Koul
I will work on moving
memcpy32_toioto core and move users as well :)We can move them into
sound/core/memory.c. They are pretty small and useful.
It's not really anything to do with sound though, the other users are MTD devices at the minute.
Re: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
At Fri, 17 Oct 2014 14:01:47 +0200,
Quoted 11 lines · Mark Brown
Quoted 6 lines · Takashi Iwai
Quoted 1 line · Vinod Koul
I will work on moving
memcpy32_toioto core and move users as well :)We can move them into
sound/core/memory.c. They are pretty small and useful.It's not really anything to do with sound though, the other users are MTD devices at the minute.
Yeah, we can move up again, then :)
I think it's even not bad to have it as a static inline function.
Takashi
Re: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
Quoted 7 lines · Takashi Iwai
At Fri, 17 Oct 2014 14:01:47 +0200,
Quoted 5 lines · Mark Brown
Quoted 3 lines · Takashi Iwai
Quoted 1 line · Vinod Koul
I will work on moving
memcpy32_toioto core and move users as well :)
And I did prepare RFC for that and had to trash it :(
Turns out we already have an API for this in kernel.
While adding the new header, though it should be io.h, stumbled upon not much used __iowrite32_copy() which seems to be the API I need.
I am testing it as we speak, will send conversion patch today.
Signature · 1 line
~Vinod
Quoted 17 lines
Quoted 6 lines
Quoted 3 lines
We can move them into
sound/core/memory.c. They are pretty small and useful.It's not really anything to do with sound though, the other users are MTD devices at the minute.
Yeah, we can move up again, then :)
I think it's even not bad to have it as a static inline function.
Takashi
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Mark Brown
maintainerRe: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
Quoted 4 lines · Vinod Koul
Quoted 1 line · Takashi Iwai
Quoted 1 line
Quoted 1 line
Quoted 1 line
I will work on moving
memcpy32_toioto core and move users as well :)
Quoted 8 lines
And I did prepare RFC for that and had to trash it :(
Turns out we already have an API for this in kernel.
While adding the new header, though it should be
io.h, stumbled upon not much used__iowrite32_copy()which seems to be the API I need.I am testing it as we speak, will send conversion patch today.
Probably best to send patches for the MTD devices too while you're at it.
Re: [PATCH v4 2/7] ASoC: Intel: mrfld - Add DSP load and management
Quoted 9 lines · Mark Brown
Quoted 7 lines · Vinod Koul
Quoted 1 line · Takashi Iwai
Quoted 1 line
Quoted 1 line
Quoted 1 line
I will work on moving
memcpy32_toioto core and move users as well :)And I did prepare RFC for that and had to trash it :(
Turns out we already have an API for this in kernel.
Quoted 7 lines
Quoted 4 lines
While adding the new header, though it should be
io.h, stumbled upon not much used__iowrite32_copy()which seems to be the API I need.I am testing it as we speak, will send conversion patch today.
Probably best to send patches for the MTD devices too while you're at it.
Yup, sent out few moments back.
Thanks
Signature · 1 line
~Vinod
PATCH v4 3/7 ASoC: Intel: sst - add pcm ops handling
In reply to Vinod KoulThis patch adds low level IPC handling for pcm stream operations
--- sound/soc/intel/sst/sst_drv_interface.c | 403 +++++++++++++++++++++++++++++++ 1 files changed, 403 insertions(+), 0 deletions(-) create mode 100644 sound/soc/intel/sst/sst_drv_interface.c
sound/soc/intel/sst/sst_drv_interface.c new file +403 -0
@@ -0,0 +1,403 @@ +/* +* sst_drv_interface.c - Intel SST Driver for audio engine +* +* Copyright (C) 2008-14 Intel Corp +* Authors: Vinod Koul <[email protected]> +* Harsha Priya <[email protected]> +* Dharageswari R <[email protected]) +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/ +#include <linux/delay.h> +#include <linux/pci.h> +#include <linux/fs.h> +#include <linux/firmware.h> +#include <linux/pm_runtime.h> +#include <linux/pm_qos.h> +#include <linux/math64.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/compress_driver.h> +#include <asm/platform_sst_audio.h> +#include "../sst-mfld-platform.h" +#include "sst.h" +#include "../sst-dsp.h" + + + +#define NUM_CODEC 2 +#define MIN_FRAGMENT 2 +#define MAX_FRAGMENT 4 +#define MIN_FRAGMENT_SIZE (50 * 1024) +#define MAX_FRAGMENT_SIZE (1024 * 1024) +#define SST_GET_BYTES_PER_SAMPLE (pcm_wd_sz) (((pcm_wd_sz + 15) >> 4) << 1) + +int free_stream_context (struct intel_sst_drv *ctx,unsigned int str_id) +{ +struct stream_info *stream; +int ret =0 ; + + stream =get_stream_info (ctx, str_id); +if (stream) { +/* str_id is valid, so stream is alloacted */ + ret =sst_free_stream (ctx, str_id); +if (ret) +sst_clean_stream (&ctx->streams[str_id]); +return ret; + } +return ret; +} + +int sst_get_stream_allocated (struct intel_sst_drv *ctx, +struct snd_sst_params *str_param, +struct snd_sst_lib_download **lib_dnld) +{ +int retval; + + retval = ctx->ops->alloc_stream (ctx, str_param); +if (retval >0 ) +dev_dbg (ctx->dev,"Stream allocated %d\n" , retval); +return retval; + +} + +/* +* sst_get_sfreq - this function returns the frequency of the stream +* +* @str_param : stream params +*/ +int sst_get_sfreq (struct snd_sst_params *str_param) +{ +switch (str_param->codec) { +case SST_CODEC_TYPE_PCM : +return str_param->sparams.uc.pcm_params.sfreq; +case SST_CODEC_TYPE_AAC : +return str_param->sparams.uc.aac_params.externalsr; +case SST_CODEC_TYPE_MP3 : +return 0 ; +default : +return -EINVAL ; + } +} + +/* +* sst_get_sfreq - this function returns the frequency of the stream +* +* @str_param : stream params +*/ +int sst_get_num_channel (struct snd_sst_params *str_param) +{ +switch (str_param->codec) { +case SST_CODEC_TYPE_PCM : +return str_param->sparams.uc.pcm_params.num_chan; +case SST_CODEC_TYPE_MP3 : +return str_param->sparams.uc.mp3_params.num_chan; +case SST_CODEC_TYPE_AAC : +return str_param->sparams.uc.aac_params.num_chan; +default : +return -EINVAL ; + } +} + +/* +* sst_get_stream - this function prepares for stream allocation +* +* @str_param : stream param +*/ +int sst_get_stream (struct intel_sst_drv *ctx, +struct snd_sst_params *str_param) +{ +int retval; +struct stream_info *str_info; + +/* stream is not allocated, we are allocating */ + retval = ctx->ops->alloc_stream (ctx, str_param); +if (retval <=0 ) { +return -EIO ; + } +/* store sampling freq */ + str_info = &ctx->streams[retval]; + str_info->sfreq =sst_get_sfreq (str_param); + +return retval; +} + +static int sst_power_control (struct device *dev,bool state) +{ +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + +dev_dbg (ctx->dev,"state:%d" , state); +if (state == true) +return pm_runtime_get_sync (dev); +else +return sst_pm_runtime_put (ctx); +} + +/* +* sst_open_pcm_stream - Open PCM interface +* +* @str_param: parameters of pcm stream +* +* This function is called by MID sound card driver to open +* a new pcm interface +*/ +static int sst_open_pcm_stream (struct device *dev, +struct snd_sst_params *str_param) +{ +int retval; +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + +if (!str_param) +return -EINVAL ; + + retval =pm_runtime_get_sync (ctx->dev); +if (retval <0 ) +return retval; + retval =sst_get_stream (ctx, str_param); +if (retval >0 ) { + ctx->stream_cnt++; + }else { +dev_err (ctx->dev,"sst_get_stream returned err %d\n" , retval); +sst_pm_runtime_put (ctx); + } + +return retval; +} + +/* +* sst_close_pcm_stream - Close PCM interface +* +* @str_id: stream id to be closed +* +* This function is called by MID sound card driver to close +* an existing pcm interface +*/ +static int sst_close_pcm_stream (struct device *dev,unsigned int str_id) +{ +struct stream_info *stream; +int retval =0 ; +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + + stream =get_stream_info (ctx, str_id); +if (!stream) { +dev_err (ctx->dev,"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 earlier */ +dev_dbg (ctx->dev,"stream in reset state...\n" ); + + retval =0 ; + goto put; + } + + retval =free_stream_context (ctx, str_id); +put: + stream->pcm_substream =NULL ; + stream->status =STREAM_UN_INIT ; + stream->period_elapsed =NULL ; + ctx->stream_cnt--; + +sst_pm_runtime_put (ctx); + +dev_dbg (ctx->dev,"Exit\n" ); +return 0 ; +} + +static inline int sst_calc_tstamp (struct intel_sst_drv *ctx, +struct pcm_stream_info *info, +struct snd_pcm_substream *substream, +struct snd_sst_tstamp *fw_tstamp) +{ +size_t delay_bytes, delay_frames; +size_t buffer_sz; +u32 pointer_bytes, pointer_samples; + +dev_dbg (ctx->dev,"mrfld ring_buffer_counter %llu in bytes\n" , + fw_tstamp->ring_buffer_counter); +dev_dbg (ctx->dev,"mrfld hardware_counter %llu in bytes\n" , + fw_tstamp->hardware_counter); +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) + delay_bytes = (size_t ) (fw_tstamp->ring_buffer_counter - + fw_tstamp->hardware_counter); +else + delay_bytes = (size_t ) (fw_tstamp->hardware_counter - + fw_tstamp->ring_buffer_counter); + delay_frames =bytes_to_frames (substream->runtime, delay_bytes); + buffer_sz =snd_pcm_lib_buffer_bytes (substream); +div_u64_rem (fw_tstamp->ring_buffer_counter, buffer_sz, &pointer_bytes); + pointer_samples =bytes_to_samples (substream->runtime, pointer_bytes); + +dev_dbg (ctx->dev,"pcm delay %zu in bytes\n" , delay_bytes); + + info->buffer_ptr = pointer_samples / substream->runtime->channels; + + info->pcm_delay = delay_frames / substream->runtime->channels; +dev_dbg (ctx->dev,"buffer ptr %llu pcm_delay rep: %llu\n" , + info->buffer_ptr, info->pcm_delay); +return 0 ; +} + +static int sst_read_timestamp (struct device *dev,struct pcm_stream_info *info) +{ +struct stream_info *stream; +struct snd_pcm_substream *substream; +struct snd_sst_tstamp fw_tstamp; +unsigned int str_id; +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + + str_id = info->str_id; + stream =get_stream_info (ctx, str_id); +if (!stream) +return -EINVAL ; + +if (!stream->pcm_substream) +return -EINVAL ; + substream = stream->pcm_substream; + +memcpy_fromio (&fw_tstamp, + ((void *)(ctx->mailbox + ctx->tstamp) + + (str_id *sizeof (fw_tstamp))), +sizeof (fw_tstamp)); +return sst_calc_tstamp (ctx, info, substream, &fw_tstamp); +} + +static int sst_stream_start (struct device *dev,int str_id) +{ +struct stream_info *str_info; +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + +if (ctx->sst_state !=SST_FW_RUNNING ) +return 0 ; + str_info =get_stream_info (ctx, str_id); +if (!str_info) +return -EINVAL ; + str_info->prev = str_info->status; + str_info->status =STREAM_RUNNING ; +sst_start_stream (ctx, str_id); + +return 0 ; +} + +static int sst_stream_drop (struct device *dev,int str_id) +{ +struct stream_info *str_info; +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + +if (ctx->sst_state !=SST_FW_RUNNING ) +return 0 ; + + str_info =get_stream_info (ctx, str_id); +if (!str_info) +return -EINVAL ; + str_info->prev =STREAM_UN_INIT ; + str_info->status =STREAM_INIT ; +return sst_drop_stream (ctx, str_id); +} + +static int sst_stream_init (struct device *dev,struct pcm_stream_info *str_info) +{ +int str_id =0 ; +struct stream_info *stream; +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + + str_id = str_info->str_id; + +if (ctx->sst_state !=SST_FW_RUNNING ) +return 0 ; + + stream =get_stream_info (ctx, str_id); +if (!stream) +return -EINVAL ; + +dev_dbg (ctx->dev,"setting the period ptrs\n" ); + stream->pcm_substream = str_info->arg; + stream->period_elapsed = str_info->period_elapsed; + stream->sfreq = str_info->sfreq; + stream->prev = stream->status; + stream->status =STREAM_INIT ; +dev_dbg (ctx->dev, +"pcm_substream %p, period_elapsed %p, sfreq %d, status %d\n" , + stream->pcm_substream, stream->period_elapsed, + stream->sfreq, stream->status); + +return 0 ; +} + +/* +* sst_set_byte_stream - Set generic params +* +* @cmd: control cmd to be set +* @arg: command argument +* +* This function is called by MID sound card driver to configure +* SST runtime params. +*/ +static int sst_send_byte_stream (struct device *dev, +struct snd_sst_bytes_v2 *bytes) +{ +int ret_val =0 ; +struct intel_sst_drv *ctx =dev_get_drvdata (dev); + +if (NULL == bytes) +return -EINVAL ; + ret_val =pm_runtime_get_sync (ctx->dev); +if (ret_val <0 ) +return ret_val; + + ret_val =sst_send_byte_stream_mrfld (ctx, bytes); +sst_pm_runtime_put (ctx); + +return ret_val; +} + +static struct sst_ops pcm_ops = { + .open = sst_open_pcm_stream, + .stream_init = sst_stream_init, + .stream_start = sst_stream_start, + .stream_drop = sst_stream_drop, + .stream_read_tstamp = sst_read_timestamp, + .send_byte_stream = sst_send_byte_stream, + .close = sst_close_pcm_stream, + .power = sst_power_control, +}; + +static struct sst_device sst_dsp_device = { + .name ="Intel(R) SST LPE" , + .dev =NULL , + .ops = &pcm_ops, +}; + +/* +* sst_register - function to register DSP +* +* This functions registers DSP with the platform driver +*/ +int sst_register (struct device *dev) +{ +int ret_val; + + sst_dsp_device.dev = dev; + ret_val =sst_register_dsp (&sst_dsp_device); +if (ret_val) +dev_err (dev,"Unable to register DSP with platform driver\n" ); + +return ret_val; +} + +int sst_unregister (struct device *dev) +{ +return sst_unregister_dsp (&sst_dsp_device); +}
Signature · 1 line
1.7.0.4
Mark Brown
maintainerRe: [PATCH v4 3/7] ASoC: Intel: sst - add pcm ops handling
Quoted 5 lines · Vinod Koul
sound/soc/intel/sst/sst_drv_interface.c new file +5
-0+int free_stream_context (struct intel_sst_drv *ctx,unsigned int str_id) +{ +struct stream_info *stream; +int ret =0 ; +
sound/soc/intel/sst/sst_drv_interface.c line 60
Quoted 10 lines
sound/soc/intel/sst/sst_drv_interface.c new file +10
-0+ stream =get_stream_info (ctx, str_id); +if (stream) { +/* str_id is valid, so stream is alloacted */ + ret =sst_free_stream (ctx, str_id); +if (ret) +sst_clean_stream (&ctx->streams[str_id]); +return ret; + } +return ret; +}
I keep on asking for this to print an error on double frees.
sound/soc/intel/sst/sst_drv_interface.c line 99
Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c new file +6
-0+/* +* sst_get_sfreq - this function returns the frequency of the stream +* +* @str_param : stream params +*/ +int sst_get_num_channel (struct snd_sst_params *str_param)
Cut'n'paste error in the kerneldoc.
Re: [PATCH v4 3/7] ASoC: Intel: sst - add pcm ops handling
Quoted 11 lines · Mark Brown
Quoted 9 lines · Vinod Koul
sound/soc/intel/sst/sst_drv_interface.c new file +9
-0+int free_stream_context (struct intel_sst_drv *ctx,unsigned int str_id) +{ +struct stream_info *stream; +int ret =0 ; + + stream =get_stream_info (ctx, str_id); +if (stream) { +/* str_id is valid, so stream is alloacted */ + ret =sst_free_stream (ctx, str_id);
Quoted 8 lines
sound/soc/intel/sst/sst_drv_interface.c line 60
Quoted 6 lines
sound/soc/intel/sst/sst_drv_interface.c new file +6
-0+if (ret) +sst_clean_stream (&ctx->streams[str_id]); +return ret; + } +return ret; +}I keep on asking for this to print an error on double frees.
Okay looks like I missed this instance though I do rember fixed another one. I will fix it up.
Quoted 9 lines
sound/soc/intel/sst/sst_drv_interface.c line 99
Quoted 7 lines
sound/soc/intel/sst/sst_drv_interface.c new file +6
-0+/* +* sst_get_sfreq - this function returns the frequency of the stream +* +* @str_param : stream params +*/ +int sst_get_num_channel (struct snd_sst_params *str_param)Cut'n'paste error in the kerneldoc.
Oops will fix
Signature · 1 line
~Vinod
PATCH v4 4/7 ASoC: Intel: sst: Add IPC handling
In reply to Vinod KoulThis patch adds APIs to post IPCs and process reply messages.
--- sound/soc/intel/sst/sst_ipc.c | 358 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 358 insertions(+), 0 deletions(-) create mode 100644 sound/soc/intel/sst/sst_ipc.c
sound/soc/intel/sst/sst_ipc.c new file +358 -0
@@ -0,0 +1,358 @@ +/* +* sst_ipc.c - Intel SST Driver for audio engine +* +* Copyright (C) 2008-14 Intel Corporation +* Authors: Vinod Koul <[email protected]> +* Harsha Priya <[email protected]> +* Dharageswari R <[email protected]> +* KP Jeeja <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/ +#include <linux/pci.h> +#include <linux/firmware.h> +#include <linux/sched.h> +#include <linux/delay.h> +#include <linux/pm_runtime.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/compress_driver.h> +#include <asm/intel-mid.h> +#include <asm/platform_sst_audio.h> +#include "../sst-mfld-platform.h" +#include "sst.h" +#include "../sst-dsp.h" + +struct sst_block *sst_create_block (struct intel_sst_drv *ctx, +u32 msg_id,u32 drv_id) +{ +struct sst_block *msg =NULL ; + +dev_dbg (ctx->dev,"Enter\n" ); + msg =kzalloc (sizeof (*msg),GFP_KERNEL ); +if (!msg) +return NULL ; + msg->condition = false; + msg->on = true; + msg->msg_id = msg_id; + msg->drv_id = drv_id; +spin_lock_bh (&ctx->block_lock); +list_add_tail (&msg->node, &ctx->block_list); +spin_unlock_bh (&ctx->block_lock); + +return msg; +} + +int sst_wake_up_block (struct intel_sst_drv *ctx,int result, +u32 drv_id,u32 ipc,void *data,u32 size) +{ +struct sst_block *block =NULL ; + +dev_dbg (ctx->dev,"Enter\n" ); + +spin_lock_bh (&ctx->block_lock); +list_for_each_entry (block, &ctx->block_list, node) { +dev_dbg (ctx->dev,"Block ipc %d, drv_id %d\n" , block->msg_id, + block->drv_id); +if (block->msg_id == ipc && block->drv_id == drv_id) { +dev_dbg (ctx->dev,"free up the block\n" ); + block->ret_code = result; + block->data = data; + block->size = size; + block->condition = true; +spin_unlock_bh (&ctx->block_lock); +wake_up (&ctx->wait_queue); +return 0 ; + } + } +spin_unlock_bh (&ctx->block_lock); +dev_dbg (ctx->dev, +"Block not found or a response received for a short msg for ipc %d, drv_id %d\n" , + ipc, drv_id); +return -EINVAL ; +} + +int sst_free_block (struct intel_sst_drv *ctx,struct sst_block *freed) +{ +struct sst_block *block =NULL , *__block; + +dev_dbg (ctx->dev,"Enter\n" ); +spin_lock_bh (&ctx->block_lock); +list_for_each_entry_safe (block, __block, &ctx->block_list, node) { +if (block == freed) { +pr_debug ("pvt_id freed --> %d\n" , freed->drv_id); +/* toggle the index position of pvt_id */ +list_del (&freed->node); +spin_unlock_bh (&ctx->block_lock); +kfree (freed->data); + freed->data =NULL ; +kfree (freed); +return 0 ; + } + } +spin_unlock_bh (&ctx->block_lock); +dev_err (ctx->dev,"block is already freed!!!\n" ); +return -EINVAL ; +} + +int sst_post_message_mrfld (struct intel_sst_drv *sst_drv_ctx, +struct ipc_post *ipc_msg,bool sync) +{ +struct ipc_post *msg = ipc_msg; +union ipc_header_mrfld header; +unsigned int loop_count =0 ; +int retval =0 ; +unsigned long irq_flags; + +dev_dbg (sst_drv_ctx->dev,"Enter: sync: %d\n" , sync); +spin_lock_irqsave (&sst_drv_ctx->ipc_spin_lock, irq_flags); + header.full =sst_shim_read64 (sst_drv_ctx->shim,SST_IPCX ); +if (sync) { +while (header.p.header_high.part.busy) { +if (loop_count >25 ) { +dev_err (sst_drv_ctx->dev, +"sst: Busy wait failed, cant send this msg\n" ); + retval = -EBUSY ; + goto out; + } +cpu_relax (); + loop_count++; + header.full =sst_shim_read64 (sst_drv_ctx->shim,SST_IPCX ); + } + }else { +if (list_empty (&sst_drv_ctx->ipc_dispatch_list)) { +/* queue is empty, nothing to send */ +spin_unlock_irqrestore (&sst_drv_ctx->ipc_spin_lock, irq_flags); +dev_dbg (sst_drv_ctx->dev, +"Empty msg queue... NO Action\n" ); +return 0 ; + } + +if (header.p.header_high.part.busy) { +spin_unlock_irqrestore (&sst_drv_ctx->ipc_spin_lock, irq_flags); +dev_dbg (sst_drv_ctx->dev,"Busy not free... post later\n" ); +return 0 ; + } + +/* copy msg from list */ + msg =list_entry (sst_drv_ctx->ipc_dispatch_list.next, + struct ipc_post, node); +list_del (&msg->node); + } +dev_dbg (sst_drv_ctx->dev,"sst: Post message: header = %x\n" , + msg->mrfld_header.p.header_high.full); +dev_dbg (sst_drv_ctx->dev,"sst: size = 0x%x\n" , + msg->mrfld_header.p.header_low_payload); + +if (msg->mrfld_header.p.header_high.part.large) +memcpy_toio (sst_drv_ctx->mailbox +SST_MAILBOX_SEND , + msg->mailbox_data, + msg->mrfld_header.p.header_low_payload); + +sst_shim_write64 (sst_drv_ctx->shim,SST_IPCX , msg->mrfld_header.full); + +out: +spin_unlock_irqrestore (&sst_drv_ctx->ipc_spin_lock, irq_flags); +kfree (msg->mailbox_data); +kfree (msg); +return retval; +} + +void intel_sst_clear_intr_mrfld (struct intel_sst_drv *sst_drv_ctx) +{ +union interrupt_reg_mrfld isr; +union interrupt_reg_mrfld imr; +union ipc_header_mrfld clear_ipc; +unsigned long irq_flags; + +spin_lock_irqsave (&sst_drv_ctx->ipc_spin_lock, irq_flags); + imr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_IMRX ); + isr.full =sst_shim_read64 (sst_drv_ctx->shim,SST_ISRX ); + +/* write 1 to clear*/ + isr.part.busy_interrupt =1 ; +sst_shim_write64 (sst_drv_ctx->shim,SST_ISRX , isr.full); + +/* Set IA done bit */ + clear_ipc.full =sst_shim_read64 (sst_drv_ctx->shim,SST_IPCD ); + + clear_ipc.p.header_high.part.busy =0 ; + clear_ipc.p.header_high.part.done =1 ; + clear_ipc.p.header_low_payload =IPC_ACK_SUCCESS ; +sst_shim_write64 (sst_drv_ctx->shim,SST_IPCD , clear_ipc.full); +/* un mask busy interrupt */ + imr.part.busy_interrupt =0 ; +sst_shim_write64 (sst_drv_ctx->shim,SST_IMRX , imr.full); +spin_unlock_irqrestore (&sst_drv_ctx->ipc_spin_lock, irq_flags); +} + + +/* +* process_fw_init - process the FW init msg +* +* @msg: IPC message mailbox data from FW +* +* This function processes the FW init msg from FW +* marks FW state and prints debug info of loaded FW +*/ +static void process_fw_init (struct intel_sst_drv *sst_drv_ctx, +void *msg) +{ +struct ipc_header_fw_init *init = + (struct ipc_header_fw_init *)msg; +int retval =0 ; + +dev_dbg (sst_drv_ctx->dev,"*** FW Init msg came***\n" ); +if (init->result) { + sst_drv_ctx->sst_state =SST_RESET ; +dev_err (sst_drv_ctx->dev,"FW Init failed, Error %x\n" , + init->result); + retval = init->result; + goto ret; + } + +ret: +sst_wake_up_block (sst_drv_ctx, retval,FW_DWNL_ID ,0 ,NULL ,0 ); +} + +static void process_fw_async_msg (struct intel_sst_drv *sst_drv_ctx, +struct ipc_post *msg) +{ +u32 msg_id; +int str_id; +u32 data_size, i; +void *data_offset; +struct stream_info *stream; +union ipc_header_high msg_high; +u32 msg_low, pipe_id; + + msg_high = msg->mrfld_header.p.header_high; + msg_low = msg->mrfld_header.p.header_low_payload; + msg_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->cmd_id; + data_offset = (msg->mailbox_data +sizeof (struct ipc_dsp_hdr )); + data_size = msg_low - (sizeof (struct ipc_dsp_hdr )); + +switch (msg_id) { +case IPC_SST_PERIOD_ELAPSED_MRFLD : + pipe_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->pipe_id; + str_id =get_stream_id_mrfld (sst_drv_ctx, pipe_id); +if (str_id >0 ) { +dev_dbg (sst_drv_ctx->dev, +"Period elapsed rcvd for pipe id 0x%x\n" , + pipe_id); + stream = &sst_drv_ctx->streams[str_id]; +if (stream->period_elapsed) + stream->period_elapsed (stream->pcm_substream); +if (stream->compr_cb) + stream->compr_cb (stream->compr_cb_param); + } +break ; + +case IPC_IA_DRAIN_STREAM_MRFLD : + pipe_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->pipe_id; + str_id =get_stream_id_mrfld (sst_drv_ctx, pipe_id); +if (str_id >0 ) { + stream = &sst_drv_ctx->streams[str_id]; +if (stream->drain_notify) + stream->drain_notify (stream->drain_cb_param); + } +break ; + +case IPC_IA_FW_ASYNC_ERR_MRFLD : +dev_err (sst_drv_ctx->dev,"FW sent async error msg:\n" ); +for (i =0 ; i < (data_size/4 ); i++) +print_hex_dump (KERN_DEBUG ,NULL ,DUMP_PREFIX_NONE , +16 ,4 , data_offset, data_size, false); +break ; + +case IPC_IA_FW_INIT_CMPLT_MRFLD : +process_fw_init (sst_drv_ctx, data_offset); +break ; + +case IPC_IA_BUF_UNDER_RUN_MRFLD : + pipe_id = ((struct ipc_dsp_hdr *)msg->mailbox_data)->pipe_id; + str_id =get_stream_id_mrfld (sst_drv_ctx, pipe_id); +if (str_id >0 ) +dev_err (sst_drv_ctx->dev, +"Buffer under-run for pipe:%#x str_id:%d\n" , + pipe_id, str_id); +break ; + +default : +dev_err (sst_drv_ctx->dev, +"Unrecognized async msg from FW msg_id %#x\n" , msg_id); + } +} + +void sst_process_reply_mrfld (struct intel_sst_drv *sst_drv_ctx, +struct ipc_post *msg) +{ +unsigned int drv_id; +void *data; +union ipc_header_high msg_high; +u32 msg_low; +struct ipc_dsp_hdr *dsp_hdr; +unsigned int cmd_id; + + msg_high = msg->mrfld_header.p.header_high; + msg_low = msg->mrfld_header.p.header_low_payload; + +dev_dbg (sst_drv_ctx->dev,"IPC process message header %x payload %x\n" , + msg->mrfld_header.p.header_high.full, + msg->mrfld_header.p.header_low_payload); + + drv_id = msg_high.part.drv_id; + +/* Check for async messages first */ +if (drv_id ==SST_ASYNC_DRV_ID ) { +/*FW sent async large message*/ +process_fw_async_msg (sst_drv_ctx, msg); +return ; + } + +/* FW sent short error response for an IPC */ +if (msg_high.part.result && drv_id && !msg_high.part.large) { +/* 32-bit FW error code in msg_low */ +dev_err (sst_drv_ctx->dev,"FW sent error response 0x%x" , msg_low); +sst_wake_up_block (sst_drv_ctx, msg_high.part.result, + msg_high.part.drv_id, + msg_high.part.msg_id,NULL ,0 ); +return ; + } + +/* +* Process all valid responses +* if it is a large message, the payload contains the size to +* copy from mailbox +**/ +if (msg_high.part.large) { + data =kzalloc (msg_low,GFP_KERNEL ); +if (!data) +return ; +memcpy (data, (void *) msg->mailbox_data, msg_low); +/* Copy command id so that we can use to put sst to reset */ + dsp_hdr = (struct ipc_dsp_hdr *)data; + cmd_id = dsp_hdr->cmd_id; +dev_dbg (sst_drv_ctx->dev,"cmd_id %d\n" , dsp_hdr->cmd_id); +if (sst_wake_up_block (sst_drv_ctx, msg_high.part.result, + msg_high.part.drv_id, + msg_high.part.msg_id, data, msg_low)) +kfree (data); + }else { +sst_wake_up_block (sst_drv_ctx, msg_high.part.result, + msg_high.part.drv_id, + msg_high.part.msg_id,NULL ,0 ); + } + +}
Signature · 1 line
1.7.0.4
Mark Brown
maintainerRe: [PATCH v4 4/7] ASoC: Intel: sst: Add IPC handling
sound/soc/intel/sst/sst_ipc.c line 83
Quoted 5 lines · Vinod Koul
sound/soc/intel/sst/sst_ipc.c new file +5
-0+spin_unlock_bh (&ctx->block_lock); +dev_dbg (ctx->dev, +"Block not found or a response received for a short msg for ipc %d, drv_id %d\n" , + ipc, drv_id); +return -EINVAL ;
Shouldn't this be a dev_err() or something?
Re: [PATCH v4 4/7] ASoC: Intel: sst: Add IPC handling
Quoted 9 lines · Mark Brown
sound/soc/intel/sst/sst_ipc.c line 83
Quoted 5 lines · Vinod Koul
sound/soc/intel/sst/sst_ipc.c new file +5
-0+spin_unlock_bh (&ctx->block_lock); +dev_dbg (ctx->dev, +"Block not found or a response received for a short msg for ipc %d, drv_id %d\n" , + ipc, drv_id); +return -EINVAL ;Shouldn't this be a
dev_err()or something?
Not really.
We get response from FW which cna be short or long. In former there wont be anyone waiting as all blocked ones are large.
We cant distiguish between the two thats why we log debug message here. If its real then finally the message will timeout and we would see that as error. Yes this is limiation in IPC.
Putting this as err makes log very noisy :(
Signature · 1 line
~Vinod
Mark Brown
maintainerRe: [PATCH v4 4/7] ASoC: Intel: sst: Add IPC handling
Quoted 4 lines · Vinod Koul
Quoted 1 line · Mark Brown
Shouldn't this be a
dev_err()or something?
Quoted 8 lines
Not really.
We get response from FW which cna be short or long. In former there wont be anyone waiting as all blocked ones are large.
We cant distiguish between the two thats why we log debug message here. If its real then finally the message will timeout and we would see that as error. Yes this is limiation in IPC.
Putting this as err makes log very noisy :(
OK, perhaps a comment explaining that the firmware generates lots of false positives might be in order?
Re: [PATCH v4 4/7] ASoC: Intel: sst: Add IPC handling
Quoted 14 lines · Mark Brown
Quoted 4 lines · Vinod Koul
Quoted 1 line · Mark Brown
Shouldn't this be a
dev_err()or something?Quoted 8 lines
Not really.
We get response from FW which cna be short or long. In former there wont be anyone waiting as all blocked ones are large.
We cant distiguish between the two thats why we log debug message here. If its real then finally the message will timeout and we would see that as error. Yes this is limiation in IPC.
Putting this as err makes log very noisy :(
Quoted 2 lines
OK, perhaps a comment explaining that the firmware generates lots of false positives might be in order?
Sure, that sound okay to me.
I will send that in fixes for these
Signature · 1 line
~Vinod
PATCH v4 5/7 ASoC: Intel: sst: add stream operations
In reply to Vinod KoulThis patch adds pcm and compressed stream control operations.
--- sound/soc/intel/sst/sst_stream.c | 437 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 437 insertions(+), 0 deletions(-) create mode 100644 sound/soc/intel/sst/sst_stream.c
sound/soc/intel/sst/sst_stream.c new file +437 -0
@@ -0,0 +1,437 @@ +/* +* sst_stream.c - Intel SST Driver for audio engine +* +* Copyright (C) 2008-14 Intel Corp +* Authors: Vinod Koul <[email protected]> +* Harsha Priya <[email protected]> +* Dharageswari R <[email protected]> +* KP Jeeja <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/ +#include <linux/pci.h> +#include <linux/firmware.h> +#include <linux/sched.h> +#include <linux/delay.h> +#include <linux/pm_runtime.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/compress_driver.h> +#include <asm/platform_sst_audio.h> +#include "../sst-mfld-platform.h" +#include "sst.h" +#include "../sst-dsp.h" + +int sst_alloc_stream_mrfld (struct intel_sst_drv *sst_drv_ctx,void *params) +{ +struct snd_sst_alloc_mrfld alloc_param; +struct snd_sst_params *str_params; +struct snd_sst_tstamp fw_tstamp; +struct stream_info *str_info; +struct snd_sst_alloc_response *response; +unsigned int str_id, pipe_id, task_id; +int i, num_ch, ret =0 ; +void *data =NULL ; + +dev_dbg (sst_drv_ctx->dev,"Enter\n" ); +BUG_ON (!params); + + str_params = (struct snd_sst_params *)params; +memset (&alloc_param,0 ,sizeof (alloc_param)); + alloc_param.operation = str_params->ops; + alloc_param.codec_type = str_params->codec; + alloc_param.sg_count = str_params->aparams.sg_count; + alloc_param.ring_buf_info[0 ].addr = + str_params->aparams.ring_buf_info[0 ].addr; + alloc_param.ring_buf_info[0 ].size = + str_params->aparams.ring_buf_info[0 ].size; + alloc_param.frag_size = str_params->aparams.frag_size; + +memcpy (&alloc_param.codec_params, &str_params->sparams, +sizeof (struct snd_sst_stream_params )); + +/* +* fill channel map params for multichannel support. +* Ideally channel map should be received from upper layers +* for multichannel support. +* Currently hardcoding as per FW reqm. +*/ + num_ch =sst_get_num_channel (str_params); +for (i =0 ; i <8 ; i++) { +if (i < num_ch) + alloc_param.codec_params.uc.pcm_params.channel_map[i] = i; +else + alloc_param.codec_params.uc.pcm_params.channel_map[i] =0xFF ; + } + + str_id = str_params->stream_id; + str_info =get_stream_info (sst_drv_ctx, str_id); +if (str_info ==NULL ) { +dev_err (sst_drv_ctx->dev,"get stream info returned null\n" ); +return -EINVAL ; + } + + pipe_id = str_params->device_type; + task_id = str_params->task; + sst_drv_ctx->streams[str_id].pipe_id = pipe_id; + sst_drv_ctx->streams[str_id].task_id = task_id; + sst_drv_ctx->streams[str_id].num_ch = num_ch; + +if (sst_drv_ctx->info.lpe_viewpt_rqd) + alloc_param.ts = sst_drv_ctx->info.mailbox_start + + sst_drv_ctx->tstamp + (str_id *sizeof (fw_tstamp)); +else + alloc_param.ts = sst_drv_ctx->mailbox_add + + sst_drv_ctx->tstamp + (str_id *sizeof (fw_tstamp)); + +dev_dbg (sst_drv_ctx->dev,"alloc tstamp location = 0x%x\n" , + alloc_param.ts); +dev_dbg (sst_drv_ctx->dev,"assigned pipe id 0x%x to task %d\n" , + pipe_id, task_id); + +/* allocate device type context */ +sst_init_stream (&sst_drv_ctx->streams[str_id], alloc_param.codec_type, + str_id, alloc_param.operation,0 ); + +dev_info (sst_drv_ctx->dev,"Alloc for str %d pipe %#x\n" , + str_id, pipe_id); + ret =sst_prepare_and_post_msg (sst_drv_ctx, task_id,IPC_CMD , +IPC_IA_ALLOC_STREAM_MRFLD , pipe_id,sizeof (alloc_param), + &alloc_param, data, true, true, false, true); + +if (ret <0 ) { +dev_err (sst_drv_ctx->dev,"FW alloc failed ret %d\n" , ret); +/* alloc failed, so reset the state to uninit */ + str_info->status =STREAM_UN_INIT ; + str_id = ret; + }else if (data) { + response = (struct snd_sst_alloc_response *)data; + ret = response->str_type.result; +if (!ret) + goto out; +dev_err (sst_drv_ctx->dev,"FW alloc failed ret %d\n" , ret); +if (ret ==SST_ERR_STREAM_IN_USE ) { +dev_err (sst_drv_ctx->dev, +"FW not in clean state, send free for:%d\n" , str_id); +sst_free_stream (sst_drv_ctx, str_id); + } + str_id = -ret; + } +out: +kfree (data); +return str_id; +} + +/** +* sst_start_stream - Send msg for a starting stream +* @str_id: stream ID +* +* This function is called by any function which wants to start +* a stream. +*/ +int sst_start_stream (struct intel_sst_drv *sst_drv_ctx,int str_id) +{ +int retval =0 ; +struct stream_info *str_info; +u16 data =0 ; + +dev_dbg (sst_drv_ctx->dev,"sst_start_stream for %d\n" , str_id); + str_info =get_stream_info (sst_drv_ctx, str_id); +if (!str_info) +return -EINVAL ; +if (str_info->status !=STREAM_RUNNING ) +return -EBADRQC ; + + retval =sst_prepare_and_post_msg (sst_drv_ctx, str_info->task_id, +IPC_CMD ,IPC_IA_START_STREAM_MRFLD , str_info->pipe_id, +sizeof (u16), &data,NULL , true, true, true, false); + +return retval; +} + +int sst_send_byte_stream_mrfld (struct intel_sst_drv *sst_drv_ctx, +struct snd_sst_bytes_v2 *bytes) +{struct ipc_post *msg =NULL ; +u32 length; +int pvt_id, ret =0 ; +struct sst_block *block =NULL ; + +dev_dbg (sst_drv_ctx->dev, +"type:%u ipc_msg:%u block:%u task_id:%u pipe: %#x length:%#x\n" , + bytes->type, bytes->ipc_msg, bytes->block, bytes->task_id, + bytes->pipe_id, bytes->len); + +if (sst_create_ipc_msg (&msg, true)) +return -ENOMEM ; + + pvt_id =sst_assign_pvt_id (sst_drv_ctx); +sst_fill_header_mrfld (&msg->mrfld_header, bytes->ipc_msg, + bytes->task_id,1 , pvt_id); + msg->mrfld_header.p.header_high.part.res_rqd = bytes->block; + length = bytes->len; + msg->mrfld_header.p.header_low_payload = length; +dev_dbg (sst_drv_ctx->dev,"length is %d\n" , length); +memcpy (msg->mailbox_data, &bytes->bytes, bytes->len); +if (bytes->block) { + block =sst_create_block (sst_drv_ctx, bytes->ipc_msg, pvt_id); +if (block ==NULL ) { +kfree (msg); + ret = -ENOMEM ; + goto out; + } + } + +sst_add_to_dispatch_list_and_post (sst_drv_ctx, msg); +dev_dbg (sst_drv_ctx->dev,"msg->mrfld_header.p.header_low_payload:%d" , + msg->mrfld_header.p.header_low_payload); + +if (bytes->block) { + ret =sst_wait_timeout (sst_drv_ctx, block); +if (ret) { +dev_err (sst_drv_ctx->dev,"fw returned err %d\n" , ret); +sst_free_block (sst_drv_ctx, block); + goto out; + } + } +if (bytes->type ==SND_SST_BYTES_GET ) { +/* +* copy the reply and send back +* we need to update only sz and payload +*/ +if (bytes->block) { +unsigned char *r = block->data; + +dev_dbg (sst_drv_ctx->dev,"read back %d bytes" , + bytes->len); +memcpy (bytes->bytes, r, bytes->len); + } + } +if (bytes->block) +sst_free_block (sst_drv_ctx, block); +out: +test_and_clear_bit (pvt_id, &sst_drv_ctx->pvt_id); +return 0 ; +} + +/* +* sst_pause_stream - Send msg for a pausing stream +* @str_id: stream ID +* +* This function is called by any function which wants to pause +* an already running stream. +*/ +int sst_pause_stream (struct intel_sst_drv *sst_drv_ctx,int str_id) +{ +int retval =0 ; +struct stream_info *str_info; + +dev_dbg (sst_drv_ctx->dev,"SST DBG:sst_pause_stream for %d\n" , str_id); + str_info =get_stream_info (sst_drv_ctx, str_id); +if (!str_info) +return -EINVAL ; +if (str_info->status ==STREAM_PAUSED ) +return 0 ; +if (str_info->status ==STREAM_RUNNING || + str_info->status ==STREAM_INIT ) { +if (str_info->prev ==STREAM_UN_INIT ) +return -EBADRQC ; + + retval =sst_prepare_and_post_msg (sst_drv_ctx, str_info->task_id,IPC_CMD , +IPC_IA_PAUSE_STREAM_MRFLD , str_info->pipe_id, +0 ,NULL ,NULL , true, true, false, true); + +if (retval ==0 ) { + str_info->prev = str_info->status; + str_info->status =STREAM_PAUSED ; + }else if (retval ==SST_ERR_INVALID_STREAM_ID ) { + retval = -EINVAL ; +mutex_lock (&sst_drv_ctx->sst_lock); +sst_clean_stream (str_info); +mutex_unlock (&sst_drv_ctx->sst_lock); + } + }else { + retval = -EBADRQC ; +dev_dbg (sst_drv_ctx->dev,"SST DBG:BADRQC for stream\n " ); + } + +return retval; +} + +/** +* sst_resume_stream - Send msg for resuming stream +* @str_id: stream ID +* +* This function is called by any function which wants to resume +* an already paused stream. +*/ +int sst_resume_stream (struct intel_sst_drv *sst_drv_ctx,int str_id) +{ +int retval =0 ; +struct stream_info *str_info; + +dev_dbg (sst_drv_ctx->dev,"SST DBG:sst_resume_stream for %d\n" , str_id); + str_info =get_stream_info (sst_drv_ctx, str_id); +if (!str_info) +return -EINVAL ; +if (str_info->status ==STREAM_RUNNING ) +return 0 ; +if (str_info->status ==STREAM_PAUSED ) { + retval =sst_prepare_and_post_msg (sst_drv_ctx, str_info->task_id, +IPC_CMD ,IPC_IA_RESUME_STREAM_MRFLD , + str_info->pipe_id,0 ,NULL ,NULL , + true, true, false, true); + +if (!retval) { +if (str_info->prev ==STREAM_RUNNING ) + str_info->status =STREAM_RUNNING ; +else + str_info->status =STREAM_INIT ; + str_info->prev =STREAM_PAUSED ; + }else if (retval == -SST_ERR_INVALID_STREAM_ID ) { + retval = -EINVAL ; +mutex_lock (&sst_drv_ctx->sst_lock); +sst_clean_stream (str_info); +mutex_unlock (&sst_drv_ctx->sst_lock); + } + }else { + retval = -EBADRQC ; +dev_err (sst_drv_ctx->dev,"SST ERR: BADQRC for stream\n" ); + } + +return retval; +} + + +/** +* sst_drop_stream - Send msg for stopping stream +* @str_id: stream ID +* +* This function is called by any function which wants to stop +* a stream. +*/ +int sst_drop_stream (struct intel_sst_drv *sst_drv_ctx,int str_id) +{ +int retval =0 ; +struct stream_info *str_info; + +dev_dbg (sst_drv_ctx->dev,"SST DBG:sst_drop_stream for %d\n" , str_id); + str_info =get_stream_info (sst_drv_ctx, str_id); +if (!str_info) +return -EINVAL ; + +if (str_info->status !=STREAM_UN_INIT ) { + str_info->prev =STREAM_UN_INIT ; + str_info->status =STREAM_INIT ; + str_info->cumm_bytes =0 ; + retval =sst_prepare_and_post_msg (sst_drv_ctx, str_info->task_id, +IPC_CMD ,IPC_IA_DROP_STREAM_MRFLD , + str_info->pipe_id,0 ,NULL ,NULL , + true, true, true, false); + }else { + retval = -EBADRQC ; +dev_dbg (sst_drv_ctx->dev,"BADQRC for stream, state %x\n" , + str_info->status); + } +return retval; +} + +/** +* sst_drain_stream - Send msg for draining stream +* @str_id: stream ID +* +* This function is called by any function which wants to drain +* a stream. +*/ +int sst_drain_stream (struct intel_sst_drv *sst_drv_ctx, +int str_id,bool partial_drain) +{ +int retval =0 ; +struct stream_info *str_info; + +dev_dbg (sst_drv_ctx->dev,"SST DBG:sst_drain_stream for %d\n" , str_id); + str_info =get_stream_info (sst_drv_ctx, str_id); +if (!str_info) +return -EINVAL ; +if (str_info->status !=STREAM_RUNNING && + str_info->status !=STREAM_INIT && + str_info->status !=STREAM_PAUSED ) { +dev_err (sst_drv_ctx->dev,"SST ERR: BADQRC for stream = %d\n" , + str_info->status); +return -EBADRQC ; + } + + retval =sst_prepare_and_post_msg (sst_drv_ctx, str_info->task_id,IPC_CMD , +IPC_IA_DRAIN_STREAM_MRFLD , str_info->pipe_id, +sizeof (u8), &partial_drain,NULL , true, true, false, false); +/* +* with new non blocked drain implementation in core we dont need to +* wait for respsonse, and need to only invoke callback for drain +* complete +*/ + +return retval; +} + +/** +* sst_free_stream - Frees a stream +* @str_id: stream ID +* +* This function is called by any function which wants to free +* a stream. +*/ +int sst_free_stream (struct intel_sst_drv *sst_drv_ctx,int str_id) +{ +int retval =0 ; +struct stream_info *str_info; +struct intel_sst_ops *ops; + +dev_dbg (sst_drv_ctx->dev,"SST DBG:sst_free_stream for %d\n" , str_id); + +mutex_lock (&sst_drv_ctx->sst_lock); +if (sst_drv_ctx->sst_state ==SST_RESET ) { +mutex_unlock (&sst_drv_ctx->sst_lock); +return -ENODEV ; + } +mutex_unlock (&sst_drv_ctx->sst_lock); + str_info =get_stream_info (sst_drv_ctx, str_id); +if (!str_info) +return -EINVAL ; + ops = sst_drv_ctx->ops; + +mutex_lock (&str_info->lock); +if (str_info->status !=STREAM_UN_INIT ) { + str_info->prev = str_info->status; + str_info->status =STREAM_UN_INIT ; +mutex_unlock (&str_info->lock); + +dev_info (sst_drv_ctx->dev,"Free for str %d pipe %#x\n" , + str_id, str_info->pipe_id); + retval =sst_prepare_and_post_msg (sst_drv_ctx, str_info->task_id,IPC_CMD , +IPC_IA_FREE_STREAM_MRFLD , str_info->pipe_id,0 , +NULL ,NULL , true, true, false, true); + +dev_dbg (sst_drv_ctx->dev,"sst: wait for free returned %d\n" , + retval); +mutex_lock (&sst_drv_ctx->sst_lock); +sst_clean_stream (str_info); +mutex_unlock (&sst_drv_ctx->sst_lock); +dev_dbg (sst_drv_ctx->dev,"SST DBG:Stream freed\n" ); + }else { +mutex_unlock (&str_info->lock); + retval = -EBADRQC ; +dev_dbg (sst_drv_ctx->dev,"SST DBG:BADQRC for stream\n" ); + } + +return retval; +}
Signature · 1 line
1.7.0.4
PATCH v4 6/7 ASoC: Intel: sst: Add some helper functions
In reply to Vinod KoulThis patch adds helper functions like wait, creating ipc headers, shim wrappers.
--- sound/soc/intel/sst/sst_pvt.c | 446 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 446 insertions(+), 0 deletions(-) create mode 100644 sound/soc/intel/sst/sst_pvt.c
sound/soc/intel/sst/sst_pvt.c new file +446 -0
@@ -0,0 +1,446 @@ +/* +* sst_pvt.c - Intel SST Driver for audio engine +* +* Copyright (C) 2008-14 Intel Corp +* Authors: Vinod Koul <[email protected]> +* Harsha Priya <[email protected]> +* Dharageswari R <[email protected]> +* KP Jeeja <[email protected]> +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; version 2 of the License. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +*/ +#include <linux/kobject.h> +#include <linux/pci.h> +#include <linux/fs.h> +#include <linux/firmware.h> +#include <linux/pm_runtime.h> +#include <linux/sched.h> +#include <linux/delay.h> +#include <sound/asound.h> +#include <sound/core.h> +#include <sound/pcm.h> +#include <sound/soc.h> +#include <sound/compress_driver.h> +#include <asm/platform_sst_audio.h> +#include "../sst-mfld-platform.h" +#include "sst.h" +#include "../sst-dsp.h" + +int sst_shim_write (void __iomem *addr,int offset,int value) +{ +writel (value, addr + offset); +return 0 ; +} + +u32 sst_shim_read (void __iomem *addr,int offset) +{ +return readl (addr + offset); +} + +u64 sst_reg_read64 (void __iomem *addr,int offset) +{ +u64 val =0 ; + +memcpy_fromio (&val, addr + offset,sizeof (val)); + +return val; +} + +int sst_shim_write64 (void __iomem *addr,int offset,u64 value) +{ +memcpy_toio (addr + offset, &value,sizeof (value)); +return 0 ; +} + +u64 sst_shim_read64 (void __iomem *addr,int offset) +{ +u64 val =0 ; + +memcpy_fromio (&val, addr + offset,sizeof (val)); +return val; +} + +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); +} + +/* +* sst_wait_interruptible - wait on event +* +* @sst_drv_ctx: Driver context +* @block: Driver block to wait on +* +* This function waits without a timeout (and is interruptable) for a +* given block event +*/ +int sst_wait_interruptible (struct intel_sst_drv *sst_drv_ctx, +struct sst_block *block) +{ +int retval =0 ; + +if (!wait_event_interruptible (sst_drv_ctx->wait_queue, + block->condition)) { +/* event wake */ +if (block->ret_code <0 ) { +dev_err (sst_drv_ctx->dev, +"stream failed %d\n" , block->ret_code); + retval = -EBUSY ; + }else { +dev_dbg (sst_drv_ctx->dev,"event up\n" ); + retval =0 ; + } + }else { +dev_err (sst_drv_ctx->dev,"signal interrupted\n" ); + retval = -EINTR ; + } +return retval; + +} + +unsigned long long read_shim_data (struct intel_sst_drv *sst,int addr) +{ +unsigned long long val =0 ; + +switch (sst->pci_id) { +case SST_MRFLD_PCI_ID : + val =sst_shim_read64 (sst->shim, addr); +break ; + } +return val; +} + +void write_shim_data (struct intel_sst_drv *sst,int addr, +unsigned long long data) +{ +switch (sst->pci_id) { +case SST_MRFLD_PCI_ID : +sst_shim_write64 (sst->shim, addr, (u64 ) data); +break ; + } +} + +/* +* sst_wait_timeout - wait on event for timeout +* +* @sst_drv_ctx: Driver context +* @block: Driver block to wait on +* +* This function waits with a timeout value (and is not interruptible) on a +* given block event +*/ +int sst_wait_timeout (struct intel_sst_drv *sst_drv_ctx,struct sst_block *block) +{ +int retval =0 ; + +/* +* NOTE: +* Observed that FW processes the alloc msg and replies even +* before the alloc thread has finished execution +*/ +dev_dbg (sst_drv_ctx->dev, +"waiting for condition %x ipc %d drv_id %d\n" , + block->condition, block->msg_id, block->drv_id); +if (wait_event_timeout (sst_drv_ctx->wait_queue, + block->condition, +msecs_to_jiffies (SST_BLOCK_TIMEOUT ))) { +/* event wake */ +dev_dbg (sst_drv_ctx->dev,"Event wake %x\n" , + block->condition); +dev_dbg (sst_drv_ctx->dev,"message ret: %d\n" , + block->ret_code); + retval = -block->ret_code; + }else { + block->on = false; +dev_err (sst_drv_ctx->dev, +"Wait timed-out condition:%#x, msg_id:%#x fw_state %#x\n" , + block->condition, block->msg_id, sst_drv_ctx->sst_state); + sst_drv_ctx->sst_state =SST_RESET ; + + retval = -EBUSY ; + } +return retval; +} + +/* +* sst_create_ipc_msg - create a IPC message +* +* @arg: ipc message +* @large: large or short message +* +* this function allocates structures to send a large or short +* message to the firmware +*/ +int sst_create_ipc_msg (struct ipc_post **arg,bool large) +{ +struct ipc_post *msg; + + msg =kzalloc (sizeof (struct ipc_post ),GFP_ATOMIC ); +if (!msg) +return -ENOMEM ; +if (large) { + msg->mailbox_data =kzalloc (SST_MAILBOX_SIZE ,GFP_ATOMIC ); +if (!msg->mailbox_data) { +kfree (msg); +return -ENOMEM ; + } + }else { + msg->mailbox_data =NULL ; + } + msg->is_large = large; + *arg = msg; +return 0 ; +} + +/* +* sst_create_block_and_ipc_msg - Creates IPC message and sst block +* @arg: passed to sst_create_ipc_message API +* @large: large or short message +* @sst_drv_ctx: sst driver context +* @block: return block allocated +* @msg_id: IPC +* @drv_id: stream id or private id +*/ +int sst_create_block_and_ipc_msg (struct ipc_post **arg,bool large, +struct intel_sst_drv *sst_drv_ctx,struct sst_block **block, +u32 msg_id,u32 drv_id) +{ +int retval =0 ; + + retval =sst_create_ipc_msg (arg, large); +if (retval) +return retval; + *block =sst_create_block (sst_drv_ctx, msg_id, drv_id); +if (*block ==NULL ) { +kfree (*arg); +return -ENOMEM ; + } +return retval; +} + +/* +* sst_clean_stream - clean the stream context +* +* @stream: stream structure +* +* this function resets the stream contexts +* should be called in free +*/ +void sst_clean_stream (struct stream_info *stream) +{ + stream->status =STREAM_UN_INIT ; + stream->prev =STREAM_UN_INIT ; +mutex_lock (&stream->lock); + stream->cumm_bytes =0 ; +mutex_unlock (&stream->lock); +} + +int sst_prepare_and_post_msg (struct intel_sst_drv *sst, +int task_id,int ipc_msg,int cmd_id,int pipe_id, +size_t mbox_data_len,const void *mbox_data,void **data, +bool large,bool fill_dsp,bool sync,bool response) +{ +struct ipc_post *msg =NULL ; +struct ipc_dsp_hdr dsp_hdr; +struct sst_block *block; +int ret =0 , pvt_id; + + pvt_id =sst_assign_pvt_id (sst); +if (pvt_id <0 ) +return pvt_id; + +if (response) + ret =sst_create_block_and_ipc_msg ( + &msg, large, sst, &block, ipc_msg, pvt_id); +else + ret =sst_create_ipc_msg (&msg, large); + +if (ret <0 ) { +test_and_clear_bit (pvt_id, &sst->pvt_id); +return -ENOMEM ; + } + +dev_dbg (sst->dev,"pvt_id = %d, pipe id = %d, task = %d ipc_msg: %d\n" , + pvt_id, pipe_id, task_id, ipc_msg); +sst_fill_header_mrfld (&msg->mrfld_header, ipc_msg, + task_id, large, pvt_id); + msg->mrfld_header.p.header_low_payload =sizeof (dsp_hdr) + mbox_data_len; + msg->mrfld_header.p.header_high.part.res_rqd = !sync; +dev_dbg (sst->dev,"header:%x\n" , + msg->mrfld_header.p.header_high.full); +dev_dbg (sst->dev,"response rqd: %x" , + msg->mrfld_header.p.header_high.part.res_rqd); +dev_dbg (sst->dev,"msg->mrfld_header.p.header_low_payload:%d" , + msg->mrfld_header.p.header_low_payload); +if (fill_dsp) { +sst_fill_header_dsp (&dsp_hdr, cmd_id, pipe_id, mbox_data_len); +memcpy (msg->mailbox_data, &dsp_hdr,sizeof (dsp_hdr)); +if (mbox_data_len) { +memcpy (msg->mailbox_data +sizeof (dsp_hdr), + mbox_data, mbox_data_len); + } + } + +if (sync) + sst->ops->post_message (sst, msg, true); +else +sst_add_to_dispatch_list_and_post (sst, msg); + +if (response) { + ret =sst_wait_timeout (sst, block); +if (ret <0 ) { + goto out; + }else if (block->data) { +if (!data) + goto out; + *data =kzalloc (block->size,GFP_KERNEL ); +if (!(*data)) { + ret = -ENOMEM ; + goto out; + }else +memcpy (data, (void *) block->data, block->size); + } + } +out: +if (response) +sst_free_block (sst, block); +test_and_clear_bit (pvt_id, &sst->pvt_id); +return ret; +} + +int sst_pm_runtime_put (struct intel_sst_drv *sst_drv) +{ +int ret; + +pm_runtime_mark_last_busy (sst_drv->dev); + ret =pm_runtime_put_autosuspend (sst_drv->dev); +if (ret <0 ) +return ret; +return 0 ; +} + +void sst_fill_header_mrfld (union ipc_header_mrfld *header, +int msg,int task_id,int large,int drv_id) +{ + header->full =0 ; + header->p.header_high.part.msg_id = msg; + header->p.header_high.part.task_id = task_id; + header->p.header_high.part.large = large; + header->p.header_high.part.drv_id = drv_id; + header->p.header_high.part.done =0 ; + header->p.header_high.part.busy =1 ; + header->p.header_high.part.res_rqd =1 ; +} + +void sst_fill_header_dsp (struct ipc_dsp_hdr *dsp,int msg, +int pipe_id,int len) +{ + dsp->cmd_id = msg; + dsp->mod_index_id =0xff ; + dsp->pipe_id = pipe_id; + dsp->length = len; + dsp->mod_id =0 ; +} + +#define SST_MAX_BLOCKS 15 +/* +* sst_assign_pvt_id - assign a pvt id for stream +* +* @sst_drv_ctx : driver context +* +* this function assigns a private id for calls that dont have stream +* context yet, should be called with lock held +* uses bits for the id, and finds first free bits and assigns that +*/ +int sst_assign_pvt_id (struct intel_sst_drv *drv) +{ +int local; + +spin_lock (&drv->block_lock); +/* find first zero index from lsb */ + local =ffz (drv->pvt_id); +dev_dbg (drv->dev,"pvt_id assigned --> %d\n" , local); +if (local >=SST_MAX_BLOCKS ){ +spin_unlock (&drv->block_lock); +dev_err (drv->dev,"PVT _ID error: no free id blocks " ); +return -EINVAL ; + } +/* toggle the index */ +change_bit (local, &drv->pvt_id); +spin_unlock (&drv->block_lock); +return local; +} + +void sst_init_stream (struct stream_info *stream, +int codec,int sst_id,int ops,u8 slot) +{ + stream->status =STREAM_INIT ; + stream->prev =STREAM_UN_INIT ; + stream->ops = ops; +} + +int sst_validate_strid ( +struct intel_sst_drv *sst_drv_ctx,int str_id) +{ +if (str_id <=0 || str_id > sst_drv_ctx->info.max_streams) { +dev_err (sst_drv_ctx->dev, +"SST ERR: invalid stream id : %d, max %d\n" , + str_id, sst_drv_ctx->info.max_streams); +return -EINVAL ; + } + +return 0 ; +} + +struct stream_info *get_stream_info ( +struct intel_sst_drv *sst_drv_ctx,int str_id) +{ +if (sst_validate_strid (sst_drv_ctx, str_id)) +return NULL ; +return &sst_drv_ctx->streams[str_id]; +} + +int get_stream_id_mrfld (struct intel_sst_drv *sst_drv_ctx, +u32 pipe_id) +{ +int i; + +for (i =1 ; i <= sst_drv_ctx->info.max_streams; i++) +if (pipe_id == sst_drv_ctx->streams[i].pipe_id) +return i; + +dev_dbg (sst_drv_ctx->dev,"no such pipe_id(%u)" , pipe_id); +return -1 ; +} + +u32 relocate_imr_addr_mrfld (u32 base_addr) +{ +/* Get the difference from 512MB aligned base addr */ +/* relocate the base */ + base_addr =MRFLD_FW_VIRTUAL_BASE + (base_addr % (512 *1024 *1024 )); +return base_addr; +} + +void sst_add_to_dispatch_list_and_post (struct intel_sst_drv *sst, +struct ipc_post *msg) +{ +unsigned long irq_flags; + +spin_lock_irqsave (&sst->ipc_spin_lock, irq_flags); +list_add_tail (&msg->node, &sst->ipc_dispatch_list); +spin_unlock_irqrestore (&sst->ipc_spin_lock, irq_flags); + sst->ops->post_message (sst,NULL , false); +}
Signature · 1 line
1.7.0.4
PATCH v4 7/7 ASoC: Intel: sst: Add makefile and kconfig changes
In reply to Vinod Koul--- sound/soc/intel/Kconfig | 4 ++++ sound/soc/intel/Makefile | 3 +++ sound/soc/intel/sst/Makefile | 3 +++ 3 files changed, 10 insertions(+), 0 deletions(-) create mode 100644 sound/soc/intel/sst/Makefile
sound/soc/intel/Kconfig +4 -0
@@ -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
@@ -31,3 +31,6 @@ 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 obj-$(CONFIG_SND_SOC_INTEL_BROADWELL_MACH) += snd-soc-sst-broadwell.o + +# DSP driver +obj-$(CONFIG_SND_SST_IPC) += sst/
sound/soc/intel/sst/Makefile new file +3 -0
@@ -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
Signature · 1 line
1.7.0.4
Mark Brown
maintainerQuoted 3 lines · Vinod Koul
This path series adds the Merrifield IPC driver which is used to load and manage the DSP along with sending and receiving IPCs for PCM and compressed audio.
I had some concerns that I replied to the individual patches with but they're all pretty minor so I've applied everything - please send followup patches dealing with these things.
Quoted 9 lines · Mark Brown
Quoted 3 lines · Vinod Koul
This path series adds the Merrifield IPC driver which is used to load and manage the DSP along with sending and receiving IPCs for PCM and compressed audio.
I had some concerns that I replied to the individual patches with but they're all pretty minor so I've applied everything - please send followup patches dealing with these things.
Thanks a bunch,
Sure I will follow up with you on those. Time to catch the plane now :)
Signature · 1 line
~Vinod