xref: /openbmc/linux/sound/soc/intel/common/sst-ipc.h (revision cbecf716ca618fd44feda6bd9a64a8179d031fc5)
11802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2a33c1ec5SJin Yao /*
3a33c1ec5SJin Yao  * Intel SST generic IPC Support
4a33c1ec5SJin Yao  *
5a33c1ec5SJin Yao  * Copyright (C) 2015, Intel Corporation. All rights reserved.
6a33c1ec5SJin Yao  */
7a33c1ec5SJin Yao 
8a33c1ec5SJin Yao #ifndef __SST_GENERIC_IPC_H
9a33c1ec5SJin Yao #define __SST_GENERIC_IPC_H
10a33c1ec5SJin Yao 
11a33c1ec5SJin Yao #include <linux/types.h>
12a33c1ec5SJin Yao #include <linux/kernel.h>
13a33c1ec5SJin Yao #include <linux/wait.h>
14a33c1ec5SJin Yao #include <linux/list.h>
15a33c1ec5SJin Yao #include <linux/workqueue.h>
16a33c1ec5SJin Yao #include <linux/sched.h>
17a33c1ec5SJin Yao 
18*abf31feeSCezary Rojewski struct sst_ipc_message {
19*abf31feeSCezary Rojewski 	u64 header;
20*abf31feeSCezary Rojewski 	void *data;
21*abf31feeSCezary Rojewski 	size_t size;
22*abf31feeSCezary Rojewski };
23*abf31feeSCezary Rojewski 
24a33c1ec5SJin Yao struct ipc_message {
25a33c1ec5SJin Yao 	struct list_head list;
26*abf31feeSCezary Rojewski 	struct sst_ipc_message tx;
27*abf31feeSCezary Rojewski 	struct sst_ipc_message rx;
28a33c1ec5SJin Yao 
29a33c1ec5SJin Yao 	wait_queue_head_t waitq;
30a33c1ec5SJin Yao 	bool pending;
31a33c1ec5SJin Yao 	bool complete;
32a33c1ec5SJin Yao 	bool wait;
33a33c1ec5SJin Yao 	int errno;
34a33c1ec5SJin Yao };
35a33c1ec5SJin Yao 
36a33c1ec5SJin Yao struct sst_generic_ipc;
37bcc2a2dcSCezary Rojewski struct sst_dsp;
38a33c1ec5SJin Yao 
39a33c1ec5SJin Yao struct sst_plat_ipc_ops {
40a33c1ec5SJin Yao 	void (*tx_msg)(struct sst_generic_ipc *, struct ipc_message *);
41a33c1ec5SJin Yao 	void (*shim_dbg)(struct sst_generic_ipc *, const char *);
42a33c1ec5SJin Yao 	void (*tx_data_copy)(struct ipc_message *, char *, size_t);
43a33c1ec5SJin Yao 	u64  (*reply_msg_match)(u64 header, u64 *mask);
446022d330SSubhransu S. Prusty 	bool (*is_dsp_busy)(struct sst_dsp *dsp);
45f999d1fdSVinod Koul 	int (*check_dsp_lp_on)(struct sst_dsp *dsp, bool state);
46a33c1ec5SJin Yao };
47a33c1ec5SJin Yao 
48a33c1ec5SJin Yao /* SST generic IPC data */
49a33c1ec5SJin Yao struct sst_generic_ipc {
50a33c1ec5SJin Yao 	struct device *dev;
51a33c1ec5SJin Yao 	struct sst_dsp *dsp;
52a33c1ec5SJin Yao 
53a33c1ec5SJin Yao 	/* IPC messaging */
54a33c1ec5SJin Yao 	struct list_head tx_list;
55a33c1ec5SJin Yao 	struct list_head rx_list;
56a33c1ec5SJin Yao 	struct list_head empty_list;
57a33c1ec5SJin Yao 	wait_queue_head_t wait_txq;
58a33c1ec5SJin Yao 	struct task_struct *tx_thread;
59786e1c37STakashi Iwai 	struct work_struct kwork;
60a33c1ec5SJin Yao 	bool pending;
61a33c1ec5SJin Yao 	struct ipc_message *msg;
621925e219SSubhransu S. Prusty 	int tx_data_max_size;
631925e219SSubhransu S. Prusty 	int rx_data_max_size;
64a33c1ec5SJin Yao 
65a33c1ec5SJin Yao 	struct sst_plat_ipc_ops ops;
66a33c1ec5SJin Yao };
67a33c1ec5SJin Yao 
68*abf31feeSCezary Rojewski int sst_ipc_tx_message_wait(struct sst_generic_ipc *ipc,
69*abf31feeSCezary Rojewski 	struct sst_ipc_message request, struct sst_ipc_message *reply);
70a33c1ec5SJin Yao 
71*abf31feeSCezary Rojewski int sst_ipc_tx_message_nowait(struct sst_generic_ipc *ipc,
72*abf31feeSCezary Rojewski 	struct sst_ipc_message request);
73a33c1ec5SJin Yao 
74*abf31feeSCezary Rojewski int sst_ipc_tx_message_nopm(struct sst_generic_ipc *ipc,
75*abf31feeSCezary Rojewski 	struct sst_ipc_message request, struct sst_ipc_message *reply);
7680a0df18SVinod Koul 
77a33c1ec5SJin Yao struct ipc_message *sst_ipc_reply_find_msg(struct sst_generic_ipc *ipc,
78a33c1ec5SJin Yao 	u64 header);
79a33c1ec5SJin Yao 
80a33c1ec5SJin Yao void sst_ipc_tx_msg_reply_complete(struct sst_generic_ipc *ipc,
81a33c1ec5SJin Yao 	struct ipc_message *msg);
82a33c1ec5SJin Yao 
83a33c1ec5SJin Yao int sst_ipc_init(struct sst_generic_ipc *ipc);
84a33c1ec5SJin Yao void sst_ipc_fini(struct sst_generic_ipc *ipc);
85a33c1ec5SJin Yao 
86a33c1ec5SJin Yao #endif
87