acp.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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) 2021, 2023 Advanced Micro Devices, Inc. All rights reserved.
  7. *
  8. * Author: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
  9. */
  10. #ifndef __SOF_AMD_ACP_H
  11. #define __SOF_AMD_ACP_H
  12. #include <linux/dmi.h>
  13. #include <linux/soundwire/sdw_amd.h>
  14. #include "../sof-priv.h"
  15. #include "../sof-audio.h"
  16. #define ACP_MAX_STREAM 8
  17. #define ACP_DSP_BAR 0
  18. #define ACP_HW_SEM_RETRY_COUNT 10000
  19. #define ACP_REG_POLL_INTERVAL 500
  20. #define ACP_REG_POLL_TIMEOUT_US 2000
  21. #define ACP_DMA_COMPLETE_TIMEOUT_US 5000
  22. #define ACP3X_PGFSM_CNTL_POWER_ON_MASK 0x01
  23. #define ACP3X_PGFSM_STATUS_MASK 0x03
  24. #define ACP6X_PGFSM_CNTL_POWER_ON_MASK 0x07
  25. #define ACP6X_PGFSM_STATUS_MASK 0x0F
  26. #define ACP70_PGFSM_CNTL_POWER_ON_MASK 0x1F
  27. #define ACP70_PGFSM_STATUS_MASK 0xFF
  28. #define ACP_POWERED_ON 0x00
  29. #define ACP_ASSERT_RESET 0x01
  30. #define ACP_RELEASE_RESET 0x00
  31. #define ACP_SOFT_RESET_DONE_MASK 0x00010001
  32. #define ACP_DSP_ASSERT_RESET 0x04
  33. #define ACP_DSP_RELEASE_RESET 0x00
  34. #define ACP_DSP_SOFT_RESET_DONE_MASK 0x00050004
  35. #define ACP_DSP_INTR_EN_MASK 0x00000001
  36. #define ACP3X_SRAM_PTE_OFFSET 0x02050000
  37. #define ACP5X_SRAM_PTE_OFFSET 0x02050000
  38. #define ACP6X_SRAM_PTE_OFFSET 0x03800000
  39. #define ACP70_SRAM_PTE_OFFSET ACP6X_SRAM_PTE_OFFSET
  40. #define PAGE_SIZE_4K_ENABLE 0x2
  41. #define ACP_PAGE_SIZE 0x1000
  42. #define ACP_DMA_CH_RUN 0x02
  43. #define ACP_MAX_DESC_CNT 0x02
  44. #define DSP_FW_RUN_ENABLE 0x01
  45. #define ACP_SHA_RUN 0x01
  46. #define ACP_SHA_RESET 0x02
  47. #define ACP_SHA_HEADER 0x01
  48. #define ACP_DMA_CH_RST 0x01
  49. #define ACP_DMA_CH_GRACEFUL_RST_EN 0x10
  50. #define ACP_ATU_CACHE_INVALID 0x01
  51. #define ACP_MAX_DESC 128
  52. #define ACPBUS_REG_BASE_OFFSET ACP_DMA_CNTL_0
  53. #define ACP_DEFAULT_DRAM_LENGTH 0x00080000
  54. #define ACP3X_SCRATCH_MEMORY_ADDRESS 0x02050000
  55. #define ACP_SYSTEM_MEMORY_WINDOW 0x4000000
  56. #define ACP_IRAM_BASE_ADDRESS 0x000000
  57. #define ACP_DRAM_BASE_ADDRESS 0x01000000
  58. #define ACP_DRAM_PAGE_COUNT 128
  59. #define ACP_SRAM_BASE_ADDRESS 0x3806000
  60. #define ACP7X_SRAM_BASE_ADDRESS 0x380C000
  61. #define ACP_DSP_TO_HOST_IRQ 0x04
  62. #define ACP_RN_PCI_ID 0x01
  63. #define ACP_VANGOGH_PCI_ID 0x50
  64. #define ACP_RMB_PCI_ID 0x6F
  65. #define ACP63_PCI_ID 0x63
  66. #define ACP70_PCI_ID 0x70
  67. #define ACP71_PCI_ID 0x71
  68. #define ACP72_PCI_ID 0x72
  69. #define HOST_BRIDGE_CZN 0x1630
  70. #define HOST_BRIDGE_VGH 0x1645
  71. #define HOST_BRIDGE_RMB 0x14B5
  72. #define HOST_BRIDGE_ACP63 0x14E8
  73. #define HOST_BRIDGE_ACP70 0x1507
  74. #define ACP_SHA_STAT 0x8000
  75. #define ACP_PSP_TIMEOUT_US 1000000
  76. #define ACP_EXT_INTR_ERROR_STAT 0x20000000
  77. #define MP0_C2PMSG_114_REG 0x3810AC8
  78. #define MP0_C2PMSG_73_REG 0x3810A24
  79. #define MBOX_ACP_SHA_DMA_COMMAND 0x70000
  80. #define MBOX_ACP_IRAM_DRAM_FENCE_COMMAND 0x80000
  81. #define MBOX_DELAY_US 1000
  82. #define MBOX_READY_MASK 0x80000000
  83. #define MBOX_STATUS_MASK 0xFFFF
  84. #define MBOX_ISREADY_FLAG 0x40000000
  85. #define IRAM_DRAM_FENCE_0 0X0
  86. #define IRAM_DRAM_FENCE_1 0X01
  87. #define IRAM_DRAM_FENCE_2 0X02
  88. #define BOX_SIZE_512 0x200
  89. #define BOX_SIZE_1024 0x400
  90. #define EXCEPT_MAX_HDR_SIZE 0x400
  91. #define AMD_STACK_DUMP_SIZE 32
  92. #define SRAM1_SIZE 0x280000
  93. #define PROBE_STATUS_BIT BIT(31)
  94. #define ACP_FIRMWARE_SIGNATURE 0x100
  95. #define ACP_ERROR_IRQ_MASK BIT(29)
  96. #define ACP_SDW0_IRQ_MASK BIT(21)
  97. #define ACP_SDW1_IRQ_MASK BIT(2)
  98. #define SDW_ACPI_ADDR_ACP63 5
  99. #define SDW_ACPI_ADDR_ACP70 SDW_ACPI_ADDR_ACP63
  100. #define ACP_DEFAULT_SRAM_LENGTH 0x00080000
  101. #define ACP_SRAM_PAGE_COUNT 128
  102. #define ACP6X_SDW_MAX_MANAGER_COUNT 2
  103. #define ACP70_SDW_MAX_MANAGER_COUNT ACP6X_SDW_MAX_MANAGER_COUNT
  104. enum clock_source {
  105. ACP_CLOCK_96M = 0,
  106. ACP_CLOCK_48M,
  107. ACP_CLOCK_24M,
  108. ACP_CLOCK_ACLK,
  109. ACP_CLOCK_MCLK,
  110. };
  111. struct acp_atu_grp_pte {
  112. u32 low;
  113. u32 high;
  114. };
  115. union dma_tx_cnt {
  116. struct {
  117. unsigned int count : 19;
  118. unsigned int reserved : 12;
  119. unsigned ioc : 1;
  120. } bitfields, bits;
  121. unsigned int u32_all;
  122. signed int i32_all;
  123. };
  124. struct dma_descriptor {
  125. unsigned int src_addr;
  126. unsigned int dest_addr;
  127. union dma_tx_cnt tx_cnt;
  128. unsigned int reserved;
  129. };
  130. /* Scratch memory structure for communication b/w host and dsp */
  131. struct scratch_ipc_conf {
  132. /* Debug memory */
  133. u8 sof_debug_box[1024];
  134. /* Exception memory*/
  135. u8 sof_except_box[1024];
  136. /* Stream buffer */
  137. u8 sof_stream_box[1024];
  138. /* Trace buffer */
  139. u8 sof_trace_box[1024];
  140. /* Host msg flag */
  141. u32 sof_host_msg_write;
  142. /* Host ack flag*/
  143. u32 sof_host_ack_write;
  144. /* DSP msg flag */
  145. u32 sof_dsp_msg_write;
  146. /* Dsp ack flag */
  147. u32 sof_dsp_ack_write;
  148. };
  149. struct scratch_reg_conf {
  150. struct scratch_ipc_conf info;
  151. struct acp_atu_grp_pte grp1_pte[16];
  152. struct acp_atu_grp_pte grp2_pte[16];
  153. struct acp_atu_grp_pte grp3_pte[16];
  154. struct acp_atu_grp_pte grp4_pte[16];
  155. struct acp_atu_grp_pte grp5_pte[16];
  156. struct acp_atu_grp_pte grp6_pte[16];
  157. struct acp_atu_grp_pte grp7_pte[16];
  158. struct acp_atu_grp_pte grp8_pte[16];
  159. struct dma_descriptor dma_desc[64];
  160. unsigned int reg_offset[8];
  161. unsigned int buf_size[8];
  162. u8 acp_tx_fifo_buf[256];
  163. u8 acp_rx_fifo_buf[256];
  164. unsigned int reserve[];
  165. };
  166. struct acp_dsp_stream {
  167. struct list_head list;
  168. struct snd_sof_dev *sdev;
  169. struct snd_pcm_substream *substream;
  170. struct snd_dma_buffer *dmab;
  171. int num_pages;
  172. int stream_tag;
  173. int active;
  174. unsigned int reg_offset;
  175. size_t posn_offset;
  176. struct snd_compr_stream *cstream;
  177. u64 cstream_posn;
  178. };
  179. struct sof_amd_acp_desc {
  180. const char *name;
  181. u32 pgfsm_base;
  182. u32 ext_intr_enb;
  183. u32 ext_intr_cntl;
  184. u32 ext_intr_stat;
  185. u32 ext_intr_stat1;
  186. u32 dsp_intr_base;
  187. u32 sram_pte_offset;
  188. u32 hw_semaphore_offset;
  189. u32 acp_clkmux_sel;
  190. u32 fusion_dsp_offset;
  191. u32 probe_reg_offset;
  192. u32 reg_start_addr;
  193. u32 reg_end_addr;
  194. u32 acp_error_stat;
  195. u32 acp_sw0_i2s_err_reason;
  196. u32 sdw_max_link_count;
  197. u64 sdw_acpi_dev_addr;
  198. };
  199. struct acp_quirk_entry {
  200. bool signed_fw_image;
  201. bool skip_iram_dram_size_mod;
  202. bool post_fw_run_delay;
  203. };
  204. /* Common device data struct for ACP devices */
  205. struct acp_dev_data {
  206. struct snd_sof_dev *dev;
  207. const struct firmware *fw_dbin;
  208. /* DMIC device */
  209. struct platform_device *dmic_dev;
  210. /* mutex lock to protect ACP common registers access */
  211. struct mutex acp_lock;
  212. /* ACPI information stored between scan and probe steps */
  213. struct sdw_amd_acpi_info info;
  214. /* sdw context allocated by SoundWire driver */
  215. struct sdw_amd_ctx *sdw;
  216. unsigned int fw_bin_size;
  217. unsigned int fw_data_bin_size;
  218. unsigned int fw_sram_data_bin_size;
  219. const char *fw_code_bin;
  220. const char *fw_data_bin;
  221. const char *fw_sram_data_bin;
  222. u32 fw_bin_page_count;
  223. u32 fw_data_bin_page_count;
  224. u32 addr;
  225. u32 reg_range;
  226. u32 blk_type;
  227. dma_addr_t sha_dma_addr;
  228. u8 *bin_buf;
  229. dma_addr_t dma_addr;
  230. u8 *data_buf;
  231. dma_addr_t sram_dma_addr;
  232. u8 *sram_data_buf;
  233. struct acp_quirk_entry *quirks;
  234. struct dma_descriptor dscr_info[ACP_MAX_DESC];
  235. struct acp_dsp_stream stream_buf[ACP_MAX_STREAM];
  236. struct acp_dsp_stream *dtrace_stream;
  237. struct acp_dsp_stream *probe_stream;
  238. bool enable_fw_debug;
  239. bool is_dram_in_use;
  240. bool is_sram_in_use;
  241. bool sdw_en_stat;
  242. /* acp70_sdw0_wake_event flag set to true when wake irq asserted for SW0 instance */
  243. bool acp70_sdw0_wake_event;
  244. /* acp70_sdw1_wake_event flag set to true when wake irq asserted for SW1 instance */
  245. bool acp70_sdw1_wake_event;
  246. unsigned int pci_rev;
  247. };
  248. void memcpy_to_scratch(struct snd_sof_dev *sdev, u32 offset, unsigned int *src, size_t bytes);
  249. void memcpy_from_scratch(struct snd_sof_dev *sdev, u32 offset, unsigned int *dst, size_t bytes);
  250. int acp_dma_status(struct acp_dev_data *adata, unsigned char ch);
  251. int configure_and_run_dma(struct acp_dev_data *adata, unsigned int src_addr,
  252. unsigned int dest_addr, int dsp_data_size);
  253. int configure_and_run_sha_dma(struct acp_dev_data *adata, void *image_addr,
  254. unsigned int start_addr, unsigned int dest_addr,
  255. unsigned int image_length);
  256. /* ACP device probe/remove */
  257. int amd_sof_acp_probe(struct snd_sof_dev *sdev);
  258. void amd_sof_acp_remove(struct snd_sof_dev *sdev);
  259. /* DSP Loader callbacks */
  260. int acp_sof_dsp_run(struct snd_sof_dev *sdev);
  261. int acp_dsp_pre_fw_run(struct snd_sof_dev *sdev);
  262. int acp_sof_load_signed_firmware(struct snd_sof_dev *sdev);
  263. int acp_get_bar_index(struct snd_sof_dev *sdev, u32 type);
  264. /* Block IO callbacks */
  265. int acp_dsp_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
  266. u32 offset, void *src, size_t size);
  267. int acp_dsp_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
  268. u32 offset, void *dest, size_t size);
  269. /* IPC callbacks */
  270. irqreturn_t acp_sof_ipc_irq_thread(int irq, void *context);
  271. int acp_sof_ipc_msg_data(struct snd_sof_dev *sdev, struct snd_sof_pcm_stream *sps,
  272. void *p, size_t sz);
  273. int acp_set_stream_data_offset(struct snd_sof_dev *sdev,
  274. struct snd_sof_pcm_stream *sps,
  275. size_t posn_offset);
  276. int acp_sof_ipc_send_msg(struct snd_sof_dev *sdev,
  277. struct snd_sof_ipc_msg *msg);
  278. int acp_sof_ipc_get_mailbox_offset(struct snd_sof_dev *sdev);
  279. int acp_sof_ipc_get_window_offset(struct snd_sof_dev *sdev, u32 id);
  280. void acp_mailbox_write(struct snd_sof_dev *sdev, u32 offset, void *message, size_t bytes);
  281. void acp_mailbox_read(struct snd_sof_dev *sdev, u32 offset, void *message, size_t bytes);
  282. /* ACP - DSP stream callbacks */
  283. int acp_dsp_stream_config(struct snd_sof_dev *sdev, struct acp_dsp_stream *stream);
  284. int acp_dsp_stream_init(struct snd_sof_dev *sdev);
  285. struct acp_dsp_stream *acp_dsp_stream_get(struct snd_sof_dev *sdev, int tag);
  286. int acp_dsp_stream_put(struct snd_sof_dev *sdev, struct acp_dsp_stream *acp_stream);
  287. /*
  288. * DSP PCM Operations.
  289. */
  290. int acp_pcm_open(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream);
  291. int acp_pcm_close(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream);
  292. int acp_pcm_hw_params(struct snd_sof_dev *sdev, struct snd_pcm_substream *substream,
  293. struct snd_pcm_hw_params *params,
  294. struct snd_sof_platform_stream_params *platform_params);
  295. snd_pcm_uframes_t acp_pcm_pointer(struct snd_sof_dev *sdev,
  296. struct snd_pcm_substream *substream);
  297. extern const struct snd_sof_dsp_ops sof_acp_common_ops;
  298. extern struct snd_sof_dsp_ops sof_renoir_ops;
  299. int sof_renoir_ops_init(struct snd_sof_dev *sdev);
  300. extern struct snd_sof_dsp_ops sof_vangogh_ops;
  301. int sof_vangogh_ops_init(struct snd_sof_dev *sdev);
  302. extern struct snd_sof_dsp_ops sof_rembrandt_ops;
  303. int sof_rembrandt_ops_init(struct snd_sof_dev *sdev);
  304. extern struct snd_sof_dsp_ops sof_acp63_ops;
  305. int sof_acp63_ops_init(struct snd_sof_dev *sdev);
  306. extern struct snd_sof_dsp_ops sof_acp70_ops;
  307. int sof_acp70_ops_init(struct snd_sof_dev *sdev);
  308. struct snd_soc_acpi_mach *amd_sof_machine_select(struct snd_sof_dev *sdev);
  309. /* Machine configuration */
  310. int snd_amd_acp_find_config(struct pci_dev *pci);
  311. /* Trace */
  312. int acp_sof_trace_init(struct snd_sof_dev *sdev, struct snd_dma_buffer *dmab,
  313. struct sof_ipc_dma_trace_params_ext *dtrace_params);
  314. int acp_sof_trace_release(struct snd_sof_dev *sdev);
  315. /* PM Callbacks */
  316. int amd_sof_acp_suspend(struct snd_sof_dev *sdev, u32 target_state);
  317. int amd_sof_acp_resume(struct snd_sof_dev *sdev);
  318. void amd_sof_ipc_dump(struct snd_sof_dev *sdev);
  319. void amd_sof_dump(struct snd_sof_dev *sdev, u32 flags);
  320. static inline const struct sof_amd_acp_desc *get_chip_info(struct snd_sof_pdata *pdata)
  321. {
  322. const struct sof_dev_desc *desc = pdata->desc;
  323. return desc->chip_info;
  324. }
  325. int acp_probes_register(struct snd_sof_dev *sdev);
  326. void acp_probes_unregister(struct snd_sof_dev *sdev);
  327. extern struct snd_soc_acpi_mach snd_soc_acpi_amd_vangogh_sof_machines[];
  328. extern const struct dmi_system_id acp_sof_quirk_table[];
  329. #endif