1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
6 #ifndef IOSM_IPC_PROTOCOL_H
7 #define IOSM_IPC_PROTOCOL_H
9 #include "iosm_ipc_imem.h"
10 #include "iosm_ipc_pm.h"
11 #include "iosm_ipc_protocol_ops.h"
13 /* Trigger the doorbell interrupt on CP. */
14 #define IPC_DOORBELL_IRQ_HPDA 0
15 #define IPC_DOORBELL_IRQ_IPC 1
16 #define IPC_DOORBELL_IRQ_SLEEP 2
18 /* IRQ vector number. */
19 #define IPC_DEVICE_IRQ_VECTOR 0
20 #define IPC_MSG_IRQ_VECTOR 0
21 #define IPC_UL_PIPE_IRQ_VECTOR 0
22 #define IPC_DL_PIPE_IRQ_VECTOR 0
24 #define IPC_MEM_MSG_ENTRIES 128
26 /* Default time out for sending IPC messages like open pipe, close pipe etc.
29 * If the message interface lock to CP times out, the link to CP is broken.
30 * mode : run mode (IPC_MEM_EXEC_STAGE_RUN)
33 #define IPC_MSG_COMPLETE_RUN_DEFAULT_TIMEOUT 500 /* 0.5 seconds */
35 /* Default time out for sending IPC messages like open pipe, close pipe etc.
38 * If the message interface lock to CP times out, the link to CP is broken.
40 * (IPC_MEM_EXEC_STAGE_BOOT | IPC_MEM_EXEC_STAGE_PSI | IPC_MEM_EXEC_STAGE_EBL)
43 #define IPC_MSG_COMPLETE_BOOT_DEFAULT_TIMEOUT 500 /* 0.5 seconds */
46 * struct ipc_protocol_context_info - Structure of the context info
47 * @device_info_addr: 64 bit address to device info
48 * @head_array: 64 bit address to head pointer arr for the pipes
49 * @tail_array: 64 bit address to tail pointer arr for the pipes
50 * @msg_head: 64 bit address to message head pointer
51 * @msg_tail: 64 bit address to message tail pointer
52 * @msg_ring_addr: 64 bit pointer to the message ring buffer
53 * @msg_ring_entries: This field provides the number of entries which
55 * @msg_irq_vector: This field provides the IRQ which shall be
56 * generated by the EP device when generating
57 * completion for Messages.
58 * @device_info_irq_vector: This field provides the IRQ which shall be
59 * generated by the EP dev after updating Dev. Info
61 struct ipc_protocol_context_info {
62 phys_addr_t device_info_addr;
63 phys_addr_t head_array;
64 phys_addr_t tail_array;
67 phys_addr_t msg_ring_addr;
68 __le16 msg_ring_entries;
70 u8 device_info_irq_vector;
74 * struct ipc_protocol_device_info - Structure for the device information
75 * @execution_stage: CP execution stage
76 * @ipc_status: IPC states
77 * @device_sleep_notification: Requested device pm states
79 struct ipc_protocol_device_info {
80 __le32 execution_stage;
82 __le32 device_sleep_notification;
86 * struct ipc_protocol_ap_shm - Protocol Shared Memory Structure
87 * @ci: Context information struct
88 * @device_info: Device information struct
89 * @msg_head: Point to msg head
90 * @head_array: Array of head pointer
91 * @msg_tail: Point to msg tail
92 * @tail_array: Array of tail pointer
93 * @msg_ring: Circular buffers for the read/tail and write/head
96 struct ipc_protocol_ap_shm {
97 struct ipc_protocol_context_info ci;
98 struct ipc_protocol_device_info device_info;
100 __le32 head_array[IPC_MEM_MAX_PIPES];
102 __le32 tail_array[IPC_MEM_MAX_PIPES];
103 union ipc_mem_msg_entry msg_ring[IPC_MEM_MSG_ENTRIES];
107 * struct iosm_protocol - Structure for IPC protocol.
108 * @p_ap_shm: Pointer to Protocol Shared Memory Structure
109 * @pm: Instance to struct iosm_pm
110 * @pcie: Pointer to struct iosm_pcie
111 * @imem: Pointer to struct iosm_imem
112 * @rsp_ring: Array of OS completion objects to be triggered once CP
113 * acknowledges a request in the message ring
114 * @dev: Pointer to device structure
115 * @phy_ap_shm: Physical/Mapped representation of the shared memory info
116 * @old_msg_tail: Old msg tail ptr, until AP has handled ACK's from CP
118 struct iosm_protocol {
119 struct ipc_protocol_ap_shm *p_ap_shm;
121 struct iosm_pcie *pcie;
122 struct iosm_imem *imem;
123 struct ipc_rsp *rsp_ring[IPC_MEM_MSG_ENTRIES];
125 phys_addr_t phy_ap_shm;
130 * struct ipc_call_msg_send_args - Structure for message argument for
132 * @prep_args: Arguments for message preparation function
133 * @response: Can be NULL if result can be ignored
134 * @msg_type: Message Type
136 struct ipc_call_msg_send_args {
137 union ipc_msg_prep_args *prep_args;
138 struct ipc_rsp *response;
139 enum ipc_msg_prep_type msg_type;
143 * ipc_protocol_tq_msg_send - prepare the msg and send to CP
144 * @ipc_protocol: Pointer to ipc_protocol instance
145 * @msg_type: Message type
146 * @prep_args: Message arguments
147 * @response: Pointer to a response object which has a
148 * completion object and return code.
150 * Returns: 0 on success and failure value on error
152 int ipc_protocol_tq_msg_send(struct iosm_protocol *ipc_protocol,
153 enum ipc_msg_prep_type msg_type,
154 union ipc_msg_prep_args *prep_args,
155 struct ipc_rsp *response);
158 * ipc_protocol_msg_send - Send ipc control message to CP and wait for response
159 * @ipc_protocol: Pointer to ipc_protocol instance
160 * @prep: Message type
161 * @prep_args: Message arguments
163 * Returns: 0 on success and failure value on error
165 int ipc_protocol_msg_send(struct iosm_protocol *ipc_protocol,
166 enum ipc_msg_prep_type prep,
167 union ipc_msg_prep_args *prep_args);
170 * ipc_protocol_suspend - Signal to CP that host wants to go to sleep (suspend).
171 * @ipc_protocol: Pointer to ipc_protocol instance
173 * Returns: true if host can suspend, false if suspend must be aborted.
175 bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol);
178 * ipc_protocol_s2idle_sleep - Call PM function to set PM variables in s2idle
180 * @ipc_protocol: Pointer to ipc_protocol instance
181 * @sleep: True for sleep/False for active
183 void ipc_protocol_s2idle_sleep(struct iosm_protocol *ipc_protocol, bool sleep);
186 * ipc_protocol_resume - Signal to CP that host wants to resume operation.
187 * @ipc_protocol: Pointer to ipc_protocol instance
189 * Returns: true if host can resume, false if there is a problem.
191 bool ipc_protocol_resume(struct iosm_protocol *ipc_protocol);
194 * ipc_protocol_pm_dev_sleep_handle - Handles the Device Sleep state change
196 * @ipc_protocol: Pointer to ipc_protocol instance.
198 * Returns: true if sleep notification handled, false otherwise.
200 bool ipc_protocol_pm_dev_sleep_handle(struct iosm_protocol *ipc_protocol);
203 * ipc_protocol_doorbell_trigger - Wrapper for PM function which wake up the
204 * device if it is in low power mode
205 * and trigger a head pointer update interrupt.
206 * @ipc_protocol: Pointer to ipc_protocol instance.
207 * @identifier: Specifies what component triggered hpda
210 void ipc_protocol_doorbell_trigger(struct iosm_protocol *ipc_protocol,
214 * ipc_protocol_sleep_notification_string - Returns last Sleep Notification as
216 * @ipc_protocol: Instance pointer of Protocol module.
218 * Returns: Pointer to string.
221 ipc_protocol_sleep_notification_string(struct iosm_protocol *ipc_protocol);
224 * ipc_protocol_init - Allocates IPC protocol instance
225 * @ipc_imem: Pointer to iosm_imem structure
227 * Returns: Address of IPC protocol instance on success & NULL on failure.
229 struct iosm_protocol *ipc_protocol_init(struct iosm_imem *ipc_imem);
232 * ipc_protocol_deinit - Deallocates IPC protocol instance
233 * @ipc_protocol: pointer to the IPC protocol instance
235 void ipc_protocol_deinit(struct iosm_protocol *ipc_protocol);