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-shmem.h 25 * 26 * Definitions for Xtensa SHMEM configuration 27 * 28 *******************************************************************************/ 29 30 #ifndef __XF_H 31 #error "xf-shmem.h mustn't be included directly" 32 #endif 33 34 /******************************************************************************* 35 * Memory structures 36 ******************************************************************************/ 37 38 /* ...data managed by host CPU (remote) - in case of shunt it is a IPC layer */ 39 struct xf_proxy_host_data 40 { 41 /* ...command queue */ 42 xf_proxy_message_t command[XF_PROXY_MESSAGE_QUEUE_LENGTH]; 43 44 /* ...writing index into command queue */ 45 u32 cmd_write_idx; 46 47 /* ...reading index for response queue */ 48 u32 rsp_read_idx; 49 #ifdef XAF_ENABLE_NON_HIKEY 50 } __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT))); 51 #else 52 }/* __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT)))*/; 53 #endif 54 55 /* ...data managed by DSP (local) */ 56 struct xf_proxy_dsp_data 57 { 58 /* ...response queue */ 59 xf_proxy_message_t response[XF_PROXY_MESSAGE_QUEUE_LENGTH]; 60 61 /* ...writing index into response queue */ 62 u32 rsp_write_idx; 63 64 /* ...reading index for command queue */ 65 u32 cmd_read_idx; 66 #ifdef XAF_ENABLE_NON_HIKEY 67 } __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT))); 68 #else 69 }/* __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT)))*/; 70 #endif 71 /* ...shared memory data */ 72 typedef struct xf_shmem_data 73 { 74 /* ...outgoing data (maintained by host CPU (remote side)) */ 75 #ifdef XAF_ENABLE_NON_HIKEY 76 struct xf_proxy_host_data remote __xf_shmem__; 77 78 /* ...ingoing data (maintained by DSP (local side)) */ 79 struct xf_proxy_dsp_data local __xf_shmem__; 80 81 /* ...shared memory pool (page-aligned; why? we map memory to user-space) */ 82 u8 buffer[XF_CFG_REMOTE_IPC_POOL_SIZE] __attribute__((__aligned__(4096))); 83 #else 84 /* ...outgoing data (maintained by host CPU (remote side)) */ 85 struct xf_proxy_host_data remote/* __xf_shmem__*/; 86 87 /* ...ingoing data (maintained by DSP (local side)) */ 88 struct xf_proxy_dsp_data local/* __xf_shmem__*/; 89 90 /* ...shared memory pool (page-aligned; why? we map memory to user-space) */ 91 uint8_t* buffer; 92 #endif 93 94 } xf_shmem_data_t; 95 96 /******************************************************************************* 97 * Shared memory accessors 98 ******************************************************************************/ 99 100 /* ...shared memory pointer for a core */ 101 #define XF_SHMEM_DATA(core) \ 102 ((xf_shmem_data_t *)XF_CORE_DATA(core)->shmem) 103 104 /* ...atomic reading */ 105 #define XF_PROXY_READ_ATOMIC(var) \ 106 ({ XF_PROXY_INVALIDATE(&(var), sizeof(var)); (var); }) 107 108 /* ...atomic writing */ 109 #define XF_PROXY_WRITE_ATOMIC(var, value) \ 110 ({(var) = (value); XF_PROXY_FLUSH(&(var), sizeof(var)); (value); }) 111 112 /* ...accessors */ 113 #define XF_PROXY_READ(core, field) \ 114 __XF_PROXY_READ_##field(XF_SHMEM_DATA(core)) 115 116 #define XF_PROXY_WRITE(core, field, v) \ 117 __XF_PROXY_WRITE_##field(XF_SHMEM_DATA(core), (v)) 118 119 /* ...individual fields accessors */ 120 #define __XF_PROXY_READ_cmd_write_idx(proxy) \ 121 XF_PROXY_READ_ATOMIC(proxy->remote.cmd_write_idx) 122 123 #define __XF_PROXY_READ_cmd_read_idx(proxy) \ 124 proxy->local.cmd_read_idx 125 126 #define __XF_PROXY_READ_rsp_write_idx(proxy) \ 127 proxy->local.rsp_write_idx 128 129 #define __XF_PROXY_READ_rsp_read_idx(proxy) \ 130 XF_PROXY_READ_ATOMIC(proxy->remote.rsp_read_idx) 131 132 /* ...individual fields accessors */ 133 #define __XF_PROXY_WRITE_cmd_write_idx(proxy, v) \ 134 XF_PROXY_WRITE_ATOMIC(proxy->remote.cmd_write_idx, v) 135 136 #define __XF_PROXY_WRITE_cmd_read_idx(proxy, v) \ 137 XF_PROXY_WRITE_ATOMIC(proxy->local.cmd_read_idx, v) 138 139 #define __XF_PROXY_WRITE_rsp_read_idx(proxy, v) \ 140 XF_PROXY_WRITE_ATOMIC(proxy->remote.rsp_read_idx, v) 141 142 #define __XF_PROXY_WRITE_rsp_write_idx(proxy, v) \ 143 XF_PROXY_WRITE_ATOMIC(proxy->local.rsp_write_idx, v) 144 145 /* ...command buffer accessor */ 146 #define XF_PROXY_COMMAND(core, idx) \ 147 (&XF_SHMEM_DATA((core))->remote.command[(idx)]) 148 149 /* ...response buffer accessor */ 150 #define XF_PROXY_RESPONSE(core, idx) \ 151 (&XF_SHMEM_DATA((core))->local.response[(idx)]) 152 153 /******************************************************************************* 154 * Platform-specific SHMEM enable status 155 ******************************************************************************/ 156 157 static inline int xf_shmem_enabled(u32 core) 158 { 159 return (core == 0); 160 } 161 162 /******************************************************************************* 163 * API functions 164 ******************************************************************************/ 165 166 /* ...process shared memory interface on given DSP core */ 167 extern void xf_shmem_process_queues(u32 core); 168 169 /* ...completion callback for message originating from remote proxy */ 170 extern void xf_msg_proxy_complete(xf_message_t *m); 171 172 /* ...initialize shared memory interface (DSP side) */ 173 extern int xf_shmem_init(u32 core); 174