162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Intel SKL IPC Support
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright (C) 2014-15, Intel Corporation.
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#ifndef __SKL_IPC_H
962306a36Sopenharmony_ci#define __SKL_IPC_H
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#include <linux/irqreturn.h>
1262306a36Sopenharmony_ci#include "../common/sst-ipc.h"
1362306a36Sopenharmony_ci#include "skl-sst-dsp.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_cistruct sst_dsp;
1662306a36Sopenharmony_cistruct sst_generic_ipc;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_cienum skl_ipc_pipeline_state {
1962306a36Sopenharmony_ci	PPL_INVALID_STATE =	0,
2062306a36Sopenharmony_ci	PPL_UNINITIALIZED =	1,
2162306a36Sopenharmony_ci	PPL_RESET =		2,
2262306a36Sopenharmony_ci	PPL_PAUSED =		3,
2362306a36Sopenharmony_ci	PPL_RUNNING =		4,
2462306a36Sopenharmony_ci	PPL_ERROR_STOP =	5,
2562306a36Sopenharmony_ci	PPL_SAVED =		6,
2662306a36Sopenharmony_ci	PPL_RESTORED =		7
2762306a36Sopenharmony_ci};
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_cistruct skl_ipc_dxstate_info {
3062306a36Sopenharmony_ci	u32 core_mask;
3162306a36Sopenharmony_ci	u32 dx_mask;
3262306a36Sopenharmony_ci};
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_cistruct skl_ipc_header {
3562306a36Sopenharmony_ci	u32 primary;
3662306a36Sopenharmony_ci	u32 extension;
3762306a36Sopenharmony_ci};
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_cistruct skl_dsp_cores {
4062306a36Sopenharmony_ci	unsigned int count;
4162306a36Sopenharmony_ci	enum skl_dsp_states *state;
4262306a36Sopenharmony_ci	int *usage_count;
4362306a36Sopenharmony_ci};
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/**
4662306a36Sopenharmony_ci * skl_d0i3_data: skl D0i3 counters data struct
4762306a36Sopenharmony_ci *
4862306a36Sopenharmony_ci * @streaming: Count of usecases that can attempt streaming D0i3
4962306a36Sopenharmony_ci * @non_streaming: Count of usecases that can attempt non-streaming D0i3
5062306a36Sopenharmony_ci * @non_d0i3: Count of usecases that cannot attempt D0i3
5162306a36Sopenharmony_ci * @state: current state
5262306a36Sopenharmony_ci * @work: D0i3 worker thread
5362306a36Sopenharmony_ci */
5462306a36Sopenharmony_cistruct skl_d0i3_data {
5562306a36Sopenharmony_ci	int streaming;
5662306a36Sopenharmony_ci	int non_streaming;
5762306a36Sopenharmony_ci	int non_d0i3;
5862306a36Sopenharmony_ci	enum skl_dsp_d0i3_states state;
5962306a36Sopenharmony_ci	struct delayed_work work;
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define SKL_LIB_NAME_LENGTH 128
6362306a36Sopenharmony_ci#define SKL_MAX_LIB 16
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_cistruct skl_lib_info {
6662306a36Sopenharmony_ci	char name[SKL_LIB_NAME_LENGTH];
6762306a36Sopenharmony_ci	const struct firmware *fw;
6862306a36Sopenharmony_ci};
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_cistruct skl_ipc_init_instance_msg {
7162306a36Sopenharmony_ci	u32 module_id;
7262306a36Sopenharmony_ci	u32 instance_id;
7362306a36Sopenharmony_ci	u16 param_data_size;
7462306a36Sopenharmony_ci	u8 ppl_instance_id;
7562306a36Sopenharmony_ci	u8 core_id;
7662306a36Sopenharmony_ci	u8 domain;
7762306a36Sopenharmony_ci};
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_cistruct skl_ipc_bind_unbind_msg {
8062306a36Sopenharmony_ci	u32 module_id;
8162306a36Sopenharmony_ci	u32 instance_id;
8262306a36Sopenharmony_ci	u32 dst_module_id;
8362306a36Sopenharmony_ci	u32 dst_instance_id;
8462306a36Sopenharmony_ci	u8 src_queue;
8562306a36Sopenharmony_ci	u8 dst_queue;
8662306a36Sopenharmony_ci	bool bind;
8762306a36Sopenharmony_ci};
8862306a36Sopenharmony_ci
8962306a36Sopenharmony_cistruct skl_ipc_large_config_msg {
9062306a36Sopenharmony_ci	u32 module_id;
9162306a36Sopenharmony_ci	u32 instance_id;
9262306a36Sopenharmony_ci	u32 large_param_id;
9362306a36Sopenharmony_ci	u32 param_data_size;
9462306a36Sopenharmony_ci};
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_cistruct skl_ipc_d0ix_msg {
9762306a36Sopenharmony_ci	u32 module_id;
9862306a36Sopenharmony_ci	u32 instance_id;
9962306a36Sopenharmony_ci	u8 streaming;
10062306a36Sopenharmony_ci	u8 wake;
10162306a36Sopenharmony_ci};
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci#define SKL_IPC_BOOT_MSECS		3000
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#define SKL_IPC_D3_MASK	0
10662306a36Sopenharmony_ci#define SKL_IPC_D0_MASK	3
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciirqreturn_t skl_dsp_irq_thread_handler(int irq, void *context);
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ciint skl_ipc_create_pipeline(struct sst_generic_ipc *ipc,
11162306a36Sopenharmony_ci		u16 ppl_mem_size, u8 ppl_type, u8 instance_id, u8 lp_mode);
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ciint skl_ipc_delete_pipeline(struct sst_generic_ipc *ipc, u8 instance_id);
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ciint skl_ipc_set_pipeline_state(struct sst_generic_ipc *ipc,
11662306a36Sopenharmony_ci		u8 instance_id,	enum skl_ipc_pipeline_state state);
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ciint skl_ipc_save_pipeline(struct sst_generic_ipc *ipc,
11962306a36Sopenharmony_ci		u8 instance_id, int dma_id);
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ciint skl_ipc_restore_pipeline(struct sst_generic_ipc *ipc, u8 instance_id);
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ciint skl_ipc_init_instance(struct sst_generic_ipc *ipc,
12462306a36Sopenharmony_ci		struct skl_ipc_init_instance_msg *msg, void *param_data);
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciint skl_ipc_bind_unbind(struct sst_generic_ipc *ipc,
12762306a36Sopenharmony_ci		struct skl_ipc_bind_unbind_msg *msg);
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ciint skl_ipc_load_modules(struct sst_generic_ipc *ipc,
13062306a36Sopenharmony_ci				u8 module_cnt, void *data);
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ciint skl_ipc_unload_modules(struct sst_generic_ipc *ipc,
13362306a36Sopenharmony_ci				u8 module_cnt, void *data);
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ciint skl_ipc_set_dx(struct sst_generic_ipc *ipc,
13662306a36Sopenharmony_ci		u8 instance_id, u16 module_id, struct skl_ipc_dxstate_info *dx);
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ciint skl_ipc_set_large_config(struct sst_generic_ipc *ipc,
13962306a36Sopenharmony_ci		struct skl_ipc_large_config_msg *msg, u32 *param);
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ciint skl_ipc_get_large_config(struct sst_generic_ipc *ipc,
14262306a36Sopenharmony_ci		struct skl_ipc_large_config_msg *msg,
14362306a36Sopenharmony_ci		u32 **payload, size_t *bytes);
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciint skl_sst_ipc_load_library(struct sst_generic_ipc *ipc,
14662306a36Sopenharmony_ci			u8 dma_id, u8 table_id, bool wait);
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ciint skl_ipc_set_d0ix(struct sst_generic_ipc *ipc,
14962306a36Sopenharmony_ci		struct skl_ipc_d0ix_msg *msg);
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ciint skl_ipc_check_D0i0(struct sst_dsp *dsp, bool state);
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_civoid skl_ipc_int_enable(struct sst_dsp *ctx);
15462306a36Sopenharmony_civoid skl_ipc_op_int_enable(struct sst_dsp *ctx);
15562306a36Sopenharmony_civoid skl_ipc_op_int_disable(struct sst_dsp *ctx);
15662306a36Sopenharmony_civoid skl_ipc_int_disable(struct sst_dsp *ctx);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_cibool skl_ipc_int_status(struct sst_dsp *ctx);
15962306a36Sopenharmony_civoid skl_ipc_free(struct sst_generic_ipc *ipc);
16062306a36Sopenharmony_ciint skl_ipc_init(struct device *dev, struct skl_dev *skl);
16162306a36Sopenharmony_civoid skl_clear_module_cnt(struct sst_dsp *ctx);
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_civoid skl_ipc_process_reply(struct sst_generic_ipc *ipc,
16462306a36Sopenharmony_ci		struct skl_ipc_header header);
16562306a36Sopenharmony_ciint skl_ipc_process_notification(struct sst_generic_ipc *ipc,
16662306a36Sopenharmony_ci		struct skl_ipc_header header);
16762306a36Sopenharmony_civoid skl_ipc_tx_data_copy(struct ipc_message *msg, char *tx_data,
16862306a36Sopenharmony_ci		size_t tx_size);
16962306a36Sopenharmony_ci#endif /* __SKL_IPC_H */
170