iosm_ipc_protocol.h 7.5 KB

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