1 /******************************************************************************* 2 * Copyright (C) 2018 Cadence Design Systems, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining 5 * a copy of this software and associated documentation files (the 6 * "Software"), to use this Software with Cadence processor cores only and 7 * not with any other processors and platforms, subject to 8 * the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included 11 * in all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 16 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 17 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 18 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 19 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21 ******************************************************************************/ 22 23 /******************************************************************************* 24 * xf-opcode.h 25 * 26 * Xtensa audio processing framework. Message API 27 * 28 ******************************************************************************/ 29 30 #ifndef __XF_H 31 #error "xf-opcode.h mustn't be included directly" 32 #endif 33 34 /******************************************************************************* 35 * Message routing composition - move somewhere else - tbd 36 ******************************************************************************/ 37 38 /* ...adjust IPC client of message going from user-space */ 39 #define XF_MSG_AP_FROM_USER(id, client) \ 40 (((id) & ~(0xF << 2)) | (client)) 41 42 /* ...wipe out IPC client from message going to user-space */ 43 #define XF_MSG_AP_TO_USER(id) \ 44 ((id) & ~(0xF << 18)) 45 46 /* ...port specification (12 bits) */ 47 #define __XF_PORT_SPEC(core, id, port) ((core) | ((id) << 2) | ((port) << 8)) 48 #define __XF_PORT_SPEC2(id, port) ((id) | ((port) << 8)) 49 #define XF_PORT_CORE(spec) ((spec) & 0x3) 50 #define XF_PORT_CLIENT(spec) (((spec) >> 2) & 0x3F) 51 #define XF_PORT_ID(spec) (((spec) >> 8) & 0xF) 52 53 /* ...message id contains source and destination ports specification */ 54 #define __XF_MSG_ID(src, dst) (((src) & 0xFFFF) | (((dst) & 0xFFFF) << 16)) 55 #define XF_MSG_SRC(id) (((id) >> 0) & 0xFFFF) 56 #define XF_MSG_SRC_CORE(id) (((id) >> 0) & 0x3) 57 #define XF_MSG_SRC_CLIENT(id) (((id) >> 2) & 0x3F) 58 #define XF_MSG_SRC_ID(id) (((id) >> 0) & 0xFF) 59 #define XF_MSG_SRC_PORT(id) (((id) >> 8) & 0xF) 60 #define XF_MSG_SRC_PROXY(id) (((id) >> 15) & 0x1) 61 #define XF_MSG_DST(id) (((id) >> 16) & 0xFFFF) 62 #define XF_MSG_DST_CORE(id) (((id) >> 16) & 0x3) 63 #define XF_MSG_DST_CLIENT(id) (((id) >> 18) & 0x3F) 64 #define XF_MSG_DST_ID(id) (((id) >> 16) & 0xFF) 65 #define XF_MSG_DST_PORT(id) (((id) >> 24) & 0xF) 66 #define XF_MSG_DST_PROXY(id) (((id) >> 31) & 0x1) 67 68 /* ...special treatment of AP-proxy destination field */ 69 #define XF_AP_IPC_CLIENT(id) (((id) >> 18) & 0xF) 70 #define XF_AP_CLIENT(id) (((id) >> 22) & 0x1FF) 71 #define __XF_AP_PROXY(core) ((core) | 0x8000) 72 #define __XF_DSP_PROXY(core) ((core) | 0x8000) 73 #define __XF_AP_CLIENT(core, client) ((core) | ((client) << 6) | 0x8000) 74 75 /* ...check if DSP message is shared between cores */ 76 #define XF_MSG_SHARED(id) \ 77 ({ u32 __id = (id); (XF_CFG_CORES_NUM > 1 ? (__id ^ (__id >> 16)) & 0x3 : 0); }) 78 79 /******************************************************************************* 80 * Opcode composition 81 ******************************************************************************/ 82 83 /* ...opcode composition with command/response data tags */ 84 #define __XF_OPCODE(c, r, op) (((c) << 31) | ((r) << 30) | ((op) & 0x3F)) 85 86 /* ...accessors */ 87 #define XF_OPCODE_CDATA(opcode) ((opcode) & (1 << 31)) 88 #define XF_OPCODE_RDATA(opcode) ((opcode) & (1 << 30)) 89 #define XF_OPCODE_TYPE(opcode) ((opcode) & (0x3F)) 90 91 /******************************************************************************* 92 * Opcode types 93 ******************************************************************************/ 94 95 /* ...unregister client */ 96 #define XF_UNREGISTER __XF_OPCODE(0, 0, 0) 97 98 /* ...register client at proxy */ 99 #define XF_REGISTER __XF_OPCODE(1, 0, 1) 100 101 /* ...port routing command */ 102 #define XF_ROUTE __XF_OPCODE(1, 0, 2) 103 104 /* ...port unrouting command */ 105 #define XF_UNROUTE __XF_OPCODE(1, 0, 3) 106 107 /* ...shared buffer allocation */ 108 #define XF_ALLOC __XF_OPCODE(0, 0, 4) 109 110 /* ...shared buffer freeing */ 111 #define XF_FREE __XF_OPCODE(0, 0, 5) 112 113 /* ...set component parameters */ 114 #define XF_SET_PARAM __XF_OPCODE(1, 0, 6) 115 116 /* ...get component parameters */ 117 #define XF_GET_PARAM __XF_OPCODE(1, 1, 7) 118 119 /* ...input buffer reception */ 120 #define XF_EMPTY_THIS_BUFFER __XF_OPCODE(1, 0, 8) 121 122 /* ...output buffer reception */ 123 #define XF_FILL_THIS_BUFFER __XF_OPCODE(0, 1, 9) 124 125 /* ...flush specific port */ 126 #define XF_FLUSH __XF_OPCODE(0, 0, 10) 127 128 /* ...start component operation */ 129 #define XF_START __XF_OPCODE(0, 0, 11) 130 131 /* ...stop component operation */ 132 #define XF_STOP __XF_OPCODE(0, 0, 12) 133 134 /* ...pause component operation */ 135 #define XF_PAUSE __XF_OPCODE(0, 0, 13) 136 137 /* ...resume component operation */ 138 #define XF_RESUME __XF_OPCODE(0, 0, 14) 139 140 /* ...extended parameter setting function */ 141 #define XF_SET_PARAM_EXT __XF_OPCODE(1, 1, 15) 142 143 /* ...extended parameter retrieval function */ 144 #define XF_GET_PARAM_EXT __XF_OPCODE(1, 1, 16) 145 146 /* ...total amount of supported decoder commands */ 147 #define __XF_OP_NUM 17 148 149 /******************************************************************************* 150 * XF_START message definition 151 ******************************************************************************/ 152 153 typedef struct xf_start_msg 154 { 155 /* ...effective sample rate */ 156 u32 sample_rate; 157 158 /* ...number of channels */ 159 u32 channels; 160 161 /* ...sample width */ 162 u32 pcm_width; 163 164 /* ...minimal size of intput buffer */ 165 u32 input_length; 166 167 /* ...size of output buffer */ 168 u32 output_length; 169 170 } __attribute__((__packed__)) xf_start_msg_t; 171 172 /******************************************************************************* 173 * XF_GET_PARAM message 174 ******************************************************************************/ 175 176 /* ...message body (command/response) */ 177 typedef union xf_get_param_msg 178 { 179 /* ...command structure */ 180 struct 181 { 182 /* ...array of parameters requested */ 183 u32 id[0]; 184 185 } __attribute__((__packed__)) c; 186 187 /* ...response structure */ 188 struct 189 { 190 /* ...array of parameters values */ 191 u32 value[0]; 192 193 } __attribute__((__packed__)) r; 194 195 } xf_get_param_msg_t; 196 197 /* ...length of the XF_GET_PARAM command/response */ 198 #define XF_GET_PARAM_CMD_LEN(params) (sizeof(u32) * (params)) 199 #define XF_GET_PARAM_RSP_LEN(params) (sizeof(u32) * (params)) 200 201 /******************************************************************************* 202 * XF_SET_PARAM message 203 ******************************************************************************/ 204 205 /* ...component initialization parameter */ 206 typedef struct xf_set_param_item 207 { 208 /* ...index of parameter passed to SET_CONFIG_PARAM call */ 209 u32 id; 210 211 /* ...value of parameter */ 212 u32 value; 213 214 } __attribute__ ((__packed__)) xf_set_param_item_t; 215 216 /* ...message body (no response message? - tbd) */ 217 typedef struct xf_set_param_msg 218 { 219 /* ...command message */ 220 xf_set_param_item_t item[0]; 221 222 } __attribute__ ((__packed__)) xf_set_param_msg_t; 223 224 /* ...length of the command message */ 225 #define XF_SET_PARAM_CMD_LEN(params) (sizeof(xf_set_param_item_t) * (params)) 226 227 /******************************************************************************* 228 * XF_SET_PARAM_EXT/XF_GET_PARAM_EXT message 229 ******************************************************************************/ 230 231 /* ...extended parameter descriptor */ 232 typedef struct xf_ext_param_desc 233 { 234 /* ...index of parameter passed to SET/GET_CONFIG_PARAM call (16-bits only) */ 235 u16 id; 236 237 /* ...length of embedded input/output parameter data (in bytes) */ 238 u16 length; 239 240 } __attribute__ ((__packed__, __aligned__(4))) xf_ext_param_desc_t; 241 242 /* ...message body (no response message? - tbd) */ 243 typedef struct xf_ext_param_msg 244 { 245 /* ...extended parameter descriptor */ 246 xf_ext_param_desc_t desc; 247 248 /* ...parameter data (in the format expected by codec; 4 bytes aligned) */ 249 u8 data[0]; 250 251 } __attribute__ ((__packed__, __aligned__(4))) xf_ext_param_msg_t; 252 253 /******************************************************************************* 254 * XF_ROUTE definition 255 ******************************************************************************/ 256 257 /* ...port routing command */ 258 typedef struct xf_route_port_msg 259 { 260 /* ...source port specification */ 261 u32 src; 262 263 /* ...destination port specification */ 264 u32 dst; 265 266 /* ...number of buffers to allocate */ 267 u32 alloc_number; 268 269 /* ...length of buffer to allocate */ 270 u32 alloc_size; 271 272 /* ...alignment restriction for a buffer */ 273 u32 alloc_align; 274 275 } __attribute__((__packed__)) xf_route_port_msg_t; 276 277 /******************************************************************************* 278 * XF_UNROUTE definition 279 ******************************************************************************/ 280 281 /* ...port unrouting command */ 282 typedef struct xf_unroute_port_msg 283 { 284 /* ...source port specification */ 285 u32 src; 286 287 /* ...destination port specification */ 288 u32 dst; 289 290 } __attribute__((__packed__)) xf_unroute_port_msg_t; 291