• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef __XF_H
24 #error  "xf-proxy.h mustn't be included directly"
25 #endif
26 
27 /*******************************************************************************
28  * User-message description - move from here to API - tbd
29  ******************************************************************************/
30 
31 /* ...need that at all? hope no */
32 struct xf_user_msg
33 {
34     /* ...source component specification */
35     u32             id;
36 
37     /* ...message opcode */
38     u32             opcode;
39 
40     /* ...buffer length */
41     u32             length;
42 
43     /* ...buffer pointer */
44     void           *buffer;
45 };
46 
47 /* ...proxy message - bad placing of that thing here - tbd */
48 struct xf_proxy_msg
49 {
50     /* ...session-id field */
51     uint32_t             id;
52 
53     /* ...message opcode */
54     uint32_t             opcode;
55 
56     /* ...buffer length */
57     uint32_t             length;
58 
59     /* ...buffer pointer */
60     uint64_t             address;
61     uint64_t         v_address;
62 
63 }   __attribute__((__packed__));
64 
65 typedef struct xf_proxy_msg_driv
66 {
67     /* ...session ID */
68     uint32_t                 id;
69 
70     /* ...proxy API command/reponse code */
71     uint32_t                 opcode;
72 
73     /* ...length of attached buffer */
74     uint32_t                 length;
75 
76     /* ...physical address of message buffer */
77     uint64_t                 address;
78     uint64_t                 v_address;
79 
80 }__attribute__((__packed__)) xf_proxy_message_driv_t;
81 /*******************************************************************************
82  * Buffer pools
83  ******************************************************************************/
84 
85 /* ...buffer pool type */
86 enum xf_pool_type
87 {
88     XF_POOL_AUX = 0,
89     XF_POOL_INPUT = 1,
90     XF_POOL_OUTPUT = 2
91 };
92 
93 /* ...buffer link pointer */
94 typedef union xf_buffer_link
95 {
96     /* ...pointer to next free buffer in a pool (for free buffer) */
97     xf_buffer_t        *next;
98 
99     /* ...reference to a buffer pool (for allocated buffer) */
100     xf_pool_t          *pool;
101 
102 }   xf_buffer_link_t;
103 
104 /* ...buffer descriptor */
105 struct xf_buffer
106 {
107     /* ...virtual address of contiguous buffer */
108     void               *address;
109 
110     /* ...link pointer */
111     xf_buffer_link_t    link;
112 };
113 
114 /* ...buffer pool */
115 struct xf_pool
116 {
117     /* ...reference to proxy data */
118     xf_proxy_t         *proxy;
119 
120     /* ...length of individual buffer in a pool */
121     u32                 length;
122 
123     /* ...number of buffers in a pool */
124     u32                 number;
125 
126     /* ...pointer to pool memory */
127     void               *p;
128 
129     /* ...pointer to first free buffer in a pool */
130     xf_buffer_t        *free;
131 
132     /* ...individual buffers */
133     xf_buffer_t         buffer[0];
134 };
135 
136 /* ...accessor to buffer data */
xf_buffer_data(xf_buffer_t * buffer)137 static inline void * xf_buffer_data(xf_buffer_t *buffer)
138 {
139     return buffer->address;
140 }
141 
142 /* ...length of buffer data */
xf_buffer_length(xf_buffer_t * buffer)143 static inline size_t xf_buffer_length(xf_buffer_t *buffer)
144 {
145     return buffer->link.pool->length;
146 }
147 
148 /*******************************************************************************
149  * Proxy handle definition
150  ******************************************************************************/
151 
152 /* ...free clients list */
153 typedef union xf_proxy_cmap_link
154 {
155     /* ...index of next free client in the list */
156     u32                     next;
157 
158     /* ...pointer to allocated component handle */
159     xf_handle_t            *handle;
160 
161 }   xf_proxy_cmap_link_t;
162 
163 /* ...proxy data structure */
164 struct xf_proxy
165 {
166     /* ...platform-specific IPC data */
167     xf_proxy_ipc_data_t     ipc;
168 
169     /* ...auxiliary buffer pool for clients */
170     xf_pool_t              *aux;
171 
172     /* ...global proxy lock */
173     xf_lock_t               lock;
174 
175     /* ...proxy thread handle */
176     xf_thread_t             thread;
177 
178     /* ...proxy identifier (core of remote DSP hosting SHMEM interface) */
179     u32                     core;
180 
181     /* ...client association map */
182     xf_proxy_cmap_link_t    cmap[XF_CFG_PROXY_MAX_CLIENTS];
183 };
184 
185 /*******************************************************************************
186  * Auxiliary proxy helpers
187  ******************************************************************************/
188 
189 /* ...get proxy identifier */
xf_proxy_id(xf_proxy_t * proxy)190 static inline u32 xf_proxy_id(xf_proxy_t *proxy)
191 {
192     return proxy->core;
193 }
194 
195 /* ...lock proxy data */
xf_proxy_lock(xf_proxy_t * proxy)196 static inline void xf_proxy_lock(xf_proxy_t *proxy)
197 {
198     __xf_lock(&proxy->lock);
199 }
200 
201 /* ...unlock proxy data */
xf_proxy_unlock(xf_proxy_t * proxy)202 static inline void xf_proxy_unlock(xf_proxy_t *proxy)
203 {
204     __xf_unlock(&proxy->lock);
205 }
206 
207 /* ...translate proxy shared address into local virtual address */
xf_proxy_a2b(xf_proxy_t * proxy,u32 address)208 static inline void * xf_proxy_a2b(xf_proxy_t *proxy, u32 address)
209 {
210     return xf_ipc_a2b(&proxy->ipc, address);
211 }
212 
213 /* ...translate local virtual address into shared proxy address */
xf_proxy_b2a(xf_proxy_t * proxy,void * b)214 static inline u32 xf_proxy_b2a(xf_proxy_t *proxy, void *b)
215 {
216     return xf_ipc_b2a(&proxy->ipc, b);
217 }
218 
219 /* ...submit asynchronous response message */
xf_proxy_response_put(xf_proxy_t * proxy,xf_proxy_msg_t * msg)220 static inline int xf_proxy_response_put(xf_proxy_t *proxy, xf_proxy_msg_t *msg)
221 {
222     return xf_proxy_ipc_response_put(&proxy->ipc, msg);
223 }
224 
225 /* ...retrieve asynchronous response message */
xf_proxy_response_get(xf_proxy_t * proxy,xf_proxy_msg_t * msg)226 static inline int xf_proxy_response_get(xf_proxy_t *proxy, xf_proxy_msg_t *msg)
227 {
228     return xf_proxy_ipc_response_get(&proxy->ipc, msg);
229 }
230 
231 /*******************************************************************************
232  * Component handle definition
233  ******************************************************************************/
234 
235 struct xf_handle
236 {
237     /* ...platform-specific IPC data */
238     xf_ipc_data_t           ipc;
239 
240     /* ...reference to proxy data */
241     xf_proxy_t             *proxy;
242 
243     /* ...component lock */
244     xf_lock_t               lock;
245 
246     /* ...auxiliary control buffer for control transactions */
247     xf_buffer_t            *aux;
248 
249     /* ...global client-id of the component */
250     u32                     id;
251 
252     /* ...local client number (think about merging into "id" field - tbd) */
253     u32                     client;
254 
255     /* ...response processing hook */
256     xf_response_cb          response;
257 };
258 
259 /*******************************************************************************
260  * Auxiliary component helpers
261  ******************************************************************************/
262 
263 /* ...component client-id (global scope) */
xf_handle_id(xf_handle_t * handle)264 static inline u32 xf_handle_id(xf_handle_t *handle)
265 {
266     return handle->id;
267 }
268 
269 /* ...pointer to auxiliary buffer */
xf_handle_aux(xf_handle_t * handle)270 static inline void * xf_handle_aux(xf_handle_t *handle)
271 {
272     return xf_buffer_data(handle->aux);
273 }
274 
275 /* ...acquire component lock */
xf_lock(xf_handle_t * handle)276 static inline void xf_lock(xf_handle_t *handle)
277 {
278     __xf_lock(&handle->lock);
279 }
280 
281 /* ...release component lock */
xf_unlock(xf_handle_t * handle)282 static inline void xf_unlock(xf_handle_t *handle)
283 {
284     __xf_unlock(&handle->lock);
285 }
286 
287 /* ...put asynchronous response into local IPC */
xf_response_put(xf_handle_t * handle,xf_user_msg_t * msg)288 static inline int xf_response_put(xf_handle_t *handle, xf_user_msg_t *msg)
289 {
290     return xf_ipc_response_put(&handle->ipc, msg);
291 }
292 
293 /* ...get asynchronous response from local IPC */
xf_response_get(xf_handle_t * handle,xf_user_msg_t * msg)294 static inline int xf_response_get(xf_handle_t *handle, xf_user_msg_t *msg)
295 {
296     return xf_ipc_response_get(&handle->ipc, msg);
297 }
298