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