acp-common.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
  2. //
  3. // This file is provided under a dual BSD/GPLv2 license. When using or
  4. // redistributing this file, you may do so under either license.
  5. //
  6. // Copyright(c) 2022 Advanced Micro Devices, Inc.
  7. //
  8. // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
  9. // V sujith kumar Reddy <Vsujithkumar.Reddy@amd.com>
  10. /* ACP-specific Common code */
  11. #include "../sof-priv.h"
  12. #include "../sof-audio.h"
  13. #include "../ops.h"
  14. #include "acp.h"
  15. #include "acp-dsp-offset.h"
  16. #include <sound/sof/xtensa.h>
  17. /**
  18. * amd_sof_ipc_dump() - This function is called when IPC tx times out.
  19. * @sdev: SOF device.
  20. */
  21. void amd_sof_ipc_dump(struct snd_sof_dev *sdev)
  22. {
  23. const struct sof_amd_acp_desc *desc = get_chip_info(sdev->pdata);
  24. u32 base = desc->dsp_intr_base;
  25. u32 dsp_msg_write = sdev->debug_box.offset +
  26. offsetof(struct scratch_ipc_conf, sof_dsp_msg_write);
  27. u32 dsp_ack_write = sdev->debug_box.offset +
  28. offsetof(struct scratch_ipc_conf, sof_dsp_ack_write);
  29. u32 host_msg_write = sdev->debug_box.offset +
  30. offsetof(struct scratch_ipc_conf, sof_host_msg_write);
  31. u32 host_ack_write = sdev->debug_box.offset +
  32. offsetof(struct scratch_ipc_conf, sof_host_ack_write);
  33. u32 dsp_msg, dsp_ack, host_msg, host_ack, irq_stat;
  34. dsp_msg = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SCRATCH_REG_0 + dsp_msg_write);
  35. dsp_ack = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SCRATCH_REG_0 + dsp_ack_write);
  36. host_msg = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SCRATCH_REG_0 + host_msg_write);
  37. host_ack = snd_sof_dsp_read(sdev, ACP_DSP_BAR, ACP_SCRATCH_REG_0 + host_ack_write);
  38. irq_stat = snd_sof_dsp_read(sdev, ACP_DSP_BAR, base + DSP_SW_INTR_STAT_OFFSET);
  39. dev_err(sdev->dev,
  40. "dsp_msg = %#x dsp_ack = %#x host_msg = %#x host_ack = %#x irq_stat = %#x\n",
  41. dsp_msg, dsp_ack, host_msg, host_ack, irq_stat);
  42. }
  43. /**
  44. * amd_get_registers() - This function is called in case of DSP oops
  45. * in order to gather information about the registers, filename and
  46. * linenumber and stack.
  47. * @sdev: SOF device.
  48. * @xoops: Stores information about registers.
  49. * @panic_info: Stores information about filename and line number.
  50. * @stack: Stores the stack dump.
  51. * @stack_words: Size of the stack dump.
  52. */
  53. static void amd_get_registers(struct snd_sof_dev *sdev,
  54. struct sof_ipc_dsp_oops_xtensa *xoops,
  55. struct sof_ipc_panic_info *panic_info,
  56. u32 *stack, size_t stack_words)
  57. {
  58. u32 offset = sdev->dsp_oops_offset;
  59. /* first read registers */
  60. acp_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
  61. /* then get panic info */
  62. if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
  63. dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
  64. xoops->arch_hdr.totalsize);
  65. return;
  66. }
  67. offset += xoops->arch_hdr.totalsize;
  68. acp_mailbox_read(sdev, offset, panic_info, sizeof(*panic_info));
  69. /* then get the stack */
  70. offset += sizeof(*panic_info);
  71. acp_mailbox_read(sdev, offset, stack, stack_words * sizeof(u32));
  72. }
  73. /**
  74. * amd_sof_dump() - This function is called when a panic message is
  75. * received from the firmware.
  76. * @sdev: SOF device.
  77. * @flags: parameter not used but required by ops prototype
  78. */
  79. void amd_sof_dump(struct snd_sof_dev *sdev, u32 flags)
  80. {
  81. struct sof_ipc_dsp_oops_xtensa xoops;
  82. struct sof_ipc_panic_info panic_info;
  83. u32 stack[AMD_STACK_DUMP_SIZE];
  84. u32 status;
  85. /* Get information about the panic status from the debug box area.
  86. * Compute the trace point based on the status.
  87. */
  88. if (sdev->dsp_oops_offset > sdev->debug_box.offset) {
  89. acp_mailbox_read(sdev, sdev->debug_box.offset, &status, sizeof(u32));
  90. } else {
  91. /* Read DSP Panic status from dsp_box.
  92. * As window information for exception box offset and size is not available
  93. * before FW_READY
  94. */
  95. acp_mailbox_read(sdev, sdev->dsp_box.offset, &status, sizeof(u32));
  96. sdev->dsp_oops_offset = sdev->dsp_box.offset + sizeof(status);
  97. }
  98. /* Get information about the registers, the filename and line
  99. * number and the stack.
  100. */
  101. amd_get_registers(sdev, &xoops, &panic_info, stack, AMD_STACK_DUMP_SIZE);
  102. /* Print the information to the console */
  103. sof_print_oops_and_stack(sdev, KERN_ERR, status, status, &xoops,
  104. &panic_info, stack, AMD_STACK_DUMP_SIZE);
  105. }
  106. #if IS_ENABLED(CONFIG_SND_SOC_SOF_AMD_SOUNDWIRE)
  107. static int amd_sof_sdw_get_slave_info(struct snd_sof_dev *sdev)
  108. {
  109. struct acp_dev_data *acp_data = sdev->pdata->hw_pdata;
  110. return sdw_amd_get_slave_info(acp_data->sdw);
  111. }
  112. static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev *sdev)
  113. {
  114. struct snd_soc_acpi_mach *mach;
  115. const struct snd_soc_acpi_link_adr *link;
  116. struct acp_dev_data *acp_data = sdev->pdata->hw_pdata;
  117. int ret, i;
  118. if (acp_data->info.count) {
  119. ret = amd_sof_sdw_get_slave_info(sdev);
  120. if (ret) {
  121. dev_info(sdev->dev, "failed to read slave information\n");
  122. return NULL;
  123. }
  124. for (mach = sdev->pdata->desc->alt_machines; mach; mach++) {
  125. if (!mach->links)
  126. break;
  127. link = mach->links;
  128. for (i = 0; i < acp_data->info.count && link->num_adr; link++, i++) {
  129. if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link,
  130. acp_data->sdw->ids,
  131. acp_data->sdw->num_slaves))
  132. break;
  133. }
  134. if (i == acp_data->info.count || !link->num_adr)
  135. break;
  136. }
  137. if (mach && mach->link_mask) {
  138. mach->mach_params.subsystem_rev = acp_data->pci_rev;
  139. mach->mach_params.links = mach->links;
  140. mach->mach_params.link_mask = mach->link_mask;
  141. mach->mach_params.platform = dev_name(sdev->dev);
  142. return mach;
  143. }
  144. }
  145. dev_info(sdev->dev, "No SoundWire machine driver found\n");
  146. return NULL;
  147. }
  148. #else
  149. static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev *sdev)
  150. {
  151. return NULL;
  152. }
  153. #endif
  154. struct snd_soc_acpi_mach *amd_sof_machine_select(struct snd_sof_dev *sdev)
  155. {
  156. struct snd_sof_pdata *sof_pdata = sdev->pdata;
  157. struct acp_dev_data *acp_data = sdev->pdata->hw_pdata;
  158. const struct sof_dev_desc *desc = sof_pdata->desc;
  159. struct snd_soc_acpi_mach *mach = NULL;
  160. if (desc->machines)
  161. mach = snd_soc_acpi_find_machine(desc->machines);
  162. if (!mach) {
  163. mach = amd_sof_sdw_machine_select(sdev);
  164. if (!mach) {
  165. dev_warn(sdev->dev, "No matching ASoC machine driver found\n");
  166. return NULL;
  167. }
  168. }
  169. mach->mach_params.subsystem_rev = acp_data->pci_rev;
  170. sof_pdata->tplg_filename = mach->sof_tplg_filename;
  171. sof_pdata->fw_filename = mach->fw_filename;
  172. return mach;
  173. }
  174. /* AMD Common DSP ops */
  175. const struct snd_sof_dsp_ops sof_acp_common_ops = {
  176. /* probe and remove */
  177. .probe = amd_sof_acp_probe,
  178. .remove = amd_sof_acp_remove,
  179. /* Register IO */
  180. .write = sof_io_write,
  181. .read = sof_io_read,
  182. /* Block IO */
  183. .block_read = acp_dsp_block_read,
  184. .block_write = acp_dsp_block_write,
  185. /*Firmware loading */
  186. .load_firmware = snd_sof_load_firmware_memcpy,
  187. .pre_fw_run = acp_dsp_pre_fw_run,
  188. .get_bar_index = acp_get_bar_index,
  189. /* DSP core boot */
  190. .run = acp_sof_dsp_run,
  191. /*IPC */
  192. .send_msg = acp_sof_ipc_send_msg,
  193. .ipc_msg_data = acp_sof_ipc_msg_data,
  194. .set_stream_data_offset = acp_set_stream_data_offset,
  195. .get_mailbox_offset = acp_sof_ipc_get_mailbox_offset,
  196. .get_window_offset = acp_sof_ipc_get_window_offset,
  197. .irq_thread = acp_sof_ipc_irq_thread,
  198. /* stream callbacks */
  199. .pcm_open = acp_pcm_open,
  200. .pcm_close = acp_pcm_close,
  201. .pcm_hw_params = acp_pcm_hw_params,
  202. .pcm_pointer = acp_pcm_pointer,
  203. .hw_info = SNDRV_PCM_INFO_MMAP |
  204. SNDRV_PCM_INFO_MMAP_VALID |
  205. SNDRV_PCM_INFO_INTERLEAVED |
  206. SNDRV_PCM_INFO_PAUSE |
  207. SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
  208. /* Machine driver callbacks */
  209. .machine_select = amd_sof_machine_select,
  210. .machine_register = sof_machine_register,
  211. .machine_unregister = sof_machine_unregister,
  212. /* Trace Logger */
  213. .trace_init = acp_sof_trace_init,
  214. .trace_release = acp_sof_trace_release,
  215. /* PM */
  216. .suspend = amd_sof_acp_suspend,
  217. .resume = amd_sof_acp_resume,
  218. .ipc_dump = amd_sof_ipc_dump,
  219. .dbg_dump = amd_sof_dump,
  220. .debugfs_add_region_item = snd_sof_debugfs_add_region_item_iomem,
  221. .dsp_arch_ops = &sof_xtensa_arch_ops,
  222. /* probe client device registation */
  223. .register_ipc_clients = acp_probes_register,
  224. .unregister_ipc_clients = acp_probes_unregister,
  225. };
  226. EXPORT_SYMBOL_NS(sof_acp_common_ops, SND_SOC_SOF_AMD_COMMON);
  227. MODULE_LICENSE("Dual BSD/GPL");
  228. MODULE_DESCRIPTION("ACP SOF COMMON Driver");
  229. MODULE_IMPORT_NS(SND_SOC_SOF_AMD_COMMON);
  230. MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
  231. MODULE_IMPORT_NS(SOUNDWIRE_AMD_INIT);