summaryrefslogtreecommitdiff
path: root/hifi/xaf/hifi-dpf/include/xf-io.h
blob: 17019a73bf6b2be3fb54db63f88074e0a8b9ec04 (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
298
/*******************************************************************************
* 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.

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

/*******************************************************************************
 * xf-io.h
 *
 * Input/output data ports
 *
 *******************************************************************************/

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

/*******************************************************************************
 * Types definitions
 ******************************************************************************/

/* ...input port with interim buffer */
typedef struct xf_input_port
{
    /* ...message queue */
    xf_msg_queue_t          queue;
    
    /* ...internal contiguous buffer to store incoming data */
    void                   *buffer;

    /* ...size of internal buffer */
    u32                     length;
    
    /* ...current writing position in the buffer */
    u32                     filled;
    
    /* ...interim pointer to input message buffer */
    void                   *access;
    
    /* ...remaining length of current input message */
    u32                     remaining;
    
    /* ...execution flags */
    u32                     flags;

}   xf_input_port_t;

/*******************************************************************************
 * Input port flags
 ******************************************************************************/

/* ...data enabled */
#define XF_INPUT_FLAG_CREATED           (1 << 0)

/* ...data enabled */
#define XF_INPUT_FLAG_ENABLED           (1 << 1)

/* ...end-of-stream condition */
#define XF_INPUT_FLAG_EOS               (1 << 2)

/* ...stream completed */
#define XF_INPUT_FLAG_DONE              (1 << 3)

/* ...stream purging sequence */
#define XF_INPUT_FLAG_PURGING           (1 << 4)

/* ...base input port flags mask */
#define __XF_INPUT_FLAGS(flags)         ((flags) & ((1 << 5) - 1))

/* ...custom input port flag */
#define __XF_INPUT_FLAG(f)              ((f) << 5)

/*******************************************************************************
 * Helpers
 ******************************************************************************/

/* ...test if input port is created */
static inline int xf_input_port_created(xf_input_port_t *port)
{
    return (port->flags & XF_INPUT_FLAG_CREATED);
}

/* ...check if input port is ready (has pending message) */
static inline int xf_input_port_ready(xf_input_port_t *port)
{
    return (xf_msg_queue_head(&port->queue) != NULL);
}

/* ...test if input port entered end-of-stream condition */
static inline int xf_input_port_done(xf_input_port_t *port)
{
    return (port->flags & XF_INPUT_FLAG_DONE);
}

/* ...check if port is in bypass mode */
static inline int xf_input_port_bypass(xf_input_port_t *port)
{
    return port->buffer == NULL;
}

/* ...bypass port only: check if there is a data available */
static inline void * xf_input_port_data(xf_input_port_t *port)
{
    return port->access;
}

/* ...bypass port only: get remaining length of current message */
static inline u32 xf_input_port_length(xf_input_port_t *port)
{
    return port->remaining;
}

/* ...non-bypass port only: get current fill level */
static inline u32 xf_input_port_level(xf_input_port_t *port)
{
    return port->filled;
}

/*******************************************************************************
 * Output port data
 ******************************************************************************/

typedef struct xf_output_port
{
    /* ...pending message queue */
    xf_msg_queue_t          queue;

    /* ...message pool */
    xf_msg_pool_t           pool;

    /* ...saved port unrouting message */
    xf_message_t           *unroute;

    /* ...length of output buffer */
    u32                     length;

    /* ...output port flags */
    u32                     flags;

}   xf_output_port_t;

/*******************************************************************************
 * Output port flags
 ******************************************************************************/

/* ...port is created */
#define XF_OUTPUT_FLAG_CREATED          (1 << 0)

/* ...port is routed */
#define XF_OUTPUT_FLAG_ROUTED           (1 << 1)

/* ...data enabled */
#define XF_OUTPUT_FLAG_ENABLED          (1 << 2)

/* ...stream completed */
#define XF_OUTPUT_FLAG_DONE             (1 << 3)

/* ...flushing sequence is on-going */
#define XF_OUTPUT_FLAG_FLUSHING         (1 << 4)

/* ...port is idle - no outstanding messages */
#define XF_OUTPUT_FLAG_IDLE             (1 << 5)

/* ...port is being unrouted */
#define XF_OUTPUT_FLAG_UNROUTING        (1 << 6)

/* ...base output port flags accessor */
#define __XF_OUTPUT_FLAGS(flags)        ((flags) & ((1 << 7) - 1))

/* ...custom output port flag */
#define __XF_OUTPUT_FLAG(f)             ((f) << 7)

/*******************************************************************************
 * Helpers
 ******************************************************************************/

/* ...test if input port is created */
static inline int xf_output_port_created(xf_output_port_t *port)
{
    return (port->flags & XF_OUTPUT_FLAG_CREATED);
}

/* ...check if port is routed */
static inline int xf_output_port_routed(xf_output_port_t *port)
{
    return ((port->flags & XF_OUTPUT_FLAG_ROUTED) != 0);
}

/* ...check if port unrouting sequence is ongoing */
static inline int xf_output_port_unrouting(xf_output_port_t *port)
{
    return ((port->flags & XF_OUTPUT_FLAG_UNROUTING) != 0);
}

/* ...check if port is idle (owns all data buffers) */
static inline int xf_output_port_idle(xf_output_port_t *port)
{
    return ((port->flags & XF_OUTPUT_FLAG_IDLE) != 0);
}

/* ...check if port is ready (has output buffers - better use flags - tbd) */
static inline int xf_output_port_ready(xf_output_port_t *port)
{
    return (xf_msg_queue_head(&port->queue) != NULL && !xf_output_port_unrouting(port));
}

/* ...output port flow-control message accessor */
static inline xf_message_t * xf_output_port_control_msg(xf_output_port_t *port)
{
    return xf_msg_pool_item(&port->pool, 0);
}

/*******************************************************************************
 * Input port API
 ******************************************************************************/

/* ...initialize input port structure */
extern int  xf_input_port_init(xf_input_port_t *port, u32 size, u32 align, u32 core);

/* ...put message into input port queue */
extern int  xf_input_port_put(xf_input_port_t *port, xf_message_t *m);

/* ...fill-in required amount of data into input port buffer */
extern int  xf_input_port_fill(xf_input_port_t *port);

/* ...pad input buffer with given value */
extern void xf_input_port_pad(xf_input_port_t *port, u8 pad);

/* ...consume bytes from input buffer */
extern void xf_input_port_consume(xf_input_port_t *port, u32 n);

/* ...purge input port queue */
extern void xf_input_port_purge(xf_input_port_t *port);

/* ...save flow-control message for propagated input port purging sequence */
extern void xf_input_port_control_save(xf_input_port_t *port, xf_message_t *m);

/* ...complete input port purging sequence */
extern void xf_input_port_purge_done(xf_input_port_t *port);

/* ...destroy input port data */
extern void xf_input_port_destroy(xf_input_port_t *port, u32 core);

/*******************************************************************************
 * Output port API
 ******************************************************************************/

/* ...initialize output port structure */
extern int  xf_output_port_init(xf_output_port_t *port, u32 size);

/* ...put next message to the output port */
extern int  xf_output_port_put(xf_output_port_t *port, xf_message_t *m);

/* ...get data buffer of output message */
extern void * xf_output_port_data(xf_output_port_t *port);

/* ...route output port */
extern int xf_output_port_route(xf_output_port_t *port, u32 id, u32 n, u32 length, u32 align);

/* ...unroute output port */
extern void xf_output_port_unroute(xf_output_port_t *port);

/* ...start output port unrouting sequence */
extern void xf_output_port_unroute_start(xf_output_port_t *port, xf_message_t *m);

/* ...complete port unrouting sequence */
extern void xf_output_port_unroute_done(xf_output_port_t *port);

/* ...produce output message marking amount of bytes produced */
extern int  xf_output_port_produce(xf_output_port_t *port, u32 n);

/* ...purge output port */
extern void xf_output_port_purge(xf_output_port_t *port);

/* ...flush output port and return non-zero result if sequence is over */
extern int xf_output_port_flush(xf_output_port_t *port, u32 opcode);

/* ...complete flushing sequence */
extern void xf_output_port_flush_done(xf_output_port_t *port);

/* ...destroy output port data */
extern void xf_output_port_destroy(xf_output_port_t *port, u32 core);