Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* arch/arm/mach-msm/qdsp5/adsp.h |
| 2 | * |
| 3 | * Copyright (C) 2008 Google, Inc. |
Manish Dewangan | 691f1c4 | 2012-02-10 12:50:14 +0530 | [diff] [blame] | 4 | * Copyright (c) 2008-2010, 2012 Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 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 | |
| 26 | int adsp_pmem_fixup(struct msm_adsp_module *module, void **addr, |
| 27 | unsigned long len); |
| 28 | int 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); |
| 31 | int adsp_pmem_paddr_fixup(struct msm_adsp_module *module, void **addr); |
| 32 | |
| 33 | int adsp_vfe_verify_cmd(struct msm_adsp_module *module, |
| 34 | unsigned int queue_id, void *cmd_data, |
| 35 | size_t cmd_size); |
| 36 | int adsp_jpeg_verify_cmd(struct msm_adsp_module *module, |
| 37 | unsigned int queue_id, void *cmd_data, |
| 38 | size_t cmd_size); |
| 39 | int adsp_lpm_verify_cmd(struct msm_adsp_module *module, |
| 40 | unsigned int queue_id, void *cmd_data, |
| 41 | size_t cmd_size); |
| 42 | int adsp_video_verify_cmd(struct msm_adsp_module *module, |
| 43 | unsigned int queue_id, void *cmd_data, |
| 44 | size_t cmd_size); |
| 45 | int adsp_videoenc_verify_cmd(struct msm_adsp_module *module, |
| 46 | unsigned int queue_id, void *cmd_data, |
| 47 | size_t cmd_size); |
Laxminath Kasam | 1a46111 | 2010-11-15 12:17:26 +0530 | [diff] [blame] | 48 | void q5audio_dsp_not_responding(void); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 49 | |
| 50 | struct adsp_event; |
| 51 | |
| 52 | int adsp_vfe_patch_event(struct msm_adsp_module *module, |
| 53 | struct adsp_event *event); |
| 54 | |
| 55 | int adsp_jpeg_patch_event(struct msm_adsp_module *module, |
| 56 | struct adsp_event *event); |
| 57 | |
| 58 | |
| 59 | struct 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 | |
| 74 | struct 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 | |
| 86 | struct 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; |
Manish Dewangan | 691f1c4 | 2012-02-10 12:50:14 +0530 | [diff] [blame] | 120 | struct mutex lock; |
Laxminath Kasam | 34aea16 | 2012-02-15 12:21:49 +0530 | [diff] [blame] | 121 | |
| 122 | /* Interrupt value */ |
| 123 | int int_adsp; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | #define RPC_ADSP_RTOS_ATOM_NULL_PROC 0 |
| 127 | #define RPC_ADSP_RTOS_MTOA_NULL_PROC 0 |
| 128 | #define RPC_ADSP_RTOS_APP_TO_MODEM_PROC 2 |
| 129 | #define RPC_ADSP_RTOS_MODEM_TO_APP_PROC 2 |
| 130 | #define RPC_ADSP_RTOS_MTOA_EVENT_INFO_PROC 3 |
| 131 | #define RPC_ADSP_RTOS_MTOA_INIT_INFO_PROC 4 |
| 132 | |
| 133 | enum rpc_adsp_rtos_proc_type { |
| 134 | RPC_ADSP_RTOS_PROC_NONE = 0, |
| 135 | RPC_ADSP_RTOS_PROC_MODEM = 1, |
| 136 | RPC_ADSP_RTOS_PROC_APPS = 2, |
| 137 | }; |
| 138 | |
| 139 | enum { |
| 140 | RPC_ADSP_RTOS_CMD_REGISTER_APP, |
| 141 | RPC_ADSP_RTOS_CMD_ENABLE, |
| 142 | RPC_ADSP_RTOS_CMD_DISABLE, |
| 143 | RPC_ADSP_RTOS_CMD_KERNEL_COMMAND, |
| 144 | RPC_ADSP_RTOS_CMD_16_COMMAND, |
| 145 | RPC_ADSP_RTOS_CMD_32_COMMAND, |
| 146 | RPC_ADSP_RTOS_CMD_DISABLE_EVENT_RSP, |
| 147 | RPC_ADSP_RTOS_CMD_REMOTE_EVENT, |
| 148 | RPC_ADSP_RTOS_CMD_SET_STATE, |
| 149 | RPC_ADSP_RTOS_CMD_REMOTE_INIT_INFO_EVENT, |
| 150 | RPC_ADSP_RTOS_CMD_GET_INIT_INFO, |
| 151 | }; |
| 152 | |
| 153 | enum rpc_adsp_rtos_mod_status_type { |
| 154 | RPC_ADSP_RTOS_MOD_READY, |
| 155 | RPC_ADSP_RTOS_MOD_DISABLE, |
| 156 | RPC_ADSP_RTOS_SERVICE_RESET, |
| 157 | RPC_ADSP_RTOS_CMD_FAIL, |
| 158 | RPC_ADSP_RTOS_CMD_SUCCESS, |
| 159 | RPC_ADSP_RTOS_INIT_INFO, |
| 160 | RPC_ADSP_RTOS_DISABLE_FAIL, |
| 161 | }; |
| 162 | |
| 163 | struct rpc_adsp_rtos_app_to_modem_args_t { |
| 164 | struct rpc_request_hdr hdr; |
| 165 | uint32_t gotit; /* if 1, the next elements are present */ |
| 166 | uint32_t cmd; /* e.g., RPC_ADSP_RTOS_CMD_REGISTER_APP */ |
| 167 | uint32_t proc_id; /* e.g., RPC_ADSP_RTOS_PROC_APPS */ |
| 168 | uint32_t module; /* e.g., QDSP_MODULE_AUDPPTASK */ |
| 169 | }; |
| 170 | |
| 171 | enum qdsp_image_type { |
| 172 | QDSP_IMAGE_COMBO, |
| 173 | QDSP_IMAGE_GAUDIO, |
| 174 | QDSP_IMAGE_QTV_LP, |
| 175 | QDSP_IMAGE_MAX, |
| 176 | /* DO NOT USE: Force this enum to be a 32bit type to improve speed */ |
| 177 | QDSP_IMAGE_32BIT_DUMMY = 0x10000 |
| 178 | }; |
| 179 | |
| 180 | struct adsp_rtos_mp_mtoa_header_type { |
| 181 | enum rpc_adsp_rtos_mod_status_type event; |
| 182 | enum rpc_adsp_rtos_proc_type proc_id; |
| 183 | }; |
| 184 | |
| 185 | /* ADSP RTOS MP Communications - Modem to APP's Event Info*/ |
| 186 | struct adsp_rtos_mp_mtoa_type { |
| 187 | uint32_t module; |
| 188 | uint32_t image; |
| 189 | uint32_t apps_okts; |
| 190 | }; |
| 191 | |
| 192 | /* ADSP RTOS MP Communications - Modem to APP's Init Info */ |
| 193 | #if CONFIG_ADSP_RPC_VER > 0x30001 |
| 194 | #define IMG_MAX 2 |
| 195 | #define ENTRIES_MAX 36 |
| 196 | #define MODULES_MAX 64 |
| 197 | #else |
| 198 | #define IMG_MAX 6 |
| 199 | #define ENTRIES_MAX 48 |
| 200 | #endif |
| 201 | #define QUEUES_MAX 64 |
| 202 | |
| 203 | struct queue_to_offset_type { |
| 204 | uint32_t queue; |
| 205 | uint32_t offset; |
| 206 | }; |
| 207 | |
| 208 | struct mod_to_queue_offsets { |
| 209 | uint32_t module; |
| 210 | uint32_t q_type; |
| 211 | uint32_t q_max_len; |
| 212 | }; |
| 213 | |
| 214 | struct adsp_rtos_mp_mtoa_init_info_type { |
| 215 | uint32_t image_count; |
| 216 | uint32_t num_queue_offsets; |
| 217 | struct queue_to_offset_type queue_offsets_tbl[IMG_MAX][ENTRIES_MAX]; |
| 218 | uint32_t num_task_module_entries; |
| 219 | uint32_t task_to_module_tbl[IMG_MAX][ENTRIES_MAX]; |
| 220 | |
| 221 | uint32_t module_table_size; |
| 222 | #if CONFIG_ADSP_RPC_VER > 0x30001 |
| 223 | uint32_t module_entries[MODULES_MAX]; |
| 224 | #else |
| 225 | uint32_t module_entries[ENTRIES_MAX]; |
| 226 | #endif |
| 227 | uint32_t mod_to_q_entries; |
| 228 | struct mod_to_queue_offsets mod_to_q_tbl[ENTRIES_MAX]; |
| 229 | /* |
| 230 | * queue_offsets[] is to store only queue_offsets |
| 231 | */ |
| 232 | uint32_t queue_offsets[IMG_MAX][QUEUES_MAX]; |
| 233 | }; |
| 234 | |
| 235 | struct adsp_rtos_mp_mtoa_s_type { |
| 236 | struct adsp_rtos_mp_mtoa_header_type mp_mtoa_header; |
| 237 | #if CONFIG_ADSP_RPC_VER == 0x30001 |
| 238 | uint32_t desc_field; |
| 239 | #endif |
| 240 | union { |
| 241 | struct adsp_rtos_mp_mtoa_init_info_type mp_mtoa_init_packet; |
| 242 | struct adsp_rtos_mp_mtoa_type mp_mtoa_packet; |
| 243 | } adsp_rtos_mp_mtoa_data; |
| 244 | }; |
| 245 | |
| 246 | struct rpc_adsp_rtos_modem_to_app_args_t { |
| 247 | struct rpc_request_hdr hdr; |
| 248 | uint32_t gotit; /* if 1, the next elements are present */ |
| 249 | struct adsp_rtos_mp_mtoa_s_type mtoa_pkt; |
| 250 | }; |
| 251 | |
| 252 | #define ADSP_STATE_DISABLED 0 |
| 253 | #define ADSP_STATE_ENABLING 1 |
| 254 | #define ADSP_STATE_ENABLED 2 |
| 255 | #define ADSP_STATE_DISABLING 3 |
| 256 | #define ADSP_STATE_INIT_INFO 4 |
| 257 | |
| 258 | struct msm_adsp_module { |
| 259 | struct mutex lock; |
| 260 | const char *name; |
| 261 | unsigned id; |
| 262 | struct adsp_info *info; |
| 263 | |
| 264 | struct msm_rpc_endpoint *rpc_client; |
| 265 | struct msm_adsp_ops *ops; |
| 266 | void *driver_data; |
| 267 | |
| 268 | /* statistics */ |
| 269 | unsigned num_commands; |
| 270 | unsigned num_events; |
| 271 | |
| 272 | wait_queue_head_t state_wait; |
| 273 | unsigned state; |
| 274 | |
| 275 | struct platform_device pdev; |
| 276 | struct clk *clk; |
| 277 | int open_count; |
| 278 | |
| 279 | struct mutex pmem_regions_lock; |
| 280 | struct hlist_head pmem_regions; |
| 281 | int (*verify_cmd) (struct msm_adsp_module*, unsigned int, void *, |
| 282 | size_t); |
| 283 | int (*patch_event) (struct msm_adsp_module*, struct adsp_event *); |
| 284 | }; |
| 285 | |
| 286 | extern void msm_adsp_publish_cdevs(struct msm_adsp_module *, unsigned); |
| 287 | extern int adsp_init_info(struct adsp_info *info); |
| 288 | extern void rmtask_init(void); |
| 289 | |
| 290 | /* Value to indicate that a queue is not defined for a particular image */ |
| 291 | #define QDSP_RTOS_NO_QUEUE 0xfffffffe |
| 292 | |
| 293 | /* |
| 294 | * Constants used to communicate with the ADSP RTOS |
| 295 | */ |
| 296 | #define ADSP_RTOS_WRITE_CTRL_WORD_MUTEX_M 0x80000000U |
| 297 | #define ADSP_RTOS_WRITE_CTRL_WORD_MUTEX_NAVAIL_V 0x80000000U |
| 298 | #define ADSP_RTOS_WRITE_CTRL_WORD_MUTEX_AVAIL_V 0x00000000U |
| 299 | |
| 300 | #define ADSP_RTOS_WRITE_CTRL_WORD_CMD_M 0x70000000U |
| 301 | #define ADSP_RTOS_WRITE_CTRL_WORD_CMD_WRITE_REQ_V 0x00000000U |
| 302 | #define ADSP_RTOS_WRITE_CTRL_WORD_CMD_WRITE_DONE_V 0x10000000U |
| 303 | #define ADSP_RTOS_WRITE_CTRL_WORD_CMD_NO_CMD_V 0x70000000U |
| 304 | |
| 305 | #define ADSP_RTOS_WRITE_CTRL_WORD_STATUS_M 0x0E000000U |
| 306 | #define ADSP_RTOS_WRITE_CTRL_WORD_NO_ERR_V 0x00000000U |
| 307 | #define ADSP_RTOS_WRITE_CTRL_WORD_NO_FREE_BUF_V 0x02000000U |
| 308 | |
| 309 | #define ADSP_RTOS_WRITE_CTRL_WORD_KERNEL_FLG_M 0x01000000U |
| 310 | #define ADSP_RTOS_WRITE_CTRL_WORD_HTOD_MSG_WRITE_V 0x00000000U |
| 311 | #define ADSP_RTOS_WRITE_CTRL_WORD_HTOD_CMD_V 0x01000000U |
| 312 | |
| 313 | #define ADSP_RTOS_WRITE_CTRL_WORD_DSP_ADDR_M 0x00FFFFFFU |
| 314 | #define ADSP_RTOS_WRITE_CTRL_WORD_HTOD_CMD_ID_M 0x00FFFFFFU |
| 315 | |
| 316 | /* Combination of MUTEX and CMD bits to check if the DSP is busy */ |
| 317 | #define ADSP_RTOS_WRITE_CTRL_WORD_READY_M 0xF0000000U |
| 318 | #define ADSP_RTOS_WRITE_CTRL_WORD_READY_V 0x70000000U |
| 319 | |
| 320 | /* RTOS to Host processor command mask values */ |
| 321 | #define ADSP_RTOS_READ_CTRL_WORD_FLAG_M 0x80000000U |
| 322 | #define ADSP_RTOS_READ_CTRL_WORD_FLAG_UP_WAIT_V 0x00000000U |
| 323 | #define ADSP_RTOS_READ_CTRL_WORD_FLAG_UP_CONT_V 0x80000000U |
| 324 | |
| 325 | #define ADSP_RTOS_READ_CTRL_WORD_CMD_M 0x60000000U |
| 326 | #define ADSP_RTOS_READ_CTRL_WORD_READ_DONE_V 0x00000000U |
| 327 | #define ADSP_RTOS_READ_CTRL_WORD_READ_REQ_V 0x20000000U |
| 328 | #define ADSP_RTOS_READ_CTRL_WORD_NO_CMD_V 0x60000000U |
| 329 | |
| 330 | /* Combination of FLAG and COMMAND bits to check if MSG ready */ |
| 331 | #define ADSP_RTOS_READ_CTRL_WORD_READY_M 0xE0000000U |
| 332 | #define ADSP_RTOS_READ_CTRL_WORD_READY_V 0xA0000000U |
| 333 | #define ADSP_RTOS_READ_CTRL_WORD_CONT_V 0xC0000000U |
| 334 | #define ADSP_RTOS_READ_CTRL_WORD_DONE_V 0xE0000000U |
| 335 | |
| 336 | #define ADSP_RTOS_READ_CTRL_WORD_STATUS_M 0x18000000U |
| 337 | #define ADSP_RTOS_READ_CTRL_WORD_NO_ERR_V 0x00000000U |
| 338 | |
| 339 | #define ADSP_RTOS_READ_CTRL_WORD_IN_PROG_M 0x04000000U |
| 340 | #define ADSP_RTOS_READ_CTRL_WORD_NO_READ_IN_PROG_V 0x00000000U |
| 341 | #define ADSP_RTOS_READ_CTRL_WORD_READ_IN_PROG_V 0x04000000U |
| 342 | |
| 343 | #define ADSP_RTOS_READ_CTRL_WORD_CMD_TYPE_M 0x03000000U |
| 344 | #define ADSP_RTOS_READ_CTRL_WORD_CMD_TASK_TO_H_V 0x00000000U |
| 345 | #define ADSP_RTOS_READ_CTRL_WORD_CMD_KRNL_TO_H_V 0x01000000U |
| 346 | #define ADSP_RTOS_READ_CTRL_WORD_CMD_H_TO_KRNL_CFM_V 0x02000000U |
| 347 | |
| 348 | #define ADSP_RTOS_READ_CTRL_WORD_DSP_ADDR_M 0x00FFFFFFU |
| 349 | |
| 350 | #define ADSP_RTOS_READ_CTRL_WORD_MSG_ID_M 0x000000FFU |
| 351 | #define ADSP_RTOS_READ_CTRL_WORD_TASK_ID_M 0x0000FF00U |
| 352 | |
| 353 | /* Base address of DSP and DSP hardware registers */ |
| 354 | #define QDSP_RAMC_OFFSET 0x400000 |
| 355 | |
| 356 | #endif |