acp-common.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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->peripherals))
  131. break;
  132. }
  133. if (i == acp_data->info.count || !link->num_adr)
  134. break;
  135. }
  136. if (mach && mach->link_mask) {
  137. mach->mach_params.subsystem_rev = acp_data->pci_rev;
  138. mach->mach_params.links = mach->links;
  139. mach->mach_params.link_mask = mach->link_mask;
  140. mach->mach_params.platform = dev_name(sdev->dev);
  141. return mach;
  142. }
  143. }
  144. dev_info(sdev->dev, "No SoundWire machine driver found\n");
  145. return NULL;
  146. }
  147. #else
  148. static struct snd_soc_acpi_mach *amd_sof_sdw_machine_select(struct snd_sof_dev *sdev)
  149. {
  150. return NULL;
  151. }
  152. #endif
  153. struct snd_soc_acpi_mach *amd_sof_machine_select(struct snd_sof_dev *sdev)
  154. {
  155. struct snd_sof_pdata *sof_pdata = sdev->pdata;
  156. struct acp_dev_data *acp_data = sdev->pdata->hw_pdata;
  157. const struct sof_dev_desc *desc = sof_pdata->desc;
  158. struct snd_soc_acpi_mach *mach = NULL;
  159. if (desc->machines)
  160. mach = snd_soc_acpi_find_machine(desc->machines);
  161. if (!mach) {
  162. mach = amd_sof_sdw_machine_select(sdev);
  163. if (!mach) {
  164. dev_warn(sdev->dev, "No matching ASoC machine driver found\n");
  165. return NULL;
  166. }
  167. }
  168. mach->mach_params.subsystem_rev = acp_data->pci_rev;
  169. sof_pdata->tplg_filename = mach->sof_tplg_filename;
  170. sof_pdata->fw_filename = mach->fw_filename;
  171. return mach;
  172. }
  173. /* AMD Common DSP ops */
  174. const struct snd_sof_dsp_ops sof_acp_common_ops = {
  175. /* probe and remove */
  176. .probe = amd_sof_acp_probe,
  177. .remove = amd_sof_acp_remove,
  178. /* Register IO */
  179. .write = sof_io_write,
  180. .read = sof_io_read,
  181. /* Block IO */
  182. .block_read = acp_dsp_block_read,
  183. .block_write = acp_dsp_block_write,
  184. /*Firmware loading */
  185. .load_firmware = snd_sof_load_firmware_memcpy,
  186. .pre_fw_run = acp_dsp_pre_fw_run,
  187. .get_bar_index = acp_get_bar_index,
  188. /* DSP core boot */
  189. .run = acp_sof_dsp_run,
  190. /*IPC */
  191. .send_msg = acp_sof_ipc_send_msg,
  192. .ipc_msg_data = acp_sof_ipc_msg_data,
  193. .set_stream_data_offset = acp_set_stream_data_offset,
  194. .get_mailbox_offset = acp_sof_ipc_get_mailbox_offset,
  195. .get_window_offset = acp_sof_ipc_get_window_offset,
  196. .irq_thread = acp_sof_ipc_irq_thread,
  197. /* stream callbacks */
  198. .pcm_open = acp_pcm_open,
  199. .pcm_close = acp_pcm_close,
  200. .pcm_hw_params = acp_pcm_hw_params,
  201. .pcm_pointer = acp_pcm_pointer,
  202. .hw_info = SNDRV_PCM_INFO_MMAP |
  203. SNDRV_PCM_INFO_MMAP_VALID |
  204. SNDRV_PCM_INFO_INTERLEAVED |
  205. SNDRV_PCM_INFO_PAUSE |
  206. SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
  207. /* Machine driver callbacks */
  208. .machine_select = amd_sof_machine_select,
  209. .machine_register = sof_machine_register,
  210. .machine_unregister = sof_machine_unregister,
  211. /* Trace Logger */
  212. .trace_init = acp_sof_trace_init,
  213. .trace_release = acp_sof_trace_release,
  214. /* PM */
  215. .suspend = amd_sof_acp_suspend,
  216. .resume = amd_sof_acp_resume,
  217. .ipc_dump = amd_sof_ipc_dump,
  218. .dbg_dump = amd_sof_dump,
  219. .debugfs_add_region_item = snd_sof_debugfs_add_region_item_iomem,
  220. .dsp_arch_ops = &sof_xtensa_arch_ops,
  221. /* probe client device registation */
  222. .register_ipc_clients = acp_probes_register,
  223. .unregister_ipc_clients = acp_probes_unregister,
  224. };
  225. EXPORT_SYMBOL_NS(sof_acp_common_ops, "SND_SOC_SOF_AMD_COMMON");
  226. MODULE_LICENSE("Dual BSD/GPL");
  227. MODULE_DESCRIPTION("ACP SOF COMMON Driver");
  228. MODULE_IMPORT_NS("SND_SOC_SOF_AMD_COMMON");
  229. MODULE_IMPORT_NS("SND_SOC_SOF_XTENSA");
  230. MODULE_IMPORT_NS("SOUNDWIRE_AMD_INIT");