icl.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. //
  3. // Copyright(c) 2021-2024 Intel Corporation
  4. //
  5. // Authors: Cezary Rojewski <cezary.rojewski@intel.com>
  6. // Amadeusz Slawinski <amadeuszx.slawinski@linux.intel.com>
  7. //
  8. #include <linux/slab.h>
  9. #include <sound/hdaudio.h>
  10. #include <sound/hdaudio_ext.h>
  11. #include "avs.h"
  12. #include "messages.h"
  13. #define ICL_VS_LTRP_GB_ICCMAX 95
  14. #ifdef CONFIG_DEBUG_FS
  15. int avs_icl_enable_logs(struct avs_dev *adev, enum avs_log_enable enable, u32 aging_period,
  16. u32 fifo_full_period, unsigned long resource_mask, u32 *priorities)
  17. {
  18. struct avs_icl_log_state_info *info;
  19. u32 size, num_libs = adev->fw_cfg.max_libs_count;
  20. int i, ret;
  21. if (fls_long(resource_mask) > num_libs)
  22. return -EINVAL;
  23. size = struct_size(info, logs_priorities_mask, num_libs);
  24. info = kzalloc(size, GFP_KERNEL);
  25. if (!info)
  26. return -ENOMEM;
  27. info->aging_timer_period = aging_period;
  28. info->fifo_full_timer_period = fifo_full_period;
  29. info->enable = enable;
  30. if (enable)
  31. for_each_set_bit(i, &resource_mask, num_libs)
  32. info->logs_priorities_mask[i] = *priorities++;
  33. ret = avs_ipc_set_enable_logs(adev, (u8 *)info, size);
  34. kfree(info);
  35. if (ret)
  36. return AVS_IPC_RET(ret);
  37. return 0;
  38. }
  39. #endif
  40. union avs_icl_memwnd2_slot_type {
  41. u32 val;
  42. struct {
  43. u32 resource_id:8;
  44. u32 type:24;
  45. };
  46. } __packed;
  47. static_assert(sizeof(union avs_icl_memwnd2_slot_type) == 4);
  48. struct avs_icl_memwnd2_desc {
  49. u32 resource_id;
  50. union avs_icl_memwnd2_slot_type slot_id;
  51. u32 vma;
  52. } __packed;
  53. static_assert(sizeof(struct avs_icl_memwnd2_desc) == 12);
  54. #define AVS_ICL_MEMWND2_SLOTS_COUNT 15
  55. struct avs_icl_memwnd2 {
  56. union {
  57. struct avs_icl_memwnd2_desc slot_desc[AVS_ICL_MEMWND2_SLOTS_COUNT];
  58. u8 rsvd[SZ_4K];
  59. };
  60. u8 slot_array[AVS_ICL_MEMWND2_SLOTS_COUNT][SZ_4K];
  61. } __packed;
  62. static_assert(sizeof(struct avs_icl_memwnd2) == 65536);
  63. #define AVS_ICL_SLOT_UNUSED \
  64. ((union avs_icl_memwnd2_slot_type) { 0x00000000U })
  65. #define AVS_ICL_SLOT_CRITICAL_LOG \
  66. ((union avs_icl_memwnd2_slot_type) { 0x54524300U })
  67. #define AVS_ICL_SLOT_DEBUG_LOG \
  68. ((union avs_icl_memwnd2_slot_type) { 0x474f4c00U })
  69. #define AVS_ICL_SLOT_GDB_STUB \
  70. ((union avs_icl_memwnd2_slot_type) { 0x42444700U })
  71. #define AVS_ICL_SLOT_BROKEN \
  72. ((union avs_icl_memwnd2_slot_type) { 0x44414544U })
  73. static int avs_icl_slot_offset(struct avs_dev *adev, union avs_icl_memwnd2_slot_type slot_type)
  74. {
  75. struct avs_icl_memwnd2_desc desc[AVS_ICL_MEMWND2_SLOTS_COUNT];
  76. int i;
  77. memcpy_fromio(&desc, avs_sram_addr(adev, AVS_DEBUG_WINDOW), sizeof(desc));
  78. for (i = 0; i < AVS_ICL_MEMWND2_SLOTS_COUNT; i++)
  79. if (desc[i].slot_id.val == slot_type.val)
  80. return offsetof(struct avs_icl_memwnd2, slot_array) + i * SZ_4K;
  81. return -ENXIO;
  82. }
  83. int avs_icl_log_buffer_offset(struct avs_dev *adev, u32 core)
  84. {
  85. union avs_icl_memwnd2_slot_type slot_type = AVS_ICL_SLOT_DEBUG_LOG;
  86. int ret;
  87. slot_type.resource_id = core;
  88. ret = avs_icl_slot_offset(adev, slot_type);
  89. if (ret < 0)
  90. dev_dbg(adev->dev, "No slot offset found for: %x\n",
  91. slot_type.val);
  92. return ret;
  93. }
  94. bool avs_icl_d0ix_toggle(struct avs_dev *adev, struct avs_ipc_msg *tx, bool wake)
  95. {
  96. /* Full-power when starting DMA engines. */
  97. if (tx->glb.set_ppl_state.state == AVS_PPL_STATE_RUNNING)
  98. return true;
  99. /* Payload-less IPCs do not take part in d0ix toggling. */
  100. return tx->size;
  101. }
  102. int avs_icl_set_d0ix(struct avs_dev *adev, bool enable)
  103. {
  104. int ret;
  105. ret = avs_ipc_set_d0ix(adev, enable, false);
  106. return AVS_IPC_RET(ret);
  107. }
  108. int avs_icl_load_basefw(struct avs_dev *adev, struct firmware *fw)
  109. {
  110. struct hdac_bus *bus = &adev->base.core;
  111. struct hdac_ext_stream *host_stream;
  112. struct snd_pcm_substream substream;
  113. struct snd_dma_buffer dmab;
  114. unsigned int sd_fmt;
  115. u8 ltrp_gb;
  116. int ret;
  117. /*
  118. * ICCMAX:
  119. *
  120. * For ICL+ platforms, as per HW recommendation LTRP_GB is set to 95us
  121. * during FW load. Its original value shall be restored once load completes.
  122. *
  123. * To avoid DMI/OPIO L1 entry during the load procedure, additional CAPTURE
  124. * stream is allocated and set to run.
  125. */
  126. memset(&substream, 0, sizeof(substream));
  127. substream.stream = SNDRV_PCM_STREAM_CAPTURE;
  128. host_stream = snd_hdac_ext_stream_assign(bus, &substream, HDAC_EXT_STREAM_TYPE_HOST);
  129. if (!host_stream)
  130. return -EBUSY;
  131. ltrp_gb = snd_hdac_chip_readb(bus, VS_LTRP) & AZX_REG_VS_LTRP_GB_MASK;
  132. /* Carries no real data, use default format. */
  133. sd_fmt = snd_hdac_stream_format(1, 32, 48000);
  134. ret = snd_hdac_dsp_prepare(hdac_stream(host_stream), sd_fmt, fw->size, &dmab);
  135. if (ret < 0)
  136. goto release_stream;
  137. snd_hdac_chip_updateb(bus, VS_LTRP, AZX_REG_VS_LTRP_GB_MASK, ICL_VS_LTRP_GB_ICCMAX);
  138. spin_lock(&bus->reg_lock);
  139. snd_hdac_stream_start(hdac_stream(host_stream));
  140. spin_unlock(&bus->reg_lock);
  141. ret = avs_hda_load_basefw(adev, fw);
  142. spin_lock(&bus->reg_lock);
  143. snd_hdac_stream_stop(hdac_stream(host_stream));
  144. spin_unlock(&bus->reg_lock);
  145. snd_hdac_dsp_cleanup(hdac_stream(host_stream), &dmab);
  146. release_stream:
  147. snd_hdac_ext_stream_release(host_stream, HDAC_EXT_STREAM_TYPE_HOST);
  148. snd_hdac_chip_updateb(bus, VS_LTRP, AZX_REG_VS_LTRP_GB_MASK, ltrp_gb);
  149. return ret;
  150. }
  151. const struct avs_dsp_ops avs_icl_dsp_ops = {
  152. .power = avs_dsp_core_power,
  153. .reset = avs_dsp_core_reset,
  154. .stall = avs_dsp_core_stall,
  155. .dsp_interrupt = avs_cnl_dsp_interrupt,
  156. .int_control = avs_dsp_interrupt_control,
  157. .load_basefw = avs_icl_load_basefw,
  158. .load_lib = avs_hda_load_library,
  159. .transfer_mods = avs_hda_transfer_modules,
  160. .log_buffer_offset = avs_icl_log_buffer_offset,
  161. .log_buffer_status = avs_apl_log_buffer_status,
  162. .coredump = avs_apl_coredump,
  163. .d0ix_toggle = avs_icl_d0ix_toggle,
  164. .set_d0ix = avs_icl_set_d0ix,
  165. AVS_SET_ENABLE_LOGS_OP(icl)
  166. };