1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2016 Intel Corporation. All rights reserved.
4  *
5  * Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
6  *         Keyon Jie <yang.jie@linux.intel.com>
7  */
8 
9 #ifndef __SOF_IPC_DRIVER_H__
10 #define __SOF_IPC_DRIVER_H__
11 
12 #include <sof/platform.h>
13 #include <rtos/sof.h>
14 #include <sof/ipc/common.h>
15 #include <rtos/task.h>
16 #include <stdbool.h>
17 #include <stdint.h>
18 
19 struct ipc_msg;
20 
21 /**
22  * \brief Provides platform specific IPC initialization.
23  * @param ipc Global IPC context
24  * @return 0 if succeeded, error code otherwise.
25  *
26  * This function must be implemented by the platform. It is called from the
27  * main IPC code, at the end of ipc_init().
28  *
29  * If the platform requires any private data to be associated with the IPC
30  * context, it may allocate it here and attach to the global context using
31  * ipc_set_drvdata(). Other platform specific IPC functions, like
32  * ipc_platform_do_cmd(), may obtain it later from the context using
33  * ipc_get_drvdata().
34  */
35 int platform_ipc_init(struct ipc *ipc);
36 
37 /**
38  * \brief Perform IPC command from host.
39  * @return The task state of the IPC command work.
40  */
41 enum task_state ipc_platform_do_cmd(struct ipc *ipc);
42 
43 /**
44  * \brief Tell host we have completed the last IPC command.
45  */
46 void ipc_platform_complete_cmd(struct ipc *ipc);
47 
48 /**
49  * \brief Send IPC message to host.
50  * @param msg The IPC message to send to host.
51  * @return 0 on success.
52  */
53 int ipc_platform_send_msg(const struct ipc_msg *msg);
54 
55 /**
56  * \brief Retrieves the ipc_data_host_buffer allocated by the platform ipc.
57  * @return Pointer to the data.
58  *
59  * This function must be implemented by platforms which use
60  * ipc...page_descriptors() while processing host page tables.
61  */
62 struct ipc_data_host_buffer *ipc_platform_get_host_buffer(struct ipc *ipc);
63 
64 /**
65  * \brief Read a compact IPC message from hardware.
66  * @param[in] hdr IPC header data
67  * @param[in] words Number of words to read in header.
68  * @return Number of word written.
69  */
70 int ipc_platform_compact_read_msg(struct ipc_cmd_hdr *hdr, int words);
71 
72 /**
73  * \brief Write a compact IPC message to hardware.
74  * @param[in] hdr Compact message header data.
75  * @param[in] words Number of words to be written from header.
76  * @return Number of word written.
77  */
78 int ipc_platform_compact_write_msg(struct ipc_cmd_hdr *hdr, int words);
79 
80 /**
81  * \brief Initialise IPC hardware for polling mode.
82  * @return 0 if successful error code otherwise.
83  */
84 int ipc_platform_poll_init(void);
85 
86 /**
87  * \brief Tell host DSP has completed command.
88  */
89 void ipc_platform_poll_set_cmd_done(void);
90 
91 /**
92  * \brief Check whether there is a new IPC command from host.
93  * @return 1 if new command is pending from host.
94  */
95 int ipc_platform_poll_is_cmd_pending(void);
96 
97 /**
98  * \brief Check whether host is ready for new IPC from DSP.
99  * @return 1 if host is ready for a new command from DSP.
100  */
101 int ipc_platform_poll_is_host_ready(void);
102 
103 /**
104  * \brief Transmit new message to host.
105  * @return 0 if successful error code otherwise.
106  */
107 int ipc_platform_poll_tx_host_msg(struct ipc_msg *msg);
108 
109 #endif
110