18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * skl-sst-ipc.c - Intel skl IPC Support 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Copyright (C) 2014-15, Intel Corporation. 68c2ecf20Sopenharmony_ci */ 78c2ecf20Sopenharmony_ci#include <linux/device.h> 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include "../common/sst-dsp.h" 108c2ecf20Sopenharmony_ci#include "../common/sst-dsp-priv.h" 118c2ecf20Sopenharmony_ci#include "skl.h" 128c2ecf20Sopenharmony_ci#include "skl-sst-dsp.h" 138c2ecf20Sopenharmony_ci#include "skl-sst-ipc.h" 148c2ecf20Sopenharmony_ci#include "sound/hdaudio_ext.h" 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#define IPC_IXC_STATUS_BITS 24 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* Global Message - Generic */ 208c2ecf20Sopenharmony_ci#define IPC_GLB_TYPE_SHIFT 24 218c2ecf20Sopenharmony_ci#define IPC_GLB_TYPE_MASK (0xf << IPC_GLB_TYPE_SHIFT) 228c2ecf20Sopenharmony_ci#define IPC_GLB_TYPE(x) ((x) << IPC_GLB_TYPE_SHIFT) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci/* Global Message - Reply */ 258c2ecf20Sopenharmony_ci#define IPC_GLB_REPLY_STATUS_SHIFT 24 268c2ecf20Sopenharmony_ci#define IPC_GLB_REPLY_STATUS_MASK ((0x1 << IPC_GLB_REPLY_STATUS_SHIFT) - 1) 278c2ecf20Sopenharmony_ci#define IPC_GLB_REPLY_STATUS(x) ((x) << IPC_GLB_REPLY_STATUS_SHIFT) 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define IPC_GLB_REPLY_TYPE_SHIFT 29 308c2ecf20Sopenharmony_ci#define IPC_GLB_REPLY_TYPE_MASK 0x1F 318c2ecf20Sopenharmony_ci#define IPC_GLB_REPLY_TYPE(x) (((x) >> IPC_GLB_REPLY_TYPE_SHIFT) \ 328c2ecf20Sopenharmony_ci & IPC_GLB_RPLY_TYPE_MASK) 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#define IPC_TIMEOUT_MSECS 3000 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#define IPC_EMPTY_LIST_SIZE 8 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#define IPC_MSG_TARGET_SHIFT 30 398c2ecf20Sopenharmony_ci#define IPC_MSG_TARGET_MASK 0x1 408c2ecf20Sopenharmony_ci#define IPC_MSG_TARGET(x) (((x) & IPC_MSG_TARGET_MASK) \ 418c2ecf20Sopenharmony_ci << IPC_MSG_TARGET_SHIFT) 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define IPC_MSG_DIR_SHIFT 29 448c2ecf20Sopenharmony_ci#define IPC_MSG_DIR_MASK 0x1 458c2ecf20Sopenharmony_ci#define IPC_MSG_DIR(x) (((x) & IPC_MSG_DIR_MASK) \ 468c2ecf20Sopenharmony_ci << IPC_MSG_DIR_SHIFT) 478c2ecf20Sopenharmony_ci/* Global Notification Message */ 488c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_TYPE_SHIFT 16 498c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_TYPE_MASK 0xFF 508c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_TYPE(x) (((x) >> IPC_GLB_NOTIFY_TYPE_SHIFT) \ 518c2ecf20Sopenharmony_ci & IPC_GLB_NOTIFY_TYPE_MASK) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_MSG_TYPE_SHIFT 24 548c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_MSG_TYPE_MASK 0x1F 558c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_MSG_TYPE(x) (((x) >> IPC_GLB_NOTIFY_MSG_TYPE_SHIFT) \ 568c2ecf20Sopenharmony_ci & IPC_GLB_NOTIFY_MSG_TYPE_MASK) 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_RSP_SHIFT 29 598c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_RSP_MASK 0x1 608c2ecf20Sopenharmony_ci#define IPC_GLB_NOTIFY_RSP_TYPE(x) (((x) >> IPC_GLB_NOTIFY_RSP_SHIFT) \ 618c2ecf20Sopenharmony_ci & IPC_GLB_NOTIFY_RSP_MASK) 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci/* Pipeline operations */ 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* Create pipeline message */ 668c2ecf20Sopenharmony_ci#define IPC_PPL_MEM_SIZE_SHIFT 0 678c2ecf20Sopenharmony_ci#define IPC_PPL_MEM_SIZE_MASK 0x7FF 688c2ecf20Sopenharmony_ci#define IPC_PPL_MEM_SIZE(x) (((x) & IPC_PPL_MEM_SIZE_MASK) \ 698c2ecf20Sopenharmony_ci << IPC_PPL_MEM_SIZE_SHIFT) 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_ci#define IPC_PPL_TYPE_SHIFT 11 728c2ecf20Sopenharmony_ci#define IPC_PPL_TYPE_MASK 0x1F 738c2ecf20Sopenharmony_ci#define IPC_PPL_TYPE(x) (((x) & IPC_PPL_TYPE_MASK) \ 748c2ecf20Sopenharmony_ci << IPC_PPL_TYPE_SHIFT) 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci#define IPC_INSTANCE_ID_SHIFT 16 778c2ecf20Sopenharmony_ci#define IPC_INSTANCE_ID_MASK 0xFF 788c2ecf20Sopenharmony_ci#define IPC_INSTANCE_ID(x) (((x) & IPC_INSTANCE_ID_MASK) \ 798c2ecf20Sopenharmony_ci << IPC_INSTANCE_ID_SHIFT) 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci#define IPC_PPL_LP_MODE_SHIFT 0 828c2ecf20Sopenharmony_ci#define IPC_PPL_LP_MODE_MASK 0x1 838c2ecf20Sopenharmony_ci#define IPC_PPL_LP_MODE(x) (((x) & IPC_PPL_LP_MODE_MASK) \ 848c2ecf20Sopenharmony_ci << IPC_PPL_LP_MODE_SHIFT) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* Set pipeline state message */ 878c2ecf20Sopenharmony_ci#define IPC_PPL_STATE_SHIFT 0 888c2ecf20Sopenharmony_ci#define IPC_PPL_STATE_MASK 0x1F 898c2ecf20Sopenharmony_ci#define IPC_PPL_STATE(x) (((x) & IPC_PPL_STATE_MASK) \ 908c2ecf20Sopenharmony_ci << IPC_PPL_STATE_SHIFT) 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci/* Module operations primary register */ 938c2ecf20Sopenharmony_ci#define IPC_MOD_ID_SHIFT 0 948c2ecf20Sopenharmony_ci#define IPC_MOD_ID_MASK 0xFFFF 958c2ecf20Sopenharmony_ci#define IPC_MOD_ID(x) (((x) & IPC_MOD_ID_MASK) \ 968c2ecf20Sopenharmony_ci << IPC_MOD_ID_SHIFT) 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci#define IPC_MOD_INSTANCE_ID_SHIFT 16 998c2ecf20Sopenharmony_ci#define IPC_MOD_INSTANCE_ID_MASK 0xFF 1008c2ecf20Sopenharmony_ci#define IPC_MOD_INSTANCE_ID(x) (((x) & IPC_MOD_INSTANCE_ID_MASK) \ 1018c2ecf20Sopenharmony_ci << IPC_MOD_INSTANCE_ID_SHIFT) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci/* Init instance message extension register */ 1048c2ecf20Sopenharmony_ci#define IPC_PARAM_BLOCK_SIZE_SHIFT 0 1058c2ecf20Sopenharmony_ci#define IPC_PARAM_BLOCK_SIZE_MASK 0xFFFF 1068c2ecf20Sopenharmony_ci#define IPC_PARAM_BLOCK_SIZE(x) (((x) & IPC_PARAM_BLOCK_SIZE_MASK) \ 1078c2ecf20Sopenharmony_ci << IPC_PARAM_BLOCK_SIZE_SHIFT) 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci#define IPC_PPL_INSTANCE_ID_SHIFT 16 1108c2ecf20Sopenharmony_ci#define IPC_PPL_INSTANCE_ID_MASK 0xFF 1118c2ecf20Sopenharmony_ci#define IPC_PPL_INSTANCE_ID(x) (((x) & IPC_PPL_INSTANCE_ID_MASK) \ 1128c2ecf20Sopenharmony_ci << IPC_PPL_INSTANCE_ID_SHIFT) 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci#define IPC_CORE_ID_SHIFT 24 1158c2ecf20Sopenharmony_ci#define IPC_CORE_ID_MASK 0x1F 1168c2ecf20Sopenharmony_ci#define IPC_CORE_ID(x) (((x) & IPC_CORE_ID_MASK) \ 1178c2ecf20Sopenharmony_ci << IPC_CORE_ID_SHIFT) 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci#define IPC_DOMAIN_SHIFT 28 1208c2ecf20Sopenharmony_ci#define IPC_DOMAIN_MASK 0x1 1218c2ecf20Sopenharmony_ci#define IPC_DOMAIN(x) (((x) & IPC_DOMAIN_MASK) \ 1228c2ecf20Sopenharmony_ci << IPC_DOMAIN_SHIFT) 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* Bind/Unbind message extension register */ 1258c2ecf20Sopenharmony_ci#define IPC_DST_MOD_ID_SHIFT 0 1268c2ecf20Sopenharmony_ci#define IPC_DST_MOD_ID(x) (((x) & IPC_MOD_ID_MASK) \ 1278c2ecf20Sopenharmony_ci << IPC_DST_MOD_ID_SHIFT) 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define IPC_DST_MOD_INSTANCE_ID_SHIFT 16 1308c2ecf20Sopenharmony_ci#define IPC_DST_MOD_INSTANCE_ID(x) (((x) & IPC_MOD_INSTANCE_ID_MASK) \ 1318c2ecf20Sopenharmony_ci << IPC_DST_MOD_INSTANCE_ID_SHIFT) 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci#define IPC_DST_QUEUE_SHIFT 24 1348c2ecf20Sopenharmony_ci#define IPC_DST_QUEUE_MASK 0x7 1358c2ecf20Sopenharmony_ci#define IPC_DST_QUEUE(x) (((x) & IPC_DST_QUEUE_MASK) \ 1368c2ecf20Sopenharmony_ci << IPC_DST_QUEUE_SHIFT) 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci#define IPC_SRC_QUEUE_SHIFT 27 1398c2ecf20Sopenharmony_ci#define IPC_SRC_QUEUE_MASK 0x7 1408c2ecf20Sopenharmony_ci#define IPC_SRC_QUEUE(x) (((x) & IPC_SRC_QUEUE_MASK) \ 1418c2ecf20Sopenharmony_ci << IPC_SRC_QUEUE_SHIFT) 1428c2ecf20Sopenharmony_ci/* Load Module count */ 1438c2ecf20Sopenharmony_ci#define IPC_LOAD_MODULE_SHIFT 0 1448c2ecf20Sopenharmony_ci#define IPC_LOAD_MODULE_MASK 0xFF 1458c2ecf20Sopenharmony_ci#define IPC_LOAD_MODULE_CNT(x) (((x) & IPC_LOAD_MODULE_MASK) \ 1468c2ecf20Sopenharmony_ci << IPC_LOAD_MODULE_SHIFT) 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* Save pipeline messgae extension register */ 1498c2ecf20Sopenharmony_ci#define IPC_DMA_ID_SHIFT 0 1508c2ecf20Sopenharmony_ci#define IPC_DMA_ID_MASK 0x1F 1518c2ecf20Sopenharmony_ci#define IPC_DMA_ID(x) (((x) & IPC_DMA_ID_MASK) \ 1528c2ecf20Sopenharmony_ci << IPC_DMA_ID_SHIFT) 1538c2ecf20Sopenharmony_ci/* Large Config message extension register */ 1548c2ecf20Sopenharmony_ci#define IPC_DATA_OFFSET_SZ_SHIFT 0 1558c2ecf20Sopenharmony_ci#define IPC_DATA_OFFSET_SZ_MASK 0xFFFFF 1568c2ecf20Sopenharmony_ci#define IPC_DATA_OFFSET_SZ(x) (((x) & IPC_DATA_OFFSET_SZ_MASK) \ 1578c2ecf20Sopenharmony_ci << IPC_DATA_OFFSET_SZ_SHIFT) 1588c2ecf20Sopenharmony_ci#define IPC_DATA_OFFSET_SZ_CLEAR ~(IPC_DATA_OFFSET_SZ_MASK \ 1598c2ecf20Sopenharmony_ci << IPC_DATA_OFFSET_SZ_SHIFT) 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci#define IPC_LARGE_PARAM_ID_SHIFT 20 1628c2ecf20Sopenharmony_ci#define IPC_LARGE_PARAM_ID_MASK 0xFF 1638c2ecf20Sopenharmony_ci#define IPC_LARGE_PARAM_ID(x) (((x) & IPC_LARGE_PARAM_ID_MASK) \ 1648c2ecf20Sopenharmony_ci << IPC_LARGE_PARAM_ID_SHIFT) 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci#define IPC_FINAL_BLOCK_SHIFT 28 1678c2ecf20Sopenharmony_ci#define IPC_FINAL_BLOCK_MASK 0x1 1688c2ecf20Sopenharmony_ci#define IPC_FINAL_BLOCK(x) (((x) & IPC_FINAL_BLOCK_MASK) \ 1698c2ecf20Sopenharmony_ci << IPC_FINAL_BLOCK_SHIFT) 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci#define IPC_INITIAL_BLOCK_SHIFT 29 1728c2ecf20Sopenharmony_ci#define IPC_INITIAL_BLOCK_MASK 0x1 1738c2ecf20Sopenharmony_ci#define IPC_INITIAL_BLOCK(x) (((x) & IPC_INITIAL_BLOCK_MASK) \ 1748c2ecf20Sopenharmony_ci << IPC_INITIAL_BLOCK_SHIFT) 1758c2ecf20Sopenharmony_ci#define IPC_INITIAL_BLOCK_CLEAR ~(IPC_INITIAL_BLOCK_MASK \ 1768c2ecf20Sopenharmony_ci << IPC_INITIAL_BLOCK_SHIFT) 1778c2ecf20Sopenharmony_ci/* Set D0ix IPC extension register */ 1788c2ecf20Sopenharmony_ci#define IPC_D0IX_WAKE_SHIFT 0 1798c2ecf20Sopenharmony_ci#define IPC_D0IX_WAKE_MASK 0x1 1808c2ecf20Sopenharmony_ci#define IPC_D0IX_WAKE(x) (((x) & IPC_D0IX_WAKE_MASK) \ 1818c2ecf20Sopenharmony_ci << IPC_D0IX_WAKE_SHIFT) 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci#define IPC_D0IX_STREAMING_SHIFT 1 1848c2ecf20Sopenharmony_ci#define IPC_D0IX_STREAMING_MASK 0x1 1858c2ecf20Sopenharmony_ci#define IPC_D0IX_STREAMING(x) (((x) & IPC_D0IX_STREAMING_MASK) \ 1868c2ecf20Sopenharmony_ci << IPC_D0IX_STREAMING_SHIFT) 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_cienum skl_ipc_msg_target { 1908c2ecf20Sopenharmony_ci IPC_FW_GEN_MSG = 0, 1918c2ecf20Sopenharmony_ci IPC_MOD_MSG = 1 1928c2ecf20Sopenharmony_ci}; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cienum skl_ipc_msg_direction { 1958c2ecf20Sopenharmony_ci IPC_MSG_REQUEST = 0, 1968c2ecf20Sopenharmony_ci IPC_MSG_REPLY = 1 1978c2ecf20Sopenharmony_ci}; 1988c2ecf20Sopenharmony_ci 1998c2ecf20Sopenharmony_ci/* Global Message Types */ 2008c2ecf20Sopenharmony_cienum skl_ipc_glb_type { 2018c2ecf20Sopenharmony_ci IPC_GLB_GET_FW_VERSION = 0, /* Retrieves firmware version */ 2028c2ecf20Sopenharmony_ci IPC_GLB_LOAD_MULTIPLE_MODS = 15, 2038c2ecf20Sopenharmony_ci IPC_GLB_UNLOAD_MULTIPLE_MODS = 16, 2048c2ecf20Sopenharmony_ci IPC_GLB_CREATE_PPL = 17, 2058c2ecf20Sopenharmony_ci IPC_GLB_DELETE_PPL = 18, 2068c2ecf20Sopenharmony_ci IPC_GLB_SET_PPL_STATE = 19, 2078c2ecf20Sopenharmony_ci IPC_GLB_GET_PPL_STATE = 20, 2088c2ecf20Sopenharmony_ci IPC_GLB_GET_PPL_CONTEXT_SIZE = 21, 2098c2ecf20Sopenharmony_ci IPC_GLB_SAVE_PPL = 22, 2108c2ecf20Sopenharmony_ci IPC_GLB_RESTORE_PPL = 23, 2118c2ecf20Sopenharmony_ci IPC_GLB_LOAD_LIBRARY = 24, 2128c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY = 26, 2138c2ecf20Sopenharmony_ci IPC_GLB_MAX_IPC_MSG_NUMBER = 31 /* Maximum message number */ 2148c2ecf20Sopenharmony_ci}; 2158c2ecf20Sopenharmony_ci 2168c2ecf20Sopenharmony_cienum skl_ipc_glb_reply { 2178c2ecf20Sopenharmony_ci IPC_GLB_REPLY_SUCCESS = 0, 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci IPC_GLB_REPLY_UNKNOWN_MSG_TYPE = 1, 2208c2ecf20Sopenharmony_ci IPC_GLB_REPLY_ERROR_INVALID_PARAM = 2, 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci IPC_GLB_REPLY_BUSY = 3, 2238c2ecf20Sopenharmony_ci IPC_GLB_REPLY_PENDING = 4, 2248c2ecf20Sopenharmony_ci IPC_GLB_REPLY_FAILURE = 5, 2258c2ecf20Sopenharmony_ci IPC_GLB_REPLY_INVALID_REQUEST = 6, 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci IPC_GLB_REPLY_OUT_OF_MEMORY = 7, 2288c2ecf20Sopenharmony_ci IPC_GLB_REPLY_OUT_OF_MIPS = 8, 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci IPC_GLB_REPLY_INVALID_RESOURCE_ID = 9, 2318c2ecf20Sopenharmony_ci IPC_GLB_REPLY_INVALID_RESOURCE_STATE = 10, 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci IPC_GLB_REPLY_MOD_MGMT_ERROR = 100, 2348c2ecf20Sopenharmony_ci IPC_GLB_REPLY_MOD_LOAD_CL_FAILED = 101, 2358c2ecf20Sopenharmony_ci IPC_GLB_REPLY_MOD_LOAD_INVALID_HASH = 102, 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci IPC_GLB_REPLY_MOD_UNLOAD_INST_EXIST = 103, 2388c2ecf20Sopenharmony_ci IPC_GLB_REPLY_MOD_NOT_INITIALIZED = 104, 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci IPC_GLB_REPLY_INVALID_CONFIG_PARAM_ID = 120, 2418c2ecf20Sopenharmony_ci IPC_GLB_REPLY_INVALID_CONFIG_DATA_LEN = 121, 2428c2ecf20Sopenharmony_ci IPC_GLB_REPLY_GATEWAY_NOT_INITIALIZED = 140, 2438c2ecf20Sopenharmony_ci IPC_GLB_REPLY_GATEWAY_NOT_EXIST = 141, 2448c2ecf20Sopenharmony_ci IPC_GLB_REPLY_SCLK_ALREADY_RUNNING = 150, 2458c2ecf20Sopenharmony_ci IPC_GLB_REPLY_MCLK_ALREADY_RUNNING = 151, 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci IPC_GLB_REPLY_PPL_NOT_INITIALIZED = 160, 2488c2ecf20Sopenharmony_ci IPC_GLB_REPLY_PPL_NOT_EXIST = 161, 2498c2ecf20Sopenharmony_ci IPC_GLB_REPLY_PPL_SAVE_FAILED = 162, 2508c2ecf20Sopenharmony_ci IPC_GLB_REPLY_PPL_RESTORE_FAILED = 163, 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci IPC_MAX_STATUS = ((1<<IPC_IXC_STATUS_BITS)-1) 2538c2ecf20Sopenharmony_ci}; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_cienum skl_ipc_notification_type { 2568c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_GLITCH = 0, 2578c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_OVERRUN = 1, 2588c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_UNDERRUN = 2, 2598c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_END_STREAM = 3, 2608c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_PHRASE_DETECTED = 4, 2618c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_RESOURCE_EVENT = 5, 2628c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_LOG_BUFFER_STATUS = 6, 2638c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_TIMESTAMP_CAPTURED = 7, 2648c2ecf20Sopenharmony_ci IPC_GLB_NOTIFY_FW_READY = 8 2658c2ecf20Sopenharmony_ci}; 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci/* Module Message Types */ 2688c2ecf20Sopenharmony_cienum skl_ipc_module_msg { 2698c2ecf20Sopenharmony_ci IPC_MOD_INIT_INSTANCE = 0, 2708c2ecf20Sopenharmony_ci IPC_MOD_CONFIG_GET = 1, 2718c2ecf20Sopenharmony_ci IPC_MOD_CONFIG_SET = 2, 2728c2ecf20Sopenharmony_ci IPC_MOD_LARGE_CONFIG_GET = 3, 2738c2ecf20Sopenharmony_ci IPC_MOD_LARGE_CONFIG_SET = 4, 2748c2ecf20Sopenharmony_ci IPC_MOD_BIND = 5, 2758c2ecf20Sopenharmony_ci IPC_MOD_UNBIND = 6, 2768c2ecf20Sopenharmony_ci IPC_MOD_SET_DX = 7, 2778c2ecf20Sopenharmony_ci IPC_MOD_SET_D0IX = 8 2788c2ecf20Sopenharmony_ci}; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_civoid skl_ipc_tx_data_copy(struct ipc_message *msg, char *tx_data, 2818c2ecf20Sopenharmony_ci size_t tx_size) 2828c2ecf20Sopenharmony_ci{ 2838c2ecf20Sopenharmony_ci if (tx_size) 2848c2ecf20Sopenharmony_ci memcpy(msg->tx.data, tx_data, tx_size); 2858c2ecf20Sopenharmony_ci} 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_cistatic bool skl_ipc_is_dsp_busy(struct sst_dsp *dsp) 2888c2ecf20Sopenharmony_ci{ 2898c2ecf20Sopenharmony_ci u32 hipci; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_ci hipci = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCI); 2928c2ecf20Sopenharmony_ci return (hipci & SKL_ADSP_REG_HIPCI_BUSY); 2938c2ecf20Sopenharmony_ci} 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci/* Lock to be held by caller */ 2968c2ecf20Sopenharmony_cistatic void skl_ipc_tx_msg(struct sst_generic_ipc *ipc, struct ipc_message *msg) 2978c2ecf20Sopenharmony_ci{ 2988c2ecf20Sopenharmony_ci struct skl_ipc_header *header = (struct skl_ipc_header *)(&msg->tx.header); 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci if (msg->tx.size) 3018c2ecf20Sopenharmony_ci sst_dsp_outbox_write(ipc->dsp, msg->tx.data, msg->tx.size); 3028c2ecf20Sopenharmony_ci sst_dsp_shim_write_unlocked(ipc->dsp, SKL_ADSP_REG_HIPCIE, 3038c2ecf20Sopenharmony_ci header->extension); 3048c2ecf20Sopenharmony_ci sst_dsp_shim_write_unlocked(ipc->dsp, SKL_ADSP_REG_HIPCI, 3058c2ecf20Sopenharmony_ci header->primary | SKL_ADSP_REG_HIPCI_BUSY); 3068c2ecf20Sopenharmony_ci} 3078c2ecf20Sopenharmony_ci 3088c2ecf20Sopenharmony_ciint skl_ipc_check_D0i0(struct sst_dsp *dsp, bool state) 3098c2ecf20Sopenharmony_ci{ 3108c2ecf20Sopenharmony_ci int ret; 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci /* check D0i3 support */ 3138c2ecf20Sopenharmony_ci if (!dsp->fw_ops.set_state_D0i0) 3148c2ecf20Sopenharmony_ci return 0; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci /* Attempt D0i0 or D0i3 based on state */ 3178c2ecf20Sopenharmony_ci if (state) 3188c2ecf20Sopenharmony_ci ret = dsp->fw_ops.set_state_D0i0(dsp); 3198c2ecf20Sopenharmony_ci else 3208c2ecf20Sopenharmony_ci ret = dsp->fw_ops.set_state_D0i3(dsp); 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci return ret; 3238c2ecf20Sopenharmony_ci} 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_cistatic struct ipc_message *skl_ipc_reply_get_msg(struct sst_generic_ipc *ipc, 3268c2ecf20Sopenharmony_ci u64 ipc_header) 3278c2ecf20Sopenharmony_ci{ 3288c2ecf20Sopenharmony_ci struct ipc_message *msg = NULL; 3298c2ecf20Sopenharmony_ci struct skl_ipc_header *header = (struct skl_ipc_header *)(&ipc_header); 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci if (list_empty(&ipc->rx_list)) { 3328c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: rx list is empty but received 0x%x\n", 3338c2ecf20Sopenharmony_ci header->primary); 3348c2ecf20Sopenharmony_ci goto out; 3358c2ecf20Sopenharmony_ci } 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci msg = list_first_entry(&ipc->rx_list, struct ipc_message, list); 3388c2ecf20Sopenharmony_ci 3398c2ecf20Sopenharmony_ci list_del(&msg->list); 3408c2ecf20Sopenharmony_ciout: 3418c2ecf20Sopenharmony_ci return msg; 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci} 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ciint skl_ipc_process_notification(struct sst_generic_ipc *ipc, 3468c2ecf20Sopenharmony_ci struct skl_ipc_header header) 3478c2ecf20Sopenharmony_ci{ 3488c2ecf20Sopenharmony_ci struct skl_dev *skl = container_of(ipc, struct skl_dev, ipc); 3498c2ecf20Sopenharmony_ci 3508c2ecf20Sopenharmony_ci if (IPC_GLB_NOTIFY_MSG_TYPE(header.primary)) { 3518c2ecf20Sopenharmony_ci switch (IPC_GLB_NOTIFY_TYPE(header.primary)) { 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci case IPC_GLB_NOTIFY_UNDERRUN: 3548c2ecf20Sopenharmony_ci dev_err(ipc->dev, "FW Underrun %x\n", header.primary); 3558c2ecf20Sopenharmony_ci break; 3568c2ecf20Sopenharmony_ci 3578c2ecf20Sopenharmony_ci case IPC_GLB_NOTIFY_RESOURCE_EVENT: 3588c2ecf20Sopenharmony_ci dev_err(ipc->dev, "MCPS Budget Violation: %x\n", 3598c2ecf20Sopenharmony_ci header.primary); 3608c2ecf20Sopenharmony_ci break; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci case IPC_GLB_NOTIFY_FW_READY: 3638c2ecf20Sopenharmony_ci skl->boot_complete = true; 3648c2ecf20Sopenharmony_ci wake_up(&skl->boot_wait); 3658c2ecf20Sopenharmony_ci break; 3668c2ecf20Sopenharmony_ci 3678c2ecf20Sopenharmony_ci case IPC_GLB_NOTIFY_PHRASE_DETECTED: 3688c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "***** Phrase Detected **********\n"); 3698c2ecf20Sopenharmony_ci 3708c2ecf20Sopenharmony_ci /* 3718c2ecf20Sopenharmony_ci * Per HW recomendation, After phrase detection, 3728c2ecf20Sopenharmony_ci * clear the CGCTL.MISCBDCGE. 3738c2ecf20Sopenharmony_ci * 3748c2ecf20Sopenharmony_ci * This will be set back on stream closure 3758c2ecf20Sopenharmony_ci */ 3768c2ecf20Sopenharmony_ci skl->enable_miscbdcge(ipc->dev, false); 3778c2ecf20Sopenharmony_ci skl->miscbdcg_disabled = true; 3788c2ecf20Sopenharmony_ci break; 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci default: 3818c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: Unhandled error msg=%x\n", 3828c2ecf20Sopenharmony_ci header.primary); 3838c2ecf20Sopenharmony_ci break; 3848c2ecf20Sopenharmony_ci } 3858c2ecf20Sopenharmony_ci } 3868c2ecf20Sopenharmony_ci 3878c2ecf20Sopenharmony_ci return 0; 3888c2ecf20Sopenharmony_ci} 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_cistruct skl_ipc_err_map { 3918c2ecf20Sopenharmony_ci const char *msg; 3928c2ecf20Sopenharmony_ci enum skl_ipc_glb_reply reply; 3938c2ecf20Sopenharmony_ci int err; 3948c2ecf20Sopenharmony_ci}; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_cistatic struct skl_ipc_err_map skl_err_map[] = { 3978c2ecf20Sopenharmony_ci {"DSP out of memory", IPC_GLB_REPLY_OUT_OF_MEMORY, -ENOMEM}, 3988c2ecf20Sopenharmony_ci {"DSP busy", IPC_GLB_REPLY_BUSY, -EBUSY}, 3998c2ecf20Sopenharmony_ci {"SCLK already running", IPC_GLB_REPLY_SCLK_ALREADY_RUNNING, 4008c2ecf20Sopenharmony_ci IPC_GLB_REPLY_SCLK_ALREADY_RUNNING}, 4018c2ecf20Sopenharmony_ci {"MCLK already running", IPC_GLB_REPLY_MCLK_ALREADY_RUNNING, 4028c2ecf20Sopenharmony_ci IPC_GLB_REPLY_MCLK_ALREADY_RUNNING}, 4038c2ecf20Sopenharmony_ci}; 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_cistatic int skl_ipc_set_reply_error_code(struct sst_generic_ipc *ipc, u32 reply) 4068c2ecf20Sopenharmony_ci{ 4078c2ecf20Sopenharmony_ci int i; 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(skl_err_map); i++) { 4108c2ecf20Sopenharmony_ci if (skl_err_map[i].reply == reply) 4118c2ecf20Sopenharmony_ci break; 4128c2ecf20Sopenharmony_ci } 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci if (i == ARRAY_SIZE(skl_err_map)) { 4158c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc FW reply: %d FW Error Code: %u\n", 4168c2ecf20Sopenharmony_ci reply, 4178c2ecf20Sopenharmony_ci ipc->dsp->fw_ops.get_fw_errcode(ipc->dsp)); 4188c2ecf20Sopenharmony_ci return -EINVAL; 4198c2ecf20Sopenharmony_ci } 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci if (skl_err_map[i].err < 0) 4228c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc FW reply: %s FW Error Code: %u\n", 4238c2ecf20Sopenharmony_ci skl_err_map[i].msg, 4248c2ecf20Sopenharmony_ci ipc->dsp->fw_ops.get_fw_errcode(ipc->dsp)); 4258c2ecf20Sopenharmony_ci else 4268c2ecf20Sopenharmony_ci dev_info(ipc->dev, "ipc FW reply: %s FW Error Code: %u\n", 4278c2ecf20Sopenharmony_ci skl_err_map[i].msg, 4288c2ecf20Sopenharmony_ci ipc->dsp->fw_ops.get_fw_errcode(ipc->dsp)); 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_ci return skl_err_map[i].err; 4318c2ecf20Sopenharmony_ci} 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_civoid skl_ipc_process_reply(struct sst_generic_ipc *ipc, 4348c2ecf20Sopenharmony_ci struct skl_ipc_header header) 4358c2ecf20Sopenharmony_ci{ 4368c2ecf20Sopenharmony_ci struct ipc_message *msg; 4378c2ecf20Sopenharmony_ci u32 reply = header.primary & IPC_GLB_REPLY_STATUS_MASK; 4388c2ecf20Sopenharmony_ci u64 *ipc_header = (u64 *)(&header); 4398c2ecf20Sopenharmony_ci struct skl_dev *skl = container_of(ipc, struct skl_dev, ipc); 4408c2ecf20Sopenharmony_ci unsigned long flags; 4418c2ecf20Sopenharmony_ci 4428c2ecf20Sopenharmony_ci spin_lock_irqsave(&ipc->dsp->spinlock, flags); 4438c2ecf20Sopenharmony_ci msg = skl_ipc_reply_get_msg(ipc, *ipc_header); 4448c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); 4458c2ecf20Sopenharmony_ci if (msg == NULL) { 4468c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "ipc: rx list is empty\n"); 4478c2ecf20Sopenharmony_ci return; 4488c2ecf20Sopenharmony_ci } 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci msg->rx.header = *ipc_header; 4518c2ecf20Sopenharmony_ci /* first process the header */ 4528c2ecf20Sopenharmony_ci if (reply == IPC_GLB_REPLY_SUCCESS) { 4538c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "ipc FW reply %x: success\n", header.primary); 4548c2ecf20Sopenharmony_ci /* copy the rx data from the mailbox */ 4558c2ecf20Sopenharmony_ci sst_dsp_inbox_read(ipc->dsp, msg->rx.data, msg->rx.size); 4568c2ecf20Sopenharmony_ci switch (IPC_GLB_NOTIFY_MSG_TYPE(header.primary)) { 4578c2ecf20Sopenharmony_ci case IPC_GLB_LOAD_MULTIPLE_MODS: 4588c2ecf20Sopenharmony_ci case IPC_GLB_LOAD_LIBRARY: 4598c2ecf20Sopenharmony_ci skl->mod_load_complete = true; 4608c2ecf20Sopenharmony_ci skl->mod_load_status = true; 4618c2ecf20Sopenharmony_ci wake_up(&skl->mod_load_wait); 4628c2ecf20Sopenharmony_ci break; 4638c2ecf20Sopenharmony_ci 4648c2ecf20Sopenharmony_ci default: 4658c2ecf20Sopenharmony_ci break; 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci } 4688c2ecf20Sopenharmony_ci } else { 4698c2ecf20Sopenharmony_ci msg->errno = skl_ipc_set_reply_error_code(ipc, reply); 4708c2ecf20Sopenharmony_ci switch (IPC_GLB_NOTIFY_MSG_TYPE(header.primary)) { 4718c2ecf20Sopenharmony_ci case IPC_GLB_LOAD_MULTIPLE_MODS: 4728c2ecf20Sopenharmony_ci case IPC_GLB_LOAD_LIBRARY: 4738c2ecf20Sopenharmony_ci skl->mod_load_complete = true; 4748c2ecf20Sopenharmony_ci skl->mod_load_status = false; 4758c2ecf20Sopenharmony_ci wake_up(&skl->mod_load_wait); 4768c2ecf20Sopenharmony_ci break; 4778c2ecf20Sopenharmony_ci 4788c2ecf20Sopenharmony_ci default: 4798c2ecf20Sopenharmony_ci break; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci } 4828c2ecf20Sopenharmony_ci } 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci spin_lock_irqsave(&ipc->dsp->spinlock, flags); 4858c2ecf20Sopenharmony_ci sst_ipc_tx_msg_reply_complete(ipc, msg); 4868c2ecf20Sopenharmony_ci spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); 4878c2ecf20Sopenharmony_ci} 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ciirqreturn_t skl_dsp_irq_thread_handler(int irq, void *context) 4908c2ecf20Sopenharmony_ci{ 4918c2ecf20Sopenharmony_ci struct sst_dsp *dsp = context; 4928c2ecf20Sopenharmony_ci struct skl_dev *skl = dsp->thread_context; 4938c2ecf20Sopenharmony_ci struct sst_generic_ipc *ipc = &skl->ipc; 4948c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 4958c2ecf20Sopenharmony_ci u32 hipcie, hipct, hipcte; 4968c2ecf20Sopenharmony_ci int ipc_irq = 0; 4978c2ecf20Sopenharmony_ci 4988c2ecf20Sopenharmony_ci if (dsp->intr_status & SKL_ADSPIS_CL_DMA) 4998c2ecf20Sopenharmony_ci skl_cldma_process_intr(dsp); 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci /* Here we handle IPC interrupts only */ 5028c2ecf20Sopenharmony_ci if (!(dsp->intr_status & SKL_ADSPIS_IPC)) 5038c2ecf20Sopenharmony_ci return IRQ_NONE; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci hipcie = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCIE); 5068c2ecf20Sopenharmony_ci hipct = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCT); 5078c2ecf20Sopenharmony_ci hipcte = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCTE); 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci /* reply message from DSP */ 5108c2ecf20Sopenharmony_ci if (hipcie & SKL_ADSP_REG_HIPCIE_DONE) { 5118c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits(dsp, SKL_ADSP_REG_HIPCCTL, 5128c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, 0); 5138c2ecf20Sopenharmony_ci 5148c2ecf20Sopenharmony_ci /* clear DONE bit - tell DSP we have completed the operation */ 5158c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits_forced(dsp, SKL_ADSP_REG_HIPCIE, 5168c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCIE_DONE, SKL_ADSP_REG_HIPCIE_DONE); 5178c2ecf20Sopenharmony_ci 5188c2ecf20Sopenharmony_ci ipc_irq = 1; 5198c2ecf20Sopenharmony_ci 5208c2ecf20Sopenharmony_ci /* unmask Done interrupt */ 5218c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits(dsp, SKL_ADSP_REG_HIPCCTL, 5228c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, SKL_ADSP_REG_HIPCCTL_DONE); 5238c2ecf20Sopenharmony_ci } 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci /* New message from DSP */ 5268c2ecf20Sopenharmony_ci if (hipct & SKL_ADSP_REG_HIPCT_BUSY) { 5278c2ecf20Sopenharmony_ci header.primary = hipct; 5288c2ecf20Sopenharmony_ci header.extension = hipcte; 5298c2ecf20Sopenharmony_ci dev_dbg(dsp->dev, "IPC irq: Firmware respond primary:%x\n", 5308c2ecf20Sopenharmony_ci header.primary); 5318c2ecf20Sopenharmony_ci dev_dbg(dsp->dev, "IPC irq: Firmware respond extension:%x\n", 5328c2ecf20Sopenharmony_ci header.extension); 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci if (IPC_GLB_NOTIFY_RSP_TYPE(header.primary)) { 5358c2ecf20Sopenharmony_ci /* Handle Immediate reply from DSP Core */ 5368c2ecf20Sopenharmony_ci skl_ipc_process_reply(ipc, header); 5378c2ecf20Sopenharmony_ci } else { 5388c2ecf20Sopenharmony_ci dev_dbg(dsp->dev, "IPC irq: Notification from firmware\n"); 5398c2ecf20Sopenharmony_ci skl_ipc_process_notification(ipc, header); 5408c2ecf20Sopenharmony_ci } 5418c2ecf20Sopenharmony_ci /* clear busy interrupt */ 5428c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits_forced(dsp, SKL_ADSP_REG_HIPCT, 5438c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCT_BUSY, SKL_ADSP_REG_HIPCT_BUSY); 5448c2ecf20Sopenharmony_ci ipc_irq = 1; 5458c2ecf20Sopenharmony_ci } 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci if (ipc_irq == 0) 5488c2ecf20Sopenharmony_ci return IRQ_NONE; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci skl_ipc_int_enable(dsp); 5518c2ecf20Sopenharmony_ci 5528c2ecf20Sopenharmony_ci /* continue to send any remaining messages... */ 5538c2ecf20Sopenharmony_ci schedule_work(&ipc->kwork); 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci return IRQ_HANDLED; 5568c2ecf20Sopenharmony_ci} 5578c2ecf20Sopenharmony_ci 5588c2ecf20Sopenharmony_civoid skl_ipc_int_enable(struct sst_dsp *ctx) 5598c2ecf20Sopenharmony_ci{ 5608c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_ADSPIC, 5618c2ecf20Sopenharmony_ci SKL_ADSPIC_IPC, SKL_ADSPIC_IPC); 5628c2ecf20Sopenharmony_ci} 5638c2ecf20Sopenharmony_ci 5648c2ecf20Sopenharmony_civoid skl_ipc_int_disable(struct sst_dsp *ctx) 5658c2ecf20Sopenharmony_ci{ 5668c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_ADSPIC, 5678c2ecf20Sopenharmony_ci SKL_ADSPIC_IPC, 0); 5688c2ecf20Sopenharmony_ci} 5698c2ecf20Sopenharmony_ci 5708c2ecf20Sopenharmony_civoid skl_ipc_op_int_enable(struct sst_dsp *ctx) 5718c2ecf20Sopenharmony_ci{ 5728c2ecf20Sopenharmony_ci /* enable IPC DONE interrupt */ 5738c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_HIPCCTL, 5748c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, SKL_ADSP_REG_HIPCCTL_DONE); 5758c2ecf20Sopenharmony_ci 5768c2ecf20Sopenharmony_ci /* Enable IPC BUSY interrupt */ 5778c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_HIPCCTL, 5788c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_BUSY, SKL_ADSP_REG_HIPCCTL_BUSY); 5798c2ecf20Sopenharmony_ci} 5808c2ecf20Sopenharmony_ci 5818c2ecf20Sopenharmony_civoid skl_ipc_op_int_disable(struct sst_dsp *ctx) 5828c2ecf20Sopenharmony_ci{ 5838c2ecf20Sopenharmony_ci /* disable IPC DONE interrupt */ 5848c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_HIPCCTL, 5858c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, 0); 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci /* Disable IPC BUSY interrupt */ 5888c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_HIPCCTL, 5898c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_BUSY, 0); 5908c2ecf20Sopenharmony_ci 5918c2ecf20Sopenharmony_ci} 5928c2ecf20Sopenharmony_ci 5938c2ecf20Sopenharmony_cibool skl_ipc_int_status(struct sst_dsp *ctx) 5948c2ecf20Sopenharmony_ci{ 5958c2ecf20Sopenharmony_ci return sst_dsp_shim_read_unlocked(ctx, 5968c2ecf20Sopenharmony_ci SKL_ADSP_REG_ADSPIS) & SKL_ADSPIS_IPC; 5978c2ecf20Sopenharmony_ci} 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_ciint skl_ipc_init(struct device *dev, struct skl_dev *skl) 6008c2ecf20Sopenharmony_ci{ 6018c2ecf20Sopenharmony_ci struct sst_generic_ipc *ipc; 6028c2ecf20Sopenharmony_ci int err; 6038c2ecf20Sopenharmony_ci 6048c2ecf20Sopenharmony_ci ipc = &skl->ipc; 6058c2ecf20Sopenharmony_ci ipc->dsp = skl->dsp; 6068c2ecf20Sopenharmony_ci ipc->dev = dev; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci ipc->tx_data_max_size = SKL_ADSP_W1_SZ; 6098c2ecf20Sopenharmony_ci ipc->rx_data_max_size = SKL_ADSP_W0_UP_SZ; 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci err = sst_ipc_init(ipc); 6128c2ecf20Sopenharmony_ci if (err) 6138c2ecf20Sopenharmony_ci return err; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci ipc->ops.tx_msg = skl_ipc_tx_msg; 6168c2ecf20Sopenharmony_ci ipc->ops.tx_data_copy = skl_ipc_tx_data_copy; 6178c2ecf20Sopenharmony_ci ipc->ops.is_dsp_busy = skl_ipc_is_dsp_busy; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci return 0; 6208c2ecf20Sopenharmony_ci} 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_civoid skl_ipc_free(struct sst_generic_ipc *ipc) 6238c2ecf20Sopenharmony_ci{ 6248c2ecf20Sopenharmony_ci /* Disable IPC DONE interrupt */ 6258c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits(ipc->dsp, SKL_ADSP_REG_HIPCCTL, 6268c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, 0); 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci /* Disable IPC BUSY interrupt */ 6298c2ecf20Sopenharmony_ci sst_dsp_shim_update_bits(ipc->dsp, SKL_ADSP_REG_HIPCCTL, 6308c2ecf20Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_BUSY, 0); 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci sst_ipc_fini(ipc); 6338c2ecf20Sopenharmony_ci} 6348c2ecf20Sopenharmony_ci 6358c2ecf20Sopenharmony_ciint skl_ipc_create_pipeline(struct sst_generic_ipc *ipc, 6368c2ecf20Sopenharmony_ci u16 ppl_mem_size, u8 ppl_type, u8 instance_id, u8 lp_mode) 6378c2ecf20Sopenharmony_ci{ 6388c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 6398c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 6408c2ecf20Sopenharmony_ci int ret; 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 6438c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 6448c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_CREATE_PPL); 6458c2ecf20Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 6468c2ecf20Sopenharmony_ci header.primary |= IPC_PPL_TYPE(ppl_type); 6478c2ecf20Sopenharmony_ci header.primary |= IPC_PPL_MEM_SIZE(ppl_mem_size); 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci header.extension = IPC_PPL_LP_MODE(lp_mode); 6508c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 6518c2ecf20Sopenharmony_ci 6528c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 6538c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 6548c2ecf20Sopenharmony_ci if (ret < 0) { 6558c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: create pipeline fail, err: %d\n", ret); 6568c2ecf20Sopenharmony_ci return ret; 6578c2ecf20Sopenharmony_ci } 6588c2ecf20Sopenharmony_ci 6598c2ecf20Sopenharmony_ci return ret; 6608c2ecf20Sopenharmony_ci} 6618c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_create_pipeline); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ciint skl_ipc_delete_pipeline(struct sst_generic_ipc *ipc, u8 instance_id) 6648c2ecf20Sopenharmony_ci{ 6658c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 6668c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 6678c2ecf20Sopenharmony_ci int ret; 6688c2ecf20Sopenharmony_ci 6698c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 6708c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 6718c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_DELETE_PPL); 6728c2ecf20Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 6738c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 6748c2ecf20Sopenharmony_ci 6758c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 6768c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 6778c2ecf20Sopenharmony_ci if (ret < 0) { 6788c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: delete pipeline failed, err %d\n", ret); 6798c2ecf20Sopenharmony_ci return ret; 6808c2ecf20Sopenharmony_ci } 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci return 0; 6838c2ecf20Sopenharmony_ci} 6848c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_delete_pipeline); 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ciint skl_ipc_set_pipeline_state(struct sst_generic_ipc *ipc, 6878c2ecf20Sopenharmony_ci u8 instance_id, enum skl_ipc_pipeline_state state) 6888c2ecf20Sopenharmony_ci{ 6898c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 6908c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 6918c2ecf20Sopenharmony_ci int ret; 6928c2ecf20Sopenharmony_ci 6938c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 6948c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 6958c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_SET_PPL_STATE); 6968c2ecf20Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 6978c2ecf20Sopenharmony_ci header.primary |= IPC_PPL_STATE(state); 6988c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 6998c2ecf20Sopenharmony_ci 7008c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 7018c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 7028c2ecf20Sopenharmony_ci if (ret < 0) { 7038c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: set pipeline state failed, err: %d\n", ret); 7048c2ecf20Sopenharmony_ci return ret; 7058c2ecf20Sopenharmony_ci } 7068c2ecf20Sopenharmony_ci return ret; 7078c2ecf20Sopenharmony_ci} 7088c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_pipeline_state); 7098c2ecf20Sopenharmony_ci 7108c2ecf20Sopenharmony_ciint 7118c2ecf20Sopenharmony_ciskl_ipc_save_pipeline(struct sst_generic_ipc *ipc, u8 instance_id, int dma_id) 7128c2ecf20Sopenharmony_ci{ 7138c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 7148c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 7158c2ecf20Sopenharmony_ci int ret; 7168c2ecf20Sopenharmony_ci 7178c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 7188c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 7198c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_SAVE_PPL); 7208c2ecf20Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci header.extension = IPC_DMA_ID(dma_id); 7238c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 7248c2ecf20Sopenharmony_ci 7258c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 7268c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 7278c2ecf20Sopenharmony_ci if (ret < 0) { 7288c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: save pipeline failed, err: %d\n", ret); 7298c2ecf20Sopenharmony_ci return ret; 7308c2ecf20Sopenharmony_ci } 7318c2ecf20Sopenharmony_ci 7328c2ecf20Sopenharmony_ci return ret; 7338c2ecf20Sopenharmony_ci} 7348c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_save_pipeline); 7358c2ecf20Sopenharmony_ci 7368c2ecf20Sopenharmony_ciint skl_ipc_restore_pipeline(struct sst_generic_ipc *ipc, u8 instance_id) 7378c2ecf20Sopenharmony_ci{ 7388c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 7398c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 7408c2ecf20Sopenharmony_ci int ret; 7418c2ecf20Sopenharmony_ci 7428c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 7438c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 7448c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_RESTORE_PPL); 7458c2ecf20Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 7468c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 7478c2ecf20Sopenharmony_ci 7488c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 7498c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 7508c2ecf20Sopenharmony_ci if (ret < 0) { 7518c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: restore pipeline failed, err: %d\n", ret); 7528c2ecf20Sopenharmony_ci return ret; 7538c2ecf20Sopenharmony_ci } 7548c2ecf20Sopenharmony_ci 7558c2ecf20Sopenharmony_ci return ret; 7568c2ecf20Sopenharmony_ci} 7578c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_restore_pipeline); 7588c2ecf20Sopenharmony_ci 7598c2ecf20Sopenharmony_ciint skl_ipc_set_dx(struct sst_generic_ipc *ipc, u8 instance_id, 7608c2ecf20Sopenharmony_ci u16 module_id, struct skl_ipc_dxstate_info *dx) 7618c2ecf20Sopenharmony_ci{ 7628c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 7638c2ecf20Sopenharmony_ci struct sst_ipc_message request; 7648c2ecf20Sopenharmony_ci int ret; 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 7678c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 7688c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_SET_DX); 7698c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(instance_id); 7708c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_ID(module_id); 7718c2ecf20Sopenharmony_ci 7728c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 7738c2ecf20Sopenharmony_ci request.data = dx; 7748c2ecf20Sopenharmony_ci request.size = sizeof(*dx); 7758c2ecf20Sopenharmony_ci 7768c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary =%x ext=%x\n", __func__, 7778c2ecf20Sopenharmony_ci header.primary, header.extension); 7788c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 7798c2ecf20Sopenharmony_ci if (ret < 0) { 7808c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: set dx failed, err %d\n", ret); 7818c2ecf20Sopenharmony_ci return ret; 7828c2ecf20Sopenharmony_ci } 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_ci return ret; 7858c2ecf20Sopenharmony_ci} 7868c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_dx); 7878c2ecf20Sopenharmony_ci 7888c2ecf20Sopenharmony_ciint skl_ipc_init_instance(struct sst_generic_ipc *ipc, 7898c2ecf20Sopenharmony_ci struct skl_ipc_init_instance_msg *msg, void *param_data) 7908c2ecf20Sopenharmony_ci{ 7918c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 7928c2ecf20Sopenharmony_ci struct sst_ipc_message request; 7938c2ecf20Sopenharmony_ci int ret; 7948c2ecf20Sopenharmony_ci u32 *buffer = (u32 *)param_data; 7958c2ecf20Sopenharmony_ci /* param_block_size must be in dwords */ 7968c2ecf20Sopenharmony_ci u16 param_block_size = msg->param_data_size / sizeof(u32); 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci print_hex_dump_debug("Param data:", DUMP_PREFIX_NONE, 7998c2ecf20Sopenharmony_ci 16, 4, buffer, param_block_size, false); 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 8028c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 8038c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_INIT_INSTANCE); 8048c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 8058c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci header.extension = IPC_CORE_ID(msg->core_id); 8088c2ecf20Sopenharmony_ci header.extension |= IPC_PPL_INSTANCE_ID(msg->ppl_instance_id); 8098c2ecf20Sopenharmony_ci header.extension |= IPC_PARAM_BLOCK_SIZE(param_block_size); 8108c2ecf20Sopenharmony_ci header.extension |= IPC_DOMAIN(msg->domain); 8118c2ecf20Sopenharmony_ci 8128c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 8138c2ecf20Sopenharmony_ci request.data = param_data; 8148c2ecf20Sopenharmony_ci request.size = msg->param_data_size; 8158c2ecf20Sopenharmony_ci 8168c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary =%x ext=%x\n", __func__, 8178c2ecf20Sopenharmony_ci header.primary, header.extension); 8188c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 8198c2ecf20Sopenharmony_ci 8208c2ecf20Sopenharmony_ci if (ret < 0) { 8218c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: init instance failed\n"); 8228c2ecf20Sopenharmony_ci return ret; 8238c2ecf20Sopenharmony_ci } 8248c2ecf20Sopenharmony_ci 8258c2ecf20Sopenharmony_ci return ret; 8268c2ecf20Sopenharmony_ci} 8278c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_init_instance); 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ciint skl_ipc_bind_unbind(struct sst_generic_ipc *ipc, 8308c2ecf20Sopenharmony_ci struct skl_ipc_bind_unbind_msg *msg) 8318c2ecf20Sopenharmony_ci{ 8328c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 8338c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 8348c2ecf20Sopenharmony_ci u8 bind_unbind = msg->bind ? IPC_MOD_BIND : IPC_MOD_UNBIND; 8358c2ecf20Sopenharmony_ci int ret; 8368c2ecf20Sopenharmony_ci 8378c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 8388c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 8398c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(bind_unbind); 8408c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 8418c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 8428c2ecf20Sopenharmony_ci 8438c2ecf20Sopenharmony_ci header.extension = IPC_DST_MOD_ID(msg->dst_module_id); 8448c2ecf20Sopenharmony_ci header.extension |= IPC_DST_MOD_INSTANCE_ID(msg->dst_instance_id); 8458c2ecf20Sopenharmony_ci header.extension |= IPC_DST_QUEUE(msg->dst_queue); 8468c2ecf20Sopenharmony_ci header.extension |= IPC_SRC_QUEUE(msg->src_queue); 8478c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 8488c2ecf20Sopenharmony_ci 8498c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s hdr=%x ext=%x\n", __func__, header.primary, 8508c2ecf20Sopenharmony_ci header.extension); 8518c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 8528c2ecf20Sopenharmony_ci if (ret < 0) { 8538c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: bind/unbind failed\n"); 8548c2ecf20Sopenharmony_ci return ret; 8558c2ecf20Sopenharmony_ci } 8568c2ecf20Sopenharmony_ci 8578c2ecf20Sopenharmony_ci return ret; 8588c2ecf20Sopenharmony_ci} 8598c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_bind_unbind); 8608c2ecf20Sopenharmony_ci 8618c2ecf20Sopenharmony_ci/* 8628c2ecf20Sopenharmony_ci * In order to load a module we need to send IPC to initiate that. DMA will 8638c2ecf20Sopenharmony_ci * performed to load the module memory. The FW supports multiple module load 8648c2ecf20Sopenharmony_ci * at single shot, so we can send IPC with N modules represented by 8658c2ecf20Sopenharmony_ci * module_cnt 8668c2ecf20Sopenharmony_ci */ 8678c2ecf20Sopenharmony_ciint skl_ipc_load_modules(struct sst_generic_ipc *ipc, 8688c2ecf20Sopenharmony_ci u8 module_cnt, void *data) 8698c2ecf20Sopenharmony_ci{ 8708c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 8718c2ecf20Sopenharmony_ci struct sst_ipc_message request; 8728c2ecf20Sopenharmony_ci int ret; 8738c2ecf20Sopenharmony_ci 8748c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 8758c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 8768c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_LOAD_MULTIPLE_MODS); 8778c2ecf20Sopenharmony_ci header.primary |= IPC_LOAD_MODULE_CNT(module_cnt); 8788c2ecf20Sopenharmony_ci 8798c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 8808c2ecf20Sopenharmony_ci request.data = data; 8818c2ecf20Sopenharmony_ci request.size = sizeof(u16) * module_cnt; 8828c2ecf20Sopenharmony_ci 8838c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_nowait(ipc, request); 8848c2ecf20Sopenharmony_ci if (ret < 0) 8858c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: load modules failed :%d\n", ret); 8868c2ecf20Sopenharmony_ci 8878c2ecf20Sopenharmony_ci return ret; 8888c2ecf20Sopenharmony_ci} 8898c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_load_modules); 8908c2ecf20Sopenharmony_ci 8918c2ecf20Sopenharmony_ciint skl_ipc_unload_modules(struct sst_generic_ipc *ipc, u8 module_cnt, 8928c2ecf20Sopenharmony_ci void *data) 8938c2ecf20Sopenharmony_ci{ 8948c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 8958c2ecf20Sopenharmony_ci struct sst_ipc_message request; 8968c2ecf20Sopenharmony_ci int ret; 8978c2ecf20Sopenharmony_ci 8988c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 8998c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 9008c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_UNLOAD_MULTIPLE_MODS); 9018c2ecf20Sopenharmony_ci header.primary |= IPC_LOAD_MODULE_CNT(module_cnt); 9028c2ecf20Sopenharmony_ci 9038c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 9048c2ecf20Sopenharmony_ci request.data = data; 9058c2ecf20Sopenharmony_ci request.size = sizeof(u16) * module_cnt; 9068c2ecf20Sopenharmony_ci 9078c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 9088c2ecf20Sopenharmony_ci if (ret < 0) 9098c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: unload modules failed :%d\n", ret); 9108c2ecf20Sopenharmony_ci 9118c2ecf20Sopenharmony_ci return ret; 9128c2ecf20Sopenharmony_ci} 9138c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_unload_modules); 9148c2ecf20Sopenharmony_ci 9158c2ecf20Sopenharmony_ciint skl_ipc_set_large_config(struct sst_generic_ipc *ipc, 9168c2ecf20Sopenharmony_ci struct skl_ipc_large_config_msg *msg, u32 *param) 9178c2ecf20Sopenharmony_ci{ 9188c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 9198c2ecf20Sopenharmony_ci struct sst_ipc_message request; 9208c2ecf20Sopenharmony_ci int ret = 0; 9218c2ecf20Sopenharmony_ci size_t sz_remaining, tx_size, data_offset; 9228c2ecf20Sopenharmony_ci 9238c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 9248c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 9258c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_LARGE_CONFIG_SET); 9268c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 9278c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 9288c2ecf20Sopenharmony_ci 9298c2ecf20Sopenharmony_ci header.extension = IPC_DATA_OFFSET_SZ(msg->param_data_size); 9308c2ecf20Sopenharmony_ci header.extension |= IPC_LARGE_PARAM_ID(msg->large_param_id); 9318c2ecf20Sopenharmony_ci header.extension |= IPC_FINAL_BLOCK(0); 9328c2ecf20Sopenharmony_ci header.extension |= IPC_INITIAL_BLOCK(1); 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci sz_remaining = msg->param_data_size; 9358c2ecf20Sopenharmony_ci data_offset = 0; 9368c2ecf20Sopenharmony_ci while (sz_remaining != 0) { 9378c2ecf20Sopenharmony_ci tx_size = sz_remaining > SKL_ADSP_W1_SZ 9388c2ecf20Sopenharmony_ci ? SKL_ADSP_W1_SZ : sz_remaining; 9398c2ecf20Sopenharmony_ci if (tx_size == sz_remaining) 9408c2ecf20Sopenharmony_ci header.extension |= IPC_FINAL_BLOCK(1); 9418c2ecf20Sopenharmony_ci 9428c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary=%#x ext=%#x\n", __func__, 9438c2ecf20Sopenharmony_ci header.primary, header.extension); 9448c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "transmitting offset: %#x, size: %#x\n", 9458c2ecf20Sopenharmony_ci (unsigned)data_offset, (unsigned)tx_size); 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 9488c2ecf20Sopenharmony_ci request.data = ((char *)param) + data_offset; 9498c2ecf20Sopenharmony_ci request.size = tx_size; 9508c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 9518c2ecf20Sopenharmony_ci if (ret < 0) { 9528c2ecf20Sopenharmony_ci dev_err(ipc->dev, 9538c2ecf20Sopenharmony_ci "ipc: set large config fail, err: %d\n", ret); 9548c2ecf20Sopenharmony_ci return ret; 9558c2ecf20Sopenharmony_ci } 9568c2ecf20Sopenharmony_ci sz_remaining -= tx_size; 9578c2ecf20Sopenharmony_ci data_offset = msg->param_data_size - sz_remaining; 9588c2ecf20Sopenharmony_ci 9598c2ecf20Sopenharmony_ci /* clear the fields */ 9608c2ecf20Sopenharmony_ci header.extension &= IPC_INITIAL_BLOCK_CLEAR; 9618c2ecf20Sopenharmony_ci header.extension &= IPC_DATA_OFFSET_SZ_CLEAR; 9628c2ecf20Sopenharmony_ci /* fill the fields */ 9638c2ecf20Sopenharmony_ci header.extension |= IPC_INITIAL_BLOCK(0); 9648c2ecf20Sopenharmony_ci header.extension |= IPC_DATA_OFFSET_SZ(data_offset); 9658c2ecf20Sopenharmony_ci } 9668c2ecf20Sopenharmony_ci 9678c2ecf20Sopenharmony_ci return ret; 9688c2ecf20Sopenharmony_ci} 9698c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_large_config); 9708c2ecf20Sopenharmony_ci 9718c2ecf20Sopenharmony_ciint skl_ipc_get_large_config(struct sst_generic_ipc *ipc, 9728c2ecf20Sopenharmony_ci struct skl_ipc_large_config_msg *msg, 9738c2ecf20Sopenharmony_ci u32 **payload, size_t *bytes) 9748c2ecf20Sopenharmony_ci{ 9758c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 9768c2ecf20Sopenharmony_ci struct sst_ipc_message request, reply = {0}; 9778c2ecf20Sopenharmony_ci unsigned int *buf; 9788c2ecf20Sopenharmony_ci int ret; 9798c2ecf20Sopenharmony_ci 9808c2ecf20Sopenharmony_ci reply.data = kzalloc(SKL_ADSP_W1_SZ, GFP_KERNEL); 9818c2ecf20Sopenharmony_ci if (!reply.data) 9828c2ecf20Sopenharmony_ci return -ENOMEM; 9838c2ecf20Sopenharmony_ci 9848c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 9858c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 9868c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_LARGE_CONFIG_GET); 9878c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 9888c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 9898c2ecf20Sopenharmony_ci 9908c2ecf20Sopenharmony_ci header.extension = IPC_DATA_OFFSET_SZ(msg->param_data_size); 9918c2ecf20Sopenharmony_ci header.extension |= IPC_LARGE_PARAM_ID(msg->large_param_id); 9928c2ecf20Sopenharmony_ci header.extension |= IPC_FINAL_BLOCK(1); 9938c2ecf20Sopenharmony_ci header.extension |= IPC_INITIAL_BLOCK(1); 9948c2ecf20Sopenharmony_ci 9958c2ecf20Sopenharmony_ci request.header = *(u64 *)&header; 9968c2ecf20Sopenharmony_ci request.data = *payload; 9978c2ecf20Sopenharmony_ci request.size = *bytes; 9988c2ecf20Sopenharmony_ci reply.size = SKL_ADSP_W1_SZ; 9998c2ecf20Sopenharmony_ci 10008c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, &reply); 10018c2ecf20Sopenharmony_ci if (ret < 0) 10028c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: get large config fail, err: %d\n", ret); 10038c2ecf20Sopenharmony_ci 10048c2ecf20Sopenharmony_ci reply.size = (reply.header >> 32) & IPC_DATA_OFFSET_SZ_MASK; 10058c2ecf20Sopenharmony_ci buf = krealloc(reply.data, reply.size, GFP_KERNEL); 10068c2ecf20Sopenharmony_ci if (!buf) { 10078c2ecf20Sopenharmony_ci kfree(reply.data); 10088c2ecf20Sopenharmony_ci return -ENOMEM; 10098c2ecf20Sopenharmony_ci } 10108c2ecf20Sopenharmony_ci *payload = buf; 10118c2ecf20Sopenharmony_ci *bytes = reply.size; 10128c2ecf20Sopenharmony_ci 10138c2ecf20Sopenharmony_ci return ret; 10148c2ecf20Sopenharmony_ci} 10158c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_get_large_config); 10168c2ecf20Sopenharmony_ci 10178c2ecf20Sopenharmony_ciint skl_sst_ipc_load_library(struct sst_generic_ipc *ipc, 10188c2ecf20Sopenharmony_ci u8 dma_id, u8 table_id, bool wait) 10198c2ecf20Sopenharmony_ci{ 10208c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 10218c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 10228c2ecf20Sopenharmony_ci int ret = 0; 10238c2ecf20Sopenharmony_ci 10248c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 10258c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 10268c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_LOAD_LIBRARY); 10278c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(table_id); 10288c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_ID(dma_id); 10298c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 10308c2ecf20Sopenharmony_ci 10318c2ecf20Sopenharmony_ci if (wait) 10328c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 10338c2ecf20Sopenharmony_ci else 10348c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_nowait(ipc, request); 10358c2ecf20Sopenharmony_ci 10368c2ecf20Sopenharmony_ci if (ret < 0) 10378c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: load lib failed\n"); 10388c2ecf20Sopenharmony_ci 10398c2ecf20Sopenharmony_ci return ret; 10408c2ecf20Sopenharmony_ci} 10418c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_sst_ipc_load_library); 10428c2ecf20Sopenharmony_ci 10438c2ecf20Sopenharmony_ciint skl_ipc_set_d0ix(struct sst_generic_ipc *ipc, struct skl_ipc_d0ix_msg *msg) 10448c2ecf20Sopenharmony_ci{ 10458c2ecf20Sopenharmony_ci struct skl_ipc_header header = {0}; 10468c2ecf20Sopenharmony_ci struct sst_ipc_message request = {0}; 10478c2ecf20Sopenharmony_ci int ret; 10488c2ecf20Sopenharmony_ci 10498c2ecf20Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 10508c2ecf20Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 10518c2ecf20Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_SET_D0IX); 10528c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 10538c2ecf20Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 10548c2ecf20Sopenharmony_ci 10558c2ecf20Sopenharmony_ci header.extension = IPC_D0IX_WAKE(msg->wake); 10568c2ecf20Sopenharmony_ci header.extension |= IPC_D0IX_STREAMING(msg->streaming); 10578c2ecf20Sopenharmony_ci request.header = *(u64 *)(&header); 10588c2ecf20Sopenharmony_ci 10598c2ecf20Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary=%x ext=%x\n", __func__, 10608c2ecf20Sopenharmony_ci header.primary, header.extension); 10618c2ecf20Sopenharmony_ci 10628c2ecf20Sopenharmony_ci /* 10638c2ecf20Sopenharmony_ci * Use the nopm IPC here as we dont want it checking for D0iX 10648c2ecf20Sopenharmony_ci */ 10658c2ecf20Sopenharmony_ci ret = sst_ipc_tx_message_nopm(ipc, request, NULL); 10668c2ecf20Sopenharmony_ci if (ret < 0) 10678c2ecf20Sopenharmony_ci dev_err(ipc->dev, "ipc: set d0ix failed, err %d\n", ret); 10688c2ecf20Sopenharmony_ci 10698c2ecf20Sopenharmony_ci return ret; 10708c2ecf20Sopenharmony_ci} 10718c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_d0ix); 1072