162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
462306a36Sopenharmony_ci * redistributing this file, you may do so under either license.
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Copyright(c) 2018 Intel Corporation. All rights reserved.
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef __INCLUDE_SOUND_SOF_HEADER_H__
1062306a36Sopenharmony_ci#define __INCLUDE_SOUND_SOF_HEADER_H__
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/types.h>
1362306a36Sopenharmony_ci#include <uapi/sound/sof/abi.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/** \addtogroup sof_uapi uAPI
1662306a36Sopenharmony_ci *  SOF uAPI specification.
1762306a36Sopenharmony_ci *  @{
1862306a36Sopenharmony_ci */
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci/*
2162306a36Sopenharmony_ci * IPC messages have a prefixed 32 bit identifier made up as follows :-
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * 0xGCCCNNNN where
2462306a36Sopenharmony_ci * G is global cmd type (4 bits)
2562306a36Sopenharmony_ci * C is command type (12 bits)
2662306a36Sopenharmony_ci * I is the ID number (16 bits) - monotonic and overflows
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * This is sent at the start of the IPM message in the mailbox. Messages should
2962306a36Sopenharmony_ci * not be sent in the doorbell (special exceptions for firmware .
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci/* Global Message - Generic */
3362306a36Sopenharmony_ci#define SOF_GLB_TYPE_SHIFT			28
3462306a36Sopenharmony_ci#define SOF_GLB_TYPE_MASK			(0xfUL << SOF_GLB_TYPE_SHIFT)
3562306a36Sopenharmony_ci#define SOF_GLB_TYPE(x)				((x) << SOF_GLB_TYPE_SHIFT)
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci/* Command Message - Generic */
3862306a36Sopenharmony_ci#define SOF_CMD_TYPE_SHIFT			16
3962306a36Sopenharmony_ci#define SOF_CMD_TYPE_MASK			(0xfffL << SOF_CMD_TYPE_SHIFT)
4062306a36Sopenharmony_ci#define SOF_CMD_TYPE(x)				((x) << SOF_CMD_TYPE_SHIFT)
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci/* Global Message Types */
4362306a36Sopenharmony_ci#define SOF_IPC_GLB_REPLY			SOF_GLB_TYPE(0x1U)
4462306a36Sopenharmony_ci#define SOF_IPC_GLB_COMPOUND			SOF_GLB_TYPE(0x2U)
4562306a36Sopenharmony_ci#define SOF_IPC_GLB_TPLG_MSG			SOF_GLB_TYPE(0x3U)
4662306a36Sopenharmony_ci#define SOF_IPC_GLB_PM_MSG			SOF_GLB_TYPE(0x4U)
4762306a36Sopenharmony_ci#define SOF_IPC_GLB_COMP_MSG			SOF_GLB_TYPE(0x5U)
4862306a36Sopenharmony_ci#define SOF_IPC_GLB_STREAM_MSG			SOF_GLB_TYPE(0x6U)
4962306a36Sopenharmony_ci#define SOF_IPC_FW_READY			SOF_GLB_TYPE(0x7U)
5062306a36Sopenharmony_ci#define SOF_IPC_GLB_DAI_MSG			SOF_GLB_TYPE(0x8U)
5162306a36Sopenharmony_ci#define SOF_IPC_GLB_TRACE_MSG			SOF_GLB_TYPE(0x9U)
5262306a36Sopenharmony_ci#define SOF_IPC_GLB_GDB_DEBUG			SOF_GLB_TYPE(0xAU)
5362306a36Sopenharmony_ci#define SOF_IPC_GLB_TEST_MSG			SOF_GLB_TYPE(0xBU)
5462306a36Sopenharmony_ci#define SOF_IPC_GLB_PROBE			SOF_GLB_TYPE(0xCU)
5562306a36Sopenharmony_ci#define SOF_IPC_GLB_DEBUG			SOF_GLB_TYPE(0xDU)
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/*
5862306a36Sopenharmony_ci * DSP Command Message Types
5962306a36Sopenharmony_ci */
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci/* topology */
6262306a36Sopenharmony_ci#define SOF_IPC_TPLG_COMP_NEW			SOF_CMD_TYPE(0x001)
6362306a36Sopenharmony_ci#define SOF_IPC_TPLG_COMP_FREE			SOF_CMD_TYPE(0x002)
6462306a36Sopenharmony_ci#define SOF_IPC_TPLG_COMP_CONNECT		SOF_CMD_TYPE(0x003)
6562306a36Sopenharmony_ci#define SOF_IPC_TPLG_PIPE_NEW			SOF_CMD_TYPE(0x010)
6662306a36Sopenharmony_ci#define SOF_IPC_TPLG_PIPE_FREE			SOF_CMD_TYPE(0x011)
6762306a36Sopenharmony_ci#define SOF_IPC_TPLG_PIPE_CONNECT		SOF_CMD_TYPE(0x012)
6862306a36Sopenharmony_ci#define SOF_IPC_TPLG_PIPE_COMPLETE		SOF_CMD_TYPE(0x013)
6962306a36Sopenharmony_ci#define SOF_IPC_TPLG_BUFFER_NEW			SOF_CMD_TYPE(0x020)
7062306a36Sopenharmony_ci#define SOF_IPC_TPLG_BUFFER_FREE		SOF_CMD_TYPE(0x021)
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/* PM */
7362306a36Sopenharmony_ci#define SOF_IPC_PM_CTX_SAVE			SOF_CMD_TYPE(0x001)
7462306a36Sopenharmony_ci#define SOF_IPC_PM_CTX_RESTORE			SOF_CMD_TYPE(0x002)
7562306a36Sopenharmony_ci#define SOF_IPC_PM_CTX_SIZE			SOF_CMD_TYPE(0x003)
7662306a36Sopenharmony_ci#define SOF_IPC_PM_CLK_SET			SOF_CMD_TYPE(0x004)
7762306a36Sopenharmony_ci#define SOF_IPC_PM_CLK_GET			SOF_CMD_TYPE(0x005)
7862306a36Sopenharmony_ci#define SOF_IPC_PM_CLK_REQ			SOF_CMD_TYPE(0x006)
7962306a36Sopenharmony_ci#define SOF_IPC_PM_CORE_ENABLE			SOF_CMD_TYPE(0x007)
8062306a36Sopenharmony_ci#define SOF_IPC_PM_GATE				SOF_CMD_TYPE(0x008)
8162306a36Sopenharmony_ci
8262306a36Sopenharmony_ci/* component runtime config - multiple different types */
8362306a36Sopenharmony_ci#define SOF_IPC_COMP_SET_VALUE			SOF_CMD_TYPE(0x001)
8462306a36Sopenharmony_ci#define SOF_IPC_COMP_GET_VALUE			SOF_CMD_TYPE(0x002)
8562306a36Sopenharmony_ci#define SOF_IPC_COMP_SET_DATA			SOF_CMD_TYPE(0x003)
8662306a36Sopenharmony_ci#define SOF_IPC_COMP_GET_DATA			SOF_CMD_TYPE(0x004)
8762306a36Sopenharmony_ci#define SOF_IPC_COMP_NOTIFICATION		SOF_CMD_TYPE(0x005)
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_ci/* DAI messages */
9062306a36Sopenharmony_ci#define SOF_IPC_DAI_CONFIG			SOF_CMD_TYPE(0x001)
9162306a36Sopenharmony_ci#define SOF_IPC_DAI_LOOPBACK			SOF_CMD_TYPE(0x002)
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* stream */
9462306a36Sopenharmony_ci#define SOF_IPC_STREAM_PCM_PARAMS		SOF_CMD_TYPE(0x001)
9562306a36Sopenharmony_ci#define SOF_IPC_STREAM_PCM_PARAMS_REPLY		SOF_CMD_TYPE(0x002)
9662306a36Sopenharmony_ci#define SOF_IPC_STREAM_PCM_FREE			SOF_CMD_TYPE(0x003)
9762306a36Sopenharmony_ci#define SOF_IPC_STREAM_TRIG_START		SOF_CMD_TYPE(0x004)
9862306a36Sopenharmony_ci#define SOF_IPC_STREAM_TRIG_STOP		SOF_CMD_TYPE(0x005)
9962306a36Sopenharmony_ci#define SOF_IPC_STREAM_TRIG_PAUSE		SOF_CMD_TYPE(0x006)
10062306a36Sopenharmony_ci#define SOF_IPC_STREAM_TRIG_RELEASE		SOF_CMD_TYPE(0x007)
10162306a36Sopenharmony_ci#define SOF_IPC_STREAM_TRIG_DRAIN		SOF_CMD_TYPE(0x008)
10262306a36Sopenharmony_ci#define SOF_IPC_STREAM_TRIG_XRUN		SOF_CMD_TYPE(0x009)
10362306a36Sopenharmony_ci#define SOF_IPC_STREAM_POSITION			SOF_CMD_TYPE(0x00a)
10462306a36Sopenharmony_ci#define SOF_IPC_STREAM_VORBIS_PARAMS		SOF_CMD_TYPE(0x010)
10562306a36Sopenharmony_ci#define SOF_IPC_STREAM_VORBIS_FREE		SOF_CMD_TYPE(0x011)
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/* probe */
10862306a36Sopenharmony_ci#define SOF_IPC_PROBE_INIT			SOF_CMD_TYPE(0x001)
10962306a36Sopenharmony_ci#define SOF_IPC_PROBE_DEINIT			SOF_CMD_TYPE(0x002)
11062306a36Sopenharmony_ci#define SOF_IPC_PROBE_DMA_ADD			SOF_CMD_TYPE(0x003)
11162306a36Sopenharmony_ci#define SOF_IPC_PROBE_DMA_INFO			SOF_CMD_TYPE(0x004)
11262306a36Sopenharmony_ci#define SOF_IPC_PROBE_DMA_REMOVE		SOF_CMD_TYPE(0x005)
11362306a36Sopenharmony_ci#define SOF_IPC_PROBE_POINT_ADD			SOF_CMD_TYPE(0x006)
11462306a36Sopenharmony_ci#define SOF_IPC_PROBE_POINT_INFO		SOF_CMD_TYPE(0x007)
11562306a36Sopenharmony_ci#define SOF_IPC_PROBE_POINT_REMOVE		SOF_CMD_TYPE(0x008)
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* trace */
11862306a36Sopenharmony_ci#define SOF_IPC_TRACE_DMA_PARAMS		SOF_CMD_TYPE(0x001)
11962306a36Sopenharmony_ci#define SOF_IPC_TRACE_DMA_POSITION		SOF_CMD_TYPE(0x002)
12062306a36Sopenharmony_ci#define SOF_IPC_TRACE_DMA_PARAMS_EXT		SOF_CMD_TYPE(0x003)
12162306a36Sopenharmony_ci#define SOF_IPC_TRACE_FILTER_UPDATE		SOF_CMD_TYPE(0x004) /**< ABI3.17 */
12262306a36Sopenharmony_ci#define SOF_IPC_TRACE_DMA_FREE		SOF_CMD_TYPE(0x005) /**< ABI3.20 */
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci/* debug */
12562306a36Sopenharmony_ci#define SOF_IPC_DEBUG_MEM_USAGE			SOF_CMD_TYPE(0x001)
12662306a36Sopenharmony_ci
12762306a36Sopenharmony_ci/* test */
12862306a36Sopenharmony_ci#define SOF_IPC_TEST_IPC_FLOOD			SOF_CMD_TYPE(0x001)
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci/* Get message component id */
13162306a36Sopenharmony_ci#define SOF_IPC_MESSAGE_ID(x)			((x) & 0xffff)
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_ci/* maximum message size for mailbox Tx/Rx */
13462306a36Sopenharmony_ci#define SOF_IPC_MSG_MAX_SIZE			384
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/*
13762306a36Sopenharmony_ci * Structure Header - Header for all IPC structures except command structs.
13862306a36Sopenharmony_ci * The size can be greater than the structure size and that means there is
13962306a36Sopenharmony_ci * extended bespoke data beyond the end of the structure including variable
14062306a36Sopenharmony_ci * arrays.
14162306a36Sopenharmony_ci */
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_cistruct sof_ipc_hdr {
14462306a36Sopenharmony_ci	uint32_t size;			/**< size of structure */
14562306a36Sopenharmony_ci} __packed;
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci/*
14862306a36Sopenharmony_ci * Command Header - Header for all IPC commands. Identifies IPC message.
14962306a36Sopenharmony_ci * The size can be greater than the structure size and that means there is
15062306a36Sopenharmony_ci * extended bespoke data beyond the end of the structure including variable
15162306a36Sopenharmony_ci * arrays.
15262306a36Sopenharmony_ci */
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_cistruct sof_ipc_cmd_hdr {
15562306a36Sopenharmony_ci	uint32_t size;			/**< size of structure */
15662306a36Sopenharmony_ci	uint32_t cmd;			/**< SOF_IPC_GLB_ + cmd */
15762306a36Sopenharmony_ci} __packed;
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci/*
16062306a36Sopenharmony_ci * Generic reply message. Some commands override this with their own reply
16162306a36Sopenharmony_ci * types that must include this at start.
16262306a36Sopenharmony_ci */
16362306a36Sopenharmony_cistruct sof_ipc_reply {
16462306a36Sopenharmony_ci	struct sof_ipc_cmd_hdr hdr;
16562306a36Sopenharmony_ci	int32_t error;			/**< negative error numbers */
16662306a36Sopenharmony_ci}  __packed;
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci/*
16962306a36Sopenharmony_ci * Compound commands - SOF_IPC_GLB_COMPOUND.
17062306a36Sopenharmony_ci *
17162306a36Sopenharmony_ci * Compound commands are sent to the DSP as a single IPC operation. The
17262306a36Sopenharmony_ci * commands are split into blocks and each block has a header. This header
17362306a36Sopenharmony_ci * identifies the command type and the number of commands before the next
17462306a36Sopenharmony_ci * header.
17562306a36Sopenharmony_ci */
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_cistruct sof_ipc_compound_hdr {
17862306a36Sopenharmony_ci	struct sof_ipc_cmd_hdr hdr;
17962306a36Sopenharmony_ci	uint32_t count;		/**< count of 0 means end of compound sequence */
18062306a36Sopenharmony_ci}  __packed;
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci/**
18362306a36Sopenharmony_ci * OOPS header architecture specific data.
18462306a36Sopenharmony_ci */
18562306a36Sopenharmony_cistruct sof_ipc_dsp_oops_arch_hdr {
18662306a36Sopenharmony_ci	uint32_t arch;		/* Identifier of architecture */
18762306a36Sopenharmony_ci	uint32_t totalsize;	/* Total size of oops message */
18862306a36Sopenharmony_ci}  __packed;
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/**
19162306a36Sopenharmony_ci * OOPS header platform specific data.
19262306a36Sopenharmony_ci */
19362306a36Sopenharmony_cistruct sof_ipc_dsp_oops_plat_hdr {
19462306a36Sopenharmony_ci	uint32_t configidhi;	/* ConfigID hi 32bits */
19562306a36Sopenharmony_ci	uint32_t configidlo;	/* ConfigID lo 32bits */
19662306a36Sopenharmony_ci	uint32_t numaregs;	/* Special regs num */
19762306a36Sopenharmony_ci	uint32_t stackoffset;	/* Offset to stack pointer from beginning of
19862306a36Sopenharmony_ci				 * oops message
19962306a36Sopenharmony_ci				 */
20062306a36Sopenharmony_ci	uint32_t stackptr;	/* Stack ptr */
20162306a36Sopenharmony_ci}  __packed;
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci/** @}*/
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci#endif
206