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