Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / sound / soc / intel / common / sst-ipc.h
1 /*
2  * Intel SST generic IPC Support
3  *
4  * Copyright (C) 2015, Intel Corporation. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version
8  * 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  */
16
17 #ifndef __SST_GENERIC_IPC_H
18 #define __SST_GENERIC_IPC_H
19
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/wait.h>
23 #include <linux/list.h>
24 #include <linux/workqueue.h>
25 #include <linux/sched.h>
26 #include <linux/kthread.h>
27
28 #define IPC_MAX_MAILBOX_BYTES   256
29
30 struct ipc_message {
31         struct list_head list;
32         u64 header;
33
34         /* direction wrt host CPU */
35         char tx_data[IPC_MAX_MAILBOX_BYTES];
36         size_t tx_size;
37         char rx_data[IPC_MAX_MAILBOX_BYTES];
38         size_t rx_size;
39
40         wait_queue_head_t waitq;
41         bool pending;
42         bool complete;
43         bool wait;
44         int errno;
45 };
46
47 struct sst_generic_ipc;
48
49 struct sst_plat_ipc_ops {
50         void (*tx_msg)(struct sst_generic_ipc *, struct ipc_message *);
51         void (*shim_dbg)(struct sst_generic_ipc *, const char *);
52         void (*tx_data_copy)(struct ipc_message *, char *, size_t);
53         u64  (*reply_msg_match)(u64 header, u64 *mask);
54 };
55
56 /* SST generic IPC data */
57 struct sst_generic_ipc {
58         struct device *dev;
59         struct sst_dsp *dsp;
60
61         /* IPC messaging */
62         struct list_head tx_list;
63         struct list_head rx_list;
64         struct list_head empty_list;
65         wait_queue_head_t wait_txq;
66         struct task_struct *tx_thread;
67         struct kthread_worker kworker;
68         struct kthread_work kwork;
69         bool pending;
70         struct ipc_message *msg;
71
72         struct sst_plat_ipc_ops ops;
73 };
74
75 int sst_ipc_tx_message_wait(struct sst_generic_ipc *ipc, u64 header,
76         void *tx_data, size_t tx_bytes, void *rx_data, size_t rx_bytes);
77
78 int sst_ipc_tx_message_nowait(struct sst_generic_ipc *ipc, u64 header,
79         void *tx_data, size_t tx_bytes);
80
81 struct ipc_message *sst_ipc_reply_find_msg(struct sst_generic_ipc *ipc,
82         u64 header);
83
84 void sst_ipc_tx_msg_reply_complete(struct sst_generic_ipc *ipc,
85         struct ipc_message *msg);
86
87 void sst_ipc_drop_all(struct sst_generic_ipc *ipc);
88 int sst_ipc_init(struct sst_generic_ipc *ipc);
89 void sst_ipc_fini(struct sst_generic_ipc *ipc);
90
91 #endif