OSDN Git Service

Merge "cnss2: Add support for genoa sdio"
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / include / linux / qdsp6v2 / apr.h
1 /* Copyright (c) 2010-2017, 2019, 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
16 #include <linux/mutex.h>
17 #include <soc/qcom/subsystem_notif.h>
18
19 enum apr_subsys_state {
20         APR_SUBSYS_DOWN,
21         APR_SUBSYS_UP,
22         APR_SUBSYS_LOADED,
23 };
24
25 struct apr_q6 {
26         void *pil;
27         atomic_t q6_state;
28         atomic_t modem_state;
29         struct mutex lock;
30 };
31
32 struct apr_hdr {
33         uint16_t hdr_field;
34         uint16_t pkt_size;
35         uint8_t src_svc;
36         uint8_t src_domain;
37         uint16_t src_port;
38         uint8_t dest_svc;
39         uint8_t dest_domain;
40         uint16_t dest_port;
41         uint32_t token;
42         uint32_t opcode;
43 };
44
45 #define APR_HDR_LEN(hdr_len) ((hdr_len)/4)
46 #define APR_PKT_SIZE(hdr_len, payload_len) ((hdr_len) + (payload_len))
47 #define APR_HDR_FIELD(msg_type, hdr_len, ver)\
48         (((msg_type & 0x3) << 8) | ((hdr_len & 0xF) << 4) | (ver & 0xF))
49
50 #define APR_HDR_SIZE sizeof(struct apr_hdr)
51
52 /* Version */
53 #define APR_PKT_VER             0x0
54
55 /* Command and Response Types */
56 #define APR_MSG_TYPE_EVENT      0x0
57 #define APR_MSG_TYPE_CMD_RSP    0x1
58 #define APR_MSG_TYPE_SEQ_CMD    0x2
59 #define APR_MSG_TYPE_NSEQ_CMD   0x3
60 #define APR_MSG_TYPE_MAX        0x04
61
62 /* APR Basic Response Message */
63 #define APR_BASIC_RSP_RESULT 0x000110E8
64 #define APR_RSP_ACCEPTED     0x000100BE
65
66 /* Domain IDs */
67 #define APR_DOMAIN_SIM  0x1
68 #define APR_DOMAIN_PC           0x2
69 #define APR_DOMAIN_MODEM        0x3
70 #define APR_DOMAIN_ADSP 0x4
71 #define APR_DOMAIN_APPS 0x5
72 #define APR_DOMAIN_SDSP 0x8
73 #define APR_DOMAIN_MAX  0x9
74
75
76 /* ADSP service IDs */
77 #define APR_SVC_TEST_CLIENT     0x2
78 #define APR_SVC_ADSP_CORE       0x3
79 #define APR_SVC_AFE             0x4
80 #define APR_SVC_VSM             0x5
81 #define APR_SVC_VPM             0x6
82 #define APR_SVC_ASM             0x7
83 #define APR_SVC_ADM             0x8
84 #define APR_SVC_ADSP_MVM        0x09
85 #define APR_SVC_ADSP_CVS        0x0A
86 #define APR_SVC_ADSP_CVP        0x0B
87 #define APR_SVC_USM             0x0C
88 #define APR_SVC_LSM             0x0D
89 #define APR_SVC_VIDC            0x16
90 #define APR_SVC_MAX             0x17
91
92 /* Modem Service IDs */
93 #define APR_SVC_MVS             0x3
94 #define APR_SVC_MVM             0x4
95 #define APR_SVC_CVS             0x5
96 #define APR_SVC_CVP             0x6
97 #define APR_SVC_SRD             0x7
98
99 /* Sensor DSP Micro Audio Service IDs */
100 #define APR_SVC_MAS     0x3
101
102 /* APR Port IDs */
103 #define APR_MAX_PORTS           0x80
104
105 #define APR_NAME_MAX            0x40
106
107 #define RESET_EVENTS            0x000130D7
108
109 #define LPASS_RESTART_EVENT     0x1000
110 #define LPASS_RESTART_READY     0x1001
111
112 struct apr_client_data {
113         uint16_t reset_event;
114         uint16_t reset_proc;
115         uint16_t payload_size;
116         uint16_t hdr_len;
117         uint16_t msg_type;
118         uint16_t src;
119         uint16_t dest_svc;
120         uint16_t src_port;
121         uint16_t dest_port;
122         uint32_t token;
123         uint32_t opcode;
124         void *payload;
125 };
126
127 typedef int32_t (*apr_fn)(struct apr_client_data *data, void *priv);
128
129 struct apr_svc {
130         uint16_t id;
131         uint16_t dest_id;
132         uint16_t client_id;
133         uint16_t dest_domain;
134         uint8_t rvd;
135         uint8_t port_cnt;
136         uint8_t svc_cnt;
137         uint8_t need_reset;
138         apr_fn port_fn[APR_MAX_PORTS];
139         void *port_priv[APR_MAX_PORTS];
140         apr_fn fn;
141         void *priv;
142         struct mutex m_lock;
143         spinlock_t w_lock;
144         uint8_t pkt_owner;
145 #ifdef CONFIG_MSM_QDSP6_APRV2_VM
146         uint16_t vm_dest_svc;
147         uint32_t vm_handle;
148 #endif
149 };
150
151 struct apr_client {
152         uint8_t id;
153         uint8_t svc_cnt;
154         uint8_t rvd;
155         struct mutex m_lock;
156         struct apr_svc_ch_dev *handle;
157         struct apr_svc svc[APR_SVC_MAX];
158 };
159
160 struct apr_rx_intents {
161         int num_of_intents;
162         uint32_t size;
163 };
164
165 struct apr_pkt_cfg {
166         uint8_t pkt_owner;
167         struct apr_rx_intents intents;
168 };
169
170 int apr_load_adsp_image(void);
171 struct apr_client *apr_get_client(int dest_id, int client_id);
172 int apr_wait_for_device_up(int dest_id);
173 int apr_get_svc(const char *svc_name, int dest_id, int *client_id,
174                 int *svc_idx, int *svc_id);
175 void apr_cb_func(void *buf, int len, void *priv);
176 struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn,
177                                         uint32_t src_port, void *priv);
178 inline int apr_fill_hdr(void *handle, uint32_t *buf, uint16_t src_port,
179                         uint16_t msg_type, uint16_t dest_port,
180                         uint32_t token, uint32_t opcode, uint16_t len);
181
182 int apr_send_pkt(void *handle, uint32_t *buf);
183 int apr_deregister(void *handle);
184 void subsys_notif_register(char *client_name, int domain,
185                            struct notifier_block *nb);
186 int apr_get_dest_id(char *dest);
187 uint16_t apr_get_data_src(struct apr_hdr *hdr);
188 void change_q6_state(int state);
189 void q6audio_dsp_not_responding(void);
190 void apr_reset(void *handle);
191 enum apr_subsys_state apr_get_subsys_state(void);
192 enum apr_subsys_state apr_get_modem_state(void);
193 void apr_set_modem_state(enum apr_subsys_state state);
194 enum apr_subsys_state apr_get_q6_state(void);
195 int apr_set_q6_state(enum apr_subsys_state state);
196 void apr_set_subsys_state(void);
197 const char *apr_get_lpass_subsys_name(void);
198 uint16_t apr_get_reset_domain(uint16_t proc);
199 #ifdef CONFIG_MSM_QDSP6_APRV2_VM
200 static inline int apr_start_rx_rt(void *handle)
201 {
202         return 0;
203 }
204
205 static inline int apr_end_rx_rt(void *handle)
206 {
207         return 0;
208 }
209 #else
210 int apr_start_rx_rt(void *handle);
211 int apr_end_rx_rt(void *handle);
212 #endif
213 int apr_dummy_init(void);
214 void apr_dummy_exit(void);
215 #endif