summaryrefslogtreecommitdiff
path: root/hifi/xaf/host-apf/include/xf-proxy.h
blob: 90d707933f6cab2d2595f8c31233d334a29568ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
/*******************************************************************************
* Copyright (C) 2018 Cadence Design Systems, Inc.
* 
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to use this Software with Cadence processor cores only and 
* not with any other processors and platforms, subject to
* the following conditions:
* 
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************************/

#ifndef __XF_H
#error  "xf-proxy.h mustn't be included directly"
#endif

/*******************************************************************************
 * User-message description - move from here to API - tbd
 ******************************************************************************/

/* ...need that at all? hope no */
struct xf_user_msg
{
    /* ...source component specification */
    u32             id;
    
    /* ...message opcode */
    u32             opcode;
    
    /* ...buffer length */
    u32             length;
    
    /* ...buffer pointer */
    void           *buffer;
};

/* ...proxy message - bad placing of that thing here - tbd */
struct xf_proxy_msg
{
    /* ...session-id field */
    uint32_t             id;
    
    /* ...message opcode */
    uint32_t             opcode;
    
    /* ...buffer length */
    uint32_t             length;
    
    /* ...buffer pointer */
    uint64_t             address;
    uint64_t         v_address;

}   __attribute__((__packed__));

typedef struct xf_proxy_msg_driv
{
    /* ...session ID */
    uint32_t                 id;

    /* ...proxy API command/reponse code */
    uint32_t                 opcode;

    /* ...length of attached buffer */
    uint32_t                 length;

    /* ...physical address of message buffer */
    uint64_t                 address;
    uint64_t                 v_address;

}__attribute__((__packed__)) xf_proxy_message_driv_t;
/*******************************************************************************
 * Buffer pools
 ******************************************************************************/

/* ...buffer pool type */
enum xf_pool_type
{
    XF_POOL_AUX = 0,
    XF_POOL_INPUT = 1,
    XF_POOL_OUTPUT = 2
};

/* ...buffer link pointer */
typedef union xf_buffer_link
{
    /* ...pointer to next free buffer in a pool (for free buffer) */
    xf_buffer_t        *next;
    
    /* ...reference to a buffer pool (for allocated buffer) */
    xf_pool_t          *pool;

}   xf_buffer_link_t;

/* ...buffer descriptor */
struct xf_buffer
{
    /* ...virtual address of contiguous buffer */
    void               *address;

    /* ...link pointer */
    xf_buffer_link_t    link;
};

/* ...buffer pool */
struct xf_pool
{
    /* ...reference to proxy data */
    xf_proxy_t         *proxy;

    /* ...length of individual buffer in a pool */
    u32                 length;
    
    /* ...number of buffers in a pool */
    u32                 number;

    /* ...pointer to pool memory */
    void               *p;
    
    /* ...pointer to first free buffer in a pool */
    xf_buffer_t        *free;

    /* ...individual buffers */
    xf_buffer_t         buffer[0];
};

/* ...accessor to buffer data */
static inline void * xf_buffer_data(xf_buffer_t *buffer)
{
    return buffer->address;
}

/* ...length of buffer data */
static inline size_t xf_buffer_length(xf_buffer_t *buffer)
{
    return buffer->link.pool->length;
}

/*******************************************************************************
 * Proxy handle definition
 ******************************************************************************/

/* ...free clients list */
typedef union xf_proxy_cmap_link
{
    /* ...index of next free client in the list */
    u32                     next;
    
    /* ...pointer to allocated component handle */
    xf_handle_t            *handle;

}   xf_proxy_cmap_link_t;

/* ...proxy data structure */
struct xf_proxy
{
    /* ...platform-specific IPC data */
    xf_proxy_ipc_data_t     ipc;
    
    /* ...auxiliary buffer pool for clients */
    xf_pool_t              *aux;

    /* ...global proxy lock */
    xf_lock_t               lock;

    /* ...proxy thread handle */
    xf_thread_t             thread;

    /* ...proxy identifier (core of remote DSP hosting SHMEM interface) */
    u32                     core;

    /* ...client association map */
    xf_proxy_cmap_link_t    cmap[XF_CFG_PROXY_MAX_CLIENTS];
};

/*******************************************************************************
 * Auxiliary proxy helpers
 ******************************************************************************/

/* ...get proxy identifier */
static inline u32 xf_proxy_id(xf_proxy_t *proxy)
{
    return proxy->core;
}

/* ...lock proxy data */
static inline void xf_proxy_lock(xf_proxy_t *proxy)
{
    __xf_lock(&proxy->lock);
}

/* ...unlock proxy data */
static inline void xf_proxy_unlock(xf_proxy_t *proxy)
{
    __xf_unlock(&proxy->lock);
}

/* ...translate proxy shared address into local virtual address */
static inline void * xf_proxy_a2b(xf_proxy_t *proxy, u32 address)
{
    return xf_ipc_a2b(&proxy->ipc, address);
}

/* ...translate local virtual address into shared proxy address */
static inline u32 xf_proxy_b2a(xf_proxy_t *proxy, void *b)
{
    return xf_ipc_b2a(&proxy->ipc, b);
}

/* ...submit asynchronous response message */
static inline int xf_proxy_response_put(xf_proxy_t *proxy, xf_proxy_msg_t *msg)
{
    return xf_proxy_ipc_response_put(&proxy->ipc, msg);
}

/* ...retrieve asynchronous response message */
static inline int xf_proxy_response_get(xf_proxy_t *proxy, xf_proxy_msg_t *msg)
{
    return xf_proxy_ipc_response_get(&proxy->ipc, msg);
}

/*******************************************************************************
 * Component handle definition
 ******************************************************************************/

struct xf_handle
{
    /* ...platform-specific IPC data */
    xf_ipc_data_t           ipc;
    
    /* ...reference to proxy data */
    xf_proxy_t             *proxy;
    
    /* ...component lock */
    xf_lock_t               lock;
 
    /* ...auxiliary control buffer for control transactions */
    xf_buffer_t            *aux;

    /* ...global client-id of the component */
    u32                     id;

    /* ...local client number (think about merging into "id" field - tbd) */
    u32                     client;
    
    /* ...response processing hook */
    xf_response_cb          response;
};

/*******************************************************************************
 * Auxiliary component helpers
 ******************************************************************************/

/* ...component client-id (global scope) */
static inline u32 xf_handle_id(xf_handle_t *handle)
{
    return handle->id;
}

/* ...pointer to auxiliary buffer */
static inline void * xf_handle_aux(xf_handle_t *handle)
{
    return xf_buffer_data(handle->aux);
}

/* ...acquire component lock */
static inline void xf_lock(xf_handle_t *handle)
{
    __xf_lock(&handle->lock);
}

/* ...release component lock */
static inline void xf_unlock(xf_handle_t *handle)
{
    __xf_unlock(&handle->lock);
}

/* ...put asynchronous response into local IPC */
static inline int xf_response_put(xf_handle_t *handle, xf_user_msg_t *msg)
{
    return xf_ipc_response_put(&handle->ipc, msg);
}

/* ...get asynchronous response from local IPC */
static inline int xf_response_get(xf_handle_t *handle, xf_user_msg_t *msg)
{
    return xf_ipc_response_get(&handle->ipc, msg);
}