blob: 0ef27b965080f933680a4007d1cfe7ddc50467b2 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* arch/arm/mach-msm/qdsp5/adsp.h
2 *
3 * Copyright (C) 2008 Google, Inc.
4 * Copyright (c) 2008-2010, Code Aurora Forum. All rights reserved.
5 * Author: Iliyan Malchev <ibm@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18#ifndef _ARCH_ARM_MACH_MSM_ADSP_H
19#define _ARCH_ARM_MACH_MSM_ADSP_H
20
21#include <linux/types.h>
22#include <linux/msm_adsp.h>
23#include <mach/msm_rpcrouter.h>
24#include <mach/msm_adsp.h>
25
26int adsp_pmem_fixup(struct msm_adsp_module *module, void **addr,
27 unsigned long len);
28int adsp_pmem_fixup_kvaddr(struct msm_adsp_module *module, void **addr,
29 unsigned long *kvaddr, unsigned long len,
30 struct file **filp, unsigned long *offset);
31int adsp_pmem_paddr_fixup(struct msm_adsp_module *module, void **addr);
32
33int adsp_vfe_verify_cmd(struct msm_adsp_module *module,
34 unsigned int queue_id, void *cmd_data,
35 size_t cmd_size);
36int adsp_jpeg_verify_cmd(struct msm_adsp_module *module,
37 unsigned int queue_id, void *cmd_data,
38 size_t cmd_size);
39int adsp_lpm_verify_cmd(struct msm_adsp_module *module,
40 unsigned int queue_id, void *cmd_data,
41 size_t cmd_size);
42int adsp_video_verify_cmd(struct msm_adsp_module *module,
43 unsigned int queue_id, void *cmd_data,
44 size_t cmd_size);
45int adsp_videoenc_verify_cmd(struct msm_adsp_module *module,
46 unsigned int queue_id, void *cmd_data,
47 size_t cmd_size);
Laxminath Kasam1a461112010-11-15 12:17:26 +053048void q5audio_dsp_not_responding(void);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049
50struct adsp_event;
51
52int adsp_vfe_patch_event(struct msm_adsp_module *module,
53 struct adsp_event *event);
54
55int adsp_jpeg_patch_event(struct msm_adsp_module *module,
56 struct adsp_event *event);
57
58
59struct adsp_module_info {
60 const char *name;
61 const char *pdev_name;
62 uint32_t id;
63 const char *clk_name;
64 unsigned long clk_rate;
65 int (*verify_cmd) (struct msm_adsp_module*, unsigned int, void *,
66 size_t);
67 int (*patch_event) (struct msm_adsp_module*, struct adsp_event *);
68};
69
70#define ADSP_EVENT_MAX_SIZE 496
71#define EVENT_LEN 12
72#define EVENT_MSG_ID ((uint16_t)~0)
73
74struct adsp_event {
75 struct list_head list;
76 uint32_t size; /* always in bytes */
77 uint16_t msg_id;
78 uint16_t type; /* 0 for msgs (from aDSP), -1 for events (from ARM9) */
79 int is16; /* always 0 (msg is 32-bit) when the event type is 1(ARM9) */
80 union {
81 uint16_t msg16[ADSP_EVENT_MAX_SIZE / 2];
82 uint32_t msg32[ADSP_EVENT_MAX_SIZE / 4];
83 } data;
84};
85
86struct adsp_info {
87 uint32_t send_irq;
88 uint32_t read_ctrl;
89 uint32_t write_ctrl;
90
91 uint32_t max_msg16_size;
92 uint32_t max_msg32_size;
93
94 uint32_t max_task_id;
95 uint32_t max_module_id;
96 uint32_t max_queue_id;
97 uint32_t max_image_id;
98
99 /* for each image id, a map of queue id to offset */
100 uint32_t **queue_offset;
101
102 /* for each image id, a map of task id to module id */
103 uint32_t **task_to_module;
104
105 /* for each module id, map of module id to module */
106 struct msm_adsp_module **id_to_module;
107
108 uint32_t module_count;
109 struct adsp_module_info *module;
110
111 /* stats */
112 uint32_t events_received;
113 uint32_t event_backlog_max;
114
115 /* rpc_client for init_info */
116 struct msm_rpc_endpoint *init_info_rpc_client;
117 struct adsp_rtos_mp_mtoa_init_info_type *init_info_ptr;
118 wait_queue_head_t init_info_wait;
119 unsigned init_info_state;
120};
121
122#define RPC_ADSP_RTOS_ATOM_NULL_PROC 0
123#define RPC_ADSP_RTOS_MTOA_NULL_PROC 0
124#define RPC_ADSP_RTOS_APP_TO_MODEM_PROC 2
125#define RPC_ADSP_RTOS_MODEM_TO_APP_PROC 2
126#define RPC_ADSP_RTOS_MTOA_EVENT_INFO_PROC 3
127#define RPC_ADSP_RTOS_MTOA_INIT_INFO_PROC 4
128
129enum rpc_adsp_rtos_proc_type {
130 RPC_ADSP_RTOS_PROC_NONE = 0,
131 RPC_ADSP_RTOS_PROC_MODEM = 1,
132 RPC_ADSP_RTOS_PROC_APPS = 2,
133};
134
135enum {
136 RPC_ADSP_RTOS_CMD_REGISTER_APP,
137 RPC_ADSP_RTOS_CMD_ENABLE,
138 RPC_ADSP_RTOS_CMD_DISABLE,
139 RPC_ADSP_RTOS_CMD_KERNEL_COMMAND,
140 RPC_ADSP_RTOS_CMD_16_COMMAND,
141 RPC_ADSP_RTOS_CMD_32_COMMAND,
142 RPC_ADSP_RTOS_CMD_DISABLE_EVENT_RSP,
143 RPC_ADSP_RTOS_CMD_REMOTE_EVENT,
144 RPC_ADSP_RTOS_CMD_SET_STATE,
145 RPC_ADSP_RTOS_CMD_REMOTE_INIT_INFO_EVENT,
146 RPC_ADSP_RTOS_CMD_GET_INIT_INFO,
147};
148
149enum rpc_adsp_rtos_mod_status_type {
150 RPC_ADSP_RTOS_MOD_READY,
151 RPC_ADSP_RTOS_MOD_DISABLE,
152 RPC_ADSP_RTOS_SERVICE_RESET,
153 RPC_ADSP_RTOS_CMD_FAIL,
154 RPC_ADSP_RTOS_CMD_SUCCESS,
155 RPC_ADSP_RTOS_INIT_INFO,
156 RPC_ADSP_RTOS_DISABLE_FAIL,
157};
158
159struct rpc_adsp_rtos_app_to_modem_args_t {
160 struct rpc_request_hdr hdr;
161 uint32_t gotit; /* if 1, the next elements are present */
162 uint32_t cmd; /* e.g., RPC_ADSP_RTOS_CMD_REGISTER_APP */
163 uint32_t proc_id; /* e.g., RPC_ADSP_RTOS_PROC_APPS */
164 uint32_t module; /* e.g., QDSP_MODULE_AUDPPTASK */
165};
166
167enum qdsp_image_type {
168 QDSP_IMAGE_COMBO,
169 QDSP_IMAGE_GAUDIO,
170 QDSP_IMAGE_QTV_LP,
171 QDSP_IMAGE_MAX,
172 /* DO NOT USE: Force this enum to be a 32bit type to improve speed */
173 QDSP_IMAGE_32BIT_DUMMY = 0x10000
174};
175
176struct adsp_rtos_mp_mtoa_header_type {
177 enum rpc_adsp_rtos_mod_status_type event;
178 enum rpc_adsp_rtos_proc_type proc_id;
179};
180
181/* ADSP RTOS MP Communications - Modem to APP's Event Info*/
182struct adsp_rtos_mp_mtoa_type {
183 uint32_t module;
184 uint32_t image;
185 uint32_t apps_okts;
186};
187
188/* ADSP RTOS MP Communications - Modem to APP's Init Info */
189#if CONFIG_ADSP_RPC_VER > 0x30001
190#define IMG_MAX 2
191#define ENTRIES_MAX 36
192#define MODULES_MAX 64
193#else
194#define IMG_MAX 6
195#define ENTRIES_MAX 48
196#endif
197#define QUEUES_MAX 64
198
199struct queue_to_offset_type {
200 uint32_t queue;
201 uint32_t offset;
202};
203
204struct mod_to_queue_offsets {
205 uint32_t module;
206 uint32_t q_type;
207 uint32_t q_max_len;
208};
209
210struct adsp_rtos_mp_mtoa_init_info_type {
211 uint32_t image_count;
212 uint32_t num_queue_offsets;
213 struct queue_to_offset_type queue_offsets_tbl[IMG_MAX][ENTRIES_MAX];
214 uint32_t num_task_module_entries;
215 uint32_t task_to_module_tbl[IMG_MAX][ENTRIES_MAX];
216
217 uint32_t module_table_size;
218#if CONFIG_ADSP_RPC_VER > 0x30001
219 uint32_t module_entries[MODULES_MAX];
220#else
221 uint32_t module_entries[ENTRIES_MAX];
222#endif
223 uint32_t mod_to_q_entries;
224 struct mod_to_queue_offsets mod_to_q_tbl[ENTRIES_MAX];
225 /*
226 * queue_offsets[] is to store only queue_offsets
227 */
228 uint32_t queue_offsets[IMG_MAX][QUEUES_MAX];
229};
230
231struct adsp_rtos_mp_mtoa_s_type {
232 struct adsp_rtos_mp_mtoa_header_type mp_mtoa_header;
233#if CONFIG_ADSP_RPC_VER == 0x30001
234 uint32_t desc_field;
235#endif
236 union {
237 struct adsp_rtos_mp_mtoa_init_info_type mp_mtoa_init_packet;
238 struct adsp_rtos_mp_mtoa_type mp_mtoa_packet;
239 } adsp_rtos_mp_mtoa_data;
240};
241
242struct rpc_adsp_rtos_modem_to_app_args_t {
243 struct rpc_request_hdr hdr;
244 uint32_t gotit; /* if 1, the next elements are present */
245 struct adsp_rtos_mp_mtoa_s_type mtoa_pkt;
246};
247
248#define ADSP_STATE_DISABLED 0
249#define ADSP_STATE_ENABLING 1
250#define ADSP_STATE_ENABLED 2
251#define ADSP_STATE_DISABLING 3
252#define ADSP_STATE_INIT_INFO 4
253
254struct msm_adsp_module {
255 struct mutex lock;
256 const char *name;
257 unsigned id;
258 struct adsp_info *info;
259
260 struct msm_rpc_endpoint *rpc_client;
261 struct msm_adsp_ops *ops;
262 void *driver_data;
263
264 /* statistics */
265 unsigned num_commands;
266 unsigned num_events;
267
268 wait_queue_head_t state_wait;
269 unsigned state;
270
271 struct platform_device pdev;
272 struct clk *clk;
273 int open_count;
274
275 struct mutex pmem_regions_lock;
276 struct hlist_head pmem_regions;
277 int (*verify_cmd) (struct msm_adsp_module*, unsigned int, void *,
278 size_t);
279 int (*patch_event) (struct msm_adsp_module*, struct adsp_event *);
280};
281
282extern void msm_adsp_publish_cdevs(struct msm_adsp_module *, unsigned);
283extern int adsp_init_info(struct adsp_info *info);
284extern void rmtask_init(void);
285
286/* Value to indicate that a queue is not defined for a particular image */
287#define QDSP_RTOS_NO_QUEUE 0xfffffffe
288
289/*
290 * Constants used to communicate with the ADSP RTOS
291 */
292#define ADSP_RTOS_WRITE_CTRL_WORD_MUTEX_M 0x80000000U
293#define ADSP_RTOS_WRITE_CTRL_WORD_MUTEX_NAVAIL_V 0x80000000U
294#define ADSP_RTOS_WRITE_CTRL_WORD_MUTEX_AVAIL_V 0x00000000U
295
296#define ADSP_RTOS_WRITE_CTRL_WORD_CMD_M 0x70000000U
297#define ADSP_RTOS_WRITE_CTRL_WORD_CMD_WRITE_REQ_V 0x00000000U
298#define ADSP_RTOS_WRITE_CTRL_WORD_CMD_WRITE_DONE_V 0x10000000U
299#define ADSP_RTOS_WRITE_CTRL_WORD_CMD_NO_CMD_V 0x70000000U
300
301#define ADSP_RTOS_WRITE_CTRL_WORD_STATUS_M 0x0E000000U
302#define ADSP_RTOS_WRITE_CTRL_WORD_NO_ERR_V 0x00000000U
303#define ADSP_RTOS_WRITE_CTRL_WORD_NO_FREE_BUF_V 0x02000000U
304
305#define ADSP_RTOS_WRITE_CTRL_WORD_KERNEL_FLG_M 0x01000000U
306#define ADSP_RTOS_WRITE_CTRL_WORD_HTOD_MSG_WRITE_V 0x00000000U
307#define ADSP_RTOS_WRITE_CTRL_WORD_HTOD_CMD_V 0x01000000U
308
309#define ADSP_RTOS_WRITE_CTRL_WORD_DSP_ADDR_M 0x00FFFFFFU
310#define ADSP_RTOS_WRITE_CTRL_WORD_HTOD_CMD_ID_M 0x00FFFFFFU
311
312/* Combination of MUTEX and CMD bits to check if the DSP is busy */
313#define ADSP_RTOS_WRITE_CTRL_WORD_READY_M 0xF0000000U
314#define ADSP_RTOS_WRITE_CTRL_WORD_READY_V 0x70000000U
315
316/* RTOS to Host processor command mask values */
317#define ADSP_RTOS_READ_CTRL_WORD_FLAG_M 0x80000000U
318#define ADSP_RTOS_READ_CTRL_WORD_FLAG_UP_WAIT_V 0x00000000U
319#define ADSP_RTOS_READ_CTRL_WORD_FLAG_UP_CONT_V 0x80000000U
320
321#define ADSP_RTOS_READ_CTRL_WORD_CMD_M 0x60000000U
322#define ADSP_RTOS_READ_CTRL_WORD_READ_DONE_V 0x00000000U
323#define ADSP_RTOS_READ_CTRL_WORD_READ_REQ_V 0x20000000U
324#define ADSP_RTOS_READ_CTRL_WORD_NO_CMD_V 0x60000000U
325
326/* Combination of FLAG and COMMAND bits to check if MSG ready */
327#define ADSP_RTOS_READ_CTRL_WORD_READY_M 0xE0000000U
328#define ADSP_RTOS_READ_CTRL_WORD_READY_V 0xA0000000U
329#define ADSP_RTOS_READ_CTRL_WORD_CONT_V 0xC0000000U
330#define ADSP_RTOS_READ_CTRL_WORD_DONE_V 0xE0000000U
331
332#define ADSP_RTOS_READ_CTRL_WORD_STATUS_M 0x18000000U
333#define ADSP_RTOS_READ_CTRL_WORD_NO_ERR_V 0x00000000U
334
335#define ADSP_RTOS_READ_CTRL_WORD_IN_PROG_M 0x04000000U
336#define ADSP_RTOS_READ_CTRL_WORD_NO_READ_IN_PROG_V 0x00000000U
337#define ADSP_RTOS_READ_CTRL_WORD_READ_IN_PROG_V 0x04000000U
338
339#define ADSP_RTOS_READ_CTRL_WORD_CMD_TYPE_M 0x03000000U
340#define ADSP_RTOS_READ_CTRL_WORD_CMD_TASK_TO_H_V 0x00000000U
341#define ADSP_RTOS_READ_CTRL_WORD_CMD_KRNL_TO_H_V 0x01000000U
342#define ADSP_RTOS_READ_CTRL_WORD_CMD_H_TO_KRNL_CFM_V 0x02000000U
343
344#define ADSP_RTOS_READ_CTRL_WORD_DSP_ADDR_M 0x00FFFFFFU
345
346#define ADSP_RTOS_READ_CTRL_WORD_MSG_ID_M 0x000000FFU
347#define ADSP_RTOS_READ_CTRL_WORD_TASK_ID_M 0x0000FF00U
348
349/* Base address of DSP and DSP hardware registers */
350#define QDSP_RAMC_OFFSET 0x400000
351
352#endif