Path: blob/main/sys/contrib/vchiq/interface/vchi/vchi.h
48383 views
/**1* Copyright (c) 2010-2012 Broadcom. All rights reserved.2*3* Redistribution and use in source and binary forms, with or without4* modification, are permitted provided that the following conditions5* are met:6* 1. Redistributions of source code must retain the above copyright7* notice, this list of conditions, and the following disclaimer,8* without modification.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. The names of the above-listed copyright holders may not be used13* to endorse or promote products derived from this software without14* specific prior written permission.15*16* ALTERNATIVELY, this software may be distributed under the terms of the17* GNU General Public License ("GPL") version 2, as published by the Free18* Software Foundation.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS21* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,22* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR23* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR24* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,25* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,26* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR27* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF28* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING29* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS30* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*/3233#ifndef VCHI_H_34#define VCHI_H_3536#include "interface/vchi/vchi_cfg.h"37#include "interface/vchi/vchi_common.h"38#include "interface/vchi/connections/connection.h"39#include "vchi_mh.h"404142/******************************************************************************43Global defs44*****************************************************************************/4546#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))47#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))48#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))4950#ifdef USE_VCHIQ_ARM51#define VCHI_BULK_ALIGNED(x) 152#else53#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)54#endif5556struct vchi_version {57uint32_t version;58uint32_t version_min;59};60#define VCHI_VERSION(v_) { v_, v_ }61#define VCHI_VERSION_EX(v_, m_) { v_, m_ }6263typedef enum64{65VCHI_VEC_POINTER,66VCHI_VEC_HANDLE,67VCHI_VEC_LIST68} VCHI_MSG_VECTOR_TYPE_T;6970typedef struct vchi_msg_vector_ex {7172VCHI_MSG_VECTOR_TYPE_T type;73union74{75// a memory handle76struct77{78VCHI_MEM_HANDLE_T handle;79uint32_t offset;80int32_t vec_len;81} handle;8283// an ordinary data pointer84struct85{86const void *vec_base;87int32_t vec_len;88} ptr;8990// a nested vector list91struct92{93struct vchi_msg_vector_ex *vec;94uint32_t vec_len;95} list;96} u;97} VCHI_MSG_VECTOR_EX_T;9899100// Construct an entry in a msg vector for a pointer (p) of length (l)101#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }102103// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)104#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }105106// Macros to manipulate 'FOURCC' values107#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))108#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF109110111// Opaque service information112struct opaque_vchi_service_t;113114// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,115// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.116typedef struct117{118struct opaque_vchi_service_t *service;119void *message;120} VCHI_HELD_MSG_T;121122123124// structure used to provide the information needed to open a server or a client125typedef struct {126struct vchi_version version;127int32_t service_id;128VCHI_CONNECTION_T *connection;129uint32_t rx_fifo_size;130uint32_t tx_fifo_size;131VCHI_CALLBACK_T callback;132void *callback_param;133/* client intends to receive bulk transfers of134odd lengths or into unaligned buffers */135int32_t want_unaligned_bulk_rx;136/* client intends to transmit bulk transfers of137odd lengths or out of unaligned buffers */138int32_t want_unaligned_bulk_tx;139/* client wants to check CRCs on (bulk) xfers.140Only needs to be set at 1 end - will do both directions. */141int32_t want_crc;142} SERVICE_CREATION_T;143144// Opaque handle for a VCHI instance145typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;146147// Opaque handle for a server or client148typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;149150// Service registration & startup151typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);152153typedef struct service_info_tag {154const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */155VCHI_SERVICE_INIT init; /* Service initialisation function */156void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */157} SERVICE_INFO_T;158159/******************************************************************************160Global funcs - implementation is specific to which side you are on (local / remote)161*****************************************************************************/162163#ifdef __cplusplus164extern "C" {165#endif166167extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,168const VCHI_MESSAGE_DRIVER_T * low_level);169170171// Routine used to initialise the vchi on both local + remote connections172extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );173174extern int32_t vchi_exit( void );175176extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,177const uint32_t num_connections,178VCHI_INSTANCE_T instance_handle );179180//When this is called, ensure that all services have no data pending.181//Bulk transfers can remain 'queued'182extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );183184// Global control over bulk CRC checking185extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,186VCHI_CRC_CONTROL_T control );187188// helper functions189extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);190extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);191extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);192193194/******************************************************************************195Global service API196*****************************************************************************/197// Routine to create a named service198extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,199SERVICE_CREATION_T *setup,200VCHI_SERVICE_HANDLE_T *handle );201202// Routine to destory a service203extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );204205// Routine to open a named service206extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,207SERVICE_CREATION_T *setup,208VCHI_SERVICE_HANDLE_T *handle);209210extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,211short *peer_version );212213// Routine to close a named service214extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );215216// Routine to increment ref count on a named service217extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );218219// Routine to decrement ref count on a named service220extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );221222// Routine to set a control option for a named service223extern int32_t vchi_service_set_option( const VCHI_SERVICE_HANDLE_T handle,224VCHI_SERVICE_OPTION_T option,225int value);226227// Routine to send a message across a service228extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,229const void *data,230uint32_t data_size,231VCHI_FLAGS_T flags,232void *msg_handle );233234// scatter-gather (vector) and send message235int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,236VCHI_MSG_VECTOR_EX_T *vector,237uint32_t count,238VCHI_FLAGS_T flags,239void *msg_handle );240241// legacy scatter-gather (vector) and send message, only handles pointers242int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,243VCHI_MSG_VECTOR_T *vector,244uint32_t count,245VCHI_FLAGS_T flags,246void *msg_handle );247248// Routine to receive a msg from a service249// Dequeue is equivalent to hold, copy into client buffer, release250extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,251void *data,252uint32_t max_data_size_to_read,253uint32_t *actual_msg_size,254VCHI_FLAGS_T flags );255256// Routine to look at a message in place.257// The message is not dequeued, so a subsequent call to peek or dequeue258// will return the same message.259extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,260void **data,261uint32_t *msg_size,262VCHI_FLAGS_T flags );263264// Routine to remove a message after it has been read in place with peek265// The first message on the queue is dequeued.266extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );267268// Routine to look at a message in place.269// The message is dequeued, so the caller is left holding it; the descriptor is270// filled in and must be released when the user has finished with the message.271extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,272void **data, // } may be NULL, as info can be273uint32_t *msg_size, // } obtained from HELD_MSG_T274VCHI_FLAGS_T flags,275VCHI_HELD_MSG_T *message_descriptor );276277// Initialise an iterator to look through messages in place278extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,279VCHI_MSG_ITER_T *iter,280VCHI_FLAGS_T flags );281282/******************************************************************************283Global service support API - operations on held messages and message iterators284*****************************************************************************/285286// Routine to get the address of a held message287extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );288289// Routine to get the size of a held message290extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );291292// Routine to get the transmit timestamp as written into the header by the peer293extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );294295// Routine to get the reception timestamp, written as we parsed the header296extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );297298// Routine to release a held message after it has been processed299extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );300301// Indicates whether the iterator has a next message.302extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );303304// Return the pointer and length for the next message and advance the iterator.305extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,306void **data,307uint32_t *msg_size );308309// Remove the last message returned by vchi_msg_iter_next.310// Can only be called once after each call to vchi_msg_iter_next.311extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );312313// Hold the last message returned by vchi_msg_iter_next.314// Can only be called once after each call to vchi_msg_iter_next.315extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,316VCHI_HELD_MSG_T *message );317318// Return information for the next message, and hold it, advancing the iterator.319extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,320void **data, // } may be NULL321uint32_t *msg_size, // }322VCHI_HELD_MSG_T *message );323324325/******************************************************************************326Global bulk API327*****************************************************************************/328329// Routine to prepare interface for a transfer from the other side330extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,331void *data_dst,332uint32_t data_size,333VCHI_FLAGS_T flags,334void *transfer_handle );335336337// Prepare interface for a transfer from the other side into relocatable memory.338int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,339VCHI_MEM_HANDLE_T h_dst,340uint32_t offset,341uint32_t data_size,342const VCHI_FLAGS_T flags,343void * const bulk_handle );344345// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)346extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,347void *data_src,348uint32_t data_size,349VCHI_FLAGS_T flags,350void *transfer_handle );351352353/******************************************************************************354Configuration plumbing355*****************************************************************************/356357// function prototypes for the different mid layers (the state info gives the different physical connections)358extern const VCHI_CONNECTION_API_T *single_get_func_table( void );359//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );360//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );361362// declare all message drivers here363const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );364365#ifdef __cplusplus366}367#endif368369extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,370VCHI_MEM_HANDLE_T h_src,371uint32_t offset,372uint32_t data_size,373VCHI_FLAGS_T flags,374void *transfer_handle );375#endif /* VCHI_H_ */376377/****************************** End of file **********************************/378379380