apr.h 4.7 KB

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