blob: 17019a73bf6b2be3fb54db63f88074e0a8b9ec04 [file] [log] [blame]
/*******************************************************************************
* 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);