apr.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2010-2017, 2019, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef __APR_H_
  6. #define __APR_H_
  7. #include <linux/mutex.h>
  8. #include <soc/qcom/subsystem_notif.h>
  9. enum apr_subsys_state {
  10. APR_SUBSYS_DOWN,
  11. APR_SUBSYS_UP,
  12. APR_SUBSYS_LOADED,
  13. };
  14. struct apr_q6 {
  15. void *pil;
  16. atomic_t q6_state;
  17. atomic_t modem_state;
  18. struct mutex lock;
  19. };
  20. struct apr_hdr {
  21. uint16_t hdr_field;
  22. uint16_t pkt_size;
  23. uint8_t src_svc;
  24. uint8_t src_domain;
  25. uint16_t src_port;
  26. uint8_t dest_svc;
  27. uint8_t dest_domain;
  28. uint16_t dest_port;
  29. uint32_t token;
  30. uint32_t opcode;
  31. };
  32. #define APR_HDR_LEN(hdr_len) ((hdr_len)/4)
  33. #define APR_PKT_SIZE(hdr_len, payload_len) ((hdr_len) + (payload_len))
  34. #define APR_HDR_FIELD(msg_type, hdr_len, ver)\
  35. (((msg_type & 0x3) << 8) | ((hdr_len & 0xF) << 4) | (ver & 0xF))
  36. #define APR_HDR_SIZE sizeof(struct apr_hdr)
  37. /* Version */
  38. #define APR_PKT_VER 0x0
  39. /* Command and Response Types */
  40. #define APR_MSG_TYPE_EVENT 0x0
  41. #define APR_MSG_TYPE_CMD_RSP 0x1
  42. #define APR_MSG_TYPE_SEQ_CMD 0x2
  43. #define APR_MSG_TYPE_NSEQ_CMD 0x3
  44. #define APR_MSG_TYPE_MAX 0x04
  45. /* APR Basic Response Message */
  46. #define APR_BASIC_RSP_RESULT 0x000110E8
  47. #define APR_RSP_ACCEPTED 0x000100BE
  48. /* Domain IDs */
  49. #define APR_DOMAIN_SIM 0x1
  50. #define APR_DOMAIN_PC 0x2
  51. #define APR_DOMAIN_MODEM 0x3
  52. #define APR_DOMAIN_ADSP 0x4
  53. #define APR_DOMAIN_APPS 0x5
  54. #define APR_DOMAIN_MAX 0x6
  55. /* ADSP service IDs */
  56. #define APR_SVC_TEST_CLIENT 0x2
  57. #define APR_SVC_ADSP_CORE 0x3
  58. #define APR_SVC_AFE 0x4
  59. #define APR_SVC_VSM 0x5
  60. #define APR_SVC_VPM 0x6
  61. #define APR_SVC_ASM 0x7
  62. #define APR_SVC_ADM 0x8
  63. #define APR_SVC_ADSP_MVM 0x09
  64. #define APR_SVC_ADSP_CVS 0x0A
  65. #define APR_SVC_ADSP_CVP 0x0B
  66. #define APR_SVC_USM 0x0C
  67. #define APR_SVC_LSM 0x0D
  68. #define APR_SVC_VIDC 0x16
  69. #define APR_SVC_MAX 0x17
  70. /* Modem Service IDs */
  71. #define APR_SVC_MVS 0x3
  72. #define APR_SVC_MVM 0x4
  73. #define APR_SVC_CVS 0x5
  74. #define APR_SVC_CVP 0x6
  75. #define APR_SVC_SRD 0x7
  76. /* APR Port IDs */
  77. #define APR_MAX_PORTS 0x80
  78. #define APR_NAME_MAX 0x40
  79. #define RESET_EVENTS 0x000130D7
  80. #define LPASS_RESTART_EVENT 0x1000
  81. #define LPASS_RESTART_READY 0x1001
  82. struct apr_client_data {
  83. uint16_t reset_event;
  84. uint16_t reset_proc;
  85. uint16_t payload_size;
  86. uint16_t hdr_len;
  87. uint16_t msg_type;
  88. uint16_t src;
  89. uint16_t dest_svc;
  90. uint16_t src_port;
  91. uint16_t dest_port;
  92. uint32_t token;
  93. uint32_t opcode;
  94. void *payload;
  95. };
  96. typedef int32_t (*apr_fn)(struct apr_client_data *data, void *priv);
  97. struct apr_svc {
  98. uint16_t id;
  99. uint16_t dest_id;
  100. uint16_t client_id;
  101. uint16_t dest_domain;
  102. uint8_t rvd;
  103. uint8_t port_cnt;
  104. uint8_t svc_cnt;
  105. uint8_t need_reset;
  106. apr_fn port_fn[APR_MAX_PORTS];
  107. void *port_priv[APR_MAX_PORTS];
  108. apr_fn fn;
  109. void *priv;
  110. struct mutex m_lock;
  111. spinlock_t w_lock;
  112. uint8_t pkt_owner;
  113. #ifdef CONFIG_MSM_QDSP6_APRV2_VM
  114. uint16_t vm_dest_svc;
  115. uint32_t vm_handle;
  116. #endif
  117. };
  118. struct apr_client {
  119. uint8_t id;
  120. uint8_t svc_cnt;
  121. uint8_t rvd;
  122. struct mutex m_lock;
  123. struct apr_svc_ch_dev *handle;
  124. struct apr_svc svc[APR_SVC_MAX];
  125. };
  126. struct apr_rx_intents {
  127. int num_of_intents;
  128. uint32_t size;
  129. };
  130. struct apr_pkt_cfg {
  131. uint8_t pkt_owner;
  132. struct apr_rx_intents intents;
  133. };
  134. int apr_load_adsp_image(void);
  135. struct apr_client *apr_get_client(int dest_id, int client_id);
  136. int apr_wait_for_device_up(int dest_id);
  137. int apr_get_svc(const char *svc_name, int dest_id, int *client_id,
  138. int *svc_idx, int *svc_id);
  139. void apr_cb_func(void *buf, int len, void *priv);
  140. struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn,
  141. uint32_t src_port, void *priv);
  142. inline int apr_fill_hdr(void *handle, uint32_t *buf, uint16_t src_port,
  143. uint16_t msg_type, uint16_t dest_port,
  144. uint32_t token, uint32_t opcode, uint16_t len);
  145. int apr_send_pkt(void *handle, uint32_t *buf);
  146. int apr_deregister(void *handle);
  147. void subsys_notif_register(char *client_name, int domain,
  148. struct notifier_block *nb);
  149. void subsys_notif_deregister(char *client_name);
  150. int apr_get_dest_id(char *dest);
  151. uint16_t apr_get_data_src(struct apr_hdr *hdr);
  152. void change_q6_state(int state);
  153. void q6audio_dsp_not_responding(void);
  154. void apr_reset(void *handle);
  155. enum apr_subsys_state apr_get_subsys_state(void);
  156. enum apr_subsys_state apr_get_modem_state(void);
  157. void apr_set_modem_state(enum apr_subsys_state state);
  158. enum apr_subsys_state apr_get_q6_state(void);
  159. int apr_set_q6_state(enum apr_subsys_state state);
  160. void apr_set_subsys_state(void);
  161. const char *apr_get_lpass_subsys_name(void);
  162. uint16_t apr_get_reset_domain(uint16_t proc);
  163. int apr_start_rx_rt(void *handle);
  164. int apr_end_rx_rt(void *handle);
  165. #endif