1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) 2 // 3 // Copyright(c) 2022 Intel Corporation. All rights reserved. 4 // 5 // Authors: Ranjani Sridharan <ranjani.sridharan@linux.intel.com> 6 // 7 8 /* 9 * Hardware interface for audio DSP on Meteorlake. 10 */ 11 12 #include <linux/firmware.h> 13 #include <sound/sof/ipc4/header.h> 14 #include <trace/events/sof_intel.h> 15 #include "../ipc4-priv.h" 16 #include "../ops.h" 17 #include "hda.h" 18 #include "hda-ipc.h" 19 #include "../sof-audio.h" 20 #include "mtl.h" 21 22 static const struct snd_sof_debugfs_map mtl_dsp_debugfs[] = { 23 {"hda", HDA_DSP_HDA_BAR, 0, 0x4000, SOF_DEBUGFS_ACCESS_ALWAYS}, 24 {"pp", HDA_DSP_PP_BAR, 0, 0x1000, SOF_DEBUGFS_ACCESS_ALWAYS}, 25 {"dsp", HDA_DSP_BAR, 0, 0x10000, SOF_DEBUGFS_ACCESS_ALWAYS}, 26 }; 27 28 static void mtl_ipc_host_done(struct snd_sof_dev *sdev) 29 { 30 /* 31 * clear busy interrupt to tell dsp controller this interrupt has been accepted, 32 * not trigger it again 33 */ 34 snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDR, 35 MTL_DSP_REG_HFIPCXTDR_BUSY, MTL_DSP_REG_HFIPCXTDR_BUSY); 36 /* 37 * clear busy bit to ack dsp the msg has been processed and send reply msg to dsp 38 */ 39 snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDA, 40 MTL_DSP_REG_HFIPCXTDA_BUSY, 0); 41 } 42 43 static void mtl_ipc_dsp_done(struct snd_sof_dev *sdev) 44 { 45 /* 46 * set DONE bit - tell DSP we have received the reply msg from DSP, and processed it, 47 * don't send more reply to host 48 */ 49 snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDA, 50 MTL_DSP_REG_HFIPCXIDA_DONE, MTL_DSP_REG_HFIPCXIDA_DONE); 51 52 /* unmask Done interrupt */ 53 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXCTL, 54 MTL_DSP_REG_HFIPCXCTL_DONE, MTL_DSP_REG_HFIPCXCTL_DONE); 55 } 56 57 /* Check if an IPC IRQ occurred */ 58 static bool mtl_dsp_check_ipc_irq(struct snd_sof_dev *sdev) 59 { 60 u32 irq_status; 61 u32 hfintipptr; 62 63 if (sdev->dspless_mode_selected) 64 return false; 65 66 /* read Interrupt IP Pointer */ 67 hfintipptr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_HFINTIPPTR) & MTL_HFINTIPPTR_PTR_MASK; 68 irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, hfintipptr + MTL_DSP_IRQSTS); 69 70 trace_sof_intel_hda_irq_ipc_check(sdev, irq_status); 71 72 if (irq_status != U32_MAX && (irq_status & MTL_DSP_IRQSTS_IPC)) 73 return true; 74 75 return false; 76 } 77 78 /* Check if an SDW IRQ occurred */ 79 static bool mtl_dsp_check_sdw_irq(struct snd_sof_dev *sdev) 80 { 81 u32 irq_status; 82 u32 hfintipptr; 83 84 /* read Interrupt IP Pointer */ 85 hfintipptr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_HFINTIPPTR) & MTL_HFINTIPPTR_PTR_MASK; 86 irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, hfintipptr + MTL_DSP_IRQSTS); 87 88 if (irq_status != U32_MAX && (irq_status & MTL_DSP_IRQSTS_SDW)) 89 return true; 90 91 return false; 92 } 93 94 static int mtl_ipc_send_msg(struct snd_sof_dev *sdev, struct snd_sof_ipc_msg *msg) 95 { 96 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; 97 struct sof_ipc4_msg *msg_data = msg->msg_data; 98 99 if (hda_ipc4_tx_is_busy(sdev)) { 100 hdev->delayed_ipc_tx_msg = msg; 101 return 0; 102 } 103 104 hdev->delayed_ipc_tx_msg = NULL; 105 106 /* send the message via mailbox */ 107 if (msg_data->data_size) 108 sof_mailbox_write(sdev, sdev->host_box.offset, msg_data->data_ptr, 109 msg_data->data_size); 110 111 snd_sof_dsp_write(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDDY, 112 msg_data->extension); 113 snd_sof_dsp_write(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDR, 114 msg_data->primary | MTL_DSP_REG_HFIPCXIDR_BUSY); 115 116 hda_dsp_ipc4_schedule_d0i3_work(hdev, msg); 117 118 return 0; 119 } 120 121 static void mtl_enable_ipc_interrupts(struct snd_sof_dev *sdev) 122 { 123 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; 124 const struct sof_intel_dsp_desc *chip = hda->desc; 125 126 if (sdev->dspless_mode_selected) 127 return; 128 129 /* enable IPC DONE and BUSY interrupts */ 130 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, chip->ipc_ctl, 131 MTL_DSP_REG_HFIPCXCTL_BUSY | MTL_DSP_REG_HFIPCXCTL_DONE, 132 MTL_DSP_REG_HFIPCXCTL_BUSY | MTL_DSP_REG_HFIPCXCTL_DONE); 133 } 134 135 static void mtl_disable_ipc_interrupts(struct snd_sof_dev *sdev) 136 { 137 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; 138 const struct sof_intel_dsp_desc *chip = hda->desc; 139 140 if (sdev->dspless_mode_selected) 141 return; 142 143 /* disable IPC DONE and BUSY interrupts */ 144 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, chip->ipc_ctl, 145 MTL_DSP_REG_HFIPCXCTL_BUSY | MTL_DSP_REG_HFIPCXCTL_DONE, 0); 146 } 147 148 static void mtl_enable_sdw_irq(struct snd_sof_dev *sdev, bool enable) 149 { 150 u32 hipcie; 151 u32 mask; 152 u32 val; 153 int ret; 154 155 if (sdev->dspless_mode_selected) 156 return; 157 158 /* Enable/Disable SoundWire interrupt */ 159 mask = MTL_DSP_REG_HfSNDWIE_IE_MASK; 160 if (enable) 161 val = mask; 162 else 163 val = 0; 164 165 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_DSP_REG_HfSNDWIE, mask, val); 166 167 /* check if operation was successful */ 168 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, MTL_DSP_REG_HfSNDWIE, hipcie, 169 (hipcie & mask) == val, 170 HDA_DSP_REG_POLL_INTERVAL_US, HDA_DSP_RESET_TIMEOUT_US); 171 if (ret < 0) 172 dev_err(sdev->dev, "failed to set SoundWire IPC interrupt %s\n", 173 enable ? "enable" : "disable"); 174 } 175 176 static int mtl_enable_interrupts(struct snd_sof_dev *sdev, bool enable) 177 { 178 u32 hfintipptr; 179 u32 irqinten; 180 u32 hipcie; 181 u32 mask; 182 u32 val; 183 int ret; 184 185 if (sdev->dspless_mode_selected) 186 return 0; 187 188 /* read Interrupt IP Pointer */ 189 hfintipptr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_HFINTIPPTR) & MTL_HFINTIPPTR_PTR_MASK; 190 191 /* Enable/Disable Host IPC and SOUNDWIRE */ 192 mask = MTL_IRQ_INTEN_L_HOST_IPC_MASK | MTL_IRQ_INTEN_L_SOUNDWIRE_MASK; 193 if (enable) 194 val = mask; 195 else 196 val = 0; 197 198 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, hfintipptr, mask, val); 199 200 /* check if operation was successful */ 201 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, hfintipptr, irqinten, 202 (irqinten & mask) == val, 203 HDA_DSP_REG_POLL_INTERVAL_US, HDA_DSP_RESET_TIMEOUT_US); 204 if (ret < 0) { 205 dev_err(sdev->dev, "failed to %s Host IPC and/or SOUNDWIRE\n", 206 enable ? "enable" : "disable"); 207 return ret; 208 } 209 210 /* Enable/Disable Host IPC interrupt*/ 211 mask = MTL_DSP_REG_HfHIPCIE_IE_MASK; 212 if (enable) 213 val = mask; 214 else 215 val = 0; 216 217 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_DSP_REG_HfHIPCIE, mask, val); 218 219 /* check if operation was successful */ 220 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, MTL_DSP_REG_HfHIPCIE, hipcie, 221 (hipcie & mask) == val, 222 HDA_DSP_REG_POLL_INTERVAL_US, HDA_DSP_RESET_TIMEOUT_US); 223 if (ret < 0) { 224 dev_err(sdev->dev, "failed to set Host IPC interrupt %s\n", 225 enable ? "enable" : "disable"); 226 return ret; 227 } 228 229 return ret; 230 } 231 232 /* pre fw run operations */ 233 static int mtl_dsp_pre_fw_run(struct snd_sof_dev *sdev) 234 { 235 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; 236 u32 dsphfpwrsts; 237 u32 dsphfdsscs; 238 u32 cpa; 239 u32 pgs; 240 int ret; 241 242 /* Set the DSP subsystem power on */ 243 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_HFDSSCS, 244 MTL_HFDSSCS_SPA_MASK, MTL_HFDSSCS_SPA_MASK); 245 246 /* Wait for unstable CPA read (1 then 0 then 1) just after setting SPA bit */ 247 usleep_range(1000, 1010); 248 249 /* poll with timeout to check if operation successful */ 250 cpa = MTL_HFDSSCS_CPA_MASK; 251 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, MTL_HFDSSCS, dsphfdsscs, 252 (dsphfdsscs & cpa) == cpa, HDA_DSP_REG_POLL_INTERVAL_US, 253 HDA_DSP_RESET_TIMEOUT_US); 254 if (ret < 0) { 255 dev_err(sdev->dev, "failed to enable DSP subsystem\n"); 256 return ret; 257 } 258 259 /* Power up gated-DSP-0 domain in order to access the DSP shim register block. */ 260 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_HFPWRCTL, 261 MTL_HFPWRCTL_WPDSPHPXPG, MTL_HFPWRCTL_WPDSPHPXPG); 262 263 usleep_range(1000, 1010); 264 265 /* poll with timeout to check if operation successful */ 266 pgs = MTL_HFPWRSTS_DSPHPXPGS_MASK; 267 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, MTL_HFPWRSTS, dsphfpwrsts, 268 (dsphfpwrsts & pgs) == pgs, 269 HDA_DSP_REG_POLL_INTERVAL_US, 270 HDA_DSP_RESET_TIMEOUT_US); 271 if (ret < 0) 272 dev_err(sdev->dev, "failed to power up gated DSP domain\n"); 273 274 /* if SoundWire is used, make sure it is not power-gated */ 275 if (hdev->info.handle && hdev->info.link_mask > 0) 276 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_HFPWRCTL, 277 MTL_HfPWRCTL_WPIOXPG(1), MTL_HfPWRCTL_WPIOXPG(1)); 278 279 return ret; 280 } 281 282 static int mtl_dsp_post_fw_run(struct snd_sof_dev *sdev) 283 { 284 int ret; 285 286 if (sdev->first_boot) { 287 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; 288 289 ret = hda_sdw_startup(sdev); 290 if (ret < 0) { 291 dev_err(sdev->dev, "could not startup SoundWire links\n"); 292 return ret; 293 } 294 295 /* Check if IMR boot is usable */ 296 if (!sof_debug_check_flag(SOF_DBG_IGNORE_D3_PERSISTENT)) 297 hdev->imrboot_supported = true; 298 } 299 300 hda_sdw_int_enable(sdev, true); 301 return 0; 302 } 303 304 static void mtl_dsp_dump(struct snd_sof_dev *sdev, u32 flags) 305 { 306 char *level = (flags & SOF_DBG_DUMP_OPTIONAL) ? KERN_DEBUG : KERN_ERR; 307 u32 romdbgsts; 308 u32 romdbgerr; 309 u32 fwsts; 310 u32 fwlec; 311 312 fwsts = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_ROM_STS); 313 fwlec = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_ROM_ERROR); 314 romdbgsts = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFFLGPXQWY); 315 romdbgerr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFFLGPXQWY_ERROR); 316 317 dev_err(sdev->dev, "ROM status: %#x, ROM error: %#x\n", fwsts, fwlec); 318 dev_err(sdev->dev, "ROM debug status: %#x, ROM debug error: %#x\n", romdbgsts, 319 romdbgerr); 320 romdbgsts = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFFLGPXQWY + 0x8 * 3); 321 dev_printk(level, sdev->dev, "ROM feature bit%s enabled\n", 322 romdbgsts & BIT(24) ? "" : " not"); 323 } 324 325 static bool mtl_dsp_primary_core_is_enabled(struct snd_sof_dev *sdev) 326 { 327 int val; 328 329 val = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP2CXCTL_PRIMARY_CORE); 330 if (val != U32_MAX && val & MTL_DSP2CXCTL_PRIMARY_CORE_CPA_MASK) 331 return true; 332 333 return false; 334 } 335 336 static int mtl_dsp_core_power_up(struct snd_sof_dev *sdev, int core) 337 { 338 unsigned int cpa; 339 u32 dspcxctl; 340 int ret; 341 342 /* Only the primary core can be powered up by the host */ 343 if (core != SOF_DSP_PRIMARY_CORE || mtl_dsp_primary_core_is_enabled(sdev)) 344 return 0; 345 346 /* Program the owner of the IP & shim registers (10: Host CPU) */ 347 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_DSP2CXCTL_PRIMARY_CORE, 348 MTL_DSP2CXCTL_PRIMARY_CORE_OSEL, 349 0x2 << MTL_DSP2CXCTL_PRIMARY_CORE_OSEL_SHIFT); 350 351 /* enable SPA bit */ 352 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_DSP2CXCTL_PRIMARY_CORE, 353 MTL_DSP2CXCTL_PRIMARY_CORE_SPA_MASK, 354 MTL_DSP2CXCTL_PRIMARY_CORE_SPA_MASK); 355 356 /* Wait for unstable CPA read (1 then 0 then 1) just after setting SPA bit */ 357 usleep_range(1000, 1010); 358 359 /* poll with timeout to check if operation successful */ 360 cpa = MTL_DSP2CXCTL_PRIMARY_CORE_CPA_MASK; 361 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, MTL_DSP2CXCTL_PRIMARY_CORE, dspcxctl, 362 (dspcxctl & cpa) == cpa, HDA_DSP_REG_POLL_INTERVAL_US, 363 HDA_DSP_RESET_TIMEOUT_US); 364 if (ret < 0) 365 dev_err(sdev->dev, "%s: timeout on MTL_DSP2CXCTL_PRIMARY_CORE read\n", 366 __func__); 367 368 return ret; 369 } 370 371 static int mtl_dsp_core_power_down(struct snd_sof_dev *sdev, int core) 372 { 373 u32 dspcxctl; 374 int ret; 375 376 /* Only the primary core can be powered down by the host */ 377 if (core != SOF_DSP_PRIMARY_CORE || !mtl_dsp_primary_core_is_enabled(sdev)) 378 return 0; 379 380 /* disable SPA bit */ 381 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_DSP2CXCTL_PRIMARY_CORE, 382 MTL_DSP2CXCTL_PRIMARY_CORE_SPA_MASK, 0); 383 384 /* Wait for unstable CPA read (0 then 1 then 0) just after setting SPA bit */ 385 usleep_range(1000, 1010); 386 387 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, MTL_DSP2CXCTL_PRIMARY_CORE, dspcxctl, 388 !(dspcxctl & MTL_DSP2CXCTL_PRIMARY_CORE_CPA_MASK), 389 HDA_DSP_REG_POLL_INTERVAL_US, 390 HDA_DSP_PD_TIMEOUT * USEC_PER_MSEC); 391 if (ret < 0) 392 dev_err(sdev->dev, "failed to power down primary core\n"); 393 394 return ret; 395 } 396 397 static int mtl_power_down_dsp(struct snd_sof_dev *sdev) 398 { 399 u32 dsphfdsscs, cpa; 400 int ret; 401 402 /* first power down core */ 403 ret = mtl_dsp_core_power_down(sdev, SOF_DSP_PRIMARY_CORE); 404 if (ret) { 405 dev_err(sdev->dev, "mtl dsp power down error, %d\n", ret); 406 return ret; 407 } 408 409 /* Set the DSP subsystem power down */ 410 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_HFDSSCS, 411 MTL_HFDSSCS_SPA_MASK, 0); 412 413 /* Wait for unstable CPA read (0 then 1 then 0) just after setting SPA bit */ 414 usleep_range(1000, 1010); 415 416 /* poll with timeout to check if operation successful */ 417 cpa = MTL_HFDSSCS_CPA_MASK; 418 dsphfdsscs = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_HFDSSCS); 419 return snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, MTL_HFDSSCS, dsphfdsscs, 420 (dsphfdsscs & cpa) == 0, HDA_DSP_REG_POLL_INTERVAL_US, 421 HDA_DSP_RESET_TIMEOUT_US); 422 } 423 424 static int mtl_dsp_cl_init(struct snd_sof_dev *sdev, int stream_tag, bool imr_boot) 425 { 426 struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata; 427 const struct sof_intel_dsp_desc *chip = hda->desc; 428 unsigned int status; 429 u32 ipc_hdr; 430 int ret; 431 432 /* step 1: purge FW request */ 433 ipc_hdr = chip->ipc_req_mask | HDA_DSP_ROM_IPC_CONTROL; 434 if (!imr_boot) 435 ipc_hdr |= HDA_DSP_ROM_IPC_PURGE_FW | ((stream_tag - 1) << 9); 436 437 snd_sof_dsp_write(sdev, HDA_DSP_BAR, chip->ipc_req, ipc_hdr); 438 439 /* step 2: power up primary core */ 440 ret = mtl_dsp_core_power_up(sdev, SOF_DSP_PRIMARY_CORE); 441 if (ret < 0) { 442 if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS) 443 dev_err(sdev->dev, "dsp core 0/1 power up failed\n"); 444 goto err; 445 } 446 447 dev_dbg(sdev->dev, "Primary core power up successful\n"); 448 449 /* step 3: wait for IPC DONE bit from ROM */ 450 ret = snd_sof_dsp_read_poll_timeout(sdev, HDA_DSP_BAR, chip->ipc_ack, status, 451 ((status & chip->ipc_ack_mask) == chip->ipc_ack_mask), 452 HDA_DSP_REG_POLL_INTERVAL_US, MTL_DSP_PURGE_TIMEOUT_US); 453 if (ret < 0) { 454 if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS) 455 dev_err(sdev->dev, "timeout waiting for purge IPC done\n"); 456 goto err; 457 } 458 459 /* set DONE bit to clear the reply IPC message */ 460 snd_sof_dsp_update_bits_forced(sdev, HDA_DSP_BAR, chip->ipc_ack, chip->ipc_ack_mask, 461 chip->ipc_ack_mask); 462 463 /* step 4: enable interrupts */ 464 ret = mtl_enable_interrupts(sdev, true); 465 if (ret < 0) { 466 if (hda->boot_iteration == HDA_FW_BOOT_ATTEMPTS) 467 dev_err(sdev->dev, "%s: failed to enable interrupts\n", __func__); 468 goto err; 469 } 470 471 mtl_enable_ipc_interrupts(sdev); 472 473 /* 474 * ACE workaround: don't wait for ROM INIT. 475 * The platform cannot catch ROM_INIT_DONE because of a very short 476 * timing window. Follow the recommendations and skip this part. 477 */ 478 479 return 0; 480 481 err: 482 snd_sof_dsp_dbg_dump(sdev, "MTL DSP init fail", 0); 483 mtl_dsp_core_power_down(sdev, SOF_DSP_PRIMARY_CORE); 484 return ret; 485 } 486 487 static irqreturn_t mtl_ipc_irq_thread(int irq, void *context) 488 { 489 struct sof_ipc4_msg notification_data = {{ 0 }}; 490 struct snd_sof_dev *sdev = context; 491 bool ack_received = false; 492 bool ipc_irq = false; 493 u32 hipcida; 494 u32 hipctdr; 495 496 hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDA); 497 hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDR); 498 499 /* reply message from DSP */ 500 if (hipcida & MTL_DSP_REG_HFIPCXIDA_DONE) { 501 /* DSP received the message */ 502 snd_sof_dsp_update_bits(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXCTL, 503 MTL_DSP_REG_HFIPCXCTL_DONE, 0); 504 505 mtl_ipc_dsp_done(sdev); 506 507 ipc_irq = true; 508 ack_received = true; 509 } 510 511 if (hipctdr & MTL_DSP_REG_HFIPCXTDR_BUSY) { 512 /* Message from DSP (reply or notification) */ 513 u32 extension = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDDY); 514 u32 primary = hipctdr & MTL_DSP_REG_HFIPCXTDR_MSG_MASK; 515 516 /* 517 * ACE fw sends a new fw ipc message to host to 518 * notify the status of the last host ipc message 519 */ 520 if (primary & SOF_IPC4_MSG_DIR_MASK) { 521 /* Reply received */ 522 if (likely(sdev->fw_state == SOF_FW_BOOT_COMPLETE)) { 523 struct sof_ipc4_msg *data = sdev->ipc->msg.reply_data; 524 525 data->primary = primary; 526 data->extension = extension; 527 528 spin_lock_irq(&sdev->ipc_lock); 529 530 snd_sof_ipc_get_reply(sdev); 531 mtl_ipc_host_done(sdev); 532 snd_sof_ipc_reply(sdev, data->primary); 533 534 spin_unlock_irq(&sdev->ipc_lock); 535 } else { 536 dev_dbg_ratelimited(sdev->dev, 537 "IPC reply before FW_READY: %#x|%#x\n", 538 primary, extension); 539 } 540 } else { 541 /* Notification received */ 542 notification_data.primary = primary; 543 notification_data.extension = extension; 544 545 sdev->ipc->msg.rx_data = ¬ification_data; 546 snd_sof_ipc_msgs_rx(sdev); 547 sdev->ipc->msg.rx_data = NULL; 548 549 mtl_ipc_host_done(sdev); 550 } 551 552 ipc_irq = true; 553 } 554 555 if (!ipc_irq) { 556 /* This interrupt is not shared so no need to return IRQ_NONE. */ 557 dev_dbg_ratelimited(sdev->dev, "nothing to do in IPC IRQ thread\n"); 558 } 559 560 if (ack_received) { 561 struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata; 562 563 if (hdev->delayed_ipc_tx_msg) 564 mtl_ipc_send_msg(sdev, hdev->delayed_ipc_tx_msg); 565 } 566 567 return IRQ_HANDLED; 568 } 569 570 static int mtl_dsp_ipc_get_mailbox_offset(struct snd_sof_dev *sdev) 571 { 572 return MTL_DSP_MBOX_UPLINK_OFFSET; 573 } 574 575 static int mtl_dsp_ipc_get_window_offset(struct snd_sof_dev *sdev, u32 id) 576 { 577 return MTL_SRAM_WINDOW_OFFSET(id); 578 } 579 580 static void mtl_ipc_dump(struct snd_sof_dev *sdev) 581 { 582 u32 hipcidr, hipcidd, hipcida, hipctdr, hipctdd, hipctda, hipcctl; 583 584 hipcidr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDR); 585 hipcidd = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDDY); 586 hipcida = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXIDA); 587 hipctdr = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDR); 588 hipctdd = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDDY); 589 hipctda = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXTDA); 590 hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, MTL_DSP_REG_HFIPCXCTL); 591 592 dev_err(sdev->dev, 593 "Host IPC initiator: %#x|%#x|%#x, target: %#x|%#x|%#x, ctl: %#x\n", 594 hipcidr, hipcidd, hipcida, hipctdr, hipctdd, hipctda, hipcctl); 595 } 596 597 static int mtl_dsp_disable_interrupts(struct snd_sof_dev *sdev) 598 { 599 mtl_enable_sdw_irq(sdev, false); 600 mtl_disable_ipc_interrupts(sdev); 601 return mtl_enable_interrupts(sdev, false); 602 } 603 604 static u64 mtl_dsp_get_stream_hda_link_position(struct snd_sof_dev *sdev, 605 struct snd_soc_component *component, 606 struct snd_pcm_substream *substream) 607 { 608 struct hdac_stream *hstream = substream->runtime->private_data; 609 u32 llp_l, llp_u; 610 611 llp_l = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, MTL_PPLCLLPL(hstream->index)); 612 llp_u = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, MTL_PPLCLLPU(hstream->index)); 613 return ((u64)llp_u << 32) | llp_l; 614 } 615 616 /* Meteorlake ops */ 617 struct snd_sof_dsp_ops sof_mtl_ops; 618 EXPORT_SYMBOL_NS(sof_mtl_ops, SND_SOC_SOF_INTEL_HDA_COMMON); 619 620 int sof_mtl_ops_init(struct snd_sof_dev *sdev) 621 { 622 struct sof_ipc4_fw_data *ipc4_data; 623 624 /* common defaults */ 625 memcpy(&sof_mtl_ops, &sof_hda_common_ops, sizeof(struct snd_sof_dsp_ops)); 626 627 /* shutdown */ 628 sof_mtl_ops.shutdown = hda_dsp_shutdown; 629 630 /* doorbell */ 631 sof_mtl_ops.irq_thread = mtl_ipc_irq_thread; 632 633 /* ipc */ 634 sof_mtl_ops.send_msg = mtl_ipc_send_msg; 635 sof_mtl_ops.get_mailbox_offset = mtl_dsp_ipc_get_mailbox_offset; 636 sof_mtl_ops.get_window_offset = mtl_dsp_ipc_get_window_offset; 637 638 /* debug */ 639 sof_mtl_ops.debug_map = mtl_dsp_debugfs; 640 sof_mtl_ops.debug_map_count = ARRAY_SIZE(mtl_dsp_debugfs); 641 sof_mtl_ops.dbg_dump = mtl_dsp_dump; 642 sof_mtl_ops.ipc_dump = mtl_ipc_dump; 643 644 /* pre/post fw run */ 645 sof_mtl_ops.pre_fw_run = mtl_dsp_pre_fw_run; 646 sof_mtl_ops.post_fw_run = mtl_dsp_post_fw_run; 647 648 /* parse platform specific extended manifest */ 649 sof_mtl_ops.parse_platform_ext_manifest = NULL; 650 651 /* dsp core get/put */ 652 /* TODO: add core_get and core_put */ 653 654 sof_mtl_ops.get_stream_position = mtl_dsp_get_stream_hda_link_position; 655 656 sdev->private = devm_kzalloc(sdev->dev, sizeof(struct sof_ipc4_fw_data), GFP_KERNEL); 657 if (!sdev->private) 658 return -ENOMEM; 659 660 ipc4_data = sdev->private; 661 ipc4_data->manifest_fw_hdr_offset = SOF_MAN4_FW_HDR_OFFSET; 662 663 ipc4_data->mtrace_type = SOF_IPC4_MTRACE_INTEL_CAVS_2; 664 665 /* External library loading support */ 666 ipc4_data->load_library = hda_dsp_ipc4_load_library; 667 668 /* set DAI ops */ 669 hda_set_dai_drv_ops(sdev, &sof_mtl_ops); 670 671 sof_mtl_ops.set_power_state = hda_dsp_set_power_state_ipc4; 672 673 return 0; 674 }; 675 EXPORT_SYMBOL_NS(sof_mtl_ops_init, SND_SOC_SOF_INTEL_HDA_COMMON); 676 677 const struct sof_intel_dsp_desc mtl_chip_info = { 678 .cores_num = 3, 679 .init_core_mask = BIT(0), 680 .host_managed_cores_mask = BIT(0), 681 .ipc_req = MTL_DSP_REG_HFIPCXIDR, 682 .ipc_req_mask = MTL_DSP_REG_HFIPCXIDR_BUSY, 683 .ipc_ack = MTL_DSP_REG_HFIPCXIDA, 684 .ipc_ack_mask = MTL_DSP_REG_HFIPCXIDA_DONE, 685 .ipc_ctl = MTL_DSP_REG_HFIPCXCTL, 686 .rom_status_reg = MTL_DSP_ROM_STS, 687 .rom_init_timeout = 300, 688 .ssp_count = MTL_SSP_COUNT, 689 .ssp_base_offset = CNL_SSP_BASE_OFFSET, 690 .sdw_shim_base = SDW_SHIM_BASE_ACE, 691 .sdw_alh_base = SDW_ALH_BASE_ACE, 692 .d0i3_offset = MTL_HDA_VS_D0I3C, 693 .read_sdw_lcount = hda_sdw_check_lcount_common, 694 .enable_sdw_irq = mtl_enable_sdw_irq, 695 .check_sdw_irq = mtl_dsp_check_sdw_irq, 696 .check_ipc_irq = mtl_dsp_check_ipc_irq, 697 .cl_init = mtl_dsp_cl_init, 698 .power_down_dsp = mtl_power_down_dsp, 699 .disable_interrupts = mtl_dsp_disable_interrupts, 700 .hw_ip_version = SOF_INTEL_ACE_1_0, 701 }; 702 EXPORT_SYMBOL_NS(mtl_chip_info, SND_SOC_SOF_INTEL_HDA_COMMON); 703