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