162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * skl-sst-ipc.c - Intel skl IPC Support 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2014-15, Intel Corporation. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci#include <linux/device.h> 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include "../common/sst-dsp.h" 1062306a36Sopenharmony_ci#include "../common/sst-dsp-priv.h" 1162306a36Sopenharmony_ci#include "skl.h" 1262306a36Sopenharmony_ci#include "skl-sst-dsp.h" 1362306a36Sopenharmony_ci#include "skl-sst-ipc.h" 1462306a36Sopenharmony_ci#include "sound/hdaudio_ext.h" 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define IPC_IXC_STATUS_BITS 24 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* Global Message - Generic */ 2062306a36Sopenharmony_ci#define IPC_GLB_TYPE_SHIFT 24 2162306a36Sopenharmony_ci#define IPC_GLB_TYPE_MASK (0xf << IPC_GLB_TYPE_SHIFT) 2262306a36Sopenharmony_ci#define IPC_GLB_TYPE(x) ((x) << IPC_GLB_TYPE_SHIFT) 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci/* Global Message - Reply */ 2562306a36Sopenharmony_ci#define IPC_GLB_REPLY_STATUS_SHIFT 24 2662306a36Sopenharmony_ci#define IPC_GLB_REPLY_STATUS_MASK ((0x1 << IPC_GLB_REPLY_STATUS_SHIFT) - 1) 2762306a36Sopenharmony_ci#define IPC_GLB_REPLY_STATUS(x) ((x) << IPC_GLB_REPLY_STATUS_SHIFT) 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci#define IPC_GLB_REPLY_TYPE_SHIFT 29 3062306a36Sopenharmony_ci#define IPC_GLB_REPLY_TYPE_MASK 0x1F 3162306a36Sopenharmony_ci#define IPC_GLB_REPLY_TYPE(x) (((x) >> IPC_GLB_REPLY_TYPE_SHIFT) \ 3262306a36Sopenharmony_ci & IPC_GLB_RPLY_TYPE_MASK) 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define IPC_TIMEOUT_MSECS 3000 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci#define IPC_EMPTY_LIST_SIZE 8 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#define IPC_MSG_TARGET_SHIFT 30 3962306a36Sopenharmony_ci#define IPC_MSG_TARGET_MASK 0x1 4062306a36Sopenharmony_ci#define IPC_MSG_TARGET(x) (((x) & IPC_MSG_TARGET_MASK) \ 4162306a36Sopenharmony_ci << IPC_MSG_TARGET_SHIFT) 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define IPC_MSG_DIR_SHIFT 29 4462306a36Sopenharmony_ci#define IPC_MSG_DIR_MASK 0x1 4562306a36Sopenharmony_ci#define IPC_MSG_DIR(x) (((x) & IPC_MSG_DIR_MASK) \ 4662306a36Sopenharmony_ci << IPC_MSG_DIR_SHIFT) 4762306a36Sopenharmony_ci/* Global Notification Message */ 4862306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_TYPE_SHIFT 16 4962306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_TYPE_MASK 0xFF 5062306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_TYPE(x) (((x) >> IPC_GLB_NOTIFY_TYPE_SHIFT) \ 5162306a36Sopenharmony_ci & IPC_GLB_NOTIFY_TYPE_MASK) 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_MSG_TYPE_SHIFT 24 5462306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_MSG_TYPE_MASK 0x1F 5562306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_MSG_TYPE(x) (((x) >> IPC_GLB_NOTIFY_MSG_TYPE_SHIFT) \ 5662306a36Sopenharmony_ci & IPC_GLB_NOTIFY_MSG_TYPE_MASK) 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_RSP_SHIFT 29 5962306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_RSP_MASK 0x1 6062306a36Sopenharmony_ci#define IPC_GLB_NOTIFY_RSP_TYPE(x) (((x) >> IPC_GLB_NOTIFY_RSP_SHIFT) \ 6162306a36Sopenharmony_ci & IPC_GLB_NOTIFY_RSP_MASK) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/* Pipeline operations */ 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* Create pipeline message */ 6662306a36Sopenharmony_ci#define IPC_PPL_MEM_SIZE_SHIFT 0 6762306a36Sopenharmony_ci#define IPC_PPL_MEM_SIZE_MASK 0x7FF 6862306a36Sopenharmony_ci#define IPC_PPL_MEM_SIZE(x) (((x) & IPC_PPL_MEM_SIZE_MASK) \ 6962306a36Sopenharmony_ci << IPC_PPL_MEM_SIZE_SHIFT) 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#define IPC_PPL_TYPE_SHIFT 11 7262306a36Sopenharmony_ci#define IPC_PPL_TYPE_MASK 0x1F 7362306a36Sopenharmony_ci#define IPC_PPL_TYPE(x) (((x) & IPC_PPL_TYPE_MASK) \ 7462306a36Sopenharmony_ci << IPC_PPL_TYPE_SHIFT) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#define IPC_INSTANCE_ID_SHIFT 16 7762306a36Sopenharmony_ci#define IPC_INSTANCE_ID_MASK 0xFF 7862306a36Sopenharmony_ci#define IPC_INSTANCE_ID(x) (((x) & IPC_INSTANCE_ID_MASK) \ 7962306a36Sopenharmony_ci << IPC_INSTANCE_ID_SHIFT) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci#define IPC_PPL_LP_MODE_SHIFT 0 8262306a36Sopenharmony_ci#define IPC_PPL_LP_MODE_MASK 0x1 8362306a36Sopenharmony_ci#define IPC_PPL_LP_MODE(x) (((x) & IPC_PPL_LP_MODE_MASK) \ 8462306a36Sopenharmony_ci << IPC_PPL_LP_MODE_SHIFT) 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci/* Set pipeline state message */ 8762306a36Sopenharmony_ci#define IPC_PPL_STATE_SHIFT 0 8862306a36Sopenharmony_ci#define IPC_PPL_STATE_MASK 0x1F 8962306a36Sopenharmony_ci#define IPC_PPL_STATE(x) (((x) & IPC_PPL_STATE_MASK) \ 9062306a36Sopenharmony_ci << IPC_PPL_STATE_SHIFT) 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/* Module operations primary register */ 9362306a36Sopenharmony_ci#define IPC_MOD_ID_SHIFT 0 9462306a36Sopenharmony_ci#define IPC_MOD_ID_MASK 0xFFFF 9562306a36Sopenharmony_ci#define IPC_MOD_ID(x) (((x) & IPC_MOD_ID_MASK) \ 9662306a36Sopenharmony_ci << IPC_MOD_ID_SHIFT) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci#define IPC_MOD_INSTANCE_ID_SHIFT 16 9962306a36Sopenharmony_ci#define IPC_MOD_INSTANCE_ID_MASK 0xFF 10062306a36Sopenharmony_ci#define IPC_MOD_INSTANCE_ID(x) (((x) & IPC_MOD_INSTANCE_ID_MASK) \ 10162306a36Sopenharmony_ci << IPC_MOD_INSTANCE_ID_SHIFT) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci/* Init instance message extension register */ 10462306a36Sopenharmony_ci#define IPC_PARAM_BLOCK_SIZE_SHIFT 0 10562306a36Sopenharmony_ci#define IPC_PARAM_BLOCK_SIZE_MASK 0xFFFF 10662306a36Sopenharmony_ci#define IPC_PARAM_BLOCK_SIZE(x) (((x) & IPC_PARAM_BLOCK_SIZE_MASK) \ 10762306a36Sopenharmony_ci << IPC_PARAM_BLOCK_SIZE_SHIFT) 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci#define IPC_PPL_INSTANCE_ID_SHIFT 16 11062306a36Sopenharmony_ci#define IPC_PPL_INSTANCE_ID_MASK 0xFF 11162306a36Sopenharmony_ci#define IPC_PPL_INSTANCE_ID(x) (((x) & IPC_PPL_INSTANCE_ID_MASK) \ 11262306a36Sopenharmony_ci << IPC_PPL_INSTANCE_ID_SHIFT) 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci#define IPC_CORE_ID_SHIFT 24 11562306a36Sopenharmony_ci#define IPC_CORE_ID_MASK 0x1F 11662306a36Sopenharmony_ci#define IPC_CORE_ID(x) (((x) & IPC_CORE_ID_MASK) \ 11762306a36Sopenharmony_ci << IPC_CORE_ID_SHIFT) 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci#define IPC_DOMAIN_SHIFT 28 12062306a36Sopenharmony_ci#define IPC_DOMAIN_MASK 0x1 12162306a36Sopenharmony_ci#define IPC_DOMAIN(x) (((x) & IPC_DOMAIN_MASK) \ 12262306a36Sopenharmony_ci << IPC_DOMAIN_SHIFT) 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci/* Bind/Unbind message extension register */ 12562306a36Sopenharmony_ci#define IPC_DST_MOD_ID_SHIFT 0 12662306a36Sopenharmony_ci#define IPC_DST_MOD_ID(x) (((x) & IPC_MOD_ID_MASK) \ 12762306a36Sopenharmony_ci << IPC_DST_MOD_ID_SHIFT) 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci#define IPC_DST_MOD_INSTANCE_ID_SHIFT 16 13062306a36Sopenharmony_ci#define IPC_DST_MOD_INSTANCE_ID(x) (((x) & IPC_MOD_INSTANCE_ID_MASK) \ 13162306a36Sopenharmony_ci << IPC_DST_MOD_INSTANCE_ID_SHIFT) 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci#define IPC_DST_QUEUE_SHIFT 24 13462306a36Sopenharmony_ci#define IPC_DST_QUEUE_MASK 0x7 13562306a36Sopenharmony_ci#define IPC_DST_QUEUE(x) (((x) & IPC_DST_QUEUE_MASK) \ 13662306a36Sopenharmony_ci << IPC_DST_QUEUE_SHIFT) 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci#define IPC_SRC_QUEUE_SHIFT 27 13962306a36Sopenharmony_ci#define IPC_SRC_QUEUE_MASK 0x7 14062306a36Sopenharmony_ci#define IPC_SRC_QUEUE(x) (((x) & IPC_SRC_QUEUE_MASK) \ 14162306a36Sopenharmony_ci << IPC_SRC_QUEUE_SHIFT) 14262306a36Sopenharmony_ci/* Load Module count */ 14362306a36Sopenharmony_ci#define IPC_LOAD_MODULE_SHIFT 0 14462306a36Sopenharmony_ci#define IPC_LOAD_MODULE_MASK 0xFF 14562306a36Sopenharmony_ci#define IPC_LOAD_MODULE_CNT(x) (((x) & IPC_LOAD_MODULE_MASK) \ 14662306a36Sopenharmony_ci << IPC_LOAD_MODULE_SHIFT) 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ci/* Save pipeline messgae extension register */ 14962306a36Sopenharmony_ci#define IPC_DMA_ID_SHIFT 0 15062306a36Sopenharmony_ci#define IPC_DMA_ID_MASK 0x1F 15162306a36Sopenharmony_ci#define IPC_DMA_ID(x) (((x) & IPC_DMA_ID_MASK) \ 15262306a36Sopenharmony_ci << IPC_DMA_ID_SHIFT) 15362306a36Sopenharmony_ci/* Large Config message extension register */ 15462306a36Sopenharmony_ci#define IPC_DATA_OFFSET_SZ_SHIFT 0 15562306a36Sopenharmony_ci#define IPC_DATA_OFFSET_SZ_MASK 0xFFFFF 15662306a36Sopenharmony_ci#define IPC_DATA_OFFSET_SZ(x) (((x) & IPC_DATA_OFFSET_SZ_MASK) \ 15762306a36Sopenharmony_ci << IPC_DATA_OFFSET_SZ_SHIFT) 15862306a36Sopenharmony_ci#define IPC_DATA_OFFSET_SZ_CLEAR ~(IPC_DATA_OFFSET_SZ_MASK \ 15962306a36Sopenharmony_ci << IPC_DATA_OFFSET_SZ_SHIFT) 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci#define IPC_LARGE_PARAM_ID_SHIFT 20 16262306a36Sopenharmony_ci#define IPC_LARGE_PARAM_ID_MASK 0xFF 16362306a36Sopenharmony_ci#define IPC_LARGE_PARAM_ID(x) (((x) & IPC_LARGE_PARAM_ID_MASK) \ 16462306a36Sopenharmony_ci << IPC_LARGE_PARAM_ID_SHIFT) 16562306a36Sopenharmony_ci 16662306a36Sopenharmony_ci#define IPC_FINAL_BLOCK_SHIFT 28 16762306a36Sopenharmony_ci#define IPC_FINAL_BLOCK_MASK 0x1 16862306a36Sopenharmony_ci#define IPC_FINAL_BLOCK(x) (((x) & IPC_FINAL_BLOCK_MASK) \ 16962306a36Sopenharmony_ci << IPC_FINAL_BLOCK_SHIFT) 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci#define IPC_INITIAL_BLOCK_SHIFT 29 17262306a36Sopenharmony_ci#define IPC_INITIAL_BLOCK_MASK 0x1 17362306a36Sopenharmony_ci#define IPC_INITIAL_BLOCK(x) (((x) & IPC_INITIAL_BLOCK_MASK) \ 17462306a36Sopenharmony_ci << IPC_INITIAL_BLOCK_SHIFT) 17562306a36Sopenharmony_ci#define IPC_INITIAL_BLOCK_CLEAR ~(IPC_INITIAL_BLOCK_MASK \ 17662306a36Sopenharmony_ci << IPC_INITIAL_BLOCK_SHIFT) 17762306a36Sopenharmony_ci/* Set D0ix IPC extension register */ 17862306a36Sopenharmony_ci#define IPC_D0IX_WAKE_SHIFT 0 17962306a36Sopenharmony_ci#define IPC_D0IX_WAKE_MASK 0x1 18062306a36Sopenharmony_ci#define IPC_D0IX_WAKE(x) (((x) & IPC_D0IX_WAKE_MASK) \ 18162306a36Sopenharmony_ci << IPC_D0IX_WAKE_SHIFT) 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci#define IPC_D0IX_STREAMING_SHIFT 1 18462306a36Sopenharmony_ci#define IPC_D0IX_STREAMING_MASK 0x1 18562306a36Sopenharmony_ci#define IPC_D0IX_STREAMING(x) (((x) & IPC_D0IX_STREAMING_MASK) \ 18662306a36Sopenharmony_ci << IPC_D0IX_STREAMING_SHIFT) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_cienum skl_ipc_msg_target { 19062306a36Sopenharmony_ci IPC_FW_GEN_MSG = 0, 19162306a36Sopenharmony_ci IPC_MOD_MSG = 1 19262306a36Sopenharmony_ci}; 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_cienum skl_ipc_msg_direction { 19562306a36Sopenharmony_ci IPC_MSG_REQUEST = 0, 19662306a36Sopenharmony_ci IPC_MSG_REPLY = 1 19762306a36Sopenharmony_ci}; 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci/* Global Message Types */ 20062306a36Sopenharmony_cienum skl_ipc_glb_type { 20162306a36Sopenharmony_ci IPC_GLB_GET_FW_VERSION = 0, /* Retrieves firmware version */ 20262306a36Sopenharmony_ci IPC_GLB_LOAD_MULTIPLE_MODS = 15, 20362306a36Sopenharmony_ci IPC_GLB_UNLOAD_MULTIPLE_MODS = 16, 20462306a36Sopenharmony_ci IPC_GLB_CREATE_PPL = 17, 20562306a36Sopenharmony_ci IPC_GLB_DELETE_PPL = 18, 20662306a36Sopenharmony_ci IPC_GLB_SET_PPL_STATE = 19, 20762306a36Sopenharmony_ci IPC_GLB_GET_PPL_STATE = 20, 20862306a36Sopenharmony_ci IPC_GLB_GET_PPL_CONTEXT_SIZE = 21, 20962306a36Sopenharmony_ci IPC_GLB_SAVE_PPL = 22, 21062306a36Sopenharmony_ci IPC_GLB_RESTORE_PPL = 23, 21162306a36Sopenharmony_ci IPC_GLB_LOAD_LIBRARY = 24, 21262306a36Sopenharmony_ci IPC_GLB_NOTIFY = 26, 21362306a36Sopenharmony_ci IPC_GLB_MAX_IPC_MSG_NUMBER = 31 /* Maximum message number */ 21462306a36Sopenharmony_ci}; 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cienum skl_ipc_glb_reply { 21762306a36Sopenharmony_ci IPC_GLB_REPLY_SUCCESS = 0, 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci IPC_GLB_REPLY_UNKNOWN_MSG_TYPE = 1, 22062306a36Sopenharmony_ci IPC_GLB_REPLY_ERROR_INVALID_PARAM = 2, 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci IPC_GLB_REPLY_BUSY = 3, 22362306a36Sopenharmony_ci IPC_GLB_REPLY_PENDING = 4, 22462306a36Sopenharmony_ci IPC_GLB_REPLY_FAILURE = 5, 22562306a36Sopenharmony_ci IPC_GLB_REPLY_INVALID_REQUEST = 6, 22662306a36Sopenharmony_ci 22762306a36Sopenharmony_ci IPC_GLB_REPLY_OUT_OF_MEMORY = 7, 22862306a36Sopenharmony_ci IPC_GLB_REPLY_OUT_OF_MIPS = 8, 22962306a36Sopenharmony_ci 23062306a36Sopenharmony_ci IPC_GLB_REPLY_INVALID_RESOURCE_ID = 9, 23162306a36Sopenharmony_ci IPC_GLB_REPLY_INVALID_RESOURCE_STATE = 10, 23262306a36Sopenharmony_ci 23362306a36Sopenharmony_ci IPC_GLB_REPLY_MOD_MGMT_ERROR = 100, 23462306a36Sopenharmony_ci IPC_GLB_REPLY_MOD_LOAD_CL_FAILED = 101, 23562306a36Sopenharmony_ci IPC_GLB_REPLY_MOD_LOAD_INVALID_HASH = 102, 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci IPC_GLB_REPLY_MOD_UNLOAD_INST_EXIST = 103, 23862306a36Sopenharmony_ci IPC_GLB_REPLY_MOD_NOT_INITIALIZED = 104, 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci IPC_GLB_REPLY_INVALID_CONFIG_PARAM_ID = 120, 24162306a36Sopenharmony_ci IPC_GLB_REPLY_INVALID_CONFIG_DATA_LEN = 121, 24262306a36Sopenharmony_ci IPC_GLB_REPLY_GATEWAY_NOT_INITIALIZED = 140, 24362306a36Sopenharmony_ci IPC_GLB_REPLY_GATEWAY_NOT_EXIST = 141, 24462306a36Sopenharmony_ci IPC_GLB_REPLY_SCLK_ALREADY_RUNNING = 150, 24562306a36Sopenharmony_ci IPC_GLB_REPLY_MCLK_ALREADY_RUNNING = 151, 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci IPC_GLB_REPLY_PPL_NOT_INITIALIZED = 160, 24862306a36Sopenharmony_ci IPC_GLB_REPLY_PPL_NOT_EXIST = 161, 24962306a36Sopenharmony_ci IPC_GLB_REPLY_PPL_SAVE_FAILED = 162, 25062306a36Sopenharmony_ci IPC_GLB_REPLY_PPL_RESTORE_FAILED = 163, 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci IPC_MAX_STATUS = ((1<<IPC_IXC_STATUS_BITS)-1) 25362306a36Sopenharmony_ci}; 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_cienum skl_ipc_notification_type { 25662306a36Sopenharmony_ci IPC_GLB_NOTIFY_GLITCH = 0, 25762306a36Sopenharmony_ci IPC_GLB_NOTIFY_OVERRUN = 1, 25862306a36Sopenharmony_ci IPC_GLB_NOTIFY_UNDERRUN = 2, 25962306a36Sopenharmony_ci IPC_GLB_NOTIFY_END_STREAM = 3, 26062306a36Sopenharmony_ci IPC_GLB_NOTIFY_PHRASE_DETECTED = 4, 26162306a36Sopenharmony_ci IPC_GLB_NOTIFY_RESOURCE_EVENT = 5, 26262306a36Sopenharmony_ci IPC_GLB_NOTIFY_LOG_BUFFER_STATUS = 6, 26362306a36Sopenharmony_ci IPC_GLB_NOTIFY_TIMESTAMP_CAPTURED = 7, 26462306a36Sopenharmony_ci IPC_GLB_NOTIFY_FW_READY = 8 26562306a36Sopenharmony_ci}; 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci/* Module Message Types */ 26862306a36Sopenharmony_cienum skl_ipc_module_msg { 26962306a36Sopenharmony_ci IPC_MOD_INIT_INSTANCE = 0, 27062306a36Sopenharmony_ci IPC_MOD_CONFIG_GET = 1, 27162306a36Sopenharmony_ci IPC_MOD_CONFIG_SET = 2, 27262306a36Sopenharmony_ci IPC_MOD_LARGE_CONFIG_GET = 3, 27362306a36Sopenharmony_ci IPC_MOD_LARGE_CONFIG_SET = 4, 27462306a36Sopenharmony_ci IPC_MOD_BIND = 5, 27562306a36Sopenharmony_ci IPC_MOD_UNBIND = 6, 27662306a36Sopenharmony_ci IPC_MOD_SET_DX = 7, 27762306a36Sopenharmony_ci IPC_MOD_SET_D0IX = 8 27862306a36Sopenharmony_ci}; 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_civoid skl_ipc_tx_data_copy(struct ipc_message *msg, char *tx_data, 28162306a36Sopenharmony_ci size_t tx_size) 28262306a36Sopenharmony_ci{ 28362306a36Sopenharmony_ci if (tx_size) 28462306a36Sopenharmony_ci memcpy(msg->tx.data, tx_data, tx_size); 28562306a36Sopenharmony_ci} 28662306a36Sopenharmony_ci 28762306a36Sopenharmony_cistatic bool skl_ipc_is_dsp_busy(struct sst_dsp *dsp) 28862306a36Sopenharmony_ci{ 28962306a36Sopenharmony_ci u32 hipci; 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci hipci = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCI); 29262306a36Sopenharmony_ci return (hipci & SKL_ADSP_REG_HIPCI_BUSY); 29362306a36Sopenharmony_ci} 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ci/* Lock to be held by caller */ 29662306a36Sopenharmony_cistatic void skl_ipc_tx_msg(struct sst_generic_ipc *ipc, struct ipc_message *msg) 29762306a36Sopenharmony_ci{ 29862306a36Sopenharmony_ci struct skl_ipc_header *header = (struct skl_ipc_header *)(&msg->tx.header); 29962306a36Sopenharmony_ci 30062306a36Sopenharmony_ci if (msg->tx.size) 30162306a36Sopenharmony_ci sst_dsp_outbox_write(ipc->dsp, msg->tx.data, msg->tx.size); 30262306a36Sopenharmony_ci sst_dsp_shim_write_unlocked(ipc->dsp, SKL_ADSP_REG_HIPCIE, 30362306a36Sopenharmony_ci header->extension); 30462306a36Sopenharmony_ci sst_dsp_shim_write_unlocked(ipc->dsp, SKL_ADSP_REG_HIPCI, 30562306a36Sopenharmony_ci header->primary | SKL_ADSP_REG_HIPCI_BUSY); 30662306a36Sopenharmony_ci} 30762306a36Sopenharmony_ci 30862306a36Sopenharmony_ciint skl_ipc_check_D0i0(struct sst_dsp *dsp, bool state) 30962306a36Sopenharmony_ci{ 31062306a36Sopenharmony_ci int ret; 31162306a36Sopenharmony_ci 31262306a36Sopenharmony_ci /* check D0i3 support */ 31362306a36Sopenharmony_ci if (!dsp->fw_ops.set_state_D0i0) 31462306a36Sopenharmony_ci return 0; 31562306a36Sopenharmony_ci 31662306a36Sopenharmony_ci /* Attempt D0i0 or D0i3 based on state */ 31762306a36Sopenharmony_ci if (state) 31862306a36Sopenharmony_ci ret = dsp->fw_ops.set_state_D0i0(dsp); 31962306a36Sopenharmony_ci else 32062306a36Sopenharmony_ci ret = dsp->fw_ops.set_state_D0i3(dsp); 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci return ret; 32362306a36Sopenharmony_ci} 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_cistatic struct ipc_message *skl_ipc_reply_get_msg(struct sst_generic_ipc *ipc, 32662306a36Sopenharmony_ci u64 ipc_header) 32762306a36Sopenharmony_ci{ 32862306a36Sopenharmony_ci struct ipc_message *msg = NULL; 32962306a36Sopenharmony_ci struct skl_ipc_header *header = (struct skl_ipc_header *)(&ipc_header); 33062306a36Sopenharmony_ci 33162306a36Sopenharmony_ci if (list_empty(&ipc->rx_list)) { 33262306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: rx list is empty but received 0x%x\n", 33362306a36Sopenharmony_ci header->primary); 33462306a36Sopenharmony_ci goto out; 33562306a36Sopenharmony_ci } 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci msg = list_first_entry(&ipc->rx_list, struct ipc_message, list); 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci list_del(&msg->list); 34062306a36Sopenharmony_ciout: 34162306a36Sopenharmony_ci return msg; 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci} 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ciint skl_ipc_process_notification(struct sst_generic_ipc *ipc, 34662306a36Sopenharmony_ci struct skl_ipc_header header) 34762306a36Sopenharmony_ci{ 34862306a36Sopenharmony_ci struct skl_dev *skl = container_of(ipc, struct skl_dev, ipc); 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ci if (IPC_GLB_NOTIFY_MSG_TYPE(header.primary)) { 35162306a36Sopenharmony_ci switch (IPC_GLB_NOTIFY_TYPE(header.primary)) { 35262306a36Sopenharmony_ci 35362306a36Sopenharmony_ci case IPC_GLB_NOTIFY_UNDERRUN: 35462306a36Sopenharmony_ci dev_err(ipc->dev, "FW Underrun %x\n", header.primary); 35562306a36Sopenharmony_ci break; 35662306a36Sopenharmony_ci 35762306a36Sopenharmony_ci case IPC_GLB_NOTIFY_RESOURCE_EVENT: 35862306a36Sopenharmony_ci dev_err(ipc->dev, "MCPS Budget Violation: %x\n", 35962306a36Sopenharmony_ci header.primary); 36062306a36Sopenharmony_ci break; 36162306a36Sopenharmony_ci 36262306a36Sopenharmony_ci case IPC_GLB_NOTIFY_FW_READY: 36362306a36Sopenharmony_ci skl->boot_complete = true; 36462306a36Sopenharmony_ci wake_up(&skl->boot_wait); 36562306a36Sopenharmony_ci break; 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci case IPC_GLB_NOTIFY_PHRASE_DETECTED: 36862306a36Sopenharmony_ci dev_dbg(ipc->dev, "***** Phrase Detected **********\n"); 36962306a36Sopenharmony_ci 37062306a36Sopenharmony_ci /* 37162306a36Sopenharmony_ci * Per HW recomendation, After phrase detection, 37262306a36Sopenharmony_ci * clear the CGCTL.MISCBDCGE. 37362306a36Sopenharmony_ci * 37462306a36Sopenharmony_ci * This will be set back on stream closure 37562306a36Sopenharmony_ci */ 37662306a36Sopenharmony_ci skl->enable_miscbdcge(ipc->dev, false); 37762306a36Sopenharmony_ci skl->miscbdcg_disabled = true; 37862306a36Sopenharmony_ci break; 37962306a36Sopenharmony_ci 38062306a36Sopenharmony_ci default: 38162306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: Unhandled error msg=%x\n", 38262306a36Sopenharmony_ci header.primary); 38362306a36Sopenharmony_ci break; 38462306a36Sopenharmony_ci } 38562306a36Sopenharmony_ci } 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci return 0; 38862306a36Sopenharmony_ci} 38962306a36Sopenharmony_ci 39062306a36Sopenharmony_cistruct skl_ipc_err_map { 39162306a36Sopenharmony_ci const char *msg; 39262306a36Sopenharmony_ci enum skl_ipc_glb_reply reply; 39362306a36Sopenharmony_ci int err; 39462306a36Sopenharmony_ci}; 39562306a36Sopenharmony_ci 39662306a36Sopenharmony_cistatic struct skl_ipc_err_map skl_err_map[] = { 39762306a36Sopenharmony_ci {"DSP out of memory", IPC_GLB_REPLY_OUT_OF_MEMORY, -ENOMEM}, 39862306a36Sopenharmony_ci {"DSP busy", IPC_GLB_REPLY_BUSY, -EBUSY}, 39962306a36Sopenharmony_ci {"SCLK already running", IPC_GLB_REPLY_SCLK_ALREADY_RUNNING, 40062306a36Sopenharmony_ci IPC_GLB_REPLY_SCLK_ALREADY_RUNNING}, 40162306a36Sopenharmony_ci {"MCLK already running", IPC_GLB_REPLY_MCLK_ALREADY_RUNNING, 40262306a36Sopenharmony_ci IPC_GLB_REPLY_MCLK_ALREADY_RUNNING}, 40362306a36Sopenharmony_ci}; 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_cistatic int skl_ipc_set_reply_error_code(struct sst_generic_ipc *ipc, u32 reply) 40662306a36Sopenharmony_ci{ 40762306a36Sopenharmony_ci int i; 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(skl_err_map); i++) { 41062306a36Sopenharmony_ci if (skl_err_map[i].reply == reply) 41162306a36Sopenharmony_ci break; 41262306a36Sopenharmony_ci } 41362306a36Sopenharmony_ci 41462306a36Sopenharmony_ci if (i == ARRAY_SIZE(skl_err_map)) { 41562306a36Sopenharmony_ci dev_err(ipc->dev, "ipc FW reply: %d FW Error Code: %u\n", 41662306a36Sopenharmony_ci reply, 41762306a36Sopenharmony_ci ipc->dsp->fw_ops.get_fw_errcode(ipc->dsp)); 41862306a36Sopenharmony_ci return -EINVAL; 41962306a36Sopenharmony_ci } 42062306a36Sopenharmony_ci 42162306a36Sopenharmony_ci if (skl_err_map[i].err < 0) 42262306a36Sopenharmony_ci dev_err(ipc->dev, "ipc FW reply: %s FW Error Code: %u\n", 42362306a36Sopenharmony_ci skl_err_map[i].msg, 42462306a36Sopenharmony_ci ipc->dsp->fw_ops.get_fw_errcode(ipc->dsp)); 42562306a36Sopenharmony_ci else 42662306a36Sopenharmony_ci dev_info(ipc->dev, "ipc FW reply: %s FW Error Code: %u\n", 42762306a36Sopenharmony_ci skl_err_map[i].msg, 42862306a36Sopenharmony_ci ipc->dsp->fw_ops.get_fw_errcode(ipc->dsp)); 42962306a36Sopenharmony_ci 43062306a36Sopenharmony_ci return skl_err_map[i].err; 43162306a36Sopenharmony_ci} 43262306a36Sopenharmony_ci 43362306a36Sopenharmony_civoid skl_ipc_process_reply(struct sst_generic_ipc *ipc, 43462306a36Sopenharmony_ci struct skl_ipc_header header) 43562306a36Sopenharmony_ci{ 43662306a36Sopenharmony_ci struct ipc_message *msg; 43762306a36Sopenharmony_ci u32 reply = header.primary & IPC_GLB_REPLY_STATUS_MASK; 43862306a36Sopenharmony_ci u64 *ipc_header = (u64 *)(&header); 43962306a36Sopenharmony_ci struct skl_dev *skl = container_of(ipc, struct skl_dev, ipc); 44062306a36Sopenharmony_ci unsigned long flags; 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_ci spin_lock_irqsave(&ipc->dsp->spinlock, flags); 44362306a36Sopenharmony_ci msg = skl_ipc_reply_get_msg(ipc, *ipc_header); 44462306a36Sopenharmony_ci spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); 44562306a36Sopenharmony_ci if (msg == NULL) { 44662306a36Sopenharmony_ci dev_dbg(ipc->dev, "ipc: rx list is empty\n"); 44762306a36Sopenharmony_ci return; 44862306a36Sopenharmony_ci } 44962306a36Sopenharmony_ci 45062306a36Sopenharmony_ci msg->rx.header = *ipc_header; 45162306a36Sopenharmony_ci /* first process the header */ 45262306a36Sopenharmony_ci if (reply == IPC_GLB_REPLY_SUCCESS) { 45362306a36Sopenharmony_ci dev_dbg(ipc->dev, "ipc FW reply %x: success\n", header.primary); 45462306a36Sopenharmony_ci /* copy the rx data from the mailbox */ 45562306a36Sopenharmony_ci sst_dsp_inbox_read(ipc->dsp, msg->rx.data, msg->rx.size); 45662306a36Sopenharmony_ci switch (IPC_GLB_NOTIFY_MSG_TYPE(header.primary)) { 45762306a36Sopenharmony_ci case IPC_GLB_LOAD_MULTIPLE_MODS: 45862306a36Sopenharmony_ci case IPC_GLB_LOAD_LIBRARY: 45962306a36Sopenharmony_ci skl->mod_load_complete = true; 46062306a36Sopenharmony_ci skl->mod_load_status = true; 46162306a36Sopenharmony_ci wake_up(&skl->mod_load_wait); 46262306a36Sopenharmony_ci break; 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ci default: 46562306a36Sopenharmony_ci break; 46662306a36Sopenharmony_ci 46762306a36Sopenharmony_ci } 46862306a36Sopenharmony_ci } else { 46962306a36Sopenharmony_ci msg->errno = skl_ipc_set_reply_error_code(ipc, reply); 47062306a36Sopenharmony_ci switch (IPC_GLB_NOTIFY_MSG_TYPE(header.primary)) { 47162306a36Sopenharmony_ci case IPC_GLB_LOAD_MULTIPLE_MODS: 47262306a36Sopenharmony_ci case IPC_GLB_LOAD_LIBRARY: 47362306a36Sopenharmony_ci skl->mod_load_complete = true; 47462306a36Sopenharmony_ci skl->mod_load_status = false; 47562306a36Sopenharmony_ci wake_up(&skl->mod_load_wait); 47662306a36Sopenharmony_ci break; 47762306a36Sopenharmony_ci 47862306a36Sopenharmony_ci default: 47962306a36Sopenharmony_ci break; 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci } 48262306a36Sopenharmony_ci } 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_ci spin_lock_irqsave(&ipc->dsp->spinlock, flags); 48562306a36Sopenharmony_ci sst_ipc_tx_msg_reply_complete(ipc, msg); 48662306a36Sopenharmony_ci spin_unlock_irqrestore(&ipc->dsp->spinlock, flags); 48762306a36Sopenharmony_ci} 48862306a36Sopenharmony_ci 48962306a36Sopenharmony_ciirqreturn_t skl_dsp_irq_thread_handler(int irq, void *context) 49062306a36Sopenharmony_ci{ 49162306a36Sopenharmony_ci struct sst_dsp *dsp = context; 49262306a36Sopenharmony_ci struct skl_dev *skl = dsp->thread_context; 49362306a36Sopenharmony_ci struct sst_generic_ipc *ipc = &skl->ipc; 49462306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 49562306a36Sopenharmony_ci u32 hipcie, hipct, hipcte; 49662306a36Sopenharmony_ci int ipc_irq = 0; 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci if (dsp->intr_status & SKL_ADSPIS_CL_DMA) 49962306a36Sopenharmony_ci skl_cldma_process_intr(dsp); 50062306a36Sopenharmony_ci 50162306a36Sopenharmony_ci /* Here we handle IPC interrupts only */ 50262306a36Sopenharmony_ci if (!(dsp->intr_status & SKL_ADSPIS_IPC)) 50362306a36Sopenharmony_ci return IRQ_NONE; 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci hipcie = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCIE); 50662306a36Sopenharmony_ci hipct = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCT); 50762306a36Sopenharmony_ci hipcte = sst_dsp_shim_read_unlocked(dsp, SKL_ADSP_REG_HIPCTE); 50862306a36Sopenharmony_ci 50962306a36Sopenharmony_ci /* reply message from DSP */ 51062306a36Sopenharmony_ci if (hipcie & SKL_ADSP_REG_HIPCIE_DONE) { 51162306a36Sopenharmony_ci sst_dsp_shim_update_bits(dsp, SKL_ADSP_REG_HIPCCTL, 51262306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, 0); 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_ci /* clear DONE bit - tell DSP we have completed the operation */ 51562306a36Sopenharmony_ci sst_dsp_shim_update_bits_forced(dsp, SKL_ADSP_REG_HIPCIE, 51662306a36Sopenharmony_ci SKL_ADSP_REG_HIPCIE_DONE, SKL_ADSP_REG_HIPCIE_DONE); 51762306a36Sopenharmony_ci 51862306a36Sopenharmony_ci ipc_irq = 1; 51962306a36Sopenharmony_ci 52062306a36Sopenharmony_ci /* unmask Done interrupt */ 52162306a36Sopenharmony_ci sst_dsp_shim_update_bits(dsp, SKL_ADSP_REG_HIPCCTL, 52262306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, SKL_ADSP_REG_HIPCCTL_DONE); 52362306a36Sopenharmony_ci } 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_ci /* New message from DSP */ 52662306a36Sopenharmony_ci if (hipct & SKL_ADSP_REG_HIPCT_BUSY) { 52762306a36Sopenharmony_ci header.primary = hipct; 52862306a36Sopenharmony_ci header.extension = hipcte; 52962306a36Sopenharmony_ci dev_dbg(dsp->dev, "IPC irq: Firmware respond primary:%x\n", 53062306a36Sopenharmony_ci header.primary); 53162306a36Sopenharmony_ci dev_dbg(dsp->dev, "IPC irq: Firmware respond extension:%x\n", 53262306a36Sopenharmony_ci header.extension); 53362306a36Sopenharmony_ci 53462306a36Sopenharmony_ci if (IPC_GLB_NOTIFY_RSP_TYPE(header.primary)) { 53562306a36Sopenharmony_ci /* Handle Immediate reply from DSP Core */ 53662306a36Sopenharmony_ci skl_ipc_process_reply(ipc, header); 53762306a36Sopenharmony_ci } else { 53862306a36Sopenharmony_ci dev_dbg(dsp->dev, "IPC irq: Notification from firmware\n"); 53962306a36Sopenharmony_ci skl_ipc_process_notification(ipc, header); 54062306a36Sopenharmony_ci } 54162306a36Sopenharmony_ci /* clear busy interrupt */ 54262306a36Sopenharmony_ci sst_dsp_shim_update_bits_forced(dsp, SKL_ADSP_REG_HIPCT, 54362306a36Sopenharmony_ci SKL_ADSP_REG_HIPCT_BUSY, SKL_ADSP_REG_HIPCT_BUSY); 54462306a36Sopenharmony_ci ipc_irq = 1; 54562306a36Sopenharmony_ci } 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci if (ipc_irq == 0) 54862306a36Sopenharmony_ci return IRQ_NONE; 54962306a36Sopenharmony_ci 55062306a36Sopenharmony_ci skl_ipc_int_enable(dsp); 55162306a36Sopenharmony_ci 55262306a36Sopenharmony_ci /* continue to send any remaining messages... */ 55362306a36Sopenharmony_ci schedule_work(&ipc->kwork); 55462306a36Sopenharmony_ci 55562306a36Sopenharmony_ci return IRQ_HANDLED; 55662306a36Sopenharmony_ci} 55762306a36Sopenharmony_ci 55862306a36Sopenharmony_civoid skl_ipc_int_enable(struct sst_dsp *ctx) 55962306a36Sopenharmony_ci{ 56062306a36Sopenharmony_ci sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_ADSPIC, 56162306a36Sopenharmony_ci SKL_ADSPIC_IPC, SKL_ADSPIC_IPC); 56262306a36Sopenharmony_ci} 56362306a36Sopenharmony_ci 56462306a36Sopenharmony_civoid skl_ipc_int_disable(struct sst_dsp *ctx) 56562306a36Sopenharmony_ci{ 56662306a36Sopenharmony_ci sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_ADSPIC, 56762306a36Sopenharmony_ci SKL_ADSPIC_IPC, 0); 56862306a36Sopenharmony_ci} 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_civoid skl_ipc_op_int_enable(struct sst_dsp *ctx) 57162306a36Sopenharmony_ci{ 57262306a36Sopenharmony_ci /* enable IPC DONE interrupt */ 57362306a36Sopenharmony_ci sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_HIPCCTL, 57462306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, SKL_ADSP_REG_HIPCCTL_DONE); 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ci /* Enable IPC BUSY interrupt */ 57762306a36Sopenharmony_ci sst_dsp_shim_update_bits(ctx, SKL_ADSP_REG_HIPCCTL, 57862306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_BUSY, SKL_ADSP_REG_HIPCCTL_BUSY); 57962306a36Sopenharmony_ci} 58062306a36Sopenharmony_ci 58162306a36Sopenharmony_civoid skl_ipc_op_int_disable(struct sst_dsp *ctx) 58262306a36Sopenharmony_ci{ 58362306a36Sopenharmony_ci /* disable IPC DONE interrupt */ 58462306a36Sopenharmony_ci sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_HIPCCTL, 58562306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, 0); 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ci /* Disable IPC BUSY interrupt */ 58862306a36Sopenharmony_ci sst_dsp_shim_update_bits_unlocked(ctx, SKL_ADSP_REG_HIPCCTL, 58962306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_BUSY, 0); 59062306a36Sopenharmony_ci 59162306a36Sopenharmony_ci} 59262306a36Sopenharmony_ci 59362306a36Sopenharmony_cibool skl_ipc_int_status(struct sst_dsp *ctx) 59462306a36Sopenharmony_ci{ 59562306a36Sopenharmony_ci return sst_dsp_shim_read_unlocked(ctx, 59662306a36Sopenharmony_ci SKL_ADSP_REG_ADSPIS) & SKL_ADSPIS_IPC; 59762306a36Sopenharmony_ci} 59862306a36Sopenharmony_ci 59962306a36Sopenharmony_ciint skl_ipc_init(struct device *dev, struct skl_dev *skl) 60062306a36Sopenharmony_ci{ 60162306a36Sopenharmony_ci struct sst_generic_ipc *ipc; 60262306a36Sopenharmony_ci int err; 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ci ipc = &skl->ipc; 60562306a36Sopenharmony_ci ipc->dsp = skl->dsp; 60662306a36Sopenharmony_ci ipc->dev = dev; 60762306a36Sopenharmony_ci 60862306a36Sopenharmony_ci ipc->tx_data_max_size = SKL_ADSP_W1_SZ; 60962306a36Sopenharmony_ci ipc->rx_data_max_size = SKL_ADSP_W0_UP_SZ; 61062306a36Sopenharmony_ci 61162306a36Sopenharmony_ci err = sst_ipc_init(ipc); 61262306a36Sopenharmony_ci if (err) 61362306a36Sopenharmony_ci return err; 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ci ipc->ops.tx_msg = skl_ipc_tx_msg; 61662306a36Sopenharmony_ci ipc->ops.tx_data_copy = skl_ipc_tx_data_copy; 61762306a36Sopenharmony_ci ipc->ops.is_dsp_busy = skl_ipc_is_dsp_busy; 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ci return 0; 62062306a36Sopenharmony_ci} 62162306a36Sopenharmony_ci 62262306a36Sopenharmony_civoid skl_ipc_free(struct sst_generic_ipc *ipc) 62362306a36Sopenharmony_ci{ 62462306a36Sopenharmony_ci /* Disable IPC DONE interrupt */ 62562306a36Sopenharmony_ci sst_dsp_shim_update_bits(ipc->dsp, SKL_ADSP_REG_HIPCCTL, 62662306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_DONE, 0); 62762306a36Sopenharmony_ci 62862306a36Sopenharmony_ci /* Disable IPC BUSY interrupt */ 62962306a36Sopenharmony_ci sst_dsp_shim_update_bits(ipc->dsp, SKL_ADSP_REG_HIPCCTL, 63062306a36Sopenharmony_ci SKL_ADSP_REG_HIPCCTL_BUSY, 0); 63162306a36Sopenharmony_ci 63262306a36Sopenharmony_ci sst_ipc_fini(ipc); 63362306a36Sopenharmony_ci} 63462306a36Sopenharmony_ci 63562306a36Sopenharmony_ciint skl_ipc_create_pipeline(struct sst_generic_ipc *ipc, 63662306a36Sopenharmony_ci u16 ppl_mem_size, u8 ppl_type, u8 instance_id, u8 lp_mode) 63762306a36Sopenharmony_ci{ 63862306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 63962306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 64062306a36Sopenharmony_ci int ret; 64162306a36Sopenharmony_ci 64262306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 64362306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 64462306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_CREATE_PPL); 64562306a36Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 64662306a36Sopenharmony_ci header.primary |= IPC_PPL_TYPE(ppl_type); 64762306a36Sopenharmony_ci header.primary |= IPC_PPL_MEM_SIZE(ppl_mem_size); 64862306a36Sopenharmony_ci 64962306a36Sopenharmony_ci header.extension = IPC_PPL_LP_MODE(lp_mode); 65062306a36Sopenharmony_ci request.header = *(u64 *)(&header); 65162306a36Sopenharmony_ci 65262306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 65362306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 65462306a36Sopenharmony_ci if (ret < 0) { 65562306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: create pipeline fail, err: %d\n", ret); 65662306a36Sopenharmony_ci return ret; 65762306a36Sopenharmony_ci } 65862306a36Sopenharmony_ci 65962306a36Sopenharmony_ci return ret; 66062306a36Sopenharmony_ci} 66162306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_create_pipeline); 66262306a36Sopenharmony_ci 66362306a36Sopenharmony_ciint skl_ipc_delete_pipeline(struct sst_generic_ipc *ipc, u8 instance_id) 66462306a36Sopenharmony_ci{ 66562306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 66662306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 66762306a36Sopenharmony_ci int ret; 66862306a36Sopenharmony_ci 66962306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 67062306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 67162306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_DELETE_PPL); 67262306a36Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 67362306a36Sopenharmony_ci request.header = *(u64 *)(&header); 67462306a36Sopenharmony_ci 67562306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 67662306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 67762306a36Sopenharmony_ci if (ret < 0) { 67862306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: delete pipeline failed, err %d\n", ret); 67962306a36Sopenharmony_ci return ret; 68062306a36Sopenharmony_ci } 68162306a36Sopenharmony_ci 68262306a36Sopenharmony_ci return 0; 68362306a36Sopenharmony_ci} 68462306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_delete_pipeline); 68562306a36Sopenharmony_ci 68662306a36Sopenharmony_ciint skl_ipc_set_pipeline_state(struct sst_generic_ipc *ipc, 68762306a36Sopenharmony_ci u8 instance_id, enum skl_ipc_pipeline_state state) 68862306a36Sopenharmony_ci{ 68962306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 69062306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 69162306a36Sopenharmony_ci int ret; 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 69462306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 69562306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_SET_PPL_STATE); 69662306a36Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 69762306a36Sopenharmony_ci header.primary |= IPC_PPL_STATE(state); 69862306a36Sopenharmony_ci request.header = *(u64 *)(&header); 69962306a36Sopenharmony_ci 70062306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 70162306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 70262306a36Sopenharmony_ci if (ret < 0) { 70362306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: set pipeline state failed, err: %d\n", ret); 70462306a36Sopenharmony_ci return ret; 70562306a36Sopenharmony_ci } 70662306a36Sopenharmony_ci return ret; 70762306a36Sopenharmony_ci} 70862306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_pipeline_state); 70962306a36Sopenharmony_ci 71062306a36Sopenharmony_ciint 71162306a36Sopenharmony_ciskl_ipc_save_pipeline(struct sst_generic_ipc *ipc, u8 instance_id, int dma_id) 71262306a36Sopenharmony_ci{ 71362306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 71462306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 71562306a36Sopenharmony_ci int ret; 71662306a36Sopenharmony_ci 71762306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 71862306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 71962306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_SAVE_PPL); 72062306a36Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 72162306a36Sopenharmony_ci 72262306a36Sopenharmony_ci header.extension = IPC_DMA_ID(dma_id); 72362306a36Sopenharmony_ci request.header = *(u64 *)(&header); 72462306a36Sopenharmony_ci 72562306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 72662306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 72762306a36Sopenharmony_ci if (ret < 0) { 72862306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: save pipeline failed, err: %d\n", ret); 72962306a36Sopenharmony_ci return ret; 73062306a36Sopenharmony_ci } 73162306a36Sopenharmony_ci 73262306a36Sopenharmony_ci return ret; 73362306a36Sopenharmony_ci} 73462306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_save_pipeline); 73562306a36Sopenharmony_ci 73662306a36Sopenharmony_ciint skl_ipc_restore_pipeline(struct sst_generic_ipc *ipc, u8 instance_id) 73762306a36Sopenharmony_ci{ 73862306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 73962306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 74062306a36Sopenharmony_ci int ret; 74162306a36Sopenharmony_ci 74262306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 74362306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 74462306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_RESTORE_PPL); 74562306a36Sopenharmony_ci header.primary |= IPC_INSTANCE_ID(instance_id); 74662306a36Sopenharmony_ci request.header = *(u64 *)(&header); 74762306a36Sopenharmony_ci 74862306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s header=%d\n", __func__, header.primary); 74962306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 75062306a36Sopenharmony_ci if (ret < 0) { 75162306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: restore pipeline failed, err: %d\n", ret); 75262306a36Sopenharmony_ci return ret; 75362306a36Sopenharmony_ci } 75462306a36Sopenharmony_ci 75562306a36Sopenharmony_ci return ret; 75662306a36Sopenharmony_ci} 75762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_restore_pipeline); 75862306a36Sopenharmony_ci 75962306a36Sopenharmony_ciint skl_ipc_set_dx(struct sst_generic_ipc *ipc, u8 instance_id, 76062306a36Sopenharmony_ci u16 module_id, struct skl_ipc_dxstate_info *dx) 76162306a36Sopenharmony_ci{ 76262306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 76362306a36Sopenharmony_ci struct sst_ipc_message request; 76462306a36Sopenharmony_ci int ret; 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 76762306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 76862306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_SET_DX); 76962306a36Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(instance_id); 77062306a36Sopenharmony_ci header.primary |= IPC_MOD_ID(module_id); 77162306a36Sopenharmony_ci 77262306a36Sopenharmony_ci request.header = *(u64 *)(&header); 77362306a36Sopenharmony_ci request.data = dx; 77462306a36Sopenharmony_ci request.size = sizeof(*dx); 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary =%x ext=%x\n", __func__, 77762306a36Sopenharmony_ci header.primary, header.extension); 77862306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 77962306a36Sopenharmony_ci if (ret < 0) { 78062306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: set dx failed, err %d\n", ret); 78162306a36Sopenharmony_ci return ret; 78262306a36Sopenharmony_ci } 78362306a36Sopenharmony_ci 78462306a36Sopenharmony_ci return ret; 78562306a36Sopenharmony_ci} 78662306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_dx); 78762306a36Sopenharmony_ci 78862306a36Sopenharmony_ciint skl_ipc_init_instance(struct sst_generic_ipc *ipc, 78962306a36Sopenharmony_ci struct skl_ipc_init_instance_msg *msg, void *param_data) 79062306a36Sopenharmony_ci{ 79162306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 79262306a36Sopenharmony_ci struct sst_ipc_message request; 79362306a36Sopenharmony_ci int ret; 79462306a36Sopenharmony_ci u32 *buffer = (u32 *)param_data; 79562306a36Sopenharmony_ci /* param_block_size must be in dwords */ 79662306a36Sopenharmony_ci u16 param_block_size = msg->param_data_size / sizeof(u32); 79762306a36Sopenharmony_ci 79862306a36Sopenharmony_ci print_hex_dump_debug("Param data:", DUMP_PREFIX_NONE, 79962306a36Sopenharmony_ci 16, 4, buffer, param_block_size, false); 80062306a36Sopenharmony_ci 80162306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 80262306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 80362306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_INIT_INSTANCE); 80462306a36Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 80562306a36Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 80662306a36Sopenharmony_ci 80762306a36Sopenharmony_ci header.extension = IPC_CORE_ID(msg->core_id); 80862306a36Sopenharmony_ci header.extension |= IPC_PPL_INSTANCE_ID(msg->ppl_instance_id); 80962306a36Sopenharmony_ci header.extension |= IPC_PARAM_BLOCK_SIZE(param_block_size); 81062306a36Sopenharmony_ci header.extension |= IPC_DOMAIN(msg->domain); 81162306a36Sopenharmony_ci 81262306a36Sopenharmony_ci request.header = *(u64 *)(&header); 81362306a36Sopenharmony_ci request.data = param_data; 81462306a36Sopenharmony_ci request.size = msg->param_data_size; 81562306a36Sopenharmony_ci 81662306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary =%x ext=%x\n", __func__, 81762306a36Sopenharmony_ci header.primary, header.extension); 81862306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 81962306a36Sopenharmony_ci 82062306a36Sopenharmony_ci if (ret < 0) { 82162306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: init instance failed\n"); 82262306a36Sopenharmony_ci return ret; 82362306a36Sopenharmony_ci } 82462306a36Sopenharmony_ci 82562306a36Sopenharmony_ci return ret; 82662306a36Sopenharmony_ci} 82762306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_init_instance); 82862306a36Sopenharmony_ci 82962306a36Sopenharmony_ciint skl_ipc_bind_unbind(struct sst_generic_ipc *ipc, 83062306a36Sopenharmony_ci struct skl_ipc_bind_unbind_msg *msg) 83162306a36Sopenharmony_ci{ 83262306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 83362306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 83462306a36Sopenharmony_ci u8 bind_unbind = msg->bind ? IPC_MOD_BIND : IPC_MOD_UNBIND; 83562306a36Sopenharmony_ci int ret; 83662306a36Sopenharmony_ci 83762306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 83862306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 83962306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(bind_unbind); 84062306a36Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 84162306a36Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 84262306a36Sopenharmony_ci 84362306a36Sopenharmony_ci header.extension = IPC_DST_MOD_ID(msg->dst_module_id); 84462306a36Sopenharmony_ci header.extension |= IPC_DST_MOD_INSTANCE_ID(msg->dst_instance_id); 84562306a36Sopenharmony_ci header.extension |= IPC_DST_QUEUE(msg->dst_queue); 84662306a36Sopenharmony_ci header.extension |= IPC_SRC_QUEUE(msg->src_queue); 84762306a36Sopenharmony_ci request.header = *(u64 *)(&header); 84862306a36Sopenharmony_ci 84962306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s hdr=%x ext=%x\n", __func__, header.primary, 85062306a36Sopenharmony_ci header.extension); 85162306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 85262306a36Sopenharmony_ci if (ret < 0) { 85362306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: bind/unbind failed\n"); 85462306a36Sopenharmony_ci return ret; 85562306a36Sopenharmony_ci } 85662306a36Sopenharmony_ci 85762306a36Sopenharmony_ci return ret; 85862306a36Sopenharmony_ci} 85962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_bind_unbind); 86062306a36Sopenharmony_ci 86162306a36Sopenharmony_ci/* 86262306a36Sopenharmony_ci * In order to load a module we need to send IPC to initiate that. DMA will 86362306a36Sopenharmony_ci * performed to load the module memory. The FW supports multiple module load 86462306a36Sopenharmony_ci * at single shot, so we can send IPC with N modules represented by 86562306a36Sopenharmony_ci * module_cnt 86662306a36Sopenharmony_ci */ 86762306a36Sopenharmony_ciint skl_ipc_load_modules(struct sst_generic_ipc *ipc, 86862306a36Sopenharmony_ci u8 module_cnt, void *data) 86962306a36Sopenharmony_ci{ 87062306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 87162306a36Sopenharmony_ci struct sst_ipc_message request; 87262306a36Sopenharmony_ci int ret; 87362306a36Sopenharmony_ci 87462306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 87562306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 87662306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_LOAD_MULTIPLE_MODS); 87762306a36Sopenharmony_ci header.primary |= IPC_LOAD_MODULE_CNT(module_cnt); 87862306a36Sopenharmony_ci 87962306a36Sopenharmony_ci request.header = *(u64 *)(&header); 88062306a36Sopenharmony_ci request.data = data; 88162306a36Sopenharmony_ci request.size = sizeof(u16) * module_cnt; 88262306a36Sopenharmony_ci 88362306a36Sopenharmony_ci ret = sst_ipc_tx_message_nowait(ipc, request); 88462306a36Sopenharmony_ci if (ret < 0) 88562306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: load modules failed :%d\n", ret); 88662306a36Sopenharmony_ci 88762306a36Sopenharmony_ci return ret; 88862306a36Sopenharmony_ci} 88962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_load_modules); 89062306a36Sopenharmony_ci 89162306a36Sopenharmony_ciint skl_ipc_unload_modules(struct sst_generic_ipc *ipc, u8 module_cnt, 89262306a36Sopenharmony_ci void *data) 89362306a36Sopenharmony_ci{ 89462306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 89562306a36Sopenharmony_ci struct sst_ipc_message request; 89662306a36Sopenharmony_ci int ret; 89762306a36Sopenharmony_ci 89862306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 89962306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 90062306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_UNLOAD_MULTIPLE_MODS); 90162306a36Sopenharmony_ci header.primary |= IPC_LOAD_MODULE_CNT(module_cnt); 90262306a36Sopenharmony_ci 90362306a36Sopenharmony_ci request.header = *(u64 *)(&header); 90462306a36Sopenharmony_ci request.data = data; 90562306a36Sopenharmony_ci request.size = sizeof(u16) * module_cnt; 90662306a36Sopenharmony_ci 90762306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 90862306a36Sopenharmony_ci if (ret < 0) 90962306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: unload modules failed :%d\n", ret); 91062306a36Sopenharmony_ci 91162306a36Sopenharmony_ci return ret; 91262306a36Sopenharmony_ci} 91362306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_unload_modules); 91462306a36Sopenharmony_ci 91562306a36Sopenharmony_ciint skl_ipc_set_large_config(struct sst_generic_ipc *ipc, 91662306a36Sopenharmony_ci struct skl_ipc_large_config_msg *msg, u32 *param) 91762306a36Sopenharmony_ci{ 91862306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 91962306a36Sopenharmony_ci struct sst_ipc_message request; 92062306a36Sopenharmony_ci int ret = 0; 92162306a36Sopenharmony_ci size_t sz_remaining, tx_size, data_offset; 92262306a36Sopenharmony_ci 92362306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 92462306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 92562306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_LARGE_CONFIG_SET); 92662306a36Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 92762306a36Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 92862306a36Sopenharmony_ci 92962306a36Sopenharmony_ci header.extension = IPC_DATA_OFFSET_SZ(msg->param_data_size); 93062306a36Sopenharmony_ci header.extension |= IPC_LARGE_PARAM_ID(msg->large_param_id); 93162306a36Sopenharmony_ci header.extension |= IPC_FINAL_BLOCK(0); 93262306a36Sopenharmony_ci header.extension |= IPC_INITIAL_BLOCK(1); 93362306a36Sopenharmony_ci 93462306a36Sopenharmony_ci sz_remaining = msg->param_data_size; 93562306a36Sopenharmony_ci data_offset = 0; 93662306a36Sopenharmony_ci while (sz_remaining != 0) { 93762306a36Sopenharmony_ci tx_size = sz_remaining > SKL_ADSP_W1_SZ 93862306a36Sopenharmony_ci ? SKL_ADSP_W1_SZ : sz_remaining; 93962306a36Sopenharmony_ci if (tx_size == sz_remaining) 94062306a36Sopenharmony_ci header.extension |= IPC_FINAL_BLOCK(1); 94162306a36Sopenharmony_ci 94262306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary=%#x ext=%#x\n", __func__, 94362306a36Sopenharmony_ci header.primary, header.extension); 94462306a36Sopenharmony_ci dev_dbg(ipc->dev, "transmitting offset: %#x, size: %#x\n", 94562306a36Sopenharmony_ci (unsigned)data_offset, (unsigned)tx_size); 94662306a36Sopenharmony_ci 94762306a36Sopenharmony_ci request.header = *(u64 *)(&header); 94862306a36Sopenharmony_ci request.data = ((char *)param) + data_offset; 94962306a36Sopenharmony_ci request.size = tx_size; 95062306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 95162306a36Sopenharmony_ci if (ret < 0) { 95262306a36Sopenharmony_ci dev_err(ipc->dev, 95362306a36Sopenharmony_ci "ipc: set large config fail, err: %d\n", ret); 95462306a36Sopenharmony_ci return ret; 95562306a36Sopenharmony_ci } 95662306a36Sopenharmony_ci sz_remaining -= tx_size; 95762306a36Sopenharmony_ci data_offset = msg->param_data_size - sz_remaining; 95862306a36Sopenharmony_ci 95962306a36Sopenharmony_ci /* clear the fields */ 96062306a36Sopenharmony_ci header.extension &= IPC_INITIAL_BLOCK_CLEAR; 96162306a36Sopenharmony_ci header.extension &= IPC_DATA_OFFSET_SZ_CLEAR; 96262306a36Sopenharmony_ci /* fill the fields */ 96362306a36Sopenharmony_ci header.extension |= IPC_INITIAL_BLOCK(0); 96462306a36Sopenharmony_ci header.extension |= IPC_DATA_OFFSET_SZ(data_offset); 96562306a36Sopenharmony_ci } 96662306a36Sopenharmony_ci 96762306a36Sopenharmony_ci return ret; 96862306a36Sopenharmony_ci} 96962306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_large_config); 97062306a36Sopenharmony_ci 97162306a36Sopenharmony_ciint skl_ipc_get_large_config(struct sst_generic_ipc *ipc, 97262306a36Sopenharmony_ci struct skl_ipc_large_config_msg *msg, 97362306a36Sopenharmony_ci u32 **payload, size_t *bytes) 97462306a36Sopenharmony_ci{ 97562306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 97662306a36Sopenharmony_ci struct sst_ipc_message request, reply = {0}; 97762306a36Sopenharmony_ci unsigned int *buf; 97862306a36Sopenharmony_ci int ret; 97962306a36Sopenharmony_ci 98062306a36Sopenharmony_ci reply.data = kzalloc(SKL_ADSP_W1_SZ, GFP_KERNEL); 98162306a36Sopenharmony_ci if (!reply.data) 98262306a36Sopenharmony_ci return -ENOMEM; 98362306a36Sopenharmony_ci 98462306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 98562306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 98662306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_LARGE_CONFIG_GET); 98762306a36Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 98862306a36Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 98962306a36Sopenharmony_ci 99062306a36Sopenharmony_ci header.extension = IPC_DATA_OFFSET_SZ(msg->param_data_size); 99162306a36Sopenharmony_ci header.extension |= IPC_LARGE_PARAM_ID(msg->large_param_id); 99262306a36Sopenharmony_ci header.extension |= IPC_FINAL_BLOCK(1); 99362306a36Sopenharmony_ci header.extension |= IPC_INITIAL_BLOCK(1); 99462306a36Sopenharmony_ci 99562306a36Sopenharmony_ci request.header = *(u64 *)&header; 99662306a36Sopenharmony_ci request.data = *payload; 99762306a36Sopenharmony_ci request.size = *bytes; 99862306a36Sopenharmony_ci reply.size = SKL_ADSP_W1_SZ; 99962306a36Sopenharmony_ci 100062306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, &reply); 100162306a36Sopenharmony_ci if (ret < 0) 100262306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: get large config fail, err: %d\n", ret); 100362306a36Sopenharmony_ci 100462306a36Sopenharmony_ci reply.size = (reply.header >> 32) & IPC_DATA_OFFSET_SZ_MASK; 100562306a36Sopenharmony_ci buf = krealloc(reply.data, reply.size, GFP_KERNEL); 100662306a36Sopenharmony_ci if (!buf) { 100762306a36Sopenharmony_ci kfree(reply.data); 100862306a36Sopenharmony_ci return -ENOMEM; 100962306a36Sopenharmony_ci } 101062306a36Sopenharmony_ci *payload = buf; 101162306a36Sopenharmony_ci *bytes = reply.size; 101262306a36Sopenharmony_ci 101362306a36Sopenharmony_ci return ret; 101462306a36Sopenharmony_ci} 101562306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_get_large_config); 101662306a36Sopenharmony_ci 101762306a36Sopenharmony_ciint skl_sst_ipc_load_library(struct sst_generic_ipc *ipc, 101862306a36Sopenharmony_ci u8 dma_id, u8 table_id, bool wait) 101962306a36Sopenharmony_ci{ 102062306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 102162306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 102262306a36Sopenharmony_ci int ret = 0; 102362306a36Sopenharmony_ci 102462306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_FW_GEN_MSG); 102562306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 102662306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_GLB_LOAD_LIBRARY); 102762306a36Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(table_id); 102862306a36Sopenharmony_ci header.primary |= IPC_MOD_ID(dma_id); 102962306a36Sopenharmony_ci request.header = *(u64 *)(&header); 103062306a36Sopenharmony_ci 103162306a36Sopenharmony_ci if (wait) 103262306a36Sopenharmony_ci ret = sst_ipc_tx_message_wait(ipc, request, NULL); 103362306a36Sopenharmony_ci else 103462306a36Sopenharmony_ci ret = sst_ipc_tx_message_nowait(ipc, request); 103562306a36Sopenharmony_ci 103662306a36Sopenharmony_ci if (ret < 0) 103762306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: load lib failed\n"); 103862306a36Sopenharmony_ci 103962306a36Sopenharmony_ci return ret; 104062306a36Sopenharmony_ci} 104162306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_sst_ipc_load_library); 104262306a36Sopenharmony_ci 104362306a36Sopenharmony_ciint skl_ipc_set_d0ix(struct sst_generic_ipc *ipc, struct skl_ipc_d0ix_msg *msg) 104462306a36Sopenharmony_ci{ 104562306a36Sopenharmony_ci struct skl_ipc_header header = {0}; 104662306a36Sopenharmony_ci struct sst_ipc_message request = {0}; 104762306a36Sopenharmony_ci int ret; 104862306a36Sopenharmony_ci 104962306a36Sopenharmony_ci header.primary = IPC_MSG_TARGET(IPC_MOD_MSG); 105062306a36Sopenharmony_ci header.primary |= IPC_MSG_DIR(IPC_MSG_REQUEST); 105162306a36Sopenharmony_ci header.primary |= IPC_GLB_TYPE(IPC_MOD_SET_D0IX); 105262306a36Sopenharmony_ci header.primary |= IPC_MOD_INSTANCE_ID(msg->instance_id); 105362306a36Sopenharmony_ci header.primary |= IPC_MOD_ID(msg->module_id); 105462306a36Sopenharmony_ci 105562306a36Sopenharmony_ci header.extension = IPC_D0IX_WAKE(msg->wake); 105662306a36Sopenharmony_ci header.extension |= IPC_D0IX_STREAMING(msg->streaming); 105762306a36Sopenharmony_ci request.header = *(u64 *)(&header); 105862306a36Sopenharmony_ci 105962306a36Sopenharmony_ci dev_dbg(ipc->dev, "In %s primary=%x ext=%x\n", __func__, 106062306a36Sopenharmony_ci header.primary, header.extension); 106162306a36Sopenharmony_ci 106262306a36Sopenharmony_ci /* 106362306a36Sopenharmony_ci * Use the nopm IPC here as we dont want it checking for D0iX 106462306a36Sopenharmony_ci */ 106562306a36Sopenharmony_ci ret = sst_ipc_tx_message_nopm(ipc, request, NULL); 106662306a36Sopenharmony_ci if (ret < 0) 106762306a36Sopenharmony_ci dev_err(ipc->dev, "ipc: set d0ix failed, err %d\n", ret); 106862306a36Sopenharmony_ci 106962306a36Sopenharmony_ci return ret; 107062306a36Sopenharmony_ci} 107162306a36Sopenharmony_ciEXPORT_SYMBOL_GPL(skl_ipc_set_d0ix); 1072